]> Dogcows Code - chaz/openbox/blob - openbox/stacking.c
support for transients of groups
[chaz/openbox] / openbox / stacking.c
1 #include "openbox.h"
2 #include "prop.h"
3 #include "focus.h"
4 #include "client.h"
5 #include "group.h"
6 #include "frame.h"
7 #include <glib.h>
8
9 GList *stacking_list = NULL;
10
11 void stacking_set_list()
12 {
13 Window *windows, *win_it;
14 GList *it;
15 guint size = g_list_length(stacking_list);
16
17 /* on shutdown, don't update the properties, so that we can read it back
18 in on startup and re-stack the windows as they were before we shut down
19 */
20 if (ob_state == State_Exiting) return;
21
22 /* create an array of the window ids (from bottom to top,
23 reverse order!) */
24 if (size > 0) {
25 windows = g_new(Window, size);
26 win_it = windows;
27 for (it = g_list_last(stacking_list); it != NULL;
28 it = it->prev, ++win_it)
29 *win_it = ((Client*)it->data)->window;
30 } else
31 windows = NULL;
32
33 PROP_SET32A(ob_root, net_client_list_stacking, window, windows, size);
34
35 if (windows)
36 g_free(windows);
37 }
38
39 void stacking_raise(Client *client)
40 {
41 Window wins[2]; /* only ever restack 2 windows. */
42 GList *it;
43 Client *m;
44
45 g_assert(stacking_list != NULL); /* this would be bad */
46
47 m = client_find_modal_child(client);
48 /* if we have a modal child, raise it instead, we'll go along tho later */
49 if (m) stacking_raise(m);
50
51 /* remove the client before looking so we can't run into ourselves */
52 stacking_list = g_list_remove(stacking_list, client);
53
54 /* the stacking list is from highest to lowest */
55 it = stacking_list;
56 while (it != NULL) {
57 Client *c = it->data;
58 if (client->layer >= c->layer && m != c)
59 break;
60 it = it->next;
61 }
62
63 /*
64 if our new position is the top, we want to stack under the focus_backup.
65 otherwise, we want to stack under the previous window in the stack.
66 */
67 if (it == stacking_list)
68 wins[0] = focus_backup;
69 else if (it != NULL)
70 wins[0] = ((Client*)it->prev->data)->frame->window;
71 else
72 wins[0] = ((Client*)g_list_last(stacking_list)->data)->frame->window;
73 wins[1] = client->frame->window;
74
75 stacking_list = g_list_insert_before(stacking_list, it, client);
76
77 XRestackWindows(ob_display, wins, 2);
78
79 stacking_set_list();
80 }
81
82 void stacking_lower(Client *client)
83 {
84 Window wins[2]; /* only ever restack 2 windows. */
85 GList *it;
86
87 g_assert(stacking_list != NULL); /* this would be bad */
88
89 if (client->modal && client->transient_for) {
90 if (client->transient_for == TRAN_GROUP) {
91 /* don't let a modal of the group lower below any other windows
92 in the group */
93 for (it = stacking_list; it; it = it->next) {
94 GSList *sit;
95 Client *c = it->data;
96
97 for (sit = c->group->members; sit; sit = sit->next)
98 if (sit->data == it->data) break;
99 if (sit) break; /* got it */
100 }
101 if (it == NULL)
102 goto lower_no_parent;
103 } else {
104 /* don't let a modal window lower below its transient_for */
105 it = g_list_find(stacking_list, client->transient_for);
106 }
107 g_assert(it != NULL);
108
109 wins[0] = (it == stacking_list ? focus_backup :
110 ((Client*)it->prev->data)->frame->window);
111 wins[1] = client->frame->window;
112 if (wins[0] == wins[1]) return; /* already right above the window */
113
114 stacking_list = g_list_remove(stacking_list, client);
115 stacking_list = g_list_insert_before(stacking_list, it, client);
116 } else {
117 lower_no_parent:
118
119 it = g_list_last(stacking_list);
120
121 while (it != stacking_list) {
122 Client *c = it->data;
123 if (client->layer <= c->layer)
124 break;
125 it = it->prev;
126 }
127 if (it->data == client) return; /* already the bottom, return */
128
129 wins[0] = ((Client*)it->data)->frame->window;
130 wins[1] = client->frame->window;
131
132 stacking_list = g_list_remove(stacking_list, client);
133 stacking_list = g_list_insert_before(stacking_list,
134 it->next, client);
135 }
136
137 XRestackWindows(ob_display, wins, 2);
138 stacking_set_list();
139 }
140
This page took 0.044089 seconds and 5 git commands to generate.