Exemplo n.º 1
0
int main (int argc, const char * argv[]) {
  uint32_t displayCount;
  CGGetActiveDisplayList(0, NULL, &displayCount);

  if (displayCount != 2) {
    fprintf(stderr, "Error: expected exactly 2 displays, %d found\n", displayCount);
    exit(1);
  }
  
  CGDirectDisplayID activeDisplays[displayCount];
  CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount);

  const int32_t xTranslation = -CGRectGetMinX(CGDisplayBounds(activeDisplays[1]));
  
  CGDisplayConfigRef config;
  CGBeginDisplayConfiguration(&config);
  CGConfigureDisplayFadeEffect(config, 0.2, 0.2, 0, 0, 0);
  for (int i = 0; i < displayCount; ++i) {
    CGDirectDisplayID display = activeDisplays[i];
    CGRect displayBounds = CGDisplayBounds(display);
    CGConfigureDisplayOrigin(config, display, CGRectGetMinX(displayBounds) + xTranslation, CGRectGetMinY(displayBounds));
  }  
  CGCompleteDisplayConfiguration(config, kCGConfigurePermanently);
  
  return 0;
}
Exemplo n.º 2
0
void
COSXScreen::updateScreenShape()
{
	// get info for each display
	CGDisplayCount displayCount = 0;

	if (CGGetActiveDisplayList(0, NULL, &displayCount) != CGDisplayNoErr) {
		return;
	}
	
	if (displayCount == 0) {
		return;
	}

	CGDirectDisplayID* displays = new CGDirectDisplayID[displayCount];
	if (displays == NULL) {
		return;
	}

	if (CGGetActiveDisplayList(displayCount,
							displays, &displayCount) != CGDisplayNoErr) {
		delete[] displays;
		return;
	}

	// get smallest rect enclosing all display rects
	CGRect totalBounds = CGRectZero;
	for (CGDisplayCount i = 0; i < displayCount; ++i) {
		CGRect bounds = CGDisplayBounds(displays[i]);
		totalBounds   = CGRectUnion(totalBounds, bounds);
	}

	// get shape of default screen
	m_x = (SInt32)totalBounds.origin.x;
	m_y = (SInt32)totalBounds.origin.y;
	m_w = (SInt32)totalBounds.size.width;
	m_h = (SInt32)totalBounds.size.height;

	// get center of default screen
  CGDirectDisplayID main = CGMainDisplayID();
  const CGRect rect = CGDisplayBounds(main);
  m_xCenter = (rect.origin.x + rect.size.width) / 2;
  m_yCenter = (rect.origin.y + rect.size.height) / 2;

	delete[] displays;
	// We want to notify the peer screen whether we are primary screen or not
	sendEvent(m_events->forIScreen().shapeChanged());

	LOG((CLOG_DEBUG "screen shape: center=%d,%d size=%dx%d on %u %s",
         m_x, m_y, m_w, m_h, displayCount,
         (displayCount == 1) ? "display" : "displays"));
}
Exemplo n.º 3
0
void
COSXScreen::updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags flags)
{
    
	// get info for each display
	CGDisplayCount displayCount = 0;

	if (CGGetActiveDisplayList(0, NULL, &displayCount) != CGDisplayNoErr) {
		return;
	}
	
	if (displayCount == 0) {
		return;
	}

	CGDirectDisplayID* displays = new CGDirectDisplayID[displayCount];
	if (displays == NULL) {
		return;
	}

	if (CGGetActiveDisplayList(displayCount,
							displays, &displayCount) != CGDisplayNoErr) {
		delete[] displays;
		return;
	}

	// get smallest rect enclosing all display rects
	CGRect totalBounds = CGRectZero;
	for (CGDisplayCount i = 0; i < displayCount; ++i) {
		CGRect bounds = CGDisplayBounds(displays[i]);
		totalBounds   = CGRectUnion(totalBounds, bounds);
	}

	// get shape of default screen
	m_x = (SInt32)totalBounds.origin.x;
	m_y = (SInt32)totalBounds.origin.y;
	m_w = (SInt32)totalBounds.size.width;
	m_h = (SInt32)totalBounds.size.height;

	// get center of default screen
  CGDirectDisplayID main = CGMainDisplayID();
  const CGRect rect = CGDisplayBounds(main);
  m_xCenter = (rect.origin.x + rect.size.width) / 2;
  m_yCenter = (rect.origin.y + rect.size.height) / 2;

	delete[] displays;
    if (m_isPrimary && !m_isOnScreen) {
        sendEvent(getShapeChangedEvent());
    }

	LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d on %u %s", m_x, m_y, m_w, m_h, displayCount, (displayCount == 1) ? "display" : "displays"));
}
Exemplo n.º 4
0
void
setMainDisplay(CGDirectDisplayID targetDisplay)
{
    int				   deltaX, deltaY, flag;
    CGDisplayErr       dErr;
    CGDisplayCount     displayCount, i;
    CGDirectDisplayID mainDisplay;
    CGDisplayCount     maxDisplays = MAX_DISPLAYS;
    CGDirectDisplayID  onlineDisplays[MAX_DISPLAYS]; 
	CGDisplayConfigRef config;

	mainDisplay = CGMainDisplayID();
	
	if (mainDisplay == targetDisplay) {
	exit(0);
	}
	
    dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr);
        exit(1);
    }
	
	flag = 0;
    for (i = 0; i < displayCount; i++) {
    	CGDirectDisplayID dID = onlineDisplays[i];
			if (dID == targetDisplay) { flag = 1; }
	}	
	if (flag == 0) {
        fprintf(stderr, "No such display ID: %10p.\n", targetDisplay);
        exit(1);
    }

	deltaX = -CGRectGetMinX (CGDisplayBounds (targetDisplay));
    deltaY = -CGRectGetMinY (CGDisplayBounds (targetDisplay));

    CGBeginDisplayConfiguration (&config);
    
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dID = onlineDisplays[i];
    
    CGConfigureDisplayOrigin (config, dID,
    	CGRectGetMinX (CGDisplayBounds (dID)) + deltaX,
    	CGRectGetMinY (CGDisplayBounds (dID)) + deltaY );
	}

    CGCompleteDisplayConfiguration (config, kCGConfigureForSession);
   
   
    exit(0);
}
Exemplo n.º 5
0
void QuartzWindow::warp_pointer(int x, int y) {
  // lprintf("warping to: %d, %d\n", x, y);
# if TARGET_OS_VERSION == MACOSX_VERSION
    CGPoint pt;
    pt.x = x;
    pt.y = y;
    const int n = 16;
    CGDisplayCount count = 0;
    CGDirectDisplayID dspys[n];
    CGDisplayErr err = CGGetDisplaysWithPoint( pt, n, dspys, &count);
    if (err != noErr) {
      lprintf("CGGetDisplaysWithPoint failed: %d\n", err);
      return;
    }
    // lprintf("CGGetDisplaysWithPoint count = %d\n", count);
    for (int i = 0;  i < count;  ++i) {
      // MUST adj pt to be relative to TL of display -- dmu 5/03
      CGRect bounds = CGDisplayBounds(dspys[i]);
      CGPoint adjusted_pt;
      adjusted_pt.x = pt.x - bounds.origin.x;
      adjusted_pt.y = pt.y - bounds.origin.y;
      err = CGDisplayMoveCursorToPoint( dspys[i], adjusted_pt);
      // lprintf("CGDisplayMoveCursorToPoint %d returned %d\n", i, err);
    }
# else
  Unused(x); Unused(y);
# endif
}
Exemplo n.º 6
0
/***********************************************************************
 *              macdrv_get_desktop_rect
 *
 * Returns the rectangle encompassing all the screens.
 */
