]> git.lizzy.rs Git - bspwm.git/blob - rules.c
Show / hide wrappers should make unmap_notify work
[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 *fullscreen, 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_t win_state;
52
53     if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
54         for (unsigned int i = 0; i < win_state.atoms_len; i++) {
55             xcb_atom_t a = win_state.atoms[i];
56             if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
57                 *fullscreen = true;
58             }
59         }
60     }
61
62     /* xcb_ewmh_get_atoms_reply_wipe(&win_type); */
63
64     xcb_window_t transient_for = XCB_NONE;
65     xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
66     *transient = (transient_for == XCB_NONE ? false : true);
67     if (*transient)
68         *floating = true;
69
70     rule_t *rule = rule_head;
71
72     while (rule != NULL) {
73         if (is_match(rule, win)) {
74             if (rule->effect.floating) {
75                 *floating = true;
76             }
77         }
78         rule = rule->next;
79     }
80 }