Tuesday Oct 21, 2008

GNOME 2.24 Session Save & Restore

The latest version of the GNOME Desktop version 2.24.0 contains pretty much a complete rewrite of it's session handling module gnome-session.

One of the features missing from this release is the ability to Save and Restore your session, now bear in mind the session saving and restoring was not completely functional in the first place, applications such as StarOffice, Firefox and Thunderbird all ignore the session management and thus could not be restored via gnome-session.

So how can one get around this, is there a valid workaround ?

Actually there is and it's not that difficult :)

The new gnome-session implements an autostart mechanism for determining what applications are launched for a given session. The autostart mechanism in turn employs .desktop files to define the applications and paramaters etc. You can use gnome-session-propertites capplet maintain the list of applications to be launched for your session.

The default set of autostart files are located under /usr/share/gnome/autostart, for user specific applications .desktop files are located under $HOME/.config/autostart.

You can add specific applications via the preferences capplet gnome-session-properties, which will create the custom .desktop files for your in $HOME/.config/autostart, or you can manually create then .desktop files yourself.

So specifying what applications should be Launched/Restored for your session is quite easy.

The only issue here is that all your apps will appear on the the same workspace (first one), and as for geometry, you would have to rely on the specific application having some CLI for setting X/Y and width/height.

For me this wasn't enough, so I thought how difficult could be be to write a simple shell script that would given some config data, do all this positioning/sizing for me. Turned out to be relatively simple.

So I hacked together two scripts, save-session and restore-session.

Looking at restore-session firstly, it simply reads config data from $HOME/.config/restore-session.conf. This new config file contains a list of name identified applications with location and sizing information. Each line contains TAB separated fields of the following format :

    NAME WORKSPACE X Y WIDTH HEIGHT

e.g.
    #NAME WORKSPACE X Y WIDTH HEIGHT
    GnomeTerminal1 0 397 266 593 719
    GnomeTerminal2 0 1001 266 593 719
    GnomeTerminal3 1 30 30 726 719


Line 1 of the config file is ignored as it just defines column headers, for readability. The NAME column is a single word identification for the specific application. In this example I specify three gnome terminals, two will be located on first workspace (bear in mind workspaces tend to be numbered from 0), and the third terminal located in second workspace.

The restore-session script uses the command line utility wnckprop to get and set information for application windows. This is delivered as part of the SUNWgnome-panel package.

So expanding on the example config file above, for my session I want to restore three terminals with the location and size specified. I now need three .desktop files to start my three terminals on login.

Here's an example for one of them :

    [Desktop Entry]
    Type=Application
    Name=Terminal 1
    Exec=gnome-terminal --title="GnomeTerminal1"
    Icon=utilities-terminal
    Comment=Run a command line shell

Notice how you can specify the title for your terminal via the --title CLI option for gnome-terminal. Just create three of these desktop files and set the titles to be GnomeTerminal1, GnomeTerminal2 and GnomeTerminal3. and place them in $HOME /,config/autostart. The next time you login three terminals will be launched.

Then you ask but this dosen't restore the locations/sizes, there are two methods of doing this part. One would be to create another .desktop file and call the restore-session script directly from it, this however is not reliable as there's no way of guaranteeing the launching order of applications via the autostart method, thus the restore-session could get run before your terminals, and thus will not be able to set their window properties.

The 2nd method is to simply place a launcher on your panel, which runs this script. Again not ideal but still a very simple method to set the properties, you just need to press one launcher each time you login in and presto all your windows get relocated and resized to where you want them.

The 2nd script save-session simply get's the name, size and location properties of all your current application windows and generates a $HOME/.config/restore-session.conf file. This generates config file requires hand editing to set the correct names, but it's a good starting point for generating a $HOME/.config/restore-session.conf file.

Both scripts were written over a few hours one evening so are not perfect, but they do highlight a means of working around the fact that your session is not restored anymore. I'm sure they can be improved. To access the source for the scripts and the example config file just click on any of the links.

About

Install engineer at Oracle who is passionate about Music, Sport and has a soft spot for Solaris

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today