From 10ab8b274020a9323413d093c45f13490929fb81 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Sat, 14 Jan 2023 14:51:47 -0500 Subject: Estimate buffer size in advance for render_frame The size of the surface used to draw the indicator depends on the extents of the text being drawn on and under the indicator. This commit refactors the `render_frame` function so that the surface size is computed before drawing; before, `render_frame` drew onto a buffer, estimated the size the buffer should have had, and recursively called itself to try again with the estimated size, if necessary. This was done because Cairo's methods to estimate font and text size require that a cairo_t context object and an associated cairo_surface already have been set up. Since the surface size depends on the text size, the natural way to use Cairo would have a circular dependency. In order to compute sizes _before_ the buffer is created, this commit adds a 1x1 surface and a matching `test_cairo` context which is set to the same font and drawing parameters as the buffer that will be created. Font/text extent measurements should give the same results as for the final buffer. --- include/swaylock.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/swaylock.h') diff --git a/include/swaylock.h b/include/swaylock.h index 2d38488..e29a99e 100644 --- a/include/swaylock.h +++ b/include/swaylock.h @@ -86,6 +86,8 @@ struct swaylock_state { struct swaylock_args args; struct swaylock_password password; struct swaylock_xkb xkb; + cairo_surface_t *test_surface; + cairo_t *test_cairo; // used to estimate font/text sizes enum auth_state auth_state; int failed_attempts; bool run_display; -- cgit v1.2.3