From 52361ed3606311e7f47ff6e6a5357dfb43069d1b Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Sun, 21 Nov 2021 11:00:57 -0800 Subject: [PATCH] refactor(bar): make setVisible switch between "default" and "invisible" modes --- include/bar.hpp | 2 -- src/bar.cpp | 29 ++++++++++++----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 426c55c2..1d7f4a98 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -78,7 +78,6 @@ class Bar { struct waybar_output *output; Json::Value config; struct wl_surface *surface; - bool exclusive = true; bool visible = true; bool vertical = false; Gtk::Window window; @@ -96,7 +95,6 @@ class Bar { std::string last_mode_{MODE_DEFAULT}; std::unique_ptr surface_impl_; - bar_layer layer_; Gtk::Box left_; Gtk::Box center_; Gtk::Box right_; diff --git a/src/bar.cpp b/src/bar.cpp index 43a627ab..a7b24a6b 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -426,7 +426,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) : output(w_output), config(w_config), window{Gtk::WindowType::WINDOW_TOPLEVEL}, - layer_{bar_layer::BOTTOM}, left_(Gtk::ORIENTATION_HORIZONTAL, 0), center_(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) { - layer_ = mode.layer; - exclusive = mode.exclusive; - surface_impl_->setLayer(layer_); - surface_impl_->setExclusiveZone(exclusive); + surface_impl_->setLayer(mode.layer); + surface_impl_->setExclusiveZone(mode.exclusive); 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*) { @@ -600,17 +605,7 @@ void waybar::Bar::onMap(GdkEventAny*) { void waybar::Bar::setVisible(bool value) { visible = value; - if (!visible) { - 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(); + setMode(visible ? MODE_DEFAULT : MODE_INVISIBLE); } void waybar::Bar::toggle() { setVisible(!visible); }