10 void query_monitors(coordinates_t loc, domain_t dom, char *rsp)
13 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
14 if (loc.monitor != NULL && m != loc.monitor)
16 if (dom != DOMAIN_DESKTOP) {
17 if (dom == DOMAIN_MONITOR) {
18 snprintf(line, sizeof(line), "%s\n", m->name);
19 strncat(rsp, line, REMLEN(rsp));
22 snprintf(line, sizeof(line), "%s %ux%u%+i%+i", m->name, m->rectangle.width, m->rectangle.height, m->rectangle.x, m->rectangle.y);
23 strncat(rsp, line, REMLEN(rsp));
25 strncat(rsp, " #", REMLEN(rsp));
26 else if (m == last_mon)
27 strncat(rsp, " ~", REMLEN(rsp));
28 strncat(rsp, "\n", REMLEN(rsp));
31 query_desktops(m, dom, loc, (dom == DOMAIN_DESKTOP ? 0 : 1), rsp);
35 void query_desktops(monitor_t *m, domain_t dom, coordinates_t loc, unsigned int depth, char *rsp)
38 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
39 if (loc.desktop != NULL && d != loc.desktop)
41 for (unsigned int i = 0; i < depth; i++)
42 strncat(rsp, " ", REMLEN(rsp));
43 if (dom == DOMAIN_DESKTOP) {
44 snprintf(line, sizeof(line), "%s\n", d->name);
45 strncat(rsp, line, REMLEN(rsp));
48 snprintf(line, sizeof(line), "%s %c", d->name, (d->layout == LAYOUT_TILED ? 'T' : 'M'));
49 strncat(rsp, line, REMLEN(rsp));
51 strncat(rsp, " @", REMLEN(rsp));
52 else if (d == m->last_desk)
53 strncat(rsp, " ~", REMLEN(rsp));
54 strncat(rsp, "\n", REMLEN(rsp));
56 query_tree(d, d->root, rsp, depth + 1);
60 void query_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
67 for (unsigned int i = 0; i < depth; i++)
68 strncat(rsp, " ", REMLEN(rsp));
71 client_t *c = n->client;
72 snprintf(line, sizeof(line), "%c %s %X %u %ux%u%+i%+i %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, (c->floating ? 'f' : '-'), (c->transient ? 't' : '-'), (c->fullscreen ? 'F' : '-'), (c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'));
74 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);
77 strncat(rsp, line, REMLEN(rsp));
80 strncat(rsp, " *", REMLEN(rsp));
81 strncat(rsp, "\n", REMLEN(rsp));
83 query_tree(d, n->first_child, rsp, depth + 1);
84 query_tree(d, n->second_child, rsp, depth + 1);
87 void query_history(coordinates_t loc, char *rsp)
90 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
91 if (loc.monitor != NULL && m != loc.monitor)
93 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
94 if (loc.desktop != NULL && d != loc.desktop)
96 snprintf(line, sizeof(line), "%s\n", d->name);
97 strncat(rsp, line, REMLEN(rsp));
98 for (node_list_t *a = d->history->tail; a != NULL; a = a->prev) {
99 snprintf(line, sizeof(line), " %X\n", a->node->client->window);
100 strncat(rsp, line, REMLEN(rsp));
106 void query_windows(coordinates_t loc, char *rsp)
110 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
111 if (loc.monitor != NULL && m != loc.monitor)
113 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
114 if (loc.desktop != NULL && d != loc.desktop)
116 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
117 if (loc.node != NULL && n != loc.node)
119 snprintf(line, sizeof(line), "0x%X\n", n->client->window);
120 strncat(rsp, line, REMLEN(rsp));
126 bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
129 sel.type = CLIENT_TYPE_ALL;
130 sel.class = CLIENT_CLASS_ALL;
132 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
135 if (streq("tiled", tok)) {
136 sel.type = CLIENT_TYPE_TILED;
137 } else if (streq("floating", tok)) {
138 sel.type = CLIENT_TYPE_FLOATING;
139 } else if (streq("like", tok)) {
140 sel.class = CLIENT_CLASS_EQUAL;
141 } else if (streq("unlike", tok)) {
142 sel.class = CLIENT_CLASS_DIFFER;
146 dst->monitor = ref->monitor;
147 dst->desktop = ref->desktop;
152 if (parse_direction(desc, &dir)) {
153 dst->node = nearest_neighbor(dst->desktop, ref->node, dir);
154 if (dst->node == NULL && monitor_focus_fallback) {
155 if (monitor_from_desc(desc, ref, dst)) {
156 dst->desktop = dst->monitor->desk;
157 dst->node = dst->monitor->desk->focus;
161 } else if (parse_cycle_direction(desc, &cyc)) {
162 dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
163 } else if (streq("last", desc)) {
164 dst->node = history_get(ref->desktop->history, 1);
165 } else if (streq("biggest", desc)) {
166 dst->node = find_biggest(ref->desktop);
167 } else if (streq("focused", desc)) {
169 dst->desktop = mon->desk;
170 dst->node = mon->desk->focus;
173 if (parse_window_id(desc, &wid))
174 locate_window(wid, dst);
177 return (dst->node != NULL);
180 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
182 desktop_select_t sel;
185 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
188 if (streq("free", tok)) {
190 } else if (streq("occupied", tok)) {
191 sel = DESKTOP_OCCUPIED;
198 if (parse_cycle_direction(desc, &cyc)) {
199 dst->monitor = ref->monitor;
200 dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
201 } else if (streq("last", desc)) {
203 dst->desktop = mon->last_desk;
204 } else if (streq("focused", desc)) {
206 dst->desktop = mon->desk;
208 locate_desktop(desc, dst);
211 return (dst->desktop != NULL);
214 bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
216 desktop_select_t sel;
219 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
222 if (streq("free", tok)) {
224 } else if (streq("occupied", tok)) {
225 sel = DESKTOP_OCCUPIED;
233 if (parse_direction(desc, &dir)) {
234 dst->monitor = nearest_monitor(ref->monitor, dir);
235 } else if (parse_cycle_direction(desc, &cyc)) {
236 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
237 } else if (streq("last", desc)) {
238 dst->monitor = last_mon;
239 } else if (streq("focused", desc)) {
242 locate_monitor(desc, dst);
245 return (dst->monitor != NULL);
248 bool locate_window(xcb_window_t win, coordinates_t *loc)
250 for (monitor_t *m = mon_head; m != NULL; m = m->next)
251 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
252 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
253 if (n->client->window == win) {
262 bool locate_desktop(char *name, coordinates_t *loc)
264 for (monitor_t *m = mon_head; m != NULL; m = m->next)
265 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
266 if (streq(d->name, name)) {
274 bool locate_monitor(char *name, coordinates_t *loc)
276 for (monitor_t *m = mon_head; m != NULL; m = m->next)
277 if (streq(m->name, name)) {