Difference between revisions of "Tutorials/C Programming Tutorial/How to find out which window has the focus"

From ThorstensHome
Jump to: navigation, search
m (1 revision(s))
(brettcrumbs now work!)
Line 1: Line 1:
You are here: [[Main Page]] -> [[My Tutorials]] -> [[Programming Tutorials]] -> [[C Programming Tutorial]] -> [[How to find out which window has the focus]]
 
 
 
You can use the following source code to find out which window has the focus on your Linux desktop:
 
You can use the following source code to find out which window has the focus on your Linux desktop:
  

Revision as of 03:08, 11 May 2009

You can use the following source code to find out which window has the focus on your Linux desktop:

main.cpp

#include <stdio.h>
#include <X11/Xlib.h>

/* Compile this using
g++ -lXtst main.cpp
*/

int main()
{
  Display* display= XOpenDisplay(NULL);
  char* name="blahblah";
  Window window=0;
  int i=0;
  XGetInputFocus(display, &window, &i);
  int  status = XFetchName (display, window , &name);

  XCloseDisplay( display );
  printf("%i",i);
  printf("%i",window);
  printf(name);
}

Compile, link and run it

g++ -lXtst main.cpp
./a.out

See also