From 5c639ff68abf0f16f2e63fb3f8aca016d54c7d10 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Mon, 11 May 2020 14:56:40 -0700 Subject: [PATCH] sway: focus.followMouse supports yes/no/always Also add associated tests for both Sway and i3. PR #1231 --- .../window-managers/i3-sway/lib/options.nix | 12 +- .../services/window-managers/i3-sway/sway.nix | 2 +- tests/default.nix | 1 + .../services/window-managers/i3/default.nix | 5 +- .../i3/i3-followmouse-expected.conf | 105 ++++++++++++++++++ .../window-managers/i3/i3-followmouse.nix | 29 +++++ .../services/window-managers/sway/default.nix | 4 + .../sway/sway-followmouse-expected.conf | 94 ++++++++++++++++ .../sway-followmouse-legacy-expected.conf | 94 ++++++++++++++++ .../sway/sway-followmouse-legacy.nix | 37 ++++++ .../window-managers/sway/sway-followmouse.nix | 37 ++++++ 11 files changed, 416 insertions(+), 4 deletions(-) create mode 100644 tests/modules/services/window-managers/i3/i3-followmouse-expected.conf create mode 100644 tests/modules/services/window-managers/i3/i3-followmouse.nix create mode 100644 tests/modules/services/window-managers/sway/default.nix create mode 100644 tests/modules/services/window-managers/sway/sway-followmouse-expected.conf create mode 100644 tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf create mode 100644 tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix create mode 100644 tests/modules/services/window-managers/sway/sway-followmouse.nix diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix index 2d483bfd7..b5216f8ca 100644 --- a/modules/services/window-managers/i3-sway/lib/options.nix +++ b/modules/services/window-managers/i3-sway/lib/options.nix @@ -390,9 +390,17 @@ in { }; followMouse = mkOption { - type = types.bool; - default = true; + type = if moduleName == "sway" then + types.either (types.enum [ "yes" "no" "always" ]) types.bool + else + types.bool; + default = if moduleName == "sway" then "yes" else true; description = "Whether focus should follow the mouse."; + apply = val: + if (moduleName == "sway" && isBool val) then + (if val then "yes" else "no") + else + val; }; forceWrapping = mkOption { diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 0445e46e2..83c8afd6c 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -253,7 +253,7 @@ let } ${toString floating.border} hide_edge_borders ${window.hideEdgeBorders} focus_wrapping ${if focus.forceWrapping then "yes" else "no"} - focus_follows_mouse ${if focus.followMouse then "yes" else "no"} + focus_follows_mouse ${focus.followMouse} focus_on_window_activation ${focus.newWindow} mouse_warping ${if focus.mouseWarping then "output" else "none"} workspace_layout ${workspaceLayout} diff --git a/tests/default.nix b/tests/default.nix index 4e9d05a36..cad8cd044 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -83,6 +83,7 @@ import nmt { ./modules/services/sxhkd ./modules/services/fluidsynth ./modules/services/window-managers/i3 + ./modules/services/window-managers/sway ./modules/systemd ./modules/targets ]); diff --git a/tests/modules/services/window-managers/i3/default.nix b/tests/modules/services/window-managers/i3/default.nix index e239d6c07..c523dfcd0 100644 --- a/tests/modules/services/window-managers/i3/default.nix +++ b/tests/modules/services/window-managers/i3/default.nix @@ -1 +1,4 @@ -{ i3-keybindings = ./i3-keybindings.nix; } +{ + i3-followmouse = ./i3-followmouse.nix; + i3-keybindings = ./i3-keybindings.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 new file mode 100644 index 000000000..729605be4 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf @@ -0,0 +1,105 @@ +font pango:monospace 8 +floating_modifier Mod1 +new_window normal 2 +new_float normal 2 +hide_edge_borders none +force_focus_wrapping no +focus_follows_mouse no +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 + 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 + } + +} + + + + + + diff --git a/tests/modules/services/window-managers/i3/i3-followmouse.nix b/tests/modules/services/window-managers/i3/i3-followmouse.nix new file mode 100644 index 000000000..8d51e3488 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-followmouse.nix @@ -0,0 +1,29 @@ +{ config, lib, ... }: + +with lib; + +{ + config = { + xsession.windowManager.i3 = { + enable = true; + + config.focus.followMouse = false; + }; + + nixpkgs.overlays = [ + (self: super: { + dmenu = super.dmenu // { outPath = "@dmenu@"; }; + + i3 = super.i3 // { outPath = "@i3@"; }; + + i3status = super.i3status // { outPath = "@i3status@"; }; + }) + ]; + + nmt.script = '' + assertFileExists home-files/.config/i3/config + assertFileContent home-files/.config/i3/config \ + ${./i3-followmouse-expected.conf} + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix new file mode 100644 index 000000000..95e15cc9d --- /dev/null +++ b/tests/modules/services/window-managers/sway/default.nix @@ -0,0 +1,4 @@ +{ + sway-followmouse = ./sway-followmouse.nix; + sway-followmouse-legacy = ./sway-followmouse-legacy.nix; +} diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf b/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf new file mode 100644 index 000000000..198ce4bd3 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf @@ -0,0 +1,94 @@ +font pango:monospace 8 +floating_modifier Mod1 +default_border pixel 2 +default_floating_border pixel 2 +hide_edge_borders none +focus_wrapping no +focus_follows_mouse always +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 +} + + + + + + + + +exec "systemctl --user import-environment; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf b/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf new file mode 100644 index 000000000..cbc55722a --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf @@ -0,0 +1,94 @@ +font pango:monospace 8 +floating_modifier Mod1 +default_border pixel 2 +default_floating_border pixel 2 +hide_edge_borders none +focus_wrapping no +focus_follows_mouse no +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 +} + + + + + + + + +exec "systemctl --user import-environment; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix new file mode 100644 index 000000000..9b80a63bc --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix @@ -0,0 +1,37 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + wayland.windowManager.sway = { + enable = true; + + config = { + focus.followMouse = false; + menu = "${pkgs.dmenu}/bin/dmenu_run"; + bars = [ ]; + }; + }; + + nixpkgs.overlays = [ + (self: super: { + dmenu = super.dmenu // { outPath = "@dmenu@"; }; + rxvt-unicode-unwrapped = super.rxvt-unicode-unwrapped // { + outPath = "@rxvt-unicode-unwrapped@"; + }; + sway-unwrapped = + pkgs.runCommandLocal "dummy-sway-unwrapped" { version = "1"; } + "mkdir $out"; + swaybg = pkgs.writeScriptBin "dummy-swaybg" ""; + xwayland = pkgs.writeScriptBin "xwayland" ""; + }) + ]; + + nmt.script = '' + assertFileExists home-files/.config/sway/config + assertFileContent home-files/.config/sway/config \ + ${./sway-followmouse-legacy-expected.conf} + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/sway-followmouse.nix b/tests/modules/services/window-managers/sway/sway-followmouse.nix new file mode 100644 index 000000000..e05b4e56f --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-followmouse.nix @@ -0,0 +1,37 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + wayland.windowManager.sway = { + enable = true; + + config = { + focus.followMouse = "always"; + menu = "${pkgs.dmenu}/bin/dmenu_run"; + bars = [ ]; + }; + }; + + nixpkgs.overlays = [ + (self: super: { + dmenu = super.dmenu // { outPath = "@dmenu@"; }; + rxvt-unicode-unwrapped = super.rxvt-unicode-unwrapped // { + outPath = "@rxvt-unicode-unwrapped@"; + }; + sway-unwrapped = + pkgs.runCommandLocal "dummy-sway-unwrapped" { version = "1"; } + "mkdir $out"; + swaybg = pkgs.writeScriptBin "dummy-swaybg" ""; + xwayland = pkgs.writeScriptBin "xwayland" ""; + }) + ]; + + nmt.script = '' + assertFileExists home-files/.config/sway/config + assertFileContent home-files/.config/sway/config \ + ${./sway-followmouse-expected.conf} + ''; + }; +}