Independent workspaces for multihead X server

I have always had trouble adjusting to multihead setup. There are physical problems:

  • you have to move your windows as you connect and disconnect second display (it's a mess),
  • you have to make room for another display,
  • you might need to adjust working space and maybe you will also need get another (higher) chair.

Aside from these problems there are also conceptual problems. I am long used to 4 and more workspaces on 1 display. You can browse on workspace 1, write code on workspace 2, 3 and 5 and maybe e-mail on 4). It is quick and convenient and very comfortable even if you have to do number of tasks for long time (switch between them as needed or suspend the system).

The Problem

If you add another display to this, it brings some annoyances. In you can have two separate displays and can't really move the windows between them or swap them completely (there are some ways to do this but not very stable). Then came Xinerama and now you can have one wide workspace across all displays. Great, right? No.

See, when you switch workspaces, you will switch both displays at one time. In Windows system you are fine, you get two workspaces! Some folks even get three but beyond that point it is REALLY ridiculous, you can't watch all your displays at once, just use workspaces and you'll be fine with one display (and you have it always with you if you use laptop!).

So second workspace is huge advantage. But I already have N workspaces and with another display I get only one more. I guess it is typically used with sticky browser window (testing, documentation, facebook?), not so great advantage. When doing projects for school there were only few occasions when I really did want another display for that one additional workspace.

The Solution?

I have always imagined independent workspaces for both displays. Yeah, when you imagine something and don't think it through, you can really wonder why isn't it possible… it's perfect, right? Well, you don't really know until you try it. I have tried it, it has obvious advatages.

But there are some problems:

  1. implementation for arbitrary number of displays, stacked on the top and on the sides, would be really complex (maybe impossible?),
  2. it is more complex to use – more keyboard shortcuts, more things to remember about current state in YOUR brain,
  3. there are more windows to tab between as they are coupled for both displays,
  4. it is harder to organize your windows – in the end you don't use all 2×4 workspaces, and it is easier to make mess (you can swap windows on current workspace between displays),
  5. it will make huge mess if you unplug display and really do use all workspaces!

Some of them could be solved with native implementation of independent workspaces but maybe it is not even worth it. Implementation has to work around the concept which is in place, there are some quirks and EWMH workspace pagers will be a bit confusing (netwmpager has problems with updates, xfce4-panel seems to be OK).

If you want to use it on desktop, then I think it is really worth it, although it is more complex to use.

The Implementation

:!: Note that it implements support only for 2 displays next to each other. It might work if they are not in line but I never tested this. Also I had to account for some weird offsets in reported positions so these numbers might be different on another system.

We need 1 native workspace which we use to show current selection of independent workspaces. For 2×4 independent workspaces we use 4 more native workspaces and we move windows between these and active workspace. We might use 8 native workspaces for this and it would be better in case of unplugging second display but unfortunatelly, pagers would get REALLY large and even more confusing.

I am using wmctrl for sending commands to windows and xrandr to retrieve information about screens. It is fast enough but xrandr was slow so you have to send command to update information about screens. There is this Ruby script for on-screen display which has infrastructure for receiving commands via Unix socket so I leveraged this and added this new prototype feature for workspace management.

You have to send echo wm switch <0-1> <1-4> | nc -U /tmp/osd.socket to switch to workspace 1-4 on display 0-1. There are more commands (simple swap between current independent workspaces and more advanced swaps) but I won't document them here.

So I have tested this setup:

  • 2 displays next to each other (XRandR),
  • 5 native workspaces (2×4 independent),
  • xbindkeys shortcuts for both displays – Ctrl+F1..F4 and Win+1..4; Win+Tab for swapping,
  • my workspace managing script.

Bonus: It will switch between current and last selected workspace if you “switch” to current workspace (i.e. Ctrl+F1 on workspace 1 switches to previous workspace).

The Conclusion

  • It works.
  • It is viable.
  • It is not better for people who want just 2 workspaces.
  • It is better for me but I will rather not get used to it. One display and five workspaces is good enough and I can take it anywhere.
  • I would probably use it on desktop (but I wouldn't need as much workspaces there, I'd rather keep work on laptop).

(:!: Read updates below about advanced implementation with alternative approach which I am currently using.)


This is just an experiment, a prototype, proof of concept. And it's based on my ugly little OSD script. But it worked. It can be faster and more efficient (maybe with direct xlib or xcb calls), but it is not worth the time. Here it is: osd-wm.rb

It should work with any EWMH compliant window manager which uses workspaces, probably not with viewports (I am not familiar with this concept so maybe it is possible).

:!: Ported to Python – catches X keys by itself and doesn't need xbindkeys, xrandr or wmctrl. Just install Python and python-xlib. Then set your window manager to 5 workspaces and switch to first workspace. Then run python

Shortcuts are Ctrl+F1..4 for left display, Win+1..4 (Win is Mod4) for right display and Win+Tab for swap. If it doesn't work edit and change keycodes according to xev output. :!: For best results unbind these keys elsewhere (xfwm4 or other window managers, xbindkeys).

:!: Update: there is new default behaviour which uses (N-1) independent workspaces shared by all displays. This has some advantages when unplugging and even should work on more than 2 displays.

:!: Update: there is new default behaviour which uses (N-1) independent workspaces shared by all displays. This has some advantages when unplugging and even should work on more than 2 displays.

:!: Update: After more than two years of usage I can say (N-1) independent desktops is just perfect (2 displays with identical width resolution set). In the latest update there is support for simple clearing of secondary display to allow turning it off.


stuff/independent-workspaces-for-multihead.txt · Last modified: 2014/09/28 07:40 by disorder