on xenial help sign in
Hide the greeter when an app is focused, fixing snap decisions launching an app in the greeter (like receiving a call).

Approved by Michał Sawicz.

commitc9648b7a82dcdee8a73ceaa58f642504ba73d173 authorMichael Terry <michael.terry@canonical.com> dateThu 10 Oct 2013, 00:43 (13 years ago) parente4a75c6879cc16
3 files changed+52−65
Components/ApplicationManagerWrapper.qml−29 Shell.qml+46−34 tests/qmltests/tst_Shell.qml+6−2
Components/ApplicationManagerWrapper.qml−29
@@ -25,7 +25,6 @@ Item {
2525 property variant mainStageFocusedApplication: null
2626 property variant sideStageFocusedApplication: null
2727 property bool sideStageEnabled: true
28− signal focusRequested(string desktopFile)
2928 property bool keyboardVisible: ApplicationManager.keyboardVisible
3029 property int keyboardHeight: ApplicationManager.keyboardHeight
3130
@@ -155,32 +154,4 @@ Item {
155154 }
156155 return desktopFile.substring(left+1, right);
157156 }
158−
159− Connections {
160− target: ApplicationManager
161− onFocusRequested: {
162− // FIXME: hardcoded mapping from ApplicationManager.FavoriteApplications
163− // enum to desktop files
164− var desktopFile
165− if (favoriteApplication == ApplicationManager.CameraApplication) {
166− desktopFile = "/usr/share/applications/camera-app.desktop"
167− } else if (favoriteApplication == ApplicationManager.GalleryApplication) {
168− desktopFile = "/usr/share/applications/gallery-app.desktop"
169− } else if (favoriteApplication == ApplicationManager.ShareApplication) {
170− desktopFile = "/usr/share/applications/share-app.desktop"
171− } else if (favoriteApplication == ApplicationManager.BrowserApplication) {
172− desktopFile = "/usr/share/applications/webbrowser-app.desktop"
173− } else if (favoriteApplication == ApplicationManager.PhoneApplication) {
174− desktopFile = "/usr/share/applications/phone-app.desktop"
175− } else if (favoriteApplication == ApplicationManager.DialerApplication) {
176− desktopFile = "/usr/share/applications/dialer-app.desktop"
177− } else if (favoriteApplication == ApplicationManager.MessagingApplication) {
178− desktopFile = "/usr/share/applications/messaging-app.desktop"
179− } else if (favoriteApplication == ApplicationManager.AddressbookApplication) {
180− desktopFile = "/usr/share/applications/address-book-app.desktop"
181− }
182−
183− applicationManager.focusRequested(desktopFile);
184− }
185− }
186157}
Shell.qml+46−34
@@ -99,17 +99,6 @@ FocusScope {
9999 }
100100 }
101101
102− Connections {
103− target: applicationManager
104− ignoreUnknownSignals: true
105− onFocusRequested: {
106− // TODO: this should be protected to only unlock for certain applications / certain usecases
107− // potentially only in connection with a notification
108− greeter.hide();
109− shell.activateApplication(desktopFile);
110− }
111− }
112−
113102 function activateApplication(desktopFile, argument) {
114103 if (applicationManager) {
115104 // For newly started applications, as it takes them time to draw their first frame
@@ -468,6 +457,26 @@ FocusScope {
468457
469458 dragHandleWidth: shell.edgeSize
470459
460+ property var previousMainApp: null
461+ property var previousSideApp: null
462+
463+ function removeApplicationFocus() {
464+ greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
465+ greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
466+ applicationManager.unfocusCurrentApplication();
467+ }
468+
469+ function restoreApplicationFocus() {
470+ if (greeter.previousMainApp) {
471+ applicationManager.focusApplication(greeter.previousMainApp);
472+ greeter.previousMainApp = null;
473+ }
474+ if (greeter.previousSideApp) {
475+ applicationManager.focusApplication(greeter.previousSideApp);
476+ greeter.previousSideApp = null;
477+ }
478+ }
479+
471480 onShownChanged: {
472481 if (shown) {
473482 lockscreen.reset();
@@ -478,6 +487,9 @@ FocusScope {
478487 greeter.selected(0);
479488 }
480489 greeter.forceActiveFocus();
490+ removeApplicationFocus();
491+ } else {
492+ restoreApplicationFocus();
481493 }
482494 }
483495
@@ -494,6 +506,29 @@ FocusScope {
494506 launcher.tease();
495507 }
496508 }
509+
510+ Connections {
511+ target: applicationManager
512+ ignoreUnknownSignals: true
513+ // If any app is focused when greeter is open, it's due to a user action
514+ // like a snap decision (say, an incoming call).
515+ // TODO: these should be protected to only unlock for certain applications / certain usecases
516+ // potentially only in connection with a notification.
517+ onMainStageFocusedApplicationChanged: {
518+ if (greeter.shown && applicationManager.mainStageFocusedApplication) {
519+ greeter.previousMainApp = null // make way for new focused app
520+ greeter.previousSideApp = null
521+ greeter.hide()
522+ }
523+ }
524+ onSideStageFocusedApplicationChanged: {
525+ if (greeter.shown && applicationManager.sideStageFocusedApplication) {
526+ greeter.previousMainApp = null // make way for new focused app
527+ greeter.previousSideApp = null
528+ greeter.hide()
529+ }
530+ }
531+ }
497532 }
498533
499534 InputFilterArea {
@@ -506,34 +541,11 @@ FocusScope {
506541 id: powerConnection
507542 target: Powerd
508543
509− property var previousMainApp: null
510− property var previousSideApp: null
511−
512− function setFocused(focused) {
513− if (!focused) {
514− powerConnection.previousMainApp = applicationManager.mainStageFocusedApplication;
515− powerConnection.previousSideApp = applicationManager.sideStageFocusedApplication;
516− applicationManager.unfocusCurrentApplication();
517− } else {
518− if (powerConnection.previousMainApp) {
519− applicationManager.focusApplication(powerConnection.previousMainApp);
520− powerConnection.previousMainApp = null;
521− }
522− if (powerConnection.previousSideApp) {
523− applicationManager.focusApplication(powerConnection.previousSideApp);
524− powerConnection.previousSideApp = null;
525− }
526− }
527− }
528−
529544 onDisplayPowerStateChange: {
530545 // We ignore any display-off signals when the proximity sensor
531546 // is active. This usually indicates something like a phone call.
532547 if (status == Powerd.Off && (flags & Powerd.UseProximity) == 0) {
533− powerConnection.setFocused(false);
534548 greeter.showNow();
535− } else if (status == Powerd.On) {
536− powerConnection.setFocused(true);
537549 }
538550
539551 // No reason to chew demo CPU when user isn't watching
tests/qmltests/tst_Shell.qml+6−2
@@ -157,7 +157,7 @@ Item {
157157 waitUntilApplicationWindowIsFullyVisible();
158158
159159 var mainApp = ApplicationManager.focusedApplicationId;
160− tryCompareFunction(function() { return mainApp != ""; }, true);
160+ verify(mainApp != "");
161161
162162 // Try to suspend while proximity is engaged...
163163 Powerd.displayPowerStateChange(Powerd.Off, Powerd.UseProximity);
@@ -170,8 +170,12 @@ Item {
170170
171171 // And wake up
172172 Powerd.displayPowerStateChange(Powerd.On, 0);
173− tryCompare(ApplicationManager, "focusedApplicationId", mainApp);
173+ tryCompare(ApplicationManager, "focusedApplicationId", "");
174174 tryCompare(greeter, "showProgress", 1);
175+
176+ // Swipe away greeter to focus app
177+ swipeAwayGreeter();
178+ tryCompare(ApplicationManager, "focusedApplicationId", mainApp);
175179 }
176180
177181 function swipeAwayGreeter() {