3 #include <xcb/xcb_icccm.h>
4 #include <xcb/xcb_ewmh.h>
10 void add_rule(rule_t *r)
12 if (rule_head == NULL) {
13 rule_head = rule_tail = r;
21 bool is_match(rule_t *r, xcb_window_t win)
23 xcb_icccm_get_wm_class_reply_t reply;
24 if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1
25 && (strcmp(reply.class_name, r->cause.name) == 0
26 || strcmp(reply.instance_name, r->cause.name) == 0)) {
27 xcb_icccm_get_wm_class_reply_wipe(&reply);
33 void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating, bool *transient, bool *fullscreen, bool *takes_focus, bool *manage)
35 xcb_ewmh_get_atoms_reply_t win_type;
37 if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
38 for (unsigned int i = 0; i < win_type.atoms_len; i++) {
39 xcb_atom_t a = win_type.atoms[i];
40 if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
41 || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
43 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
45 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DOCK || a == ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION) {
49 xcb_ewmh_get_atoms_reply_wipe(&win_type);
52 xcb_size_hints_t size_hints;
54 if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &size_hints, NULL) == 1) {
55 if (size_hints.min_width > 0 && size_hints.min_height > 0
56 && size_hints.min_width == size_hints.max_width
57 && size_hints.min_height == size_hints.max_height)
61 xcb_ewmh_get_atoms_reply_t win_state;
63 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
64 for (unsigned int i = 0; i < win_state.atoms_len; i++) {
65 xcb_atom_t a = win_state.atoms[i];
66 if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
70 xcb_ewmh_get_atoms_reply_wipe(&win_state);
73 xcb_window_t transient_for = XCB_NONE;
74 xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
75 *transient = (transient_for == XCB_NONE ? false : true);
79 rule_t *rule = rule_head;
81 while (rule != NULL) {
82 if (is_match(rule, win)) {
83 rule_effect_t efc = rule->effect;
86 if (efc.monitor != NULL && efc.desktop != NULL) {
95 void list_rules(char *rsp)
99 for (rule_t *r = rule_head; r != NULL; r = r->next) {
100 snprintf(line, sizeof(line), "%02X %s %s %s\n", r->uid, r->cause.name, (r->effect.desktop != NULL ? r->effect.desktop->name : "\b"), (r->effect.floating ? "floating" : "\b"));
101 strncat(rsp, line, REMLEN(rsp));