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

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


 vcl/inc/unx/gtk/gtkframe.hxx |    1 
 vcl/unx/gtk3/gtkframe.cxx    |   90 ++++++++++++++++++++-----------------------
 2 files changed, 44 insertions(+), 47 deletions(-)

New commits:
commit 2947ae712ff0e21fd9c1c32a0926284f2b87d4a7
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon May 10 15:44:14 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon May 10 17:50:04 2021 +0200

    gtk4: get the event state into the button press/release
    
    Change-Id: I85b7e64cf8216a7abf18432bbf7bf659876ee07a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115337
    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 e918b3157bdb..56ef0fce5262 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -275,6 +275,7 @@ class GtkSalFrame final : public SalFrame
 #endif
     static void         gestureSwipe(GtkGestureSwipe* gesture, gdouble velocity_x, gdouble velocity_y, gpointer frame);
     static void         gestureLongPress(GtkGestureLongPress* gesture, gdouble x, gdouble y, gpointer frame);
+    bool                DrawingAreaButton(SalEvent nEventType, int nEventX, int nEventY, int nButton, guint32 nTime, guint nState);
 #if GTK_CHECK_VERSION(4, 0, 0)
     static void         gesturePressed(GtkGestureClick* gesture, int n_press, gdouble x, gdouble y, gpointer frame);
     static void         gestureReleased(GtkGestureClick* gesture, int n_press, gdouble x, gdouble y, gpointer frame);
diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx
index bb68a376290c..c683b5e2d9e4 100644
--- a/vcl/unx/gtk3/gtkframe.cxx
+++ b/vcl/unx/gtk3/gtkframe.cxx
@@ -2848,11 +2848,35 @@ void GtkSalFrame::GrabFocus()
     }
 }
 
+bool GtkSalFrame::DrawingAreaButton(SalEvent nEventType, int nEventX, int nEventY, int nButton, guint32 nTime, guint nState)
+{
+    UpdateLastInputEventTime(nTime);
+
+    SalMouseEvent aEvent;
+    switch(nButton)
+    {
+        case 1: aEvent.mnButton = MOUSE_LEFT;   break;
+        case 2: aEvent.mnButton = MOUSE_MIDDLE; break;
+        case 3: aEvent.mnButton = MOUSE_RIGHT;  break;
+        default: return false;
+    }
+
+    aEvent.mnTime = nTime;
+    aEvent.mnX = nEventX;
+    aEvent.mnY = nEventY;
+    aEvent.mnCode = GetMouseModCode(nState);
+
+    if( AllSettings::GetLayoutRTL() )
+        aEvent.mnX = maGeometry.nWidth-1-aEvent.mnX;
+
+    CallCallbackExc(nEventType, &aEvent);
+
+    return true;
+}
+
 #if !GTK_CHECK_VERSION(4, 0, 0)
 gboolean GtkSalFrame::signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer frame)
 {
-    UpdateLastInputEventTime(pEvent->time);
-
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
     GtkWidget* pEventWidget = pThis->getMouseEventWidget();
     bool bDifferentEventWindow = pEvent->window != gtk_widget_get_window(pEventWidget);
@@ -2872,7 +2896,6 @@ gboolean GtkSalFrame::signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer
             pThis->GrabFocus();
     }
 
-    SalMouseEvent aEvent;
     SalEvent nEventType = SalEvent::NONE;
     switch( pEvent->type )
     {
@@ -2885,13 +2908,6 @@ gboolean GtkSalFrame::signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer
         default:
             return false;
     }
-    switch( pEvent->button )
-    {
-        case 1: aEvent.mnButton = MOUSE_LEFT;   break;
-        case 2: aEvent.mnButton = MOUSE_MIDDLE; break;
-        case 3: aEvent.mnButton = MOUSE_RIGHT;  break;
-        default: return false;
-    }
 
     vcl::DeletionListener aDel( pThis );
 
@@ -2930,59 +2946,39 @@ gboolean GtkSalFrame::signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer
         }
     }
 
