[pygtk] sending X messages to other windows

Antoine Martin antoine at nagafix.co.uk
Tue Jun 23 06:43:11 WST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi,

I've got a little app in pygtk that needs to send X events (just close
and minimize for now) to other applications only known by their pid.

I've got 2 working implementations using:
1) python-wnck:
find the matching pid on the windows from screen.get_windows():
window.get_application().get_pid()
and call "minimize()" or "close(n)" or whatever on the "wnck.Window" object.
2) the win32 implementation does it using:
win32gui.GetWindow(..) in a loop and
win32process.GetWindowThreadProcessId(window) to match the pid,
then win32gui.PostMessage(...)

Problem is that python-wnck brings in far too many dependencies.
Since gtk/gdk can't seem to access windows that were not created by the
current program, I thought I'd try to use python-xlib to fill the gap.

So I did in python-xlib:
for each screen on the current display, iterate over all the top level
windows using screen.root.query_tree().children,
find the pid with some get_property magic:
window.get_property(self.net_wm_pid_atom, X.AnyPropertyType, 0, 10)
Then just send the event:
window.send_event(ClientMessage(...))

The window does close as expected, but my app becomes unresponsive, like
GTK is stuck or something.
So I thought that maybe I needed locking around the send_event() and
added a "gtk.gdk.flush()" before, I also added "gtk.gdk.threads_enter()"
/ "gtk.gdk.threads_leave()" around it.
To no avail...

What gives?

Thanks
Antoine
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREKAAYFAkpACP4ACgkQGK2zHPGK1rsVaQCcDyXwEmytKmPqQojjPHL34Qsn
Xu4AnRXWho79+/OtnwmjPM8DqCDfHH1f
=cqb4
-----END PGP SIGNATURE-----


More information about the pygtk mailing list