Friday, 12 July 2013

A Little About startx

startx [ [ client ] options ... ] [ −− [ server ] [ display ] options ... ]

OK, so startx is what is used to start your X server and some X clients. As I previously mentioned, most times you'll just be running your Display Manager (xdm, gdm, etc.) which will do similar things to what startx would; that is - start your X server (hardware abstraction) and X clients; a lovely login screen ready for GNOME (or whatever).

Not having a /dev/fb0, and thus not being able to run startx in its default greatness, meant I needed to look under the hood. I found this command;
startx -- `which Xvfb` :1 -screen 0 1024x768x24

Assuming you have Xvfb installed (I believe it is by default on BB A6), then try typing which Xvfb at the command prompt. You should see /usr/bin/Xvfb. That's to say you could just as happily typed;
startx -- /usr/bin/Xvfb :1 -screen 0 1024x768x24

Here we only have server side arguments (stuff after the '--'); that is, the server to use, what display to attach it to, and some server arguments.

Now, just some of the variables that are set up in the default code;
userclientrc=$HOME/.xinitrc               DOES NOT EXIST
sysclientrc=/usr/lib/X11/xinit/xinitrc    EXISTS
userserverrc=$HOME/.xserverrc             DOES NOT EXIST
sysserverrc=/usr/lib/X11/xinit/xserverrc  DOES NOT EXIST
defaultclient=xterm
defaultserver=/usr/bin/X

This is from the manual.
To determine the client to run, startx first looks for a file called .xinitrc in the user’s home directory. If that is not found, it uses the file xinitrc in the xinit library directory. If command line client options are given, they override this behavior and revert to the xinit(1) behavior.
To determine the server to run, startx first looks for a file called .xserverrc in the user’s home directory. If that is not found, it uses the file xserverrc in the xinit library directory. If command line server options are given, they override this behavior and revert to the xinit(1) behavior. Users rarely need to provide a .xserverrc file.
See the xinit(1) manual page for more details on the arguments.
OK, so lets use an example. The system-wide xinitrc and xserverrc files are found in the /usr/lib/X11/xinit directory. Now looking at the code;

# process client arguments
if [ x"$client" = x ]; then
    client=$defaultclient

    if [ x"$clientargs" = x ]; then
        if [ -f "$userclientrc" ]; then
            client=$userclientrc
        elif [ -f "$sysclientrc" ]; then
            client=$sysclientrc
        fi
    fi
fi

This checks if $client is NULL.
x"$client" = x

If it is, then it sets the default client. Now, if no client arguments are given, then that is replaced with the xinitrc file. So running this command;
startx -geometry 80x50+494+51

Would cause the client to be set to xterm via the $defaultclient, however, the xinitrc file would not be run due to the arguments.

The .xinitrc is typically a shell script which starts many clients according to the user’s preference. When this shell script exits, startx kills the server and performs any
other session shutdown needed. Most of the clients started by .xinitrc should be run in the background. The last client should run in the foreground; when it exits, the
session will exit. People often choose a session manager, window manager, or xterm as the 'magic' client.

twm &
xclock -geometry 50x50-1+1 &
exec xterm -geometry 80x66+0+0 -name login

So, start all your clients in the background using the '&' operator. The last one should use exec and be run in the foreground. This basically means that the process is passed over to xterm. Once this shuts down, xinit will then shutdown the X server and process any shutdown commands.

No comments:

Post a Comment