@@ -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