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.follow = false;
17 r->effect.focus = false;
18 r->effect.unmanage = false;
20 r->effect.desc[0] = '\0';
26 void add_rule(rule_t *r)
28 if (rule_head == NULL) {
29 rule_head = rule_tail = r;
37 void remove_rule(rule_t *r)
41 rule_t *prev = r->prev;
42 rule_t *next = r->next;
54 void remove_rule_by_uid(unsigned int uid)
56 remove_rule(find_rule(uid));
59 rule_t *find_rule(unsigned int uid)
61 for (rule_t *r = rule_head; r != NULL; r = r->next)
67 bool is_match(rule_t *r, xcb_window_t win)
69 xcb_icccm_get_wm_class_reply_t reply;
71 if (streq(r->cause.name, MATCH_ALL) ||
72 ((success = xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL)) == 1
73 && (streq(reply.class_name, r->cause.name)
74 || streq(reply.instance_name, r->cause.name)))) {
76 xcb_icccm_get_wm_class_reply_wipe(&reply);
82 void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating, bool *fullscreen, bool *locked, bool *follow, bool *transient, bool *takes_focus, bool *manage)
84 xcb_ewmh_get_atoms_reply_t win_type;
86 if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
87 for (unsigned int i = 0; i < win_type.atoms_len; i++) {
88 xcb_atom_t a = win_type.atoms[i];
89 if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
90 || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
92 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
94 } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DOCK || a == ewmh->_NET_WM_WINDOW_TYPE_DESKTOP || a == ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION) {
96 if (a == ewmh->_NET_WM_WINDOW_TYPE_DESKTOP)
100 xcb_ewmh_get_atoms_reply_wipe(&win_type);
103 xcb_size_hints_t size_hints;
105 if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &size_hints, NULL) == 1) {
106 if (size_hints.min_width > 0 && size_hints.min_height > 0
107 && size_hints.min_width == size_hints.max_width
108 && size_hints.min_height == size_hints.max_height)
112 xcb_ewmh_get_atoms_reply_t win_state;
114 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
115 for (unsigned int i = 0; i < win_state.atoms_len; i++) {
116 xcb_atom_t a = win_state.atoms[i];
117 if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
121 xcb_ewmh_get_atoms_reply_wipe(&win_state);
124 xcb_window_t transient_for = XCB_NONE;
125 xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
126 *transient = (transient_for == XCB_NONE ? false : true);
130 rule_t *rule = rule_head;
132 while (rule != NULL) {
133 if (is_match(rule, win)) {
134 rule_effect_t efc = rule->effect;
147 if (efc.desc[0] != '\0') {
148 coordinates_t ref = {*m, *d, NULL};
150 if (desktop_from_desc(efc.desc, &ref, &loc)) {
156 rule_t *next = rule->next;
163 void list_rules(char *pattern, char *rsp)
167 for (rule_t *r = rule_head; r != NULL; r = r->next) {
168 if (pattern != NULL && !streq(pattern, r->cause.name))
170 snprintf(line, sizeof(line), "%2X %s", r->uid, r->cause.name);
171 strncat(rsp, line, REMLEN(rsp));
172 if (r->effect.floating)
173 strncat(rsp, " --floating", REMLEN(rsp));
174 if (r->effect.fullscreen)
175 strncat(rsp, " --fullscreen", REMLEN(rsp));
176 if (r->effect.locked)
177 strncat(rsp, " --locked", REMLEN(rsp));
178 if (r->effect.follow)
179 strncat(rsp, " --follow", REMLEN(rsp));
181 strncat(rsp, " --focus", REMLEN(rsp));
182 if (r->effect.unmanage)
183 strncat(rsp, " --unmanage", REMLEN(rsp));
185 strncat(rsp, " --one-shot", REMLEN(rsp));
186 if (r->effect.desc[0] != '\0') {
187 snprintf(line, sizeof(line), " -d %s", r->effect.desc);
188 strncat(rsp, line, REMLEN(rsp));
190 strncat(rsp, "\n", REMLEN(rsp));