Compare commits

..

No commits in common. "4922b7f304e00a02dbed320b19abc8ed07b939c0" and "a46131716ed30fa60bdd846f0f349eeae3f1d6fc" have entirely different histories.

7 changed files with 4 additions and 287 deletions

View File

@ -12,7 +12,7 @@ CPPFLAGS += $(shell pkg-config --cflags $(DEPS))
LDLIBS += $(shell pkg-config --libs $(DEPS)) LDLIBS += $(shell pkg-config --libs $(DEPS))
INTERP ?= INTERP ?=
MAIN = main MAIN = main
OBJS = main.o events.o processing.o graph.o config.o event_code_names.o hash_table.o module_registry.o event_predicate.o nodes/getchar.o nodes/print.o nodes/evdev.o nodes/tee.o nodes/router.o nodes/modifiers.o OBJS = main.o events.o processing.o graph.o config.o event_code_names.o hash_table.o module_registry.o event_predicate.o nodes/getchar.o nodes/print.o nodes/evdev.o nodes/tee.o nodes/router.o
all: $(MAIN) all: $(MAIN)

View File

@ -266,18 +266,12 @@ parse_event_predicate_type(const char *name)
if (strcmp(name, "payload") == 0) { if (strcmp(name, "payload") == 0) {
return EVPRED_PAYLOAD; return EVPRED_PAYLOAD;
} }
if (strcmp(name, "input_index") == 0) {
return EVPRED_INPUT_INDEX;
}
if (strcmp(name, "conjunction") == 0 || strcmp(name, "and") == 0) { if (strcmp(name, "conjunction") == 0 || strcmp(name, "and") == 0) {
return EVPRED_CONJUNCTION; return EVPRED_CONJUNCTION;
} }
if (strcmp(name, "disjunction") == 0 || strcmp(name, "or") == 0) { if (strcmp(name, "disjunction") == 0 || strcmp(name, "or") == 0) {
return EVPRED_DISJUNCTION; return EVPRED_DISJUNCTION;
} }
if (strcmp(name, "modifier") == 0) {
return EVPRED_MODIFIER;
}
return EVPRED_INVALID; return EVPRED_INVALID;
} }
@ -301,7 +295,7 @@ load_single_predicate(const config_setting_t * setting, EventPredicateHandleRegi
return -1; return -1;
case EVPRED_ACCEPT: case EVPRED_ACCEPT:
break; break;
case EVPRED_CODE_NS...EVPRED_INPUT_INDEX: case EVPRED_CODE_NS...EVPRED_PAYLOAD:
{ {
int64_t min_value = INT64_MIN; int64_t min_value = INT64_MIN;
int64_t max_value = INT64_MAX; int64_t max_value = INT64_MAX;
@ -327,15 +321,6 @@ load_single_predicate(const config_setting_t * setting, EventPredicateHandleRegi
predicate.aggregate_data.handles = handles; predicate.aggregate_data.handles = handles;
} }
break; break;
case EVPRED_MODIFIER:
{
long long modifier = resolve_constant_or(constants, config_setting_get_member(setting, "modifier"), -1);
if (modifier < 0 || modifier > MODIFIER_MAX) {
return -1;
}
predicate.single_modifier = modifier;
}
break;
default: default:
return -1; return -1;
} }

View File

@ -1,7 +1,3 @@
constants = {
my_modifier = 9;
};
enums = { enums = {
namespaces: ["stdin", "clickpad"]; namespaces: ["stdin", "clickpad"];
}; };
@ -46,21 +42,7 @@ nodes = {
select_key_events = { select_key_events = {
type = "router"; type = "router";
options = { options = {
predicates = ( predicates = ["key_event"];
"key_event",
{
type = "or";
inverted = 1;
args = ["key_event"];
}
);
};
};
set_modifier = {
type = "modifiers";
options = {
operation = "set";
modifiers = ["my_modifier"];
}; };
}; };
}; };
@ -73,13 +55,7 @@ channels = ({
to: ("select_key_events", 1); to: ("select_key_events", 1);
}, { }, {
from: ("select_key_events", 0); from: ("select_key_events", 0);
to: ("set_modifier", 0);
}, {
from: ("set_modifier", 0);
to: ("print", 0); to: ("print", 0);
}, {
from: ("select_key_events", 1);
to: ("print", 1);
}); });
// vim: ft=libconfig // vim: ft=libconfig

View File

