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
wnckprop
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
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.
Saving
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 ...
Restoring
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.
Title Matching
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:
WRONG:
[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:
CORRECT:
[Terminal .*] workspace = 3 [Terminal 1] x = 50 y = 60 [Terminal 2] x = 500 y = 60
Actions
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.
Example
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
Reference
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
To Do
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.
Comments
Thialfihar 11:52 March 18, 2010
Hmm, no idea. I've only used this without compiz and only up to four desktops. You could try to turn compiz off and see what wnckprop says, to rule out that compiz somehow messes it up. Same with the number of desktops?
Sorry about the late response. I ought to implement some notification here. ;)
Matt 02:13 December 23, 2010
Is there any way to manipulate windows with special characters. When I browse a web site that contains brackets in the title it is not seen by the script.
So if a window title is something like "Zimba Inbox: (3) - Google Chrome" that window will not be saved or restored even if you use a RE like "*Google Chrome"
Thialfihar 17:05 December 25, 2010
Matt: I haven't tried this, but perhaps your regular expression is off? It should be ".*Google Chrome", just an asterisk (*) is not enough in regex.
Jan Christoph Uhde 05:35 May 09, 2011
maybe you want to take a look at:
Sam 11:32 February 16, 2010
Thanks for this. Nice work!
I've tried the script and couldn't get it to work properly. For some reason wnckprop does not see my other workspaces. The script returns workspace = 0 for all the windows.
I'm using Compiz with 6 desktops. Do you have any clue how to get around this?