Window Position Session
Yesterday I finally sat down to properly set up some mechanisms to restore my desktop and the window arrangements on all workspaces (I use four). I use GNOME and it features Startup Applications, allowing to run everything at login. Cool, but now all those applications are slapped into the first workspace, with window positions and sizes all over the place, so I started googling, and a few links down found this post on Mattman's blog.
He also explains how to set up Startup Applications (and give terminals specific titles) and provides two scripts to save and restore window geometry and put them on the right workspace. It was just what I needed, but there were three problems I had, which weren't solved by the scripts yet:
- titles couldn't have spaces, due to the way his conf file works
- you needed the full title, but "Amarok - The Times They Are A-Changin' by Bob Dylan" wouldn't always be the guaranteed title
- states like maximized, pinned, etc. couldn't be restored
I looked at his scripts and they use a tool called wnckprop, which in Ubuntu 9.04 for instance can be obtained by
~> sudo apt-get install libwnck-dev
wnckprop apparently follows EWMH specifications, so my script might work with KDE as well. I haven't tried that, but if you do, please comment.
Usage is straightforward:
~> ./window_position.py --help
Gives some help...
Usage: window_position.py [options] [file] Options: -h, --help show this help message and exit -s, --save save all window positions -r, --restore restore all window positions -i, --case-insensitive case insensitive window title matching
file is optional. If not given, then -r will read from stdin and -s will write to stdout.
Using -s will result in a conf file with one section per window, the section name is the window title:
... [Terminal] x = 123 y = 50 width = 500 height = 400 workspace = 0 [Amarok - The Times They Are A-Changin' by Bob Dylan] x = 50 y = 50 width = 600 height = 500 workspace = 1 actions = pin ...
This file can now be used with -r to restore the exact arrangements again. Tho you usually want to edit it and only use the windows and attributes you really want to set.
Sections can have spaces, so no problem there. It is also possible to use regular expressions in those section names, so this would be more useful:
[Amarok .*] x = 50 y = 50 width = 600 height = 500 workspace = 1 actions = pin
NOTE! due to the way ConfigParser parses the conf file there is no way to determine the order of the sections (at least not that I could see in the docs), so you can't just overwrite attributes:
[Terminal .*] x = 0 y = 0 workspace = 3 [Terminal 1] x = 50 y = 60 [Terminal 2] x = 500 y = 60
This might produce odd results, if Terminal.* is looked at -after- one of the others, resetting the x and y attributes again. Use distinct sections:
[Terminal .*] workspace = 3 [Terminal 1] x = 50 y = 60 [Terminal 2] x = 500 y = 60
You can add several actions like so:
[Terminal] actions = pin, minimize, unmake above
Which would pin the window to all workspaces, minimize it, and make sure it isn't set to above (always on top). See below for a reference of all available actions.
Here's a snippet of what I use:
# all 'Dev Terminal *' terminals go to workspace 1, # have same dimensions [Dev Terminal .*] workspace = 1 width = 700 height = 480 # then arrange them top-left, top-right, bottom-right, bottom-left [Dev Terminal 1] x = 0 y = 0 [Dev Terminal 2] x = 983 y = 0 [Dev Terminal 3] x = 983 y = 548 [Dev Terminal 4] x = 0 y = 548 # Eclipse is put somewhere in the middle on the same workspace [.*Eclipse.*] workspace = 1 x = 232 y = 102 width = 1219 height = 838 # KVIrc is on the first workspace and maximized [KVIrc.*] workspace = 0 actions = maximize # my Pidgin window initially is opened, but I want it closed, # this will only close the window, Pidgin will still by in the Panel [Buddy List] actions = close # Amarok should be available on all workspaces and initially minimized [Amarok.*] actions = pin, minimize
x = 0 y = 0 width = 500 height = 500 workspace = 2 (usually starts at 0) actions = close, move, shade, unshade, maximize horizontally, unmaximize horizontally, maximize vertically, unmaximize vertically, pin, unpin, minimize, unminimize, maximize, unmaximize, make above, unmake above, make below, unmake below
There's a slight problem with wnckprop when reading the x and y values. If I put a window to the top left of the workspace, for instance, then I get the y value 25, because of the Panel that is still above the window. But when it then sets y to 25, it actually ends up 25 down relative to the Panel. The solution is to put y = 0 manually.
I'd also like to find a way to specify the tab order in the bottom Panel. wnckprop can't handle that, I don't think, so if anyone has an idea for that: please comment. As an example: I'd like to have Dev Terminal 1, Dev Terminal 2, Dev Terminal 3, Dev Terminal 4 as tabs in that order, but GNOME's Startup Applications of course don't guarantee any order.