]> git.lizzy.rs Git - bspwm.git/blob - rules.c
79eecb2c354735ad8f3df0e9ef0a948b8c6e28e6
[bspwm.git] / rules.c
1 #include <string.h>
2 #include <xcb/xcb_icccm.h>
3 #include <xcb/xcb_ewmh.h>
4 #include "types.h"
5 #include "bspwm.h"
6 #include "ewmh.h"
7 #include "rules.h"
8
9 rule_t *next_match(rule_t *rule, xcb_window_t win)
10 {
11     if (rule == NULL)
12         return NULL;
13     rule_t *r = rule;
14     rule_t *found = NULL;
15     while (r != NULL && found == NULL) {
16         if (is_match(r, win))
17             found = r;
18         r = r->next;
19     }
20     return found;
21 }
22
23 bool is_match(rule_t *r, xcb_window_t win)
24 {
25     xcb_icccm_get_wm_class_reply_t reply; 
26     if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1
27             && (strcmp(reply.class_name, r->cause.name) == 0
28                 || strcmp(reply.instance_name, r->cause.name) == 0)) {
29         xcb_icccm_get_wm_class_reply_wipe(&reply);
30         return true;
31     }
32     return false;
33 }
34
35 void handle_rules(xcb_window_t win, bool *floating, bool *transient, bool *takes_focus)
36 {
37     xcb_ewmh_get_atoms_reply_t win_type;
38
39     if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
40         for (unsigned int i = 0; i < win_type.atoms_len; i++) {
41             xcb_atom_t a = win_type.atoms[i];
42             if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
43                     || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
44                 *takes_focus = false;
45             } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
46                 *floating = true;
47             }
48         }
49     }
50
51     /* xcb_ewmh_get_atoms_reply_wipe(&win_type); */
52
53     xcb_window_t transient_for = XCB_NONE;
54     xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
55     *transient = (transient_for == XCB_NONE ? false : true);
56     if (*transient)
57         *floating = true;
58
59     rule_t *rule = rule_head;
60
61     while (rule != NULL) {
62         if (is_match(rule, win)) {
63             if (rule->effect.floating) {
64                 *floating = true;
65             }
66         }
67         rule = rule->next;
68     }
69 }