From ae756a8409bce442c881e24cfe2a0430d603440f Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 23 Jul 2022 17:15:22 +1000 Subject: [PATCH] Use scaling when setting min/max window (#1557) * Use scaling when setting min/max window * Fix compile issue. Add debug * Fix scaling issue --- v2/internal/frontend/desktop/linux/window.go | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index 78262e81c..b487082f8 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -34,17 +34,6 @@ static GtkBox* GTKBOX(void *pointer) { return GTK_BOX(pointer); } -static 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; - int flags = GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE; - size.max_height = (max_height == 0 ? INT_MAX : max_height); - size.max_width = (max_width == 0 ? INT_MAX : max_width); - size.min_height = min_height; - size.min_width = min_width; - gtk_window_set_geometry_hints(window, NULL, &size, flags); -} - GdkMonitor* getCurrentMonitor(GtkWindow *window) { // Get the monitor that the window is currently on GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); @@ -69,6 +58,20 @@ int getCurrentMonitorScaleFactor(GtkWindow *window) { return gdk_monitor_get_scale_factor(monitor); } +static 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); + 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; + printf("SetMinMaxSize - min: (%d,%d) max: (%d,%d)\n", size.min_width, size.min_height, size.max_width, size.max_height); + gtk_window_set_geometry_hints(window, NULL, &size, flags); +} + gboolean Center(gpointer data) { GtkWindow *window = (GtkWindow*)data; @@ -82,6 +85,8 @@ gboolean Center(gpointer data) { int newX = ((m.width - windowWidth) / 2) + m.x; int newY = ((m.height - windowHeight) / 2) + m.y; + printf("Center: %dx%d\n", newX, newY); + // Place the window at the center of the monitor gtk_window_move(window, newX, newY); @@ -480,6 +485,7 @@ void SetPosition(void* window, int x, int y) { args->window = window; args->x = monitorDimensions.x + x; args->y = monitorDimensions.y + y; + printf("SetPosition: %dx%d\n", args->x, args->y); ExecuteOnMainThread(setPosition, (gpointer)args); } @@ -525,6 +531,7 @@ gboolean Fullscreen(gpointer data) { // Get the geometry of the monitor. GdkRectangle m = getCurrentMonitorGeometry(window); int scale = getCurrentMonitorScaleFactor(window); + printf("Fullscreen scale: %d\n", scale); SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale); gtk_window_fullscreen(window); @@ -643,11 +650,11 @@ func NewWindow(appoptions *options.App, debug bool) *Window { // Setup window result.SetKeepAbove(appoptions.AlwaysOnTop) result.SetResizable(!appoptions.DisableResize) - result.SetSize(appoptions.Width, appoptions.Height) result.SetDecorated(!appoptions.Frameless) result.SetTitle(appoptions.Title) result.SetMinSize(appoptions.MinWidth, appoptions.MinHeight) result.SetMaxSize(appoptions.MaxWidth, appoptions.MaxHeight) + result.SetSize(appoptions.Width, appoptions.Height) if appoptions.Linux != nil { if appoptions.Linux.Icon != nil { result.SetWindowIcon(appoptions.Linux.Icon) @@ -830,6 +837,7 @@ func (w *Window) SetResizable(resizable bool) { } func (w *Window) SetSize(width int, height int) { + println("SetSize: ", width, height) C.gtk_window_resize(w.asGTKWindow(), C.gint(width), C.gint(height)) }