]> nyquistdev.net Git - ubuntu-rice.git/commitdiff
goto window dwm shortcut
authorA-Larsen <austin.larsen@mailfence.com>
Tue, 13 Oct 2026 14:13:52 +0000 (10:13 -0400)
committerA-Larsen <austin.larsen@mailfence.com>
Tue, 13 Oct 2026 14:13:52 +0000 (10:13 -0400)
usr-local-bin/dwm-goto-window [new file with mode: 0755]

diff --git a/usr-local-bin/dwm-goto-window b/usr-local-bin/dwm-goto-window
new file mode 100755 (executable)
index 0000000..07a8d8e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# # List all open windows, pipe into dmenu
+# window=$(wmctrl -l | awk '{print $1, $4" "$5" "$6" "$7" "$8" "$9}' | dmenu -i -p "Switch to window:")
+
+# if [ -n "$window" ]; then
+#     # Extract window ID and trigger activation
+#     wid=$(echo "$window" | awk '{print $1}')
+#     wmctrl -i -a "$wid"
+# fi
+
+# Get unique application names using wmctrl, pipe into dmenu
+selected=$(wmctrl -lx | awk '{
+    split($3, a, ".");
+    app = a[length(a)];
+    if (!seen[app]++) print app;
+}' | dmenu -i -p "Switch to application:")
+
+if [ -n "$selected" ]; then
+    # Find the window ID for the selected app name
+    wid=$(wmctrl -lx | awk -v sel="$selected" '{
+        split($3, a, ".");
+        app = a[length(a)] == "" ? $3 : a[length(a)];
+        if (app == sel) {
+            print $1;
+            exit;
+        }
+    }')
+    
+    if [ -n "$wid" ]; then
+        # Use xdotool to reliably trigger DWM's tag, monitor, and focus jump
+        xdotool windowactivate "$wid"
+    fi
+fi
+
+
+
+# Display only unique application names in dmenu
+# selected=$(wmctrl -lx | awk '{
+#     split($3, a, ".");
+#     app = a[length(a)];
+#     if (!seen[app]++) print app;
+# }' | dmenu -i -p "Switch to application:")
+
+# if [ -n "$selected" ]; then
+#     wid=$(wmctrl -lx | awk -v sel="$selected" '{
+#         split($3, a, ".");
+#         app = a[length(a)] == "" ? $3 : a[length(a)];
+#         if (app == sel) {
+#             print $1;
+#             exit;
+#         }
+#     }')
+    
+#     if [ -n "$wid" ]; then
+#         # wmctrl automatically tags this as a pager request (Source 2)
+#         wmctrl -i -a "$wid"
+#     fi
+# fi