mirror of
https://github.com/kolunmi/dwlb.git
synced 2025-10-27 18:24:42 +00:00
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:
parent
641899d473
commit
e0bf2d0483
22
dwlb.c
22
dwlb.c
@ -111,6 +111,7 @@
|
|||||||
" -set-top [OUTPUT] draw bar at the top\n" \
|
" -set-top [OUTPUT] draw bar at the top\n" \
|
||||||
" -set-bottom [OUTPUT] draw bar at the bottom\n" \
|
" -set-bottom [OUTPUT] draw bar at the bottom\n" \
|
||||||
" -toggle-location [OUTPUT] toggle bar location\n" \
|
" -toggle-location [OUTPUT] toggle bar location\n" \
|
||||||
|
" -printinfo [OUTPUT] print the title of focused window\n" \
|
||||||
"Other\n" \
|
"Other\n" \
|
||||||
" -v get version information\n" \
|
" -v get version information\n" \
|
||||||
" -h view this help text\n"
|
" -h view this help text\n"
|
||||||
@ -1751,6 +1752,27 @@ main(int argc, char **argv)
|
|||||||
if (++i >= argc)
|
if (++i >= argc)
|
||||||
DIE("Option -printinfo requires an argument");
|
DIE("Option -printinfo requires an argument");
|
||||||
client_send_command(&sock_address, argv[i], "printinfo", NULL, target_socket);
|
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;
|
return 0;
|
||||||
} else if (!strcmp(argv[i], "-toggle-visibility")) {
|
} else if (!strcmp(argv[i], "-toggle-visibility")) {
|
||||||
if (++i >= argc)
|
if (++i >= argc)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user