]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: Simplify the code
authorConsus <consus@ftml.net>
Mon, 28 Aug 2023 15:29:20 +0000 (18:29 +0300)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 1 Oct 2023 13:17:29 +0000 (14:17 +0100)
Replace action_str_from_arg() and action_get_first_arg() with
action_get_str().

Two reasons:

- This optimization reduces neither LOC nor amount of work done during
  the arguments processing, but requires two additional functions.

- Logging only the first argument of an action creates an illusion that
  only one argument was given. Instead of confusing the user just log
  the fact that the action is being handled.

src/action.c

index 8ac0c909a82ef9bfc13172219f82983e6f126653..7d91c49a05459f10d92be9a2535a044c80f6e6c7 100644 (file)
@@ -284,25 +284,6 @@ cleanup:
        free(argument);
 }
 
-static const char *
-action_str_from_arg(struct action_arg *arg)
-{
-       assert(arg->type == LAB_ACTION_ARG_STR);
-       return ((struct action_arg_str *)arg)->value;
-}
-
-
-static struct action_arg *
-action_get_first_arg(struct action *action)
-{
-       struct action_arg *arg;
-       struct wl_list *item = action->args.next;
-       if (item == &action->args) {
-               return NULL;
-       }
-       return wl_container_of(item, arg, link);
-}
-
 static enum action_type
 action_type_from_str(const char *action_name)
 {
@@ -496,19 +477,9 @@ actions_run(struct view *activator, struct server *server,
 
        struct view *view;
        struct action *action;
-       struct action_arg *arg;
        wl_list_for_each(action, actions, link) {
-               /* Get arg now so we don't have to repeat every time we only need one */
-               arg = action_get_first_arg(action);
-
-               if (arg && arg->type == LAB_ACTION_ARG_STR) {
-                       wlr_log(WLR_DEBUG, "Handling action %u: %s %s",
-                               action->type, action_names[action->type],
-                               action_str_from_arg(arg));
-               } else {
-                       wlr_log(WLR_DEBUG, "Handling action %u: %s",
-                               action->type, action_names[action->type]);
-               }
+               wlr_log(WLR_DEBUG, "Handling action %u: %s", action->type,
+                       action_names[action->type]);
 
                /*
                 * Refetch view because it may have been changed due to the
@@ -541,7 +512,7 @@ actions_run(struct view *activator, struct server *server,
                        {
                                struct buf cmd;
                                buf_init(&cmd);
-                               buf_add(&cmd, action_str_from_arg(arg));
+                               buf_add(&cmd, action_get_str(action, "command", NULL));
                                buf_expand_tilde(&cmd);
                                spawn_async_no_shell(cmd.buf);
                                free(cmd.buf);
@@ -578,7 +549,7 @@ actions_run(struct view *activator, struct server *server,
                        kill(getpid(), SIGHUP);
                        break;
                case ACTION_TYPE_SHOW_MENU:
-                       show_menu(server, view, action_str_from_arg(arg));
+                       show_menu(server, view, action_get_str(action, "menu", NULL));
                        break;
                case ACTION_TYPE_TOGGLE_MAXIMIZE:
                        if (view) {
@@ -702,7 +673,7 @@ actions_run(struct view *activator, struct server *server,
                        if (!output) {
                                break;
                        }
-                       const char *region_name = action_str_from_arg(arg);
+                       const char *region_name = action_get_str(action, "region", NULL);
                        struct region *region = regions_from_name(region_name, output);
                        if (region) {
                                view_snap_to_region(view, region,
@@ -718,7 +689,7 @@ actions_run(struct view *activator, struct server *server,
                        break;
                case ACTION_TYPE_FOCUS_OUTPUT:
                        {
-                               const char *output_name = action_str_from_arg(arg);
+                               const char *output_name = action_get_str(action, "output", NULL);
                                desktop_focus_output(output_from_name(server, output_name));
                        }
                        break;