X11: GdkScreen misreports its own size
Steps to reproduce
-
Have a Thinkpad x240, or probably anything with Intel graphics (see Reproducibility below). One monitor is enough.
-
Check the current screen size with xrandr:
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
- Use xrandr to change the screen size:
xrandr --fb 2000x2000
- Check the screen size again with xrandr:
Screen 0: minimum 320 x 200, current 2000 x 2000, maximum 16384 x 16384
- Check it with
xwininfo -root
:
Width: 2000
Height: 2000
- Check it with Xlib:
#include <X11/Xlib.h>
int main (int argc, char *argv[])
{
Display *dpy = XOpenDisplay(NULL);
Screen *scrn = XScreenOfDisplay(dpy, 0);
printf("Screen according to X11: %dx%d\n", WidthOfScreen(scrn), HeightOfScreen(scrn));
}
Result: Screen according to X11: 2000x2000
- Check it with Gtk2:
#include <gtk/gtk.h>
#include <gdk/gdk.h>
int main (int argc, char *argv[])
{
GdkDisplay *display = gdk_display_open(NULL);
GdkScreen *screen = gdk_display_get_default_screen(display);
printf("Screen according to Gtk2: %dx%d\n",
gdk_screen_get_width(screen),
gdk_screen_get_height(screen));
}
Result: Screen according to Gtk2: 2000x2000
- Check it with Gtk3:
#include <gtk/gtk.h>
#include <gdk/gdk.h>
int main (int argc, char *argv[])
{
GdkDisplay *display = gdk_display_open(NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GdkScreen *screen = gdk_display_get_default_screen(display);
printf("Screen according to Gtk3: %dx%d\n",
gdk_screen_get_width(screen),
gdk_screen_get_height(screen));
G_GNUC_END_IGNORE_DEPRECATIONS
}
Result: Screen according to Gtk3: 1920x1080
Current behavior
Gtk3 assumes that a GdkScreen will always be the same size as the bounding rectangle of all of its monitors. (https://bugzilla.gnome.org/show_bug.cgi?id=715029)
This is not always true, as demonstrated by the above example.
Expected outcome
GdkScreen should report the correct size, in this case 2000x2000.
Version information
Ubuntu 19.10, Gtk 3.24.13-1ubuntu1
Impact
Gtk 3 applications which set struts on the bottom or right edge of the screen will set them in the wrong place and they won't function. This is mitigated if your window manager also uses Gtk 3 and GdkScreen to determine the screen size, because it will have the same incorrect information.
Reproducibility
This bug cannot be reproduced with the Nvidia proprietary driver. It forces panning on all monitors when the screen size is larger than the bounding rectangle, and the panning size is what is reported to Gdk by xrandr. In this case the monitor geometries will not match the physical sizes, but their bounding rect will accurately reflect the screen size.
I have not tested with any other video drivers.