From 7304cf9e0742fe112d8bf654fa5cd479523ea07a Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 11 Mar 2010 10:23:22 +0100 Subject: Mac: scroll speed does not match native applications It turns out that we limit wheel scrolling on mac to an upper limit per event to one page. This behaviour is a bit strange in the first place, and on mac, it is just wrong. Besides, even when this limitation is removed, we still scroll a bit slower that native. The 'problem' is to come up with a good conversion from pixel scrolling to line based scrolling (Qt does not really have an API for pixel scrolling). But we up the speed a bit to make it perform more similar to xcode. Rev-by: msorvig --- src/gui/kernel/qapplication_mac.mm | 9 +++++++-- src/gui/kernel/qcocoaview_mac.mm | 13 +++++++------ src/gui/widgets/qabstractslider.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index c7d0e48..28072fc 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1759,14 +1759,19 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event // (actually two events; one for horizontal and one for vertical). // As a results of this, and to make sure we dont't receive duplicate events, // we try to detect when this happend by checking the 'compatibilityEvent'. + // Since delta is delivered as pixels rather than degrees, we need to + // convert from pixels to degrees in a sensible manner. + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; SInt32 mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaX = mdelt; + wheel_deltaX = mdelt * pixelsToDegrees; mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaY = mdelt; + wheel_deltaY = mdelt * pixelsToDegrees; GetEventParameter(event, kEventParamEventRef, typeEventRef, 0, sizeof(compatibilityEvent), 0, &compatibilityEvent); } else if (ekind == kEventMouseWheelMoved) { diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index f7cb21f..4f71681 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -480,7 +480,7 @@ static int qCocoaViewCount = 0; return; if (QApplicationPrivate::graphicsSystem() != 0) { - if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) { + if (qwidgetprivate->maybeBackingStore()) { // Drawing is handled on the window level // See qcocoasharedwindowmethods_mac_p.h if (!qwidget->testAttribute(Qt::WA_PaintOnScreen)) @@ -819,11 +819,12 @@ static int qCocoaViewCount = 0; // The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad). // Since deviceDelta is delivered as pixels rather than degrees, we need to // convert from pixels to degrees in a sensible manner. - // It looks like four degrees per pixel behaves most native. - // Qt expects the unit for delta to be 1/8 of a degree: - deltaX = [theEvent deviceDeltaX]; - deltaY = [theEvent deviceDeltaY]; - deltaZ = [theEvent deviceDeltaZ]; + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; // 8 * 1/4 + deltaX = [theEvent deviceDeltaX] * pixelsToDegrees; + deltaY = [theEvent deviceDeltaY] * pixelsToDegrees; + deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees; } else { // carbonEventKind == kEventMouseWheelMoved // Remove acceleration, and use either -120 or 120 as delta: diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 2888490..522d472 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -712,7 +712,15 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb offset_accumulated = 0; offset_accumulated += stepsToScrollF; +#ifndef Q_WS_MAC + // Dont't scroll more than one page in any case: stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); +#else + // Native UI-elements on Mac can scroll hundreds of lines at a time as + // a result of acceleration. So keep the same behaviour in Qt, and + // dont restrict stepsToScroll to certain maximum (pageStep): + stepsToScroll = int(offset_accumulated); +#endif offset_accumulated -= int(offset_accumulated); if (stepsToScroll == 0) return false; -- cgit v0.12