mirror of
https://github.com/swaywm/sway.git
synced 2024-11-13 05:54:11 +01:00
Merge pull request #2488 from RyanDwyer/separate-gaps-functions
Make separate gaps functions per container type
This commit is contained in:
commit
1a30c50ef4
@ -4,12 +4,6 @@
|
|||||||
|
|
||||||
struct sway_container;
|
struct sway_container;
|
||||||
|
|
||||||
// Remove gaps around container
|
|
||||||
void remove_gaps(struct sway_container *c);
|
|
||||||
|
|
||||||
// Add gaps around container
|
|
||||||
void add_gaps(struct sway_container *c);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arrange layout for all the children of the given container.
|
* Arrange layout for all the children of the given container.
|
||||||
*/
|
*/
|
||||||
|
@ -335,6 +335,10 @@ struct sway_output *container_get_effective_output(struct sway_container *con);
|
|||||||
|
|
||||||
void container_discover_outputs(struct sway_container *con);
|
void container_discover_outputs(struct sway_container *con);
|
||||||
|
|
||||||
|
void container_remove_gaps(struct sway_container *container);
|
||||||
|
|
||||||
|
void container_add_gaps(struct sway_container *container);
|
||||||
|
|
||||||
int container_sibling_index(const struct sway_container *child);
|
int container_sibling_index(const struct sway_container *child);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -75,4 +75,8 @@ struct sway_container *workspace_wrap_children(struct sway_container *ws);
|
|||||||
void workspace_add_floating(struct sway_container *workspace,
|
void workspace_add_floating(struct sway_container *workspace,
|
||||||
struct sway_container *con);
|
struct sway_container *con);
|
||||||
|
|
||||||
|
void workspace_remove_gaps(struct sway_container *ws);
|
||||||
|
|
||||||
|
void workspace_add_gaps(struct sway_container *ws);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,7 +39,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
|
|||||||
child->width = parent->width;
|
child->width = parent->width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remove_gaps(child);
|
container_remove_gaps(child);
|
||||||
total_width += child->width;
|
total_width += child->width;
|
||||||
}
|
}
|
||||||
double scale = parent->width / total_width;
|
double scale = parent->width / total_width;
|
||||||
@ -62,7 +62,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
|
|||||||
if (i == num_children - 1) {
|
if (i == num_children - 1) {
|
||||||
child->width = parent->x + parent->width - child->x;
|
child->width = parent->x + parent->width - child->x;
|
||||||
}
|
}
|
||||||
add_gaps(child);
|
container_add_gaps(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ static void apply_vert_layout(struct sway_container *parent) {
|
|||||||
child->height = parent_height;
|
child->height = parent_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remove_gaps(child);
|
container_remove_gaps(child);
|
||||||
total_height += child->height;
|
total_height += child->height;
|
||||||
}
|
}
|
||||||
double scale = parent_height / total_height;
|
double scale = parent_height / total_height;
|
||||||
@ -115,7 +115,7 @@ static void apply_vert_layout(struct sway_container *parent) {
|
|||||||
child->height =
|
child->height =
|
||||||
parent->y + parent_offset + parent_height - child->y;
|
parent->y + parent_offset + parent_height - child->y;
|
||||||
}
|
}
|
||||||
add_gaps(child);
|
container_add_gaps(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,12 +133,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
|
|||||||
size_t parent_height = parent->height - parent_offset;
|
size_t parent_height = parent->height - parent_offset;
|
||||||
for (int i = 0; i < parent->children->length; ++i) {
|
for (int i = 0; i < parent->children->length; ++i) {
|
||||||
struct sway_container *child = parent->children->items[i];
|
struct sway_container *child = parent->children->items[i];
|
||||||
remove_gaps(child);
|
container_remove_gaps(child);
|
||||||
child->x = parent->x;
|
child->x = parent->x;
|
||||||
child->y = parent->y + parent_offset;
|
child->y = parent->y + parent_offset;
|
||||||
child->width = parent->width;
|
child->width = parent->width;
|
||||||
child->height = parent_height;
|
child->height = parent_height;
|
||||||
add_gaps(child);
|
container_add_gaps(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ static void arrange_workspace(struct sway_container *workspace) {
|
|||||||
struct wlr_box *area = &output->sway_output->usable_area;
|
struct wlr_box *area = &output->sway_output->usable_area;
|
||||||
wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d",
|
wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d",
|
||||||
area->width, area->height, area->x, area->y);
|
area->width, area->height, area->x, area->y);
|
||||||
remove_gaps(workspace);
|
workspace_remove_gaps(workspace);
|
||||||
|
|
||||||
double prev_x = workspace->x;
|
double prev_x = workspace->x;
|
||||||
double prev_y = workspace->y;
|
double prev_y = workspace->y;
|
||||||
@ -230,7 +230,7 @@ static void arrange_workspace(struct sway_container *workspace) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_gaps(workspace);
|
workspace_add_gaps(workspace);
|
||||||
container_set_dirty(workspace);
|
container_set_dirty(workspace);
|
||||||
wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
|
wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
|
||||||
workspace->x, workspace->y);
|
workspace->x, workspace->y);
|
||||||
@ -314,41 +314,3 @@ void arrange_windows(struct sway_container *container) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_gaps(struct sway_container *c) {
|
|
||||||
if (c->current_gaps == 0) {
|
|
||||||
wlr_log(WLR_DEBUG, "Removing gaps: not gapped: %p", c);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->width += c->current_gaps * 2;
|
|
||||||
c->height += c->current_gaps * 2;
|
|
||||||
c->x -= c->current_gaps;
|
|
||||||
c->y -= c->current_gaps;
|
|
||||||
|
|
||||||
c->current_gaps = 0;
|
|
||||||
|
|
||||||
wlr_log(WLR_DEBUG, "Removing gaps %p", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_gaps(struct sway_container *c) {
|
|
||||||
if (c->current_gaps > 0 || c->type == C_CONTAINER) {
|
|
||||||
wlr_log(WLR_DEBUG, "Not adding gaps: %p", c);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c->type == C_WORKSPACE &&
|
|
||||||
!(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner;
|
|
||||||
|
|
||||||
c->x += gaps;
|
|
||||||
c->y += gaps;
|
|
||||||
c->width -= 2 * gaps;
|
|
||||||
c->height -= 2 * gaps;
|
|
||||||
c->current_gaps = gaps;
|
|
||||||
|
|
||||||
wlr_log(WLR_DEBUG, "Adding gaps: %p", c);
|
|
||||||
}
|
|
||||||
|
@ -1124,7 +1124,38 @@ void container_discover_outputs(struct sway_container *con) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void container_remove_gaps(struct sway_container *c) {
|
||||||
|
if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW,
|
||||||
|
"Expected a container or view")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (c->current_gaps == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->width += c->current_gaps * 2;
|
||||||
|
c->height += c->current_gaps * 2;
|
||||||
|
c->x -= c->current_gaps;
|
||||||
|
c->y -= c->current_gaps;
|
||||||
|
c->current_gaps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void container_add_gaps(struct sway_container *c) {
|
||||||
|
if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW,
|
||||||
|
"Expected a container or view")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (c->current_gaps > 0 || c->type != C_VIEW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->current_gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner;
|
||||||
|
c->x += c->current_gaps;
|
||||||
|
c->y += c->current_gaps;
|
||||||
|
c->width -= 2 * c->current_gaps;
|
||||||
|
c->height -= 2 * c->current_gaps;
|
||||||
|
}
|
||||||
|
|
||||||
int container_sibling_index(const struct sway_container *child) {
|
int container_sibling_index(const struct sway_container *child) {
|
||||||
return list_find(child->parent->children, child);
|
return list_find(child->parent->children, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,8 @@ struct sway_container *container_split(struct sway_container *child,
|
|||||||
|
|
||||||
wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child);
|
wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child);
|
||||||
|
|
||||||
remove_gaps(child);
|
child->type == C_WORKSPACE ? workspace_remove_gaps(child)
|
||||||
|
: container_remove_gaps(child);
|
||||||
|
|
||||||
cont->prev_split_layout = L_NONE;
|
cont->prev_split_layout = L_NONE;
|
||||||
cont->width = child->width;
|
cont->width = child->width;
|
||||||
@ -229,7 +230,7 @@ struct sway_container *container_split(struct sway_container *child,
|
|||||||
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
||||||
bool set_focus = (seat_get_focus(seat) == child);
|
bool set_focus = (seat_get_focus(seat) == child);
|
||||||
|
|
||||||
add_gaps(cont);
|
container_add_gaps(cont);
|
||||||
|
|
||||||
if (child->type == C_WORKSPACE) {
|
if (child->type == C_WORKSPACE) {
|
||||||
struct sway_container *workspace = child;
|
struct sway_container *workspace = child;
|
||||||
|
@ -665,3 +665,38 @@ void workspace_add_floating(struct sway_container *workspace,
|
|||||||
container_set_dirty(workspace);
|
container_set_dirty(workspace);
|
||||||
container_set_dirty(con);
|
container_set_dirty(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void workspace_remove_gaps(struct sway_container *ws) {
|
||||||
|
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ws->current_gaps == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws->width += ws->current_gaps * 2;
|
||||||
|
ws->height += ws->current_gaps * 2;
|
||||||
|
ws->x -= ws->current_gaps;
|
||||||
|
ws->y -= ws->current_gaps;
|
||||||
|
ws->current_gaps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void workspace_add_gaps(struct sway_container *ws) {
|
||||||
|
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ws->current_gaps > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool should_apply =
|
||||||
|
config->edge_gaps || (config->smart_gaps && ws->children->length > 1);
|
||||||
|
if (!should_apply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner;
|
||||||
|
ws->x += ws->current_gaps;
|
||||||
|
ws->y += ws->current_gaps;
|
||||||
|
ws->width -= 2 * ws->current_gaps;
|
||||||
|
ws->height -= 2 * ws->current_gaps;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user