on xenial help sign in
some launcher workarounds for the snapping
493e111Michael Zanetti
qml/Launcher/LauncherPanel.qml+28−14
@@ -145,19 +145,23 @@ Rectangle {
145 // destroyed when dragging them outside the list. This needs to be at least
145 // destroyed when dragging them outside the list. This needs to be at least
146 // itemHeight to prevent folded items from disappearing and DragArea limits
146 // itemHeight to prevent folded items from disappearing and DragArea limits
147 // need to be smaller than this size to avoid breakage.
147 // need to be smaller than this size to avoid breakage.
148− property int extensionSize: 0
148+ property int extensionSize: itemHeight * 3
149−
149+
150− // Setting extensionSize after the list has been populated because it has
150+ // Workaround: The snap settings in the launcher, will always try to
151− // the potential to mess up with the intial positioning in combination
151+ // snap to what we told it to do. However, we want the initial position
152− // with snapping to the center of the list. This catches all the cases
152+ // of the launcher to not be centered, but instead start with the topmost
153− // where the item would be outside the list for more than itemHeight / 2.
153+ // item unfolded completely. Lets wait for the ListView to settle after
154− // For the rest, give it a flick to scroll to the beginning. Note that
154+ // creation and then reposition it to 0.
155− // the flicking alone isn't enough because in some cases it's not strong
156− // enough to overcome the snapping.
157 // https://bugreports.qt-project.org/browse/QTBUG-32251
155 // https://bugreports.qt-project.org/browse/QTBUG-32251
158 Component.onCompleted: {
156 Component.onCompleted: {
159− extensionSize = itemHeight * 3
157+ initTimer.start();
160− flick(0, clickFlickSpeed)
158+ }
159+ Timer {
160+ id: initTimer
161+ interval: 1
162+ onTriggered: {
163+ launcherListView.moveToIndex(0)
164+ }
161 }
165 }
162
166
163 // The height of the area where icons start getting folded
167 // The height of the area where icons start getting folded
@@ -417,7 +421,18 @@ Rectangle {
417 property int startX
421 property int startX
418 property int startY
422 property int startY
419
423
424+ // This is a workaround for some issue in the QML ListView:
425+ // When calling moveToItem(0), the listview visually positions itself
426+ // correctly to display the first item expanded. However, some internal
427+ // state seems to not be valid, and the next time the user clicks on it,
428+ // it snaps back to the snap boundries before executing the onClicked handler.
429+ // This can cause the listview getting stuck in a snapped position where you can't
430+ // launch things without first dragging the launcher manually. So lets read the item
431+ // angle before that happens and use that angle instead of the one we get in onClicked.
432+ property real pressedStartAngle: 0
420 onPressed: {
433 onPressed: {
434+ var clickedItem = launcherListView.itemAt(mouseX, mouseY + launcherListView.realContentY)
435+ pressedStartAngle = clickedItem.angle;
421 processPress(mouse);
436 processPress(mouse);
422 }
437 }
423
438
@@ -444,9 +459,8 @@ Rectangle {
444
459
445 // First/last item do the scrolling at more than 12 degrees
460 // First/last item do the scrolling at more than 12 degrees
446 if (index == 0 || index == launcherListView.count - 1) {
461 if (index == 0 || index == launcherListView.count - 1) {
447− if (clickedItem.angle > 12 || clickedItem.angle < -12) {
448− launcherListView.moveToIndex(index);
462+ launcherListView.moveToIndex(index);
449− } else {
463+ if (pressedStartAngle <= 12 && pressedStartAngle >= -12) {
450 root.applicationSelected(LauncherModel.get(index).appId);
464 root.applicationSelected(LauncherModel.get(index).appId);
451 }
465 }
452 return;
466 return;