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 (stacking_list_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;
167 if (parse_direction(desc, &dir)) {
168 dst->node = nearest_neighbor(dst->desktop, ref->node, dir, sel);
169 } else if (parse_cycle_direction(desc, &cyc)) {
170 dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
171 } else if (parse_history_direction(desc, &hdi)) {
172 history_navigate(hdi, dst);
173 } else if (streq("last", desc)) {
174 history_last_node(ref->node, sel, dst);
175 } else if (streq("last_local", desc)) {
176 dst->node = history_get_node(ref->desktop, ref->node);
177 } else if (streq("biggest", desc)) {
178 dst->node = find_biggest(ref->desktop, ref->node, sel);
179 } else if (streq("focused", desc)) {
180 if (node_matches(ref->node, mon->desk->focus, sel)) {
182 dst->desktop = mon->desk;
183 dst->node = mon->desk->focus;
187 if (parse_window_id(desc, &wid))
188 locate_window(wid, dst);
191 return (dst->node != NULL);
194 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
196 desktop_select_t sel;
197 sel.status = DESKTOP_STATUS_ALL;
198 sel.urgency = DESKTOP_URGENCY_ALL;
200 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
203 if (streq("free", tok)) {
204 sel.status = DESKTOP_STATUS_FREE;
205 } else if (streq("occupied", tok)) {
206 sel.status = DESKTOP_STATUS_OCCUPIED;
207 } else if (streq("urgent", tok)) {
208 sel.urgency = DESKTOP_URGENCY_ON;
209 } else if (streq("nonurgent", tok)) {
210 sel.urgency = DESKTOP_URGENCY_OFF;
218 if (parse_cycle_direction(desc, &cyc)) {
219 dst->monitor = ref->monitor;
220 dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
221 } else if (parse_index(desc, &idx)) {
222 desktop_from_index(idx, dst);
223 } else if (streq("last", desc)) {
224 history_last_desktop(ref->desktop, sel, dst);
225 } else if (streq("last_local", desc)) {
226 dst->monitor = ref->monitor;
227 dst->desktop = history_get_desktop(ref->monitor, ref->desktop);
228 } else if (streq("focused", desc)) {
229 if (desktop_matches(mon->desk, sel)) {
231 dst->desktop = mon->desk;
234 locate_desktop(desc, dst);
237 return (dst->desktop != NULL);
240 bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
242 desktop_select_t sel;
243 sel.status = DESKTOP_STATUS_ALL;
244 sel.urgency = DESKTOP_URGENCY_ALL;
246 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
249 if (streq("free", tok)) {
250 sel.status = DESKTOP_STATUS_FREE;
251 } else if (streq("occupied", tok)) {
252 sel.status = DESKTOP_STATUS_OCCUPIED;
261 if (parse_direction(desc, &dir)) {
262 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
263 } else if (parse_cycle_direction(desc, &cyc)) {
264 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
265 } else if (parse_index(desc, &idx)) {
266 monitor_from_index(idx, dst);
267 } else if (streq("last", desc)) {
268 history_last_monitor(ref->monitor, sel, dst);
269 } else if (streq("primary", desc)) {
270 if (pri_mon != NULL && desktop_matches(pri_mon->desk, sel))
271 dst->monitor = pri_mon;
272 } else if (streq("focused", desc)) {
273 if (desktop_matches(mon->desk, sel))
276 locate_monitor(desc, dst);
279 return (dst->monitor != NULL);
282 bool locate_window(xcb_window_t win, coordinates_t *loc)
284 for (monitor_t *m = mon_head; m != NULL; m = m->next)
285 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
286 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
287 if (n->client->window == win) {
296 bool locate_desktop(char *name, coordinates_t *loc)
298 for (monitor_t *m = mon_head; m != NULL; m = m->next)
299 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
300 if (streq(d->name, name)) {
308 bool locate_monitor(char *name, coordinates_t *loc)
310 for (monitor_t *m = mon_head; m != NULL; m = m->next)
311 if (streq(m->name, name)) {
318 bool desktop_from_index(int i, coordinates_t *loc)
320 for (monitor_t *m = mon_head; m != NULL; m = m->next)
321 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
331 bool monitor_from_index(int i, coordinates_t *loc)
333 for (monitor_t *m = mon_head; m != NULL; m = m->next, i--)
344 * Check if the specified node matches the selection criteria.
347 * node_t *c - the active node
348 * node_t *t - the node to test
349 * client_sel_t sel - the selection criteria
351 * Returns true if the node matches.
353 bool node_matches(node_t *c, node_t *t, client_select_t sel)
355 if (sel.type != CLIENT_TYPE_ALL &&
357 ? sel.type == CLIENT_TYPE_FLOATING
358 : sel.type == CLIENT_TYPE_TILED
361 if (sel.class != CLIENT_CLASS_ALL &&
362 streq(c->client->class_name, t->client->class_name)
363 ? sel.class == CLIENT_CLASS_DIFFER
364 : sel.class == CLIENT_CLASS_EQUAL
367 if (sel.mode != CLIENT_MODE_ALL &&
368 t->split_mode == MODE_MANUAL
369 ? sel.mode == CLIENT_MODE_AUTOMATIC
370 : sel.mode == CLIENT_MODE_MANUAL)
373 if (sel.urgency != CLIENT_URGENCY_ALL &&
375 ? sel.urgency == CLIENT_URGENCY_OFF
376 : sel.urgency == CLIENT_URGENCY_ON
382 bool desktop_matches(desktop_t *t, desktop_select_t sel)
384 if (sel.status != DESKTOP_STATUS_ALL &&
386 ? sel.status == DESKTOP_STATUS_OCCUPIED
387 : sel.status == DESKTOP_STATUS_FREE
390 if (sel.urgency != DESKTOP_URGENCY_ALL &&
392 ? sel.urgency == DESKTOP_URGENCY_OFF
393 : sel.urgency == DESKTOP_URGENCY_ON