Closed iamcalledrob closed 1 month ago
Maybe you can try return the WindowInsets
that is provided by compose foundation. like this.
WindowInsets(
left = if (isMaximized) {
frameX + padding
} else {
edgeX
},
right = if (isMaximized) {
frameX + padding
} else {
edgeX
},
top = if (isMaximized) {
frameY + padding
} else {
edgeY
},
bottom = if (isMaximized) {
frameY + padding
} else {
edgeY
}
)
@Sanlorng
You could stuff the frame widths into WindowInsets
, but since that uses Dp
sizing, density would need to be taken into account.
What I think should happen here is that this should be considered a bug, and ComposeWindow
should make this adjustment internally when setting the window size.
That way, a 200dp window on Mac, Linux and Win will all open to the same visible size.
The current logic made sense when windows had visible frames (Win8 and earlier) but doesn't make sense today.
Similarly, as a feature request, I think WindowState
should have minimumSize
and maximumSize
fields that bypass the broken AWT implementation.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Currently, window sizing (at least on Windows) is fairly broken for a few reasons:
Swing has some hi-dpi bugs that make
window.minimumSize
andwindow.maximumSize
not really usablewindow.minimumSize
takes a density-independent pixel (not dp) value. However, due to a bug, when setting the value the window will get resized to a minimum size with scaling applied.On a 200% display,
window.minimumSize = Dimension(400, 400)
will resize the window to 800x800px, then prevent the window from shrinking below 400x400px.https://github.com/JetBrains/compose-multiplatform/assets/87964/940e433e-ac0d-46ee-b3ca-561682b17d52
The only workaround for this that I've found is to implement a custom WindowProc and implement WM_GETMINMAXINFO manually for the window
WindowState.size
is inconsistent, and includes the invisible window frame that surrounds a Windows 10/11 windowYou might expect the window size to either be the size of the content below the titlebar, or the size of the visible window.
WindowState.size
corresponds to the window's frame (i.e.NSWindow.frame
)WindowState.size
is a value that's larger than the visible size of the window, and includes some invisible padding that Windows added when they removed visible (thick) window borders around windows. There's an invisible border around each window to allow for resize handles, and this is included in the window size.Repro:
This means that sizing logic needs to be platform-specific, and needs to factor in the border thickness for Windows. You have to use something along the lines of:
The combination of these two issues means that:
I'd love to see improvements in this area, since currently a lot of extra work is needed to workaround these issues -- and it's likely that developers primarily using Linux or macOS are not aware of these behavior differences on Windows!