Merge lp:~gerboland/miral/qt-bump-to-qtmir-529 into lp:miral

Proposed by Gerry Boland
Status: Merged
Approved by: Alan Griffiths
Approved revision: 239
Merged at revision: 237
Proposed branch: lp:~gerboland/miral/qt-bump-to-qtmir-529
Merge into: lp:miral
Diff against target: 1275 lines (+453/-333)
29 files modified
miral-qt/CMakeLists.txt (+2/-3)
miral-qt/debian/control (+3/-2)
miral-qt/debian/gles-patches/convert-to-gles.patch (+1/-1)
miral-qt/src/modules/Unity/Application/CMakeLists.txt (+3/-1)
miral-qt/src/modules/Unity/Application/application.cpp (+1/-0)
miral-qt/src/modules/Unity/Application/application_manager.cpp (+3/-0)
miral-qt/src/modules/Unity/Application/application_manager.h (+2/-0)
miral-qt/src/modules/Unity/Application/cgmanager.cpp (+117/-0)
miral-qt/src/modules/Unity/Application/cgmanager.h (+42/-0)
miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp (+89/-0)
miral-qt/src/modules/Unity/Application/dbusfocusinfo.h (+54/-0)
miral-qt/src/modules/Unity/Application/mirsurface.cpp (+41/-0)
miral-qt/src/modules/Unity/Application/mirsurface.h (+8/-0)
miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h (+6/-0)
miral-qt/src/modules/Unity/Application/mirsurfaceitem.cpp (+11/-49)
miral-qt/src/modules/Unity/Application/mirsurfaceitem.h (+1/-2)
miral-qt/src/modules/Unity/Application/plugin.cpp (+0/-10)
miral-qt/src/modules/Unity/Application/session.cpp (+17/-0)
miral-qt/src/modules/Unity/Application/session.h (+4/-0)
miral-qt/src/modules/Unity/Application/session_interface.h (+6/-0)
miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.cpp (+0/-173)
miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.h (+0/-87)
miral-qt/src/platforms/mirserver/logging.cpp (+1/-0)
miral-qt/src/platforms/mirserver/logging.h (+1/-0)
miral-qt/src/platforms/mirserver/mirwindowmanager.cpp (+9/-4)
miral-qt/src/platforms/mirserver/surfaceobserver.cpp (+20/-0)
miral-qt/src/platforms/mirserver/surfaceobserver.h (+3/-1)
miral-qt/tests/framework/fake_mirsurface.h (+4/-0)
miral-qt/tests/framework/fake_session.h (+4/-0)
To merge this branch: bzr merge lp:~gerboland/miral/qt-bump-to-qtmir-529
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+301168@code.launchpad.net

Commit message

[miral-qt] Bump to rev 529 of qtmir

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I wonder why "DBusFocusInfo *m_dbusFocusInfo;" isn't "DBusFocusInfo m_dbusFocusInfo;" (avoiding explicit memory management) but I guess this is the wrong project in which to ask that.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ QRect inputBounds() const override { return QRect(0,0,10,10); }

Is this really an override? It seems to be missing in the MirSurfaceInterface base class.

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ void inputBoundsChanged(const QRect &rect);

Neither the linker nor I can find the implementation.

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Hmm. A clean rebuild fixed those. (Is there a depends missing somewhere in CMakeLists.txt?)

review: Approve
Revision history for this message
Gerry Boland (gerboland) wrote :

> DBusFocusInfo *m_dbusFocusInfo
good point, I didn't see it as it landed while I was on hols!

