tags:

views:

79

answers:

3

Is it possible to find out what application/window/frame is currently hold a focus? It may be a shell command or a library that I can program with.

A: 

Yes

At the low level this information can be extracted from the X server via xlib calls. At a higher level the window managers sometimes implement accessibility protocols which must communicate focus, and in any case their corresponding toolkits will have higher level abstractions.

An example of accessibility features are atk and at-spi. Libraries that provide window management functions will be good examples, see: XEmbed. Check Qt and Gnome documentation for C++ API elements dealing with focus.

DigitalRoss
+1  A: 

Modern window managers set a _NET_ACTIVE_WINDOW property on the root window. See question http://stackoverflow.com/questions/1014822/

Marten
Seems a lot more plausible than my answer.
Michiel Buddingh'
What a shame ... I should have found that question in a search. Thanks anyway.
NawaMan
A: 

A quick excursion to Google suggests XGetInputFocus. There's a nice example program linked here

Michiel Buddingh'