[wip] src/action.c: Add action_arg_box

This commit is contained in:
Consolatis 2022-07-04 00:33:35 +02:00
parent 9b49f19a73
commit a0e22d5e07
3 changed files with 27 additions and 0 deletions

View file

@ -5,6 +5,7 @@
struct view;
struct server;
struct wl_list;
struct wlr_box;
struct action {
struct wl_list link; /* struct keybinding.actions,
@ -17,6 +18,7 @@ struct action {
struct action *action_create(const char *action_name);
void action_arg_add_str(struct action *action, char *key, const char *value);
struct wlr_box *action_arg_add_box(struct action *action, char *name);
void actions_run(struct view *activator, struct server *server,
struct wl_list *actions, uint32_t resize_edges);
void action_list_free(struct wl_list *action_list);

View file

@ -7,6 +7,7 @@
enum action_arg_type {
LAB_ACTION_ARG_STR = 0,
LAB_ACTION_ARG_BOX,
};
struct action_arg {
@ -21,4 +22,9 @@ struct action_arg_str {
char *value;
};
struct action_arg_box {
struct action_arg base;
struct wlr_box value;
};
#endif /* __LABWC_PRIVATE_ACTION_H */

View file

@ -73,6 +73,13 @@ action_str_from_arg(struct action_arg *arg)
return ((struct action_arg_str *)arg)->value;
}
static struct wlr_box *
action_box_from_arg(struct action_arg *arg)
{
assert(arg->type == LAB_ACTION_ARG_BOX);
return &((struct action_arg_box *)arg)->value;
}
static struct action_arg *
action_get_first_arg(struct action *action)
{
@ -357,3 +364,15 @@ action_arg_add_str(struct action *action, char *key, const char *value)
arg->value = strdup(value);
wl_list_insert(action->args.prev, &arg->base.link);
}
struct wlr_box *
action_arg_add_box(struct action *action, char *name)
{
struct action_arg_box *arg = calloc(1, sizeof(*arg));
arg->base.type = LAB_ACTION_ARG_BOX;
if (name) {
arg->base.key = strdup(name);
}
wl_list_insert(action->args.prev, &arg->base.link);
return &arg->value;
}