From 913d7f0ee220d527894ac3c984418d6975fa4eaa Mon Sep 17 00:00:00 2001 From: Aleksandra Olemskaia Date: Tue, 28 Jul 2026 18:10:35 +0200 Subject: [PATCH] [settings] IJPL-248297 Fit non-modal window bounds to screen Mirror DialogWrapper bounds fitting in NonModalWindowWrapper so restored or resized Settings windows stay within the visible screen after scale changes, including high-DPI Windows configurations. (cherry picked from commit 97316571ff6ec210d0a05c12abbd39d5d54a49e5) IJ-CR-217470 GitOrigin-RevId: 63031c7fb58812090f95d0e3c245430aa4f2210a --- .../openapi/ui/NonModalWindowWrapper.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/NonModalWindowWrapper.kt b/platform/platform-impl/src/com/intellij/openapi/ui/NonModalWindowWrapper.kt index 0321f55e85bb..559cd249b687 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/NonModalWindowWrapper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/ui/NonModalWindowWrapper.kt @@ -263,6 +263,13 @@ abstract class NonModalWindowWrapper( */ private fun fitWindowToScreen(window: Window) { clampMinimumSizeToScreen(window) + window.bounds = fitBoundsToScreen(window.bounds) + } + + private fun fitBoundsToScreen(bounds: Rectangle): Rectangle { + val rect = Rectangle(bounds) + ScreenUtil.fitToScreen(rect) + return rect } /** @@ -346,25 +353,22 @@ abstract class NonModalWindowWrapper( } override fun setSize(width: Int, height: Int) { - val rect = Rectangle(location.x, location.y, width, height) - ScreenUtil.fitToScreen(rect) - super.setSize(rect.width, rect.height) + val rect = fitBoundsToScreen(Rectangle(location.x, location.y, width, height)) if (location.x != rect.x || location.y != rect.y) { setLocation(rect.x, rect.y) } + super.setSize(rect.width, rect.height) } override fun setBounds(x: Int, y: Int, width: Int, height: Int) { clampMinimumSizeToScreen(this) - val rect = Rectangle(x, y, width, height) - ScreenUtil.fitToScreen(rect) + val rect = fitBoundsToScreen(Rectangle(x, y, width, height)) super.setBounds(rect.x, rect.y, rect.width, rect.height) } override fun setBounds(r: Rectangle) { clampMinimumSizeToScreen(this) - ScreenUtil.fitToScreen(r) - super.setBounds(r) + super.setBounds(fitBoundsToScreen(r)) } override fun uiDataSnapshot(sink: DataSink): Unit = this@NonModalWindowWrapper.uiDataSnapshot(sink) @@ -378,25 +382,22 @@ abstract class NonModalWindowWrapper( } override fun setSize(width: Int, height: Int) { - val rect = Rectangle(location.x, location.y, width, height) - ScreenUtil.fitToScreen(rect) - super.setSize(rect.width, rect.height) + val rect = fitBoundsToScreen(Rectangle(location.x, location.y, width, height)) if (location.x != rect.x || location.y != rect.y) { setLocation(rect.x, rect.y) } + super.setSize(rect.width, rect.height) } override fun setBounds(x: Int, y: Int, width: Int, height: Int) { clampMinimumSizeToScreen(this) - val rect = Rectangle(x, y, width, height) - ScreenUtil.fitToScreen(rect) + val rect = fitBoundsToScreen(Rectangle(x, y, width, height)) super.setBounds(rect.x, rect.y, rect.width, rect.height) } override fun setBounds(r: Rectangle) { clampMinimumSizeToScreen(this) - ScreenUtil.fitToScreen(r) - super.setBounds(r) + super.setBounds(fitBoundsToScreen(r)) } override fun uiDataSnapshot(sink: DataSink): Unit = this@NonModalWindowWrapper.uiDataSnapshot(sink)