From 489d77b96df8547221d141bf15665d85f60f426e Mon Sep 17 00:00:00 2001 From: Quinten Date: Sun, 18 Aug 2024 17:23:27 -0700 Subject: [PATCH 1/2] support scroll mapping --- src/daemon.c | 23 +++++++++++++++++++++-- src/keys.c | 4 ++-- src/keys.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 90333724..ad2f2d40 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -182,6 +182,22 @@ static void load_configs() closedir(dh); } +const struct descriptor *get_active_layer_mapping(struct keyboard *kbd, uint8_t code) { + int i; + struct descriptor *mapping = NULL; + + for (i = kbd->config.nr_layers - 1; i >= 0; i--) { + if (kbd->layer_state[i].active) { + mapping = &kbd->config.layers[i].keymap[code]; + if (mapping->op != 0) { + return mapping; + } + } + } + + return NULL; +} + static struct config_ent *lookup_config_ent(const char *id, uint8_t flags) { struct config_ent *ent = configs; @@ -486,7 +502,7 @@ static int event_handler(struct event *ev) * cleared. */ if (active_kbd) { - kev.code = KEYD_EXTERNAL_MOUSE_BUTTON; + kev.code = ev->devev->x == 0 ? ((int)ev->devev->y > 0 ? KEYD_SCROLL_UP : KEYD_SCROLL_DOWN): KEYD_EXTERNAL_MOUSE_BUTTON; kev.pressed = 1; kev.timestamp = ev->timestamp; @@ -495,8 +511,11 @@ static int event_handler(struct event *ev) kev.pressed = 0; timeout = kbd_process_events(ev->dev->data, &kev, 1); } + const struct descriptor *mapping = active_kbd? get_active_layer_mapping(active_kbd, kev.code): NULL; + if (mapping == NULL) { + vkbd_mouse_scroll(vkbd, ev->devev->x, ev->devev->y); + } - vkbd_mouse_scroll(vkbd, ev->devev->x, ev->devev->y); break; } } else if (ev->dev->is_virtual && ev->devev->type == DEV_LED) { diff --git a/src/keys.c b/src/keys.c index 52f22ee4..3cd76e43 100644 --- a/src/keys.c +++ b/src/keys.c @@ -228,8 +228,8 @@ const struct keycode_table_ent keycode_table[256] = { [KEYD_SEARCH] = { "search", NULL, NULL }, [KEYD_CONNECT] = { "connect", NULL, NULL }, [KEYD_FINANCE] = { "finance", NULL, NULL }, - [KEYD_SPORT] = { "sport", NULL, NULL }, - [KEYD_SHOP] = { "shop", NULL, NULL }, + [KEYD_SCROLL_UP] = { "scrollup", NULL, NULL }, + [KEYD_SCROLL_DOWN] = { "scrolldown", NULL, NULL }, [KEYD_VOICECOMMAND] = { "voicecommand", NULL, NULL }, [KEYD_CANCEL] = { "cancel", NULL, NULL }, [KEYD_BRIGHTNESSDOWN] = { "brightnessdown", NULL, NULL }, diff --git a/src/keys.h b/src/keys.h index d7a09e77..8c436c8d 100644 --- a/src/keys.h +++ b/src/keys.h @@ -242,8 +242,6 @@ struct modifier { #define KEYD_SEARCH 217 #define KEYD_CONNECT 218 #define KEYD_FINANCE 219 -#define KEYD_SPORT 220 -#define KEYD_SHOP 221 #define KEYD_VOICECOMMAND 222 #define KEYD_CANCEL 223 #define KEYD_BRIGHTNESSDOWN 224 @@ -285,6 +283,8 @@ struct modifier { #define KEYD_MOUSE_1 252 #define KEYD_MOUSE_2 253 #define KEYD_MOUSE_BACK 178 +#define KEYD_SCROLL_UP 220 +#define KEYD_SCROLL_DOWN 221 #define KEYD_FN 254 #define KEYD_MOUSE_FORWARD 255 From a7e3bd32c121eb5d16b0f5a9b722aaec94875c3b Mon Sep 17 00:00:00 2001 From: Quinten Date: Sun, 25 Aug 2024 17:26:13 -0700 Subject: [PATCH 2/2] fix weird behavior after normal scrolling --- src/daemon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index ad2f2d40..aebd167b 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -501,8 +501,13 @@ static int event_handler(struct event *ev) * Treat scroll events as mouse buttons so oneshot and the like get * cleared. */ + + kev.code = ev->devev->x == 0 ? ((int)ev->devev->y > 0 ? KEYD_SCROLL_UP : KEYD_SCROLL_DOWN): KEYD_EXTERNAL_MOUSE_BUTTON; + const struct descriptor *mapping = active_kbd? get_active_layer_mapping(active_kbd, kev.code): NULL; if (active_kbd) { - kev.code = ev->devev->x == 0 ? ((int)ev->devev->y > 0 ? KEYD_SCROLL_UP : KEYD_SCROLL_DOWN): KEYD_EXTERNAL_MOUSE_BUTTON; + if (mapping == NULL){ + kev.code = KEYD_EXTERNAL_MOUSE_BUTTON; + } kev.pressed = 1; kev.timestamp = ev->timestamp; @@ -511,7 +516,6 @@ static int event_handler(struct event *ev) kev.pressed = 0; timeout = kbd_process_events(ev->dev->data, &kev, 1); } - const struct descriptor *mapping = active_kbd? get_active_layer_mapping(active_kbd, kev.code): NULL; if (mapping == NULL) { vkbd_mouse_scroll(vkbd, ev->devev->x, ev->devev->y); }