vcl/inc/osx/salframeview.h |    3 +++
 vcl/osx/salframeview.mm    |   43 ++++++++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 17 deletions(-)

New commits:
commit b197379e867087413be86bd1a32030b912ecaa8a
Author:     Patrick Luby <[email protected]>
AuthorDate: Sat Jan 18 11:30:30 2025 -0500
Commit:     Patrick Luby <[email protected]>
CommitDate: Sun Jan 19 12:27:19 2025 +0100

    tdf#151423 use the same modifier keys during a scrolling session
    
    Revert commit f5ef5eafdf70a36edd5129147502a9c74df89456 as it
    completely disabled the ability to zoom on mice with limited
    support for gestures such as the Apple Magic Mouse by pressing
    pressing the Command key while scrolling. So try a different
    approach and use the modifier keys that were pressed when the
    current scrolling session was started for the entire scrolling
    session.
    
    Unfortunately, session state changes such as a scrolling session
    began or ended are not fired when scrolling with a regular mouse
    scrollwheel so use a significant pause between scrolling events
    as a rough indicator that a new scrolling session has begun.
    
    Change-Id: I898d7f0d3e28ad0436fcb75504f9efb6bf9cdb7d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180451
    Tested-by: Jenkins
    Reviewed-by: Patrick Luby <[email protected]>

diff --git a/vcl/inc/osx/salframeview.h b/vcl/inc/osx/salframeview.h
index 287ccaedbc06..52459ea99cde 100644
--- a/vcl/inc/osx/salframeview.h
+++ b/vcl/inc/osx/salframeview.h
@@ -112,6 +112,9 @@ enum class SalEvent;
     NSAttributedString* mpLastMarkedText;
     BOOL            mbTextInputWantsNonRepeatKeyDown;
     NSTrackingArea* mpLastTrackingArea;
+
+    NSTimeInterval  mfLastScrollEventTime;
+    NSEventModifierFlags mnLastScrollModifierFlags;
 }
 +(void)unsetMouseFrame: (AquaSalFrame*)pFrame;
 -(id)initWithSalFrame: (AquaSalFrame*)pFrame;
diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index a5cb9270600b..19c4234600c7 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -45,6 +45,8 @@
 
 #define WHEEL_EVENT_FACTOR 1.5
 
+const static NSTimeInterval fScrollEventTimeoutTime = 1.0f;
+
 static sal_uInt16 ImplGetModifierMask( unsigned int nMask )
 {
     sal_uInt16 nRet = 0;
@@ -238,11 +240,6 @@ static void freezeWindowSizeAndReschedule( NSWindow 
*pWindow )
     }
 }
 
-static bool isMouseScrollWheelEvent( NSEvent *pEvent )
-{
-    return ( pEvent && [pEvent type] == NSEventTypeScrollWheel && [pEvent 
phase] == NSEventPhaseNone && [pEvent momentumPhase] == NSEventPhaseNone );
-}
-
 static void updateMenuBarVisibility( const AquaSalFrame *pFrame )
 {
     // Show the menubar if application is in native full screen mode
@@ -936,6 +933,9 @@ static void updateMenuBarVisibility( const AquaSalFrame 
*pFrame )
         mpLastMarkedText = nil;
         mbTextInputWantsNonRepeatKeyDown = NO;
         mpLastTrackingArea = nil;
+
+        mfLastScrollEventTime = 0.0f;
+        mnLastScrollModifierFlags = 0;
     }
 
     return self;
@@ -1350,17 +1350,35 @@ static void updateMenuBarVisibility( const AquaSalFrame 
*pFrame )
         mpFrame->mnLastEventTime = static_cast<sal_uInt64>( [pEvent timestamp] 
* 1000.0 );
         mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
 
+        // tdf#151423 use the same modifier keys during a scrolling session
+        // Revert commit f5ef5eafdf70a36edd5129147502a9c74df89456 as it
+        // completely disabled the ability to zoom on mice with limited
+        // support for gestures such as the Apple Magic Mouse by pressing
+        // pressing the Command key while scrolling. So try a different
+        // approach and use the modifier keys that were pressed when the
+        // current scrolling session was started for the entire scrolling
+        // session.
+        // Unfortunately, session state changes such as a scrolling session
+        // began or ended are not fired when scrolling with a regular mouse
+        // scrollwheel so use a significant pause between scrolling events
+        // as a rough indicator that a new scrolling session has begun.
+        if( [pEvent momentumPhase] == NSEventPhaseNone && 
mnLastScrollModifierFlags != [pEvent modifierFlags] )
+        {
+            if( [pEvent timestamp] - mfLastScrollEventTime > 
fScrollEventTimeoutTime )
+                mnLastScrollModifierFlags = [pEvent modifierFlags];
+        }
+
         // merge pending scroll wheel events
         CGFloat dX = 0.0;
         CGFloat dY = 0.0;
-        bool bAllowModifiers = isMouseScrollWheelEvent( pEvent );
         for(;;)
         {
+            mfLastScrollEventTime = [pEvent timestamp];
             dX += [pEvent deltaX];
             dY += [pEvent deltaY];
             NSEvent* pNextEvent = [NSApp nextEventMatchingMask: 
NSEventMaskScrollWheel
                 untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ];
-            if( !pNextEvent || ( isMouseScrollWheelEvent( pNextEvent ) != 
bAllowModifiers ) )
+            if( !pNextEvent )
                 break;
             pEvent = pNextEvent;
         }
@@ -1372,16 +1390,7 @@ static void updateMenuBarVisibility( const AquaSalFrame 
*pFrame )
         aEvent.mnTime         = mpFrame->mnLastEventTime;
         aEvent.mnX = static_cast<tools::Long>(aPt.x) - 
mpFrame->GetUnmirroredGeometry().x();
         aEvent.mnY = static_cast<tools::Long>(aPt.y) - 
mpFrame->GetUnmirroredGeometry().y();
-        // 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.mnCode         = ImplGetModifierMask( mnLastScrollModifierFlags 
);
         aEvent.mbDeltaIsPixel = false;
 
         if( AllSettings::GetLayoutRTL() )

Reply via email to