View Issue Details

IDProjectCategoryView StatusLast Update
0013878LazarusLCLpublic2010-10-10 22:50
ReporterMartin Friebe Assigned ToZeljan Rikalo  
Status closedResolutionfixed 
Product Version0.9.27 (SVN) 
Target Version1.0.0 
Summary0013878: GTK2 MouseCapture shows strange behaviour
DescriptionUnder GTK2 MouseCapture is set in a different manner than under other WidgetSets (tested Windows).

SynEdit receives the following events (for a doublecklick, and some mouse-move):
- Mouse down
- mouse up
- Mouse down
 - DblClick => sets MouseCapture := False
 - MouseMove => unter GTK2 (lately) Mousecapture is true at this time
- mouse up

Since Synedit has not touched Mousecapture between the 2 steps, and since under Windows it does keep it's Value, I assume the GTK2 widgetset must do something do it.
TagsNo tags attached.
Fixed in Revision27638
WidgetsetGTK 2
Attached Files


related to 0008888 closedZeljan Rikalo Mouse capture is not working for form and controls (both gtk1 and gtk2) 
related to 0008178 closedZeljan Rikalo Cant turn off mouse capturing in TWinControl 
related to 0012460 closedMartin Friebe Editor stop selecting text [Caused by hint window / temp work around applied] 
related to 0015955 closedZeljan Rikalo GTK2: SetCaptureControl() doesn't work 
related to 0015895 closedZeljan Rikalo TListBox/TTreeView etc. scrollbar locks mouse input when used with TSplitter 
related to 0015271 closedZeljan Rikalo TPageControl freeze after TMemo events 


Martin Friebe

2009-07-24 17:23

manager   ~0029235

If this gets fixed, please see notes on issue 0012460 and undo the workaround from revision 20935.

Mattias Gaertner

2009-08-19 23:58

manager   ~0030003

Last edited: 2009-08-19 23:59

Can you give some more details:

I should double click and while double clicking move the mouse, right?
And MouseCapture should be false all the time, right?

With what flag should I compile synedit to see the bug?

2009-08-20 14:05


mouse_capture.rar (3,159 bytes)

Martin Friebe

2009-08-20 14:10

manager   ~0030023

Sorry this is a fine example for a badly reported bug.
See attached project.

IT works the same on win, gtk1, gtk2.

but if you uncomment the line "MouseCapture := false;" in the MouseDown handling then:
- windows will remember this, that is all further debugln show MouseCapture = false

- under both gtk nothing happens. MouseCapture is still true (even within the MouseDown handler)

Another thing (which may have the same cause, if not I will report separately):
Under GTK any hint window steals MouseCapture.
Under windows the mouse capture remains where it is, even while the hint is showing.


2010-02-02 02:40

reporter   ~0034148

Using MouseCapture := false and SetCaptureControl(nil) does nothing. But if you use GtkProc.ReleaseMouseCapture it will release mouse capture.

Zeljan Rikalo

2010-03-12 22:48

developer   ~0035408

I'm still wondering why setCapture() is so complicated for gtk2 and what's the point with it. Just created small patch which implements more simple setCapture() - which compiles and IDE is useable :), don't see any bad spots, but need some good test example to see if this implementation of setCapture() works ok.
Patch is attached (svn diff against 23969)

2010-03-12 22:48


gtk2setcapturepatch.diff (2,312 bytes)   
Index: lcl/interfaces/gtk/
--- lcl/interfaces/gtk/	(revision 23969)
+++ lcl/interfaces/gtk/	(working copy)
@@ -4864,6 +4864,9 @@
   OldMouseCaptureWidget: PGtkWidget;
   Info: PWidgetInfo;
+  {$ifndef gtk1}
+  exit;
+  {$endif}
   {$IFDEF VerboseMouseCapture}
   DebugLn('ReleaseMouseCapture ',dbgs(ord(MouseCaptureType)),' MouseCaptureWidget=[',GetWidgetDebugReport(MouseCaptureWidget),']');
