forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
202 lines (177 loc) · 5.56 KB
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* stack.c - client stack management
*
* Copyright © 2008-2009 Julien Danjou <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "stack.h"
#include "ewmh.h"
#include "objects/client.h"
#include "objects/drawin.h"
void
stack_client_remove(client_t *c)
{
foreach(client, globalconf.stack)
if(*client == c)
{
client_array_remove(&globalconf.stack, client);
break;
}
ewmh_update_net_client_list_stacking();
stack_windows();
}
/** Push the client at the beginning of the client stack.
* \param c The client to push.
*/
void
stack_client_push(client_t *c)
{
stack_client_remove(c);
client_array_push(&globalconf.stack, c);
ewmh_update_net_client_list_stacking();
stack_windows();
}
/** Push the client at the end of the client stack.
* \param c The client to push.
*/
void
stack_client_append(client_t *c)
{
stack_client_remove(c);
client_array_append(&globalconf.stack, c);
ewmh_update_net_client_list_stacking();
stack_windows();
}
static bool need_stack_refresh = false;
void
stack_windows(void)
{
need_stack_refresh = true;
}
/** Stack a window above another window, without causing errors.
* \param w The window.
* \param previous The window which should be below this window.
*/
static void
stack_window_above(xcb_window_t w, xcb_window_t previous)
{
if (previous == XCB_NONE)
/* This would cause an error from the X server. Also, if we really
* changed the stacking order of all windows, they'd all have to redraw
* themselves. Doing it like this is better. */
return;
xcb_configure_window(globalconf.connection, w,
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
(uint32_t[]) { previous, XCB_STACK_MODE_ABOVE });
}
/** Stack a client above.
* \param c The client.
* \param previous The previous client on the stack.
* \return The next-previous!
*/
static xcb_window_t
stack_client_above(client_t *c, xcb_window_t previous)
{
stack_window_above(c->frame_window, previous);
previous = c->frame_window;
/* stack transient window on top of their parents */
foreach(node, globalconf.stack)
if((*node)->transient_for == c)
previous = stack_client_above(*node, previous);
return previous;
}
/** Stacking layout layers */
typedef enum
{
/** This one is a special layer */
WINDOW_LAYER_IGNORE,
WINDOW_LAYER_DESKTOP,
WINDOW_LAYER_BELOW,
WINDOW_LAYER_NORMAL,
WINDOW_LAYER_ABOVE,
WINDOW_LAYER_FULLSCREEN,
WINDOW_LAYER_ONTOP,
/** This one only used for counting and is not a real layer */
WINDOW_LAYER_COUNT
} window_layer_t;
/** Get the real layer of a client according to its attribute (fullscreen, …)
* \param c The client.
* \return The real layer.
*/
static window_layer_t
client_layer_translator(client_t *c)
{
/* first deal with user set attributes */
if(c->ontop)
return WINDOW_LAYER_ONTOP;
/* Fullscreen windows only get their own layer when they have the focus */
else if(c->fullscreen && globalconf.focus.client == c)
return WINDOW_LAYER_FULLSCREEN;
else if(c->above)
return WINDOW_LAYER_ABOVE;
else if(c->below)
return WINDOW_LAYER_BELOW;
/* check for transient attr */
else if(c->transient_for)
return WINDOW_LAYER_IGNORE;
/* then deal with windows type */
switch(c->type)
{
case WINDOW_TYPE_DESKTOP:
return WINDOW_LAYER_DESKTOP;
default:
break;
}
return WINDOW_LAYER_NORMAL;
}
/** Restack clients.
* \todo It might be worth stopping to restack everyone and only stack `c'
* relatively to the first matching in the list.
*/
void
stack_refresh()
{
if(!need_stack_refresh)
return;
xcb_window_t next = XCB_NONE;
/* stack desktop windows */
for(window_layer_t layer = WINDOW_LAYER_DESKTOP; layer < WINDOW_LAYER_BELOW; layer++)
foreach(node, globalconf.stack)
if(client_layer_translator(*node) == layer)
next = stack_client_above(*node, next);
/* first stack not ontop drawin window */
foreach(drawin, globalconf.drawins)
if(!(*drawin)->ontop)
{
stack_window_above((*drawin)->window, next);
next = (*drawin)->window;
}
/* then stack clients */
for(window_layer_t layer = WINDOW_LAYER_BELOW; layer < WINDOW_LAYER_COUNT; layer++)
foreach(node, globalconf.stack)
if(client_layer_translator(*node) == layer)
next = stack_client_above(*node, next);
/* then stack ontop drawin window */
foreach(drawin, globalconf.drawins)
if((*drawin)->ontop)
{
stack_window_above((*drawin)->window, next);
next = (*drawin)->window;
}
need_stack_refresh = false;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80