CGRect macdrv_get_desktop_rect(void)
{
    CGRect ret;
    CGDirectDisplayID displayIDs[32];
    uint32_t count, i;

    EnterCriticalSection(&device_data_section);

    if (!device_data_valid)
    {
        desktop_rect = CGRectNull;
        if (CGGetActiveDisplayList(sizeof(displayIDs)/sizeof(displayIDs[0]),
                                   displayIDs, &count) != kCGErrorSuccess ||
            !count)
        {
            displayIDs[0] = CGMainDisplayID();
            count = 1;
        }

        for (i = 0; i < count; i++)
            desktop_rect = CGRectUnion(desktop_rect, CGDisplayBounds(displayIDs[i]));
    }

    ret = desktop_rect;
    LeaveCriticalSection(&device_data_section);

    TRACE("%s\n", wine_dbgstr_cgrect(ret));

    return ret;
}
Exemplo n.º 7
0
CGRect
max_bounds()
{
	OSErr err;
	CGDirectDisplayID* d; 
	CGDisplayCount c, i;
	CGRect r;
	int bx=0, by=0, rx=0, ry=0;

	err = CGGetActiveDisplayList(0, NULL, &c);
	if(err != noErr)
		sysfatal("can not enumerate active displays");

	d = (CGDirectDisplayID *)malloc(c * sizeof(CGDirectDisplayID));
	if(d == NULL)
		sysfatal("can not allocate memory for display list");

	err = CGGetActiveDisplayList(c, d, &c);
	if(err != noErr)
		sysfatal("can not obtain active display list");

	for (i = 0; i < c; i++) {
		r = CGDisplayBounds(d[i]);
		rx = r.size.width;
		ry = r.size.height;
		if(rx > bx)
			bx = rx;
		if(ry > by)
			by = ry;
	}
	
	return CGRectMake(0,0,bx,by);
}
Exemplo n.º 8
0
OSStatus wxOverlayImpl::CreateOverlayWindow()
{
    OSStatus err;

    WindowAttributes overlayAttributes  = kWindowIgnoreClicksAttribute;

    if ( m_window )
    {
        m_overlayParentWindow =(WindowRef) m_window->MacGetTopLevelWindowRef();

        Rect bounds ;
        MacGetBounds(&bounds);
        err  = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
        if ( err == noErr )
        {
            SetWindowGroup( m_overlayWindow, GetWindowGroup(m_overlayParentWindow));    //  Put them in the same group so that their window layers are consistent
        }
    }
    else
    {
        m_overlayParentWindow = NULL ;
        CGRect cgbounds ;
        cgbounds = CGDisplayBounds(CGMainDisplayID());
        Rect bounds;
        bounds.top = (short)cgbounds.origin.y;
        bounds.left = (short)cgbounds.origin.x;
        bounds.bottom = (short)(bounds.top + cgbounds.size.height);
        bounds.right = (short)(bounds.left  + cgbounds.size.width);
        err  = CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, &m_overlayWindow );
    }
    ShowWindow(m_overlayWindow);
    return err;
}
Exemplo n.º 9
0
// Create a DC representing the whole screen
wxScreenDCImpl::wxScreenDCImpl( wxDC *owner ) :
   wxWindowDCImpl( owner )
{
#if wxOSX_USE_COCOA_OR_CARBON
    CGRect cgbounds ;
    cgbounds = CGDisplayBounds(CGMainDisplayID());
    m_width = (wxCoord)cgbounds.size.width;
    m_height = (wxCoord)cgbounds.size.height;
#else
    wxDisplaySize( &m_width, &m_height );
#endif
#if wxOSX_USE_COCOA_OR_IPHONE
    SetGraphicsContext( wxGraphicsContext::Create() );
#else
    Rect bounds;
    bounds.top = (short)cgbounds.origin.y;
    bounds.left = (short)cgbounds.origin.x;
    bounds.bottom = bounds.top + (short)cgbounds.size.height;
    bounds.right = bounds.left  + (short)cgbounds.size.width;
    WindowAttributes overlayAttributes  = kWindowIgnoreClicksAttribute;
    CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
    ShowWindow((WindowRef)m_overlayWindow);
    SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
#endif
    m_ok = true ;
}
Exemplo n.º 10
0
screen_info CreateDefaultScreenInfo(int DisplayIndex, int ScreenIndex)
{
    CGRect DisplayRect = CGDisplayBounds(DisplayIndex);
    screen_info Screen;

    Screen.ID = ScreenIndex;
    Screen.ForceContainerUpdate = false;
    Screen.ActiveSpace = 0;
    Screen.OldWindowListCount = -1;

    Screen.X = DisplayRect.origin.x;
    Screen.Y = DisplayRect.origin.y;
    Screen.Width = DisplayRect.size.width;
    Screen.Height = DisplayRect.size.height;

    Screen.PaddingTop = DefaultPaddingTop;
    Screen.PaddingLeft = DefaultPaddingLeft;
    Screen.PaddingRight = DefaultPaddingRight;
    Screen.PaddingBottom = DefaultPaddingBottom;

    Screen.VerticalGap = DefaultGapVertical;
    Screen.HorizontalGap = DefaultGapHorizontal;

    return Screen;
}
Exemplo n.º 11
0
void
screeninit(void)
{
	int fmt;
	int dx, dy;
	ProcessSerialNumber psn = { 0, kCurrentProcess };
	TransformProcessType(&psn, kProcessTransformToForegroundApplication);
	SetFrontProcess(&psn);

	fmt = XBGR32; //XRGB32;
	devRect = max_bounds();
	dx = devRect.size.width;
	dy = devRect.size.height;

	gscreen = allocmemimage(Rect(0,0,dx,dy), fmt);
	dataProviderRef = CGDataProviderCreateWithData(0, gscreen->data->bdata,
					dx * dy * 4, 0);
	fullScreenImage = CGImageCreate(dx, dy, 8, 32, dx * 4,
				CGColorSpaceCreateDeviceRGB(),
				kCGImageAlphaNoneSkipLast,
				dataProviderRef, 0, 0, kCGRenderingIntentDefault);

	devRect = CGDisplayBounds(CGMainDisplayID());

	kproc("osxscreen", winproc, nil, 0);
	kproc("osxflush", flushproc, nil, 0);
	Sleep(&rend, isready, nil);
}
Exemplo n.º 12
0
int main(int argc, const char * argv[]) {
    uint32_t maxDisplays = 256;
    CGDirectDisplayID activeDisplays[maxDisplays];
    uint32_t displayCount = 0;
    
    CGError error = CGGetActiveDisplayList(maxDisplays, activeDisplays, &displayCount);

    if (error != kCGErrorSuccess) {
        fprintf(stderr, "Quartz error %d.  See http://developer.apple.com/library/mac/#documentation/CoreGraphics/Reference/CoreGraphicsConstantsRef/Reference/reference.html#//apple_ref/doc/uid/TP40008794", error);
        return error;
    }
    
    if (argc != 1) {
        fprintf(stderr, "usage: screenarrangement\nprints all active display {origin, size} as an AppleScript list");
        return 2;
    }
    
    printf("{");
    for (int i = 0; i < displayCount; i++) {
        CGRect bounds = CGDisplayBounds(activeDisplays[i]);
        CGPoint origin = bounds.origin;
        CGSize size = bounds.size;
        
        printf("{{%d, %d}, {%d, %d}}", (uint32_t) origin.x, (uint32_t) origin.y, (uint32_t) size.width, (uint32_t) size.height);
        if (i != displayCount - 1) {
            printf(", ");
        }
    }
    printf("}\n");
    
    return 0;
}
Exemplo n.º 13
0
int main(int argc, char * argv[])
{
    IOReturn            err;
    CGDirectDisplayID   dspy = CGMainDisplayID();
    io_service_t        framebuffer;
    CGRect              bounds;
    vm_address_t        buffer;
    vm_size_t           size, rowBytes;

    framebuffer = CGDisplayIOServicePort(dspy);
    assert (framebuffer != MACH_PORT_NULL);
    dspy = CGMainDisplayID();
    bounds = CGDisplayBounds(dspy);
    rowBytes = CGDisplayBytesPerRow(dspy);

    err = IOAccelReadFramebuffer(framebuffer, bounds.size.width, bounds.size.height, rowBytes,
                                 &buffer, &size);
    if (kIOReturnSuccess == err)
    {
        fprintf(stderr, "writing 0x%x bytes from 0x%x\n", size, buffer);
        write(STDOUT_FILENO, (const void *) buffer, size);
        vm_deallocate(mach_task_self(), buffer, size);
    }
    return (0);
}
Exemplo n.º 14
0
wxRect wxDisplayImplMacOSX::GetGeometry() const
{
    CGRect theRect = CGDisplayBounds(m_id);
    return wxRect( (int)theRect.origin.x,
                   (int)theRect.origin.y,
                   (int)theRect.size.width,
                   (int)theRect.size.height ); //floats
}
Exemplo n.º 15
0
// Get size of display
void wxDisplaySize(int *width, int *height)
{
    // TODO adapt for multi-displays
    CGRect bounds = CGDisplayBounds(CGMainDisplayID());
    if ( width )
        *width = (int)bounds.size.width ;
    if ( height )
        *height = (int)bounds.size.height;
}
Exemplo n.º 16
0
void
infoDisplays(void)
{
    CGDisplayErr      dErr;
    CGDisplayCount    displayCount, i;
    CGDirectDisplayID mainDisplay;
    CGDisplayCount    maxDisplays = MAX_DISPLAYS;
    CGDirectDisplayID onlineDisplays[MAX_DISPLAYS];
    
    CGEventRef ourEvent = CGEventCreate(NULL);
    CGPoint ourLoc = CGEventGetLocation(ourEvent);
    
    CFRelease(ourEvent);
    
    mainDisplay = CGMainDisplayID();
   
    dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "CGGetOnlineDisplayList: error %d.\n", dErr);
        exit(1);
    }
   
    printf("#  Display_ID  Resolution  ____Display_Bounds____  Rotation\n");
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dID = onlineDisplays[i];
        printf("%-2d %10p  %4lux%-4lu  %5.0f %5.0f %5.0f %5.0f    %3.0f    %s%s%s", 
               CGDisplayUnitNumber (dID), dID,
               CGDisplayPixelsWide(dID), CGDisplayPixelsHigh(dID),
               CGRectGetMinX (CGDisplayBounds (dID)),
               CGRectGetMinY (CGDisplayBounds (dID)),
               CGRectGetMaxX (CGDisplayBounds (dID)),
               CGRectGetMaxY (CGDisplayBounds (dID)),           
               CGDisplayRotation (dID),
               (CGDisplayIsActive (dID)) ? "" : "[inactive]",
               (dID == mainDisplay) ? "[main]" : "",
               (CGDisplayIsBuiltin (dID)) ? "[internal]\n" : "\n");
    }
    
    printf("Mouse Cursor Position:  ( %5.0f , %5.0f )\n",
               (float)ourLoc.x, (float)ourLoc.y);
   
    exit(0);
}
Exemplo n.º 17
0
    std::string Platform::GetScreenResolution()
    {
        CGRect mainMonitor = CGDisplayBounds(CGMainDisplayID());
        CGFloat monitorHeight = CGRectGetHeight(mainMonitor);
        CGFloat monitorWidth = CGRectGetWidth(mainMonitor);
        
        std::stringstream ss;
        ss << int(monitorWidth) << "x" << int(monitorHeight);
		
        return ss.str();
    }
