11 void query_monitors(coordinates_t loc, domain_t dom, char *rsp)
14 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
15 if (loc.monitor != NULL && m != loc.monitor)
17 if (dom != DOMAIN_DESKTOP) {
18 if (dom == DOMAIN_MONITOR) {
19 snprintf(line, sizeof(line), "%s\n", m->name);
20 strncat(rsp, line, REMLEN(rsp));
23 snprintf(line, sizeof(line), "%s %ux%u%+i%+i %i,%i,%i,%i", m->name, m->rectangle.width, m->rectangle.height, m->rectangle.x, m->rectangle.y, m->top_padding, m->right_padding, m->bottom_padding, m->left_padding);
24 strncat(rsp, line, REMLEN(rsp));
26 strncat(rsp, " *", REMLEN(rsp));
27 strncat(rsp, "\n", REMLEN(rsp));
30 query_desktops(m, dom, loc, (dom == DOMAIN_DESKTOP ? 0 : 1), rsp);
34 void query_desktops(monitor_t *m, domain_t dom, coordinates_t loc, unsigned int depth, char *rsp)
37 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
38 if (loc.desktop != NULL && d != loc.desktop)
40 for (unsigned int i = 0; i < depth; i++)
41 strncat(rsp, " ", REMLEN(rsp));
42 if (dom == DOMAIN_DESKTOP) {
43 snprintf(line, sizeof(line), "%s\n", d->name);
44 strncat(rsp, line, REMLEN(rsp));
47 snprintf(line, sizeof(line), "%s %u %i %u %c", d->name, d->border_width, d->window_gap, d->tags_field, (d->layout == LAYOUT_TILED ? 'T' : 'M'));
48 strncat(rsp, line, REMLEN(rsp));
50 strncat(rsp, " *", REMLEN(rsp));
51 strncat(rsp, "\n", REMLEN(rsp));
53 query_tree(d, d->root, rsp, depth + 1);
57 void query_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
64 for (unsigned int i = 0; i < depth; i++)
65 strncat(rsp, " ", REMLEN(rsp));
68 client_t *c = n->client;
69 snprintf(line, sizeof(line), "%c %s 0x%X %u %u %ux%u%+i%+i %c %c%c%c%c%c%c%c", (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), c->class_name, c->window, c->tags_field, c->border_width, c->floating_rectangle.width, c->floating_rectangle.height, c->floating_rectangle.x, c->floating_rectangle.y, (n->split_dir == DIR_UP ? 'U' : (n->split_dir == DIR_RIGHT ? 'R' : (n->split_dir == DIR_DOWN ? 'D' : 'L'))), (c->floating ? 'f' : '-'), (c->transient ? 't' : '-'), (c->fullscreen ? 'F' : '-'), (c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'), (c->sticky ? 's' : '-'), (n->split_mode ? 'p' : '-'));
71 snprintf(line, sizeof(line), "%c %c %.2f", (n->split_type == TYPE_HORIZONTAL ? 'H' : 'V'), (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), n->split_ratio);
74 strncat(rsp, line, REMLEN(rsp));
77 strncat(rsp, " *", REMLEN(rsp));
78 strncat(rsp, "\n", REMLEN(rsp));
80 query_tree(d, n->first_child, rsp, depth + 1);
81 query_tree(d, n->second_child, rsp, depth + 1);
84 void query_history(coordinates_t loc, char *rsp)
87 for (history_t *h = history_head; h != NULL; h = h->next) {
88 if ((loc.monitor != NULL && h->loc.monitor != loc.monitor)
89 || (loc.desktop != NULL && h->loc.desktop != loc.desktop))
91 xcb_window_t win = XCB_NONE;
92 if (h->loc.node != NULL)
93 win = h->loc.node->client->window;
94 snprintf(line, sizeof(line), "%s %s 0x%X", h->loc.monitor->name, h->loc.desktop->name, win);
95 strncat(rsp, line, REMLEN(rsp));
96 strncat(rsp, "\n", REMLEN(rsp));
100 void query_stack(char *rsp)
103 for (stack_t *s = stack_head; s != NULL; s = s->next) {
104 snprintf(line, sizeof(line), "0x%X", s->node->client->window);
105 strncat(rsp, line, REMLEN(rsp));
106 strncat(rsp, "\n", REMLEN(rsp));
110 void query_windows(coordinates_t loc, char *rsp)
114 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
115 if (loc.monitor != NULL && m != loc.monitor)
117 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
118 if (loc.desktop != NULL && d != loc.desktop)
120 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
121 if (loc.node != NULL && n != loc.node)
123 snprintf(line, sizeof(line), "0x%X\n", n->client->window);
124 strncat(rsp, line, REMLEN(rsp));
130 bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
133 sel.type = CLIENT_TYPE_ALL;
134 sel.class = CLIENT_CLASS_ALL;
135 sel.mode = CLIENT_MODE_ALL;
136 sel.urgency = CLIENT_URGENCY_ALL;
138 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
141 if (streq("tiled", tok)) {
142 sel.type = CLIENT_TYPE_TILED;
143 } else if (streq("floating", tok)) {
144 sel.type = CLIENT_TYPE_FLOATING;
145 } else if (streq("like", tok)) {
146 sel.class = CLIENT_CLASS_EQUAL;
147 } else if (streq("unlike", tok)) {
148 sel.class = CLIENT_CLASS_DIFFER;
149 } else if (streq("automatic", tok)) {
150 sel.mode = CLIENT_MODE_AUTOMATIC;
151 } else if (streq("manual", tok)) {
152 sel.mode = CLIENT_MODE_MANUAL;
153 } else if (streq("urgent", tok)) {
154 sel.urgency = CLIENT_URGENCY_ON;
155 } else if (streq("nonurgent", tok)) {
156 sel.urgency = CLIENT_URGENCY_OFF;
160 dst->monitor = ref->monitor;
161 dst->desktop = ref->desktop;
166 if (parse_direction(desc, &dir)) {
167 dst->node = nearest_neighbor(dst->desktop, ref->node, dir, sel);
168 } else if (parse_cycle_direction(desc, &cyc)) {
169 dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
170 } else if (streq("last", desc)) {
171 history_last_node(ref->node, sel, dst);
172 } else if (streq("biggest", desc)) {
173 dst->node = find_biggest(ref->desktop, ref->node, sel);
174 } else if (streq("focused", desc)) {
175 if (node_matches(ref->node, mon->desk->focus, sel)) {
177 dst->desktop = mon->desk;
178 dst->node = mon->desk->focus;
182 if (parse_window_id(desc, &wid))
183 locate_window(wid, dst);
186 return (dst->node != NULL);
189 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
191 desktop_select_t sel;
192 sel.status = DESKTOP_STATUS_ALL;
193 sel.urgency = DESKTOP_URGENCY_ALL;
195 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
198 if (streq("free", tok)) {
199 sel.status = DESKTOP_STATUS_FREE;
200 } else if (streq("occupied", tok)) {
201 sel.status = DESKTOP_STATUS_OCCUPIED;
202 } else if (streq("urgent", tok)) {
203 sel.urgency = DESKTOP_URGENCY_ON;
204 } else if (streq("nonurgent", tok)) {
205 sel.urgency = DESKTOP_URGENCY_OFF;
213 if (parse_cycle_direction(desc, &cyc)) {
214 dst->monitor = ref->monitor;
215 dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
216 } else if (parse_index(desc, &idx)) {
217 desktop_from_index(idx, dst);
218 } else if (streq("last", desc)) {
219 history_last_desktop(ref->desktop, sel, dst);
220 } else if (streq("focused", desc)) {
221 if (desktop_matches(mon->desk, sel)) {
223 dst->desktop = mon->desk;
226 locate_desktop(desc, dst);
229 return (dst->desktop != NULL);
232 bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
234 desktop_select_t sel;
235 sel.status = DESKTOP_STATUS_ALL;
236 sel.urgency = DESKTOP_URGENCY_ALL;
238 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
241 if (streq("free", tok)) {
242 sel.status = DESKTOP_STATUS_FREE;
243 } else if (streq("occupied", tok)) {
244 sel.status = DESKTOP_STATUS_OCCUPIED;
253 if (parse_direction(desc, &dir)) {
254 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
255 } else if (parse_cycle_direction(desc, &cyc)) {
256 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
257 } else if (parse_index(desc, &idx)) {
258 monitor_from_index(idx, dst);
259 } else if (streq("last", desc)) {
260 history_last_monitor(ref->monitor, sel, dst);
261 } else if (streq("primary", desc)) {
262 if (pri_mon != NULL && desktop_matches(pri_mon->desk, sel))
263 dst->monitor = pri_mon;
264 } else if (streq("focused", desc)) {
265 if (desktop_matches(mon->desk, sel))
268 locate_monitor(desc, dst);
271 return (dst->monitor != NULL);
274 bool locate_window(xcb_window_t win, coordinates_t *loc)
276 for (monitor_t *m = mon_head; m != NULL; m = m->next)
277 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
278 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
279 if (n->client->window == win) {
288 bool locate_desktop(char *name, coordinates_t *loc)
290 for (monitor_t *m = mon_head; m != NULL; m = m->next)
291 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
292 if (streq(d->name, name)) {
300 bool locate_monitor(char *name, coordinates_t *loc)
302 for (monitor_t *m = mon_head; m != NULL; m = m->next)
303 if (streq(m->name, name)) {
310 bool desktop_from_index(int i, coordinates_t *loc)
312 for (monitor_t *m = mon_head; m != NULL; m = m->next)
313 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
323 bool monitor_from_index(int i, coordinates_t *loc)
325 for (monitor_t *m = mon_head; m != NULL; m = m->next, i--)
336 * Check if the specified node matches the selection criteria.
339 * node_t *c - the active node
340 * node_t *t - the node to test
341 * client_sel_t sel - the selection criteria
343 * Returns true if the node matches.
345 bool node_matches(node_t *c, node_t *t, client_select_t sel)
347 if (sel.type != CLIENT_TYPE_ALL &&
349 ? sel.type == CLIENT_TYPE_FLOATING
350 : sel.type == CLIENT_TYPE_TILED
353 if (sel.class != CLIENT_CLASS_ALL &&
354 streq(c->client->class_name, t->client->class_name)
355 ? sel.class == CLIENT_CLASS_DIFFER
356 : sel.class == CLIENT_CLASS_EQUAL
359 if (sel.mode != CLIENT_MODE_ALL &&
360 t->split_mode == MODE_MANUAL
361 ? sel.mode == CLIENT_MODE_AUTOMATIC
362 : sel.mode == CLIENT_MODE_MANUAL)
365 if (sel.urgency != CLIENT_URGENCY_ALL &&
367 ? sel.urgency == CLIENT_URGENCY_OFF
368 : sel.urgency == CLIENT_URGENCY_ON
374 bool desktop_matches(desktop_t *t, desktop_select_t sel)
376 if (sel.status != DESKTOP_STATUS_ALL &&
378 ? sel.status == DESKTOP_STATUS_OCCUPIED
379 : sel.status == DESKTOP_STATUS_FREE
382 if (sel.urgency != DESKTOP_URGENCY_ALL &&
384 ? sel.urgency == DESKTOP_URGENCY_OFF
385 : sel.urgency == DESKTOP_URGENCY_ON