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.
37 void query_tree(FILE *rsp)
40 fprintf(rsp, "\"focusedMonitorId\":%u,", mon->id);
41 if (pri_mon != NULL) {
42 fprintf(rsp, "\"primaryMonitorId\":%u,", pri_mon->id);
44 fprintf(rsp, "\"clientsCount\":%i,", clients_count);
45 fprintf(rsp, "\"monitors\":");
47 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
48 query_monitor(m, rsp);
49 if (m->next != NULL) {
55 fprintf(rsp, "\"focusHistory\":");
58 fprintf(rsp, "\"stackingList\":");
64 void query_monitor(monitor_t *m, FILE *rsp)
67 fprintf(rsp, "\"name\":\"%s\",", m->name);
68 fprintf(rsp, "\"id\":%u,", m->id);
69 fprintf(rsp, "\"randrId\":%u,", m->randr_id);
70 fprintf(rsp, "\"wired\":%s,", BOOL_STR(m->wired));
71 fprintf(rsp, "\"stickyCount\":%i,", m->sticky_count);
72 fprintf(rsp, "\"windowGap\":%i,", m->window_gap);
73 fprintf(rsp, "\"borderWidth\":%u,", m->border_width);
74 fprintf(rsp, "\"focusedDesktopId\":%u,", m->desk->id);
75 fprintf(rsp, "\"padding\":");
76 query_padding(m->padding, rsp);
78 fprintf(rsp, "\"rectangle\":");
79 query_rectangle(m->rectangle, rsp);
81 fprintf(rsp, "\"desktops\":");
83 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
84 query_desktop(d, rsp);
85 if (d->next != NULL) {
93 void query_desktop(desktop_t *d, FILE *rsp)
96 fprintf(rsp, "\"name\":\"%s\",", d->name);
97 fprintf(rsp, "\"id\":%u,", d->id);
98 fprintf(rsp, "\"layout\":\"%s\",", LAYOUT_STR(d->layout));
99 fprintf(rsp, "\"windowGap\":%i,", d->window_gap);
100 fprintf(rsp, "\"borderWidth\":%u,", d->border_width);
101 fprintf(rsp, "\"focusedNodeId\":%u,", d->focus != NULL ? d->focus->id : 0);
102 fprintf(rsp, "\"padding\":");
103 query_padding(d->padding, rsp);
105 fprintf(rsp, "\"root\":");
106 query_node(d->root, rsp);
110 void query_node(node_t *n, FILE *rsp)
113 fprintf(rsp, "null");
116 fprintf(rsp, "\"id\":%u,", n->id);
117 fprintf(rsp, "\"splitType\":\"%s\",", SPLIT_TYPE_STR(n->split_type));
118 fprintf(rsp, "\"splitRatio\":%lf,", n->split_ratio);
119 fprintf(rsp, "\"birthRotation\":%i,", n->birth_rotation);
120 fprintf(rsp, "\"vacant\":%s,", BOOL_STR(n->vacant));
121 fprintf(rsp, "\"hidden\":%s,", BOOL_STR(n->hidden));
122 fprintf(rsp, "\"sticky\":%s,", BOOL_STR(n->sticky));
123 fprintf(rsp, "\"private\":%s,", BOOL_STR(n->private));
124 fprintf(rsp, "\"locked\":%s,", BOOL_STR(n->locked));
125 fprintf(rsp, "\"presel\":");
126 query_presel(n->presel, rsp);
128 fprintf(rsp, "\"rectangle\":");
129 query_rectangle(n->rectangle, rsp);
131 fprintf(rsp, "\"constraints\":");
132 query_constraints(n->constraints, rsp);
134 fprintf(rsp, "\"firstChild\":");
135 query_node(n->first_child, rsp);
137 fprintf(rsp, "\"secondChild\":");
138 query_node(n->second_child, rsp);
140 fprintf(rsp, "\"client\":");
141 query_client(n->client, rsp);
146 void query_presel(presel_t *p, FILE *rsp)
149 fprintf(rsp, "null");
151 fprintf(rsp, "{\"splitDir\":\"%s\",\"splitRatio\":%lf}", SPLIT_DIR_STR(p->split_dir), p->split_ratio);
155 void query_client(client_t *c, FILE *rsp)
158 fprintf(rsp, "null");
161 fprintf(rsp, "\"className\":\"%s\",", c->class_name);
162 fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
163 fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
164 fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
165 fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
166 fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
167 fprintf(rsp, "\"lastLayer\":\"%s\",", LAYER_STR(c->last_layer));
168 fprintf(rsp, "\"urgent\":%s,", BOOL_STR(c->urgent));
169 fprintf(rsp, "\"shown\":%s,", BOOL_STR(c->shown));
170 fprintf(rsp, "\"tiledRectangle\":");
171 query_rectangle(c->tiled_rectangle, rsp);
173 fprintf(rsp, "\"floatingRectangle\":");
174 query_rectangle(c->floating_rectangle, rsp);
179 void query_rectangle(xcb_rectangle_t r, FILE *rsp)
181 fprintf(rsp, "{\"x\":%i,\"y\":%i,\"width\":%u,\"height\":%u}", r.x, r.y, r.width, r.height);
184 void query_constraints(constraints_t c, FILE *rsp)
186 fprintf(rsp, "{\"min_width\":%u,\"min_height\":%u}", c.min_width, c.min_height);
189 void query_padding(padding_t p, FILE *rsp)
191 fprintf(rsp, "{\"top\":%i,\"right\":%i,\"bottom\":%i,\"left\":%i}", p.top, p.right, p.bottom, p.left);
194 void query_history(FILE *rsp)
197 for (history_t *h = history_head; h != NULL; h = h->next) {
198 query_coordinates(&h->loc, rsp);
199 if (h->next != NULL) {
206 void query_coordinates(coordinates_t *loc, FILE *rsp)
208 fprintf(rsp, "{\"monitorId\":%u,\"desktopId\":%u,\"nodeId\":%u}", loc->monitor->id, loc->desktop->id, loc->node!=NULL?loc->node->id:0);
211 void query_stack(FILE *rsp)
214 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
215 fprintf(rsp, "%u", s->node->id);
216 if (s->next != NULL) {
223 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
226 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
227 if (trg->monitor != NULL && m != trg->monitor) {
230 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
231 if (trg->desktop != NULL && d != trg->desktop) {
234 count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
240 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)
246 coordinates_t loc = {m, d, n};
247 if ((trg->node == NULL || n == trg->node) &&
248 (sel == NULL || node_matches(&loc, ref, *sel))) {
249 fprintf(rsp, "0x%08X\n", n->id);
252 count += query_node_ids_in(n->first_child, d, m, ref, trg, sel, rsp);
253 count += query_node_ids_in(n->second_child, d, m, ref, trg, sel, rsp);
258 int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
261 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
262 if (trg->monitor != NULL && m != trg->monitor) {
265 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
266 coordinates_t loc = {m, d, NULL};
267 if ((trg->desktop != NULL && d != trg->desktop) ||
268 (sel != NULL && !desktop_matches(&loc, ref, *sel))) {
278 int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
281 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
282 coordinates_t loc = {m, NULL, NULL};
283 if ((trg->monitor != NULL && m != trg->monitor) ||
284 (sel != NULL && !monitor_matches(&loc, ref, *sel))) {
293 void fprint_monitor_id(monitor_t *m, FILE *rsp)
295 fprintf(rsp, "0x%08X\n", m->id);
298 void fprint_monitor_name(monitor_t *m, FILE *rsp)
300 fprintf(rsp, "%s\n", m->name);
303 void fprint_desktop_id(desktop_t *d, FILE *rsp)
305 fprintf(rsp, "0x%08X\n", d->id);
308 void fprint_desktop_name(desktop_t *d, FILE *rsp)
310 fprintf(rsp, "%s\n", d->name);
313 void print_modifier_mask(uint16_t m, FILE *rsp)
316 case XCB_MOD_MASK_SHIFT:
317 fprintf(rsp, "shift");
319 case XCB_MOD_MASK_CONTROL:
320 fprintf(rsp, "control");
322 case XCB_MOD_MASK_LOCK:
323 fprintf(rsp, "lock");
326 fprintf(rsp, "mod1");
329 fprintf(rsp, "mod2");
332 fprintf(rsp, "mod3");
335 fprintf(rsp, "mod4");
338 fprintf(rsp, "mod5");
343 void print_button_index(int8_t b, FILE *rsp)
346 case XCB_BUTTON_INDEX_ANY:
349 case XCB_BUTTON_INDEX_1:
350 fprintf(rsp, "button1");
352 case XCB_BUTTON_INDEX_2:
353 fprintf(rsp, "button2");
355 case XCB_BUTTON_INDEX_3:
356 fprintf(rsp, "button3");
359 fprintf(rsp, "none");
364 void print_pointer_action(pointer_action_t a, FILE *rsp)
368 fprintf(rsp, "move");
370 case ACTION_RESIZE_SIDE:
371 fprintf(rsp, "resize_side");
373 case ACTION_RESIZE_CORNER:
374 fprintf(rsp, "resize_corner");
377 fprintf(rsp, "focus");
380 fprintf(rsp, "none");
385 node_select_t make_node_select(void)
387 node_select_t sel = {
388 .automatic = OPTION_NONE,
389 .focused = OPTION_NONE,
390 .local = OPTION_NONE,
391 .active = OPTION_NONE,
393 .window = OPTION_NONE,
394 .tiled = OPTION_NONE,
395 .pseudo_tiled = OPTION_NONE,
396 .floating = OPTION_NONE,
397 .fullscreen = OPTION_NONE,
398 .hidden = OPTION_NONE,
399 .sticky = OPTION_NONE,
400 .private = OPTION_NONE,
401 .locked = OPTION_NONE,
402 .urgent = OPTION_NONE,
403 .same_class = OPTION_NONE,
404 .descendant_of = OPTION_NONE,
405 .ancestor_of = OPTION_NONE,
406 .below = OPTION_NONE,
407 .normal = OPTION_NONE,
413 desktop_select_t make_desktop_select(void)
415 desktop_select_t sel = {
416 .occupied = OPTION_NONE,
417 .focused = OPTION_NONE,
418 .urgent = OPTION_NONE,
424 monitor_select_t make_monitor_select(void)
426 monitor_select_t sel = {
427 .occupied = OPTION_NONE,
428 .focused = OPTION_NONE
433 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
435 coordinates_t ref_copy = *ref;
437 char *desc_copy = copy_string(desc, strlen(desc));
441 char *path = strrchr(desc, '@');
443 hash = strrchr(desc, '#');
445 if (path != desc && *(path - 1) == '#') {
453 coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
454 if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
462 node_select_t sel = make_node_select();
463 char *colon = strrchr(desc, ':');
465 if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
467 return SELECTOR_BAD_MODIFIERS;
475 if (parse_direction(desc, &dir)) {
476 find_nearest_neighbor(ref, dst, dir, sel);
477 } else if (parse_cycle_direction(desc, &cyc)) {
478 find_closest_node(ref, dst, cyc, sel);
479 } else if (parse_history_direction(desc, &hdi)) {
480 history_find_node(hdi, ref, dst, sel);
481 } else if (streq("last", desc)) {
482 history_find_node(HISTORY_OLDER, ref, dst, sel);
483 } else if (streq("biggest", desc)) {
484 find_biggest(ref, dst, sel);
485 } else if (streq("pointed", desc)) {
486 xcb_window_t win = XCB_NONE;
487 query_pointer(&win, NULL);
488 if (locate_window(win, dst) && node_matches(dst, ref, sel)) {
491 return SELECTOR_INVALID;
493 } else if (streq("focused", desc)) {
494 coordinates_t loc = {mon, mon->desk, mon->desk->focus};
495 if (node_matches(&loc, ref, sel)) {
498 } else if (*desc == '@') {
504 if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
505 dst->node = dst->desktop->focus;
513 dst->node = dst->desktop->root;
515 char *move = strtok(desc, PTH_TOK);
516 while (move != NULL && dst->node != NULL) {
517 if (streq("first", move) || streq("1", move)) {
518 dst->node = dst->node->first_child;
519 } else if (streq("second", move) || streq("2", move)) {
520 dst->node = dst->node->second_child;
521 } else if (streq("parent", move)) {
522 dst->node = dst->node->parent;
523 } else if (streq("brother", move)) {
524 dst->node = brother_tree(dst->node);
527 if (parse_direction(move, &dir)) {
528 dst->node = find_fence(dst->node, dir);
531 return SELECTOR_BAD_DESCRIPTOR;
534 move = strtok(NULL, PTH_TOK);
537 if (dst->node != NULL) {
538 if (node_matches(dst, ref, sel)) {
541 return SELECTOR_INVALID;
543 } else if (dst->desktop->root != NULL) {
544 return SELECTOR_INVALID;
549 if (parse_id(desc, &id)) {
551 if (find_by_id(id, dst) && node_matches(dst, ref, sel)) {
554 return SELECTOR_INVALID;
558 return SELECTOR_BAD_DESCRIPTOR;
564 if (dst->node == NULL) {
565 return SELECTOR_INVALID;
571 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
573 coordinates_t ref_copy = *ref;
575 char *desc_copy = copy_string(desc, strlen(desc));
578 char *hash = strrchr(desc, '#');
583 coordinates_t tmp = {mon, mon->desk, NULL};
584 if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
592 desktop_select_t sel = make_desktop_select();
593 char *colon = strrchr(desc, ':');
595 if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
597 return SELECTOR_BAD_MODIFIERS;
606 if (parse_cycle_direction(desc, &cyc)) {
607 find_closest_desktop(ref, dst, cyc, sel);
608 } else if (parse_history_direction(desc, &hdi)) {
609 history_find_desktop(hdi, ref, dst, sel);
610 } else if (streq("last", desc)) {
611 history_find_desktop(HISTORY_OLDER, ref, dst, sel);
612 } else if (streq("focused", desc)) {
613 coordinates_t loc = {mon, mon->desk, NULL};
614 if (desktop_matches(&loc, ref, sel)) {
617 } else if (colon != NULL) {
620 if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
621 if (streq("focused", colon + 1)) {
622 coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
623 if (desktop_matches(&loc, ref, sel)) {
626 } else if (parse_index(colon + 1, &idx)) {
628 if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, sel)) {
631 return SELECTOR_INVALID;
635 return SELECTOR_BAD_DESCRIPTOR;
641 } else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
643 if (desktop_matches(dst, ref, sel)) {
646 return SELECTOR_INVALID;
648 } else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
650 if (desktop_matches(dst, ref, sel)) {
653 return SELECTOR_INVALID;
657 if (desktop_from_name(desc, ref, dst, sel, &hits)) {
663 return SELECTOR_INVALID;
665 return SELECTOR_BAD_DESCRIPTOR;
672 if (dst->desktop == NULL) {
673 return SELECTOR_INVALID;
679 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
681 coordinates_t ref_copy = *ref;
683 char *desc_copy = copy_string(desc, strlen(desc));
686 char *hash = strrchr(desc, '#');
691 coordinates_t tmp = {mon, NULL, NULL};
692 if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
700 monitor_select_t sel = make_monitor_select();
702 if (!parse_monitor_modifiers(desc, &sel)) {
704 return SELECTOR_BAD_MODIFIERS;
714 if (parse_direction(desc, &dir)) {
715 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
716 } else if (parse_cycle_direction(desc, &cyc)) {
717 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
718 } else if (parse_history_direction(desc, &hdi)) {
719 history_find_monitor(hdi, ref, dst, sel);
720 } else if (streq("last", desc)) {
721 history_find_monitor(HISTORY_OLDER, ref, dst, sel);
722 } else if (streq("primary", desc)) {
723 if (pri_mon != NULL) {
724 coordinates_t loc = {pri_mon, NULL, NULL};
725 if (monitor_matches(&loc, ref, sel)) {
726 dst->monitor = pri_mon;
729 } else if (streq("focused", desc)) {
730 coordinates_t loc = {mon, NULL, NULL};
731 if (monitor_matches(&loc, ref, sel)) {
734 } else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
736 if (monitor_matches(dst, ref, sel)) {
739 return SELECTOR_INVALID;
741 } else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
743 if (monitor_matches(dst, ref, sel)) {
746 return SELECTOR_INVALID;
749 if (locate_monitor(desc, dst)) {
751 if (monitor_matches(dst, ref, sel)) {
754 return SELECTOR_INVALID;
758 return SELECTOR_BAD_DESCRIPTOR;
764 if (dst->monitor == NULL) {
765 return SELECTOR_INVALID;
771 bool locate_window(xcb_window_t win, coordinates_t *loc)
773 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
774 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
775 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
776 if (n->client == NULL) {
791 bool locate_desktop(char *name, coordinates_t *loc)
793 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
794 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
795 if (streq(d->name, name)) {
805 bool locate_monitor(char *name, coordinates_t *loc)
807 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
808 if (streq(m->name, name)) {
816 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
818 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
819 if (mm != NULL && m != mm) {
822 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
834 bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel, int *hits)
836 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
837 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
838 if (streq(d->name, name)) {
842 coordinates_t loc = {m, d, NULL};
843 if (desktop_matches(&loc, ref, sel)) {
854 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
856 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
857 if (mm != NULL && m != mm) {
860 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, idx--) {
872 bool monitor_from_id(uint32_t id, coordinates_t *loc)
874 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
885 bool monitor_from_index(int idx, coordinates_t *loc)
887 for (monitor_t *m = mon_head; m != NULL; m = m->next, idx--) {
898 bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t sel)
900 if (loc->node == NULL) {
904 if (sel.focused != OPTION_NONE &&
905 loc->node != loc->desktop->focus
906 ? sel.focused == OPTION_TRUE
907 : sel.focused == OPTION_FALSE) {
911 if (sel.automatic != OPTION_NONE &&
912 loc->node->presel != NULL
913 ? sel.automatic == OPTION_TRUE
914 : sel.automatic == OPTION_FALSE) {
918 if (sel.local != OPTION_NONE &&
919 loc->desktop != ref->desktop
920 ? sel.local == OPTION_TRUE
921 : sel.local == OPTION_FALSE) {
925 if (sel.active != OPTION_NONE &&
926 loc->desktop != loc->monitor->desk
927 ? sel.active == OPTION_TRUE
928 : sel.active == OPTION_FALSE) {
932 if (sel.leaf != OPTION_NONE &&
934 ? sel.leaf == OPTION_TRUE
935 : sel.leaf == OPTION_FALSE) {
939 if (sel.window != OPTION_NONE &&
940 loc->node->client == NULL
941 ? sel.window == OPTION_TRUE
942 : sel.window == OPTION_FALSE) {
947 if (sel.p != OPTION_NONE && \
949 ? sel.p == OPTION_TRUE \
950 : sel.p == OPTION_FALSE) { \
959 if (loc->node->client == NULL &&
960 (sel.same_class != OPTION_NONE ||
961 sel.tiled != OPTION_NONE ||
962 sel.pseudo_tiled != OPTION_NONE ||
963 sel.floating != OPTION_NONE ||
964 sel.fullscreen != OPTION_NONE ||
965 sel.below != OPTION_NONE ||
966 sel.normal != OPTION_NONE ||
967 sel.above != OPTION_NONE ||
968 sel.urgent != OPTION_NONE)) {
972 if (ref->node != NULL && ref->node->client != NULL &&
973 sel.same_class != OPTION_NONE &&
974 streq(loc->node->client->class_name, ref->node->client->class_name)
975 ? sel.same_class == OPTION_FALSE
976 : sel.same_class == OPTION_TRUE) {
980 if (sel.descendant_of != OPTION_NONE &&
981 !is_descendant(loc->node, ref->node)
982 ? sel.descendant_of == OPTION_TRUE
983 : sel.descendant_of == OPTION_FALSE) {
987 if (sel.ancestor_of != OPTION_NONE &&
988 !is_descendant(ref->node, loc->node)
989 ? sel.ancestor_of == OPTION_TRUE
990 : sel.ancestor_of == OPTION_FALSE) {
994 #define WSTATE(p, e) \
995 if (sel.p != OPTION_NONE && \
996 loc->node->client->state != e \
997 ? sel.p == OPTION_TRUE \
998 : sel.p == OPTION_FALSE) { \
1001 WSTATE(tiled, STATE_TILED)
1002 WSTATE(pseudo_tiled, STATE_PSEUDO_TILED)
1003 WSTATE(floating, STATE_FLOATING)
1004 WSTATE(fullscreen, STATE_FULLSCREEN)
1007 #define WLAYER(p, e) \
1008 if (sel.p != OPTION_NONE && \
1009 loc->node->client->layer != e \
1010 ? sel.p == OPTION_TRUE \
1011 : sel.p == OPTION_FALSE) { \
1014 WLAYER(below, LAYER_BELOW)
1015 WLAYER(normal, LAYER_NORMAL)
1016 WLAYER(above, LAYER_ABOVE)
1020 if (sel.p != OPTION_NONE && \
1021 !loc->node->client->p \
1022 ? sel.p == OPTION_TRUE \
1023 : sel.p == OPTION_FALSE) { \
1032 bool desktop_matches(coordinates_t *loc, coordinates_t *ref, desktop_select_t sel)
1034 if (sel.occupied != OPTION_NONE &&
1035 loc->desktop->root == NULL
1036 ? sel.occupied == OPTION_TRUE
1037 : sel.occupied == OPTION_FALSE) {
1041 if (sel.focused != OPTION_NONE &&
1042 loc->desktop != loc->monitor->desk
1043 ? sel.focused == OPTION_TRUE
1044 : sel.focused == OPTION_FALSE) {
1048 if (sel.urgent != OPTION_NONE &&
1049 !is_urgent(loc->desktop)
1050 ? sel.urgent == OPTION_TRUE
1051 : sel.urgent == OPTION_FALSE) {
1055 if (sel.local != OPTION_NONE &&
1056 ref->monitor != loc->monitor
1057 ? sel.local == OPTION_TRUE
1058 : sel.local == OPTION_FALSE) {
1065 bool monitor_matches(coordinates_t *loc, __attribute__((unused)) coordinates_t *ref, monitor_select_t sel)
1067 if (sel.occupied != OPTION_NONE &&
1068 loc->monitor->desk->root == NULL
1069 ? sel.occupied == OPTION_TRUE
1070 : sel.occupied == OPTION_FALSE) {
1074 if (sel.focused != OPTION_NONE &&
1076 ? sel.focused == OPTION_TRUE
1077 : sel.focused == OPTION_FALSE) {