diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-24 05:45:26 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-24 05:45:26 +0200 |
| commit | d96a422496fe3a6b80659a720e63c6abc41b7de9 (patch) | |
| tree | 20f90abb5ce91875a40027333efbb52877902132 /common/scripts/utils/move_terminal | |
| parent | 521215add7da7fef6722c7b5adec839b84d72db0 (diff) | |
| parent | a1627ac743289e768b138f1a60753a62e0869cc4 (diff) | |
| download | dotfiles-d96a422496fe3a6b80659a720e63c6abc41b7de9.tar.gz dotfiles-d96a422496fe3a6b80659a720e63c6abc41b7de9.zip | |
Add 'common/scripts/' from commit 'a1627ac743289e768b138f1a60753a62e0869cc4'
git-subtree-dir: common/scripts
git-subtree-mainline: 521215add7da7fef6722c7b5adec839b84d72db0
git-subtree-split: a1627ac743289e768b138f1a60753a62e0869cc4
Diffstat (limited to 'common/scripts/utils/move_terminal')
| -rwxr-xr-x | common/scripts/utils/move_terminal | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/common/scripts/utils/move_terminal b/common/scripts/utils/move_terminal new file mode 100755 index 0000000..2b447d0 --- /dev/null +++ b/common/scripts/utils/move_terminal @@ -0,0 +1,65 @@ +#!/bin/bash + +SCRATCHPAD_CLASSES=("scratchpad" "pack" "heads-up-display") +PRIMARY_MONITOR="eDP-1" +SECOND_MONITOR="HDMI-A-2" + +PRIMARY_WORKSPACES=(2 4 5 6) +SECOND_WORKSPACES=(1 3) + +# Check if second monitor exists +if ! hyprctl monitors -j | jq -e ".[] | select(.name == \"$SECOND_MONITOR\")" >/dev/null; then + # No second monitor, do nothing + exit 0 +fi + +# Check if list of workspaces has any windows +has_windows_in_workspaces() { + local workspaces=("$@") + for ws in "${workspaces[@]}"; do + local count + count=$(hyprctl clients -j | jq "[.[] | select(.workspace.id == $ws)] | length") + if ((count > 0)); then + return 0 + fi + done + return 1 +} + +# Check window presence +primary_has_windows=false +second_has_windows=false + +if has_windows_in_workspaces "${PRIMARY_WORKSPACES[@]}"; then + primary_has_windows=true +fi +if has_windows_in_workspaces "${SECOND_WORKSPACES[@]}"; then + second_has_windows=true +fi + +# Decide target monitor +if [[ "$primary_has_windows" == true && "$second_has_windows" == false ]]; then + TARGET_MONITOR="$SECOND_MONITOR" +elif [[ "$primary_has_windows" == false && "$second_has_windows" == true ]]; then + TARGET_MONITOR="$PRIMARY_MONITOR" +else + TARGET_MONITOR="$SECOND_MONITOR" # both busy or both empty → second monitor +fi + +# Get workspace id of the target monitor +TARGET_WORKSPACE=$(hyprctl monitors -j | jq ".[] | select(.name == \"$TARGET_MONITOR\") | .activeWorkspace.id") + +# Wait for scratchpad window to appear and move it +for _ in {1..20}; do + for class in "${SCRATCHPAD_CLASSES[@]}"; do + client=$(hyprctl clients -j | jq -r ".[] | select(.class == \"$class\") | .address") + if [[ -n "$client" ]]; then + hyprctl dispatch movetoworkspacesilent "$TARGET_WORKSPACE,address:$client" + hyprctl dispatch focuswindow address:"$client" + exit 0 + fi + done + sleep 0.1 +done + +exit 1 |