Build fail - am surprised, I bumped the required unity-shell-application version to the correct one (19). It should have not tried to build unless you have libunity-api-dev version 7.116 already installed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'miral-qt/CMakeLists.txt'
--- miral-qt/CMakeLists.txt 2016-06-21 13:38:53 +0000
+++ miral-qt/CMakeLists.txt 2016-07-26 12:46:18 +0000
@@ -90,9 +90,8 @@
90pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)90pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
91pkg_check_modules(QTDBUSTEST libqtdbustest-1 REQUIRED)91pkg_check_modules(QTDBUSTEST libqtdbustest-1 REQUIRED)
92pkg_check_modules(QTDBUSMOCK libqtdbusmock-1 REQUIRED)92pkg_check_modules(QTDBUSMOCK libqtdbusmock-1 REQUIRED)
93pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=18)93pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=19)
9494pkg_check_modules(CGMANAGER libcgmanager REQUIRED)
95include_directories(${APPLICATION_API_INCLUDE_DIRS})
9695
97add_definitions(-DMIR_REQUIRE_DEPRECATED_EVENT_OPT_IN=1)96add_definitions(-DMIR_REQUIRE_DEPRECATED_EVENT_OPT_IN=1)
9897
9998
=== modified file 'miral-qt/debian/control'
--- miral-qt/debian/control 2016-06-21 13:38:53 +0000
+++ miral-qt/debian/control 2016-07-26 12:46:18 +0000
@@ -6,6 +6,7 @@
6 cmake-extras (>= 0.3),6 cmake-extras (>= 0.3),
7 debhelper (>= 9),7 debhelper (>= 9),
8 google-mock (>= 1.6.0+svn437),8 google-mock (>= 1.6.0+svn437),
9 libcgmanager-dev,
9 libfontconfig1-dev,10 libfontconfig1-dev,
10 libgles2-mesa-dev,11 libgles2-mesa-dev,
11 libglib2.0-dev,12 libglib2.0-dev,
@@ -22,7 +23,7 @@
22 libubuntu-app-launch2-dev (>= 0.9),23 libubuntu-app-launch2-dev (>= 0.9),
23 libubuntu-application-api-dev (>= 2.1.0),24 libubuntu-application-api-dev (>= 2.1.0),
24 libudev-dev,25 libudev-dev,
25 libunity-api-dev (>= 7.114),26 libunity-api-dev (>= 7.116),
26 liburl-dispatcher1-dev,27 liburl-dispatcher1-dev,
27 libxkbcommon-dev,28 libxkbcommon-dev,
28 libxrender-dev,29 libxrender-dev,
@@ -93,7 +94,7 @@
93Conflicts: libqtmir,94Conflicts: libqtmir,
94 libunity-mir1,95 libunity-mir1,
95Provides: unity-application-impl,96Provides: unity-application-impl,
96 unity-application-impl-17,97 unity-application-impl-19,
97Description: Qt plugin for Unity specific Mir APIs98Description: Qt plugin for Unity specific Mir APIs
98 QtMir provides Qt/QML bindings for Mir features that are exposed through the99 QtMir provides Qt/QML bindings for Mir features that are exposed through the
99 qtmir-desktop or qtmir-android QPA plugin such as Application management100 qtmir-desktop or qtmir-android QPA plugin such as Application management
100101
=== modified file 'miral-qt/debian/gles-patches/convert-to-gles.patch'
--- miral-qt/debian/gles-patches/convert-to-gles.patch 2016-06-07 20:32:04 +0000
+++ miral-qt/debian/gles-patches/convert-to-gles.patch 2016-07-26 12:46:18 +0000
@@ -84,7 +84,7 @@
84-Conflicts: libqtmir,84-Conflicts: libqtmir,
85- libunity-mir1,85- libunity-mir1,
86-Provides: unity-application-impl,86-Provides: unity-application-impl,
87- unity-application-impl-17,87- unity-application-impl-19,
88-Description: Qt plugin for Unity specific Mir APIs88-Description: Qt plugin for Unity specific Mir APIs
89- QtMir provides Qt/QML bindings for Mir features that are exposed through the89- QtMir provides Qt/QML bindings for Mir features that are exposed through the
90- qtmir-desktop or qtmir-android QPA plugin such as Application management90- qtmir-desktop or qtmir-android QPA plugin such as Application management
9191
=== modified file 'miral-qt/src/modules/Unity/Application/CMakeLists.txt'
--- miral-qt/src/modules/Unity/Application/CMakeLists.txt 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/CMakeLists.txt 2016-07-26 12:46:18 +0000
@@ -10,6 +10,7 @@
10 ${MIRAL_QT_SOURCE_DIR}/src/platforms/mirserver10 ${MIRAL_QT_SOURCE_DIR}/src/platforms/mirserver
11 ${MIRAL_QT_SOURCE_DIR}/src/common11 ${MIRAL_QT_SOURCE_DIR}/src/common
12 ${GSETTINGS_QT_INCLUDE_DIRS}12 ${GSETTINGS_QT_INCLUDE_DIRS}
13 ${CGMANAGER_INCLUDE_DIRS}
1314
14 ${LTTNG_INCLUDE_DIRS}15 ${LTTNG_INCLUDE_DIRS}
15 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}16 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
@@ -25,12 +26,13 @@
25set(QMLMIRPLUGIN_SRC26set(QMLMIRPLUGIN_SRC
26 application_manager.cpp27 application_manager.cpp
27 application.cpp28 application.cpp
29 cgmanager.cpp
28 ../../../common/abstractdbusservicemonitor.cpp30 ../../../common/abstractdbusservicemonitor.cpp
29 ../../../common/debughelpers.cpp31 ../../../common/debughelpers.cpp
32 dbusfocusinfo.cpp
30 plugin.cpp33 plugin.cpp
31 dbuswindowstack.cpp34 dbuswindowstack.cpp
32 mirsurfacemanager.cpp35 mirsurfacemanager.cpp
33 ubuntukeyboardinfo.cpp
34 mirfocuscontroller.cpp36 mirfocuscontroller.cpp
35 mirsurface.cpp37 mirsurface.cpp
36 mirsurfaceinterface.h38 mirsurfaceinterface.h
3739
=== modified file 'miral-qt/src/modules/Unity/Application/application.cpp'
--- miral-qt/src/modules/Unity/Application/application.cpp 2016-06-21 13:38:53 +0000
+++ miral-qt/src/modules/Unity/Application/application.cpp 2016-07-26 12:46:18 +0000
@@ -18,6 +18,7 @@
18#include "application.h"18#include "application.h"
19#include "applicationinfo.h"19#include "applicationinfo.h"
20#include "application_manager.h"20#include "application_manager.h"
21#include "mirsurfaceinterface.h"
21#include "session.h"22#include "session.h"
22#include "sharedwakelock.h"23#include "sharedwakelock.h"
23#include "timer.h"24#include "timer.h"
2425
=== modified file 'miral-qt/src/modules/Unity/Application/application_manager.cpp'
--- miral-qt/src/modules/Unity/Application/application_manager.cpp 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/application_manager.cpp 2016-07-26 12:46:18 +0000
@@ -18,6 +18,7 @@
18#include "application_manager.h"18#include "application_manager.h"
19#include "application.h"19#include "application.h"
20#include "applicationinfo.h"20#include "applicationinfo.h"
21#include "dbusfocusinfo.h"
21#include "dbuswindowstack.h"22#include "dbuswindowstack.h"
22#include "mirfocuscontroller.h"23#include "mirfocuscontroller.h"
23#include "session.h"24#include "session.h"
@@ -176,6 +177,7 @@
176 const QSharedPointer<SettingsInterface>& settings,177 const QSharedPointer<SettingsInterface>& settings,
177 QObject *parent)178 QObject *parent)
178 : ApplicationManagerInterface(parent)179 : ApplicationManagerInterface(parent)
180 , m_dbusFocusInfo(new DBusFocusInfo(m_applications))
179 , m_dbusWindowStack(new DBusWindowStack(this))181 , m_dbusWindowStack(new DBusWindowStack(this))
180 , m_taskController(taskController)182 , m_taskController(taskController)
181 , m_procInfo(procInfo)183 , m_procInfo(procInfo)
@@ -200,6 +202,7 @@
200ApplicationManager::~ApplicationManager()202ApplicationManager::~ApplicationManager()
201{203{
202 qCDebug(QTMIR_APPLICATIONS) << "ApplicationManager::~ApplicationManager";204 qCDebug(QTMIR_APPLICATIONS) << "ApplicationManager::~ApplicationManager";
205 delete m_dbusFocusInfo;
203}206}
204207
205int ApplicationManager::rowCount(const QModelIndex &parent) const208int ApplicationManager::rowCount(const QModelIndex &parent) const
206209
=== modified file 'miral-qt/src/modules/Unity/Application/application_manager.h'
--- miral-qt/src/modules/Unity/Application/application_manager.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/application_manager.h 2016-07-26 12:46:18 +0000
@@ -49,6 +49,7 @@
4949
50namespace qtmir {50namespace qtmir {
5151
52class DBusFocusInfo;
52class DBusWindowStack;53class DBusWindowStack;
53class MirSurfaceManager;54class MirSurfaceManager;
54class ProcInfo;55class ProcInfo;
@@ -138,6 +139,7 @@
138 Application *findApplication(MirSurfaceInterface* surface);139 Application *findApplication(MirSurfaceInterface* surface);
139140
140 QList<Application*> m_applications;141 QList<Application*> m_applications;
142 DBusFocusInfo *m_dbusFocusInfo;
141 DBusWindowStack* m_dbusWindowStack;143 DBusWindowStack* m_dbusWindowStack;
142 QSharedPointer<TaskController> m_taskController;144 QSharedPointer<TaskController> m_taskController;
143 QSharedPointer<ProcInfo> m_procInfo;145 QSharedPointer<ProcInfo> m_procInfo;
144146
=== added file 'miral-qt/src/modules/Unity/Application/cgmanager.cpp'
--- miral-qt/src/modules/Unity/Application/cgmanager.cpp 1970-01-01 00:00:00 +0000
+++ miral-qt/src/modules/Unity/Application/cgmanager.cpp 2016-07-26 12:46:18 +0000
@@ -0,0 +1,117 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "cgmanager.h"
18
19// QPA mirserver
20#include <logging.h>
21
22#include <cgmanager/cgmanager.h>
23
24#include <QDBusArgument>
25#include <QDBusMessage>
26
27using namespace qtmir;
28
29// According to D-Bus interface defined in:
30// https://github.com/lxc/cgmanager/blob/master/org.linuxcontainers.cgmanager.xml
31
32CGManager::CGManager(QObject *parent)
33 : QObject(parent)
34{
35}
36
37CGManager::~CGManager()
38{
39 QDBusConnection::disconnectFromPeer("cgmanager");
40}
41
42QDBusConnection CGManager::getConnection()
43{
44 auto connection = QDBusConnection("cgmanager");
45
46 if (!connection.isConnected()) {
47 connection = QDBusConnection::connectToPeer(CGMANAGER_DBUS_PATH, "cgmanager");
48 if (!connection.isConnected()) {
49 qCWarning(QTMIR_DBUS, "CGManager: Failed to connect to %s", CGMANAGER_DBUS_PATH);
50 }
51 }
52
53 return connection;
54}
55
56QString CGManager::getCGroupOfPid(const QString &controller, pid_t pid)
57{
58 auto connection = getConnection();
59 if (!connection.isConnected()) {
60 return QString();
61 }
62
63 auto message = QDBusMessage::createMethodCall(QString() /*service*/, m_path, m_interface, "GetPidCgroup");
64
65 QList<QVariant> arguments;
66 arguments << QVariant(controller);
67 arguments << QVariant((int)pid);
68
69 message.setArguments(arguments);
70
71 QDBusMessage reply = connection.call(message);
72
73 if (reply.type() == QDBusMessage::ReplyMessage) {
74 return reply.arguments()[0].toString();
75 } else {
76 Q_ASSERT(reply.type() == QDBusMessage::ErrorMessage);
77 qCWarning(QTMIR_DBUS) << "CGManager::getCGroupOfPid failed." << reply.errorMessage();
78 return QString();
79 }
80}
81
82QSet<pid_t> CGManager::getTasks(const QString &controller, const QString &cgroup)
83{
84 auto connection = getConnection();
85 if (!connection.isConnected()) {
86 return QSet<pid_t>();
87 }
88
89 auto message = QDBusMessage::createMethodCall(QString() /*service*/, m_path, m_interface, "GetTasks");
90
91 QList<QVariant> arguments;
92 arguments << QVariant(controller);
93 arguments << QVariant(cgroup);
94
95 message.setArguments(arguments);
96
97 QDBusMessage reply = connection.call(message);
98
99 if (reply.type() == QDBusMessage::ErrorMessage) {
100 qCWarning(QTMIR_DBUS) << "CGManager::getCGroupOfPid failed." << reply.errorMessage();
101 return QSet<pid_t>();
102 }
103
104 Q_ASSERT(reply.type() == QDBusMessage::ReplyMessage);
105
106 auto arg = reply.arguments()[0].value<QDBusArgument>();
107 Q_ASSERT(arg.currentType() == QDBusArgument::ArrayType);
108
109 auto pidList = qdbus_cast<QList<int>>(arg);
110 Q_ASSERT(pidList.count() > 0);
111
112 QSet<pid_t> pidSet;
113 for (int i = 0; i < pidList.count(); ++i) {
114 pidSet << (pid_t)pidList[i];
115 }
116 return pidSet;
117}
0118
=== added file 'miral-qt/src/modules/Unity/Application/cgmanager.h'
--- miral-qt/src/modules/Unity/Application/cgmanager.h 1970-01-01 00:00:00 +0000
+++ miral-qt/src/modules/Unity/Application/cgmanager.h 2016-07-26 12:46:18 +0000
@@ -0,0 +1,42 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QTMIR_CGMANAGER_H
18#define QTMIR_CGMANAGER_H
19
20#include <QDBusConnection>
21
22namespace qtmir {
23
24class CGManager : public QObject {
25 Q_OBJECT
26public:
27 CGManager(QObject *parent = nullptr);
28 virtual ~CGManager();
29
30 QString getCGroupOfPid(const QString &controller, pid_t pid);
31
32 QSet<pid_t> getTasks(const QString &controller, const QString &cgroup);
33
34private:
35 const QString m_interface{"org.linuxcontainers.cgmanager0_0"};
36 const QString m_path{"/org/linuxcontainers/cgmanager"};
37 QDBusConnection getConnection();
38};
39
40} // namespace qtmir
41
42#endif // QTMIR_CGMANAGER_H
043
=== added file 'miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp'
--- miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp 1970-01-01 00:00:00 +0000
+++ miral-qt/src/modules/Unity/Application/dbusfocusinfo.cpp 2016-07-26 12:46:18 +0000
@@ -0,0 +1,89 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "dbusfocusinfo.h"
18
19// local
20#include "cgmanager.h"
21
22// QPA mirserver
23#include <logging.h>
24
25#include <QDBusConnection>
26
27using namespace qtmir;
28
29DBusFocusInfo::DBusFocusInfo(const QList<Application*> &applications)
30 : m_applications(applications)
31{
32 QDBusConnection::sessionBus().registerService("com.canonical.Unity.FocusInfo");
33 QDBusConnection::sessionBus().registerObject("/com/canonical/Unity/FocusInfo", this, QDBusConnection::ExportScriptableSlots);
34
35 m_cgManager = new CGManager(this);
36}
37
38bool DBusFocusInfo::isPidFocused(unsigned int pid)
39{
40 if (QCoreApplication::applicationPid() == (qint64)pid) {
41 // Shell itself.
42 // Don't bother checking if it has a QML with activeFocus() which is not a MirSurfaceItem.
43 return true;
44 } else {
45 auto pidSet = fetchAssociatedPids((pid_t)pid);
46 SessionInterface *session = findSessionWithPid(pidSet);
47 return session ? session->activeFocus() : false;
48 }
49}
50
51QSet<pid_t> DBusFocusInfo::fetchAssociatedPids(pid_t pid)
52{
53 QString cgroup = m_cgManager->getCGroupOfPid("freezer", pid);
54
55 // If a cgroup has a format like this:
56 // /user.slice/user-32011.slice/session-c3.scope/upstart/application-legacy-puritine_gedit_0.0-
57 // All PIds in it are associated with a single application.
58 if (cgroup.split("/").contains("upstart")) {
59 QSet<pid_t> pidSet = m_cgManager->getTasks("freezer", cgroup);
60 qCDebug(QTMIR_DBUS) << "DBusFocusInfo: pid" << pid << "is in cgroup" << cgroup << "along with:" << pidSet;
61 if (pidSet.isEmpty()) {
62 pidSet << pid;
63 }
64 return pidSet;
65 } else {
66 qCDebug(QTMIR_DBUS) << "DBusFocusInfo: pid" << pid << "is in cgroup" << cgroup << "which is not app-specific";
67 return QSet<pid_t>({pid});
68 }
69}
70
71SessionInterface* DBusFocusInfo::findSessionWithPid(const QSet<pid_t> &pidSet)
72{
73 Q_FOREACH (Application* application, m_applications) {
74 auto session = application->session();
75 if (pidSet.contains(session->pid())) {
76 return session;
77 }
78 SessionInterface *chosenChildSession = nullptr;
79 session->foreachChildSession([&](SessionInterface* childSession) {
80 if (pidSet.contains(childSession->pid())) {
81 chosenChildSession = childSession;
82 }
83 });
84 if (chosenChildSession) {
85 return chosenChildSession;
86 }
87 }
88 return nullptr;
89}
090
=== added file 'miral-qt/src/modules/Unity/Application/dbusfocusinfo.h'
--- miral-qt/src/modules/Unity/Application/dbusfocusinfo.h 1970-01-01 00:00:00 +0000
+++ miral-qt/src/modules/Unity/Application/dbusfocusinfo.h 2016-07-26 12:46:18 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <QList>
18#include <QSet>
19
20#include "application.h"
21
22namespace qtmir {
23
24class CGManager;
25
26/*
27 FIXME: This is a hack to provide OSK with needed info for avoiding input snooping.
28 Remove when possible
29 */
30class DBusFocusInfo : public QObject
31{
32 Q_OBJECT
33 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.FocusInfo")
34public:
35 explicit DBusFocusInfo(const QList<Application*> &applications);
36 virtual ~DBusFocusInfo() {}
37
38public Q_SLOTS:
39
40 /*
41 Returns true if the application with the given PID has input focus
42 */
43 Q_SCRIPTABLE bool isPidFocused(unsigned int pid);
44
45private:
46 QSet<pid_t> fetchAssociatedPids(pid_t pid);
47 SessionInterface* findSessionWithPid(const QSet<pid_t> &pidSet);
48
49 const QList<Application*> &m_applications;
50
51 CGManager *m_cgManager;
52};
53
54} // namespace qtmir
055
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp'
--- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-07-25 13:48:41 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-07-26 12:46:18 +0000
@@ -219,6 +219,7 @@
219 connect(observer.get(), &SurfaceObserver::shellChromeChanged, this, [&](MirShellChrome shell_chrome) {219 connect(observer.get(), &SurfaceObserver::shellChromeChanged, this, [&](MirShellChrome shell_chrome) {
220 setShellChrome(static_cast<Mir::ShellChrome>(shell_chrome));220 setShellChrome(static_cast<Mir::ShellChrome>(shell_chrome));
221 });221 });
222 connect(observer.get(), &SurfaceObserver::inputBoundsChanged, this, &MirSurface::setInputBounds);
222 observer->setListener(this);223 observer->setListener(this);
223 }224 }
224225
@@ -277,12 +278,15 @@
277{278{
278 switch (attribute) {279 switch (attribute) {
279 case mir_surface_attrib_type:280 case mir_surface_attrib_type:
281 DEBUG_MSG << " type = " << mirSurfaceTypeToStr(state());
280 Q_EMIT typeChanged(type());282 Q_EMIT typeChanged(type());
281 break;283 break;
282 case mir_surface_attrib_state:284 case mir_surface_attrib_state:
285 DEBUG_MSG << " state = " << mirSurfaceStateToStr(state());
283 Q_EMIT stateChanged(state());286 Q_EMIT stateChanged(state());
284 break;287 break;
285 case mir_surface_attrib_visibility:288 case mir_surface_attrib_visibility:
289 DEBUG_MSG << " visible = " << visible();
286 Q_EMIT visibleChanged(visible());290 Q_EMIT visibleChanged(visible());
287 break;291 break;
288 default:292 default:
@@ -453,6 +457,11 @@
453 }457 }
454}458}
455459
460bool MirSurface::activeFocus() const
461{
462 return !m_activelyFocusedViews.empty();
463}
464
456void MirSurface::updateActiveFocus()465void MirSurface::updateActiveFocus()
457{466{
458 if (!m_session) {467 if (!m_session) {
@@ -871,6 +880,24 @@
871 }880 }
872}881}
873882
883bool MirSurface::inputAreaContains(const QPoint &point) const
884{
885 bool result;
886
887
888 // Can't use it due to https://bugs.launchpad.net/mir/+bug/1598936
889 // FIXME: Use the line below instead of m_inputBounds once this bug gets fixed.
890 //result = m_surface->input_area_contains(mir::geometry::Point(point.x(), point.y()));
891
892 if (m_inputBounds.isNull()) {
893 result = true;
894 } else {
895 result = m_inputBounds.contains(point);
896 }
897
898 return result;
899}
900
874void MirSurface::setCursor(const QCursor &cursor)901void MirSurface::setCursor(const QCursor &cursor)
875{902{
876 DEBUG_MSG << "(" << qtCursorShapeToStr(cursor.shape()) << ")";903 DEBUG_MSG << "(" << qtCursorShapeToStr(cursor.shape()) << ")";
@@ -962,6 +989,11 @@
962 return m_focused;989 return m_focused;
963}990}
964991
992QRect MirSurface::inputBounds() const
993{
994 return m_inputBounds;
995}
996
965void MirSurface::requestFocus()997void MirSurface::requestFocus()
966{998{
967 DEBUG_MSG << "()";999 DEBUG_MSG << "()";
@@ -1003,3 +1035,12 @@
1003 m_closeTimer->start();1035 m_closeTimer->start();
1004 }1036 }
1005}1037}
1038
1039void MirSurface::setInputBounds(const QRect &rect)
1040{
1041 if (m_inputBounds != rect) {
1042 DEBUG_MSG << "(" << rect << ")";
1043 m_inputBounds = rect;
1044 Q_EMIT inputBoundsChanged(m_inputBounds);
1045 }
1046}
10061047
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.h'
--- miral-qt/src/modules/Unity/Application/mirsurface.h 2016-07-25 13:48:41 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurface.h 2016-07-26 12:46:18 +0000
@@ -24,6 +24,7 @@
24#include <QCursor>24#include <QCursor>
25#include <QMutex>25#include <QMutex>
26#include <QPointer>26#include <QPointer>
27#include <QRect>
27#include <QSharedPointer>28#include <QSharedPointer>
28#include <QWeakPointer>29#include <QWeakPointer>
29#include <QSet>30#include <QSet>
@@ -89,6 +90,7 @@
89 int heightIncrement() const override;90 int heightIncrement() const override;
9091
91 bool focused() const override;92 bool focused() const override;
93 QRect inputBounds() const override;
9294
93 Q_INVOKABLE void requestFocus() override;95 Q_INVOKABLE void requestFocus() override;
94 Q_INVOKABLE void close() override;96 Q_INVOKABLE void close() override;
@@ -121,6 +123,7 @@
121 void setFocused(bool focus) override;123 void setFocused(bool focus) override;
122124
123 void setViewActiveFocus(qintptr viewId, bool value) override;125 void setViewActiveFocus(qintptr viewId, bool value) override;
126 bool activeFocus() const override;
124127
125 void mousePressEvent(QMouseEvent *event) override;128 void mousePressEvent(QMouseEvent *event) override;
126 void mouseMoveEvent(QMouseEvent *event) override;129 void mouseMoveEvent(QMouseEvent *event) override;
@@ -149,6 +152,8 @@
149152
150 SessionInterface* session() override { return m_session.data(); }153 SessionInterface* session() override { return m_session.data(); }
151154
155 bool inputAreaContains(const QPoint &) const override;
156
152 ////157 ////
153 // Own API158 // Own API
154159
@@ -174,6 +179,7 @@
174 void emitSizeChanged();179 void emitSizeChanged();
175 void setCursor(const QCursor &cursor);180 void setCursor(const QCursor &cursor);
176 void onCloseTimedOut();181 void onCloseTimedOut();
182 void setInputBounds(const QRect &rect);
177183
178private:184private:
179 void syncSurfaceSizeWithItemSize();185 void syncSurfaceSizeWithItemSize();
@@ -223,6 +229,8 @@
223 int m_widthIncrement{0};229 int m_widthIncrement{0};
224 int m_heightIncrement{0};230 int m_heightIncrement{0};
225231
232 QRect m_inputBounds;
233
226 bool m_focused{false};234 bool m_focused{false};
227235
228 enum ClosingState {236 enum ClosingState {
229237
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h'
--- miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-07-25 13:48:41 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-07-26 12:46:18 +0000
@@ -77,6 +77,10 @@
77 the name.77 the name.
78 */78 */
79 virtual void setViewActiveFocus(qintptr viewId, bool value) = 0;79 virtual void setViewActiveFocus(qintptr viewId, bool value) = 0;
80 /*
81 Whether any view of this surface currently has QML active focus
82 */
83 virtual bool activeFocus() const = 0;
8084
81 virtual void mousePressEvent(QMouseEvent *event) = 0;85 virtual void mousePressEvent(QMouseEvent *event) = 0;
82 virtual void mouseMoveEvent(QMouseEvent *event) = 0;86 virtual void mouseMoveEvent(QMouseEvent *event) = 0;
@@ -100,6 +104,8 @@
100104
101 virtual SessionInterface* session() = 0;105 virtual SessionInterface* session() = 0;
102106
107 virtual bool inputAreaContains(const QPoint &) const = 0;
108
103public Q_SLOTS:109public Q_SLOTS:
104 virtual void onCompositorSwappedBuffers() = 0;110 virtual void onCompositorSwappedBuffers() = 0;
105111
106112
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurfaceitem.cpp'
--- miral-qt/src/modules/Unity/Application/mirsurfaceitem.cpp 2016-07-25 13:48:41 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurfaceitem.cpp 2016-07-26 12:46:18 +0000
@@ -20,7 +20,6 @@
20#include "mirsurfaceitem.h"20#include "mirsurfaceitem.h"
21#include "mirfocuscontroller.h"21#include "mirfocuscontroller.h"
22#include "logging.h"22#include "logging.h"
23#include "ubuntukeyboardinfo.h"
24#include "tracepoints.h" // generated from tracepoints.tp23#include "tracepoints.h" // generated from tracepoints.tp
25#include "timestamp.h"24#include "timestamp.h"
2625
@@ -103,10 +102,6 @@
103 setSmooth(true);102 setSmooth(true);
104 setFlag(QQuickItem::ItemHasContents, true); //so scene graph will render this item103 setFlag(QQuickItem::ItemHasContents, true); //so scene graph will render this item
105104
106 if (!UbuntuKeyboardInfo::instance()) {
107 new UbuntuKeyboardInfo;
108 }
109
110 m_updateMirSurfaceSizeTimer.setSingleShot(true);105 m_updateMirSurfaceSizeTimer.setSingleShot(true);
111 m_updateMirSurfaceSizeTimer.setInterval(1);106 m_updateMirSurfaceSizeTimer.setInterval(1);
112 connect(&m_updateMirSurfaceSizeTimer, &QTimer::timeout, this, &MirSurfaceItem::updateMirSurfaceSize);107 connect(&m_updateMirSurfaceSizeTimer, &QTimer::timeout, this, &MirSurfaceItem::updateMirSurfaceSize);
@@ -290,17 +285,9 @@
290285
291void MirSurfaceItem::mousePressEvent(QMouseEvent *event)286void MirSurfaceItem::mousePressEvent(QMouseEvent *event)
292{287{
293 if (m_consumesInput && m_surface && m_surface->live()) {288 auto mousePos = event->localPos().toPoint();
294 if (type() == Mir::InputMethodType) {289 if (m_consumesInput && m_surface && m_surface->live() && m_surface->inputAreaContains(mousePos)) {
295 // FIXME: Hack to get the VKB use case working while we don't have the proper solution in place.290 m_surface->mousePressEvent(event);
296 if (isMouseInsideUbuntuKeyboard(event)) {
297 m_surface->mousePressEvent(event);
298 } else {
299 event->ignore();
300 }
301 } else {
302 m_surface->mousePressEvent(event);
303 }
304 } else {291 } else {
305 event->ignore();292 event->ignore();
306 }293 }
@@ -471,51 +458,26 @@
471 return false;458 return false;
472 }459 }
473460
474 bool accepted = true;461 if (eventType == QEvent::TouchBegin && !hasTouchInsideInputRegion(touchPoints)) {
475 if (type() == Mir::InputMethodType && eventType == QEvent::TouchBegin) {462 return false;
476 // FIXME: Hack to get the VKB use case working while we don't have the proper solution in place.
477 if (hasTouchInsideUbuntuKeyboard(touchPoints)) {
478 validateAndDeliverTouchEvent(eventType, timestamp, mods, touchPoints, touchPointStates);
479 } else {
480 accepted = false;
481 }
482
483 } else {
484 // NB: If we are getting QEvent::TouchUpdate or QEvent::TouchEnd it's because we've
485 // previously accepted the corresponding QEvent::TouchBegin
486 validateAndDeliverTouchEvent(eventType, timestamp, mods, touchPoints, touchPointStates);
487 }463 }
488 return accepted;464
465 validateAndDeliverTouchEvent(eventType, timestamp, mods, touchPoints, touchPointStates);
466
467 return true;
489}468}
490469
491bool MirSurfaceItem::hasTouchInsideUbuntuKeyboard(const QList<QTouchEvent::TouchPoint> &touchPoints)470bool MirSurfaceItem::hasTouchInsideInputRegion(const QList<QTouchEvent::TouchPoint> &touchPoints)
492{471{
493 UbuntuKeyboardInfo *ubuntuKeyboardInfo = UbuntuKeyboardInfo::instance();
494
495 for (int i = 0; i < touchPoints.count(); ++i) {472 for (int i = 0; i < touchPoints.count(); ++i) {
496 QPoint pos = touchPoints.at(i).pos().toPoint();473 QPoint pos = touchPoints.at(i).pos().toPoint();
497 if (pos.x() >= ubuntuKeyboardInfo->x()474 if (m_surface->inputAreaContains(pos)) {
498 && pos.x() <= (ubuntuKeyboardInfo->x() + ubuntuKeyboardInfo->width())
499 && pos.y() >= ubuntuKeyboardInfo->y()
500 && pos.y() <= (ubuntuKeyboardInfo->y() + ubuntuKeyboardInfo->height())) {
501 return true;475 return true;
502 }476 }
503 }477 }
504 return false;478 return false;
505}479}
506480
507bool MirSurfaceItem::isMouseInsideUbuntuKeyboard(const QMouseEvent *event)
508{
509 UbuntuKeyboardInfo *ubuntuKeyboardInfo = UbuntuKeyboardInfo::instance();
510
511 const QPointF &pos = event->localPos();
512
513 return pos.x() >= ubuntuKeyboardInfo->x()
514 && pos.x() <= (ubuntuKeyboardInfo->x() + ubuntuKeyboardInfo->width())
515 && pos.y() >= ubuntuKeyboardInfo->y()
516 && pos.y() <= (ubuntuKeyboardInfo->y() + ubuntuKeyboardInfo->height());
517}
518
519Mir::State MirSurfaceItem::surfaceState() const481Mir::State MirSurfaceItem::surfaceState() const
520{482{
521 if (m_surface) {483 if (m_surface) {
522484
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurfaceitem.h'
--- miral-qt/src/modules/Unity/Application/mirsurfaceitem.h 2016-07-25 13:48:41 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurfaceitem.h 2016-07-26 12:46:18 +0000
@@ -126,8 +126,7 @@
126private:126private:
127 void ensureTextureProvider();127 void ensureTextureProvider();
128128
129 bool hasTouchInsideUbuntuKeyboard(const QList<QTouchEvent::TouchPoint> &touchPoints);129 bool hasTouchInsideInputRegion(const QList<QTouchEvent::TouchPoint> &touchPoints);
130 bool isMouseInsideUbuntuKeyboard(const QMouseEvent *event);
131130
132 QString appId() const;131 QString appId() const;
133 void endCurrentTouchSequence(ulong timestamp);132 void endCurrentTouchSequence(ulong timestamp);
134133
=== modified file 'miral-qt/src/modules/Unity/Application/plugin.cpp'
--- miral-qt/src/modules/Unity/Application/plugin.cpp 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/plugin.cpp 2016-07-26 12:46:18 +0000
@@ -25,7 +25,6 @@
25#include "mirsurfaceinterface.h"25#include "mirsurfaceinterface.h"
26#include "mirsurfaceitem.h"26#include "mirsurfaceitem.h"
27#include "mirsurfacelistmodel.h"27#include "mirsurfacelistmodel.h"
28#include "ubuntukeyboardinfo.h"
2928
30// platforms/mirserver29// platforms/mirserver
31#include <mirsingleton.h>30#include <mirsingleton.h>
@@ -55,13 +54,6 @@
55 return qtmir::MirSurfaceManager::singleton();54 return qtmir::MirSurfaceManager::singleton();
56}55}
5756
58QObject* ubuntuKeyboardInfoSingleton(QQmlEngine* /*engine*/, QJSEngine* /*scriptEngine*/) {
59 if (!UbuntuKeyboardInfo::instance()) {
60 new UbuntuKeyboardInfo;
61 }
62 return UbuntuKeyboardInfo::instance();
63}
64
65QObject* mirSingleton(QQmlEngine* /*engine*/, QJSEngine* /*scriptEngine*/) {57QObject* mirSingleton(QQmlEngine* /*engine*/, QJSEngine* /*scriptEngine*/) {
66 return qtmir::Mir::instance();58 return qtmir::Mir::instance();
67}59}
@@ -101,8 +93,6 @@
101 qmlRegisterUncreatableType<unity::shell::application::MirSurfaceInterface>(93 qmlRegisterUncreatableType<unity::shell::application::MirSurfaceInterface>(
102 uri, 0, 1, "MirSurface", "MirSurface can't be instantiated from QML");94 uri, 0, 1, "MirSurface", "MirSurface can't be instantiated from QML");
103 qmlRegisterType<qtmir::MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem");95 qmlRegisterType<qtmir::MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem");
104 qmlRegisterSingletonType<qtmir::UbuntuKeyboardInfo>(
105 uri, 0, 1, "UbuntuKeyboardInfo", ubuntuKeyboardInfoSingleton);
106 qmlRegisterSingletonType<qtmir::Mir>(uri, 0, 1, "Mir", mirSingleton);96 qmlRegisterSingletonType<qtmir::Mir>(uri, 0, 1, "Mir", mirSingleton);
107 }97 }
10898
10999
=== modified file 'miral-qt/src/modules/Unity/Application/session.cpp'
--- miral-qt/src/modules/Unity/Application/session.cpp 2016-06-21 13:38:53 +0000
+++ miral-qt/src/modules/Unity/Application/session.cpp 2016-07-26 12:46:18 +0000
@@ -514,6 +514,23 @@
514 return m_hadSurface;514 return m_hadSurface;
515}515}
516516
517bool Session::activeFocus() const
518{
519 for (int i = 0; i < m_surfaceList.count(); ++i) {
520 auto surface = static_cast<const MirSurfaceInterface*>(m_surfaceList.get(i));
521 if (surface->activeFocus()) {
522 return true;
523 }
524 }
525
526 return false;
527}
528
529pid_t Session::pid() const
530{
531 return m_session->process_id();
532}
533
517void Session::setSuspendTimer(AbstractTimer *timer)534void Session::setSuspendTimer(AbstractTimer *timer)
518{535{
519 bool timerWasRunning = false;536 bool timerWasRunning = false;
520537
=== modified file 'miral-qt/src/modules/Unity/Application/session.h'
--- miral-qt/src/modules/Unity/Application/session.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/session.h 2016-07-26 12:46:18 +0000
@@ -67,6 +67,10 @@
67 bool hadSurface() const override;67 bool hadSurface() const override;
68 bool hasClosingSurfaces() const override;68 bool hasClosingSurfaces() const override;
6969
70 bool activeFocus() const override;
71
72 pid_t pid() const override;
73
70 void addChildSession(SessionInterface* session) override;74 void addChildSession(SessionInterface* session) override;
71 void insertChildSession(uint index, SessionInterface* session) override;75 void insertChildSession(uint index, SessionInterface* session) override;
72 void removeChildSession(SessionInterface* session) override;76 void removeChildSession(SessionInterface* session) override;
7377
=== modified file 'miral-qt/src/modules/Unity/Application/session_interface.h'
--- miral-qt/src/modules/Unity/Application/session_interface.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/session_interface.h 2016-07-26 12:46:18 +0000
@@ -92,6 +92,12 @@
92 virtual bool hadSurface() const = 0; // whether this session ever had any surface (currently or in the past)92 virtual bool hadSurface() const = 0; // whether this session ever had any surface (currently or in the past)
93 virtual bool hasClosingSurfaces() const = 0; // whether it has surfaces being forcibly closed93 virtual bool hasClosingSurfaces() const = 0; // whether it has surfaces being forcibly closed
9494
95 // Whether any of its MirSurfaces has activeFocus()
96 // See qtmir::MirSurfaceInterface::activeFocus
97 virtual bool activeFocus() const = 0;
98
99 virtual pid_t pid() const = 0;
100
95 // For SessionManager use101 // For SessionManager use
96102
97 virtual void addChildSession(SessionInterface* session) = 0;103 virtual void addChildSession(SessionInterface* session) = 0;
98104
=== removed file 'miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.cpp'
--- miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.cpp 2016-06-21 13:38:53 +0000
+++ miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.cpp 1970-01-01 00:00:00 +0000
@@ -1,173 +0,0 @@
1/*
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "ubuntukeyboardinfo.h"
18
19#include <QDir>
20
21namespace qtmir {
22
23namespace {
24 const int gConnectionAttemptIntervalMs = 5000;
25 const int gMaxConsecutiveAttempts = 10;
26 const char gServerName[] = "ubuntu-keyboard-info";
27}
28
29UbuntuKeyboardInfo* UbuntuKeyboardInfo::m_instance = nullptr;
30
31UbuntuKeyboardInfo* UbuntuKeyboardInfo::instance()
32{
33 return m_instance;
34}
35
36UbuntuKeyboardInfo::UbuntuKeyboardInfo(QObject *parent)
37 : QObject(parent),
38 m_consecutiveAttempts(0),
39 m_lastX(0),
40 m_lastY(0),
41 m_lastWidth(0),
42 m_lastHeight(0)
43{
44 if (m_instance) {
45 qFatal("Cannot have more than one instance of UbuntuKeyboardInfo simultaneously.");
46 }
47 m_instance = this;
48
49 connect(&m_socket, &QLocalSocket::stateChanged, this, &UbuntuKeyboardInfo::onSocketStateChanged);
50 connect(&m_socket, &QIODevice::readyRead,
51 this, &UbuntuKeyboardInfo::readAllBytesFromSocket);
52
53 buildSocketFilePath();
54
55 typedef void (QLocalSocket::*MemberFunctionType)(QLocalSocket::LocalSocketError);
56 MemberFunctionType funcPointer = &QLocalSocket::error;
57 connect(&m_socket, funcPointer,
58 this, &UbuntuKeyboardInfo::onSocketError);
59
60 m_connectionRetryTimer.setInterval(gConnectionAttemptIntervalMs);
61 m_connectionRetryTimer.setSingleShot(true);
62 connect(&m_connectionRetryTimer, &QTimer::timeout,
63 this, &UbuntuKeyboardInfo::tryConnectingToServer);
64 tryConnectingToServer();
65}
66
67UbuntuKeyboardInfo::~UbuntuKeyboardInfo()
68{
69 // Make sure we don't get onSocketStateChanged() called during
70 // destruction.
71 m_socket.disconnect(this);
72
73 Q_ASSERT(m_instance);
74 m_instance = nullptr;
75}
76
77void UbuntuKeyboardInfo::tryConnectingToServer()
78{
79 ++m_consecutiveAttempts;
80 Q_ASSERT(!m_socketFilePath.isEmpty());
81 m_socket.connectToServer(m_socketFilePath, QIODevice::ReadOnly);
82}
83
84void UbuntuKeyboardInfo::onSocketStateChanged(QLocalSocket::LocalSocketState socketState)
85{
86 switch (socketState) {
87 case QLocalSocket::UnconnectedState:
88 retryConnection();
89 break;
90 case QLocalSocket::ConnectedState:
91 m_consecutiveAttempts = 0;
92 break;
93 default:
94 break;
95 }
96}
97
98void UbuntuKeyboardInfo::onSocketError(QLocalSocket::LocalSocketError socketError)
99{
100 Q_UNUSED(socketError);
101 qWarning() << "UbuntuKeyboardInfo - socket error:" << m_socket.errorString();
102}
103
104void UbuntuKeyboardInfo::retryConnection()
105{
106 // Polling every gConnectionAttemptIntervalMs. Not the best approach but could be worse.
107 if (m_consecutiveAttempts < gMaxConsecutiveAttempts) {
108 if (!m_connectionRetryTimer.isActive()) {
109 m_connectionRetryTimer.start();
110 }
111 } else {
112 qCritical() << "Failed to connect to" << m_socketFilePath << "after"
113 << m_consecutiveAttempts << "failed attempts";
114
115 // it shouldn't be running, but just to be sure.
116 m_connectionRetryTimer.stop();
117 }
118}
119
120void UbuntuKeyboardInfo::readAllBytesFromSocket()
121{
122 while (m_socket.bytesAvailable() > 0) {
123 readInfoFromSocket();
124 }
125}
126
127void UbuntuKeyboardInfo::readInfoFromSocket()
128{
129 const size_t sharedInfoSize = sizeof(struct SharedInfo);
130 QByteArray bytes = m_socket.read(sharedInfoSize);
131 if (bytes.size() != sharedInfoSize) {
132 qWarning() << "UbuntuKeyboardInfo: expected to receive" << sharedInfoSize
133 << "but got" << bytes.size();
134 return;
135 }
136
137 {
138 struct SharedInfo *sharedInfo = reinterpret_cast<struct SharedInfo*>(bytes.data());
139
140 if (m_lastX != sharedInfo->keyboardX) {
141 m_lastX = sharedInfo->keyboardX;
142 Q_EMIT xChanged(m_lastX);
143 }
144
145 if (m_lastY != sharedInfo->keyboardY) {
146 m_lastY = sharedInfo->keyboardY;
147 Q_EMIT yChanged(m_lastY);
148 }
149
150 if (m_lastWidth != sharedInfo->keyboardWidth) {
151 m_lastWidth = sharedInfo->keyboardWidth;
152 Q_EMIT widthChanged(m_lastWidth);
153 }
154
155 if (m_lastHeight != sharedInfo->keyboardHeight) {
156 m_lastHeight = sharedInfo->keyboardHeight;
157 Q_EMIT heightChanged(m_lastHeight);
158 }
159 }
160}
161
162void UbuntuKeyboardInfo::buildSocketFilePath()
163{
164 char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR");
165
166 if (xdgRuntimeDir) {
167 m_socketFilePath = QDir(xdgRuntimeDir).filePath(gServerName);
168 } else {
169 m_socketFilePath = QDir("/tmp").filePath(gServerName);
170 }
171}
172
173} // namespace qtmir
1740
=== removed file 'miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.h'
--- miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/ubuntukeyboardinfo.h 1970-01-01 00:00:00 +0000
@@ -1,87 +0,0 @@
1/*
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef UBUNTU_KEYBOARD_INFO_H
18#define UBUNTU_KEYBOARD_INFO_H
19
20#include <QLocalSocket>
21#include <QTimer>
22
23namespace qtmir {
24
25// Temporary solution to get information about the onscreen keyboard
26// This shouldn't be needed once the OSK is a properly sized surface
27// instead of a fullscreen one.
28class UbuntuKeyboardInfo : public QObject {
29 Q_OBJECT
30 Q_PROPERTY(qreal x READ x NOTIFY xChanged)
31 Q_PROPERTY(qreal y READ y NOTIFY yChanged)
32 Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
33 Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
34public:
35 UbuntuKeyboardInfo(QObject *parent = 0);
36 virtual ~UbuntuKeyboardInfo();
37
38 static UbuntuKeyboardInfo* instance();
39
40 qreal x() const { return m_lastX; }
41 qreal y() const { return m_lastY; }
42 qreal width() const { return m_lastWidth; }
43 qreal height() const { return m_lastHeight; }
44
45Q_SIGNALS:
46 void xChanged(qreal x);
47 void yChanged(qreal y);
48 void widthChanged(qreal width);
49 void heightChanged(qreal height);
50
51private Q_SLOTS:
52 void tryConnectingToServer();
53 void onSocketStateChanged(QLocalSocket::LocalSocketState socketState);
54 void onSocketError(QLocalSocket::LocalSocketError socketError);
55 void readAllBytesFromSocket();
56
57private:
58 // NB! Must match the definition in ubuntu-keyboard. Not worth creating a shared header
59 // just for that.
60 struct SharedInfo {
61 qint32 keyboardX;
62 qint32 keyboardY;
63 qint32 keyboardWidth;
64 qint32 keyboardHeight;
65 };
66 void readInfoFromSocket();
67 void retryConnection();
68 void buildSocketFilePath();
69
70 int m_consecutiveAttempts;
71
72 QLocalSocket m_socket;
73 qint32 m_lastX;
74 qint32 m_lastY;
75 qint32 m_lastWidth;
76 qint32 m_lastHeight;
77 QTimer m_connectionRetryTimer;
78
79 // Path to the socket file created by ubuntu-keyboard
80 QString m_socketFilePath;
81
82 static UbuntuKeyboardInfo* m_instance;
83};
84
85} // namespace qtmir
86
87#endif // UBUNTU_KEYBOARD_INFO_H
880
=== modified file 'miral-qt/src/platforms/mirserver/logging.cpp'
--- miral-qt/src/platforms/mirserver/logging.cpp 2016-06-01 22:06:51 +0000
+++ miral-qt/src/platforms/mirserver/logging.cpp 2016-07-26 12:46:18 +0000
@@ -24,3 +24,4 @@
24Q_LOGGING_CATEGORY(QTMIR_CLIPBOARD, "qtmir.clipboard")24Q_LOGGING_CATEGORY(QTMIR_CLIPBOARD, "qtmir.clipboard")
25Q_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES, "qtmir.sensor")25Q_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES, "qtmir.sensor")
26Q_LOGGING_CATEGORY(QTMIR_SCREENS, "qtmir.screens")26Q_LOGGING_CATEGORY(QTMIR_SCREENS, "qtmir.screens")
27Q_LOGGING_CATEGORY(QTMIR_DBUS, "qtmir.dbus", QtWarningMsg)
2728
=== modified file 'miral-qt/src/platforms/mirserver/logging.h'
--- miral-qt/src/platforms/mirserver/logging.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/platforms/mirserver/logging.h 2016-07-26 12:46:18 +0000
@@ -26,5 +26,6 @@
26Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT)26Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT)
27Q_DECLARE_LOGGING_CATEGORY(QTMIR_CLIPBOARD)27Q_DECLARE_LOGGING_CATEGORY(QTMIR_CLIPBOARD)
28Q_DECLARE_LOGGING_CATEGORY(QTMIR_SCREENS)28Q_DECLARE_LOGGING_CATEGORY(QTMIR_SCREENS)
29Q_DECLARE_LOGGING_CATEGORY(QTMIR_DBUS)
2930
30#endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H31#endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H
3132
=== modified file 'miral-qt/src/platforms/mirserver/mirwindowmanager.cpp'
--- miral-qt/src/platforms/mirserver/mirwindowmanager.cpp 2016-06-07 18:03:38 +0000
+++ miral-qt/src/platforms/mirserver/mirwindowmanager.cpp 2016-07-26 12:46:18 +0000
@@ -197,14 +197,19 @@
197 const mir::shell::SurfaceSpecification& modifications)197 const mir::shell::SurfaceSpecification& modifications)
198{198{
199 QMutexLocker lock(&SurfaceObserver::mutex);199 QMutexLocker lock(&SurfaceObserver::mutex);
200
201 if (modifications.name.is_set()) {
202 surface->rename(modifications.name.value());
203 }
204
205 if (modifications.input_shape.is_set()) {
206 surface->set_input_region(modifications.input_shape.value());
207 }
208
200 SurfaceObserver *observer = SurfaceObserver::observerForSurface(surface.get());209 SurfaceObserver *observer = SurfaceObserver::observerForSurface(surface.get());
201 if (observer) {210 if (observer) {
202 observer->notifySurfaceModifications(modifications);211 observer->notifySurfaceModifications(modifications);
203 }212 }
204
205 if (modifications.name.is_set()) {
206 surface->rename(modifications.name.value());
207 }
208}213}
209214
210std::shared_ptr<MirWindowManager> MirWindowManager::create(215std::shared_ptr<MirWindowManager> MirWindowManager::create(
211216
=== modified file 'miral-qt/src/platforms/mirserver/surfaceobserver.cpp'
--- miral-qt/src/platforms/mirserver/surfaceobserver.cpp 2016-06-01 22:06:51 +0000
+++ miral-qt/src/platforms/mirserver/surfaceobserver.cpp 2016-07-26 12:46:18 +0000
@@ -28,6 +28,22 @@
28#include <mir/geometry/size.h>28#include <mir/geometry/size.h>
29#include <mir/shell/surface_specification.h>29#include <mir/shell/surface_specification.h>
3030
31namespace {
32
33QRect calculateBoundingRect(const std::vector<mir::geometry::Rectangle> &rectVector)
34{
35 QRect boundingRect;
36 for (auto mirRect : rectVector) {
37 boundingRect |= QRect(mirRect.top_left.x.as_int(),
38 mirRect.top_left.y.as_int(),
39 mirRect.size.width.as_int(),
40 mirRect.size.height.as_int());
41 }
42 return boundingRect;
43}
44
45} // anonymous namespace
46
31QMap<const mir::scene::Surface*, SurfaceObserver*> SurfaceObserver::m_surfaceToObserverMap;47QMap<const mir::scene::Surface*, SurfaceObserver*> SurfaceObserver::m_surfaceToObserverMap;
32QMutex SurfaceObserver::mutex;48QMutex SurfaceObserver::mutex;
3349
@@ -154,6 +170,10 @@
154 if (modifications.shell_chrome.is_set()) {170 if (modifications.shell_chrome.is_set()) {
155 Q_EMIT shellChromeChanged(modifications.shell_chrome.value());171 Q_EMIT shellChromeChanged(modifications.shell_chrome.value());
156 }172 }
173 if (modifications.input_shape.is_set()) {
174 QRect qRect = calculateBoundingRect(modifications.input_shape.value());
175 Q_EMIT inputBoundsChanged(qRect);
176 }
157}177}
158178
159SurfaceObserver *SurfaceObserver::observerForSurface(const mir::scene::Surface *surface)179SurfaceObserver *SurfaceObserver::observerForSurface(const mir::scene::Surface *surface)
160180
=== modified file 'miral-qt/src/platforms/mirserver/surfaceobserver.h'
--- miral-qt/src/platforms/mirserver/surfaceobserver.h 2016-06-01 22:06:51 +0000
+++ miral-qt/src/platforms/mirserver/surfaceobserver.h 2016-07-26 12:46:18 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2014-2015 Canonical, Ltd.2 * Copyright (C) 2014-2016 Canonical, Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it under4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -22,6 +22,7 @@
22#include <QObject>22#include <QObject>
23#include <QMap>23#include <QMap>
24#include <QMutex>24#include <QMutex>
25#include <QRect>
25#include <QSize>26#include <QSize>
26#include <mir/scene/surface_observer.h>27#include <mir/scene/surface_observer.h>
2728
@@ -84,6 +85,7 @@
84 void widthIncrementChanged(int);85 void widthIncrementChanged(int);
85 void heightIncrementChanged(int);86 void heightIncrementChanged(int);
86 void shellChromeChanged(MirShellChrome);87 void shellChromeChanged(MirShellChrome);
88 void inputBoundsChanged(const QRect &rect);
8789
88private:90private:
89 QCursor createQCursorFromMirCursorImage(const mir::graphics::CursorImage &cursorImage);91 QCursor createQCursorFromMirCursorImage(const mir::graphics::CursorImage &cursorImage);
9092
=== modified file 'miral-qt/tests/framework/fake_mirsurface.h'
--- miral-qt/tests/framework/fake_mirsurface.h 2016-07-25 13:48:41 +0000
+++ miral-qt/tests/framework/fake_mirsurface.h 2016-07-26 12:46:18 +0000
@@ -76,6 +76,7 @@
76 Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }76 Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
7777
78 bool focused() const override { return false; }78 bool focused() const override { return false; }
79 QRect inputBounds() const override { return QRect(0,0,10,10); }
7980
80 void requestFocus() override {81 void requestFocus() override {
81 Q_EMIT focusRequested();82 Q_EMIT focusRequested();
@@ -110,6 +111,7 @@
110 void setFocused(bool focus) override;111 void setFocused(bool focus) override;
111112
112 void setViewActiveFocus(qintptr, bool) override {};113 void setViewActiveFocus(qintptr, bool) override {};
114 bool activeFocus() const override { return false; }
113115
114 void mousePressEvent(QMouseEvent *) override;116 void mousePressEvent(QMouseEvent *) override;
115 void mouseMoveEvent(QMouseEvent *) override;117 void mouseMoveEvent(QMouseEvent *) override;
@@ -132,6 +134,8 @@
132134
133 SessionInterface* session() override { return m_session; }135 SessionInterface* session() override { return m_session; }
134136
137 bool inputAreaContains(const QPoint &) const override { return true; }
138
135public Q_SLOTS:139public Q_SLOTS:
136 void onCompositorSwappedBuffers() override;140 void onCompositorSwappedBuffers() override;
137141
138142
=== modified file 'miral-qt/tests/framework/fake_session.h'
--- miral-qt/tests/framework/fake_session.h 2016-06-07 20:32:04 +0000
+++ miral-qt/tests/framework/fake_session.h 2016-07-26 12:46:18 +0000
@@ -58,6 +58,10 @@
5858
59 void close() override;59 void close() override;
6060
61 bool activeFocus() const override { return false; }
62
63 pid_t pid() const override { return 0; }
64
61 // For SessionManager use65 // For SessionManager use
6266
63 void addChildSession(SessionInterface*) override;67 void addChildSession(SessionInterface*) override;

Subscribers

People subscribed via source and target branches