vcl/osx/salframeview.mm |   30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

New commits:
commit 36cb8c808527d80d947a005b934de585a55b12b6
Author:     Patrick Luby <[email protected]>
AuthorDate: Mon Nov 11 10:22:08 2024 -0500
Commit:     Michael Weghorn <[email protected]>
CommitDate: Mon Nov 18 09:10:55 2024 +0100

    tdf#151423 Only allow modifiers for mouse scrollwheel events
    
    The Command modifier converts scrollwheel events into
    magnification events and the Shift modifier converts vertical
    scrollwheel events into horizontal scrollwheel events. This
    behavior is reasonable for mouse scrollwheel events since many
    mice only have a single, vertical scrollwheel but trackpads
    already have specific gestures for magnification and horizontal
    scrolling. So, behave like most macOS applications and ignore
    all modifiers if this a trackpad scrollwheel event.
    
    Also, ignore all modifiers for swipe events since it appears
    that devices that generate swipe events can generate both
    vertical and horizontal swipe events.
    
    Change-Id: I3c0c726759ef010d528f221c63d1e7e401726db5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176510
    Reviewed-by: Patrick Luby <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index 15228b7b5e91..8948b77985df 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -238,6 +238,11 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
     }
 }
 
+static bool isMouseScrollWheelEvent( NSEvent *pEvent )
+{
+    return ( pEvent && [pEvent type] == NSEventTypeScrollWheel && [pEvent 
phase] == NSEventPhaseNone && [pEvent momentumPhase] == NSEventPhaseNone );
+}
+
 @interface NSResponder (SalFrameWindow)
 -(BOOL)accessibilityIsIgnored;
 @end
@@ -1144,7 +1149,7 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
         {
             dX += [pEvent deltaX];
             dY += [pEvent deltaY];
-            NSEvent* pNextEvent = [NSApp nextEventMatchingMask: 
NSEventMaskScrollWheel
+            NSEvent* pNextEvent = [NSApp nextEventMatchingMask: 
NSEventMaskSwipe
             untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ];
             if( !pNextEvent )
                 break;
@@ -1158,7 +1163,11 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
         aEvent.mnTime           = mpFrame->mnLastEventTime;
         aEvent.mnX = static_cast<tools::Long>(aPt.x) - mpFrame->maGeometry.x();
         aEvent.mnY = static_cast<tools::Long>(aPt.y) - mpFrame->maGeometry.y();
-        aEvent.mnCode           = ImplGetModifierMask( 
mpFrame->mnLastModifierFlags );
+        // tdf#151423 Ignore all modifiers for swipe events
+        // It appears that devices that generate swipe events can generate
+        // both veritical and horizontal swipe events. So, behave like most
+        // macOS applications and ignore all modifiers if this a swipe event.
+        aEvent.mnCode           = 0;
         aEvent.mbDeltaIsPixel   = true;
 
         if( AllSettings::GetLayoutRTL() )
@@ -1184,6 +1193,9 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
             aEvent.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
             mpFrame->CallCallback( SalEvent::WheelMouse, &aEvent );
         }
+
+        // tdf#155266 force flush after scrolling
+        mpFrame->mbForceFlush = true;
     }
 }
 
@@ -1199,13 +1211,14 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
         // merge pending scroll wheel events
         CGFloat dX = 0.0;
         CGFloat dY = 0.0;
+        bool bAllowModifiers = isMouseScrollWheelEvent( pEvent );
         for(;;)
         {
             dX += [pEvent deltaX];
             dY += [pEvent deltaY];
             NSEvent* pNextEvent = [NSApp nextEventMatchingMask: 
NSEventMaskScrollWheel
                 untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ];
-            if( !pNextEvent )
+            if( !pNextEvent || ( isMouseScrollWheelEvent( pNextEvent ) != 
bAllowModifiers ) )
                 break;
             pEvent = pNextEvent;
         }
@@ -1217,7 +1230,16 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
         aEvent.mnTime         = mpFrame->mnLastEventTime;
         aEvent.mnX = static_cast<tools::Long>(aPt.x) - mpFrame->maGeometry.x();
         aEvent.mnY = static_cast<tools::Long>(aPt.y) - mpFrame->maGeometry.y();
-        aEvent.mnCode         = ImplGetModifierMask( 
mpFrame->mnLastModifierFlags );
+        // tdf#151423 Only allow modifiers for mouse scrollwheel events
+        // The Command modifier converts scrollwheel events into
+        // magnification events and the Shift modifier converts vertical
+        // scrollwheel events into horizontal scrollwheel events. This
+        // behavior is reasonable for mouse scrollwheel events since many
+        // mice only have a single, vertical scrollwheel but trackpads
+        // already have specific gestures for magnification and horizontal
+        // scrolling. So, behave like most macOS applications and ignore
+        // all modifiers if this a trackpad scrollwheel event.
+        aEvent.mnCode         = bAllowModifiers ? ImplGetModifierMask( 
mpFrame->mnLastModifierFlags ) : 0;
         aEvent.mbDeltaIsPixel = false;
 
         if( AllSettings::GetLayoutRTL() )

Reply via email to