Skip to content

Commit

Permalink
refactor(bar): default width is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Aug 11, 2018
1 parent 3c66f4b commit 8d5b61a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 44 deletions.
10 changes: 1 addition & 9 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ namespace waybar {
const char *name);
static void _handleDescription(void *data,
struct zxdg_output_v1 *zxdg_output_v1, const char *description);
static void _handleGeometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
int32_t subpixel, const char *make, const char *model, int32_t transform);
static void _handleMode(void *data, struct wl_output *wl_output,
uint32_t f, int32_t w, int32_t h, int32_t refresh);
static void _handleDone(void *data, struct wl_output *);
static void _handleScale(void *data, struct wl_output *wl_output,
int32_t factor);
static void _layerSurfaceHandleConfigure(void *data,
struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width,
uint32_t height);
Expand All @@ -47,7 +39,7 @@ namespace waybar {
auto _setupConfig() -> void;
auto _setupWidgets() -> void;
auto _setupCss() -> void;
uint32_t _width = 10;
uint32_t _width = 0;
uint32_t _height = 30;
Json::Value _config;
Glib::RefPtr<Gtk::StyleContext> _styleContext;
Expand Down
38 changes: 3 additions & 35 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
: client(client), window{Gtk::WindowType::WINDOW_TOPLEVEL},
output(std::move(p_output))
{
static const struct wl_output_listener outputListener = {
.geometry = _handleGeometry,
.mode = _handleMode,
.done = _handleDone,
.scale = _handleScale,
};
static const struct zxdg_output_v1_listener xdgOutputListener = {
.logical_position = _handleLogicalPosition,
.logical_size = _handleLogicalSize,
.done = _handleDone,
.name = _handleName,
.description = _handleDescription,
};
wl_output_add_listener(*output, &outputListener, this);
_xdgOutput =
zxdg_output_manager_v1_get_xdg_output(client.xdg_output_manager, *output);
zxdg_output_v1_add_listener(_xdgOutput, &xdgOutputListener, this);
Expand Down Expand Up @@ -87,43 +80,18 @@ void waybar::Bar::_handleDescription(void *data,
// Nothing here
}

void waybar::Bar::_handleGeometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
int32_t subpixel, const char *make, const char *model, int32_t transform)
{
// Nothing here
}

void waybar::Bar::_handleMode(void *data, struct wl_output *wl_output,
uint32_t f, int32_t w, int32_t h, int32_t refresh)
{
auto o = reinterpret_cast<waybar::Bar *>(data);
// If the width is configured we force it
o->setWidth(o->_config["width"] ? o->_config["width"].asUInt() : w);
}

void waybar::Bar::_handleDone(void *data, struct wl_output *)
{
// Nothing here
}

void waybar::Bar::_handleScale(void *data, struct wl_output *wl_output,
int32_t factor)
{
// Nothing here
}

void waybar::Bar::_layerSurfaceHandleConfigure(
void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial,
uint32_t width, uint32_t height)
{
auto o = reinterpret_cast<waybar::Bar *>(data);
o->window.show_all();
o->setWidth(o->_config["width"] ? o->_config["width"].asUInt() : width);
zwlr_layer_surface_v1_ack_configure(surface, serial);
if (o->_height != 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_size(surface, o->_width, height);
zwlr_layer_surface_v1_set_exclusive_zone(surface, o->visible ? height : 0);
wl_surface_commit(o->surface);
}
Expand All @@ -147,7 +115,7 @@ auto waybar::Bar::setWidth(uint32_t width) -> void
this->_width = width;
window.set_size_request(width);
window.resize(width, _height);
zwlr_layer_surface_v1_set_size(layerSurface, width, 40);
zwlr_layer_surface_v1_set_size(layerSurface, width, _height + 1);
wl_surface_commit(surface);
}

Expand Down

0 comments on commit 8d5b61a

Please sign in to comment.