Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which window has focus and how to change it?

Tags:

x11

I would like to know how can I ask X11 which windows has focus. And if for any reason my own application (that may be visible or not) got the focus I want be able to let the former windows to get focus again.

For instance, my application is running with many others (e.g. firefox, gvim, nautilus,...)

Suppose that at first firefox has focus and that the user clicked on my app which now has the focus. I want that my application put focus on firefox again.

Does anyone knows how to achieve this? Books recommendations would be very nice.

Thanks a lot.

like image 960
Plicatibu Avatar asked Jun 18 '09 19:06

Plicatibu


1 Answers

Take a look at the _NET_ACTIVE_WINDOW value of the root window which is set by most modern window managers:

xprop -root _NET_ACTIVE_WINDOW

This value can, of course, be obtained using Xlib library calls.

like image 163
Marten Avatar answered Sep 21 '22 15:09

Marten