Add "modify_predicate" node type
Change "enabled" and "inverted" predicate flags when received events satisfy other predicates
This commit is contained in:
parent
4922b7f304
commit
f76eaa53f2
2
Makefile
2
Makefile
|
@ -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 nodes/modifiers.o nodes/modify_predicate.o
|
||||||
|
|
||||||
all: $(MAIN)
|
all: $(MAIN)
|
||||||
|
|
||||||
|
|
45
config.cfg
45
config.cfg
|
@ -23,6 +23,31 @@ predicates = {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
btn_touch_event = {
|
||||||
|
type = "and";
|
||||||
|
args = (
|
||||||
|
"key_event",
|
||||||
|
{
|
||||||
|
type = "code_minor";
|
||||||
|
min = "button_event.TOUCH";
|
||||||
|
max = "button_event.TOUCH";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
payload_zero = {
|
||||||
|
type = "payload";
|
||||||
|
min = 0;
|
||||||
|
max = 0;
|
||||||
|
};
|
||||||
|
payload_one = {
|
||||||
|
type = "payload";
|
||||||
|
min = 1;
|
||||||
|
max = 1;
|
||||||
|
};
|
||||||
|
touch_held = {
|
||||||
|
type = "accept";
|
||||||
|
inverted = 1;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
|
@ -63,6 +88,20 @@ nodes = {
|
||||||
modifiers = ["my_modifier"];
|
modifiers = ["my_modifier"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
update_touch_held = {
|
||||||
|
type = "modify_predicate";
|
||||||
|
options = {
|
||||||
|
target = "touch_held";
|
||||||
|
uninvert_on = {type: "and", args: ["btn_touch_event", "payload_one"]};
|
||||||
|
invert_on = {type: "and", args: ["btn_touch_event", "payload_zero"]};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
while_touch_held = {
|
||||||
|
type = "router";
|
||||||
|
options = {
|
||||||
|
predicates = ["touch_held"];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
channels = ({
|
channels = ({
|
||||||
|
@ -79,7 +118,13 @@ channels = ({
|
||||||
to: ("print", 0);
|
to: ("print", 0);
|
||||||
}, {
|
}, {
|
||||||
from: ("select_key_events", 1);
|
from: ("select_key_events", 1);
|
||||||
|
to: ("while_touch_held", 0);
|
||||||
|
}, {
|
||||||
|
from: ("while_touch_held", 0);
|
||||||
to: ("print", 1);
|
to: ("print", 1);
|
||||||
|
}, {
|
||||||
|
from: ("clickpad", 1);
|
||||||
|
to: ("update_touch_held", 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// vim: ft=libconfig
|
// vim: ft=libconfig
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
#include "../graph.h"
|
||||||
|
#include "../module_registry.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GraphNode as_GraphNode;
|
||||||
|
EventPredicateHandle target;
|
||||||
|
EventPredicateHandle enable_on, disable_on, invert_on, uninvert_on;
|
||||||
|
} ModifyPredicateGraphNode;
|
||||||
|
|
||||||
|
static bool
|
||||||
|
handle_event(EventPositionBase * self, EventNode * event)
|
||||||
|
{
|
||||||
|
ModifyPredicateGraphNode *node = DOWNCAST(ModifyPredicateGraphNode, GraphNode, DOWNCAST(GraphNode, EventPositionBase, self));
|
||||||
|
bool
|
||||||
|
should_enable = false,
|
||||||
|
should_disable = false,
|
||||||
|
should_invert = false,
|
||||||
|
should_uninvert = false;
|
||||||
|
EventPredicateHandle target = node->target;
|
||||||
|
EventPredicate target_state = event_predicate_get(target);
|
||||||
|
|
||||||
|
if (target_state.enabled) {
|
||||||
|
should_disable = event_predicate_apply(node->disable_on, event) == EVPREDRES_ACCEPTED;
|
||||||
|
} else {
|
||||||
|
should_enable = event_predicate_apply(node->enable_on, event) == EVPREDRES_ACCEPTED;
|
||||||
|
}
|
||||||
|
if (target_state.inverted) {
|
||||||
|
should_uninvert = event_predicate_apply(node->uninvert_on, event) == EVPREDRES_ACCEPTED;
|
||||||
|
} else {
|
||||||
|
should_invert = event_predicate_apply(node->invert_on, event) == EVPREDRES_ACCEPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (should_enable) {
|
||||||
|
event_predicate_set_enabled(target, true);
|
||||||
|
}
|
||||||
|
if (should_disable) {
|
||||||
|
event_predicate_set_enabled(target, false);
|
||||||
|
}
|
||||||
|
if (should_invert) {
|
||||||
|
event_predicate_set_inverted(target, true);
|
||||||
|
}
|
||||||
|
if (should_uninvert) {
|
||||||
|
event_predicate_set_inverted(target, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
event_destroy(event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GraphNode *
|
||||||
|
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||||
|
{
|
||||||
|
(void) config;
|
||||||
|
(void) env;
|
||||||
|
ModifyPredicateGraphNode * node = T_ALLOC(1, ModifyPredicateGraphNode);
|
||||||
|
if (!node) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventPredicateHandle target = env_resolve_event_predicate(env, config_setting_get_member(config->options, "target"));
|
||||||
|
if (target < 0) {
|
||||||
|
free(node);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*node = (ModifyPredicateGraphNode) {
|
||||||
|
.as_GraphNode = {
|
||||||
|
.as_EventPositionBase = {
|
||||||
|
.handle_event = &handle_event,
|
||||||
|
.waiting_new_event = false,
|
||||||
|
},
|
||||||
|
.specification = spec,
|
||||||
|
.inputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||||
|
.outputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||||
|
},
|
||||||
|
.target = target,
|
||||||
|
.enable_on = env_resolve_event_predicate(env, config_setting_get_member(config->options, "enable_on")),
|
||||||
|
.disable_on = env_resolve_event_predicate(env, config_setting_get_member(config->options, "disable_on")),
|
||||||
|
.invert_on = env_resolve_event_predicate(env, config_setting_get_member(config->options, "invert_on")),
|
||||||
|
.uninvert_on = env_resolve_event_predicate(env, config_setting_get_member(config->options, "uninvert_on")),
|
||||||
|
};
|
||||||
|
return &node->as_GraphNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy
|
||||||
|
(GraphNodeSpecification * self, GraphNode * target)
|
||||||
|
{
|
||||||
|
(void) self;
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphNodeSpecification nodespec_modify_predicate = (GraphNodeSpecification) {
|
||||||
|
.create = &create,
|
||||||
|
.destroy = &destroy,
|
||||||
|
.register_io = NULL,
|
||||||
|
.name = "modify_predicate",
|
||||||
|
};
|
||||||
|
|
||||||
|
MODULE_CONSTRUCTOR(init)
|
||||||
|
{
|
||||||
|
register_graph_node_specification(&nodespec_modify_predicate);
|
||||||
|
}
|
Loading…
Reference in New Issue