Index: lcl/interfaces/gtk2/
--- lcl/interfaces/gtk2/	(revision 23969)
+++ lcl/interfaces/gtk2/	(working copy)
@@ -669,6 +669,34 @@
   Result := true;
+function TGtk2WidgetSet.SetCapture(AHandle: HWND): HWND;
+  Widget: PGtkWidget;
+  CaptureWidget: PGtkWidget;
+  // Assert(False, Format('Trace:> [TGtkWidgetSet.SetCapture] 0x%x', [AHandle]));
+  Widget := PGtkWidget(AHandle);
+  {$IfDef VerboseMouseCapture}
+  DebugLn('TGtkWidgetSet.SetCapture NewValue=[',GetWidgetDebugReport(Widget),']');
+  {$EndIf}
+  // return old capture handle
+  Result := GetCapture;
+  if Result <> 0 then
+    gtk_grab_remove(gtk_grab_get_current);
+  if Widget = nil then
+    exit;
+  CaptureWidget:=GetDefaultMouseCaptureWidget(Widget);
+  if CaptureWidget=nil then exit;
+  if not gtk_widget_has_focus(CaptureWidget) then
+    gtk_widget_grab_focus(CaptureWidget);
+  gtk_grab_add(CaptureWidget);
 function TGtk2WidgetSet.SetCursorPos(X, Y: Integer): Boolean;
 {$ifdef GTK_2_8}
Index: lcl/interfaces/gtk2/
--- lcl/interfaces/gtk2/	(revision 23969)
+++ lcl/interfaces/gtk2/	(working copy)
@@ -48,6 +48,7 @@
 function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;
 function ScrollWindowEx(hWnd: HWND; dx, dy: Integer; prcScroll, prcClip: PRect; hrgnUpdate: HRGN; prcUpdate: PRect; flags: UINT): Boolean; override;
+function SetCapture(AHandle: HWND): HWND; override;
 function SetCursorPos(X, Y: Integer): Boolean; override;
 function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;
gtk2setcapturepatch.diff (2,312 bytes)   


2010-03-14 08:19

reporter   ~0035474

With your patch an explicit call to ReleaseMouseCapture is not needed. Capture is released by setting MouseCapture := False or SetCaptureControl(nil). So I guess it would solve this issue?

Zeljan Rikalo

2010-03-14 08:36

developer   ~0035476

@cobines thanks for testing, is the event order in synedit correct now ?

Zeljan Rikalo

2010-07-02 23:29

developer   ~0038956

@Martin can you retest this issue please ?

Martin Friebe

2010-07-10 02:49

manager   ~0039215

The part of the bug described in this issue is fixed.

But the fix is not complete, it does not include the issue 0012460 (which was incorrectly closed)

Basically under GTK2 when a hint window pops up, mouse capture is unset. Under Windows it is kept. as far as I know it is meant to be kept.

In order to test this, search SynEdit for the 2 references to bug 12460 (search for the number). Comment the 2 code blocks, and start selecting some text, using the mouse.
While keeping the left mouse down (in order to later continue selection) wait for a hint to be displayed. Try to continue the selection => it does not work, because mouse capture was released.

Zeljan Rikalo

2010-07-10 20:49

developer   ~0039251

@Martin, so exactly this issue (13878) is fixed or not ? 12460 is resolved because reporter said that's ok now.

Martin Friebe

2010-07-10 21:03

manager   ~0039252

12460 is hidden because synedit contains are rather crude workaround (search for the bug number in the source). But the underlying bug is not solved.

Zeljan Rikalo

2010-10-09 15:34

developer   ~0041650

@Martin, just tested Lazarus 0.9.29 r27629M FPC 2.4.1 i386-linux-gtk 2 (beta) and I cannot reproduce anything wrong (qt have same behaviour as gtk2 using your example project here).

Martin Friebe

2010-10-10 03:19

manager   ~0041671

I have just tested again, with 27637

The attached app still(again?) fails. Uncomment the
  //MouseCapture := False;

run the app.
press the mouse.
expected output: mc=false
output I et: mc=true

ubuntu9 gnome

Also it seems a hint window still steals the focus, if anther control has already captured it.

