After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 609956 - Missing global mouse capture when a mouse button is held down
Missing global mouse capture when a mouse button is held down
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Backend: Win32
2.16.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2010-02-15 01:24 UTC by Tim Evans
Modified: 2018-02-10 03:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against gtk+-2.18.7 that hacks around this bug (3.22 KB, patch)
2010-02-15 04:16 UTC, Tim Evans
none Details | Review
Improved version of the previous patch (4.54 KB, patch)
2010-02-17 01:17 UTC, Tim Evans
none Details | Review
win32: Restore button event propagation (2.63 KB, patch)
2010-10-24 02:07 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Generate pointer grab broken event when focus is lost (2.04 KB, patch)
2010-10-24 16:06 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Restore pointer event propagation (3.70 KB, patch)
2010-10-24 16:06 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Restore pointer event propagation (3.70 KB, patch)
2010-10-24 16:19 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Pointer grab broken event on focus loss (1.98 KB, patch)
2010-10-24 16:27 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Pointer grab broken event on focus loss (1.81 KB, patch)
2010-10-24 18:29 UTC, Ole André Vadla Ravnås
none Details | Review
win32: Restore emulation of X11's automatic active grab (2.64 KB, patch)
2010-10-24 18:29 UTC, Ole André Vadla Ravnås
none Details | Review

Description Tim Evans 2010-02-15 01:24:56 UTC
I'm running this test under Windows Vista, in case that matters.

Steps to reproduce:
1. Run gtk-demo.
2. Run the "Text Widget / Multiple Views" demo.
3. Move the "TextView" so that the right hand side of the window is clear of the "GTK+ Code Demos" window.
4. Press and hold the mouse button on the larger of the two scrollbars.
5. Move the mouse up and down on top of the "TextView" window and observe that scrolling works fine here.
6. Move the mouse to just off the right of the "TextView" window and observe that moving the mouse up and down does not scroll at all here.
7. While the mouse is outside the window, release the button.  Move the mouse back into the window and observe that the button-release message was missed and GTK thinks the button is still down.

There needs to be some sort of global mouse capture when a button is pressed.  Currently it seems that the mouse is captured only for windows in the same application.
Comment 1 Tim Evans 2010-02-15 04:16:08 UTC
Created attachment 153812 [details] [review]
Patch against gtk+-2.18.7 that hacks around this bug

Attaching a patch that fixes the problem.  I call SetCapture and ReleaseCapture when mouse buttons are pressed and released, and pass messages to the captured window while one is active.

It's a complete hack, almost certainly the wrong way to do it, but it works.  Might be a good starting point for someone that knows how that code should be modified.
Comment 2 Tor Lillqvist 2010-02-16 09:42:32 UTC
Thanks. Please add a comment here if you notice any bad side-effect of this. If not, I guess it should be committed.
Comment 3 Tim Evans 2010-02-16 22:05:18 UTC
I already know it'll break any gdk_pointer_grab() currently in effect.  So far I've found that this breaks submenus, and it probably breaks other things too.  Currently I'm playing around with having button_down_grab_start() do nothing if GetCapture() returns non-NULL.

I tried using gdk_pointer_grab() instead of going straight to win32 SetCapture() but then events didn't arrive at all.  At a guess it was capturing on the wrong HWND.
Comment 4 Tim Evans 2010-02-17 01:17:50 UTC
Created attachment 153989 [details] [review]
Improved version of the previous patch

This is an improved version of the patch that tries to avoid stomping on grabs created by gdk_pointer_grab() and friends.  It really needs to be properly integrated with the exist grab system, but I don't understand that code well enough to do it properly.
Comment 5 Ole André Vadla Ravnås 2010-10-24 02:07:20 UTC
Created attachment 173100 [details] [review]
win32: Restore button event propagation

Here's a simple patch that restores mouse button event propagation (like in 2.16.x and before), but ported to the new API. It will ensure that for example mouse up event outside the window will reach the GdkWindow which is currently grabbing the pointer.

It does not solve the case where another window gets focused (like pressing Alt+Tab while still holding down the mouse button), but I'm working on another patch which will solve that issue (it is a separate issue).
Comment 6 Ole André Vadla Ravnås 2010-10-24 02:16:11 UTC
Comment on attachment 153989 [details] [review]
Improved version of the previous patch

Sorry, I didn't mean to obsolete your patch. :)
Comment 7 Ole André Vadla Ravnås 2010-10-24 02:21:50 UTC
This bug seems to be related to bug #605569.
Comment 8 Ole André Vadla Ravnås 2010-10-24 16:06:05 UTC
Created attachment 173123 [details] [review]
win32: Generate pointer grab broken event when focus is lost
Comment 9 Ole André Vadla Ravnås 2010-10-24 16:06:32 UTC
Created attachment 173124 [details] [review]
win32: Restore pointer event propagation

Fixes delivery of button and motion events when pointer is grabbed.

These events are quite essential for widgets like GtkScrollbar
and GtkPaned.
Comment 10 Ole André Vadla Ravnås 2010-10-24 16:07:36 UTC
Comment on attachment 173100 [details] [review]
win32: Restore button event propagation

Replaced by new patch which also propagates pointer motion events.
Comment 11 Ole André Vadla Ravnås 2010-10-24 16:19:14 UTC
Created attachment 173125 [details] [review]
win32: Restore pointer event propagation

Fixes delivery of button and motion events when pointer is grabbed.

These events are quite essential for widgets like GtkScrollbar
and GtkPaned.
Comment 12 Ole André Vadla Ravnås 2010-10-24 16:27:18 UTC
Created attachment 173126 [details] [review]
win32: Pointer grab broken event on focus loss

Tweak variable naming and remove a redundant check.
Comment 13 Ole André Vadla Ravnås 2010-10-24 16:28:07 UTC
Comment on attachment 173123 [details] [review]
win32: Generate pointer grab broken event when focus is lost

Forgot to obsolete the previous version of this patch.
Comment 14 Ole André Vadla Ravnås 2010-10-24 18:29:13 UTC
Created attachment 173130 [details] [review]
win32: Pointer grab broken event on focus loss

Simplify a bit.
Comment 15 Ole André Vadla Ravnås 2010-10-24 18:29:47 UTC
Created attachment 173131 [details] [review]
win32: Restore emulation of X11's automatic active grab
Comment 16 Ole André Vadla Ravnås 2010-10-24 18:45:19 UTC
Alright, I think I'm a happy, been testing my GTK+-based application with these changes and everything seems to be in order. Wonderful to be able to use scroll-bars like before, buttons behaving like they used to, and GtkPaned not ending up in a bad state when the mouse leaves the window. :)
Comment 17 Matthias Clasen 2018-02-10 03:29:21 UTC
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and
still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue
for it.