From ddc157e8cbbe5d9245d8ed64fa53e02945518730 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 13 Jul 2022 19:19:46 +1000 Subject: [PATCH 1/5] Use scaling when setting min/max window --- v2/internal/frontend/desktop/linux/window.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index 374450a92f6..10afd525399 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -35,6 +35,14 @@ static GtkBox* GTKBOX(void *pointer) { } static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int max_width, int max_height) { + // Get the geometry of the monitor. + GdkRectangle m = getCurrentMonitorGeometry(window); + int scale = getCurrentMonitorScaleFactor(window); + min_width = min_width * scale; + min_height = min_height * scale; + max_width = max_width * scale; + max_height = max_height * scale; + 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; @@ -532,8 +540,7 @@ gboolean Fullscreen(gpointer data) { // Get the geometry of the monitor. GdkRectangle m = getCurrentMonitorGeometry(window); - int scale = getCurrentMonitorScaleFactor(window); - SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale); + SetMinMaxSize(window, 0, 0, m.width, m.height); gtk_window_fullscreen(window); From c143f831066d41b23ecaede5f97cdb9e30934ce6 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 16 Jul 2022 17:01:36 +1000 Subject: [PATCH 2/5] Fix compile issue. Add debug --- v2/internal/frontend/desktop/linux/window.go | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index 10afd525399..c3f3e3adb31 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -34,15 +34,8 @@ 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) { - // Get the geometry of the monitor. - GdkRectangle m = getCurrentMonitorGeometry(window); - int scale = getCurrentMonitorScaleFactor(window); - min_width = min_width * scale; - min_height = min_height * scale; - max_width = max_width * scale; - max_height = max_height * scale; +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; @@ -50,9 +43,11 @@ static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int size.max_width = (max_width == 0 ? INT_MAX : 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); } + GdkMonitor* getCurrentMonitor(GtkWindow *window) { // Get the monitor that the window is currently on GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); @@ -90,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); @@ -496,6 +493,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); } @@ -540,7 +538,9 @@ gboolean Fullscreen(gpointer data) { // Get the geometry of the monitor. GdkRectangle m = getCurrentMonitorGeometry(window); - SetMinMaxSize(window, 0, 0, m.width, m.height); + int scale = getCurrentMonitorScaleFactor(window); + printf("Fullscreen scale: %d\n", scale); + SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale); gtk_window_fullscreen(window); @@ -658,11 +658,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) @@ -846,6 +846,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)) } From 0175668aec5bf6063d85dce5bcd0b212e5303f50 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 16 Jul 2022 17:16:50 +1000 Subject: [PATCH 3/5] Fix scaling issue --- v2/internal/frontend/desktop/linux/window.go | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index c3f3e3adb31..d31e8725b16 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -34,20 +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; - 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); -} - - GdkMonitor* getCurrentMonitor(GtkWindow *window) { // Get the monitor that the window is currently on GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); @@ -72,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; From 43b2435c923ab33597f40af822b0fcbb99e5ac0f Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 26 Jul 2022 20:12:37 +1000 Subject: [PATCH 4/5] Fix window widget warnings & shutdown issue. Remove debug lines for linux --- v2/internal/appng/app_production.go | 7 ++--- v2/internal/frontend/desktop/linux/window.go | 31 +++++++++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/v2/internal/appng/app_production.go b/v2/internal/appng/app_production.go index 05e20571221..5c659827e80 100644 --- a/v2/internal/appng/app_production.go +++ b/v2/internal/appng/app_production.go @@ -35,15 +35,14 @@ type App struct { } func (a *App) Shutdown() { - if a.shutdownCallback != nil { - a.shutdownCallback(a.ctx) - } a.frontend.Quit() } func (a *App) Run() error { err := a.frontend.Run(a.ctx) - a.Shutdown() + if a.shutdownCallback != nil { + a.shutdownCallback(a.ctx) + } return err } diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index d31e8725b16..e1eed38fee9 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -38,16 +38,27 @@ GdkMonitor* getCurrentMonitor(GtkWindow *window) { // Get the monitor that the window is currently on GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); + if( gdk_window == NULL ) { + return NULL; + } GdkMonitor *monitor = gdk_display_get_monitor_at_window(display, gdk_window); return GDK_MONITOR(monitor); } +bool isNULLRectangle(GdkRectangle input) { + return input.x == -1 && input.y == -1 && input.width == -1 && input.height == -1; +} + GdkRectangle getCurrentMonitorGeometry(GtkWindow *window) { GdkMonitor *monitor = getCurrentMonitor(window); + GdkRectangle result; + if( monitor == NULL ) { + result.x = result.y = result.height = result.width = -1; + return result; + } // Get the geometry of the monitor - GdkRectangle result; gdk_monitor_get_geometry (monitor,&result); return result; } @@ -63,12 +74,14 @@ static void SetMinMaxSize(GtkWindow* window, int min_width, int min_height, int size.min_width = size.min_height = size.max_width = size.max_height = 0; GdkRectangle monitorSize = getCurrentMonitorGeometry(window); + if( isNULLRectangle(monitorSize) ) { + 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; - 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); } @@ -77,6 +90,9 @@ gboolean Center(gpointer data) { // Get the geometry of the monitor GdkRectangle m = getCurrentMonitorGeometry(window); + if( isNULLRectangle(m) ) { + return G_SOURCE_REMOVE; + } // Get the window width/height int windowWidth, windowHeight; @@ -85,8 +101,6 @@ 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); @@ -489,11 +503,13 @@ gboolean setPosition(gpointer data) { void SetPosition(void* window, int x, int y) { GdkRectangle monitorDimensions = getCurrentMonitorGeometry(window); + if( isNULLRectangle(monitorDimensions) ) { + return; + } SetPositionArgs* args = malloc(sizeof(SetPositionArgs)); 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); } @@ -538,8 +554,10 @@ gboolean Fullscreen(gpointer data) { // Get the geometry of the monitor. GdkRectangle m = getCurrentMonitorGeometry(window); + if( isNULLRectangle(m) ) { + return G_SOURCE_REMOVE; + } int scale = getCurrentMonitorScaleFactor(window); - printf("Fullscreen scale: %d\n", scale); SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale); gtk_window_fullscreen(window); @@ -846,7 +864,6 @@ 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)) } From f32b6f5d8b02118d6ed2be1b13efb8cd75069c29 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 2 Aug 2022 06:57:03 +1000 Subject: [PATCH 5/5] Update dev build with shutdown fix --- v2/internal/appng/app_dev.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/v2/internal/appng/app_dev.go b/v2/internal/appng/app_dev.go index e71149180ee..264ddf14863 100644 --- a/v2/internal/appng/app_dev.go +++ b/v2/internal/appng/app_dev.go @@ -45,15 +45,14 @@ type App struct { } func (a *App) Shutdown() { - if a.shutdownCallback != nil { - a.shutdownCallback(a.ctx) - } a.frontend.Quit() } func (a *App) Run() error { err := a.frontend.Run(a.ctx) - a.Shutdown() + if a.shutdownCallback != nil { + a.shutdownCallback(a.ctx) + } return err }