#!/usr/bin/python

from gi.repository import GLib, Gdk, Wnck

def active_window_change_cb(screen, window, data):
    if window:
        print 'active window changed:', window.get_name(), 'pid', window.get_pid()
    else:
        print 'active window changed (none)'

# main
screen = Wnck.Screen.get_default()

screen.connect('active_window_changed', active_window_change_cb, None)

main_loop = GLib.MainLoop()

print 'wnck set up for 5 seconds; change window focus to test...'
GLib.timeout_add_seconds(5, GLib.MainLoop.quit, main_loop)
main_loop.run()

print 'shutting down wnck for 5 seconds'
Wnck.shutdown()
GLib.timeout_add_seconds(5, GLib.MainLoop.quit, main_loop)
main_loop.run()

print 'reinitializing wnck'
screen = Wnck.Screen.get_default()
screen.connect('active_window_changed', active_window_change_cb, None)
print 'wnck set up; do more focus changes to test, press Control_C to finish'
main_loop.run()

