mirror of
https://github.com/labwc/labwc.git
synced 2026-03-02 01:40:24 -05:00
src/action.c: enforce action arg->key being set
This commit is contained in:
parent
d0b52139ed
commit
b05b92bb27
3 changed files with 40 additions and 46 deletions
|
|
@ -20,7 +20,7 @@ struct action {
|
||||||
|
|
||||||
struct action *action_create(const char *action_name);
|
struct action *action_create(const char *action_name);
|
||||||
|
|
||||||
void action_arg_add_str(struct action *action, char *key, const char *value);
|
void action_arg_add_str(struct action *action, const char *key, const char *value);
|
||||||
|
|
||||||
void action_arg_from_xml_node(struct action *action, char *nodename, char *content);
|
void action_arg_from_xml_node(struct action *action, char *nodename, char *content);
|
||||||
|
|
||||||
|
|
|
||||||
36
src/action.c
36
src/action.c
|
|
@ -122,38 +122,38 @@ const char *action_names[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
action_arg_add_str(struct action *action, char *key, const char *value)
|
action_arg_add_str(struct action *action, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
|
assert(key);
|
||||||
assert(value && "Tried to add NULL action string argument");
|
assert(value && "Tried to add NULL action string argument");
|
||||||
struct action_arg_str *arg = znew(*arg);
|
struct action_arg_str *arg = znew(*arg);
|
||||||
arg->base.type = LAB_ACTION_ARG_STR;
|
arg->base.type = LAB_ACTION_ARG_STR;
|
||||||
if (key) {
|
arg->base.key = xstrdup(key);
|
||||||
arg->base.key = xstrdup(key);
|
|
||||||
}
|
|
||||||
arg->value = xstrdup(value);
|
arg->value = xstrdup(value);
|
||||||
wl_list_append(&action->args, &arg->base.link);
|
wl_list_append(&action->args, &arg->base.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
action_arg_add_bool(struct action *action, char *key, bool value)
|
action_arg_add_bool(struct action *action, const char *key, bool value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
|
assert(key);
|
||||||
struct action_arg_bool *arg = znew(*arg);
|
struct action_arg_bool *arg = znew(*arg);
|
||||||
arg->base.type = LAB_ACTION_ARG_BOOL;
|
arg->base.type = LAB_ACTION_ARG_BOOL;
|
||||||
if (key) {
|
arg->base.key = xstrdup(key);
|
||||||
arg->base.key = xstrdup(key);
|
|
||||||
}
|
|
||||||
arg->value = value;
|
arg->value = value;
|
||||||
wl_list_append(&action->args, &arg->base.link);
|
wl_list_append(&action->args, &arg->base.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
action_arg_add_int(struct action *action, char *key, int value)
|
action_arg_add_int(struct action *action, const char *key, int value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
|
assert(key);
|
||||||
struct action_arg_int *arg = znew(*arg);
|
struct action_arg_int *arg = znew(*arg);
|
||||||
arg->base.type = LAB_ACTION_ARG_INT;
|
arg->base.type = LAB_ACTION_ARG_INT;
|
||||||
if (key) {
|
arg->base.key = xstrdup(key);
|
||||||
arg->base.key = xstrdup(key);
|
|
||||||
}
|
|
||||||
arg->value = value;
|
arg->value = value;
|
||||||
wl_list_append(&action->args, &arg->base.link);
|
wl_list_append(&action->args, &arg->base.link);
|
||||||
}
|
}
|
||||||
|
|
@ -252,12 +252,10 @@ action_str_from_arg(struct action_arg *arg)
|
||||||
static const char *
|
static const char *
|
||||||
get_arg_value_str(struct action *action, const char *key, const char *default_value)
|
get_arg_value_str(struct action *action, const char *key, const char *default_value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
assert(key);
|
assert(key);
|
||||||
struct action_arg *arg;
|
struct action_arg *arg;
|
||||||
wl_list_for_each(arg, &action->args, link) {
|
wl_list_for_each(arg, &action->args, link) {
|
||||||
if (!arg->key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcasecmp(key, arg->key)) {
|
if (!strcasecmp(key, arg->key)) {
|
||||||
return action_str_from_arg(arg);
|
return action_str_from_arg(arg);
|
||||||
}
|
}
|
||||||
|
|
@ -268,12 +266,10 @@ get_arg_value_str(struct action *action, const char *key, const char *default_va
|
||||||
static bool
|
static bool
|
||||||
get_arg_value_bool(struct action *action, const char *key, bool default_value)
|
get_arg_value_bool(struct action *action, const char *key, bool default_value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
assert(key);
|
assert(key);
|
||||||
struct action_arg *arg;
|
struct action_arg *arg;
|
||||||
wl_list_for_each(arg, &action->args, link) {
|
wl_list_for_each(arg, &action->args, link) {
|
||||||
if (!arg->key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcasecmp(key, arg->key)) {
|
if (!strcasecmp(key, arg->key)) {
|
||||||
assert(arg->type == LAB_ACTION_ARG_BOOL);
|
assert(arg->type == LAB_ACTION_ARG_BOOL);
|
||||||
return ((struct action_arg_bool *)arg)->value;
|
return ((struct action_arg_bool *)arg)->value;
|
||||||
|
|
@ -285,12 +281,10 @@ get_arg_value_bool(struct action *action, const char *key, bool default_value)
|
||||||
static int
|
static int
|
||||||
get_arg_value_int(struct action *action, const char *key, int default_value)
|
get_arg_value_int(struct action *action, const char *key, int default_value)
|
||||||
{
|
{
|
||||||
|
assert(action);
|
||||||
assert(key);
|
assert(key);
|
||||||
struct action_arg *arg;
|
struct action_arg *arg;
|
||||||
wl_list_for_each(arg, &action->args, link) {
|
wl_list_for_each(arg, &action->args, link) {
|
||||||
if (!arg->key) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strcasecmp(key, arg->key)) {
|
if (!strcasecmp(key, arg->key)) {
|
||||||
assert(arg->type == LAB_ACTION_ARG_INT);
|
assert(arg->type == LAB_ACTION_ARG_INT);
|
||||||
return ((struct action_arg_int *)arg)->value;
|
return ((struct action_arg_int *)arg)->value;
|
||||||
|
|
|
||||||
|
|
@ -808,28 +808,28 @@ rcxml_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char *binding, *action, *command;
|
const char *binding, *action, *attribute, *value;
|
||||||
} key_combos[] = {
|
} key_combos[] = {
|
||||||
{ "A-Tab", "NextWindow", NULL },
|
{ "A-Tab", "NextWindow", NULL, NULL },
|
||||||
{ "W-Return", "Execute", "alacritty" },
|
{ "W-Return", "Execute", "command", "alacritty" },
|
||||||
{ "A-F3", "Execute", "bemenu-run" },
|
{ "A-F3", "Execute", "command", "bemenu-run" },
|
||||||
{ "A-F4", "Close", NULL },
|
{ "A-F4", "Close", NULL, NULL },
|
||||||
{ "W-a", "ToggleMaximize", NULL },
|
{ "W-a", "ToggleMaximize", NULL, NULL },
|
||||||
{ "A-Left", "MoveToEdge", "left" },
|
{ "A-Left", "MoveToEdge", "direction", "left" },
|
||||||
{ "A-Right", "MoveToEdge", "right" },
|
{ "A-Right", "MoveToEdge", "direction", "right" },
|
||||||
{ "A-Up", "MoveToEdge", "up" },
|
{ "A-Up", "MoveToEdge", "direction", "up" },
|
||||||
{ "A-Down", "MoveToEdge", "down" },
|
{ "A-Down", "MoveToEdge", "direction", "down" },
|
||||||
{ "W-Left", "SnapToEdge", "left" },
|
{ "W-Left", "SnapToEdge", "direction", "left" },
|
||||||
{ "W-Right", "SnapToEdge", "right" },
|
{ "W-Right", "SnapToEdge", "direction", "right" },
|
||||||
{ "W-Up", "SnapToEdge", "up" },
|
{ "W-Up", "SnapToEdge", "direction", "up" },
|
||||||
{ "W-Down", "SnapToEdge", "down" },
|
{ "W-Down", "SnapToEdge", "direction", "down" },
|
||||||
{ "A-Space", "ShowMenu", "client-menu"},
|
{ "A-Space", "ShowMenu", "menu", "client-menu"},
|
||||||
{ "XF86_AudioLowerVolume", "Execute", "amixer sset Master 5%-" },
|
{ "XF86_AudioLowerVolume", "Execute", "command", "amixer sset Master 5%-" },
|
||||||
{ "XF86_AudioRaiseVolume", "Execute", "amixer sset Master 5%+" },
|
{ "XF86_AudioRaiseVolume", "Execute", "command", "amixer sset Master 5%+" },
|
||||||
{ "XF86_AudioMute", "Execute", "amixer sset Master toggle" },
|
{ "XF86_AudioMute", "Execute", "command", "amixer sset Master toggle" },
|
||||||
{ "XF86_MonBrightnessUp", "Execute", "brightnessctl set +10%" },
|
{ "XF86_MonBrightnessUp", "Execute", "command", "brightnessctl set +10%" },
|
||||||
{ "XF86_MonBrightnessDown", "Execute", "brightnessctl set 10%-" },
|
{ "XF86_MonBrightnessDown", "Execute", "command", "brightnessctl set 10%-" },
|
||||||
{ NULL, NULL, NULL },
|
{ NULL, NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -846,8 +846,8 @@ load_default_key_bindings(void)
|
||||||
action = action_create(key_combos[i].action);
|
action = action_create(key_combos[i].action);
|
||||||
wl_list_append(&k->actions, &action->link);
|
wl_list_append(&k->actions, &action->link);
|
||||||
|
|
||||||
if (key_combos[i].command) {
|
if (key_combos[i].attribute && key_combos[i].value) {
|
||||||
action_arg_add_str(action, NULL, key_combos[i].command);
|
action_arg_add_str(action, key_combos[i].attribute, key_combos[i].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -956,7 +956,7 @@ load_default_mouse_bindings(void)
|
||||||
* slightly more sophisticated approach will be needed.
|
* slightly more sophisticated approach will be needed.
|
||||||
*/
|
*/
|
||||||
if (current->attribute && current->value) {
|
if (current->attribute && current->value) {
|
||||||
action_arg_add_str(action, (char *)current->attribute, current->value);
|
action_arg_add_str(action, current->attribute, current->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wlr_log(WLR_DEBUG, "Loaded %u merged mousebinds", count);
|
wlr_log(WLR_DEBUG, "Loaded %u merged mousebinds", count);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue