on xenial help sign in
Add a handle to the full-screen Drawer

To improve touch interaction, add a Handle (like on the indicators) to the Drawer. Reuse some of the code from the removed MouseArea to make its drag interaction work. Also, rename openDrawer() to toggleDrawer() because the second option describes its use better.

commita4366c2cca0e097af266a34da2e4ba5b8e98980d authorDalton Durst <d@ltondur.st> dateMon 15 Apr 2019, 14:05 (8 years ago) parent3ba1a71
6 files changed+71−27
qml/Panel/Handle.qml → qml/Components/Handle.qml+1 qml/Launcher/Drawer.qml+46−3 qml/Launcher/Launcher.qml+8−8 qml/Shell.qml+9−9 tests/qmltests/Launcher/tst_Drawer.qml+6−6 tests/qmltests/tst_Shell.qml+1−1
qml/Panel/Handle.qml → qml/Components/Handle.qmlrenamed+1
@@ -29,6 +29,7 @@ Rectangle {
2929 height: childrenRect.height
3030 anchors.centerIn: parent
3131 spacing: units.gu(0.5)
32+ rotation: (parent.width >= parent.height) ? 0 : 90
3233 Repeater {
3334 model: 3
3435 delegate: Rectangle {
qml/Launcher/Drawer.qml+46−3
@@ -32,7 +32,7 @@ FocusScope {
3232
3333 signal applicationSelected(string appId)
3434
35− property bool firstOpen: true
35+ property bool handleVisible: false
3636 property bool draggingHorizontally: false
3737 property int dragDistance: 0
3838
@@ -73,6 +73,44 @@ FocusScope {
7373 color: "#111111"
7474 opacity: 0.99
7575
76+ MouseArea {
77+ id: drawerHandle
78+ anchors {
79+ right: parent.right
80+ top: parent.top
81+ bottom: parent.bottom
82+ }
83+ width: root.handleVisible ? units.gu(2) : 0
84+ property int oldX: 0
85+
86+ onPressed: {
87+ handle.active = true;
88+ oldX = mouseX;
89+ }
90+ onMouseXChanged: {
91+ var diff = oldX - mouseX;
92+ root.draggingHorizontally |= diff > units.gu(2);
93+ if (!root.draggingHorizontally) {
94+ return;
95+ }
96+ root.dragDistance += diff;
97+ oldX = mouseX
98+ }
99+ onReleased: reset()
100+ onCanceled: reset()
101+
102+ function reset() {
103+ root.draggingHorizontally = false;
104+ handle.active = false;
105+ }
106+
107+ Handle {
108+ id: handle
109+ anchors.fill: parent
110+ active: parent.pressed
111+ }
112+ }
113+
76114 AppDrawerModel {
77115 id: appDrawerModel
78116 }
@@ -86,8 +124,13 @@ FocusScope {
86124
87125 Item {
88126 id: contentContainer
89− anchors.fill: parent
90− anchors.leftMargin: root.panelWidth
127+ anchors {
128+ left: parent.left
129+ right: drawerHandle.left
130+ top: parent.top
131+ bottom: parent.bottom
132+ leftMargin: root.panelWidth
133+ }
91134
92135 Item {
93136 id: searchFieldContainer
qml/Launcher/Launcher.qml+8−8
@@ -167,7 +167,7 @@ FocusScope {
167167 switchToNextState("visible")
168168 }
169169
170− function openDrawer(focusInputField) {
170+ function toggleDrawer(focusInputField, onlyOpen) {
171171 if (!drawerEnabled) {
172172 return;
173173 }
@@ -179,7 +179,7 @@ FocusScope {
179179 if (focusInputField) {
180180 drawer.focusInput();
181181 }
182− if (state === "drawer") {
182+ if (state === "drawer" && !onlyOpen) {
183183 switchToNextState("visible");
184184 } else {
185185 switchToNextState("drawer");
@@ -357,14 +357,14 @@ FocusScope {
357357 // See drawer.onDraggingHorizontallyChanged below
358358 drawer.searchTextField.focus = hadFocus;
359359 drawer.searchTextField.select(oldSelectionStart, oldSelectionEnd);
360− resetOldFocus();
361360 } else if (fullyClosed) {
362361 drawer.searchTextField.text = "";
363− resetOldFocus();
364362 }
363+ resetOldFocus();
365364 }
366365 }
367− width: Math.min(root.width, units.gu(90)) * .9
366+ width: Math.min(root.width, units.gu(81))
367+ handleVisible: (width < units.gu(81))
368368 panelWidth: panel.width
369369 visible: x > -width
370370 property var fullyOpen: x === 0
@@ -414,7 +414,7 @@ FocusScope {
414414 if (drawer.x < -units.gu(10)) {
415415 root.hide();
416416 } else {
417− root.openDrawer();
417+ root.toggleDrawer(false, true);
418418 }
419419 }
420420 }
@@ -497,7 +497,7 @@ FocusScope {
497497 }
498498 onPassed: {
499499 if (root.drawerEnabled) {
500− root.openDrawer()
500+ root.toggleDrawer()
501501 }
502502 }
503503
@@ -573,7 +573,7 @@ FocusScope {
573573 if (!dragging) {
574574 if (distance > panel.width / 2) {
575575 if (root.drawerEnabled && distance > panel.width * 3 && dragDirection() !== "left") {
576− root.openDrawer(false)
576+ root.toggleDrawer(false)
577577 } else {
578578 root.switchToNextState("visible");
579579 }
qml/Shell.qml+9−9
@@ -235,7 +235,7 @@ StyledItem {
235235 onHomeKeyActivated: {
236236 // Ignore when greeter is active, to avoid pocket presses
237237 if (!greeter.active) {
238− launcher.openDrawer(false);
238+ launcher.toggleDrawer(false);
239239 }
240240 }
241241 onTouchBegun: { cursor.opacity = 0; }
@@ -344,7 +344,7 @@ StyledItem {
344344 if (status !== TouchGestureArea.Recognized) {
345345 if (status === TouchGestureArea.WaitingForTouch) {
346346 if (wasPressed && !dragging) {
347− launcher.openDrawer(true);
347+ launcher.toggleDrawer(true);
348348 }
349349 }
350350 wasPressed = false;
@@ -375,7 +375,7 @@ StyledItem {
375375 onLoaded: {
376376 item.objectName = "greeter"
377377 }
378− property bool openDrawerAfterUnlock: false
378+ property bool toggleDrawerAfterUnlock: false
379379 Connections {
380380 target: greeter
381381 onActiveChanged: {
@@ -383,9 +383,9 @@ StyledItem {
383383 return
384384
385385 // Show drawer in case showHome() requests it
386− if (greeterLoader.openDrawerAfterUnlock) {
387− launcher.openDrawer(false);
388− greeterLoader.openDrawerAfterUnlock = false;
386+ if (greeterLoader.toggleDrawerAfterUnlock) {
387+ launcher.toggleDrawer(false);
388+ greeterLoader.toggleDrawerAfterUnlock = false;
389389 }
390390 // Show the launcher when there are no running apps
391391 else if (topLevelSurfaceList.count < 1) {
@@ -499,9 +499,9 @@ StyledItem {
499499 SessionBroadcast.requestHomeShown(AccountsService.user);
500500 } else {
501501 if (!greeter.active) {
502− launcher.openDrawer(false);
502+ launcher.toggleDrawer(false);
503503 } else {
504− greeterLoader.openDrawerAfterUnlock = true;
504+ greeterLoader.toggleDrawerAfterUnlock = true;
505505 }
506506 }
507507 }
@@ -609,7 +609,7 @@ StyledItem {
609609 GlobalShortcut {
610610 shortcut: Qt.MetaModifier | Qt.Key_A
611611 onTriggered: {
612− launcher.openDrawer(true);
612+ launcher.toggleDrawer(true);
613613 }
614614 }
615615 GlobalShortcut {
tests/qmltests/Launcher/tst_Drawer.qml+6−6
@@ -235,7 +235,7 @@ StyledItem {
235235 function test_search() {
236236 compare(launcher.lastSelectedApplication, "");
237237
238− launcher.openDrawer(true)
238+ launcher.toggleDrawer(true)
239239 typeString("cam");
240240 keyClick(Qt.Key_Enter);
241241
@@ -279,7 +279,7 @@ StyledItem {
279279 keyClick(Qt.Key_Escape);
280280 waitForRendering(launcher);
281281 waitUntilTransitionsEnd(launcher);
282− launcher.openDrawer(true);
282+ launcher.toggleDrawer(true);
283283 waitForRendering(launcher);
284284 waitUntilTransitionsEnd(launcher);
285285
@@ -290,7 +290,7 @@ StyledItem {
290290 }
291291
292292 function test_kbdNavigation() {
293− launcher.openDrawer(true);
293+ launcher.toggleDrawer(true);
294294 waitForRendering(launcher);
295295 waitUntilTransitionsEnd(launcher);
296296 compare(launcher.lastSelectedApplication, "");
@@ -331,7 +331,7 @@ StyledItem {
331331 // once https://codereview.qt-project.org/#/c/184942/ is accepted
332332 skip();
333333
334− launcher.openDrawer(true);
334+ launcher.toggleDrawer(true);
335335 waitForRendering(launcher);
336336 waitUntilTransitionsEnd(launcher);
337337
@@ -353,7 +353,7 @@ StyledItem {
353353 keyClick(Qt.Key_Down);
354354 tryCompare(panel, "highlightIndex", 0);
355355
356− launcher.openDrawer(true);
356+ launcher.toggleDrawer(true);
357357 tryCompare(searchField, "focus", true);
358358
359359 keyClick(Qt.Key_Escape);
@@ -365,7 +365,7 @@ StyledItem {
365365 }
366366
367367 function test_closeWhileDragging() {
368− launcher.openDrawer(true);
368+ launcher.toggleDrawer(true);
369369 waitForRendering(launcher);
370370 waitUntilTransitionsEnd(launcher);
371371
tests/qmltests/tst_Shell.qml+1−1
@@ -3130,7 +3130,7 @@ Rectangle {
31303130 if (data.lockLauncher) {
31313131 panel.applicationMenus.show();
31323132 tryCompare(panel.applicationMenus, "fullyOpened", true);
3133− launcher.openDrawer();
3133+ launcher.toggleDrawer();
31343134 } else {
31353135 tryCompare(launcher, "shown", false);
31363136 panel.applicationMenus.show();