From e6b3a2f006d3fb2ca3276b8473173becd11f74af Mon Sep 17 00:00:00 2001
From: Alfred Neumayer <dev.beidl@gmail.com>
Date: Thu, 7 Mar 2024 14:50:13 +0100
Subject: [PATCH 6/8] qml: Disallow resizing unresizeable windows & follow
 maximum/minimum geometry

- Set window geometry based on surface's minimum and maximum limits
- Prevent resize handles from doing anything when minimum and maximum limits match

Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 qml/Stage/ApplicationWindow.qml | 12 ++++++++++++
 qml/Stage/DecoratedWindow.qml   |  5 +----
 2 files changed, 13 insertions(+), 4 deletions(-)

--- a/qml/Stage/ApplicationWindow.qml
+++ b/qml/Stage/ApplicationWindow.qml
@@ -30,6 +30,7 @@
     readonly property string title: surface && surface.name !== "" ? surface.name : d.name
     readonly property QtObject focusedSurface: d.focusedSurface.surface
     readonly property alias surfaceInitialized: d.surfaceInitialized
+    readonly property bool supportsResize: d.surfaceOldEnoughToBeResized && d.supportsSurfaceResize
 
     // to be set from outside
     property QtObject surface
@@ -49,6 +50,15 @@
 
     signal sizeChanged(size size)
 
+    onSizeChanged: {
+        let width = Math.max(size.width, root.minimumWidth)
+        width = Math.min(width, root.maximumWidth)
+        let height = Math.max(size.height, root.minimumHeight)
+        height = Math.min(height, root.maximumHeight)
+        implicitWidth = width
+        implicitHeight = height
+    }
+
     Connections {
         target: surface
         function onReady() {  d.surfaceUp() }
@@ -104,6 +114,8 @@
                 &&
                 ((application.supportedOrientations & Qt.LandscapeOrientation)
                  || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
+                &&
+                !((root.minimumWidth === root.maximumWidth) && (root.minimumHeight === root.maximumHeight))
 
         property bool surfaceOldEnoughToBeResized: false
 
--- a/qml/Stage/DecoratedWindow.qml
+++ b/qml/Stage/DecoratedWindow.qml
@@ -33,6 +33,7 @@
     property alias application: applicationWindow.application
     property alias surface: applicationWindow.surface
     readonly property alias focusedSurface: applicationWindow.focusedSurface
+    readonly property alias supportsResize: applicationWindow.supportsResize
     property alias active: decoration.active
     readonly property alias title: applicationWindow.title
     property alias maximizeButtonShown: decoration.maximizeButtonShown
@@ -182,10 +183,6 @@
 //        onRequestedWidthChanged: oldRequestedWidth = requestedWidth
 //        onRequestedHeightChanged: oldRequestedHeight = requestedHeight
         focus: true
-        onSizeChanged: {
-            implicitWidth = size.width
-            implicitHeight = size.height
-        }
 
         property real itemScale: 1
         property real minSize: Math.min(root.scaleToPreviewSize, Math.min(requestedHeight, Math.min(requestedWidth, Math.min(implicitHeight, implicitWidth))))
