@@ -19,6 +19,7 @@ import Ubuntu.Application 0.1
1919import Ubuntu.Components 0.1
2020import Ubuntu.Gestures 0.1
2121import LightDM 0.1 as LightDM
22+import Power 0.1
2223import "Dash"
2324import "Greeter"
2425import "Launcher"
@@ -420,9 +421,6 @@ FocusScope {
420421
421422 dragHandleWidth: shell.edgeSize
422423
423− property var previousMainApp: null
424− property var previousSideApp: null
425−
426424 onShownChanged: {
427425 if (shown) {
428426 lockscreen.reset();
@@ -432,20 +430,6 @@ FocusScope {
432430 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
433431 }
434432 greeter.forceActiveFocus();
435− // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
436− // the stage was actually shown
437− if (mainStage.fullyShown) greeter.previousMainApp = applicationManager.mainStageFocusedApplication;
438− if (sideStage.fullyShown) greeter.previousSideApp = applicationManager.sideStageFocusedApplication;
439− applicationManager.unfocusCurrentApplication();
440− } else {
441− if (greeter.previousMainApp) {
442− applicationManager.focusApplication(greeter.previousMainApp);
443− greeter.previousMainApp = null;
444− }
445− if (greeter.previousSideApp) {
446− applicationManager.focusApplication(greeter.previousSideApp);
447− greeter.previousSideApp = null;
448− }
449433 }
450434 }
451435
@@ -467,6 +451,41 @@ FocusScope {
467451 blockInput: greeter.shown || lockscreen.shown
468452 }
469453
454+ Connections {
455+ id: powerConnection
456+ target: Power
457+
458+ property var previousMainApp: null
459+ property var previousSideApp: null
460+
461+ function setFocused(focused) {
462+ if (!focused) {
463+ // FIXME: *FocusedApplication are not updated when unfocused, hence the need to check whether
464+ // the stage was actually shown
465+ if (mainStage.fullyShown) powerConnection.previousMainApp = applicationManager.mainStageFocusedApplication;
466+ if (sideStage.fullyShown) powerConnection.previousSideApp = applicationManager.sideStageFocusedApplication;
467+ applicationManager.unfocusCurrentApplication();
468+ } else {
469+ if (powerConnection.previousMainApp) {
470+ applicationManager.focusApplication(powerConnection.previousMainApp);
471+ powerConnection.previousMainApp = null;
472+ }
473+ if (powerConnection.previousSideApp) {
474+ applicationManager.focusApplication(powerConnection.previousSideApp);
475+ powerConnection.previousSideApp = null;
476+ }
477+ }
478+ }
479+
480+ onPowerStateChange: {
481+ if (state == 0) { // suspend
482+ powerConnection.setFocused(false);
483+ } else if (state == 1) { // active
484+ powerConnection.setFocused(true);
485+ }
486+ }
487+ }
488+
470489 Item {
471490 id: overlay
472491