mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
Merge pull request #97 from taiyu-len/master
setup for resizable windows, drop weight
This commit is contained in:
commit
95f5660897
|
@ -44,8 +44,6 @@ struct sway_container {
|
||||||
bool is_floating;
|
bool is_floating;
|
||||||
bool is_focused;
|
bool is_focused;
|
||||||
|
|
||||||
int weight;
|
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
int gaps;
|
int gaps;
|
||||||
|
|
|
@ -242,6 +242,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
|
||||||
add_sibling(focused, view);
|
add_sibling(focused, view);
|
||||||
}
|
}
|
||||||
// Refocus on the view once its been put back into the layout
|
// Refocus on the view once its been put back into the layout
|
||||||
|
view->width = view->height = 0;
|
||||||
arrange_windows(active_workspace, -1, -1);
|
arrange_windows(active_workspace, -1, -1);
|
||||||
}
|
}
|
||||||
set_focused_container(view);
|
set_focused_container(view);
|
||||||
|
|
|
@ -14,7 +14,6 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
c->handle = -1;
|
c->handle = -1;
|
||||||
c->layout = L_NONE;
|
c->layout = L_NONE;
|
||||||
c->type = type;
|
c->type = type;
|
||||||
c->weight = 1;
|
|
||||||
if (type != C_VIEW) {
|
if (type != C_VIEW) {
|
||||||
c->children = create_list();
|
c->children = create_list();
|
||||||
}
|
}
|
||||||
|
@ -172,6 +171,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
||||||
view->name = title ? strdup(title) : NULL;
|
view->name = title ? strdup(title) : NULL;
|
||||||
view->visible = true;
|
view->visible = true;
|
||||||
view->is_focused = true;
|
view->is_focused = true;
|
||||||
|
//Setup geometry
|
||||||
|
view->width = 0;
|
||||||
|
view->height = 0;
|
||||||
|
|
||||||
view->gaps = config->gaps_inner;
|
view->gaps = config->gaps_inner;
|
||||||
|
|
||||||
|
|
|
@ -186,40 +186,62 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double total_weight = 0;
|
x = y = 0;
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
double scale = 0;
|
||||||
swayc_t *child = container->children->items[i];
|
|
||||||
total_weight += child->weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (container->layout) {
|
switch (container->layout) {
|
||||||
case L_HORIZ:
|
case L_HORIZ:
|
||||||
default:
|
default:
|
||||||
|
//Calculate total width
|
||||||
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
|
int *old_width = &((swayc_t *)container->children->items[i])->width;
|
||||||
|
if (*old_width <= 0) {
|
||||||
|
if (container->children->length > 1) {
|
||||||
|
*old_width = width / (container->children->length - 1);
|
||||||
|
} else {
|
||||||
|
*old_width = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scale += *old_width;
|
||||||
|
}
|
||||||
|
//Resize windows
|
||||||
|
if (scale > 0.1) {
|
||||||
|
scale = width / scale;
|
||||||
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = container->children->items[i];
|
||||||
double percent = child->weight / total_weight;
|
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale);
|
||||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width);
|
|
||||||
child->x = x + container->x;
|
child->x = x + container->x;
|
||||||
child->y = y + container->y;
|
child->y = y + container->y;
|
||||||
int w = width * percent;
|
arrange_windows(child, child->width * scale, height);
|
||||||
int h = height;
|
x += child->width;
|
||||||
arrange_windows(child, w, h);
|
}
|
||||||
x += w;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case L_VERT:
|
case L_VERT:
|
||||||
|
//Calculate total height
|
||||||
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
|
int *old_height = &((swayc_t *)container->children->items[i])->height;
|
||||||
|
if (*old_height <= 0) {
|
||||||
|
if (container->children->length > 1) {
|
||||||
|
*old_height = height / (container->children->length - 1);
|
||||||
|
} else {
|
||||||
|
*old_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scale += *old_height;
|
||||||
|
}
|
||||||
|
//Resize
|
||||||
|
if (scale > 0.1) {
|
||||||
|
scale = height / scale;
|
||||||
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = container->children->items[i];
|
||||||
double percent = child->weight / total_weight;
|
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale);
|
||||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width);
|
|
||||||
child->x = x + container->x;
|
child->x = x + container->x;
|
||||||
child->y = y + container->y;
|
child->y = y + container->y;
|
||||||
int w = width;
|
arrange_windows(child, width, child->height * scale);
|
||||||
int h = height * percent;
|
y += child->height;
|
||||||
arrange_windows(child, w, h);
|
}
|
||||||
y += h;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,6 @@ static void container_log(const swayc_t *c) {
|
||||||
fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
|
fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
|
||||||
fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
|
fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
|
||||||
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
||||||
fprintf(stderr, "wgt:%d|", c->weight);
|
|
||||||
fprintf(stderr, "name:%.16s|", c->name);
|
fprintf(stderr, "name:%.16s|", c->name);
|
||||||
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
|
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue