Make sway more modal

This commit is contained in:
Alexander Bantyev 2023-02-07 13:51:46 +04:00
parent e0e3d8495a
commit 99248a56c2
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5

View File

@ -2,8 +2,8 @@
let let
thm = pkgs.my-lib.thmHash config.themes.colors; thm = pkgs.my-lib.thmHash config.themes.colors;
apps = config.defaultApplications; apps = config.defaultApplications;
lock_fork = lock_fork = pkgs.writeShellScript "lock_fork"
pkgs.writeShellScript "lock_fork" "sudo /run/current-system/sw/bin/lock all &"; "sudo /run/current-system/sw/bin/lock all &";
lock = pkgs.writeShellScript "lock" lock = pkgs.writeShellScript "lock"
"swaymsg 'output * dpms off'; sudo /run/current-system/sw/bin/lock all; swaymsg 'output * dpms on'"; "swaymsg 'output * dpms off'; sudo /run/current-system/sw/bin/lock all; swaymsg 'output * dpms on'";
htmlify = pkgs.writeShellScript "htmlify" '' htmlify = pkgs.writeShellScript "htmlify" ''
@ -105,106 +105,103 @@ in {
"dbus-update-activation-environment --systemd WAYLAND_DISPLAY GDK_BACKEND"; "dbus-update-activation-environment --systemd WAYLAND_DISPLAY GDK_BACKEND";
} }
]; ];
modes = {
keybindings = let normal = let
script = name: content: "exec ${pkgs.writeScript name content}"; script = name: content: "exec ${pkgs.writeScript name content}";
workspaces = (builtins.genList (x: [ (toString x) (toString x) ]) 10) workspaces = (builtins.genList (x: [ (toString x) (toString x) ]) 10)
++ [ [ "c" "" ] [ "t" "" ] [ "m" "" ] ]; ++ [ [ "c" "" ] [ "t" "" ] [ "m" "" ] ];
in ({ in ({
"${modifier}+q" = "kill"; "Escape" = "mode default";
"${modifier}+Shift+q" = "Return" = "mode default";
"i" = "mode default";
"r" = "mode resize";
"q" = "kill";
"Shift+q" =
"move container to workspace temp; [workspace=__focused__] kill; workspace temp; move container to workspace temp; workspace temp"; "move container to workspace temp; [workspace=__focused__] kill; workspace temp; move container to workspace temp; workspace temp";
"${modifier}+Return" = "exec ${apps.term.cmd}"; "o" = "layout toggle all";
"${modifier}+e" = "exec ${apps.editor.cmd}";
"${modifier}+o" = "layout toggle all";
"${modifier}+Left" = "focus child; focus left"; "Left" = "focus child; focus left";
"${modifier}+Right" = "focus child; focus right"; "Right" = "focus child; focus right";
"${modifier}+Up" = "focus child; focus up"; "Up" = "focus child; focus up";
"${modifier}+Down" = "focus child; focus down"; "Down" = "focus child; focus down";
"${modifier}+Control+Left" = "focus parent; focus left"; "Control+Left" = "focus parent; focus left";
"${modifier}+Control+Right" = "focus parent; focus right"; "Control+Right" = "focus parent; focus right";
"${modifier}+Control+Up" = "focus parent; focus up"; "Control+Up" = "focus parent; focus up";
"${modifier}+Control+Down" = "focus parent; focus down"; "Control+Down" = "focus parent; focus down";
"${modifier}+Shift+Up" = "move up"; "Shift+Up" = "move up";
"${modifier}+Shift+Down" = "move down"; "Shift+Down" = "move down";
"${modifier}+Shift+Right" = "move right"; "Shift+Right" = "move right";
"${modifier}+Shift+Left" = "move left"; "Shift+Left" = "move left";
"${modifier}+Comma" = "workspace prev"; "Comma" = "workspace prev";
"${modifier}+Period" = "workspace next"; "Period" = "workspace next";
"${modifier}+a" = "focus child; focus left"; "h" = "focus child; focus left";
"${modifier}+d" = "focus child; focus right"; "l" = "focus child; focus right";
"${modifier}+w" = "focus child; focus up"; "k" = "focus child; focus up";
"${modifier}+s" = "focus child; focus down"; "j" = "focus child; focus down";
"${modifier}+Control+a" = "focus parent; focus left"; "Control+h" = "focus parent; focus left";
"${modifier}+Control+d" = "focus parent; focus right"; "Control+l" = "focus parent; focus right";
"${modifier}+Control+w" = "focus parent; focus up"; "Control+k" = "focus parent; focus up";
"${modifier}+Control+s" = "focus parent; focus down"; "Control+j" = "focus parent; focus down";
"${modifier}+Shift+w" = "move up"; "Shift+k" = "move up";
"${modifier}+Shift+s" = "move down"; "Shift+j" = "move down";
"${modifier}+Shift+d" = "move right"; "Shift+l" = "move right";
"${modifier}+Shift+a" = "move left"; "Shift+h" = "move left";
"${modifier}+f" = "fullscreen toggle; floating toggle"; "f" = "fullscreen toggle; floating toggle";
"${modifier}+r" = "mode resize"; "Shift+f" = "floating toggle";
"${modifier}+Shift+f" = "floating toggle";
"${modifier}+Escape" = "Shift+Escape" =
''exec ${apps.monitor.cmd}; [app_id="gnome-system-monitor"] focus''; ''exec ${apps.monitor.cmd}; [app_id="gnome-system-monitor"] focus'';
"${modifier}+F1" = '' "F1" = ''
exec ${pkgs.pavucontrol}/bin/pavucontrol; [app_id="pavucontrol"] focus''; exec ${pkgs.pavucontrol}/bin/pavucontrol; [app_id="pavucontrol"] focus'';
"${modifier}+Shift+F1" = '' "Shift+F1" = ''
exec ${pkgs.helvum}/bin/helvum; [app_id="org.freedesktop.ryuukyu.Helvum"] focus''; exec ${pkgs.helvum}/bin/helvum; [app_id="org.freedesktop.ryuukyu.Helvum"] focus'';
"${modifier}+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture cap"; "F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture cap";
"${modifier}+Shift+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture nocap"; "Shift+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture nocap";
"${modifier}+F5" = "reload"; "F5" = "reload";
"${modifier}+Shift+F5" = "exit"; "Shift+F5" = "exit";
"${modifier}+z" = "exec ${pkgs.mako}/bin/makoctl dismiss"; "z" = "exec ${pkgs.mako}/bin/makoctl dismiss";
"${modifier}+Shift+z" = "exec ${pkgs.mako}/bin/makoctl restore"; "Shift+z" = "exec ${pkgs.mako}/bin/makoctl restore";
"${modifier}+Control+z" = "exec ${pkgs.mako}/bin/makoctl dismiss -a"; "Control+z" = "exec ${pkgs.mako}/bin/makoctl dismiss -a";
"${modifier}+F9" = "exec ${pkgs.libnotify}/bin/notify-send \"Do not disturb: on\"; exec ${pkgs.mako}/bin/makoctl set-mode do-not-disturb"; "F9" = ''
"${modifier}+Shift+F9" = "exec ${pkgs.libnotify}/bin/notify-send \"Do not disturb: off\"; exec ${pkgs.mako}/bin/makoctl set-mode default"; exec ${pkgs.libnotify}/bin/notify-send "Do not disturb: on"; exec ${pkgs.mako}/bin/makoctl set-mode do-not-disturb'';
"${modifier}+F11" = "output * dpms off"; "Shift+F9" = ''
"${modifier}+F12" = "output * dpms on"; exec ${pkgs.libnotify}/bin/notify-send "Do not disturb: off"; exec ${pkgs.mako}/bin/makoctl set-mode default'';
"${modifier}+End" = "exec ${lock}"; "F11" = "output * dpms off";
"F12" = "output * dpms on";
"End" = "exec ${lock}";
"${modifier}+j" = "exec ${pkgs.playerctl}/bin/playerctl previous"; "Slash" = "exec ${pkgs.copyq}/bin/copyq menu";
"${modifier}+k" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; "Shift+Slash" = "exec ${htmlify}";
"${modifier}+l" = "exec ${pkgs.playerctl}/bin/playerctl next";
"${modifier}+Slash" = "exec ${pkgs.copyq}/bin/copyq menu"; "Print" = script "screenshot"
"${modifier}+Shift+Slash" = "exec ${htmlify}";
"${modifier}+Print" = script "screenshot"
"${pkgs.grim}/bin/grim Pictures/$(date +'%Y-%m-%d+%H:%M:%S').png"; "${pkgs.grim}/bin/grim Pictures/$(date +'%Y-%m-%d+%H:%M:%S').png";
"${modifier}+Control+Print" = script "screenshot-copy" "Control+Print" = script "screenshot-copy"
"${pkgs.grim}/bin/grim - | ${pkgs.wl-clipboard}/bin/wl-copy"; "${pkgs.grim}/bin/grim - | ${pkgs.wl-clipboard}/bin/wl-copy";
"--release ${modifier}+Shift+Print" = script "screenshot-area" '' "--release Shift+Print" = script "screenshot-area" ''
${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" Pictures/$(date +'%Y-%m-%d+%H:%M:%S').png''; ${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" Pictures/$(date +'%Y-%m-%d+%H:%M:%S').png'';
"--release ${modifier}+Control+Shift+Print" = "--release Control+Shift+Print" = script "screenshot-area-copy" ''
script "screenshot-area-copy" ''
${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" - | ${pkgs.wl-clipboard}/bin/wl-copy''; ${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" - | ${pkgs.wl-clipboard}/bin/wl-copy'';
"--release ${modifier}+Insert" = "--release Insert" = script "screenshot-ocr" ''
script "screenshot-ocr" ${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" - | ${pkgs.tesseract5}/bin/tesseract -l eng - - | ${pkgs.wl-clipboard}/bin/wl-copy'';
"${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.tesseract5}/bin/tesseract -l eng - - | ${pkgs.wl-clipboard}/bin/wl-copy";
"${modifier}+x" = "focus output right"; "x" = "focus output right";
"${modifier}+Shift+x" = "move workspace to output right"; "Shift+x" = "move workspace to output right";
"${modifier}+Shift+h" = "layout splith"; "quotedbl" = "layout splith";
"${modifier}+Shift+v" = "layout splitv"; "apostrophe" = "layout splitv";
"${modifier}+h" = "split h"; "minus" = "move to scratchpad";
"${modifier}+v" = "split v"; "underscore" = "scratchpad show";
"${modifier}+i" = "move to scratchpad"; "p" = "sticky toggle";
"${modifier}+Shift+i" = "scratchpad show"; "b" = "focus mode_toggle";
"${modifier}+p" = "sticky toggle"; "Space" = script "lambda-launcher"
"${modifier}+b" = "focus mode_toggle";
"${modifier}+Space" = script "lambda-launcher"
"${pkgs.lambda-launcher}/bin/lambda-launcher"; "${pkgs.lambda-launcher}/bin/lambda-launcher";
"XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; "XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
"XF86AudioPause" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; "XF86AudioPause" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
@ -213,19 +210,48 @@ in {
"XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer -d 2"; "XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer -d 2";
"XF86AudioRaiseVolume" = "exec ${pkgs.pamixer}/bin/pamixer -i 2"; "XF86AudioRaiseVolume" = "exec ${pkgs.pamixer}/bin/pamixer -i 2";
"XF86AudioMute" = "exec ${pkgs.pamixer}/bin/pamixer -t"; "XF86AudioMute" = "exec ${pkgs.pamixer}/bin/pamixer -t";
"${modifier}+XF86AudioLowerVolume" =
"exec ${pkgs.pamixer}/bin/pamixer -d 1";
"${modifier}+XF86AudioRaiseVolume" =
"exec ${pkgs.pamixer}/bin/pamixer -i 1";
"button2" = "kill"; "button2" = "kill";
"--whole-window ${modifier}+button2" = "kill"; "--whole-window button2" = "kill";
} // builtins.listToAttrs (builtins.map (x: { } // builtins.listToAttrs (builtins.map (x: {
name = "${modifier}+${builtins.elemAt x 0}"; name = "${builtins.elemAt x 0}";
value = "workspace ${builtins.elemAt x 1}"; value = "workspace ${builtins.elemAt x 1}";
}) workspaces) // builtins.listToAttrs (builtins.map (x: { }) workspaces) // builtins.listToAttrs (builtins.map (x: {
name = "${modifier}+Shift+${builtins.elemAt x 0}"; name = "Shift+${builtins.elemAt x 0}";
value = "move container to workspace ${builtins.elemAt x 1}"; value = "move container to workspace ${builtins.elemAt x 1}";
}) workspaces)); }) workspaces));
resize = {
Down = "resize grow height 50 px";
Escape = "mode default";
Left = "resize shrink width 50 px";
Return = "mode default";
Right = "resize grow width 50 px";
Up = "resize shrink height 50 px";
h = "resize shrink width 50 px";
j = "resize grow height 50 px";
k = "resize shrink height 50 px";
l = "resize grow width 50 px";
};
};
keybindings = lib.mapAttrs' (name:
let
s = lib.splitString " " name;
flags = lib.init s;
in lib.nameValuePair "${builtins.concatStringsSep " " flags}${
lib.optionalString (builtins.length flags != 0) " "
}${modifier}+${lib.last s}") modes.normal // {
"${modifier}+Escape" = "mode normal";
"${modifier}+Return" = "exec ${apps.term.cmd}";
"XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
"XF86AudioPause" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
"XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl next";
"XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl previous";
"XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer -d 2";
"XF86AudioRaiseVolume" = "exec ${pkgs.pamixer}/bin/pamixer -i 2";
"XF86AudioMute" = "exec ${pkgs.pamixer}/bin/pamixer -t";
};
keycodebindings = { }; keycodebindings = { };
workspaceLayout = "tabbed"; workspaceLayout = "tabbed";
workspaceAutoBackAndForth = true; workspaceAutoBackAndForth = true;