From 9181ea1e6f6c1435dc6c392111845ca2705792e4 Mon Sep 17 00:00:00 2001 From: Orfeas <38209077+0xfea5@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:05:45 +0300 Subject: [PATCH] query: added "decoration" option --- include/ssd.h | 3 ++- include/view.h | 1 + src/action.c | 7 ++++++- src/config/rcxml.c | 2 ++ src/ssd/ssd.c | 6 ++++-- src/view.c | 28 +++++++++++++++++++++++----- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/ssd.h b/include/ssd.h index d5b66c08..fe56be54 100644 --- a/include/ssd.h +++ b/include/ssd.h @@ -62,9 +62,10 @@ enum ssd_part_type { }; enum ssd_mode { + LAB_SSD_MODE_INVALID, LAB_SSD_MODE_NONE, LAB_SSD_MODE_BORDER, - LAB_SSD_MODE_FULL + LAB_SSD_MODE_FULL, }; /* Forward declare arguments */ diff --git a/include/view.h b/include/view.h index ed1d4145..6b052b20 100644 --- a/include/view.h +++ b/include/view.h @@ -300,6 +300,7 @@ struct view_query { enum view_edge tiled; char *tiled_region; char *desktop; + enum ssd_mode decoration; }; struct xdg_toplevel_view { diff --git a/src/action.c b/src/action.c index 810026a6..0c5c7c7d 100644 --- a/src/action.c +++ b/src/action.c @@ -378,7 +378,12 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char case ACTION_TYPE_SET_DECORATIONS: if (!strcmp(argument, "decorations")) { enum ssd_mode mode = ssd_mode_parse(content); - action_arg_add_int(action, argument, mode); + if (mode != LAB_SSD_MODE_INVALID) { + action_arg_add_int(action, argument, mode); + } else { + wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)", + action_names[action->type], argument, content); + } goto cleanup; } if (!strcasecmp(argument, "forceSSD")) { diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 463b5139..f226f337 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -493,6 +493,8 @@ fill_action_query(char *nodename, char *content, struct action *action) current_view_query->tiled_region = xstrdup(content); } else if (!strcasecmp(nodename, "desktop")) { current_view_query->desktop = xstrdup(content); + } else if (!strcasecmp(nodename, "decoration")) { + current_view_query->decoration = ssd_mode_parse(content); } } diff --git a/src/ssd/ssd.c b/src/ssd/ssd.c index c1e4e0e5..a9fc1abc 100644 --- a/src/ssd/ssd.c +++ b/src/ssd/ssd.c @@ -350,14 +350,16 @@ enum ssd_mode ssd_mode_parse(const char *mode) { if (!mode) { - return LAB_SSD_MODE_FULL; + return LAB_SSD_MODE_INVALID; } if (!strcasecmp(mode, "none")) { return LAB_SSD_MODE_NONE; } else if (!strcasecmp(mode, "border")) { return LAB_SSD_MODE_BORDER; - } else { + } else if (!strcasecmp(mode, "full")) { return LAB_SSD_MODE_FULL; + } else { + return LAB_SSD_MODE_INVALID; } } diff --git a/src/view.c b/src/view.c index 1c6282c7..0497bac5 100644 --- a/src/view.c +++ b/src/view.c @@ -89,14 +89,20 @@ view_query_free(struct view_query *query) zfree(query); } +static enum three_state +bool_to_tristate(bool b) +{ + return b ? LAB_STATE_ENABLED : LAB_STATE_DISABLED; +} + static enum three_state match_tristate(enum three_state desired, bool actual, enum three_state old_match) { switch (desired) { case LAB_STATE_ENABLED: - return actual ? LAB_STATE_ENABLED : LAB_STATE_DISABLED; + return bool_to_tristate(actual); case LAB_STATE_DISABLED: - return actual ? LAB_STATE_DISABLED : LAB_STATE_ENABLED; + return bool_to_tristate(!actual); default: return old_match; } @@ -209,14 +215,26 @@ view_matches_query(struct view *view, struct view_query *query) if (query->desktop) { if (!strcasecmp(query->desktop, "other")) { - return strcasecmp(view->workspace->name, - view->server->workspaces.current->name); + struct workspace *current = view->server->workspaces.current; + match = bool_to_tristate(strcasecmp(view->workspace->name, current->name)); } else { // TODO: perhaps allow wrapping for "left" and "right" workspaces struct workspace *target = workspaces_find(view->server->workspaces.current, query->desktop, false); - return target && !strcasecmp(view->workspace->name, target->name); + match = bool_to_tristate(target && + !strcasecmp(view->workspace->name, target->name)); + } + if (match == LAB_STATE_DISABLED) { + return false; + } + } + + enum ssd_mode decoration = view_get_ssd_mode(view); + if (query->decoration != LAB_SSD_MODE_INVALID) { + match = bool_to_tristate(query->decoration == decoration); + if (match == LAB_STATE_DISABLED) { + return false; } }