From 97a23a26ddf88c74d2204f4da95d3f17eb3357d8 Mon Sep 17 00:00:00 2001 From: kenji Date: Wed, 14 Jan 2026 19:20:13 -0600 Subject: [PATCH] add(binds): focus between nonfloating and floaters --- apps/hyprland/hypr/binds.nix | 7 +++++++ apps/hyprland/scripts/movement.nix | 20 ++++++++++++++++++++ test/focus_switch_test.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/focus_switch_test.sh diff --git a/apps/hyprland/hypr/binds.nix b/apps/hyprland/hypr/binds.nix index 8e880a2..964492e 100644 --- a/apps/hyprland/hypr/binds.nix +++ b/apps/hyprland/hypr/binds.nix @@ -27,6 +27,7 @@ "SUPER, K, Move focus up, movefocus, u" "SUPER, H, Move focus left, movefocus, l" "SUPER, L, Move focus right, movefocus, r" + "SUPER, G, Switch Focus (Float/Tile), exec, hakase-focus-switch" # move window "SUPER SHIFT, h, Move window left, movewindow, l" @@ -55,6 +56,12 @@ # [Workspaces] Toggle between most recent workspaces "SUPER, Tab, Cycle workspaces, workspace, previous" + # [Workspaces] Move to another workspace + "CTRL SHIFT, H, Move to previous workspace, split:workspace, -1" + "CTRL SHIFT, L, Move to next workspace, split:workspace, +1" + "CTRL SHIFT, K, Move to previous workspace, split:workspace, -1" + "CTRL SHIFT, J, Move to next workspace, split:workspace, +1" + # hyprspace - workspace overview "SUPER, E, Toggle Workspace Overview, overview:toggle" ] diff --git a/apps/hyprland/scripts/movement.nix b/apps/hyprland/scripts/movement.nix index 754da4a..47e6591 100644 --- a/apps/hyprland/scripts/movement.nix +++ b/apps/hyprland/scripts/movement.nix @@ -28,8 +28,28 @@ exit 0 ''; + + hakase-focus-switch = pkgs.writeShellScriptBin "hakase-focus-switch" '' + HYPRCTL="${pkgs.hyprland}/bin/hyprctl" + JQ="${pkgs.jq}/bin/jq" + + workspace_id=$($HYPRCTL activeworkspace -j | $JQ '.id') + active_window=$($HYPRCTL activewindow -j) + is_floating=$(echo "$active_window" | $JQ '.floating') + + if [ "$is_floating" == "true" ]; then + target_addr=$($HYPRCTL clients -j | $JQ -r --argjson ws "$workspace_id" '[.[] | select(.workspace.id == $ws and .floating == false)] | .[0].address') + else + target_addr=$($HYPRCTL clients -j | $JQ -r --argjson ws "$workspace_id" '[.[] | select(.workspace.id == $ws and .floating == true)] | .[0].address') + fi + + if [ "$target_addr" != "null" ] && [ -n "$target_addr" ]; then + $HYPRCTL dispatch focuswindow address:$target_addr + fi + ''; in { home.packages = [ hakase-workspace-switch-force + hakase-focus-switch ]; } diff --git a/test/focus_switch_test.sh b/test/focus_switch_test.sh new file mode 100644 index 0000000..8be595d --- /dev/null +++ b/test/focus_switch_test.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Get current workspace ID +workspace_id=$(hyprctl activeworkspace -j | jq '.id') + +# Get active window info +active_window=$(hyprctl activewindow -j) +is_floating=$(echo "$active_window" | jq '.floating') + +echo "Current Workspace: $workspace_id" +echo "Active Window Floating: $is_floating" + +if [ "$is_floating" == "true" ]; then + echo "Switching to Tiled..." + # Find a tiled window on the current workspace + # We sort by focus history or just pick the first one + target_addr=$(hyprctl clients -j | jq -r --argjson ws "$workspace_id" '[.[] | select(.workspace.id == $ws and .floating == false)] | sort_by(.focusHistoryID) | .[0].address') +else + echo "Switching to Floating..." + # Find a floating window on the current workspace + target_addr=$(hyprctl clients -j | jq -r --argjson ws "$workspace_id" '[.[] | select(.workspace.id == $ws and .floating == true)] | sort_by(.focusHistoryID) | .[0].address') +fi + +echo "Target Address: $target_addr" + +if [ "$target_addr" != "null" ] && [ -n "$target_addr" ]; then + hyprctl dispatch focuswindow address:$target_addr +else + echo "No target window found." +fi