aboutsummaryrefslogtreecommitdiff
path: root/sway/criteria.c
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-07-15 22:43:33 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-07-16 08:19:25 +1000
commit315d5311b2004b9e148e7b52a7de161b6dfe3878 (patch)
tree1a70d1d73cbffb26bf432c1c7b395ee996651ad3 /sway/criteria.c
parentb314a8f2cc792aa59d8f12e5adb9aed2967af646 (diff)
Implement urgency base functionality
Introduces a command to manually set urgency, as well as rendering of urgent views, sending the IPC event, removing urgency after focused for one second, and matching urgent views via criteria.
Diffstat (limited to 'sway/criteria.c')
-rw-r--r--sway/criteria.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/sway/criteria.c b/sway/criteria.c
index 29a3668b..c999d248 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -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) {