Exemplo n.º 18
0
JNIEXPORT void JNICALL OS_NATIVE(CGDisplayBounds)
	(JNIEnv *env, jclass that, jint arg0, jobject arg1)
{
	CGRect _arg1, *lparg1=NULL;
	OS_NATIVE_ENTER(env, that, CGDisplayBounds_FUNC);
	if (arg1) if ((lparg1 = getCGRectFields(env, arg1, &_arg1)) == NULL) goto fail;
	*lparg1 = CGDisplayBounds((CGDirectDisplayID)arg0);
fail:
	if (arg1 && lparg1) setCGRectFields(env, arg1, lparg1);
	OS_NATIVE_EXIT(env, that, CGDisplayBounds_FUNC);
}
Exemplo n.º 19
0
/* Return dimensions of current main display as an array of two integers */
VALUE MW_display_size(VALUE module) {
    CGRect bounds;
    VALUE retval;

    bounds = CGDisplayBounds(CGMainDisplayID());
    retval = rb_ary_new();
    rb_ary_push(retval, INT2NUM((int)CGRectGetMaxX(bounds)));
    rb_ary_push(retval, INT2NUM((int)CGRectGetMaxY(bounds)));

    return retval;
}
Exemplo n.º 20
0
void
COSXScreen::postMouseEvent(CGPoint& pos) const
{
	// check if cursor position is valid on the client display configuration
	// [email protected]
	CGDisplayCount displayCount = 0;
	CGGetDisplaysWithPoint(pos, 0, NULL, &displayCount);
	if (displayCount == 0) {
		// cursor position invalid - clamp to bounds of last valid display.
		// find the last valid display using the last cursor position.
		displayCount = 0;
		CGDirectDisplayID displayID;
		CGGetDisplaysWithPoint(CGPointMake(m_xCursor, m_yCursor), 1,
								&displayID, &displayCount);
		if (displayCount != 0) {
			CGRect displayRect = CGDisplayBounds(displayID);
			if (pos.x < displayRect.origin.x) {
				pos.x = displayRect.origin.x;
			}
			else if (pos.x > displayRect.origin.x +
								displayRect.size.width - 1) {
				pos.x = displayRect.origin.x + displayRect.size.width - 1;
			}
			if (pos.y < displayRect.origin.y) {
				pos.y = displayRect.origin.y;
			}
			else if (pos.y > displayRect.origin.y +
								displayRect.size.height - 1) {
				pos.y = displayRect.origin.y + displayRect.size.height - 1;
			}
		}
	}
 	
	// synthesize event.  CGPostMouseEvent is a particularly good
	// example of a bad API.  we have to shadow the mouse state to
	// use this API and if we want to support more buttons we have
	// to recompile.
	//
	// the order of buttons on the mac is:
	// 1 - Left
	// 2 - Right
	// 3 - Middle
	// Whatever the USB device defined.
	//
	// It is a bit weird that the behaviour of buttons over 3 are dependent
	// on currently plugged in USB devices.
	CGPostMouseEvent(pos, true, sizeof(m_buttons) / sizeof(m_buttons[0]),
				m_buttons[0],
				m_buttons[2],
				m_buttons[1],
				m_buttons[3],
				m_buttons[4]);
}
Exemplo n.º 21
0
void UpdateExistingScreenInfo(screen_info *Screen, int DisplayIndex, int ScreenIndex)
{
    CGRect DisplayRect = CGDisplayBounds(DisplayIndex);
    Screen->ID = ScreenIndex;

    Screen->X = DisplayRect.origin.x;
    Screen->Y = DisplayRect.origin.y;
    Screen->Width = DisplayRect.size.width;
    Screen->Height = DisplayRect.size.height;

    Screen->Settings.Offset = KWMScreen.DefaultOffset;
    Screen->Settings.Mode = SpaceModeDefault;
}
Exemplo n.º 22
0
/* Calculate the _bottom_left and _top_right corners of our virtual display.
 * Must be called after init_displays.
 */
