[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] [PATCH] Query for dimensions to apply to the screen when receiving

From: Will Storey
Subject: [RP] [PATCH] Query for dimensions to apply to the screen when receiving an XRRCrtcChangeNotifyEvent
Date: Sat, 16 Dec 2017 16:55:02 -0800

When receiving this event, we're told the dimensions of the CRTC. These
dimensions apparently do not reflect the actual dimensions of the CRTC.
This means ratpoison's knowledge of screen size can be inaccurate and
ratpoison will use only a portion of the screen.

This change makes us query for the dimensions of the CRTC and then use
those rather than use the dimensions provided by the event.

This addresses a problem with different sized screens after using the
xrandr command. In my setup I have two different sized screens with
different DPIs (a laptop and a monitor). Upon logging on, I issue an
xrandr command to scale the monitor's output. Prior to this change,
ratpoison used only part of the monitor after doing this (the top left).
Restarting ratpoison is a workaround to make it aware of the monitor's
dimensions, but an unsatisfactory one.

I believe the issue stems from scaling for mixed DPI. The CRTC change
event appears to have a width and height prior to applying scaling
(2x2) (1920x1080 vs. 3840x2160 in my case).
 src/xrandr.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/xrandr.c b/src/xrandr.c
index 5ddf082..db9946d 100644
--- a/src/xrandr.c
+++ b/src/xrandr.c
@@ -209,25 +209,49 @@ static void
 xrandr_crtc_change (XRRCrtcChangeNotifyEvent *ev)
   rp_screen *screen;
+  XRRScreenResources *screen_resources;
+  XRRCrtcInfo *crtc_info;
   if (!ev->crtc || !ev->width || !ev->height)
   screen = xrandr_screen_crtc (ev->crtc);
-  PRINT_DEBUG (("%s: crtc %s, rotation %s "
+  PRINT_DEBUG (("%s: crtc %lu %s, rotation %s "
                 "ev->x %d, ev->y %d, ev->width %d, ev->height %d\n",
-                __func__, screen ? "found" : "not found",
+                __func__, ev->crtc, screen ? "found" : "not found",
                 xrandr_rotation_string (ev->rotation),
                 ev->x, ev->y, ev->width, ev->height));
   if (!screen)
+  /* While the event has position and dimension information, it is not always
+   * correct. Query and get the correct information. This particularly appears
+   * to happen when scaling an output. */
+  screen_resources = XRRGetScreenResourcesCurrent (dpy, RootWindow (dpy,
+                                                   DefaultScreen (dpy)));
+  if (!screen_resources) {
+    PRINT_ERROR (("%s: XRRGetScreenResources() failed\n", __func__));
+    return;
+  }
+  crtc_info = XRRGetCrtcInfo (dpy, screen_resources, screen->xrandr.crtc);
+  if (!crtc_info) {
+    PRINT_ERROR (("%s: XRRGetCrtcInfo() failed\n", __func__));
+    XRRFreeScreenResources (screen_resources);
+    return;
+  }
   if (ev->rotation == RR_Rotate_90 || ev->rotation == RR_Rotate_270)
-    screen_update (screen, ev->x, ev->y, ev->height, ev->width);
+    screen_update (screen, crtc_info->x, crtc_info->y, crtc_info->height,
+                   crtc_info->width);
-    screen_update (screen, ev->x, ev->y, ev->width, ev->height);
+    screen_update (screen, crtc_info->x, crtc_info->y, crtc_info->width,
+                   crtc_info->height);
+  XRRFreeScreenResources (screen_resources);
+  XRRFreeCrtcInfo (crtc_info);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]