Exemplo n.º 1
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.º 2
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.º 3
0
/*
 * xprAddPseudoramiXScreens
 *  Add a single virtual screen encompassing all the physical screens
 *  with PseudoramiX.
 */
static void
xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScreen)
{
    CGDisplayCount i, displayCount;
    CGDirectDisplayID *displayList = NULL;
    CGRect unionRect = CGRectNull, frame;

    // Find all the CoreGraphics displays
    CGGetActiveDisplayList(0, NULL, &displayCount);
    DEBUG_LOG("displayCount: %d\n", (int)displayCount);

    if(!displayCount) {
        ErrorF("CoreGraphics has reported no connected displays.  Creating a stub 800x600 display.\n");
        *x = *y = 0;
        *width = 800;
        *height = 600;
        PseudoramiXAddScreen(*x, *y, *width, *height);
        return;
    }

    displayList = malloc(displayCount * sizeof(CGDirectDisplayID));
    if(!displayList)
        FatalError("Unable to allocate memory for list of displays.\n");
    CGGetActiveDisplayList(displayCount, displayList, &displayCount);
    QuartzCopyDisplayIDs(pScreen, displayCount, displayList);

    /* Get the union of all screens */
    for (i = 0; i < displayCount; i++) {
        CGDirectDisplayID dpy = displayList[i];
        frame = displayScreenBounds(dpy);
        unionRect = CGRectUnion(unionRect, frame);
    }

    /* Use unionRect as the screen size for the X server. */
    *x = unionRect.origin.x;
    *y = unionRect.origin.y;
    *width = unionRect.size.width;
    *height = unionRect.size.height;

    DEBUG_LOG("  screen union origin: (%d,%d) size: (%d,%d).\n",
              *x, *y, *width, *height);

    /* Tell PseudoramiX about the real screens. */
    for (i = 0; i < displayCount; i++)
    {
        CGDirectDisplayID dpy = displayList[i];

        frame = displayScreenBounds(dpy);
        frame.origin.x -= unionRect.origin.x;
        frame.origin.y -= unionRect.origin.y;

        DEBUG_LOG("    placed at X11 coordinate (%d,%d).\n",
                  (int)frame.origin.x, (int)frame.origin.y);

        PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
                             frame.size.width, frame.size.height);
    }

    free(displayList);
}
Exemplo n.º 4
0
/* Initialize the array and size of the Active Displays */
void ScreenShooter::init_displays() {
    /* How many active displays do we have? */
    CGGetActiveDisplayList(0, NULL, (uint32_t*)&_dsp_count);
    
    /* Allocate enough memory to hold all the display IDs we have. */
    _displays = (CGDirectDisplayID*) calloc((size_t) _dsp_count, sizeof(CGDirectDisplayID));
    
    /* Get the list of active displays */
    CGGetActiveDisplayList(_dsp_count, _displays, &_dsp_count);
}
Exemplo n.º 5
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.º 6
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.º 7
0
/*
 * xprAddPseudoramiXScreens
 *  Add a single virtual screen encompassing all the physical screens
 *  with PseudoramiX.
 */
