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,127 +105,153 @@ 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";
"move container to workspace temp; [workspace=__focused__] kill; workspace temp; move container to workspace temp; workspace temp"; "i" = "mode default";
"${modifier}+Return" = "exec ${apps.term.cmd}"; "r" = "mode resize";
"${modifier}+e" = "exec ${apps.editor.cmd}";
"${modifier}+o" = "layout toggle all";
"${modifier}+Left" = "focus child; focus left"; "q" = "kill";
"${modifier}+Right" = "focus child; focus right"; "Shift+q" =
"${modifier}+Up" = "focus child; focus up"; "move container to workspace temp; [workspace=__focused__] kill; workspace temp; move container to workspace temp; workspace temp";
"${modifier}+Down" = "focus child; focus down"; "o" = "layout toggle all";
"${modifier}+Control+Left" = "focus parent; focus left";
"${modifier}+Control+Right" = "focus parent; focus right";
"${modifier}+Control+Up" = "focus parent; focus up";
"${modifier}+Control+Down" = "focus parent; focus down";
"${modifier}+Shift+Up" = "move up";
"${modifier}+Shift+Down" = "move down";
"${modifier}+Shift+Right" = "move right";
"${modifier}+Shift+Left" = "move left";
"${modifier}+Comma" = "workspace prev"; "Left" = "focus child; focus left";
"${modifier}+Period" = "workspace next"; "Right" = "focus child; focus right";
"Up" = "focus child; focus up";
"Down" = "focus child; focus down";
"Control+Left" = "focus parent; focus left";
"Control+Right" = "focus parent; focus right";
"Control+Up" = "focus parent; focus up";
"Control+Down" = "focus parent; focus down";
"Shift+Up" = "move up";
"Shift+Down" = "move down";
"Shift+Right" = "move right";
"Shift+Left" = "move left";
"${modifier}+a" = "focus child; focus left"; "Comma" = "workspace prev";
"${modifier}+d" = "focus child; focus right"; "Period" = "workspace next";
"${modifier}+w" = "focus child; focus up";
"${modifier}+s" = "focus child; focus down";
"${modifier}+Control+a" = "focus parent; focus left";
"${modifier}+Control+d" = "focus parent; focus right";
"${modifier}+Control+w" = "focus parent; focus up";
"${modifier}+Control+s" = "focus parent; focus down";
"${modifier}+Shift+w" = "move up";
"${modifier}+Shift+s" = "move down";
"${modifier}+Shift+d" = "move right";
"${modifier}+Shift+a" = "move left";
"${modifier}+f" = "fullscreen toggle; floating toggle"; "h" = "focus child; focus left";
"${modifier}+r" = "mode resize"; "l" = "focus child; focus right";
"${modifier}+Shift+f" = "floating toggle"; "k" = "focus child; focus up";
"j" = "focus child; focus down";
"Control+h" = "focus parent; focus left";
"Control+l" = "focus parent; focus right";
"Control+k" = "focus parent; focus up";
"Control+j" = "focus parent; focus down";
"Shift+k" = "move up";
"Shift+j" = "move down";
"Shift+l" = "move right";
"Shift+h" = "move left";
"${modifier}+Escape" = "f" = "fullscreen toggle; floating toggle";
''exec ${apps.monitor.cmd}; [app_id="gnome-system-monitor"] focus''; "Shift+f" = "floating toggle";
"${modifier}+F1" = ''
exec ${pkgs.pavucontrol}/bin/pavucontrol; [app_id="pavucontrol"] focus'';
"${modifier}+Shift+F1" = ''
exec ${pkgs.helvum}/bin/helvum; [app_id="org.freedesktop.ryuukyu.Helvum"] focus'';
"${modifier}+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture cap";
"${modifier}+Shift+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture nocap";
"${modifier}+F5" = "reload";
"${modifier}+Shift+F5" = "exit";
"${modifier}+z" = "exec ${pkgs.mako}/bin/makoctl dismiss";
"${modifier}+Shift+z" = "exec ${pkgs.mako}/bin/makoctl restore";
"${modifier}+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";
"${modifier}+Shift+F9" = "exec ${pkgs.libnotify}/bin/notify-send \"Do not disturb: off\"; exec ${pkgs.mako}/bin/makoctl set-mode default";
"${modifier}+F11" = "output * dpms off";
"${modifier}+F12" = "output * dpms on";
"${modifier}+End" = "exec ${lock}";
"${modifier}+j" = "exec ${pkgs.playerctl}/bin/playerctl previous"; "Shift+Escape" =
"${modifier}+k" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; ''exec ${apps.monitor.cmd}; [app_id="gnome-system-monitor"] focus'';
"${modifier}+l" = "exec ${pkgs.playerctl}/bin/playerctl next"; "F1" = ''
exec ${pkgs.pavucontrol}/bin/pavucontrol; [app_id="pavucontrol"] focus'';
"Shift+F1" = ''
exec ${pkgs.helvum}/bin/helvum; [app_id="org.freedesktop.ryuukyu.Helvum"] focus'';
"F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture cap";
"Shift+F3" = "exec ${pkgs.alsa-utils}/bin/amixer set Capture nocap";
"F5" = "reload";
"Shift+F5" = "exit";
"z" = "exec ${pkgs.mako}/bin/makoctl dismiss";
"Shift+z" = "exec ${pkgs.mako}/bin/makoctl restore";
"Control+z" = "exec ${pkgs.mako}/bin/makoctl dismiss -a";
"F9" = ''
exec ${pkgs.libnotify}/bin/notify-send "Do not disturb: on"; exec ${pkgs.mako}/bin/makoctl set-mode do-not-disturb'';
"Shift+F9" = ''
exec ${pkgs.libnotify}/bin/notify-send "Do not disturb: off"; exec ${pkgs.mako}/bin/makoctl set-mode default'';
"F11" = "output * dpms off";
"F12" = "output * dpms on";
"End" = "exec ${lock}";
"${modifier}+Slash" = "exec ${pkgs.copyq}/bin/copyq menu"; "Slash" = "exec ${pkgs.copyq}/bin/copyq menu";
"${modifier}+Shift+Slash" = "exec ${htmlify}"; "Shift+Slash" = "exec ${htmlify}";
"${modifier}+Print" = script "screenshot" "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";
"x" = "focus output right";
"Shift+x" = "move workspace to output right";
"quotedbl" = "layout splith";
"apostrophe" = "layout splitv";
"minus" = "move to scratchpad";
"underscore" = "scratchpad show";
"p" = "sticky toggle";
"b" = "focus mode_toggle";
"Space" = script "lambda-launcher"
"${pkgs.lambda-launcher}/bin/lambda-launcher";
"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";
"button2" = "kill";
"--whole-window button2" = "kill";
} // builtins.listToAttrs (builtins.map (x: {
name = "${builtins.elemAt x 0}";
value = "workspace ${builtins.elemAt x 1}";
}) workspaces) // builtins.listToAttrs (builtins.map (x: {
name = "Shift+${builtins.elemAt x 0}";
value = "move container to workspace ${builtins.elemAt x 1}";
}) 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";
};
"${modifier}+x" = "focus output right";
"${modifier}+Shift+x" = "move workspace to output right";
"${modifier}+Shift+h" = "layout splith";
"${modifier}+Shift+v" = "layout splitv";
"${modifier}+h" = "split h";
"${modifier}+v" = "split v";
"${modifier}+i" = "move to scratchpad";
"${modifier}+Shift+i" = "scratchpad show";
"${modifier}+p" = "sticky toggle";
"${modifier}+b" = "focus mode_toggle";
"${modifier}+Space" = script "lambda-launcher"
"${pkgs.lambda-launcher}/bin/lambda-launcher";
"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";
"${modifier}+XF86AudioLowerVolume" =
"exec ${pkgs.pamixer}/bin/pamixer -d 1";
"${modifier}+XF86AudioRaiseVolume" =
"exec ${pkgs.pamixer}/bin/pamixer -i 1";
"button2" = "kill";
"--whole-window ${modifier}+button2" = "kill";
} // builtins.listToAttrs (builtins.map (x: {
name = "${modifier}+${builtins.elemAt x 0}";
value = "workspace ${builtins.elemAt x 1}";
}) workspaces) // builtins.listToAttrs (builtins.map (x: {
name = "${modifier}+Shift+${builtins.elemAt x 0}";
value = "move container to workspace ${builtins.elemAt x 1}";
}) workspaces));
keycodebindings = { }; keycodebindings = { };
workspaceLayout = "tabbed"; workspaceLayout = "tabbed";
workspaceAutoBackAndForth = true; workspaceAutoBackAndForth = true;
@ -246,8 +272,8 @@ in {
} // lib.optionalAttrs (config.device == "AMD-Workstation") { } // lib.optionalAttrs (config.device == "AMD-Workstation") {
# DP-1.position = "0 400"; # DP-1.position = "0 400";
# HDMI-A-1 = { # HDMI-A-1 = {
# transform = "90"; # transform = "90";
# position = "2560 0"; # position = "2560 0";
# }; # };
} // lib.optionalAttrs (config.device == "X2100-Laptop") { } // lib.optionalAttrs (config.device == "X2100-Laptop") {
"Unknown 0x0000 0x00000000".scale = "2"; "Unknown 0x0000 0x00000000".scale = "2";