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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 19 15:21:45 UTC 2019


 vcl/unx/gtk3/gtk3gtkframe.cxx |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

New commits:
commit bce3b6af1a71d4586f1e0d4cf56cd794454ea3b1
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Dec 17 15:32:23 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Dec 19 16:20:46 2019 +0100

    allow default GtkWindow to handle key events first
    
    which, in the case of native GtkWidget children of a LibreOffice window would
    get the keystrokes to the correct focused widget
    
    Change-Id: I0c0864701668f0b6b017517c3065c11322fdc45d
    Reviewed-on: https://gerrit.libreoffice.org/85308
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 82953b608583..6c9fa21828b2 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -850,6 +850,7 @@ void GtkSalFrame::InitCommon()
     // add the fixed container child,
     // fixed is needed since we have to position plugin windows
     m_pFixedContainer = GTK_FIXED(g_object_new( ooo_fixed_get_type(), nullptr ));
+    gtk_widget_set_can_focus(GTK_WIDGET(m_pFixedContainer), true);
     gtk_widget_set_size_request(GTK_WIDGET(m_pFixedContainer), 1, 1);
     gtk_container_add( GTK_CONTAINER(m_pEventBox), GTK_WIDGET(m_pFixedContainer) );
 
@@ -1926,7 +1927,9 @@ void GtkSalFrame::ToTop( SalFrameToTop nFlags )
     if( m_pWindow )
     {
         if( isChild( false ) )
-            gtk_widget_grab_focus( m_pWindow );
+        {
+            gtk_widget_grab_focus(GTK_WIDGET(m_pFixedContainer));
+        }
         else if( IS_WIDGET_MAPPED( m_pWindow ) )
         {
             if (!(nFlags & SalFrameToTop::GrabFocusOnly))
@@ -2470,7 +2473,7 @@ namespace
     }
 }
 
-gboolean GtkSalFrame::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer frame )
+gboolean GtkSalFrame::signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer frame)
 {
     UpdateLastInputEventTime(pEvent->time);
 
@@ -2478,15 +2481,21 @@ gboolean GtkSalFrame::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer
     GtkWidget* pEventWidget = pThis->getMouseEventWidget();
     bool bDifferentEventWindow = pEvent->window != gtk_widget_get_window(pEventWidget);
 
-    // tdf#120764 It isn't allowed under wayland to have two visible popups that share
-    // the same top level parent. The problem is that since gtk 3.24 tooltips are also
-    // implemented as popups, which means that we cannot show any popup if there is a
-    // visible tooltip. In fact, gtk will hide the tooltip by itself after this handler,
-    // in case of a button press event. But if we intend to show a popup on button press
-    // it will be too late, so just do it here:
     if (pEvent->type == GDK_BUTTON_PRESS)
+    {
+        // tdf#120764 It isn't allowed under wayland to have two visible popups that share
+        // the same top level parent. The problem is that since gtk 3.24 tooltips are also
+        // implemented as popups, which means that we cannot show any popup if there is a
+        // visible tooltip. In fact, gtk will hide the tooltip by itself after this handler,
+        // in case of a button press event. But if we intend to show a popup on button press
+        // it will be too late, so just do it here:
         pThis->HideTooltip();
 
+        // focus on click
+        if (!bDifferentEventWindow)
+            gtk_widget_grab_focus(GTK_WIDGET(pThis->m_pFixedContainer));
+    }
+
     SalMouseEvent aEvent;
     SalEvent nEventType = SalEvent::NONE;
     switch( pEvent->type )
@@ -3065,6 +3074,22 @@ gboolean GtkSalFrame::signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointe
 
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
 
+    if (GTK_IS_WINDOW(pThis->m_pWindow))
+    {
+        GtkWidget* pFocusWindow = gtk_window_get_focus(GTK_WINDOW(pThis->m_pWindow));
+        if (pFocusWindow && pFocusWindow != GTK_WIDGET(pThis->m_pFixedContainer))
+        {
+            gpointer pClass = g_type_class_ref(GTK_TYPE_WINDOW);
+            GtkWidgetClass* pWindowClass = GTK_WIDGET_CLASS(pClass);
+            // if the focus is not in our main widget, see if there is a handler
+            // for this key stroke in GtkWindow first
+            bool bHandled = pWindowClass->key_press_event(pThis->m_pWindow, pEvent);
+            g_type_class_unref(pClass);
+            if (bHandled)
+                return true;
+        }
+    }
+
     if (pThis->isFloatGrabWindow())
         return signalKey(pWidget, pEvent, pThis->m_pParent);
 


More information about the Libreoffice-commits mailing list