From bed3ec416302460f8d770bd3b907646c37571767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A1mb=C3=B3=2C=20Levente?= Date: Wed, 5 Feb 2025 15:13:11 +0100 Subject: [PATCH 1/7] add decorator diff to window max values --- v2/internal/frontend/desktop/linux/window.c | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index 0dee24f42..a45ab0cdf 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -228,6 +228,9 @@ void SetPosition(void *window, int x, int y) ExecuteOnMainThread(setPosition, (gpointer)args); } +static int decoratorWidth = 0; +static int decoratorHeight = 0; + void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_width, int max_height) { GdkGeometry size; @@ -238,11 +241,33 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid { 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; + +# ifdef GDK_WINDOWING_WAYLAND + if (decoratorWidth == 0 && decoratorHeight == 0) { + 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); + + decoratorWidth = (windowAllocation.width-windowWidth); + decoratorHeight = (windowAllocation.height-windowHeight); + } + } + + size.max_height = decoratorHeight+size.max_height; + size.max_width = decoratorWidth+size.max_width; +#endif + gtk_window_set_geometry_hints(window, NULL, &size, flags); } From d04fd9a35fbac24aa93f3245539c30136f84b3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A1mb=C3=B3=2C=20Levente?= Date: Wed, 5 Feb 2025 15:49:11 +0100 Subject: [PATCH 2/7] change ifdef to function --- v2/internal/frontend/desktop/linux/window.c | 44 +++++++++++++++------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index a45ab0cdf..dd56c8af4 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -14,6 +14,9 @@ static float xroot = 0.0f; static float yroot = 0.0f; static int dragTime = -1; static uint mouseButton = 0; +static int wmIsWayland = -1; +static int decoratorWidth = -1; +static int decoratorHeight = -1; // casts void ExecuteOnMainThread(void *f, gpointer jscallback) @@ -68,6 +71,27 @@ static bool isNULLRectangle(GdkRectangle input) return input.x == -1 && input.y == -1 && input.width == -1 && input.height == -1; } +static gboolean onWayland() +{ + switch (wmIsWayland) + { + case -1: + char *gdkBackend = getenv("XDG_SESSION_TYPE"); + if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0) + { + wmIsWayland = 1; + return TRUE; + } + + wmIsWayland = 0; + return FALSE; + case 1: + return TRUE; + default: + return FALSE; + } +} + static GdkMonitor *getCurrentMonitor(GtkWindow *window) { // Get the monitor that the window is currently on @@ -228,9 +252,6 @@ void SetPosition(void *window, int x, int y) ExecuteOnMainThread(setPosition, (gpointer)args); } -static int decoratorWidth = 0; -static int decoratorHeight = 0; - void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_width, int max_height) { GdkGeometry size; @@ -249,10 +270,10 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid size.min_height = min_height; size.min_width = min_width; -# ifdef GDK_WINDOWING_WAYLAND - if (decoratorWidth == 0 && decoratorHeight == 0) { - char *gdkBackend = getenv("XDG_SESSION_TYPE"); - if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0 && gtk_window_get_decorated(window)) { + if(onWayland()) + { + if(decoratorWidth == -1 && decoratorHeight == -1) + { int windowWidth, windowHeight; gtk_window_get_size(window, &windowWidth, &windowHeight); @@ -260,14 +281,13 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation); decoratorWidth = (windowAllocation.width-windowWidth); - decoratorHeight = (windowAllocation.height-windowHeight); + decoratorHeight = (windowAllocation.height-windowHeight); } + + size.max_height = decoratorHeight+size.max_height; + size.max_width = decoratorWidth+size.max_width; } - size.max_height = decoratorHeight+size.max_height; - size.max_width = decoratorWidth+size.max_width; -#endif - gtk_window_set_geometry_hints(window, NULL, &size, flags); } From f07ead3fb2c5b15d8c95d8d69a8df056cb0a3583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A1mb=C3=B3=2C=20Levente?= Date: Wed, 5 Feb 2025 16:04:49 +0100 Subject: [PATCH 3/7] add comments --- v2/internal/frontend/desktop/linux/window.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index dd56c8af4..cff982883 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -270,6 +270,7 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid size.min_height = min_height; size.min_width = min_width; + // On Wayland window manager get the decoratgors and calculate the differences from the windows' size. if(onWayland()) { if(decoratorWidth == -1 && decoratorHeight == -1) @@ -284,6 +285,7 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid decoratorHeight = (windowAllocation.height-windowHeight); } + // Add the decorator difference to the window so fullscreen and maximise can fill the window. size.max_height = decoratorHeight+size.max_height; size.max_width = decoratorWidth+size.max_width; } From 8d1e5188ad0090ae4c95ee87ddf180d22ddf421f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A1mb=C3=B3=2C=20Levente?= Date: Wed, 5 Feb 2025 16:07:42 +0100 Subject: [PATCH 4/7] fix typo --- v2/internal/frontend/desktop/linux/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index cff982883..2a71ba2ec 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -270,7 +270,7 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid size.min_height = min_height; size.min_width = min_width; - // On Wayland window manager get the decoratgors and calculate the differences from the windows' size. + // On Wayland window manager get the decorators and calculate the differences from the windows' size. if(onWayland()) { if(decoratorWidth == -1 && decoratorHeight == -1) From 89db2ad0826a5f87c91d1de65116b3df3e8efb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A1mb=C3=B3=2C=20Levente?= Date: Thu, 6 Feb 2025 11:23:50 +0100 Subject: [PATCH 5/7] add changelog --- website/src/pages/changelog.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 3cc504c90..bbc9ff230 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed more binding and typescript export bugs [PR](https://github.com/wailsapp/wails/pull/3978) by [@pbnjay](https://github.com/pbnjay) - Fixed Dispatcher.ProcessMessage crash process instead of return error [PR](https://github.com/wailsapp/wails/pull/4016) [#4015](https://github.com/wailsapp/wails/issues/4015) by [@ronaldinho_x86](https://github.com/RonaldinhoL) - Fixed Windows SaveDialog crash by [@leaanthony](https://github.com/leaanthony) +- Fixed Window size issues on Wayland [PR](https://github.com/wailsapp/wails/pull/4047) by [@lyimmi](https://github.com/lyimmi) ### Changed - Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756) From 347d8cf861f6d2f9a78ccfe48d016c6612e99c3c Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 8 Feb 2025 10:37:58 +1100 Subject: [PATCH 6/7] Make calls thread safe --- v2/internal/frontend/desktop/linux/window.c | 41 ++++++--------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index 2a71ba2ec..9c3b7c707 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -14,9 +14,6 @@ static float xroot = 0.0f; static float yroot = 0.0f; static int dragTime = -1; static uint mouseButton = 0; -static int wmIsWayland = -1; -static int decoratorWidth = -1; -static int decoratorHeight = -1; // casts void ExecuteOnMainThread(void *f, gpointer jscallback) @@ -73,23 +70,13 @@ static bool isNULLRectangle(GdkRectangle input) static gboolean onWayland() { - switch (wmIsWayland) + const char *gdkBackend = getenv("XDG_SESSION_TYPE"); + if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0) { - case -1: - char *gdkBackend = getenv("XDG_SESSION_TYPE"); - if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0) - { - wmIsWayland = 1; - return TRUE; - } - - wmIsWayland = 0; - return FALSE; - case 1: return TRUE; - default: - return FALSE; } + + return FALSE; } static GdkMonitor *getCurrentMonitor(GtkWindow *window) @@ -270,24 +257,18 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid size.min_height = min_height; size.min_width = min_width; - // On Wayland window manager get the decorators and calculate the differences from the windows' size. + // On Wayland window manager get the decorators and calculate the differences from the window size. if(onWayland()) { - if(decoratorWidth == -1 && decoratorHeight == -1) - { - int windowWidth, windowHeight; - gtk_window_get_size(window, &windowWidth, &windowHeight); + int windowWidth, windowHeight; + gtk_window_get_size(window, &windowWidth, &windowHeight); - GtkAllocation windowAllocation; - gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation); + GtkAllocation windowAllocation; + gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation); - decoratorWidth = (windowAllocation.width-windowWidth); - decoratorHeight = (windowAllocation.height-windowHeight); - } - // Add the decorator difference to the window so fullscreen and maximise can fill the window. - size.max_height = decoratorHeight+size.max_height; - size.max_width = decoratorWidth+size.max_width; + size.max_height = (windowAllocation.height-windowHeight)+size.max_height; + size.max_width = (windowAllocation.width-windowWidth)+size.max_width; } gtk_window_set_geometry_hints(window, NULL, &size, flags); From de29a0bd6ff13fa5782123d3fe080f7818af2582 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 18 Apr 2025 16:36:46 +1000 Subject: [PATCH 7/7] Revert "Make calls thread safe" This reverts commit 347d8cf861f6d2f9a78ccfe48d016c6612e99c3c. --- v2/internal/frontend/desktop/linux/window.c | 41 +++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index 9c3b7c707..2a71ba2ec 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -14,6 +14,9 @@ static float xroot = 0.0f; static float yroot = 0.0f; static int dragTime = -1; static uint mouseButton = 0; +static int wmIsWayland = -1; +static int decoratorWidth = -1; +static int decoratorHeight = -1; // casts void ExecuteOnMainThread(void *f, gpointer jscallback) @@ -70,13 +73,23 @@ static bool isNULLRectangle(GdkRectangle input) static gboolean onWayland() { - const char *gdkBackend = getenv("XDG_SESSION_TYPE"); - if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0) + switch (wmIsWayland) { + case -1: + char *gdkBackend = getenv("XDG_SESSION_TYPE"); + if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0) + { + wmIsWayland = 1; + return TRUE; + } + + wmIsWayland = 0; + return FALSE; + case 1: return TRUE; + default: + return FALSE; } - - return FALSE; } static GdkMonitor *getCurrentMonitor(GtkWindow *window) @@ -257,18 +270,24 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid size.min_height = min_height; size.min_width = min_width; - // On Wayland window manager get the decorators and calculate the differences from the window size. + // On Wayland window manager get the decorators and calculate the differences from the windows' size. if(onWayland()) { - int windowWidth, windowHeight; - gtk_window_get_size(window, &windowWidth, &windowHeight); + if(decoratorWidth == -1 && decoratorHeight == -1) + { + int windowWidth, windowHeight; + gtk_window_get_size(window, &windowWidth, &windowHeight); - GtkAllocation windowAllocation; - gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation); + GtkAllocation windowAllocation; + gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation); + decoratorWidth = (windowAllocation.width-windowWidth); + decoratorHeight = (windowAllocation.height-windowHeight); + } + // Add the decorator difference to the window so fullscreen and maximise can fill the window. - size.max_height = (windowAllocation.height-windowHeight)+size.max_height; - size.max_width = (windowAllocation.width-windowWidth)+size.max_width; + size.max_height = decoratorHeight+size.max_height; + size.max_width = decoratorWidth+size.max_width; } gtk_window_set_geometry_hints(window, NULL, &size, flags);