on xenial help sign in
[Stage] handle "Application" level focus request

Application emits focusRequested when it has no surface (i.e. their processes died). Unity 8 used to handle this case. However, commit f1dcc66d18e1218ebfa46f205681048a4e71989f (Let the model deal with some window management decisions) removed the code. This commit makes the stage listens to each application's focusRequested signal. When received, it'll find the topmost window for the application and activate it, after which the app will be requested to be running. Fixes: https://github.com/ubports/ubuntu-touch/issues/1242

commitbe956d129c9ecd2f0eb139f8f4a1f11b21bc9e74 authorRatchanan Srirattanamet <ratchanan@ubports.com> dateMon 16 Dec 2019, 22:40 (7 years ago) parent41fc208
1 file changed+20
qml/Stage/Stage.qml+20
qml/Stage/Stage.qml+20
@@ -485,6 +485,26 @@ FocusScope {
485485 ? (!model.application.isTouchApp || isExemptFromLifecycle(model.application.appId))
486486 : false
487487 }
488+
489+ property var focusRequestedConnection: Connections {
490+ target: model.application
491+
492+ onFocusRequested: {
493+ // Application emits focusRequested when it has no surface (i.e. their processes died).
494+ // Find the topmost window for this application and activate it, after which the app
495+ // will be requested to be running.
496+
497+ for (var i = 0; i < appRepeater.count; i++) {
498+ var appDelegate = appRepeater.itemAt(i);
499+ if (appDelegate.application.appId === model.application.appId) {
500+ appDelegate.activate();
501+ return;
502+ }
503+ }
504+
505+ console.warn("Application requested te be focused but no window for it. What should we do?");
506+ }
507+ }
488508 }
489509 }
490510