How do I switch between window manager workspaces using Python with the Xlib module?
This is my most promising attempt:
#!/usr/bin/python from Xlib import X, display, error, Xatom, Xutil import Xlib.protocol.event screen = Xlib.display.Display().screen() root = screen.root def sendEvent(win, ctype, data, mask=None): """ Send a ClientMessage event to the root """ data = (data+[0]*(5-len(data)))[:5] ev = Xlib.protocol.event.ClientMessage(window=win, client_type=ctype, data=(32,(data))) if not mask: mask = (X.SubstructureRedirectMask|X.SubstructureNotifyMask) root.send_event(ev, event_mask=mask) # switch to desktop 2 sendEvent(root, Xlib.display.Display().intern_atom("_NET_CURRENT_DESKTOP"), [2])
The above code is shamelessly stolen from different places in the PyPanel source; Unfortunately, it does nothing, does not even generate a warning / exception. Did I miss something?
I am using Python and PyGTK. Xlib seems to be the right choice for switching desktops. I do not intend to use wnck (the Python buggy module) or similar, but I would still recognize any pointers.
I can add that this is my first attempt to write a Python application using Xlib (or PyGTK).
source share