on xenial help sign in
merge removeForceActiveFocus branch
commitb334b790e73b8d0251105c6f84fee5e3a43329bd authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 17 Sep 2015, 14:25 (11 years ago) parent27132870237ea8
6 files changed+48−9
plugins/Utils/activefocuslogger.h−1 qml/Stages/DesktopSpread.qml+8−1 qml/Stages/DesktopStage.qml+14−3 tests/mocks/Unity/Application/MirSurfaceItem.cpp+15 tests/mocks/Unity/Application/MirSurfaceItem.h+3 tests/qmltests/Stages/tst_DesktopStage.qml+8−4
plugins/Utils/activefocuslogger.h−1
@@ -35,4 +35,3 @@ private:
3535};
3636
3737#endif // UNITY_ACTIVEFOCUSLOGGER_H
38−
qml/Stages/DesktopSpread.qml+8−1
@@ -12,8 +12,15 @@ FocusScope {
1212
1313 readonly property alias highlightedIndex: spreadRepeater.highlightedIndex
1414
15+ onFocusChanged: {
16+ // When the spread comes active, we want to keep focus to the input handler below
17+ // Make sure nothing inside the ApplicationWindow grabs our focus!
18+ if (focus) {
19+ forceActiveFocus();
20+ }
21+ }
22+
1523 Keys.onPressed: {
16− print("key pressed", event.key)
1724 switch (event.key) {
1825 case Qt.Key_Left:
1926 case Qt.Key_Backtab:
qml/Stages/DesktopStage.qml+14−3
@@ -70,7 +70,7 @@ Rectangle {
7070 var appIndex = priv.indexOf(appId);
7171 var appDelegate = appRepeater.itemAt(appIndex);
7272 appDelegate.minimized = false;
73− ApplicationManager.focusApplication(appId);
73+ appDelegate.focus = true;
7474 }
7575 }
7676
@@ -145,7 +145,18 @@ Rectangle {
145145 property bool maximized: false
146146 property bool minimized: false
147147
148− focus: priv.focusedAppId === model.appId && spread.state !== "altTab"
148+ onFocusChanged: {
149+ if (focus && ApplicationManager.focusedApplicationId !== model.appId) {
150+ ApplicationManager.focusApplication(model.appId);
151+ }
152+ }
153+
154+ Component.onCompleted: {
155+ // Focus the top-most or AppMan-focused application on start up.
156+ if (ApplicationManager.focusedApplicationId === model.appId && !focus) {
157+ focus = true;
158+ }
159+ }
149160
150161 Binding {
151162 target: ApplicationManager.get(index)
@@ -220,7 +231,7 @@ Rectangle {
220231 resizeHandleWidth: units.gu(2)
221232 windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
222233
223− onPressed: ApplicationManager.focusApplication(model.appId);
234+ onPressed: { appDelegate.focus = true; }
224235 }
225236
226237 DecoratedWindow {
tests/mocks/Unity/Application/MirSurfaceItem.cpp+15
@@ -161,6 +161,21 @@ void MirSurfaceItem::touchEvent(QTouchEvent * event)
161161 }
162162}
163163
164+void MirSurfaceItem::mousePressEvent(QMouseEvent * event)
165+{
166+ event->accept();
167+}
168+
169+void MirSurfaceItem::mouseMoveEvent(QMouseEvent * event)
170+{
171+ event->accept();
172+}
173+
174+void MirSurfaceItem::mouseReleaseEvent(QMouseEvent * event)
175+{
176+ event->accept();
177+}
178+
164179void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
165180{
166181 qDebug().nospace() << "MirSurfaceItem::setSurface() this=" << (void*)(this)
tests/mocks/Unity/Application/MirSurfaceItem.h+3
@@ -79,6 +79,9 @@ Q_SIGNALS:
7979
8080protected:
8181 void touchEvent(QTouchEvent * event) override;
82+ void mousePressEvent(QMouseEvent * event) override;
83+ void mouseMoveEvent(QMouseEvent * event) override;
84+ void mouseReleaseEvent(QMouseEvent * event) override;
8285 void itemChange(ItemChange change, const ItemChangeData & value) override;
8386
8487private Q_SLOTS:
tests/qmltests/Stages/tst_DesktopStage.qml+8−4
@@ -161,8 +161,8 @@ Item {
161161
162162 function test_tappingOnWindowChangesFocusedApp_data() {
163163 return [
164− {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
165− {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
164+ {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
165+ {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
166166 ]
167167 }
168168
@@ -171,16 +171,20 @@ Item {
171171 for (i = 0; i < data.apps.length; i++) {
172172 startApplication(data.apps[i]);
173173 }
174+ var fromAppId = data.apps[data.focusfrom];
175+ var toAppId = data.apps[data.focusTo]
174176
175− var fromAppWindow = findChild(desktopStage, "appWindow_" + data.apps[data.focusfrom]);
177+ var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
176178 verify(fromAppWindow);
177179 tap(fromAppWindow);
178180 compare(fromAppWindow.application.session.surface.activeFocus, true);
181+ compare(ApplicationManager.focusedApplicationId, fromAppId);
179182
180− var toAppWindow = findChild(desktopStage, "appWindow_" + data.apps[data.focusTo]);
183+ var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
181184 verify(toAppWindow);
182185 tap(toAppWindow);
183186 compare(toAppWindow.application.session.surface.activeFocus, true);
187+ compare(ApplicationManager.focusedApplicationId, toAppId);
184188 }
185189
186190 function test_tappingOnDecorationFocusesApplication_data() {