dedicated dumb client to run bspc query -D -d .occupied --names
This commit is contained in:
parent
0fca3dba56
commit
fb2a937f02
42
bspc.c
42
bspc.c
|
@ -29,23 +29,17 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <sys/un.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* prototypes */
|
||||
void warn(char *fmt, ...);
|
||||
|
@ -218,16 +212,12 @@ bool is_hex_color(const char *color)
|
|||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
char *send_msg_to_bspwm(char *args[], int count)
|
||||
{
|
||||
int sock_fd;
|
||||
struct sockaddr_un sock_address;
|
||||
char msg[BUFSIZ], rsp[BUFSIZ];
|
||||
|
||||
if (argc < 2) {
|
||||
err("No arguments given.\n");
|
||||
}
|
||||
|
||||
sock_address.sun_family = AF_UNIX;
|
||||
char *sp;
|
||||
|
||||
|
@ -251,11 +241,10 @@ int main(int argc, char *argv[])
|
|||
err("Failed to connect to the socket.\n");
|
||||
}
|
||||
|
||||
argc--, argv++;
|
||||
int msg_len = 0;
|
||||
|
||||
for (int offset = 0, rem = sizeof(msg), n = 0; argc > 0 && rem > 0; offset += n, rem -= n, argc--, argv++) {
|
||||
n = snprintf(msg + offset, rem, "%s%c", *argv, 0);
|
||||
for (int offset = 0, rem = sizeof(msg), n = 0; count > 0 && rem > 0; offset += n, rem -= n, count--, args++) {
|
||||
n = snprintf(msg + offset, rem, "%s%c", *args, 0);
|
||||
msg_len += n;
|
||||
}
|
||||
|
||||
|
@ -274,14 +263,7 @@ int main(int argc, char *argv[])
|
|||
if (fds[0].revents & POLLIN) {
|
||||
if ((nb = recv(sock_fd, rsp, sizeof(rsp)-1, 0)) > 0) {
|
||||
rsp[nb] = '\0';
|
||||
if (rsp[0] == FAILURE_MESSAGE[0]) {
|
||||
ret = EXIT_FAILURE;
|
||||
fprintf(stderr, "%s", rsp + 1);
|
||||
fflush(stderr);
|
||||
} else {
|
||||
fprintf(stdout, "%s", rsp);
|
||||
fflush(stdout);
|
||||
}
|
||||
return strdup(rsp);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -292,5 +274,13 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
close(sock_fd);
|
||||
return ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char *text[] = {"query", "-D", "-d", ".occupied", "--names"};
|
||||
int count = 5;
|
||||
|
||||
char *hi = send_msg_to_bspwm(text, count);
|
||||
printf("%s", hi);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue