about summary refs log tree commit diff
path: root/modules/i3/default.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2014-07-14 22:47:14 +0200
committeraszlig <aszlig@redmoonstudios.org>2014-07-14 22:47:14 +0200
commit1018cd7cc704f08e3329cb758a73e6da98d4e087 (patch)
tree7ee1659af7cce5cbd5d0f6c0236b10fac3edb87c /modules/i3/default.nix
parentc65f5ba3a7eb43e01f098d63f8d22cdc1e78d8bd (diff)
i3: Add NixOS options to configure workspaces.
This allows for a more dynamic workspace assignments, especially when
varying between the number of heads. We now not only can use the NixOS
module system to set workspaces but also assign applications to them.

And the default workspace layout is to evenly spread out the heads among
the available heads.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules/i3/default.nix')
-rw-r--r--modules/i3/default.nix69
1 files changed, 52 insertions, 17 deletions
diff --git a/modules/i3/default.nix b/modules/i3/default.nix
index 86ba462c..2c668cc4 100644
--- a/modules/i3/default.nix
+++ b/modules/i3/default.nix
@@ -1,9 +1,56 @@
-{ pkgs, config, ... }:
+{ pkgs, lib, config, ... }:
 
-with pkgs.lib;
+with lib;
 
+let
+  # The symbols if you press shift and a number key.
+  wsNumberSymbols = [
+    "exclam" "at" "numbersign" "dollar" "percent"
+    "asciicircum" "ampersand" "asterisk" "parenleft" "parenright"
+  ];
+
+  wsCount = length wsNumberSymbols;
+
+  headCount = length config.services.xserver.xrandrHeads;
+  wsPerHead = wsCount / headCount;
+  excessWs = wsCount - (headCount * wsPerHead);
+  getHeadAt = elemAt config.services.xserver.xrandrHeads;
+
+  mkDefaultWorkspace = number: numberSymbol: {
+    name = toString number;
+    value = mkDefault {
+      label = null;
+      labelPrefix = "${toString number}: ";
+      keys.switchTo = "$mod+${toString number}";
+      keys.moveTo = "$mod+Shift+${numberSymbol}";
+      head = getHeadAt ((number - (excessWs + 1)) / wsPerHead);
+    };
+  };
+
+  wsCfgList = mapAttrsToList (_: getAttr "config") config.aszlig.i3.workspaces;
+  wsConfig = concatStrings wsCfgList;
+  defaultWorkspaces = listToAttrs (imap mkDefaultWorkspace wsNumberSymbols);
+in
 {
-  services.xserver.windowManager = {
+  options.aszlig.i3 = {
+    workspaces = mkOption {
+      type = types.attrsOf (types.submodule ./workspace.nix);
+      default = listToAttrs (imap mkDefaultWorkspace wsNumberSymbols);
+      description = ''
+        Workspace to monitor assignment.
+
+        Workspaces are by default assigned starting from the leftmost monitor
+        being workspace 1 and the rightmost monitor being workspace 10. The
+        workspaces are divided by the number of available heads, so if you have
+        a dual head system, you'll end up having workspace 1 to 5 on the left
+        monitor and 6 to 10 on the right.
+      '';
+    };
+  };
+
+  config.aszlig.i3.workspaces = defaultWorkspaces;
+
+  config.services.xserver.windowManager = {
     default = "i3";
 
     i3.enable = true;
@@ -17,6 +64,7 @@ with pkgs.lib;
 
       inherit (pkgs) dmenu xterm pvolctrl;
       inherit (pkgs.xorg) xsetroot;
+      inherit wsConfig;
 
       leftHead = head config.services.xserver.xrandrHeads;
       rightHead = last config.services.xserver.xrandrHeads;
@@ -30,19 +78,6 @@ with pkgs.lib;
     in if config.networking.hostName == "mmrnmhrm"
        then { inherit leftHead rightHead; }
        else { leftHead = rightHead; rightHead = leftHead; }
-    ) // (let
-      wsConfig = if config.networking.hostName == "mmrnmhrm"
-                 then [ "XMPP" null "chromium" null null
-                        null   null null       null null ]
-                 else [ null       null null null null
-                        "chromium" null null null null ];
-
-      mkWsName = num: name: let
-        mkPair = nameValuePair "ws${toString num}";
-      in if name == null
-         then mkPair (toString num)
-         else mkPair "${toString num}: ${name}";
-
-    in listToAttrs (imap mkWsName wsConfig)));
+    ));
   };
 }