Add an option to retrieve the current focused window title from dwlb

This commit is contained in:
André Desgualdo Pereira 2025-10-22 16:27:08 -03:00
parent 48dbe00bdb
commit 641899d473

14
dwlb.c
View File

@ -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");