From c792871f6efe719e1eed6766f9a5b8f988a8fa72 Mon Sep 17 00:00:00 2001 From: Alexis Date: Fri, 10 Aug 2018 18:46:31 +0200 Subject: [PATCH] feat(bar): choose height from config file --- include/bar.hpp | 5 +++-- include/client.hpp | 1 - src/bar.cpp | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 1439e21b..8236dde0 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -17,7 +17,7 @@ namespace waybar { struct zwlr_layer_surface_v1 *layerSurface; std::unique_ptr output; bool visible = true; - auto setWidth(int) -> void; + auto setWidth(uint32_t) -> void; auto toggle() -> void; private: static void _handleGeometry(void *data, struct wl_output *wl_output, @@ -36,7 +36,8 @@ namespace waybar { auto _setupConfig() -> void; auto _setupWidgets() -> void; auto _setupCss() -> void; - int _width = 10; + uint32_t _width = 10; + uint32_t _height = 30; Json::Value _config; Glib::RefPtr _styleContext; Glib::RefPtr _cssProvider; diff --git a/include/client.hpp b/include/client.hpp index 24a838d3..4efaa0f5 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -23,7 +23,6 @@ namespace waybar { struct Client { - uint32_t height = 30; std::string cssFile; std::string configFile; diff --git a/src/bar.cpp b/src/bar.cpp index 7517bc67..92629f35 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -24,6 +24,8 @@ waybar::Bar::Bar(Client &client, std::unique_ptr &&p_output) _setupConfig(); _setupCss(); _setupWidgets(); + if (_config["height"]) + _height = _config["height"].asUInt(); bool positionBottom = _config["position"] == "bottom"; bool layerTop = _config["layer"] == "top"; gtk_widget_realize(GTK_WIDGET(window.gobj())); @@ -37,7 +39,7 @@ waybar::Bar::Bar(Client &client, std::unique_ptr &&p_output) zwlr_layer_surface_v1_set_anchor(layerSurface, ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | (positionBottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)); - zwlr_layer_surface_v1_set_size(layerSurface, _width, client.height); + zwlr_layer_surface_v1_set_size(layerSurface, _width, _height); static const struct zwlr_layer_surface_v1_listener layerSurfaceListener = { .configure = _layerSurfaceHandleConfigure, .closed = _layerSurfaceHandleClosed, @@ -79,9 +81,9 @@ void waybar::Bar::_layerSurfaceHandleConfigure( auto o = reinterpret_cast(data); o->window.show_all(); zwlr_layer_surface_v1_ack_configure(surface, serial); - if (o->client.height != height) + if (o->_height != height) { - height = o->client.height; + height = o->_height; std::cout << fmt::format("New Height: {}", height) << std::endl; zwlr_layer_surface_v1_set_size(surface, width, height); zwlr_layer_surface_v1_set_exclusive_zone(surface, o->visible ? height : 0); @@ -100,13 +102,13 @@ void waybar::Bar::_layerSurfaceHandleClosed(void *data, o->window.close(); } -auto waybar::Bar::setWidth(int width) -> void +auto waybar::Bar::setWidth(uint32_t width) -> void { if (width == this->_width) return; std::cout << fmt::format("Bar width configured: {}", width) << std::endl; this->_width = width; window.set_size_request(width); - window.resize(width, client.height); + window.resize(width, _height); zwlr_layer_surface_v1_set_size(layerSurface, width, 40); wl_surface_commit(surface); } @@ -114,7 +116,7 @@ auto waybar::Bar::setWidth(int width) -> void auto waybar::Bar::toggle() -> void { visible = !visible; - auto zone = visible ? client.height : 0; + auto zone = visible ? _height : 0; zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, zone); wl_surface_commit(surface); }