dev: implement input event hooks

This commit is contained in:
2023-06-11 16:46:58 +01:00
parent 3cc72f1f24
commit 7308fd98fb
3 changed files with 90 additions and 1 deletions

View File

@@ -38,7 +38,24 @@ kern_status_t input_device_report_event(struct input_device *dev, const struct i
flags = S_NOBLOCK;
}
size_t r = ringbuffer_write(event_queue, sizeof *ev, ev, flags);
struct input_event new_ev = *ev;
enum input_event_hook_flags hook_flags = 0;
queue_foreach (struct input_event_hook, hook, &dev->i_hooks, hook_head) {
if (hook->hook_callback) {
hook->hook_callback(input_device_base(dev), &new_ev, &hook_flags, hook->hook_arg);
}
if (hook_flags & INPUT_HOOK_SQUASH_EVENT) {
break;
}
}
if (hook_flags & INPUT_HOOK_SQUASH_EVENT) {
return KERN_OK;
}
size_t r = ringbuffer_write(event_queue, sizeof new_ev, &new_ev, flags);
return r == sizeof *ev ? KERN_OK : KERN_WOULD_BLOCK;
}
@@ -61,6 +78,30 @@ kern_status_t input_device_read(struct device *dev, void *buf, size_t size, size
return KERN_OK;
}
kern_status_t input_device_add_hook(struct device *dev, struct input_event_hook *hook)
{
struct input_device *inputdev = INPUT_DEVICE(dev);
if (!inputdev) {
return KERN_INVALID_ARGUMENT;
}
queue_push_back(&inputdev->i_hooks, &hook->hook_head);
return KERN_OK;
}
kern_status_t input_device_remove_hook(struct device *dev, struct input_event_hook *hook)
{
struct input_device *inputdev = INPUT_DEVICE(dev);
if (!inputdev) {
return KERN_INVALID_ARGUMENT;
}
queue_delete(&inputdev->i_hooks, &hook->hook_head);
return KERN_OK;
}
static kern_status_t generate_name(struct input_device *dev, char out[DEV_NAME_MAX])
{
snprintf(out, DEV_NAME_MAX, "input%u", dev->i_id);