diff --git a/src/daemon.c b/src/daemon.c index 9033372..aebd167 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; @@ -485,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 = KEYD_EXTERNAL_MOUSE_BUTTON; + if (mapping == NULL){ + kev.code = KEYD_EXTERNAL_MOUSE_BUTTON; + } kev.pressed = 1; kev.timestamp = ev->timestamp; @@ -495,8 +516,10 @@ static int event_handler(struct event *ev) kev.pressed = 0; timeout = kbd_process_events(ev->dev->data, &kev, 1); } + 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 52f22ee..3cd76e4 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 d7a09e7..8c436c8 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