Support smooth scroll and horizontal scroll

note that this changes Scroll mousebinds from taking a "button"
attribute to taking a "direction" attribute
This commit is contained in:
bi4k8 2022-11-09 05:18:14 +00:00 committed by Johan Malm
parent 6164ba73ff
commit 2b753a98b8
7 changed files with 119 additions and 20 deletions

View file

@ -34,16 +34,44 @@ mousebind_button_from_str(const char *str, uint32_t *modifiers)
return BTN_RIGHT;
} else if (!strcasecmp(str, "Middle")) {
return BTN_MIDDLE;
} else if (!strcasecmp(str, "Up")) {
return BTN_GEAR_UP;
} else if (!strcasecmp(str, "Down")) {
return BTN_GEAR_DOWN;
}
invalid:
wlr_log(WLR_ERROR, "unknown button (%s)", str);
return UINT32_MAX;
}
enum direction
mousebind_direction_from_str(const char *str, uint32_t *modifiers)
{
assert(str);
if (modifiers) {
*modifiers = 0;
while (strlen(str) >= 2 && str[1] == '-') {
char modname[2] = {str[0], 0};
uint32_t parsed_modifier = parse_modifier(modname);
if (!parsed_modifier) {
goto invalid;
}
*modifiers |= parsed_modifier;
str += 2;
}
}
if (!strcasecmp(str, "Left")) {
return LAB_DIRECTION_LEFT;
} else if (!strcasecmp(str, "Right")) {
return LAB_DIRECTION_RIGHT;
} else if (!strcasecmp(str, "Up")) {
return LAB_DIRECTION_UP;
} else if (!strcasecmp(str, "Down")) {
return LAB_DIRECTION_DOWN;
}
invalid:
wlr_log(WLR_ERROR, "unknown direction (%s)", str);
return LAB_DIRECTION_INVALID;
}
enum mouse_event
mousebind_event_from_str(const char *str)
{

View file

@ -131,6 +131,9 @@ fill_mousebind(char *nodename, char *content)
} else if (!strcmp(nodename, "button")) {
current_mousebind->button = mousebind_button_from_str(content,
&current_mousebind->modifiers);
} else if (!strcmp(nodename, "direction")) {
current_mousebind->direction = mousebind_direction_from_str(content,
&current_mousebind->modifiers);
} else if (!strcmp(nodename, "action")) {
/* <mousebind button="" action="EVENT"> */
current_mousebind->mouse_event =
@ -621,9 +624,14 @@ load_default_mouse_bindings(void)
|| strcmp(current->event, mouse_combos[i - 1].event)) {
/* Create new mousebind */
m = mousebind_create(current->context);
m->button = mousebind_button_from_str(current->button,
&m->modifiers);
m->mouse_event = mousebind_event_from_str(current->event);
if (m->mouse_event == MOUSE_ACTION_SCROLL) {
m->direction = mousebind_direction_from_str(current->button,
&m->modifiers);
} else {
m->button = mousebind_button_from_str(current->button,
&m->modifiers);
}
count++;
}
@ -649,6 +657,7 @@ merge_mouse_bindings(void)
}
if (existing->context == current->context
&& existing->button == current->button
&& existing->direction == current->direction
&& existing->mouse_event == current->mouse_event) {
wl_list_remove(&existing->link);
action_list_free(&existing->actions);