XGetInputFocus not working

Peter Hutterer peter.hutterer at who-t.net
Mon Apr 20 23:54:56 PDT 2009


On Tue, Apr 21, 2009 at 08:10:16AM +0200, VARADHARAJAN RAVINDRANATH wrote:
> Hi,
> 
>    Following is the code in the windows manager to get the focused
> window details:
> 
> Some_fn()
> {
> 	Window focusWindow;
> 	Display *focusDisplay;
> 	focusDisplay = XOpenDisplay(NULL);
> 	int retcode = 0;
> 	int param = 0;
> 	retcode = XGetInputFocus(focusDisplay,&focusWindow,&param);
> 	fprintf(stderr,"Retcode = %d\n Focus Window = %u\nparam = %d
> \n",retcode,focusWindow,param);
> }
> 
> 
> A sample X11 application is written to check if the focus is obtained
> correctly. This x11 aplication creates a simple window and starts
> listening to KeyPress Events. During the startup of this x11
> application, I printed the Window ID [6291457]. Now when I click the
> mouse in the window which the x11 application has created [to bring the
> x11 application to focus], I find that the windows manager prints the
> following line 
> 
> Retcode = 1
>  Focus Window = 64
>  Param = 
> 
> Can you pls point where am I getting wrong ??

As I said, have you set the focus?
If you're writing a window manager, you're responsible for setting the input
focus to the window when you click into it. The server does not change the
focus by itself.

The code should be something like:
XNextEvent(ev)
if (ev == key press)
    XSetInputFocus(ev.window);

Cheers,
  Peter



More information about the xorg mailing list