sc/source/ui/inc/tabview.hxx  |    2 +
 sc/source/ui/view/tabview.cxx |   46 ++++++++++++++++++++++++++++++++++++++++++
 vcl/osx/salframeview.mm       |    8 +++----
 3 files changed, 52 insertions(+), 4 deletions(-)

New commits:
commit 48c13e2cefb0251d9ca975f4e4f39af3d8adec6f
Author:     Patrick Luby <plub...@libreoffice.org>
AuthorDate: Mon Dec 25 09:19:48 2023 -0500
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Jan 5 15:59:57 2024 +0100

    tdf#135478 Reduce sensitivity of horizontal scrollwheel
    
    Problem: at least on macOS, swipe events are very
    precise. So, when swiping at a slight angle off of
    vertical, swipe events will include a small amount
    of horizontal movement. Since horizontal swipe units
    are measured in cell widths, these small amounts of
    horizontal movement results in shifting many columns
    to the right or left while swiping almost vertically.
    
    So my hacky fix is to reduce the amount of horizontal
    swipe events to roughly match the "visual distance"
    of vertical swipe events.
    
    The reduction factor is arbitrary but is set to
    roughly the ratio of default cell width divided by
    default cell height. This hacky fix isn't a perfect
    fix, but hopefully it reduces the amount of
    unexpected horizontal shifting while swiping
    vertically to a tolerable amount for most users.
    
    Note: the potential downside of doing this is that
    some users might find horizontal swiping to be
    slower than they are used to. If that becomes an
    issue for enough users, the reduction factor may
    need to be lowered to find a good balance point.
    
    Lastly, fix the unbalanced rounding of delta X and Y
    values due to using floor() for macOS native swipe
    and scroll wheel events.
    
    Change-Id: I8c0c9a3aa688e411c47ebb5e7500f3a50f6f673b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161278
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Patrick Luby <plub...@libreoffice.org>
    (cherry picked from commit 689ddab27bb0658e43ab0e0d4d8235e45d8904d4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161318
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index 3f270770ec89..eb62660f2a28 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -216,6 +216,8 @@ private:
 
     double              mfLastZoomScale = 0;
     double              mfAccumulatedZoom = 0;
+    tools::Long         mnPendingaHScrollLeftDelta = 0;
+    tools::Long         mnPendingaHScrollRightDelta = 0;
 
     void            Init();
 
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index aa5bd477a15b..6ead63b98d85 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -1216,6 +1216,52 @@ void ScTabView::ScrollHdl(ScrollAdaptor* pScroll)
                     else
                         nDelta = 0;
                 }
+                else if ( bHoriz )
+                {
+                    // tdf#135478 Reduce sensitivity of horizontal scrollwheel
+                    // Problem: at least on macOS, swipe events are very
+                    // precise. So, when swiping at a slight angle off of
+                    // vertical, swipe events will include a small amount
+                    // of horizontal movement. Since horizontal swipe units
+                    // are measured in cell widths, these small amounts of
+                    // horizontal movement results in shifting many columns
+                    // to the right or left while swiping almost vertically.
+                    // So my hacky fix is to reduce the amount of horizontal
+                    // swipe events to roughly match the "visual distance"
+                    // of vertical swipe events.
+                    // The reduction factor is arbitrary but is set to
+                    // roughly the ratio of default cell width divided by
+                    // default cell height. This hacky fix isn't a perfect
+                    // fix, but hopefully it reduces the amount of
+                    // unexpected horizontal shifting while swiping
+                    // vertically to a tolerable amount for most users.
+                    // Note: the potential downside of doing this is that
+                    // some users might find horizontal swiping to be
+                    // slower than they are used to. If that becomes an
+                    // issue for enough users, the reduction factor may
+                    // need to be lowered to find a good balance point.
+                    static const sal_uInt16 nHScrollReductionFactor = 8;
+                    if ( pScroll == aHScrollLeft.get() )
+                    {
+                        mnPendingaHScrollLeftDelta += nDelta;
+                        nDelta = 0;
+                        if ( abs(mnPendingaHScrollLeftDelta) > 
nHScrollReductionFactor )
+                        {
+                            nDelta = mnPendingaHScrollLeftDelta / 
nHScrollReductionFactor;
+                            mnPendingaHScrollLeftDelta = 
mnPendingaHScrollLeftDelta % nHScrollReductionFactor;
+                        }
+                    }
+                    else if ( pScroll == aHScrollRight.get() )
+                    {
+                        mnPendingaHScrollRightDelta += nDelta;
+                        nDelta = 0;
+                        if ( abs(mnPendingaHScrollRightDelta) > 
nHScrollReductionFactor )
+                        {
+                            nDelta = mnPendingaHScrollRightDelta / 
nHScrollReductionFactor;
+                            mnPendingaHScrollRightDelta = 
mnPendingaHScrollRightDelta % nHScrollReductionFactor;
+                        }
+                    }
+                }
 
                 nPrevDragPos = nScrollPos;
             }
diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index 54df8d390f53..6f5e49a30c5f 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -1093,7 +1093,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
 
         if( dX != 0.0 )
         {
-            aEvent.mnDelta = static_cast<tools::Long>(floor(dX));
+            aEvent.mnDelta = static_cast<tools::Long>(dX < 0 ? floor(dX) : 
ceil(dX));
             aEvent.mnNotchDelta = (dX < 0) ? -1 : +1;
             if( aEvent.mnDelta == 0 )
                 aEvent.mnDelta = aEvent.mnNotchDelta;
@@ -1103,7 +1103,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
         }
         if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame ))
         {
-            aEvent.mnDelta = static_cast<tools::Long>(floor(dY));
+            aEvent.mnDelta = static_cast<tools::Long>(dY < 0 ? floor(dY) : 
ceil(dY));
             aEvent.mnNotchDelta = (dY < 0) ? -1 : +1;
             if( aEvent.mnDelta == 0 )
                 aEvent.mnDelta = aEvent.mnNotchDelta;
@@ -1152,7 +1152,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
 
         if( dX != 0.0 )
         {
-            aEvent.mnDelta = static_cast<tools::Long>(floor(dX));
+            aEvent.mnDelta = static_cast<tools::Long>(dX < 0 ? floor(dX) : 
ceil(dX));
             aEvent.mnNotchDelta = (dX < 0) ? -1 : +1;
             if( aEvent.mnDelta == 0 )
                 aEvent.mnDelta = aEvent.mnNotchDelta;
@@ -1166,7 +1166,7 @@ static void updateWinDataInLiveResize(bool bInLiveResize)
         }
         if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame ) )
         {
-            aEvent.mnDelta = static_cast<tools::Long>(floor(dY));
+            aEvent.mnDelta = static_cast<tools::Long>(dY < 0 ? floor(dY) : 
ceil(dY));
             aEvent.mnNotchDelta = (dY < 0) ? -1 : +1;
             if( aEvent.mnDelta == 0 )
                 aEvent.mnDelta = aEvent.mnNotchDelta;

Reply via email to