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 void remove_rule(rule_t *r)
25 rule_t *prev = r->prev;
26 rule_t *next = r->next;
38 void remove_rule_by_uid(unsigned int uid)
40 remove_rule(find_rule(uid));
43 rule_t *find_rule(unsigned int uid)
45 for (rule_t *r = rule_head; r != NULL; r = r->next)
51 bool is_match(rule_t *r, xcb_window_t win)
53 xcb_icccm_get_wm_class_reply_t reply;
54 if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1
55 && (strcmp(reply.class_name, r->cause.name) == 0
56 || strcmp(reply.instance_name, r->cause.name) == 0)) {
57 xcb_icccm_get_wm_class_reply_wipe(&reply);
63 void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating, bool *transient, bool *fullscreen, bool *takes_focus, bool *manage)
65 xcb_ewmh_get_atoms_reply_t win_type;
67 if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
68 for (unsigned int i = 0; i < win_type.atoms_len; i++) {
69 xcb_atom_t a = win_type.atoms[i];
70 if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
71 || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
73 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
75 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DOCK || a == ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION) {
79 xcb_ewmh_get_atoms_reply_wipe(&win_type);
82 xcb_size_hints_t size_hints;
84 if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &size_hints, NULL) == 1) {
85 if (size_hints.min_width > 0 && size_hints.min_height > 0
86 && size_hints.min_width == size_hints.max_width
87 && size_hints.min_height == size_hints.max_height)
91 xcb_ewmh_get_atoms_reply_t win_state;
93 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
94 for (unsigned int i = 0; i < win_state.atoms_len; i++) {
95 xcb_atom_t a = win_state.atoms[i];
96 if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
100 xcb_ewmh_get_atoms_reply_wipe(&win_state);
103 xcb_window_t transient_for = XCB_NONE;
104 xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
105 *transient = (transient_for == XCB_NONE ? false : true);
109 rule_t *rule = rule_head;
111 while (rule != NULL) {
112 if (is_match(rule, win)) {
113 rule_effect_t efc = rule->effect;
116 if (efc.monitor != NULL && efc.desktop != NULL) {
125 void list_rules(char *rsp)
129 for (rule_t *r = rule_head; r != NULL; r = r->next) {
130 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"));
131 strncat(rsp, line, REMLEN(rsp));