]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rcxml.c: combine common code in fill_{key,mouse}bind()
authorJohan Malm <jgm323@gmail.com>
Sun, 30 Oct 2022 14:26:57 +0000 (14:26 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 30 Oct 2022 18:26:45 +0000 (18:26 +0000)
src/config/rcxml.c

index c04150049afdd9d2153317bf89869597de982f08..cf839304945d827610d824a715eeb44ce341df8f 100644 (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);
        }
 }