static void
xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
{
    CGDisplayCount i, displayCount;
    CGDirectDisplayID *displayList = NULL;
    CGRect unionRect = CGRectNull, frame;

    // Find all the CoreGraphics displays
    CGGetActiveDisplayList(0, NULL, &displayCount);
    displayList = xalloc(displayCount * sizeof(CGDirectDisplayID));
    CGGetActiveDisplayList(displayCount, displayList, &displayCount);

    /* Get the union of all screens */
    for (i = 0; i < displayCount; i++)
    {
        CGDirectDisplayID dpy = displayList[i];
        frame = displayScreenBounds(dpy);
        unionRect = CGRectUnion(unionRect, frame);
    }

    /* Use unionRect as the screen size for the X server. */
    *x = unionRect.origin.x;
    *y = unionRect.origin.y;
    *width = unionRect.size.width;
    *height = unionRect.size.height;

    /* Tell PseudoramiX about the real screens. */
    for (i = 0; i < displayCount; i++)
    {
        CGDirectDisplayID dpy = displayList[i];

        frame = displayScreenBounds(dpy);

        ErrorF("PseudoramiX screen %d added: %dx%d @ (%d,%d).\n", i,
               (int)frame.size.width, (int)frame.size.height,
               (int)frame.origin.x, (int)frame.origin.y);

        frame.origin.x -= unionRect.origin.x;
        frame.origin.y -= unionRect.origin.y;

        ErrorF("PseudoramiX screen %d placed at X11 coordinate (%d,%d).\n",
               i, (int)frame.origin.x, (int)frame.origin.y);

        PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
                             frame.size.width, frame.size.height);
    }

    xfree(displayList);
}
Exemplo n.º 8
0
void RefreshActiveDisplays(bool ShouldFocusScreen)
{
    if(KWMScreen.Displays)
        free(KWMScreen.Displays);

    KWMScreen.Displays = (CGDirectDisplayID*) malloc(sizeof(CGDirectDisplayID) * KWMScreen.MaxCount);
    CGGetActiveDisplayList(KWMScreen.MaxCount, KWMScreen.Displays, &KWMScreen.ActiveCount);
    for(std::size_t DisplayIndex = 0; DisplayIndex < KWMScreen.ActiveCount; ++DisplayIndex)
    {
        unsigned int DisplayID = KWMScreen.Displays[DisplayIndex];
        std::map<unsigned int, screen_info>::iterator It = KWMTiling.DisplayMap.find(DisplayID);

        if(It != KWMTiling.DisplayMap.end())
            UpdateExistingScreenInfo(&KWMTiling.DisplayMap[DisplayID], DisplayID, DisplayIndex);
        else
            KWMTiling.DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex << " and Identifier " << CFStringGetCStringPtr(KWMTiling.DisplayMap[DisplayID].Identifier,kCFStringEncodingUTF8));
    }

    if (ShouldFocusScreen)
    {
        screen_info *NewScreen = GetDisplayOfMousePointer();
        if(NewScreen)
            GiveFocusToScreen(NewScreen->ID, NULL, false, true);
    }
}
Exemplo n.º 9
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.º 10
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.º 11
0
static int Open(void * hwnd)
{
    CGLRendererInfoObj renderer;
    long numRenderer;
	CGDirectDisplayID l[32];
	CGDisplayCount count;

	SYS_ASSERT(g_pCGLC == 0);
	UNUSED(hwnd);
	CGGetActiveDisplayList (sizeof(l), l, &count);

#ifdef _DEBUG
	// Debug in multiple monitor. Use the secondary monitor for rendering
	g_cgDisplayID = l[count-1];
#else
	g_cgDisplayID = CGMainDisplayID ();
#endif

	g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID);
	g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID);

    CGLQueryRendererInfo(CGDisplayIDToOpenGLDisplayMask(g_cgDisplayID), &renderer, &numRenderer);
    CGLDestroyRendererInfo(renderer);

    return 0;
}
Exemplo n.º 12
0
/*
 * xprDisplayInit
 *  Find number of CoreGraphics displays and initialize Xplugin.
 */