void ScreenShooter::calculate_bounds() {
  _display_bounds = new CGRect[_dsp_count];
  
  for(unsigned int i = 0; i < _dsp_count; i++)
  {
      _display_bounds[i] = CGDisplayBounds(_displays[i]);
      CGRect bounds   = _display_bounds[i];
      _bottom_left.x = min(_bottom_left.x, bounds.origin.x);
      _bottom_left.y = max(_bottom_left.y, bounds.origin.y+bounds.size.height);
      _top_right.x   = max(_top_right.x, bounds.origin.x+bounds.size.width);
      _top_right.y   = min(_top_right.y, bounds.origin.y);
  }
}
Exemplo n.º 23
0
void UpdateExistingScreenInfo(screen_info *Screen, int DisplayIndex, int ScreenIndex)
{
    CGRect DisplayRect = CGDisplayBounds(DisplayIndex);
    Screen->ID = ScreenIndex;

    Screen->X = DisplayRect.origin.x;
    Screen->Y = DisplayRect.origin.y;
    Screen->Width = DisplayRect.size.width;
    Screen->Height = DisplayRect.size.height;

    Screen->Offset = DefaultContainerOffset;
    Screen->ForceContainerUpdate = true;
}
Exemplo n.º 24
0
/* The following function was contributed by Anthony Liguori Jan 18 2015.
 * https://github.com/kwhat/libuiohook/pull/18
 */
