Class: NSScreen

Inherits:
Object show all
Defined in:
ext/accessibility/extras/extras.c,
ext/accessibility/extras/extras.c

Overview

A small subset of Cocoa's NSScreen class. Methods that might be useful to have have been bridged.

See Apple's Developer Reference for documentation on the methods available in this class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mainScreenObject



467
468
469
470
471
472
# File 'ext/accessibility/extras/extras.c', line 467

static
VALUE
rb_screen_main(VALUE self)
{
  return wrap_screen([NSScreen mainScreen]);
}

.screensObject



474
475
476
477
478
479
# File 'ext/accessibility/extras/extras.c', line 474

static
VALUE
rb_screen_screens(VALUE self)
{
    return wrap_array_screens((CFArrayRef)[NSScreen screens]);
}

.wakeupObject

our custom method



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'ext/accessibility/extras/extras.c', line 488

static
VALUE
rb_screen_wake(VALUE self)
{
  // don't bother if we are awake
  if (!CGDisplayIsAsleep(CGMainDisplayID()))
    return Qtrue;

  if (screen_connection == MACH_PORT_NULL) {
    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
    if (service != MACH_PORT_NULL) {
      IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &screen_connection);
      IOObjectRelease(service);
    }
    else { // give up
      return Qfalse;
    }
  }

  CGPoint      mouse = NSPointToCGPoint([NSEvent mouseLocation]);
  IOGPoint     point = { mouse.x, mouse.y };
  unsigned int flags = (unsigned int)[NSEvent modifierFlags];
  NXEventData   data;

  IOHIDPostEvent(screen_connection, NX_FLAGSCHANGED, point, &data, kNXEventDataVersion, flags, 0);

  // spin rims while we wait for the screen to fully wake up
  spin(1);

  return Qtrue;
}

Instance Method Details

#frameObject

our custom method



481
482
483
484
485
486
# File 'ext/accessibility/extras/extras.c', line 481

static
VALUE
rb_screen_frame(VALUE self)
{
    return wrap_rect(NSRectToCGRect([unwrap_screen(self) frame]));
}