Restore chromium/firefox windows to original workspace/desktop

chromefirefoxworkspaces

I have a three monitor setup, with two monitors driven directly by Ubuntu 12.04 for a total workspace/desktop area of 3840×1200¹. I usually work with 5 virtual workspaces, often more if I work on several projects in parallel. I typically have at least 15 browser windows open (mostly Firefox-nightly, but also standard 12.04 Firefox and Chrome).

Whenever the browsers need to restart as the result of an update (c.q. crash), or need to start after a login, the browser windows come back to the original positions, but all are on the same workspace. After that I have to tediously move at least 80% of the windows to other workspaces².

Neither Firefox nor Chrome save the extra EWMH information that is needed for restoration to the original workspace. I have read unresolved bug reports dating from 4-5 years ago about that.

It seems that, at least a few years back, KDE managed workspaces as large offsets (wider than the screen(s) width), which allowed the browser to restore to the correct workspace. But this no longer seems to be the case (deducted from a bug report, not from personal experience).

Is there is a workspace/desktop-manager that doesn't have this restore-all-to-one-workspace behaviour with Firefox and Chrome (preferably on for Ubuntu or Linux Mint)?

Or is there another way to enhance Firefox and Chrome (e.g. add-on) to enforce this behaviour?

Mine is not a fixed layout, where Browser X on workspace Y always opens to a specific URL. The restoring function gives me the windows, positions and URLs exactly the way I want them. They "just" need to be on the correct workspace.

¹ A third 1200×1920 monitor is on a separate machine with x2vnc used to share a single mouse and keyboard. That nicely keeps my reading material like man pages and documentation available (in portrait mode).
² All U&L stuff is on workspace 3. I normally leave the machine running, and stay logged in, for weeks at a time, one of the reasons for that being the restoration of the various windows.

Best Answer

There doesn't seem to much motivation to implement some EWMH support in Firefox nor in Chrome, even though this would get the restoration to workspace issue resolved with a large number of desktops. A bug has been open for Firefox since 2007 and one for Chrome since 2009.

What you can do outside of Firefox and Chrome, if the active TABs in different browser windows point to different URLs, is to use tendency that different URLs usually have different titles associated with the pages and hence with the window in which they are displayed.

Starting with that idea you can use the output of wmctrl -l -G -p which provides you with

  • window id
  • workspace number
  • process id
  • x,y position of window
  • width and height of window
  • machine name
  • window title (if any)

for each window. Given a process id PID you can see where the link /proc/PID/exe points to and filter out non-browser windows. For the browser related windows, save at least the window title and workspace number (possible also the browser type and all the other information).

After a browser (re-)start, when all the windows are restored, but on in one workspace, use the saved data to lookup the new window id, WID, associated with a specific title and push it to the retrieved related workspace with wmctrl -i -r WID -t workspacenumber.


If you don't want to implement the above yourself (it is mostly text processing and a symlink lookup) in your shell or scripting language of choice, you can download a program that does all this for you (and a bit more). Or you can install it from PyPI using:

sudo pip install ruamel.bws

after which the bws command should be available with options to save (multiple saves are kept, 10 by default), list (show the saved dates with number of windows saved), or restore (by default the latest saved info).

Related Question