mirror of
https://github.com/kolunmi/dwlb.git
synced 2025-10-26 17:54:31 +00:00
Merge 1149930689ecdd3b19c63d07b3782b30714f2be8 into 48dbe00bdb98a1ae6a0e60558ce14503616aa759
This commit is contained in:
commit
337e53882f
38
dwlb.c
38
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"
|
||||
@ -1451,11 +1452,14 @@ read_socket(void)
|
||||
if ((cli_fd = accept(sock_fd, NULL, 0)) == -1)
|
||||
EDIE("accept");
|
||||
ssize_t len = recv(cli_fd, sockbuf, sizeof sockbuf - 1, 0);
|
||||
if (len == -1)
|
||||
if (len == -1) {
|
||||
close(cli_fd);
|
||||
EDIE("recv");
|
||||
close(cli_fd);
|
||||
if (len == 0)
|
||||
}
|
||||
if (len == 0) {
|
||||
close(cli_fd);
|
||||
return;
|
||||
}
|
||||
sockbuf[len] = '\0';
|
||||
|
||||
char *wordbeg, *wordend;
|
||||
@ -1485,6 +1489,7 @@ read_socket(void)
|
||||
}
|
||||
|
||||
if (!all && !bar)
|
||||
close(cli_fd);
|
||||
return;
|
||||
|
||||
ADVANCE();
|
||||
@ -1543,6 +1548,11 @@ read_socket(void)
|
||||
if (!bar->hidden)
|
||||
hide_bar(bar);
|
||||
}
|
||||
} else if (!strcmp(wordbeg, "printinfo")) {
|
||||
const char *info = (bar->window_title && bar->window_title[0] != '\0') ? bar->window_title : "(none)";
|
||||
if (send(cli_fd, info, strlen(info), 0) == -1) {
|
||||
perror("send");
|
||||
}
|
||||
} else if (!strcmp(wordbeg, "toggle-visibility")) {
|
||||
if (all) {
|
||||
wl_list_for_each(bar, &bar_list, link)
|
||||
@ -1589,6 +1599,7 @@ read_socket(void)
|
||||
else
|
||||
set_bottom(bar);
|
||||
}
|
||||
close(cli_fd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1738,6 +1749,27 @@ 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");
|
||||
int sockfd;
|
||||
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;
|
||||
} else if (!strcmp(argv[i], "-toggle-visibility")) {
|
||||
if (++i >= argc)
|
||||
DIE("Option -toggle requires an argument");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user