Merge lp:~dandrader/unity-mir/fix_lp1234600 into lp:unity-mir

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Michał Sawicz
Approved revision: 103
Merged at revision: 111
Proposed branch: lp:~dandrader/unity-mir/fix_lp1234600
Merge into: lp:unity-mir
Diff against target: 277 lines (+177/-9)
5 files modified
src/modules/Unity/Application/Application.pro (+3/-1)
src/modules/Unity/Application/OSKController.qml (+8/-8)
src/modules/Unity/Application/plugin.cpp (+2/-0)
src/modules/Unity/Application/ubuntukeyboardinfo.cpp (+103/-0)
src/modules/Unity/Application/ubuntukeyboardinfo.h (+61/-0)
To merge this branch: bzr merge lp:~dandrader/unity-mir/fix_lp1234600
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+190190@code.launchpad.net

Commit message

Replace hardcoded keyboard size with info straight from ubuntu-keyboard

Have a communication channel between ubuntu-keyboard and unity-mir where
the former hands out all the information about itself that unity-mir might
be interested into.

Note that I'm just replacing a crude hack with a more sophisticated one.
That all should go away (including InputFilters) once a proper architecure gets
implemented.

Fixes LP#1234600

Description of the change

Not thoroughly tested.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Worky worky!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/Application.pro'
2--- src/modules/Unity/Application/Application.pro 2013-09-26 10:02:15 +0000
3+++ src/modules/Unity/Application/Application.pro 2013-10-09 16:59:45 +0000
4@@ -29,7 +29,8 @@
5 mirsurfacemanager.cpp \
6 inputarea.cpp \
7 inputfilterarea.cpp \
8- shellinputarea.cpp
9+ shellinputarea.cpp \
10+ ubuntukeyboardinfo.cpp
11
12 HEADERS += application_manager.h \
13 application.h \
14@@ -42,6 +43,7 @@
15 shellinputarea.h \
16 inputarea.h \
17 inputfilterarea.h \
18+ ubuntukeyboardinfo.h \
19 /usr/include/unity/shell/application/ApplicationManagerInterface.h \
20 /usr/include/unity/shell/application/ApplicationInfoInterface.h
21
22
23=== modified file 'src/modules/Unity/Application/OSKController.qml'
24--- src/modules/Unity/Application/OSKController.qml 2013-10-08 12:00:13 +0000
25+++ src/modules/Unity/Application/OSKController.qml 2013-10-09 16:59:45 +0000
26@@ -23,6 +23,10 @@
27 property variant __oskSurface: null
28 readonly property bool enabled: __oskSurface !== null
29
30+ UbuntuKeyboardInfo {
31+ id: ubuntuKeyboardInfo
32+ }
33+
34 Connections {
35 target: SurfaceManager
36 onSurfaceCreated: {
37@@ -50,10 +54,6 @@
38 InputArea {
39 id: oskInputArea
40
41- //FIXME(greyback) hardcoded - taken from maliit - Qt.inputMethod.keyboardRectangle not working
42- readonly property real heightInPortrait: units.gu(30)
43- readonly property real heightInLandscape: units.gu(20)
44-
45 readonly property int orientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
46
47 surface: __oskSurface
48@@ -64,7 +64,7 @@
49 states: [
50 State {
51 name: "0"
52- PropertyChanges { target: oskInputArea; height: heightInPortrait; width: undefined }
53+ PropertyChanges { target: oskInputArea; height: ubuntuKeyboardInfo.height; width: undefined }
54 AnchorChanges { target: oskInputArea; anchors {
55 top: undefined
56 bottom: parent.bottom
57@@ -74,7 +74,7 @@
58 },
59 State {
60 name: "180"
61- PropertyChanges { target: oskInputArea; height: heightInPortrait; width: undefined }
62+ PropertyChanges { target: oskInputArea; height: ubuntuKeyboardInfo.height; width: undefined }
63 AnchorChanges { target: oskInputArea; anchors {
64 top: parent.top
65 bottom: undefined
66@@ -84,7 +84,7 @@
67 },
68 State {
69 name: "270"
70- PropertyChanges { target: oskInputArea; height: undefined; width: heightInLandscape }
71+ PropertyChanges { target: oskInputArea; height: undefined; width: ubuntuKeyboardInfo.height }
72 AnchorChanges { target: oskInputArea; anchors {
73 top: parent.top
74 bottom: parent.bottom
75@@ -94,7 +94,7 @@
76 },
77 State {
78 name: "90"
79- PropertyChanges { target: oskInputArea; height: undefined; width: heightInLandscape }
80+ PropertyChanges { target: oskInputArea; height: undefined; width: ubuntuKeyboardInfo.height }
81 AnchorChanges { target: oskInputArea; anchors {
82 top: parent.top
83 bottom: parent.bottom
84
85=== modified file 'src/modules/Unity/Application/plugin.cpp'
86--- src/modules/Unity/Application/plugin.cpp 2013-09-11 13:20:08 +0000
87+++ src/modules/Unity/Application/plugin.cpp 2013-10-09 16:59:45 +0000
88@@ -26,6 +26,7 @@
89 #include "inputarea.h"
90 #include "inputfilterarea.h"
91 #include "shellinputarea.h"
92+#include "ubuntukeyboardinfo.h"
93
94 // unity-mir
95 #include "logging.h"
96@@ -71,6 +72,7 @@
97 qmlRegisterType<InputArea>(uri, 0, 1, "InputArea");
98 qmlRegisterType<ShellInputArea>(uri, 0, 1, "ShellInputArea");
99 qmlRegisterType<InputFilterArea>(uri, 0, 1, "InputFilterArea");
100+ qmlRegisterType<UbuntuKeyboardInfo>(uri, 0, 1, "UbuntuKeyboardInfo");
101 }
102
103 virtual void initializeEngine(QQmlEngine *engine, const char *uri)
104
105=== added file 'src/modules/Unity/Application/ubuntukeyboardinfo.cpp'
106--- src/modules/Unity/Application/ubuntukeyboardinfo.cpp 1970-01-01 00:00:00 +0000
107+++ src/modules/Unity/Application/ubuntukeyboardinfo.cpp 2013-10-09 16:59:45 +0000
108@@ -0,0 +1,103 @@
109+/*
110+ * Copyright (C) 2013 Canonical, Ltd.
111+ *
112+ * This program is free software: you can redistribute it and/or modify it under
113+ * the terms of the GNU Lesser General Public License version 3, as published by
114+ * the Free Software Foundation.
115+ *
116+ * This program is distributed in the hope that it will be useful, but WITHOUT
117+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
118+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
119+ * Lesser General Public License for more details.
120+ *
121+ * You should have received a copy of the GNU Lesser General Public License
122+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
123+ */
124+
125+#include "ubuntukeyboardinfo.h"
126+
127+#include <QTimer>
128+
129+namespace {
130+ const int gConnectionAttemptIntervalMs = 5000;
131+ const int gMaxFailedAttempts = 10;
132+ const char gServerName[] = "ubuntu-keyboard-info";
133+}
134+
135+UbuntuKeyboardInfo::UbuntuKeyboardInfo(QObject *parent)
136+ : QObject(parent),
137+ m_failedAttempts(0),
138+ m_lastWidth(0),
139+ m_lastHeight(0)
140+{
141+ connect(&m_socket, &QLocalSocket::connected, this, &UbuntuKeyboardInfo::onConnected);
142+ connect(&m_socket, &QLocalSocket::disconnected, this, &UbuntuKeyboardInfo::onDisconnected);
143+ connect(&m_socket, &QIODevice::readyRead,
144+ this, &UbuntuKeyboardInfo::readAllBytesFromSocket);
145+
146+ typedef void (QLocalSocket::*MemberFunctionType)(QLocalSocket::LocalSocketError);
147+ MemberFunctionType funcPointer = &QLocalSocket::error;
148+ connect(&m_socket, funcPointer,
149+ this, &UbuntuKeyboardInfo::onSocketError);
150+
151+ tryConnectingToServer();
152+}
153+
154+void UbuntuKeyboardInfo::tryConnectingToServer()
155+{
156+ m_socket.connectToServer(gServerName, QIODevice::ReadOnly);
157+}
158+
159+void UbuntuKeyboardInfo::onConnected()
160+{
161+ m_failedAttempts = 0;
162+}
163+
164+void UbuntuKeyboardInfo::onDisconnected()
165+{
166+ qWarning("UbuntuKeyboardInfo - disconnected");
167+}
168+
169+void UbuntuKeyboardInfo::onSocketError(QLocalSocket::LocalSocketError socketError)
170+{
171+ // Polling every gConnectionAttemptIntervalMs. Not the best approach but could be worse.
172+ Q_UNUSED(socketError);
173+ ++m_failedAttempts;
174+ if (m_failedAttempts < gMaxFailedAttempts) {
175+ QTimer::singleShot(gConnectionAttemptIntervalMs, this, SLOT(tryConnectingToServer()));
176+ } else {
177+ qCritical() << "Failed to connect to" << gServerName << "after"
178+ << m_failedAttempts << "failed attempts";
179+ }
180+}
181+
182+void UbuntuKeyboardInfo::readAllBytesFromSocket()
183+{
184+ while (m_socket.bytesAvailable() > 0) {
185+ readInfoFromSocket();
186+ }
187+}
188+
189+void UbuntuKeyboardInfo::readInfoFromSocket()
190+{
191+ const size_t sharedInfoSize = sizeof(struct SharedInfo);
192+ QByteArray bytes = m_socket.read(sharedInfoSize);
193+ if (bytes.size() != sharedInfoSize) {
194+ qWarning() << "UbuntuKeyboardInfo: expected to receive" << sharedInfoSize
195+ << "but got" << bytes.size();
196+ return;
197+ }
198+
199+ {
200+ struct SharedInfo *sharedInfo = reinterpret_cast<struct SharedInfo*>(bytes.data());
201+ if (m_lastWidth != sharedInfo->keyboardWidth) {
202+ m_lastWidth = sharedInfo->keyboardWidth;
203+ Q_EMIT widthChanged(m_lastWidth);
204+ }
205+
206+ if (m_lastHeight != sharedInfo->keyboardHeight) {
207+ m_lastHeight = sharedInfo->keyboardHeight;
208+ Q_EMIT heightChanged(m_lastHeight);
209+ }
210+ }
211+}
212
213=== added file 'src/modules/Unity/Application/ubuntukeyboardinfo.h'
214--- src/modules/Unity/Application/ubuntukeyboardinfo.h 1970-01-01 00:00:00 +0000
215+++ src/modules/Unity/Application/ubuntukeyboardinfo.h 2013-10-09 16:59:45 +0000
216@@ -0,0 +1,61 @@
217+/*
218+ * Copyright (C) 2013 Canonical, Ltd.
219+ *
220+ * This program is free software: you can redistribute it and/or modify it under
221+ * the terms of the GNU Lesser General Public License version 3, as published by
222+ * the Free Software Foundation.
223+ *
224+ * This program is distributed in the hope that it will be useful, but WITHOUT
225+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
226+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
227+ * Lesser General Public License for more details.
228+ *
229+ * You should have received a copy of the GNU Lesser General Public License
230+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
231+ */
232+
233+#ifndef UBUNTU_KEYBOARD_INFO_H
234+#define UBUNTU_KEYBOARD_INFO_H
235+
236+#include <QLocalSocket>
237+
238+// Temporary solution to get information about the onscreen keyboard
239+// This shouldn't be needed once the OSK is a properly sized surface
240+// instead of a fullscreen one.
241+class UbuntuKeyboardInfo : public QObject {
242+ Q_OBJECT
243+ Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
244+ Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
245+public:
246+ UbuntuKeyboardInfo(QObject *parent = 0);
247+ qreal width() const { return m_lastWidth; }
248+ qreal height() const { return m_lastHeight; }
249+
250+Q_SIGNALS:
251+ void widthChanged(qreal width);
252+ void heightChanged(qreal height);
253+
254+private Q_SLOTS:
255+ void tryConnectingToServer();
256+ void onConnected();
257+ void onDisconnected();
258+ void onSocketError(QLocalSocket::LocalSocketError socketError);
259+ void readAllBytesFromSocket();
260+
261+private:
262+ // NB! Must match the definition in ubuntu-keyboard. Not worth creating a shared header
263+ // just for that.
264+ struct SharedInfo {
265+ qint32 keyboardWidth;
266+ qint32 keyboardHeight;
267+ };
268+ void readInfoFromSocket();
269+
270+ int m_failedAttempts;
271+
272+ QLocalSocket m_socket;
273+ qint32 m_lastWidth;
274+ qint32 m_lastHeight;
275+};
276+
277+#endif // UBUNTU_KEYBOARD_INFO_H

Subscribers

People subscribed via source and target branches