add bspwm module
This commit is contained in:
parent
fb2a937f02
commit
c1e5b28402
46
bspc.c
46
bspc.c
|
@ -129,7 +129,7 @@ char *copy_string(char *str, size_t len)
|
|||
{
|
||||
char *cpy = calloc(1, ((len+1) * sizeof(char)));
|
||||
if (cpy == NULL) {
|
||||
perror("Copy string: calloc");
|
||||
perror("Copy string: callow");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(cpy, str, len);
|
||||
|
@ -216,7 +216,8 @@ char *send_msg_to_bspwm(char *args[], int count)
|
|||
{
|
||||
int sock_fd;
|
||||
struct sockaddr_un sock_address;
|
||||
char msg[BUFSIZ], rsp[BUFSIZ];
|
||||
char msg[BUFSIZ];
|
||||
static char rsp[BUFSIZ];
|
||||
|
||||
sock_address.sun_family = AF_UNIX;
|
||||
char *sp;
|
||||
|
@ -263,7 +264,7 @@ char *send_msg_to_bspwm(char *args[], int count)
|
|||
if (fds[0].revents & POLLIN) {
|
||||
if ((nb = recv(sock_fd, rsp, sizeof(rsp)-1, 0)) > 0) {
|
||||
rsp[nb] = '\0';
|
||||
return strdup(rsp);
|
||||
return rsp;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -278,9 +279,42 @@ char *send_msg_to_bspwm(char *args[], int count)
|
|||
}
|
||||
|
||||
int main(void) {
|
||||
char *text[] = {"query", "-D", "-d", ".occupied", "--names"};
|
||||
char finalbuffer[64], currentdesktop[2];
|
||||
char *occupied[] = {"query", "-D", "-d", ".occupied", "--names"};
|
||||
char *focused[] = {"query", "-D", "-d", ".focused", "--names"};
|
||||
char *result;
|
||||
char current;
|
||||
int count = 5;
|
||||
|
||||
char *hi = send_msg_to_bspwm(text, count);
|
||||
printf("%s", hi);
|
||||
result = send_msg_to_bspwm(occupied, count);
|
||||
if(!result) {
|
||||
printf("error: sending message to bspwm failed!\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(&finalbuffer, result, 64);
|
||||
|
||||
result = send_msg_to_bspwm(focused, count);
|
||||
if(!result) {
|
||||
printf("error: sending message to bspwm failed!\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy(¤tdesktop, result, 2);
|
||||
*(currentdesktop + 1) = '\0';
|
||||
|
||||
result = finalbuffer;
|
||||
for(int i = 0; i < 64; i++) {
|
||||
current = *(finalbuffer + i);
|
||||
if(current == '\0') break;
|
||||
if(isdigit(current) && *currentdesktop == current)
|
||||
*(finalbuffer + i + 1) = '<';
|
||||
if(current == '\n')
|
||||
current = ' ';
|
||||
}
|
||||
printf("%s", finalbuffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue