-
Notifications
You must be signed in to change notification settings - Fork 1
/
kwin-mv-activity
138 lines (130 loc) · 3.63 KB
/
kwin-mv-activity
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
#!/bin/bash
version="0.0.2";
usage="Usage: kwin-mv-activity [OPTION] [[ARGUMENT]]";
# displays the help text
# returns 0
showHelp () {
echo -e "$usage\n"\
"Moves the currently active window to the passed activity\n"\
"OPTIONS\n"\
" -a, --activity ID Move window to the activity with the passed ID\n"\
" -h, --help Shows this help text\n"\
" -A, --activity-name NAME Move window to the activity with the passed name\n"\
" -n, --next Move window to the next activity relative to the\n"\
" current one - when the current activity is the\n"\
" last one, it wraps around to the first\n"\
" -p, --prev Move window to the previous activity relative to\n"\
" the current one - when the current activity is\n"\
" the first, it wraps around to the last\n"\
" -v, --version Shows the scripts version\n"\
"EXIT CODES\n"\
" 0 success\n"\
" 1 invalid option\n"\
" 2 invalid argument\n"\
" 3 unexpected error\n"\
" 4 no active window found\n"\
"VERSION\n"\
" $version";
return 0;
}
# displays the usage text
# args
# invalid-argument
# returns 2
showUsageForUnknownActivity () {
echo -e "$usage\nUnknown activity '$activity'. to get a list of all activities, use\n"\
"kactivities-cli --list-activities";
return 2;
}
# checks if the activity-id is not empty and a window which can be moved exists
# args
# activity-id
# returns
# 3 on empty args or when xdotool returned an empty window id
# 4 when the found window is the desktop (no active window found)
# xprop…?
moveWindow () {
if [ -z "$1" ]; then
echo "unexpected empty parameter for moveWindow";
return 3;
fi
focusedWindow=$(xdotool getwindowfocus);
if [ -z "$focusedWindow" ]; then
echo "xdotool returned an unexpected empty id for current window";
return 3;
fi
type=$(xprop -id "$focusedWindow" _NET_WM_WINDOW_TYPE);
if [[ "$type" =~ _NET_WM_WINDOW_TYPE_DESKTOP$ ]]; then
echo "no active window found";
return 4;
fi
xprop -f _KDE_NET_WM_ACTIVITIES 8s \
-id "$focusedWindow" \
-set _KDE_NET_WM_ACTIVITIES "$1";
return $?;
}
if [ -z "$1" ]; then
showHelp;
exit 1;
fi
case "$1" in
--activity | -a)
if [ -z "$2" ]; then
showUsageForUnknownActivity;
exit $?;
fi
kactivities-cli --list-activities | grep "$2";
if [ $? -ne 0 ]; then
showUsageForUnknownActivity;
exit $?;
fi
moveWindow "$2";
exit $?;
;;
--activity-name | -A)
if [ -z "$2" ]; then
showUsageForUnknownActivity;
exit $?;
fi
activity=$(kactivities-cli --list-activities | grep "$2" | cut -d" " -f2);
if [ $? -ne 0 ] || [ -z "$activity" ]; then
showUsageForUnknownActivity;
exit $?;
fi
moveWindow "$activity";
exit $?;
;;
--help | -h)
showHelp;
exit $?;
;;
--next | -n)
activity=$(kactivities-cli --list-activities |
grep -A 1 -C 0 -F '[CURRENT] ' |
grep -F '[RUNNING] ' |
cut -d" " -f2);
if [ -z "$activity" ]; then
activity=$(kactivities-cli --list-activities | head -n 1 | cut -d" " -f2);
fi
moveWindow "$activity";
;;
--prev | -p)
activity=$(kactivities-cli --list-activities |
grep -B 1 -C 0 -F '[CURRENT] ' |
grep -F '[RUNNING] ' |
cut -d" " -f2);
if [ -z "$activity" ]; then
activity=$(kactivities-cli --list-activities | tail -n 1 | cut -d" " -f2);
fi
moveWindow "$activity";
;;
--version | -v)
echo "$version";
exit 0;
;;
*)
exit 1;
;;
esac
echo "unexpected EOF";
exit 3;