Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse scroll support #814

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 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 @@ -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;

Expand All @@ -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) {
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