mirror of
https://github.com/labwc/labwc.git
synced 2026-03-11 05:33:49 -04:00
action: add get_arg_value_{str,bool} to simplify multi-arg handling
This commit is contained in:
parent
440f7bd760
commit
473f0aacbd
1 changed files with 30 additions and 20 deletions
50
src/action.c
50
src/action.c
|
|
@ -164,18 +164,38 @@ action_arg_from_xml_node(struct action *action, char *nodename, char *content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static const char *
|
||||||
action_str_from_arg(struct action_arg *arg)
|
action_str_from_arg(struct action_arg *arg)
|
||||||
{
|
{
|
||||||
assert(arg->type == LAB_ACTION_ARG_STR);
|
assert(arg->type == LAB_ACTION_ARG_STR);
|
||||||
return ((struct action_arg_str *)arg)->value;
|
return ((struct action_arg_str *)arg)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static const char *
|
||||||
action_bool_from_arg(struct action_arg *arg)
|
get_arg_value_str(struct action *action, const char *key, const char *default_value)
|
||||||
{
|
{
|
||||||
assert(arg->type == LAB_ACTION_ARG_BOOL);
|
assert(key);
|
||||||
return ((struct action_arg_bool *)arg)->value;
|
struct action_arg *arg;
|
||||||
|
wl_list_for_each(arg, &action->args, link) {
|
||||||
|
if (!strcasecmp(key, arg->key)) {
|
||||||
|
return action_str_from_arg(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
get_arg_value_bool(struct action *action, const char *key, bool default_value)
|
||||||
|
{
|
||||||
|
assert(key);
|
||||||
|
struct action_arg *arg;
|
||||||
|
wl_list_for_each(arg, &action->args, link) {
|
||||||
|
if (!strcasecmp(key, arg->key)) {
|
||||||
|
assert(arg->type == LAB_ACTION_ARG_BOOL);
|
||||||
|
return ((struct action_arg_bool *)arg)->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct action_arg *
|
static struct action_arg *
|
||||||
|
|
@ -244,7 +264,7 @@ void action_list_free(struct wl_list *action_list)
|
||||||
wl_list_remove(&arg->link);
|
wl_list_remove(&arg->link);
|
||||||
zfree(arg->key);
|
zfree(arg->key);
|
||||||
if (arg->type == LAB_ACTION_ARG_STR) {
|
if (arg->type == LAB_ACTION_ARG_STR) {
|
||||||
free(action_str_from_arg(arg));
|
free((void *)action_str_from_arg(arg));
|
||||||
}
|
}
|
||||||
zfree(arg);
|
zfree(arg);
|
||||||
}
|
}
|
||||||
|
|
@ -484,7 +504,7 @@ actions_run(struct view *activator, struct server *server,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
struct workspace *target;
|
struct workspace *target;
|
||||||
char *target_name = action_str_from_arg(arg);
|
const char *target_name = action_str_from_arg(arg);
|
||||||
target = workspaces_find(server->workspace_current, target_name);
|
target = workspaces_find(server->workspace_current, target_name);
|
||||||
if (target) {
|
if (target) {
|
||||||
workspaces_switch_to(target);
|
workspaces_switch_to(target);
|
||||||
|
|
@ -492,19 +512,9 @@ actions_run(struct view *activator, struct server *server,
|
||||||
break;
|
break;
|
||||||
case ACTION_TYPE_SEND_TO_DESKTOP:
|
case ACTION_TYPE_SEND_TO_DESKTOP:
|
||||||
if (view) {
|
if (view) {
|
||||||
struct action_arg *arg;
|
const char *to = get_arg_value_str(action, "to", NULL);
|
||||||
char *target_name = NULL;
|
bool follow = get_arg_value_bool(action, "follow", true);
|
||||||
struct workspace *target;
|
struct workspace *target = workspaces_find(view->workspace, to);
|
||||||
bool follow = true;
|
|
||||||
|
|
||||||
wl_list_for_each(arg, &action->args, link) {
|
|
||||||
if (!strcmp("to", arg->key)) {
|
|
||||||
target_name = action_str_from_arg(arg);
|
|
||||||
} else if (!strcmp("follow", arg->key)) {
|
|
||||||
follow = action_bool_from_arg(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
target = workspaces_find(view->workspace, target_name);
|
|
||||||
if (target) {
|
if (target) {
|
||||||
view_move_to_workspace(view, target);
|
view_move_to_workspace(view, target);
|
||||||
if (follow) {
|
if (follow) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue