-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnihwmctl
executable file
·229 lines (193 loc) · 5.18 KB
/
nihwmctl
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/sh
#define VERSION 0.12
NIHWMCTL_VERSION=0.12
# The X Set Root
# Display Style here
# Is this shit bloated? I hope not
# This is very slow UwU
# Should I use C? The lazy thing is that I am not sure if
# combining C with programs/forking is a good idea
# TODO make this unbloated
battery_notified=false
iscommand() {
if ! [ -x $(command -v $1) ]; then
echo "$1 is not installed."
notify-send --icon=dialog-warning "nihwmctl" "$1 is not installed"
fi
}
sendsignal() {
xsetroot -name "signal:$*"
echo "sent $*"
}
iscommand rofi
iscommand xprop
iscommand wmctrl
iscommand xsetroot
# Init variables
function initvar() {
battery=$(upower -i $(upower -e | grep 'BAT') | grep 'percentage' | cut -d " " -f15)
volume=$(amixer get Master | grep 'Right:.*\(.*\)' | cut -d" " -f7)
nums=$(xset q | grep 'Num Lock' | awk '{print $8}')
caps=$(xset q | grep 'Caps Lock' | awk '{print $4}')
btrresizing=$(xprop -root _NIHWM_BOTTOM_RIGHT_RESIZING | cut -d"=" -f2)
iscursorwarp=$(xprop -root _NIHWM_CURSOR_WARP | cut -d"=" -f2)
ignoremasterfocus=$(xprop -root _NIHWM_IGNORE_MASTER_FOCUS | cut -d"=" -f2)
showoverlay=$(xprop -root _NIHWM_SHOW_OVERLAY | cut -d"=" -f2)
allownextfloating=$(xprop -root _NIHWM_ALLOW_NEXT_FLOATING | cut -d"=" -f2)
attachbelow=$(xprop -root _NIHWM_ATTACH_BELOW | cut -d"=" -f2)
compositoractive=$(xprop -root _NIHWM_USING_COMPOSITOR | cut -d"=" -f2)
focusmode=$(xprop -root _NIHWM_FOCUS_CHANGE | cut -d"=" -f2)
tagclick=$(xprop -root _NIHWM_TAG_CLICK | cut -d"=" -f2)
keymode=$(xprop -root _NIHWM_KEYMODE | cut -d"=" -f2)
focuspopup=$(xprop -root _NIHWM_FOCUS_POPUP | cut -d"=" -f2)
floatingvisible=$(xprop -root _NIHWM_FLOATING_VISIBLE | cut -d"=" -f2)
invisiblewindow=$(xprop -root _NIHWM_INVISIBLE_WINDOW | cut -d"=" -f2)
fullmenu=$(xprop -root _NIHWM_FULL_MENU | cut -d"=" -f2) # To be implemented
}
initvar
# TODO optimize this
if [ "$#" -lt 0 ]; then
echo "Usage"
echo " statusbar logoutmenu"
echo " shutdown reboot graceful_close"
exit 1
fi
# TODO optimize this
graceful_close() {
rofi -show window -theme nihwm-theme &
OIFS="$IFS"
IFS=$'\n'
for p in $(wmctrl -l); do
program=$(echo $p | awk 'BEGIN {ORS = " ";} {for ( i = 4; i <= NF; i++ ) print $i;}' | sed 's/ $//g' )
echo "Asking to die peacefully to program \"$program\""
wmctrl -c $program
done
IFS="$OIFS"
while [ $(wmctrl -l | wc -l) -gt 1 ] ; do
echo Waiting...
sleep 0.5
done
}
if [ "$1" = "-v" ] || [ "$1" = "version" ]; then
echo $NIHWMCTL_VERSION
exit 1
elif [ "$1" = "logoutmenu" ]; then
option=$(printf "shutdown\nreboot\nlogout\n" | dmenu)
if [ "$option" = "shutdown" ]; then
graceful_close
shutdown -P 0
elif [ "$option" = "logout" ]; then
graceful_close
kill nihwm # TODO should I use/invoke Mod-Shift-Cmd-Q?
elif [ "$option" = "reboot" ]; then
graceful_close
shutdown r -P 0
fi
elif [ "$1" = "shutdown" ]; then # SHUTDOWN
graceful_close; shutdown -P 0
exit 0
elif [ "$1" = "reboot" ]; then # REBOOT
graceful_close; reboot
exit 0
# TODO implement this properly
elif [ "$1" = "set" ]; then
shift 1
sendsignal $@
elif [ "$1" = "get" ]; then
if [ "$#" -lt 2 ]; then
printenv
else
shift 1
for i in "$@"; do
eval "echo \$$i"
done
fi
## THIS IS WHERE NIHWM's STATUSBAR is DEFINED ##
## TODO DONT USE XSETROOT BECAUSE OF WMNAME DESTROYS NEOFETCH ##
elif [ "$1" = "statusbar" ]; then # STATUSBAR
while true
do
initvar
if [ "$caps" = "on" ]; then
caps='C'
else
caps=''
fi
if [ "$nums" = "on" ]; then
nums='N'
else
nums=''
fi
if [ "$focusmode" = ' 1' ]; then
focusmode='F'
else
focusmode=''
fi
if [ "$compositoractive" = ' 1' ]; then
compositoractive='@'
else
compositoractive=''
fi
if [ "$attachbelow" = ' 1' ]; then
attachbelow='a'
else
attachbelow=''
fi
if [ "$allownextfloating" = ' 1' ]; then
allownextfloating='_'
else
allownextfloating=''
fi
if [ "$showoverlay" = ' 1' ]; then
showoverlay='w'
else
showoverlay=''
fi
if [ "$ignoremasterfocus" = ' 1' ]; then
ignoremasterfocus='M'
else
ignoremasterfocus=''
fi
if [ "$iscursorwarp" = ' 1' ]; then
iscursorwarp='^'
else
iscursorwarp=''
fi
if [ "$btrresizing" = ' 1' ]; then
btrresizing='R'
else
btrresizing=''
fi
if [ "$tagclick" = ' 0' ]; then
tagclick='t'
else
tagclick=''
fi
if [ "$focuspopup" = ' 0' ]; then
focuspopup='P'
else
focuspopup=''
fi
if [ "$floatingvisible" = ' 0' ]; then
floatingvisible='f'
else
floatingvisible=''
fi
if [ "$invisiblewindow" = ' 0' ]; then
invisiblewindow=''
else
invisiblewindow=" -${invisiblewindow:1}"
fi
# Battery checker
if [ "${battery%?}" -le "20" ] && [ "$battery_notified" = "false" ]; then
notify-send --urgency=critical -t 0 --icon=battery "Battery is low" "<span font='45px'>Please charge your Laptop's battery or use the cable while your laptop is still on.</span>"
battery_notified=true
fi
# All the rules, capslock, et cetera
condition="${nums}${caps}${showoverlay}${tagclick}${focuspopup}${btrresizing}${iscursorwarp}${ignoremasterfocus}${allownextfloating}${focusmode}${compositoractive}${attachbelow}${floatingvisible}"
# Set status bar
! xsetroot -name "[$condition]${keymode}${invisiblewindow} | $(date) | ${volume} | ${battery} | nihwm" && exit 69
sleep 0.1
done
exit 0
fi