refactor(bar): make setVisible switch between "default" and "invisible" modes

This commit is contained in:
Aleksei Bavshin 2021-11-21 11:00:57 -08:00
parent 87b43c2171
commit 52361ed360
No known key found for this signature in database
GPG Key ID: 4F071603387A382A
2 changed files with 12 additions and 19 deletions

View File

@ -78,7 +78,6 @@ class Bar {
struct waybar_output *output; struct waybar_output *output;
Json::Value config; Json::Value config;
struct wl_surface *surface; struct wl_surface *surface;
bool exclusive = true;
bool visible = true; bool visible = true;
bool vertical = false; bool vertical = false;
Gtk::Window window; Gtk::Window window;
@ -96,7 +95,6 @@ class Bar {
std::string last_mode_{MODE_DEFAULT}; std::string last_mode_{MODE_DEFAULT};
std::unique_ptr<BarSurface> surface_impl_; std::unique_ptr<BarSurface> surface_impl_;
bar_layer layer_;
Gtk::Box left_; Gtk::Box left_;
Gtk::Box center_; Gtk::Box center_;
Gtk::Box right_; Gtk::Box right_;

View File

@ -426,7 +426,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
: output(w_output), : output(w_output),
config(w_config), config(w_config),
window{Gtk::WindowType::WINDOW_TOPLEVEL}, window{Gtk::WindowType::WINDOW_TOPLEVEL},
layer_{bar_layer::BOTTOM},
left_(Gtk::ORIENTATION_HORIZONTAL, 0), left_(Gtk::ORIENTATION_HORIZONTAL, 0),
center_(Gtk::ORIENTATION_HORIZONTAL, 0), center_(Gtk::ORIENTATION_HORIZONTAL, 0),
right_(Gtk::ORIENTATION_HORIZONTAL, 0), right_(Gtk::ORIENTATION_HORIZONTAL, 0),
@ -582,12 +581,18 @@ void waybar::Bar::setMode(const std::string_view& mode) {
} }
void waybar::Bar::setMode(const struct bar_mode& mode) { void waybar::Bar::setMode(const struct bar_mode& mode) {
layer_ = mode.layer; surface_impl_->setLayer(mode.layer);
exclusive = mode.exclusive; surface_impl_->setExclusiveZone(mode.exclusive);
surface_impl_->setLayer(layer_);
surface_impl_->setExclusiveZone(exclusive);
surface_impl_->setPassThrough(mode.passthrough); surface_impl_->setPassThrough(mode.passthrough);
setVisible(mode.visible);
if (mode.visible) {
window.get_style_context()->remove_class("hidden");
window.set_opacity(1);
} else {
window.get_style_context()->add_class("hidden");
window.set_opacity(0);
}
surface_impl_->commit();
} }
void waybar::Bar::onMap(GdkEventAny*) { void waybar::Bar::onMap(GdkEventAny*) {
@ -600,17 +605,7 @@ void waybar::Bar::onMap(GdkEventAny*) {
void waybar::Bar::setVisible(bool value) { void waybar::Bar::setVisible(bool value) {
visible = value; visible = value;
if (!visible) { setMode(visible ? MODE_DEFAULT : MODE_INVISIBLE);
window.get_style_context()->add_class("hidden");
window.set_opacity(0);
surface_impl_->setLayer(bar_layer::BOTTOM);
} else {
window.get_style_context()->remove_class("hidden");
window.set_opacity(1);
surface_impl_->setLayer(layer_);
}
surface_impl_->setExclusiveZone(exclusive && visible);
surface_impl_->commit();
} }
void waybar::Bar::toggle() { setVisible(!visible); } void waybar::Bar::toggle() { setVisible(!visible); }