-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3dWS.sh
More file actions
executable file
·145 lines (123 loc) · 4.75 KB
/
Copy path3dWS.sh
File metadata and controls
executable file
·145 lines (123 loc) · 4.75 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# ==============================================================================
# 3D Printing Workspace (Orca + [Thingiverse, Inmoov] + Mainsail)
# ==============================================================================
# 0. CONFIG
TOP_BAR=32 # Hardcoded Top Bar Height
# 1. SETUP
if ! grep -q "Name=3DWS" ~/.mozilla/firefox/profiles.ini; then
firefox -CreateProfile "3DWS" >/dev/null 2>&1
fi
get_windows_json() {
python3 -c "
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio
try:
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None, 'org.gnome.Shell', '/org/gnome/Shell/Extensions/Windows', 'org.gnome.Shell.Extensions.Windows', None)
print(proxy.call_sync('List', None, Gio.DBusCallFlags.NONE, -1, None).unpack()[0])
except:
print('[]')
" 2>/dev/null
}
# 2. HARDWARE
read -r P_X P_Y P_W P_H S_X S_Y S_W S_H <<< $(python3 -c "
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
display = Gdk.Display.get_default()
monitors = []
for i in range(display.get_n_monitors()):
g = display.get_monitor(i).get_geometry()
monitors.append({'x': g.x, 'y': g.y, 'w': g.width, 'h': g.height})
monitors.sort(key=lambda m: m['w'], reverse=True)
p = monitors[0]
s = monitors[1] if len(monitors) > 1 else {'x':0,'y':0,'w':0,'h':0}
print(f'{p[\"x\"]} {p[\"y\"]} {p[\"w\"]} {p[\"h\"]} {s[\"x\"]} {s[\"y\"]} {s[\"w\"]} {s[\"h\"]}')
")
if [ "$S_W" -gt 0 ]; then MODE="DUAL"; else MODE="SINGLE"; fi
echo "Detected Mode: $MODE"
# 3. SNAPSHOT & LAUNCH
echo "Snapshotting existing windows..."
EXISTING_IDS=$(get_windows_json | jq -r '.[] | select(.wm_class != null and (.wm_class | test("firefox"; "i"))) | .id')
is_old_id() {
local check_id=$1
if echo "$EXISTING_IDS" | grep -q "^$check_id$"; then return 0; else return 1; fi
}
echo "Launching Apps..."
flatpak run com.orcaslicer.OrcaSlicer >/dev/null 2>&1 &
FF_CMD="firefox -P 3DWS"
$FF_CMD --no-remote --new-window "https://www.thingiverse.com" &
sleep 2
$FF_CMD "https://inmoov.fr" &
sleep 1
$FF_CMD --new-window "http://192.168.188.195" &
# 4. SMART WAIT LOOP
echo "Scanning for NEW windows..."
MAX_RETRIES=60
count=0
while [ $count -lt $MAX_RETRIES ]; do
WINDOWS=$(get_windows_json)
ID_ORCA=$(echo "$WINDOWS" | jq -r '.[] | select(.wm_class != null and (.wm_class | test("orca"; "i"))) | .id' | head -n 1)
ALL_FF_IDS=$(echo "$WINDOWS" | jq -r '.[] | select(.wm_class != null and (.wm_class | test("firefox"; "i"))) | .id' | sort -rn)
NEW_FF_IDS=()
for id in $ALL_FF_IDS; do
if ! is_old_id "$id"; then NEW_FF_IDS+=("$id"); fi
done
if [ -n "$ID_ORCA" ] && [ "${#NEW_FF_IDS[@]}" -ge 2 ]; then
ID_MAINSAIL=${NEW_FF_IDS[0]}
ID_RESEARCH=${NEW_FF_IDS[1]}
TITLE_MAIN=$(echo "$WINDOWS" | jq -r --arg id "$ID_MAINSAIL" '.[] | select(.id == ($id|tonumber)) | .title')
if [[ "$TITLE_MAIN" =~ "Thingiverse" ]] || [[ "$TITLE_MAIN" =~ "InMoov" ]]; then
TEMP=$ID_MAINSAIL; ID_MAINSAIL=$ID_RESEARCH; ID_RESEARCH=$TEMP
fi
echo "Targets Locked: Orca($ID_ORCA), Main($ID_MAINSAIL), Res($ID_RESEARCH)"
break
fi
sleep 0.5
((count++))
done
# 5. MOVE AND ARRANGE
win_call() {
METHOD=$1; shift; ID=$1; shift;
if [[ "$ID" =~ ^[0-9]+$ ]]; then
gdbus call --session --dest org.gnome.Shell \
--object-path /org/gnome/Shell/Extensions/Windows \
--method org.gnome.Shell.Extensions.Windows."$METHOD" \
"$ID" "$@" >/dev/null 2>&1
fi
}
place_window() {
local WIN_ID=$1; local X=$2; local Y=$3; local W=$4; local H=$5
win_call "Unmaximize" "$WIN_ID"
win_call "MoveResize" "$WIN_ID" "$X" "$Y" "$W" "$H"
}
if [ "$MODE" == "DUAL" ]; then
echo "Applying Dual Monitor Layout..."
win_call "Unmaximize" "$ID_ORCA"
SAFE_X=$((P_X + 100))
win_call "Move" "$ID_ORCA" "$SAFE_X" "$P_Y"
win_call "Maximize" "$ID_ORCA"
win_call "Activate" "$ID_ORCA"
SPLIT_W=$((S_W / 2))
RIGHT_POS=$((S_X + SPLIT_W))
place_window "$ID_RESEARCH" "$RIGHT_POS" "$S_Y" "$SPLIT_W" "$S_H"
place_window "$ID_MAINSAIL" "$S_X" "$S_Y" "$SPLIT_W" "$S_H"
else
echo "Applying Single Monitor Layout (Dashboard Style)..."
# Calculate Safe Geometry
WORK_H=$((P_H - TOP_BAR))
HALF_W=$((P_W / 2))
# 1. Place Browsers (Background)
echo " > Arranging Dashboard (Y=$TOP_BAR)..."
place_window "$ID_MAINSAIL" 0 "$TOP_BAR" "$HALF_W" "$WORK_H"
place_window "$ID_RESEARCH" "$HALF_W" "$TOP_BAR" "$HALF_W" "$WORK_H"
# 2. Place Orca (Foreground)
echo " > Maximizing Orca..."
win_call "Unmaximize" "$ID_ORCA"
win_call "Move" "$ID_ORCA" 100 100
win_call "Maximize" "$ID_ORCA"
win_call "Activate" "$ID_ORCA"
fi
echo "Layout Complete."