Raising window and setting keyboard focus

Glynn Clements glynn at gclements.plus.com
Thu Dec 2 01:50:03 PST 2004


Chris Kurecka wrote:

> I'm trying to write a program using Xlib that will move another window
> to the foreground and give it keyboard focus.  I tried using the
> following calls:
> 
> Window raise;
> /* assign raise to appropriate window */
> XRaiseWindow(dpy, raise);
> XSetInputFocus(dpy, raise, RevertToNone, CurrentTime);
> 
> This raises the window to the foreground but does not give it input
> focus, which still goes to the terminal that launched my program.
> 
> I also tried:
> int did_it_work = XGrabKeyboard(dpy, raise, false, GrabModeAsync,
> GrabModeAsync, CurrentTime);
> 
> No errors are returned.  Is this not working because I didn't create
> the window I'm trying to change the focus to, or is it something else?
>  I've tried it in both KDE and GNOME, so I don't think it's window
> manager dependent.  Is there any way to do what I'm seeking, without
> using Qt/GTK calls?

I suspect that the problem is essentially that the WM is getting in
your way. It isn't WM *dependent* as almost all WMs perform keyboard
focus management, so you'll observe the same behaviour regardless of
which WM you use. Try it with no WM running.

See §4.1.7 of the ICCCM for information on the WM-related aspects of
keyboard focus management.

Also, I doubt that using Gtk/Qt calls will help you at all. More
likely, you'll need to either communicate directly with the WM via
some WM-specific interface, or simply give up on the idea.

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list