on xenial help sign in
Further clean up and refactor focus handling in DesktopStage

+ Turn ActiveFocusLogger into a QML item so it can be easily added and removed

commit966b9e633d7e720a8733f22d3b5a2ff1e3791734 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 17 Aug 2015, 16:32 (11 years ago) parent96eb52d
9 files changed+14−114
plugins/Utils/CMakeLists.txt+1 plugins/Utils/plugin.cpp+2 qml/Stages/DesktopStage.qml+8−15 tests/mocks/Utils/CMakeLists.txt+1 tests/mocks/Utils/plugin.cpp+2 tests/uqmlscene/ActiveFocusLogger.cpp−48 tests/uqmlscene/ActiveFocusLogger.h−37 tests/uqmlscene/CMakeLists.txt−1 tests/uqmlscene/main.cpp−13
plugins/Utils/CMakeLists.txt+1
@@ -9,6 +9,7 @@ include_directories(
99)
1010
1111set(QMLPLUGIN_SRC
12+ activefocuslogger.cpp
1213 constants.cpp
1314 HomeKeyWatcher.cpp
1415 inputwatcher.cpp
plugins/Utils/plugin.cpp+2
@@ -23,6 +23,7 @@
2323#include "plugin.h"
2424
2525// local
26+#include "activefocuslogger.h"
2627#include "easingcurve.h"
2728#include "HomeKeyWatcher.h"
2829#include "inputwatcher.h"
@@ -66,6 +67,7 @@ void UtilsPlugin::registerTypes(const char *uri)
6667 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
6768 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
6869 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
70+ qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
6971}
7072
7173void UtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
qml/Stages/DesktopStage.qml+8−15
@@ -77,7 +77,6 @@ Rectangle {
7777 var appIndex = priv.indexOf(appId);
7878 var appDelegate = appRepeater.itemAt(appIndex);
7979 appDelegate.minimized = false;
80− appDelegate.focus = true;
8180 ApplicationManager.focusApplication(appId);
8281 }
8382 }
@@ -91,12 +90,6 @@ Rectangle {
9190 return index >= 0 && index < appRepeater.count ? appRepeater.itemAt(index) : null
9291 }
9392
94− onFocusedAppDelegateChanged: {
95− if (focusedAppDelegate) {
96− focusedAppDelegate.focus = true;
97− }
98− }
99−
10093 function indexOf(appId) {
10194 for (var i = 0; i < ApplicationManager.count; i++) {
10295 if (ApplicationManager.get(i).appId == appId) {
@@ -140,17 +133,21 @@ Rectangle {
140133 case Qt.Key_Left:
141134 case Qt.Key_Backtab:
142135 selectPrevious(event.isAutoRepeat)
136+ event.accepted = true;
143137 break;
144138 case Qt.Key_Right:
145139 case Qt.Key_Tab:
146140 selectNext(event.isAutoRepeat)
141+ event.accepted = true;
147142 break;
148143 case Qt.Key_Escape:
149144 appRepeater.highlightedIndex = -1
145+ event.accepted = true;
150146 case Qt.Key_Enter:
151147 case Qt.Key_Return:
152148 case Qt.Key_Space:
153149 root.state = ""
150+ event.accepted = true;
154151 }
155152 }
156153
@@ -181,7 +178,8 @@ Rectangle {
181178
182179 function focusSelected() {
183180 if (appRepeater.highlightedIndex != -1) {
184− appRepeater.itemAt(appRepeater.highlightedIndex).focus = true;
181+ var application = ApplicationManager.get(appRepeater.highlightedIndex);
182+ ApplicationManager.focusApplication(application.appId);
185183 }
186184 }
187185
@@ -206,11 +204,7 @@ Rectangle {
206204 property bool maximized: false
207205 property bool minimized: false
208206
209− onFocusChanged: {
210− if (focus && ApplicationManager.focusedApplicationId !== model.appId) {
211− ApplicationManager.requestFocusApplication(model.appId);
212− }
213− }
207+ focus: priv.focusedAppId === model.appId && root.state !== "altTab"
214208
215209 Binding {
216210 target: ApplicationManager.get(index)
@@ -321,7 +315,7 @@ Rectangle {
321315 resizeHandleWidth: units.gu(2)
322316 windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
323317
324− onPressed: appDelegate.focus = true;
318+ onPressed: ApplicationManager.focusApplication(model.appId);
325319 }
326320
327321 DecoratedWindow {
@@ -577,7 +571,6 @@ Rectangle {
577571 PropertyChanges { target: spreadFlickable; enabled: true }
578572 PropertyChanges { target: currentSelectedLabel; visible: true }
579573 PropertyChanges { target: spreadBackground; visible: true }
580− PropertyChanges { target: appContainer; focus: true }
581574 }
582575 ]
583576 signal updateWorkspaces();
tests/mocks/Utils/CMakeLists.txt+1
@@ -10,6 +10,7 @@ include_directories(
1010)
1111
1212set(QMLPLUGIN_SRC
13+ ${CMAKE_SOURCE_DIR}/plugins/Utils/activefocuslogger.cpp
1314 ${CMAKE_SOURCE_DIR}/plugins/Utils/qlimitproxymodelqml.cpp
1415 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
1516 ${CMAKE_SOURCE_DIR}/plugins/Utils/relativetimeformatter.cpp
tests/mocks/Utils/plugin.cpp+2
@@ -35,6 +35,7 @@
3535#include "constants.h"
3636
3737// plugin
38+#include <activefocuslogger.h>
3839#include <inputwatcher.h>
3940#include <qlimitproxymodelqml.h>
4041#include <unitysortfilterproxymodelqml.h>
@@ -74,6 +75,7 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
7475 qmlRegisterSingletonType<WindowStateStorage>(uri, 0, 1, "WindowStateStorage", createWindowStateStorage);
7576 qmlRegisterType<InputWatcher>(uri, 0, 1, "InputWatcher");
7677 qmlRegisterSingletonType<Constants>(uri, 0, 1, "Constants", createConstants);
78+ qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
7779}
7880
7981void FakeUtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
tests/uqmlscene/ActiveFocusLogger.cppdeleted−48
@@ -1,48 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "ActiveFocusLogger.h"
18−
19−#include <QDebug>
20−#include <QQuickItem>
21−
22−void ActiveFocusLogger::setWindow(QQuickWindow *window)
23−{
24− m_window = window;
25− QObject::connect(window, &QQuickWindow::activeFocusItemChanged,
26− this, &ActiveFocusLogger::printActiveFocusInfo);
27−}
28−
29−void ActiveFocusLogger::printActiveFocusInfo()
30−{
31− if (!m_window) {
32− return;
33− }
34−
35− qDebug() << "============== Active focus info START ================";
36− if (m_window->activeFocusItem()) {
37− qDebug() << m_window->activeFocusItem();
38− qDebug() << "Ancestry:";
39− QQuickItem *item = m_window->activeFocusItem()->parentItem();
40− while (item != nullptr) {
41− qDebug() << item << ", isFocusScope =" << item->isFocusScope();
42− item = item->parentItem();
43− }
44− } else {
45− qDebug() << "NULL";
46− }
47− qDebug() << "============== Active focus info END ================";
48−}
tests/uqmlscene/ActiveFocusLogger.hdeleted−37
@@ -1,37 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef ACTIVE_FOCUS_LOGGER_H
18−#define ACTIVE_FOCUS_LOGGER_H
19−
20−#include <QObject>
21−#include <QQuickWindow>
22−#include <QPointer>
23−
24−class ActiveFocusLogger : public QObject {
25− Q_OBJECT
26−
27−public:
28− void setWindow(QQuickWindow *window);
29−
30−private Q_SLOTS:
31− void printActiveFocusInfo();
32−
33−private:
34− QPointer<QQuickWindow> m_window;
35−};
36−
37−#endif // ACTIVE_FOCUS_LOGGER_H
tests/uqmlscene/CMakeLists.txt−1
@@ -1,6 +1,5 @@
11add_executable(uqmlscene
22 ${shellapplication_MOC_SRCS}
3− ActiveFocusLogger.cpp
43 main.cpp
54 )
65
tests/uqmlscene/main.cpp−13
@@ -63,12 +63,6 @@
6363#include <QtCore/QTranslator>
6464#include <QtCore/QLibraryInfo>
6565
66−#define UQMLSCENE_DEBUG_ACTIVE_FOCUS 0
67−
68−#if UQMLSCENE_DEBUG_ACTIVE_FOCUS
69− #include "ActiveFocusLogger.h"
70−#endif
71−
7266#ifdef QML_RUNTIME_TESTING
7367class RenderStatistics
7468{
@@ -393,10 +387,6 @@ int main(int argc, char ** argv)
393387{
394388 Options options;
395389
396− #if UQMLSCENE_DEBUG_ACTIVE_FOCUS
397− ActiveFocusLogger activeFocusLogger;
398− #endif
399−
400390 QStringList imports;
401391 QList<QPair<QString, QString> > bundles;
402392 for (int i = 1; i < argc; ++i) {
@@ -515,9 +505,6 @@ int main(int argc, char ** argv)
515505 QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
516506 if (contentItem) {
517507 qxView = new QQuickView(&engine, nullptr);
518− #if UQMLSCENE_DEBUG_ACTIVE_FOCUS
519− activeFocusLogger.setWindow(qxView);
520− #endif
521508 window = qxView;
522509 // Set window default properties; the qml can still override them
523510 QString oname = contentItem->objectName();