Merge lp:~phablet-team/qtubuntu/shellRotation into lp:qtubuntu

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Michael Zanetti
Approved revision: 258
Merged at revision: 260
Proposed branch: lp:~phablet-team/qtubuntu/shellRotation
Merge into: lp:qtubuntu
Diff against target: 171 lines (+72/-9)
4 files modified
debian/changelog (+6/-0)
src/ubuntumirclient/input.cpp (+7/-0)
src/ubuntumirclient/screen.cpp (+57/-7)
src/ubuntumirclient/screen.h (+2/-2)
To merge this branch: bzr merge lp:~phablet-team/qtubuntu/shellRotation
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+259044@code.launchpad.net

Commit message

Flip screen dimensions to compensate for a rotated window

And unify logging switch in input.cpp

Description of the change

Needed for shell rotation.

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
Michael Zanetti (mzanetti) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-03-20 12:37:32 +0000
3+++ debian/changelog 2015-05-13 19:27:06 +0000
4@@ -1,3 +1,9 @@
5+qtubuntu (0.61) UNRELEASED; urgency=medium
6+
7+ * Flip screen dimensions to compensate for a rotated window
8+
9+ -- Daniel d'Andrada <daniel.dandrada@canonical.com> Fri, 31 Oct 2014 16:39:11 -0200
10+
11 qtubuntu (0.60+15.04.20150318-0ubuntu3) vivid; urgency=medium
12
13 * No-change rebuild against latest platform-api
14
15=== modified file 'src/ubuntumirclient/input.cpp'
16--- src/ubuntumirclient/input.cpp 2015-02-17 17:39:47 +0000
17+++ src/ubuntumirclient/input.cpp 2015-05-13 19:27:06 +0000
18@@ -219,7 +219,14 @@
19 break;
20 case mir_event_type_resize:
21 {
22+ Q_ASSERT(ubuntuEvent->window->screen() == mIntegration->screen());
23+
24 auto resizeEvent = mir_event_get_resize_event(nativeEvent);
25+
26+ mIntegration->screen()->handleWindowSurfaceResize(
27+ mir_resize_event_get_width(resizeEvent),
28+ mir_resize_event_get_height(resizeEvent));
29+
30 ubuntuEvent->window->handleSurfaceResize(mir_resize_event_get_width(resizeEvent),
31 mir_resize_event_get_height(resizeEvent));
32 break;
33
34=== modified file 'src/ubuntumirclient/screen.cpp'
35--- src/ubuntumirclient/screen.cpp 2014-09-09 14:10:21 +0000
36+++ src/ubuntumirclient/screen.cpp 2015-05-13 19:27:06 +0000
37@@ -34,6 +34,24 @@
38 static const int kSwapInterval = 1;
39
40 #if !defined(QT_NO_DEBUG)
41+
42+static const char *orientationToStr(Qt::ScreenOrientation orientation) {
43+ switch (orientation) {
44+ case Qt::PrimaryOrientation:
45+ return "primary";
46+ case Qt::PortraitOrientation:
47+ return "portrait";
48+ case Qt::LandscapeOrientation:
49+ return "landscape";
50+ case Qt::InvertedPortraitOrientation:
51+ return "inverted portrait";
52+ case Qt::InvertedLandscapeOrientation:
53+ return "inverted landscape";
54+ default:
55+ return "INVALID!";
56+ }
57+}
58+
59 static void printEglConfig(EGLDisplay display, EGLConfig config) {
60 DASSERT(display != EGL_NO_DISPLAY);
61 DASSERT(config != nullptr);
62@@ -146,12 +164,11 @@
63 ua_ui_display_destroy(display);
64
65 mGeometry = QRect(0, 0, kScreenWidth, kScreenHeight);
66- mAvailableGeometry = QRect(0, 0, kScreenWidth, kScreenHeight);
67
68 DLOG("QUbuntuScreen::QUbuntuScreen (this=%p)", this);
69
70 // Set the default orientation based on the initial screen dimmensions.
71- mNativeOrientation = (mAvailableGeometry.width() >= mAvailableGeometry.height()) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
72+ mNativeOrientation = (mGeometry.width() >= mGeometry.height()) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
73
74 // If it's a landscape device (i.e. some tablets), start in landscape, otherwise portrait
75 mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
76@@ -168,22 +185,22 @@
77 OrientationChangeEvent* oReadingEvent = static_cast<OrientationChangeEvent*>(event);
78 switch (oReadingEvent->mOrientation) {
79 case QOrientationReading::LeftUp: {
80- mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
81+ mCurrentOrientation = (screen()->primaryOrientation() == Qt::LandscapeOrientation) ?
82 Qt::InvertedPortraitOrientation : Qt::LandscapeOrientation;
83 break;
84 }
85 case QOrientationReading::TopUp: {
86- mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
87+ mCurrentOrientation = (screen()->primaryOrientation() == Qt::LandscapeOrientation) ?
88 Qt::LandscapeOrientation : Qt::PortraitOrientation;
89 break;
90 }
91 case QOrientationReading::RightUp: {
92- mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
93+ mCurrentOrientation = (screen()->primaryOrientation() == Qt::LandscapeOrientation) ?
94 Qt::PortraitOrientation : Qt::InvertedLandscapeOrientation;
95 break;
96 }
97 case QOrientationReading::TopDown: {
98- mCurrentOrientation = (mNativeOrientation == Qt::LandscapeOrientation) ?
99+ mCurrentOrientation = (screen()->primaryOrientation() == Qt::LandscapeOrientation) ?
100 Qt::InvertedLandscapeOrientation : Qt::InvertedPortraitOrientation;
101 break;
102 }
103@@ -194,6 +211,39 @@
104 }
105
106 // Raise the event signal so that client apps know the orientation changed
107+ DLOG("UbuntuScreen::customEvent - handling orientation change to %s", orientationToStr(mCurrentOrientation));
108 QWindowSystemInterface::handleScreenOrientationChange(screen(), mCurrentOrientation);
109- DLOG("UbuntuScreen::customEvent - handling orientation change to %d", mCurrentOrientation);
110+}
111+
112+void UbuntuScreen::handleWindowSurfaceResize(int windowWidth, int windowHeight)
113+{
114+ if ((windowWidth > windowHeight && mGeometry.width() < mGeometry.height())
115+ || (windowWidth < windowHeight && mGeometry.width() > mGeometry.height())) {
116+
117+ // The window aspect ratio differ's from the screen one. This means that
118+ // unity8 has rotated the window in its scene.
119+ // As there's no way to express window rotation in Qt's API, we have
120+ // Flip QScreen's dimensions so that orientation properties match
121+ // (primaryOrientation particularly).
122+ // FIXME: This assumes a phone scenario. Won't work, or make sense,
123+ // on the desktop
124+
125+ QRect currGeometry = mGeometry;
126+ mGeometry.setWidth(currGeometry.height());
127+ mGeometry.setHeight(currGeometry.width());
128+
129+ DLOG("UbuntuScreen::handleWindowSurfaceResize - new screen geometry (w=%d, h=%d)",
130+ mGeometry.width(), mGeometry.height());
131+ QWindowSystemInterface::handleScreenGeometryChange(screen(),
132+ mGeometry /* newGeometry */,
133+ mGeometry /* newAvailableGeometry */);
134+
135+ if (mGeometry.width() < mGeometry.height()) {
136+ mCurrentOrientation = Qt::PortraitOrientation;
137+ } else {
138+ mCurrentOrientation = Qt::LandscapeOrientation;
139+ }
140+ DLOG("UbuntuScreen::handleWindowSurfaceResize - new orientation %s",orientationToStr(mCurrentOrientation));
141+ QWindowSystemInterface::handleScreenOrientationChange(screen(), mCurrentOrientation);
142+ }
143 }
144
145=== modified file 'src/ubuntumirclient/screen.h'
146--- src/ubuntumirclient/screen.h 2014-08-25 15:24:02 +0000
147+++ src/ubuntumirclient/screen.h 2015-05-13 19:27:06 +0000
148@@ -32,7 +32,7 @@
149 QImage::Format format() const override { return mFormat; }
150 int depth() const override { return mDepth; }
151 QRect geometry() const override { return mGeometry; }
152- QRect availableGeometry() const override { return mAvailableGeometry; }
153+ QRect availableGeometry() const override { return mGeometry; }
154 Qt::ScreenOrientation nativeOrientation() const override { return mNativeOrientation; }
155 Qt::ScreenOrientation orientation() const override { return mNativeOrientation; }
156
157@@ -41,13 +41,13 @@
158 EGLDisplay eglDisplay() const { return mEglDisplay; }
159 EGLConfig eglConfig() const { return mEglConfig; }
160 EGLNativeDisplayType eglNativeDisplay() const { return mEglNativeDisplay; }
161+ void handleWindowSurfaceResize(int width, int height);
162
163 // QObject methods.
164 void customEvent(QEvent* event);
165
166 private:
167 QRect mGeometry;
168- QRect mAvailableGeometry;
169 Qt::ScreenOrientation mNativeOrientation;
170 Qt::ScreenOrientation mCurrentOrientation;
171 QImage::Format mFormat;

Subscribers

People subscribed via source and target branches