commit 118ac041ca319a377f8d63bd0f11265c26676e89
parent ce99b50cb1fb18a14756ec822711f7bc704c5df6
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 27 Sep 2020 20:42:10 +0200
Add special event (such as click) handling
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/blocks.def.h b/blocks.def.h
@@ -1,6 +1,6 @@
#define SCRIPT_DIR(x) "/opt/wmsl-scripts/" x
-/* use READY or IDLE to set if script should be run on startup */
+/* use flags to set the scripts starting behavior */
struct block blocks[] = {
/* command block-id interval flags */
diff --git a/wmsl.c b/wmsl.c
@@ -13,9 +13,10 @@
#define OUTPUTMAX 256
#define STATUSMAX 1024
-enum block_state {
- IDLE,
- READY
+enum {
+ IDLE = 0,
+ READY = 1,
+ EVENT = 2
};
struct block {
@@ -69,8 +70,10 @@ signal_handler(int sig, siginfo_t *info, void *context)
debug("received signal for block with id %i\n", block_id);
for (i = 0; i < ARRSIZE(blocks); i++) {
- if (blocks[i].id == block_id) {
+ if (blocks[i].id == abs(block_id)) {
blocks[i].flags |= READY;
+ if (block_id < 0)
+ blocks[i].flags |= EVENT;
break;
}
}
@@ -104,6 +107,10 @@ update_blocks()
if ((blocks[i].flags & READY) ||
blocks[i].sleep_max && blocks[i].sleep_left <= 0.5) {
blocks[i].sleep_left = blocks[i].sleep_max;
+ if (blocks[i].flags & EVENT)
+ setenv("WMSLEVENT", "1", 1);
+ else
+ unsetenv("WMSLEVENT");
blocks[i].flags = IDLE;
/* get command output */