feat(bar): choose height from config file
parent
8b0cdc5f4b
commit
c792871f6e
|
@ -17,7 +17,7 @@ namespace waybar {
|
|||
struct zwlr_layer_surface_v1 *layerSurface;
|
||||
std::unique_ptr<struct wl_output *> 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<Gtk::StyleContext> _styleContext;
|
||||
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
namespace waybar {
|
||||
|
||||
struct Client {
|
||||
uint32_t height = 30;
|
||||
std::string cssFile;
|
||||
std::string configFile;
|
||||
|
||||
|
|
14
src/bar.cpp
14
src/bar.cpp
|
@ -24,6 +24,8 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&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<struct wl_output *> &&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<waybar::Bar *>(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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue