feat(resize-api): add runtime resize functionality for desktop widgets (#3114)

It would be nice to see it documented in the plugin development guide: https://danklinux.com/docs/dankmaterialshell/plugin-development#desktop-plugins
This commit is contained in:
Sunlight authored and GitHub committed 2026-08-20 12:34:25 -04:00
1 parent 7028ea323d
commit 7ebe072255
3 files changed
+58

No files matched your search

@@ -14,6 +14,9 @@ Item {
property real minWidth: 100
property real minHeight: 100
property var requestResize: null
property var clearResize: null
readonly property bool isInstance: instanceId !== "" && instanceData !== null
readonly property var instanceConfig: instanceData?.config ?? {}
@@ -231,6 +231,20 @@ Item {
dragOverrideH = -1;
}
function requestResize(width, height) {
if (width < minWidth || height < minHeight)
return;
if (width > screenWidth || height > screenHeight)
return;
dragOverrideW = width;
dragOverrideH = height;
}
function clearResize() {
dragOverrideW = -1;
dragOverrideH = -1;
}
property real minWidth: contentLoader.item?.minWidth ?? 100
property real minHeight: contentLoader.item?.minHeight ?? 100
property bool forceSquare: contentLoader.item?.forceSquare ?? false
@@ -442,6 +456,10 @@ Item {
item.widgetHeight = Qt.binding(() => contentLoader.height);
if (item.screen !== undefined)
item.screen = Qt.binding(() => root.screen);
if (item.requestResize !== undefined)
item.requestResize = root.requestResize;
if (item.clearResize !== undefined)
item.clearResize = root.clearResize;
}
}
+37
View File
@@ -1651,6 +1651,43 @@ Define these properties on your widget to customize behavior:
- `minWidth`: Minimum allowed width (default: 100)
- `minHeight`: Minimum allowed height (default: 100)
### Runtime Resize API
Desktop widgets can resize their live surface at runtime without saving the new size to disk.
The wrapper exposes two functions on the widget instance:
- `requestResize(width, height)`: Applies a temporary surface size override
- `clearResize()`: Clears the temporary override and restores the normal persisted size
These are available as properties on `DesktopPluginComponent` and are passed through by `DesktopPluginWrapper` automatically.
```qml
import QtQuick
import qs.Common
Item {
id: root
function expandPreview() {
if (requestResize) {
requestResize(420, 260)
}
}
function resetPreview() {
if (clearResize) {
clearResize()
}
}
}
```
Notes:
- This is a transient runtime resize only; it does not persist to `settings.json`
- The requested size must stay within the screen bounds and above `minWidth` / `minHeight`
- Use `clearResize()` when you want to return to the saved widget dimensions
### Loading and Saving Data
Use the injected `pluginService` to persist widget-specific data: