-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window maximum width and height issues on Linux Wayland #2431
Comments
Sounds wonderful, I'll take a look at it as soon as I have time this week. (I hope) |
Hi, sorry it took me so long to look into this. I think I found the core of the issue. Wails sets default min and max sizes for the window when they are not set in the app options (to the current display's resolution) and we pass the window geometry hints If I remove the hints in v2/internal/frontend/desktop/linux/window.c L:190 the problem goes away, but then we have no built in window size control via GTK. As far as I can tell the default Wayland compositor counts the shadows/borders/etc in the window's width and height. For a quick and dirty temporary fix I recommend to set the window max values in the app options to some arbitrary big number (maybe over a 4k displays resolution). I'll look into how fix this properly. |
Thanks for looking into this @lyimmi 🙏 |
Thank you for checking this out! I've tried to look into this myself, but I am far too unfamiliar with GTK to do anything here, especially when taking into account those Wayland quirks. Nevertheless, I'm grateful for your efforts and I'll provide you with any additional info if I find any. Cheers! |
FWIW, I experience the same issue. Installed Wails doctor
Screencast.from.2024-02-06.12-11-13.webmI use Gnome 45.3 on Wayland. |
I think I found a way to fix this issue, but I have not seen this kind of solution anywhere, so I'm not exactly sure if it is a good solution. Basically we could compare the window's initial size and the allocated size that contains the window decorators and shadows as well and add the difference to the window's max size values. The comparison can be ignored on frameless windows because non decorated windows report the correct size on Wayland. As far as I can tell the initial window size does not mater, the size of the decorators does not change just the window's size. The solution still behaves badly on my portrait display, because for some reason Wayland returns the main display's resolution... So the max height is about half of the portrait display's height. At this time I can't figure out why. What do you think @leaanthony, is it good enough for a PR? Edit: it needs more work, maximising works, but fullscreen and unfullscreen is still broken. It would look like this: void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_width, int max_height)
{
GdkGeometry size;
size.min_width = size.min_height = size.max_width = size.max_height = 0;
GdkRectangle monitorSize = getCurrentMonitorGeometry(window);
if (isNULLRectangle(monitorSize))
{
return;
}
int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE;
size.max_height = (max_height == 0 ? monitorSize.height : max_height);
size.max_width = (max_width == 0 ? monitorSize.width : max_width);
size.min_height = min_height;
size.min_width = min_width;
// wayland specific code start
# ifdef GDK_WINDOWING_WAYLAND
char *gdkBackend = getenv("XDG_SESSION_TYPE");
if (gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0 && gtk_window_get_decorated(window)) {
int windowWidth, windowHeight;
gtk_window_get_size(window, &windowWidth, &windowHeight);
GtkAllocation windowAllocation;
gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation);
// only for debug
g_printf("window decorated: %d\n", gtk_window_get_decorated(window));
g_printf("window alloc width:%d height:%d\n", windowAllocation.width, windowAllocation.height);
g_printf("window window width:%d height:%d\n", windowWidth, windowHeight);
g_printf("window & decorator diff width:%d height:%d\n", (windowAllocation.width-windowWidth), (windowAllocation.height-windowHeight));
g_printf("window max width:%d height:%d\n", size.max_width, size.max_height);
size.max_height = (windowAllocation.height-windowHeight)+size.max_height;
size.max_width = (windowAllocation.width-windowWidth)+size.max_width;
// only for debug
g_printf("window new max width:%d height:%d\n", size.max_width, size.max_height);
}
#endif
// wayland specific code end
gtk_window_set_geometry_hints(window, NULL, &size, flags);
} It prints: window decorated: 1
window alloc width:1452 height:857
window window width:1400 height:768
window & decorator diff width:52 height:89
window max width:2560 height:1080
window new max width:2612 height:1169
|
@lyimmi - I can't believe this slipped through the net! This looks like a good solution! Are you still ok to open a PR for it? |
@leaanthony - Sure, give me some time, I'm a little busy lately! |
Hi, I think my PR solves this issue, please try out the PR! |
Description
There are 3 similar issues that I've found:
To Reproduce
For all:
First bug:
Second bug:
Third bug:
Expected behaviour
First bug: The app resizes accordingly without constraints.
Second bug: The app maximizes.
Third bug: The app goes to fullscreen.
Screenshots
Screencast.from.2023-02-28.14-06-22.webm
Attempted Fixes
No response
System Details
Additional context
I have tried to reproduce the problem under Xwayland (launching the app with GDK_BACKEND=x11 and XDG_SESSION_TYPE=X11) but the bugs weren't present there.
I also successfully managed to reproduce the bugs on another machine running Arch with Gnome on Wayland.
Strangely, it also seems that the "phantom maximum width and height" depend on the GTK theme - for some themes they are a bit bigger and for some they are a bit smaller.
The text was updated successfully, but these errors were encountered: