From 95da56b783e4ccc8ded71137e4add780b239dd46 Mon Sep 17 00:00:00 2001 From: Basti Date: Thu, 3 Jun 2021 02:03:20 +0200 Subject: [PATCH] i3,sway: workspace output assignment (#2003) (cherry picked from commit ea3ff797c87313e71f2ed2fd2b932a18a4b4400b) --- .../services/window-managers/i3-sway/i3.nix | 5 +- .../window-managers/i3-sway/lib/functions.nix | 2 + .../window-managers/i3-sway/lib/options.nix | 31 +++++ .../services/window-managers/i3-sway/sway.nix | 5 +- .../services/window-managers/i3/default.nix | 1 + .../i3/i3-followmouse-expected.conf | 1 + .../window-managers/i3/i3-fonts-expected.conf | 1 + .../i3/i3-keybindings-expected.conf | 1 + .../i3/i3-workspace-default-expected.conf | 1 + .../i3/i3-workspace-output-expected.conf | 110 +++++++++++++++++ .../i3/i3-workspace-output.nix | 46 +++++++ .../services/window-managers/sway/default.nix | 1 + .../sway/sway-workspace-output-expected.conf | 115 ++++++++++++++++++ .../sway/sway-workspace-output.nix | 53 ++++++++ 14 files changed, 369 insertions(+), 4 deletions(-) create mode 100644 tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf create mode 100644 tests/modules/services/window-managers/i3/i3-workspace-output.nix create mode 100644 tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf create mode 100644 tests/modules/services/window-managers/sway/sway-workspace-output.nix diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix index 9fd40cc86..6e779b4f1 100644 --- a/modules/services/window-managers/i3-sway/i3.nix +++ b/modules/services/window-managers/i3-sway/i3.nix @@ -17,7 +17,7 @@ let inherit (commonOptions) fonts window floating focus assigns modifier workspaceLayout workspaceAutoBackAndForth keycodebindings colors bars startup gaps menu - terminal defaultWorkspace; + terminal defaultWorkspace workspaceOutputAssign; keybindings = mkOption { type = types.attrsOf (types.nullOr types.str); @@ -141,7 +141,7 @@ let inherit (commonFunctions) keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString - fontConfigStr keybindingDefaultWorkspace keybindingsRest; + fontConfigStr keybindingDefaultWorkspace keybindingsRest workspaceOutputStr; startupEntryStr = { command, always, notification, workspace, ... }: '' ${if always then "exec_always" else "exec"} ${ @@ -186,6 +186,7 @@ let ${concatStringsSep "\n" (map floatingCriteriaStr floating.criteria)} ${concatStringsSep "\n" (map windowCommandsStr window.commands)} ${concatStringsSep "\n" (map startupEntryStr startup)} + ${concatStringsSep "\n" (map workspaceOutputStr workspaceOutputAssign)} '' else "") + "\n" + cfg.extraConfig); diff --git a/modules/services/window-managers/i3-sway/lib/functions.nix b/modules/services/window-managers/i3-sway/lib/functions.nix index 2f82667d3..bb5958574 100644 --- a/modules/services/window-managers/i3-sway/lib/functions.nix +++ b/modules/services/window-managers/i3-sway/lib/functions.nix @@ -155,4 +155,6 @@ rec { "for_window ${criteriaStr criteria} floating enable"; windowCommandsStr = { command, criteria, ... }: "for_window ${criteriaStr criteria} ${command}"; + workspaceOutputStr = item: + ''workspace "${item.workspace}" output ${item.output}''; } diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix index b29d5de62..08882d7c4 100644 --- a/modules/services/window-managers/i3-sway/lib/options.nix +++ b/modules/services/window-managers/i3-sway/lib/options.nix @@ -831,4 +831,35 @@ in { ''; example = "workspace number 9"; }; + + workspaceOutputAssign = mkOption { + type = with types; + let + workspaceOutputOpts = submodule { + options = { + workspace = mkOption { + type = str; + default = ""; + example = "Web"; + description = '' + Name of the workspace to assign. + ''; + }; + + output = mkOption { + type = str; + default = ""; + example = "eDP"; + description = '' + Name of the output from + ${if isSway then "swaymsg" else "i3-msg"} -t get_outputs + . + ''; + }; + }; + }; + in listOf workspaceOutputOpts; + default = [ ]; + description = "Assign workspaces to outputs."; + }; } diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index d10eda249..1dcd8662f 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -17,7 +17,7 @@ let inherit (commonOptions) fonts window floating focus assigns workspaceLayout workspaceAutoBackAndForth modifier keycodebindings colors bars startup - gaps menu terminal defaultWorkspace; + gaps menu terminal defaultWorkspace workspaceOutputAssign; left = mkOption { type = types.str; @@ -246,7 +246,7 @@ let inherit (commonFunctions) keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString - fontConfigStr keybindingDefaultWorkspace keybindingsRest; + fontConfigStr keybindingDefaultWorkspace keybindingsRest workspaceOutputStr; startupEntryStr = { command, always, ... }: '' ${if always then "exec_always" else "exec"} ${command} @@ -307,6 +307,7 @@ let ++ map floatingCriteriaStr floating.criteria # floating ++ map windowCommandsStr window.commands # window commands ++ map startupEntryStr startup # startup + ++ map workspaceOutputStr workspaceOutputAssign # custom mapping )} '' else diff --git a/tests/modules/services/window-managers/i3/default.nix b/tests/modules/services/window-managers/i3/default.nix index 7c8ff42ff..f51260821 100644 --- a/tests/modules/services/window-managers/i3/default.nix +++ b/tests/modules/services/window-managers/i3/default.nix @@ -5,4 +5,5 @@ i3-keybindings = ./i3-keybindings.nix; i3-null-config = ./i3-null-config.nix; i3-workspace-default = ./i3-workspace-default.nix; + i3-workspace-output = ./i3-workspace-output.nix; } 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 420f19e05..2079288aa 100644 --- a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf @@ -104,3 +104,4 @@ bar { + 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 ecf69f079..9bcb6884f 100644 --- a/tests/modules/services/window-managers/i3/i3-fonts-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-fonts-expected.conf @@ -104,3 +104,4 @@ bar { + 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 ceffb162c..e533e6200 100644 --- a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf @@ -105,3 +105,4 @@ bar { + 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 52ed1c72d..dedb303a5 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 @@ -103,3 +103,4 @@ bar { + 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 new file mode 100644 index 000000000..3e7c85deb --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-workspace-output-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_workspace #4c7899 #285577 #ffffff + active_workspace #333333 #5f676a #ffffff + inactive_workspace #333333 #222222 #888888 + urgent_workspace #2f343a #900000 #ffffff + binding_mode #2f343a #900000 #ffffff + } + +} + + + + + +workspace "1" output eDP +workspace "ABC" output DP +workspace "3: Test" output HDMI +workspace "!"§$%&/(){}[]=?\*#<>-_.:,;²³" output DVI + diff --git a/tests/modules/services/window-managers/i3/i3-workspace-output.nix b/tests/modules/services/window-managers/i3/i3-workspace-output.nix new file mode 100644 index 000000000..b2ff90e02 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-workspace-output.nix @@ -0,0 +1,46 @@ +{ config, lib, ... }: + +with lib; + +{ + config = let + i3 = { + ws1 = "1"; + ws2 = "ABC"; + ws3 = "3: Test"; + ws4 = ''!"§$%&/(){}[]=?\*#<>-_.:,;²³''; + }; + + in { + xsession.windowManager.i3 = { + enable = true; + + config.workspaceOutputAssign = [ + { + workspace = "${i3.ws1}"; + output = "eDP"; + } + { + workspace = "${i3.ws2}"; + output = "DP"; + } + { + workspace = "${i3.ws3}"; + output = "HDMI"; + } + { + workspace = "${i3.ws4}"; + output = "DVI"; + } + ]; + }; + + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/i3/config + assertFileContent home-files/.config/i3/config \ + ${./i3-workspace-output-expected.conf} + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix index 14aa19323..5464e90c2 100644 --- a/tests/modules/services/window-managers/sway/default.nix +++ b/tests/modules/services/window-managers/sway/default.nix @@ -7,4 +7,5 @@ sway-null-package = ./sway-null-package.nix; sway-modules = ./sway-modules.nix; sway-workspace-default = ./sway-workspace-default.nix; + sway-workspace-output = ./sway-workspace-output.nix; } 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 new file mode 100644 index 000000000..cd481cf07 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf @@ -0,0 +1,115 @@ +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_workspace #4c7899 #285577 #ffffff + active_workspace #333333 #5f676a #ffffff + inactive_workspace #333333 #222222 #888888 + urgent_workspace #2f343a #900000 #ffffff + binding_mode #2f343a #900000 #ffffff + } + +} + +workspace "1" output eDP +workspace "ABC" output DP +workspace "3: Test" output HDMI +workspace "!"§$%&/(){}[]=?\*#<>-_.:,;²³" output DVI + +exec "systemctl --user import-environment; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-workspace-output.nix b/tests/modules/services/window-managers/sway/sway-workspace-output.nix new file mode 100644 index 000000000..5791a3da4 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-workspace-output.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + dummy-package = pkgs.runCommandLocal "dummy-package" { } "mkdir $out"; + +in { + config = let + i3 = { + ws1 = "1"; + ws2 = "ABC"; + ws3 = "3: Test"; + ws4 = ''!"§$%&/(){}[]=?\*#<>-_.:,;²³''; + }; + + in { + wayland.windowManager.sway = { + enable = true; + package = dummy-package // { outPath = "@sway"; }; + # overriding findutils causes issues + config.menu = "${pkgs.dmenu}/bin/dmenu_run"; + + config.workspaceOutputAssign = [ + { + workspace = "${i3.ws1}"; + output = "eDP"; + } + { + workspace = "${i3.ws2}"; + output = "DP"; + } + { + workspace = "${i3.ws3}"; + output = "HDMI"; + } + { + workspace = "${i3.ws4}"; + output = "DVI"; + } + ]; + }; + + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/sway/config + assertFileContent home-files/.config/sway/config \ + ${./sway-workspace-output-expected.conf} + ''; + }; +}