-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Better support for smooth scrolling trackpads and mice #7941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
allejok96
wants to merge
14
commits into
LMMS:master
Choose a base branch
from
allejok96:hiResScroll2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+468
−233
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9a3e173
Better support for smooth scrolling trackpads and mice
allejok96 5584cc4
Remove unused declaration
allejok96 be49b65
Swap orientation with Shift/Alt. Adjust scroll speeds.
allejok96 1a07647
Fix Fader scroll. Rename getDelta to getAngleDelta.
allejok96 9a0076f
Merge branch 'master' of https://github.com/LMMS/lmms into hiResScroll2
allejok96 e84f393
Clarify double subtraction
allejok96 c23dc6f
Common PIXELS_PER_STEP
allejok96 2649063
Namespace lmms::gui
allejok96 be98b5a
Don't propagate horizontal scroll on knobs and faders
allejok96 19ef197
Horizontal scroll on knobs for finer adjustments
allejok96 e73e56f
macOS swaps scroll orientation with Alt too
allejok96 1fd8c5d
Merge branch 'master' of https://github.com/LMMS/lmms into hiResScroll2
allejok96 8d20f33
Merge branch 'master' of https://github.com/LMMS/lmms into hiResScroll2
allejok96 74981d9
Fix merge issues
allejok96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* | ||
| * Scroll.h - calculate scroll distance | ||
| * | ||
| * Copyright (c) 2025 Alex <allejok96/gmail> | ||
| * | ||
| * This file is part of LMMS - https://lmms.io | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public | ||
| * License along with this program (see COPYING); if not, write to the | ||
| * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| * Boston, MA 02110-1301 USA. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef SCROLL_H | ||
| #define SCROLL_H | ||
|
|
||
| #include "Flags.h" | ||
| #include "lmms_export.h" | ||
|
|
||
|
|
||
| class QWheelEvent; | ||
|
|
||
|
|
||
| namespace lmms::gui { | ||
|
|
||
|
|
||
| class LMMS_EXPORT Scroll | ||
| { | ||
| public: | ||
| //! QWheelEvent->angleDelta() that corresponds to a "wheel tick" | ||
| static constexpr float ANGLE_DELTA_PER_TICK = 120; | ||
| //! Default scroll speed for various editors | ||
| static constexpr int PIXELS_PER_STEP = 36; | ||
|
|
||
| enum class Flag { | ||
| NoFlag = 0x0, | ||
| Horizontal = 0x1, | ||
| //! Change any natural (inverted) scroll to regular scroll. | ||
| //! This is useful for widgets like faders, where you want up to be up. | ||
| //! Some operating systems does not support this. | ||
| DisableNaturalScrolling = 0x2, | ||
| //! Swap x/y scroll orientation when pressing Shift. | ||
| //! On Windows and Linux this flag will also let you use Alt to swap, | ||
| //! because that is the default behavior of Qt on those platforms, | ||
| //! so it will match QScrollBar and other built-in widgets. | ||
| SwapWithShiftOrAlt = 0x4, | ||
| }; | ||
|
|
||
| using Flags = lmms::Flags<Flag>; | ||
|
|
||
|
|
||
| /*! \brief Scroll delta | ||
| * | ||
| * This class measures scroll delta in "wheel ticks", | ||
| * unlike QWheelEvent which measures scroll delta in 1/8ths of a degree. | ||
| */ | ||
| Scroll(QWheelEvent* event); | ||
|
|
||
|
|
||
| /*! \brief Return number of completely scrolled steps of some size | ||
| * | ||
| * The return value is positive when the wheel is rotated away from the hand. | ||
| * | ||
| * `stepsPerWheelTick` is the number of steps to count for every wheel tick. | ||
| * If set to 5 it will count a step whenever the wheel has moved 1/5 of a tick. | ||
| * It will always cound at least one step per wheel tick. | ||
| * | ||
| * -------------------------------------------------------------------------- | ||
| * | ||
| * You should always use this function instead of the following: | ||
| * int steps = wheelEvent->angleDelta().y() / some_value | ||
| * | ||
| * This is because some trackpads and mice report much smaller chunks of angleDelta | ||
| * than the standard 120 (which is a "wheel tick"). In the worst case scenario | ||
| * the result will always be rounded down to 0. This function solves it by accumulating | ||
| * the angleDelta until a complete step is reached. | ||
| * | ||
| * Note: don't call this function if you intend to ignore() the event, as it | ||
| * may result in double-counting scroll delta. | ||
| */ | ||
| int getSteps(const float stepsPerWheelTick = 1.0, const Flags flags = Flag::NoFlag); | ||
|
|
||
| inline int getSteps(const Flags flags) | ||
| { | ||
| return getSteps(1.0, flags); | ||
| } | ||
|
|
||
|
|
||
| /*! \brief Return number of scrolled "wheel ticks" | ||
| * | ||
| * The value is positive when the wheel is rotated away from the hand. | ||
| * | ||
| * If you intend to use this in a calculation where the end result is an integer, | ||
| * you should probably use getSteps() instead to avoid rounding issues with | ||
| * smooth scrolling trackpads and mice. | ||
| */ | ||
| inline float getStepsFloat(const Flags flags) | ||
| { | ||
| return getAngleDelta(flags) / ANGLE_DELTA_PER_TICK; | ||
| } | ||
|
|
||
| //! \brief True when scrolling vertically | ||
| bool isVertical(); | ||
|
|
||
| //! \brief True when scrolling horizontally | ||
| bool isHorizontal(); | ||
|
|
||
| private: | ||
| int getAngleDelta(const Flags flags = Flag::NoFlag); | ||
| int calculateSteps(const int angleDelta, const float stepsPerTick, const bool horizontal); | ||
|
|
||
| QWheelEvent* m_event; | ||
|
|
||
| // These are used by calculateSteps() to accumulate partially scrolled steps | ||
| // They are shared across all widgets but that doesn't notisable affect the user experience | ||
| static float s_partialStepX; | ||
| static float s_partialStepY; | ||
|
|
||
| const float m_initialPartialStepX; | ||
| const float m_initialPartialStepY; | ||
| }; | ||
|
|
||
| LMMS_DECLARE_OPERATORS_FOR_FLAGS(Scroll::Flag) | ||
|
|
||
|
|
||
| } // namespace lmms::gui | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
scroll.getSteps()returns an int I don't think we need to round to the nearest multiple ofCOMP_GRID_SPACINGbecause the new value will always be a multiple ofCOMP_GRID_SPACING.