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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon May 10 15:57:20 UTC 2021


 vcl/inc/unx/gtk/gtkframe.hxx |    8 ++++++-
 vcl/unx/gtk3/gtkframe.cxx    |   49 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

New commits:
commit eabdf3bfce20513b3650766836f7d141fa088bfd
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon May 10 16:03:18 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon May 10 17:56:45 2021 +0200

    gtk4: add focus-in/out
    
    Change-Id: Ia954b2b1cc0ea368a318549f39e2efab42a0ebb2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115339
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 56ef0fce5262..94f54989b323 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -281,8 +281,14 @@ class GtkSalFrame final : public SalFrame
     static void         gestureReleased(GtkGestureClick* gesture, int n_press, gdouble x, gdouble y, gpointer frame);
     void                gestureButton(GtkGestureClick* gesture, SalEvent nEventType, gdouble x, gdouble y);
 #endif
-#if !GTK_CHECK_VERSION(4, 0, 0)
+    void                DrawingAreaFocusInOut(SalEvent nEventType);
+#if GTK_CHECK_VERSION(4, 0, 0)
+    static void         signalFocusEnter(GtkEventControllerFocus* pController, gpointer frame);
+    static void         signalFocusLeave(GtkEventControllerFocus* pController, gpointer frame);
+#else
     static gboolean     signalFocus( GtkWidget*, GdkEventFocus*, gpointer );
+#endif
+#if !GTK_CHECK_VERSION(4, 0, 0)
     static void         signalSetFocus( GtkWindow* pWindow, GtkWidget* pWidget, gpointer frame );
 #endif
     void WindowMap();
diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx
index c683b5e2d9e4..a1dd33d8bd1f 100644
--- a/vcl/unx/gtk3/gtkframe.cxx
+++ b/vcl/unx/gtk3/gtkframe.cxx
@@ -1004,6 +1004,11 @@ void GtkSalFrame::InitCommon()
     g_signal_connect_after( G_OBJECT(m_pWindow), "focus-out-event", G_CALLBACK(signalFocus), this );
     if (GTK_IS_WINDOW(m_pWindow)) // i.e. not if it's a GtkEventBox which doesn't have the signal
         m_nSetFocusSignalId = g_signal_connect( G_OBJECT(m_pWindow), "set-focus", G_CALLBACK(signalSetFocus), this );
+#else
+    GtkEventController* pFocusController = gtk_event_controller_focus_new();
+    g_signal_connect(pFocusController, "enter", G_CALLBACK(signalFocusEnter), this);
+    g_signal_connect(pFocusController, "leave", G_CALLBACK(signalFocusLeave), this);
+    gtk_widget_add_controller(pEventWidget, pFocusController);
 #endif
 #if !GTK_CHECK_VERSION(4,0,0)
     g_signal_connect( G_OBJECT(m_pWindow), "map-event", G_CALLBACK(signalMap), this );
@@ -3511,6 +3516,36 @@ void GtkSalFrame::TriggerPaintEvent()
     gtk_widget_queue_draw(GTK_WIDGET(m_pFixedContainer));
 }
 
+void GtkSalFrame::DrawingAreaFocusInOut(SalEvent nEventType)
+{
+    SalGenericInstance* pSalInstance =
+        static_cast<SalGenericInstance*>(GetSalData()->m_pInstance);
+
+    // check if printers have changed (analogous to salframe focus handler)
+    pSalInstance->updatePrinterUpdate();
+
+    if (nEventType == SalEvent::LoseFocus)
+        m_nKeyModifiers = ModKeyFlags::NONE;
+
+    if (m_pIMHandler)
+    {
+        bool bFocusInAnotherGtkWidget = false;
+        if (GTK_IS_WINDOW(m_pWindow))
+        {
+            GtkWidget* pFocusWindow = gtk_window_get_focus(GTK_WINDOW(m_pWindow));
+            bFocusInAnotherGtkWidget = pFocusWindow && pFocusWindow != GTK_WIDGET(m_pFixedContainer);
+        }
+        if (!bFocusInAnotherGtkWidget)
+            m_pIMHandler->focusChanged(nEventType == SalEvent::GetFocus);
+    }
+
+    // ask for changed printers like generic implementation
+    if (nEventType == SalEvent::GetFocus && pSalInstance->isPrinterInit())
+        pSalInstance->updatePrinterUpdate();
+
+    CallCallbackExc(nEventType, nullptr);
+}
+
 #if !GTK_CHECK_VERSION(4, 0, 0)
 gboolean GtkSalFrame::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer frame )
 {
@@ -3559,7 +3594,21 @@ gboolean GtkSalFrame::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer f
 
     return false;
 }
+#else
+void GtkSalFrame::signalFocusEnter(GtkEventControllerFocus*, gpointer frame)
+{
+    GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
+    pThis->DrawingAreaFocusInOut(SalEvent::GetFocus);
+}
 
+void GtkSalFrame::signalFocusLeave(GtkEventControllerFocus*, gpointer frame)
+{
+    GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
+    pThis->DrawingAreaFocusInOut(SalEvent::LoseFocus);
+}
+#endif
+
+#if !GTK_CHECK_VERSION(4, 0, 0)
 // change of focus between native widgets within the toplevel
 void GtkSalFrame::signalSetFocus(GtkWindow*, GtkWidget* pWidget, gpointer frame)
 {


More information about the Libreoffice-commits mailing list