summary refs log tree commit diff
path: root/modules/services/x11/xserver.nix
diff options
context:
space:
mode:
authorCarles Pagès <page@cubata.homelinux.net>2013-01-16 22:53:39 +0100
committerCarles Pagès <page@cubata.homelinux.net>2013-01-16 22:53:39 +0100
commit3965f4608518744a3dec08b458e0f4938b991c2f (patch)
tree79694c444fbad66f92d6341e1f13316d362a5580 /modules/services/x11/xserver.nix
parentab29ea3c3741c51f53ca6447581a6a157abb654f (diff)
parente201da376e510ed96b3b40ac091423a1ea5b5dd4 (diff)
downloadnixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar.gz
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar.bz2
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar.lz
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar.xz
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.tar.zst
nixlib-3965f4608518744a3dec08b458e0f4938b991c2f.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'modules/services/x11/xserver.nix')
-rw-r--r--modules/services/x11/xserver.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/services/x11/xserver.nix b/modules/services/x11/xserver.nix
index 7c9f7552d9cb..239746e1948c 100644
--- a/modules/services/x11/xserver.nix
+++ b/modules/services/x11/xserver.nix
@@ -43,6 +43,36 @@ let
       pkgs.xorg.fontadobe75dpi
     ];
 
+  # Just enumerate all heads without discarding XRandR output information.
+  xrandrHeads = let
+    mkHead = num: output: {
+      name = "multihead${toString num}";
+      inherit output;
+    };
+  in imap mkHead cfg.xrandrHeads;
+
+  xrandrDeviceSection = flip concatMapStrings xrandrHeads (h: ''
+    Option "monitor-${h.output}" "${h.name}"
+  '');
+
+  # Here we chain every monitor from the left to right, so we have:
+  # m4 right of m3 right of m2 right of m1   .----.----.----.----.
+  # Which will end up in reverse ----------> | m1 | m2 | m3 | m4 |
+  #                                          `----^----^----^----'
+  xrandrMonitorSections = let
+    mkMonitor = previous: current: previous ++ singleton {
+      inherit (current) name;
+      value = ''
+        Section "Monitor"
+          Identifier "${current.name}"
+          ${optionalString (previous != []) ''
+          Option "RightOf" "${(head previous).name}"
+          ''}
+        EndSection
+      '';
+    };
+    monitors = foldl mkMonitor [] xrandrHeads;
+  in concatMapStrings (getAttr "value") monitors;
 
   configFile = pkgs.stdenv.mkDerivation {
     name = "xserver.conf";
@@ -256,6 +286,21 @@ in
         description = "Contents of the first Monitor section of the X server configuration file.";
       };
 
+      xrandrHeads = mkOption {
+        default = [];
+        example = [ "HDMI-0" "DVI-0" ];
+        type = with types; listOf string;
+        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
+          list.
+
+          Be careful using this option with multiple graphic adapters or with
+          drivers that have poor support for XRandR, unexpected things might
+          happen with those.
+        '';
+      };
+
       moduleSection = mkOption {
         default = "";
         example =
@@ -515,6 +560,7 @@ in
             Identifier "Device-${driver.name}[0]"
             Driver "${driver.driverName}"
             ${cfg.deviceSection}
+            ${xrandrDeviceSection}
           EndSection
 
           Section "Screen"
@@ -556,6 +602,8 @@ in
 
           EndSection
         '')}
+
+        ${xrandrMonitorSections}
       '';
 
   });