The WNCK API (Window Navigation Construction Kit) allows user interface developers to track all events of GNOME/GTK windows. It is realized as C-library. I found two binding libraries for Perl and Python. The binding libraries can be downloaded on Ubuntu Linux systems with the following command:
sudo apt-get install python-wnck libgnome2-wnck-perl
The following rudimentary example shows how to use the WNCK API with Python.
import Xlib.display
import wnck
import gtk
#First XLib tryouts
# Get X screen
screen = Xlib.display.Display().screen()
# Get root window
root_win = screen.root
# First lets look with XLib methods, which windows instances are running
window_names = []
for window in root_win.query_tree()._data['children']:
window_name = window.get_wm_name()
window_names.append(window_name)
print window_names
#Second WNCK tryouts
scr = wnck.screen_get_default()
# This is a standard GTK mechanism, which is required to capture all existing events
while gtk.events_pending():
gtk.main_iteration()
def window_focused_switch_handler(screen,window):
# Get the focused window
application = screen.get_active_window().get_application()
# Get the name of the focused and running application
cur_app_name = application.get_name()
print "The name of current application is %s" %cur_app_name
# Set the listener method
scr.connect("active-window-changed", window_focused_switch_handler)
# Needed GTK main method
gtk.main()
Regards
Rafael Sobek
Technorati Tags: GNOME WNCK Eventhandling
