diff options
author | aszlig <aszlig@redmoonstudios.org> | 2017-05-02 23:07:24 +0200 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2017-05-02 23:14:26 +0200 |
commit | 9dca737d6269759745c9e68ea462446cde4d9be9 (patch) | |
tree | 4a5cee04ccc3debfb5b67038d01d4a5722626902 /nixos/modules/services/x11 | |
parent | beff1984f4c84435c706244871b65bf1833fbee8 (diff) | |
parent | 79e712822fcfe797c545e2db5bcef9a07b00b2e5 (diff) | |
download | nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar.gz nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar.bz2 nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar.lz nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar.xz nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.tar.zst nixpkgs-9dca737d6269759745c9e68ea462446cde4d9be9.zip |
Merge pull request #15353 (improve xrandrHeads)
When you have a setup consisting of multiple monitors, the default is that the first monitor detected by xrandr is set to the primary monitor. However this may not be the monitor you need to be set as primary. In fact this monitor set to primary may in fact be disconnected. This has happened for the original submitter of the pull request and it affected these programs: * XMonad: Gets confused with Super + {w,e,r} * SDDM: Puts the login screen on the wrong monitor, and does not currently duplicate the login screen on all monitors * XMobar: Puts the XMobar on the wrong monitor, as it only puts the taskbar on the primary monitor These changes should fix that not only by setting a primary monitor in xrandrHeads but also make it possible to make a different monitor the primary one. The changes are also backwards-compatible.
Diffstat (limited to 'nixos/modules/services/x11')
-rw-r--r-- | nixos/modules/services/x11/xserver.nix | 94 |
1 files changed, 82 insertions, 12 deletions
diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 262115b39e7..09fcdd0b72b 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -31,18 +31,51 @@ let pkgs.xorg.fontadobe75dpi ]; + xrandrOptions = { + output = mkOption { + type = types.str; + example = "DVI-0"; + description = '' + The output name of the monitor, as shown by <citerefentry> + <refentrytitle>xrandr</refentrytitle> + <manvolnum>1</manvolnum> + </citerefentry> invoked without arguments. + ''; + }; + + primary = mkOption { + type = types.bool; + default = false; + description = '' + Whether this head is treated as the primary monitor, + ''; + }; + + monitorConfig = mkOption { + type = types.lines; + default = ""; + example = '' + DisplaySize 408 306 + Option "DPMS" "false" + ''; + description = '' + Extra lines to append to the <literal>Monitor</literal> section + verbatim. + ''; + }; + }; # Just enumerate all heads without discarding XRandR output information. xrandrHeads = let - mkHead = num: output: { + mkHead = num: config: { name = "multihead${toString num}"; - inherit output; + inherit config; }; in imap mkHead cfg.xrandrHeads; xrandrDeviceSection = let monitors = flip map xrandrHeads (h: '' - Option "monitor-${h.output}" "${h.name}" + Option "monitor-${h.config.output}" "${h.name}" ''); # First option is indented through the space in the config but any # subsequent options aren't so we need to apply indentation to @@ -62,9 +95,13 @@ let value = '' Section "Monitor" Identifier "${current.name}" + ${optionalString (current.config.primary) '' + Option "Primary" "true" + ''} ${optionalString (previous != []) '' Option "RightOf" "${(head previous).name}" ''} + ${current.config.monitorConfig} EndSection ''; } ++ previous; @@ -329,13 +366,39 @@ in xrandrHeads = mkOption { default = []; - example = [ "HDMI-0" "DVI-0" ]; - type = with types; listOf string; + example = [ + "HDMI-0" + { output = "DVI-0"; primary = true; } + { output = "DVI-1"; monitorConfig = "Option \"Rotate\" \"left\""; } + ]; + type = with types; listOf (coercedTo str (output: { + inherit output; + }) (submodule { options = xrandrOptions; })); + # Set primary to true for the first head if no other has been set + # primary already. + apply = heads: let + hasPrimary = any (x: x.primary) heads; + firstPrimary = head heads // { primary = true; }; + newHeads = singleton firstPrimary ++ tail heads; + in if heads != [] && !hasPrimary then newHeads else heads; description = '' - Simple multiple monitor configuration, just specify a list of XRandR - outputs which will be mapped from left to right in the order of the + Multiple monitor configuration, just specify a list of XRandR + outputs. The individual elements should be either simple strings or + an attribute set of output options. + + If the element is a string, it is denoting the physical output for a + monitor, if it's an attribute set, you must at least provide the + <option>output</option> option. + + The monitors will be mapped from left to right in the order of the list. + By default, the first monitor will be set as the primary monitor if + none of the elements contain an option that has set + <option>primary</option> to <literal>true</literal>. + + <note><para>Only one monitor is allowed to be primary.</para></note> + Be careful using this option with multiple graphic adapters or with drivers that have poor support for XRandR, unexpected things might happen with those. @@ -469,11 +532,18 @@ in nixpkgs.config.xorg = optionalAttrs (elem "vboxvideo" cfg.videoDrivers) { abiCompat = "1.18"; }; - assertions = - [ { assertion = config.security.polkit.enable; - message = "X11 requires Polkit to be enabled (‘security.polkit.enable = true’)."; - } - ]; + assertions = [ + { assertion = config.security.polkit.enable; + message = "X11 requires Polkit to be enabled (‘security.polkit.enable = true’)."; + } + (let primaryHeads = filter (x: x.primary) cfg.xrandrHeads; in { + assertion = length primaryHeads < 2; + message = "Only one head is allowed to be primary in " + + "‘services.xserver.xrandrHeads’, but there are " + + "${toString (length primaryHeads)} heads set to primary: " + + concatMapStringsSep ", " (x: x.output) primaryHeads; + }) + ]; environment.etc = (optionals cfg.exportConfiguration |