commit 0f57e7d483e89f5961299605482e5ec95ece792d
parent 1aa6048e9c8dc5a75ec62ab79747fcdb6f863b02
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 18 Jul 2020 16:24:48 -0500
Redid script to better differentiate windows
Diffstat:
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/smartlaunch.sh b/smartlaunch.sh
@@ -2,11 +2,20 @@
# To use the script, bind it to a key combination in dwm's config.h, and also bind THE SAME KEY to switch to the dedicated tag for the window to be launched.
-PROPNAME=$1 # A string that should match 'NET_WM_NAME' for the target window, in whole or in part. See xprop(1).
-CMDNAME=$2 # The command to execute if no matching window is found.
+CMDNAME=$1 # The command to execute if no matching window is found.
+PROPNAME=$2 # A string that should match 'WM_NAME' for the target window, in whole or in part. See xprop(1).
+PROPCLASS=$3 # A string that should match *THE FIRST FIELD* of 'WM_CLASS' in the target window, in whole or in part. See xprop(1)
-WINEXISTS=$(xwininfo -root -tree | grep -o '^[[:space:]]*0x.\{7\}' | while read line; do xprop -id $line | grep "NET_WM_NAME.*$PROPNAME"; done)
+WINIDS=$(xwininfo -root -tree | grep -o '^[[:space:]]*0x.\{7\}')
+EXISTS=0
-if [ -z "$WINEXISTS" ]; then
+for w in $WINIDS; do
+ props=$(xprop -id $w | grep '^WM_NAME\|^WM_CLASS')
+ if [[ $props == *"WM_NAME("*") = \"$PROPNAME"* && $props == *"WM_CLASS("*") = \"$PROPCLASS"* ]]; then
+ EXISTS=1
+ fi
+done
+if [ $EXISTS -eq 0 ]; then
exec $CMDNAME
fi
+unset w props