Improved the -printinfo function, not it prints the title of the focused window. Also updated the help to inform user of the option

This commit is contained in:
André Desgualdo Pereira 2025-10-26 08:19:28 -03:00
parent 641899d473
commit e0bf2d0483

22
dwlb.c
View File

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