add a module system
This commit is contained in:
parent
f44a1c3ffe
commit
c97943855f
|
@ -1,2 +1,3 @@
|
||||||
tags
|
tags
|
||||||
bspc
|
bspc
|
||||||
|
tstatus
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -1,8 +1,8 @@
|
||||||
bspc:
|
tstatus:
|
||||||
cc bspc.c -o bspc -lxcb -Wall -Wextra -std=c99
|
cc tstatus.c -o tstatus -lxcb -Wall -Wextra -std=c99
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
cc bspc.c -o bspc -lxcb -Wall -Wextra -std=c99 -ggdb
|
cc tstatus.c -o tstatus -lxcb -Wall -Wextra -std=c99 -ggdb
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm bspc
|
rm tstatus
|
||||||
|
|
30
bspc.c
30
bspc.c
|
@ -27,6 +27,8 @@
|
||||||
#define SOCKET_ENV_VAR "BSPWM_SOCKET"
|
#define SOCKET_ENV_VAR "BSPWM_SOCKET"
|
||||||
#define FAILURE_MESSAGE "\x07"
|
#define FAILURE_MESSAGE "\x07"
|
||||||
|
|
||||||
|
#define LENGTH(x) (sizeof(x) / sizeof(*x))
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -42,6 +44,8 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
void warn(char *fmt, ...);
|
void warn(char *fmt, ...);
|
||||||
void err(char *fmt, ...);
|
void err(char *fmt, ...);
|
||||||
|
@ -279,23 +283,22 @@ char *send_msg_to_bspwm(char *args[], int count)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int bspwm_update(struct module *module) {
|
||||||
char final[64], current[2];
|
char current[2];
|
||||||
char *occupied[] = {"query", "-D", "-d", ".occupied", "--names"};
|
char *occupied[] = {"query", "-D", "-d", ".occupied", "--names"};
|
||||||
char *focused[] = {"query", "-D", "-d", ".focused", "--names"};
|
char *focused[] = {"query", "-D", "-d", ".focused", "--names"};
|
||||||
char *result;
|
char *result;
|
||||||
int count = 5;
|
|
||||||
|
|
||||||
result = send_msg_to_bspwm(occupied, count);
|
result = send_msg_to_bspwm(occupied, LENGTH(occupied));
|
||||||
if(!result) {
|
if(!result) {
|
||||||
printf("error: sending message to bspwm failed!\n");
|
printf("error: sending message to bspwm failed!\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&final, result, 64);
|
memcpy(&module->buffer, result, MODULE_BUFFER_LEN);
|
||||||
|
|
||||||
result = send_msg_to_bspwm(focused, count);
|
result = send_msg_to_bspwm(focused, LENGTH(focused));
|
||||||
if(!result) {
|
if(!result) {
|
||||||
printf("error: sending message to bspwm failed!\n");
|
printf("error: sending message to bspwm failed!\n");
|
||||||
|
|
||||||
|
@ -305,19 +308,18 @@ int main(void) {
|
||||||
memcpy(¤t, result, 2);
|
memcpy(¤t, result, 2);
|
||||||
current[1] = '\0';
|
current[1] = '\0';
|
||||||
|
|
||||||
for(int i = 0; i < 64; i++) {
|
for(int i = 0; i < MODULE_BUFFER_LEN; i++) {
|
||||||
if(final[i] == '\0') {
|
if(module->buffer[i] == '\0') {
|
||||||
/* XXX: susceptible to buffer underflow */
|
/* XXX: susceptible to buffer underflow */
|
||||||
if (i) final[i - 1] = '\0';
|
if(i) module->buffer[i - 1] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(isdigit(final[i]) && *current == final[i])
|
if(isdigit(module->buffer[i]) && *current == module->buffer[i])
|
||||||
/* XXX: susceptible to buffer overflow */
|
/* XXX: susceptible to buffer overflow */
|
||||||
final[i + 1] = '<';
|
if(i == MODULE_BUFFER_LEN) module->buffer[i + 1] = '<';
|
||||||
if(final[i] == '\n')
|
if(module->buffer[i] == '\n')
|
||||||
final[i] = ' ';
|
module->buffer[i] = ' ';
|
||||||
}
|
}
|
||||||
printf("%s", final);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef TSTATUS_MODULE_H
|
||||||
|
#define MODULE_BUFFER_LEN 64
|
||||||
|
struct module {
|
||||||
|
int update; /* update interval in seconds */
|
||||||
|
int termcode; /* update termcode */
|
||||||
|
|
||||||
|
int (*updatecallback)(struct module *); /* update function */
|
||||||
|
char buffer[MODULE_BUFFER_LEN]; /* buffer for text */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#define TSTATUS_MODULE_H
|
Loading…
Reference in New Issue