dotfiles/.bin/sp

55 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-01-08 17:34:37 +01:00
#!/bin/sh
2023-01-07 21:45:05 +01:00
# read resolution from xrandr: "1920x1080 60.03*+"
RES=$(xrandr | grep "*+" | awk '{print $1}')
# parse xrandr output
RESH=${RES%x*}
RESV=${RES#*x}
# calculate pixel gap that should surround the window
GAP=$(( RESH / 12 ))
# Calculate the horzontal/vertical dimensions of the window
H=$(( RESH - 2 * GAP ))
V=$(( RESV - 2 * GAP ))
# 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
# start terminal (sterm is st.suckless.org)
# XXX st is resized properly when hidden, st takes rows,
# columns as size input. We don't have that so that's just
# what echo $COLUMNS $LINES reports after the resize.
# So on the first start, the windows is "almost" correctly
# sized and we fix it later (when hidden).
sterm -c scratchpad -g 134x29+$GAP+$GAP &
# XXX we cannot resize with wmctrl here, because the window is not
# mapped yet. Adding a sleep here and resize then is visually
# unpleasant.
2023-01-07 21:45:05 +01:00
else
# 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
[ -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
wmctrl -i -r $WID -b remove,hidden
2023-01-08 09:17:11 +01:00
# activate (give focus)
wmctrl -i -a $WID
2023-01-08 09:17:11 +01:00
else
wmctrl -i -r $WID -t 11
2023-01-08 09:17:11 +01:00
# window is visible => hide
wmctrl -i -r $WID -b add,hidden
# correct size while hidden
wmctrl -i -r $WID -e 0,$GAP,$GAP,$H,$V
2023-01-07 21:45:05 +01:00
fi
fi