From 34c72bbc7ac419a81e1ae4b14a18979bfafbb671 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Jan 2025 10:56:37 +0100 Subject: ... --- accounts/gkleen@sif/niri/default.nix | 143 +++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 16 deletions(-) (limited to 'accounts/gkleen@sif/niri/default.nix') diff --git a/accounts/gkleen@sif/niri/default.nix b/accounts/gkleen@sif/niri/default.nix index 6aa4391c..fa39fdd4 100644 --- a/accounts/gkleen@sif/niri/default.nix +++ b/accounts/gkleen@sif/niri/default.nix @@ -8,11 +8,11 @@ let loginctl = lib.getExe' hostConfig.systemd.package "loginctl"; systemctl = lib.getExe' hostConfig.systemd.package "systemctl"; - focus-or-spawn = pkgs.writeShellApplication { + focus_or_spawn = pkgs.writeShellApplication { name = "focus-or-spawn"; runtimeInputs = [ niri pkgs.gojq pkgs.gnugrep pkgs.socat ]; text = '' - app_id="$1" + window_select="$1" shift workspace_name="$1" shift @@ -20,12 +20,15 @@ let workspaces_json="$(niri msg -j workspaces)" workspace_output="$(jq -r --arg workspace_name "$workspace_name" '.[] | select(.name == $workspace_name) | .output' <<<"$workspaces_json")" active_workspace="$(jq -r --arg workspace_output "$workspace_output" '.[] | select(.output == $workspace_output and .is_active) | .id' <<<"$workspaces_json")" - niri msg action move-workspace-to-monitor --output "$(jq -r '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" "$workspace_name" - socat STDIO "$NIRI_SOCKET" <<<'{"Action":{"FocusWorkspace":{"reference":{"Id":'"''${active_workspace}"'}}}}' - niri msg action move-workspace-to-index --index 1 "$workspace_name" + active_output="$(jq -r '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" + if [[ $workspace_output != "$active_output" ]]; then + niri msg action move-workspace-to-monitor --output "$active_output" "$workspace_name" + socat STDIO "$NIRI_SOCKET" <<<'{"Action":{"FocusWorkspace":{"reference":{"Id":'"''${active_workspace}"'}}}}' + niri msg action move-workspace-to-index --index 1 "$workspace_name" + fi while IFS=$'\n' read -r window_json; do - if jq -r '.app_id' <<<"$window_json" | grep -q "$app_id"; then + if [[ -n $(jq -c "$window_select" <<<"$window_json") ]]; then niri msg action focus-window --id "$(jq -r '.id' <<<"$window_json")" exit 0 fi @@ -34,7 +37,65 @@ let exec "$@" ''; }; - focus-or-spawn-action = app_id: workspace_name: config.lib.niri.actions.spawn (lib.getExe focus-or-spawn) (lib.escapeShellArg app_id) (lib.escapeShellArg workspace_name); + focus-or-spawn-action = config.lib.niri.actions.spawn (lib.getExe focus_or_spawn); + focus-or-spawn-action-app_id = app_id: focus-or-spawn-action ''select(.app_id == "${app_id}")''; + + with_adjacent_workspace = pkgs.writeShellApplication { + name = "with-adjacent-workspace"; + runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; + text = '' + blacklist="$1" + shift + direction="$1" + shift + action="$1" + shift + + workspaces_json="$(niri msg -j workspaces)" + active_workspace="$(jq -r '.[] | select(.is_focused) | .id' <<<"$workspaces_json")" + workspace_output="$(jq -r --arg active_workspace "$active_workspace" '.[] | select(.id == ($active_workspace | tonumber)) | .output' <<<"$workspaces_json")" + workspace_idx="$(jq -r '.[] | select(.is_focused) | .idx' <<<"$workspaces_json")" + + jq_script='map(select(' + case "$direction" in + down) + # shellcheck disable=SC2016 + jq_script=''${jq_script}'.idx > ($workspace_idx | tonumber)';; + up) + # shellcheck disable=SC2016 + jq_script=''${jq_script}'.idx < ($workspace_idx | tonumber)';; + esac + # shellcheck disable=SC2016 + jq_script=''${jq_script}' and .output == $workspace_output and ((.name == null) or (.name | test($blacklist) | not)))) | sort_by(.idx)' + [[ $direction == "up" ]] && jq_script=''${jq_script}' | reverse' + jq_script=''${jq_script}' | .[0]' + + workspace_json=$(jq -c --arg blacklist "$blacklist" --arg workspace_output "$workspace_output" --arg workspace_idx "$workspace_idx" "$jq_script" <<<"$workspaces_json") + [[ -n $workspace_json && $workspace_json != null ]] || exit 0 + jq --arg active_workspace "$active_workspace" -c "$action" <<<"$workspace_json" | tee /dev/stderr | socat STDIO "$NIRI_SOCKET" + ''; + }; + with-adjacent-workspace-action = config.lib.niri.actions.spawn (lib.getExe with_adjacent_workspace) "^pwctl|kpxc|bmgr|edit|term$"; + focus-adjacent-workspace = direction: with-adjacent-workspace-action direction ''{"Action":{"FocusWorkspace":{"reference":{"Id": .id}}}}''; + move-column-to-adjacent-workspace = direction: with-adjacent-workspace-action direction ''{"Action":{"MoveColumnToWorkspace":{"reference":{"Id": .id}}}}''; + + with_unnamed_workspace = pkgs.writeShellApplication { + name = "with-unnamed-workspace"; + runtimeInputs = [ niri pkgs.gojq pkgs.socat ]; + text = '' + action="$1" + shift + + workspaces_json="$(niri msg -j workspaces)" + active_output="$(jq -r '.[] | select(.is_focused) | .output' <<<"$workspaces_json")" + active_workspace="$(jq -r '.[] | select(.is_focused) | .id' <<<"$workspaces_json")" + + workspace_json="$(jq -c --arg active_output "$active_output" 'map(select(.output == $active_output and .name == null)) | sort_by(.idx) | .[0]' <<<"$workspaces_json")" + [[ -n $workspace_json && $workspace_json != null && $active_workspace != "$(jq -r '.id' <<<"$workspace_json")" ]] || exit 0 + jq --arg active_workspace "$active_workspace" -c "$action" <<<"$workspace_json" | tee /dev/stderr | socat STDIO "$NIRI_SOCKET" + ''; + }; + with-unnamed-workspace-action = config.lib.niri.actions.spawn (lib.getExe with_unnamed_workspace); in { imports = [ ./waybar.nix @@ -110,10 +171,27 @@ in { layout = { gaps = 8; - struts = { left = 8; right = 8; top = 0; bottom = 0; }; + struts = { left = 0; right = 0; top = 0; bottom = 0; }; focus-ring = { width = 2; }; + + preset-column-widths = [ + { proportion = 1. / 4.; } + { proportion = 1. / 3.; } + { proportion = 1. / 2.; } + { proportion = 2. / 3.; } + { proportion = 3. / 4.; } + ]; + default-column-width.proportion = 1. / 2.; + preset-window-heights = [ + { proportion = 1. / 3.; } + { proportion = 1. / 2.; } + { proportion = 2. / 3.; } + { proportion = 1.; } + ]; + + always-center-single-column = true; }; cursor.hide-when-typing = true; @@ -122,6 +200,8 @@ in { "001".name = "pwctl"; "002".name = "kpxc"; "003".name = "bmgr"; + "004".name = "term"; + "005".name = "edit"; "101".name = "comm"; "102".name = "web"; "104".name = "read"; @@ -134,8 +214,9 @@ in { geometry-corner-radius = let allCorners = r: { bottom-left = r; bottom-right = r; top-left = r; top-right = r; }; - in allCorners 8.; + in allCorners 4.; clip-to-geometry = true; + open-focused = true; } { matches = [ { app-id = "^com\.saivert\.pwvucontrol$"; } ]; @@ -155,6 +236,14 @@ in { open-on-workspace = "kpxc"; open-focused = false; } + { + matches = [ { app-id = "^kitty-scratch$"; } ]; + open-on-workspace = "term"; + } + { + matches = [ { title = "^scratch$"; app-id = "^emacs$"; } ]; + open-on-workspace = "edit"; + } { matches = [ { app-id = "^thunderbird$"; } @@ -195,6 +284,8 @@ in { "Mod+D".action = spawn (lib.getExe config.programs.fuzzel.package); "Mod+Shift+D".action = spawn (lib.getExe config.programs.fuzzel.package) "--list-executables-in-path"; + "Mod+Alt+E".action = spawn (lib.getExe' config.services.emacs.package "emacsclient") "-c"; + "Mod+H".action = focus-column-left; "Mod+T".action = focus-window-down; "Mod+N".action = focus-window-up; @@ -215,15 +306,33 @@ in { "Mod+Shift+Control+N".action = move-workspace-to-monitor-up; "Mod+Shift+Control+S".action = move-workspace-to-monitor-right; - "Mod+G".action = focus-workspace-down; - "Mod+C".action = focus-workspace-up; + "Mod+G".action = focus-adjacent-workspace "down"; + "Mod+C".action = focus-adjacent-workspace "up"; - "Mod+Shift+G".action = move-column-to-workspace-down; - "Mod+Shift+C".action = move-column-to-workspace-up; + "Mod+Shift+G".action = move-column-to-adjacent-workspace "down"; + "Mod+Shift+C".action = move-column-to-adjacent-workspace "up"; "Mod+Shift+Control+G".action = move-workspace-down; "Mod+Shift+Control+C".action = move-workspace-up; + "Mod+ParenLeft".action = focus-workspace "comm"; + "Mod+Shift+ParenLeft".action = move-column-to-workspace "comm"; + + "Mod+ParenRight".action = focus-workspace "web"; + "Mod+Shift+ParenRight".action = move-column-to-workspace "web"; + + "Mod+BraceRight".action = focus-workspace "read"; + "Mod+Shift+BraceRight".action = move-column-to-workspace "read"; + + "Mod+BraceLeft".action = focus-workspace "mon"; + "Mod+Shift+BraceLeft".action = move-column-to-workspace "mon"; + + "Mod+Asterisk".action = focus-workspace "vid"; + "Mod+Shift+Asterisk".action = move-column-to-workspace "vid"; + + "Mod+Plus".action = with-unnamed-workspace-action ''{"Action":{"FocusWorkspace":{"reference":{"Id": .id}}}}''; + "Mod+Shift+Plus".action = with-unnamed-workspace-action ''{"Action":{"MoveColumnToWorkspace":{"reference":{"Id": .id}}}}''; + "Mod+M".action = consume-or-expel-window-left; "Mod+W".action = consume-or-expel-window-right; @@ -280,9 +389,11 @@ in { "Mod+Period".action = spawn dunstctl "context"; "Mod+Comma".action = spawn dunstctl "history-pop"; - "Mod+Alt+A".action = focus-or-spawn-action "^com\.saivert\.pwvucontrol$" "pwctl" "pwvucontrol"; - "Mod+Alt+P".action = focus-or-spawn-action "^org\.keepassxc\.KeePassXC$" "kpxc" "keepassxc"; - "Mod+Alt+B".action = focus-or-spawn-action "^\.blueman-manager-wrapped$" "bmgr" "blueman-manager"; + "Mod+Control+A".action = focus-or-spawn-action-app_id "com.saivert.pwvucontrol" "pwctl" "pwvucontrol"; + "Mod+Control+P".action = focus-or-spawn-action-app_id "org.keepassxc.KeePassXC" "kpxc" "keepassxc"; + "Mod+Control+B".action = focus-or-spawn-action-app_id ".blueman-manager-wrapped" "bmgr" "blueman-manager"; + "Mod+Control+Return".action = focus-or-spawn-action-app_id "kitty-scratch" "term" "kitty" "--app-id" "kitty-scratch"; + "Mod+Control+E".action = focus-or-spawn-action "select(.app_id == \"emacs\" and .title == \"scratch\")" "edit" "emacsclient" "-c" "--frame-parameters=(quote (name . \"scratch\"))"; }; }; }; -- cgit v1.2.3