1 /* * Copyright (c) 2012-2013 Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation and/or
11 * other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 ON
20 * 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.
30 stacking_list_t *make_stack(node_t *n)
32 stacking_list_t *s = malloc(sizeof(stacking_list_t));
34 s->prev = s->next = NULL;
38 void stack_insert_after(stacking_list_t *a, node_t *n)
40 stacking_list_t *s = make_stack(n);
42 stack_head = stack_tail = s;
45 stacking_list_t *b = a->next;
56 void stack_insert_before(stacking_list_t *a, node_t *n)
58 stacking_list_t *s = make_stack(n);
60 stack_head = stack_tail = s;
63 stacking_list_t *b = a->prev;
74 void remove_stack(stacking_list_t *s)
78 stacking_list_t *a = s->prev;
79 stacking_list_t *b = s->next;
91 void remove_stack_node(node_t *n)
93 for (stacking_list_t *s = stack_head; s != NULL; s = s->next)
100 void stack(node_t *n, stack_flavor_t f)
102 PRINTF("stack %X\n", n->client->window);
104 if (stack_head == NULL) {
105 stack_insert_after(NULL, n);
106 } else if (n->client->fullscreen) {
107 if (f == STACK_ABOVE) {
108 stack_insert_after(stack_tail, n);
109 window_raise(n->client->window);
112 if (f == STACK_ABOVE && n->client->floating && !auto_raise)
114 stacking_list_t *latest_tiled = NULL;
115 stacking_list_t *oldest_floating = NULL;
116 for (stacking_list_t *s = (f == STACK_ABOVE ? stack_tail : stack_head); s != NULL; s = (f == STACK_ABOVE ? s->prev : s->next)) {
118 if (s->node->client->floating == n->client->floating) {
119 if (f == STACK_ABOVE) {
120 stack_insert_after(s, n);
121 window_above(n->client->window, s->node->client->window);
123 stack_insert_before(s, n);
124 window_below(n->client->window, s->node->client->window);
127 } else if ((f != STACK_ABOVE || latest_tiled == NULL) && !s->node->client->floating) {
129 } else if ((f == STACK_ABOVE || oldest_floating == NULL) && s->node->client->floating) {
134 if (latest_tiled == NULL && oldest_floating == NULL)
136 if (n->client->floating) {
137 if (latest_tiled == NULL)
139 window_above(n->client->window, latest_tiled->node->client->window);
140 stack_insert_after(latest_tiled, n);
142 if (oldest_floating == NULL)
144 window_below(n->client->window, oldest_floating->node->client->window);
145 stack_insert_before(oldest_floating, n);