Mysterious extra button_release event?



I'm having some trouble with what seems to be an extra button_release event
showing up sometimes.  The situation is as follows (based partly upon
GNOME-MDI's method of moving notebook tabs); I apologize for it being so
complicated:


I have a GtkNotebook with signal handlers connected for button_press and
button_release events.

The button_press handler connects motion_notify and leave_notify signal
handlers to the notebook.

The motion_notify and leave_notify handlers both do the same thing: after
the cursor moves outside of the notebook tab that the button_press event
occurred in, they disconnect the motion_notify and leave_notify signals and
initiate a pointer grab on behalf of the notebook.

The button_release handler can do two different things.  If the pointer is
not currently grabbed, the motion_notify and leave_notify signals are
disconnected.  If the pointer _is_ grabbed, then it is ungrabbed, and the
notebook tab is moved to wherever the user dropped it.

Most of the time, this works the way it's supposed to.  However, when I
start clicking really quickly while moving the cursor near the edge of the
tab, I sometimes see events occur in the following order:

  button_press (signals are connected)
  motion_notify (outside of tab, so grab is initiated)
  button_release (pointer is ungrabbed)

  [so far, so good]

  button_press (signals are connected)
  motion_notify (outside of tab, so grab is initiated)
  button_release (pointer is ungrabbed)
  button_release (?!)


I have no idea where that second button_release event is coming from; it
seems to me that there is no corresponding button_press event.  I imagine I
could write a hack to work around this (by ignoring consecutive
button_release events), but I'd prefer to know why it's showing up.

I'm pretty clueless when it comes to events and signals, so it's likely
that I'm just misunderstanding something here.  Could someone set me
straight? :)  Thanks,

Daniel

p.s. Looking at this psuedocode, I think I see an additional unrelated
problem.  It looks like it would be possible for the user to release the
mouse button outside of the notebook while the motion_notify or
leave_notify handler is executing, before the pointer has been grabbed.  Is
this indeed a possibility?  If so, can anyone give an advice on how I can
prevent this from happening?  Is grabbing the pointer on button_press the
only way to do this?  Thanks again!




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]