deskmngr and killwindows
parent
4e90a47d34
commit
83db88765b
|
@ -0,0 +1,93 @@
|
|||
#!/bin/bash
|
||||
# Daniel Napora 2021 <napcok@gmail.com>
|
||||
#: deskmngr - save all programs (windows) running on current desktop in session file.
|
||||
#: With windows positions and state (decorated or not)
|
||||
#: Usage:
|
||||
#: -s|save - save session from current desktop
|
||||
#: -r|restore sesionfile desktop_nr - restore session from sessionfile on desktop
|
||||
#:
|
||||
SESSIONDIR="$HOME/.config/deskmngr/"
|
||||
mkdir -p $SESSIONDIR
|
||||
|
||||
savesession() {
|
||||
curdesk=$(wmctrl -d | grep "*" | awk '{print $1}')
|
||||
echo "$curdesk"
|
||||
filename=$(yad --center --title "Save session as:" --entry --entry-label="Session name" --entry-text="Session name") || exit 1
|
||||
#echo "$filename"
|
||||
windows=()
|
||||
wmctrl -l -p -G | {
|
||||
while IFS= read -r line
|
||||
do
|
||||
read -r ID DESK PID x_offset y_offset width height rest< <(echo $line)
|
||||
if [[ "$DESK" != "-1" ]]; then
|
||||
if [[ "$DESK" == "$curdesk" ]]; then
|
||||
cmdline=$(ps -fp $PID -o command=)
|
||||
xwininfo -id "$ID" -wm | grep -q Undecorated && D="u" || D="d"
|
||||
##
|
||||
frameY=$(xwininfo -id "$ID" -stats | grep "Relative upper-left Y:" | cut -d: -f2)
|
||||
frameX=$(xwininfo -id "$ID" -stats | grep "Relative upper-left X:" | cut -d: -f2)
|
||||
|
||||
windows+=("$D $width $height $((x_offset-frameX)) $((y_offset-2*frameY)) $cmdline")
|
||||
|
||||
|
||||
#windows+=("$D $width $height $x_offset $y_offset $cmdline")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
printf "%s\n" "${windows[@]}" > "$SESSIONDIR/${filename// /_}.desk"
|
||||
# Serch replace
|
||||
if command -v sd 1>/dev/null; then
|
||||
sd -s "/usr/lib/chromium/chromium" "chromium --new-window" "$SESSIONDIR/${filename// /_}.desk"
|
||||
sd -s "/usr/lib/firefox/firefox" "firefox --new-window" "$SESSIONDIR/${filename// /_}.desk"
|
||||
sd -s "/usr/bin/python3 /usr/bin/terminator" "terminator" "$SESSIONDIR/${filename// /_}.desk"
|
||||
sd -s "geany" "geany -i" "$SESSIONDIR/${filename// /_}.desk"
|
||||
sd -s "cherrytree" "cherrytree --new-window" "$SESSIONDIR/${filename// /_}.desk"
|
||||
sd -s "pcmanfm -d" "pcmanfm" "$SESSIONDIR/${filename// /_}.desk"
|
||||
fi
|
||||
#echo "$desktop"
|
||||
geany "$SESSIONDIR/${filename// /_}.desk"
|
||||
}
|
||||
}
|
||||
|
||||
restoresession() {
|
||||
sessfile="$1"
|
||||
DESK="$2"
|
||||
echo "$sessfile"
|
||||
cat "$SESSIONDIR/$sessfile" | {
|
||||
while IFS= read -r line
|
||||
do
|
||||
read -r D width height x y cmdline< <(echo $line)
|
||||
#echo -e "Desktop ID: $DESK , Decorated: $D, Size: ${width}x${height}, position: $x $y\nCommandline: $cmdline"
|
||||
wmctrl -s ${DESK}
|
||||
${cmdline} > /dev/null 2>&1 &
|
||||
# wmctrl -lp| tail -n1 |awk '{print $1}'
|
||||
|
||||
# _NET_WM_STATE(ATOM) = _OB_WM_STATE_UNDECORATED
|
||||
sleep 1.5
|
||||
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
|
||||
if [[ "$D" = "u" ]]; then xdotool key super+b; fi
|
||||
wmctrl -r :ACTIVE: -e 0,${x},${y},${width},${height}
|
||||
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
listsessions() {
|
||||
#for i in $(ls -1 ${SESSIONDIR}); do echo "${i}";done
|
||||
ls -1 ${SESSIONDIR}
|
||||
}
|
||||
|
||||
usage() {
|
||||
grep "^#:" $0 | while read DOC; do printf '%s\n' "${DOC###:}"; done
|
||||
exit
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
-s|save) savesession "$2";;
|
||||
-r|restore) restoresession "$2" "$3";;
|
||||
-l|list) listsessions ;;
|
||||
-h|--help) usage;;
|
||||
*) usage;;
|
||||
esac
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
desktop() {
|
||||
for n in $(wmctrl -l | awk -v d="$1" '$2 == d {print $1}')
|
||||
do
|
||||
wmctrl -i -c $n;
|
||||
done
|
||||
}
|
||||
all() {
|
||||
for n in $(wmctrl -l | awk $2 '!/-1/ {print $1}')
|
||||
do
|
||||
wmctrl -i -c $n;
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
all) all;;
|
||||
*) desktop "$1";;
|
||||
esac
|
Loading…
Reference in New Issue