Patch for lipstick-jolla-home-qt5 to support any framebuffer orientation [off-topic]

asked 2014-01-08 12:10:19 +0300

coderus gravatar image

updated 2014-01-08 13:57:10 +0300

AL13N gravatar image

Hello Jolla!

I made a patch for lipstick-jolla-home-qt5. In #sailfishos Jolla people suggested to write here.

Patch fixing peek active area checkings, default notifications position, switcher item cover orientation and shutdown window orientation to match device framebuffer orientation.

Framebuffer orientation is checked by comparing Qt.PrimaryOrientation with Qt.PortraitOrientation.

Patch below (also alailable here: http://paste.ubuntu.com/6714011/).

Code contain comments.

diff --git a/qml/AmbiencePage.qml b/qml/AmbiencePage.qml
index e80cb4c..965a805 100644
--- a/qml/AmbiencePage.qml
+++ b/qml/AmbiencePage.qml
@@ -38,7 +38,7 @@ Page {
     property bool ambienceSwitcherEnabled: true
     readonly property bool _switcherEnabled: !deviceIsLocked && (!progressAnimation.running && !contentAnimation.running)
                 && (ambienceSwitcherOpen || (ambienceSwitcherEnabled && ambienceModel.count > 1))
-                && (PeekFilter.activeArea == PeekFilter.Left || PeekFilter.activeArea == PeekFilter.Right) && Lipstick.compositor.homeActive
+                && (PeekFilter.activeArea == Lipstick.compositor._peekLeft || PeekFilter.activeArea == Lipstick.compositor._peekRight) && Lipstick.compositor.homeActive

     property string _currentHomeWallpaper: Ambience.homeWallpaper

@@ -58,7 +58,7 @@ Page {
     PeekFilter.onGestureCanceled: {
         if (progressBinding.when) {
             progressBinding.when = false
-            progressAnimation.to = page.ambienceSwitcherOpen ? (PeekFilter.activeArea == PeekFilter.Left ? -1 : 1) : 0
+            progressAnimation.to = page.ambienceSwitcherOpen ? (PeekFilter.activeArea == Lipstick.compositor._peekLeft ? -1 : 1) : 0
             progressAnimation.restart()
         }
     }
@@ -74,7 +74,7 @@ Page {
     signal ambienceSwitcherClosed

     onAmbienceSwitcherOpenChanged: {
-        progressAnimation.to = ambienceSwitcherOpen ? (PeekFilter.activeArea == PeekFilter.Left ? 1 : -1) : 0
+        progressAnimation.to = ambienceSwitcherOpen ? (PeekFilter.activeArea == Lipstick.compositor._peekLeft ? 1 : -1) : 0
         progressAnimation.restart()
     }

@@ -123,7 +123,7 @@ Page {
     }

     function anchorAmbienceItem() {
-        if ((PeekFilter.activeArea == PeekFilter.Left) ^  ambienceSwitcherOpen) {
+        if ((PeekFilter.activeArea == Lipstick.compositor._peekLeft) ^  ambienceSwitcherOpen) {
             ambienceItem.anchors.left = undefined
             ambienceItem.anchors.right = contentItem.left
         } else {
@@ -138,7 +138,7 @@ Page {
     Binding on _progress {
         id: progressBinding
         when: false
-        value: PeekFilter.activeArea == PeekFilter.Left
+        value: PeekFilter.activeArea == Lipstick.compositor._peekLeft
                     ? page.ambienceSwitcherOpen ? -1 + _progressDistance : _progressDistance
                     : page.ambienceSwitcherOpen ?  1 - _progressDistance : -_progressDistance
     }
diff --git a/qml/ShutdownScreen.qml b/qml/ShutdownScreen.qml
index bf8050c..f5852de 100644
--- a/qml/ShutdownScreen.qml
+++ b/qml/ShutdownScreen.qml
@@ -12,7 +12,13 @@ import Sailfish.Silica 1.0
 SystemWindow {
     width: initialWidth
     height: initialHeight
-    transform: []
+
+    transform: Rotation {
+        //set rotation to be always in portrait
+        origin.x: width / 2
+        origin.y: width / 2
+        angle: 360 - Lipstick.compositor._defaultAngle
+    }

     Rectangle {
         property bool shouldBeVisible
diff --git a/qml/SwitcherItem.qml b/qml/SwitcherItem.qml
index 1f13dbd..f79826c 100644
--- a/qml/SwitcherItem.qml
+++ b/qml/SwitcherItem.qml
@@ -20,7 +20,7 @@ Item {
     property int windowId
     readonly property Item window: Lipstick.compositor.windowForId(wrapper.windowId)
     property bool windowMapPending
-    property bool rotateCoverContent: (window.screenRotation == 90) ? desktop.isPortrait : !desktop.isPortrait
+    property bool rotateCoverContent: coverId ? false : true //if cover set we dont need to rotate it in any case. if not set we rotating it according to window orientation
     property real oldY: -1
     property int showingPid: switcherWrapper.showingPid
     property bool columnsChanging: columnChangeAnimation.running
diff --git a/qml/compositor.qml b/qml/compositor.qml
index bfa13c5..eac9d19 100644
--- a/qml/compositor.qml
+++ b/qml/compositor.qml
@@ -71,7 +71,7 @@ Compositor {
     // The topmost Alarm window (e.g. incoming voice call, clock alarm)
     property Item topmostAlarmWindow

-    property int topmostWindowOrientation: (topmostWindow && topmostWindow.window.surface) ? topmostWindow.window.surface.contentOrientation : Qt.PrimaryOrientation
+    property int topmostWindowOrientation: (topmostWindow && topmostWindow.window.surface && topmostWindow.window.surface.contentOrientation != Qt.PrimaryOrientation) ? topmostWindow.window.surface.contentOrientation : Qt.PortraitOrientation //fix for new windows, Qt.PrimaryOrientation is set for surface.contentOrientation, which is Qt.LandscapeOrientation on framebuffer-rotated devices
     property int topmostWindowAngle: Screen.angleBetween(topmostWindowOrientation, Qt.PrimaryOrientation)

     onTopmostWindowChanged: updateWindows()
@@ -84,12 +84,48 @@ Compositor {

     property var desktop

-    readonly property bool appPeek: (PeekFilter.activeArea == PeekFilter.Bottom || PeekFilter.activeArea == PeekFilter.Top)
+    //Qt allow to check default framebuffer orientation by using Qt.PrimaryOrientation
+    property int _defaultAngle: Screen.angleBetween(Qt.PrimaryOrientation, Qt.PortraitOrientation)
+
+    //changing peek values according to framebuffer orientation
+    Component.onCompleted: {
+        switch (_defaultAngle) {
+            case 90:
+                _peekTop = PeekFilter.Left
+                _peekLeft = PeekFilter.Bottom
+                _peekBottom = PeekFilter.Right
+                _peekRight = PeekFilter.Top
+                break
+            case 180:
+                _peekTop = PeekFilter.Bottom
+                _peekLeft = PeekFilter.Right
+                _peekBottom = PeekFilter.Top
+                _peekRight = PeekFilter.Left
+                break
+            case 270:
+                _peekTop = PeekFilter.Right
+                _peekRight = PeekFilter.Bottom
+                _peekBottom = PeekFilter.Left
+                _peekLeft = PeekFilter.Top
+                break
+            default:
+                break
+        }
+    }
+
+    //default peek values
+    property int _peekTop: PeekFilter.Top
+    property int _peekLeft: PeekFilter.Left
+    property int _peekBottom: PeekFilter.Bottom
+    property int _peekRight: PeekFilter.Right
+
+    //replacing PeekFilter.[xxx] with _peek[xxx]
+    readonly property bool appPeek: (PeekFilter.activeArea == _peekBottom || PeekFilter.activeArea == _peekTop)
                            && root.eventsActive && root.preEventPeekWindow != root.homeWindow
-    readonly property bool eventPeek: PeekFilter.activeArea == PeekFilter.Bottom && !root.eventsActive
-    readonly property bool homePeek: PeekFilter.activeArea == PeekFilter.Left || PeekFilter.activeArea == PeekFilter.Right ||
-                            (root.preEventPeekWindow == root.homeWindow && root.eventsActive && PeekFilter.activeArea == PeekFilter.Bottom)
-    readonly property bool closePeek: PeekFilter.activeArea == PeekFilter.Top
+    readonly property bool eventPeek: PeekFilter.activeArea == _peekBottom && !root.eventsActive
+    readonly property bool homePeek: PeekFilter.activeArea == _peekLeft || PeekFilter.activeArea == _peekRight ||
+                            (root.preEventPeekWindow == root.homeWindow && root.eventsActive && PeekFilter.activeArea == _peekBottom)
+    readonly property bool closePeek: PeekFilter.activeArea == _peekTop
     readonly property bool singleAlarmDismissPeek: closePeek && root.alarmActive
     readonly property bool peeking: (appPeek || eventPeek || homePeek)
edit retag flag offensive reopen delete

The question has been closed for the following reason "question is off-topic or not relevant" by coderus
close date 2014-08-25 05:15:48.830399

Comments

Does this code mean, ones incorporated, Sailfish would support rotation for more apps than just Gallery and Camera?

jgr ( 2014-01-08 15:25:40 +0300 )edit

@jgr no, it means that some stuff would work correctly on devices where the default framebuffer orientation is landscape, not portrait.

Venemo ( 2014-01-12 17:44:07 +0300 )edit

Nice work! I see lipstick on jolla has an interesting command line argument; would that need to be removed? /usr/bin/lipstick -plugin evdevtouch:/dev/input/event0:rotate=0

mdengler ( 2014-01-15 17:51:47 +0300 )edit

No, touchscreen orientation shouldn't be changed.

coderus ( 2014-01-16 12:46:03 +0300 )edit

@coderus is this an attempt to fix N9 port for example (based on @Venemo's comment, this is what I understand)

Sfiet_Konstantin ( 2014-04-03 22:06:14 +0300 )edit