Skip to content

Commit 4788263

Browse files
authored
Merge pull request #4047 from lyimmi/bugfix/2431_wayland_max_size
[V2 - Linux] Bugfix/2431 wayland max size
2 parents 467bbfc + a220d53 commit 4788263

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

v2/internal/frontend/desktop/linux/window.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ static float xroot = 0.0f;
1414
static float yroot = 0.0f;
1515
static int dragTime = -1;
1616
static uint mouseButton = 0;
17+
static int wmIsWayland = -1;
18+
static int decoratorWidth = -1;
19+
static int decoratorHeight = -1;
1720

1821
// casts
1922
void ExecuteOnMainThread(void *f, gpointer jscallback)
@@ -68,6 +71,27 @@ static bool isNULLRectangle(GdkRectangle input)
6871
return input.x == -1 && input.y == -1 && input.width == -1 && input.height == -1;
6972
}
7073

74+
static gboolean onWayland()
75+
{
76+
switch (wmIsWayland)
77+
{
78+
case -1:
79+
char *gdkBackend = getenv("XDG_SESSION_TYPE");
80+
if(gdkBackend != NULL && strcmp(gdkBackend, "wayland") == 0)
81+
{
82+
wmIsWayland = 1;
83+
return TRUE;
84+
}
85+
86+
wmIsWayland = 0;
87+
return FALSE;
88+
case 1:
89+
return TRUE;
90+
default:
91+
return FALSE;
92+
}
93+
}
94+
7195
static GdkMonitor *getCurrentMonitor(GtkWindow *window)
7296
{
7397
// 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
238262
{
239263
return;
240264
}
265+
241266
int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE;
267+
242268
size.max_height = (max_height == 0 ? monitorSize.height : max_height);
243269
size.max_width = (max_width == 0 ? monitorSize.width : max_width);
244270
size.min_height = min_height;
245271
size.min_width = min_width;
272+
273+
// On Wayland window manager get the decorators and calculate the differences from the windows' size.
274+
if(onWayland())
275+
{
276+
if(decoratorWidth == -1 && decoratorHeight == -1)
277+
{
278+
int windowWidth, windowHeight;
279+
gtk_window_get_size(window, &windowWidth, &windowHeight);
280+
281+
GtkAllocation windowAllocation;
282+
gtk_widget_get_allocation(GTK_WIDGET(window), &windowAllocation);
283+
284+
decoratorWidth = (windowAllocation.width-windowWidth);
285+
decoratorHeight = (windowAllocation.height-windowHeight);
286+
}
287+
288+
// Add the decorator difference to the window so fullscreen and maximise can fill the window.
289+
size.max_height = decoratorHeight+size.max_height;
290+
size.max_width = decoratorWidth+size.max_width;
291+
}
292+
246293
gtk_window_set_geometry_hints(window, NULL, &size, flags);
247294
}
248295

website/src/pages/changelog.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
## [Unreleased]
1616

17+
### Fixed
18+
- Fixed Window size issues on Wayland [PR](https://github.com/wailsapp/wails/pull/4047) by [@lyimmi](https://github.com/lyimmi)
19+
20+
1721
### Changed
1822
- Updated recommendation for Svelte router in [#4085](https://github.com/wailsapp/wails/pull/4085) by [@benmccann](https://github.com/benmccann)
1923
- Updated documentation to clarify `WebviewGpuPolicy` default behavior on Linux in [#4162](https://github.com/wailsapp/wails/pull/4162) by [@brianetaveras](https://github.com/brianetaveras)

0 commit comments

Comments
 (0)