+    bool bRet = false;
     if (!aDel.isDeleted())
     {
-        aEvent.mnTime   = pEvent->time;
-        aEvent.mnX      = static_cast<tools::Long>(pEvent->x_root) - pThis->maGeometry.nX;
-        aEvent.mnY      = static_cast<tools::Long>(pEvent->y_root) - pThis->maGeometry.nY;
-        aEvent.mnCode   = GetMouseModCode( pEvent->state );
-
-        if( AllSettings::GetLayoutRTL() )
-            aEvent.mnX = pThis->maGeometry.nWidth-1-aEvent.mnX;
-
-        pThis->CallCallbackExc( nEventType, &aEvent );
+        bRet = pThis->DrawingAreaButton(nEventType,
+                                        pEvent->x_root - pThis->maGeometry.nX,
+                                        pEvent->y_root - pThis->maGeometry.nY,
+                                        pEvent->button,
+                                        pEvent->time,
+                                        pEvent->state);
     }
 
-    return true;
+    return bRet;
 }
 #else
-void GtkSalFrame::gesturePressed(GtkGestureClick* gesture, int /*n_press*/, gdouble x, gdouble y, gpointer frame)
+void GtkSalFrame::gesturePressed(GtkGestureClick* pGesture, int /*n_press*/, gdouble x, gdouble y, gpointer frame)
 {
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
-    pThis->gestureButton(gesture, SalEvent::MouseButtonDown, x, y);
+    pThis->gestureButton(pGesture, SalEvent::MouseButtonDown, x, y);
 }
 
-void GtkSalFrame::gestureReleased(GtkGestureClick* gesture, int /*n_press*/, gdouble x, gdouble y, gpointer frame)
+void GtkSalFrame::gestureReleased(GtkGestureClick* pGesture, int /*n_press*/, gdouble x, gdouble y, gpointer frame)
 {
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
-    pThis->gestureButton(gesture, SalEvent::MouseButtonUp, x, y);
+    pThis->gestureButton(pGesture, SalEvent::MouseButtonUp, x, y);
 }
 
-void GtkSalFrame::gestureButton(GtkGestureClick* gesture, SalEvent nEventType, gdouble x, gdouble y)
+void GtkSalFrame::gestureButton(GtkGestureClick* pGesture, SalEvent nEventType, gdouble x, gdouble y)
 {
-    SalMouseEvent aEvent;
-    switch (gtk_gesture_single_get_current_button(GTK_GESTURE_SINGLE(gesture)))
-    {
-        case 1: aEvent.mnButton = MOUSE_LEFT;   break;
-        case 2: aEvent.mnButton = MOUSE_MIDDLE; break;
-        case 3: aEvent.mnButton = MOUSE_RIGHT;  break;
-        default: return;
-    }
-
-    GdkEvent* pEvent = gtk_gesture_get_last_event(GTK_GESTURE(gesture), nullptr);
-
-    aEvent.mnTime   = gdk_event_get_time(pEvent);
-    aEvent.mnX      = x;
-    aEvent.mnY      = y;
-//TODO    aEvent.mnCode   = GetMouseModCode( pEvent->state );
-    aEvent.mnCode   = aEvent.mnButton;
-
-    if( AllSettings::GetLayoutRTL() )
-        aEvent.mnX = maGeometry.nWidth-1-aEvent.mnX;
-
-    CallCallbackExc(nEventType, &aEvent);
+    GdkEvent* pEvent = gtk_event_controller_get_current_event(GTK_EVENT_CONTROLLER(pGesture));
+    GdkModifierType eType = gtk_event_controller_get_current_event_state(GTK_EVENT_CONTROLLER(pGesture));
+    int nButton = gtk_gesture_single_get_current_button(GTK_GESTURE_SINGLE(pGesture));
+    DrawingAreaButton(nEventType, x, y, nButton, gdk_event_get_time(pEvent), eType);
 }
-
 #endif
 
 #if !GTK_CHECK_VERSION(4, 0, 0)


More information about the Libreoffice-commits mailing list