Compare commits
2 Commits
3a9eed56bb
...
52b3b74e7b
Author | SHA1 | Date |
---|---|---|
Vftdan | 52b3b74e7b | |
Vftdan | 74f11849b3 |
2
Makefile
2
Makefile
|
@ -12,7 +12,7 @@ CPPFLAGS += $(shell pkg-config --cflags $(DEPS))
|
|||
LDLIBS += $(shell pkg-config --libs $(DEPS))
|
||||
INTERP ?=
|
||||
MAIN = main
|
||||
OBJS = main.o events.o processing.o graph.o config.o event_code_names.o hash_table.o queue.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 nodes/uinput.o nodes/assign.o nodes/differentiate.o nodes/scale.o nodes/window.o
|
||||
OBJS = main.o events.o processing.o graph.o config.o event_code_names.o hash_table.o queue.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 nodes/uinput.o nodes/assign.o nodes/differentiate.o nodes/integrate.o nodes/scale.o nodes/window.o
|
||||
|
||||
all: $(MAIN)
|
||||
|
||||
|
|
78
config.cfg
78
config.cfg
|
@ -3,7 +3,8 @@ constants = {
|
|||
};
|
||||
|
||||
enums = {
|
||||
namespaces: ["stdin", "clickpad"];
|
||||
namespaces: ["stdin", "clickpad", "variable"];
|
||||
variables: ["num_touches"];
|
||||
};
|
||||
|
||||
predicates = {
|
||||
|
@ -23,6 +24,17 @@ predicates = {
|
|||
}
|
||||
);
|
||||
};
|
||||
abs_event = {
|
||||
type = "and";
|
||||
args = (
|
||||
"is_evdev",
|
||||
{
|
||||
type = "code_major";
|
||||
min = "event_type.ABS";
|
||||
max = "event_type.ABS";
|
||||
}
|
||||
);
|
||||
};
|
||||
btn_touch_event = {
|
||||
type = "and";
|
||||
args = (
|
||||
|
@ -34,6 +46,17 @@ predicates = {
|
|||
}
|
||||
);
|
||||
};
|
||||
touch_tracking_id = {
|
||||
type = "and";
|
||||
args = (
|
||||
"abs_event",
|
||||
{
|
||||
type = "code_minor";
|
||||
min = "absolute_axis.MT_TRACKING_ID";
|
||||
max = "absolute_axis.MT_TRACKING_ID";
|
||||
}
|
||||
);
|
||||
};
|
||||
payload_zero = {
|
||||
type = "payload";
|
||||
min = 0;
|
||||
|
@ -44,6 +67,22 @@ predicates = {
|
|||
min = 1;
|
||||
max = 1;
|
||||
};
|
||||
payload_negative = {
|
||||
type = "payload";
|
||||
max = -1;
|
||||
};
|
||||
payload_nonnegative = {
|
||||
type = "payload";
|
||||
min = 0;
|
||||
};
|
||||
touch_start = {
|
||||
type = "and";
|
||||
args = ["touch_tracking_id", "payload_nonnegative"];
|
||||
};
|
||||
touch_end = {
|
||||
type = "and";
|
||||
args = ["touch_tracking_id", "payload_negative"];
|
||||
};
|
||||
touch_held = {
|
||||
type = "accept";
|
||||
inverted = 1;
|
||||
|
@ -78,7 +117,9 @@ nodes = {
|
|||
type = "or";
|
||||
inverted = 1;
|
||||
args = ["key_event"];
|
||||
}
|
||||
},
|
||||
"touch_start",
|
||||
"touch_end"
|
||||
);
|
||||
};
|
||||
};
|
||||
|
@ -116,6 +157,24 @@ nodes = {
|
|||
);
|
||||
};
|
||||
};
|
||||
set_one = {
|
||||
type = "assign";
|
||||
options = {
|
||||
payload = 1;
|
||||
};
|
||||
};
|
||||
count_touches = {
|
||||
// This exact usecase may be implemented using events like button_event.TOOL_DOUBLETAP, button_event.TOOL_TRIPLETAP, button_event.TOOL_QUADTAP, button_event.TOOL_QUINTTAP
|
||||
type = "integrate";
|
||||
};
|
||||
set_variable_num_touches = {
|
||||
type = "assign";
|
||||
options = {
|
||||
namespace = "namespaces.variable";
|
||||
major = "variables.num_touches";
|
||||
minor = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
channels = ({
|
||||
|
@ -139,6 +198,21 @@ channels = ({
|
|||
}, {
|
||||
from: ("clickpad", 1);
|
||||
to: ("update_touch_held", 0);
|
||||
}, {
|
||||
from: ("select_key_events", 2); // touch_start
|
||||
to: ("set_one", 0);
|
||||
}, {
|
||||
from: ("set_one", 0);
|
||||
to: ("count_touches", 0);
|
||||
}, {
|
||||
from: ("select_key_events", 3); // touch_end
|
||||
to: ("count_touches", 1);
|
||||
}, {
|
||||
from: ("count_touches", 0);
|
||||
to: ("set_variable_num_touches", 0);
|
||||
}, {
|
||||
from: ("set_variable_num_touches", 0);
|
||||
to: ("print", 2);
|
||||
});
|
||||
|
||||
// vim: ft=libconfig
|
||||
|
|
6
events.c
6
events.c
|
@ -21,8 +21,7 @@ event_replicate(EventNode * source, size_t count)
|
|||
}
|
||||
replica->position = NULL;
|
||||
replica->input_index = 0;
|
||||
replica->data = source->data;
|
||||
replica->data.modifiers = modifier_set_copy(source->data.modifiers);
|
||||
replica->data = event_data_copy(source->data);
|
||||
replica->prev = source;
|
||||
replica->next = source->next;
|
||||
source->next->prev = replica;
|
||||
|
@ -39,8 +38,7 @@ event_create(const EventData * content)
|
|||
return NULL;
|
||||
}
|
||||
if (content) {
|
||||
event->data = *content;
|
||||
event->data.modifiers = modifier_set_copy(content->modifiers);
|
||||
event->data = event_data_copy(*content);
|
||||
} else {
|
||||
event->data.time = get_current_time();
|
||||
}
|
||||
|
|
7
events.h
7
events.h
|
@ -49,4 +49,11 @@ EventNode * event_create(const EventData * content);
|
|||
void event_destroy(EventNode * self);
|
||||
void event_destroy_all();
|
||||
|
||||
__attribute__((unused)) inline static EventData
|
||||
event_data_copy(EventData orig)
|
||||
{
|
||||
orig.modifiers = modifier_set_copy(orig.modifiers);
|
||||
return orig;
|
||||
}
|
||||
|
||||
#endif /* end of include guard: EVENTS_H_ */
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#include "../graph.h"
|
||||
#include "../module_registry.h"
|
||||
|
||||
typedef struct {
|
||||
GraphNode as_GraphNode;
|
||||
int64_t total;
|
||||
} IntegrateGraphNode;
|
||||
|
||||
static bool
|
||||
handle_event(EventPositionBase * self, EventNode * event)
|
||||
{
|
||||
IntegrateGraphNode *node = DOWNCAST(IntegrateGraphNode, GraphNode, DOWNCAST(GraphNode, EventPositionBase, self));
|
||||
size_t count = node->as_GraphNode.outputs.length;
|
||||
if (!count) {
|
||||
event_destroy(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t total = node->total;
|
||||
total += event->data.payload;
|
||||
event->data.payload = total;
|
||||
node->total = total;
|
||||
|
||||
graph_node_broadcast_forward_event(&node->as_GraphNode, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
static GraphNode *
|
||||
create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEnvironment * env)
|
||||
{
|
||||
(void) config;
|
||||
(void) env;
|
||||
IntegrateGraphNode * node = T_ALLOC(1, IntegrateGraphNode);
|
||||
if (!node) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t initial = 0;
|
||||
if (config->options) {
|
||||
initial = env_resolve_constant(env, config_setting_get_member(config->options, "initial"));
|
||||
}
|
||||
|
||||
*node = (IntegrateGraphNode) {
|
||||
.as_GraphNode = {
|
||||
.as_EventPositionBase = {
|
||||
.handle_event = &handle_event,
|
||||
.waiting_new_event = false,
|
||||
},
|
||||
.specification = spec,
|
||||
.inputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||
.outputs = EMPTY_GRAPH_CHANNEL_LIST,
|
||||
},
|
||||
.total = initial,
|
||||
};
|
||||
return &node->as_GraphNode;
|
||||
}
|
||||
|
||||
static void destroy
|
||||
(GraphNodeSpecification * self, GraphNode * target)
|
||||
{
|
||||
(void) self;
|
||||
free(target);
|
||||
}
|
||||
|
||||
GraphNodeSpecification nodespec_integrate = (GraphNodeSpecification) {
|
||||
.create = &create,
|
||||
.destroy = &destroy,
|
||||
.register_io = NULL,
|
||||
.name = "integrate",
|
||||
.documentation = "Calculates a running sum of previous event payloads and replaces with it the current one\nAccepts events on any connector\nSends events on all connectors"
|
||||
"\nOption 'initial' (optional): the initial partial sum value"
|
||||
,
|
||||
};
|
||||
|
||||
MODULE_CONSTRUCTOR(init)
|
||||
{
|
||||
register_graph_node_specification(&nodespec_integrate);
|
||||
}
|
|
@ -69,6 +69,7 @@ trigger_new_window(WindowGraphNode * node, EventNode * base)
|
|||
terminator->data.code = node->terminator_prototype.code;
|
||||
terminator->data.modifiers = modifier_set_copy(node->terminator_prototype.modifiers);
|
||||
terminator->data.payload = node->terminator_prototype.payload;
|
||||
// Preserve ttl, priority, time
|
||||
graph_node_broadcast_forward_event(&node->as_GraphNode, terminator);
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +103,7 @@ trigger_new_window(WindowGraphNode * node, EventNode * base)
|
|||
if (!recipient) {
|
||||
continue;
|
||||
}
|
||||
recipient->data = orig->data;
|
||||
recipient->data.modifiers = modifier_set_copy(orig->data.modifiers);
|
||||
recipient->data = event_data_copy(orig->data);
|
||||
graph_node_broadcast_forward_event(&node->as_GraphNode, recipient);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue