Merge lp:~gerboland/qtubuntu/exposeOrientation into lp:qtubuntu

Proposed by Gerry Boland
Status: Merged
Approved by: Daniel d'Andrada
Approved revision: 249
Merged at revision: 243
Proposed branch: lp:~gerboland/qtubuntu/exposeOrientation
Merge into: lp:qtubuntu
Diff against target: 323 lines (+120/-54)
7 files modified
debian/control (+1/-1)
src/ubuntumirclient/input.cpp (+74/-0)
src/ubuntumirclient/input.h (+1/-0)
src/ubuntumirclient/orientationchangeevent_p.h (+36/-0)
src/ubuntumirclient/screen.cpp (+7/-45)
src/ubuntumirclient/screen.h (+0/-8)
src/ubuntumirclient/ubuntumirclient.pro (+1/-0)
To merge this branch: bzr merge lp:~gerboland/qtubuntu/exposeOrientation
Reviewer Review Type Date Requested Status
Daniel d'Andrada (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+232252@code.launchpad.net

Commit message

Expose Mir surface orientation property instead of connecting to orientation sensor directly

To post a comment you must log in.
244. By Gerry Boland

Depend on PAPI 2.2.1

245. By Gerry Boland

Alphabetize

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

In src/ubuntumirclient/input.cpp

"""
    LOG("ORIENTATION direction:%d", event->orientation.direction);
"""

Convert the enum value to a nice human-readable string, please.

""""
    Qt::ScreenOrientation orientation;
    switch (event->orientation.direction) {
    case U_ORIENTATION_NORMAL:
        orientation = Qt::PortraitOrientation;
        break;
    case U_ORIENTATION_LEFT:
        orientation = Qt::LandscapeOrientation;
        break;
    case U_ORIENTATION_INVERTED:
        orientation = Qt::InvertedPortraitOrientation;
        break;
    case U_ORIENTATION_RIGHT:
        orientation = Qt::InvertedLandscapeOrientation;
        break;
    default:
        DLOG("No such orientation %d", event->orientation.direction);
        return;
    }

    // Dispatch orientation event to [Platform]Screen, as that is where Qt reads it. Screen will handle
    // notifying Qt of the actual orientation change - done to prevent multiple Windows each creating
    // an identical orientation change event and passing it directly to Qt.
    // [Platform]Screen can also factor in the native orientation.
    QCoreApplication::postEvent(static_cast<UbuntuScreen*>(window->screen()->handle()),
                                new OrientationChangeEvent(OrientationChangeEvent::mType, orientation));
""""

Then please use the same nomenclature that the mir event uses in that internal OrientationChangeEvent, thus avoiding mentioning landscape or portrait at this point, which is misleading. You could stick with the QOrientationReading::Orientation enum.

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

> Then please use the same nomenclature that the mir event uses in that internal
> OrientationChangeEvent, thus avoiding mentioning landscape or portrait at this
> point, which is misleading. You could stick with the
> QOrientationReading::Orientation enum.

Can you explain your reasoning why this is misleading? We need to convert from Mir event nomenclature (normal,left,right,inverted) to QScreenOrientation (portrait, landscape, invertedlandscape, invertedportrait) somewhere, it struck me as a good idea to convert to Qt's definition as quickly as possible.

Do I understand you want me to add an intermediary 3rd nomenclature, the QOrientationReading::Orientation. So then we have Mir->QOrientationReading->QScreenOrientation ?

246. By Gerry Boland

Add text description for a debug output

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

> > Then please use the same nomenclature that the mir event uses in that
> internal
> > OrientationChangeEvent, thus avoiding mentioning landscape or portrait at
> this
> > point, which is misleading. You could stick with the
> > QOrientationReading::Orientation enum.
>
> Can you explain your reasoning why this is misleading? We need to convert from
> Mir event nomenclature (normal,left,right,inverted) to QScreenOrientation
> (portrait, landscape, invertedlandscape, invertedportrait) somewhere, it
> struck me as a good idea to convert to Qt's definition as quickly as possible.

Because in UbuntuInput::dispatchOrientationEvent you're doing a wrong conversion as you're assuming that the native orientation is portrait, just to later fix it in QScreen. By converting it to QOrientationReading you don't have to make any such assumptions. For what it's worth, QOrientationReading is also a "Qt definition".

>
> Do I understand you want me to add an intermediary 3rd nomenclature, the
> QOrientationReading::Orientation. So then we have
> Mir->QOrientationReading->QScreenOrientation ?

Yes. If I understood QOrientationReading correctly, it's a one-to-one mapping of the Mir enum.

