From df6dde131f0ed5d77ec4ce5eeb64e02a32225e50 Mon Sep 17 00:00:00 2001 From: massi Date: Mon, 11 May 2026 16:39:22 -0700 Subject: [PATCH] window-title: implement window-title command line argument When -t or --window-title is supplied, its required argument is treated as a format string where `%o` is replaced by the `wlr-output`'s `name` when we set the window title. This uses glib to split and join the format string because our own `string-helpers` library only has `str_join`. Otherwise using `string-helpers` would have been preferred. --- include/labwc.h | 2 ++ src/main.c | 11 ++++++++++- src/output.c | 14 +++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index edde2771..bbee63cf 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -315,6 +315,8 @@ struct server { struct sfdo *sfdo; pid_t primary_client_pid; + + char *window_title_fmt; }; /* defined in main.c */ diff --git a/src/main.c b/src/main.c index 501c2b7a..93351b22 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #include "common/font.h" #include "common/macros.h" #include "common/spawn.h" +#include "common/string-helpers.h" #include "config/rcxml.h" #include "config/session.h" #include "labwc.h" @@ -37,6 +38,7 @@ static const struct option long_options[] = { {"reconfigure", no_argument, NULL, 'r'}, {"startup", required_argument, NULL, 's'}, {"session", required_argument, NULL, 'S'}, + {"window-title", required_argument, NULL, 't'}, {"version", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'V'}, {0, 0, 0, 0} @@ -178,7 +180,7 @@ main(int argc, char *argv[]) int c; while (1) { int index = 0; - c = getopt_long(argc, argv, "c:C:dehmrs:S:vV", long_options, &index); + c = getopt_long(argc, argv, "c:C:dehmrs:S:t:vV", long_options, &index); if (c == -1) { break; } @@ -207,6 +209,9 @@ main(int argc, char *argv[]) case 'S': primary_client = optarg; break; + case 't': + server.window_title_fmt = optarg; + break; case 'v': print_version(); exit(0); @@ -265,6 +270,10 @@ main(int argc, char *argv[]) increase_nofile_limit(); + if (string_null_or_empty(server.window_title_fmt)) { + server.window_title_fmt = "labwc - %o"; + } + server_init(); server_start(); diff --git a/src/output.c b/src/output.c index 1139aca2..33154e58 100644 --- a/src/output.c +++ b/src/output.c @@ -10,6 +10,7 @@ #include "output.h" #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include "common/macros.h" #include "common/mem.h" #include "common/scene-helpers.h" +#include "common/string-helpers.h" #include "config/rcxml.h" #include "labwc.h" #include "layers.h" @@ -605,13 +607,11 @@ handle_new_output(struct wl_listener *listener, void *data) } if (wlr_output_is_wl(wlr_output)) { - char title[64]; - if (getenv("LABWC_TITLE")) { - snprintf(title, sizeof(title), "%s", getenv("LABWC_TITLE")); - } else { - snprintf(title, sizeof(title), "%s - %s", "labwc", wlr_output->name); - } - wlr_wl_output_set_title(wlr_output, title); + gchar** parts = g_strsplit(server.window_title_fmt, "%o", -1); + gchar* formatted_title = g_strjoinv(wlr_output->name, parts); + g_strfreev(parts); + wlr_wl_output_set_title(wlr_output, formatted_title); + g_free(formatted_title); wlr_wl_output_set_app_id(wlr_output, "labwc"); }