From 82f8e0035821ca0f3fb52335190e59e5b778ac0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=E1=BB=B3nh=20Thi=E1=BB=87n=20L=E1=BB=99c?= Date: Fri, 30 Oct 2026 20:09:00 +0700 Subject: [PATCH] feat(widget-editor): resize square with shift (#4030) port 2.0 (cherry picked from commit bca75138255f3cf00f6599d14212912c26d549fa) --- .../Modules/Plugins/DesktopWidgetGeometry.qml | 18 +++++++++++++++--- quickshell/Modules/Plugins/WidgetEditItem.qml | 4 ++-- quickshell/Widgets/DGridEditChrome.qml | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/quickshell/Modules/Plugins/DesktopWidgetGeometry.qml b/quickshell/Modules/Plugins/DesktopWidgetGeometry.qml index 63e30e683..4a05e91d3 100644 --- a/quickshell/Modules/Plugins/DesktopWidgetGeometry.qml +++ b/quickshell/Modules/Plugins/DesktopWidgetGeometry.qml @@ -183,13 +183,25 @@ QtObject { return Qt.point(newX, newY); } - function dragResizeTo(startWidth, startHeight, dx, dy) { - let newW = Math.max(minWidth, Math.min(startWidth + dx, screenWidth - widgetX)); - let newH = Math.max(minHeight, Math.min(startHeight + dy, screenHeight - widgetY)); + function dragResizeTo(startWidth, startHeight, dx, dy, squareResize = false) { + const maxWidth = screenWidth - widgetX; + const maxHeight = screenHeight - widgetY; + let newW = Math.max(minWidth, Math.min(startWidth + dx, maxWidth)); + let newH = Math.max(minHeight, Math.min(startHeight + dy, maxHeight)); if (gridEnabled) { newW = Math.max(minWidth, snapToGrid(newW)); newH = Math.max(minHeight, snapToGrid(newH)); } + if (squareResize) { + squareSnapped = true; + const minSize = Math.max(minWidth, minHeight); + const maxSquare = Math.min(maxWidth, maxHeight); + let size = Math.min(Math.max(newW, newH), maxSquare); + if (gridEnabled && size < Math.max(newW, newH)) + size = Math.floor(size / gridSize) * gridSize; + size = Math.max(minSize, size); + return Qt.size(size, size); + } if (!forceSquare) { squareSnapped = Math.abs(newW - newH) <= (gridEnabled ? gridSize / 2 : Theme.spacingL); if (!squareSnapped) diff --git a/quickshell/Modules/Plugins/WidgetEditItem.qml b/quickshell/Modules/Plugins/WidgetEditItem.qml index cd074c15e..b94470cda 100644 --- a/quickshell/Modules/Plugins/WidgetEditItem.qml +++ b/quickshell/Modules/Plugins/WidgetEditItem.qml @@ -242,9 +242,9 @@ Item { } resizing = true; } - onResizeMoved: (px, py) => { + onResizeMoved: (px, py, modifiers) => { const current = chrome.mapToItem(root.hostLayer, px, py); - const next = geometry.dragResizeTo(startWidth, startHeight, current.x - startPos.x, current.y - startPos.y); + const next = geometry.dragResizeTo(startWidth, startHeight, current.x - startPos.x, current.y - startPos.y, !!(modifiers & Qt.ShiftModifier)); geometry.dragOverrideW = next.width; geometry.dragOverrideH = next.height; } diff --git a/quickshell/Widgets/DGridEditChrome.qml b/quickshell/Widgets/DGridEditChrome.qml index 742bfc9e9..38658c9fa 100644 --- a/quickshell/Widgets/DGridEditChrome.qml +++ b/quickshell/Widgets/DGridEditChrome.qml @@ -41,7 +41,7 @@ Item { signal optionsRequested(var anchor) signal resizeStarted(real px, real py, int signX) signal resizeCanceled - signal resizeMoved(real px, real py) + signal resizeMoved(real px, real py, int modifiers) signal resizeEnded component HitMask: Item { @@ -195,7 +195,7 @@ Item { if (!pressed) return; const p = mapToItem(root, mouse.x, mouse.y); - root.resizeMoved(p.x - root.contentInset, p.y - root.contentInset); + root.resizeMoved(p.x - root.contentInset, p.y - root.contentInset, mouse.modifiers); } onReleased: root.resizeEnded() onCanceled: root.resizeCanceled()