pandora-xfce-defaults: Commit 1st cut at defaults (WIP)
[openpandora.oe.git] / recipes / branding / pandora-xfce-defaults / xfce4 / xinitrc
1 #!/bin/sh
2
3 # fix broken $UID on some system...
4 if test "x$UID" = "x"; then
5         if test -x /usr/xpg4/bin/id; then
6                 UID=`/usr/xpg4/bin/id -u`;
7         else
8                 UID=`id -u`;
9         fi
10 fi
11
12 # $XDG_CONFIG_HOME defines the base directory relative to which user specific 
13 # configuration files should be stored. If $XDG_CONFIG_HOME is either not set 
14 # or empty, a default equal to $HOME/.config should be used.
15 if test "x$XDG_CONFIG_HOME" = "x" ; then
16   XDG_CONFIG_HOME=$HOME/.config
17 fi
18 [ -d "$XDG_CONFIG_HOME" ] || mkdir "$XDG_CONFIG_HOME"
19
20 # $XDG_CACHE_HOME defines the base directory relative to which user specific 
21 # non-essential data files should be stored. If $XDG_CACHE_HOME is either not 
22 # set or empty, a default equal to $HOME/.cache should be used.
23 if test "x$XDG_CACHE_HOME" = "x" ; then
24   XDG_CACHE_HOME=$HOME/.cache
25 fi
26 [ -d "$XDG_CACHE_HOME" ] || mkdir "$XDG_CACHE_HOME"
27
28
29 # set up XDG user directores.  see
30 # http://freedesktop.org/wiki/Software/xdg-user-dirs
31 if type xdg-user-dirs-update >/dev/null 2>&1; then
32     xdg-user-dirs-update
33 fi
34
35 if test -f "$XDG_CONFIG_HOME/user-dirs.dirs"; then
36     . "$XDG_CONFIG_HOME/user-dirs.dirs"
37     # i'm deliberately not 'export'-ing the XDG_ vars, because you shouldn't
38     # rely on the env vars inside apps, since the file could be changed at
39     # any time by the user.  this is solely here for migration purposes.
40
41     # a bit of user dir migration...
42     if test -d "$HOME/Desktop" -a ! -L "$HOME/Desktop" \
43             -a "$XDG_DESKTOP_DIR" \
44             -a "$HOME/Desktop" != "$XDG_DESKTOP_DIR"
45     then
46         echo "Migrating $HOME/Desktop to $XDG_DESKTOP_DIR..."
47         test -d "$XDG_DESKTOP_DIR" && rmdir "$XDG_DESKTOP_DIR"
48         mv "$HOME/Desktop" "$XDG_DESKTOP_DIR" || echo "Desktop migration failed" >&2
49     fi
50
51     if test -d "$HOME/Templates" -a ! -L "$HOME/Templates" \
52             -a "$XDG_TEMPLATES_DIR" \
53             -a "$HOME/Templates" != "$XDG_TEMPLATES_DIR"
54     then
55         echo "Migrating $HOME/Templates to $XDG_TEMPLATES_DIR..."
56         test -d "$XDG_TEMPLATES_DIR" && rmdir "$XDG_TEMPLATES_DIR"
57         mv "$HOME/Templates" "$XDG_TEMPLATES_DIR" || echo "Templates migration failed" >&2
58     fi
59 fi
60
61
62 # Modify libglade and glade environment variables so that
63 # it will find the files installed by Xfce
64 export LIBGLADE_MODULE_PATH="$LIBGLADE_MODULE_PATH:/usr/lib/libglade/2.0"
65 export GLADE_CATALOG_PATH="$GLADE_CATALOG_PATH:"
66 export GLADE_PIXMAP_PATH="$GLADE_PIXMAP_PATH:"
67 export GLADE_MODULE_PATH="$GLADE_MODULE_PATH:"
68
69
70 # Export GTK_PATH so that GTK+ can find the Xfce theme engine
71 export GTK_PATH="$GTK_PATH:/usr/lib/gtk-2.0"
72
73
74 # For now, start with an empty list
75 XRESOURCES=""
76
77 # Has to go prior to merging Xft.xrdb, as its the "Defaults" file
78 test -r "/etc/xdg/xfce4/Xft.xrdb" && XRESOURCES="$XRESOURCES /etc/xdg/xfce4/Xft.xrdb"
79 test -r $HOME/.Xdefaults && XRESOURCES="$XRESOURCES $HOME/.Xdefaults"
80
81 BASEDIR=$XDG_CONFIG_HOME/xfce4
82 if test -r "$BASEDIR/Xft.xrdb"; then
83   XRESOURCES="$XRESOURCES $BASEDIR/Xft.xrdb"
84 elif test -r "$XFCE4HOME/Xft.xrdb"; then
85   mkdir -p "$BASEDIR"
86   cp "$XFCE4HOME/Xft.xrdb" "$BASEDIR"/
87   XRESOURCES="$XRESOURCES $BASEDIR/Xft.xrdb"
88 fi
89
90 # merge in X cursor settings
91 test -r "$BASEDIR/Xcursor.xrdb" && XRESOURCES="$XRESOURCES $BASEDIR/Xcursor.xrdb"
92
93 # ~/.Xresources contains overrides to the above
94 test -r "$HOME/.Xresources" && XRESOURCES="$XRESOURCES $HOME/.Xresources"
95
96 # load all X resources (adds /dev/null to avoid an empty list that would hang the process)
97 cat /dev/null $XRESOURCES | xrdb -nocpp -merge -
98
99 # load local modmap
100 test -r $HOME/.Xmodmap && xmodmap $HOME/.Xmodmap
101
102 # Launch xscreensaver (if available), but only as non-root user
103 if test $UID -gt 0 -a -z "$VNCSESSION"; then 
104     if test x"`which xscreensaver 2>/dev/null`" != x""; then
105         xscreensaver -no-splash &
106     elif test x"`which gnome-screensaver 2>/dev/null`" != x""; then
107         gnome-screensaver &
108     fi
109 fi 
110
111 # Use ssh-agent if installed and not already running.  Run it separately
112 # so it populates the environment here, so we can clean it up later.
113 sshagent=`which ssh-agent`
114 kill_sshagent=0
115 if test -z "$SSH_AGENT_PID" -a "$sshagent" -a "x$sshagent" != "xno"; then
116         eval `$sshagent -s`
117         kill_sshagent=1
118 fi
119
120 # Use dbus-launch if installed.
121 if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
122         dbuslaunch=`which dbus-launch`
123         if test x"$dbuslaunch" != x"" -a x"$dbuslaunch" != x"no"; then
124                 eval `$dbuslaunch --sh-syntax --exit-with-session`
125         fi
126 fi
127
128 # Run xfce4-session if installed
129 xfcesm=`which xfce4-session`
130 case "x$xfcesm" in
131         x|xno*)
132                 ;;
133         *)
134                 $xfcesm
135
136                 if test $kill_sshagent -eq 1; then
137                         eval `$sshagent -k`
138                 fi
139                 exit 0
140                 ;;
141 esac
142
143
144 ##################
145 # IMPORTANT NOTE #
146 ##################
147
148 # Everything below here ONLY gets executed if you are NOT using xfce4-session
149 # (Xfce's session manager).  If you are using the session manager, everything
150 # below is handled by it, and the code below is not executed at all.  If you're
151 # not sure if you're using the session manager, type 'ps -e|grep xfce4-session'
152 # in a terminal while Xfce is running.
153
154 ##################
155
156
157 # this is only necessary when running w/o xfce4-session
158 xsetroot -solid black -cursor_name watch
159
160 # or use old-fashioned startup script otherwise
161
162 xfsettingsd &
163 xfwm4 --daemon
164
165 # start up stuff in $XDG_CONFIG_HOME/autostart/, as that looks to be
166 # the new standard.  if that directory doesn't exist, try the old
167 # ~/Desktop/Autostart method.  we're not going to do any migration here.
168 if test -d "$XDG_CONFIG_HOME/autostart"; then
169   for i in ${XDG_CONFIG_HOME}/autostart/*.desktop; do
170     grep -q -E "^Hidden=true" "$i" && continue
171     if grep -q -E "^OnlyShowIn=" "$i"; then
172       # need to test twice, as lack of the line entirely means we still run it
173       grep -E "^OnlyShowIn=" "$i" | grep -q 'XFCE;' || continue
174     fi
175     grep -E "^NotShowIn=" "$i" | grep -q 'XFCE;' && continue
176     
177     # check for TryExec
178     trycmd=`grep -E "^TryExec=" "$i" | cut -d'=' -f2`
179     if test "$trycmd"; then
180       type "$trycmd" >/dev/null 2>&1 || continue
181     fi
182     
183     cmd=`grep -E "^Exec=" "$i" | cut -d'=' -f2`
184     if test "$cmd" && type "$cmd" >/dev/null 2>&1; then
185       $cmd &
186     fi
187   done
188 elif test -d "$HOME/Desktop/Autostart"; then
189   for i in `ls -1 -L ${HOME}/Desktop/Autostart/ 2>/dev/null`; do
190     if test -x $HOME/Desktop/Autostart/$i; then
191       $HOME/Desktop/Autostart/$i &
192     fi
193   done
194 fi
195
196 xfdesktop&
197 orage &
198
199 panel=`which xfce4-panel`
200 case "x$panel" in
201         x|xno*)
202                 ;;
203         *)
204                 $panel
205                 ret=$?
206                 while test $ret -ne 0; do
207                         xmessage -center -file - -timeout 20 -title Error <<EOF
208 A crash occured in the panel
209 Please report this to the xfce4-dev@xfce.org list
210 or on http://bugs.xfce.org
211 Meanwhile the panel will be restarted
212 EOF
213                         cat >&2 <<EOF
214 A crash occured in the panel
215 Please report this to the xfce4-dev@xfce.org list
216 or on http://bugs.xfce.org
217 Meanwhile the panel will be restarted
218 EOF
219                         $panel
220                         ret=$?
221                 done
222                 ;;
223 esac
224
225 if test $kill_sshagent -eq 1; then
226         eval `$sshagent -k`
227 fi
228
229 xsetroot -bg white -fg red  -solid black -cursor_name watch