5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-01 15:10:48 +08:00

Merge pull request #4047 from lyimmi/bugfix/2431_wayland_max_size

[V2 - Linux] Bugfix/2431 wayland max size
This commit is contained in:
Lea Anthony 2025-04-18 16:40:09 +10:00 committed by GitHub
commit 4788263b9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 0 deletions

View File

@ -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
@ -238,11 +262,34 @@ 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;
// On Wayland window manager get the decorators and calculate the differences from the windows' size.
if(onWayland())
{
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);
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;
}
gtk_window_set_geometry_hints(window, NULL, &size, flags);
}

View File

@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Fixed Window size issues on Wayland [PR](https://github.com/wailsapp/wails/pull/4047) by [@lyimmi](https://github.com/lyimmi)
### Changed
- Updated recommendation for Svelte router in [#4085](https://github.com/wailsapp/wails/pull/4085) by [@benmccann](https://github.com/benmccann)
- Updated documentation to clarify `WebviewGpuPolicy` default behavior on Linux in [#4162](https://github.com/wailsapp/wails/pull/4162) by [@brianetaveras](https://github.com/brianetaveras)