-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwcp-template.sh
executable file
·182 lines (136 loc) · 5.49 KB
/
wcp-template.sh
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
#!/usr/bin/env bash
PIPE_IN="/tmp/wcp"
# reset fifo in case it already exists and used by an older process
rm -f $PIPE_IN
mkfifo $PIPE_IN
exec 3<>$PIPE_IN
# update sliders and labels in ui
function update()
{
echo "WCP.SH Getting volume"
# PULSEAUDIO - uncomment if you use pulseaudio
# vol=$(pulsemixer --get-volume | awk '{print $1;}')
# volrat=$(echo "scale=2 ; $vol / 100" | bc)
echo "WCP.SH Volume Ratio $volrat"
echo "WCP.SH Getting brightness"
# BRIGHTNESSCONTROL - uncomment if you have an lcd & use brightnesscontrol
# lcdact=$(brightnessctl g)
# lcdmax=$(brightnessctl m)
# lcdrat=$(echo "scale=2 ; $lcdact / $lcdmax" | bc)
echo "WCP.SH Brightness ratio $lcdrat"
echo "WCP.SH Getting bluetooth device"
# BLUETOOTHCTL - uncomment if you have bluetooth and bluetoothctl
# btdevice=$(bluetoothctl info | sed -n 2p | awk '{for(i=2;i<=NF;i++) printf $i" "}')
# if [ ${#btdevice} -eq 0 ]
# then
# btdevice="No_device_connected"
# fi
echo "WCP.SH Bluetooth device $btdevice"
echo "WCP.SH Getting wifi network"
# NMCLI - uncomment if you use nmcli for wifi
# network=$(nmcli con show | awk 'NR==2 {print $1}')
# IWGTK - uncomment if you use iwgtk for wifi
# network=$(iwctl station wlp0s20f3 show | sed -n 7p | awk '{print $NF}')
echo "WCP.SH Wifi network $network"
echo "WCP.SH Getting printer"
# LPSTAT - uncomment if you use a printer and lpstat
# printer=$(lpstat -e)
echo "WCP.SH Printer $printer"
echo "WCP.SH Getting layout"
layout=$(swaymsg -t get_inputs | jq '.[0].xkb_active_layout_name' | sed 's/^.//;s/.$//')
echo "WCP.SH Layout $layout"
echo "set ratio div volslider value $volrat" >&3
echo "set ratio div lcdslider value $lcdrat" >&3
echo "set text div btoothlabel value $btdevice" >&3
echo "set text div wifilabel value $network" >&3
echo "set text div printerlabel value ${printer// /_}" >&3
echo "set text div keyboardlabel value ${layout// /_}" >&3
}
kuid -v <&3 | while IFS= read -r line; do # start kuid with file descriptor 3 as input and pipe its output to a reader
echo "KUID:" $line
words=($line)
if [ ${words[0]} = "event" ] # analyze words in kuid output
then
if [ ${words[1]} = "init" ] # init event arrived
then
echo "WCP.SH Creating layer"
echo "create layer width 300 height 258 anchor rt margin 10" >&3
echo "load html src ~/.config/wcp/res/main.html" >&3
echo "WCP.SH Layer created"
update # update sliders and labels
elif [ ${words[1]} = "update" ]
then
update # update sliders and labels
# slider events
elif [ ${words[1]} == "ratio" ]
then
if [ ${words[3]} == "volslider" ] # volume slider moved
then
echo "WCP.SH Setting volume"
# PACTL - uncomment if you use pactl
# vol=${words[7]}
# res=$(pactl set-sink-volume @DEFAULT_SINK@ $vol%) # pactl
echo "WCP.SH Volume set"
elif [ ${words[3]} == "lcdslider" ] # lcd slider moved
then
echo "WCP.SH Setting brightness"
# BRIGHTNESSCLT - uncomment if you use brightnessctl
# lcd=${words[7]}
# res=$(brightnessctl set $lcd%) # brightnessctl
echo "WCP.SH Brightness set"
fi
# button events
elif [ ${words[1]} == "state" ]
then
if [ ${words[3]} == "mutebtn" ] # volume button pressed
then
# PAVUCONTROL - uncomment if you use pavucontrol for volume control
# swaymsg exec pavucontrol
elif [ ${words[3]} == "displaybtn" ] # display button pressed
then
# WDISPLAYS - uncomment if you use wdisplays for display setup
# swaymsg exec wdisplays
elif [ ${words[3]} == "wifibtn" ] ||
[ ${words[3]} == "wifilabelback" ] # wifi button pressed
then
# IWGTK - uncomment if you use iwftk for wifi setup
# swaymsg exec iwgtk
# NMTUI - uncomment if you use nmtui for wifi setup
# swaymsg exec "foot nmtui"
elif [ ${words[3]} == "bluetoothbtn" ] ||
[ ${words[3]} == "btoothlabelbck" ] # bluetooth button pressed
then
# BLUEMAN - uncomment if you use blueman-manager for bluetooth setup
# swaymsg exec blueman-manager
elif [ ${words[3]} == "lockbtn" ] # lock button pressed
then
# SWAYLOCK - uncomment if you use swaylock
# swaymsg exec swaylock
elif [ ${words[3]} == "logoutbtn" ] # logout button pressed
then
# SWAY EXIT - uncomment if you use sway exit
# sway exit
# LOGINCTL - uncomment if you use loginctl
# swaymsg exec loginctl terminate-user $USER
elif [ ${words[3]} == "suspendbtn" ] # suspend button pressed
then
# ZZZ - uncomment if you use zz for suspend ( void linux )
# sudo /sbin/zzz
# SYSTEMD - uncomment if you use systemd
# swaymsg exec systemctl suspend
elif [ ${words[3]} == "rebootbtn" ] # reboot button pressed
then
# REBOOT - uncomment if you use reboot for reboot
# sudo /sbin/reboot
# SYSTEMD - uncomment if you use systemd
# swaymsg exec systemctl reboot
elif [ ${words[3]} == "shutdownbtn" ] # shutdown button pressed
then
# POWEROFF - uncomment if you use poweroff for poweroff
# sudo /sbin/poweroff
# SYSTEMD - uncomment if you use systemd
# swaymsg exec systemctl poweroff
fi
fi
fi
done