From 18d0291fb3b51797efd67389687b97122d710c89 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 16 May 2023 13:16:38 +0200 Subject: bspwm: send update the macropad each time the node is updated --- bspwm/scripts/bspwm/macropad.sh | 54 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'bspwm/scripts') 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 -- cgit v1.2.3