Compare commits

..

No commits in common. "1149930689ecdd3b19c63d07b3782b30714f2be8" and "641899d4733b3f2d33e35a6c39902c006d8b7782" have entirely different histories.

42
dwlb.c
View File

@ -111,7 +111,6 @@
" -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"
@ -209,6 +208,8 @@ static uint32_t height, textpadding, buffer_scale;
static bool run_display; static bool run_display;
static char *last_logged_title = NULL;
#include "config.h" #include "config.h"
static void static void
@ -1220,6 +1221,7 @@ read_stdin(void)
if (!(bar->window_title = strdup(wordend))) if (!(bar->window_title = strdup(wordend)))
EDIE("strdup"); EDIE("strdup");
bar->redraw = true; bar->redraw = true;
last_logged_title = strdup(wordend);
} else if (!strcmp(wordbeg, "selmon")) { } else if (!strcmp(wordbeg, "selmon")) {
ADVANCE(); ADVANCE();
if ((val = atoi(wordbeg)) != bar->sel) { if ((val = atoi(wordbeg)) != bar->sel) {
@ -1452,14 +1454,11 @@ read_socket(void)
if ((cli_fd = accept(sock_fd, NULL, 0)) == -1) if ((cli_fd = accept(sock_fd, NULL, 0)) == -1)
EDIE("accept"); EDIE("accept");
ssize_t len = recv(cli_fd, sockbuf, sizeof sockbuf - 1, 0); ssize_t len = recv(cli_fd, sockbuf, sizeof sockbuf - 1, 0);
if (len == -1) { if (len == -1)
close(cli_fd);
EDIE("recv"); EDIE("recv");
} close(cli_fd);
if (len == 0) { if (len == 0)
close(cli_fd);
return; return;
}
sockbuf[len] = '\0'; sockbuf[len] = '\0';
char *wordbeg, *wordend; char *wordbeg, *wordend;
@ -1489,7 +1488,6 @@ read_socket(void)
} }
if (!all && !bar) if (!all && !bar)
close(cli_fd);
return; return;
ADVANCE(); ADVANCE();
@ -1549,10 +1547,11 @@ read_socket(void)
hide_bar(bar); hide_bar(bar);
} }
} else if (!strcmp(wordbeg, "printinfo")) { } else if (!strcmp(wordbeg, "printinfo")) {
const char *info = (bar->window_title && bar->window_title[0] != '\0') ? bar->window_title : "(none)"; FILE *f = fopen("/tmp/dwlb_info", "w");
if (send(cli_fd, info, strlen(info), 0) == -1) { if (f) {
perror("send"); fprintf(f, "%s", last_logged_title ? last_logged_title : "(none)");
} fclose(f);
}
} else if (!strcmp(wordbeg, "toggle-visibility")) { } else if (!strcmp(wordbeg, "toggle-visibility")) {
if (all) { if (all) {
wl_list_for_each(bar, &bar_list, link) wl_list_for_each(bar, &bar_list, link)
@ -1599,7 +1598,6 @@ read_socket(void)
else else
set_bottom(bar); set_bottom(bar);
} }
close(cli_fd);
} }
} }
@ -1752,23 +1750,7 @@ main(int argc, char **argv)
} else if (!strcmp(argv[i], "-printinfo")) { } else if (!strcmp(argv[i], "-printinfo")) {
if (++i >= argc) if (++i >= argc)
DIE("Option -printinfo requires an argument"); DIE("Option -printinfo requires an argument");
int sockfd; client_send_command(&sock_address, argv[i], "printinfo", NULL, target_socket);
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
EDIE("socket");
snprintf(sock_address.sun_path, sizeof(sock_address.sun_path), "%s/%s", socketdir, target_socket ? target_socket : "dwlb-0");
if (connect(sockfd, (struct sockaddr *)&sock_address, sizeof(sock_address)) == -1)
EDIE("connect");
char cmd[256];
snprintf(cmd, sizeof(cmd), "%s printinfo", argv[i]);
if (send(sockfd, cmd, strlen(cmd), 0) == -1)
EDIE("send");
char buf[1024];
ssize_t len = recv(sockfd, buf, sizeof(buf) - 1, 0);
if (len > 0) {
buf[len] = '\0';
printf("%s\n", buf);
}
close(sockfd);
return 0; return 0;
} else if (!strcmp(argv[i], "-toggle-visibility")) { } else if (!strcmp(argv[i], "-toggle-visibility")) {
if (++i >= argc) if (++i >= argc)