aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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