on xenial help sign in
Cursor: Let AnimatedSprite run only on animated cursors and while the display is on

That awesome component would keep running even on single-frame animations (ie, on non-animated cursors) triggering redraws or otherwise keeping CPU busy for nothing. Also optimize things by using a regular and bug-free Image component to display non-animated (single-frame) cursors. A second optimization is to only load the cursor image at all if the device has a mouse or touchpad.

commit533b0fc749d3550d1555841cc3da28898486a052 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 15 Jun 2016, 17:33 (10 years ago) parent7fdbae9
1 file changed+26−11
plugins/Cursor/Cursor.qml+26−11
plugins/Cursor/Cursor.qml+26−11
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.4
1818import Cursor 1.1
19+import Powerd 0.1
1920
2021MousePointer {
2122 id: mousePointer
@@ -26,19 +27,33 @@ MousePointer {
2627 cursorName: mousePointer.cursorName
2728 }
2829
29− AnimatedSprite {
30− x: -imageInfo.hotspot.x
31− y: -imageInfo.hotspot.y
32− source: "image://cursor/" + mousePointer.themeName + "/" + mousePointer.cursorName
30+ Loader {
31+ active: mousePointer.visible && imageInfo.frameCount > 1
32+ sourceComponent: AnimatedSprite {
33+ x: -imageInfo.hotspot.x
34+ y: -imageInfo.hotspot.y
35+ source: "image://cursor/" + mousePointer.themeName + "/" + mousePointer.cursorName
3336
34− interpolate: false
37+ interpolate: false
3538
36− width: imageInfo.frameWidth
37− height: imageInfo.frameHeight
39+ width: imageInfo.frameWidth
40+ height: imageInfo.frameHeight
3841
39− frameCount: imageInfo.frameCount
40− frameDuration: imageInfo.frameDuration
41− frameWidth: imageInfo.frameWidth
42− frameHeight: imageInfo.frameHeight
42+ frameCount: imageInfo.frameCount
43+ frameDuration: imageInfo.frameDuration
44+ frameWidth: imageInfo.frameWidth
45+ frameHeight: imageInfo.frameHeight
46+
47+ running: Powerd.status === Powerd.On
48+ }
49+ }
50+
51+ Loader {
52+ active: mousePointer.visible && imageInfo.frameCount === 1
53+ sourceComponent: Image {
54+ x: -imageInfo.hotspot.x
55+ y: -imageInfo.hotspot.y
56+ source: "image://cursor/" + mousePointer.themeName + "/" + mousePointer.cursorName
57+ }
4358 }
4459}