From 13e866fd94bd1d1ab31c06aff9a1e2d28b603cdc Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Tue, 22 Jun 2021 18:02:42 +0300 Subject: [PATCH] i3,sway: add bar color options for the focused output Both i3bar and swaybar can use different colors for the bar on the currently focused monitor output; add color options for this feature. --- .../window-managers/i3-sway/lib/functions.nix | 12 ++ .../window-managers/i3-sway/lib/options.nix | 24 ++++ .../services/window-managers/i3/default.nix | 1 + .../i3/i3-bar-focused-colors-expected.conf | 110 +++++++++++++++++ .../i3/i3-bar-focused-colors.nix | 25 ++++ .../i3/i3-followmouse-expected.conf | 3 + .../window-managers/i3/i3-fonts-expected.conf | 3 + .../i3/i3-keybindings-expected.conf | 3 + .../i3/i3-workspace-default-expected.conf | 3 + .../i3/i3-workspace-output-expected.conf | 3 + .../services/window-managers/sway/default.nix | 1 + .../sway/sway-bar-focused-colors.conf | 114 ++++++++++++++++++ .../sway/sway-bar-focused-colors.nix | 32 +++++ .../window-managers/sway/sway-default.conf | 3 + .../window-managers/sway/sway-modules.conf | 3 + .../sway/sway-null-package.conf | 3 + .../sway/sway-workspace-default-expected.conf | 3 + .../sway/sway-workspace-output-expected.conf | 3 + 18 files changed, 349 insertions(+) create mode 100644 tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf create mode 100644 tests/modules/services/window-managers/i3/i3-bar-focused-colors.nix create mode 100644 tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf create mode 100644 tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix diff --git a/modules/services/window-managers/i3-sway/lib/functions.nix b/modules/services/window-managers/i3-sway/lib/functions.nix index bb5958574a52..1317f5dbb7b9 100644 --- a/modules/services/window-managers/i3-sway/lib/functions.nix +++ b/modules/services/window-managers/i3-sway/lib/functions.nix @@ -102,6 +102,18 @@ rec { optionalString (colors.separator != null) "separator ${colors.separator}" } + ${ + optionalString (colors.focusedBackground != null) + "focused_background ${colors.focusedBackground}" + } + ${ + optionalString (colors.focusedStatusline != null) + "focused_statusline ${colors.focusedStatusline}" + } + ${ + optionalString (colors.focusedSeparator != null) + "focused_separator ${colors.focusedSeparator}" + } ${ optionalString (colors.focusedWorkspace != null) "focused_workspace ${barColorSetStr colors.focusedWorkspace}" diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix index 08882d7c4c76..af72f2e6bd44 100644 --- a/modules/services/window-managers/i3-sway/lib/options.nix +++ b/modules/services/window-managers/i3-sway/lib/options.nix @@ -190,6 +190,30 @@ let description = "Text color to be used for the separator."; }; + focusedBackground = mkOption { + type = types.nullOr types.str; + default = null; + description = + "Background color of the bar on the currently focused monitor output."; + example = "#000000"; + }; + + focusedStatusline = mkOption { + type = types.nullOr types.str; + default = null; + description = + "Text color to be used for the statusline on the currently focused monitor output."; + example = "#ffffff"; + }; + + focusedSeparator = mkOption { + type = types.nullOr types.str; + default = null; + description = + "Text color to be used for the separator on the currently focused monitor output."; + example = "#666666"; + }; + focusedWorkspace = mkNullableOption { type = barColorSetModule; default = { diff --git a/tests/modules/services/window-managers/i3/default.nix b/tests/modules/services/window-managers/i3/default.nix index f51260821886..28631a1a5a27 100644 --- a/tests/modules/services/window-managers/i3/default.nix +++ b/tests/modules/services/window-managers/i3/default.nix @@ -1,4 +1,5 @@ { + i3-bar-focused-colors = ./i3-bar-focused-colors.nix; i3-followmouse = ./i3-followmouse.nix; i3-fonts = ./i3-fonts.nix; i3-fonts-deprecated = ./i3-fonts-deprecated.nix; diff --git a/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf b/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf new file mode 100644 index 000000000000..c50f317ad975 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf @@ -0,0 +1,110 @@ +font pango:monospace 8.000000 +floating_modifier Mod1 +default_border normal 2 +default_floating_border normal 2 +hide_edge_borders none +force_focus_wrapping no +focus_follows_mouse yes +focus_on_window_activation smart +mouse_warping output +workspace_layout default +workspace_auto_back_and_forth no + +client.focused #4c7899 #285577 #ffffff #2e9ef4 #285577 +client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a +client.unfocused #333333 #222222 #888888 #292d2e #222222 +client.urgent #2f343a #900000 #ffffff #900000 #900000 +client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c +client.background #ffffff + + +bindsym Mod1+0 workspace number 10 +bindsym Mod1+1 workspace number 1 +bindsym Mod1+2 workspace number 2 +bindsym Mod1+3 workspace number 3 +bindsym Mod1+4 workspace number 4 +bindsym Mod1+5 workspace number 5 +bindsym Mod1+6 workspace number 6 +bindsym Mod1+7 workspace number 7 +bindsym Mod1+8 workspace number 8 +bindsym Mod1+9 workspace number 9 +bindsym Mod1+Down focus down +bindsym Mod1+Left focus left +bindsym Mod1+Return exec i3-sensible-terminal +bindsym Mod1+Right focus right +bindsym Mod1+Shift+0 move container to workspace number 10 +bindsym Mod1+Shift+1 move container to workspace number 1 +bindsym Mod1+Shift+2 move container to workspace number 2 +bindsym Mod1+Shift+3 move container to workspace number 3 +bindsym Mod1+Shift+4 move container to workspace number 4 +bindsym Mod1+Shift+5 move container to workspace number 5 +bindsym Mod1+Shift+6 move container to workspace number 6 +bindsym Mod1+Shift+7 move container to workspace number 7 +bindsym Mod1+Shift+8 move container to workspace number 8 +bindsym Mod1+Shift+9 move container to workspace number 9 +bindsym Mod1+Shift+Down move down +bindsym Mod1+Shift+Left move left +bindsym Mod1+Shift+Right move right +bindsym Mod1+Shift+Up move up +bindsym Mod1+Shift+c reload +bindsym Mod1+Shift+e exec i3-nagbar -t warning -m 'Do you want to exit i3?' -b 'Yes' 'i3-msg exit' +bindsym Mod1+Shift+minus move scratchpad +bindsym Mod1+Shift+q kill +bindsym Mod1+Shift+r restart +bindsym Mod1+Shift+space floating toggle +bindsym Mod1+Up focus up +bindsym Mod1+a focus parent +bindsym Mod1+d exec @dmenu@/bin/dmenu_run +bindsym Mod1+e layout toggle split +bindsym Mod1+f fullscreen toggle +bindsym Mod1+h split h +bindsym Mod1+minus scratchpad show +bindsym Mod1+r mode resize +bindsym Mod1+s layout stacking +bindsym Mod1+space focus mode_toggle +bindsym Mod1+v split v +bindsym Mod1+w layout tabbed + +mode "resize" { +bindsym Down resize grow height 10 px or 10 ppt +bindsym Escape mode default +bindsym Left resize shrink width 10 px or 10 ppt +bindsym Return mode default +bindsym Right resize grow width 10 px or 10 ppt +bindsym Up resize shrink height 10 px or 10 ppt +} + + +bar { + + font pango:monospace 8.000000 + mode dock + hidden_state hide + position bottom + status_command @i3status@/bin/i3status + i3bar_command @i3@/bin/i3bar + workspace_buttons yes + strip_workspace_numbers no + tray_output primary + colors { + background #000000 + statusline #ffffff + separator #666666 + focused_background #ffffff + focused_statusline #000000 + focused_separator #999999 + focused_workspace #4c7899 #285577 #ffffff + active_workspace #333333 #5f676a #ffffff + inactive_workspace #333333 #222222 #888888 + urgent_workspace #2f343a #900000 #ffffff + binding_mode #2f343a #900000 #ffffff + } + +} + + + + + + + diff --git a/tests/modules/services/window-managers/i3/i3-bar-focused-colors.nix b/tests/modules/services/window-managers/i3/i3-bar-focused-colors.nix new file mode 100644 index 000000000000..aaa6809f5b6d --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-bar-focused-colors.nix @@ -0,0 +1,25 @@ +{ config, lib, ... }: + +with lib; + +{ + config = { + xsession.windowManager.i3 = { + enable = true; + + config.bars = [{ + colors.focusedBackground = "#ffffff"; + colors.focusedStatusline = "#000000"; + colors.focusedSeparator = "#999999"; + }]; + }; + + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/i3/config + assertFileContent home-files/.config/i3/config \ + ${./i3-bar-focused-colors-expected.conf} + ''; + }; +} diff --git a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf index 2079288aa1eb..3d8ad0d21de4 100644 --- a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf @@ -90,6 +90,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/i3/i3-fonts-expected.conf b/tests/modules/services/window-managers/i3/i3-fonts-expected.conf index 9bcb6884f395..8a565bc3fc0e 100644 --- a/tests/modules/services/window-managers/i3/i3-fonts-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-fonts-expected.conf @@ -90,6 +90,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf index e533e6200464..6c310baac92b 100644 --- a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf @@ -91,6 +91,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf b/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf index dedb303a5946..d214a96b48e2 100644 --- a/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf @@ -89,6 +89,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf b/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf index 3e7c85deb370..9166cf9bbead 100644 --- a/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf @@ -90,6 +90,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix index 5464e90c225d..16f7751cb0ef 100644 --- a/tests/modules/services/window-managers/sway/default.nix +++ b/tests/modules/services/window-managers/sway/default.nix @@ -1,4 +1,5 @@ { + sway-bar-focused-colors = ./sway-bar-focused-colors.nix; sway-default = ./sway-default.nix; sway-post-2003 = ./sway-post-2003.nix; sway-followmouse = ./sway-followmouse.nix; diff --git a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf new file mode 100644 index 000000000000..dc8319d6b84d --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf @@ -0,0 +1,114 @@ +font pango:monospace 8.000000 +floating_modifier Mod1 +default_border pixel 2 +default_floating_border pixel 2 +hide_edge_borders none +focus_wrapping no +focus_follows_mouse yes +focus_on_window_activation smart +mouse_warping output +workspace_layout default +workspace_auto_back_and_forth no + +client.focused #4c7899 #285577 #ffffff #2e9ef4 #285577 +client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a +client.unfocused #333333 #222222 #888888 #292d2e #222222 +client.urgent #2f343a #900000 #ffffff #900000 #900000 +client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c +client.background #ffffff + + +bindsym Mod1+1 workspace number 1 +bindsym Mod1+2 workspace number 2 +bindsym Mod1+3 workspace number 3 +bindsym Mod1+4 workspace number 4 +bindsym Mod1+5 workspace number 5 +bindsym Mod1+6 workspace number 6 +bindsym Mod1+7 workspace number 7 +bindsym Mod1+8 workspace number 8 +bindsym Mod1+9 workspace number 9 +bindsym Mod1+Down focus down +bindsym Mod1+Left focus left +bindsym Mod1+Return exec @rxvt-unicode-unwrapped@/bin/urxvt +bindsym Mod1+Right focus right +bindsym Mod1+Shift+1 move container to workspace number 1 +bindsym Mod1+Shift+2 move container to workspace number 2 +bindsym Mod1+Shift+3 move container to workspace number 3 +bindsym Mod1+Shift+4 move container to workspace number 4 +bindsym Mod1+Shift+5 move container to workspace number 5 +bindsym Mod1+Shift+6 move container to workspace number 6 +bindsym Mod1+Shift+7 move container to workspace number 7 +bindsym Mod1+Shift+8 move container to workspace number 8 +bindsym Mod1+Shift+9 move container to workspace number 9 +bindsym Mod1+Shift+Down move down +bindsym Mod1+Shift+Left move left +bindsym Mod1+Shift+Right move right +bindsym Mod1+Shift+Up move up +bindsym Mod1+Shift+c reload +bindsym Mod1+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit' +bindsym Mod1+Shift+h move left +bindsym Mod1+Shift+j move down +bindsym Mod1+Shift+k move up +bindsym Mod1+Shift+l move right +bindsym Mod1+Shift+minus move scratchpad +bindsym Mod1+Shift+q kill +bindsym Mod1+Shift+space floating toggle +bindsym Mod1+Up focus up +bindsym Mod1+a focus parent +bindsym Mod1+b splith +bindsym Mod1+d exec @dmenu@/bin/dmenu_run +bindsym Mod1+e layout toggle split +bindsym Mod1+f fullscreen toggle +bindsym Mod1+h focus left +bindsym Mod1+j focus down +bindsym Mod1+k focus up +bindsym Mod1+l focus right +bindsym Mod1+minus scratchpad show +bindsym Mod1+r mode resize +bindsym Mod1+s layout stacking +bindsym Mod1+space focus mode_toggle +bindsym Mod1+v splitv +bindsym Mod1+w layout tabbed + +mode "resize" { +bindsym Down resize grow height 10 px +bindsym Escape mode default +bindsym Left resize shrink width 10 px +bindsym Return mode default +bindsym Right resize grow width 10 px +bindsym Up resize shrink height 10 px +bindsym h resize shrink width 10 px +bindsym j resize grow height 10 px +bindsym k resize shrink height 10 px +bindsym l resize grow width 10 px +} + +bar { + + font pango:monospace 8.000000 + mode dock + hidden_state hide + position bottom + status_command @i3status@/bin/i3status + swaybar_command @sway/bin/swaybar + workspace_buttons yes + strip_workspace_numbers no + tray_output primary + colors { + background #000000 + statusline #ffffff + separator #666666 + focused_background #ffffff + focused_statusline #000000 + focused_separator #999999 + focused_workspace #4c7899 #285577 #ffffff + active_workspace #333333 #5f676a #ffffff + inactive_workspace #333333 #222222 #888888 + urgent_workspace #2f343a #900000 #ffffff + binding_mode #2f343a #900000 #ffffff + } + +} + + +exec "systemctl --user import-environment; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix new file mode 100644 index 000000000000..8b3df36ef10b --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + dummy-package = pkgs.runCommandLocal "dummy-package" { } "mkdir $out"; + +in { + config = { + wayland.windowManager.sway = { + enable = true; + package = dummy-package // { outPath = "@sway"; }; + # overriding findutils causes issues + config.menu = "${pkgs.dmenu}/bin/dmenu_run"; + + config.bars = [{ + colors.focusedBackground = "#ffffff"; + colors.focusedStatusline = "#000000"; + colors.focusedSeparator = "#999999"; + }]; + }; + + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/sway/config + assertFileContent home-files/.config/sway/config \ + ${./sway-bar-focused-colors.conf} + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/sway-default.conf b/tests/modules/services/window-managers/sway/sway-default.conf index ec4ae0bce878..cbcd2d8320d1 100644 --- a/tests/modules/services/window-managers/sway/sway-default.conf +++ b/tests/modules/services/window-managers/sway/sway-default.conf @@ -98,6 +98,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/sway/sway-modules.conf b/tests/modules/services/window-managers/sway/sway-modules.conf index 7c24ba5cf56c..ee633305444d 100644 --- a/tests/modules/services/window-managers/sway/sway-modules.conf +++ b/tests/modules/services/window-managers/sway/sway-modules.conf @@ -110,6 +110,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/sway/sway-null-package.conf b/tests/modules/services/window-managers/sway/sway-null-package.conf index b4f27cee4736..1cd75fd522ad 100644 --- a/tests/modules/services/window-managers/sway/sway-null-package.conf +++ b/tests/modules/services/window-managers/sway/sway-null-package.conf @@ -98,6 +98,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf b/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf index dd15fcbf0745..9441bf5cfd5e 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf @@ -97,6 +97,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888 diff --git a/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf b/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf index cd481cf07dc4..6ef9f6d13457 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf @@ -98,6 +98,9 @@ bar { background #000000 statusline #ffffff separator #666666 + + + focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff inactive_workspace #333333 #222222 #888888