diff options
| author | Federico Angelilli <code@fedang.net> | 2025-04-12 17:40:28 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2025-04-12 17:40:28 +0200 |
| commit | 47dfeaa43f263896ad8ce13701f8a65c489f0bb9 (patch) | |
| tree | 600f00943bf2bde5f84e783bebf3fc12060c191f | |
| parent | fd2ef765de733fbbbb15e28c91df255da36d5338 (diff) | |
Start working on Lua bindings
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | README | 6 | ||||
| -rw-r--r-- | comet.conf | 4 | ||||
| -rw-r--r-- | src/action.c | 4 | ||||
| -rw-r--r-- | src/block.h | 4 | ||||
| -rw-r--r-- | src/blocks/slider.c | 4 | ||||
| -rw-r--r-- | src/comet.c | 6 | ||||
| -rw-r--r-- | src/event.c | 4 | ||||
| -rw-r--r-- | src/layout.c | 8 | ||||
| -rw-r--r-- | src/lua/api.c | 14 | ||||
| -rw-r--r-- | src/lua/api.h | 17 |
11 files changed, 59 insertions, 15 deletions
@@ -10,7 +10,8 @@ PCDEP = xcb \ xcb-shape \ xcb-errors \ "xcb-randr >= 1.5" \ - pangocairo + pangocairo \ + lua5.4 CFLAGS := $(shell pkg-config --cflags $(PCDEP)) -Wall -Werror $(CFLAGS) LDFLAGS := $(shell pkg-config --libs $(PCDEP)) -lm $(LDFLAGS) @@ -1 +1,7 @@ Comet is a wip status bar + +TODOs: +- Add script integration with Lua (like NVim) +- Fix blocks (e.g. slider) +- Add effect/animation system +- Add systray support @@ -98,12 +98,12 @@ sus = 1 [block.slide] type = slider bar-value = 88 - ;color = #18baf2 + color = #18baf2 bar-width = 120 bar-height = 17 bar-color = #f1baee, #CCCCFF bar-line-color = #000 - bar-line-width = 10 + ;bar-line-width = 10 bar-bg-color = #fff seekable = true knob = rectangle diff --git a/src/action.c b/src/action.c index df6ad3a..a09d7e5 100644 --- a/src/action.c +++ b/src/action.c @@ -103,8 +103,8 @@ bool action_perform(action_t *action, block_t *block, config_t *config) event_init_trigger(&event, action->label, value); action_t *action = target->actions[EVENT_TRIGGER]; - block_event_t event_fn = target->type == BLOCK_SPEC - ? ((block_spec_t *)target)->event_fn + block_event_t event_fn = target->type == BLOCK_DYNAMIC + ? ((block_dynamic_t *)target)->event_fn : NULL; log_value_debug("Block received a trigger", diff --git a/src/block.h b/src/block.h index 983c6b9..cda6444 100644 --- a/src/block.h +++ b/src/block.h @@ -23,7 +23,7 @@ typedef enum { typedef enum { BLOCK_TEXT, BLOCK_GROUP, - BLOCK_SPEC, + BLOCK_DYNAMIC, } block_type_t; typedef struct block block_t; @@ -90,7 +90,7 @@ typedef struct { block_layout_t layout_fn; block_render_t render_fn; block_event_t event_fn; -} block_spec_t; +} block_dynamic_t; // Called to allocate a block with its default state // diff --git a/src/blocks/slider.c b/src/blocks/slider.c index f4a9ad0..93b51d2 100644 --- a/src/blocks/slider.c +++ b/src/blocks/slider.c @@ -17,7 +17,7 @@ typedef enum { } block_slider_knob_t; typedef struct { - block_spec_t block; + block_dynamic_t block; int value; unsigned int height; unsigned int width; @@ -240,7 +240,7 @@ static void block_slider_event(layout_t *layout, config_t *config, event_t event static void block_slider_init(block_t *block) { - block->type = BLOCK_SPEC; + block->type = BLOCK_DYNAMIC; block_slider_t *slider = (block_slider_t *)block; slider->block.layout_fn = block_slider_layout; slider->block.render_fn = block_slider_render; diff --git a/src/comet.c b/src/comet.c index dbb7139..fec831e 100644 --- a/src/comet.c +++ b/src/comet.c @@ -9,6 +9,7 @@ #include "event.h" #include "config.h" #include "block.h" +#include "lua/api.h" #ifdef RELEASE #define ANY_LOG_VALUE_BEFORE(level, module, func, message) \ @@ -70,6 +71,9 @@ int main(int argc, char **argv) any_log_init(stdout, log_level); + lua_api_t lua; + lua_api_init(&lua); + config_t config; config_init(&config); log_debug("Copied default config"); @@ -162,7 +166,9 @@ int main(int argc, char **argv) window_close(&window); display_close(&display); + config_free(&config); + lua_api_close(&lua); return 0; } diff --git a/src/event.c b/src/event.c index 24975bf..db00e30 100644 --- a/src/event.c +++ b/src/event.c @@ -86,8 +86,8 @@ static layout_t *event_dispatch_find(block_t *block, layout_t *layout) static void event_dispatch_callback(event_state_t *state, layout_t *layout, event_t event) { - block_event_t event_fn = layout->block->type == BLOCK_SPEC - ? ((block_spec_t *)layout->block)->event_fn + block_event_t event_fn = layout->block->type == BLOCK_DYNAMIC + ? ((block_dynamic_t *)layout->block)->event_fn : NULL; log_value_debug("Block received an event", diff --git a/src/layout.c b/src/layout.c index ee82f83..e45526a 100644 --- a/src/layout.c +++ b/src/layout.c @@ -72,9 +72,9 @@ void layout_init(layout_t *layout, block_t *block, layout_info_t info) break; } - case BLOCK_SPEC: { + case BLOCK_DYNAMIC: { // You are on your own - block_spec_t *spec = (block_spec_t *)block; + block_dynamic_t *spec = (block_dynamic_t *)block; spec->layout_fn(block, layout, info); // TODO: Add more checks @@ -155,12 +155,12 @@ void layout_render(layout_t *layout, cairo_t *cr) break; } - case BLOCK_SPEC: { + case BLOCK_DYNAMIC: { // NOTE: What if a special block adds children to the layout? // For now do nothing and let them handle it, however // this is a strange behavior in my opinion... // - block_spec_t *spec = (block_spec_t *)layout->block; + block_dynamic_t *spec = (block_dynamic_t *)layout->block; spec->render_fn(layout, cr); break; } diff --git a/src/lua/api.c b/src/lua/api.c new file mode 100644 index 0000000..5a29cca --- /dev/null +++ b/src/lua/api.c @@ -0,0 +1,14 @@ +#include "api.h" + + +bool lua_api_init(lua_api_t *api) +{ + api->state = luaL_newstate(); + luaL_openlibs(api->state); + return true; +} + +void lua_api_close(lua_api_t *api) +{ + lua_close(api->state); +} diff --git a/src/lua/api.h b/src/lua/api.h new file mode 100644 index 0000000..a134aa0 --- /dev/null +++ b/src/lua/api.h @@ -0,0 +1,17 @@ +#ifndef COMET_LUA_API_H +#define COMET_LUA_API_H + +#include <lauxlib.h> +#include <lua.h> +#include <lualib.h> +#include <stdbool.h> + +typedef struct { + lua_State *state; +} lua_api_t; + +bool lua_api_init(lua_api_t *api); + +void lua_api_close(lua_api_t *api); + +#endif |
