]> git.sur5r.net Git - i3/i3/blob - src/match.c
c384c41acd654830915a0be25f042b21657e10b9
[i3/i3] / src / match.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * A "match" is a data structure which acts like a mask or expression to match
8  * certain windows or not. For example, when using commands, you can specify a
9  * command like this: [title="*Firefox*"] kill. The title member of the match
10  * data structure will then be filled and i3 will check each window using
11  * match_matches_window() to find the windows affected by this command.
12  *
13  */
14
15 #include "all.h"
16
17 /*
18  * Check if a match is empty. This is necessary while parsing commands to see
19  * whether the user specified a match at all.
20  *
21  */
22 bool match_is_empty(Match *match) {
23     /* we cannot simply use memcmp() because the structure is part of a
24      * TAILQ and I don’t want to start with things like assuming that the
25      * last member of a struct really is at the end in memory… */
26     return (match->title == NULL &&
27             match->mark == NULL &&
28             match->application == NULL &&
29             match->class == NULL &&
30             match->instance == NULL &&
31             match->id == XCB_NONE &&
32             match->con_id == NULL &&
33             match->floating == M_ANY);
34 }
35
36 /*
37  * Check if a match data structure matches the given window.
38  *
39  */
40 bool match_matches_window(Match *match, i3Window *window) {
41     /* TODO: pcre, full matching, … */
42     if (match->class != NULL && window->class_class != NULL && strcasecmp(match->class, window->class_class) == 0) {
43         LOG("match made by window class (%s)\n", window->class_class);
44         return true;
45     }
46
47     if (match->instance != NULL && window->class_instance != NULL && strcasecmp(match->instance, window->class_instance) == 0) {
48         LOG("match made by window instance (%s)\n", window->class_instance);
49         return true;
50     }
51
52     if (match->id != XCB_NONE && window->id == match->id) {
53         LOG("match made by window id (%d)\n", window->id);
54         return true;
55     }
56
57     LOG("window %d (%s) could not be matched\n", window->id, window->class_class);
58
59     return false;
60 }
61