From 1e16dc4e6613b26a408160b9764a41814184a7b7 Mon Sep 17 00:00:00 2001 From: "committer@tuxwarrior" Date: Mon, 25 May 2026 20:27:38 -0500 Subject: [PATCH] u --- dots/bin/hypr-snap.sh | 46 ++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/dots/bin/hypr-snap.sh b/dots/bin/hypr-snap.sh index 21fc7ee..69ee76b 100644 --- a/dots/bin/hypr-snap.sh +++ b/dots/bin/hypr-snap.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # hypr-snap.sh # Move a window in a direction. If already touching that edge, snap to fill -# the full usable area of the monitor. Works across any monitor configuration. +# the full usable area of the monitor (via fullscreen). Stays tiled. +# Works across any monitor configuration. # # Usage: hypr-snap.sh # @@ -21,8 +22,6 @@ fi WIN=$(hyprctl activewindow -j) MON=$(hyprctl monitors -j | jq '.[] | select(.focused == true)') -# Do all math inside jq to avoid shell integer truncation and floating point issues. -# A window is considered "at the edge" when it is within TOLERANCE pixels of it. DATA=$(jq -n \ --argjson win "$WIN" \ --argjson mon "$MON" ' @@ -33,18 +32,15 @@ DATA=$(jq -n \ ($mon.reserved[0]) as $res_t | ($mon.reserved[1]) as $res_b | { - win_x: $win.at[0], - win_y: $win.at[1], - win_r: ($win.at[0] + $win.size[0]), - win_b: ($win.at[1] + $win.size[1]), - floating: $win.floating, + win_x: $win.at[0], + win_y: $win.at[1], + win_r: ($win.at[0] + $win.size[0]), + win_b: ($win.at[1] + $win.size[1]), - use_x: ($mon.x + $res_l), - use_y: ($mon.y + $res_t), - use_w: ($mw - $res_l - $res_r), - use_h: ($mh - $res_t - $res_b), - use_r: ($mon.x + $mw - $res_r), - use_b: ($mon.y + $mh - $res_b) + use_x: ($mon.x + $res_l), + use_y: ($mon.y + $res_t), + use_r: ($mon.x + $mw - $res_r), + use_b: ($mon.y + $mh - $res_b) } ') @@ -52,52 +48,40 @@ WIN_X=$(echo "$DATA" | jq '.win_x') WIN_Y=$(echo "$DATA" | jq '.win_y') WIN_R=$(echo "$DATA" | jq '.win_r') WIN_B=$(echo "$DATA" | jq '.win_b') -FLOATING=$(echo "$DATA" | jq '.floating') USE_X=$(echo "$DATA" | jq '.use_x') USE_Y=$(echo "$DATA" | jq '.use_y') -USE_W=$(echo "$DATA" | jq '.use_w') -USE_H=$(echo "$DATA" | jq '.use_h') USE_R=$(echo "$DATA" | jq '.use_r') USE_B=$(echo "$DATA" | jq '.use_b') -# How many pixels past the edge the window needs to reach before snapping. -# movewindoworgroup moves in steps, so set this to at least one step size. +# How close (in pixels) the window edge must be to the monitor edge to trigger snap. TOLERANCE=50 -snap() { - if [[ "$FLOATING" != "true" ]]; then - hyprctl dispatch togglefloating - fi - hyprctl dispatch moveactive exact "$USE_X" "$USE_Y" - hyprctl dispatch resizeactive exact "$USE_W" "$USE_H" -} - case $DIRECTION in l) if [[ "$WIN_X" -le $((USE_X + TOLERANCE)) ]]; then - snap + hyprctl dispatch fullscreen 1 else hyprctl dispatch movewindoworgroup l fi ;; r) if [[ "$WIN_R" -ge $((USE_R - TOLERANCE)) ]]; then - snap + hyprctl dispatch fullscreen 1 else hyprctl dispatch movewindoworgroup r fi ;; u) if [[ "$WIN_Y" -le $((USE_Y + TOLERANCE)) ]]; then - snap + hyprctl dispatch fullscreen 1 else hyprctl dispatch movewindoworgroup u fi ;; d) if [[ "$WIN_B" -ge $((USE_B - TOLERANCE)) ]]; then - snap + hyprctl dispatch fullscreen 1 else hyprctl dispatch movewindoworgroup d fi