add a new module to the statusbar
make it such that notifications can occur. that is, write to ~/.cache/statusbar_notification, and things appear on the bar. pretty cool right?
This commit is contained in:
parent
405fed6955
commit
275fa01164
|
@ -1,6 +1,6 @@
|
|||
LDFLAGS=`pkg-config --cflags --libs xcb`
|
||||
CFLAGS=-ggdb -fsanitize=address
|
||||
main: battery.o bspwm.o time.o battstatus.o
|
||||
main: battery.o bspwm.o time.o battstatus.o message.o
|
||||
|
||||
clean:
|
||||
rm *.o main
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
#include "battstatus.h"
|
||||
#include "bspwm.h"
|
||||
#include "time.h"
|
||||
#include "message.h"
|
||||
|
||||
struct module mods[] = {
|
||||
{mod_battery, "battery", "BAT0", { '\0' }},
|
||||
{mod_battstatus, "battstatus", "BAT0", { '\0' }},
|
||||
{mod_time, "time", "", { '\0' }},
|
||||
{mod_bspwm, "bspwm", "", { '\0' }},
|
||||
{mod_message, "message", "/home/usr/.cache/statusbar_notification", { '\0' }},
|
||||
};
|
||||
|
||||
void create_module_proc(int index, char *pipename) {
|
||||
|
@ -59,17 +61,12 @@ void redraw() {
|
|||
static char NAMED_PIPE[] = "/home/usr/.cache/statusbar_pipe";
|
||||
|
||||
int main(void) {
|
||||
char pipename[BUFFER_SIZE];
|
||||
srand(time(NULL));
|
||||
strcpy(pipename, &NAMED_PIPE);
|
||||
pipename[sizeof(NAMED_PIPE) - 1] = 'A' + (rand() % 26);
|
||||
pipename[sizeof(NAMED_PIPE)] = 'A' + (rand() % 26);
|
||||
pipename[sizeof(NAMED_PIPE) + 1] = '\0';
|
||||
mkfifo(pipename, 0666);
|
||||
int fd = open(pipename, O_RDWR);
|
||||
mkfifo(&NAMED_PIPE, 0666); /* it's okay if this fails */
|
||||
int fd = open(&NAMED_PIPE, O_RDWR);
|
||||
struct message msg;
|
||||
|
||||
create_module_procs(pipename);
|
||||
create_module_procs(&NAMED_PIPE);
|
||||
|
||||
for (;;) {
|
||||
int ret = read(fd, &msg, sizeof(msg));
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#include "message.h"
|
||||
#include "common.h"
|
||||
|
||||
int mod_message(char *config, char *name, char *pipename) {
|
||||
struct message msg;
|
||||
struct inotify_event buf;
|
||||
strcpy(msg.name, name);
|
||||
|
||||
int fd = inotify_init();
|
||||
int outfd = open(pipename, O_WRONLY);
|
||||
|
||||
for(;;) {
|
||||
int watchdesc = inotify_add_watch(fd, config, IN_MODIFY);
|
||||
read(fd, &buf, sizeof(struct inotify_event));
|
||||
|
||||
/* the file's changed, so reread it */
|
||||
int filefd = open(config, O_RDONLY, 0);
|
||||
int read_in = read(filefd, msg.content, sizeof(msg.content));
|
||||
msg.content[read_in - 1] = '\0';
|
||||
close(filefd);
|
||||
|
||||
/* write the new */
|
||||
write(outfd, &msg, sizeof(msg));
|
||||
inotify_rm_watch(fd, watchdesc); /* not sure why this is needed */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef STATUS_MESSAGE_H
|
||||
#define STATUS_MESSAGE_H
|
||||
|
||||
int mod_message(char *config, char *name, char *pipename);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue