arduino Raspberry Pi project

Raspberry Pi Window Manager Control with Xinitrc

by Lewis Loflin

Updated for the Raspberry Pi 2. PiBang has been replaced by Wheezy Raspbian.

Raspberry Pi has sold over 1 million copies and is a gold mine for leaning about computers and programming. While aimed at kids, it can be a superb tool for those wanting to learn Linux as well. For more on this series see Build Your Own Raspberry Pi Arduino System

Note the Wheezy used with Raspberry Pi 2 will work on Raspberry Pi 1.

What we will do here applies to any Debian based Linux system that boots to the command line and not a display manager.

While we can do most Linux functions from the command line having a "windows" style display is a must. Here we will avoid to use of the built in display managers and directly configure and control the display with a file known as Xinitrc. For a sample of what I've built see the following screen shots.

An explanation of desktops

We need to be clear just what is a desktop? While this is aimed at Raspberry Pi it's the same on most other Linux desktops - here I'm sticking with basic Debian.

Raspberry Pi comes with the LXDE Desktop, it has a window manager bar at the bottom or top. These allow one to access files, holds a clock, etc. The 'desktop" where there are clickable icons, etc. uses PCmanFM which comes standard with LXDE and is also the file manager.

One can have multiple desktops such as Fluxbox, Openbox, JWM, KDE, etc. I stick with the first three because they are easy to configure and use very little system resources. This is important because the Raspberry Pi A and B lack both memory and CPU power - Raspberry Pi 2 has double the DRAM and up to six times the CPU power.

What that means one can operate larger programs or multiple programs at once. Fluxbox, Openbox, and JWM only need 50-60 megabytes of system memory to operate and on a Raspberry Pi about 4% of the CPU power. That means web browsers like Midori will work fairly well.

Here are some more examples click on the link:

This is Fluxbox with the Rox-Filer pinboard for icons with the Rox-Filer file manager. Right click on the desktop and the menu will drop down. Fast and easy to use, but is not like the old Microsoft Windows.

To get this download the following:

~ $ sudo apt-get install fluxbox rox-filer

Openbox actually comes with the LXDE on the Raspberry Pi. Illustrated ss3.png uses the tint2 bar at the bottom with the rox-filer pinboard. To make it fully functional download the following:

~ $ sudo apt-get install obmenu rox-filer xfce4-panel tint2

The tint2 or the xfce4-panel can be placed at the top or bottom just like the LXDE bar.

The screen shot saa1.jpg illustrates the xfce-panel at the bottom of the picture.

JWM1 is the most like Windows, so one needs the following:

~ $ sudo apt-get install jwm x11-apps

Stored in the users home directory .xinitrc controls which window manager we use and what to use with it. I'm using lightweight window managers Openbox, Fluxbox, and JWM. This is a hidden file that that's named as .xinitrc in the home directory with a number of other hidden configuration files and folders.

The "." at the beginning of the name means this is a hidden file.

The following was derived from the Xinitrc Wiki

The ~/.xinitrc file is a shell script read by xinit and by its front-end startx. It is mainly used to execute desktop environments, window managers and other programs when starting the X server. The xinit program starts the X Window System server and works as first client program on systems that are not using a display manager.

One of the main functions of ~/.xinitrc is to dictate which client for the X Window System is invoked with startx or xinit programs on a per-user basis.

In the case of Raspberry Pi a missing .xinitrc file the system will default back to the original LXDE desktop it came with.

Overriding xinitrc from command line

If you have a working ~/.xinitrc, but just want to try other WM/DE, you can run it by issuing startx followed by the path to the window manager:

$ startx /full/path/to/window-manager

Now, edit ~/.xinitrc and uncomment the line that corresponds to your DE/WM. For example, if you want to test your basic X configuration (mouse, keyboard, graphics resolution), you can simply use terminal program such as Lxterminal:

~ $ /usr/bin/jwm

The above assumes you are not already running a window manager! Below is our most basic .xinitrc file.

# ~/.xinitrc
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  unset f

# exec fluxbox
# exec openbox-session
# exec jwm
# ...or the Window Manager of your choice

Below is the version I setup for this series. Copy and past with your favorite text editor and save in your home directory as .xinitrc . When you type startx the system will read this file and follow it. This is self-explanatory.

For setting up Openbox see Setting up Openbox for Raspberry Pi. A line with "#" is considered "commented out" so if one want to use say JWM, the Rox-filer pinboard with clipit in the tray simply delete "#". Chose only one window manager!

See the section below on setting up wallpaper.

Note that if this file is missing or renamed the original LXDE will operate. The following assumes the associated program was installed.


# save this file as .xinitrc in your home directory.
# make this file executable: (as root) chmod +x .xinitrc

if [ -d /etc/X11/xinit/xinitrc.d ]; then
        for f in /etc/X11/xinit/xinitrc.d/*; do
                [ -x "$f" ] && . "$f"
        unset f

xrdb -merge ~/.Xresources         # update x resources db

xscreensaver -no-splash &         # starts screensaver daemon 
xsetroot -cursor_name left_ptr &  # sets the cursor icon

# feh wallpaper must be added to openbox autostart to work.
# ok for JWM or Fluxbox
#sh ~/.fehbg &                     

#rox-filer pinboard. If using with conky set both to same background
# may not work with conky
#exec rox --pinboard=pblewis &

#This is a panel strip for the top or bottom or top 
# don't use with above
#rox --top=myp2 &

# pcmanfm that comes with LXDE 
# can be used as a desktop manager for JWM
# this retains the desktop links used with LXDE
#exec pcmanfm --desktop &

# conky is a system monitor - don't use as root.
# don't use with pcmanfm
# exec conky &

# clipboard in tray use which ever was installed but only one.
# exec parcellite &
# exec clipit &

# this is the tray for use with openbox 
# don't use with JWM or fluxbox
# exec tint2 &

# use this as an alternative to tint2 
# don't use with JWM or fluxbox
# exec xfce4-panel &

# select only one window manager
# exec openbox-session
# exec fluxbox
# exec jwm