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, "\"presel\":");
127 query_presel(n->presel, rsp);
129 fprintf(rsp, "\"rectangle\":");
130 query_rectangle(n->rectangle, rsp);
132 fprintf(rsp, "\"constraints\":");
133 query_constraints(n->constraints, rsp);
135 fprintf(rsp, "\"firstChild\":");
136 query_node(n->first_child, rsp);
138 fprintf(rsp, "\"secondChild\":");
139 query_node(n->second_child, rsp);
141 fprintf(rsp, "\"client\":");
142 query_client(n->client, rsp);
147 void query_presel(presel_t *p, FILE *rsp)
150 fprintf(rsp, "null");
152 fprintf(rsp, "{\"splitDir\":\"%s\",\"splitRatio\":%lf}", SPLIT_DIR_STR(p->split_dir), p->split_ratio);
156 void query_client(client_t *c, FILE *rsp)
159 fprintf(rsp, "null");
162 fprintf(rsp, "\"className\":\"%s\",", c->class_name);
163 fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
164 fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
165 fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
166 fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
167 fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
168 fprintf(rsp, "\"lastLayer\":\"%s\",", LAYER_STR(c->last_layer));
169 fprintf(rsp, "\"urgent\":%s,", BOOL_STR(c->urgent));
170 fprintf(rsp, "\"shown\":%s,", BOOL_STR(c->shown));
171 fprintf(rsp, "\"tiledRectangle\":");
172 query_rectangle(c->tiled_rectangle, rsp);
174 fprintf(rsp, "\"floatingRectangle\":");
175 query_rectangle(c->floating_rectangle, rsp);
180 void query_rectangle(xcb_rectangle_t r, FILE *rsp)
182 fprintf(rsp, "{\"x\":%i,\"y\":%i,\"width\":%u,\"height\":%u}", r.x, r.y, r.width, r.height);
185 void query_constraints(constraints_t c, FILE *rsp)
187 fprintf(rsp, "{\"min_width\":%u,\"min_height\":%u}", c.min_width, c.min_height);
190 void query_padding(padding_t p, FILE *rsp)
192 fprintf(rsp, "{\"top\":%i,\"right\":%i,\"bottom\":%i,\"left\":%i}", p.top, p.right, p.bottom, p.left);
195 void query_history(FILE *rsp)
198 for (history_t *h = history_head; h != NULL; h = h->next) {
199 query_coordinates(&h->loc, rsp);
200 if (h->next != NULL) {
207 void query_coordinates(coordinates_t *loc, FILE *rsp)
209 fprintf(rsp, "{\"monitorId\":%u,\"desktopId\":%u,\"nodeId\":%u}", loc->monitor->id, loc->desktop->id, loc->node!=NULL?loc->node->id:0);
212 void query_stack(FILE *rsp)
215 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
216 fprintf(rsp, "%u", s->node->id);
217 if (s->next != NULL) {
224 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
227 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
228 if (trg->monitor != NULL && m != trg->monitor) {
231 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
232 if (trg->desktop != NULL && d != trg->desktop) {
235 count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
241 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)
247 coordinates_t loc = {m, d, n};
248 if ((trg->node == NULL || n == trg->node) &&
249 (sel == NULL || node_matches(&loc, ref, *sel))) {
250 fprintf(rsp, "0x%08X\n", n->id);
253 count += query_node_ids_in(n->first_child, d, m, ref, trg, sel, rsp);
254 count += query_node_ids_in(n->second_child, d, m, ref, trg, sel, rsp);
259 int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
262 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
263 if (trg->monitor != NULL && m != trg->monitor) {
266 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
267 coordinates_t loc = {m, d, NULL};
268 if ((trg->desktop != NULL && d != trg->desktop) ||
269 (sel != NULL && !desktop_matches(&loc, ref, *sel))) {
279 int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
282 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
283 coordinates_t loc = {m, NULL, NULL};
284 if ((trg->monitor != NULL && m != trg->monitor) ||
285 (sel != NULL && !monitor_matches(&loc, ref, *sel))) {
294 void fprint_monitor_id(monitor_t *m, FILE *rsp)
296 fprintf(rsp, "0x%08X\n", m->id);
299 void fprint_monitor_name(monitor_t *m, FILE *rsp)
301 fprintf(rsp, "%s\n", m->name);
304 void fprint_desktop_id(desktop_t *d, FILE *rsp)
306 fprintf(rsp, "0x%08X\n", d->id);
309 void fprint_desktop_name(desktop_t *d, FILE *rsp)
311 fprintf(rsp, "%s\n", d->name);
314 void print_modifier_mask(uint16_t m, FILE *rsp)
317 case XCB_MOD_MASK_SHIFT:
318 fprintf(rsp, "shift");
320 case XCB_MOD_MASK_CONTROL:
321 fprintf(rsp, "control");
323 case XCB_MOD_MASK_LOCK:
324 fprintf(rsp, "lock");
327 fprintf(rsp, "mod1");
330 fprintf(rsp, "mod2");
333 fprintf(rsp, "mod3");
336 fprintf(rsp, "mod4");
339 fprintf(rsp, "mod5");
344 void print_button_index(int8_t b, FILE *rsp)
347 case XCB_BUTTON_INDEX_ANY:
350 case XCB_BUTTON_INDEX_1:
351 fprintf(rsp, "button1");
353 case XCB_BUTTON_INDEX_2:
354 fprintf(rsp, "button2");
356 case XCB_BUTTON_INDEX_3:
357 fprintf(rsp, "button3");
360 fprintf(rsp, "none");
365 void print_pointer_action(pointer_action_t a, FILE *rsp)
369 fprintf(rsp, "move");
371 case ACTION_RESIZE_SIDE:
372 fprintf(rsp, "resize_side");
374 case ACTION_RESIZE_CORNER:
375 fprintf(rsp, "resize_corner");
378 fprintf(rsp, "focus");
381 fprintf(rsp, "none");
386 node_select_t make_node_select(void)
388 node_select_t sel = {
389 .automatic = OPTION_NONE,
390 .focused = OPTION_NONE,
391 .local = OPTION_NONE,
392 .active = OPTION_NONE,
394 .window = OPTION_NONE,
395 .tiled = OPTION_NONE,
396 .pseudo_tiled = OPTION_NONE,
397 .floating = OPTION_NONE,
398 .fullscreen = OPTION_NONE,
399 .hidden = OPTION_NONE,
400 .sticky = OPTION_NONE,
401 .private = OPTION_NONE,
402 .locked = OPTION_NONE,
403 .urgent = OPTION_NONE,
404 .same_class = OPTION_NONE,
405 .descendant_of = OPTION_NONE,
406 .ancestor_of = OPTION_NONE,
407 .below = OPTION_NONE,
408 .normal = OPTION_NONE,
414 desktop_select_t make_desktop_select(void)
416 desktop_select_t sel = {
417 .occupied = OPTION_NONE,
418 .focused = OPTION_NONE,
419 .urgent = OPTION_NONE,
425 monitor_select_t make_monitor_select(void)
427 monitor_select_t sel = {
428 .occupied = OPTION_NONE,
429 .focused = OPTION_NONE
434 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
436 coordinates_t ref_copy = *ref;
438 char *desc_copy = copy_string(desc, strlen(desc));
442 char *path = strrchr(desc, '@');
444 hash = strrchr(desc, '#');
446 if (path != desc && *(path - 1) == '#') {
454 coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
455 if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
463 node_select_t sel = make_node_select();
464 char *colon = strrchr(desc, ':');
466 if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
468 return SELECTOR_BAD_MODIFIERS;
476 if (parse_direction(desc, &dir)) {
477 find_nearest_neighbor(ref, dst, dir, sel);
478 } else if (parse_cycle_direction(desc, &cyc)) {
479 find_closest_node(ref, dst, cyc, sel);
480 } else if (parse_history_direction(desc, &hdi)) {
481 history_find_node(hdi, ref, dst, sel);
482 } else if (streq("last", desc)) {
483 history_find_node(HISTORY_OLDER, ref, dst, sel);
484 } else if (streq("biggest", desc)) {
485 find_biggest(ref, dst, sel);
486 } else if (streq("pointed", desc)) {
487 xcb_window_t win = XCB_NONE;
488 query_pointer(&win, NULL);
489 if (locate_window(win, dst) && node_matches(dst, ref, sel)) {
492 return SELECTOR_INVALID;
494 } else if (streq("focused", desc)) {
495 coordinates_t loc = {mon, mon->desk, mon->desk->focus};
496 if (node_matches(&loc, ref, sel)) {
499 } else if (*desc == '@') {
505 if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
506 dst->node = dst->desktop->focus;
514 dst->node = dst->desktop->root;
516 char *move = strtok(desc, PTH_TOK);
517 while (move != NULL && dst->node != NULL) {
518 if (streq("first", move) || streq("1", move)) {
519 dst->node = dst->node->first_child;
520 } else if (streq("second", move) || streq("2", move)) {
521 dst->node = dst->node->second_child;
522 } else if (streq("parent", move)) {
523 dst->node = dst->node->parent;
524 } else if (streq("brother", move)) {
525 dst->node = brother_tree(dst->node);
528 if (parse_direction(move, &dir)) {
529 dst->node = find_fence(dst->node, dir);
532 return SELECTOR_BAD_DESCRIPTOR;
535 move = strtok(NULL, PTH_TOK);
538 if (dst->node != NULL) {
539 if (node_matches(dst, ref, sel)) {
542 return SELECTOR_INVALID;
544 } else if (dst->desktop->root != NULL) {
545 return SELECTOR_INVALID;
550 if (parse_id(desc, &id)) {
552 if (find_by_id(id, dst) && node_matches(dst, ref, sel)) {
555 return SELECTOR_INVALID;
559 return SELECTOR_BAD_DESCRIPTOR;
565 if (dst->node == NULL) {
566 return SELECTOR_INVALID;
572 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
575 locate_desktop(desc + 1, dst);
579 coordinates_t ref_copy = *ref;
581 char *desc_copy = copy_string(desc, strlen(desc));
584 char *hash = strrchr(desc, '#');
589 coordinates_t tmp = {mon, mon->desk, NULL};
590 if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
598 desktop_select_t sel = make_desktop_select();
599 char *colon = strrchr(desc, ':');
601 if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
603 return SELECTOR_BAD_MODIFIERS;
612 if (parse_cycle_direction(desc, &cyc)) {
613 find_closest_desktop(ref, dst, cyc, sel);
614 } else if (parse_history_direction(desc, &hdi)) {
615 history_find_desktop(hdi, ref, dst, sel);
616 } else if (streq("last", desc)) {
617 history_find_desktop(HISTORY_OLDER, ref, dst, sel);
618 } else if (streq("focused", desc)) {
619 coordinates_t loc = {mon, mon->desk, NULL};
620 if (desktop_matches(&loc, ref, sel)) {
623 } else if (colon != NULL) {
626 if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
627 if (streq("focused", colon + 1)) {
628 coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
629 if (desktop_matches(&loc, ref, sel)) {
632 } else if (parse_index(colon + 1, &idx)) {
634 if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, sel)) {
637 return SELECTOR_INVALID;
641 return SELECTOR_BAD_DESCRIPTOR;
647 } else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
649 if (desktop_matches(dst, ref, sel)) {
652 return SELECTOR_INVALID;
654 } else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
656 if (desktop_matches(dst, ref, sel)) {
659 return SELECTOR_INVALID;
663 if (desktop_from_name(desc, ref, dst, sel, &hits)) {
669 return SELECTOR_INVALID;
671 return SELECTOR_BAD_DESCRIPTOR;
679 if (dst->desktop == NULL) {
680 return SELECTOR_INVALID;
686 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
689 locate_monitor(desc + 1, dst);
693 coordinates_t ref_copy = *ref;
695 char *desc_copy = copy_string(desc, strlen(desc));
698 char *hash = strrchr(desc, '#');
703 coordinates_t tmp = {mon, NULL, NULL};
704 if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
712 monitor_select_t sel = make_monitor_select();
714 if (!parse_monitor_modifiers(desc, &sel)) {
716 return SELECTOR_BAD_MODIFIERS;
726 if (parse_direction(desc, &dir)) {
727 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
728 } else if (parse_cycle_direction(desc, &cyc)) {
729 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
730 } else if (parse_history_direction(desc, &hdi)) {
731 history_find_monitor(hdi, ref, dst, sel);
732 } else if (streq("last", desc)) {
733 history_find_monitor(HISTORY_OLDER, ref, dst, sel);
734 } else if (streq("primary", desc)) {
735 if (pri_mon != NULL) {
736 coordinates_t loc = {pri_mon, NULL, NULL};
737 if (monitor_matches(&loc, ref, sel)) {
738 dst->monitor = pri_mon;
741 } else if (streq("focused", desc)) {
742 coordinates_t loc = {mon, NULL, NULL};
743 if (monitor_matches(&loc, ref, sel)) {
746 } else if (streq("pointed", desc)) {
748 query_pointer(NULL, &pointer);
749 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
750 if (is_inside(pointer, m->rectangle)) {
755 } else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
757 if (monitor_matches(dst, ref, sel)) {
760 return SELECTOR_INVALID;
762 } else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
764 if (monitor_matches(dst, ref, sel)) {
767 return SELECTOR_INVALID;
770 if (locate_monitor(desc, dst)) {
772 if (monitor_matches(dst, ref, sel)) {
775 return SELECTOR_INVALID;
779 return SELECTOR_BAD_DESCRIPTOR;
786 if (dst->monitor == NULL) {
787 return SELECTOR_INVALID;
793 bool locate_window(xcb_window_t win, coordinates_t *loc)
795 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
796 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
797 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
798 if (n->client == NULL) {
813 bool locate_desktop(char *name, coordinates_t *loc)
815 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
816 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
817 if (streq(d->name, name)) {
827 bool locate_monitor(char *name, coordinates_t *loc)
829 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
830 if (streq(m->name, name)) {
838 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
840 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
841 if (mm != NULL && m != mm) {
844 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
856 bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel, int *hits)
858 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
859 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
860 if (streq(d->name, name)) {
864 coordinates_t loc = {m, d, NULL};
865 if (desktop_matches(&loc, ref, sel)) {
876 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
878 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
879 if (mm != NULL && m != mm) {
882 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, idx--) {
894 bool monitor_from_id(uint32_t id, coordinates_t *loc)
896 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
907 bool monitor_from_index(int idx, coordinates_t *loc)
909 for (monitor_t *m = mon_head; m != NULL; m = m->next, idx--) {
920 bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t sel)
922 if (loc->node == NULL) {
926 if (sel.focused != OPTION_NONE &&
927 loc->node != loc->desktop->focus
928 ? sel.focused == OPTION_TRUE
929 : sel.focused == OPTION_FALSE) {
933 if (sel.automatic != OPTION_NONE &&
934 loc->node->presel != NULL
935 ? sel.automatic == OPTION_TRUE
936 : sel.automatic == OPTION_FALSE) {
940 if (sel.local != OPTION_NONE &&
941 loc->desktop != ref->desktop
942 ? sel.local == OPTION_TRUE
943 : sel.local == OPTION_FALSE) {
947 if (sel.active != OPTION_NONE &&
948 loc->desktop != loc->monitor->desk
949 ? sel.active == OPTION_TRUE
950 : sel.active == OPTION_FALSE) {
954 if (sel.leaf != OPTION_NONE &&
956 ? sel.leaf == OPTION_TRUE
957 : sel.leaf == OPTION_FALSE) {
961 if (sel.window != OPTION_NONE &&
962 loc->node->client == NULL
963 ? sel.window == OPTION_TRUE
964 : sel.window == OPTION_FALSE) {
969 if (sel.p != OPTION_NONE && \
971 ? sel.p == OPTION_TRUE \
972 : sel.p == OPTION_FALSE) { \
981 if (loc->node->client == NULL &&
982 (sel.same_class != OPTION_NONE ||
983 sel.tiled != OPTION_NONE ||
984 sel.pseudo_tiled != OPTION_NONE ||
985 sel.floating != OPTION_NONE ||
986 sel.fullscreen != OPTION_NONE ||
987 sel.below != OPTION_NONE ||
988 sel.normal != OPTION_NONE ||
989 sel.above != OPTION_NONE ||
990 sel.urgent != OPTION_NONE)) {
994 if (ref->node != NULL && ref->node->client != NULL &&
995 sel.same_class != OPTION_NONE &&
996 streq(loc->node->client->class_name, ref->node->client->class_name)
997 ? sel.same_class == OPTION_FALSE
998 : sel.same_class == OPTION_TRUE) {
1002 if (sel.descendant_of != OPTION_NONE &&
1003 !is_descendant(loc->node, ref->node)
1004 ? sel.descendant_of == OPTION_TRUE
1005 : sel.descendant_of == OPTION_FALSE) {
1009 if (sel.ancestor_of != OPTION_NONE &&
1010 !is_descendant(ref->node, loc->node)
1011 ? sel.ancestor_of == OPTION_TRUE
1012 : sel.ancestor_of == OPTION_FALSE) {
1016 #define WSTATE(p, e) \
1017 if (sel.p != OPTION_NONE && \
1018 loc->node->client->state != e \
1019 ? sel.p == OPTION_TRUE \
1020 : sel.p == OPTION_FALSE) { \
1023 WSTATE(tiled, STATE_TILED)
1024 WSTATE(pseudo_tiled, STATE_PSEUDO_TILED)
1025 WSTATE(floating, STATE_FLOATING)
1026 WSTATE(fullscreen, STATE_FULLSCREEN)
1029 #define WLAYER(p, e) \
1030 if (sel.p != OPTION_NONE && \
1031 loc->node->client->layer != e \
1032 ? sel.p == OPTION_TRUE \
1033 : sel.p == OPTION_FALSE) { \
1036 WLAYER(below, LAYER_BELOW)
1037 WLAYER(normal, LAYER_NORMAL)
1038 WLAYER(above, LAYER_ABOVE)
1042 if (sel.p != OPTION_NONE && \
1043 !loc->node->client->p \
1044 ? sel.p == OPTION_TRUE \
1045 : sel.p == OPTION_FALSE) { \
1054 bool desktop_matches(coordinates_t *loc, coordinates_t *ref, desktop_select_t sel)
1056 if (sel.occupied != OPTION_NONE &&
1057 loc->desktop->root == NULL
1058 ? sel.occupied == OPTION_TRUE
1059 : sel.occupied == OPTION_FALSE) {
1063 if (sel.focused != OPTION_NONE &&
1064 loc->desktop != loc->monitor->desk
1065 ? sel.focused == OPTION_TRUE
1066 : sel.focused == OPTION_FALSE) {
1070 if (sel.urgent != OPTION_NONE &&
1071 !is_urgent(loc->desktop)
1072 ? sel.urgent == OPTION_TRUE
1073 : sel.urgent == OPTION_FALSE) {
1077 if (sel.local != OPTION_NONE &&
1078 ref->monitor != loc->monitor
1079 ? sel.local == OPTION_TRUE
1080 : sel.local == OPTION_FALSE) {
1087 bool monitor_matches(coordinates_t *loc, __attribute__((unused)) coordinates_t *ref, monitor_select_t sel)
1089 if (sel.occupied != OPTION_NONE &&
1090 loc->monitor->desk->root == NULL
1091 ? sel.occupied == OPTION_TRUE
1092 : sel.occupied == OPTION_FALSE) {
1096 if (sel.focused != OPTION_NONE &&
1098 ? sel.focused == OPTION_TRUE
1099 : sel.focused == OPTION_FALSE) {