Wofi will now keep its percentage size even when moving between monitors

This commit is contained in:
Scoopta 2020-05-18 20:16:57 -07:00
parent 74a77c23b2
commit 61ef7b55b2

View File

@ -97,6 +97,7 @@ static int64_t ix, iy;
static uint8_t konami_cycle; static uint8_t konami_cycle;
static bool is_konami = false; static bool is_konami = false;
static GDBusProxy* dbus = NULL; static GDBusProxy* dbus = NULL;
static GdkRectangle resolution = {0};
static struct map* keys; static struct map* keys;
@ -1448,18 +1449,28 @@ static gboolean do_percent_size(gpointer data) {
char** geo_str = data; char** geo_str = data;
bool width_percent = strchr(geo_str[0], '%') != NULL; bool width_percent = strchr(geo_str[0], '%') != NULL;
bool height_percent = strchr(geo_str[1], '%') != NULL && lines == 0; 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)); GdkMonitor* monitor = gdk_display_get_monitor_at_window(gdk_display_get_default(), gtk_widget_get_window(window));
GdkRectangle rect; GdkRectangle rect;
gdk_monitor_get_geometry(monitor, &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) { 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) { 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(); update_surface_size();
free(geo_str); return G_SOURCE_CONTINUE;
return G_SOURCE_REMOVE;
} }
void wofi_init(struct map* _config) { void wofi_init(struct map* _config) {
@ -1685,10 +1696,11 @@ void wofi_init(struct map* _config) {
bool width_percent = strchr(width_str, '%') != NULL; bool width_percent = strchr(width_str, '%') != NULL;
bool height_percent = strchr(height_str, '%') != NULL && lines == 0; bool height_percent = strchr(height_str, '%') != NULL && lines == 0;
if(width_percent || height_percent) { if(width_percent || height_percent) {
char** geo_str = malloc(sizeof(char*) * 2); static char* geo_str[2];
geo_str[0] = width_str; geo_str[0] = width_str;
geo_str[1] = height_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)); struct wl_list* modes = malloc(sizeof(struct wl_list));