static void
xprDisplayInit(void)
{
    CGDisplayCount displayCount;

    ErrorF("Display mode: Rootless Quartz -- Xplugin implementation\n");

    CGGetActiveDisplayList(0, NULL, &displayCount);

    /* With PseudoramiX, the X server only sees one screen; only PseudoramiX
       itself knows about all of the screens. */

    if (noPseudoramiXExtension)
        darwinScreensFound = displayCount;
    else
        darwinScreensFound =  1;

    if (xp_init(XP_IN_BACKGROUND) != Success)
    {
        FatalError("Could not initialize the Xplugin library.");
    }

    xp_select_events(XP_EVENT_DISPLAY_CHANGED
                     | XP_EVENT_WINDOW_STATE_CHANGED
                     | XP_EVENT_WINDOW_MOVED
                     | XP_EVENT_SURFACE_CHANGED
                     | XP_EVENT_SURFACE_DESTROYED,
                     eventHandler, NULL);

    AppleDRIExtensionInit();
    xprAppleWMInit();
}
Exemplo n.º 13
0
uint32 CGGetActiveDisplayCount_wrap(void* FH) {
  uint32 count;
  CGDisplayErr e = CGGetActiveDisplayList( 0, NULL, &count);
  return e != CGDisplayNoErr
    ? (uint32)reportOSError(e, "CGGetActiveDisplayCount", FH)
    : count;
}
Exemplo n.º 14
0
CGDirectDisplayID CGGetActiveDisplayAt_wrap(uint32 n, void* FH) {
  uint32 count;
  ResourceMark rm;
  CGDirectDisplayID *displays = NEW_RESOURCE_ARRAY(CGDirectDisplayID, n + 1);
  CGDisplayErr e =  CGGetActiveDisplayList( n + 1, displays, &count);
  return  e != CGDisplayNoErr  ?  (CGDirectDisplayID)reportOSError(e, "CGGetActiveDisplayAt", FH)
  :       count < n + 1        ?  (CGDirectDisplayID)(failure(FH, "not enough displays"), NULL)
  :                               displays[n];
}
Exemplo n.º 15
0
QuartzToggler::QuartzToggler() :
originalMode(NULL),
activeDspys(NULL),
widgetScreen(0),
isFull(false)
{
	CGDisplayCount dspyCnt = 0;
	CGGetActiveDisplayList(0, 0, &dspyCnt);

	activeDspys = new CGDirectDisplayID[dspyCnt];
	CGGetActiveDisplayList(dspyCnt, activeDspys, &dspyCnt);

	infoVector.resize(dspyCnt);
	fullResIndex.resize(dspyCnt);
	fullRateIndex.resize(dspyCnt);

	for (CGDisplayCount i = 0; i < dspyCnt; ++i) {
		CGDirectDisplayID display = activeDspys[i];
		CFDictionaryRef currentMode = CGDisplayCurrentMode(display);
		CFArrayRef modesArray = CGDisplayAvailableModes(display);
		CFIndex numModes = CFArrayGetCount(modesArray);
		CFNumberRef bpp = static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel));

		for (CFIndex j = 0; j < numModes; ++j) {
			CFDictionaryRef mode = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(modesArray, j));

			if (CFNumberCompare(bpp, static_cast<CFNumberRef>(CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel)), NULL) == kCFCompareEqualTo) {
				addMode(mode, infoVector[i], NULL, NULL);
			}
		}
	}

	originalMode = CGDisplayCurrentMode(activeDspys[widgetScreen]);

	for (CGDisplayCount i = 0; i < dspyCnt; ++i) {
		unsigned resIndex = 0;
		unsigned rateIndex = 0;
		addMode(CGDisplayCurrentMode(activeDspys[i]), infoVector[i], &resIndex, &rateIndex);
		fullResIndex[i] = resIndex;
		fullRateIndex[i] = rateIndex;
	}
}
/*
 * displayAtIndex
 *  Return the display ID for a particular display index.
 */
