summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Vogt <[email protected]>2017-03-14 22:19:09 +0100
committerFabian Vogt <[email protected]>2017-03-14 22:19:51 +0100
commit82a44a3f264cecc9982b3e0ed164aeb0b11ef18c (patch)
tree2dd86fc393f1226cdb30c8194604ffb2c926a154
parent40d42d55e3ab5a10ccec45dac6b0196f36a2a587 (diff)
Do not use fixed steps when scrolling on battery icon
Summary: This makes it possible to have some more fine-grained control over the screen brightness with scroll devices that support it, like touchpads or trackpoints. Test Plan: Tested with touchpad, trackpoint and scroll wheel on mouse Reviewers: #plasma, broulik Reviewed By: #plasma, broulik Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D5025
-rwxr-xr-xapplets/batterymonitor/package/contents/ui/batterymonitor.qml31
1 files changed, 8 insertions, 23 deletions
diff --git a/applets/batterymonitor/package/contents/ui/batterymonitor.qml b/applets/batterymonitor/package/contents/ui/batterymonitor.qml
index 1872cfc..ae6d591 100755
--- a/applets/batterymonitor/package/contents/ui/batterymonitor.qml
+++ b/applets/batterymonitor/package/contents/ui/batterymonitor.qml
@@ -144,29 +144,14 @@ Item {
onExited: wheelDelta = 0
onWheel: {
var delta = wheel.angleDelta.y || wheel.angleDelta.x
- if ((delta < 0 && wheelDelta > 0) || (delta > 0 && wheelDelta < 0)) { // reset when direction changes
- wheelDelta = 0
- }
- wheelDelta += delta;
- // magic number 120 for common "one click"
- // See: http://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
- var increment = 0;
- while (wheelDelta >= 120) {
- wheelDelta -= 120;
- increment++;
- }
- while (wheelDelta <= -120) {
- wheelDelta += 120;
- increment--;
- }
- if (increment != 0) {
- var maximumBrightness = batterymonitor.maximumScreenBrightness
- // Don't allow the UI to turn off the screen
- // Please see https://git.reviewboard.kde.org/r/122505/ for more information
- var minimumBrightness = (maximumBrightness > 100 ? 1 : 0)
- var steps = Math.max(1, Math.round(maximumBrightness / 20))
- batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, batterymonitor.screenBrightness + increment * steps));
- }
+
+ var maximumBrightness = batterymonitor.maximumScreenBrightness
+ // Don't allow the UI to turn off the screen
+ // Please see https://git.reviewboard.kde.org/r/122505/ for more information
+ var minimumBrightness = (maximumBrightness > 100 ? 1 : 0)
+ var steps = Math.max(1, Math.round(maximumBrightness / 20))
+ var deltaSteps = delta / 120;
+ batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, batterymonitor.screenBrightness + deltaSteps * steps));
}
}