aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-20 04:47:36 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-20 04:47:36 -0700
commitfbaa9111a8525daeef8a5534784da2f793917a36 (patch)
tree19c6150da805f3c765746740f0eb8f250682292c /sway
parentchanges (diff)
downloadsway-fbaa9111a8525daeef8a5534784da2f793917a36.tar.gz
sway-fbaa9111a8525daeef8a5534784da2f793917a36.tar.zst
sway-fbaa9111a8525daeef8a5534784da2f793917a36.zip
setup for resizable windows, drop weight
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c1
-rw-r--r--sway/container.c9
-rw-r--r--sway/layout.c75
-rw-r--r--sway/log.c1
4 files changed, 58 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 9c6b78e9..c9163784 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,14 @@ 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 = sibling->parent->width;
176 view->height = sibling->parent->height;
177 if (sibling->parent->layout == L_HORIZ) {
178 view->width /= sibling->parent->children->length;
179 } else {
180 view->height /= sibling->parent->children->length;
181 }
175 182
176 view->gaps = config->gaps_inner; 183 view->gaps = config->gaps_inner;
177 184
diff --git a/sway/layout.c b/sway/layout.c
index f600cf49..50a25442 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -186,40 +186,63 @@ 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 sway_log(L_DEBUG,"setting width as %d",*old_width);
208 x += w; 204 }
205 scale += *old_width;
206 }
207 //Resize windows
208 if (scale > 0.1) {
209 scale = width / scale;
210 sway_log(L_DEBUG, "Arranging %p horizontally", container);
211 for (i = 0; i < container->children->length; ++i) {
212 swayc_t *child = container->children->items[i];
213 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale);
214 child->x = x + container->x;
215 child->y = y + container->y;
216 arrange_windows(child, child->width * scale, height);
217 x += child->width;
218 }
209 } 219 }
210 break; 220 break;
211 case L_VERT: 221 case L_VERT:
212 sway_log(L_DEBUG, "Arranging %p vertically", container); 222 //Calculate total height
213 for (i = 0; i < container->children->length; ++i) { 223 for (i = 0; i < container->children->length; ++i) {
214 swayc_t *child = container->children->items[i]; 224 int *old_height = &((swayc_t *)container->children->items[i])->height;
215 double percent = child->weight / total_weight; 225 if (container->children->length > 1) {
216 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width); 226 *old_height = height / (container->children->length - 1);
217 child->x = x + container->x; 227 } else {
218 child->y = y + container->y; 228 *old_height = height;
219 int w = width; 229 }
220 int h = height * percent; 230 if (*old_height == 0) {
221 arrange_windows(child, w, h); 231 }
222 y += h; 232 scale += *old_height;
233 }
234 //Resize
235 if (scale > 0.1) {
236 scale = height / scale;
237 sway_log(L_DEBUG, "Arranging %p vertically", container);
238 for (i = 0; i < container->children->length; ++i) {
239 swayc_t *child = container->children->items[i];
240 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale);
241 child->x = x + container->x;
242 child->y = y + container->y;
243 arrange_windows(child, width, child->height * scale);
244 y += child->height;
245 }
223 } 246 }
224 break; 247 break;
225 } 248 }
diff --git a/sway/log.c b/sway/log.c
index 44f6e366..49a74e02 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -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}