vcl/unx/gtk3/gtkframe.cxx |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

New commits:
commit d404f6c8b28bc9b298cd618ef6c0dd6d755bdc17
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu May 19 09:34:16 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu May 19 12:47:23 2022 +0200

    merge the g_bus_get_sync calls
    
    Change-Id: I320feb6673f18d6d8d9c5afa9ab602b9405ec581
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134604
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx
index 4c2aab8e7a28..9037b9eaf915 100644
--- a/vcl/unx/gtk3/gtkframe.cxx
+++ b/vcl/unx/gtk3/gtkframe.cxx
@@ -76,6 +76,12 @@ int GtkSalFrame::m_nFloats = 0;
 
 static GDBusConnection* pSessionBus = nullptr;
 
+static void EnsureSessionBus()
+{
+    if (!pSessionBus)
+        pSessionBus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
+}
+
 sal_uInt16 GtkSalFrame::GetKeyModCode( guint state )
 {
     sal_uInt16 nCode = 0;
@@ -541,8 +547,7 @@ static void attach_menu_model(GtkSalFrame* pSalFrame)
 
 #if !GTK_CHECK_VERSION(4,0,0)
     // Get a DBus session connection.
-    if (!pSessionBus)
-        pSessionBus = g_bus_get_sync (G_BUS_TYPE_SESSION, nullptr, nullptr);
+    EnsureSessionBus();
     if (!pSessionBus)
         return;
 
@@ -629,13 +634,9 @@ void GtkSalFrame::EnsureAppMenuWatch()
         return;
 
     // Get a DBus session connection.
-    if ( pSessionBus == nullptr )
-    {
-        pSessionBus = g_bus_get_sync( G_BUS_TYPE_SESSION, nullptr, nullptr );
-
-        if ( pSessionBus == nullptr )
-            return;
-    }
+    EnsureSessionBus();
+    if (!pSessionBus)
+        return;
 
     // Publish the menu only if AppMenu registrar is available.
     m_nWatcherId = g_bus_watch_name_on_connection( pSessionBus,

Reply via email to