Tuesday, March 13, 2012

nodm and matchbox window manager and auto starting applications

I'm working on a project for work that is based around a live distro.  For the live distro building, I went with live-build since Debian is by far my favorite distro.  The live build was pretty easy to implement, and I'm not going to bore you with the details when there's plenty of documentation out there, especially the live-manual.  This post is all about how to get Xorg started and how to launch an application when Xorg starts up without diverting files in other packages, or having a match install anything to a users home directory.

The clear start to this task is nodm.  It'll automatically login as a user and start your xsession.  If you don't have an xsession installed, it'll fall back to the normal Debian xsession script that'll just launch an xterm.  This is simple enough, but remember that without a window manager, you're not going to get any of the standard desktop magic that the freedesktop.org window manager specification gives you.  For example, being able to call gtk_window_maximize.

To fix that problem I went with matchbox window manager.  It's very light weight window manager meant mostly for mobile devices and runs apps in full screen, thus eliminating my need to maximize the application window.  Matchbox registers itself as an alternative for x-window-manager under Debian which, in this bare bones approach will start matchbox on boot, but no apps.

Luckily, the matchbox package depends on matchbox-common and matchbox-common contains /usr/bin/matchbox-session.  This script looks for a session script and will execute it, if it doesn't find one, it'll launch matchbox-desktop and matchbox-panel in the background, and then launch matchbox-window-manager in the foreground.  The real awesomeness here, is that matchbox-session checks if there is an executable script named session in /etc/matchbox/.  What this means, is that you can easily create a package that depends on matchbox and install that file.  This fulfills all of our requirements!!  But wait, matchbox-session won't be called from nodm...

Solving that problem is actually a lot easier than you're probably thinking.  Debian's Xsession scripts give a higher priority to x-session-manager which is in the alternatives system.  So all we need to do, is to register matchbox-session as an alternative for x-session-manager.  Once this is done, our custom /etc/matchbox/session will get executed and we're good to go :)

Due to NDA's and stuff, I can't post my exact package here, but here's the jist of it.

Make sure your control file depends on "matchbox" (that's the meta package for matchbox and will pull everything in); you can probably clean it up to just matchbox-common and matchbox-window-manager, but I leave that to you.

Next create a postinst script that contains the following:

#!/bin/sh
set -e
case "$1" in
        configure)
                update-alternatives --install /usr/bin/x-session-manager \
                        x-session-manager /usr/bin/matchbox-session 50
        ;;
esac
#DEBHELPER#
and a prerm which contains the following:

#!/bin/sh
set -e
case "$1" in
        remove)
                update-alternatives --remove x-session-manager /usr/bin/matchbox-session
        ;;
esac
#DEBHELPER#
Then create your custom session script.  Mine looks something like this:

#!/bin/sh
application &
exec matchbox-window-manager
Make sure all three of those are executable, add the session script to your install file, fire off debuild  and you should be good to go.

I hope this helps other, since googling for this earlier came up pretty empty :)


3 comments:

  1. Hello! I have been looking for a post like this since days! I am trying to follow your instructions and installed nodm fine. The problem is than Gnome Windows Manager keeps running instead Matchbox Windows Manager. Where the f%&$ I can tell Debian to run Matchbox instead Gnome???

    Thanks a lot in advance!

    ReplyDelete
    Replies
    1. You should be able to "sudo update-alternatives --config x-window-manager" from inside the chroot or on a live system. So you can either do this via a live-build script or put together a simple package that tweaks the priority on matchbox. I don't have an example of that handy, so maybe the live-build script is a better idea ;)

      Delete
  2. Hello there,

    I installed Debian Jessie 8.3 AMD64 with matchbox as the window manager and slin as the login manager, it works fine.
    I can login and then I get a matchbox environment with a mouse pointer.
    But now I want to start a user specific GUI application.
    I created a session file with the following contents:

    #!/bin/sh
    lxterminal &
    exec matchbox-window-manager

    The file is placed under the .matchbox directory of my home folder.

    What am I doing wrong?

    Thanks in advance,

    Jan Visser

    ReplyDelete