diff options
author | 2015-08-20 08:07:16 -0400 | |
---|---|---|
committer | 2015-08-20 08:07:16 -0400 | |
commit | 95f5660897b6640f13623178651f45549a917efb (patch) | |
tree | 0811a259f740cfc7185974c87fbdaa40e9a956e6 /sway | |
parent | Fix compiler warning (diff) | |
parent | small fix, default width/height 0 (diff) | |
download | sway-95f5660897b6640f13623178651f45549a917efb.tar.gz sway-95f5660897b6640f13623178651f45549a917efb.tar.zst sway-95f5660897b6640f13623178651f45549a917efb.zip |
Merge pull request #97 from taiyu-len/master
setup for resizable windows, drop weight
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/container.c | 4 | ||||
-rw-r--r-- | sway/layout.c | 74 | ||||
-rw-r--r-- | sway/log.c | 1 |
4 files changed, 52 insertions, 28 deletions
diff --git a/sway/commands.c b/sway/commands.c index c4cf96a2..babefd02 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -242,6 +242,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
242 | add_sibling(focused, view); | 242 | add_sibling(focused, view); |
243 | } | 243 | } |
244 | // Refocus on the view once its been put back into the layout | 244 | // Refocus on the view once its been put back into the layout |
245 | view->width = view->height = 0; | ||
245 | arrange_windows(active_workspace, -1, -1); | 246 | arrange_windows(active_workspace, -1, -1); |
246 | } | 247 | } |
247 | set_focused_container(view); | 248 | set_focused_container(view); |
diff --git a/sway/container.c b/sway/container.c index dee4028d..0e247393 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -14,7 +14,6 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
14 | c->handle = -1; | 14 | c->handle = -1; |
15 | c->layout = L_NONE; | 15 | c->layout = L_NONE; |
16 | c->type = type; | 16 | c->type = type; |
17 | c->weight = 1; | ||
18 | if (type != C_VIEW) { | 17 | if (type != C_VIEW) { |
19 | c->children = create_list(); | 18 | c->children = create_list(); |
20 | } | 19 | } |
@@ -172,6 +171,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
172 | view->name = title ? strdup(title) : NULL; | 171 | view->name = title ? strdup(title) : NULL; |
173 | view->visible = true; | 172 | view->visible = true; |
174 | view->is_focused = true; | 173 | view->is_focused = true; |
174 | //Setup geometry | ||
175 | view->width = 0; | ||
176 | view->height = 0; | ||
175 | 177 | ||
176 | view->gaps = config->gaps_inner; | 178 | view->gaps = config->gaps_inner; |
177 | 179 | ||
diff --git a/sway/layout.c b/sway/layout.c index 37db2e52..54fdbcf8 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -186,40 +186,62 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
186 | break; | 186 | break; |
187 | } | 187 | } |
188 | 188 | ||
189 | double total_weight = 0; | 189 | x = y = 0; |
190 | for (i = 0; i < container->children->length; ++i) { | 190 | double scale = 0; |
191 | swayc_t *child = container->children->items[i]; | ||
192 | total_weight += child->weight; | ||
193 | } | ||
194 | |||
195 | switch (container->layout) { | 191 | switch (container->layout) { |
196 | case L_HORIZ: | 192 | case L_HORIZ: |
197 | default: | 193 | default: |
198 | sway_log(L_DEBUG, "Arranging %p horizontally", container); | 194 | //Calculate total width |
199 | for (i = 0; i < container->children->length; ++i) { | 195 | for (i = 0; i < container->children->length; ++i) { |
200 | swayc_t *child = container->children->items[i]; | 196 | int *old_width = &((swayc_t *)container->children->items[i])->width; |
201 | double percent = child->weight / total_weight; | 197 | if (*old_width <= 0) { |
202 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); | 198 | if (container->children->length > 1) { |
203 | child->x = x + container->x; | 199 | *old_width = width / (container->children->length - 1); |
204 | child->y = y + container->y; | 200 | } else { |
205 | int w = width * percent; | 201 | *old_width = width; |
206 | int h = height; | 202 | } |
207 | arrange_windows(child, w, h); | 203 | } |
208 | x += w; | 204 | scale += *old_width; |
205 | } | ||
206 | //Resize windows | ||
207 | if (scale > 0.1) { | ||
208 | scale = width / scale; | ||
209 | sway_log(L_DEBUG, "Arranging %p horizontally", container); | ||
210 | for (i = 0; i < container->children->length; ++i) { | ||
211 | swayc_t *child = container->children->items[i]; | ||
212 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); | ||
213 | child->x = x + container->x; | ||
214 | child->y = y + container->y; | ||
215 | arrange_windows(child, child->width * scale, height); | ||
216 | x += child->width; | ||
217 | } | ||
209 | } | 218 | } |
210 | break; | 219 | break; |
211 | case L_VERT: | 220 | case L_VERT: |
212 | sway_log(L_DEBUG, "Arranging %p vertically", container); | 221 | //Calculate total height |
213 | for (i = 0; i < container->children->length; ++i) { | 222 | for (i = 0; i < container->children->length; ++i) { |
214 | swayc_t *child = container->children->items[i]; | 223 | int *old_height = &((swayc_t *)container->children->items[i])->height; |
215 | double percent = child->weight / total_weight; | 224 | if (*old_height <= 0) { |
216 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); | 225 | if (container->children->length > 1) { |
217 | child->x = x + container->x; | 226 | *old_height = height / (container->children->length - 1); |
218 | child->y = y + container->y; | 227 | } else { |
219 | int w = width; | 228 | *old_height = height; |
220 | int h = height * percent; | 229 | } |
221 | arrange_windows(child, w, h); | 230 | } |
222 | y += h; | 231 | scale += *old_height; |
232 | } | ||
233 | //Resize | ||
234 | if (scale > 0.1) { | ||
235 | scale = height / scale; | ||
236 | sway_log(L_DEBUG, "Arranging %p vertically", container); | ||
237 | for (i = 0; i < container->children->length; ++i) { | ||
238 | swayc_t *child = container->children->items[i]; | ||
239 | sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); | ||
240 | child->x = x + container->x; | ||
241 | child->y = y + container->y; | ||
242 | arrange_windows(child, width, child->height * scale); | ||
243 | y += child->height; | ||
244 | } | ||
223 | } | 245 | } |
224 | break; | 246 | break; |
225 | } | 247 | } |
@@ -114,7 +114,6 @@ static void container_log(const swayc_t *c) { | |||
114 | fprintf(stderr, "w:%d|h:%d|", c->width, c->height); | 114 | fprintf(stderr, "w:%d|h:%d|", c->width, c->height); |
115 | fprintf(stderr, "x:%d|y:%d|", c->x, c->y); | 115 | fprintf(stderr, "x:%d|y:%d|", c->x, c->y); |
116 | fprintf(stderr, "vis:%c|", c->visible?'t':'f'); | 116 | fprintf(stderr, "vis:%c|", c->visible?'t':'f'); |
117 | fprintf(stderr, "wgt:%d|", c->weight); | ||
118 | fprintf(stderr, "name:%.16s|", c->name); | 117 | fprintf(stderr, "name:%.16s|", c->name); |
119 | fprintf(stderr, "children:%d\n",c->children?c->children->length:0); | 118 | fprintf(stderr, "children:%d\n",c->children?c->children->length:0); |
120 | } | 119 | } |