on xenial help sign in
Make shell respect supported orientations of focused application
401988eDaniel d'Andrada
qml/OrientedShell.qml+52−3
@@ -26,9 +26,58 @@ Item {
26 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
26 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
27 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
27 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
28
28
29− property int orientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
29+ property int acceptedOrientationAngle: {
30+ var screenOrientation = Screen.orientation;
31+ var acceptedOrientation;
30
32
31− state: orientationAngle.toString()
33+ if (screenOrientation & shell.supportedScreenOrientations) {
34+ acceptedOrientation = screenOrientation;
35+ } else {
36+ // try orientations at -90, 90 and 180
37+ switch (screenOrientation) {
38+ case Qt.PortraitOrientation:
39+ if (Qt.LandscapeOrientation & shell.supportedScreenOrientations) {
40+ acceptedOrientation = Qt.LandscapeOrientation;
41+ } else if (Qt.InvertedLandscapeOrientation & shell.supportedScreenOrientations) {
42+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
43+ } else {
44+ acceptedOrientation = Qt.InvertedPortraitOrientation;
45+ }
46+ break;
47+ case Qt.InvertedPortraitOrientation:
48+ if (Qt.LandscapeOrientation & shell.supportedScreenOrientations) {
49+ acceptedOrientation = Qt.LandscapeOrientation;
50+ } else if (Qt.InvertedLandscapeOrientation & shell.supportedScreenOrientations) {
51+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
52+ } else {
53+ acceptedOrientation = Qt.PortraitOrientation;
54+ }
55+ break;
56+ case Qt.LandscapeOrientation:
57+ if (Qt.PortraitOrientation & shell.supportedScreenOrientations) {
58+ acceptedOrientation = Qt.PortraitOrientation;
59+ } else if (Qt.InvertedPortraitOrientation & shell.supportedScreenOrientations) {
60+ acceptedOrientation = Qt.InvertedPortraitOrientation;
61+ } else {
62+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
63+ }
64+ break;
65+ default: // Qt.InvertedLandscapeOrientation
66+ if (Qt.PortraitOrientation & shell.supportedScreenOrientations) {
67+ acceptedOrientation = Qt.PortraitOrientation;
68+ } else if (Qt.InvertedPortraitOrientation & shell.supportedScreenOrientations) {
69+ acceptedOrientation = Qt.InvertedPortraitOrientation;
70+ } else {
71+ acceptedOrientation = Qt.LandscapeOrientation;
72+ }
73+ break;
74+ }
75+ }
76+
77+ return Screen.angleBetween(Screen.primaryOrientation, acceptedOrientation);
78+ }
79+
80+ state: acceptedOrientationAngle.toString()
32 states: [
81 states: [
33 State {
82 State {
34 name: "0"
83 name: "0"
@@ -79,6 +128,6 @@ Item {
79 Shell {
128 Shell {
80 id: shell
129 id: shell
81 transformOrigin: Item.TopLeft
130 transformOrigin: Item.TopLeft
82− orientationAngle: orientedShell.orientationAngle
131+ orientationAngle: orientedShell.acceptedOrientationAngle
83 }
132 }
84}
133}
qml/Shell.qml+14−3
@@ -37,6 +37,18 @@ FocusScope {
37 id: shell
37 id: shell
38
38
39 property int orientationAngle
39 property int orientationAngle
40+
41+ property int supportedScreenOrientations: {
42+ if (stages.shown && SurfaceManager.topmostSurface) {
43+ return SurfaceManager.topmostSurface.application.supportedOrientations;
44+ } else {
45+ return Qt.PortraitOrientation
46+ | Qt.InvertedPortraitOrientation
47+ | Qt.LandscapeOrientation
48+ | Qt.InvertedLandscapeOrientation;
49+ }
50+ }
51+
40 property real edgeSize: units.gu(2)
52 property real edgeSize: units.gu(2)
41 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
53 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
42 property url background
54 property url background
@@ -177,9 +189,8 @@ FocusScope {
177 property bool shown: false
189 property bool shown: false
178 onShownChanged: {
190 onShownChanged: {
179 if (shown) {
191 if (shown) {
180− if (SurfaceManager.count > 0) {
192+ if (SurfaceManager.topmostSurface) {
181− var topmostSurface = SurfaceManager.getSurface(0);
182− ApplicaitonManager.focusApplication(topmostSurface.application.appId);
193+ ApplicationManager.focusApplication(SurfaceManager.topmostSurface.application.appId);
183 }
194 }
184 } else {
195 } else {
185 if (ApplicationManager.focusedApplicationId) {
196 if (ApplicationManager.focusedApplicationId) {