aboutsummaryrefslogtreecommitdiff
path: root/sway/criteria.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-07-23 20:27:56 -0400
committerDrew DeVault <sir@cmpwn.com>2018-07-23 20:31:11 -0400
commitf4b882475eee7a81c206c7825616cc4656b2f60b (patch)
tree38e6ebf81b235424f105dcbcbb194e5e9eac70c0 /sway/criteria.c
parentacd79e1505c06089e4fb9fb6c0c6e1d351ba9176 (diff)
parent224ade138208e9aa525423cbfbd643aa9d9b63c3 (diff)
Merge branch 'master' into pid-workspaces
Diffstat (limited to 'sway/criteria.c')
-rw-r--r--sway/criteria.c57
1 files changed, 53 insertions, 4 deletions
diff --git a/sway/criteria.c b/sway/criteria.c
index d9f09ecc..c2e9c07e 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -37,7 +37,7 @@ void criteria_destroy(struct criteria *criteria) {
pcre_free(criteria->con_mark);
pcre_free(criteria->window_role);
free(criteria->workspace);
-
+ free(criteria->cmdlist);
free(criteria->raw);
free(criteria);
}
@@ -46,6 +46,31 @@ static int regex_cmp(const char *item, const pcre *regex) {
return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
}
+static int cmp_urgent(const void *_a, const void *_b) {
+ struct sway_view *a = *(void **)_a;
+ struct sway_view *b = *(void **)_b;
+
+ if (a->urgent.tv_sec < b->urgent.tv_sec) {
+ return -1;
+ } else if (a->urgent.tv_sec > b->urgent.tv_sec) {
+ return 1;
+ }
+ if (a->urgent.tv_nsec < b->urgent.tv_nsec) {
+ return -1;
+ } else if (a->urgent.tv_nsec > b->urgent.tv_nsec) {
+ return 1;
+ }
+ return 0;
+}
+
+static void find_urgent_iterator(struct sway_container *swayc, void *data) {
+ if (swayc->type != C_VIEW || !view_is_urgent(swayc->sway_view)) {
+ return;
+ }
+ list_t *urgent_views = data;
+ list_add(urgent_views, swayc->sway_view);
+}
+
static bool criteria_matches_view(struct criteria *criteria,
struct sway_view *view) {
if (criteria->title) {
@@ -133,8 +158,23 @@ static bool criteria_matches_view(struct criteria *criteria,
}
if (criteria->urgent) {
- // TODO
- return false;
+ if (!view_is_urgent(view)) {
+ return false;
+ }
+ list_t *urgent_views = create_list();
+ container_for_each_descendant_dfs(&root_container,
+ find_urgent_iterator, urgent_views);
+ list_stable_sort(urgent_views, cmp_urgent);
+ struct sway_view *target;
+ if (criteria->urgent == 'o') { // oldest
+ target = urgent_views->items[0];
+ } else { // latest
+ target = urgent_views->items[urgent_views->length - 1];
+ }
+ list_free(urgent_views);
+ if (view != target) {
+ return false;
+ }
}
if (criteria->workspace) {
@@ -185,6 +225,15 @@ list_t *criteria_get_views(struct criteria *criteria) {
};
container_for_each_descendant_dfs(&root_container,
criteria_get_views_iterator, &data);
+
+ // Scratchpad items which are hidden are not in the tree.
+ for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
+ struct sway_container *con =
+ root_container.sway_root->scratchpad->items[i];
+ if (!con->parent) {
+ criteria_get_views_iterator(con, &data);
+ }
+ }
return matches;
}
@@ -507,7 +556,7 @@ struct criteria *criteria_parse(char *raw, char **error_arg) {
}
unescape(value);
}
- wlr_log(L_DEBUG, "Found pair: %s=%s", name, value);
+ wlr_log(WLR_DEBUG, "Found pair: %s=%s", name, value);
if (!parse_token(criteria, name, value)) {
*error_arg = error;
goto cleanup;