1 /* Copyright (c) 2012-2014, 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.
24 * The views and conclusions contained in the software and documentation are those
25 * of the authors and should not be interpreted as representing official policies,
26 * either expressed or implied, of the FreeBSD Project.
34 stacking_list_t *make_stack(node_t *n)
36 stacking_list_t *s = malloc(sizeof(stacking_list_t));
38 s->prev = s->next = NULL;
42 void stack_insert_after(stacking_list_t *a, node_t *n)
44 stacking_list_t *s = make_stack(n);
46 stack_head = stack_tail = s;
51 stacking_list_t *b = a->next;
62 void stack_insert_before(stacking_list_t *a, node_t *n)
64 stacking_list_t *s = make_stack(n);
66 stack_head = stack_tail = s;
71 stacking_list_t *b = a->prev;
82 void remove_stack(stacking_list_t *s)
86 stacking_list_t *a = s->prev;
87 stacking_list_t *b = s->next;
99 void remove_stack_node(node_t *n)
101 for (stacking_list_t *s = stack_head; s != NULL; s = s->next)
108 void stack(node_t *n, stack_flavor_t f)
110 PRINTF("stack %X\n", n->client->window);
112 if (stack_head == NULL) {
113 stack_insert_after(NULL, n);
114 } else if (n->client->fullscreen) {
115 if (f == STACK_ABOVE) {
116 stack_insert_after(stack_tail, n);
117 window_raise(n->client->window);
120 if (f == STACK_ABOVE && n->client->floating && !auto_raise)
122 stacking_list_t *latest_tiled = NULL;
123 stacking_list_t *oldest_floating = NULL;
124 stacking_list_t *oldest_fullscreen = NULL;
125 for (stacking_list_t *s = (f == STACK_ABOVE ? stack_tail : stack_head); s != NULL; s = (f == STACK_ABOVE ? s->prev : s->next)) {
127 if (s->node->client->fullscreen) {
128 if (oldest_fullscreen == NULL)
129 oldest_fullscreen = s;
132 if (s->node->client->floating == n->client->floating) {
133 if (f == STACK_ABOVE) {
134 stack_insert_after(s, n);
135 window_above(n->client->window, s->node->client->window);
137 stack_insert_before(s, n);
138 window_below(n->client->window, s->node->client->window);
141 } else if ((f != STACK_ABOVE || latest_tiled == NULL) && !s->node->client->floating) {
143 } else if ((f == STACK_ABOVE || oldest_floating == NULL) && s->node->client->floating) {
148 if (latest_tiled == NULL && oldest_floating == NULL && oldest_fullscreen == NULL)
150 if (n->client->floating) {
151 if (latest_tiled != NULL) {
152 window_above(n->client->window, latest_tiled->node->client->window);
153 stack_insert_after(latest_tiled, n);
154 } else if (oldest_fullscreen != NULL) {
155 window_below(n->client->window, oldest_fullscreen->node->client->window);
156 stack_insert_before(oldest_fullscreen, n);
159 if (oldest_floating != NULL) {
160 window_below(n->client->window, oldest_floating->node->client->window);
161 stack_insert_before(oldest_floating, n);
162 } else if (oldest_fullscreen != NULL) {
163 window_below(n->client->window, oldest_fullscreen->node->client->window);
164 stack_insert_before(oldest_fullscreen, n);