-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch-to-wayland
executable file
·84 lines (73 loc) · 1.65 KB
/
switch-to-wayland
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
#!/bin/bash
usage() {
printf '%s\n' "Usage: switch-to-wayland [-h]
switch-to-wayland switches to a specific window using gdbus.
Only works with GNOME Shell, but does work with Wayland display
server.
where:
-h, --help - show this help text
-c, --class - set the window class to switch to"
}
main() {
# Pass a message to the window manager to activate the window with the
# provided WM_CLASS.
result="$(gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "
global
.get_window_actors()
.map(a=>a.meta_window)
.find((w) => {
return w.get_wm_class() === '${WM_CLASS}'
})
.activate(0)")"
# If the window was not found, open the application using the provided
# command
if ! grep -q '^(true,' <<< "${result}" ; then
"${OPEN_CMD}"
fi
}
# Option parsing
declare PARAMS=''
declare WM_CLASS=''
declare OPEN_CMD=''
while (( "$#" )); do
case $1 in
-h|--help) # display help message
usage
exit 1
;;
-c|--class) # set the window class
WM_CLASS=$2
shift 2
;;
--) # End argument parsing
shift
break
;;
-*|--*) # unsupported flags
echo "Unsupported flag: $1" >&2
usage
exit 1
;;
*) # preserve positional arguments
PARAMS="${PARAMS} $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "${PARAMS}"
# parse positional arguments
OPEN_CMD="$1"
# validate parameters
if [[ -z "${OPEN_CMD}" ]]; then
echo "Missing required argument: OPEN_CMD" >&2
usage
exit 1
fi
# Freeze configuration flags
readonly WM_CLASS OPEN_CMD
main "$@"