@ -109,7 +109,7 @@ event_predicate_apply(EventPredicateHandle handle, EventNode * event)
case EVPRED_ACCEPT: case EVPRED_ACCEPT:
accepted = true; accepted = true;
break; break;
case EVPRED_CODE_NS...EVPRED_INPUT_INDEX: case EVPRED_CODE_NS...EVPRED_PAYLOAD:
if (!event) { if (!event) {
return EVPREDRES_DISABLED; return EVPREDRES_DISABLED;
} }
@ -128,9 +128,6 @@ event_predicate_apply(EventPredicateHandle handle, EventNode * event)
case EVPRED_PAYLOAD: case EVPRED_PAYLOAD:
actual = event->data.payload; actual = event->data.payload;
break; break;
case EVPRED_INPUT_INDEX:
actual = event->input_index;
break;
default: default:
return EVPREDRES_DISABLED; return EVPREDRES_DISABLED;
} }
@ -168,14 +165,6 @@ event_predicate_apply(EventPredicateHandle handle, EventNode * event)
} }
} }
break; break;
case EVPRED_MODIFIER:
if (!event) {
return EVPREDRES_DISABLED;
}
{
accepted = modifier_set_has(event->data.modifiers, ptr->single_modifier);
}
break;
default: default:
return EVPREDRES_DISABLED; return EVPREDRES_DISABLED;
} }

View File

@ -14,12 +14,9 @@ typedef enum {
EVPRED_CODE_MAJOR, EVPRED_CODE_MAJOR,
EVPRED_CODE_MINOR, EVPRED_CODE_MINOR,
EVPRED_PAYLOAD, EVPRED_PAYLOAD,
EVPRED_INPUT_INDEX,
// Aggregation // Aggregation
EVPRED_CONJUNCTION, EVPRED_CONJUNCTION,
EVPRED_DISJUNCTION, EVPRED_DISJUNCTION,
// Modifier
EVPRED_MODIFIER,
} EventPredicateType; } EventPredicateType;
typedef enum { typedef enum {
@ -41,7 +38,6 @@ struct event_predicate {
size_t length; size_t length;
EventPredicateHandle *handles; EventPredicateHandle *handles;
} aggregate_data; } aggregate_data;
Modifier single_modifier;
}; };
}; };

View File

@ -9,16 +9,7 @@ typedef struct {
uint8_t *bits; uint8_t *bits;
} ModifierSet; } ModifierSet;
typedef int32_t Modifier;
typedef enum {
MODOP_SET,
MODOP_UNSET,
MODOP_TOGGLE,
} ModifierOperation;
#define EMPTY_MODIFIER_SET ((ModifierSet) {.byte_length = 0, .bits = NULL}) #define EMPTY_MODIFIER_SET ((ModifierSet) {.byte_length = 0, .bits = NULL})
#define MODIFIER_MAX ((Modifier) 0xFFFFF)
__attribute__((unused)) inline static ModifierSet __attribute__((unused)) inline static ModifierSet
modifier_set_copy(const ModifierSet old) modifier_set_copy(const ModifierSet old)
@ -63,9 +54,6 @@ modifier_set_set_from(ModifierSet * target, const ModifierSet source)
{ {
modifier_set_extend(target, source.byte_length); modifier_set_extend(target, source.byte_length);
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] |= source.bits[i]; target->bits[i] |= source.bits[i];
} }
} }
@ -74,9 +62,6 @@ __attribute__((unused)) inline static void
modifier_set_unset_from(ModifierSet * target, const ModifierSet source) modifier_set_unset_from(ModifierSet * target, const ModifierSet source)
{ {
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] &= ~source.bits[i]; target->bits[i] &= ~source.bits[i];
} }
} }
@ -86,123 +71,8 @@ modifier_set_toggle_from(ModifierSet * target, const ModifierSet source)
{ {
modifier_set_extend(target, source.byte_length); modifier_set_extend(target, source.byte_length);
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] ^= source.bits[i]; target->bits[i] ^= source.bits[i];
} }
} }
__attribute__((unused)) inline static void
modifier_index_and_mask(Modifier modifier, size_t * byte_index, uint8_t * mask)
{
if (byte_index) {
*byte_index = modifier >> 3;
}
if (mask) {
*mask = 1 << (modifier & 7);
}
}
__attribute__((unused)) inline static bool
modifier_set_has(ModifierSet collection, Modifier element)
{
size_t byte_index;
uint8_t mask;
modifier_index_and_mask(element, &byte_index, &mask);
if (byte_index >= collection.byte_length) {
return false;
}
return (collection.bits[byte_index] & mask) != 0;
}
__attribute__((unused)) inline static void
modifier_set_set(ModifierSet * target, Modifier element)
{
size_t byte_index;
uint8_t mask;
modifier_index_and_mask(element, &byte_index, &mask);
if (!modifier_set_extend(target, byte_index + 1)) {
return;
}
target->bits[byte_index] |= mask;
}
__attribute__((unused)) inline static void
modifier_set_unset(ModifierSet * target, Modifier element)
{
size_t byte_index;
uint8_t mask;
modifier_index_and_mask(element, &byte_index, &mask);
if (byte_index >= target->byte_length) {
return;
}
target->bits[byte_index] &= ~mask;
}
__attribute__((unused)) inline static void
modifier_set_toggle(ModifierSet * target, Modifier element)
{
size_t byte_index;
uint8_t mask;
modifier_index_and_mask(element, &byte_index, &mask);
if (!modifier_set_extend(target, byte_index + 1)) {
return;
}
target->bits[byte_index] ^= mask;
}
__attribute__((unused)) inline static void
modifier_set_operation_from(ModifierSet * target, const ModifierSet source, ModifierOperation op)
{
switch (op) {
case MODOP_SET:
modifier_set_set_from(target, source);
return;
case MODOP_UNSET:
modifier_set_unset_from(target, source);
return;
case MODOP_TOGGLE:
modifier_set_toggle_from(target, source);
return;
}
}
__attribute__((unused)) inline static void
modifier_set_operation(ModifierSet * target, Modifier element, ModifierOperation op)
{
switch (op) {
case MODOP_SET:
modifier_set_set(target, element);
return;
case MODOP_UNSET:
modifier_set_unset(target, element);
return;
case MODOP_TOGGLE:
modifier_set_toggle(target, element);
return;
}
}
__attribute__((unused)) inline static ModifierOperation
modifier_operation_parse(const char* name)
{
if (!name) {
return -1;
}
if (strcmp(name, "set") == 0) {
return MODOP_SET;
}
if (strcmp(name, "unset") == 0) {
return MODOP_UNSET;
}
if (strcmp(name, "reset") == 0) {
return MODOP_UNSET;
}
if (strcmp(name, "togggle") == 0) {
return MODOP_TOGGLE;
}
return -1;
}
#endif /* end of include guard: MODIFIERS_H_ */ #endif /* end of include guard: MODIFIERS_H_ */

