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

Proposed by Gerry Boland
Status: Merged
Approved by: Michael Zanetti
Approved revision: 244
Merged at revision: 255
Proposed branch: lp:~gerboland/qtmir/exposeOrientation
Merge into: lp:qtmir
Diff against target: 325 lines (+170/-2)
6 files modified
src/modules/Unity/Application/mirsurfaceitem.cpp (+48/-0)
src/modules/Unity/Application/mirsurfaceitem.h (+5/-0)
src/platforms/mirserver/logging.h (+1/-0)
src/platforms/mirserver/mirserverintegration.cpp (+11/-0)
src/platforms/mirserver/screen.cpp (+95/-2)
src/platforms/mirserver/screen.h (+10/-0)
To merge this branch: bzr merge lp:~gerboland/qtmir/exposeOrientation
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Abstain
Daniel d'Andrada (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+232485@code.launchpad.net

Commit message

Expose Mir surface orientation property to QML

Description of the change

Expose Mir surface orientation property to QML

 * Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~gerboland/unity8/orientationLock/+merge/232484
https://code.launchpad.net/~gerboland/qtubuntu/exposeOrientation/+merge/232252
https://code.launchpad.net/~gerboland/platform-api/exposeOrientation/+merge/232250

 * Did you perform an exploratory manual test run of your code change and any related functionality?
Y

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

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
Daniel d'Andrada (dandrader) wrote :

Now that prompts-in-prompts has landed, there are merge conflicts in:
src/modules/Unity/Application/mirsurfaceitem.cpp
src/modules/Unity/Application/mirsurfaceitem.h

review: Needs Fixing
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/modules/Unity/Application/mirsurfaceitem.cpp:

"""
    case Qt::PortraitOrientation:
        mirOrientation = mir_orientation_normal;
"""

Here you're assuming that the screen aspect-ratio is portrait, which is not always the case.

Qt::ScreenOrientation values do not map directly to MirOrientation ones. The two enums express orientation differently. Trying to shoehorn one into the other is no good.

Either do a proper translation between the two or make MirSurfaceItem::orientation use an enum that does match with MirOrientation.

------------------------

In src/platforms/mirserver/screen.cpp:

Who's calling Screen::toggleSensors()?
It was supposed to be called whenever the display goes on and off.

---------------------------

In src/platforms/mirserver/screen.cpp:

"""
    QCoreApplication::postEvent(this, new OrientationReadingEvent(
                                    OrientationReadingEvent::m_type, m_orientationSensor->reading()->orientation()));
"""

Weird indentation.

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

> In src/modules/Unity/Application/mirsurfaceitem.cpp:
>
> """
> case Qt::PortraitOrientation:
> mirOrientation = mir_orientation_normal;
> """
>
> Here you're assuming that the screen aspect-ratio is portrait, which is not
> always the case.

Why would we care here? This is just the shell telling an application: this is your orientation now.

> Qt::ScreenOrientation values do not map directly to MirOrientation ones. The
> two enums express orientation differently. Trying to shoehorn one into the
> other is no good.

I think it's a bad idea that there are 2 ways to express orientation, and we should just use one. You don't like that I ignore PrimaryOrientation?

> Either do a proper translation between the two or make
> MirSurfaceItem::orientation use an enum that does match with MirOrientation.

I prefer using a subset of an existing enum than creating a new enum. QML already knows about Qt::*Orientation - it would be a waste to duplicate it IMO.

> ------------------------
>
> In src/platforms/mirserver/screen.cpp:
>
> Who's calling Screen::toggleSensors()?
> It was supposed to be called whenever the display goes on and off.

Nobody yet. I had hoped to wire it up to the hide/show window event for display off/on, but that event doesn't happen. I'm not sure what signal to wire it up to still. Will be later MR.

> ---------------------------
>
> In src/platforms/mirserver/screen.cpp:
>
> """
> QCoreApplication::postEvent(this, new OrientationReadingEvent(
> OrientationReadingEvent::m_type,
> m_orientationSensor->reading()->orientation()));
> """
>
> Weird indentation.
done

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

> > In src/modules/Unity/Application/mirsurfaceitem.cpp:
> >
> > """
> > case Qt::PortraitOrientation:
> > mirOrientation = mir_orientation_normal;
> > """
> >
> > Here you're assuming that the screen aspect-ratio is portrait, which is not
> > always the case.
>
> Why would we care here? This is just the shell telling an application: this is
> your orientation now.

Because the code is wrong. If it's a main stage tablet app and shell says "surface.orientation = Landscape" it means mir_orientation_normal, not mir_orientation_left.

>
> > Qt::ScreenOrientation values do not map directly to MirOrientation ones. The
> > two enums express orientation differently. Trying to shoehorn one into the
> > other is no good.
>
> I think it's a bad idea that there are 2 ways to express orientation, and we
> should just use one.

But that's what we have in your patch. There's Qt::ScreenOrientation and MirOrientation. Ignoring it will not make it go away. :)

So I will more explicitly: I see two ways of fixing it:
1 - Doing the proper translation from Qt::ScreenOrientation to MirOrientation in MirSurfaceItem::setOrientation
2 - Using an enum semantically equivalent to MirOrientation in MirSurfaceItem.orientation.

> You don't like that I ignore PrimaryOrientation?

It's not about that. But now that you mentioned it, there should be at least a warning if unity8 uses it if it's explicitly not supported. Otherwise we would be hiding an implementation bug in unity8.

>
> > Either do a proper translation between the two or make
> > MirSurfaceItem::orientation use an enum that does match with MirOrientation.
>
> I prefer using a subset of an existing enum than creating a new enum. QML
> already knows about Qt::*Orientation - it would be a waste to duplicate it
> IMO.

I suppose you're talking about going for the option 2 above. We wouldn't be duplicating Qt::ScreenOrientation as it would be a semantically different enum.

>
>
>
> > ------------------------
> >
> > In src/platforms/mirserver/screen.cpp:
> >
> > Who's calling Screen::toggleSensors()?
> > It was supposed to be called whenever the display goes on and off.
>
> Nobody yet. I had hoped to wire it up to the hide/show window event for
> display off/on, but that event doesn't happen. I'm not sure what signal to
> wire it up to still. Will be later MR.

If not body uses it then it's dead code. I think it would be better to only add it once we have use for it.

Btw, I think we should have a big FIXME somewhere saying that we must turn off the orientation sensor when the display is off.

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

> > I think it's a bad idea that there are 2 ways to express orientation, and we
> > should just use one.
>
> But that's what we have in your patch. There's Qt::ScreenOrientation and
> MirOrientation. Ignoring it will not make it go away. :)
>
> So I will more explicitly: I see two ways of fixing it:
> 1 - Doing the proper translation from Qt::ScreenOrientation to MirOrientation
> in MirSurfaceItem::setOrientation

I finally saw what you mean. I'm not such a big fan of it, and it relies other toolkits to deal with orientation in the same way Qt does (i.e. compare supplied orientation with a deduced native orientation), but anyway: it's done.

> > You don't like that I ignore PrimaryOrientation?
>
> It's not about that. But now that you mentioned it, there should be at least a
> warning if unity8 uses it if it's explicitly not supported. Otherwise we would
> be hiding an implementation bug in unity8.

I implemented it properly, PrimaryOrientation = native orientation.

> > > ------------------------
> > >
> > > In src/platforms/mirserver/screen.cpp:
> > >
> > > Who's calling Screen::toggleSensors()?
> > > It was supposed to be called whenever the display goes on and off.
> >
> > Nobody yet. I had hoped to wire it up to the hide/show window event for
> > display off/on, but that event doesn't happen. I'm not sure what signal to
> > wire it up to still. Will be later MR.
>
> If not body uses it then it's dead code. I think it would be better to only
> add it once we have use for it.
>
> Btw, I think we should have a big FIXME somewhere saying that we must turn off
> the orientation sensor when the display is off.

It's not dead if we'll use it soon :) I added a FIXME on top of the method. Will that do?

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

> [...]
>
> I finally saw what you mean. I'm not such a big fan of it, and it relies other
> toolkits to deal with orientation in the same way Qt does (i.e. compare
> supplied orientation with a deduced native orientation), but anyway: it's
> done.

Didn't get your comment. It relies on other toolkits dealing with MirOrientation the way it's defined. e.g. "rotate UI left by 90 if mir_orientation_left", "right by 90 if mir_orientation_right" and so on. Regardless of the aspect ratio.

But anyway, glad you did the change so I'm happy with it now. :)

--------------------------------

In src/modules/Unity/Application/mirsurfaceitem.cpp:

"""
    default:
        qWarning("Unrecognized Qt::ScreenOrientation!");
        return;
"""

It should use qCWarning(QTMIR_SURFACES), but I won't block this MP because of that as this review has been going on for too long now.

review: Approve
Revision history for this message
Michael Zanetti (mzanetti) wrote :

Text conflict in src/modules/Unity/Application/mirsurfaceitem.h
1 conflicts encountered.

review: Needs Fixing
244. By Gerry Boland

Merge trunk and resolve conflict

Revision history for this message
Michael Zanetti (mzanetti) wrote :

conflicts fixed.

review: Abstain
245. By Gerry Boland

Merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.cpp'
--- src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-11 20:21:47 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-19 12:20:29 +0000
@@ -30,8 +30,10 @@
3030
31// Qt31// Qt
32#include <QDebug>32#include <QDebug>
33#include <QGuiApplication>
33#include <QQmlEngine>34#include <QQmlEngine>
34#include <QQuickWindow>35#include <QQuickWindow>
36#include <QScreen>
35#include <QSGSimpleTextureNode>37#include <QSGSimpleTextureNode>
36#include <QSGTextureProvider>38#include <QSGTextureProvider>
37#include <QTimer>39#include <QTimer>
@@ -243,6 +245,7 @@
243 , m_session(session)245 , m_session(session)
244 , m_firstFrameDrawn(false)246 , m_firstFrameDrawn(false)
245 , m_live(true)247 , m_live(true)
248 , m_orientation(Qt::PortraitOrientation)
246 , m_textureProvider(nullptr)249 , m_textureProvider(nullptr)
247 , m_lastTouchEvent(nullptr)250 , m_lastTouchEvent(nullptr)
248{251{
@@ -349,6 +352,51 @@
349 return static_cast<MirSurfaceItem::State>(m_surface->state());352 return static_cast<MirSurfaceItem::State>(m_surface->state());
350}353}
351354
355Qt::ScreenOrientation MirSurfaceItem::orientation() const
356{
357 return m_orientation;
358}
359
360void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
361{
362 qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::setOrientation - orientation=" << orientation;
363
364 if (m_orientation == orientation)
365 return;
366
367 MirOrientation mirOrientation;
368 Qt::ScreenOrientation nativeOrientation = QGuiApplication::primaryScreen()->nativeOrientation();
369 const bool landscapeNativeOrientation = (nativeOrientation == Qt::LandscapeOrientation);
370
371 Qt::ScreenOrientation requestedOrientation = orientation;
372 if (orientation == Qt::PrimaryOrientation) { // means orientation equals native orientation, set it as such
373 requestedOrientation = nativeOrientation;
374 }
375
376 switch(requestedOrientation) {
377 case Qt::PortraitOrientation:
378 mirOrientation = (landscapeNativeOrientation) ? mir_orientation_right : mir_orientation_normal;
379 break;
380 case Qt::LandscapeOrientation:
381 mirOrientation = (landscapeNativeOrientation) ? mir_orientation_normal : mir_orientation_left;
382 break;
383 case Qt::InvertedPortraitOrientation:
384 mirOrientation = (landscapeNativeOrientation) ? mir_orientation_left : mir_orientation_inverted;
385 break;
386 case Qt::InvertedLandscapeOrientation:
387 mirOrientation = (landscapeNativeOrientation) ? mir_orientation_inverted : mir_orientation_right;
388 break;
389 default:
390 qWarning("Unrecognized Qt::ScreenOrientation!");
391 return;
392 }
393
394 m_surface->set_orientation(mirOrientation);
395
396 m_orientation = orientation;
397 Q_EMIT orientationChanged();
398}
399
352QString MirSurfaceItem::name() const400QString MirSurfaceItem::name() const
353{401{
354 //FIXME - how to listen to change in this property?402 //FIXME - how to listen to change in this property?
355403
=== modified file 'src/modules/Unity/Application/mirsurfaceitem.h'
--- src/modules/Unity/Application/mirsurfaceitem.h 2014-09-11 20:21:47 +0000
+++ src/modules/Unity/Application/mirsurfaceitem.h 2014-09-19 12:20:29 +0000
@@ -75,6 +75,7 @@
75 Q_PROPERTY(State state READ state NOTIFY stateChanged)75 Q_PROPERTY(State state READ state NOTIFY stateChanged)
76 Q_PROPERTY(QString name READ name NOTIFY nameChanged)76 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
77 Q_PROPERTY(bool live READ live NOTIFY liveChanged)77 Q_PROPERTY(bool live READ live NOTIFY liveChanged)
78 Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged DESIGNABLE false)
7879
79public:80public:
80 explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,81 explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,
@@ -107,6 +108,7 @@
107 State state() const;108 State state() const;
108 QString name() const;109 QString name() const;
109 bool live() const;110 bool live() const;
111 Qt::ScreenOrientation orientation() const;
110 SessionInterface *session() const;112 SessionInterface *session() const;
111113
112 Q_INVOKABLE void release();114 Q_INVOKABLE void release();
@@ -120,6 +122,7 @@
120122
121 bool isFirstFrameDrawn() const { return m_firstFrameDrawn; }123 bool isFirstFrameDrawn() const { return m_firstFrameDrawn; }
122124
125 void setOrientation(const Qt::ScreenOrientation orientation);
123 void setSession(SessionInterface *app);126 void setSession(SessionInterface *app);
124127
125 // to allow easy touch event injection from tests128 // to allow easy touch event injection from tests
@@ -132,6 +135,7 @@
132 void typeChanged();135 void typeChanged();
133 void stateChanged();136 void stateChanged();
134 void nameChanged();137 void nameChanged();
138 void orientationChanged();
135 void liveChanged(bool live);139 void liveChanged(bool live);
136 void firstFrameDrawn(MirSurfaceItem *item);140 void firstFrameDrawn(MirSurfaceItem *item);
137141
@@ -191,6 +195,7 @@
191 QPointer<SessionInterface> m_session;195 QPointer<SessionInterface> m_session;
192 bool m_firstFrameDrawn;196 bool m_firstFrameDrawn;
193 bool m_live;197 bool m_live;
198 Qt::ScreenOrientation m_orientation; //FIXME - have to save the state as Mir has no getter for it (bug:1357429)
194199
195 QMirSurfaceTextureProvider *m_textureProvider;200 QMirSurfaceTextureProvider *m_textureProvider;
196201
197202
=== modified file 'src/platforms/mirserver/logging.h'
--- src/platforms/mirserver/logging.h 2014-09-07 19:42:14 +0000
+++ src/platforms/mirserver/logging.h 2014-09-19 12:20:29 +0000
@@ -22,6 +22,7 @@
22Q_DECLARE_LOGGING_CATEGORY(QTMIR_SESSIONS)22Q_DECLARE_LOGGING_CATEGORY(QTMIR_SESSIONS)
23Q_DECLARE_LOGGING_CATEGORY(QTMIR_SURFACES)23Q_DECLARE_LOGGING_CATEGORY(QTMIR_SURFACES)
24Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES)24Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES)
25Q_DECLARE_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES)
25Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT)26Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT)
2627
27#endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H28#endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H
2829
=== modified file 'src/platforms/mirserver/mirserverintegration.cpp'
--- src/platforms/mirserver/mirserverintegration.cpp 2014-07-08 18:23:45 +0000
+++ src/platforms/mirserver/mirserverintegration.cpp 2014-09-19 12:20:29 +0000
@@ -80,6 +80,17 @@
80 }80 }
81 argv[args.size()] = '\0';81 argv[args.size()] = '\0';
8282
83 // For access to sensors, qtmir uses qtubuntu-sensors. qtubuntu-sensors reads the
84 // UBUNTU_PLATFORM_API_BACKEND variable to decide if to load a valid sensor backend or not.
85 // For it to function we need to ensure a valid backend has been specified
86 if (qEnvironmentVariableIsEmpty("UBUNTU_PLATFORM_API_BACKEND")) {
87 if (qgetenv("DESKTOP_SESSION").contains("mir")) {
88 qputenv("UBUNTU_PLATFORM_API_BACKEND", "desktop_mirserver");
89 } else {
90 qputenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirserver");
91 }
92 }
93
83 m_mirConfig = QSharedPointer<MirServerConfiguration>(94 m_mirConfig = QSharedPointer<MirServerConfiguration>(
84 new MirServerConfiguration(args.length(), const_cast<const char**>(argv)));95 new MirServerConfiguration(args.length(), const_cast<const char**>(argv)));
8596
8697
=== modified file 'src/platforms/mirserver/screen.cpp'
--- src/platforms/mirserver/screen.cpp 2014-07-08 18:31:50 +0000
+++ src/platforms/mirserver/screen.cpp 2014-09-19 12:20:29 +0000
@@ -18,8 +18,11 @@
18 * Gerry Boland <gerry.boland@canonical.com>18 * Gerry Boland <gerry.boland@canonical.com>
19 */19 */
2020
21// local
21#include "screen.h"22#include "screen.h"
23#include "logging.h"
2224
25// Mir
23#include "mir/geometry/size.h"26#include "mir/geometry/size.h"
2427
25// Qt28// Qt
@@ -29,8 +32,14 @@
29#include <QtSensors/QOrientationReading>32#include <QtSensors/QOrientationReading>
30#include <QThread>33#include <QThread>
3134
35// Qt sensors
36#include <QtSensors/QOrientationReading>
37#include <QtSensors/QOrientationSensor>
38
32namespace mg = mir::geometry;39namespace mg = mir::geometry;
3340
41Q_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES, "qtmir.sensor")
42
34namespace {43namespace {
35bool isLittleEndian() {44bool isLittleEndian() {
36 unsigned int i = 1;45 unsigned int i = 1;
@@ -80,16 +89,42 @@
8089
81} // namespace {90} // namespace {
8291
92
93class OrientationReadingEvent : public QEvent {
94public:
95 OrientationReadingEvent(QEvent::Type type, QOrientationReading::Orientation orientation)
96 : QEvent(type)
97 , m_orientation(orientation) {
98 }
99
100 static const QEvent::Type m_type;
101 QOrientationReading::Orientation m_orientation;
102};
103
104const QEvent::Type OrientationReadingEvent::m_type =
105 static_cast<QEvent::Type>(QEvent::registerEventType());
106
107
108
83Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen)109Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen)
84 : QObject(nullptr)110 : QObject(nullptr)
111 , m_orientationSensor(new QOrientationSensor(this))
85{112{
86 readMirDisplayConfiguration(screen);113 readMirDisplayConfiguration(screen);
87114
88 // Set the default orientation based on the initial screen dimmensions.115 // Set the default orientation based on the initial screen dimmensions.
89 m_nativeOrientation = (m_geometry.width() >= m_geometry.height())116 m_nativeOrientation = (m_geometry.width() >= m_geometry.height())
90 ? Qt::LandscapeOrientation : Qt::PortraitOrientation;117 ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
91118 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen - nativeOrientation is:" << m_nativeOrientation;
92 m_currentOrientation = m_nativeOrientation;119
120 // If it's a landscape device (i.e. some tablets), start in landscape, otherwise portrait
121 m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation)
122 ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
123 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen - initial currentOrientation is:" << m_currentOrientation;
124
125 QObject::connect(m_orientationSensor, &QOrientationSensor::readingChanged,
126 this, &Screen::onOrientationReadingChanged);
127 m_orientationSensor->start();
93}128}
94129
95void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen)130void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen)
@@ -111,3 +146,61 @@
111146
112 m_refreshRate = mode.vrefresh_hz;147 m_refreshRate = mode.vrefresh_hz;
113}148}
149
150// FIXME: nothing is using this method yet, but we should turn off sensors when display is off.
151void Screen::toggleSensors(const bool enable) const
152{
153 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::toggleSensors - enable=" << enable;
154 if (enable) {
155 m_orientationSensor->start();
156 } else {
157 m_orientationSensor->stop();
158 }
159}
160
161void Screen::customEvent(QEvent* event)
162{
163 OrientationReadingEvent* oReadingEvent = static_cast<OrientationReadingEvent*>(event);
164 switch (oReadingEvent->m_orientation) {
165 case QOrientationReading::LeftUp: {
166 m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ?
167 Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation;
168 break;
169 }
170 case QOrientationReading::TopUp: {
171 m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ?
172 Qt::LandscapeOrientation : Qt::PortraitOrientation;
173 break;
174 }
175 case QOrientationReading::RightUp: {
176 m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ?
177 Qt::PortraitOrientation : Qt::InvertedLandscapeOrientation;
178 break;
179 }
180 case QOrientationReading::TopDown: {
181 m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ?
182 Qt::InvertedLandscapeOrientation : Qt::InvertedPortraitOrientation;
183 break;
184 }
185 default: {
186 qWarning("Unknown orientation.");
187 event->accept();
188 return;
189 }
190 }
191
192 // Raise the event signal so that client apps know the orientation changed
193 QWindowSystemInterface::handleScreenOrientationChange(screen(), m_currentOrientation);
194 event->accept();
195 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::customEvent - new orientation" << m_currentOrientation << "handled";
196}
197
198void Screen::onOrientationReadingChanged()
199{
200 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::onOrientationReadingChanged";
201
202 // Make sure to switch to the main Qt thread context
203 QCoreApplication::postEvent(this, new OrientationReadingEvent(
204 OrientationReadingEvent::m_type,
205 m_orientationSensor->reading()->orientation()));
206}
114207
=== modified file 'src/platforms/mirserver/screen.h'
--- src/platforms/mirserver/screen.h 2014-06-30 16:13:01 +0000
+++ src/platforms/mirserver/screen.h 2014-09-19 12:20:29 +0000
@@ -23,6 +23,7 @@
23#include <QObject>23#include <QObject>
24#include <QTimer>24#include <QTimer>
25#include <qpa/qplatformscreen.h>25#include <qpa/qplatformscreen.h>
26
26#include "mir/graphics/display_configuration.h"27#include "mir/graphics/display_configuration.h"
2728
28class QOrientationSensor;29class QOrientationSensor;
@@ -42,6 +43,14 @@
42 Qt::ScreenOrientation nativeOrientation() const override { return m_nativeOrientation; }43 Qt::ScreenOrientation nativeOrientation() const override { return m_nativeOrientation; }
43 Qt::ScreenOrientation orientation() const override { return m_currentOrientation; }44 Qt::ScreenOrientation orientation() const override { return m_currentOrientation; }
4445
46 void toggleSensors(const bool enable) const;
47
48 // QObject methods.
49 void customEvent(QEvent* event) override;
50
51public Q_SLOTS:
52 void onOrientationReadingChanged();
53
45private:54private:
46 void readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const&);55 void readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const&);
4756
@@ -53,6 +62,7 @@
5362
54 Qt::ScreenOrientation m_nativeOrientation;63 Qt::ScreenOrientation m_nativeOrientation;
55 Qt::ScreenOrientation m_currentOrientation;64 Qt::ScreenOrientation m_currentOrientation;
65 QOrientationSensor *m_orientationSensor;
56};66};
5767
58#endif // SCREEN_H68#endif // SCREEN_H

Subscribers

People subscribed via source and target branches