Gracefully exit when no fonts are installed

...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.
This commit is contained in:
tokyo4j 2025-05-08 19:28:15 +09:00 committed by Johan Malm
parent ab8b25c9b1
commit ca287de584

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <pango/pangocairo.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -64,6 +65,31 @@ die_on_detecting_suid(void)
exit(EXIT_FAILURE); 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 static void
send_signal_to_labwc_pid(int signal) send_signal_to_labwc_pid(int signal)
{ {
@ -166,6 +192,7 @@ main(int argc, char *argv[])
wlr_log_init(verbosity, NULL); wlr_log_init(verbosity, NULL);
die_on_detecting_suid(); die_on_detecting_suid();
die_on_no_fonts();
session_environment_init(); session_environment_init();