5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 17:52:29 +08:00

change ifdef to function

This commit is contained in:
Zámbó, Levente 2025-02-05 15:49:11 +01:00
parent bed3ec4163
commit d04fd9a35f

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
@ -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);
@ -262,11 +283,10 @@ void SetMinMaxSize(GtkWindow *window, int min_width, int min_height, int max_wid
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);
}