commit d888d1e2b94a2446fcee20bfe67066846993bd51
parent 52a759423468f8ce6d5c0ed06d850a4303bfd564
Author: Jacob R. Edwards <n/a>
Date: Wed, 23 Nov 2022 16:34:51 -0600
Add win and hidewin scripts
Win provides an easy way to hide and show windows (aswell as
optionally SIGSTOP and SIGCONT their processes). Hidewin is a
simple wrapper around win which allows you to select a window with
"xdotool selectwindow" instead of from a list of all visable windows.
(Caution: Some windows don't want to be shown, so best practice
would be to only show windows you've hidden yourself. Example:
Firefox had/has a window which, when shown, will crash dwm (or X,
I don't remember).)
Diffstat:
2 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/local/bin/bin/hidewin b/local/bin/bin/hidewin
@@ -0,0 +1,6 @@
+#!/bin/sh
+# Copyright 2022 Jacob R. Edwards
+
+id=$(xdotool selectwindow) ||
+ exit 1
+exec win hide $id
diff --git a/local/bin/bin/win b/local/bin/bin/win
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Copyright 2022 Jacob R. Edwards
+# Map, unmap, suspend, and resume X windows
+#
+# There are 4 commands: hide, stop, show, and toggle:
+#
+# - Hide unmaps windows without sending SIGSTOP to _NET_WM_PID
+# - Stop does the same, but does send SIGSTOP
+# - Show sends SIGCONT and maps windows
+# - Toggle toggles between stop and show
+#
+# Caveat: Commands, for the most part, only change what windows are
+# listed in the menu. Thus, an arbitrary window id could be entered
+# and could be treated in an unexpected way.
+
+case "${1:-toggle}" in
+(hide|stop) ;;
+(show) flags=-u ;;
+(toggle) flags=-a ;;
+(*)
+ echo "$1: Command not found" 1>&2
+ echo 'Commands: hide stop show toggle' 1>&2
+ exit 1;
+ ;;
+esac
+
+if test $# -gt 1
+then
+ id=$(printf '0x%x\n' "$2")
+else
+ id="$(
+ for id in $(lswin $flags)
+ do
+ if ! wattr o "$id" && name="$(wname $id)"
+ then
+ echo $id "$name"
+ fi
+ done | dmenu -i | sed 1q | cut -d ' ' -f1
+ )"
+fi
+
+! test "$id" &&
+ exit 1
+
+set -x
+if test $1 != hide && pid=$(xdotool getwindowpid "$id")
+then
+ if wattr m "$1"
+ then
+ pkill -STOP $pid
+ else
+ pkill -CONT $pid
+ fi
+fi
+
+if mapw -t "$id"
+then
+ echo "$id"
+fi