5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:51:44 +08:00

Use scaling when setting min/max window (#1557)

* Use scaling when setting min/max window

* Fix compile issue. Add debug

* Fix scaling issue
This commit is contained in:
Lea Anthony 2022-07-23 17:15:22 +10:00 committed by GitHub
parent f3516d0810
commit ae756a8409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,17 +34,6 @@ static GtkBox* GTKBOX(void *pointer) {
return GTK_BOX(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) { GdkMonitor* getCurrentMonitor(GtkWindow *window) {
// Get the monitor that the window is currently on // Get the monitor that the window is currently on
GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window));
@ -69,6 +58,20 @@ int getCurrentMonitorScaleFactor(GtkWindow *window) {
return gdk_monitor_get_scale_factor(monitor); 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) { gboolean Center(gpointer data) {
GtkWindow *window = (GtkWindow*)data; GtkWindow *window = (GtkWindow*)data;
@ -82,6 +85,8 @@ gboolean Center(gpointer data) {
int newX = ((m.width - windowWidth) / 2) + m.x; int newX = ((m.width - windowWidth) / 2) + m.x;
int newY = ((m.height - windowHeight) / 2) + m.y; int newY = ((m.height - windowHeight) / 2) + m.y;
printf("Center: %dx%d\n", newX, newY);
// Place the window at the center of the monitor // Place the window at the center of the monitor
gtk_window_move(window, newX, newY); gtk_window_move(window, newX, newY);
@ -480,6 +485,7 @@ void SetPosition(void* window, int x, int y) {
args->window = window; args->window = window;
args->x = monitorDimensions.x + x; args->x = monitorDimensions.x + x;
args->y = monitorDimensions.y + y; args->y = monitorDimensions.y + y;
printf("SetPosition: %dx%d\n", args->x, args->y);
ExecuteOnMainThread(setPosition, (gpointer)args); ExecuteOnMainThread(setPosition, (gpointer)args);
} }
@ -525,6 +531,7 @@ gboolean Fullscreen(gpointer data) {
// Get the geometry of the monitor. // Get the geometry of the monitor.
GdkRectangle m = getCurrentMonitorGeometry(window); GdkRectangle m = getCurrentMonitorGeometry(window);
int scale = getCurrentMonitorScaleFactor(window); int scale = getCurrentMonitorScaleFactor(window);
printf("Fullscreen scale: %d\n", scale);
SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale); SetMinMaxSize(window, 0, 0, m.width * scale, m.height * scale);
gtk_window_fullscreen(window); gtk_window_fullscreen(window);
@ -643,11 +650,11 @@ func NewWindow(appoptions *options.App, debug bool) *Window {
// Setup window // Setup window
result.SetKeepAbove(appoptions.AlwaysOnTop) result.SetKeepAbove(appoptions.AlwaysOnTop)
result.SetResizable(!appoptions.DisableResize) result.SetResizable(!appoptions.DisableResize)
result.SetSize(appoptions.Width, appoptions.Height)
result.SetDecorated(!appoptions.Frameless) result.SetDecorated(!appoptions.Frameless)
result.SetTitle(appoptions.Title) result.SetTitle(appoptions.Title)
result.SetMinSize(appoptions.MinWidth, appoptions.MinHeight) result.SetMinSize(appoptions.MinWidth, appoptions.MinHeight)
result.SetMaxSize(appoptions.MaxWidth, appoptions.MaxHeight) result.SetMaxSize(appoptions.MaxWidth, appoptions.MaxHeight)
result.SetSize(appoptions.Width, appoptions.Height)
if appoptions.Linux != nil { if appoptions.Linux != nil {
if appoptions.Linux.Icon != nil { if appoptions.Linux.Icon != nil {
result.SetWindowIcon(appoptions.Linux.Icon) result.SetWindowIcon(appoptions.Linux.Icon)
@ -830,6 +837,7 @@ func (w *Window) SetResizable(resizable bool) {
} }
func (w *Window) SetSize(width int, height int) { func (w *Window) SetSize(width int, height int) {
println("SetSize: ", width, height)
C.gtk_window_resize(w.asGTKWindow(), C.gint(width), C.gint(height)) C.gtk_window_resize(w.asGTKWindow(), C.gint(width), C.gint(height))
} }