diff options
Diffstat (limited to 'scripts/toggle_float_center.sh')
| -rwxr-xr-x | scripts/toggle_float_center.sh | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/scripts/toggle_float_center.sh b/scripts/toggle_float_center.sh index 889430c..831f162 100755 --- a/scripts/toggle_float_center.sh +++ b/scripts/toggle_float_center.sh @@ -1,18 +1,30 @@ #!/bin/bash +# 切换窗口浮动:平铺 -> 浮动(缩放至 50%x75% 并居中) / 浮动 -> 平铺 +# +# 注意:Lua 配置(hyprland.lua)下,`hyprctl dispatch` 是 hl.dispatch(...) 的包装, +# 旧 dispatcher 名(togglefloating/resizeactive/centerwindow/movecursor)已不可用, +# 必须使用 Lua 语法(hl.dsp.*)。 + # 使用 grep 检查浮动状态 FLOATING=$(hyprctl activewindow | grep -oP 'floating:\s*\K\w+') if [ "$FLOATING" = "0" ] || [ -z "$FLOATING" ]; then # 平铺 -> 浮动 - hyprctl dispatch togglefloating + hyprctl dispatch "hl.dsp.window.float({ action = \"enable\" })" sleep 0.05 - hyprctl dispatch resizeactive exact 50% 75% - hyprctl dispatch centerwindow + + # 计算屏幕逻辑尺寸:逻辑 = 像素 / scale(取聚焦显示器) + eval "$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | "MW=\(.width / .scale) MH=\(.height / .scale) MX=\(.x) MY=\(.y)"')" + + W=$((MW * 50 / 100)) # 50% 宽 + H=$((MH * 75 / 100)) # 75% 高 + hyprctl dispatch "hl.dsp.window.resize({ x = $W, y = $H })" + hyprctl dispatch "hl.dsp.window.center()" sleep 0.05 - # 移动鼠标到屏幕中心(近似窗口中心) - hyprctl dispatch movecursor 50% 50% + # 移动鼠标到屏幕中心(对应原 movecursor 50% 50%) + hyprctl dispatch "hl.dsp.cursor.move({ x = $((MX + MW / 2)), y = $((MY + MH / 2)) })" else # 浮动 -> 平铺 - hyprctl dispatch togglefloating + hyprctl dispatch "hl.dsp.window.float({ action = \"disable\" })" fi |
