Lines 1-145
Link Here
|
1 |
#!/bin/sh -e |
|
|
2 |
# |
3 |
# $Id: runwm,v 1.5 2005/09/29 23:00:38 ldv Exp $ |
4 |
# Copyright (C) 2002, 2005 Dmitry V. Levin <ldv@altlinux.org> |
5 |
# |
6 |
# Executes window manager using wm.d database. |
7 |
# |
8 |
# This program is free software; you can redistribute it and/or modify |
9 |
# it under the terms of the GNU General Public License as published by |
10 |
# the Free Software Foundation; either version 2 of the License, or |
11 |
# (at your option) any later version. |
12 |
# |
13 |
# This program is distributed in the hope that it will be useful, |
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
# GNU General Public License for more details. |
17 |
# |
18 |
# You should have received a copy of the GNU General Public License |
19 |
# along with this program; if not, write to the Free Software |
20 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
21 |
# |
22 |
|
23 |
PROG="${0##*/}" |
24 |
WM_DIR=/etc/X11/wmsession.d |
25 |
|
26 |
Usage() |
27 |
{ |
28 |
[ "$1" = 0 ] || exec >&2 |
29 |
cat <<EOF |
30 |
Usage: $PROG <window manager> [args] |
31 |
$PROG --print <window manager> [args] |
32 |
$PROG --list |
33 |
$PROG --help |
34 |
EOF |
35 |
[ -n "$1" ] && exit "$1" || exit |
36 |
} |
37 |
|
38 |
[ "$1" != '--help' ] || Usage 0 |
39 |
|
40 |
print_only= |
41 |
if [ "$1" = '--print' ]; then |
42 |
print_only=1 |
43 |
shift |
44 |
fi |
45 |
|
46 |
if [ $# -lt 1 ]; then |
47 |
Usage |
48 |
fi |
49 |
|
50 |
wm=`printf %s "$1" |tr '[:upper:]' '[:lower:]'` |
51 |
shift |
52 |
|
53 |
try_exec_wm() |
54 |
{ |
55 |
local f |
56 |
for f in "$@"; do |
57 |
if [ -x "$f" ]; then |
58 |
exec "$f" ||: |
59 |
fi |
60 |
done |
61 |
} |
62 |
|
63 |
exec_wm() |
64 |
{ |
65 |
if [ -n "$print_only" ]; then |
66 |
printf '%s\n' "$*" |
67 |
exit |
68 |
else |
69 |
exec "$@" |
70 |
fi |
71 |
} |
72 |
|
73 |
is_safe_config() |
74 |
{ |
75 |
[ -f "$1" -a -r "$1" -a -s "$1" ] || return |
76 |
} |
77 |
|
78 |
found_default= |
79 |
scan_wm_dir() |
80 |
{ |
81 |
local wm="$1" && shift |
82 |
local d |
83 |
|
84 |
for d in "$WM_DIR/default" "$WM_DIR"/*; do |
85 |
is_safe_config "$d" || continue |
86 |
|
87 |
local n=${d##*/} |
88 |
|
89 |
# skip files with names containing dot |
90 |
[ -n "${n##*.*}" ] || continue |
91 |
|
92 |
# if found default, skip file named "default" |
93 |
[ -z "$found_default" -o "$n" != default ] || continue |
94 |
|
95 |
# fetch pathname for later execution |
96 |
local exec=`sed -ne 's,^EXEC=\(/.\+\)$,\1,pg' "$d" |tail -1` |
97 |
|
98 |
if [ -x "$exec" ]; then |
99 |
# fetch WM name |
100 |
local name0=`sed -ne 's,^NAME=\(.\+\)$,\1,pg' "$d" |tail -1` |
101 |
[ -n "$name0" ] || continue |
102 |
|
103 |
# canonicalize WM name |
104 |
local name=`printf %s "$name0" |tr '[:upper:]' '[:lower:]'` |
105 |
|
106 |
# if in list mode, print and continue |
107 |
if [ "$wm" = '--list' ]; then |
108 |
printf '%s\n' "$name0" |
109 |
[ "$name" != default ] || found_default=1 |
110 |
continue |
111 |
fi |
112 |
|
113 |
# if found WM, execute |
114 |
if [ "$wm" = default -o "$wm" = "$name" ]; then |
115 |
exec_wm "$exec" "$@" |
116 |
fi |
117 |
fi |
118 |
done |
119 |
} |
120 |
|
121 |
if [ "$wm" = failsafe ]; then |
122 |
if [ -n "$print_only" ]; then |
123 |
echo "/usr/X11R6/bin/xterm -geometry 100x25+0+0 $@" |
124 |
else |
125 |
/usr/X11R6/bin/xterm -geometry 100x25+0+0 & |
126 |
try_exec_wm /usr/X11R6/bin/icewm-light /usr/X11R6/bin/twm |
127 |
fi |
128 |
exit |
129 |
fi |
130 |
|
131 |
prefdm_config=/etc/sysconfig/desktop |
132 |
if [ "$wm" = default ] && is_safe_config "$prefdm_config"; then |
133 |
prefdm="$(sed -ne 's/^[[:space:]]*\([^#[:space:]]\+\)[[:space:]]*$/\1/p' "$prefdm_config" | |
134 |
head -1 |tr '[:upper:]' '[:lower:]')" |
135 |
[ -z "$prefdm" ] || scan_wm_dir "$prefdm" "$@" |
136 |
fi |
137 |
|
138 |
scan_wm_dir "$wm" "$@" |
139 |
|
140 |
if [ "$wm" != '--list' ]; then |
141 |
printf '%s: window manager "%s" not found.\n' "$PROG" "$wm" >&2 |
142 |
exit 1 |
143 |
fi |
144 |
|
145 |
[ -n "$found_default" ] || echo default |