[Libreoffice-commits] core.git: vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed May 12 07:49:35 UTC 2021


 vcl/unx/gtk3/gtksys.cxx |   26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

New commits:
commit 0f76fccf16ed865c5af97082c1bc9c36eba986ad
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue May 11 20:08:54 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed May 12 09:48:54 2021 +0200

    gtk4: improve gtk_dialog_run replcement to not crash on ESC
    
    e.g. open/save file dialog
    
    Change-Id: I71813125589866affc2313c72e44159c15501ec4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115445
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/unx/gtk3/gtksys.cxx b/vcl/unx/gtk3/gtksys.cxx
index 6a3701e10686..41777f099f17 100644
--- a/vcl/unx/gtk3/gtksys.cxx
+++ b/vcl/unx/gtk3/gtksys.cxx
@@ -264,24 +264,34 @@ namespace
 {
     struct DialogLoop
     {
-        GMainLoop* m_pLoop = nullptr;
+        GMainLoop* pLoop = nullptr;
         gint nResponseId = GTK_RESPONSE_NONE;
+        gulong nSignalResponseId = 0;
+        gulong nSignalCloseRequestId= 0;
 
-        static void DialogResponse(GtkDialog*, gint nResponseId, gpointer data)
+        static gboolean DialogClose(GtkWindow* pDialog, gpointer /*data*/)
+        {
+            gtk_dialog_response(GTK_DIALOG(pDialog), GTK_RESPONSE_CANCEL);
+            return true;
+        }
+
+        static void DialogResponse(GtkDialog* pDialog, gint nResponseId, gpointer data)
         {
             DialogLoop* pDialogLoop = static_cast<DialogLoop*>(data);
+            g_signal_handler_disconnect(pDialog, pDialogLoop->nSignalResponseId);
+            g_signal_handler_disconnect(pDialog, pDialogLoop->nSignalCloseRequestId);
             pDialogLoop->nResponseId = nResponseId;
-            g_main_loop_quit(pDialogLoop->m_pLoop);
+            g_main_loop_quit(pDialogLoop->pLoop);
         }
 
         int run(GtkDialog *pDialog)
         {
-            gulong nSignalResponseId = g_signal_connect(pDialog, "response", G_CALLBACK(DialogResponse), this);
+            nSignalResponseId = g_signal_connect(pDialog, "response", G_CALLBACK(DialogResponse), this);
+            nSignalCloseRequestId = g_signal_connect(pDialog, "close-request", G_CALLBACK(DialogClose), this);
             gtk_window_present(GTK_WINDOW(pDialog));
-            m_pLoop = g_main_loop_new(nullptr, false);
-            main_loop_run(m_pLoop);
-            g_main_loop_unref(m_pLoop);
-            g_signal_handler_disconnect(pDialog, nSignalResponseId);
+            pLoop = g_main_loop_new(nullptr, false);
+            main_loop_run(pLoop);
+            g_main_loop_unref(pLoop);
             return nResponseId;
         }
 


More information about the Libreoffice-commits mailing list