aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-09-12 19:19:45 +0200
committerFederico Angelilli <code@fedang.net>2024-09-12 19:19:45 +0200
commitbc70dead7fb518f073fecb21a04fa374e9ad6dd0 (patch)
treeae26af52759cd63310a965a8e2bfe0f3b4083f62
parentbd8dbe03ead6c73f28df517f8873675108277bf5 (diff)
Start working on actions
-rw-r--r--comet.conf2
-rw-r--r--src/action.c3
-rw-r--r--src/action.h25
-rw-r--r--src/block.c8
-rw-r--r--src/block.h16
-rw-r--r--src/blocks/date.c4
-rw-r--r--src/blocks/fs.c6
-rw-r--r--src/blocks/ram.c6
-rw-r--r--src/effect.c1
-rw-r--r--src/effect.h3
-rw-r--r--src/event.c9
11 files changed, 53 insertions, 30 deletions
diff --git a/comet.conf b/comet.conf
index a405f74..7ea5933 100644
--- a/comet.conf
+++ b/comet.conf
@@ -22,7 +22,7 @@
text-color = #a123fc
text = "a"
color = #fff
- x-padding = 2
+ ;x-padding = 10
y-padding = 2
[block.perf]
diff --git a/src/action.c b/src/action.c
new file mode 100644
index 0000000..2508b5c
--- /dev/null
+++ b/src/action.c
@@ -0,0 +1,3 @@
+#include "action.h"
+
+
diff --git a/src/action.h b/src/action.h
new file mode 100644
index 0000000..1990de6
--- /dev/null
+++ b/src/action.h
@@ -0,0 +1,25 @@
+#ifndef COMET_ACTION_H
+#define COMET_ACTION_H
+
+#include "event.h"
+
+// TODO
+
+typedef enum {
+ ACTION_SCRIPT
+} action_type_t;
+
+typedef struct action action_t;
+
+typedef struct layout layout_t;
+
+struct action {
+ action_type_t type;
+ char *label;
+};
+
+void action_perform(action_t *action, const layout_t *layout, event_t event);
+
+void action_free(action_t *action);
+
+#endif
diff --git a/src/block.c b/src/block.c
index 29a8394..e6289a1 100644
--- a/src/block.c
+++ b/src/block.c
@@ -6,7 +6,7 @@
void block_update(block_t *block)
{
- if (block->update_cb != NULL) {
+ if (block->update != NULL) {
struct timespec now, diff;
timespec_get(&now, TIME_UTC);
diff = timespec_diff(now, block->update_last);
@@ -16,7 +16,7 @@ void block_update(block_t *block)
"s:label", block->label,
"g:ts", ANY_LOG_FORMATTER(timespec_print), &now);
- block->update_cb(block);
+ block->update(block);
block->update_last = now;
}
}
@@ -57,6 +57,6 @@ void block_free(block_t *block)
free(block->group.children);
}
- if (block->finalize_cb != NULL)
- block->finalize_cb(block);
+ if (block->finalize != NULL)
+ block->finalize(block);
}
diff --git a/src/block.h b/src/block.h
index 6eeb0c0..d38a79d 100644
--- a/src/block.h
+++ b/src/block.h
@@ -8,6 +8,8 @@
#include "event.h"
#include "util.h"
#include "config.h"
+#include "action.h"
+#include "effect.h"
// Element or text alignment
//
@@ -26,10 +28,6 @@ typedef enum {
typedef struct block block_t;
-// Triggered when an event is directed towards the block
-//
-typedef void (*block_event_t)(block_t *block, event_t event);
-
// Regularly called depending on the inverval passed from the last update
//
typedef void (*block_update_t)(block_t *block);
@@ -49,10 +47,12 @@ struct block {
void *state;
struct timespec update_interval;
struct timespec update_last;
- block_update_t update_cb;
- block_event_t event_cb;
- block_finalize_t finalize_cb;
- struct effect *effect;
+ block_update_t update;
+ block_finalize_t finalize;
+ effect_t *effect;
+ action_t *right_click_action;
+ action_t *middle_click_action;
+ action_t *left_click_action;
color_t color;
color_t line_color;
unsigned int line_width;
diff --git a/src/blocks/date.c b/src/blocks/date.c
index 01c62c3..887346e 100644
--- a/src/blocks/date.c
+++ b/src/blocks/date.c
@@ -44,8 +44,8 @@ const block_scheme_t block_date_scheme = {
.tv_sec = 1,
.tv_nsec = 0,
},
- .update_cb = block_date_update,
- .finalize_cb = block_date_finalize,
+ .update = block_date_update,
+ .finalize = block_date_finalize,
},
.size = sizeof(char *),
.entries = NULL,
diff --git a/src/blocks/fs.c b/src/blocks/fs.c
index 65e8fe2..98a5059 100644
--- a/src/blocks/fs.c
+++ b/src/blocks/fs.c
@@ -58,7 +58,7 @@ static bool block_fs_validate(block_t *block, const block_scheme_t *scheme)
if (strstr(block->text.text, "%{") == NULL) {
log_warn("Block '%s' does not use any fs variable", block->label);
- block->update_cb = NULL;
+ block->update = NULL;
log_debug("Disabled updates for block '%s'", block->label);
return true;
}
@@ -90,8 +90,8 @@ const block_scheme_t block_fs_scheme = {
.tv_sec = 20,
.tv_nsec = 0,
},
- .update_cb = block_fs_update,
- .finalize_cb = block_fs_finalize,
+ .update = block_fs_update,
+ .finalize = block_fs_finalize,
},
.size = 2 * sizeof(char *),
.entries = block_fs_entries,
diff --git a/src/blocks/ram.c b/src/blocks/ram.c
index 5a95013..ade7aac 100644
--- a/src/blocks/ram.c
+++ b/src/blocks/ram.c
@@ -67,7 +67,7 @@ static bool block_ram_validate(block_t *block, const block_scheme_t *scheme)
if (strstr(block->text.text, "%{") == NULL) {
log_warn("Block '%s' does not use any ram variable", block->label);
- block->update_cb = NULL;
+ block->update = NULL;
log_debug("Disabled updates for block '%s'", block->label);
return true;
}
@@ -85,8 +85,8 @@ const block_scheme_t block_ram_scheme = {
.tv_sec = 1,
.tv_nsec = 0,
},
- .update_cb = block_ram_update,
- .finalize_cb = block_ram_finalize,
+ .update = block_ram_update,
+ .finalize = block_ram_finalize,
},
.size = sizeof(char *),
.entries = NULL,
diff --git a/src/effect.c b/src/effect.c
index ae44c68..705c42d 100644
--- a/src/effect.c
+++ b/src/effect.c
@@ -1,5 +1,6 @@
#include <math.h>
+#include "layout.h"
#include "effect.h"
#include "any_log.h"
diff --git a/src/effect.h b/src/effect.h
index b6c6282..1bf1a9e 100644
--- a/src/effect.h
+++ b/src/effect.h
@@ -4,7 +4,6 @@
#include <cairo.h>
#include "util.h"
-#include "layout.h"
typedef enum {
EFFECT_PULSE,
@@ -12,6 +11,8 @@ typedef enum {
typedef struct effect effect_t;
+typedef struct layout layout_t;
+
typedef void (*effect_render_t)(effect_t *effect, layout_t *layout, cairo_t *cr);
struct effect {
diff --git a/src/event.c b/src/event.c
index a433fba..5d315a3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -36,7 +36,6 @@ static bool event_click(layout_t *layout, event_t event)
layout->block->effect = effect_pulse(timespec_from_ms(200));
}
- block_event_t event_cb = layout->block->event_cb;
log_value_debug("Block was clicked",
"s:type", even_type_to_string(event.type),
"i:x", event.x,
@@ -45,13 +44,7 @@ static bool event_click(layout_t *layout, event_t event)
"i:block_x", layout->x,
"i:block_y", layout->y,
"i:block_width", layout->width,
- "i:block_height", layout->height,
- "b:callback", event_cb != NULL);
-
- if (event_cb != NULL) {
- event_cb(layout->block, event);
- log_trace("Completed event callback");
- }
+ "i:block_height", layout->height);
return true;
}