]> Dogcows Code - chaz/openbox/blob - openbox/stacking.c
put focus_cycle into focus.c, use it there in the action. improved it as well to...
[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 XRestackWindows(ob_display, wins, 2);
77
78 stacking_set_list();
79 }
80
81 void stacking_lower(Client *client)
82 {
83 Window wins[2]; /* only ever restack 2 windows. */
84 GList *it;
85
86 g_assert(stacking_list != NULL); /* this would be bad */
87
88 it = g_list_last(stacking_list);
89
90 if (client->modal && client->transient_for) {
91 /* don't let a modal window lower below its transient_for */
92 it = g_list_find(stacking_list, client->transient_for);
93 g_assert(it != NULL);
94
95 wins[0] = (it == stacking_list ? focus_backup :
96 ((Client*)it->prev->data)->frame->window);
97 wins[1] = client->frame->window;
98 if (wins[0] == wins[1]) return; /* already right above the window */
99
100 stacking_list = g_list_remove(stacking_list, client);
101 stacking_list = g_list_insert_before(stacking_list, it, client);
102 } else {
103 while (it != stacking_list) {
104 Client *c = it->data;
105 if (client->layer <= c->layer)
106 break;
107 it = it->prev;
108 }
109 if (it->data == client) return; /* already the bottom, return */
110
111 wins[0] = ((Client*)it->data)->frame->window;
112 wins[1] = client->frame->window;
113
114 stacking_list = g_list_remove(stacking_list, client);
115 stacking_list = g_list_insert_before(stacking_list,
116 it->next, client);
117 }
118
119 XRestackWindows(ob_display, wins, 2);
120 stacking_set_list();
121 }
122
This page took 0.045741 seconds and 4 git commands to generate.