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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
NawaMan
  • 901
  • 5
  • 12

3 Answers3

2

Modern window managers set a _NET_ACTIVE_WINDOW property on the root window. See question How to know which window has focus and how to change it?

Community
  • 1
  • 1
Marten
  • 1,136
  • 1
  • 8
  • 15
0

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
  • 143,651
  • 25
  • 248
  • 329
0

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

Michiel Buddingh
  • 5,783
  • 1
  • 21
  • 32
  • That link currently goes to a "modern web site layout spectacular parade" site, not a nice example program? – Dronz Oct 24 '20 at 02:34