mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(bar): make setVisible switch between "default" and "invisible" modes
This commit is contained in:
parent
87b43c2171
commit
52361ed360
@ -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_;
|
||||||
|
29
src/bar.cpp
29
src/bar.cpp
@ -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); }
|
||||||
|
Loading…
Reference in New Issue
Block a user