on xenial help sign in
Make shell respect supported orientations of focused application
commit401988e3f929b0b4238afd25bcf9b0714bd7e569 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 22 May 2014, 14:04 (12 years ago) parentc0b380b
2 files changed+66−6
qml/OrientedShell.qml+52−3 qml/Shell.qml+14−3
qml/OrientedShell.qml+52−3
@@ -26,9 +26,58 @@ Item {
2626 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
2727 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
2828
29− property int orientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
29+ property int acceptedOrientationAngle: {
30+ var screenOrientation = Screen.orientation;
31+ var acceptedOrientation;
3032
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()
3281 states: [
3382 State {
3483 name: "0"
@@ -79,6 +128,6 @@ Item {
79128 Shell {
80129 id: shell
81130 transformOrigin: Item.TopLeft
82− orientationAngle: orientedShell.orientationAngle
131+ orientationAngle: orientedShell.acceptedOrientationAngle
83132 }
84133}
qml/Shell.qml+14−3
@@ -37,6 +37,18 @@ FocusScope {
3737 id: shell
3838
3939 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+
4052 property real edgeSize: units.gu(2)
4153 property url defaultBackground: Qt.resolvedUrl(shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg")
4254 property url background
@@ -177,9 +189,8 @@ FocusScope {
177189 property bool shown: false
178190 onShownChanged: {
179191 if (shown) {
180− if (SurfaceManager.count > 0) {
181− var topmostSurface = SurfaceManager.getSurface(0);
182− ApplicaitonManager.focusApplication(topmostSurface.application.appId);
192+ if (SurfaceManager.topmostSurface) {
193+ ApplicationManager.focusApplication(SurfaceManager.topmostSurface.application.appId);
183194 }
184195 } else {
185196 if (ApplicationManager.focusedApplicationId) {