feat(bar): choose height from config file
parent
8b0cdc5f4b
commit
c792871f6e
|
@ -17,7 +17,7 @@ namespace waybar {
|
||||||
struct zwlr_layer_surface_v1 *layerSurface;
|
struct zwlr_layer_surface_v1 *layerSurface;
|
||||||
std::unique_ptr<struct wl_output *> output;
|
std::unique_ptr<struct wl_output *> output;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
auto setWidth(int) -> void;
|
auto setWidth(uint32_t) -> void;
|
||||||
auto toggle() -> void;
|
auto toggle() -> void;
|
||||||
private:
|
private:
|
||||||
static void _handleGeometry(void *data, struct wl_output *wl_output,
|
static void _handleGeometry(void *data, struct wl_output *wl_output,
|
||||||
|
@ -36,7 +36,8 @@ namespace waybar {
|
||||||
auto _setupConfig() -> void;
|
auto _setupConfig() -> void;
|
||||||
auto _setupWidgets() -> void;
|
auto _setupWidgets() -> void;
|
||||||
auto _setupCss() -> void;
|
auto _setupCss() -> void;
|
||||||
int _width = 10;
|
uint32_t _width = 10;
|
||||||
|
uint32_t _height = 30;
|
||||||
Json::Value _config;
|
Json::Value _config;
|
||||||
Glib::RefPtr<Gtk::StyleContext> _styleContext;
|
Glib::RefPtr<Gtk::StyleContext> _styleContext;
|
||||||
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
|
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
struct Client {
|
struct Client {
|
||||||
uint32_t height = 30;
|
|
||||||
std::string cssFile;
|
std::string cssFile;
|
||||||
std::string configFile;
|
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();
|
_setupConfig();
|
||||||
_setupCss();
|
_setupCss();
|
||||||
_setupWidgets();
|
_setupWidgets();
|
||||||
|
if (_config["height"])
|
||||||
|
_height = _config["height"].asUInt();
|
||||||
bool positionBottom = _config["position"] == "bottom";
|
bool positionBottom = _config["position"] == "bottom";
|
||||||
bool layerTop = _config["layer"] == "top";
|
bool layerTop = _config["layer"] == "top";
|
||||||
gtk_widget_realize(GTK_WIDGET(window.gobj()));
|
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_set_anchor(layerSurface,
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
|
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));
|
(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 = {
|
static const struct zwlr_layer_surface_v1_listener layerSurfaceListener = {
|
||||||
.configure = _layerSurfaceHandleConfigure,
|
.configure = _layerSurfaceHandleConfigure,
|
||||||
.closed = _layerSurfaceHandleClosed,
|
.closed = _layerSurfaceHandleClosed,
|
||||||
|
@ -79,9 +81,9 @@ void waybar::Bar::_layerSurfaceHandleConfigure(
|
||||||
auto o = reinterpret_cast<waybar::Bar *>(data);
|
auto o = reinterpret_cast<waybar::Bar *>(data);
|
||||||
o->window.show_all();
|
o->window.show_all();
|
||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
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;
|
std::cout << fmt::format("New Height: {}", height) << std::endl;
|
||||||
zwlr_layer_surface_v1_set_size(surface, width, height);
|
zwlr_layer_surface_v1_set_size(surface, width, height);
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(surface, o->visible ? height : 0);
|
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();
|
o->window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::Bar::setWidth(int width) -> void
|
auto waybar::Bar::setWidth(uint32_t width) -> void
|
||||||
{
|
{
|
||||||
if (width == this->_width) return;
|
if (width == this->_width) return;
|
||||||
std::cout << fmt::format("Bar width configured: {}", width) << std::endl;
|
std::cout << fmt::format("Bar width configured: {}", width) << std::endl;
|
||||||
this->_width = width;
|
this->_width = width;
|
||||||
window.set_size_request(width);
|
window.set_size_request(width);
|
||||||
window.resize(width, client.height);
|
window.resize(width, _height);
|
||||||
zwlr_layer_surface_v1_set_size(layerSurface, width, 40);
|
zwlr_layer_surface_v1_set_size(layerSurface, width, 40);
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +116,7 @@ auto waybar::Bar::setWidth(int width) -> void
|
||||||
auto waybar::Bar::toggle() -> void
|
auto waybar::Bar::toggle() -> void
|
||||||
{
|
{
|
||||||
visible = !visible;
|
visible = !visible;
|
||||||
auto zone = visible ? client.height : 0;
|
auto zone = visible ? _height : 0;
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, zone);
|
zwlr_layer_surface_v1_set_exclusive_zone(layerSurface, zone);
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue