Merge lp:~gerboland/qtmir/exposeOrientation into lp:qtmir
- exposeOrientation
- Merge into trunk
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 | ||||||||
Related bugs: |
|
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:/
https:/
https:/
* 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
PS Jenkins bot (ps-jenkins) wrote : | # |
Daniel d'Andrada (dandrader) wrote : | # |
Now that prompts-in-prompts has landed, there are merge conflicts in:
src/modules/
src/modules/
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:237
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Daniel d'Andrada (dandrader) wrote : | # |
In src/modules/
"""
case Qt::PortraitOri
"""
Here you're assuming that the screen aspect-ratio is portrait, which is not always the case.
Qt::ScreenOrien
Either do a proper translation between the two or make MirSurfaceItem:
-------
In src/platforms/
Who's calling Screen:
It was supposed to be called whenever the display goes on and off.
-------
In src/platforms/
"""
QCoreApplic
"""
Weird indentation.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:238
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Gerry Boland (gerboland) wrote : | # |
> In src/modules/
>
> """
> case Qt::PortraitOri
> mirOrientation = mir_orientation
> """
>
> 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::ScreenOrien
> 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:
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/
>
> Who's calling Screen:
> 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/
>
> """
> QCoreApplicatio
> OrientationRead
> m_orientationSe
> """
>
> Weird indentation.
done
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:239
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Daniel d'Andrada (dandrader) wrote : | # |
> > In src/modules/
> >
> > """
> > case Qt::PortraitOri
> > mirOrientation = mir_orientation
> > """
> >
> > 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.
>
> > Qt::ScreenOrien
> > 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::ScreenOrien
So I will more explicitly: I see two ways of fixing it:
1 - Doing the proper translation from Qt::ScreenOrien
2 - Using an enum semantically equivalent to MirOrientation in MirSurfaceItem.
> 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:
>
> 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::ScreenOrien
>
>
>
> > -------
> >
> > In src/platforms/
> >
> > Who's calling Screen:
> > 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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:241
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:242
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
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::ScreenOrien
> 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::ScreenOrien
> in MirSurfaceItem:
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/
> > >
> > > Who's calling Screen:
> > > 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?
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:243
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
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
But anyway, glad you did the change so I'm happy with it now. :)
-------
In src/modules/
"""
default:
return;
"""
It should use qCWarning(
Michael Zanetti (mzanetti) wrote : | # |
Text conflict in src/modules/
1 conflicts encountered.
- 244. By Gerry Boland
-
Merge trunk and resolve conflict
Michael Zanetti (mzanetti) wrote : | # |
conflicts fixed.
- 245. By Gerry Boland
-
Merge trunk
Preview Diff
1 | === modified file 'src/modules/Unity/Application/mirsurfaceitem.cpp' | |||
2 | --- src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-11 20:21:47 +0000 | |||
3 | +++ src/modules/Unity/Application/mirsurfaceitem.cpp 2014-09-19 12:20:29 +0000 | |||
4 | @@ -30,8 +30,10 @@ | |||
5 | 30 | 30 | ||
6 | 31 | // Qt | 31 | // Qt |
7 | 32 | #include <QDebug> | 32 | #include <QDebug> |
8 | 33 | #include <QGuiApplication> | ||
9 | 33 | #include <QQmlEngine> | 34 | #include <QQmlEngine> |
10 | 34 | #include <QQuickWindow> | 35 | #include <QQuickWindow> |
11 | 36 | #include <QScreen> | ||
12 | 35 | #include <QSGSimpleTextureNode> | 37 | #include <QSGSimpleTextureNode> |
13 | 36 | #include <QSGTextureProvider> | 38 | #include <QSGTextureProvider> |
14 | 37 | #include <QTimer> | 39 | #include <QTimer> |
15 | @@ -243,6 +245,7 @@ | |||
16 | 243 | , m_session(session) | 245 | , m_session(session) |
17 | 244 | , m_firstFrameDrawn(false) | 246 | , m_firstFrameDrawn(false) |
18 | 245 | , m_live(true) | 247 | , m_live(true) |
19 | 248 | , m_orientation(Qt::PortraitOrientation) | ||
20 | 246 | , m_textureProvider(nullptr) | 249 | , m_textureProvider(nullptr) |
21 | 247 | , m_lastTouchEvent(nullptr) | 250 | , m_lastTouchEvent(nullptr) |
22 | 248 | { | 251 | { |
23 | @@ -349,6 +352,51 @@ | |||
24 | 349 | return static_cast<MirSurfaceItem::State>(m_surface->state()); | 352 | return static_cast<MirSurfaceItem::State>(m_surface->state()); |
25 | 350 | } | 353 | } |
26 | 351 | 354 | ||
27 | 355 | Qt::ScreenOrientation MirSurfaceItem::orientation() const | ||
28 | 356 | { | ||
29 | 357 | return m_orientation; | ||
30 | 358 | } | ||
31 | 359 | |||
32 | 360 | void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation) | ||
33 | 361 | { | ||
34 | 362 | qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::setOrientation - orientation=" << orientation; | ||
35 | 363 | |||
36 | 364 | if (m_orientation == orientation) | ||
37 | 365 | return; | ||
38 | 366 | |||
39 | 367 | MirOrientation mirOrientation; | ||
40 | 368 | Qt::ScreenOrientation nativeOrientation = QGuiApplication::primaryScreen()->nativeOrientation(); | ||
41 | 369 | const bool landscapeNativeOrientation = (nativeOrientation == Qt::LandscapeOrientation); | ||
42 | 370 | |||
43 | 371 | Qt::ScreenOrientation requestedOrientation = orientation; | ||
44 | 372 | if (orientation == Qt::PrimaryOrientation) { // means orientation equals native orientation, set it as such | ||
45 | 373 | requestedOrientation = nativeOrientation; | ||
46 | 374 | } | ||
47 | 375 | |||
48 | 376 | switch(requestedOrientation) { | ||
49 | 377 | case Qt::PortraitOrientation: | ||
50 | 378 | mirOrientation = (landscapeNativeOrientation) ? mir_orientation_right : mir_orientation_normal; | ||
51 | 379 | break; | ||
52 | 380 | case Qt::LandscapeOrientation: | ||
53 | 381 | mirOrientation = (landscapeNativeOrientation) ? mir_orientation_normal : mir_orientation_left; | ||
54 | 382 | break; | ||
55 | 383 | case Qt::InvertedPortraitOrientation: | ||
56 | 384 | mirOrientation = (landscapeNativeOrientation) ? mir_orientation_left : mir_orientation_inverted; | ||
57 | 385 | break; | ||
58 | 386 | case Qt::InvertedLandscapeOrientation: | ||
59 | 387 | mirOrientation = (landscapeNativeOrientation) ? mir_orientation_inverted : mir_orientation_right; | ||
60 | 388 | break; | ||
61 | 389 | default: | ||
62 | 390 | qWarning("Unrecognized Qt::ScreenOrientation!"); | ||
63 | 391 | return; | ||
64 | 392 | } | ||
65 | 393 | |||
66 | 394 | m_surface->set_orientation(mirOrientation); | ||
67 | 395 | |||
68 | 396 | m_orientation = orientation; | ||
69 | 397 | Q_EMIT orientationChanged(); | ||
70 | 398 | } | ||
71 | 399 | |||
72 | 352 | QString MirSurfaceItem::name() const | 400 | QString MirSurfaceItem::name() const |
73 | 353 | { | 401 | { |
74 | 354 | //FIXME - how to listen to change in this property? | 402 | //FIXME - how to listen to change in this property? |
75 | 355 | 403 | ||
76 | === modified file 'src/modules/Unity/Application/mirsurfaceitem.h' | |||
77 | --- src/modules/Unity/Application/mirsurfaceitem.h 2014-09-11 20:21:47 +0000 | |||
78 | +++ src/modules/Unity/Application/mirsurfaceitem.h 2014-09-19 12:20:29 +0000 | |||
79 | @@ -75,6 +75,7 @@ | |||
80 | 75 | Q_PROPERTY(State state READ state NOTIFY stateChanged) | 75 | Q_PROPERTY(State state READ state NOTIFY stateChanged) |
81 | 76 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) | 76 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
82 | 77 | Q_PROPERTY(bool live READ live NOTIFY liveChanged) | 77 | Q_PROPERTY(bool live READ live NOTIFY liveChanged) |
83 | 78 | Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged DESIGNABLE false) | ||
84 | 78 | 79 | ||
85 | 79 | public: | 80 | public: |
86 | 80 | explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface, | 81 | explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface, |
87 | @@ -107,6 +108,7 @@ | |||
88 | 107 | State state() const; | 108 | State state() const; |
89 | 108 | QString name() const; | 109 | QString name() const; |
90 | 109 | bool live() const; | 110 | bool live() const; |
91 | 111 | Qt::ScreenOrientation orientation() const; | ||
92 | 110 | SessionInterface *session() const; | 112 | SessionInterface *session() const; |
93 | 111 | 113 | ||
94 | 112 | Q_INVOKABLE void release(); | 114 | Q_INVOKABLE void release(); |
95 | @@ -120,6 +122,7 @@ | |||
96 | 120 | 122 | ||
97 | 121 | bool isFirstFrameDrawn() const { return m_firstFrameDrawn; } | 123 | bool isFirstFrameDrawn() const { return m_firstFrameDrawn; } |
98 | 122 | 124 | ||
99 | 125 | void setOrientation(const Qt::ScreenOrientation orientation); | ||
100 | 123 | void setSession(SessionInterface *app); | 126 | void setSession(SessionInterface *app); |
101 | 124 | 127 | ||
102 | 125 | // to allow easy touch event injection from tests | 128 | // to allow easy touch event injection from tests |
103 | @@ -132,6 +135,7 @@ | |||
104 | 132 | void typeChanged(); | 135 | void typeChanged(); |
105 | 133 | void stateChanged(); | 136 | void stateChanged(); |
106 | 134 | void nameChanged(); | 137 | void nameChanged(); |
107 | 138 | void orientationChanged(); | ||
108 | 135 | void liveChanged(bool live); | 139 | void liveChanged(bool live); |
109 | 136 | void firstFrameDrawn(MirSurfaceItem *item); | 140 | void firstFrameDrawn(MirSurfaceItem *item); |
110 | 137 | 141 | ||
111 | @@ -191,6 +195,7 @@ | |||
112 | 191 | QPointer<SessionInterface> m_session; | 195 | QPointer<SessionInterface> m_session; |
113 | 192 | bool m_firstFrameDrawn; | 196 | bool m_firstFrameDrawn; |
114 | 193 | bool m_live; | 197 | bool m_live; |
115 | 198 | Qt::ScreenOrientation m_orientation; //FIXME - have to save the state as Mir has no getter for it (bug:1357429) | ||
116 | 194 | 199 | ||
117 | 195 | QMirSurfaceTextureProvider *m_textureProvider; | 200 | QMirSurfaceTextureProvider *m_textureProvider; |
118 | 196 | 201 | ||
119 | 197 | 202 | ||
120 | === modified file 'src/platforms/mirserver/logging.h' | |||
121 | --- src/platforms/mirserver/logging.h 2014-09-07 19:42:14 +0000 | |||
122 | +++ src/platforms/mirserver/logging.h 2014-09-19 12:20:29 +0000 | |||
123 | @@ -22,6 +22,7 @@ | |||
124 | 22 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SESSIONS) | 22 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SESSIONS) |
125 | 23 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SURFACES) | 23 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SURFACES) |
126 | 24 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES) | 24 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES) |
127 | 25 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES) | ||
128 | 25 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT) | 26 | Q_DECLARE_LOGGING_CATEGORY(QTMIR_MIR_INPUT) |
129 | 26 | 27 | ||
130 | 27 | #endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H | 28 | #endif // UBUNTU_APPLICATION_PLUGIN_LOGGING_H |
131 | 28 | 29 | ||
132 | === modified file 'src/platforms/mirserver/mirserverintegration.cpp' | |||
133 | --- src/platforms/mirserver/mirserverintegration.cpp 2014-07-08 18:23:45 +0000 | |||
134 | +++ src/platforms/mirserver/mirserverintegration.cpp 2014-09-19 12:20:29 +0000 | |||
135 | @@ -80,6 +80,17 @@ | |||
136 | 80 | } | 80 | } |
137 | 81 | argv[args.size()] = '\0'; | 81 | argv[args.size()] = '\0'; |
138 | 82 | 82 | ||
139 | 83 | // For access to sensors, qtmir uses qtubuntu-sensors. qtubuntu-sensors reads the | ||
140 | 84 | // UBUNTU_PLATFORM_API_BACKEND variable to decide if to load a valid sensor backend or not. | ||
141 | 85 | // For it to function we need to ensure a valid backend has been specified | ||
142 | 86 | if (qEnvironmentVariableIsEmpty("UBUNTU_PLATFORM_API_BACKEND")) { | ||
143 | 87 | if (qgetenv("DESKTOP_SESSION").contains("mir")) { | ||
144 | 88 | qputenv("UBUNTU_PLATFORM_API_BACKEND", "desktop_mirserver"); | ||
145 | 89 | } else { | ||
146 | 90 | qputenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirserver"); | ||
147 | 91 | } | ||
148 | 92 | } | ||
149 | 93 | |||
150 | 83 | m_mirConfig = QSharedPointer<MirServerConfiguration>( | 94 | m_mirConfig = QSharedPointer<MirServerConfiguration>( |
151 | 84 | new MirServerConfiguration(args.length(), const_cast<const char**>(argv))); | 95 | new MirServerConfiguration(args.length(), const_cast<const char**>(argv))); |
152 | 85 | 96 | ||
153 | 86 | 97 | ||
154 | === modified file 'src/platforms/mirserver/screen.cpp' | |||
155 | --- src/platforms/mirserver/screen.cpp 2014-07-08 18:31:50 +0000 | |||
156 | +++ src/platforms/mirserver/screen.cpp 2014-09-19 12:20:29 +0000 | |||
157 | @@ -18,8 +18,11 @@ | |||
158 | 18 | * Gerry Boland <gerry.boland@canonical.com> | 18 | * Gerry Boland <gerry.boland@canonical.com> |
159 | 19 | */ | 19 | */ |
160 | 20 | 20 | ||
161 | 21 | // local | ||
162 | 21 | #include "screen.h" | 22 | #include "screen.h" |
163 | 23 | #include "logging.h" | ||
164 | 22 | 24 | ||
165 | 25 | // Mir | ||
166 | 23 | #include "mir/geometry/size.h" | 26 | #include "mir/geometry/size.h" |
167 | 24 | 27 | ||
168 | 25 | // Qt | 28 | // Qt |
169 | @@ -29,8 +32,14 @@ | |||
170 | 29 | #include <QtSensors/QOrientationReading> | 32 | #include <QtSensors/QOrientationReading> |
171 | 30 | #include <QThread> | 33 | #include <QThread> |
172 | 31 | 34 | ||
173 | 35 | // Qt sensors | ||
174 | 36 | #include <QtSensors/QOrientationReading> | ||
175 | 37 | #include <QtSensors/QOrientationSensor> | ||
176 | 38 | |||
177 | 32 | namespace mg = mir::geometry; | 39 | namespace mg = mir::geometry; |
178 | 33 | 40 | ||
179 | 41 | Q_LOGGING_CATEGORY(QTMIR_SENSOR_MESSAGES, "qtmir.sensor") | ||
180 | 42 | |||
181 | 34 | namespace { | 43 | namespace { |
182 | 35 | bool isLittleEndian() { | 44 | bool isLittleEndian() { |
183 | 36 | unsigned int i = 1; | 45 | unsigned int i = 1; |
184 | @@ -80,16 +89,42 @@ | |||
185 | 80 | 89 | ||
186 | 81 | } // namespace { | 90 | } // namespace { |
187 | 82 | 91 | ||
188 | 92 | |||
189 | 93 | class OrientationReadingEvent : public QEvent { | ||
190 | 94 | public: | ||
191 | 95 | OrientationReadingEvent(QEvent::Type type, QOrientationReading::Orientation orientation) | ||
192 | 96 | : QEvent(type) | ||
193 | 97 | , m_orientation(orientation) { | ||
194 | 98 | } | ||
195 | 99 | |||
196 | 100 | static const QEvent::Type m_type; | ||
197 | 101 | QOrientationReading::Orientation m_orientation; | ||
198 | 102 | }; | ||
199 | 103 | |||
200 | 104 | const QEvent::Type OrientationReadingEvent::m_type = | ||
201 | 105 | static_cast<QEvent::Type>(QEvent::registerEventType()); | ||
202 | 106 | |||
203 | 107 | |||
204 | 108 | |||
205 | 83 | Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen) | 109 | Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen) |
206 | 84 | : QObject(nullptr) | 110 | : QObject(nullptr) |
207 | 111 | , m_orientationSensor(new QOrientationSensor(this)) | ||
208 | 85 | { | 112 | { |
209 | 86 | readMirDisplayConfiguration(screen); | 113 | readMirDisplayConfiguration(screen); |
210 | 87 | 114 | ||
211 | 88 | // Set the default orientation based on the initial screen dimmensions. | 115 | // Set the default orientation based on the initial screen dimmensions. |
212 | 89 | m_nativeOrientation = (m_geometry.width() >= m_geometry.height()) | 116 | m_nativeOrientation = (m_geometry.width() >= m_geometry.height()) |
213 | 90 | ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | 117 | ? Qt::LandscapeOrientation : Qt::PortraitOrientation; |
216 | 91 | 118 | qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen - nativeOrientation is:" << m_nativeOrientation; | |
217 | 92 | m_currentOrientation = m_nativeOrientation; | 119 | |
218 | 120 | // If it's a landscape device (i.e. some tablets), start in landscape, otherwise portrait | ||
219 | 121 | m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) | ||
220 | 122 | ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||
221 | 123 | qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen - initial currentOrientation is:" << m_currentOrientation; | ||
222 | 124 | |||
223 | 125 | QObject::connect(m_orientationSensor, &QOrientationSensor::readingChanged, | ||
224 | 126 | this, &Screen::onOrientationReadingChanged); | ||
225 | 127 | m_orientationSensor->start(); | ||
226 | 93 | } | 128 | } |
227 | 94 | 129 | ||
228 | 95 | void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen) | 130 | void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen) |
229 | @@ -111,3 +146,61 @@ | |||
230 | 111 | 146 | ||
231 | 112 | m_refreshRate = mode.vrefresh_hz; | 147 | m_refreshRate = mode.vrefresh_hz; |
232 | 113 | } | 148 | } |
233 | 149 | |||
234 | 150 | // FIXME: nothing is using this method yet, but we should turn off sensors when display is off. | ||
235 | 151 | void Screen::toggleSensors(const bool enable) const | ||
236 | 152 | { | ||
237 | 153 | qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::toggleSensors - enable=" << enable; | ||
238 | 154 | if (enable) { | ||
239 | 155 | m_orientationSensor->start(); | ||
240 | 156 | } else { | ||
241 | 157 | m_orientationSensor->stop(); | ||
242 | 158 | } | ||
243 | 159 | } | ||
244 | 160 | |||
245 | 161 | void Screen::customEvent(QEvent* event) | ||
246 | 162 | { | ||
247 | 163 | OrientationReadingEvent* oReadingEvent = static_cast<OrientationReadingEvent*>(event); | ||
248 | 164 | switch (oReadingEvent->m_orientation) { | ||
249 | 165 | case QOrientationReading::LeftUp: { | ||
250 | 166 | m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ? | ||
251 | 167 | Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation; | ||
252 | 168 | break; | ||
253 | 169 | } | ||
254 | 170 | case QOrientationReading::TopUp: { | ||
255 | 171 | m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ? | ||
256 | 172 | Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||
257 | 173 | break; | ||
258 | 174 | } | ||
259 | 175 | case QOrientationReading::RightUp: { | ||
260 | 176 | m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ? | ||
261 | 177 | Qt::PortraitOrientation : Qt::InvertedLandscapeOrientation; | ||
262 | 178 | break; | ||
263 | 179 | } | ||
264 | 180 | case QOrientationReading::TopDown: { | ||
265 | 181 | m_currentOrientation = (m_nativeOrientation == Qt::LandscapeOrientation) ? | ||
266 | 182 | Qt::InvertedLandscapeOrientation : Qt::InvertedPortraitOrientation; | ||
267 | 183 | break; | ||
268 | 184 | } | ||
269 | 185 | default: { | ||
270 | 186 | qWarning("Unknown orientation."); | ||
271 | 187 | event->accept(); | ||
272 | 188 | return; | ||
273 | 189 | } | ||
274 | 190 | } | ||
275 | 191 | |||
276 | 192 | // Raise the event signal so that client apps know the orientation changed | ||
277 | 193 | QWindowSystemInterface::handleScreenOrientationChange(screen(), m_currentOrientation); | ||
278 | 194 | event->accept(); | ||
279 | 195 | qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::customEvent - new orientation" << m_currentOrientation << "handled"; | ||
280 | 196 | } | ||
281 | 197 | |||
282 | 198 | void Screen::onOrientationReadingChanged() | ||
283 | 199 | { | ||
284 | 200 | qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::onOrientationReadingChanged"; | ||
285 | 201 | |||
286 | 202 | // Make sure to switch to the main Qt thread context | ||
287 | 203 | QCoreApplication::postEvent(this, new OrientationReadingEvent( | ||
288 | 204 | OrientationReadingEvent::m_type, | ||
289 | 205 | m_orientationSensor->reading()->orientation())); | ||
290 | 206 | } | ||
291 | 114 | 207 | ||
292 | === modified file 'src/platforms/mirserver/screen.h' | |||
293 | --- src/platforms/mirserver/screen.h 2014-06-30 16:13:01 +0000 | |||
294 | +++ src/platforms/mirserver/screen.h 2014-09-19 12:20:29 +0000 | |||
295 | @@ -23,6 +23,7 @@ | |||
296 | 23 | #include <QObject> | 23 | #include <QObject> |
297 | 24 | #include <QTimer> | 24 | #include <QTimer> |
298 | 25 | #include <qpa/qplatformscreen.h> | 25 | #include <qpa/qplatformscreen.h> |
299 | 26 | |||
300 | 26 | #include "mir/graphics/display_configuration.h" | 27 | #include "mir/graphics/display_configuration.h" |
301 | 27 | 28 | ||
302 | 28 | class QOrientationSensor; | 29 | class QOrientationSensor; |
303 | @@ -42,6 +43,14 @@ | |||
304 | 42 | Qt::ScreenOrientation nativeOrientation() const override { return m_nativeOrientation; } | 43 | Qt::ScreenOrientation nativeOrientation() const override { return m_nativeOrientation; } |
305 | 43 | Qt::ScreenOrientation orientation() const override { return m_currentOrientation; } | 44 | Qt::ScreenOrientation orientation() const override { return m_currentOrientation; } |
306 | 44 | 45 | ||
307 | 46 | void toggleSensors(const bool enable) const; | ||
308 | 47 | |||
309 | 48 | // QObject methods. | ||
310 | 49 | void customEvent(QEvent* event) override; | ||
311 | 50 | |||
312 | 51 | public Q_SLOTS: | ||
313 | 52 | void onOrientationReadingChanged(); | ||
314 | 53 | |||
315 | 45 | private: | 54 | private: |
316 | 46 | void readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const&); | 55 | void readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const&); |
317 | 47 | 56 | ||
318 | @@ -53,6 +62,7 @@ | |||
319 | 53 | 62 | ||
320 | 54 | Qt::ScreenOrientation m_nativeOrientation; | 63 | Qt::ScreenOrientation m_nativeOrientation; |
321 | 55 | Qt::ScreenOrientation m_currentOrientation; | 64 | Qt::ScreenOrientation m_currentOrientation; |
322 | 65 | QOrientationSensor *m_orientationSensor; | ||
323 | 56 | }; | 66 | }; |
324 | 57 | 67 | ||
325 | 58 | #endif // SCREEN_H | 68 | #endif // SCREEN_H |
PASSED: Continuous integration, rev:236 jenkins. qa.ubuntu. com/job/ qtmir-ci/ 42/ jenkins. qa.ubuntu. com/job/ qtmir-utopic- amd64-ci/ 42 jenkins. qa.ubuntu. com/job/ qtmir-utopic- armhf-ci/ 42
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/qtmir- ci/42/rebuild
http://