But if you don't like that intermediate enum, then I'm fine if you store the Mir enum value in that internal QEvent as well. I just don't want the wrong conversion I mentioned above.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

"""
LOG("ORIENTATION direction: %d", nativeOrientationDirectionToStr(event->orientation.direction));
"""

Should be '%s', not '%d'. Did it work at all like that?

review: Needs Fixing
247. By Gerry Boland

oops, %s not %d

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
248. By Gerry Boland

Use QOrientationReading::Orientation in the OrientationChangeEvent

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

In src/ubuntumirclient/screen.cpp:

"""
- case QOrientationReading::LeftUp: {
+ case QOrientationReading::RightUp: {
             mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
- Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation;
+ Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation;
"""

This is wrong. The original code had the correct conversion.

"""
- case QOrientationReading::RightUp: {
+ case QOrientationReading::LeftUp: {
             mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
- Qt::PortraitOrientation : Qt::InvertedLandscapeOrientation;
+ Qt::PortraitOrientation : Qt::LandscapeOrientation;
"""

Same here.

See https://www.dropbox.com/s/4ctoecuq4269j5m/QtScreenOrientation.png?dl=0

review: Needs Fixing
249. By Gerry Boland

Undo changes to mapping of OrientationReading->ScreenOrientation, better the old way

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

Looking good.

review: Approve
250. By Gerry Boland

