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 %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);
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 %i %c", d->name, d->window_gap, (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%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' : '-'));
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;
131 sel.mode = CLIENT_MODE_ALL;
132 sel.urgency = CLIENT_URGENCY_ALL;
134 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
137 if (streq("tiled", tok)) {
138 sel.type = CLIENT_TYPE_TILED;
139 } else if (streq("floating", tok)) {
140 sel.type = CLIENT_TYPE_FLOATING;
141 } else if (streq("like", tok)) {
142 sel.class = CLIENT_CLASS_EQUAL;
143 } else if (streq("unlike", tok)) {
144 sel.class = CLIENT_CLASS_DIFFER;
145 } else if (streq("automatic", tok)) {
146 sel.mode = CLIENT_MODE_AUTOMATIC;
147 } else if (streq("manual", tok)) {
148 sel.mode = CLIENT_MODE_MANUAL;
149 } else if (streq("urgent", tok)) {
150 sel.urgency = CLIENT_URGENCY_ON;
151 } else if (streq("nonurgent", tok)) {
152 sel.urgency = CLIENT_URGENCY_OFF;
156 dst->monitor = ref->monitor;
157 dst->desktop = ref->desktop;
162 if (parse_direction(desc, &dir)) {
163 dst->node = nearest_neighbor(dst->desktop, ref->node, dir, sel);
164 } else if (parse_cycle_direction(desc, &cyc)) {
165 dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
166 } else if (streq("last", desc)) {
167 dst->node = history_last(ref->desktop->history, ref->node, sel);
168 } else if (streq("biggest", desc)) {
169 dst->node = find_biggest(ref->desktop, ref->node, sel);
170 } else if (streq("focused", desc)) {
171 if (node_matches(ref->node, mon->desk->focus, sel)) {
173 dst->desktop = mon->desk;
174 dst->node = mon->desk->focus;
178 if (parse_window_id(desc, &wid))
179 locate_window(wid, dst);
182 return (dst->node != NULL);
185 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
187 desktop_select_t sel;
188 sel.status = DESKTOP_STATUS_ALL;
189 sel.urgency = DESKTOP_URGENCY_ALL;
191 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
194 if (streq("free", tok)) {
195 sel.status = DESKTOP_STATUS_FREE;
196 } else if (streq("occupied", tok)) {
197 sel.status = DESKTOP_STATUS_OCCUPIED;
198 } else if (streq("urgent", tok)) {
199 sel.urgency = DESKTOP_URGENCY_ON;
200 } else if (streq("nonurgent", tok)) {
201 sel.urgency = DESKTOP_URGENCY_OFF;
209 if (parse_cycle_direction(desc, &cyc)) {
210 dst->monitor = ref->monitor;
211 dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
212 } else if (parse_index(desc, &idx)) {
213 desktop_from_index(idx, dst);
214 } else if (streq("last", desc)) {
215 if (mon->last_desk != NULL && desktop_matches(mon->last_desk, sel)) {
217 dst->desktop = mon->last_desk;
219 } else if (streq("focused", desc)) {
220 if (desktop_matches(mon->desk, sel)) {
222 dst->desktop = mon->desk;
225 locate_desktop(desc, dst);
228 return (dst->desktop != NULL);
231 bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
233 desktop_select_t sel;
234 sel.status = DESKTOP_STATUS_ALL;
235 sel.urgency = DESKTOP_URGENCY_ALL;
237 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
240 if (streq("free", tok)) {
241 sel.status = DESKTOP_STATUS_FREE;
242 } else if (streq("occupied", tok)) {
243 sel.status = DESKTOP_STATUS_OCCUPIED;
252 if (parse_direction(desc, &dir)) {
253 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
254 } else if (parse_cycle_direction(desc, &cyc)) {
255 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
256 } else if (parse_index(desc, &idx)) {
257 monitor_from_index(idx, dst);
258 } else if (streq("last", desc)) {
259 if (last_mon != NULL && desktop_matches(last_mon->desk, sel))
260 dst->monitor = last_mon;
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--)