static CGDirectDisplayID
displayAtIndex(int index)
{
    CGError err;
    CGDisplayCount cnt;
    CGDirectDisplayID dpy[index+1];

    err = CGGetActiveDisplayList(index + 1, dpy, &cnt);
    if (err == kCGErrorSuccess && cnt == index + 1)
        return dpy[index];
    else
        return kCGNullDirectDisplay;
}
Exemplo n.º 17
0
void GetActiveDisplays()
{
    CGGetActiveDisplayList(MaxDisplayCount, (CGDirectDisplayID*)&ActiveDisplays, &ActiveDisplaysCount);
    for(int DisplayIndex = 0; DisplayIndex < ActiveDisplaysCount; ++DisplayIndex)
    {
        unsigned int DisplayID = ActiveDisplays[DisplayIndex];
        DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);;

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex)
    }

    Screen = GetDisplayOfMousePointer();
    CGDisplayRegisterReconfigurationCallback(DisplayReconfigurationCallBack, NULL);
}
Exemplo n.º 18
0
void GetActiveDisplays()
{
    KWMScreen.Displays = (CGDirectDisplayID*) malloc(sizeof(CGDirectDisplayID) * KWMScreen.MaxCount);
    CGGetActiveDisplayList(KWMScreen.MaxCount, KWMScreen.Displays, &KWMScreen.ActiveCount);
    for(int DisplayIndex = 0; DisplayIndex < KWMScreen.ActiveCount; ++DisplayIndex)
    {
        unsigned int DisplayID = KWMScreen.Displays[DisplayIndex];
        DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);;

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex)
    }

    KWMScreen.Current = GetDisplayOfMousePointer();
    CGDisplayRegisterReconfigurationCallback(DisplayReconfigurationCallBack, NULL);
}
Exemplo n.º 19
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.º 20
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.º 21
0
void RefreshActiveDisplays()
{
    CGGetActiveDisplayList(MaxDisplayCount, (CGDirectDisplayID*)&ActiveDisplays, &ActiveDisplaysCount);
    for(int DisplayIndex = 0; DisplayIndex < ActiveDisplaysCount; ++DisplayIndex)
    {
        unsigned int DisplayID = ActiveDisplays[DisplayIndex];
        std::map<unsigned int, screen_info>::iterator It;

        if(It != DisplayMap.end())
            UpdateExistingScreenInfo(&DisplayMap[DisplayID], DisplayID, DisplayIndex);
        else
            DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex)
    }

    Screen = GetDisplayOfMousePointer();
}
Exemplo n.º 22
0
void GetActiveDisplays()
{
    KWMScreen.Displays = (CGDirectDisplayID*) malloc(sizeof(CGDirectDisplayID) * KWMScreen.MaxCount);
    CGGetActiveDisplayList(KWMScreen.MaxCount, KWMScreen.Displays, &KWMScreen.ActiveCount);
    for(std::size_t DisplayIndex = 0; DisplayIndex < KWMScreen.ActiveCount; ++DisplayIndex)
    {
        unsigned int DisplayID = KWMScreen.Displays[DisplayIndex];
        KWMTiling.DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);;

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex << " and Identifier " << CFStringGetCStringPtr(KWMTiling.DisplayMap[DisplayID].Identifier,kCFStringEncodingUTF8));
    }

    KWMScreen.Current = GetDisplayOfMousePointer();
    KWMScreen.Current->ActiveSpace = GetActiveSpaceOfDisplay(KWMScreen.Current);
    ShouldActiveSpaceBeManaged();

    CGDisplayRegisterReconfigurationCallback(DisplayReconfigurationCallBack, NULL);
}
Exemplo n.º 23
0
//--------------------------------------------------------------
// global initialization called in main.m
void initFramework(
  const char* resourceDir)
{
  chdir(resourceDir);

  mgOSLaunchSendLog();
  
  // initialize random numbers
  time_t seed;
  time(&seed);
  srand(12123123); // srand(seed & 0xFFFF);
  
  mgDebugReset();         // reset trace file

  mgDebug(":Program: %s", mgProgramName != NULL ? mgProgramName : "unknown");
  mgDebug(":Program Version: %s", mgProgramVersion != NULL ? mgProgramVersion : "unknown");
  
  char machineID[256];
  getPlatformUUID(machineID, sizeof(machineID)-1);
  machineID[sizeof(machineID)-1] = '\0';
  mgDebug(":Machine Id: %s", machineID);
    
  struct utsname name;
  if (uname(&name) != -1)
  {
    mgDebug(":OS: %s", name.sysname);
    mgDebug(":Machine 64-bit: %s", strstr(name.machine, "_64") != NULL ? "true" : "false");
  }
  else mgDebug(":OS: OSX");

  const int MAX_DISPLAYS = 20;
  uint32_t displayCount;
  CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount);
  mgDebug(":Machine Monitor count: %d", displayCount);

  CGDirectDisplayID mainDisplay = CGMainDisplayID();
  mgDebug(":Machine Monitor res: %d by %d", CGDisplayPixelsWide(mainDisplay), CGDisplayPixelsHigh(mainDisplay));

  mgOSInitTimer();       // performance timer
  
  atexit(termFramework);
}
Exemplo n.º 24
0
void RefreshActiveDisplays()
{
    if(KWMScreen.Displays)
        free(KWMScreen.Displays);

    KWMScreen.Displays = (CGDirectDisplayID*) malloc(sizeof(CGDirectDisplayID) * KWMScreen.MaxCount);
    CGGetActiveDisplayList(KWMScreen.MaxCount, KWMScreen.Displays, &KWMScreen.ActiveCount);
    for(int DisplayIndex = 0; DisplayIndex < KWMScreen.ActiveCount; ++DisplayIndex)
    {
        unsigned int DisplayID = KWMScreen.Displays[DisplayIndex];
        std::map<unsigned int, screen_info>::iterator It = DisplayMap.find(DisplayID);

        if(It != DisplayMap.end())
            UpdateExistingScreenInfo(&DisplayMap[DisplayID], DisplayID, DisplayIndex);
        else
            DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex)
    }

    KWMScreen.Current = GetDisplayOfMousePointer();
}
Exemplo n.º 25
0
int
main(int argc, const char *argv[])
{
    CGDirectDisplayID display[kMaxDisplays];
    CGDisplayCount numDisplays;
    CGDisplayCount i;
    CGDisplayErr err;

    err = CGGetActiveDisplayList(kMaxDisplays,
                                 display,
                                 &numDisplays);
    if ( err != CGDisplayNoErr )
    {
        printf("Cannot get displays (%d)\n", err);
        exit( 1 );
    }
    printf( "%d displays found\n", (int)numDisplays );
    for ( i = 0; i < numDisplays; ++i )
    {
        modewhacker(display[i]);
    }
    exit(0);
}
/*
 * xprDisplayInit
 *  Find number of CoreGraphics displays and initialize Xplugin.
 */
