XGrabKey questions

Wang Baisheng baisheng.wang.cn at gmail.com
Thu Feb 28 14:50:09 PST 2008


On Thursday 28 February 2008 04:48:48 am Peter Hutterer wrote:
> Wang Baisheng wrote:
> >>> 	First, for params keyboard_mode, the man page says "If the
> >>> keyboard_mode argument is GrabModeAsync, keyboard event processing
> >>> continues as usual", but when I write some code like, "  
> >>> XGrabKey(display,
> >>> XKeysymToKeycode(display, XK_d), 0, rootWindow, True, GrabModeAsync,
> >>> GrabModeAsync);", the focus application can not receive any key d press
> >>> event.
> >>
> >> this is correct. you told the x server to deliver any d press that
> >> happens on the root window (== every press) to you. No matter who has
> >> the focus.
> >>
> >> grabs work top down (checking the root window first for grabs). event
> >> delivery works bottom up (checking focus window first for delivery).
> >> This is an important distinction.
> >
> > You mean that if I use the parameter GrabModeAsync, the x server only
> > deliver the d press to the root window and then do not deliver it to the
> > focus window.
> > And if I want to let the focus window receive the d press event I have to
> > send the d press event manually when the root window receive the d press
> > event.
>
> yep. if you use GrabModeSync, the server stores the event in the device,
>   and replays it on the next window down when you call
> XAllowEvent(ReplayKeyboard).
>
> >>>  And the man page says "Actual keyboard changes are not lost while the
> >>> keyboard is frozen; they are simply queued in the server for later
> >>> processing", but after I receive the key press event, I call
> >>> XAllowEvents, but I can not receive any KeyRelease event, why ?
> >>
> >> you can't XAllowEvents if you don't freeze the device. so it's either
> >> GrabModeAsync or XAllowEvents.
> >
> > Yes. I passed GrabModeSync to the XGrabKey. After I receive the key press
> > event, I call XAllowEvents but I can not receive any KeyRelease event.
>
> Well, here's the problem. When you call XAllowEvent(ReplayKeyboard), you
> also release the grab. So the release event is sent to the focus window,
> not to your grabbing client.

Great!  I got it!  Thank you very much.

>
> Cheers,
>    Peter





More information about the xorg mailing list