-
Notifications
You must be signed in to change notification settings - Fork 0
/
xeph
executable file
·59 lines (51 loc) · 1.3 KB
/
xeph
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
declare size='800x600'
declare disp
cleanup() {
xdo_pid=$(pgrep -f 'xdotool.*windowfocus') && kill "$xdo_pid"
pkill Xephyr
# exit
}
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT SIGABRT
start_server() {
disp="$DISPLAY"
disp="${disp/#:}"
(( ++disp ))
(Xephyr -name "xephyr_$disp" -ac -br -noreset -screen "$size" ":$disp" &)
send_cmd 'xrdb -load ~/.Xresources'
for cmd; do
send_cmd "$cmd"
done
follow_focus
read_input
}
repl_help() {
LESS=-FEXR less <<'HELP'
q quit
r restart new xephyr process
f attempt to enable focus-follows-mouse inside xephyr [requires xdotool]
size= change the proportion of the xephyr window, eg size=800x600
HELP
}
read_input() {
read -r -e -p 'xeph> ' <> /dev/tty || { cleanup; return; }
[[ -n "$REPLY" ]] && case "$REPLY" in
h) repl_help ;;
q) pkill Xephyr; exit ;;
r) pkill Xephyr; start_server ;;
f) follow_focus ;;
size=*) size="${REPLY#*=}"; echo 'restart to take effect' ;;
*) [[ -n $REPLY ]] && send_cmd "$REPLY" & ;;
esac
read_input
}
follow_focus() {
xdo_pid=$(pgrep -f 'xdotool.*windowfocus') && kill "$xdo_pid"
send_cmd 'xdotool search . behave %@ mouse-enter windowfocus' &>/dev/null
}
send_cmd() {
DISPLAY=":$disp.0" "$SHELL" -c "$*" &
}
echo 'press h for help'
start_server "$@"
cleanup