Setting default user session in GDM (default != latest)

Throughout most of my linux life I have had two desktops installed: Gnome and Openbox. The first for most everyday uses, the second specifically to create a no-nonsense environment for games. Openbox just works better for a lot of wine as well as native inux games – less screen-, keyboard and ressources-hogging etc.

So when I log out of Openbox it’s in order toget back to business. GDM sees it differently: You’re always set to log into the last desktop you logged out of. This is just plain wrong. To set it right I found this Fedora forum post pretty helpful. Here’s how I put it to use to set a default desktop for my user, regardless of what I was last logged in to.

In short, you want to make the change in /var/lib/AccountsService/users/[name of user] which is a small ini-like config file that stores user related settings for your login manager, stuff like your picture and default session.  However any changes to the latter are overwritten as soon as you log out. So. We need to overwrite the overwrite after each session.

To do this, edit the file /etc/gdm/PostSession/Default which is a tiny (on my install, empty) script run by GDM when a user logs out. We then give this script a single line of sed that changes whatever desktop has been set in the AccountsService file with the default desktop of our choice. Simple.

The forum post makes use of the environment variable USER. Seeing as GDM runs as the root/gdm user I’m not entirely convinced that would work. Since I only have one user on my laptop, I simply substitute my user name for the variable. So: Whenever any user logs out, my default is reset. I don’t see any harm in that.

#!/bin/sh

sed -i '' -e 's|^XSession=.*|XSession=gnome|' /var/lib/AccountsService/users/[name of user]

exit 0

Sed is difficult with backup and temporary files: It insists on making them and storing them in the folder of the original file. -i ” should tell it not to make backups. And since we can’t prevent temporary files, it will only work when run with root permissions (because only root has write access to the folder).

As for the meat of the line: It finds a line that begins with Xsession and changes the bit after the equal sign to ‘gnome’. Check /usr/share/xsessions to see which are available (oh and since you’re there, rename any you don’t want to see in GDM with a .bak extension). Sed can complain even when it works so if you test it manually before logging in and out of various user sessions, do check the config file before and after to avoid false negatives.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.