static void
xprDisplayInit(void)
{
    CGDisplayCount displayCount;

    DEBUG_LOG("");

    CGGetActiveDisplayList(0, NULL, &displayCount);

    /* With PseudoramiX, the X server only sees one screen; only PseudoramiX
       itself knows about all of the screens. */

    if (noPseudoramiXExtension)
        darwinScreensFound = displayCount;
    else
        darwinScreensFound =  1;

    if (xp_init(XP_BACKGROUND_EVENTS | XP_NO_DEFERRED_UPDATES) != Success)
        FatalError("Could not initialize the Xplugin library.");

    xp_select_events(XP_EVENT_DISPLAY_CHANGED
                     | XP_EVENT_WINDOW_STATE_CHANGED
                     | XP_EVENT_WINDOW_MOVED
#ifdef XP_EVENT_SPACE_CHANGED
                     | XP_EVENT_SPACE_CHANGED
#endif
                     | XP_EVENT_SURFACE_CHANGED
                     | XP_EVENT_SURFACE_DESTROYED,
                     eventHandler, NULL);

    AppleDRIExtensionInit();
    xprAppleWMInit();

    XQuartzIsRootless = XQuartzRootlessDefault;
    if (!XQuartzIsRootless)
        RootlessHideAllWindows();
}
Exemplo n.º 27
0
void RefreshActiveDisplays()
{
    CGGetActiveDisplayList(MaxDisplayCount, (CGDirectDisplayID*)&ActiveDisplays, &ActiveDisplaysCount);
    for(int DisplayIndex = 0; DisplayIndex < ActiveDisplaysCount; ++DisplayIndex)
    {
        unsigned int DisplayID = ActiveDisplays[DisplayIndex];
        std::map<unsigned int, screen_info>::iterator It;
        if(It != DisplayMap.end())
        {
            CGRect DisplayRect = CGDisplayBounds(ActiveDisplays[DisplayIndex]);
            DisplayMap[DisplayID].ID = DisplayIndex;

            DisplayMap[DisplayID].X = DisplayRect.origin.x;
            DisplayMap[DisplayID].Y = DisplayRect.origin.y;
            DisplayMap[DisplayID].Width = DisplayRect.size.width;
            DisplayMap[DisplayID].Height = DisplayRect.size.height;

            DisplayMap[DisplayID].PaddingTop = DefaultPaddingTop;
            DisplayMap[DisplayID].PaddingLeft = DefaultPaddingLeft;
            DisplayMap[DisplayID].PaddingRight = DefaultPaddingRight;
            DisplayMap[DisplayID].PaddingBottom = DefaultPaddingBottom;

            DisplayMap[DisplayID].VerticalGap = DefaultGapVertical;
            DisplayMap[DisplayID].HorizontalGap = DefaultGapHorizontal;
            DisplayMap[DisplayID].ForceContainerUpdate = true;
        }
        else
        {
            DisplayMap[DisplayID] = CreateDefaultScreenInfo(DisplayID, DisplayIndex);
        }

        DEBUG("DisplayID " << DisplayID << " has index " << DisplayIndex)
    }

    Screen = GetDisplayOfMousePointer();
}
Exemplo n.º 28
0
static int Open(void * hwnd)
{

	CGDirectDisplayID l[32];
	CGDisplayCount count;
	CGGetActiveDisplayList (sizeof(l), l, &count);

	SYS_ASSERT(g_pAGLC == 0);
	SYS_ASSERT(hwnd);
	static Rect rect;
	g_pRect = &rect;
	g_hWnd = (WindowPtr) hwnd;
#ifdef _DEBUG
	// Debug in multiple monitor. Use the secondary monitor for rendering
	g_cgDisplayID = l[count-1];
#else
	g_cgDisplayID = CGMainDisplayID ();
#endif

	g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID);
	g_cgOldDisplayModeRestore = 0;
	g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID);
    return 0;
}
Exemplo n.º 29
0
int main(int argc, const char *argv[]) {
    // http://developer.apple.com/library/IOs/#documentation/CoreFoundation/Conceptual/CFStrings/Articles/MutableStrings.html
    int i;
    CFMutableStringRef args = CFStringCreateMutable(NULL, 0);
    CFStringEncoding encoding = CFStringGetSystemEncoding();
    CFStringAppend(args, CFSTR("starting screenresolution argv="));
    for (i = 0 ; i < argc ; i++) {
        CFStringAppendCString(args, argv[i], encoding);
        // If I were so motivated, I'd probably use CFStringAppendFormat
        CFStringAppend(args, CFSTR(" "));
    }
    // This has security implications.  Will look at that later
    NSLog(CFSTR("%@"), args);
    unsigned int exitcode = 0;

    if (argc > 1) {
        int d;
        int keepgoing = 1;
        CGError rc;
        uint32_t displayCount = 0;
        uint32_t activeDisplayCount = 0;
        CGDirectDisplayID *activeDisplays = NULL;

        rc = CGGetActiveDisplayList(0, NULL, &activeDisplayCount);
        if (rc != kCGErrorSuccess) {
            NSLog(CFSTR("%s"), "Error: failed to get list of active displays");
            return 1;
        }
        // Allocate storage for the next CGGetActiveDisplayList call
        activeDisplays = (CGDirectDisplayID *) malloc(activeDisplayCount * sizeof(CGDirectDisplayID));
        if (activeDisplays == NULL) {
            NSLog(CFSTR("s"), "Error: could not allocate memory for display list");
            return 1;
        }
        rc = CGGetActiveDisplayList(activeDisplayCount, activeDisplays, &displayCount);
        if (rc != kCGErrorSuccess) {
            NSLog(CFSTR("%s"), "Error: failed to get list of active displays");
            return 1;
        }

        // This loop should probably be in another function.
        for (d = 0; d < displayCount && keepgoing; d++) {
            if (strcmp(argv[1], "get") == 0) {
                if (!listCurrentMode(activeDisplays[d], d)) {
                    exitcode++;
                }
            } else if (strcmp(argv[1], "list") == 0) {
                if (!listAvailableModes(activeDisplays[d], d)) {
                    exitcode++;
                }
            } else if (strcmp(argv[1], "set") == 0) {
                if (d < (argc - 2)) {
                    if (strcmp(argv[d+2], "skip") == 0 && d < (argc - 2)) {
                        printf("Skipping display %d\n", d);
                    } else {
                        struct config newConfig;
                        if (parseStringConfig(argv[d + 2], &newConfig)) {
                            if (!configureDisplay(activeDisplays[d], &newConfig, d)) {
                                exitcode++;
                            }
                        } else {
                            exitcode++;
                        }
                    }
                }
            } else if (strcmp(argv[1], "-version") == 0) {
                printf("screenresolution version %s\nLicensed under GPLv2\n", VERSION);
                keepgoing = 0;
            } else {
                NSLog(CFSTR("I'm sorry %s. I'm afraid I can't do that"), getlogin());
                exitcode++;
                keepgoing = 0;
            }
        }
        free(activeDisplays);
        activeDisplays = NULL;
    } else {
        NSLog(CFSTR("%s"), "Incorrect command line");
        exitcode++;
    }
    return exitcode > 0;
}
Exemplo n.º 30
0
bool DisplayManagerOSX::initialize()
{
  int totalModes = 0;

  m_displays.clear();

  for (int i = 0; i < m_osxDisplayModes.size(); i++)
  {
    if (m_osxDisplayModes[i])
      CFRelease(m_osxDisplayModes[i]);
  }
  m_osxDisplayModes.clear();

  CGError err = CGGetActiveDisplayList(MAX_DISPLAYS, m_osxDisplays, &m_osxnumDisplays);
  if (err)
  {
    m_osxnumDisplays = 0;
    QLOG_ERROR() << "CGGetActiveDisplayList returned failure:" << err;
    return false;
  }

  for (int displayid = 0; displayid < m_osxnumDisplays; displayid++)
  {
    // add the display to the list
    DMDisplayPtr display = DMDisplayPtr(new DMDisplay);
    display->m_id = displayid;
    display->m_name = QString("Display %1").arg(displayid);
    m_displays[display->m_id] = display;

    m_osxDisplayModes[displayid] = CGDisplayCopyAllDisplayModes(m_osxDisplays[displayid], nullptr);
    if (!m_osxDisplayModes[displayid])
      continue;

    int numModes = (int)CFArrayGetCount(m_osxDisplayModes[displayid]);

    for (int modeid = 0; modeid < numModes; modeid++)
    {
      totalModes++;
      
      // add the videomode to the display
      DMVideoModePtr mode = DMVideoModePtr(new DMVideoMode);
      mode->m_id = modeid;
      display->m_videoModes[modeid] = mode;

      // grab videomode info
      CGDisplayModeRef displayMode =
      (CGDisplayModeRef)CFArrayGetValueAtIndex(m_osxDisplayModes[displayid], modeid);

      mode->m_height = CGDisplayModeGetHeight(displayMode);
      mode->m_width = CGDisplayModeGetWidth(displayMode);
      mode->m_refreshRate = CGDisplayModeGetRefreshRate(displayMode);

      CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(displayMode);

      if (CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
        mode->m_bitsPerPixel = 32;
      else if (CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
        mode->m_bitsPerPixel = 16;
      else if (CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
        mode->m_bitsPerPixel = 8;

      CFRelease(pixEnc);

      mode->m_interlaced = (CGDisplayModeGetIOFlags(displayMode) & kDisplayModeInterlacedFlag) > 0;

      if (mode->m_refreshRate == 0)
        mode->m_refreshRate = 60;
    }
  }

  if (totalModes == 0)
    return false;
  else
    return DisplayManager::initialize();
}