Optionally grabbing evdev device

This commit is contained in:
Vftdan 2024-08-18 17:31:45 +02:00
parent 97e45aa8c6
commit 60a2cb7408
2 changed files with 12 additions and 0 deletions

View File

@ -66,6 +66,7 @@ nodes = {
options = {
file = "/dev/input/event7";
namespace = "namespaces.clickpad";
// grab = 1;
};
};
select_key_events = {

View File

@ -76,8 +76,10 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
return NULL;
}
const char *filename = NULL;
bool should_grab = false;
if (config) {
node->namespace = env_resolve_constant(env, config_setting_get_member(config->options, "namespace"));
should_grab = env_resolve_constant(env, config_setting_get_member(config->options, "grab")) != 0;
config_setting_lookup_string(config->options, "file", &filename);
}
if (filename == NULL) {
@ -91,6 +93,14 @@ create(GraphNodeSpecification * spec, GraphNodeConfig * config, InitializationEn
free(node);
return NULL;
}
if (should_grab) {
if ((err = libevdev_grab(node->dev, LIBEVDEV_GRAB)) < 0) {
errno = -err;
libevdev_free(node->dev);
free(node);
return NULL;
}
}
*node = (EvdevGraphNode) {
.as_GraphNode = {
.as_EventPositionBase = {
@ -142,6 +152,7 @@ GraphNodeSpecification nodespec_evdev = (GraphNodeSpecification) {
.documentation = "Reads evdev events of the specified device\nDoes not accept events\nSends events on all connectors with major code, minor code, payload respectively set to evdev event type, code, value"
"\nOption 'namespace' (optional): set namespace for the generated events"
"\nOption 'file' (required): device file to read events from (like '/dev/input/eventN'), the process must have sufficient privileges to read the file"
"\nOption 'grab' (optional): whether to prevent others from receiving events from this device"
,
};