aboutsummaryrefslogtreecommitdiffstats
path: root/sway/criteria.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-01 23:04:49 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-01 23:04:49 +1000
commitf4ec3083766280a5197cf40680bf991cc9afa41b (patch)
treeb20160b4d0b0798bd0b6a6050a455b5285479442 /sway/criteria.c
parentMerge pull request #2546 from RyanDwyer/fix-transaction-spamming (diff)
downloadsway-f4ec3083766280a5197cf40680bf991cc9afa41b.tar.gz
sway-f4ec3083766280a5197cf40680bf991cc9afa41b.tar.zst
sway-f4ec3083766280a5197cf40680bf991cc9afa41b.zip
Implement window_type criteria token
Diffstat (limited to 'sway/criteria.c')
-rw-r--r--sway/criteria.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/sway/criteria.c b/sway/criteria.c
index 5452c4ee..13176fa1 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -2,6 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <stdbool.h> 4#include <stdbool.h>
5#include <strings.h>
5#include <pcre.h> 6#include <pcre.h>
6#include "sway/criteria.h" 7#include "sway/criteria.h"
7#include "sway/tree/container.h" 8#include "sway/tree/container.h"
@@ -25,7 +26,7 @@ bool criteria_is_empty(struct criteria *criteria) {
25 && !criteria->id 26 && !criteria->id
26#endif 27#endif
27 && !criteria->window_role 28 && !criteria->window_role
28 && !criteria->window_type 29 && criteria->window_type == ATOM_LAST
29 && !criteria->floating 30 && !criteria->floating
30 && !criteria->tiling 31 && !criteria->tiling
31 && !criteria->urgent 32 && !criteria->urgent
@@ -50,6 +51,23 @@ static int regex_cmp(const char *item, const pcre *regex) {
50 return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0); 51 return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
51} 52}
52 53
54static bool view_has_window_type(struct sway_view *view, enum atom_name name) {
55#ifdef HAVE_XWAYLAND
56 if (view->type != SWAY_VIEW_XWAYLAND) {
57 return false;
58 }
59 struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface;
60 struct sway_xwayland *xwayland = &server.xwayland;
61 xcb_atom_t desired_atom = xwayland->atoms[name];
62 for (size_t i = 0; i < surface->window_type_len; ++i) {
63 if (surface->window_type[i] == desired_atom) {
64 return true;
65 }
66 }
67#endif
68 return false;
69}
70
53static int cmp_urgent(const void *_a, const void *_b) { 71static int cmp_urgent(const void *_a, const void *_b) {
54 struct sway_view *a = *(void **)_a; 72 struct sway_view *a = *(void **)_a;
55 struct sway_view *b = *(void **)_b; 73 struct sway_view *b = *(void **)_b;
@@ -144,9 +162,8 @@ static bool criteria_matches_view(struct criteria *criteria,
144 // TODO 162 // TODO
145 } 163 }
146 164
147 if (criteria->window_type) { 165 if (criteria->window_type != ATOM_LAST) {
148 uint32_t type = view_get_window_type(view); 166 if (!view_has_window_type(view, criteria->window_type)) {
149 if (!type || type != criteria->window_type) {
150 return false; 167 return false;
151 } 168 }
152 } 169 }
@@ -254,6 +271,21 @@ static bool generate_regex(pcre **regex, char *value) {
254 return true; 271 return true;
255} 272}
256 273
274static enum atom_name parse_window_type(const char *type) {
275 if (strcasecmp(type, "normal") == 0) {
276 return NET_WM_WINDOW_TYPE_NORMAL;
277 } else if (strcasecmp(type, "dialog") == 0) {
278 return NET_WM_WINDOW_TYPE_DIALOG;
279 } else if (strcasecmp(type, "utility") == 0) {
280 return NET_WM_WINDOW_TYPE_UTILITY;
281 } else if (strcasecmp(type, "toolbar") == 0) {
282 return NET_WM_WINDOW_TYPE_TOOLBAR;
283 } else if (strcasecmp(type, "splash") == 0) {
284 return NET_WM_WINDOW_TYPE_SPLASH;
285 }
286 return ATOM_LAST; // ie. invalid
287}
288
257enum criteria_token { 289enum criteria_token {
258 T_APP_ID, 290 T_APP_ID,
259 T_CLASS, 291 T_CLASS,
@@ -434,7 +466,7 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
434 generate_regex(&criteria->window_role, effective_value); 466 generate_regex(&criteria->window_role, effective_value);
435 break; 467 break;
436 case T_WINDOW_TYPE: 468 case T_WINDOW_TYPE:
437 // TODO: This is a string but will be stored as an enum or integer 469 criteria->window_type = parse_window_type(effective_value);
438 break; 470 break;
439#ifdef HAVE_XWAYLAND 471#ifdef HAVE_XWAYLAND
440 case T_ID: 472 case T_ID:
@@ -526,7 +558,8 @@ struct criteria *criteria_parse(char *raw, char **error_arg) {
526 } 558 }
527 ++head; 559 ++head;
528 560
529 struct criteria *criteria = calloc(sizeof(struct criteria), 1); 561 struct criteria *criteria = calloc(1, sizeof(struct criteria));
562 criteria->window_type = ATOM_LAST; // default value
530 char *name = NULL, *value = NULL; 563 char *name = NULL, *value = NULL;
531 bool in_quotes = false; 564 bool in_quotes = false;
532 565