diff options
author | 2015-08-08 18:34:33 -0400 | |
---|---|---|
committer | 2015-08-08 18:34:44 -0400 | |
commit | 4181c36862904e92c81582f73b2118e380c71d2e (patch) | |
tree | 4181a405c6ad0576dc5d7846ee14fa579898ec56 | |
parent | Deny window resize requests (diff) | |
download | sway-4181c36862904e92c81582f73b2118e380c71d2e.tar.gz sway-4181c36862904e92c81582f73b2118e380c71d2e.tar.zst sway-4181c36862904e92c81582f73b2118e380c71d2e.zip |
Handle focus changes
And some simple refactoring
-rw-r--r-- | sway/layout.c | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/sway/layout.c b/sway/layout.c index bbdcb844..403ec13a 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -11,22 +11,17 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
11 | int i; | 11 | int i; |
12 | if (width == -1 || height == -1) { | 12 | if (width == -1 || height == -1) { |
13 | sway_log(L_DEBUG, "Arranging layout for %p", container); | 13 | sway_log(L_DEBUG, "Arranging layout for %p", container); |
14 | } | ||
15 | if (width == -1) { | ||
16 | width = container->width; | 14 | width = container->width; |
17 | } | ||
18 | if (height == -1) { | ||
19 | height = container->height; | 15 | height = container->height; |
20 | } | 16 | } |
21 | 17 | ||
22 | if (container->type == C_ROOT) { | 18 | switch (container->type) { |
19 | case C_ROOT: | ||
23 | for (i = 0; i < container->children->length; ++i) { | 20 | for (i = 0; i < container->children->length; ++i) { |
24 | arrange_windows(container->children->items[i], -1, -1); | 21 | arrange_windows(container->children->items[i], -1, -1); |
25 | } | 22 | } |
26 | return; | 23 | return; |
27 | } | 24 | case C_VIEW: |
28 | |||
29 | if (container->type == C_VIEW) { | ||
30 | sway_log(L_DEBUG, "Setting view to %d x %d @ %d, %d", width, height, container->x, container->y); | 25 | sway_log(L_DEBUG, "Setting view to %d x %d @ %d, %d", width, height, container->x, container->y); |
31 | struct wlc_geometry geometry = { | 26 | struct wlc_geometry geometry = { |
32 | .origin = { | 27 | .origin = { |
@@ -39,10 +34,14 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
39 | } | 34 | } |
40 | }; | 35 | }; |
41 | wlc_view_set_geometry(container->handle, &geometry); | 36 | wlc_view_set_geometry(container->handle, &geometry); |
37 | container->width = width; | ||
38 | container->height = height; | ||
42 | return; | 39 | return; |
40 | default: | ||
41 | container->width = width; | ||
42 | container->height = height; | ||
43 | break; | ||
43 | } | 44 | } |
44 | container->width = width; | ||
45 | container->height = height; | ||
46 | 45 | ||
47 | double total_weight = 0; | 46 | double total_weight = 0; |
48 | for (i = 0; i < container->children->length; ++i) { | 47 | for (i = 0; i < container->children->length; ++i) { |
@@ -66,12 +65,25 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
66 | x += w; | 65 | x += w; |
67 | } | 66 | } |
68 | break; | 67 | break; |
68 | case L_VERT: | ||
69 | for (i = 0; i < container->children->length; ++i) { | ||
70 | swayc_t *child = container->children->items[i]; | ||
71 | double percent = child->weight / total_weight; | ||
72 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); | ||
73 | child->x = x + container->x; | ||
74 | child->y = y + container->y; | ||
75 | int w = width; | ||
76 | int h = height * percent; | ||
77 | arrange_windows(child, w, h); | ||
78 | y += h; | ||
79 | } | ||
80 | break; | ||
69 | } | 81 | } |
70 | } | 82 | } |
71 | 83 | ||
72 | void init_layout() { | 84 | void init_layout() { |
73 | root_container.type = C_ROOT; | 85 | root_container.type = C_ROOT; |
74 | root_container.layout = L_HORIZ; // TODO: Default layout | 86 | root_container.layout = L_NONE; |
75 | root_container.children = create_list(); | 87 | root_container.children = create_list(); |
76 | root_container.handle = -1; | 88 | root_container.handle = -1; |
77 | } | 89 | } |
@@ -146,12 +158,36 @@ void destroy_view(swayc_t *view) { | |||
146 | 158 | ||
147 | free_swayc(view); | 159 | free_swayc(view); |
148 | 160 | ||
149 | // TODO: Focus some other window | 161 | if (parent->children->length != 0) { |
162 | focus_view(parent->children->items[0]); | ||
163 | } else { | ||
164 | focus_view(parent); | ||
165 | } | ||
150 | 166 | ||
151 | arrange_windows(parent, -1, -1); | 167 | arrange_windows(parent, -1, -1); |
152 | } | 168 | } |
153 | 169 | ||
170 | void unfocus_all(swayc_t *container) { | ||
171 | if (container->children == NULL) { | ||
172 | return; | ||
173 | } | ||
174 | int i; | ||
175 | for (i = 0; i < container->children->length; ++i) { | ||
176 | swayc_t *view = container->children->items[i]; | ||
177 | if (view->type == C_VIEW) { | ||
178 | wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, false); | ||
179 | } else { | ||
180 | unfocus_all(view); | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
154 | void focus_view(swayc_t *view) { | 185 | void focus_view(swayc_t *view) { |
186 | if (view->type == C_VIEW) { | ||
187 | unfocus_all(&root_container); | ||
188 | wlc_view_set_state(view->handle, WLC_BIT_ACTIVATED, true); | ||
189 | wlc_view_focus(view->handle); | ||
190 | } | ||
155 | if (view == &root_container) { | 191 | if (view == &root_container) { |
156 | return; | 192 | return; |
157 | } | 193 | } |