From 501c6eb018fea7647027a330e0ee9fef79d3b5bb Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Thu, 23 Jan 2020 02:02:52 +0200 Subject: [PATCH] * Source/x11/XGServerWindow.m (boundsForScreen:): if Xrandr support enabled get screen dimensions using Xrandr objects. * Source/x11/XGServerEvent.m (processEvent:): process Xrandr event and send NSApplicationDidChangeScreenParametersNotification. * Source/x11/XGServer.m (_initXContext): subscribe to the Xrandr event. --- ChangeLog | 10 ++++++++++ Source/x11/XGServer.m | 13 +++++++++++++ Source/x11/XGServerEvent.m | 24 ++++++++++++++++++++++++ Source/x11/XGServerWindow.m | 36 +++++++++++++++++++++++++++++------- 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b77c11f..87ed616 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2020-01-23 Sergii Stoian + + * Source/x11/XGServerWindow.m (boundsForScreen:): if Xrandr support + enabled get screen dimensions using Xrandr objects. + + * Source/x11/XGServerEvent.m (processEvent:): process Xrandr event and + send NSApplicationDidChangeScreenParametersNotification. + + * Source/x11/XGServer.m (_initXContext): subscribe to the Xrandr event. + 2020-01-22 Sergii Stoian * configure.ac: check for availability of Xrandr library. diff --git a/Source/x11/XGServer.m b/Source/x11/XGServer.m index 1d9b069..ea7bd30 100644 --- a/Source/x11/XGServer.m +++ b/Source/x11/XGServer.m @@ -69,6 +69,10 @@ terminate(int sig) #include "x11/XGOpenGL.h" #endif +#ifdef HAVE_XRANDR +#include +#endif + #include #include #include @@ -465,6 +469,15 @@ _parse_display_name(NSString *name, int *dn, int *sn) [self _setupRootWindow]; inputServer = [[XIMInputServer allocWithZone: [self zone]] initWithDelegate: nil display: dpy name: @"XIM"]; + +#ifdef HAVE_XRANDR + int count = ScreenCount(dpy); + int i; + for (i = 0; i < count; i++) + { + XRRSelectInput(dpy, RootWindow(dpy, i), RRScreenChangeNotifyMask); + } +#endif return self; } diff --git a/Source/x11/XGServerEvent.m b/Source/x11/XGServerEvent.m index 55a921f..f57f93d 100644 --- a/Source/x11/XGServerEvent.m +++ b/Source/x11/XGServerEvent.m @@ -55,6 +55,9 @@ #else #include "x11/wraster.h" #endif +#ifdef HAVE_XRANDR +#include +#endif #include "math.h" #include @@ -1894,6 +1897,27 @@ posixFileDescriptor: (NSPosixFileDescriptor*)fileDescriptor ((XShmCompletionEvent *)&xEvent)->drawable]; break; } +#endif +#ifdef HAVE_XRANDR + if (xEvent.type & RRScreenChangeNotifyMask) + { + int count = ScreenCount(dpy); + int i; + for (i = 0; i < count; i++) + { + if (xEvent.xconfigure.window == RootWindow(dpy, i)) + { + NSLog(@"[XGServerEvent] RRScreenChangeNotify for screen %i/%i", + i, count); + XRRUpdateConfiguration(event); + [[NSNotificationCenter defaultCenter] + postNotificationName: NSApplicationDidChangeScreenParametersNotification + object: NSApp]; + break; + } + } + break; + } #endif NSLog(@"Received an untrapped event\n"); break; diff --git a/Source/x11/XGServerWindow.m b/Source/x11/XGServerWindow.m index 4662a66..4991df2 100644 --- a/Source/x11/XGServerWindow.m +++ b/Source/x11/XGServerWindow.m @@ -66,6 +66,9 @@ #if HAVE_XFIXES #include #endif +#ifdef HAVE_XRANDR +#include +#endif #include "x11/XGDragView.h" #include "x11/XGInputServer.h" @@ -4509,13 +4512,32 @@ _computeDepth(int class, int bpp) - (NSRect) boundsForScreen: (int)screen { - if (screen < 0 || screen >= ScreenCount(dpy)) - { - NSLog(@"Invalidparam: no screen %d", screen); - return NSZeroRect; - } - return NSMakeRect(0, 0, DisplayWidth(dpy, screen), - DisplayHeight(dpy, screen)); + if (screen < 0 || screen >= ScreenCount(dpy)) + { + NSLog(@"Invalidparam: no screen %d", screen); + return NSZeroRect; + } +#ifdef HAVE_XRANDR + XRRScreenResources *screen_res; + XRROutputInfo *output_info; + NSRect boundsRect = {{0,0},{0,0}}; + screen_res = XRRGetScreenResources(dpy, RootWindow(dpy, screen)); + output_info = XRRGetOutputInfo(dpy, screen_res, screen_res->outputs[0]); + if (output_info->crtc) + { + XRRCrtcInfo *crtc_info; + crtc_info = XRRGetCrtcInfo(dpy, screen_res, output_info->crtc); + NSLog(@"Screen bounds: %i,%i %ux%u", + crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height); + boundsRect = NSMakeRect(crtc_info->x, crtc_info->y, + crtc_info->width, crtc_info->height); + } + XRRFreeScreenResources(screen_res); + return boundsRect; +#else + return NSMakeRect(0, 0, DisplayWidth(dpy, screen), + DisplayHeight(dpy, screen)); +#endif } - (NSImage *) iconTileImage