fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Sven Friedrichi3-sway: multiple outputs (#4223)f63b39a6

master
6.4 KiB165 linesraw
1{ cfg, config, lib, moduleName }:
2
3with lib;
4
5rec {
6  criteriaStr = criteria:
7    let
8      toCriteria = k: v:
9        if builtins.isBool v then
10          (if v then "${k}" else "")
11        else
12          ''${k}="${v}"'';
13    in "[${concatStringsSep " " (mapAttrsToList toCriteria criteria)}]";
14
15  keybindingDefaultWorkspace = filterAttrs (n: v:
16    cfg.config.defaultWorkspace != null && v == cfg.config.defaultWorkspace)
17    cfg.config.keybindings;
18
19  keybindingsRest = filterAttrs (n: v:
20    cfg.config.defaultWorkspace == null || v != cfg.config.defaultWorkspace)
21    cfg.config.keybindings;
22
23  keybindingsStr = { keybindings, bindsymArgs ? "", indent ? "" }:
24    concatStringsSep "\n" (mapAttrsToList (keycomb: action:
25      optionalString (action != null) "${indent}bindsym ${
26        lib.optionalString (bindsymArgs != "") "${bindsymArgs} "
27      }${keycomb} ${action}") keybindings);
28
29  keycodebindingsStr = keycodebindings:
30    concatStringsSep "\n" (mapAttrsToList (keycomb: action:
31      optionalString (action != null) "bindcode ${keycomb} ${action}")
32      keycodebindings);
33
34  colorSetStr = c:
35    concatStringsSep " " [
36      c.border
37      c.background
38      c.text
39      c.indicator
40      c.childBorder
41    ];
42  barColorSetStr = c: concatStringsSep " " [ c.border c.background c.text ];
43
44  modeStr = bindkeysToCode: name: keybindings: ''
45    mode "${name}" {
46    ${keybindingsStr {
47      inherit keybindings;
48      bindsymArgs = lib.optionalString bindkeysToCode "--to-code";
49      indent = "  ";
50    }}
51    }
52  '';
53
54  assignStr = workspace: criteria:
55    concatStringsSep "\n"
56    (map (c: "assign ${criteriaStr c} ${workspace}") criteria);
57
58  fontConfigStr = let
59    toFontStr = { names, style ? "", size ? "" }:
60      optionalString (names != [ ]) concatStringsSep " "
61      (remove "" [ "font" "pango:${concatStringsSep ", " names}" style size ]);
62  in fontCfg:
63  if isList fontCfg then
64    toFontStr { names = fontCfg; }
65  else
66    toFontStr {
67      inherit (fontCfg) names style;
68      size = toString fontCfg.size;
69    };
70
71  barStr = { id, fonts, mode, hiddenState, position, workspaceButtons
72    , workspaceNumbers, command, statusCommand, colors, trayOutput, trayPadding
73    , extraConfig, ... }:
74    let colorsNotNull = lib.filterAttrs (n: v: v != null) colors != { };
75    in concatMapStrings (x: x + "\n") (indent (lists.subtractLists [ "" null ]
76      (flatten [
77        "bar {"
78        (optionalString (id != null) "id ${id}")
79        (fontConfigStr fonts)
80        (optionalString (mode != null) "mode ${mode}")
81        (optionalString (hiddenState != null) "hidden_state ${hiddenState}")
82        (optionalString (position != null) "position ${position}")
83        (optionalString (statusCommand != null)
84          "status_command ${statusCommand}")
85        "${moduleName}bar_command ${command}"
86        (optionalString (workspaceButtons != null)
87          "workspace_buttons ${lib.hm.booleans.yesNo workspaceButtons}")
88        (optionalString (workspaceNumbers != null) "strip_workspace_numbers ${
89            lib.hm.booleans.yesNo (!workspaceNumbers)
90          }")
91        (optionalString (trayOutput != null) "tray_output ${trayOutput}")
92        (optionalString (trayPadding != null)
93          "tray_padding ${toString trayPadding}")
94        (optionals colorsNotNull (indent (lists.subtractLists [ "" null ] [
95          "colors {"
96          (optionalString (colors.background != null)
97            "background ${colors.background}")
98          (optionalString (colors.statusline != null)
99            "statusline ${colors.statusline}")
100          (optionalString (colors.separator != null)
101            "separator ${colors.separator}")
102          (optionalString (colors.focusedBackground != null)
103            "focused_background ${colors.focusedBackground}")
104          (optionalString (colors.focusedStatusline != null)
105            "focused_statusline ${colors.focusedStatusline}")
106          (optionalString (colors.focusedSeparator != null)
107            "focused_separator ${colors.focusedSeparator}")
108          (optionalString (colors.focusedWorkspace != null)
109            "focused_workspace ${barColorSetStr colors.focusedWorkspace}")
110          (optionalString (colors.activeWorkspace != null)
111            "active_workspace ${barColorSetStr colors.activeWorkspace}")
112          (optionalString (colors.inactiveWorkspace != null)
113            "inactive_workspace ${barColorSetStr colors.inactiveWorkspace}")
114          (optionalString (colors.urgentWorkspace != null)
115            "urgent_workspace ${barColorSetStr colors.urgentWorkspace}")
116          (optionalString (colors.bindingMode != null)
117            "binding_mode ${barColorSetStr colors.bindingMode}")
118          "}"
119        ]) { }))
120        extraConfig
121        "}"
122      ])) { });
123
124  gapsStr = with cfg.config.gaps;
125    concatStringsSep "\n" (lists.subtractLists [ "" null ] [
126      (optionalString (inner != null) "gaps inner ${toString inner}")
127      (optionalString (outer != null) "gaps outer ${toString outer}")
128      (optionalString (horizontal != null)
129        "gaps horizontal ${toString horizontal}")
130      (optionalString (vertical != null) "gaps vertical ${toString vertical}")
131      (optionalString (top != null) "gaps top ${toString top}")
132      (optionalString (bottom != null) "gaps bottom ${toString bottom}")
133      (optionalString (left != null) "gaps left ${toString left}")
134      (optionalString (right != null) "gaps right ${toString right}")
135      (optionalString smartGaps "smart_gaps on")
136      (optionalString (smartBorders != "off") "smart_borders ${smartBorders}")
137    ]);
138
139  windowBorderString = window: floating:
140    let
141      titlebarString = { titlebar, border, ... }:
142        "${if titlebar then "normal" else "pixel"} ${toString border}";
143    in concatStringsSep "\n" [
144      "default_border ${titlebarString window}"
145      "default_floating_border ${titlebarString floating}"
146    ];
147
148  floatingCriteriaStr = criteria:
149    "for_window ${criteriaStr criteria} floating enable";
150  windowCommandsStr = { command, criteria, ... }:
151    "for_window ${criteriaStr criteria} ${command}";
152  workspaceOutputStr = item:
153    let outputs = concatMapStringsSep " " strings.escapeNixString item.output;
154    in ''workspace "${item.workspace}" output ${outputs}'';
155
156  indent = list:
157    { includesWrapper ? true, level ? 1 }:
158    let prefix = concatStringsSep "" (lib.genList (x: " ") (level * 2));
159
160    in (lib.imap1 (i: v:
161      "${if includesWrapper && (i == 1 || i == (lib.length list)) then
162        v
163      else
164        "${prefix}${v}"}") list);
165}