View Issue Details

IDProjectCategoryView StatusLast Update
0038402LazarusWidgetsetpublic2021-02-10 13:15
ReporterAndrzej Kilijanski Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformamd64OSLinux Mint 
Product Version2.1 (SVN) 
Summary0038402: GTK2: SpeedButton freezes (need extra click) after close popup menu without choosing any popup menu item (Fix 2).
DescriptionThis is the second part of the popup menu problem - https://bugs.freepascal.org/view.php?id=38401 (closing the menu freezes some controls (eg SpeedButton)) - this solves the problem with the system/default menus.

I divided the whole solution into two parts because, perhaps it should be fixed in a different way. This part solves the problem with the system/default popup menus by using the populate-popup signal to access the system popup menu.

This fixes:
- Edit
- Memo
- Combobox
- MAskEdit
- SpinEdit
- LabeledEdit

In the example program this part (fix 2) will fix the controls with no PopupMenu added in Lazarus.
Steps To ReproduceThe easiest way to cause the controls to freeze is:
1. Add SpeedButton to the Form
2. Add Edit
3. After run click right on Edit and then click on the form to hide the popup menu
5. At this point, the SpeedButton will be frozen (need extra click to start working)
Tagspatches
Fixed in Revisionr64431, r64473
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

has duplicate 0038461 resolvedJuha Manninen speedbutton not responding at first click after form opened from popupmenu 
related to 0038401 resolvedJuha Manninen GTK2: SpeedButton freezes (need extra click) after close popup menu without choosing any popup menu item (Fix 1). 

Activities

Andrzej Kilijanski

2021-01-26 14:50

reporter  

popupmenu_fix2.diff (2,600 bytes)   
Index: lcl/interfaces/gtk2/gtk2wscustommemo.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2wscustommemo.inc	(wersja 64422)
+++ lcl/interfaces/gtk2/gtk2wscustommemo.inc	(kopia robocza)
@@ -108,6 +108,9 @@
   SignalConnect(AWidgetInfo^.CoreWidget, 'cut-clipboard', @Gtk2WS_MemoCutToClip, AWidgetInfo);
   SignalConnect(AWidgetInfo^.CoreWidget, 'copy-clipboard', @Gtk2WS_MemoCopyToClip, AWidgetInfo);
   SignalConnect(AWidgetInfo^.CoreWidget, 'paste-clipboard', @Gtk2WS_MemoPasteFromClip, AWidgetInfo);
