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 else if (m == last_mon)
28 strncat(rsp, " ~", REMLEN(rsp));
29 strncat(rsp, "\n", REMLEN(rsp));
32 query_desktops(m, dom, loc, (dom == DOMAIN_DESKTOP ? 0 : 1), rsp);
36 void query_desktops(monitor_t *m, domain_t dom, coordinates_t loc, unsigned int depth, char *rsp)
39 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
40 if (loc.desktop != NULL && d != loc.desktop)
42 for (unsigned int i = 0; i < depth; i++)
43 strncat(rsp, " ", REMLEN(rsp));
44 if (dom == DOMAIN_DESKTOP) {
45 snprintf(line, sizeof(line), "%s\n", d->name);
46 strncat(rsp, line, REMLEN(rsp));
49 snprintf(line, sizeof(line), "%s %i %c", d->name, d->window_gap, (d->layout == LAYOUT_TILED ? 'T' : 'M'));
50 strncat(rsp, line, REMLEN(rsp));
52 strncat(rsp, " @", REMLEN(rsp));
53 else if (d == m->last_desk)
54 strncat(rsp, " ~", REMLEN(rsp));
55 strncat(rsp, "\n", REMLEN(rsp));
57 query_tree(d, d->root, rsp, depth + 1);
61 void query_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
68 for (unsigned int i = 0; i < depth; i++)
69 strncat(rsp, " ", REMLEN(rsp));
72 client_t *c = n->client;
73 snprintf(line, sizeof(line), "%c %s %X %u %ux%u%+i%+i %c %c%c%c%c%c%c", (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), c->class_name, c->window, 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' : '-'), (n->split_mode ? 'p' : '-'));
75 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);
78 strncat(rsp, line, REMLEN(rsp));
81 strncat(rsp, " *", REMLEN(rsp));
82 strncat(rsp, "\n", REMLEN(rsp));
84 query_tree(d, n->first_child, rsp, depth + 1);
85 query_tree(d, n->second_child, rsp, depth + 1);
88 void query_history(coordinates_t loc, char *rsp)
91 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
92 if (loc.monitor != NULL && m != loc.monitor)
94 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
95 if (loc.desktop != NULL && d != loc.desktop)
97 snprintf(line, sizeof(line), "%s\n", d->name);
98 strncat(rsp, line, REMLEN(rsp));
99 for (node_list_t *a = d->history->tail; a != NULL; a = a->prev) {
100 snprintf(line, sizeof(line), " %X\n", a->node->client->window);
101 strncat(rsp, line, REMLEN(rsp));
107 void query_windows(coordinates_t loc, char *rsp)
111 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
112 if (loc.monitor != NULL && m != loc.monitor)
114 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
115 if (loc.desktop != NULL && d != loc.desktop)
117 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
118 if (loc.node != NULL && n != loc.node)
120 snprintf(line, sizeof(line), "0x%X\n", n->client->window);
121 strncat(rsp, line, REMLEN(rsp));
127 bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
130 sel.type = CLIENT_TYPE_ALL;
131 sel.class = CLIENT_CLASS_ALL;
132 sel.mode = CLIENT_MODE_ALL;
133 sel.urgency = CLIENT_URGENCY_ALL;
135 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
138 if (streq("tiled", tok)) {
139 sel.type = CLIENT_TYPE_TILED;
140 } else if (streq("floating", tok)) {
141 sel.type = CLIENT_TYPE_FLOATING;
142 } else if (streq("like", tok)) {
143 sel.class = CLIENT_CLASS_EQUAL;
144 } else if (streq("unlike", tok)) {
145 sel.class = CLIENT_CLASS_DIFFER;
146 } else if (streq("automatic", tok)) {
147 sel.mode = CLIENT_MODE_AUTOMATIC;
148 } else if (streq("manual", tok)) {
149 sel.mode = CLIENT_MODE_MANUAL;
150 } else if (streq("urgent", tok)) {
151 sel.urgency = CLIENT_URGENCY_ON;
152 } else if (streq("nonurgent", tok)) {
153 sel.urgency = CLIENT_URGENCY_OFF;
157 dst->monitor = ref->monitor;
158 dst->desktop = ref->desktop;
163 if (parse_direction(desc, &dir)) {
164 dst->node = nearest_neighbor(dst->desktop, ref->node, dir, sel);
165 } else if (parse_cycle_direction(desc, &cyc)) {
166 dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
167 } else if (streq("last", desc)) {
168 dst->node = history_last(ref->desktop->history, ref->node, sel);
169 } else if (streq("biggest", desc)) {
170 dst->node = find_biggest(ref->desktop, ref->node, sel);
171 } else if (streq("focused", desc)) {
172 if (node_matches(ref->node, mon->desk->focus, sel)) {
174 dst->desktop = mon->desk;
175 dst->node = mon->desk->focus;
179 if (parse_window_id(desc, &wid))
180 locate_window(wid, dst);
183 return (dst->node != NULL);
186 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
188 desktop_select_t sel;
189 sel.status = DESKTOP_STATUS_ALL;
190 sel.urgency = DESKTOP_URGENCY_ALL;
192 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
195 if (streq("free", tok)) {
196 sel.status = DESKTOP_STATUS_FREE;
197 } else if (streq("occupied", tok)) {
198 sel.status = DESKTOP_STATUS_OCCUPIED;
199 } else if (streq("urgent", tok)) {
200 sel.urgency = DESKTOP_URGENCY_ON;
201 } else if (streq("nonurgent", tok)) {
202 sel.urgency = DESKTOP_URGENCY_OFF;
210 if (parse_cycle_direction(desc, &cyc)) {
211 dst->monitor = ref->monitor;
212 dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
213 } else if (parse_index(desc, &idx)) {
214 desktop_from_index(idx, dst);
215 } else if (streq("last", desc)) {
216 if (mon->last_desk != NULL && desktop_matches(mon->last_desk, sel)) {
218 dst->desktop = mon->last_desk;
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 if (last_mon != NULL && desktop_matches(last_mon->desk, sel))
261 dst->monitor = last_mon;
262 } else if (streq("primary", desc)) {
263 if (pri_mon != NULL && desktop_matches(pri_mon->desk, sel))
264 dst->monitor = pri_mon;
265 } else if (streq("focused", desc)) {
266 if (desktop_matches(mon->desk, sel))
269 locate_monitor(desc, dst);
272 return (dst->monitor != NULL);
275 bool locate_window(xcb_window_t win, coordinates_t *loc)
277 for (monitor_t *m = mon_head; m != NULL; m = m->next)
278 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
279 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
280 if (n->client->window == win) {
289 bool locate_desktop(char *name, coordinates_t *loc)
291 for (monitor_t *m = mon_head; m != NULL; m = m->next)
292 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
293 if (streq(d->name, name)) {
301 bool locate_monitor(char *name, coordinates_t *loc)
303 for (monitor_t *m = mon_head; m != NULL; m = m->next)
304 if (streq(m->name, name)) {
311 bool desktop_from_index(int i, coordinates_t *loc)
313 for (monitor_t *m = mon_head; m != NULL; m = m->next)
314 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
324 bool monitor_from_index(int i, coordinates_t *loc)
326 for (monitor_t *m = mon_head; m != NULL; m = m->next, i--)
337 * Check if the specified node matches the selection criteria.
340 * node_t *c - the active node
341 * node_t *t - the node to test
342 * client_sel_t sel - the selection criteria
344 * Returns true if the node matches.
346 bool node_matches(node_t *c, node_t *t, client_select_t sel)
348 if (sel.type != CLIENT_TYPE_ALL &&
350 ? sel.type == CLIENT_TYPE_FLOATING
351 : sel.type == CLIENT_TYPE_TILED
354 if (sel.class != CLIENT_CLASS_ALL &&
355 streq(c->client->class_name, t->client->class_name)
356 ? sel.class == CLIENT_CLASS_DIFFER
357 : sel.class == CLIENT_CLASS_EQUAL
360 if (sel.mode != CLIENT_MODE_ALL &&
361 t->split_mode == MODE_MANUAL
362 ? sel.mode == CLIENT_MODE_AUTOMATIC
363 : sel.mode == CLIENT_MODE_MANUAL)
366 if (sel.urgency != CLIENT_URGENCY_ALL &&
368 ? sel.urgency == CLIENT_URGENCY_OFF
369 : sel.urgency == CLIENT_URGENCY_ON
375 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