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.
28 #include "subscribe.h"
33 stacking_list_t *make_stack(node_t *n)
35 stacking_list_t *s = calloc(1, sizeof(stacking_list_t));
37 s->prev = s->next = NULL;
41 void stack_insert_after(stacking_list_t *a, node_t *n)
43 stacking_list_t *s = make_stack(n);
45 stack_head = stack_tail = s;
52 stacking_list_t *b = a->next;
59 if (stack_tail == a) {
65 void stack_insert_before(stacking_list_t *a, node_t *n)
67 stacking_list_t *s = make_stack(n);
69 stack_head = stack_tail = s;
76 stacking_list_t *b = a->prev;
83 if (stack_head == a) {
89 void remove_stack(stacking_list_t *s)
94 stacking_list_t *a = s->prev;
95 stacking_list_t *b = s->next;
102 if (s == stack_head) {
105 if (s == stack_tail) {
111 void remove_stack_node(node_t *n)
113 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
114 for (stacking_list_t *s = stack_head; s != NULL; s = s->next) {
123 int stack_level(client_t *c)
125 int layer_level = (c->layer == LAYER_NORMAL ? 1 : (c->layer == LAYER_BELOW ? 0 : 2));
126 int state_level = (IS_TILED(c) ? 0 : (IS_FLOATING(c) ? 1 : 2));
127 return 3 * layer_level + state_level;
130 int stack_cmp(client_t *c1, client_t *c2)
132 return stack_level(c1) - stack_level(c2);
135 stacking_list_t *limit_above(node_t *n)
137 stacking_list_t *s = stack_head;
138 while (s != NULL && stack_cmp(n->client, s->node->client) >= 0) {
150 stacking_list_t *limit_below(node_t *n)
152 stacking_list_t *s = stack_tail;
153 while (s != NULL && stack_cmp(n->client, s->node->client) <= 0) {
165 void stack(desktop_t *d, node_t *n, bool focused)
167 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
168 if (f->client == NULL || (IS_FLOATING(f->client) && !auto_raise)) {
172 if (stack_head == NULL) {
173 stack_insert_after(NULL, f);
175 stacking_list_t *s = (focused ? limit_above(f) : limit_below(f));
179 int i = stack_cmp(f->client, s->node->client);
180 if (i < 0 || (i == 0 && !focused)) {
181 stack_insert_before(s, f);
182 window_below(f->id, s->node->id);
183 put_status(SBSC_MASK_NODE_STACK, "node_stack 0x%08X below 0x%08X\n", f->id, s->node->id);
185 stack_insert_after(s, f);
186 window_above(f->id, s->node->id);
187 put_status(SBSC_MASK_NODE_STACK, "node_stack 0x%08X above 0x%08X\n", f->id, s->node->id);
192 ewmh_update_client_list(true);
193 restack_presel_feedbacks(d);
196 void restack_presel_feedbacks(desktop_t *d)
198 stacking_list_t *s = stack_tail;
199 while (s != NULL && !IS_TILED(s->node->client)) {
203 restack_presel_feedbacks_in(d->root, s->node);
207 void restack_presel_feedbacks_in(node_t *r, node_t *n)
212 if (r->presel != NULL) {
213 window_above(r->presel->feedback, n->id);
215 restack_presel_feedbacks_in(r->first_child, n);
216 restack_presel_feedbacks_in(r->second_child, n);