features idk

This commit is contained in:
Gvidas Juknevičius 2024-06-16 20:09:24 +03:00
parent 63de55f170
commit 6357677d13
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
5 changed files with 52 additions and 3 deletions

View File

@ -5,7 +5,8 @@ CCARGS=-Isrc/include -Wall -pedantic
MODULES= \
modules/clock.dim \
modules/battery.dim \
modules/timesince.dim
modules/timesince.dim \
modules/volume.dim
all: $(BIN) $(MODULES) compile_commands.json
@ -16,7 +17,7 @@ $(BIN): src/main.c src/plug.c src/socket.c src/util.c
modules/%.dim: src/modules/%.c
mkdir -p $(dir $@)
$(CC) -o $@ $^ -rdynamic -shared -fPIC $(CCARGS)
$(CC) -o $@ $^ -rdynamic -shared -fPIC $(CCARGS) -lasound
compile_commands.json:
compiledb -n make

View File

@ -5,6 +5,7 @@
#include <stddef.h>
#include <stdbool.h>
typedef void* (*plug_init_f) (void);
typedef void* (*plug_pre_reload_f) (void);
typedef void (*plug_post_reload_f) (void*);
@ -31,5 +32,6 @@ char* poll_plugins(char* sep);
void free_plugins(void);
void reload_plugins(void);
#endif

36
src/include/plug_utils.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _H_PLUG_UTILS
#define _H_PLUG_UTILS
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
void* make_result_val(void* v, int size) {
void* v2 = malloc(size);
memcpy(v2, v, size);
return v2;
}
#define make_result(is_ok, v) ((Result){ \
.is_ok = (is_ok), \
.val = make_result_val((v), sizeof((v))) \
})
#define Ok(v) make_result(true, v)
#define Ok(v) make_result(true, v)
typedef struct Result {
bool is_ok;
void* val;
} Result;
void* res_unwrap(Result r) {
if (!r.is_ok) assert(0);
return r.val;
}
#endif

View File

@ -8,6 +8,16 @@
#include "plug.h"
#include "socket.h"
// TODO: Modules to add:
// - Sound level
// - cpu %
// - ram %
// - weather
// - cpu temp
// - uptime
// - storage usage
// - Network name + strength
void interrupt_handler(int);
void print_help(void);

View File

@ -36,7 +36,7 @@ void plug_poll(char* buf, size_t len) {
time_t diff = difftime(time(0), mktime(&t)) / (60 * 60 * 24);
snprintf(buf, len, " %ld days <3", diff);
snprintf(buf, len, "%ld days <3", diff);
}
void plug_free(void) {