Merge lp:~dandrader/ubuntu-keyboard/fix_lp1234600 into lp:ubuntu-keyboard

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Thomas Voß
Approved revision: 66
Merged at revision: 68
Proposed branch: lp:~dandrader/ubuntu-keyboard/fix_lp1234600
Merge into: lp:ubuntu-keyboard
Diff against target: 151 lines (+91/-4)
2 files modified
src/plugin/ubuntuapplicationapiwrapper.cpp (+70/-1)
src/plugin/ubuntuapplicationapiwrapper.h (+21/-3)
To merge this branch: bzr merge lp:~dandrader/ubuntu-keyboard/fix_lp1234600
Reviewer Review Type Date Requested Status
Thomas Voß (community) Approve
Michał Sawicz Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+190189@code.launchpad.net

Commit message

Publish keyboard info on a socket so that unity-mir can have it

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.

That all should go away 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 :

Wow that's low level ;D But it works :)

review: Approve
Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM, although we should refactor the overall osk/im setup asap.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/ubuntuapplicationapiwrapper.cpp'
2--- src/plugin/ubuntuapplicationapiwrapper.cpp 2013-08-29 11:23:23 +0000
3+++ src/plugin/ubuntuapplicationapiwrapper.cpp 2013-10-09 16:58:20 +0000
4@@ -28,12 +28,27 @@
5 #include <QtGlobal>
6 #include <QByteArray>
7
8+namespace {
9+ const char gServerName[] = "ubuntu-keyboard-info";
10+}
11+
12 UbuntuApplicationApiWrapper::UbuntuApplicationApiWrapper()
13- : m_runningOnMir(false)
14+ : m_runningOnMir(false),
15+ m_clientConnection(0)
16 {
17 if (qgetenv("QT_QPA_PLATFORM") == "ubuntumirclient") {
18 m_runningOnMir = true;
19 }
20+
21+ if (m_runningOnMir) {
22+ connect(&m_localServer, &QLocalServer::newConnection,
23+ this, &UbuntuApplicationApiWrapper::onNewConnection);
24+ bool ok = m_localServer.listen(gServerName);
25+ if (!ok) {
26+ qWarning() << "UbuntuApplicationApiWrapper: failed to listen for connections on"
27+ << gServerName;
28+ }
29+ }
30 }
31
32 void UbuntuApplicationApiWrapper::reportOSKVisible(const int x, const int y, const int width, const int height)
33@@ -48,6 +63,8 @@
34 Q_UNUSED(width)
35 Q_UNUSED(height)
36 #endif
37+
38+ sendInfoToClientConnection(width, height);
39 }
40
41 void UbuntuApplicationApiWrapper::reportOSKInvisible()
42@@ -68,3 +85,55 @@
43 #endif
44 }
45
46+void UbuntuApplicationApiWrapper::sendInfoToClientConnection(int width, int height)
47+{
48+ if (!m_clientConnection
49+ || m_clientConnection->state() != QLocalSocket::ConnectedState) {
50+ // can't do it
51+ return;
52+ }
53+
54+ struct SharedInfo sharedInfo;
55+ sharedInfo.keyboardWidth = width;
56+ sharedInfo.keyboardHeight = height;
57+ const qint64 sharedInfoSize = sizeof(struct SharedInfo);
58+ qint64 bytesWritten = m_clientConnection->write(reinterpret_cast<char *>(&sharedInfo),
59+ sharedInfoSize);
60+
61+ if (bytesWritten < 0) {
62+ qWarning("UbuntuApplicationApiWrapper: Failed to write bytes on client connection");
63+ } else if (bytesWritten != sharedInfoSize) {
64+ // Could try sending the remaining bytes until completion but it's really unlikely that
65+ // this situation will occur
66+ qWarning() << "UbuntuApplicationApiWrapper: tried to write" << sharedInfoSize << "bytes"
67+ "but only" << bytesWritten << "went through";
68+ }
69+}
70+
71+void UbuntuApplicationApiWrapper::onNewConnection()
72+{
73+ if (m_clientConnection)
74+ return; // ignore it. for simplicity we care to serve only one client (unity8-mir)
75+
76+ m_clientConnection = m_localServer.nextPendingConnection();
77+ connect(m_clientConnection, &QLocalSocket::disconnected,
78+ this, &UbuntuApplicationApiWrapper::onClientDisconnected);
79+
80+ typedef void (QLocalSocket::*MemberFunctionType)(QLocalSocket::LocalSocketError);
81+ MemberFunctionType funcPointer = &QLocalSocket::error;
82+ connect(m_clientConnection, funcPointer,
83+ this, &UbuntuApplicationApiWrapper::onClientError);
84+}
85+
86+void UbuntuApplicationApiWrapper::onClientDisconnected()
87+{
88+ delete m_clientConnection;
89+ m_clientConnection = 0;
90+}
91+
92+void UbuntuApplicationApiWrapper::onClientError(QLocalSocket::LocalSocketError socketError)
93+{
94+ Q_UNUSED(socketError);
95+ delete m_clientConnection;
96+ m_clientConnection = 0;
97+}
98
99=== modified file 'src/plugin/ubuntuapplicationapiwrapper.h'
100--- src/plugin/ubuntuapplicationapiwrapper.h 2013-08-23 12:11:19 +0000
101+++ src/plugin/ubuntuapplicationapiwrapper.h 2013-10-09 16:58:20 +0000
102@@ -17,6 +17,10 @@
103 #ifndef UBUNTUAPPLICATIONAPIWRAPPER_H
104 #define UBUNTUAPPLICATIONAPIWRAPPER_H
105
106+#include <QObject>
107+#include <QLocalServer>
108+#include <QLocalSocket>
109+
110 /*
111 * Class: UbuntuApplicationApiWrapper
112 * The OSK-related functions in the ubuntu application api are marked as deprecated.
113@@ -24,12 +28,11 @@
114 * we are running on: if SurfaceFlinger-based, call the deprecated API, else NOOP.
115 *
116 * Have added other little methods to help smooth the transition.
117- *
118- * Once we discard the SurfaceFlinger-base, much of this can be removed.
119 */
120
121-class UbuntuApplicationApiWrapper
122+class UbuntuApplicationApiWrapper : public QObject
123 {
124+ Q_OBJECT
125 public:
126 UbuntuApplicationApiWrapper();
127
128@@ -38,8 +41,23 @@
129 void reportOSKVisible(const int, const int, const int, const int);
130 void reportOSKInvisible();
131
132+private Q_SLOTS:
133+ void onNewConnection();
134+ void onClientDisconnected();
135+ void onClientError(QLocalSocket::LocalSocketError socketError);
136+
137 private:
138+ // NB! Must match the definition in unity-mir. Not worth creating a shared header
139+ // just for that.
140+ struct SharedInfo {
141+ qint32 keyboardWidth;
142+ qint32 keyboardHeight;
143+ };
144+ void sendInfoToClientConnection(int width, int height);
145+
146 bool m_runningOnMir;
147+ QLocalServer m_localServer;
148+ QLocalSocket *m_clientConnection;
149 };
150
151 #endif // UBUNTUAPPLICATIONAPIWRAPPER_H

Subscribers

People subscribed via source and target branches