* Source/x11/XGServerWindow.m (screenList): join RandR and non-RandR

code. Failback to Xlib generic method if any no RandR available or
  RandR function call was unsuccessful. In Xlib generic method fill in
  monitors array with values.
  (boundsForScreen:): use values from cached `monitors` array since
  -screenList fills it on both cases with or without RandR available.
This commit is contained in:
Sergii Stoian 2020-01-31 19:28:32 +02:00
parent 7e6dfa39e8
commit 3e53e04c58
2 changed files with 49 additions and 45 deletions

View file

@ -1,3 +1,12 @@
2020-01-31 Sergii Stoian <stoyan255@gmail.com>
* Source/x11/XGServerWindow.m (screenList): join RandR and non-RandR
code. Failback to Xlib generic method if any no RandR available or
RandR function call was unsuccessful. In Xlib generic method fill in
monitors array with values.
(boundsForScreen:): use values from cached `monitors` array since
-screenList fills it on both cases with or without RandR available.
2020-01-30 Sergii Stoian <stoyan255@gmail.com> 2020-01-30 Sergii Stoian <stoyan255@gmail.com>
* Headers/x11/XGServer.h: new structure `MonitorDevice` and ivar * Headers/x11/XGServer.h: new structure `MonitorDevice` and ivar

View file

@ -4420,11 +4420,17 @@ _computeDepth(int class, int bpp)
X11 Screen - its a plane where X Server can draw on. X11 Screen - its a plane where X Server can draw on.
XRandR - Xorg extension that halps to manipulate monitors layout providing XRandR - Xorg extension that halps to manipulate monitors layout providing
X11 Screen. */ X11 Screen. */
#ifdef HAVE_XRANDR
- (NSArray *)screenList - (NSArray *)screenList
{ {
NSMutableArray *screens; NSMutableArray *screens;
int i; int i;
monitorsCount = 0;
if (monitors != NULL) {
NSZoneFree([self zone], monitors);
}
#ifdef HAVE_XRANDR
XRRScreenResources *screen_res; XRRScreenResources *screen_res;
XRROutputInfo *output_info; XRROutputInfo *output_info;
XRRCrtcInfo *crtc_info; XRRCrtcInfo *crtc_info;
@ -4432,10 +4438,9 @@ _computeDepth(int class, int bpp)
screen_res = XRRGetScreenResources(dpy, RootWindow(dpy, defScreen)); screen_res = XRRGetScreenResources(dpy, RootWindow(dpy, defScreen));
monitorsCount = screen_res->noutput; monitorsCount = screen_res->noutput;
if (monitorsCount > 0)
{
screens = [NSMutableArray arrayWithCapacity: monitorsCount]; screens = [NSMutableArray arrayWithCapacity: monitorsCount];
if (monitors != NULL) {
NSZoneFree([self zone], monitors);
}
monitors = NSZoneMalloc([self zone], monitorsCount * sizeof(MonitorDevice)); monitors = NSZoneMalloc([self zone], monitorsCount * sizeof(MonitorDevice));
for (i = 0; i < monitorsCount; i++) for (i = 0; i < monitorsCount; i++)
@ -4454,33 +4459,28 @@ _computeDepth(int class, int bpp)
[screens addObject: [NSNumber numberWithInt: i]]; [screens addObject: [NSNumber numberWithInt: i]];
} }
} }
}
XRRFreeScreenResources(screen_res); XRRFreeScreenResources(screen_res);
#endif
return screens; if (monitorsCount == 0)
}
#else // HAVE_XRANDR
- (NSArray *)screenList
{ {
int i;
NSMutableArray *screens;
monitorsCount = ScreenCount(dpy); monitorsCount = ScreenCount(dpy);
monitors = NSZoneMalloc([self zone], monitorsCount * sizeof(MonitorDevice));
screens = [NSMutableArray arrayWithCapacity: monitorsCount]; screens = [NSMutableArray arrayWithCapacity: monitorsCount];
if (monitorsCount > 0)
{
/* I guess screen numbers are in order starting from zero, but we
put the main screen first */
[screens addObject: [NSNumber numberWithInt: defScreen]];
}
for (i = 0; i < monitorsCount; i++) for (i = 0; i < monitorsCount; i++)
{ {
if (i != defScreen) monitors[i].depth = [self windowDepthForScreen: i];
monitors[i].resolution = [self resolutionForScreen: i];
monitors[i].frame = NSMakeRect(0, 0,
DisplayWidth(dpy, i),
DisplayHeight(dpy, i));
[screens addObject: [NSNumber numberWithInt: i]]; [screens addObject: [NSNumber numberWithInt: i]];
} }
}
return screens; return screens;
} }
#endif
- (NSWindowDepth) windowDepthForScreen: (int) screen - (NSWindowDepth) windowDepthForScreen: (int) screen
{ {
@ -4593,15 +4593,10 @@ _computeDepth(int class, int bpp)
return NSZeroRect; return NSZeroRect;
} }
#ifdef HAVE_XRANDR
if (monitors != NULL) if (monitors != NULL)
{ {
boundsRect = monitors[screen].frame; boundsRect = monitors[screen].frame;
} }
#else
boundsRect = NSMakeRect(0, 0, DisplayWidth(dpy, screen),
DisplayHeight(dpy, screen));
#endif
return boundsRect; return boundsRect;
} }