~scoopta/wofi

6 2

[PATCH] Hide the small window before percent resizing

lbonn
Details
Message ID
<a574c2d2ebabc847da5e.1587549509@skinnylynx.lan>
DKIM signature
pass
Download raw message
# HG changeset patch
# User lbonn <bonnans.l@gmail.com>
# Date 1587547343 -7200
#      Wed Apr 22 11:22:23 2020 +0200
# Node ID a574c2d2ebabc847da5ea80a372b4466350513a3
# Parent  ad0d4e28c6cba94290693c1cea8c8e932f56206f
Hide the small window before percent resizing

diff -r ad0d4e28c6cb -r a574c2d2ebab src/wofi.c
--- a/src/wofi.c	Fri Apr 10 22:12:43 2020 -0700
+++ b/src/wofi.c	Wed Apr 22 11:22:23 2020 +0200
@@ -1416,6 +1416,7 @@
 	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(width_percent) {
@@ -1425,7 +1426,8 @@
 		height = (height / 100.f) * rect.height;
 	}
 	update_surface_size();
-	free(geo_str);
+
+	gtk_widget_show_all(window);
 	return G_SOURCE_REMOVE;
 }
 
@@ -1628,13 +1630,14 @@
 
 	gdk_threads_add_timeout(filter_rate, do_search, NULL);
 
-
+	bool delay_show = false;
 	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;
+		delay_show = true;
 		gdk_threads_add_timeout(70, do_percent_size, geo_str);
 	}
 
@@ -1655,5 +1658,7 @@
 	gdk_threads_add_idle(insert_all_widgets, modes);
 
 	gtk_window_set_title(GTK_WINDOW(window), prompt);
-	gtk_widget_show_all(window);
+	if (!delay_show) {
+		gtk_widget_show_all(window);
+	}
 }
Scoopta
Details
Message ID
<404fd2d1-6777-70c9-d835-8629db9ccc7c@scoopta.email>
In-Reply-To
<a574c2d2ebabc847da5e.1587549509@skinnylynx.lan> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Is there some guarantee that wofi_init() won't return before
do_percent_size() is called? That was the main reason geo_str was
malloced instead of being placed on the stack. Otherwise it looks good.
Scoopta
Details
Message ID
<85eba396-2b54-f174-5a8e-6830520ff879@scoopta.email>
In-Reply-To
<404fd2d1-6777-70c9-d835-8629db9ccc7c@scoopta.email> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Actually now that I think about it wouldn't there always be a stack
issue here since do_percent_size() won't be called until gtk_main()
which happens after wofi_init() returns? This works fine even with
libasan so part of me wonders if I'm just missing something obvious but
I don't think geo_str should work.
lbonn
Details
Message ID
<CAAJ3AHcPB4F0HzU2aQtGNX-5fvQBk3rgjYisW+_yGXSP5OJ6-w@mail.gmail.com>
In-Reply-To
<85eba396-2b54-f174-5a8e-6830520ff879@scoopta.email> (view parent)
DKIM signature
pass
Download raw message
> Is there some guarantee that wofi_init() won't return before
> do_percent_size() is called? That was the main reason geo_str was
> malloced instead of being placed on the stack. Otherwise it looks good.

There is no such guarantee but it won't be a problem as geo_str does
not live in the stack but is statically allocated.
The only guarantee we need is that geo_str gets initialized before
being read in do_percent_size, which should be self-evident.
Scoopta
Details
Message ID
<303281aa-94af-8894-b7a6-135eeb90f063@scoopta.email>
In-Reply-To
<404fd2d1-6777-70c9-d835-8629db9ccc7c@scoopta.email> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Reads this email, looks at code, sees static keyword, ah yes, oops, pushed.
Scoopta
Details
Message ID
<e40c2a5b-89fc-0b18-48a3-d1fbc83a4208@scoopta.email>
In-Reply-To
<404fd2d1-6777-70c9-d835-8629db9ccc7c@scoopta.email> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
I'm going to have to back this out. Unfortunately it actually breaks
something that I didn't notice until now. By not showing the window GTK
assumes the window will open on the primary monitor which unfortunately
causes the size calculated to be based on the resolution of your primary
monitor(monitor at 0,0) instead of the monitor it will actually open on.
That's what the 70ms delay is for in the first place. GTK likes to
assume it'll be on the primary monitor unless I get the window open on
the actual monitor before calculating the size. I'll try to see how
small I can get the window to be. Hopefully I can make it small enough
that it might as well not be rendered.
Scoopta
Details
Message ID
<ac0127c1-8800-7b6e-e340-a3f52306d31c@scoopta.email>
In-Reply-To
<404fd2d1-6777-70c9-d835-8629db9ccc7c@scoopta.email> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
14e50fb5d18f is probably a good compromise for this, the window should
never change size unless you open on a monitor with a different scale
than your primary. For now it's the best I've got.
Reply to thread Export thread (mbox)