aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfwsmit <fw.smit01@gmail.com>2021-04-06 10:24:11 +0200
committerRonan Pigott <rpigott@berkeley.edu>2021-04-12 12:13:25 -0700
commit8106f01c176a61f2683b02672e29197b20b23fc2 (patch)
tree596a70e0bf65f4a5d989a982ca5ad47c37d3dc3c
parentb40c6448e6492df5763b77204bdfa1b16936c9d3 (diff)
desktop/layer_shell: fix centering for opposing anchors
-rw-r--r--sway/desktop/layer_shell.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index 91e113a7..19718991 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -115,9 +115,10 @@ static void arrange_layer(struct sway_output *output, struct wl_list *list,
// Horizontal axis
const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
- if ((state->anchor & both_horiz) && box.width == 0) {
+ if (box.width == 0) {
box.x = bounds.x;
- box.width = bounds.width;
+ } else if ((state->anchor & both_horiz) == both_horiz) {
+ box.x = bounds.x + ((bounds.width / 2) - (box.width / 2));
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) {
box.x = bounds.x;
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
@@ -128,9 +129,10 @@ static void arrange_layer(struct sway_output *output, struct wl_list *list,
// Vertical axis
const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
- if ((state->anchor & both_vert) && box.height == 0) {
+ if (box.height == 0) {
box.y = bounds.y;
- box.height = bounds.height;
+ } else if ((state->anchor & both_vert) == both_vert) {
+ box.y = bounds.y + ((bounds.height / 2) - (box.height / 2));
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) {
box.y = bounds.y;
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) {
@@ -139,17 +141,23 @@ static void arrange_layer(struct sway_output *output, struct wl_list *list,
box.y = bounds.y + ((bounds.height / 2) - (box.height / 2));
}
// Margin
- if ((state->anchor & both_horiz) == both_horiz) {
+ if (box.width == 0) {
box.x += state->margin.left;
- box.width -= state->margin.left + state->margin.right;
+ box.width = bounds.width -
+ (state->margin.left + state->margin.right);
+ } else if ((state->anchor & both_horiz) == both_horiz) {
+ // don't apply margins
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) {
box.x += state->margin.left;
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
box.x -= state->margin.right;
}
- if ((state->anchor & both_vert) == both_vert) {
+ if (box.height == 0) {
box.y += state->margin.top;
- box.height -= state->margin.top + state->margin.bottom;
+ box.height = bounds.height -
+ (state->margin.top + state->margin.bottom);
+ } else if ((state->anchor & both_vert) == both_vert) {
+ // don't apply margins
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) {
box.y += state->margin.top;
} else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) {