From 641899d4733b3f2d33e35a6c39902c006d8b7782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Desgualdo=20Pereira?= Date: Wed, 22 Oct 2025 16:27:08 -0300 Subject: [PATCH] Add an option to retrieve the current focused window title from dwlb --- dwlb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dwlb.c b/dwlb.c index faab2d9..1572cd7 100644 --- a/dwlb.c +++ b/dwlb.c @@ -208,6 +208,8 @@ static uint32_t height, textpadding, buffer_scale; static bool run_display; +static char *last_logged_title = NULL; + #include "config.h" static void @@ -1219,6 +1221,7 @@ read_stdin(void) if (!(bar->window_title = strdup(wordend))) EDIE("strdup"); bar->redraw = true; + last_logged_title = strdup(wordend); } else if (!strcmp(wordbeg, "selmon")) { ADVANCE(); if ((val = atoi(wordbeg)) != bar->sel) { @@ -1543,6 +1546,12 @@ read_socket(void) if (!bar->hidden) hide_bar(bar); } + } else if (!strcmp(wordbeg, "printinfo")) { + FILE *f = fopen("/tmp/dwlb_info", "w"); + if (f) { + fprintf(f, "%s", last_logged_title ? last_logged_title : "(none)"); + fclose(f); + } } else if (!strcmp(wordbeg, "toggle-visibility")) { if (all) { wl_list_for_each(bar, &bar_list, link) @@ -1738,6 +1747,11 @@ main(int argc, char **argv) DIE("Option -hide requires an argument"); client_send_command(&sock_address, argv[i], "hide", NULL, target_socket); return 0; + } else if (!strcmp(argv[i], "-printinfo")) { + if (++i >= argc) + DIE("Option -printinfo requires an argument"); + client_send_command(&sock_address, argv[i], "printinfo", NULL, target_socket); + return 0; } else if (!strcmp(argv[i], "-toggle-visibility")) { if (++i >= argc) DIE("Option -toggle requires an argument");