View Issue Details

IDProjectCategoryView StatusLast Update
0035720LazarusLCLpublic2021-06-25 09:26
Reporterchronos Assigned To 
Status newResolutionopen 
Product Version2.0.2 
Fixed in Version2.0.10 
Summary0035720: First mouse event is lost in new modal form shown from MouseDown event
DescriptionThere is MouseDown handler in Form1 from which new Form2 is shown using ShowModal method. After Form2 is shown then its first MouseDown event is not captured. Second and consecutive events works ok. From user usability perspective it leads to unresponsive form for first mouse click. So user needs to click again after first click has no effect.

Under Windows it works correctly but under Linux/Gtk2 first event is not fired up. It may be limitation of Gtk2 framework but it may be problem in Gtk2 widgetset.

Usually response to click is handled by OnClick or OnMouseUp events. But in this case same functionality is required in OnMouseDown event. So workaround would be to execute ShowModal method from OnMouseUp or OnClick events. But as the behavior between Windows and Gtk2 is different then it should be better fixed. I tried to investigate this little bit but I didn't found cause of this problem.
Steps To ReproduceExtract and open attached demo. Left click on all three panels OnMouseDown, OnMouseUp and OnClick to show new modal form. In modal form click inside form area and observe captured events in text memo. Execute demo under Windows where everything works ok and under Gtk2 where first mouse click is lost in modal form if it is executed from MouseDown event handler.
TagsNo tags attached.
Fixed in Revision63203
WidgetsetGTK 2
Attached Files


related to 0035094 resolvedMichl Lazarus TSpeedButton, TStringGrid and TDBGrid do not react to left mouse click with first time 
related to 0032199 closedMichl Packages Sparta form designer component event and delete problems on gtk2 



2019-06-15 09:19

reporter (3,109 bytes)


2019-06-15 09:54

reporter   ~0116733

I tested that under Lazarus 1.6 and it works ok. So it was working previously. Under Lazarus 2.1.0 trunk it is also not working. So perhaps I would be able to identify which commit broke that.


2019-06-15 10:35

reporter   ~0116734

So faulty commit is rev 56053.


2019-06-15 11:30

reporter   ~0116735

Last edited: 2019-06-15 11:31

View 2 revisions

Similar problem:

Juha Manninen

2019-06-15 16:57

developer   ~0116737

r56053 was committed 2017-10-14.
 "Sparta_DockedFormEditor: GTK2: Fixed mouse default event handler creation."


2020-05-21 21:27

developer   ~0122997

Fixed in revision 63203. Please test and close if ok.


2020-05-22 09:11

reporter   ~0123004

Working ok. Thanks.


2021-03-15 17:52

reporter   ~0129696

In fact this issue is still not fixed. I tested that incorrectly. It still loses one MouseDown event if ShowModal is executed from another MouseDown event. Tested in both Lazarus 2.0.12 and trunk version.

Problematic code is in file lcl/interfaces/gtk2/ on line 1972 in function CheckMouseButtonDown:
        // After a LastMouse.Down has to follow a LastMouse.Up. Issue 0032199
        if LastMouse.WinControl <> AWinControl then

It is nicely visible and simply testable if you click on OnMouseDown button in attached MouseDown demo. It needs to be fixed somehow to not drop MouseDown event.


2021-03-17 08:19

reporter   ~0129729

Here is another test app where we can see that first click is handled correctly but subsequent clicks on modal forms works only as second click. (2,067 bytes)


2021-06-15 11:06

reporter   ~0131316

Unfortunately after two years this bug is still not resolved. So I am forced to use some workaround.
I can't comment out that bad code in LCL. So I need to set LastMouse.WinControl directly. This needs to be done for all affected TForm descendants or a new class can be created to avoid duplicate code.
So I added {$IFDEF LCLGTK2}, Gtk2Globals{$ENDIF} to uses section.
And added following to TForm OnShow event FormShow method:
  // GTK2 bug workaround
  if Visible then LastMouse.WinControl := Self;

Or this can be added to VisibleChangedHandler method registered with AddHandlerOnVisibleChanged method in OnCreate/FormCreate method or Create constructor.

I hope this won't take many more years to fix.


2021-06-25 09:08

developer   ~0131486

Detaching myself. I've currently no time to investigate here.

Issue History

Date Modified Username Field Change
2019-06-15 09:19 chronos New Issue
2019-06-15 09:19 chronos File Added:
2019-06-15 09:54 chronos Note Added: 0116733
2019-06-15 10:35 chronos Note Added: 0116734
2019-06-15 11:30 sembit Note Added: 0116735
2019-06-15 11:31 sembit Note Edited: 0116735 View Revisions
2019-06-15 16:50 Juha Manninen Relationship added related to 0035094
2019-06-15 16:53 Juha Manninen Relationship added related to 0032199
2019-06-15 16:55 Juha Manninen Assigned To => Michl
2019-06-15 16:55 Juha Manninen Status new => assigned
2019-06-15 16:57 Juha Manninen Note Added: 0116737
2020-05-21 21:27 Michl Status assigned => resolved
2020-05-21 21:27 Michl Resolution open => fixed
2020-05-21 21:27 Michl Fixed in Version => 2.0.10
2020-05-21 21:27 Michl Fixed in Revision => 63203
2020-05-21 21:27 Michl LazTarget => -
2020-05-21 21:27 Michl Widgetset GTK 2 => GTK 2
2020-05-21 21:27 Michl Note Added: 0122997
2020-05-22 09:11 chronos Status resolved => closed
2020-05-22 09:11 chronos Note Added: 0123004
2021-03-15 17:52 chronos Status closed => assigned
2021-03-15 17:52 chronos Resolution fixed => open
2021-03-15 17:52 chronos Note Added: 0129696
2021-03-17 08:19 chronos Note Added: 0129729
2021-03-17 08:19 chronos File Added:
2021-06-15 11:06 chronos Note Added: 0131316
2021-06-25 09:08 Michl Assigned To Michl =>
2021-06-25 09:08 Michl Assigned To => Michl
2021-06-25 09:08 Michl Status assigned => new
2021-06-25 09:08 Michl Note Added: 0131486
2021-06-25 09:26 Michl Assigned To Michl =>
2021-06-25 09:26 Michl Widgetset GTK 2 => GTK 2