summaryrefslogtreecommitdiff
path: root/scripts/x-banish
blob: df9f9395e418c3db558edbd1240e8d0e3bea905b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
dir="${HOME}/.wm-banished"
programs_to_stop='(surf|acroread|firefox)'

pid() {
	action=$1
	wid=$2
	pid=$( xdotool getwindowpid $wid )
	ps h -p $pid | grep -qsE "$programs_to_stop" || return 0
	case $action in
		stop) kill -STOP $pid;;
		cont) kill -CONT $pid;;
	esac
}

[[ ! -d $dir ]] && mkdir -p $dir

[[ "$1" = "clean" ]] && {
	for i in $dir/*; do
		[[ -f "$i" ]] && rm "$i"
	done
	exit 0
}

[[ "$1" = "push" ]] && {
	w_id=$( xdotool search --maxdepth 1 --onlyvisible . 2>/dev/null | tail -1 )
	xdotool windowunmap $w_id
	pid "stop" $w_id
	#echo "banished $(xdotool getwindowname $w_id)" | dmenu #~/bin/dmenu.sh
	touch "${dir}/${w_id}"
	exit 0 
}

w_id=$( ls -tr $dir | tail -1)
[[ "$w_id" = "" ]] && { 
	exit 0
}
pid "cont" $w_id
xdotool windowmap $w_id windowraise
xdotool windowraise  $w_id
rm -f "${dir}/${w_id}"