aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAlex Rice <alexrice999@hotmail.co.uk>2020-07-13 12:31:55 +0100
committerRobert Helgesson <robert@rycee.net>2020-08-26 00:05:05 +0200
commit0869e237007aa48f458c9d9ba9080280565a7160 (patch)
treeba335b0301fc5f9f8b0620295d97c73d0154abdf /modules
parent625b92cbba26852d80eb9a221f93cad0c4efa17b (diff)
sway: set bar defaults to null
Allows fields of bar to be nullable and omit them from the generated configuration if unset. Fixes #1361 PR #1386
Diffstat (limited to 'modules')
-rw-r--r--modules/services/window-managers/i3-sway/i3.nix2
-rw-r--r--modules/services/window-managers/i3-sway/lib/functions.nix69
-rw-r--r--modules/services/window-managers/i3-sway/lib/options.nix96
-rw-r--r--modules/services/window-managers/i3-sway/sway.nix2
4 files changed, 131 insertions, 38 deletions
diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix
index 540025055c3..f7124e6fd23 100644
--- a/modules/services/window-managers/i3-sway/i3.nix
+++ b/modules/services/window-managers/i3-sway/i3.nix
@@ -7,7 +7,7 @@ let
cfg = config.xsession.windowManager.i3;
commonOptions = import ./lib/options.nix {
- inherit lib cfg pkgs;
+ inherit config lib cfg pkgs;
moduleName = "i3";
isGaps = cfg.package == pkgs.i3-gaps;
};
diff --git a/modules/services/window-managers/i3-sway/lib/functions.nix b/modules/services/window-managers/i3-sway/lib/functions.nix
index ea2938e6f6e..9391e6e92fc 100644
--- a/modules/services/window-managers/i3-sway/lib/functions.nix
+++ b/modules/services/window-managers/i3-sway/lib/functions.nix
@@ -41,31 +41,66 @@ rec {
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}"}
- font pango:${concatStringsSep ", " fonts}
- mode ${mode}
- hidden_state ${hiddenState}
- position ${position}
+ ${
+ 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}
- workspace_buttons ${if workspaceButtons then "yes" else "no"}
- strip_workspace_numbers ${if !workspaceNumbers then "yes" else "no"}
- tray_output ${trayOutput}
- colors {
- background ${colors.background}
- statusline ${colors.statusline}
- separator ${colors.separator}
- focused_workspace ${barColorSetStr colors.focusedWorkspace}
- active_workspace ${barColorSetStr colors.activeWorkspace}
- inactive_workspace ${barColorSetStr colors.inactiveWorkspace}
- urgent_workspace ${barColorSetStr colors.urgentWorkspace}
- binding_mode ${barColorSetStr colors.bindingMode}
+ ${
+ 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}
}
'';
diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix
index b5216f8ca1c..edfdcd4feae 100644
--- a/modules/services/window-managers/i3-sway/lib/options.nix
+++ b/modules/services/window-managers/i3-sway/lib/options.nix
@@ -1,4 +1,5 @@
-{ lib, moduleName, cfg, pkgs, capitalModuleName ? moduleName, isGaps ? true }:
+{ config, lib, moduleName, cfg, pkgs, capitalModuleName ? moduleName
+, isGaps ? true }:
with lib;
@@ -49,8 +50,23 @@ let
};
barModule = types.submodule {
- options = {
- inherit fonts;
+ options = let
+ versionAtLeast2009 = versionAtLeast config.home.stateVersion "20.09";
+ mkNullableOption = { type, default, ... }@args:
+ mkOption (args // optionalAttrs versionAtLeast2009 {
+ type = types.nullOr type;
+ default = null;
+ example = default;
+ } // {
+ defaultText = literalExample ''
+ ${
+ if isString default then default else "See code"
+ } for state version < 20.09,
+ null for state version ≥ 20.09
+ '';
+ });
+ in {
+ fonts = fonts // optionalAttrs versionAtLeast2009 { default = [ ]; };
extraConfig = mkOption {
type = types.lines;
@@ -68,31 +84,31 @@ let
'';
};
- mode = mkOption {
+ mode = mkNullableOption {
type = types.enum [ "dock" "hide" "invisible" ];
default = "dock";
description = "Bar visibility mode.";
};
- hiddenState = mkOption {
+ hiddenState = mkNullableOption {
type = types.enum [ "hide" "show" ];
default = "hide";
description = "The default bar mode when 'bar.mode' == 'hide'.";
};
- position = mkOption {
+ position = mkNullableOption {
type = types.enum [ "top" "bottom" ];
default = "bottom";
description = "The edge of the screen ${moduleName}bar should show up.";
};
- workspaceButtons = mkOption {
+ workspaceButtons = mkNullableOption {
type = types.bool;
default = true;
description = "Whether workspace buttons should be shown or not.";
};
- workspaceNumbers = mkOption {
+ workspaceNumbers = mkNullableOption {
type = types.bool;
default = true;
description =
@@ -112,32 +128,34 @@ let
statusCommand = mkOption {
type = types.nullOr types.str;
- default = "${pkgs.i3status}/bin/i3status";
+ default =
+ if versionAtLeast2009 then null else "${pkgs.i3status}/bin/i3status";
+ example = "i3status";
description = "Command that will be used to get status lines.";
};
colors = mkOption {
type = types.submodule {
options = {
- background = mkOption {
+ background = mkNullableOption {
type = types.str;
default = "#000000";
description = "Background color of the bar.";
};
- statusline = mkOption {
+ statusline = mkNullableOption {
type = types.str;
default = "#ffffff";
description = "Text color to be used for the statusline.";
};
- separator = mkOption {
+ separator = mkNullableOption {
type = types.str;
default = "#666666";
description = "Text color to be used for the separator.";
};
- focusedWorkspace = mkOption {
+ focusedWorkspace = mkNullableOption {
type = barColorSetModule;
default = {
border = "#4c7899";
@@ -149,7 +167,7 @@ let
'';
};
- activeWorkspace = mkOption {
+ activeWorkspace = mkNullableOption {
type = barColorSetModule;
default = {
border = "#333333";
@@ -161,7 +179,7 @@ let
'';
};
- inactiveWorkspace = mkOption {
+ inactiveWorkspace = mkNullableOption {
type = barColorSetModule;
default = {
border = "#333333";
@@ -174,7 +192,7 @@ let
'';
};
- urgentWorkspace = mkOption {
+ urgentWorkspace = mkNullableOption {
type = barColorSetModule;
default = {
border = "#2f343a";
@@ -187,7 +205,7 @@ let
'';
};
- bindingMode = mkOption {
+ bindingMode = mkNullableOption {
type = barColorSetModule;
default = {
border = "#2f343a";
@@ -210,7 +228,7 @@ let
'';
};
- trayOutput = mkOption {
+ trayOutput = mkNullableOption {
type = types.str;
default = "primary";
description = "Where to output tray.";
@@ -573,7 +591,47 @@ in {
bars = mkOption {
type = types.listOf barModule;
- default = [ { } ];
+ default = if versionAtLeast config.home.stateVersion "20.09" then [{
+ mode = "dock";
+ hiddenState = "hide";
+ position = "bottom";
+ workspaceButtons = true;
+ workspaceNumbers = true;
+ statusCommand = "${pkgs.i3status}/bin/i3status";
+ fonts = [ "monospace 8" ];
+ trayOutput = "primary";
+ colors = {
+ background = "#000000";
+ statusline = "#ffffff";
+ separator = "#666666";
+ focusedWorkspace = {
+ border = "#4c7899";
+ background = "#285577";
+ text = "#ffffff";
+ };
+ activeWorkspace = {
+ border = "#333333";
+ background = "#5f676a";
+ text = "#ffffff";
+ };
+ inactiveWorkspace = {
+ border = "#333333";
+ background = "#222222";
+ text = "#888888";
+ };
+ urgentWorkspace = {
+ border = "#2f343a";
+ background = "#900000";
+ text = "#ffffff";
+ };
+ bindingMode = {
+ border = "#2f343a";
+ background = "#900000";
+ text = "#ffffff";
+ };
+ };
+ }] else
+ [ { } ];
description = ''
${capitalModuleName} bars settings blocks. Set to empty list to remove bars completely.
'';
diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix
index 83c8afd6c46..8f0ee608104 100644
--- a/modules/services/window-managers/i3-sway/sway.nix
+++ b/modules/services/window-managers/i3-sway/sway.nix
@@ -7,7 +7,7 @@ let
cfg = config.wayland.windowManager.sway;
commonOptions = import ./lib/options.nix {
- inherit lib cfg pkgs;
+ inherit config lib cfg pkgs;
moduleName = "sway";
capitalModuleName = "Sway";
};