mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Rewrite of resize command to make it more sane
This commit is contained in:
parent
c9935507f2
commit
f589731f29
5 changed files with 60 additions and 47 deletions
|
@ -33,12 +33,12 @@ struct sway_container {
|
||||||
enum swayc_layouts layout;
|
enum swayc_layouts layout;
|
||||||
|
|
||||||
// Not including borders or margins
|
// Not including borders or margins
|
||||||
int width, height;
|
double width, height;
|
||||||
|
|
||||||
// Used for setting floating geometry
|
// Used for setting floating geometry
|
||||||
int desired_width, desired_height;
|
int desired_width, desired_height;
|
||||||
|
|
||||||
int x, y;
|
double x, y;
|
||||||
|
|
||||||
bool visible;
|
bool visible;
|
||||||
bool is_floating;
|
bool is_floating;
|
||||||
|
|
|
@ -29,6 +29,6 @@ swayc_t *get_focused_container(swayc_t *parent);
|
||||||
swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);
|
swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);
|
||||||
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir);
|
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir);
|
||||||
|
|
||||||
void recursive_resize(swayc_t *container, double amount, enum movement_direction dir);
|
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -478,31 +478,37 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
|
||||||
sibling = parent->parent->children->items[i];
|
sibling = parent->parent->children->items[i];
|
||||||
if (sibling->x != focused->x) {
|
if (sibling->x != focused->x) {
|
||||||
if (sibling->x < parent->x) {
|
if (sibling->x < parent->x) {
|
||||||
double pixels = -1 * (amount/lnumber);
|
double pixels = -1 * amount;
|
||||||
if (lnumber) {
|
pixels /= lnumber;
|
||||||
recursive_resize(sibling, pixels/2, MOVE_RIGHT);
|
if (rnumber) {
|
||||||
|
recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT);
|
||||||
} else {
|
} else {
|
||||||
recursive_resize(sibling, pixels, MOVE_RIGHT);
|
recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT);
|
||||||
}
|
}
|
||||||
} else if (sibling->x > parent->x) {
|
} else if (sibling->x > parent->x) {
|
||||||
double pixels = -1 * (amount/rnumber);
|
double pixels = -1 * amount;
|
||||||
if (rnumber) {
|
pixels /= rnumber;
|
||||||
recursive_resize(sibling, pixels/2, MOVE_LEFT);
|
if (lnumber) {
|
||||||
|
recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT);
|
||||||
} else {
|
} else {
|
||||||
recursive_resize(sibling, pixels, MOVE_LEFT);
|
recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rnumber != 0 && lnumber != 0) {
|
if (rnumber != 0 && lnumber != 0) {
|
||||||
recursive_resize(parent, amount/2, MOVE_LEFT);
|
double pixels = amount;
|
||||||
recursive_resize(parent, amount/2, MOVE_RIGHT);
|
pixels /= 2;
|
||||||
|
recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT);
|
||||||
|
recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT);
|
||||||
} else if (rnumber) {
|
} else if (rnumber) {
|
||||||
recursive_resize(parent, amount, MOVE_RIGHT);
|
recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT);
|
||||||
} else if (lnumber) {
|
} else if (lnumber) {
|
||||||
recursive_resize(parent, amount, MOVE_LEFT);
|
recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Recursive resize does not handle positions, let arrange_windows
|
||||||
|
// take care of that.
|
||||||
arrange_windows(active_workspace, -1, -1);
|
arrange_windows(active_workspace, -1, -1);
|
||||||
return true;
|
return true;
|
||||||
} else if (strcmp(argv[1], "height") == 0) {
|
} else if (strcmp(argv[1], "height") == 0) {
|
||||||
|
@ -535,28 +541,31 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) {
|
||||||
sibling = parent->parent->children->items[i];
|
sibling = parent->parent->children->items[i];
|
||||||
if (sibling->y != focused->y) {
|
if (sibling->y != focused->y) {
|
||||||
if (sibling->y < parent->y) {
|
if (sibling->y < parent->y) {
|
||||||
double pixels = -1 * (amount/bnumber);
|
double pixels = -1 * amount;
|
||||||
|
pixels /= bnumber;
|
||||||
if (tnumber) {
|
if (tnumber) {
|
||||||
recursive_resize(sibling, pixels/2, MOVE_UP);
|
recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM);
|
||||||
} else {
|
} else {
|
||||||
recursive_resize(sibling, pixels, MOVE_UP);
|
recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM);
|
||||||
}
|
}
|
||||||
} else if (sibling->x > parent->x) {
|
} else if (sibling->x > parent->x) {
|
||||||
double pixels = -1 * (amount/tnumber);
|
double pixels = -1 * amount;
|
||||||
|
pixels /= tnumber;
|
||||||
if (bnumber) {
|
if (bnumber) {
|
||||||
recursive_resize(sibling, pixels/2, MOVE_DOWN);
|
recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP);
|
||||||
} else {
|
} else {
|
||||||
recursive_resize(sibling, pixels, MOVE_DOWN);
|
recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (bnumber != 0 && tnumber != 0) {
|
if (bnumber != 0 && tnumber != 0) {
|
||||||
recursive_resize(parent, amount/2, MOVE_UP);
|
double pixels = amount/2;
|
||||||
recursive_resize(parent, amount/2, MOVE_DOWN);
|
recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP);
|
||||||
|
recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM);
|
||||||
} else if (tnumber) {
|
} else if (tnumber) {
|
||||||
recursive_resize(parent, amount, MOVE_UP);
|
recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP);
|
||||||
} else if (bnumber) {
|
} else if (bnumber) {
|
||||||
recursive_resize(parent, amount, MOVE_DOWN);
|
recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ static int index_child(swayc_t *parent, swayc_t *child) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_child(swayc_t *parent, swayc_t *child) {
|
void add_child(swayc_t *parent, swayc_t *child) {
|
||||||
sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type,
|
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
|
||||||
child->width, child->height, parent, parent->type, parent->width, parent->height);
|
child->width, child->height, parent, parent->type, parent->width, parent->height);
|
||||||
list_add(parent->children, child);
|
list_add(parent->children, child);
|
||||||
child->parent = parent;
|
child->parent = parent;
|
||||||
|
@ -40,7 +40,7 @@ void add_child(swayc_t *parent, swayc_t *child) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_floating(swayc_t *ws, swayc_t *child) {
|
void add_floating(swayc_t *ws, swayc_t *child) {
|
||||||
sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type,
|
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
|
||||||
child->width, child->height, ws, ws->type, ws->width, ws->height);
|
child->width, child->height, ws, ws->type, ws->width, ws->height);
|
||||||
list_add(ws->floating, child);
|
list_add(ws->floating, child);
|
||||||
child->parent = ws;
|
child->parent = ws;
|
||||||
|
@ -144,7 +144,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
child->y = y + container->gaps;
|
child->y = y + container->gaps;
|
||||||
child->width = width - container->gaps * 2;
|
child->width = width - container->gaps * 2;
|
||||||
child->height = height - container->gaps * 2;
|
child->height = height - container->gaps * 2;
|
||||||
sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y);
|
sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y);
|
||||||
arrange_windows(child, -1, -1);
|
arrange_windows(child, -1, -1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -193,7 +193,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
default:
|
default:
|
||||||
// Calculate total width
|
// Calculate total width
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
int *old_width = &((swayc_t *)container->children->items[i])->width;
|
double *old_width = &((swayc_t *)container->children->items[i])->width;
|
||||||
if (*old_width <= 0) {
|
if (*old_width <= 0) {
|
||||||
if (container->children->length > 1) {
|
if (container->children->length > 1) {
|
||||||
*old_width = width / (container->children->length - 1);
|
*old_width = width / (container->children->length - 1);
|
||||||
|
@ -220,7 +220,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
case L_VERT:
|
case L_VERT:
|
||||||
// Calculate total height
|
// Calculate total height
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
int *old_height = &((swayc_t *)container->children->items[i])->height;
|
double *old_height = &((swayc_t *)container->children->items[i])->height;
|
||||||
if (*old_height <= 0) {
|
if (*old_height <= 0) {
|
||||||
if (container->children->length > 1) {
|
if (container->children->length > 1) {
|
||||||
*old_height = height / (container->children->length - 1);
|
*old_height = height / (container->children->length - 1);
|
||||||
|
@ -371,34 +371,38 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursive_resize(swayc_t *container, double amount, enum movement_direction dir) {
|
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
|
||||||
int i;
|
int i;
|
||||||
bool layout_match = true;
|
bool layout_match = true;
|
||||||
if (dir == MOVE_LEFT) {
|
sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount);
|
||||||
container->x += (int) amount;
|
if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) {
|
||||||
container->width += (int) amount;
|
container->width += amount;
|
||||||
layout_match = container->layout == L_HORIZ;
|
layout_match = container->layout == L_HORIZ;
|
||||||
} else if (dir == MOVE_RIGHT) {
|
} else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) {
|
||||||
container->width += (int) amount;
|
container->height += amount;
|
||||||
layout_match = container->layout == L_HORIZ;
|
|
||||||
} else if (dir == MOVE_UP) {
|
|
||||||
container->y += (int) amount;
|
|
||||||
container->height += (int) amount;
|
|
||||||
layout_match = container->layout == L_VERT;
|
|
||||||
} else if (dir == MOVE_DOWN) {
|
|
||||||
container->height += (int) amount;
|
|
||||||
layout_match = container->layout == L_VERT;
|
layout_match = container->layout == L_VERT;
|
||||||
}
|
}
|
||||||
if (container->type == C_VIEW) {
|
if (container->type == C_VIEW) {
|
||||||
|
struct wlc_geometry geometry = {
|
||||||
|
.origin = {
|
||||||
|
.x = container->x + container->gaps / 2,
|
||||||
|
.y = container->y + container->gaps / 2
|
||||||
|
},
|
||||||
|
.size = {
|
||||||
|
.w = container->width - container->gaps,
|
||||||
|
.h = container->height - container->gaps
|
||||||
|
}
|
||||||
|
};
|
||||||
|
wlc_view_set_geometry(container->handle, edge, &geometry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (layout_match) {
|
if (layout_match) {
|
||||||
for (i = 0; i < container->children->length; i++) {
|
for (i = 0; i < container->children->length; i++) {
|
||||||
recursive_resize(container->children->items[i], amount/container->children->length, dir);
|
recursive_resize(container->children->items[i], amount/container->children->length, edge);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < container->children->length; i++) {
|
for (i = 0; i < container->children->length; i++) {
|
||||||
recursive_resize(container->children->items[i], amount, dir);
|
recursive_resize(container->children->items[i], amount, edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,8 +142,8 @@ static void container_log(const swayc_t *c) {
|
||||||
c->layout == L_STACKED ? "Stacked|":
|
c->layout == L_STACKED ? "Stacked|":
|
||||||
c->layout == L_FLOATING ? "Floating|":
|
c->layout == L_FLOATING ? "Floating|":
|
||||||
"Unknown|");
|
"Unknown|");
|
||||||
fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
|
fprintf(stderr, "w:%f|h:%f|", c->width, c->height);
|
||||||
fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
|
fprintf(stderr, "x:%f|y:%f|", c->x, c->y);
|
||||||
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
||||||
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