aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-20 21:42:23 +0100
committerSven Gothel <[email protected]>2015-03-20 21:42:23 +0100
commit2c88b6dfd4eb7e2cd9a50fa48e08ecafc980931a (patch)
tree2d89ec775fdd59499a934d622462b8915b89cead /src/newt/native
parentd9fe5c4aee7547bb89571c19c89ad173b63a4598 (diff)
Bug 1147 - Fix XRandR13 Usage: Rotate / Change-Mode, use unique CRTC/Mode ids, ..
RandR 1.3 XRRSetCrtcConfig related: - X11RandR13 now sets the new screen size via XRRSetScreenSize(..) - X11RandR13 now propagates RRScreenChangeNotify events via XRRUpdateConfiguration(event). Hence reporting virtual desktop size now. - X11RandR13 now disables the CRTC before XRRSetCrtcConfig(..) to avoid invalid configuration (see spec)! RandR 1.3 General: - Uses unique id named instead of unstable index for modes and CRTC. This allows proper identification even for 'swizzled' devices.
Diffstat (limited to 'src/newt/native')
-rw-r--r--src/newt/native/X11Display.c22
-rw-r--r--src/newt/native/X11RandR11.c89
-rw-r--r--src/newt/native/X11RandR13.c275
-rw-r--r--src/newt/native/X11Screen.c6
-rw-r--r--src/newt/native/X11Screen.h4
-rw-r--r--src/newt/native/X11Window.c6
-rw-r--r--src/newt/native/xrandr_utils.c322
7 files changed, 591 insertions, 133 deletions
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index 60daf1af2..b79c1ee95 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -39,6 +39,7 @@ jmethodID visibleChangedID = NULL;
static const char * const ClazzNameX11NewtWindow = "jogamp/newt/driver/x11/WindowDriver";
static jmethodID displayCompletedID = NULL;
+static jmethodID sendRRScreenChangeNotifyID = NULL;
static jmethodID getCurrentThreadNameID = NULL;
static jmethodID dumpStackID = NULL;
@@ -242,8 +243,9 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_initIDs0
}
}
- // displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJJ)V"); // Variant using XKB
- displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJ)V");
+ // displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJJII)V"); // Variant using XKB
+ displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJII)V");
+ sendRRScreenChangeNotifyID = (*env)->GetMethodID(env, clazz, "sendRRScreenChangeNotify", "(J)V");
getCurrentThreadNameID = (*env)->GetStaticMethodID(env, X11NewtWindowClazz, "getCurrentThreadName", "()Ljava/lang/String;");
dumpStackID = (*env)->GetStaticMethodID(env, X11NewtWindowClazz, "dumpStack", "()V");
insetsChangedID = (*env)->GetMethodID(env, X11NewtWindowClazz, "insetsChanged", "(ZIIII)V");
@@ -259,6 +261,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_initIDs0
requestFocusID = (*env)->GetMethodID(env, X11NewtWindowClazz, "requestFocus", "(Z)V");
if (displayCompletedID == NULL ||
+ sendRRScreenChangeNotifyID == NULL ||
getCurrentThreadNameID == NULL ||
dumpStackID == NULL ||
insetsChangedID == NULL ||
@@ -311,9 +314,13 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_CompleteDisplay
// XSetCloseDownMode(dpy, RetainTemporary); // Just a try ..
// kbdHandle = (jlong) (intptr_t) XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd); // XKB disabled for now
+ int randr_event_base, randr_error_base;
+ XRRQueryExtension(dpy, &randr_event_base, &randr_error_base);
+
DBG_PRINT("X11: X11Display_completeDisplay dpy %p\n", dpy);
- (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom /*, kbdHandle*/); // XKB disabled for now
+ (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom /*, kbdHandle*/, // XKB disabled for now
+ randr_event_base, randr_error_base);
}
/*
@@ -349,7 +356,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DisplayRelease0
* Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0
- (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/)
+ (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/,
+ jint randr_event_base, jint randr_error_base)
{
Display * dpy = (Display *) (intptr_t) display;
Atom wm_delete_atom = (Atom)windowDeleteAtom;
@@ -397,6 +405,12 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
return ;
}
+ if( randr_event_base > 0 && RRScreenChangeNotify == ( evt.type - randr_event_base ) ) {
+ DBG_PRINT( "X11: DispatchMessages dpy %p, Event RRScreenChangeNotify %p\n", (void*)dpy, (void*)&evt);
+ (*env)->CallVoidMethod(env, obj, sendRRScreenChangeNotifyID, (jlong)(intptr_t)&evt);
+ continue;
+ }
+
if( 0==evt.xany.window ) {
DBG_PRINT( "X11: DispatchMessages dpy %p, Event %d - Window NULL, ignoring\n", (void*)dpy, (int)evt.type);
continue;
diff --git a/src/newt/native/X11RandR11.c b/src/newt/native/X11RandR11.c
index 38d61289b..8d2651d61 100644
--- a/src/newt/native/X11RandR11.c
+++ b/src/newt/native/X11RandR11.c
@@ -297,75 +297,56 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR11_setCurrentScreenM
DBG_PRINT("X11Screen.setCurrentScreenMode0: CHANGED TO %d: %d x %d PIXELS, %d Hz, %d degree\n",
resMode_idx, xrrs[resMode_idx].width, xrrs[resMode_idx].height, (int)freq, rotation);
- int xrot = NewtScreen_Degree2XRotation(env, rotation);
-
XRRSelectInput (dpy, root, RRScreenChangeNotifyMask);
-
- XSync(dpy, False);
+ Rotation xrot = NewtScreen_Degree2XRotation(env, rotation);
XRRSetScreenConfigAndRate(dpy, conf, root, (int)resMode_idx, xrot, (short)freq, CurrentTime);
- XSync(dpy, False);
-
return JNI_TRUE;
}
/*
* Class: jogamp_newt_driver_x11_RandR11
- * Method: setCurrentScreenModePollEnd0
- * Signature: (JIII)Z
+ * Method: sendRRScreenChangeNotify0
+ * Signature: (JIJIII)Z
*/
-JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR11_setCurrentScreenModePollEnd0
- (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jint resMode_idx, jint freq, jint rotation)
+JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR11_sendRRScreenChangeNotify0
+ (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong jevent, jint resMode_idx, jint freq, jint rotation)
{
- Display *dpy = (Display *) (intptr_t) display;
- int randr_event_base, randr_error_base;
- XEvent evt;
- XRRScreenChangeNotifyEvent * scn_event = (XRRScreenChangeNotifyEvent *) &evt;
-
+ Display * dpy = (Display *) (intptr_t) display;
+ XEvent *event = (XEvent*)(intptr_t)jevent;
+ XRRUpdateConfiguration(event);
+ DBG_PRINT("RandR11_sendRRScreenChangeNotify0: dpy %p, event %p\n", dpy, event);
+ if( -1 == resMode_idx || -1 == screen_idx ) {
+ // No validation requested
+ return JNI_FALSE;
+ }
+ // Validate numbers ..
+ XRRScreenChangeNotifyEvent * scn_event = (XRRScreenChangeNotifyEvent *) event;
int num_sizes;
XRRScreenSize *xrrs = XRRSizes(dpy, (int)screen_idx, &num_sizes); //get possible screen resolutions
- XRRScreenConfiguration *conf;
-
if( 0 > resMode_idx || resMode_idx >= num_sizes ) {
NewtCommon_throwNewRuntimeException(env, "Invalid resolution index: ! 0 < %d < %d", resMode_idx, num_sizes);
}
- XRRQueryExtension(dpy, &randr_event_base, &randr_error_base);
-
- int done = 0;
- int rot;
- do {
- if ( 0 >= XEventsQueued(dpy, QueuedAfterFlush) ) {
- return JNI_FALSE; // not done
+ jboolean done = JNI_FALSE;
+ if(0 < scn_event->rotation ) { // All valid values greater zero: 0, 90, 180, 270, ..
+ int rot = NewtScreen_XRotation2Degree(env, scn_event->rotation);
+ DBG_PRINT( "XRANDR: event . RRScreenChangeNotify call(OK) %p (root %p) resIdx %d rot %d %dx%d\n",
+ (void*)scn_event->window, (void*)scn_event->root,
+ (int)scn_event->size_index, rot,
+ scn_event->width, scn_event->height);
+ // done = scn_event->size_index == resMode_idx; // not reliable ..
+ if( rot == rotation &&
+ scn_event->width == xrrs[resMode_idx].width &&
+ scn_event->height == xrrs[resMode_idx].height ) {
+ done = JNI_TRUE;
}
- XNextEvent(dpy, &evt);
-
- switch (evt.type - randr_event_base) {
- case RRScreenChangeNotify:
- if(0 < scn_event->rotation ) {
- rot = NewtScreen_XRotation2Degree(env, (int)scn_event->rotation);
- DBG_PRINT( "XRANDR: event . RRScreenChangeNotify call(1) %p (root %p) resIdx %d rot %d %dx%d\n",
- (void*)scn_event->window, (void*)scn_event->root,
- (int)scn_event->size_index, rot,
- scn_event->width, scn_event->height);
- // done = scn_event->size_index == resMode_idx; // not reliable ..
- done = rot == rotation &&
- scn_event->width == xrrs[resMode_idx].width &&
- scn_event->height == xrrs[resMode_idx].height;
- } else {
- DBG_PRINT( "XRANDR: event . RRScreenChangeNotify call(0) %p (root %p) resIdx %d %dx%d\n",
- (void*)scn_event->window, (void*)scn_event->root,
- (int)scn_event->size_index,
- scn_event->width, scn_event->height);
- }
- break;
- default:
- DBG_PRINT("RANDR: event . unhandled %d 0x%X call %p\n", (int)evt.type, (int)evt.type, (void*)evt.xany.window);
- }
- XRRUpdateConfiguration(&evt);
- } while(!done);
-
- XSync(dpy, False);
-
- return done ? JNI_TRUE : JNI_FALSE;
+ } else { // invalid .. skip
+ DBG_PRINT( "XRANDR: event . RRScreenChangeNotify call(SKIP) %p (root %p) resIdx %d %dx%d\n",
+ (void*)scn_event->window, (void*)scn_event->root,
+ (int)scn_event->size_index,
+ scn_event->width, scn_event->height);
+ }
+ return done;
}
+
diff --git a/src/newt/native/X11RandR13.c b/src/newt/native/X11RandR13.c
index 4f52ad190..37a6ea055 100644
--- a/src/newt/native/X11RandR13.c
+++ b/src/newt/native/X11RandR13.c
@@ -61,33 +61,35 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_freeScreenResources0
#define SAFE_STRING(s) (NULL==s?"":s)
-static void dumpOutputs(const char *prefix, Display *dpy, int screen_idx, XRRScreenResources *resources, int noutput, RROutput * outputs) {
+static void dumpOutput(const char *prefix, Display *dpy, int screen_idx, XRRScreenResources *resources, int outputIdx, RROutput output) {
int i, j, primIdx=0;
Window root = RootWindow(dpy, screen_idx);
RROutput pxid = XRRGetOutputPrimary (dpy, root);
- fprintf(stderr, "%s %p: Output[count %d, prim %#lx]\n", prefix, resources, noutput, pxid);
+ int isPrim =0;
+ if ( None != pxid && pxid == output ) {
+ primIdx = i;
+ isPrim = 1;
+ }
+ XRROutputInfo * xrrOutputInfo = XRRGetOutputInfo (dpy, resources, output);
+ fprintf(stderr, "%s: Output[%d]: id %#lx, crtx 0x%lX, name %s (%d), %lux%lu, ncrtc %d, nclone %d, nmode %d (preferred %d), primary %d\n",
+ prefix, outputIdx, output, xrrOutputInfo->crtc, SAFE_STRING(xrrOutputInfo->name), xrrOutputInfo->nameLen,
+ xrrOutputInfo->mm_width, xrrOutputInfo->mm_height,
+ xrrOutputInfo->ncrtc, xrrOutputInfo->nclone, xrrOutputInfo->nmode, xrrOutputInfo->npreferred, isPrim);
+ for(j=0; j<xrrOutputInfo->ncrtc; j++) {
+ fprintf(stderr, "%s: Output[%d].Crtc[%d].id %#lx\n", prefix, i, j, xrrOutputInfo->crtcs[j]);
+ }
+ for(j=0; j<xrrOutputInfo->nclone; j++) {
+ fprintf(stderr, "%s: Output[%d].Clones[%d].id %#lx\n", prefix, i, j, xrrOutputInfo->clones[j]);
+ }
+ for(j=0; j<xrrOutputInfo->nmode; j++) {
+ fprintf(stderr, "%s: Output[%d].Mode[%d].id %#lx\n", prefix, i, j, xrrOutputInfo->modes[j]);
+ }
+ XRRFreeOutputInfo (xrrOutputInfo);
+}
+static void dumpOutputs(const char *prefix, Display *dpy, int screen_idx, XRRScreenResources *resources, int noutput, RROutput * outputs) {
+ int i;
for(i=0; i<noutput; i++) {
- int isPrim =0;
- RROutput output = outputs[i];
- if ( None != pxid && pxid == output ) {
- primIdx = i;
- isPrim = 1;
- }
- XRROutputInfo * xrrOutputInfo = XRRGetOutputInfo (dpy, resources, output);
- fprintf(stderr, " Output[%d]: id %#lx, crtx 0x%lX, name %s (%d), %lux%lu, ncrtc %d, nclone %d, nmode %d (preferred %d), primary %d\n",
- i, output, xrrOutputInfo->crtc, SAFE_STRING(xrrOutputInfo->name), xrrOutputInfo->nameLen,
- xrrOutputInfo->mm_width, xrrOutputInfo->mm_height,
- xrrOutputInfo->ncrtc, xrrOutputInfo->nclone, xrrOutputInfo->nmode, xrrOutputInfo->npreferred, isPrim);
- for(j=0; j<xrrOutputInfo->ncrtc; j++) {
- fprintf(stderr, " Output[%d].Crtc[%d].id %#lx\n", i, j, xrrOutputInfo->crtcs[j]);
- }
- for(j=0; j<xrrOutputInfo->nclone; j++) {
- fprintf(stderr, " Output[%d].Clones[%d].id %#lx\n", i, j, xrrOutputInfo->clones[j]);
- }
- for(j=0; j<xrrOutputInfo->nmode; j++) {
- fprintf(stderr, " Output[%d].Mode[%d].id %#lx\n", i, j, xrrOutputInfo->modes[j]);
- }
- XRRFreeOutputInfo (xrrOutputInfo);
+ dumpOutput(prefix, dpy, screen_idx, resources, i, outputs[i]);
}
}
@@ -116,7 +118,39 @@ static float getVRefresh(XRRModeInfo *mode) {
}
return rate;
}
+static RRCrtc findRRCrtc(XRRScreenResources *resources, RRCrtc crtc) {
+ if( NULL != resources ) {
+ int i;
+ for(i=resources->ncrtc-1; i>=0; i--) {
+ if( resources->crtcs[i] == crtc ) {
+ return crtc;
+ }
+ }
+ }
+ return 0;
+}
+static XRRCrtcInfo* getXRRCrtcInfo(Display *dpy, XRRScreenResources *resources, RRCrtc _crtc) {
+ RRCrtc crtc = findRRCrtc( resources, _crtc );
+ if( 0 == crtc ) {
+ return NULL;
+ } else {
+ return XRRGetCrtcInfo (dpy, resources, crtc);
+ }
+}
+static XRRModeInfo* findMode(XRRScreenResources *resources, RRMode modeId) {
+ if( NULL != resources ) {
+ int i;
+ for(i=resources->nmode-1; i>=0; i--) {
+ XRRModeInfo *imode = &resources->modes[i];
+ if( imode->id == modeId ) {
+ return imode;
+ }
+ }
+ }
+ return NULL;
+}
+#include "xrandr_utils.c"
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_dumpInfo0
(JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources)
@@ -144,10 +178,11 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_dumpInfo0
for(i=0; i<resources->ncrtc; i++) {
RRCrtc crtc = resources->crtcs[i];
XRRCrtcInfo *xrrCrtcInfo = XRRGetCrtcInfo (dpy, resources, crtc);
- fprintf(stderr, "Crtc[%d]: %d/%d %dx%d, rot 0x%X, mode.id %#lx\n",
- i, xrrCrtcInfo->x, xrrCrtcInfo->y, xrrCrtcInfo->width, xrrCrtcInfo->height, xrrCrtcInfo->rotations, xrrCrtcInfo->mode);
+ fprintf(stderr, "Crtc[%d] %#lx: %d/%d %dx%d, rot 0x%X, mode.id %#lx\n",
+ i, crtc, xrrCrtcInfo->x, xrrCrtcInfo->y, xrrCrtcInfo->width, xrrCrtcInfo->height, xrrCrtcInfo->rotations, xrrCrtcInfo->mode);
for(j=0; j<xrrCrtcInfo->noutput; j++) {
fprintf(stderr, " Crtc[%d].Output[%d].id %#lx\n", i, j, xrrCrtcInfo->outputs[j]);
+ dumpOutput(" ", dpy, screen_idx, resources, j, xrrCrtcInfo->outputs[j]);
}
XRRFreeCrtcInfo(xrrCrtcInfo);
}
@@ -166,14 +201,28 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_dumpInfo0
/*
* Class: jogamp_newt_driver_x11_RandR13
- * Method: getMonitorDeviceCount0
+ * Method: getMonitorDeviceIds0
* Signature: (J)I
*/
-JNIEXPORT jint JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDeviceCount0
+JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDeviceIds0
(JNIEnv *env, jclass clazz, jlong screenResources)
{
XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
- return ( NULL != resources ) ? resources->ncrtc : 0;
+ int ncrtc = ( NULL != resources ) ? resources->ncrtc : 0;
+ jintArray properties = NULL;
+ if( 0 < ncrtc ) {
+ int crtcs[ncrtc];
+ int i;
+ for(i=0; i<ncrtc; i++) {
+ crtcs[i] = (int)(intptr_t)resources->crtcs[i];
+ }
+ properties = (*env)->NewIntArray(env, ncrtc);
+ if (properties == NULL) {
+ NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", ncrtc);
+ }
+ (*env)->SetIntArrayRegion(env, properties, 0, ncrtc, crtcs);
+ }
+ return properties;
}
/*
@@ -182,19 +231,12 @@ JNIEXPORT jint JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDeviceCount
* Signature: (JIJI)J
*/
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorInfoHandle0
- (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources, jint crt_idx)
+ (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources, jint crt_id)
{
- Display *dpy = (Display *) (intptr_t) display;
- Window root = RootWindow(dpy, (int)screen_idx);
- XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
-
- if( NULL == resources || crt_idx >= resources->ncrtc ) {
- return 0;
- }
- RRCrtc crtc = resources->crtcs[crt_idx];
- XRRCrtcInfo *xrrCrtcInfo = XRRGetCrtcInfo (dpy, resources, crtc);
-
- return (jlong) (intptr_t) xrrCrtcInfo;
+ XRRCrtcInfo *xrrCrtcInfo = getXRRCrtcInfo((Display *)(intptr_t)display,
+ (XRRScreenResources *)(intptr_t)screenResources,
+ (RRCrtc)(intptr_t)crt_id );
+ return (jlong)(intptr_t)xrrCrtcInfo;
}
/*
@@ -360,16 +402,8 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorCurren
return NULL;
}
- int modeId = xrrCrtcInfo->mode;
- XRRModeInfo *mode = NULL;
- int i;
- for(i=0; i<resources->nmode; i++) {
- XRRModeInfo *imode = &resources->modes[i];
- if( imode->id == modeId ) {
- mode = imode;
- break;
- }
- }
+ RRMode modeId = xrrCrtcInfo->mode;
+ XRRModeInfo *mode = findMode(resources, modeId);
if( NULL == mode ) {
// oops ..
return NULL;
@@ -412,17 +446,20 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorCurren
* Signature: (JJJJ)[I
*/
JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice0
- (JNIEnv *env, jclass clazz, jlong display, jlong screenResources, jlong monitorInfo, jint crt_idx)
+ (JNIEnv *env, jclass clazz, jlong display, jlong screenResources, jlong monitorInfo, jint crt_id)
{
Display * dpy = (Display *) (intptr_t) display;
XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
+ RRCrtc crtc = findRRCrtc( resources, (RRCrtc)(intptr_t)crt_id );
+ if( 0 == crtc ) {
+ // n/a
+ return NULL;
+ }
XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo;
-
- if( NULL == resources || NULL == xrrCrtcInfo || crt_idx >= resources->ncrtc ) {
+ if( NULL == xrrCrtcInfo ) {
// n/a
return NULL;
}
-
if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) {
// disabled
return NULL;
@@ -444,7 +481,7 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice
int propIndex = 0;
prop[propIndex++] = propCount;
- prop[propIndex++] = crt_idx;
+ prop[propIndex++] = crt_id;
prop[propIndex++] = 0; // isClone, does not work: 0 < xrrOutputInfo->nclone ? 1 : 0;
prop[propIndex++] = isPrimary;
prop[propIndex++] = xrrOutputInfo->mm_width;
@@ -457,14 +494,13 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice
prop[propIndex++] = xrrCrtcInfo->y; // rotated viewport window units (same)
prop[propIndex++] = xrrCrtcInfo->width; // rotated viewport window units (same)
prop[propIndex++] = xrrCrtcInfo->height; // rotated viewport window units (same)
- prop[propIndex++] = xrrCrtcInfo->mode; // current mode id
+ prop[propIndex++] = xrrCrtcInfo->mode; // current mode id
prop[propIndex++] = NewtScreen_XRotation2Degree(env, xrrCrtcInfo->rotation);
int i;
for(i=0; i<numModes; i++) {
// avail modes ..
prop[propIndex++] = xrrOutputInfo->modes[i];
}
-
XRRFreeOutputInfo (xrrOutputInfo);
jintArray properties = (*env)->NewIntArray(env, propCount);
@@ -482,43 +518,147 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice
* Signature: (JJJIIIII)Z
*/
JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR13_setMonitorMode0
- (JNIEnv *env, jclass clazz, jlong display, jlong screenResources, jlong monitorInfo, jint crt_idx, jint modeId, jint rotation, jint x, jint y)
+ (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources,
+ jlong monitorInfo, jint crt_id,
+ jint jmode_id, jint rotation, jint x, jint y)
{
+ jboolean res = JNI_FALSE;
Display * dpy = (Display *) (intptr_t) display;
+ Window root = RootWindow(dpy, (int)screen_idx);
XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources;
+ RRCrtc crtc = findRRCrtc( resources, (RRCrtc)(intptr_t)crt_id );
+ if( 0 == crtc ) {
+ // n/a
+ DBG_PRINT("RandR13_setMonitorMode0.0: n/a: resources %p (%d), crt_id %#lx \n",
+ resources, (NULL == resources ? 0 : resources->ncrtc), (RRCrtc)(intptr_t)crt_id);
+ return res;
+ }
XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo;
- jboolean res = JNI_FALSE;
-
- if( NULL == resources || NULL == xrrCrtcInfo || crt_idx >= resources->ncrtc ) {
+ if( NULL == xrrCrtcInfo ) {
// n/a
+ DBG_PRINT("RandR13_setMonitorMode0.1: n/a: resources %p (%d), xrrCrtcInfo %p, crtc %#lx\n",
+ resources, (NULL == resources ? 0 : resources->ncrtc), xrrCrtcInfo, crtc);
return res;
}
-
if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) {
// disabled
+ DBG_PRINT("RandR13_setMonitorMode0: disabled: mode %d, noutput %d\n", xrrCrtcInfo->mode, xrrCrtcInfo->noutput);
return res;
}
-
- if( 0 >= modeId ) {
+ if( 0 >= jmode_id ) {
// oops ..
+ DBG_PRINT("RandR13_setMonitorMode0: inv. modeId: modeId %d\n", jmode_id);
return res;
}
+ RRMode mode_id = (RRMode)(intptr_t)jmode_id;
+ XRRModeInfo *mode_info = findMode(resources, mode_id);
+ if( NULL == mode_info ) {
+ // oops ..
+ DBG_PRINT("RandR13_setMonitorMode0: inv. mode_id: mode_id %#lx\n", mode_id);
+ return res;
+ }
if( 0 > x || 0 > y ) {
x = xrrCrtcInfo->x;
y = xrrCrtcInfo->y;
}
- Status status = XRRSetCrtcConfig( dpy, resources, resources->crtcs[crt_idx], CurrentTime,
- x, y, modeId, NewtScreen_Degree2XRotation(env, rotation),
- xrrCrtcInfo->outputs, xrrCrtcInfo->noutput );
+ Rotation xrotation = NewtScreen_Degree2XRotation(env, rotation);
+ int rot_change = xrrCrtcInfo->rotation != xrotation;
+ DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, noutput %d -> 0x%X, mode %#lx -> %#lx, pos %d / %d, rotation %d -> %d (change %d)\n",
+ crtc, xrrCrtcInfo->noutput, xrrCrtcInfo->outputs[0], xrrCrtcInfo->mode, mode_id,
+ x, y, (int)xrrCrtcInfo->rotation, (int)xrotation, rot_change);
+
+ XRRSelectInput (dpy, root, RRScreenChangeNotifyMask);
+ Status status = RRSetConfigSuccess;
+ int pre_fb_width=0, pre_fb_height=0;
+ int fb_width=0, fb_height=0;
+ int fb_width_mm=0, fb_height_mm=0;
+
+ crtc_t *root_crtc = get_screen_size1(dpy, root, &fb_width, &fb_height,
+ resources, crtc, xrrCrtcInfo, xrotation, x, y, mode_info);
+
+ Bool fb_change = get_screen_sizemm(dpy, screen_idx, fb_width, fb_height,
+ &fb_width_mm, &fb_height_mm,
+ &pre_fb_width, &pre_fb_height);
+
+ DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, fb[change %d: %d x %d -> %d x %d [%d x %d mm]\n",
+ crtc, fb_change, pre_fb_width, pre_fb_height, fb_width, fb_height, fb_width_mm, fb_height_mm);
+ if(fb_change) {
+ // Disable CRTC first, since new size differs from current
+ // and we shall avoid invalid intermediate configuration (see spec)!
+ #if 0
+ {
+ // Disable all CRTCs (Not required!)
+ crtc_t * iter_crtc;
+ for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) {
+ if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) {
+ // disabled
+ continue;
+ }
+ status = XRRSetCrtcConfig (dpy, resources, iter_crtc->crtc_id, CurrentTime,
+ 0, 0, None, RR_Rotate_0, NULL, 0);
+ }
+ }
+ #else
+ status = XRRSetCrtcConfig (dpy, resources, crtc, CurrentTime,
+ 0, 0, None, RR_Rotate_0, NULL, 0);
+ #endif
+ DBG_PRINT("RandR13_setMonitorMode0: crt %#lx disable: %d -> %d\n", crtc, status, RRSetConfigSuccess == status);
+ if( RRSetConfigSuccess == status ) {
+ XRRSetScreenSize (dpy, root, fb_width, fb_height,
+ fb_width_mm, fb_height_mm);
+ DBG_PRINT("RandR13_setMonitorMode0: crt %#lx screen-size\n", crtc);
+ }
+ }
+ if( RRSetConfigSuccess == status ) {
+ #if 0
+ {
+ // Enable/Set all CRTCs (Not required!)
+ crtc_t * iter_crtc;
+ for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) {
+ if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) {
+ // disabled
+ continue;
+ }
+ status = XRRSetCrtcConfig( dpy, resources, iter_crtc->crtc_id, CurrentTime,
+ iter_crtc->x, iter_crtc->y, iter_crtc->mode_id, iter_crtc->rotation,
+ iter_crtc->crtc_info->outputs, iter_crtc->crtc_info->noutput );
+ }
+ }
+ #else
+ status = XRRSetCrtcConfig( dpy, resources, crtc, CurrentTime,
+ x, y, mode_id, xrotation,
+ xrrCrtcInfo->outputs, xrrCrtcInfo->noutput );
+ #endif
+ DBG_PRINT("RandR13_setMonitorMode0: crt %#lx set-config: %d -> %d\n", crtc, status, RRSetConfigSuccess == status);
+ }
+
res = status == RRSetConfigSuccess;
+ DBG_PRINT("RandR13_setMonitorMode0: FIN: %d -> ok %d\n", status, res);
+
+ destroyCrtcChain(root_crtc, crtc);
+ root_crtc=NULL;
return res;
}
/*
* Class: jogamp_newt_driver_x11_RandR13
+ * Method: sendRRScreenChangeNotify0
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_sendRRScreenChangeNotify0
+ (JNIEnv *env, jclass clazz, jlong display, jlong jevent)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ XEvent *event = (XEvent*)(intptr_t)jevent;
+ XRRUpdateConfiguration(event);
+ DBG_PRINT("RandR13_sendRRScreenChangeNotify0: dpy %p, event %p\n", dpy, event);
+}
+
+/*
+ * Class: jogamp_newt_driver_x11_RandR13
* Method: setScreenViewport0
* Signature: (JIJIIII)Z
*/
@@ -539,4 +679,3 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR13_setScreenViewport
return JNI_TRUE;
}
-
diff --git a/src/newt/native/X11Screen.c b/src/newt/native/X11Screen.c
index 152a092c9..b4bb8a112 100644
--- a/src/newt/native/X11Screen.c
+++ b/src/newt/native/X11Screen.c
@@ -74,7 +74,7 @@ JNIEXPORT jint JNICALL Java_jogamp_newt_driver_x11_ScreenDriver_getHeight0
return (jint) DisplayHeight( dpy, scrn_idx);
}
-int NewtScreen_XRotation2Degree(JNIEnv *env, int xrotation) {
+int NewtScreen_XRotation2Degree(JNIEnv *env, Rotation xrotation) {
int degree;
if(xrotation == RR_Rotate_0) {
degree = 0;
@@ -93,8 +93,8 @@ int NewtScreen_XRotation2Degree(JNIEnv *env, int xrotation) {
return degree;
}
-int NewtScreen_Degree2XRotation(JNIEnv *env, int degree) {
- int xrot;
+Rotation NewtScreen_Degree2XRotation(JNIEnv *env, int degree) {
+ Rotation xrot;
if(degree == 0) {
xrot = RR_Rotate_0;
}
diff --git a/src/newt/native/X11Screen.h b/src/newt/native/X11Screen.h
index c81ee05d5..5f47cc90d 100644
--- a/src/newt/native/X11Screen.h
+++ b/src/newt/native/X11Screen.h
@@ -32,7 +32,7 @@
#include "X11Common.h"
-int NewtScreen_XRotation2Degree(JNIEnv *env, int xrotation);
-int NewtScreen_Degree2XRotation(JNIEnv *env, int degree);
+int NewtScreen_XRotation2Degree(JNIEnv *env, Rotation xrotation);
+Rotation NewtScreen_Degree2XRotation(JNIEnv *env, int degree);
#endif /* _X11SCREEN_H */
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 43506c6a6..e640b0c20 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -696,7 +696,8 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CreateWindow0
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
- (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/) // XKB disabled for now
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/, // XKB disabled for now
+ jint randr_event_base, jint randr_error_base)
{
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
@@ -726,7 +727,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
XUnmapWindow(dpy, w);
// Drain all events related to this window ..
- Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom /*, kbdHandle */); // XKB disabled for now
+ Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom /*, kbdHandle */, // XKB disabled for now
+ randr_event_base, randr_error_base);
XDestroyWindow(dpy, w);
if( None != xwa.colormap ) {
diff --git a/src/newt/native/xrandr_utils.c b/src/newt/native/xrandr_utils.c
new file mode 100644
index 000000000..564fdd44b
--- /dev/null
+++ b/src/newt/native/xrandr_utils.c
@@ -0,0 +1,322 @@
+/**
+ * This file contains code from xrandr.c,
+ * see <http://cgit.freedesktop.org/xorg/app/xrandr/tree/xrandr.c>:
+ *
+ * ++++
+ *
+ * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2002 Hewlett Packard Company, Inc.
+ * Copyright © 2006 Intel Corporation
+ * Copyright © 2013 NVIDIA Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * Thanks to Jim Gettys who wrote most of the client side code,
+ * and part of the server code for randr.
+ *
+ * ++++
+ *
+ * Modifications / Additions are from:
+ *
+ * Copyright 2015 JogAmp Community. All rights reserved.
+ *
+ * License text: Same as above!
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+#include "X11Common.h"
+
+#include <math.h>
+
+typedef struct {
+ int x1, y1, x2, y2;
+} box_t;
+typedef struct {
+ int x, y;
+} point_t;
+typedef struct {
+ XTransform transform;
+ char *filter;
+ int nparams;
+ XFixed *params;
+} transform_t;
+typedef struct _crtc {
+ struct _crtc *next;
+ RRCrtc crtc_id;
+ Rotation rotation;
+ transform_t transform;
+ int x, y;
+ RRMode mode_id;
+ // float refresh;
+ // Bool primary;
+
+ XRRModeInfo *mode_info;
+ XRRCrtcInfo *crtc_info;
+ XRRPanning *panning_info;
+} crtc_t;
+static int mode_height (XRRModeInfo *mode_info, Rotation rotation) {
+ switch (rotation & 0xf) {
+ case RR_Rotate_0:
+ case RR_Rotate_180:
+ return mode_info->height;
+ case RR_Rotate_90:
+ case RR_Rotate_270:
+ return mode_info->width;
+ default:
+ return 0;
+ }
+}
+static int mode_width (XRRModeInfo *mode_info, Rotation rotation) {
+ switch (rotation & 0xf) {
+ case RR_Rotate_0:
+ case RR_Rotate_180:
+ return mode_info->width;
+ case RR_Rotate_90:
+ case RR_Rotate_270:
+ return mode_info->height;
+ default:
+ return 0;
+ }
+}
+static Bool transform_point (XTransform *transform, double *xp, double *yp) {
+ double vector[3];
+ double result[3];
+ int i, j;
+ double v;
+
+ vector[0] = *xp;
+ vector[1] = *yp;
+ vector[2] = 1;
+ for (j = 0; j < 3; j++)
+ {
+ v = 0;
+ for (i = 0; i < 3; i++) {
+ v += (XFixedToDouble (transform->matrix[j][i]) * vector[i]);
+ }
+ if (v > 32767 || v < -32767) {
+ return False;
+ }
+ result[j] = v;
+ }
+ if (!result[2]) {
+ return False;
+ }
+ for (j = 0; j < 2; j++) {
+ vector[j] = result[j] / result[2];
+ }
+ *xp = vector[0];
+ *yp = vector[1];
+ return True;
+}
+static void path_bounds (XTransform *transform, point_t *points, int npoints, box_t *box) {
+ int i;
+ box_t point;
+
+ for (i = 0; i < npoints; i++) {
+ double x, y;
+ x = points[i].x;
+ y = points[i].y;
+ transform_point (transform, &x, &y);
+ point.x1 = floor (x);
+ point.y1 = floor (y);
+ point.x2 = ceil (x);
+ point.y2 = ceil (y);
+ if (i == 0) {
+ *box = point;
+ } else {
+ if (point.x1 < box->x1) { box->x1 = point.x1; }
+ if (point.y1 < box->y1) { box->y1 = point.y1; }
+ if (point.x2 > box->x2) { box->x2 = point.x2; }
+ if (point.y2 > box->y2) { box->y2 = point.y2; }
+ }
+ }
+}
+static void mode_geometry (XRRModeInfo *mode_info, Rotation rotation,
+ XTransform *transform, box_t *bounds) {
+ point_t rect[4];
+ int width = mode_width (mode_info, rotation);
+ int height = mode_height (mode_info, rotation);
+
+ rect[0].x = 0;
+ rect[0].y = 0;
+ rect[1].x = width;
+ rect[1].y = 0;
+ rect[2].x = width;
+ rect[2].y = height;
+ rect[3].x = 0;
+ rect[3].y = height;
+ path_bounds (transform, rect, 4, bounds);
+}
+static void get_screen_size0(Display * dpy, Window root,
+ crtc_t * root_crtc, int *io_scrn_width, int *io_scrn_height) {
+ int fb_width = *io_scrn_width;
+ int fb_height = *io_scrn_height;
+ crtc_t *crtc;
+ for (crtc = root_crtc; NULL != crtc; crtc = crtc->next) {
+ if( None == crtc->mode_id || NULL == crtc->mode_info || 0 == crtc->crtc_info->noutput ) {
+ // disabled
+ continue;
+ }
+ XRRModeInfo *mode_info = crtc->mode_info;
+ int x, y, w, h;
+ box_t bounds;
+
+ mode_geometry (mode_info, crtc->rotation,
+ &crtc->transform.transform, &bounds);
+ x = crtc->x + bounds.x1;
+ y = crtc->y + bounds.y1;
+ w = bounds.x2 - bounds.x1;
+ h = bounds.y2 - bounds.y1;
+
+ /* fit fb to crtc */
+ XRRPanning *pan;
+ if (x + w > fb_width) {
+ fb_width = x + w;
+ }
+ if (y + h > fb_height) {
+ fb_height = y + h;
+ }
+ pan = crtc->panning_info;
+ if (pan && pan->left + pan->width > fb_width) {
+ fb_width = pan->left + pan->width;
+ }
+ if (pan && pan->top + pan->height > fb_height) {
+ fb_height = pan->top + pan->height;
+ }
+ }
+ int minWidth=0, minHeight=0, maxWidth=0, maxHeight=0;
+ if( 1 != XRRGetScreenSizeRange (dpy, root, &minWidth, &minHeight, &maxWidth, &maxHeight) ) {
+ // Use defaults in case of error ..
+ minWidth=8; minHeight=8; maxWidth=16384; maxHeight=16384;
+ }
+ if( fb_width < minWidth ) {
+ fb_width = minWidth;
+ } else if( fb_width > maxWidth ) {
+ fb_width = maxWidth;
+ }
+ if( fb_height < minHeight ) {
+ fb_height = minHeight;
+ } else if( fb_height > maxHeight ) {
+ fb_height = maxHeight;
+ }
+ *io_scrn_width = fb_width;
+ *io_scrn_height = fb_height;
+}
+static crtc_t* createCrtcChain(Display *dpy,
+ XRRScreenResources *resources,
+ RRCrtc customCrtc, XRRCrtcInfo *customCrtcInfo,
+ Rotation customRotation, int customX, int customY,
+ XRRModeInfo *customModeInfo)
+{
+ crtc_t *root_crtc = NULL;
+ crtc_t *iter_crtc = NULL;
+ int i;
+ for(i=0; i<resources->ncrtc; i++) {
+ crtc_t *next_crtc = calloc(1, sizeof(crtc_t));
+ if( NULL == iter_crtc ) {
+ root_crtc = next_crtc;
+ } else {
+ iter_crtc->next = next_crtc;
+ }
+ iter_crtc = next_crtc;
+
+ RRCrtc crtcId = resources->crtcs[i];
+ iter_crtc->crtc_id = crtcId;
+ if( crtcId == customCrtc && 0 != customCrtc ) {
+ iter_crtc->rotation = customRotation;
+ iter_crtc->x = customX;
+ iter_crtc->y = customY;
+ iter_crtc->mode_info = customModeInfo;
+ iter_crtc->mode_id = customModeInfo->id;
+ iter_crtc->crtc_info = customCrtcInfo;
+ } else {
+ XRRCrtcInfo *xrrCrtcInfo = XRRGetCrtcInfo (dpy, resources, crtcId);
+ iter_crtc->rotation = xrrCrtcInfo->rotation;
+ iter_crtc->x = xrrCrtcInfo->x;
+ iter_crtc->y = xrrCrtcInfo->y;
+ iter_crtc->mode_id = xrrCrtcInfo->mode;
+ iter_crtc->mode_info = findMode(resources, iter_crtc->mode_id);
+ iter_crtc->crtc_info = xrrCrtcInfo;
+ }
+ iter_crtc->panning_info = XRRGetPanning(dpy, resources, crtcId);
+ }
+ return root_crtc;
+}
+static void destroyCrtcChain(crtc_t *root_crtc, RRCrtc customCrtc) {
+ crtc_t * iter_crtc = root_crtc;
+ while(NULL!=iter_crtc) {
+ if( NULL != iter_crtc->crtc_info ) {
+ if( iter_crtc->crtc_id != customCrtc || 0 == customCrtc ) {
+ XRRFreeCrtcInfo(iter_crtc->crtc_info);
+ }
+ iter_crtc->crtc_info = NULL;
+ }
+ if( NULL != iter_crtc->panning_info ) {
+ XRRFreePanning(iter_crtc->panning_info);
+ iter_crtc->panning_info = NULL;
+ }
+ {
+ crtc_t * last = iter_crtc;
+ iter_crtc = iter_crtc->next;
+ last->next = NULL;
+ free(last);
+ }
+ }
+}
+static crtc_t *get_screen_size1(Display * dpy, Window root,
+ int *io_scrn_width, int *io_scrn_height,
+ XRRScreenResources *resources,
+ RRCrtc customCrtc, XRRCrtcInfo *customCrtcInfo,
+ Rotation customRotation, int customX, int customY,
+ XRRModeInfo *customModeInfo) {
+ crtc_t *root_crtc = createCrtcChain(dpy, resources, customCrtc, customCrtcInfo,
+ customRotation, customX, customY, customModeInfo);
+ get_screen_size0(dpy, root, root_crtc, io_scrn_width, io_scrn_height);
+ return root_crtc;
+}
+static crtc_t *get_screen_size2(Display * dpy, Window root,
+ int *io_scrn_width, int *io_scrn_height,
+ XRRScreenResources *resources) {
+ crtc_t *root_crtc = createCrtcChain(dpy, resources, 0, NULL, 0, 0, 0, NULL);
+ get_screen_size0(dpy, root, root_crtc, io_scrn_width, io_scrn_height);
+ return root_crtc;
+}
+static Bool get_screen_sizemm(Display *dpy, int screen_idx,
+ int fb_width, int fb_height,
+ int *fb_width_mm, int *fb_height_mm,
+ int *pre_fb_width, int *pre_fb_height) {
+ *pre_fb_width = DisplayWidth (dpy, screen_idx);
+ *pre_fb_height = DisplayHeight (dpy, screen_idx);
+ Bool fb_change;
+ if (fb_width != *pre_fb_width || fb_height != *pre_fb_height ) {
+ float dpi = (25.4 * *pre_fb_height) / DisplayHeightMM(dpy, screen_idx);
+ *fb_width_mm = (25.4 * fb_width) / dpi;
+ *fb_height_mm = (25.4 * fb_height) / dpi;
+ fb_change = True;
+ } else {
+ *fb_width_mm = DisplayWidthMM (dpy, screen_idx);
+ *fb_height_mm = DisplayHeightMM (dpy, screen_idx);
+ fb_change = False;
+ }
+ return fb_change;
+}
+