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