XGetInputFocus not working

VARADHARAJAN RAVINDRANATH Ravindranath.Varadharajan at alcatel-lucent.com
Tue Apr 21 03:15:25 PDT 2009

Hi Peter,
   Tones of thanks !!!! it is only because, the sample application
did'nt have the focus, I was not able to get the window ID of it
properly. I have done a small workaround in my windows manager to set
the sample application in-focus for one-time and after that, I am able
to get the window ID of the sample application correctly in the windows
manager. This work around is only for checking... In real time, the
process that manages the windows will bring that to focus

Thanks again!!!!


-----Original Message-----
From: Peter Hutterer [mailto:peter.hutterer at who-t.net] 
Sent: Tuesday, April 21, 2009 12:25 PM
Cc: xorg at lists.freedesktop.org
Subject: Re: XGetInputFocus not working

On Tue, Apr 21, 2009 at 08:10:16AM +0200, VARADHARAJAN RAVINDRANATH
> 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
> 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
focus to the window when you click into it. The server does not change
focus by itself.

The code should be something like:
if (ev == key press)


More information about the xorg mailing list