blob: 2b447d0caf023c8ad45b1ee6475e83ca4c574a45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
|