fix(bar): rework surface commit calls for RawSurfaceImpl
wayland log shows that some changes were committed twice and some weren't committed until the next redraw.pull/892/head
parent
d4d35e6b2b
commit
591a417b7d
|
@ -39,6 +39,7 @@ class BarSurface {
|
||||||
virtual void setMargins(const struct bar_margins &margins) = 0;
|
virtual void setMargins(const struct bar_margins &margins) = 0;
|
||||||
virtual void setPosition(const std::string_view &position) = 0;
|
virtual void setPosition(const std::string_view &position) = 0;
|
||||||
virtual void setSize(uint32_t width, uint32_t height) = 0;
|
virtual void setSize(uint32_t width, uint32_t height) = 0;
|
||||||
|
virtual void commit(){};
|
||||||
|
|
||||||
virtual ~BarSurface() = default;
|
virtual ~BarSurface() = default;
|
||||||
};
|
};
|
||||||
|
|
34
src/bar.cpp
34
src/bar.cpp
|
@ -165,7 +165,6 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
if (zwlr_layer_surface_v1_get_version(layer_surface_) >=
|
if (zwlr_layer_surface_v1_get_version(layer_surface_) >=
|
||||||
ZWLR_LAYER_SURFACE_V1_SET_LAYER_SINCE_VERSION) {
|
ZWLR_LAYER_SURFACE_V1_SET_LAYER_SINCE_VERSION) {
|
||||||
zwlr_layer_surface_v1_set_layer(layer_surface_, layer_);
|
zwlr_layer_surface_v1_set_layer(layer_surface_, layer_);
|
||||||
commit();
|
|
||||||
} else {
|
} else {
|
||||||
spdlog::warn("Unable to set layer: layer-shell interface version is too old");
|
spdlog::warn("Unable to set layer: layer-shell interface version is too old");
|
||||||
}
|
}
|
||||||
|
@ -178,7 +177,6 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
if (layer_surface_) {
|
if (layer_surface_) {
|
||||||
zwlr_layer_surface_v1_set_margin(
|
zwlr_layer_surface_v1_set_margin(
|
||||||
layer_surface_, margins_.top, margins_.right, margins_.bottom, margins_.left);
|
layer_surface_, margins_.top, margins_.right, margins_.bottom, margins_.left);
|
||||||
commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +193,6 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
// updating already mapped window
|
// updating already mapped window
|
||||||
if (layer_surface_) {
|
if (layer_surface_) {
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface_, anchor_);
|
zwlr_layer_surface_v1_set_anchor(layer_surface_, anchor_);
|
||||||
commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +203,12 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
window_.set_size_request(width, height);
|
window_.set_size_request(width, height);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void commit() override {
|
||||||
|
if (surface_) {
|
||||||
|
wl_surface_commit(surface_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr static uint8_t VERTICAL_ANCHOR =
|
constexpr static uint8_t VERTICAL_ANCHOR =
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||||
|
@ -231,6 +234,10 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMap(GdkEventAny* ev) {
|
void onMap(GdkEventAny* ev) {
|
||||||
|
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
||||||
|
.configure = onSurfaceConfigure,
|
||||||
|
.closed = onSurfaceClosed,
|
||||||
|
};
|
||||||
auto client = Client::inst();
|
auto client = Client::inst();
|
||||||
auto gdk_window = window_.get_window()->gobj();
|
auto gdk_window = window_.get_window()->gobj();
|
||||||
surface_ = gdk_wayland_window_get_wl_surface(gdk_window);
|
surface_ = gdk_wayland_window_get_wl_surface(gdk_window);
|
||||||
|
@ -238,21 +245,16 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
layer_surface_ = zwlr_layer_shell_v1_get_layer_surface(
|
layer_surface_ = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
client->layer_shell, surface_, output_, layer_, "waybar");
|
client->layer_shell, surface_, output_, layer_, "waybar");
|
||||||
|
|
||||||
|
zwlr_layer_surface_v1_add_listener(layer_surface_, &layer_surface_listener, this);
|
||||||
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface_, false);
|
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface_, false);
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface_, anchor_);
|
zwlr_layer_surface_v1_set_anchor(layer_surface_, anchor_);
|
||||||
zwlr_layer_surface_v1_set_margin(
|
zwlr_layer_surface_v1_set_margin(
|
||||||
layer_surface_, margins_.top, margins_.right, margins_.bottom, margins_.left);
|
layer_surface_, margins_.top, margins_.right, margins_.bottom, margins_.left);
|
||||||
|
|
||||||
setSurfaceSize(width_, height_);
|
setSurfaceSize(width_, height_);
|
||||||
setExclusiveZone(exclusive_zone_);
|
setExclusiveZone(exclusive_zone_);
|
||||||
|
|
||||||
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
commit();
|
||||||
.configure = onSurfaceConfigure,
|
|
||||||
.closed = onSurfaceClosed,
|
|
||||||
};
|
|
||||||
zwlr_layer_surface_v1_add_listener(layer_surface_, &layer_surface_listener, this);
|
|
||||||
|
|
||||||
wl_surface_commit(surface_);
|
|
||||||
wl_display_roundtrip(client->wl_display);
|
wl_display_roundtrip(client->wl_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,12 +292,7 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
}
|
}
|
||||||
if (tmp_width != width_ || tmp_height != height_) {
|
if (tmp_width != width_ || tmp_height != height_) {
|
||||||
setSurfaceSize(tmp_width, tmp_height);
|
setSurfaceSize(tmp_width, tmp_height);
|
||||||
}
|
commit();
|
||||||
}
|
|
||||||
|
|
||||||
void commit() {
|
|
||||||
if (window_.get_mapped()) {
|
|
||||||
wl_surface_commit(surface_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +326,7 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||||
o->width_ == 1 ? "auto" : std::to_string(o->width_),
|
o->width_ == 1 ? "auto" : std::to_string(o->width_),
|
||||||
o->height_ == 1 ? "auto" : std::to_string(o->height_),
|
o->height_ == 1 ? "auto" : std::to_string(o->height_),
|
||||||
o->output_name_);
|
o->output_name_);
|
||||||
wl_surface_commit(o->surface_);
|
o->commit();
|
||||||
}
|
}
|
||||||
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
||||||
}
|
}
|
||||||
|
@ -467,6 +464,7 @@ void waybar::Bar::setVisible(bool value) {
|
||||||
window.set_opacity(1);
|
window.set_opacity(1);
|
||||||
}
|
}
|
||||||
surface_impl_->setExclusiveZone(visible);
|
surface_impl_->setExclusiveZone(visible);
|
||||||
|
surface_impl_->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Bar::toggle() { setVisible(!visible); }
|
void waybar::Bar::toggle() { setVisible(!visible); }
|
||||||
|
|
Loading…
Reference in New Issue