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
|
#include "openbox.h"
#include "prop.h"
#include "focus.h"
#include "client.h"
#include "frame.h"
#include <glib.h>
GList *stacking_list = NULL;
void stacking_set_list()
{
Window *windows, *win_it;
GList *it;
guint size = g_list_length(stacking_list);
/* on shutdown, don't update the properties, so that we can read it back
in on startup and re-stack the windows as they were before we shut down
*/
if (ob_state == State_Exiting) return;
/* create an array of the window ids (from bottom to top,
reverse order!) */
if (size > 0) {
windows = g_new(Window, size);
win_it = windows;
for (it = g_list_last(stacking_list); it != NULL;
it = it->prev, ++win_it)
*win_it = ((Client*)it->data)->window;
} else
windows = NULL;
PROP_SET32A(ob_root, net_client_list_stacking, window, windows, size);
if (windows)
g_free(windows);
}
void stacking_raise(Client *client)
{
Window wins[2]; /* only ever restack 2 windows. */
GList *it;
Client *m;
g_assert(stacking_list != NULL); /* this would be bad */
m = client_find_modal_child(client);
/* if we have a modal child, raise it instead, we'll go along tho later */
if (m) stacking_raise(m);
/* remove the client before looking so we can't run into ourselves */
stacking_list = g_list_remove(stacking_list, client);
/* the stacking list is from highest to lowest */
it = stacking_list;
while (it != NULL) {
Client *c = it->data;
if (client->layer >= c->layer && m != c)
break;
it = it->next;
}
/*
if our new position is the top, we want to stack under the focus_backup.
otherwise, we want to stack under the previous window in the stack.
*/
if (it == stacking_list)
wins[0] = focus_backup;
else if (it != NULL)
wins[0] = ((Client*)it->prev->data)->frame->window;
else
wins[0] = ((Client*)g_list_last(stacking_list)->data)->frame->window;
wins[1] = client->frame->window;
stacking_list = g_list_insert_before(stacking_list, it, client);
XRestackWindows(ob_display, wins, 2);
stacking_set_list();
}
void stacking_lower(Client *client)
{
Window wins[2]; /* only ever restack 2 windows. */
GList *it;
g_assert(stacking_list != NULL); /* this would be bad */
it = g_list_last(stacking_list);
if (client->modal && client->transient_for) {
/* don't let a modal window lower below its transient_for */
it = g_list_find(stacking_list, client->transient_for);
g_assert(it != NULL);
wins[0] = (it == stacking_list ? focus_backup :
((Client*)it->prev->data)->frame->window);
wins[1] = client->frame->window;
if (wins[0] == wins[1]) return; /* already right above the window */
stacking_list = g_list_remove(stacking_list, client);
stacking_list = g_list_insert_before(stacking_list, it, client);
} else {
while (it != stacking_list) {
Client *c = it->data;
if (client->layer <= c->layer)
break;
it = it->prev;
}
if (it->data == client) return; /* already the bottom, return */
wins[0] = ((Client*)it->data)->frame->window;
wins[1] = client->frame->window;
stacking_list = g_list_remove(stacking_list, client);
stacking_list = g_list_insert_before(stacking_list,
it->next, client);
}
XRestackWindows(ob_display, wins, 2);
stacking_set_list();
}
|