]> git.lizzy.rs Git - bspwm.git/blob - rules.c
fe8f3e50fa2b018985583015149a8741af3a5afc
[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, 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_ewmh_get_atoms_reply_t win_state;
42
43     if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
44         for (unsigned int i = 0; i < win_state.atoms_len; i++) {
45             xcb_atom_t a = win_state.atoms[i];
46             if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
47                 *fullscreen = true;
48             }
49         }
50         xcb_ewmh_get_atoms_reply_wipe(&win_state);
51     }
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         rule = rule->next;
67     }
68 }