From 0adbc977ac7848e8092fa1d58174d0a37aabb86b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Mar 2015 15:45:36 +0100 Subject: Bug 1142 - NEWT: Add support to retrieve the primary MonitorDevice Support added for - Windows - X11 XRandR 1.3 - OSX Note: Our whole MonitorMode association handling is currently _not_ dynamic. - only on Windows we actually use native unique ID, which might not change (adapter and monitor idx) - On OSX and X11 we simply use indices, but if monitor setup changes - they refer to different instances. In case it is desired to cover dynamic monitor setup change, we need to address this issue in a new bug entry. --- src/newt/native/X11RandR13.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/newt/native/X11RandR13.c') diff --git a/src/newt/native/X11RandR13.c b/src/newt/native/X11RandR13.c index 1d721efcb..4f52ad190 100644 --- a/src/newt/native/X11RandR13.c +++ b/src/newt/native/X11RandR13.c @@ -61,16 +61,23 @@ 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, XRRScreenResources *resources, int noutput, RROutput * outputs) { - int i, j; - fprintf(stderr, "%s %p: Output count %d\n", prefix, resources, noutput); +static void dumpOutputs(const char *prefix, Display *dpy, int screen_idx, XRRScreenResources *resources, int noutput, RROutput * outputs) { + 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); for(i=0; icrtc, SAFE_STRING(xrrOutputInfo->name), xrrOutputInfo->nameLen, xrrOutputInfo->mm_width, xrrOutputInfo->mm_height, - xrrOutputInfo->ncrtc, xrrOutputInfo->nclone, xrrOutputInfo->nmode, xrrOutputInfo->npreferred); + xrrOutputInfo->ncrtc, xrrOutputInfo->nclone, xrrOutputInfo->nmode, xrrOutputInfo->npreferred, isPrim); for(j=0; jncrtc; j++) { fprintf(stderr, " Output[%d].Crtc[%d].id %#lx\n", i, j, xrrOutputInfo->crtcs[j]); } @@ -145,7 +152,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_RandR13_dumpInfo0 XRRFreeCrtcInfo(xrrCrtcInfo); } - dumpOutputs("XRRScreenResources.outputs", dpy, resources, resources->noutput, resources->outputs); + dumpOutputs("XRRScreenResources.outputs", dpy, (int)screen_idx, resources, resources->noutput, resources->outputs); fprintf(stderr, "XRRScreenResources %p: Mode count %d\n", resources, resources->nmode); for(i=0; inmode; i++) { @@ -421,7 +428,14 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice return NULL; } + Window root = RootWindow(dpy, 0); // FIXME screen_idx); + RROutput pxid = XRRGetOutputPrimary (dpy, root); + int isPrimary = 0; + RROutput output = xrrCrtcInfo->outputs[0]; + if ( None != pxid && pxid == output ) { + isPrimary = 1; + } XRROutputInfo * xrrOutputInfo = XRRGetOutputInfo (dpy, resources, output); int numModes = xrrOutputInfo->nmode; @@ -431,7 +445,8 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice prop[propIndex++] = propCount; prop[propIndex++] = crt_idx; - prop[propIndex++] = 0; // is_clone, does not work: 0 < xrrOutputInfo->nclone ? 1 : 0; + prop[propIndex++] = 0; // isClone, does not work: 0 < xrrOutputInfo->nclone ? 1 : 0; + prop[propIndex++] = isPrimary; prop[propIndex++] = xrrOutputInfo->mm_width; prop[propIndex++] = xrrOutputInfo->mm_height; prop[propIndex++] = xrrCrtcInfo->x; // rotated viewport pixel units -- cgit v1.2.3