Skip to content

Commit

Permalink
support scroll mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
quintenroets committed Aug 19, 2024
1 parent 393d341 commit 489d77b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 21 additions & 2 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 489d77b

Please sign in to comment.