From 4a664a2e7bc389bf4c03bde74c65ae2e274ed3f9 Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Mon, 5 Feb 2024 20:16:37 +0100 Subject: [PATCH] workspace criterion also applys to containers --- sway/criteria.c | 46 +++++++++++++++++++++++++--------------------- sway/sway.5.scd | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/sway/criteria.c b/sway/criteria.c index 78ea8b8a4..484378c23 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -159,6 +159,31 @@ static bool has_container_criteria(struct criteria *criteria) { static bool criteria_matches_container(struct criteria *criteria, struct sway_container *container) { + struct sway_seat *seat = input_manager_current_seat(); + struct sway_container *focus = seat_get_focused_container(seat); + struct sway_view *focused = focus ? focus->view : NULL; + + if (criteria->workspace) { + struct sway_workspace *ws = container->pending.workspace; + if (!ws) { + return false; + } + + switch (criteria->workspace->match_type) { + case PATTERN_FOCUSED: + if (focused && + strcmp(ws->name, focused->container->pending.workspace->name)) { + return false; + } + break; + case PATTERN_PCRE2: + if (regex_cmp(ws->name, criteria->workspace->regex) < 0) { + return false; + } + break; + } + } + if (criteria->con_mark) { bool exists = false; struct sway_container *con = container; @@ -358,27 +383,6 @@ static bool criteria_matches_view(struct criteria *criteria, } } - if (criteria->workspace) { - struct sway_workspace *ws = view->container->pending.workspace; - if (!ws) { - return false; - } - - switch (criteria->workspace->match_type) { - case PATTERN_FOCUSED: - if (focused && - strcmp(ws->name, focused->container->pending.workspace->name)) { - return false; - } - break; - case PATTERN_PCRE2: - if (regex_cmp(ws->name, criteria->workspace->regex) < 0) { - return false; - } - break; - } - } - if (criteria->pid) { if (criteria->pid != view->pid) { return false; diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 7e58b5286..7146db848 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -1031,7 +1031,7 @@ The following attributes may be matched with: applications and requires XWayland. *workspace* - Compare against the workspace name for this view. Can be a regular + Compare against the workspace name for this container. Can be a regular expression. If the value is \_\_focused\_\_, then all the views on the currently focused workspace matches.