on xenial help sign in
Application-level focus requests
commit62ef20c11c3e9173e5c18779e26b0c71e7330435 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 4 Apr 2016, 10:42 (11 years ago) parentb8e8b25
6 files changed+55−18
qml/Stages/DesktopStage.qml+16−3 qml/Stages/PhoneStage.qml+16−3 qml/Stages/TabletStage.qml+12 tests/mocks/Unity/Application/ApplicationInfo.cpp+9−3 tests/mocks/Unity/Application/ApplicationInfo.h+1−4 tests/mocks/Unity/Application/ApplicationManager.cpp+1−5
qml/Stages/DesktopStage.qml+16−3
@@ -284,13 +284,26 @@ AbstractStage {
284284
285285 readonly property var surface: model.surface
286286
287+ function claimFocus() {
288+ if (spread.state == "altTab") {
289+ spread.cancel();
290+ }
291+ appDelegate.restore();
292+ }
287293 Connections {
288294 target: model.surface
295+ onFocusRequested: claimFocus();
296+ }
297+ Connections {
298+ target: model.application
289299 onFocusRequested: {
290− if (spread.state == "altTab") {
291− spread.cancel();
300+ if (!model.surface) {
301+ // when an app has no surfaces, we assume there's only one entry representing it,
302+ // this delegate.
303+ claimFocus();
304+ } else {
305+ // if the application has surfaces, focus request should be at surface-level.
292306 }
293− appDelegate.restore();
294307 }
295308 }
296309
qml/Stages/PhoneStage.qml+16−3
@@ -531,13 +531,26 @@ AbstractStage {
531531 }
532532 }
533533 }
534+ function claimFocus() {
535+ if (spreadView.phase > 0) {
536+ spreadView.snapTo(model.index);
537+ } else {
538+ appDelegate.focus = true;
539+ }
540+ }
534541 Connections {
535542 target: model.surface
543+ onFocusRequested: claimFocus()
544+ }
545+ Connections {
546+ target: model.application
536547 onFocusRequested: {
537− if (spreadView.phase > 0) {
538− spreadView.snapTo(model.index);
548+ if (!model.surface) {
549+ // when an app has no surfaces, we assume there's only one entry representing it,
550+ // this delegate.
551+ claimFocus();
539552 } else {
540− appDelegate.focus = true;
553+ // if the application has surfaces, focus request should be at surface-level.
541554 }
542555 }
543556 }
qml/Stages/TabletStage.qml+12
@@ -766,6 +766,18 @@ AbstractStage {
766766 target: model.surface
767767 onFocusRequested: spreadTile.focus = true;
768768 }
769+ Connections {
770+ target: model.application
771+ onFocusRequested: {
772+ if (!model.surface) {
773+ // when an app has no surfaces, we assume there's only one entry representing it,
774+ // this delegate.
775+ spreadTile.focus = true;
776+ } else {
777+ // if the application has surfaces, focus request should be at surface-level.
778+ }
779+ }
780+ }
769781
770782 fullscreen: {
771783 if (priv.mainStageDelegate && stage === ApplicationInfoInterface.SideStage) {
tests/mocks/Unity/Application/ApplicationInfo.cpp+9−3
@@ -108,9 +108,6 @@ void ApplicationInfo::createSurface()
108108 m_closingSurfaces.removeAll(surface);
109109 }
110110 });
111− connect(surface, &MirSurface::focusRequested, this, [this](){
112− Q_EMIT this->focusRequested();
113− });
114111 connect(surface, &MirSurface::closeRequested, this, [this, surface](){
115112 m_closingSurfaces.append(surface);
116113 if (m_state == Suspended) {
@@ -367,3 +364,12 @@ void ApplicationInfo::onSurfaceCountChanged()
367364 setState(Stopped);
368365 }
369366}
367+
368+void ApplicationInfo::requestFocus()
369+{
370+ if (m_surfaceList.count() == 0) {
371+ Q_EMIT focusRequested();
372+ } else {
373+ m_surfaceList.get(0)->requestFocus();
374+ }
375+}
tests/mocks/Unity/Application/ApplicationInfo.h+1−4
@@ -112,16 +112,13 @@ public:
112112 //////
113113 // internal mock stuff
114114 void close();
115+ void requestFocus();
115116
116117Q_SIGNALS:
117118 void fullscreenChanged(bool value);
118119 void manualSurfaceCreationChanged(bool value);
119120 void closed();
120121
121− ////
122− // FIXME: Move to unity::shell::application::ApplicationInfoInterface
123− void focusRequested();
124−
125122public Q_SLOTS:
126123 Q_INVOKABLE void createSurface();
127124
tests/mocks/Unity/Application/ApplicationManager.cpp+1−5
@@ -302,11 +302,7 @@ bool ApplicationManager::requestFocusApplication(const QString &appId)
302302 if (application == nullptr)
303303 return false;
304304
305− auto surfaceList = static_cast<MirSurfaceListModel*>(application->surfaceList());
306− if (surfaceList->count() == 0)
307− return false;
308−
309− surfaceList->get(0)->requestFocus();
305+ application->requestFocus();
310306
311307 return true;
312308}