Dump dependency on papi to 2.4.0

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-07-09 17:17:05 +0000
3+++ debian/control 2014-09-19 12:18:46 +0000
4@@ -8,7 +8,7 @@
5 libfreetype6-dev,
6 libgles2-mesa-dev,
7 libglib2.0-dev,
8- libubuntu-application-api-dev (>= 2.2.0),
9+ libubuntu-application-api-dev (>= 2.4.0),
10 libudev-dev,
11 libxrender-dev,
12 libxkbcommon-dev,
13
14=== modified file 'src/ubuntumirclient/input.cpp'
15--- src/ubuntumirclient/input.cpp 2014-08-14 09:45:04 +0000
16+++ src/ubuntumirclient/input.cpp 2014-09-19 12:18:46 +0000
17@@ -18,8 +18,10 @@
18 #include "input.h"
19 #include "integration.h"
20 #include "nativeinterface.h"
21+#include "screen.h"
22 #include "window.h"
23 #include "logging.h"
24+#include "orientationchangeevent_p.h"
25
26 // Qt
27 #if !defined(QT_NO_DEBUG)
28@@ -36,6 +38,7 @@
29
30 // Platform API
31 #include <ubuntu/application/ui/input/event.h>
32+#include <ubuntu/application/ui/window_orientation.h>
33
34 #define LOG_EVENTS 0
35
36@@ -174,6 +177,10 @@
37 break;
38 case SURFACE_WEVENT_TYPE:
39 return "SURFACE_WEVENT_TYPE";
40+ break;
41+ case ORIENTATION_WEVENT_TYPE:
42+ return "ORIENTATION_WEVENT_TYPE";
43+ break;
44 default:
45 return "INVALID!";
46 }
47@@ -218,6 +225,9 @@
48 ubuntuEvent->window->handleSurfaceFocusChange(nativeEvent->surface.value == 1);
49 }
50 break;
51+ case ORIENTATION_WEVENT_TYPE:
52+ dispatchOrientationEvent(ubuntuEvent->window->window(), nativeEvent);
53+ break;
54 default:
55 DLOG("unhandled event type %d", nativeEvent->type);
56 }
57@@ -408,3 +418,67 @@
58
59 QWindowSystemInterface::handleKeyEvent(window, timestamp, keyType, sym, modifiers, text);
60 }
61+
62+#if (LOG_EVENTS != 0)
63+static const char* nativeOrientationDirectionToStr(const int orientation)
64+{
65+ switch (orientation) {
66+ case U_ORIENTATION_NORMAL:
67+ return "Normal";
68+ break;
69+ case U_ORIENTATION_LEFT:
70+ return "Left";
71+ break;
72+ case U_ORIENTATION_INVERTED:
73+ return "Inverted";
74+ break;
75+ case U_ORIENTATION_RIGHT:
76+ return "Right";
77+ break;
78+ default:
79+ return "INVALID!";
80+ }
81+}
82+#endif
83+
84+void UbuntuInput::dispatchOrientationEvent(QWindow* window, const void* ev)
85+{
86+ const WindowEvent* event = reinterpret_cast<const WindowEvent*>(ev);
87+
88+ #if (LOG_EVENTS != 0)
89+ // Orientation event logging.
90+ LOG("ORIENTATION direction: %s", nativeOrientationDirectionToStr(event->orientation.direction));
91+ #endif
92+
93+ if (!window->screen()) {
94+ DLOG("Window has no associated screen, dropping orientation event");
95+ return;
96+ }
97+
98+ QOrientationReading::Orientation orientation;
99+ switch (event->orientation.direction) {
100+ case U_ORIENTATION_NORMAL:
101+ orientation = QOrientationReading::TopUp;
102+ break;
103+ case U_ORIENTATION_LEFT:
104+ orientation = QOrientationReading::LeftUp;
105+ break;
106+ case U_ORIENTATION_INVERTED:
107+ orientation = QOrientationReading::TopDown;
108+ break;
109+ case U_ORIENTATION_RIGHT:
110+ orientation = QOrientationReading::RightUp;
111+ break;
112+ default:
113+ DLOG("No such orientation %d", event->orientation.direction);
114+ return;
115+ }
116+
117+ // Dispatch orientation event to [Platform]Screen, as that is where Qt reads it. Screen will handle
118+ // notifying Qt of the actual orientation change - done to prevent multiple Windows each creating
119+ // an identical orientation change event and passing it directly to Qt.
120+ // [Platform]Screen can also factor in the native orientation.
121+ QCoreApplication::postEvent(static_cast<UbuntuScreen*>(window->screen()->handle()),
122+ new OrientationChangeEvent(OrientationChangeEvent::mType, orientation));
123+}
124+
125
126=== modified file 'src/ubuntumirclient/input.h'
127--- src/ubuntumirclient/input.h 2014-07-15 12:45:14 +0000
128+++ src/ubuntumirclient/input.h 2014-09-19 12:18:46 +0000
129@@ -40,6 +40,7 @@
130 protected:
131 void dispatchKeyEvent(QWindow* window, const void* event);
132 void dispatchMotionEvent(QWindow* window, const void* event);
133+ void dispatchOrientationEvent(QWindow* window, const void* event);
134
135 private:
136 UbuntuClientIntegration* mIntegration;
137
138=== added file 'src/ubuntumirclient/orientationchangeevent_p.h'
139--- src/ubuntumirclient/orientationchangeevent_p.h 1970-01-01 00:00:00 +0000
140+++ src/ubuntumirclient/orientationchangeevent_p.h 2014-09-19 12:18:46 +0000
141@@ -0,0 +1,36 @@
142+/*
143+ * Copyright (C) 2014 Canonical, Ltd.
144+ *
145+ * This program is free software: you can redistribute it and/or modify it under
146+ * the terms of the GNU Lesser General Public License version 3, as published by
147+ * the Free Software Foundation.
148+ *
149+ * This program is distributed in the hope that it will be useful, but WITHOUT
150+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
151+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152+ * Lesser General Public License for more details.
153+ *
154+ * You should have received a copy of the GNU Lesser General Public License
155+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
156+ */
157+
158+#ifndef ORIENTATIONCHANGEEVENT_P_H
159+#define ORIENTATIONCHANGEEVENT_P_H
160+
161+#include <QEvent>
162+#include <QOrientationReading>
163+#include "logging.h"
164+
165+class OrientationChangeEvent : public QEvent {
166+public:
167+ OrientationChangeEvent(QEvent::Type type, QOrientationReading::Orientation orientation)
168+ : QEvent(type)
169+ , mOrientation(orientation)
170+ {
171+ }
172+
173+ static const QEvent::Type mType;
174+ QOrientationReading::Orientation mOrientation;
175+};
176+
177+#endif // ORIENTATIONCHANGEEVENT_P_H
178
179=== modified file 'src/ubuntumirclient/screen.cpp'
180--- src/ubuntumirclient/screen.cpp 2014-06-30 14:40:47 +0000
181+++ src/ubuntumirclient/screen.cpp 2014-09-19 12:18:46 +0000
182@@ -22,13 +22,10 @@
183 #include <qpa/qwindowsysteminterface.h>
184 #include <QtPlatformSupport/private/qeglconvenience_p.h>
185
186-// Qt sensors
187-#include <QtSensors/QOrientationSensor>
188-#include <QtSensors/QOrientationReading>
189-
190 // local
191 #include "screen.h"
192 #include "logging.h"
193+#include "orientationchangeevent_p.h"
194
195 // platform-api
196 #include <ubuntu/application/ui/display.h>
197@@ -85,21 +82,8 @@
198 }
199 #endif
200
201-class OrientationReadingEvent : public QEvent {
202-public:
203- OrientationReadingEvent(QEvent::Type type, QOrientationReading::Orientation orientation)
204- : QEvent(type)
205- , mOrientation(orientation) {
206- DLOG("OrientationReadingEvent::OrientationReadingEvent()");
207- }
208- ~OrientationReadingEvent() {
209- DLOG("OrientationReadingEvent::~OrientationReadingEvent()");
210- }
211- static const QEvent::Type mType;
212- QOrientationReading::Orientation mOrientation;
213-};
214
215-const QEvent::Type OrientationReadingEvent::mType =
216+const QEvent::Type OrientationChangeEvent::mType =
217 static_cast<QEvent::Type>(QEvent::registerEventType());
218
219
220@@ -171,31 +155,17 @@
221
222 // If it's a landscape device (i.e. some tablets), start in landscape, otherwise portrait
223 mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
224-
225- mOrientationSensor = new QOrientationSensor();
226- QObject::connect(mOrientationSensor, SIGNAL(readingChanged()), this, SLOT(onOrientationReadingChanged()));
227- mOrientationSensor->start();
228 }
229
230 UbuntuScreen::~UbuntuScreen()
231 {
232 eglTerminate(mEglDisplay);
233- delete mOrientationSensor;
234-}
235-
236-void UbuntuScreen::toggleSensors(const bool enable) const {
237- DLOG("UbuntuScreen::toggleSensors (this=%p, enable=%d)", this, enable);
238- if (enable)
239- mOrientationSensor->start();
240- else
241- mOrientationSensor->stop();
242 }
243
244 void UbuntuScreen::customEvent(QEvent* event) {
245- DLOG("UbuntuScreen::customEvent (event: %p)", event);
246 DASSERT(QThread::currentThread() == thread());
247
248- OrientationReadingEvent* oReadingEvent = static_cast<OrientationReadingEvent*>(event);
249+ OrientationChangeEvent* oReadingEvent = static_cast<OrientationChangeEvent*>(event);
250 switch (oReadingEvent->mOrientation) {
251 case QOrientationReading::LeftUp: {
252 mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
253@@ -218,20 +188,12 @@
254 break;
255 }
256 default: {
257- DLOG("Unknown orientation.");
258+ DLOG("UbuntuScreen::customEvent - Unknown orientation.");
259+ return;
260 }
261 }
262
263 // Raise the event signal so that client apps know the orientation changed
264 QWindowSystemInterface::handleScreenOrientationChange(screen(), mCurrentOrientation);
265-}
266-
267-void UbuntuScreen::onOrientationReadingChanged() {
268- DLOG("UbuntuScreen::onOrientationReadingChanged");
269- DASSERT(mOrientationSensor != NULL);
270-
271- // Make sure to switch to the main Qt thread context
272- QCoreApplication::postEvent(this, new OrientationReadingEvent(
273- OrientationReadingEvent::mType, mOrientationSensor->reading()->orientation()));
274-}
275-
276+ DLOG("UbuntuScreen::customEvent - handling orientation change to %d", mCurrentOrientation);
277+}
278
279=== modified file 'src/ubuntumirclient/screen.h'
280--- src/ubuntumirclient/screen.h 2014-06-30 14:40:47 +0000
281+++ src/ubuntumirclient/screen.h 2014-09-19 12:18:46 +0000
282@@ -21,8 +21,6 @@
283 #include <QSurfaceFormat>
284 #include <EGL/egl.h>
285
286-class QOrientationSensor;
287-
288 class UbuntuScreen : public QObject, public QPlatformScreen
289 {
290 Q_OBJECT
291@@ -44,20 +42,14 @@
292 EGLConfig eglConfig() const { return mEglConfig; }
293 EGLNativeDisplayType eglNativeDisplay() const { return mEglNativeDisplay; }
294
295- void toggleSensors(bool enable) const;
296-
297 // QObject methods.
298 void customEvent(QEvent* event);
299
300-public Q_SLOTS:
301- void onOrientationReadingChanged();
302-
303 private:
304 QRect mGeometry;
305 QRect mAvailableGeometry;
306 Qt::ScreenOrientation mNativeOrientation;
307 Qt::ScreenOrientation mCurrentOrientation;
308- QOrientationSensor* mOrientationSensor;
309 QImage::Format mFormat;
310 int mDepth;
311 QSurfaceFormat mSurfaceFormat;
312
313=== modified file 'src/ubuntumirclient/ubuntumirclient.pro'
314--- src/ubuntumirclient/ubuntumirclient.pro 2014-08-14 13:18:24 +0000
315+++ src/ubuntumirclient/ubuntumirclient.pro 2014-09-19 12:18:46 +0000
316@@ -37,6 +37,7 @@
317 integration.h \
318 logging.h \
319 nativeinterface.h \
320+ orientationchangeevent_p.h \
321 platformservices.h \
322 plugin.h \
323 screen.h \

Subscribers

People subscribed via source and target branches