From 529daedcecf8e7f4f9c280f7e110a4990bc286a2 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Sun, 1 Sep 2019 00:54:53 -0700 Subject: [PATCH] fix: correct handling of margins on anchored axis --- include/bar.hpp | 1 + src/bar.cpp | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 95cab89c..7566b088 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -56,6 +56,7 @@ class Bar { void onRealize(); void onMap(GdkEventAny *ev); void setExclusiveZone(uint32_t width, uint32_t height); + void setSurfaceSize(uint32_t width, uint32_t height); auto setupWidgets() -> void; void getModules(const Factory &, const std::string &); void setupAltFormatKeyForModule(const std::string &module_name); diff --git a/src/bar.cpp b/src/bar.cpp index 7204b9dc..9de09b87 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -132,7 +132,7 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) { } } if (tmp_width != width_ || tmp_height != height_) { - zwlr_layer_surface_v1_set_size(layer_surface, tmp_width, tmp_height); + setSurfaceSize(tmp_width, tmp_height); } } @@ -153,9 +153,9 @@ void waybar::Bar::onMap(GdkEventAny* ev) { zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, false); zwlr_layer_surface_v1_set_anchor(layer_surface, anchor_); - zwlr_layer_surface_v1_set_size(layer_surface, width_, height_); zwlr_layer_surface_v1_set_margin( layer_surface, margins_.top, margins_.right, margins_.bottom, margins_.left); + setSurfaceSize(width_, height_); setExclusiveZone(width_, height_); static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { @@ -185,6 +185,22 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) { zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, zone); } +void waybar::Bar::setSurfaceSize(uint32_t width, uint32_t height) { + /* If the client is anchored to two opposite edges, layer_surface.configure will return + * size without margins for the axis. + * layer_surface.set_size, however, expects size with margins for the anchored axis. + * This is not specified by wlr-layer-shell and based on actual behavior of sway. + */ + if (vertical && height > 1) { + height += margins_.top + margins_.bottom; + } + if (!vertical && width > 1) { + width += margins_.right + margins_.left; + } + spdlog::debug("Set surface size {}x{} for output {}", width, height, output->name); + zwlr_layer_surface_v1_set_size(layer_surface, width, height); +} + // Converting string to button code rn as to avoid doing it later void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) { if (config.isMember(module_name)) {