UIOHOOK_API screen_data* hook_create_screen_info(unsigned char *count) {
	CGError status = kCGErrorFailure;
	screen_data* screens = NULL;

	// Initialize count to zero.
	*count = 0;

	// Allocate memory to hold each display id.  We will just allocate our MAX
	// because its only about 1K of memory.
	// TODO This can probably be realistically cut to something like 16 or 32....
	// If you have more than 32 monitors, send me a picture and make a donation ;)
	CGDirectDisplayID *display_ids = malloc(sizeof(CGDirectDisplayID) * UCHAR_MAX);
	if (display_ids != NULL) {
		// NOTE Pass UCHAR_MAX to make sure uint32_t doesn't overflow uint8_t.
		// TOOD Test/Check whether CGGetOnlineDisplayList is more suitable...
		status = CGGetActiveDisplayList(UCHAR_MAX, display_ids, (uint32_t *) count);

		// If there is no error and at least one monitor.
		if (status == kCGErrorSuccess && *count > 0) {
			logger(LOG_LEVEL_INFO,	"%s [%u]: CGGetActiveDisplayList: %li.\n",
					__FUNCTION__, __LINE__, *count);

			// Allocate memory for the number of screens found.
			screens = malloc(sizeof(screen_data) * (*count));
			if (screens != NULL) {
				for (uint8_t i = 0; i < *count; i++) {
					//size_t width = CGDisplayPixelsWide(display_ids[i]);
					//size_t height = CGDisplayPixelsHigh(display_ids[i]);
					CGRect boundsDisp = CGDisplayBounds(display_ids[i]);
					if (boundsDisp.size.width > 0 && boundsDisp.size.height > 0) {
						screens[i] = (screen_data) {
							.number = i + 1,
							//TODO: make sure we follow the same convention for the origin
							//in all other platform implementations (upper-left)
							//TODO: document the approach with examples in order to show different
							//cases -> different resolutions (secondary monitors origin might be
							//negative)
							.x = boundsDisp.origin.x,
							.y = boundsDisp.origin.y,
							.width = boundsDisp.size.width,
							.height = boundsDisp.size.height
						};
				}
				}
			}
		}
Exemplo n.º 25
0
/*
 * displayScreenBounds
 *  Return the bounds of a particular display.
 */
static CGRect
displayScreenBounds(CGDirectDisplayID id)
{
    CGRect frame;

    frame = CGDisplayBounds(id);

    /* Remove menubar to help standard X11 window managers. */

    if (frame.origin.x == 0 && frame.origin.y == 0)
    {
        frame.origin.y += aquaMenuBarHeight;
        frame.size.height -= aquaMenuBarHeight;
    }

    return frame;
}
Exemplo n.º 26
0
void
COSXScreen::postMouseEvent(CGPoint& pos) const
{
	// check if cursor position is valid on the client display configuration
	// [email protected]
	CGDisplayCount displayCount = 0;
	CGGetDisplaysWithPoint(pos, 0, NULL, &displayCount);
	if (displayCount == 0) {
		// cursor position invalid - clamp to bounds of last valid display.
		// find the last valid display using the last cursor position.
		displayCount = 0;
		CGDirectDisplayID displayID;
		CGGetDisplaysWithPoint(CGPointMake(m_xCursor, m_yCursor), 1,
								&displayID, &displayCount);
		if (displayCount != 0) {
			CGRect displayRect = CGDisplayBounds(displayID);
			if (pos.x < displayRect.origin.x) {
				pos.x = displayRect.origin.x;
			}
			else if (pos.x > displayRect.origin.x +
								displayRect.size.width - 1) {
				pos.x = displayRect.origin.x + displayRect.size.width - 1;
			}
			if (pos.y < displayRect.origin.y) {
				pos.y = displayRect.origin.y;
			}
			else if (pos.y > displayRect.origin.y +
								displayRect.size.height - 1) {
				pos.y = displayRect.origin.y + displayRect.size.height - 1;
			}
		}
	}
	
	CGEventType type = kCGEventMouseMoved;

	SInt8 button = m_buttonState.getFirstButtonDown();
	if (button != -1) {
		MouseButtonEventMapType thisButtonType = MouseButtonEventMap[button];
		type = thisButtonType[kMouseButtonDragged];
	}

	CGEventRef event = CGEventCreateMouseEvent(NULL, type, pos, button);
	CGEventPost(kCGHIDEventTap, event);
	
	CFRelease(event);
}
Exemplo n.º 27
0
Arquivo: gdi.c Projeto: AndreRH/wine
/***********************************************************************
 *              compute_desktop_rect
 */
static void compute_desktop_rect(void)
{
    CGDirectDisplayID displayIDs[32];
    uint32_t count, i;

    desktop_rect = CGRectNull;
    if (CGGetActiveDisplayList(sizeof(displayIDs)/sizeof(displayIDs[0]),
                               displayIDs, &count) != kCGErrorSuccess ||
        !count)
    {
        displayIDs[0] = CGMainDisplayID();
        count = 1;
    }

    for (i = 0; i < count; i++)
        desktop_rect = CGRectUnion(desktop_rect, CGDisplayBounds(displayIDs[i]));
    desktop_rect = cgrect_win_from_mac(desktop_rect);
}
Exemplo n.º 28
0
screen_info CreateDefaultScreenInfo(int DisplayIndex, int ScreenIndex)
{
    CGRect DisplayRect = CGDisplayBounds(DisplayIndex);
    screen_info Screen;

    Screen.ID = ScreenIndex;
    Screen.ForceContainerUpdate = false;
    Screen.ActiveSpace = -1;
    Screen.OldWindowListCount = -1;

    Screen.X = DisplayRect.origin.x;
    Screen.Y = DisplayRect.origin.y;
    Screen.Width = DisplayRect.size.width;
    Screen.Height = DisplayRect.size.height;

    Screen.Offset = DefaultContainerOffset;
    return Screen;
}
Exemplo n.º 29
0
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
{
#if wxMAC_USE_CORE_GRAPHICS
    CGRect cgbounds ;
    cgbounds = CGDisplayBounds(CGMainDisplayID());
    Rect bounds;
    bounds.top = (short)cgbounds.origin.y;
    bounds.left = (short)cgbounds.origin.x;
    bounds.bottom = bounds.top + (short)cgbounds.size.height;
    bounds.right = bounds.left  + (short)cgbounds.size.width;
    WindowAttributes overlayAttributes  = kWindowIgnoreClicksAttribute;
    CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
    ShowWindow((WindowRef)m_overlayWindow);
    SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
    m_width = (wxCoord)cgbounds.size.width;
    m_height = (wxCoord)cgbounds.size.height;
#else
    m_macPort = CreateNewPort() ;
    GrafPtr port ;
    GetPort( &port ) ;
    SetPort( (GrafPtr) m_macPort ) ;
    Point pt = { 0,0 } ;
    LocalToGlobal( &pt ) ;
    SetPort( port ) ;
    m_macLocalOrigin.x = -pt.h ;
    m_macLocalOrigin.y = -pt.v ;

    BitMap screenBits;
    GetQDGlobalsScreenBits( &screenBits );
    m_minX = screenBits.bounds.left ;

    SInt16 height ;
    GetThemeMenuBarHeight( &height ) ;
    m_minY = screenBits.bounds.top + height ;

    m_maxX = screenBits.bounds.right  ;
    m_maxY = screenBits.bounds.bottom ;

    MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
    OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
    CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
#endif
    m_ok = true ;
}
Exemplo n.º 30
0
void UpdateExistingScreenInfo(screen_info *Screen, int DisplayIndex, int ScreenIndex)
{
    CGRect DisplayRect = CGDisplayBounds(DisplayIndex);
    Screen->ID = ScreenIndex;

    Screen->X = DisplayRect.origin.x;
    Screen->Y = DisplayRect.origin.y;
    Screen->Width = DisplayRect.size.width;
    Screen->Height = DisplayRect.size.height;

    Screen->PaddingTop = DefaultPaddingTop;
    Screen->PaddingLeft = DefaultPaddingLeft;
    Screen->PaddingRight = DefaultPaddingRight;
    Screen->PaddingBottom = DefaultPaddingBottom;

    Screen->VerticalGap = DefaultGapVertical;
    Screen->HorizontalGap = DefaultGapHorizontal;
    Screen->ForceContainerUpdate = true;
}