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