blob: 089182b2a78477affb0e219b7390a4ac799d251c (
plain) (
blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/bin/bash
####################################################
# Include: Start windowmanager for easier handling #
####################################################
## Functions ##
# Some problems may arise with windows opening in background when
# using eg. vmware without a window manager.
start_wm() {
# Sanity checks
unset RUNVIRT_DM
for DM in "$@" openbox kwin blackbox; do
if type "${DM}" >/dev/null 2>&1 ; then
declare -g RUNVIRT_DM="${DM}"
break
fi
done
if ! isset RUNVIRT_DM; then
# not fatal, so do not exit but report via slxlog
slxlog "runvirt-wm" "Could not find any window manager to use!"
notify_user "Konnte keinen Window Manager finden. (Das ist schlecht!)"
return 1
fi
# start RUNVIRT_DM determined above
writelog "Starting ${RUNVIRT_DM}."
declare -a OPTS=()
case "$RUNVIRT_DM" in
openbox|kwin|xfwm4|metacity)
OPTS+=( "--replace" )
;;
fvwm2)
# fvwm2 is not even in the minilinux, so this might be obsolete...
echo "EdgeScroll 0 0" > "${TMPDIR}/fvwm"
OPTS+=( "-replace" "-f" "${TMPDIR}/fvwm" )
;;
esac
stop_wm
{
trap '[ -n "$wpid" ] && kill "$wpid"; exit' EXIT TERM INT
dc=0
while true; do
s="$( date +%s )"
"${RUNVIRT_DM}" "${OPTS[@]}" &> /dev/null &
wpid=$!
wait
ret=$?
wpid=
e="$( date +%s )"
duration="$(( e - s ))"
case "$ret" in
0|129|130|143) exit 0 ;;
esac
if [ "$duration" -ge 3 ]; then
dc=0
elif [ "$(( dc++ ))" -gt 5 ]; then
notify_user "$RUNVIRT_DM crasht immer wieder."
exit 1
fi
done
} &
declare -g RUNVIRT_DM_PID="$!"
if isempty HAVE_WM_CLEANUP_HOOK; then
add_cleanup stop_wm
declare -rg HAVE_WM_CLEANUP_HOOK=yes
fi
return 0
}
stop_wm() {
isempty RUNVIRT_DM_PID && return 0
kill "$RUNVIRT_DM_PID"
usleep 100000
kill -9 "$RUNVIRT_DM_PID"
declare -g RUNVIRT_DM_PID=
}
## MAIN ##
call_post_source start_wm
|