@@ -20,6 +20,7 @@ import Ubuntu.Application 0.1
2020import Ubuntu.Components 0.1
2121import Ubuntu.Gestures 0.1
2222import LightDM 0.1 as LightDM
23+import Powerd 0.1
2324import "Dash"
2425import "Greeter"
2526import "Launcher"
@@ -428,9 +429,6 @@ FocusScope {
428429
429430 dragHandleWidth: shell.edgeSize
430431
431− property var previousMainApp: null
432− property var previousSideApp: null
433−
434432 onShownChanged: {
435433 if (shown) {
436434 lockscreen.reset();
@@ -440,20 +438,6 @@ FocusScope {
440438 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
441439 }
442440 greeter.forceActiveFocus();
443− // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
444− // the stage was actually shown
445− if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
446− if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
447− applicationManager.unfocusCurrentApplication();
448− } else {
449− if (greeter.previousMainApp) {
450− applicationManager.focusApplication(greeter.previousMainApp);
451− greeter.previousMainApp = null;
452− }
453− if (greeter.previousSideApp) {
454− applicationManager.focusApplication(greeter.previousSideApp);
455− greeter.previousSideApp = null;
456− }
457441 }
458442 }
459443
@@ -475,6 +459,41 @@ FocusScope {
475459 blockInput: greeter.shown || lockscreen.shown
476460 }
477461
462+ Connections {
463+ id: powerConnection
464+ target: Powerd
465+
466+ property var previousMainApp: null
467+ property var previousSideApp: null
468+
469+ function setFocused(focused) {
470+ if (!focused) {
471+ // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
472+ // the stage was actually shown
473+ if (mainStage.fullyShown) powerConnection.previousMainApp = applicationManager.mainStageFocusedApplication;
474+ if (sideStage.fullyShown) powerConnection.previousSideApp = applicationManager.sideStageFocusedApplication;
475+ applicationManager.unfocusCurrentApplication();
476+ } else {
477+ if (powerConnection.previousMainApp) {
478+ applicationManager.focusApplication(powerConnection.previousMainApp);
479+ powerConnection.previousMainApp = null;
480+ }
481+ if (powerConnection.previousSideApp) {
482+ applicationManager.focusApplication(powerConnection.previousSideApp);
483+ powerConnection.previousSideApp = null;
484+ }
485+ }
486+ }
487+
488+ onPowerStateChange: {
489+ if (state == 0) { // suspend
490+ powerConnection.setFocused(false);
491+ } else if (state == 1) { // active
492+ powerConnection.setFocused(true);
493+ }
494+ }
495+ }
496+
478497 Item {
479498 id: overlay
480499