From 3afd666cc4a95a89dad9d0ee3a112c1cf6832670 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 29 Aug 2022 23:42:40 +0200 Subject: [PATCH] src/config/rcxml.c: Replace earlier mousebinds by later ones --- src/config/rcxml.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/config/rcxml.c b/src/config/rcxml.c index c5067ebe..3b04cd55 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -588,6 +588,7 @@ static struct mouse_combos { static void load_default_mouse_bindings(void) { + uint32_t count = 0; struct mousebind *m; struct action *action; struct mouse_combos *current; @@ -603,6 +604,7 @@ load_default_mouse_bindings(void) m->button = mousebind_button_from_str(current->button, &m->modifiers); m->mouse_event = mousebind_event_from_str(current->event); + count++; } action = action_create(current->action); @@ -612,6 +614,34 @@ load_default_mouse_bindings(void) action_arg_add_str(action, NULL, current->command); } } + wlr_log(WLR_DEBUG, "Loaded %u merged mousebinds", count); +} + +static void +merge_mouse_bindings(void) +{ + uint32_t replaced = 0; + struct mousebind *current, *tmp, *existing; + wl_list_for_each_safe(existing, tmp, &rc.mousebinds, link) { + wl_list_for_each_reverse(current, &rc.mousebinds, link) { + if (existing == current) { + break; + } + if (existing->context == current->context + && existing->button == current->button + && existing->mouse_event == current->mouse_event) { + + wl_list_remove(&existing->link); + action_list_free(&existing->actions); + free(existing); + replaced++; + break; + } + } + } + if (replaced) { + wlr_log(WLR_DEBUG, "Replaced %u mousebinds", replaced); + } } static void @@ -621,11 +651,15 @@ post_processing(void) wlr_log(WLR_INFO, "load default key bindings"); load_default_key_bindings(); } + if (!wl_list_length(&rc.mousebinds)) { wlr_log(WLR_INFO, "load default mouse bindings"); load_default_mouse_bindings(); } + /* Replace all earlier mousebindings by later ones */ + merge_mouse_bindings(); + if (!rc.font_name_activewindow) { rc.font_name_activewindow = strdup("sans"); }