rcxml.c: combine common code in fill_{key,mouse}bind()

This commit is contained in:
Johan Malm 2022-10-30 14:26:57 +00:00 committed by Johan Malm
parent e9c3080f76
commit cce2fffa1d

View file

@ -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 <action name=\"\"> 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 <action name=\"\"> 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);
}
}