+
+  g_signal_connect_after(PGtkObject(AWidgetInfo^.CoreWidget), 'populate-popup',
+    gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
 end;
 
 class function TGtk2WSCustomMemo.CreateHandle(const AWinControl: TWinControl;
Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(wersja 64422)
+++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(kopia robocza)
@@ -412,6 +412,25 @@
     Result := nil;
 end;
 
+procedure gtkDefaultPopupMenuDeactivate(Widget: PGtkWidget; data: gPointer); cdecl;
+begin
+  LastMouse.Button := 0;
+  LastMouse.ClickCount := 0;
+  LastMouse.Down := False;
+  LastMouse.MousePos := Point(0, 0);
+  LastMouse.Time := 0;
+  LastMouse.WinControl := nil;
+end;
+
+function gtkDefaultPopupMenuCloseFix(Widget: PGtkWidget; Menu: PGtkMenu;
+  data: gPointer): gboolean; cdecl;
+begin
+  // needed because closing popup menu without clicking on any menu item
+  // freezes various controls, eg SpeedButton
+  g_signal_connect(PGtkObject(Menu), 'deactivate',
+    gtk_signal_func(@gtkDefaultPopupMenuDeactivate), nil);
+end;
+
 {$I gtk2memostrings.inc}
 
 { TGtk2WSCustomListBox }
@@ -1063,6 +1082,9 @@
     SetCallback(LM_COPY, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
     SetCallback(LM_PASTE, PGtkObject(AGtkWidget), AWidgetInfo^.LCLObject);
   end;
+
+  g_signal_connect_after(PGtkObject(AGtkWidget), 'populate-popup',
+    gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
 end;
 
 class procedure TGtk2WSCustomEdit.GetPreferredSize(const AWinControl: TWinControl;
@@ -1760,6 +1782,9 @@
     g_signal_connect_after(AMenu, 'selection-done', G_CALLBACK(@GtkPopupHideCB), AWidgetInfo);
   end;
 
+  g_signal_connect_after(PGtkObject(GTK_BIN(ComboWidget)^.child), 'populate-popup',
+    gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
+
   if (gtk_major_version >= 2) and (gtk_minor_version >= 10) then
     g_signal_connect(ComboWidget, 'notify', TGCallback(@GtkNotifyCB), AWidgetInfo);
 
popupmenu_fix2.diff (2,600 bytes)   

Juha Manninen

2021-01-28 09:22

developer   ~0128634

Applied, thanks.
I could reproduce the problem only sometimes but the patch fixed it anyways.

Petr-K

2021-02-02 13:37

reporter   ~0128735

This part of the patch:

Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsstdctrls.pp (wersja 64422)
+++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp (kopia robocza)
@@ -1760,6 +1782,9 @@
     g_signal_connect_after(AMenu, 'selection-done', G_CALLBACK(@GtkPopupHideCB), AWidgetInfo);
   end;
 
+ g_signal_connect_after(PGtkObject(GTK_BIN(ComboWidget)^.child), 'populate-popup',
+ gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
+
   if (gtk_major_version >= 2) and (gtk_minor_version >= 10) then
     g_signal_connect(ComboWidget, 'notify', TGCallback(@GtkNotifyCB), AWidgetInfo);
 
-------------------------------------------------------
causes warning:

GLib-GObject-WARNING **: 13:13:46.713: ../../../gobject/gsignal.c:2617: signal 'populate-popup' is invalid for instance '0x18ba850' of type 'GtkCellView'

-------------------------------------------------------
library: libgtk 2.24
environment:
G_MESSAGES_DEBUG=all
G_DEBUG=fatal_warnings

Juha Manninen

2021-02-02 15:06

developer   ~0128741

Petr-K: How to fix it?

Andrzej Kilijanski

2021-02-02 20:28

reporter   ~0128745

Petr-K: I can't reproduce that. Can you reproduce that with my example popupmenu_spedbtn_gtk2.tar.gz?

Petr-K

2021-02-03 09:27

reporter   ~0128751

Set ComboBox1.Style = csDropDownList

Petr-K

2021-02-03 09:37

reporter   ~0128752

What about this solution:
  
if TCustomComboBox(AWinControl).Style.HasEditBox then
  g_signal_connect_after(PGtkObject(GTK_BIN(ComboWidget)^.child), 'populate-popup',
    gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);

Andrzej Kilijanski

2021-02-03 13:34

reporter   ~0128755

Oh, I forgot about styles, I think Petr-K solution is OK.

Juha Manninen

2021-02-04 12:01

developer   ~0128772

I will look at this closely soon. Now I am busy with other things.
A patch would be appreciated of course.

Petr-K

2021-02-05 09:18

reporter   ~0128780

Patch
gtk2wsstdctrls.patch (873 bytes)   
Index: lcl/interfaces/gtk2/gtk2wsstdctrls.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(revision 64456)
+++ lcl/interfaces/gtk2/gtk2wsstdctrls.pp	(working copy)
@@ -1782,8 +1782,9 @@
     g_signal_connect_after(AMenu, 'selection-done', G_CALLBACK(@GtkPopupHideCB), AWidgetInfo);
   end;
 
-  g_signal_connect_after(PGtkObject(GTK_BIN(ComboWidget)^.child), 'populate-popup',
-    gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
+  if TCustomComboBox(AWinControl).Style.HasEditBox then
+    g_signal_connect_after(PGtkObject(GTK_BIN(ComboWidget)^.child), 'populate-popup',
+      gtk_signal_func(@gtkDefaultPopupMenuCloseFix), AWidgetInfo);
 
   if (gtk_major_version >= 2) and (gtk_minor_version >= 10) then
     g_signal_connect(ComboWidget, 'notify', TGCallback(@GtkNotifyCB), AWidgetInfo);
gtk2wsstdctrls.patch (873 bytes)   

Juha Manninen

2021-02-05 12:54

developer   ~0128782

Applied, thanks.

Issue History

Date Modified Username Field Change
2021-01-26 14:50 Andrzej Kilijanski New Issue
2021-01-26 14:50 Andrzej Kilijanski File Added: popupmenu_fix2.diff
2021-01-26 14:50 Andrzej Kilijanski File Added: popupmenu_spedbtn_gtk2.tar.gz
2021-01-26 15:57 Andrzej Kilijanski Tag Attached: patches
2021-01-27 10:42 Juha Manninen Relationship added related to 0038401
2021-01-27 10:45 Juha Manninen Assigned To => Juha Manninen
2021-01-27 10:45 Juha Manninen Status new => assigned
2021-01-28 09:22 Juha Manninen Status assigned => resolved
2021-01-28 09:22 Juha Manninen Resolution open => fixed
2021-01-28 09:22 Juha Manninen Fixed in Revision => r64431
2021-01-28 09:22 Juha Manninen LazTarget => -
2021-01-28 09:22 Juha Manninen Widgetset GTK 2 => GTK 2
2021-01-28 09:22 Juha Manninen Note Added: 0128634
2021-02-02 13:37 Petr-K Note Added: 0128735
2021-02-02 15:06 Juha Manninen Status resolved => assigned
2021-02-02 15:06 Juha Manninen Resolution fixed => open
2021-02-02 15:06 Juha Manninen Note Added: 0128741
2021-02-02 20:28 Andrzej Kilijanski Note Added: 0128745
2021-02-03 09:27 Petr-K Note Added: 0128751
2021-02-03 09:37 Petr-K Note Added: 0128752
2021-02-03 13:34 Andrzej Kilijanski Note Added: 0128755
2021-02-04 12:01 Juha Manninen Note Added: 0128772
2021-02-05 09:18 Petr-K Note Added: 0128780
2021-02-05 09:18 Petr-K File Added: gtk2wsstdctrls.patch
2021-02-05 12:54 Juha Manninen Status assigned => resolved
2021-02-05 12:54 Juha Manninen Resolution open => fixed
2021-02-05 12:54 Juha Manninen Fixed in Revision r64431 => r64431, r64473
2021-02-05 12:54 Juha Manninen Widgetset GTK 2 => GTK 2
2021-02-05 12:54 Juha Manninen Note Added: 0128782
2021-02-10 13:15 Juha Manninen Relationship added has duplicate 0038461