in reply to Any way to query which X Window has focus from Perl?

The function I think you want is described in 'man 3 XGetInputFocus'. There is a last_focus_change variable which may be helpful. I've never called X directly from perl, can't help there.

After Compline,
Zaxo