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_tree(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\":");
65 void query_monitor(monitor_t *m, FILE *rsp)
68 fprintf(rsp, "\"name\":\"%s\",", m->name);
69 fprintf(rsp, "\"id\":%u,", m->id);
70 fprintf(rsp, "\"randrId\":%u,", m->randr_id);
71 fprintf(rsp, "\"wired\":%s,", BOOL_STR(m->wired));
72 fprintf(rsp, "\"stickyCount\":%i,", m->sticky_count);
73 fprintf(rsp, "\"windowGap\":%i,", m->window_gap);
74 fprintf(rsp, "\"borderWidth\":%u,", m->border_width);
75 fprintf(rsp, "\"focusedDesktopId\":%u,", m->desk->id);
76 fprintf(rsp, "\"padding\":");
77 query_padding(m->padding, rsp);
79 fprintf(rsp, "\"rectangle\":");
80 query_rectangle(m->rectangle, rsp);
82 fprintf(rsp, "\"desktops\":");
84 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
85 query_desktop(d, rsp);
86 if (d->next != NULL) {
94 void query_desktop(desktop_t *d, FILE *rsp)
97 fprintf(rsp, "\"name\":\"%s\",", d->name);
98 fprintf(rsp, "\"id\":%u,", d->id);
99 fprintf(rsp, "\"layout\":\"%s\",", LAYOUT_STR(d->layout));
100 fprintf(rsp, "\"windowGap\":%i,", d->window_gap);
101 fprintf(rsp, "\"borderWidth\":%u,", d->border_width);
102 fprintf(rsp, "\"focusedNodeId\":%u,", d->focus != NULL ? d->focus->id : 0);
103 fprintf(rsp, "\"padding\":");
104 query_padding(d->padding, rsp);
106 fprintf(rsp, "\"root\":");
107 query_node(d->root, rsp);
111 void query_node(node_t *n, FILE *rsp)
114 fprintf(rsp, "null");
117 fprintf(rsp, "\"id\":%u,", n->id);
118 fprintf(rsp, "\"splitType\":\"%s\",", SPLIT_TYPE_STR(n->split_type));
119 fprintf(rsp, "\"splitRatio\":%lf,", n->split_ratio);
120 fprintf(rsp, "\"birthRotation\":%i,", n->birth_rotation);
121 fprintf(rsp, "\"vacant\":%s,", BOOL_STR(n->vacant));
122 fprintf(rsp, "\"hidden\":%s,", BOOL_STR(n->hidden));
123 fprintf(rsp, "\"sticky\":%s,", BOOL_STR(n->sticky));
124 fprintf(rsp, "\"private\":%s,", BOOL_STR(n->private));
125 fprintf(rsp, "\"locked\":%s,", BOOL_STR(n->locked));
126 fprintf(rsp, "\"marked\":%s,", BOOL_STR(n->marked));
127 fprintf(rsp, "\"presel\":");
128 query_presel(n->presel, rsp);
130 fprintf(rsp, "\"rectangle\":");
131 query_rectangle(n->rectangle, rsp);
133 fprintf(rsp, "\"constraints\":");
134 query_constraints(n->constraints, rsp);
136 fprintf(rsp, "\"firstChild\":");
137 query_node(n->first_child, rsp);
139 fprintf(rsp, "\"secondChild\":");
140 query_node(n->second_child, rsp);
142 fprintf(rsp, "\"client\":");
143 query_client(n->client, rsp);
148 void query_presel(presel_t *p, FILE *rsp)
151 fprintf(rsp, "null");
153 fprintf(rsp, "{\"splitDir\":\"%s\",\"splitRatio\":%lf}", SPLIT_DIR_STR(p->split_dir), p->split_ratio);
157 void query_client(client_t *c, FILE *rsp)
160 fprintf(rsp, "null");
163 fprintf(rsp, "\"className\":\"%s\",", c->class_name);
164 fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
165 fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
166 fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
167 fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
168 fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
169 fprintf(rsp, "\"lastLayer\":\"%s\",", LAYER_STR(c->last_layer));
170 fprintf(rsp, "\"urgent\":%s,", BOOL_STR(c->urgent));
171 fprintf(rsp, "\"shown\":%s,", BOOL_STR(c->shown));
172 fprintf(rsp, "\"tiledRectangle\":");
173 query_rectangle(c->tiled_rectangle, rsp);
175 fprintf(rsp, "\"floatingRectangle\":");
176 query_rectangle(c->floating_rectangle, rsp);
181 void query_rectangle(xcb_rectangle_t r, FILE *rsp)
183 fprintf(rsp, "{\"x\":%i,\"y\":%i,\"width\":%u,\"height\":%u}", r.x, r.y, r.width, r.height);
186 void query_constraints(constraints_t c, FILE *rsp)
188 fprintf(rsp, "{\"min_width\":%u,\"min_height\":%u}", c.min_width, c.min_height);
191 void query_padding(padding_t p, FILE *rsp)
193 fprintf(rsp, "{\"top\":%i,\"right\":%i,\"bottom\":%i,\"left\":%i}", p.top, p.right, p.bottom, p.left);
196 void query_history(FILE *rsp)
199 for (history_t *h = history_head; h != NULL; h = h->next) {
200 query_coordinates(&h->loc, rsp);
201 if (h->next != NULL) {
208 void query_coordinates(coordinates_t *loc, FILE *rsp)
210 fprintf(rsp, "{\"monitorId\":%u,\"desktopId\":%u,\"nodeId\":%u}", loc->monitor->id, loc->desktop->id, loc->node!=NULL?loc->node->id:0);
213 void query_stack(FILE *rsp)
216 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
217 fprintf(rsp, "%u", s->node->id);
218 if (s->next != NULL) {
225 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
228 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
229 if (trg->monitor != NULL && m != trg->monitor) {
232 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
233 if (trg->desktop != NULL && d != trg->desktop) {
236 count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
242 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)
248 coordinates_t loc = {m, d, n};
249 if ((trg->node == NULL || n == trg->node) &&
250 (sel == NULL || node_matches(&loc, ref, sel))) {
251 fprintf(rsp, "0x%08X\n", n->id);
254 count += query_node_ids_in(n->first_child, d, m, ref, trg, sel, rsp);
255 count += query_node_ids_in(n->second_child, d, m, ref, trg, sel, rsp);
260 int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
263 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
264 if (trg->monitor != NULL && m != trg->monitor) {
267 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
268 coordinates_t loc = {m, d, NULL};
269 if ((trg->desktop != NULL && d != trg->desktop) ||
270 (sel != NULL && !desktop_matches(&loc, ref, sel))) {
280 int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
283 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
284 coordinates_t loc = {m, NULL, NULL};
285 if ((trg->monitor != NULL && m != trg->monitor) ||
286 (sel != NULL && !monitor_matches(&loc, ref, sel))) {
295 void fprint_monitor_id(monitor_t *m, FILE *rsp)
297 fprintf(rsp, "0x%08X\n", m->id);
300 void fprint_monitor_name(monitor_t *m, FILE *rsp)
302 fprintf(rsp, "%s\n", m->name);
305 void fprint_desktop_id(desktop_t *d, FILE *rsp)
307 fprintf(rsp, "0x%08X\n", d->id);
310 void fprint_desktop_name(desktop_t *d, FILE *rsp)
312 fprintf(rsp, "%s\n", d->name);
315 void print_ignore_request(state_transition_t st, FILE *rsp)
318 fprintf(rsp, "none");
320 unsigned int cnt = 0;
321 if (st & STATE_TRANSITION_ENTER) {
322 fprintf(rsp, "enter");
325 if (st & STATE_TRANSITION_EXIT) {
326 fprintf(rsp, "%sexit", cnt > 0 ? "," : "");
331 void print_modifier_mask(uint16_t m, FILE *rsp)
334 case XCB_MOD_MASK_SHIFT:
335 fprintf(rsp, "shift");
337 case XCB_MOD_MASK_CONTROL:
338 fprintf(rsp, "control");
340 case XCB_MOD_MASK_LOCK:
341 fprintf(rsp, "lock");
344 fprintf(rsp, "mod1");
347 fprintf(rsp, "mod2");
350 fprintf(rsp, "mod3");
353 fprintf(rsp, "mod4");
356 fprintf(rsp, "mod5");
361 void print_button_index(int8_t b, FILE *rsp)
364 case XCB_BUTTON_INDEX_ANY:
367 case XCB_BUTTON_INDEX_1:
368 fprintf(rsp, "button1");
370 case XCB_BUTTON_INDEX_2:
371 fprintf(rsp, "button2");
373 case XCB_BUTTON_INDEX_3:
374 fprintf(rsp, "button3");
377 fprintf(rsp, "none");
382 void print_pointer_action(pointer_action_t a, FILE *rsp)
386 fprintf(rsp, "move");
388 case ACTION_RESIZE_SIDE:
389 fprintf(rsp, "resize_side");
391 case ACTION_RESIZE_CORNER:
392 fprintf(rsp, "resize_corner");
395 fprintf(rsp, "focus");
398 fprintf(rsp, "none");
403 void print_rule_consequence(char **buf, rule_consequence_t *csq)
405 char *rect_buf = NULL;
406 print_rectangle(&rect_buf, csq->rect);
407 if (rect_buf == NULL) {
408 rect_buf = malloc(1);
411 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",
412 csq->monitor_desc, csq->desktop_desc, csq->node_desc,
413 csq->state == NULL ? "" : STATE_STR(*csq->state),
414 csq->layer == NULL ? "" : LAYER_STR(*csq->layer),
415 csq->split_dir, csq->split_ratio,
416 ON_OFF_STR(csq->hidden), ON_OFF_STR(csq->sticky), ON_OFF_STR(csq->private),
417 ON_OFF_STR(csq->locked), ON_OFF_STR(csq->marked), ON_OFF_STR(csq->center), ON_OFF_STR(csq->follow),
418 ON_OFF_STR(csq->manage), ON_OFF_STR(csq->focus), ON_OFF_STR(csq->border), rect_buf);
422 void print_rectangle(char **buf, xcb_rectangle_t *rect)
425 asprintf(buf, "%hux%hu+%hi+%hi", rect->width, rect->height, rect->x, rect->y);
429 node_select_t make_node_select(void)
431 node_select_t sel = {
432 .automatic = OPTION_NONE,
433 .focused = OPTION_NONE,
434 .local = OPTION_NONE,
435 .active = OPTION_NONE,
437 .window = OPTION_NONE,
438 .tiled = OPTION_NONE,
439 .pseudo_tiled = OPTION_NONE,
440 .floating = OPTION_NONE,
441 .fullscreen = OPTION_NONE,
442 .hidden = OPTION_NONE,
443 .sticky = OPTION_NONE,
444 .private = OPTION_NONE,
445 .locked = OPTION_NONE,
446 .marked = OPTION_NONE,
447 .urgent = OPTION_NONE,
448 .same_class = OPTION_NONE,
449 .descendant_of = OPTION_NONE,
450 .ancestor_of = OPTION_NONE,
451 .below = OPTION_NONE,
452 .normal = OPTION_NONE,
458 desktop_select_t make_desktop_select(void)
460 desktop_select_t sel = {
461 .occupied = OPTION_NONE,
462 .focused = OPTION_NONE,
463 .urgent = OPTION_NONE,
469 monitor_select_t make_monitor_select(void)
471 monitor_select_t sel = {
472 .occupied = OPTION_NONE,
473 .focused = OPTION_NONE
478 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
480 coordinates_t ref_copy = *ref;
482 char *desc_copy = copy_string(desc, strlen(desc));
485 char *hash = strrchr(desc, '#');
490 coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
491 if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
499 node_select_t sel = make_node_select();
500 char *colon = strrchr(desc, ':');
502 if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
504 return SELECTOR_BAD_MODIFIERS;
512 if (parse_direction(desc, &dir)) {
513 find_nearest_neighbor(ref, dst, dir, &sel);
514 } else if (parse_cycle_direction(desc, &cyc)) {
515 find_closest_node(ref, dst, cyc, &sel);
516 } else if (parse_history_direction(desc, &hdi)) {
517 history_find_node(hdi, ref, dst, &sel);
518 } else if (streq("any", desc)) {
519 find_any_node(ref, dst, &sel);
520 } else if (streq("last", desc)) {
521 history_find_node(HISTORY_OLDER, ref, dst, &sel);
522 } else if (streq("newest", desc)) {
523 history_find_newest_node(ref, dst, &sel);
524 } else if (streq("biggest", desc)) {
525 find_biggest(ref, dst, &sel);
526 } else if (streq("pointed", desc)) {
527 xcb_window_t win = XCB_NONE;
528 query_pointer(&win, NULL);
529 if (locate_window(win, dst) && node_matches(dst, ref, &sel)) {
532 return SELECTOR_INVALID;
534 } else if (streq("focused", desc)) {
535 coordinates_t loc = {mon, mon->desk, mon->desk->focus};
536 if (node_matches(&loc, ref, &sel)) {
539 } else if (*desc == '@') {
545 if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
546 dst->node = dst->desktop->focus;
554 dst->node = dst->desktop->root;
556 char *move = strtok(desc, PTH_TOK);
557 while (move != NULL && dst->node != NULL) {
558 if (streq("first", move) || streq("1", move)) {
559 dst->node = dst->node->first_child;
560 } else if (streq("second", move) || streq("2", move)) {
561 dst->node = dst->node->second_child;
562 } else if (streq("parent", move)) {
563 dst->node = dst->node->parent;
564 } else if (streq("brother", move)) {
565 dst->node = brother_tree(dst->node);
568 if (parse_direction(move, &dir)) {
569 dst->node = find_fence(dst->node, dir);
572 return SELECTOR_BAD_DESCRIPTOR;
575 move = strtok(NULL, PTH_TOK);
578 if (dst->node != NULL) {
579 if (node_matches(dst, ref, &sel)) {
582 return SELECTOR_INVALID;
584 } else if (dst->desktop->root != NULL) {
585 return SELECTOR_INVALID;
590 if (parse_id(desc, &id)) {
592 if (find_by_id(id, dst) && node_matches(dst, ref, &sel)) {
595 return SELECTOR_INVALID;
599 return SELECTOR_BAD_DESCRIPTOR;
605 if (dst->node == NULL) {
606 return SELECTOR_INVALID;
612 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
615 locate_desktop(desc + 1, dst);
619 coordinates_t ref_copy = *ref;
621 char *desc_copy = copy_string(desc, strlen(desc));
624 char *hash = strrchr(desc, '#');
629 coordinates_t tmp = {mon, mon->desk, NULL};
630 if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
638 desktop_select_t sel = make_desktop_select();
639 char *colon = strrchr(desc, ':');
641 if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
643 return SELECTOR_BAD_MODIFIERS;
652 if (parse_cycle_direction(desc, &cyc)) {
653 find_closest_desktop(ref, dst, cyc, &sel);
654 } else if (parse_history_direction(desc, &hdi)) {
655 history_find_desktop(hdi, ref, dst, &sel);
656 } else if (streq("any", desc)) {
657 find_any_desktop(ref, dst, &sel);
658 } else if (streq("last", desc)) {
659 history_find_desktop(HISTORY_OLDER, ref, dst, &sel);
660 } else if (streq("newest", desc)) {
661 history_find_newest_desktop(ref, dst, &sel);
662 } else if (streq("focused", desc)) {
663 coordinates_t loc = {mon, mon->desk, NULL};
664 if (desktop_matches(&loc, ref, &sel)) {
667 } else if (colon != NULL) {
670 if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
671 if (streq("focused", colon + 1)) {
672 coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
673 if (desktop_matches(&loc, ref, &sel)) {
676 } else if (parse_index(colon + 1, &idx)) {
678 if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, &sel)) {
681 return SELECTOR_INVALID;
685 return SELECTOR_BAD_DESCRIPTOR;
691 } else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
693 if (desktop_matches(dst, ref, &sel)) {
696 return SELECTOR_INVALID;
698 } else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
700 if (desktop_matches(dst, ref, &sel)) {
703 return SELECTOR_INVALID;
707 if (desktop_from_name(desc, ref, dst, &sel, &hits)) {
713 return SELECTOR_INVALID;
715 return SELECTOR_BAD_DESCRIPTOR;
723 if (dst->desktop == NULL) {
724 return SELECTOR_INVALID;
730 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
733 locate_monitor(desc + 1, dst);
737 coordinates_t ref_copy = *ref;
739 char *desc_copy = copy_string(desc, strlen(desc));
742 char *hash = strrchr(desc, '#');
747 coordinates_t tmp = {mon, NULL, NULL};
748 if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
756 monitor_select_t sel = make_monitor_select();
758 if (!parse_monitor_modifiers(desc, &sel)) {
760 return SELECTOR_BAD_MODIFIERS;
770 if (parse_direction(desc, &dir)) {
771 dst->monitor = nearest_monitor(ref->monitor, dir, &sel);
772 } else if (parse_cycle_direction(desc, &cyc)) {
773 dst->monitor = closest_monitor(ref->monitor, cyc, &sel);
774 } else if (parse_history_direction(desc, &hdi)) {
775 history_find_monitor(hdi, ref, dst, &sel);
776 } else if (streq("any", desc)) {
777 find_any_monitor(ref, dst, &sel);
778 } else if (streq("last", desc)) {
779 history_find_monitor(HISTORY_OLDER, ref, dst, &sel);
780 } else if (streq("newest", desc)) {
781 history_find_newest_monitor(ref, dst, &sel);
782 } else if (streq("primary", desc)) {
783 if (pri_mon != NULL) {
784 coordinates_t loc = {pri_mon, NULL, NULL};
785 if (monitor_matches(&loc, ref, &sel)) {
786 dst->monitor = pri_mon;
789 } else if (streq("focused", desc)) {
790 coordinates_t loc = {mon, NULL, NULL};
791 if (monitor_matches(&loc, ref, &sel)) {
794 } else if (streq("pointed", desc)) {
796 query_pointer(NULL, &pointer);
797 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
798 if (is_inside(pointer, m->rectangle)) {
803 } else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
805 if (monitor_matches(dst, ref, &sel)) {
808 return SELECTOR_INVALID;
810 } else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
812 if (monitor_matches(dst, ref, &sel)) {
815 return SELECTOR_INVALID;
818 if (locate_monitor(desc, dst)) {
820 if (monitor_matches(dst, ref, &sel)) {
823 return SELECTOR_INVALID;
827 return SELECTOR_BAD_DESCRIPTOR;
834 if (dst->monitor == NULL) {
835 return SELECTOR_INVALID;
841 bool locate_window(xcb_window_t win, coordinates_t *loc)
843 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
844 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
845 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
846 if (n->client == NULL) {
861 bool locate_desktop(char *name, coordinates_t *loc)
863 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
864 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
865 if (streq(d->name, name)) {
875 bool locate_monitor(char *name, coordinates_t *loc)
877 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
878 if (streq(m->name, name)) {
886 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
888 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
889 if (mm != NULL && m != mm) {
892 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
904 bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t *sel, int *hits)
906 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
907 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
908 if (streq(d->name, name)) {
912 coordinates_t loc = {m, d, NULL};
913 if (desktop_matches(&loc, ref, sel)) {
924 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
926 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
927 if (mm != NULL && m != mm) {
930 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, idx--) {
942 bool monitor_from_id(uint32_t id, coordinates_t *loc)
944 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
955 bool monitor_from_index(int idx, coordinates_t *loc)
957 for (monitor_t *m = mon_head; m != NULL; m = m->next, idx--) {
968 bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t *sel)
970 if (loc->node == NULL) {
974 if (sel->focused != OPTION_NONE &&
975 loc->node != loc->desktop->focus
976 ? sel->focused == OPTION_TRUE
977 : sel->focused == OPTION_FALSE) {
981 if (sel->automatic != OPTION_NONE &&
982 loc->node->presel != NULL
983 ? sel->automatic == OPTION_TRUE
984 : sel->automatic == OPTION_FALSE) {
988 if (sel->local != OPTION_NONE &&
989 loc->desktop != ref->desktop
990 ? sel->local == OPTION_TRUE
991 : sel->local == OPTION_FALSE) {
995 if (sel->active != OPTION_NONE &&
996 loc->desktop != loc->monitor->desk
997 ? sel->active == OPTION_TRUE
998 : sel->active == OPTION_FALSE) {
1002 if (sel->leaf != OPTION_NONE &&
1004 ? sel->leaf == OPTION_TRUE
1005 : sel->leaf == OPTION_FALSE) {
1009 if (sel->window != OPTION_NONE &&
1010 loc->node->client == NULL
1011 ? sel->window == OPTION_TRUE
1012 : sel->window == OPTION_FALSE) {
1017 if (sel->p != OPTION_NONE && \
1019 ? sel->p == OPTION_TRUE \
1020 : sel->p == OPTION_FALSE) { \
1030 if (loc->node->client == NULL &&
1031 (sel->same_class != OPTION_NONE ||
1032 sel->tiled != OPTION_NONE ||
1033 sel->pseudo_tiled != OPTION_NONE ||
1034 sel->floating != OPTION_NONE ||
1035 sel->fullscreen != OPTION_NONE ||
1036 sel->below != OPTION_NONE ||
1037 sel->normal != OPTION_NONE ||
1038 sel->above != OPTION_NONE ||
1039 sel->urgent != OPTION_NONE)) {
1043 if (ref->node != NULL && ref->node->client != NULL &&
1044 sel->same_class != OPTION_NONE &&
1045 streq(loc->node->client->class_name, ref->node->client->class_name)
1046 ? sel->same_class == OPTION_FALSE
1047 : sel->same_class == OPTION_TRUE) {
1051 if (sel->descendant_of != OPTION_NONE &&
1052 !is_descendant(loc->node, ref->node)
1053 ? sel->descendant_of == OPTION_TRUE
1054 : sel->descendant_of == OPTION_FALSE) {
1058 if (sel->ancestor_of != OPTION_NONE &&
1059 !is_descendant(ref->node, loc->node)
1060 ? sel->ancestor_of == OPTION_TRUE
1061 : sel->ancestor_of == OPTION_FALSE) {
1065 #define WSTATE(p, e) \
1066 if (sel->p != OPTION_NONE && \
1067 loc->node->client->state != e \
1068 ? sel->p == OPTION_TRUE \
1069 : sel->p == OPTION_FALSE) { \
1072 WSTATE(tiled, STATE_TILED)
1073 WSTATE(pseudo_tiled, STATE_PSEUDO_TILED)
1074 WSTATE(floating, STATE_FLOATING)
1075 WSTATE(fullscreen, STATE_FULLSCREEN)
1078 #define WLAYER(p, e) \
1079 if (sel->p != OPTION_NONE && \
1080 loc->node->client->layer != e \
1081 ? sel->p == OPTION_TRUE \
1082 : sel->p == OPTION_FALSE) { \
1085 WLAYER(below, LAYER_BELOW)
1086 WLAYER(normal, LAYER_NORMAL)
1087 WLAYER(above, LAYER_ABOVE)
1091 if (sel->p != OPTION_NONE && \
1092 !loc->node->client->p \
1093 ? sel->p == OPTION_TRUE \
1094 : sel->p == OPTION_FALSE) { \
1103 bool desktop_matches(coordinates_t *loc, coordinates_t *ref, desktop_select_t *sel)
1105 if (sel->occupied != OPTION_NONE &&
1106 loc->desktop->root == NULL
1107 ? sel->occupied == OPTION_TRUE
1108 : sel->occupied == OPTION_FALSE) {
1112 if (sel->focused != OPTION_NONE &&
1113 loc->desktop != loc->monitor->desk
1114 ? sel->focused == OPTION_TRUE
1115 : sel->focused == OPTION_FALSE) {
1119 if (sel->urgent != OPTION_NONE &&
1120 !is_urgent(loc->desktop)
1121 ? sel->urgent == OPTION_TRUE
1122 : sel->urgent == OPTION_FALSE) {
1126 if (sel->local != OPTION_NONE &&
1127 ref->monitor != loc->monitor
1128 ? sel->local == OPTION_TRUE
1129 : sel->local == OPTION_FALSE) {
1136 bool monitor_matches(coordinates_t *loc, __attribute__((unused)) coordinates_t *ref, monitor_select_t *sel)
1138 if (sel->occupied != OPTION_NONE &&
1139 loc->monitor->desk->root == NULL
1140 ? sel->occupied == OPTION_TRUE
1141 : sel->occupied == OPTION_FALSE) {
1145 if (sel->focused != OPTION_NONE &&
1147 ? sel->focused == OPTION_TRUE
1148 : sel->focused == OPTION_FALSE) {