fork/home-manager

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

Sefa Eyeogluprograms.sway: separate trayOutput values for sway (#4489)e0c70942

master
27.0 KiB931 linesraw
1{ config, lib, moduleName, cfg, pkgs, capitalModuleName ? moduleName }:
2
3with lib;
4
5let
6  isI3 = moduleName == "i3";
7  isSway = !isI3;
8
9  inherit (config.home) stateVersion;
10
11  fontOptions = types.submodule {
12    options = {
13      names = mkOption {
14        type = types.listOf types.str;
15        default = [ "monospace" ];
16        defaultText = literalExpression ''[ "monospace" ]'';
17        description = ''
18          List of font names list used for window titles. Only FreeType fonts are supported.
19          The order here is important (e.g. icons font should go before the one used for text).
20        '';
21        example = literalExpression ''[ "FontAwesome" "Terminus" ]'';
22      };
23
24      style = mkOption {
25        type = types.str;
26        default = "";
27        description = ''
28          The font style to use for window titles.
29        '';
30        example = "Bold Semi-Condensed";
31      };
32
33      size = mkOption {
34        type = types.float;
35        default = 8.0;
36        description = ''
37          The font size to use for window titles.
38        '';
39        example = 11.5;
40      };
41    };
42  };
43
44  startupModule = types.submodule {
45    options = {
46      command = mkOption {
47        type = types.str;
48        description = "Command that will be executed on startup.";
49      };
50
51      always = mkOption {
52        type = types.bool;
53        default = false;
54        description = "Whether to run command on each ${moduleName} restart.";
55      };
56    } // optionalAttrs isI3 {
57      notification = mkOption {
58        type = types.bool;
59        default = true;
60        description = ''
61          Whether to enable startup-notification support for the command.
62          See {option}`--no-startup-id` option description in the i3 user guide.
63        '';
64      };
65
66      workspace = mkOption {
67        type = types.nullOr types.str;
68        default = null;
69        description = ''
70          Launch application on a particular workspace. DEPRECATED:
71          Use [](#opt-xsession.windowManager.i3.config.assigns)
72          instead. See <https://github.com/nix-community/home-manager/issues/265>.
73        '';
74      };
75    };
76
77  };
78
79  barModule = types.submodule {
80    options = let
81      versionAtLeast2009 = versionAtLeast stateVersion "20.09";
82      mkNullableOption = { type, default, ... }@args:
83        mkOption (args // {
84          type = types.nullOr type;
85          default = if versionAtLeast2009 then null else default;
86          defaultText = literalExpression ''
87            null for state version ≥ 20.09, as example otherwise
88          '';
89          example = default;
90        });
91    in {
92      fonts = mkOption {
93        type = with types; either (listOf str) fontOptions;
94        default = { };
95        example = literalExpression ''
96          {
97            names = [ "DejaVu Sans Mono" "FontAwesome5Free" ];
98            style = "Bold Semi-Condensed";
99            size = 11.0;
100          }
101        '';
102        description = "Font configuration for this bar.";
103      };
104
105      extraConfig = mkOption {
106        type = types.lines;
107        default = "";
108        description = "Extra configuration lines for this bar.";
109      };
110
111      id = mkOption {
112        type = types.nullOr types.str;
113        default = null;
114        description = ''
115          Specifies the bar ID for the configured bar instance.
116          If this option is missing, the ID is set to bar-x, where x corresponds
117          to the position of the embedding bar block in the config file.
118        '';
119      };
120
121      mode = mkNullableOption {
122        type = types.enum [ "dock" "hide" "invisible" ];
123        default = "dock";
124        description = "Bar visibility mode.";
125      };
126
127      hiddenState = mkNullableOption {
128        type = types.enum [ "hide" "show" ];
129        default = "hide";
130        description = "The default bar mode when 'bar.mode' == 'hide'.";
131      };
132
133      position = mkNullableOption {
134        type = types.enum [ "top" "bottom" ];
135        default = "bottom";
136        description = "The edge of the screen ${moduleName}bar should show up.";
137      };
138
139      workspaceButtons = mkNullableOption {
140        type = types.bool;
141        default = true;
142        description = "Whether workspace buttons should be shown or not.";
143      };
144
145      workspaceNumbers = mkNullableOption {
146        type = types.bool;
147        default = true;
148        description =
149          "Whether workspace numbers should be displayed within the workspace buttons.";
150      };
151
152      command = mkOption {
153        type = types.str;
154        default = let
155          # If the user uses the "system" Sway (i.e. cfg.package == null) then the bar has
156          # to come from a different package
157          pkg = if isSway && isNull cfg.package then pkgs.sway else cfg.package;
158        in "${pkg}/bin/${moduleName}bar";
159        defaultText = "i3bar";
160        description = "Command that will be used to start a bar.";
161        example = if isI3 then
162          "\${pkgs.i3}/bin/i3bar -t"
163        else
164          "\${pkgs.waybar}/bin/waybar";
165      };
166
167      statusCommand = mkNullableOption {
168        type = types.str;
169        default = "${pkgs.i3status}/bin/i3status";
170        description = "Command that will be used to get status lines.";
171      };
172
173      colors = mkOption {
174        type = types.submodule {
175          options = {
176            background = mkNullableOption {
177              type = types.str;
178              default = "#000000";
179              description = "Background color of the bar.";
180            };
181
182            statusline = mkNullableOption {
183              type = types.str;
184              default = "#ffffff";
185              description = "Text color to be used for the statusline.";
186            };
187
188            separator = mkNullableOption {
189              type = types.str;
190              default = "#666666";
191              description = "Text color to be used for the separator.";
192            };
193
194            focusedBackground = mkOption {
195              type = types.nullOr types.str;
196              default = null;
197              description =
198                "Background color of the bar on the currently focused monitor output.";
199              example = "#000000";
200            };
201
202            focusedStatusline = mkOption {
203              type = types.nullOr types.str;
204              default = null;
205              description =
206                "Text color to be used for the statusline on the currently focused monitor output.";
207              example = "#ffffff";
208            };
209
210            focusedSeparator = mkOption {
211              type = types.nullOr types.str;
212              default = null;
213              description =
214                "Text color to be used for the separator on the currently focused monitor output.";
215              example = "#666666";
216            };
217
218            focusedWorkspace = mkNullableOption {
219              type = barColorSetModule;
220              default = {
221                border = "#4c7899";
222                background = "#285577";
223                text = "#ffffff";
224              };
225              description = ''
226                Border, background and text color for a workspace button when the workspace has focus.
227              '';
228            };
229
230            activeWorkspace = mkNullableOption {
231              type = barColorSetModule;
232              default = {
233                border = "#333333";
234                background = "#5f676a";
235                text = "#ffffff";
236              };
237              description = ''
238                Border, background and text color for a workspace button when the workspace is active.
239              '';
240            };
241
242            inactiveWorkspace = mkNullableOption {
243              type = barColorSetModule;
244              default = {
245                border = "#333333";
246                background = "#222222";
247                text = "#888888";
248              };
249              description = ''
250                Border, background and text color for a workspace button when the workspace does not
251                have focus and is not active.
252              '';
253            };
254
255            urgentWorkspace = mkNullableOption {
256              type = barColorSetModule;
257              default = {
258                border = "#2f343a";
259                background = "#900000";
260                text = "#ffffff";
261              };
262              description = ''
263                Border, background and text color for a workspace button when the workspace contains
264                a window with the urgency hint set.
265              '';
266            };
267
268            bindingMode = mkNullableOption {
269              type = barColorSetModule;
270              default = {
271                border = "#2f343a";
272                background = "#900000";
273                text = "#ffffff";
274              };
275              description =
276                "Border, background and text color for the binding mode indicator";
277            };
278          };
279        };
280        default = { };
281        description = ''
282          Bar color settings. All color classes can be specified using submodules
283          with 'border', 'background', 'text', fields and RGB color hex-codes as values.
284          See default values for the reference.
285          Note that 'background', 'status', and 'separator' parameters take a single RGB value.
286
287          See <https://i3wm.org/docs/userguide.html#_colors>.
288        '';
289      };
290
291      trayOutput = mkNullableOption {
292        type = types.str;
293        # Sway/Wayland doesn't have the concept of a primary output. The default for sway is to show it on all outputs
294        default = if isI3 then "primary" else "*";
295        description = "Where to output tray.";
296      };
297
298      trayPadding = mkNullableOption {
299        type = types.int;
300        default = null;
301        description = ''
302          Sets the pixel padding of the system tray.
303          This padding will surround the tray on all sides and between each item.
304        '';
305      };
306    };
307  };
308
309  barColorSetModule = types.submodule {
310    options = {
311      border = mkOption {
312        type = types.str;
313        visible = false;
314      };
315
316      background = mkOption {
317        type = types.str;
318        visible = false;
319      };
320
321      text = mkOption {
322        type = types.str;
323        visible = false;
324      };
325    };
326  };
327
328  colorSetModule = types.submodule {
329    options = {
330      border = mkOption {
331        type = types.str;
332        visible = false;
333      };
334
335      childBorder = mkOption {
336        type = types.str;
337        visible = false;
338      };
339
340      background = mkOption {
341        type = types.str;
342        visible = false;
343      };
344
345      text = mkOption {
346        type = types.str;
347        visible = false;
348      };
349
350      indicator = mkOption {
351        type = types.str;
352        visible = false;
353      };
354    };
355  };
356
357  windowCommandModule = types.submodule {
358    options = {
359      command = mkOption {
360        type = types.str;
361        description = "${capitalModuleName}wm command to execute.";
362        example = "border pixel 1";
363      };
364
365      criteria = mkOption {
366        type = criteriaModule;
367        description = ''
368          Criteria of the windows on which command should be executed.
369
370          A value of `true` is equivalent to using an empty
371          criteria (which is different from an empty string criteria).
372        '';
373        example = literalExpression ''
374          {
375            title = "x200: ~/work";
376            floating = true;
377          };
378        '';
379      };
380    };
381  };
382
383  criteriaModule = types.attrsOf (types.either types.str types.bool);
384in {
385  fonts = mkOption {
386    type = with types; either (listOf str) fontOptions;
387    default = { };
388    example = literalExpression ''
389      {
390        names = [ "DejaVu Sans Mono" "FontAwesome5Free" ];
391        style = "Bold Semi-Condensed";
392        size = 11.0;
393      }
394    '';
395    description = "Font configuration for window titles, nagbar...";
396  };
397
398  window = mkOption {
399    type = types.submodule {
400      options = {
401        titlebar = mkOption {
402          type = types.bool;
403          default = if versionOlder stateVersion "23.05" then
404            (isI3 && (cfg.config.gaps == null))
405          else
406            true;
407          defaultText = if isI3 then ''
408            true for state version ≥ 23.05
409            config.gaps == null for state version < 23.05
410          '' else ''
411            true for state version ≥ 23.05
412            false for state version < 23.05
413          '';
414          description = "Whether to show window titlebars.";
415        };
416
417        border = mkOption {
418          type = types.int;
419          default = 2;
420          description = "Window border width.";
421        };
422
423        hideEdgeBorders = mkOption {
424          type = types.enum [ "none" "vertical" "horizontal" "both" "smart" ];
425          default = "none";
426          description = "Hide window borders adjacent to the screen edges.";
427        };
428
429        commands = mkOption {
430          type = types.listOf windowCommandModule;
431          default = [ ];
432          description = ''
433            List of commands that should be executed on specific windows.
434            See {option}`for_window` ${moduleName}wm option documentation.
435          '';
436          example = [{
437            command = "border pixel 1";
438            criteria = { class = "XTerm"; };
439          }];
440        };
441      };
442    };
443    default = { };
444    description = "Window titlebar and border settings.";
445  };
446
447  floating = mkOption {
448    type = types.submodule {
449      options = {
450        titlebar = mkOption {
451          type = types.bool;
452          default = if versionOlder stateVersion "23.05" then
453            (isI3 && (cfg.config.gaps == null))
454          else
455            true;
456          defaultText = if isI3 then ''
457            true for state version ≥ 23.05
458            config.gaps == null for state version < 23.05
459          '' else ''
460            true for state version ≥ 23.05
461            false for state version < 23.05
462          '';
463          description = "Whether to show floating window titlebars.";
464        };
465
466        border = mkOption {
467          type = types.int;
468          default = 2;
469          description = "Floating windows border width.";
470        };
471
472        modifier = mkOption {
473          type = types.str;
474          default = cfg.config.modifier;
475          defaultText = "${moduleName}.config.modifier";
476          description =
477            "Modifier key or keys that can be used to drag floating windows.";
478          example = "Mod4";
479        };
480
481        criteria = mkOption {
482          type = types.listOf criteriaModule;
483          default = [ ];
484          description =
485            "List of criteria for windows that should be opened in a floating mode.";
486          example = [
487            { "title" = "Steam - Update News"; }
488            { "class" = "Pavucontrol"; }
489          ];
490        };
491      };
492    };
493    default = { };
494    description = "Floating window settings.";
495  };
496
497  focus = mkOption {
498    type = types.submodule {
499      options = {
500        newWindow = mkOption {
501          type = types.enum [ "smart" "urgent" "focus" "none" ];
502          default = "smart";
503          description = ''
504            This option modifies focus behavior on new window activation.
505
506            See <https://i3wm.org/docs/userguide.html#focus_on_window_activation>
507          '';
508          example = "none";
509        };
510
511        followMouse = mkOption {
512          type = if isSway then
513            types.either (types.enum [ "yes" "no" "always" ]) types.bool
514          else
515            types.bool;
516          default = if isSway then "yes" else true;
517          description = "Whether focus should follow the mouse.";
518          apply = val:
519            if (isSway && isBool val) then (lib.hm.booleans.yesNo val) else val;
520        };
521
522        wrapping = mkOption {
523          type = types.enum [ "yes" "no" "force" "workspace" ];
524          default = {
525            i3 = if cfg.config.focus.forceWrapping then "force" else "yes";
526            # the sway module's logic was inverted and incorrect,
527            # so preserve it for backwards compatibility purposes
528            sway = if cfg.config.focus.forceWrapping then "yes" else "no";
529          }.${moduleName};
530          description = ''
531            Whether the window focus commands automatically wrap around the edge of containers.
532
533            See <https://i3wm.org/docs/userguide.html#_focus_wrapping>
534          '';
535        };
536
537        forceWrapping = mkOption {
538          type = types.bool;
539          default = false;
540          description = ''
541            Whether to force focus wrapping in tabbed or stacked containers.
542
543            This option is deprecated, use {option}`focus.wrapping` instead.
544          '';
545        };
546
547        mouseWarping = mkOption {
548          type = if isSway then
549            types.oneOf [ types.bool (types.enum [ "container" "output" ]) ]
550          else
551            types.bool;
552          default = true;
553          description = ''
554            Whether mouse cursor should be warped to the center of the window when switching focus
555            to a window on a different output.
556          '';
557        };
558      };
559    };
560    default = { };
561    description = "Focus related settings.";
562  };
563
564  assigns = mkOption {
565    type = types.attrsOf (types.listOf criteriaModule);
566    default = { };
567    description = ''
568      An attribute set that assigns applications to workspaces based
569      on criteria.
570    '';
571    example = literalExpression ''
572      {
573      "1: web" = [{ class = "^Firefox$"; }];
574      "0: extra" = [{ class = "^Firefox$"; window_role = "About"; }];
575      }
576    '';
577  };
578
579  modifier = mkOption {
580    type = types.enum [ "Shift" "Control" "Mod1" "Mod2" "Mod3" "Mod4" "Mod5" ];
581    default = "Mod1";
582    description = "Modifier key that is used for all default keybindings.";
583    example = "Mod4";
584  };
585
586  workspaceLayout = mkOption {
587    type = types.enum [ "default" "stacking" "tabbed" ];
588    default = "default";
589    example = "tabbed";
590    description = ''
591      The mode in which new containers on workspace level will
592      start.
593    '';
594  };
595
596  workspaceAutoBackAndForth = mkOption {
597    type = types.bool;
598    default = false;
599    example = true;
600    description = ''
601      Assume you are on workspace "1: www" and switch to "2: IM" using
602      mod+2 because somebody sent you a message. You don’t need to remember
603      where you came from now, you can just press $mod+2 again to switch
604      back to "1: www".
605    '';
606  };
607
608  keycodebindings = mkOption {
609    type = types.attrsOf (types.nullOr types.str);
610    default = { };
611    description = ''
612      An attribute set that assigns keypress to an action using key code.
613      See <https://i3wm.org/docs/userguide.html#keybindings>.
614    '';
615    example = { "214" = "exec /bin/script.sh"; };
616  };
617
618  colors = mkOption {
619    type = types.submodule {
620      options = {
621        background = mkOption {
622          type = types.str;
623          default = "#ffffff";
624          description = ''
625            Background color of the window. Only applications which do not cover
626            the whole area expose the color.
627          '';
628        };
629
630        focused = mkOption {
631          type = colorSetModule;
632          default = {
633            border = "#4c7899";
634            background = "#285577";
635            text = "#ffffff";
636            indicator = "#2e9ef4";
637            childBorder = "#285577";
638          };
639          description = "A window which currently has the focus.";
640        };
641
642        focusedInactive = mkOption {
643          type = colorSetModule;
644          default = {
645            border = "#333333";
646            background = "#5f676a";
647            text = "#ffffff";
648            indicator = "#484e50";
649            childBorder = "#5f676a";
650          };
651          description = ''
652            A window which is the focused one of its container,
653            but it does not have the focus at the moment.
654          '';
655        };
656
657        unfocused = mkOption {
658          type = colorSetModule;
659          default = {
660            border = "#333333";
661            background = "#222222";
662            text = "#888888";
663            indicator = "#292d2e";
664            childBorder = "#222222";
665          };
666          description = "A window which is not focused.";
667        };
668
669        urgent = mkOption {
670          type = colorSetModule;
671          default = {
672            border = "#2f343a";
673            background = "#900000";
674            text = "#ffffff";
675            indicator = "#900000";
676            childBorder = "#900000";
677          };
678          description = "A window which has its urgency hint activated.";
679        };
680
681        placeholder = mkOption {
682          type = colorSetModule;
683          default = {
684            border = "#000000";
685            background = "#0c0c0c";
686            text = "#ffffff";
687            indicator = "#000000";
688            childBorder = "#0c0c0c";
689          };
690          description = ''
691            Background and text color are used to draw placeholder window
692            contents (when restoring layouts). Border and indicator are ignored.
693          '';
694        };
695      };
696    };
697    default = { };
698    description = ''
699      Color settings. All color classes can be specified using submodules
700      with 'border', 'background', 'text', 'indicator' and 'childBorder' fields
701      and RGB color hex-codes as values. See default values for the reference.
702      Note that '${moduleName}.config.colors.background' parameter takes a single RGB value.
703
704      See <https://i3wm.org/docs/userguide.html#_changing_colors>.
705    '';
706  };
707
708  bars = mkOption {
709    type = types.listOf barModule;
710    default = if versionAtLeast stateVersion "20.09" then [{
711      mode = "dock";
712      hiddenState = "hide";
713      position = "bottom";
714      workspaceButtons = true;
715      workspaceNumbers = true;
716      statusCommand = "${pkgs.i3status}/bin/i3status";
717      fonts = {
718        names = [ "monospace" ];
719        size = 8.0;
720      };
721      trayOutput = "primary";
722      colors = {
723        background = "#000000";
724        statusline = "#ffffff";
725        separator = "#666666";
726        focusedWorkspace = {
727          border = "#4c7899";
728          background = "#285577";
729          text = "#ffffff";
730        };
731        activeWorkspace = {
732          border = "#333333";
733          background = "#5f676a";
734          text = "#ffffff";
735        };
736        inactiveWorkspace = {
737          border = "#333333";
738          background = "#222222";
739          text = "#888888";
740        };
741        urgentWorkspace = {
742          border = "#2f343a";
743          background = "#900000";
744          text = "#ffffff";
745        };
746        bindingMode = {
747          border = "#2f343a";
748          background = "#900000";
749          text = "#ffffff";
750        };
751      };
752    }] else
753      [ { } ];
754    defaultText = literalExpression "see code";
755    description = ''
756      ${capitalModuleName} bars settings blocks. Set to empty list to remove bars completely.
757    '';
758  };
759
760  startup = mkOption {
761    type = types.listOf startupModule;
762    default = [ ];
763    description = ''
764      Commands that should be executed at startup.
765
766      See <https://i3wm.org/docs/userguide.html#_automatically_starting_applications_on_i3_startup>.
767    '';
768    example = if isI3 then
769      literalExpression ''
770        [
771        { command = "systemctl --user restart polybar"; always = true; notification = false; }
772        { command = "dropbox start"; notification = false; }
773        { command = "firefox"; }
774        ];
775      ''
776    else
777      literalExpression ''
778        [
779        { command = "systemctl --user restart waybar"; always = true; }
780        { command = "dropbox start"; }
781        { command = "firefox"; }
782        ]
783      '';
784  };
785
786  gaps = mkOption {
787    type = types.nullOr (types.submodule {
788      options = {
789        inner = mkOption {
790          type = types.nullOr types.int;
791          default = null;
792          description = "Inner gaps value.";
793          example = 12;
794        };
795
796        outer = mkOption {
797          type = types.nullOr types.int;
798          default = null;
799          description = "Outer gaps value.";
800          example = 5;
801        };
802
803        horizontal = mkOption {
804          type = types.nullOr types.int;
805          default = null;
806          description = "Horizontal gaps value.";
807          example = 5;
808        };
809
810        vertical = mkOption {
811          type = types.nullOr types.int;
812          default = null;
813          description = "Vertical gaps value.";
814          example = 5;
815        };
816
817        top = mkOption {
818          type = types.nullOr types.int;
819          default = null;
820          description = "Top gaps value.";
821          example = 5;
822        };
823
824        left = mkOption {
825          type = types.nullOr types.int;
826          default = null;
827          description = "Left gaps value.";
828          example = 5;
829        };
830
831        bottom = mkOption {
832          type = types.nullOr types.int;
833          default = null;
834          description = "Bottom gaps value.";
835          example = 5;
836        };
837
838        right = mkOption {
839          type = types.nullOr types.int;
840          default = null;
841          description = "Right gaps value.";
842          example = 5;
843        };
844
845        smartGaps = mkOption {
846          type = types.bool;
847          default = false;
848          description = ''
849            This option controls whether to disable all gaps (outer and inner)
850            on workspace with a single container.
851          '';
852          example = true;
853        };
854
855        smartBorders = mkOption {
856          type = types.enum [ "on" "off" "no_gaps" ];
857          default = "off";
858          description = ''
859            This option controls whether to disable container borders on
860            workspace with a single container.
861          '';
862        };
863      };
864    });
865    default = null;
866    description = ''
867      Gaps related settings.
868    '';
869  };
870
871  terminal = mkOption {
872    type = types.str;
873    default = if isI3 then "i3-sensible-terminal" else "${pkgs.foot}/bin/foot";
874    description = "Default terminal to run.";
875    example = "alacritty";
876  };
877
878  menu = mkOption {
879    type = types.str;
880    default = if isSway then
881      "${pkgs.dmenu}/bin/dmenu_path | ${pkgs.dmenu}/bin/dmenu | ${pkgs.findutils}/bin/xargs swaymsg exec --"
882    else
883      "${pkgs.dmenu}/bin/dmenu_run";
884    description = "Default launcher to use.";
885    example = "bemenu-run";
886  };
887
888  defaultWorkspace = mkOption {
889    type = types.nullOr types.str;
890    default = null;
891    description = ''
892      The default workspace to show when ${
893        if isSway then "sway" else "i3"
894      } is launched.
895      This must to correspond to the value of the keybinding of the default workspace.
896    '';
897    example = "workspace number 9";
898  };
899
900  workspaceOutputAssign = mkOption {
901    type = with types;
902      let
903        workspaceOutputOpts = submodule {
904          options = {
905            workspace = mkOption {
906              type = str;
907              default = "";
908              example = "Web";
909              description = ''
910                Name of the workspace to assign.
911              '';
912            };
913
914            output = mkOption {
915              type = with types; either str (listOf str);
916              default = "";
917              apply = lists.toList;
918              example = "eDP";
919              description = ''
920                Name(s) of the output(s) from {command}`
921                  ${if isSway then "swaymsg" else "i3-msg"} -t get_outputs
922                `.
923              '';
924            };
925          };
926        };
927      in listOf workspaceOutputOpts;
928    default = [ ];
929    description = "Assign workspaces to outputs.";
930  };
931}