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, "\"firstChild\":");
132 query_node(n->first_child, rsp);
134 fprintf(rsp, "\"secondChild\":");
135 query_node(n->second_child, rsp);
137 fprintf(rsp, "\"client\":");
138 query_client(n->client, rsp);
143 void query_presel(presel_t *p, FILE *rsp)
146 fprintf(rsp, "null");
148 fprintf(rsp, "{\"splitDir\":\"%s\",\"splitRatio\":%lf}", SPLIT_DIR_STR(p->split_dir), p->split_ratio);
152 void query_client(client_t *c, FILE *rsp)
155 fprintf(rsp, "null");
158 fprintf(rsp, "\"className\":\"%s\",", c->class_name);
159 fprintf(rsp, "\"instanceName\":\"%s\",", c->instance_name);
160 fprintf(rsp, "\"borderWidth\":%u,", c->border_width);
161 fprintf(rsp, "\"state\":\"%s\",", STATE_STR(c->state));
162 fprintf(rsp, "\"lastState\":\"%s\",", STATE_STR(c->last_state));
163 fprintf(rsp, "\"layer\":\"%s\",", LAYER_STR(c->layer));
164 fprintf(rsp, "\"lastLayer\":\"%s\",", LAYER_STR(c->last_layer));
165 fprintf(rsp, "\"urgent\":%s,", BOOL_STR(c->urgent));
166 fprintf(rsp, "\"shown\":%s,", BOOL_STR(c->shown));
167 fprintf(rsp, "\"tiledRectangle\":");
168 query_rectangle(c->tiled_rectangle, rsp);
170 fprintf(rsp, "\"floatingRectangle\":");
171 query_rectangle(c->floating_rectangle, rsp);
176 void query_rectangle(xcb_rectangle_t r, FILE *rsp)
178 fprintf(rsp, "{\"x\":%i,\"y\":%i,\"width\":%u,\"height\":%u}", r.x, r.y, r.width, r.height);
181 void query_padding(padding_t p, FILE *rsp)
183 fprintf(rsp, "{\"top\":%i,\"right\":%i,\"bottom\":%i,\"left\":%i}", p.top, p.right, p.bottom, p.left);
186 void query_history(FILE *rsp)
189 for (history_t *h = history_head; h != NULL; h = h->next) {
190 query_coordinates(&h->loc, rsp);
191 if (h->next != NULL) {
198 void query_coordinates(coordinates_t *loc, FILE *rsp)
200 fprintf(rsp, "{\"monitorId\":%u,\"desktopId\":%u,\"nodeId\":%u}", loc->monitor->id, loc->desktop->id, loc->node!=NULL?loc->node->id:0);
203 void query_stack(FILE *rsp)
206 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
207 fprintf(rsp, "%u", s->node->id);
208 if (s->next != NULL) {
215 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp)
218 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
219 if (trg->monitor != NULL && m != trg->monitor) {
222 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
223 if (trg->desktop != NULL && d != trg->desktop) {
226 count += query_node_ids_in(d->root, d, m, ref, trg, sel, rsp);
232 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)
238 coordinates_t loc = {m, d, n};
239 if ((trg->node == NULL || n == trg->node) &&
240 (sel == NULL || node_matches(&loc, ref, *sel))) {
241 fprintf(rsp, "0x%08X\n", n->id);
244 count += query_node_ids_in(n->first_child, d, m, ref, trg, sel, rsp);
245 count += query_node_ids_in(n->second_child, d, m, ref, trg, sel, rsp);
250 int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
253 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
254 if (trg->monitor != NULL && m != trg->monitor) {
257 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
258 coordinates_t loc = {m, d, NULL};
259 if ((trg->desktop != NULL && d != trg->desktop) ||
260 (sel != NULL && !desktop_matches(&loc, ref, *sel))) {
270 int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
273 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
274 coordinates_t loc = {m, NULL, NULL};
275 if ((trg->monitor != NULL && m != trg->monitor) ||
276 (sel != NULL && !monitor_matches(&loc, ref, *sel))) {
285 void fprint_monitor_id(monitor_t *m, FILE *rsp)
287 fprintf(rsp, "0x%08X\n", m->id);
290 void fprint_monitor_name(monitor_t *m, FILE *rsp)
292 fprintf(rsp, "%s\n", m->name);
295 void fprint_desktop_id(desktop_t *d, FILE *rsp)
297 fprintf(rsp, "0x%08X\n", d->id);
300 void fprint_desktop_name(desktop_t *d, FILE *rsp)
302 fprintf(rsp, "%s\n", d->name);
305 void print_modifier_mask(uint16_t m, FILE *rsp)
308 case XCB_MOD_MASK_SHIFT:
309 fprintf(rsp, "shift");
311 case XCB_MOD_MASK_CONTROL:
312 fprintf(rsp, "control");
314 case XCB_MOD_MASK_LOCK:
315 fprintf(rsp, "lock");
318 fprintf(rsp, "mod1");
321 fprintf(rsp, "mod2");
324 fprintf(rsp, "mod3");
327 fprintf(rsp, "mod4");
330 fprintf(rsp, "mod5");
335 void print_pointer_action(pointer_action_t a, FILE *rsp)
339 fprintf(rsp, "move");
341 case ACTION_RESIZE_SIDE:
342 fprintf(rsp, "resize_side");
344 case ACTION_RESIZE_CORNER:
345 fprintf(rsp, "resize_corner");
348 fprintf(rsp, "focus");
351 fprintf(rsp, "none");
356 node_select_t make_node_select(void)
358 node_select_t sel = {
359 .automatic = OPTION_NONE,
360 .focused = OPTION_NONE,
361 .local = OPTION_NONE,
362 .active = OPTION_NONE,
364 .window = OPTION_NONE,
365 .tiled = OPTION_NONE,
366 .pseudo_tiled = OPTION_NONE,
367 .floating = OPTION_NONE,
368 .fullscreen = OPTION_NONE,
369 .hidden = OPTION_NONE,
370 .sticky = OPTION_NONE,
371 .private = OPTION_NONE,
372 .locked = OPTION_NONE,
373 .urgent = OPTION_NONE,
374 .same_class = OPTION_NONE,
375 .descendant_of = OPTION_NONE,
376 .ancestor_of = OPTION_NONE,
377 .below = OPTION_NONE,
378 .normal = OPTION_NONE,
384 desktop_select_t make_desktop_select(void)
386 desktop_select_t sel = {
387 .occupied = OPTION_NONE,
388 .focused = OPTION_NONE,
389 .urgent = OPTION_NONE,
395 monitor_select_t make_monitor_select(void)
397 monitor_select_t sel = {
398 .occupied = OPTION_NONE,
399 .focused = OPTION_NONE
404 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
406 coordinates_t ref_copy = *ref;
408 char *desc_copy = copy_string(desc, strlen(desc));
412 char *path = strrchr(desc, '@');
414 hash = strrchr(desc, '#');
416 if (path != desc && *(path - 1) == '#') {
424 coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
425 if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
433 node_select_t sel = make_node_select();
434 char *colon = strrchr(desc, ':');
436 if (!parse_node_modifiers(colon != NULL ? colon : desc, &sel)) {
438 return SELECTOR_BAD_MODIFIERS;
446 if (parse_direction(desc, &dir)) {
447 find_nearest_neighbor(ref, dst, dir, sel);
448 } else if (parse_cycle_direction(desc, &cyc)) {
449 find_closest_node(ref, dst, cyc, sel);
450 } else if (parse_history_direction(desc, &hdi)) {
451 history_find_node(hdi, ref, dst, sel);
452 } else if (streq("last", desc)) {
453 history_find_node(HISTORY_OLDER, ref, dst, sel);
454 } else if (streq("biggest", desc)) {
455 find_biggest(ref, dst, sel);
456 } else if (streq("pointed", desc)) {
457 xcb_window_t win = XCB_NONE;
458 query_pointer(&win, NULL);
459 if (locate_window(win, dst) && node_matches(dst, ref, sel)) {
462 return SELECTOR_INVALID;
464 } else if (streq("focused", desc)) {
465 coordinates_t loc = {mon, mon->desk, mon->desk->focus};
466 if (node_matches(&loc, ref, sel)) {
469 } else if (*desc == '@') {
475 if ((ret = desktop_from_desc(desc, ref, dst)) == SELECTOR_OK) {
476 dst->node = dst->desktop->focus;
484 dst->node = dst->desktop->root;
486 char *move = strtok(desc, PTH_TOK);
487 while (move != NULL && dst->node != NULL) {
488 if (streq("first", move) || streq("1", move)) {
489 dst->node = dst->node->first_child;
490 } else if (streq("second", move) || streq("2", move)) {
491 dst->node = dst->node->second_child;
492 } else if (streq("parent", move)) {
493 dst->node = dst->node->parent;
494 } else if (streq("brother", move)) {
495 dst->node = brother_tree(dst->node);
498 if (parse_direction(move, &dir)) {
499 dst->node = find_fence(dst->node, dir);
502 return SELECTOR_BAD_DESCRIPTOR;
505 move = strtok(NULL, PTH_TOK);
508 if (dst->node != NULL) {
509 if (node_matches(dst, ref, sel)) {
512 return SELECTOR_INVALID;
514 } else if (dst->desktop->root != NULL) {
515 return SELECTOR_INVALID;
520 if (parse_id(desc, &id)) {
522 if (find_by_id(id, dst) && node_matches(dst, ref, sel)) {
525 return SELECTOR_INVALID;
529 return SELECTOR_BAD_DESCRIPTOR;
535 if (dst->node == NULL) {
536 return SELECTOR_INVALID;
542 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
544 coordinates_t ref_copy = *ref;
546 char *desc_copy = copy_string(desc, strlen(desc));
549 char *hash = strrchr(desc, '#');
554 coordinates_t tmp = {mon, mon->desk, NULL};
555 if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
563 desktop_select_t sel = make_desktop_select();
564 char *colon = strrchr(desc, ':');
566 if (!parse_desktop_modifiers(colon != NULL ? colon : desc, &sel)) {
568 return SELECTOR_BAD_MODIFIERS;
577 if (parse_cycle_direction(desc, &cyc)) {
578 find_closest_desktop(ref, dst, cyc, sel);
579 } else if (parse_history_direction(desc, &hdi)) {
580 history_find_desktop(hdi, ref, dst, sel);
581 } else if (streq("last", desc)) {
582 history_find_desktop(HISTORY_OLDER, ref, dst, sel);
583 } else if (streq("focused", desc)) {
584 coordinates_t loc = {mon, mon->desk, NULL};
585 if (desktop_matches(&loc, ref, sel)) {
588 } else if (colon != NULL) {
591 if ((ret = monitor_from_desc(desc, ref, dst)) == SELECTOR_OK) {
592 if (streq("focused", colon + 1)) {
593 coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
594 if (desktop_matches(&loc, ref, sel)) {
597 } else if (parse_index(colon + 1, &idx)) {
599 if (desktop_from_index(idx, dst, dst->monitor) && desktop_matches(dst, ref, sel)) {
602 return SELECTOR_INVALID;
606 return SELECTOR_BAD_DESCRIPTOR;
612 } else if (parse_index(desc, &idx) && desktop_from_index(idx, dst, NULL)) {
614 if (desktop_matches(dst, ref, sel)) {
617 return SELECTOR_INVALID;
619 } else if (parse_id(desc, &id) && desktop_from_id(id, dst, NULL)) {
621 if (desktop_matches(dst, ref, sel)) {
624 return SELECTOR_INVALID;
627 if (locate_desktop(desc, dst)) {
629 if (desktop_matches(dst, ref, sel)) {
632 return SELECTOR_INVALID;
636 return SELECTOR_BAD_DESCRIPTOR;
642 if (dst->desktop == NULL) {
643 return SELECTOR_INVALID;
649 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
651 coordinates_t ref_copy = *ref;
653 char *desc_copy = copy_string(desc, strlen(desc));
656 char *hash = strrchr(desc, '#');
661 coordinates_t tmp = {mon, NULL, NULL};
662 if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
670 monitor_select_t sel = make_monitor_select();
672 if (!parse_monitor_modifiers(desc, &sel)) {
674 return SELECTOR_BAD_MODIFIERS;
684 if (parse_direction(desc, &dir)) {
685 dst->monitor = nearest_monitor(ref->monitor, dir, sel);
686 } else if (parse_cycle_direction(desc, &cyc)) {
687 dst->monitor = closest_monitor(ref->monitor, cyc, sel);
688 } else if (parse_history_direction(desc, &hdi)) {
689 history_find_monitor(hdi, ref, dst, sel);
690 } else if (streq("last", desc)) {
691 history_find_monitor(HISTORY_OLDER, ref, dst, sel);
692 } else if (streq("primary", desc)) {
693 if (pri_mon != NULL) {
694 coordinates_t loc = {pri_mon, NULL, NULL};
695 if (monitor_matches(&loc, ref, sel)) {
696 dst->monitor = pri_mon;
699 } else if (streq("focused", desc)) {
700 coordinates_t loc = {mon, NULL, NULL};
701 if (monitor_matches(&loc, ref, sel)) {
704 } else if (parse_index(desc, &idx) && monitor_from_index(idx, dst)) {
706 if (monitor_matches(dst, ref, sel)) {
709 return SELECTOR_INVALID;
711 } else if (parse_id(desc, &id) && monitor_from_id(id, dst)) {
713 if (monitor_matches(dst, ref, sel)) {
716 return SELECTOR_INVALID;
719 if (locate_monitor(desc, dst)) {
721 if (monitor_matches(dst, ref, sel)) {
724 return SELECTOR_INVALID;
728 return SELECTOR_BAD_DESCRIPTOR;
734 if (dst->monitor == NULL) {
735 return SELECTOR_INVALID;
741 bool locate_window(xcb_window_t win, coordinates_t *loc)
743 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
744 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
745 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
746 if (n->client == NULL) {
761 bool locate_desktop(char *name, coordinates_t *loc)
763 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
764 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
765 if (streq(d->name, name)) {
775 bool locate_monitor(char *name, coordinates_t *loc)
777 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
778 if (streq(m->name, name)) {
786 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
788 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
789 if (mm != NULL && m != mm) {
792 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
804 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
806 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
807 if (mm != NULL && m != mm) {
810 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, idx--) {
822 bool monitor_from_id(uint32_t id, coordinates_t *loc)
824 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
835 bool monitor_from_index(int idx, coordinates_t *loc)
837 for (monitor_t *m = mon_head; m != NULL; m = m->next, idx--) {
848 bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t sel)
850 if (loc->node == NULL) {
854 if (sel.focused != OPTION_NONE &&
855 loc->node != loc->desktop->focus
856 ? sel.focused == OPTION_TRUE
857 : sel.focused == OPTION_FALSE) {
861 if (sel.automatic != OPTION_NONE &&
862 loc->node->presel != NULL
863 ? sel.automatic == OPTION_TRUE
864 : sel.automatic == OPTION_FALSE) {
868 if (sel.local != OPTION_NONE &&
869 loc->desktop != ref->desktop
870 ? sel.local == OPTION_TRUE
871 : sel.local == OPTION_FALSE) {
875 if (sel.active != OPTION_NONE &&
876 loc->desktop != loc->monitor->desk
877 ? sel.active == OPTION_TRUE
878 : sel.active == OPTION_FALSE) {
882 if (sel.leaf != OPTION_NONE &&
884 ? sel.leaf == OPTION_TRUE
885 : sel.leaf == OPTION_FALSE) {
889 if (sel.window != OPTION_NONE &&
890 loc->node->client == NULL
891 ? sel.window == OPTION_TRUE
892 : sel.window == OPTION_FALSE) {
897 if (sel.p != OPTION_NONE && \
899 ? sel.p == OPTION_TRUE \
900 : sel.p == OPTION_FALSE) { \
909 if (loc->node->client == NULL &&
910 (sel.same_class != OPTION_NONE ||
911 sel.tiled != OPTION_NONE ||
912 sel.pseudo_tiled != OPTION_NONE ||
913 sel.floating != OPTION_NONE ||
914 sel.fullscreen != OPTION_NONE ||
915 sel.below != OPTION_NONE ||
916 sel.normal != OPTION_NONE ||
917 sel.above != OPTION_NONE ||
918 sel.urgent != OPTION_NONE)) {
922 if (ref->node != NULL && ref->node->client != NULL &&
923 sel.same_class != OPTION_NONE &&
924 streq(loc->node->client->class_name, ref->node->client->class_name)
925 ? sel.same_class == OPTION_FALSE
926 : sel.same_class == OPTION_TRUE) {
930 if (sel.descendant_of != OPTION_NONE &&
931 !is_descendant(loc->node, ref->node)
932 ? sel.descendant_of == OPTION_TRUE
933 : sel.descendant_of == OPTION_FALSE) {
937 if (sel.ancestor_of != OPTION_NONE &&
938 !is_descendant(ref->node, loc->node)
939 ? sel.ancestor_of == OPTION_TRUE
940 : sel.ancestor_of == OPTION_FALSE) {
944 #define WSTATE(p, e) \
945 if (sel.p != OPTION_NONE && \
946 loc->node->client->state != e \
947 ? sel.p == OPTION_TRUE \
948 : sel.p == OPTION_FALSE) { \
951 WSTATE(tiled, STATE_TILED)
952 WSTATE(pseudo_tiled, STATE_PSEUDO_TILED)
953 WSTATE(floating, STATE_FLOATING)
954 WSTATE(fullscreen, STATE_FULLSCREEN)
957 #define WLAYER(p, e) \
958 if (sel.p != OPTION_NONE && \
959 loc->node->client->layer != e \
960 ? sel.p == OPTION_TRUE \
961 : sel.p == OPTION_FALSE) { \
964 WLAYER(below, LAYER_BELOW)
965 WLAYER(normal, LAYER_NORMAL)
966 WLAYER(above, LAYER_ABOVE)
970 if (sel.p != OPTION_NONE && \
971 !loc->node->client->p \
972 ? sel.p == OPTION_TRUE \
973 : sel.p == OPTION_FALSE) { \
982 bool desktop_matches(coordinates_t *loc, coordinates_t *ref, desktop_select_t sel)
984 if (sel.occupied != OPTION_NONE &&
985 loc->desktop->root == NULL
986 ? sel.occupied == OPTION_TRUE
987 : sel.occupied == OPTION_FALSE) {
991 if (sel.focused != OPTION_NONE &&
992 loc->desktop != loc->monitor->desk
993 ? sel.focused == OPTION_TRUE
994 : sel.focused == OPTION_FALSE) {
998 if (sel.urgent != OPTION_NONE &&
999 !is_urgent(loc->desktop)
1000 ? sel.urgent == OPTION_TRUE
1001 : sel.urgent == OPTION_FALSE) {
1005 if (sel.local != OPTION_NONE &&
1006 ref->monitor != loc->monitor
1007 ? sel.local == OPTION_TRUE
1008 : sel.local == OPTION_FALSE) {
1015 bool monitor_matches(coordinates_t *loc, __attribute__((unused)) coordinates_t *ref, monitor_select_t sel)
1017 if (sel.occupied != OPTION_NONE &&
1018 loc->monitor->desk->root == NULL
1019 ? sel.occupied == OPTION_TRUE
1020 : sel.occupied == OPTION_FALSE) {
1024 if (sel.focused != OPTION_NONE &&
1026 ? sel.focused == OPTION_TRUE
1027 : sel.focused == OPTION_FALSE) {