You can probably do this using XLib interface directly (units x, xlib) and polling. I don't know if you can get an event for this. http://tronche.com/gui/x/xlib/input/XGetInputFocus.html Warning: XLib programming is not easy. ;-)