1 /* Copyright (c) 2012, Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 void query_state(FILE *rsp)
41 fprintf(rsp, "\"focusedMonitorId\":%u,", mon->id);
42 if (pri_mon != NULL) {
43 fprintf(rsp, "\"primaryMonitorId\":%u,", pri_mon->id);
45 fprintf(rsp, "\"clientsCount\":%i,", clients_count);
46 fprintf(rsp, "\"monitors\":");
48 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
49 query_monitor(m, rsp);
50 if (m->next != NULL) {
56 fprintf(rsp, "\"focusHistory\":");
59 fprintf(rsp, "\"stackingList\":");
63 fprintf(rsp, "\"eventSubscribers\":");
64 query_subscribers(rsp);
69 void query_monitor(monitor_t *m, FILE *rsp)
72 fprintf(rsp, "\"name\":\"%s\",", m->name);
73 fprintf(rsp, "\"id\":%u,", m->id);
74 fprintf(rsp, "\"randrId\":%u,", m->randr_id);
75 fprintf(rsp, "\"wired\":%s,", BOOL_STR(m->wired));
76 fprintf(rsp, "\"stickyCount\":%i,", m->sticky_count);
77 fprintf(rsp, "\"windowGap\":%i,", m->window_gap);
78 fprintf(rsp, "\"borderWidth\":%u,", m->border_width);
79 fprintf(rsp, "\"focusedDesktopId\":%u,", m->desk->id);
80 fprintf(rsp, "\"padding\":");
81 query_padding(m->padding, rsp);
83 fprintf(rsp, "\"rectangle\":");
84 query_rectangle(m->rectangle, rsp);
86 fprintf(rsp, "\"desktops\":");
88 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
89 query_desktop(d, rsp);
90 if (d->next != NULL) {
98 void query_desktop(desktop_t *d, FILE *rsp)
101 fprintf(rsp, "\"name\":\"%s\",", d->name);
102 fprintf(rsp, "\"id\":%u,", d->id);
103 fprintf(rsp, "\"layout\":\"%s\",", LAYOUT_STR(d->layout));
104 fprintf(rsp, "\"windowGap\":%i,", d->window_gap);
105 fprintf(rsp, "\"borderWidth\":%u,", d->border_width);
106 fprintf(rsp, "\"focusedNodeId\":%u,", d->focus != NULL ? d->focus->id : 0);
107 fprintf(rsp, "\"padding\":");
108 query_padding(d->padding, rsp);
110 fprintf(rsp, "\"root\":");
111 query_node(d->root, rsp);
115 void query_node(node_t *n, FILE *rsp)
118 fprintf(rsp, "null");
121 fprintf(rsp, "\"id\":%u,", n->id);
122 fprintf(rsp, "\"splitType\":\"%s\",", SPLIT_TYPE_STR(n->split_type));
123 fprintf(rsp, "\"splitRatio\":%lf,", n->split_ratio);
124 fprintf(rsp, "\"vacant\":%s,", BOOL_STR(n->vacant));
125 fprintf(rsp, "\"hidden\":%s,", BOOL_STR(n->hidden));
126 fprintf(rsp, "\"sticky\":%s,", BOOL_STR(n->sticky));
127 fprintf(rsp, "\"private\":%s,", BOOL_STR(n->private));
128 fprintf(rsp, "\"locked\":%s,", BOOL_STR(n->locked));
129 fprintf(rsp, "\"marked\":%s,", BOOL_STR(n->marked));
130 fprintf(rsp, "\"presel\":");
131 query_presel(n->presel, rsp);
133 fprintf(rsp, "\"rectangle\":");
134 query_rectangle(n->rectangle, rsp);
136 fprintf(rsp, "\"constraints\":");
137 query_constraints(n->constraints, rsp);
139 fprintf(rsp, "\"firstChild\":");
140 query_node(n->first_child, rsp);
142 fprintf(rsp, "\"secondChild\":");
143 query_node(n->second_child, rsp);
145 fprintf(rsp, "\"client\":");
146 query_client(n->client, rsp);
151 void query_presel(presel_t *p, FILE *rsp)
154 fprintf(rsp, "null");
156 fprintf(rsp, "{\"splitDir\":\"%s\",\"splitRatio\":%lf}", SPLIT_DIR_STR(p->split_dir), p->split_ratio);
160 void query_client(client_t *c, FILE *rsp)
163 fprintf(rsp, "null");
166 fprintf(rsp, "\"className\":\"%s\",", c->class_name);
167 fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
168 fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
169 fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
170 fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
171 fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
172 fprintf(rsp, "\"lastLayer\":\"%s\",", LAYER_STR(c->last_layer));
173 fprintf(rsp, "\"urgent\":%s,", BOOL_STR(c->urgent));
174 fprintf(rsp, "\"shown\":%s,", BOOL_STR(c->shown));
175 fprintf(rsp, "\"tiledRectangle\":");
176 query_rectangle(c->tiled_rectangle, rsp);
178 fprintf(rsp, "\"floatingRectangle\":");
179 query_rectangle(c->floating_rectangle, rsp);
184 void query_rectangle(xcb_rectangle_t r, FILE *rsp)
186 fprintf(rsp, "{\"x\":%i,\"y\":%i,\"width\":%u,\"height\":%u}", r.x, r.y, r.width, r.height);
189 void query_constraints(constraints_t c, FILE *rsp)
191 fprintf(rsp, "{\"min_width\":%u,\"min_height\":%u}", c.min_width, c.min_height);
194 void query_padding(padding_t p, FILE *rsp)
196 fprintf(rsp, "{\"top\":%i,\"right\":%i,\"bottom\":%i,\"left\":%i}", p.top, p.right, p.bottom, p.left);
199 void query_history(FILE *rsp)
202 for (history_t *h = history_head; h != NULL; h = h->next) {
203 query_coordinates(&h->loc, rsp);
204 if (h->next != NULL) {
211 void query_coordinates(coordinates_t *loc, FILE *rsp)
213 fprintf(rsp, "{\"monitorId\":%u,\"desktopId\":%u,\"nodeId\":%u}", loc->monitor->id, loc->desktop->id, loc->node!=NULL?loc->node->id:0);
216 void query_stack(FILE *rsp)
219 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
220 fprintf(rsp, "%u", s->node->id);
221 if (s->next != NULL) {
228 void query_subscribers(FILE *rsp)
231 for (subscriber_list_t *s = subscribe_head; s != NULL; s = s->next) {
232 fprintf(rsp, "{\"fileDescriptor\": %i", fileno(s->stream));
233 if (s->fifo_path != NULL) {
234 fprintf(rsp, ",\"fifoPath\":\"%s\"", s->fifo_path);
236 fprintf(rsp, ",\"field\":%i,\"count\":%i}", s->field, s->count);
237 if (s->next != NULL) {
244 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
247 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
248 if (trg->monitor != NULL && m != trg->monitor) {
251 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
252 if (trg->desktop != NULL && d != trg->desktop) {
255 count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
261 int query_node_ids_in(node_t *n, desktop_t *d, monitor_t *m, coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
267 coordinates_t loc = {m, d, n};
268 if ((trg->node == NULL || n == trg->node) &&
269 (sel == NULL || node_matches(&loc, ref, sel))) {
270 fprintf(rsp, "0x%08X\n", n->id);
273 count += query_node_ids_in(n->first_child, d, m, ref, trg, sel, rsp);
274 count += query_node_ids_in(n->second_child, d, m, ref, trg, sel, rsp);
279 int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
282 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
283 if (trg->monitor != NULL && m != trg->monitor) {
286 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
287 coordinates_t loc = {m, d, NULL};
288 if ((trg->desktop != NULL && d != trg->desktop) ||
289 (sel != NULL && !desktop_matches(&loc, ref, sel))) {
299 int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
302 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
303 coordinates_t loc = {m, NULL, NULL};
304 if ((trg->monitor != NULL && m != trg->monitor) ||
305 (sel != NULL && !monitor_matches(&loc, ref, sel))) {
314 void fprint_monitor_id(monitor_t *m, FILE *rsp)
316 fprintf(rsp, "0x%08X\n", m->id);
319 void fprint_monitor_name(monitor_t *m, FILE *rsp)
321 fprintf(rsp, "%s\n", m->name);
324 void fprint_desktop_id(desktop_t *d, FILE *rsp)
326 fprintf(rsp, "0x%08X\n", d->id);
329 void fprint_desktop_name(desktop_t *d, FILE *rsp)
331 fprintf(rsp, "%s\n", d->name);
334 void print_ignore_request(state_transition_t st, FILE *rsp)
337 fprintf(rsp, "none");
339 unsigned int cnt = 0;
340 if (st & STATE_TRANSITION_ENTER) {
341 fprintf(rsp, "enter");
344 if (st & STATE_TRANSITION_EXIT) {
345 fprintf(rsp, "%sexit", cnt > 0 ? "," : "");
350 void print_modifier_mask(uint16_t m, FILE *rsp)
353 case XCB_MOD_MASK_SHIFT:
354 fprintf(rsp, "shift");
356 case XCB_MOD_MASK_CONTROL:
357 fprintf(rsp, "control");
359 case XCB_MOD_MASK_LOCK:
360 fprintf(rsp, "lock");
363 fprintf(rsp, "mod1");
366 fprintf(rsp, "mod2");
369 fprintf(rsp, "mod3");
372 fprintf(rsp, "mod4");
375 fprintf(rsp, "mod5");
380 void print_button_index(int8_t b, FILE *rsp)
383 case XCB_BUTTON_INDEX_ANY:
386 case XCB_BUTTON_INDEX_1:
387 fprintf(rsp, "button1");
389 case XCB_BUTTON_INDEX_2:
390 fprintf(rsp, "button2");
392 case XCB_BUTTON_INDEX_3:
393 fprintf(rsp, "button3");
396 fprintf(rsp, "none");
401 void print_pointer_action(pointer_action_t a, FILE *rsp)
405 fprintf(rsp, "move");
407 case ACTION_RESIZE_SIDE:
408 fprintf(rsp, "resize_side");
410 case ACTION_RESIZE_CORNER:
411 fprintf(rsp, "resize_corner");
414 fprintf(rsp, "focus");
417 fprintf(rsp, "none");
422 void print_rule_consequence(char **buf, rule_consequence_t *csq)
424 char *rect_buf = NULL;
425 print_rectangle(&rect_buf, csq->rect);
426 if (rect_buf == NULL) {
427 rect_buf = malloc(1);
430 asprintf(buf, "monitor=%s desktop=%s node=%s state=%s layer=%s split_dir=%s split_ratio=%lf hidden=%s sticky=%s private=%s locked=%s marked=%s center=%s follow=%s manage=%s focus=%s border=%s rectangle=%s",
431 csq->monitor_desc, csq->desktop_desc, csq->node_desc,
432 csq->state == NULL ? "" : STATE_STR(*csq->state),
433 csq->layer == NULL ? "" : LAYER_STR(*csq->layer),
434 csq->split_dir, csq->split_ratio,
435 ON_OFF_STR(csq->hidden), ON_OFF_STR(csq->sticky), ON_OFF_STR(csq->private),
436 ON_OFF_STR(csq->locked), ON_OFF_STR(csq->marked), ON_OFF_STR(csq->center), ON_OFF_STR(csq->follow),
437 ON_OFF_STR(csq->manage), ON_OFF_STR(csq->focus), ON_OFF_STR(csq->border), rect_buf);
441 void print_rectangle(char **buf, xcb_rectangle_t *rect)
444 asprintf(buf, "%hux%hu+%hi+%hi", rect->width, rect->height, rect->x, rect->y);
448 node_select_t make_node_select(void)
450 node_select_t sel = {
451 .automatic = OPTION_NONE,
452 .focused = OPTION_NONE,
453 .active = OPTION_NONE,
454 .local = OPTION_NONE,
456 .window = OPTION_NONE,
457 .tiled = OPTION_NONE,
458 .pseudo_tiled = OPTION_NONE,
459 .floating = OPTION_NONE,
460 .fullscreen = OPTION_NONE,
461 .hidden = OPTION_NONE,
462 .sticky = OPTION_NONE,
463 .private = OPTION_NONE,
464 .locked = OPTION_NONE,
465 .marked = OPTION_NONE,
466 .urgent = OPTION_NONE,
467 .same_class = OPTION_NONE,
468 .descendant_of = OPTION_NONE,
469 .ancestor_of = OPTION_NONE,
470 .below = OPTION_NONE,
471 .normal = OPTION_NONE,
477 desktop_select_t make_desktop_select(void)
479 desktop_select_t sel = {
480 .occupied = OPTION_NONE,
481 .focused = OPTION_NONE,
482 .active = OPTION_NONE,
483 .urgent = OPTION_NONE,
489 monitor_select_t make_monitor_select(void)
491 monitor_select_t sel = {
492 .occupied = OPTION_NONE,
493 .focused = OPTION_NONE
498 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
500 coordinates_t ref_copy = *ref;
502 char *desc_copy = copy_string(desc, strlen(desc));
505 char *hash = strrchr(desc, '#');
506 char *path = strrchr(desc, '@');
507 char *colon = strrchr(desc, ':');
509 /* Discard hashes inside a DESKTOP_SEL */
510 if (hash != NULL && colon != NULL && path != NULL &&
511 path < hash && hash < colon) {
512 if (path > desc && *(path - 1) == '#') {
522 coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
523 if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
531 node_select_t sel = make_node_select();
533 if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
535 return SELECTOR_BAD_MODIFIERS;
543 if (parse_direction(desc, &dir)) {
544 find_nearest_neighbor(ref, dst, dir, &sel);
545 } else if (parse_cycle_direction(desc, &cyc)) {
546 find_closest_node(ref, dst, cyc, &sel);
547 } else if (parse_history_direction(desc, &hdi)) {
548 history_find_node(hdi, ref, dst, &sel);
549 } else if (streq("any", desc)) {
550 find_any_node(ref, dst, &sel);
551 } else if (streq("last", desc)) {
552 history_find_node(HISTORY_OLDER, ref, dst, &sel);
553 } else if (streq("newest", desc)) {
554 history_find_newest_node(ref, dst, &sel);
555 } else if (streq("biggest", desc)) {
556 find_by_area(AREA_BIGGEST, ref, dst, &sel);
557 } else if (streq("smallest", desc)) {
558 find_by_area(AREA_SMALLEST, ref, dst, &sel);
559 } else if (streq("pointed", desc)) {
560 xcb_window_t win = XCB_NONE;
561 query_pointer(&win, NULL);
562 if (locate_window(win, dst) && node_matches(dst, ref, &sel)) {
565 return SELECTOR_INVALID;
567 } else if (streq("focused", desc)) {
568 coordinates_t loc = {mon, mon->desk, mon->desk->focus};
569 if (node_matches(&loc, ref, &sel)) {
572 } else if (*desc == '@') {
578 if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
579 dst->node = dst->desktop->focus;
587 dst->node = dst->desktop->root;
589 char *move = strtok(desc, PTH_TOK);
590 while (move != NULL && dst->node != NULL) {
591 if (streq("first", move) || streq("1", move)) {
592 dst->node = dst->node->first_child;
593 } else if (streq("second", move) || streq("2", move)) {
594 dst->node = dst->node->second_child;
595 } else if (streq("parent", move)) {
596 dst->node = dst->node->parent;
597 } else if (streq("brother", move)) {
598 dst->node = brother_tree(dst->node);
601 if (parse_direction(move, &dir)) {
602 dst->node = find_fence(dst->node, dir);
605 return SELECTOR_BAD_DESCRIPTOR;
608 move = strtok(NULL, PTH_TOK);
611 if (dst->node != NULL) {
612 if (node_matches(dst, ref, &sel)) {
615 return SELECTOR_INVALID;
617 } else if (dst->desktop->root != NULL) {
618 return SELECTOR_INVALID;
623 if (parse_id(desc, &id)) {
625 if (find_by_id(id, dst) && node_matches(dst, ref, &sel)) {
628 return SELECTOR_INVALID;
632 return SELECTOR_BAD_DESCRIPTOR;
638 if (dst->node == NULL) {
639 return SELECTOR_INVALID;
645 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
648 locate_desktop(desc + 1, dst);
652 coordinates_t ref_copy = *ref;
654 char *desc_copy = copy_string(desc, strlen(desc));
657 char *hash = strrchr(desc, '#');
662 coordinates_t tmp = {mon, mon->desk, NULL};
663 if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
671 desktop_select_t sel = make_desktop_select();
672 char *colon = strrchr(desc, ':');
674 if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
676 return SELECTOR_BAD_MODIFIERS;
685 if (parse_cycle_direction(desc, &cyc)) {
686 find_closest_desktop(ref, dst, cyc, &sel);
687 } else if (parse_history_direction(desc, &hdi)) {
688 history_find_desktop(hdi, ref, dst, &sel);
689 } else if (streq("any", desc)) {
690 find_any_desktop(ref, dst, &sel);
691 } else if (streq("last", desc)) {
692 history_find_desktop(HISTORY_OLDER, ref, dst, &sel);
693 } else if (streq("newest", desc)) {
694 history_find_newest_desktop(ref, dst, &sel);
695 } else if (streq("focused", desc)) {
696 coordinates_t loc = {mon, mon->desk, NULL};
697 if (desktop_matches(&loc, ref, &sel)) {
700 } else if (colon != NULL) {
703 if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
704 if (streq("focused", colon + 1)) {
705 coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
706 if (desktop_matches(&loc, ref, &sel)) {
709 } else if (parse_index(colon + 1, &idx)) {
711 if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, &sel)) {
714 return SELECTOR_INVALID;
718 return SELECTOR_BAD_DESCRIPTOR;
724 } else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
726 if (desktop_matches(dst, ref, &sel)) {
729 return SELECTOR_INVALID;
731 } else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
733 if (desktop_matches(dst, ref, &sel)) {
736 return SELECTOR_INVALID;
740 if (desktop_from_name(desc, ref, dst, &sel, &hits)) {
746 return SELECTOR_INVALID;
748 return SELECTOR_BAD_DESCRIPTOR;
756 if (dst->desktop == NULL) {
757 return SELECTOR_INVALID;
763 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
766 locate_monitor(desc + 1, dst);
770 coordinates_t ref_copy = *ref;
772 char *desc_copy = copy_string(desc, strlen(desc));
775 char *hash = strrchr(desc, '#');
780 coordinates_t tmp = {mon, NULL, NULL};
781 if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
789 monitor_select_t sel = make_monitor_select();
791 if (!parse_monitor_modifiers(desc, &sel)) {
793 return SELECTOR_BAD_MODIFIERS;
803 if (parse_direction(desc, &dir)) {
804 dst->monitor = nearest_monitor(ref->monitor, dir, &sel);
805 } else if (parse_cycle_direction(desc, &cyc)) {
806 dst->monitor = closest_monitor(ref->monitor, cyc, &sel);
807 } else if (parse_history_direction(desc, &hdi)) {
808 history_find_monitor(hdi, ref, dst, &sel);
809 } else if (streq("any", desc)) {
810 find_any_monitor(ref, dst, &sel);
811 } else if (streq("last", desc)) {
812 history_find_monitor(HISTORY_OLDER, ref, dst, &sel);
813 } else if (streq("newest", desc)) {
814 history_find_newest_monitor(ref, dst, &sel);
815 } else if (streq("primary", desc)) {
816 if (pri_mon != NULL) {
817 coordinates_t loc = {pri_mon, NULL, NULL};
818 if (monitor_matches(&loc, ref, &sel)) {
819 dst->monitor = pri_mon;
822 } else if (streq("focused", desc)) {
823 coordinates_t loc = {mon, NULL, NULL};
824 if (monitor_matches(&loc, ref, &sel)) {
827 } else if (streq("pointed", desc)) {
829 query_pointer(NULL, &pointer);
830 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
831 if (is_inside(pointer, m->rectangle)) {
836 } else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
838 if (monitor_matches(dst, ref, &sel)) {
841 return SELECTOR_INVALID;
843 } else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
845 if (monitor_matches(dst, ref, &sel)) {
848 return SELECTOR_INVALID;
851 if (locate_monitor(desc, dst)) {
853 if (monitor_matches(dst, ref, &sel)) {
856 return SELECTOR_INVALID;
860 return SELECTOR_BAD_DESCRIPTOR;
867 if (dst->monitor == NULL) {
868 return SELECTOR_INVALID;
874 bool locate_window(xcb_window_t win, coordinates_t *loc)
876 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
877 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
878 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
879 if (n->client == NULL) {
894 bool locate_desktop(char *name, coordinates_t *loc)
896 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
897 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
898 if (streq(d->name, name)) {
908 bool locate_monitor(char *name, coordinates_t *loc)
910 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
911 if (streq(m->name, name)) {
919 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
921 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
922 if (mm != NULL && m != mm) {
925 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
937 bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t *sel, int *hits)
939 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
940 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
941 if (streq(d->name, name)) {
945 coordinates_t loc = {m, d, NULL};
946 if (desktop_matches(&loc, ref, sel)) {
957 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
959 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
960 if (mm != NULL && m != mm) {
963 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, idx--) {
975 bool monitor_from_id(uint32_t id, coordinates_t *loc)
977 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
988 bool monitor_from_index(int idx, coordinates_t *loc)
990 for (monitor_t *m = mon_head; m != NULL; m = m->next, idx--) {
1001 bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t *sel)
1003 if (loc->node == NULL) {
1007 if (sel->focused != OPTION_NONE &&
1008 loc->node != mon->desk->focus
1009 ? sel->focused == OPTION_TRUE
1010 : sel->focused == OPTION_FALSE) {
1014 if (sel->active != OPTION_NONE &&
1015 loc->node != loc->desktop->focus
1016 ? sel->active == OPTION_TRUE
1017 : sel->active == OPTION_FALSE) {
1021 if (sel->automatic != OPTION_NONE &&
1022 loc->node->presel != NULL
1023 ? sel->automatic == OPTION_TRUE
1024 : sel->automatic == OPTION_FALSE) {
1028 if (sel->local != OPTION_NONE &&
1029 loc->desktop != ref->desktop
1030 ? sel->local == OPTION_TRUE
1031 : sel->local == OPTION_FALSE) {
1035 if (sel->active != OPTION_NONE &&
1036 loc->desktop != loc->monitor->desk
1037 ? sel->active == OPTION_TRUE
1038 : sel->active == OPTION_FALSE) {
1042 if (sel->leaf != OPTION_NONE &&
1044 ? sel->leaf == OPTION_TRUE
1045 : sel->leaf == OPTION_FALSE) {
1049 if (sel->window != OPTION_NONE &&
1050 loc->node->client == NULL
1051 ? sel->window == OPTION_TRUE
1052 : sel->window == OPTION_FALSE) {
1057 if (sel->p != OPTION_NONE && \
1059 ? sel->p == OPTION_TRUE \
1060 : sel->p == OPTION_FALSE) { \
1070 if (loc->node->client == NULL &&
1071 (sel->same_class != OPTION_NONE ||
1072 sel->tiled != OPTION_NONE ||
1073 sel->pseudo_tiled != OPTION_NONE ||
1074 sel->floating != OPTION_NONE ||
1075 sel->fullscreen != OPTION_NONE ||
1076 sel->below != OPTION_NONE ||
1077 sel->normal != OPTION_NONE ||
1078 sel->above != OPTION_NONE ||
1079 sel->urgent != OPTION_NONE)) {
1083 if (ref->node != NULL && ref->node->client != NULL &&
1084 sel->same_class != OPTION_NONE &&
1085 streq(loc->node->client->class_name, ref->node->client->class_name)
1086 ? sel->same_class == OPTION_FALSE
1087 : sel->same_class == OPTION_TRUE) {
1091 if (sel->descendant_of != OPTION_NONE &&
1092 !is_descendant(loc->node, ref->node)
1093 ? sel->descendant_of == OPTION_TRUE
1094 : sel->descendant_of == OPTION_FALSE) {
1098 if (sel->ancestor_of != OPTION_NONE &&
1099 !is_descendant(ref->node, loc->node)
1100 ? sel->ancestor_of == OPTION_TRUE
1101 : sel->ancestor_of == OPTION_FALSE) {
1105 #define WSTATE(p, e) \
1106 if (sel->p != OPTION_NONE && \
1107 loc->node->client->state != e \
1108 ? sel->p == OPTION_TRUE \
1109 : sel->p == OPTION_FALSE) { \
1112 WSTATE(tiled, STATE_TILED)
1113 WSTATE(pseudo_tiled, STATE_PSEUDO_TILED)
1114 WSTATE(floating, STATE_FLOATING)
1115 WSTATE(fullscreen, STATE_FULLSCREEN)
1118 #define WLAYER(p, e) \
1119 if (sel->p != OPTION_NONE && \
1120 loc->node->client->layer != e \
1121 ? sel->p == OPTION_TRUE \
1122 : sel->p == OPTION_FALSE) { \
1125 WLAYER(below, LAYER_BELOW)
1126 WLAYER(normal, LAYER_NORMAL)
1127 WLAYER(above, LAYER_ABOVE)
1131 if (sel->p != OPTION_NONE && \
1132 !loc->node->client->p \
1133 ? sel->p == OPTION_TRUE \
1134 : sel->p == OPTION_FALSE) { \
1143 bool desktop_matches(coordinates_t *loc, coordinates_t *ref, desktop_select_t *sel)
1145 if (sel->occupied != OPTION_NONE &&
1146 loc->desktop->root == NULL
1147 ? sel->occupied == OPTION_TRUE
1148 : sel->occupied == OPTION_FALSE) {
1152 if (sel->focused != OPTION_NONE &&
1153 loc->desktop != mon->desk
1154 ? sel->focused == OPTION_TRUE
1155 : sel->focused == OPTION_FALSE) {
1159 if (sel->active != OPTION_NONE &&
1160 loc->desktop != loc->monitor->desk
1161 ? sel->active == OPTION_TRUE
1162 : sel->active == OPTION_FALSE) {
1166 if (sel->urgent != OPTION_NONE &&
1167 !is_urgent(loc->desktop)
1168 ? sel->urgent == OPTION_TRUE
1169 : sel->urgent == OPTION_FALSE) {
1173 if (sel->local != OPTION_NONE &&
1174 ref->monitor != loc->monitor
1175 ? sel->local == OPTION_TRUE
1176 : sel->local == OPTION_FALSE) {
1183 bool monitor_matches(coordinates_t *loc, __attribute__((unused)) coordinates_t *ref, monitor_select_t *sel)
1185 if (sel->occupied != OPTION_NONE &&
1186 loc->monitor->desk->root == NULL
1187 ? sel->occupied == OPTION_TRUE
1188 : sel->occupied == OPTION_FALSE) {
1192 if (sel->focused != OPTION_NONE &&
1194 ? sel->focused == OPTION_TRUE
1195 : sel->focused == OPTION_FALSE) {