I'd like to know (programmatically) which window has current focus. Is there a window-manager independent way of discovering that?
Otherwise, how does one determine which window has focus in Compiz or Metacity?
Another thing you can use is xdotool:
would return the Window ID of the focussed window, and:
xdotool getwindowfocus getwindowname
would tell you its name.
try using the wnck lib and then use this code:
import wnck import gtk while True: if __name__ == '__main__': screen = wnck.screen_get_default() screen.force_update() while True: while gtk.events_pending(): gtk.main_iteration() #time.sleep(0.5) print screen.get_active_window().get_name()
Well if you can ping something back to the shell:
xdpyinfo | grep focus
Edit: For slightly cleaner output, try this:
xdpyinfo | grep -Eo 'window 0x[^,]+' | cut -d" " -f2
From info xtool:
getactivewindow Output the current active window. This command is often more reliable than getwindowfocus. The result is saved to the window stack. See "WINDOW STACK" for more details.
This is what I use for getting the title. (I an on 10.04)
xwininfo -id "$(xdotool getactivewindow)" |sed -n \ "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p"