Skip to content

x11: Handle monitors without outputs

xrandr --setmonitor allows one to replace an output with several monitors. This is useful to split a wide screen into two virtual monitors. Due to some oddity with X11, two monitors cannot share the same output. Therefore, when splitting an output, only the first monitor will get the physical output. The other ones need to be declared without an output. However, they are still valid and should be used to determine the number of active monitors.

xrandr --setmonitor HDMI-00 1280/266x960/200+0+0 HDMI-0
xrandr --setmonitor HDMI-01 1280/266x960/200+1280+0 none
xrandr --setmonitor HDMI-02 1280/266x960/200+2560+0 none
xrandr --setmonitor HDMI-03 1920/400x1200/250+0+960 none
xrandr --setmonitor HDMI-04 1920/400x1200/250+1920+960 none

This introduces a slight mismatch between GDK monitors and RandR monitors. GDK expects a monitor to be a physical screen, with a geometry, a physical size, a refresh rate, and a manufacturer. RandR monitors also have a geometry and a physical size, but no refresh rates and manufacturers.

Previously, GDK just skipped monitors without an attached output. This patch, based on a patch by Jim Duchek, adds them back. To get a proper manufacturer and refresh rate when there is no output attached to a monitor, we look at the info from the previous output.

This is correct in the most common case monitors are created with a set of commands like above. This is not correct if a user has two screens and interleaves xrandr calls between the two screens. This is not correct either if two outputs are merged into a single one (in this case, the monitor has several outputs and we consider only the first one). While the first case could be fixed with more codes to determine which physical output is attached to a monitor without an output, the second case is not solvable as a GDK monitor can only have one refresh rate and one manufacturer.

This patch does not introduce a regression for people not using monitors. It does not change the situation for people merging two screens into a single monitor either. It makes GDK work for people splitting a screen into several monitors (popups and menus are drawn on the first monitor only otherwise), while providing accurate information for most common setups. For the remaining setups, only the refresh rate and manufacturer may be incorrect and this should be harmless in most cases.

If possible, this patch should also be backported to GTK 3.

Fix #2013 (closed)

Merge request reports