views:

156

answers:

2

Hello everyone,

I'm looking for a way to determine if the user switches virtual desktops under X11.

I'm using Python with X11 libraries and PyGTK. I found some working examples in C, but I lack the expertise to translate them into Python, and I read the source code of several X11 pager applications (fbpanel, pypanel), but I can't seem to find what I'm looking for.

Do I have to register for a signal? Using X11 or GTK? Do I have to busy-wait?

I'm completely new to both X11 and GTK, so any hints/help would be greatly appreciated.

Greets, Philip

PS: My current efforts can be found here.

A: 

You may want to take a look at libwnck, or possibly its Python bindings.

Ignacio Vazquez-Abrams
I have already looked into libwnck (which is exceptionally neat), but I don't want to add another dependency to the program when I can as well solve it using X11/GTK.
Philip
A: 

Here is a GTK based solution:

screen = gtk.gdk.screen_get_default()
root = screen.get_root_window()
root.set_events(gtk.gdk.SUBSTRUCTURE_MASK)
root.add_filter(event_filter)

def event_filter(event, user_data):
        # process event
        return gtk.gdk.FILTER_CONTINUE

Apparently, the SUBSTRUCTURE_MASK contains events which are typically associated with workspace switches. Nevertheless, this solution feels a bit awkward. Any ideas?

Greets, Philip

Philip