Add the end of MouseDown (while the MouseCapture:=False line is commented out):
 xx:= THintWindow.Create(form1);
  xx.Hint:='xxxx';; xx.Left:=form1.left;

Zeljan Rikalo

2010-10-10 10:59

developer   ~0041676

1.Yes, gtk2 doesn't want to release MouseCapture, qt does it.
2.Hint window deactivates form (in case of qt), but nothing happens in gtk2 since mousecapture is still ownership of form.
Now, I'm wondering what could be wrong - maybe it's connected to issue (but second part of issue where reporter provided code to call modal from from OnDropDown()). Look like some messages doesn't reach gtk2.

Zeljan Rikalo

2010-10-10 17:27

developer   ~0041692

Please test and close if ok.
Martin's observations are fixed also (including THintWindow).

Martin Friebe

2010-10-10 22:50

manager   ~0041710

Thanksa lot.

yes works fine on all my test systems

Issue History

Date Modified Username Field Change
2009-05-31 21:19 Martin Friebe New Issue
2009-05-31 21:19 Martin Friebe LazTarget => -
2009-05-31 21:19 Martin Friebe Widgetset => GTK 2
2009-06-01 22:47 Vincent Snijders LazTarget - => 1.0
2009-06-01 22:47 Vincent Snijders Status new => acknowledged
2009-06-01 22:47 Vincent Snijders Target Version => 1.0.0
2009-06-04 15:16 Martin Friebe Relationship added related to 0008888
2009-06-04 15:17 Martin Friebe Relationship added related to 0008178
2009-07-19 16:06 Martin Friebe Relationship added related to 0012460
2009-07-24 17:23 Martin Friebe Note Added: 0029235
2009-08-19 23:58 Mattias Gaertner Note Added: 0030003
2009-08-19 23:58 Mattias Gaertner Status acknowledged => feedback
2009-08-19 23:58 Mattias Gaertner Note Edited: 0030003
2009-08-19 23:59 Mattias Gaertner Note Edited: 0030003
2009-08-20 14:05 Martin Friebe File Added: mouse_capture.rar
2009-08-20 14:10 Martin Friebe Note Added: 0030023
2009-09-18 16:00 Vincent Snijders Status feedback => acknowledged
2010-02-02 02:40 cobines Note Added: 0034148
2010-03-11 14:24 Zeljan Rikalo Relationship added related to 0015955
2010-03-12 22:48 Zeljan Rikalo Note Added: 0035408
2010-03-12 22:48 Zeljan Rikalo Status acknowledged => feedback
2010-03-12 22:48 Zeljan Rikalo File Added: gtk2setcapturepatch.diff
2010-03-14 08:19 cobines Note Added: 0035474
2010-03-14 08:36 Zeljan Rikalo Note Added: 0035476
2010-03-16 21:18 Zeljan Rikalo Relationship added related to 0015895
2010-06-20 12:54 Zeljan Rikalo Relationship added related to 0015271
2010-07-02 23:29 Zeljan Rikalo Note Added: 0038956
2010-07-10 02:49 Martin Friebe Note Added: 0039215
2010-07-10 20:49 Zeljan Rikalo Note Added: 0039251
2010-07-10 21:03 Martin Friebe Note Added: 0039252
2010-10-09 15:34 Zeljan Rikalo Note Added: 0041650
2010-10-09 15:34 Zeljan Rikalo Status feedback => acknowledged
2010-10-10 03:19 Martin Friebe Note Added: 0041671
2010-10-10 10:59 Zeljan Rikalo Note Added: 0041676
2010-10-10 17:27 Zeljan Rikalo Fixed in Revision => 27638
2010-10-10 17:27 Zeljan Rikalo Status acknowledged => resolved
2010-10-10 17:27 Zeljan Rikalo Resolution open => fixed
2010-10-10 17:27 Zeljan Rikalo Assigned To => Zeljan Rikalo
2010-10-10 17:27 Zeljan Rikalo Note Added: 0041692
2010-10-10 22:50 Martin Friebe Status resolved => closed
2010-10-10 22:50 Martin Friebe Note Added: 0041710