summaryrefslogtreecommitdiffstats
path: root/core/modules/pvs2/data/opt/openslx/pvs2/toggleManager.sh
blob: f2749d8b3d712bd6bc583df63ea1b667abf1bd29 (plain) (blame)
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
#!/bin/ash

wt="PVS2 Manager"
readonly wt

moveVm() {
	# make sure vmplayer is really on workspace 0
	local window windows
	windows=$(xdotool search --onlyvisible --class vmplayer)
	for window in $windows; do
		wmctrl -i -r "$window" -t 0
	done
}

moveMgr() {
	# make sure mgr is on workspace 1
	wmctrl -r "$wt" -t 1
}

getCurrent() {
	wmctrl -d | awk '{if ($2 == "*") print $1}'
}

# Do this whenever we're triggered
moveVm
moveMgr
	wmctrl -s 0

case "$EVENT" in
init)
	echo "CHECKED=false"
	;;
connected)
	echo "VISIBLE=$ISLOCAL"
	if [ "$ISLOCAL" = "true" ]; then
		moveVm
		moveMgr
		current=$(getCurrent)
		if [ "$current" = "1" ]; then
			echo "CHECKED=true"
		else
			echo "CHECKED=false"
		fi
	fi
	;;
disconnected)
	echo "VISIBLE=false"
	moveMgr
	moveVm
	wmctrl -s 0
	;;
clicked)
	moveMgr
	moveVm
	# Ignore $CHECKED here as reported by PVS, since the user might have switched desktops manually
	current=$(getCurrent)
	if [ "$current" = "1" ]; then
		wmctrl -s 0
		echo "CHECKED=false"
	else
		wmctrl -a "$wt"
		wmctrl -s 1
		echo "CHECKED=true"
	fi
	;;
esac