]> git.sur5r.net Git - i3/i3/blob - src/match.c
move match_* to match.c
[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  */
8
9 #include "all.h"
10
11 bool match_is_empty(Match *match) {
12     /* we cannot simply use memcmp() because the structure is part of a
13      * TAILQ and I don’t want to start with things like assuming that the
14      * last member of a struct really is at the end in memory… */
15     return (match->title == NULL &&
16             match->application == NULL &&
17             match->class == NULL &&
18             match->instance == NULL &&
19             match->id == XCB_NONE &&
20             match->con_id == NULL &&
21             match->floating == false);
22 }
23
24 bool match_matches_window(Match *match, i3Window *window) {
25     /* TODO: pcre, full matching, … */
26     if (match->class != NULL && window->class_class != NULL && strcasecmp(match->class, window->class_class) == 0) {
27         LOG("match made by window class (%s)\n", window->class_class);
28         return true;
29     }
30
31     if (match->instance != NULL && window->class_instance != NULL && strcasecmp(match->instance, window->class_instance) == 0) {
32         LOG("match made by window instance (%s)\n", window->class_instance);
33         return true;
34     }
35
36
37     if (match->id != XCB_NONE && window->id == match->id) {
38         LOG("match made by window id (%d)\n", window->id);
39         return true;
40     }
41
42     LOG("window %d (%s) could not be matched\n", window->id, window->class_class);
43
44     return false;
45 }
46