Doing a “Show Desktop” using Python’s libwnck bindings

Quick tip: you can do a Show Desktop from a script (from Python, in this case), with:

python -c "import gtk,wnck,gobject; s=wnck.screen_get_default(); s.toggle_showing_desktop(True); gobject.idle_add(gtk.main_quit); gtk.main()"

8 Responses to “Doing a “Show Desktop” using Python’s libwnck bindings”

  1. Interesting; I’d not seen wnck - does it allow you to show windows fullscreen without menus, etc?

    mrben
  2. mrben: wnck is an interface to the window manager, essentially. It’s what the pager uses to know where windows are and so on. I’m not sure if it lets you alter an existing window; devilspie does that, but I don’t know if it uses libwnck.

    sil
  3. mrben, sil: It seems that wnck can do that (or at least its API has the corresponding functions ;-)). It looks equivalent to devilspie, or slighly more detailed (e.g. for viewport).

    It works ONLY if you have called gtk.main(), e.g. :

    def run():
    print wnck.screen_get_default().get_windows()
    # do your job here
    gtk.main_quit()

    gobject.idle_add(run)
    gtk.main()

    jiba
  4. Well, I the code provided by jiba. But, I got none windows:

    leon@localhost ~/tmp_python $ python wm.max.py

    []

    Why ? But, the “Show Desktop” code works.

    Leon
  5. Hi, where i can find tha API for the libwnck python module ??

    Manuel Mazzuola
  6. Manuel,

    Trying to build sugar I presume? I’m looking for it as well.

    bj
  7. Sugar ? what is ?

    Manuel
  8. You need to run force_update() on the screen before pulling anything from it. If you run that before get_windows() it all works OK! :)

    mibus

Leave a Reply