12 Commits

Author SHA1 Message Date
975bb74284 Passthrough mouse events
To not block mice that have keys, which end up grabbed due to generic
configurations that simply filter anything that responds to CAPSLOCK/ESC.

Fixes #15
2021-01-01 00:18:03 -03:00
8bfd57eda2 Formatting 2020-12-30 23:40:02 -03:00
186b887e7d Make multi device example more robust
The previous one won't work when devices reattach.
2020-12-30 23:16:17 -03:00
c738e8783a Formatting 2020-12-30 21:32:58 -03:00
a062311ffb Formatting 2020-12-30 21:19:31 -03:00
ac6bbe61c2 Update README 2020-12-29 09:26:35 -03:00
12dc2f75c7 Update README 2020-12-29 03:47:41 -03:00
3eaf2bddfe Update README 2020-12-29 03:46:32 -03:00
0c8326646a Expand mouse support
Until now mouse support existed just as side effect of muxing and that
mouse clicks are registered as key events. This expands the support for
mouse wheel and movement.
2020-12-29 02:43:04 -03:00
5c7e6b5a5d Formatting 2020-12-28 23:35:47 -03:00
7428d959e0 Formatting 2020-12-28 23:31:58 -03:00
e5dc581ddf Formatting 2020-12-28 23:24:11 -03:00
2 changed files with 54 additions and 50 deletions

View File

@ -67,29 +67,28 @@ options:
For more information about the [_Interception Tools_][interception-tools], check
the project's website.
## Mouse button support
## Mouse Support
After _Interception Tools_ 0.3, `caps2esc` can work with mouse clicks. An
After _Interception Tools_ 0.3.1, `caps2esc` can observe for mouse events. An
example configuration taken from my laptop:
```yaml
SHELL: [zsh, -c]
---
- JOB: mux -c caps2esc
- JOB:
- intercept -g $DEVNODE | mux -o caps2esc
- mux -i caps2esc | caps2esc | uinput -d $DEVNODE
- JOB: >
mux -c caps2esc;
mux -i caps2esc | caps2esc | uinput -d /dev/input/by-path/platform-i8042-serio-0-event-kbd
- JOB: intercept -g $DEVNODE | mux -o caps2esc
DEVICE:
LINK: /dev/input/by-path/platform-i8042-serio-0-event-kbd
- JOB:
- intercept $DEVNODE | mux -o caps2esc
- JOB: intercept $DEVNODE | mux -o caps2esc
DEVICE:
LINK: /dev/input/by-path/platform-i8042-serio-4-event-mouse
```
For more information on the topic, check the [_Interception Tools_
README][interception-tools] about usage of the `mux` tool and device specific
setups.
setups, and [this discussion][issue-9-note] for more examples.
## Installation
@ -156,4 +155,5 @@ Copyright © 2017 Francisco Lopes da Silva
[x]: https://www.x.org
[interception]: https://github.com/oblitum/Interception
[interception-tools]: https://gitlab.com/interception/linux/tools
[issue-9-note]: https://gitlab.com/interception/linux/plugins/caps2esc/-/issues/9#note_474942893
[key-repeat-fix]: https://github.com/oblitum/caps2esc/issues/1

View File

@ -46,6 +46,7 @@ void write_event(const struct input_event *event) {
}
void write_event_with_mode(struct input_event *event, int mode) {
if (event->type == EV_KEY)
switch (mode) {
case 0:
if (event->code == KEY_ESC)
@ -66,17 +67,17 @@ void write_event_with_mode(struct input_event *event, int mode) {
}
int main(int argc, char *argv[]) {
int opt, mode = 0, delay = 20000;
while ((opt = getopt(argc, argv, "ht:m:")) != -1) {
int mode = 0, delay = 20000;
for (int opt; (opt = getopt(argc, argv, "ht:m:")) != -1;) {
switch (opt) {
case 'h':
return print_usage(stdout, argv[0]), EXIT_SUCCESS;
case 't':
delay = atoi(optarg);
continue;
case 'm':
mode = atoi(optarg);
continue;
case 't':
delay = atoi(optarg);
continue;
}
return print_usage(stderr, argv[0]), EXIT_FAILURE;
@ -91,20 +92,22 @@ int main(int argc, char *argv[]) {
if (input.type == EV_MSC && input.code == MSC_SCAN)
continue;
if (input.type != EV_KEY) {
if (input.type != EV_KEY && input.type != EV_REL &&
input.type != EV_ABS) {
write_event(&input);
continue;
}
switch (state) {
case START:
if (input.code == KEY_CAPSLOCK && input.value)
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK &&
input.value)
state = CAPSLOCK_HELD;
else
write_event_with_mode(&input, mode);
break;
case CAPSLOCK_HELD:
if (input.code == KEY_CAPSLOCK) {
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
if (input.value == 0) {
write_event(&esc_down);
write_event(&syn);
@ -112,7 +115,8 @@ int main(int argc, char *argv[]) {
write_event(&esc_up);
state = START;
}
} else if (input.value == 1) {
} else if ((input.type == EV_KEY && input.value == 1) ||
input.type == EV_REL || input.type == EV_ABS) {
write_event(&ctrl_down);
write_event(&syn);
usleep(delay);
@ -122,7 +126,7 @@ int main(int argc, char *argv[]) {
write_event_with_mode(&input, mode);
break;
case CAPSLOCK_IS_CTRL:
if (input.code == KEY_CAPSLOCK) {
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
input.code = KEY_LEFTCTRL;
write_event(&input);
if (input.value == 0)