mirror of
https://github.com/kolunmi/dwlb.git
synced 2025-12-15 02:23:18 +00:00
Compare commits
3 Commits
641899d473
...
1149930689
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1149930689 | ||
|
|
bdfee2104f | ||
|
|
e0bf2d0483 |
42
dwlb.c
42
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"
|
||||
@ -208,8 +209,6 @@ static uint32_t height, textpadding, buffer_scale;
|
||||
|
||||
static bool run_display;
|
||||
|
||||
static char *last_logged_title = NULL;
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static void
|
||||
@ -1221,7 +1220,6 @@ read_stdin(void)
|
||||
if (!(bar->window_title = strdup(wordend)))
|
||||
EDIE("strdup");
|
||||
bar->redraw = true;
|
||||
last_logged_title = strdup(wordend);
|
||||
} else if (!strcmp(wordbeg, "selmon")) {
|
||||
ADVANCE();
|
||||
if ((val = atoi(wordbeg)) != bar->sel) {
|
||||
@ -1454,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;
|
||||
@ -1488,6 +1489,7 @@ read_socket(void)
|
||||
}
|
||||
|
||||
if (!all && !bar)
|
||||
close(cli_fd);
|
||||
return;
|
||||
|
||||
ADVANCE();
|
||||
@ -1547,11 +1549,10 @@ read_socket(void)
|
||||
hide_bar(bar);
|
||||
}
|
||||
} else if (!strcmp(wordbeg, "printinfo")) {
|
||||
FILE *f = fopen("/tmp/dwlb_info", "w");
|
||||
if (f) {
|
||||
fprintf(f, "%s", last_logged_title ? last_logged_title : "(none)");
|
||||
fclose(f);
|
||||
}
|
||||
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)
|
||||
@ -1598,6 +1599,7 @@ read_socket(void)
|
||||
else
|
||||
set_bottom(bar);
|
||||
}
|
||||
close(cli_fd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1750,7 +1752,23 @@ main(int argc, char **argv)
|
||||
} else if (!strcmp(argv[i], "-printinfo")) {
|
||||
if (++i >= argc)
|
||||
DIE("Option -printinfo requires an argument");
|
||||
client_send_command(&sock_address, argv[i], "printinfo", NULL, target_socket);
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user