action: support SendToDesktop 'follow' option

Make follow 'true' by default as per Openbox 3.6 specification.
Note: this is an interface change.

Fixes: issue #841
This commit is contained in:
Johan Malm 2023-03-26 10:57:53 +01:00 committed by Consolatis
parent bdf6e13881
commit 33b98b19aa
6 changed files with 67 additions and 17 deletions

View file

@ -7,6 +7,7 @@
#include <unistd.h>
#include <wlr/util/log.h>
#include "action.h"
#include "common/get-bool.h"
#include "common/list.h"
#include "common/mem.h"
#include "common/spawn.h"
@ -20,6 +21,7 @@
enum action_arg_type {
LAB_ACTION_ARG_STR = 0,
LAB_ACTION_ARG_BOOL,
};
struct action_arg {
@ -34,6 +36,11 @@ struct action_arg_str {
char *value;
};
struct action_arg_bool {
struct action_arg base;
bool value;
};
enum action_type {
ACTION_TYPE_INVALID = 0,
ACTION_TYPE_NONE,
@ -117,7 +124,10 @@ action_arg_from_xml_node(struct action *action, char *nodename, char *content)
action_arg_add_str(action, NULL, content);
} else if (!strcmp(nodename, "to.action")) {
/* GoToDesktop, SendToDesktop */
action_arg_add_str(action, NULL, content);
action_arg_add_str(action, "to", content);
} else if (!strcmp(nodename, "follow.action")) {
/* SendToDesktop */
action_arg_add_bool(action, "follow", get_bool(content));
} else if (!strcmp(nodename, "region.action")) {
/* SnapToRegion */
action_arg_add_str(action, NULL, content);
@ -134,6 +144,13 @@ action_str_from_arg(struct action_arg *arg)
return ((struct action_arg_str *)arg)->value;
}
static bool
action_bool_from_arg(struct action_arg *arg)
{
assert(arg->type == LAB_ACTION_ARG_BOOL);
return ((struct action_arg_bool *)arg)->value;
}
static struct action_arg *
action_get_first_arg(struct action *action)
{
@ -442,16 +459,25 @@ actions_run(struct view *activator, struct server *server,
}
break;
case ACTION_TYPE_SEND_TO_DESKTOP:
if (!arg) {
wlr_log(WLR_ERROR, "Missing argument for SendToDesktop");
break;
}
if (view) {
struct action_arg *arg;
char *target_name = NULL;
struct workspace *target;
char *target_name = action_str_from_arg(arg);
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) {
view_move_to_workspace(view, target);
if (follow) {
workspaces_switch_to(target);
}
}
}
break;
@ -517,3 +543,15 @@ action_arg_add_str(struct action *action, char *key, const char *value)
arg->value = xstrdup(value);
wl_list_append(&action->args, &arg->base.link);
}
void
action_arg_add_bool(struct action *action, char *key, bool value)
{
struct action_arg_bool *arg = znew(*arg);
arg->base.type = LAB_ACTION_ARG_BOOL;
if (key) {
arg->base.key = xstrdup(key);
}
arg->value = value;
wl_list_append(&action->args, &arg->base.link);
}