aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/window-managers/i3-sway/lib/functions.nix
blob: 9391e6e92fc8b5078ecb26c61a64827cb76eb2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{ cfg, lib, moduleName }:

with lib;

rec {
  criteriaStr = criteria:
    "[${
      concatStringsSep " " (mapAttrsToList (k: v: ''${k}="${v}"'') criteria)
    }]";

  keybindingsStr = { keybindings, bindsymArgs ? "" }:
    concatStringsSep "\n" (mapAttrsToList (keycomb: action:
      optionalString (action != null) "bindsym ${
        lib.optionalString (bindsymArgs != "") "${bindsymArgs} "
      }${keycomb} ${action}") keybindings);

  keycodebindingsStr = keycodebindings:
    concatStringsSep "\n" (mapAttrsToList (keycomb: action:
      optionalString (action != null) "bindcode ${keycomb} ${action}")
      keycodebindings);

  colorSetStr = c:
    concatStringsSep " " [
      c.border
      c.background
      c.text
      c.indicator
      c.childBorder
    ];
  barColorSetStr = c: concatStringsSep " " [ c.border c.background c.text ];

  modeStr = name: keybindings: ''
    mode "${name}" {
    ${keybindingsStr { inherit keybindings; }}
    }
  '';

  assignStr = workspace: criteria:
    concatStringsSep "\n"
    (map (c: "assign ${criteriaStr c} ${workspace}") criteria);

  barStr = { id, fonts, mode, hiddenState, position, workspaceButtons
    , workspaceNumbers, command, statusCommand, colors, trayOutput, extraConfig
    , ... }:
    let colorsNotNull = lib.filterAttrs (n: v: v != null) colors != { };
    in ''
      bar {
        ${optionalString (id != null) "id ${id}"}
        ${
          optionalString (fonts != [ ])
          "font pango:${concatStringsSep ", " fonts}"
        }
        ${optionalString (mode != null) "mode ${mode}"}
        ${optionalString (hiddenState != null) "hidden_state ${hiddenState}"}
        ${optionalString (position != null) "position ${position}"}
        ${
          optionalString (statusCommand != null)
          "status_command ${statusCommand}"
        }
        ${moduleName}bar_command ${command}
        ${
          optionalString (workspaceButtons != null)
          "workspace_buttons ${if workspaceButtons then "yes" else "no"}"
        }
        ${
          optionalString (workspaceNumbers != null)
          "strip_workspace_numbers ${if !workspaceNumbers then "yes" else "no"}"
        }
        ${optionalString (trayOutput != null) "tray_output ${trayOutput}"}
        ${optionalString colorsNotNull "colors {"}
          ${
            optionalString (colors.background != null)
            "background ${colors.background}"
          }
          ${
            optionalString (colors.statusline != null)
            "statusline ${colors.statusline}"
          }
          ${
            optionalString (colors.separator != null)
            "separator ${colors.separator}"
          }
          ${
            optionalString (colors.focusedWorkspace != null)
            "focused_workspace ${barColorSetStr colors.focusedWorkspace}"
          }
          ${
            optionalString (colors.activeWorkspace != null)
            "active_workspace ${barColorSetStr colors.activeWorkspace}"
          }
          ${
            optionalString (colors.inactiveWorkspace != null)
            "inactive_workspace ${barColorSetStr colors.inactiveWorkspace}"
          }
          ${
            optionalString (colors.urgentWorkspace != null)
            "urgent_workspace ${barColorSetStr colors.urgentWorkspace}"
          }
          ${
            optionalString (colors.bindingMode != null)
            "binding_mode ${barColorSetStr colors.bindingMode}"
          }
        ${optionalString colorsNotNull "}"}
        ${extraConfig}
      }
    '';

  gapsStr = with cfg.config.gaps; ''
    ${optionalString (inner != null) "gaps inner ${toString inner}"}
    ${optionalString (outer != null) "gaps outer ${toString outer}"}
    ${optionalString (horizontal != null)
    "gaps horizontal ${toString horizontal}"}
    ${optionalString (vertical != null) "gaps vertical ${toString vertical}"}
    ${optionalString (top != null) "gaps top ${toString top}"}
    ${optionalString (bottom != null) "gaps bottom ${toString bottom}"}
    ${optionalString (left != null) "gaps left ${toString left}"}
    ${optionalString (right != null) "gaps right ${toString right}"}

    ${optionalString smartGaps "smart_gaps on"}
    ${optionalString (smartBorders != "off") "smart_borders ${smartBorders}"}
  '';

  floatingCriteriaStr = criteria:
    "for_window ${criteriaStr criteria} floating enable";
  windowCommandsStr = { command, criteria, ... }:
    "for_window ${criteriaStr criteria} ${command}";
}