Re: Missing events sometimes

2011-10-28 Thread Olivier Fourdan
Hi Peter,

On Fri, Oct 28, 2011 at 12:44 AM, Peter Hutterer
peter.hutte...@who-t.net wrote:
[...]

 I'm not sure on the actual code but there's a race condition for both - if
 the release event happens before the server receives/processes the
 GrabKey/Pointer request you may drop the event on the floor. This shouldn't
 happen since you should get it delivered based on the passive grab either
 way but there's a chance the client drops it.
 Try swapping the passive grab to sync and see if that avoids it.

Yeap it works, this plus an XAllowEvents(dpy, SyncKeyboard, ev-time)
that nails it!

[...]

 put a delay in before XGrabPointer in the client and click fast (so that the
 release happens before the request). this way you can easily verify if it is
 that race condition or something else.

Many thanks!

Cheers,
Olivier
___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com


Re: Missing events sometimes

2011-10-27 Thread Peter Hutterer
On Tue, Oct 25, 2011 at 10:16:17AM +0200, Olivier Fourdan wrote:
 I have been facing a bug in the xfce [1] window manager xfwm4 [2], for
 a very long time, no doubt the fault is with my code yet I fail to
 find the fix.
 
 Sometimes, when the system is heavily loaded and/or swapping
 intensively, the event loop does not get the ButtonReleasse or
 KeyRelease events it's waiting to exit the event loop.
 
 The logic used in the code is the following:
 
 1. For keyboard, it installs a passive grab in sync mode on keyboard, ie:
 
 XGrabKey (dpy, keycode, modifier, w, TRUE, GrabModeAsync, GrabModeSync);
 
 2. For buttons, same with Sync mode on pointer
 
 XGrabButton (dpy, button, modifier, w, FALSE,
 ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, None,
 None);
 
 3. Then when the user activates a keyboard shortcut or moves a window
 usign the mouse, the window manager installs an active grab on the
 keyboard / pointer using the timestamp of the event:
 
 XGrabKeyboard (dpy, root, TRUE, GrabModeAsync, GrabModeAsync, timestamp)
 
 or
 
 XGrabPointer (dpy, root, FALSE, PointerMotionMask |
 ButtonMotionMask |  ButtonReleaseMask | LeaveWindowMask,
 GrabModeAsync, GrabModeAsync, root, cursor, timestamp);
 
 4. Then enters an event loop processing events, until a KeyRelease
 event (in the case of a keyboard shortcut) or a ButtonRelease is
 received (in the case of a mouse op).
 
 Using this logic, the code sometimes (when the system is loaded or
 swapping) remains in the event loop because the ButtonRelease or
 KeyRelease event is not received in the event loop, so I guess it's
 consumed somehow before the code enters the event loop, but how?

I'm not sure on the actual code but there's a race condition for both - if
the release event happens before the server receives/processes the
GrabKey/Pointer request you may drop the event on the floor. This shouldn't
happen since you should get it delivered based on the passive grab either
way but there's a chance the client drops it. 
Try swapping the passive grab to sync and see if that avoids it. 

 As I said, there's probably a flaw somewhere in the logic, but I fail
 to find it (also because of the nature of the probl;em it's quite hard
 to reproduce and therefore investigate and test), so I am open to any
 suggestion...

put a delay in before XGrabPointer in the client and click fast (so that the
release happens before the request). this way you can easily verify if it is
that race condition or something else.

Cheers,
  Peter
___
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com