9 rule_t *make_rule(void)
11 rule_t *r = malloc(sizeof(rule_t));
13 r->effect.floating = false;
14 r->effect.fullscreen = false;
15 r->effect.locked = false;
16 r->effect.sticky = false;
17 r->effect.follow = false;
18 r->effect.focus = false;
19 r->effect.unmanage = false;
21 r->effect.desc[0] = '\0';
27 void add_rule(rule_t *r)
29 if (rule_head == NULL) {
30 rule_head = rule_tail = r;
38 void remove_rule(rule_t *r)
42 rule_t *prev = r->prev;
43 rule_t *next = r->next;
55 void remove_rule_by_uid(unsigned int uid)
57 remove_rule(find_rule(uid));
60 rule_t *find_rule(unsigned int uid)
62 for (rule_t *r = rule_head; r != NULL; r = r->next)
68 bool is_match(rule_t *r, xcb_window_t win)
70 xcb_icccm_get_wm_class_reply_t reply;
72 if (streq(r->cause.name, MATCH_ALL) ||
73 ((success = xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL)) == 1
74 && (streq(reply.class_name, r->cause.name)
75 || streq(reply.instance_name, r->cause.name)))) {
77 xcb_icccm_get_wm_class_reply_wipe(&reply);
83 void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating, bool *fullscreen, bool *locked, bool *sticky, bool *follow, bool *transient, bool *takes_focus, bool *manage)
85 xcb_ewmh_get_atoms_reply_t win_type;
87 if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
88 for (unsigned int i = 0; i < win_type.atoms_len; i++) {
89 xcb_atom_t a = win_type.atoms[i];
90 if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
91 || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
93 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
95 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DOCK || a == ewmh->_NET_WM_WINDOW_TYPE_DESKTOP || a == ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION) {
97 if (a == ewmh->_NET_WM_WINDOW_TYPE_DESKTOP)
101 xcb_ewmh_get_atoms_reply_wipe(&win_type);
104 xcb_size_hints_t size_hints;
106 if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &size_hints, NULL) == 1) {
107 if (size_hints.min_width > 0 && size_hints.min_height > 0
108 && size_hints.min_width == size_hints.max_width
109 && size_hints.min_height == size_hints.max_height)
113 xcb_ewmh_get_atoms_reply_t win_state;
115 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
116 for (unsigned int i = 0; i < win_state.atoms_len; i++) {
117 xcb_atom_t a = win_state.atoms[i];
118 if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
122 xcb_ewmh_get_atoms_reply_wipe(&win_state);
125 xcb_window_t transient_for = XCB_NONE;
126 xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
127 *transient = (transient_for == XCB_NONE ? false : true);
131 rule_t *rule = rule_head;
133 while (rule != NULL) {
134 if (is_match(rule, win)) {
135 rule_effect_t efc = rule->effect;
150 if (efc.desc[0] != '\0') {
151 coordinates_t ref = {*m, *d, NULL};
153 if (desktop_from_desc(efc.desc, &ref, &loc)) {
159 rule_t *next = rule->next;
171 void list_rules(char *pattern, char *rsp)
175 for (rule_t *r = rule_head; r != NULL; r = r->next) {
176 if (pattern != NULL && !streq(pattern, r->cause.name))
178 snprintf(line, sizeof(line), "%2X %s", r->uid, r->cause.name);
179 strncat(rsp, line, REMLEN(rsp));
180 if (r->effect.floating)
181 strncat(rsp, " --floating", REMLEN(rsp));
182 if (r->effect.fullscreen)
183 strncat(rsp, " --fullscreen", REMLEN(rsp));
184 if (r->effect.locked)
185 strncat(rsp, " --locked", REMLEN(rsp));
186 if (r->effect.sticky)
187 strncat(rsp, " --sticky", REMLEN(rsp));
188 if (r->effect.follow)
189 strncat(rsp, " --follow", REMLEN(rsp));
191 strncat(rsp, " --focus", REMLEN(rsp));
192 if (r->effect.unmanage)
193 strncat(rsp, " --unmanage", REMLEN(rsp));
195 strncat(rsp, " --one-shot", REMLEN(rsp));
196 if (r->effect.desc[0] != '\0') {
197 snprintf(line, sizeof(line), " -d %s", r->effect.desc);
198 strncat(rsp, line, REMLEN(rsp));
200 strncat(rsp, "\n", REMLEN(rsp));