XQuartz: RandR: Toggle rootless mode on XRandR mode switch.

Report a fake screen mode that corresponds to the screen mode at startup of the
server excluding the height of the menu bar. If a client requests this mode,
rootless mode is enabled. In all other modes, the root window is shown.

Signed-off-by: Jan Hauffa <hauffa@in.tum.de>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jan Hauffa 2010-07-16 17:54:55 +02:00 committed by Jeremy Huddleston
parent 2d411472c2
commit 97b5f53064
2 changed files with 73 additions and 29 deletions

View File

@ -38,6 +38,12 @@
#include <X11/Xdefs.h> #include <X11/Xdefs.h>
#include "privates.h" #include "privates.h"
typedef struct {
size_t width, height;
int refresh;
const void *ref;
} QuartzModeInfo, *QuartzModeInfoPtr;
// Quartz specific per screen storage structure // Quartz specific per screen storage structure
typedef struct { typedef struct {
// List of CoreGraphics displays that this X11 screen covers. // List of CoreGraphics displays that this X11 screen covers.
@ -46,6 +52,7 @@ typedef struct {
// No CG display will be covered by more than one X11 screen. // No CG display will be covered by more than one X11 screen.
int displayCount; int displayCount;
CGDirectDisplayID *displayIDs; CGDirectDisplayID *displayIDs;
QuartzModeInfo originalMode, fakeMode;
} QuartzScreenRec, *QuartzScreenPtr; } QuartzScreenRec, *QuartzScreenPtr;
#define QUARTZ_PRIV(pScreen) \ #define QUARTZ_PRIV(pScreen) \

View File

@ -37,6 +37,7 @@
#include "quartzCommon.h" #include "quartzCommon.h"
#include "quartzRandR.h" #include "quartzRandR.h"
#include "quartz.h"
#if defined(FAKE_RANDR) #if defined(FAKE_RANDR)
#include "scrnintstr.h" #include "scrnintstr.h"
@ -96,12 +97,6 @@ RREditConnectionInfo (ScreenPtr pScreen)
#define DEFAULT_REFRESH 60 #define DEFAULT_REFRESH 60
#define kDisplayModeUsableFlags (kDisplayModeValidFlag | kDisplayModeSafeFlag) #define kDisplayModeUsableFlags (kDisplayModeValidFlag | kDisplayModeSafeFlag)
typedef struct {
size_t width, height;
int refresh;
const void *ref;
} QuartzModeInfo, *QuartzModeInfoPtr;
typedef Bool (*QuartzModeCallback) typedef Bool (*QuartzModeCallback)
(ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *); (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
@ -289,21 +284,30 @@ static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
return TRUE; return TRUE;
} }
static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
QuartzModeInfoPtr pMode,
Bool isCurrentMode) {
RRScreenSizePtr pSize = RRRegisterSize(pScreen,
pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
if (pSize) {
RRRegisterRate(pScreen, pSize, pMode->refresh);
if (isCurrentMode)
RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pSize);
return TRUE;
}
return FALSE;
}
static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen, static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
CGDirectDisplayID screenId, CGDirectDisplayID screenId,
QuartzModeInfoPtr pMode, QuartzModeInfoPtr pMode,
void *data) { void *data) {
QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data; QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
RRScreenSizePtr pSize = RRRegisterSize(pScreen, return QuartzRandRRegisterMode(pScreen, pMode,
pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight); QuartzRandRModesEqual(pMode, pCurMode));
if (pSize) {
RRRegisterRate(pScreen, pSize, pMode->refresh);
if (QuartzRandRModesEqual(pMode, pCurMode))
RRSetCurrentConfig(pScreen, RR_Rotate_0, pMode->refresh, pSize);
}
return TRUE;
} }
static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen, static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
@ -329,20 +333,29 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
return FALSE; return FALSE;
if (pQuartzScreen->displayCount > 1) { if (pQuartzScreen->displayCount > 1) {
/* RandR operations are not well-defined for an X11 screen spanning /* RandR operations are not well-defined for an X11 screen spanning
multiple CG displays. Create a single entry for the current virtual multiple CG displays. Create two entries for the current virtual
resolution. */ resolution including/excluding the menu bar. */
RRScreenSizePtr pSize = RRRegisterSize(pScreen, pScreen->width, QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode,
pScreen->height, pScreen->mmWidth, pScreen->mmHeight); !quartzHasRoot);
if (pSize) { QuartzRandRRegisterMode(pScreen, &pQuartzScreen->originalMode,
RRRegisterRate(pScreen, pSize, DEFAULT_REFRESH); quartzHasRoot);
RRSetCurrentConfig(pScreen, RR_Rotate_0, DEFAULT_REFRESH, pSize);
}
return TRUE; return TRUE;
} }
screenId = pQuartzScreen->displayIDs[0]; screenId = pQuartzScreen->displayIDs[0];
if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode)) if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
return FALSE; return FALSE;
/* Add a fake mode corresponding to the original resolution excluding the
height of the menu bar. */
if (!quartzHasRoot &&
QuartzRandRModesEqual(&pQuartzScreen->originalMode, &curMode)) {
QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, TRUE);
curMode = pQuartzScreen->fakeMode;
}
else
QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, FALSE);
return QuartzRandREnumerateModes(pScreen, screenId, return QuartzRandREnumerateModes(pScreen, screenId,
QuartzRandRGetModeCallback, &curMode); QuartzRandRGetModeCallback, &curMode);
} }
@ -354,6 +367,21 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen,
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
CGDirectDisplayID screenId; CGDirectDisplayID screenId;
QuartzModeInfo reqMode, curMode; QuartzModeInfo reqMode, curMode;
Bool rootless = FALSE;
reqMode.width = pSize->width;
reqMode.height = pSize->height;
reqMode.refresh = rate;
/* If the client requested the fake screen mode, switch to rootless mode.
Switch to fullscreen mode (root window visible) if a real screen mode was
requested. */
if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->fakeMode)) {
rootless = TRUE;
reqMode = pQuartzScreen->originalMode;
}
QuartzSetFullscreen(!rootless);
QuartzSetRootless(rootless);
if (pQuartzScreen->displayCount == 0) if (pQuartzScreen->displayCount == 0)
return FALSE; return FALSE;
@ -361,15 +389,10 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen,
/* RandR operations are not well-defined for an X11 screen spanning /* RandR operations are not well-defined for an X11 screen spanning
multiple CG displays. Do not accept any configuations that differ multiple CG displays. Do not accept any configuations that differ
from the current configuration. */ from the current configuration. */
return ((pSize->width == pScreen->width) && return QuartzRandRModesEqual(&reqMode, &pQuartzScreen->originalMode);
(pSize->height == pScreen->height));
} }
screenId = pQuartzScreen->displayIDs[0]; screenId = pQuartzScreen->displayIDs[0];
reqMode.width = pSize->width;
reqMode.height = pSize->height;
reqMode.refresh = rate;
/* Do not switch modes if requested mode is equal to current mode. */ /* Do not switch modes if requested mode is equal to current mode. */
if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode)) if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
return FALSE; return FALSE;
@ -382,9 +405,23 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen,
Bool QuartzRandRInit (ScreenPtr pScreen) { Bool QuartzRandRInit (ScreenPtr pScreen) {
rrScrPrivPtr pScrPriv; rrScrPrivPtr pScrPriv;
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
if (!RRScreenInit (pScreen)) return FALSE; if (!RRScreenInit (pScreen)) return FALSE;
if (pQuartzScreen->displayCount == 1) {
if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
&pQuartzScreen->originalMode))
return FALSE;
}
else {
pQuartzScreen->originalMode.width = pScreen->width;
pQuartzScreen->originalMode.height = pScreen->height;
pQuartzScreen->originalMode.refresh = DEFAULT_REFRESH;
}
pQuartzScreen->fakeMode = pQuartzScreen->originalMode;
pQuartzScreen->fakeMode.height -= aquaMenuBarHeight;
pScrPriv = rrGetScrPriv(pScreen); pScrPriv = rrGetScrPriv(pScreen);
pScrPriv->rrGetInfo = QuartzRandRGetInfo; pScrPriv->rrGetInfo = QuartzRandRGetInfo;
pScrPriv->rrSetConfig = QuartzRandRSetConfig; pScrPriv->rrSetConfig = QuartzRandRSetConfig;