aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2023-05-16 13:16:38 +0200
committerSébastien Dailly <sebastien@dailly.me>2023-05-16 13:16:38 +0200
commit18d0291fb3b51797efd67389687b97122d710c89 (patch)
tree424ace03de1a816e94c3f5d8c5d9b7bc2424f724
parent9578c233dee6401f48ca7435828bbc27a1abbaf9 (diff)
bspwm: send update the macropad each time the node is updated
-rwxr-xr-xbspwm/scripts/bspwm/macropad.sh54
1 files changed, 33 insertions, 21 deletions
diff --git a/bspwm/scripts/bspwm/macropad.sh b/bspwm/scripts/bspwm/macropad.sh
index 0dcf843..dabdaa0 100755
--- a/bspwm/scripts/bspwm/macropad.sh
+++ b/bspwm/scripts/bspwm/macropad.sh
@@ -1,32 +1,44 @@
#!/bin/sh
# This script listen the events from BSPWM and report to the macropad the
-# layout to use.
+# layout to use.
-# The script only listen the events from switching one desktop to another one,
-# and do not report the events specific for a window.
+# The script only listen the for the changes in the selected window, and send
+# to the macropad the appropriate layout depending of the class.
+
+# The function send the code over the socket — this works fine when I use the
+# VNC connection over SSH, as long as a reverse proxy is used.
+# Use for example this configuration in the ssh/config file to open the socket :
+# RemoteForward 9999 localhost:9999
+#
+
+last_call=
-# Send to the macropad the appropriate layout depending of the desktop.
send_layout() {
- echo $1 | socat - TCP4:localhost:9999
+ if [ "$last_call" != "$1" ]; then
+ echo $1
+ last_call="$1"
+ echo $1 | socat - TCP4:localhost:9999
+ fi
}
-bspc subscribe desktop | while read -r event monitor_id desktop_id name;
-do
+bspc subscribe node | while read -r event monitor_id desktop_id name;
+do
case $event in
- desktop_focus)
- name=$(bspc query -D -d --names)
- echo $name;
- case $name in
- Web)
- send_layout "Firefox"
- ;;
- 6-girl)
- send_layout "Num pad"
- ;;
- *)
- #echo Num pad | socat - TCP4:localhost:9999;
- ;;
- esac;
+ node_focus)
+ # Read the class for the selected window
+ class=$(xprop -id $(bspc query --nodes -d -n focused) | grep ^WM_CLASS | cut -d= -f2)
+ case "$class" in
+ *"Firefox-esr"*)
+ send_layout "Firefox"
+ ;;
+ *"Qqsp"*)
+ send_layout "Num pad"
+ ;;
+ *)
+ # Do not match
+ #echo $class;
+ ;;
+ esac;
esac;
done