From 61ef7b55b2d6f1e02f40b23fa24b7c115dcd8271 Mon Sep 17 00:00:00 2001 From: Scoopta Date: Mon, 18 May 2020 20:16:57 -0700 Subject: [PATCH] Wofi will now keep its percentage size even when moving between monitors --- src/wofi.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/wofi.c b/src/wofi.c index 9db05cb..6ee84a8 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -97,6 +97,7 @@ static int64_t ix, iy; static uint8_t konami_cycle; static bool is_konami = false; static GDBusProxy* dbus = NULL; +static GdkRectangle resolution = {0}; static struct map* keys; @@ -1448,18 +1449,28 @@ static gboolean do_percent_size(gpointer data) { char** geo_str = data; bool width_percent = strchr(geo_str[0], '%') != NULL; bool height_percent = strchr(geo_str[1], '%') != NULL && lines == 0; + GdkMonitor* monitor = gdk_display_get_monitor_at_window(gdk_display_get_default(), gtk_widget_get_window(window)); + GdkRectangle rect; gdk_monitor_get_geometry(monitor, &rect); + + if(rect.width == resolution.width && rect.height == resolution.height) { + return G_SOURCE_CONTINUE; + } + + resolution = rect; + if(width_percent) { - width = (width / 100.f) * rect.width; + uint64_t w_percent = strtol(geo_str[0], NULL, 10); + width = (w_percent / 100.f) * rect.width; } if(height_percent) { - height = (height / 100.f) * rect.height; + uint64_t h_percent = strtol(geo_str[1], NULL, 10); + height = (h_percent / 100.f) * rect.height; } update_surface_size(); - free(geo_str); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } void wofi_init(struct map* _config) { @@ -1685,10 +1696,11 @@ void wofi_init(struct map* _config) { bool width_percent = strchr(width_str, '%') != NULL; bool height_percent = strchr(height_str, '%') != NULL && lines == 0; if(width_percent || height_percent) { - char** geo_str = malloc(sizeof(char*) * 2); + static char* geo_str[2]; geo_str[0] = width_str; geo_str[1] = height_str; - gdk_threads_add_timeout(70, do_percent_size, geo_str); + gdk_threads_add_timeout(50, do_percent_size, geo_str); + do_percent_size(geo_str); } struct wl_list* modes = malloc(sizeof(struct wl_list));