2023-01-08 17:34:37 +01:00
|
|
|
#!/bin/sh
|
2023-01-07 21:45:05 +01:00
|
|
|
|
2023-11-25 11:31:21 +01:00
|
|
|
# read resolution from xrandr: "1920x1080 60.03*+"
|
2024-01-08 23:06:28 +01:00
|
|
|
RES=$(xrandr | grep "*+" | awk '{print $1}' | head -1)
|
2023-11-25 11:31:21 +01:00
|
|
|
|
|
|
|
# parse xrandr output
|
2023-11-02 22:00:22 +01:00
|
|
|
RESH=${RES%x*}
|
|
|
|
RESV=${RES#*x}
|
|
|
|
|
2023-11-25 11:31:21 +01:00
|
|
|
# calculate pixel gap that should surround the window
|
|
|
|
GAP=$(( RESH / 12 ))
|
2023-11-02 22:00:22 +01:00
|
|
|
|
2023-11-25 11:31:21 +01:00
|
|
|
# Calculate the horzontal/vertical dimensions of the window
|
2023-11-02 22:00:22 +01:00
|
|
|
H=$(( RESH - 2 * GAP ))
|
|
|
|
V=$(( RESV - 2 * GAP ))
|
|
|
|
|
2024-10-01 17:54:06 +02:00
|
|
|
COLUMNS=170
|
2024-03-23 09:50:32 +01:00
|
|
|
ROWS=37
|
2024-02-16 07:42:49 +01:00
|
|
|
|
2023-11-25 11:31:21 +01:00
|
|
|
# set the quirk in .config/spectrwm/spectrwm.conf
|
|
|
|
# quirk[scratchpad] = FLOAT + ANYWHERE + FOCUSPREV
|
2023-01-07 21:45:05 +01:00
|
|
|
|
2023-01-08 09:17:11 +01:00
|
|
|
# get scratchpad window id
|
2023-01-07 21:45:05 +01:00
|
|
|
WID=$(wmctrl -x -l scratchpad | fgrep '.scratchpad' | cut -d" " -f1)
|
|
|
|
|
|
|
|
if [ -z "$WID" ]
|
|
|
|
then
|
2023-11-25 11:31:21 +01:00
|
|
|
# start terminal (sterm is st.suckless.org)
|
2024-02-16 07:42:49 +01:00
|
|
|
sterm -c scratchpad -g ${COLUMNS}x${ROWS}+${GAP}+${GAP} &
|
2023-11-25 11:31:21 +01:00
|
|
|
# XXX we cannot resize with wmctrl here, because the window is not
|
|
|
|
# mapped yet. Adding a sleep here and resize then is visually
|
2023-12-30 08:36:38 +01:00
|
|
|
# unpleasant. Therefore st is started with hardcoded dimensions
|
|
|
|
# and resized when hidden.
|
2023-01-07 21:45:05 +01:00
|
|
|
else
|
2023-11-25 11:31:21 +01:00
|
|
|
# check if window is iconified or on another WS (or both)
|
2023-01-08 09:17:11 +01:00
|
|
|
if xwininfo -id $WID | fgrep -q IsUnMapped
|
2023-01-07 21:45:05 +01:00
|
|
|
then
|
2023-01-10 08:20:01 +01:00
|
|
|
# move window to current workspace
|
2023-11-25 11:31:21 +01:00
|
|
|
[ -z $_SWM_WS ] \
|
|
|
|
&& wmctrl -i -r $WID -t $(xprop -root _NET_CURRENT_DESKTOP | cut -d'=' -f2) \
|
|
|
|
|| wmctrl -i -r $WID -t $_SWM_WS
|
2023-01-08 09:17:11 +01:00
|
|
|
# remove hidden flag
|
2023-11-25 11:31:21 +01:00
|
|
|
wmctrl -i -r $WID -b remove,hidden
|
2023-01-08 09:17:11 +01:00
|
|
|
# activate (give focus)
|
2023-11-25 11:31:21 +01:00
|
|
|
wmctrl -i -a $WID
|
2023-01-08 09:17:11 +01:00
|
|
|
else
|
|
|
|
# window is visible => hide
|
|
|
|
wmctrl -i -r $WID -b add,hidden
|
2023-11-02 22:16:28 +01:00
|
|
|
# correct size while hidden
|
|
|
|
wmctrl -i -r $WID -e 0,$GAP,$GAP,$H,$V
|
2023-12-30 08:36:38 +01:00
|
|
|
# move it beyond the WS limit to completely hide it from the bar
|
|
|
|
# XXX could also be skip_pager / skip_taskbar?
|
|
|
|
wmctrl -i -r $WID -t 11
|
2023-01-07 21:45:05 +01:00
|
|
|
fi
|
|
|
|
fi
|