Skip to content

Commit

Permalink
Mobile: don't allow width change without rotation
Browse files Browse the repository at this point in the history
We get incorrect changes to a new screen width that causes us to try
draw to a much larger screen than we actually have. Ignore those
changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
  • Loading branch information
dirkhh committed Oct 2, 2019
1 parent cd98cb8 commit 1c24ac1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions mobile-widgets/qml/main.qml
Expand Up @@ -35,6 +35,7 @@ Kirigami.ApplicationWindow {
property bool filterToggle: false
property string filterPattern: ""
property bool firstChange: true
property int lastOrientation: undefined

onNotificationTextChanged: {
if (notificationText != "") {
Expand Down Expand Up @@ -555,6 +556,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
property color lightDrawerColor: "#FFFFFF"
property color darkDrawerColor: "#424242"
property int initialWidth: rootItem.width
property int initialHeight: rootItem.height
Component.onCompleted: {
// break the binding
initialWidth = initialWidth * 1
Expand All @@ -576,14 +578,25 @@ if you have network connectivity and want to sync your data to cloud storage."),
}

onWidthChanged: {
console.log("Window width changed to " + width)
console.log("Window width changed to " + width + " orientation " + Screen.primaryOrientation)
if (subsurfaceTheme.initialWidth !== undefined) {
if (width !== subsurfaceTheme.initialWidth && rootItem.firstChange) {
rootItem.firstChange = false;
console.log("first real change, so recalculating units")
rootItem.firstChange = false
rootItem.lastOrientation = Screen.primaryOrientation
subsurfaceTheme.initialWidth = width
subsurfaceTheme.initialHeight = height
console.log("first real change, so recalculating units and recording size as " + width + " x " + height)
setupUnits()
} else if (rootItem.lastOrientation !== undefined && rootItem.lastOrientation != Screen.primaryOrientation) {
console.log("Screen rotated, no action necessary")
rootItem.lastOrientation = Screen.primaryOrientation
} else {
console.log("not recalculating base unit")
console.log("size change without rotation to " + width + " x " + height)
if (width > subsurfaceTheme.initialWidth) {
console.log("resetting to initial width " + subsurfaceTheme.initialWidth + " and height " + subsurfaceTheme.initialHeight)
rootItem.width = subsurfaceTheme.initialWidth
rootItem.height = subsurfaceTheme.initialHeight
}
}
} else {
console.log("width changed before initial width initialized, ignoring")
Expand Down

0 comments on commit 1c24ac1

Please sign in to comment.