From cce2fffa1dc306b5b95b00a5b3b9fc0f5b7b67c1 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 30 Oct 2022 14:26:57 +0000 Subject: [PATCH] rcxml.c: combine common code in fill_{key,mouse}bind() --- src/config/rcxml.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/config/rcxml.c b/src/config/rcxml.c index c0415004..cf839304 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -45,6 +45,24 @@ enum font_place { static void load_default_key_bindings(void); static void load_default_mouse_bindings(void); +static void +fill_common(char *nodename, char *content, struct action *action) +{ + if (!strcmp(nodename, "command.action")) { + /* Execute */ + action_arg_add_str(action, NULL, content); + } else if (!strcmp(nodename, "direction.action")) { + /* MoveToEdge, SnapToEdge */ + action_arg_add_str(action, NULL, content); + } else if (!strcmp(nodename, "menu.action")) { + /* ShowMenu */ + action_arg_add_str(action, NULL, content); + } else if (!strcmp(nodename, "to.action")) { + /* GoToDesktop, SendToDesktop */ + action_arg_add_str(action, NULL, content); + } +} + static void fill_keybind(char *nodename, char *content) { @@ -73,18 +91,8 @@ fill_keybind(char *nodename, char *content) } else if (!current_keybind_action) { wlr_log(WLR_ERROR, "expect element first. " "nodename: '%s' content: '%s'", nodename, content); - } else if (!strcmp(nodename, "command.action")) { - /* Execute */ - action_arg_add_str(current_keybind_action, NULL, content); - } else if (!strcmp(nodename, "direction.action")) { - /* MoveToEdge, SnapToEdge */ - action_arg_add_str(current_keybind_action, NULL, content); - } else if (!strcmp(nodename, "menu.action")) { - /* ShowMenu */ - action_arg_add_str(current_keybind_action, NULL, content); - } else if (!strcmp(nodename, "to.action")) { - /* GoToDesktop, SendToDesktop */ - action_arg_add_str(current_keybind_action, NULL, content); + } else { + fill_common(nodename, content, current_keybind_action); } } @@ -133,14 +141,8 @@ fill_mousebind(char *nodename, char *content) } else if (!current_mousebind_action) { wlr_log(WLR_ERROR, "expect element first. " "nodename: '%s' content: '%s'", nodename, content); - } else if (!strcmp(nodename, "command.action")) { - action_arg_add_str(current_mousebind_action, NULL, content); - } else if (!strcmp(nodename, "direction.action")) { - action_arg_add_str(current_mousebind_action, NULL, content); - } else if (!strcmp(nodename, "menu.action")) { - action_arg_add_str(current_mousebind_action, NULL, content); - } else if (!strcmp(nodename, "to.action")) { - action_arg_add_str(current_mousebind_action, NULL, content); + } else { + fill_common(nodename, content, current_mousebind_action); } }