From e0bf2d04832d4de76c784c32ef53c3434e244b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Desgualdo=20Pereira?= Date: Sun, 26 Oct 2025 08:19:28 -0300 Subject: [PATCH] Improved the -printinfo function, not it prints the title of the focused window. Also updated the help to inform user of the option --- dwlb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dwlb.c b/dwlb.c index 1572cd7..3e19285 100644 --- a/dwlb.c +++ b/dwlb.c @@ -111,6 +111,7 @@ " -set-top [OUTPUT] draw bar at the top\n" \ " -set-bottom [OUTPUT] draw bar at the bottom\n" \ " -toggle-location [OUTPUT] toggle bar location\n" \ + " -printinfo [OUTPUT] print the title of focused window\n" \ "Other\n" \ " -v get version information\n" \ " -h view this help text\n" @@ -1751,6 +1752,27 @@ main(int argc, char **argv) if (++i >= argc) DIE("Option -printinfo requires an argument"); client_send_command(&sock_address, argv[i], "printinfo", NULL, target_socket); + int wait_for_file_ready(const char *path, int timeout_ms) { + struct stat st; + int waited = 0; + while (waited < timeout_ms) { + if (stat(path, &st) == 0 && st.st_size > 0) + return 0; // file exists and not empty + usleep(10); // sleep .01 ms + waited += 1; + } + return -1; // timeout + } + if (wait_for_file_ready("/tmp/dwlb_info", 8) == 0) { // wait up to 8ms + FILE *f = fopen("/tmp/dwlb_info", "r"); + int c; + while ((c = fgetc(f)) != EOF) + putchar(c); + fclose(f); + } else { + fprintf(stderr, "Timed out waiting for info\n"); + } + remove("/tmp/dwlb_info"); return 0; } else if (!strcmp(argv[i], "-toggle-visibility")) { if (++i >= argc)