parse and respect modifiers for mouse bindings

This commit is contained in:
bi4k8 2021-12-01 02:32:24 +00:00 committed by ARDiDo
parent c34a2fc976
commit 8eab1e8132
4 changed files with 31 additions and 10 deletions

View file

@ -9,9 +9,22 @@
#include "config/rcxml.h"
uint32_t
mousebind_button_from_str(const char *str)
mousebind_button_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 BTN_LEFT;
} else if (!strcasecmp(str, "Right")) {
@ -19,6 +32,7 @@ mousebind_button_from_str(const char *str)
} else if (!strcasecmp(str, "Middle")) {
return BTN_MIDDLE;
}
invalid:
wlr_log(WLR_ERROR, "unknown button (%s)", str);
return UINT32_MAX;
}

View file

@ -89,7 +89,8 @@ fill_mousebind(char *nodename, char *content)
string_truncate_at_pattern(nodename, ".mousebind.context.mouse");
if (!strcmp(nodename, "button")) {
current_mousebind->button = mousebind_button_from_str(content);
current_mousebind->button = mousebind_button_from_str(content,
&current_mousebind->modifiers);
} else if (!strcmp(nodename, "action")) {
/* <mousebind button="" action="EVENT"> */
current_mousebind->mouse_event =
@ -477,7 +478,8 @@ load_default_mouse_bindings(void)
{
for (int i = 0; mouse_combos[i].context; i++) {
struct mousebind *m = mousebind_create(mouse_combos[i].context);
m->button = mousebind_button_from_str(mouse_combos[i].button);
m->button = mousebind_button_from_str(mouse_combos[i].button,
&m->modifiers);
m->mouse_event = mousebind_event_from_str(mouse_combos[i].event);
m->action = strdup(mouse_combos[i].action);
if (mouse_combos[i].command) {