title: How to know which window has focus and how to change it?
body: <p>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.</p>
  
  <p>For instance, my application is running with many others (e.g. firefox, gvim, nautilus,...)</p>
  
  <p>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.</p>
  
  <p>Does anyone knows how to achieve this? Books recommendations would be very nice.</p>
  
  <p>Thanks a lot.</p>