View File

@ -1,99 +0,0 @@
#include "../graph.h"
#include "../module_registry.h"
typedef struct {
GraphNode as_GraphNode;
ModifierSet modifiers;
ModifierOperation operation;
} ModifiersGraphNode;
static bool
handle_event(EventPositionBase * self, EventNode * event)
{
ModifiersGraphNode *node = DOWNCAST(ModifiersGraphNode, GraphNode, DOWNCAST(GraphNode, EventPositionBase, self));
size_t count = node->as_GraphNode.outputs.length;
if (!count) {
event_destroy(event);
return true;
}
modifier_set_operation_from(&event->data.modifiers, node->modifiers, node->operation);
if (count > 1) {
count = event_replicate(event, count - 1) + 1;
}
for (size_t i = 0; i < count; ++i) {
event->position = &node->as_GraphNode.outputs.elements[i]->as_EventPositionBase;
event = event->next;
}
return true;
}
static GraphNode *
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
{
(void) config;
(void) env;
ModifiersGraphNode * node = T_ALLOC(1, ModifiersGraphNode);
if (!node) {
return NULL;
}
const char *operation_name;
config_setting_lookup_string(config->options, "operation", &operation_name);
ModifierOperation op = modifier_operation_parse(operation_name);
if (op < 0) {
free(node);
return NULL;
}
config_setting_t *modifiers_setting = config_setting_get_member(config->options, "modifiers");
if (!modifiers_setting) {
free(node);
return NULL;
}
ModifierSet modifier_set = EMPTY_MODIFIER_SET;
size_t length = config_setting_length(modifiers_setting);
for (size_t i = 0; i < length; ++i) {
long long mod = env_resolve_constant_or(env, config_setting_get_elem(modifiers_setting, i), -1);
if (mod < 0 || mod > MODIFIER_MAX) {
continue;
}
modifier_set_set(&modifier_set, mod);
}
*node = (ModifiersGraphNode) {
.as_GraphNode = {
.as_EventPositionBase = {
.handle_event = &handle_event,
.waiting_new_event = false,
},
.specification = spec,
.inputs = EMPTY_GRAPH_CHANNEL_LIST,
.outputs = EMPTY_GRAPH_CHANNEL_LIST,
},
.modifiers = modifier_set,
.operation = op,
};
return &node->as_GraphNode;
}
static void destroy
(GraphNodeSpecification * self, GraphNode * target)
{
(void) self;
ModifiersGraphNode * node = DOWNCAST(ModifiersGraphNode, GraphNode, target);
modifier_set_destruct(&node->modifiers);
free(target);
}
GraphNodeSpecification nodespec_modifiers = (GraphNodeSpecification) {
.create = &create,
.destroy = &destroy,
.register_io = NULL,
.name = "modifiers",
};
MODULE_CONSTRUCTOR(init)
{
register_graph_node_specification(&nodespec_modifiers);
}