]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Gracefully exit when no fonts are installed
authortokyo4j <hrak1529@gmail.com>
Thu, 8 May 2025 10:28:15 +0000 (19:28 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 9 May 2025 19:20:54 +0000 (20:20 +0100)
...rather than emitting ugly errors like:

labwc: ../src/buffer.c:85: buffer_adopt_cairo_surface: Assertion
`cairo_image_surface_get_format(surface) == CAIRO_FORMAT_ARGB32' failed.

src/main.c

index 403589fb9560ee36211a397ba99f279088d0a027..e824123db17c83373b49459605a3fac844bbbab4 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #define _POSIX_C_SOURCE 200809L
+#include <pango/pangocairo.h>
 #include <signal.h>
 #include <string.h>
 #include <unistd.h>
@@ -64,6 +65,31 @@ die_on_detecting_suid(void)
        exit(EXIT_FAILURE);
 }
 
+static void
+die_on_no_fonts(void)
+{
+       PangoContext *context = pango_font_map_create_context(
+               pango_cairo_font_map_get_default());
+       PangoLayout *layout = pango_layout_new(context);
+       pango_layout_set_text(layout, "abcdefg", -1);
+       int nr_unknown_glyphs = pango_layout_get_unknown_glyphs_count(layout);
+       g_object_unref(layout);
+       g_object_unref(context);
+
+       if (nr_unknown_glyphs > 0) {
+               wlr_log(WLR_ERROR, "no fonts are available");
+               exit(EXIT_FAILURE);
+       }
+
+       /*
+        * Make pango's dedicated thread exit. This prevents CI failures due to
+        * SIGTERM delivered to the pango's thread. This kind of workaround is
+        * not needed after we register our SIGTERM handler in
+        * server_init() > wl_event_loop_add_signal(), which masks SIGTERM.
+        */
+       pango_cairo_font_map_set_default(NULL);
+}
+
 static void
 send_signal_to_labwc_pid(int signal)
 {
@@ -166,6 +192,7 @@ main(int argc, char *argv[])
        wlr_log_init(verbosity, NULL);
 
        die_on_detecting_suid();
+       die_on_no_fonts();
 
        session_environment_init();