]> git.lizzy.rs Git - bspwm.git/blob - rules.c
Correctly honour 'active_border_color' setting
[bspwm.git] / rules.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <xcb/xcb_icccm.h>
4 #include <xcb/xcb_ewmh.h>
5 #include "types.h"
6 #include "bspwm.h"
7 #include "ewmh.h"
8 #include "rules.h"
9
10 bool is_match(rule_t *r, xcb_window_t win)
11 {
12     xcb_icccm_get_wm_class_reply_t reply; 
13     if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1
14             && (strcmp(reply.class_name, r->cause.name) == 0
15                 || strcmp(reply.instance_name, r->cause.name) == 0)) {
16         xcb_icccm_get_wm_class_reply_wipe(&reply);
17         return true;
18     }
19     return false;
20 }
21
22 void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating, bool *transient, bool *fullscreen, bool *takes_focus, bool *manage)
23 {
24     xcb_ewmh_get_atoms_reply_t win_type;
25
26     if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
27         for (unsigned int i = 0; i < win_type.atoms_len; i++) {
28             xcb_atom_t a = win_type.atoms[i];
29             if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
30                     || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
31                 *takes_focus = false;
32             } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
33                 *floating = true;
34             } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DOCK || a == ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION) {
35                 *manage = false;
36             }
37         }
38         xcb_ewmh_get_atoms_reply_wipe(&win_type);
39     }
40
41     xcb_size_hints_t size_hints;
42
43     if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &size_hints, NULL) == 1) {
44         if (size_hints.min_width > 0 && size_hints.min_height > 0
45                 && size_hints.min_width == size_hints.max_width
46                 && size_hints.min_height == size_hints.max_height)
47             *floating = true;
48     }
49
50     xcb_ewmh_get_atoms_reply_t win_state;
51
52     if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
53         for (unsigned int i = 0; i < win_state.atoms_len; i++) {
54             xcb_atom_t a = win_state.atoms[i];
55             if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
56                 *fullscreen = true;
57             }
58         }
59         xcb_ewmh_get_atoms_reply_wipe(&win_state);
60     }
61
62     xcb_window_t transient_for = XCB_NONE;
63     xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
64     *transient = (transient_for == XCB_NONE ? false : true);
65     if (*transient)
66         *floating = true;
67
68     rule_t *rule = rule_head;
69
70     while (rule != NULL) {
71         if (is_match(rule, win)) {
72             rule_effect_t efc = rule->effect;
73             if (efc.floating)
74                 *floating = true;
75             if (efc.monitor != NULL && efc.desktop != NULL) {
76                 *m = efc.monitor;
77                 *d = efc.desktop;
78             }
79         }
80         rule = rule->next;
81     }
82 }