From 013bfb9f935d9459a0b9579b4f781fff58e357bb Mon Sep 17 00:00:00 2001 From: Henrik Nyman Date: Wed, 30 Oct 2019 20:27:06 +0200 Subject: [PATCH 01/30] Add suppport for displaying Waybar as an overlay layer Configuration option `layer` can now take a value "overlay", which draws the bar on top of the windows without creating an exclusive zone. --- src/bar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bar.cpp b/src/bar.cpp index 45e342017..8b7693784 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -260,7 +260,7 @@ void waybar::Bar::onMap(GdkEventAny* ev) { void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) { auto zone = 0; - if (visible) { + if (visible && config["layer"] != "overlay") { // exclusive zone already includes margin for anchored edge, // only opposite margin should be added if (vertical) { From 0840184af6dc933b335d1fcaeb76ea16895b14a6 Mon Sep 17 00:00:00 2001 From: Henrik Nyman Date: Wed, 30 Oct 2019 20:38:14 +0200 Subject: [PATCH 02/30] Add module sway/hide for swaybar integration This allows auto-showing the bar when the modifier is pressed Closes #255 Setup instructions: - Set the `mode` of the bar to "hide" in sway configuration file - Set the `layer` of the bar to "overlay" in Waybar configuration file - Add "sway/hide" into `modules-left` in Waybar configuration file --- include/factory.hpp | 1 + include/modules/sway/hide.hpp | 33 ++++++++++++++++++++++++++++++ meson.build | 3 ++- src/factory.cpp | 3 +++ src/modules/sway/hide.cpp | 38 +++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 include/modules/sway/hide.hpp create mode 100644 src/modules/sway/hide.cpp diff --git a/include/factory.hpp b/include/factory.hpp index ebc2359f9..d1658fae4 100644 --- a/include/factory.hpp +++ b/include/factory.hpp @@ -6,6 +6,7 @@ #include "modules/sway/mode.hpp" #include "modules/sway/window.hpp" #include "modules/sway/workspaces.hpp" +#include "modules/sway/hide.hpp" #endif #ifdef HAVE_WLR #include "modules/wlr/taskbar.hpp" diff --git a/include/modules/sway/hide.hpp b/include/modules/sway/hide.hpp new file mode 100644 index 000000000..3dd306765 --- /dev/null +++ b/include/modules/sway/hide.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include "ALabel.hpp" +#include "bar.hpp" +#include "client.hpp" +#include "modules/sway/ipc/client.hpp" +#include "util/json.hpp" +#include "util/sleeper_thread.hpp" + +namespace waybar::modules::sway { + +class Hide : public ALabel, public sigc::trackable { + public: + Hide(const std::string&, const waybar::Bar&, const Json::Value&); + ~Hide() = default; + auto update() -> void; + + private: + void onEvent(const struct Ipc::ipc_response&); + void worker(); + + const Bar& bar_; + std::string window_; + int windowId_; + util::JsonParser parser_; + + util::SleeperThread thread_; + Ipc ipc_; +}; + +} // namespace waybar::modules::sway diff --git a/meson.build b/meson.build index acc8a470f..ccf94da0e 100644 --- a/meson.build +++ b/meson.build @@ -158,7 +158,8 @@ src_files += [ 'src/modules/sway/ipc/client.cpp', 'src/modules/sway/mode.cpp', 'src/modules/sway/window.cpp', - 'src/modules/sway/workspaces.cpp' + 'src/modules/sway/workspaces.cpp', + 'src/modules/sway/hide.cpp', ] if true diff --git a/src/factory.cpp b/src/factory.cpp index af93b20fd..f21880f93 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -22,6 +22,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { if (ref == "sway/window") { return new waybar::modules::sway::Window(id, bar_, config_[name]); } + if (ref == "sway/hide") { + return new waybar::modules::sway::Hide(id, bar_, config_[name]); + } #endif #ifdef HAVE_WLR if (ref == "wlr/taskbar") { diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp new file mode 100644 index 000000000..b31a7d3cf --- /dev/null +++ b/src/modules/sway/hide.cpp @@ -0,0 +1,38 @@ +#include "modules/sway/hide.hpp" +#include + +namespace waybar::modules::sway { + +Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) + : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { + ipc_.subscribe(R"(["bar_state_update"])"); + ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); + bar_.window.get_style_context()->add_class("hidden"); + // Launch worker + worker(); +} + +void Hide::onEvent(const struct Ipc::ipc_response& res) { + + auto payload = parser_.parse(res.payload); + if (payload.isMember("visible_by_modifier")) { + if (payload["visible_by_modifier"].asBool()) + bar_.window.get_style_context()->remove_class("hidden"); + else + bar_.window.get_style_context()->add_class("hidden"); + } +} + +void Hide::worker() { + thread_ = [this] { + try { + ipc_.handleEvent(); + } catch (const std::exception& e) { + spdlog::error("Hide: {}", e.what()); + } + }; +} + +auto Hide::update() -> void { +} +} // namespace waybar::modules::sway From 0e32cff393e0ac1bd33bfa57e3bd506c990c9c53 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 01:57:14 +0100 Subject: [PATCH 03/30] Use layer shell version 2 --- src/modules/sway/hide.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index b31a7d3cf..15c2369cc 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -1,5 +1,7 @@ #include "modules/sway/hide.hpp" #include +#include "client.hpp" +#include "wlr-layer-shell-unstable-v1-client-protocol.h" namespace waybar::modules::sway { @@ -13,13 +15,23 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) } void Hide::onEvent(const struct Ipc::ipc_response& res) { + auto client = waybar::Client::inst(); auto payload = parser_.parse(res.payload); if (payload.isMember("visible_by_modifier")) { - if (payload["visible_by_modifier"].asBool()) + if (payload["visible_by_modifier"].asBool()) { bar_.window.get_style_context()->remove_class("hidden"); - else + zwlr_layer_surface_v1_set_layer(bar_.layer_surface, + ZWLR_LAYER_SHELL_V1_LAYER_TOP + | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY); + } else { bar_.window.get_style_context()->add_class("hidden"); + zwlr_layer_surface_v1_set_layer(bar_.layer_surface, + ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM); + } + + wl_surface_commit(bar_.surface); + wl_display_roundtrip(client->wl_display); } } From 4ecb22b192129ad31f39cc477e59c2ea03b1544b Mon Sep 17 00:00:00 2001 From: gammafn Date: Thu, 2 Jan 2020 08:22:09 -0600 Subject: [PATCH 04/30] (does not build) try to use barconfig_update Currently, it won't build. I am unfamiliar with C++, I don't know what's wrong. --- include/modules/sway/hide.hpp | 2 ++ src/modules/sway/hide.cpp | 39 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/modules/sway/hide.hpp b/include/modules/sway/hide.hpp index 3dd306765..1e4630893 100644 --- a/include/modules/sway/hide.hpp +++ b/include/modules/sway/hide.hpp @@ -21,6 +21,8 @@ class Hide : public ALabel, public sigc::trackable { void onEvent(const struct Ipc::ipc_response&); void worker(); + std::string current_mode; + bool visible_on_modifier; const Bar& bar_; std::string window_; int windowId_; diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 15c2369cc..d85f92de9 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -5,9 +5,12 @@ namespace waybar::modules::sway { +std::string current_mode = "hide"; +bool visible_by_modifier = true; + Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { - ipc_.subscribe(R"(["bar_state_update"])"); + ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); bar_.window.get_style_context()->add_class("hidden"); // Launch worker @@ -18,21 +21,27 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { auto client = waybar::Client::inst(); auto payload = parser_.parse(res.payload); - if (payload.isMember("visible_by_modifier")) { - if (payload["visible_by_modifier"].asBool()) { - bar_.window.get_style_context()->remove_class("hidden"); - zwlr_layer_surface_v1_set_layer(bar_.layer_surface, - ZWLR_LAYER_SHELL_V1_LAYER_TOP - | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY); - } else { - bar_.window.get_style_context()->add_class("hidden"); - zwlr_layer_surface_v1_set_layer(bar_.layer_surface, - ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM); - } - - wl_surface_commit(bar_.surface); - wl_display_roundtrip(client->wl_display); + if (payload.isMember("mode")) { + // barconfig_update: get mode + current_mode = payload["mode"]; + } else if (payload.isMember("visible_by_modifier")) { + // bar_state_update: get visible_by_modifier + visible_by_modifier = payload["visible_by_modifier"].asBool(); + } + if (current_mode == "invisible" + || (current_mode == "hide" && ! visible_by_modifier)) { + bar_.window.get_style_context()->add_class("hidden"); + zwlr_layer_surface_v1_set_layer(bar_.layer_surface, + ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM); + } else { + // TODO: support "bar mode overlay" + bar_.window.get_style_context()->remove_class("hidden"); + zwlr_layer_surface_v1_set_layer(bar_.layer_surface, + ZWLR_LAYER_SHELL_V1_LAYER_TOP + | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY); } + wl_surface_commit(bar_.surface); + wl_display_roundtrip(client->wl_display); } void Hide::worker() { From 4ec1718454cd719aad3980f2bdc25a32b982be98 Mon Sep 17 00:00:00 2001 From: gammafn Date: Thu, 2 Jan 2020 09:50:40 -0600 Subject: [PATCH 05/30] fix: thanks nyyManni This is also a rebase-fix --- include/bar.hpp | 2 +- include/modules/sway/hide.hpp | 4 ++-- src/modules/sway/hide.cpp | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index fdc5a7397..46e2cab1d 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -35,6 +35,7 @@ class Bar { struct waybar_output *output; Json::Value config; struct wl_surface * surface; + struct zwlr_layer_surface_v1 *layer_surface_; bool visible = true; bool vertical = false; Gtk::Window window; @@ -76,7 +77,6 @@ class Bar { int bottom = 0; int left = 0; } margins_; - struct zwlr_layer_surface_v1 *layer_surface_; // use gtk-layer-shell instead of handling layer surfaces directly bool use_gls_ = false; uint32_t width_ = 0; diff --git a/include/modules/sway/hide.hpp b/include/modules/sway/hide.hpp index 1e4630893..f3374b2a1 100644 --- a/include/modules/sway/hide.hpp +++ b/include/modules/sway/hide.hpp @@ -21,8 +21,8 @@ class Hide : public ALabel, public sigc::trackable { void onEvent(const struct Ipc::ipc_response&); void worker(); - std::string current_mode; - bool visible_on_modifier; + std::string current_mode_; + bool visible_by_modifier_; const Bar& bar_; std::string window_; int windowId_; diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index d85f92de9..cfc31af1a 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -5,9 +5,6 @@ namespace waybar::modules::sway { -std::string current_mode = "hide"; -bool visible_by_modifier = true; - Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); @@ -23,13 +20,13 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { auto payload = parser_.parse(res.payload); if (payload.isMember("mode")) { // barconfig_update: get mode - current_mode = payload["mode"]; + current_mode_ = payload["mode"].asString(); } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier - visible_by_modifier = payload["visible_by_modifier"].asBool(); + visible_by_modifier_ = payload["visible_by_modifier"].asBool(); } - if (current_mode == "invisible" - || (current_mode == "hide" && ! visible_by_modifier)) { + if (current_mode_ == "invisible" + || (current_mode_ == "hide" && ! visible_by_modifier_)) { bar_.window.get_style_context()->add_class("hidden"); zwlr_layer_surface_v1_set_layer(bar_.layer_surface, ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM); From 551973a9c922f2985be2b1217582453135307ca9 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 02:52:29 +0100 Subject: [PATCH 06/30] Define bar setVisible method Call this when toggling visibility with SIGUSR1, and for `sway/hide` events. --- include/bar.hpp | 3 ++- src/bar.cpp | 8 ++++++-- src/modules/sway/hide.cpp | 21 +++++---------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 46e2cab1d..ad83c8a23 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -30,12 +30,12 @@ class Bar { ~Bar() = default; auto toggle() -> void; + auto setVisible(bool) -> void; void handleSignal(int); struct waybar_output *output; Json::Value config; struct wl_surface * surface; - struct zwlr_layer_surface_v1 *layer_surface_; bool visible = true; bool vertical = false; Gtk::Window window; @@ -77,6 +77,7 @@ class Bar { int bottom = 0; int left = 0; } margins_; + struct zwlr_layer_surface_v1 *layer_surface_; // use gtk-layer-shell instead of handling layer surfaces directly bool use_gls_ = false; uint32_t width_ = 0; diff --git a/src/bar.cpp b/src/bar.cpp index 8b7693784..d407ebe48 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -389,8 +389,8 @@ void waybar::Bar::layerSurfaceHandleClosed(void* data, struct zwlr_layer_surface o->modules_right_.clear(); } -auto waybar::Bar::toggle() -> void { - visible = !visible; +auto waybar::Bar::setVisible(bool nvis) -> void { + visible = nvis; if (!visible) { window.get_style_context()->add_class("hidden"); window.set_opacity(0); @@ -404,6 +404,10 @@ auto waybar::Bar::toggle() -> void { } } +auto waybar::Bar::toggle() -> void { + return setVisible(!visible); +} + void waybar::Bar::getModules(const Factory& factory, const std::string& pos) { if (config[pos].isArray()) { for (const auto& name : config[pos]) { diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index cfc31af1a..9d365e447 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -1,3 +1,4 @@ +#include #include "modules/sway/hide.hpp" #include #include "client.hpp" @@ -15,8 +16,6 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) } void Hide::onEvent(const struct Ipc::ipc_response& res) { - auto client = waybar::Client::inst(); - auto payload = parser_.parse(res.payload); if (payload.isMember("mode")) { // barconfig_update: get mode @@ -24,21 +23,11 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); + std::cerr << "WayBar Hide: " << payload["visible_by_modifier"] << std::endl; + for (auto& bar : waybar::Client::inst()->bars) { + bar->setVisible(visible_by_modifier_); + } } - if (current_mode_ == "invisible" - || (current_mode_ == "hide" && ! visible_by_modifier_)) { - bar_.window.get_style_context()->add_class("hidden"); - zwlr_layer_surface_v1_set_layer(bar_.layer_surface, - ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM); - } else { - // TODO: support "bar mode overlay" - bar_.window.get_style_context()->remove_class("hidden"); - zwlr_layer_surface_v1_set_layer(bar_.layer_surface, - ZWLR_LAYER_SHELL_V1_LAYER_TOP - | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY); - } - wl_surface_commit(bar_.surface); - wl_display_roundtrip(client->wl_display); } void Hide::worker() { From 2253f3e0a27be97a2b9d2e1a4e987dba530846e5 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:13:36 +0100 Subject: [PATCH 07/30] Include mutext on Hide::onEvent This doesn't solve the issue, but it crashes less often... --- include/modules/sway/hide.hpp | 2 ++ src/modules/sway/hide.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/include/modules/sway/hide.hpp b/include/modules/sway/hide.hpp index f3374b2a1..90a054d88 100644 --- a/include/modules/sway/hide.hpp +++ b/include/modules/sway/hide.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "ALabel.hpp" #include "bar.hpp" #include "client.hpp" @@ -29,6 +30,7 @@ class Hide : public ALabel, public sigc::trackable { util::JsonParser parser_; util::SleeperThread thread_; + std::mutex mutex_; Ipc ipc_; }; diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 9d365e447..4a7d8c6a6 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -17,6 +17,7 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) void Hide::onEvent(const struct Ipc::ipc_response& res) { auto payload = parser_.parse(res.payload); + std::lock_guard lock(mutex_); if (payload.isMember("mode")) { // barconfig_update: get mode current_mode_ = payload["mode"].asString(); From f1cd85f9babec86ed02a90392bd730bfcb0cfc2f Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:14:17 +0100 Subject: [PATCH 08/30] Improve debug logs --- src/modules/sway/hide.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 4a7d8c6a6..b33f5f647 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -24,7 +24,7 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); - std::cerr << "WayBar Hide: " << payload["visible_by_modifier"] << std::endl; + std::cerr << "WayBar Shown: " << payload["visible_by_modifier"] << std::endl; for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(visible_by_modifier_); } From af0b18285ee680bb7b1da456e708302876f14531 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:14:39 +0100 Subject: [PATCH 09/30] Remove support for "overlay" layer Keep this as similar to "upstream" as possible. --- src/bar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bar.cpp b/src/bar.cpp index d407ebe48..5f2cac277 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -260,7 +260,7 @@ void waybar::Bar::onMap(GdkEventAny* ev) { void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) { auto zone = 0; - if (visible && config["layer"] != "overlay") { + if (visible) { // exclusive zone already includes margin for anchored edge, // only opposite margin should be added if (vertical) { From d427a5b709a5beea22e6c71c00e8db13548275c8 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:25:30 +0100 Subject: [PATCH 10/30] Hide the bar on creation, in "hide" mode --- src/modules/sway/hide.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index b33f5f647..ad76313a2 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -20,7 +20,13 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { std::lock_guard lock(mutex_); if (payload.isMember("mode")) { // barconfig_update: get mode - current_mode_ = payload["mode"].asString(); + auto mode = payload["mode"].asString(); + if (mode == "hide") { + // Hide the bars when configuring the "hide" bar + for (auto& bar : waybar::Client::inst()->bars) { + bar->setVisible(false); + } + } } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); From 3b1564510ee294f3f3f08fce6fbe3ee42ad412c5 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:33:14 +0100 Subject: [PATCH 11/30] Use logging module --- src/modules/sway/hide.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index ad76313a2..e370c86ef 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -1,4 +1,3 @@ -#include #include "modules/sway/hide.hpp" #include #include "client.hpp" @@ -30,7 +29,7 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); - std::cerr << "WayBar Shown: " << payload["visible_by_modifier"] << std::endl; + spdlog::info("WayBar Shown: {}", visible_by_modifier_); for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(visible_by_modifier_); } From 979a478ddfd0559fef64771500f00611a48556b1 Mon Sep 17 00:00:00 2001 From: somini Date: Mon, 21 Sep 2020 23:35:43 +0100 Subject: [PATCH 12/30] Don't auto-hide the bar on start This is a CSS-only change. It should be properly hidden. --- src/modules/sway/hide.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index e370c86ef..b8f6f7ab1 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -9,7 +9,6 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); - bar_.window.get_style_context()->add_class("hidden"); // Launch worker worker(); } From e2590fc36b721d02c1c11684f7857be04cbaa3a8 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Mon, 13 Sep 2021 00:23:31 +0200 Subject: [PATCH 13/30] Removed unnecessary functions and methods. --- src/bar.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index 62a92fa80..49c0e6d45 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -529,23 +529,6 @@ void waybar::Bar::onMap(GdkEventAny*) { surface = gdk_wayland_window_get_wl_surface(gdk_window); } -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(); -} - -void waybar::Bar::toggle() { setVisible(!visible); } - // Converting string to button code rn as to avoid doing it later void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) { if (config.isMember(module_name)) { @@ -607,35 +590,6 @@ void waybar::Bar::handleSignal(int signal) { } } -void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surface_v1* surface, - uint32_t serial, uint32_t width, uint32_t height) { - auto o = static_cast(data); - if (width != o->width_ || height != o->height_) { - o->width_ = width; - o->height_ = height; - o->window.set_size_request(o->width_, o->height_); - o->window.resize(o->width_, o->height_); - o->setExclusiveZone(width, height); - spdlog::info(BAR_SIZE_MSG, - o->width_ == 1 ? "auto" : std::to_string(o->width_), - o->height_ == 1 ? "auto" : std::to_string(o->height_), - o->output->name); - wl_surface_commit(o->surface); - } - zwlr_layer_surface_v1_ack_configure(surface, serial); -} - -void waybar::Bar::layerSurfaceHandleClosed(void* data, struct zwlr_layer_surface_v1* /*surface*/) { - auto o = static_cast(data); - if (o->layer_surface_) { - zwlr_layer_surface_v1_destroy(o->layer_surface_); - o->layer_surface_ = nullptr; - } - o->modules_left_.clear(); - o->modules_center_.clear(); - o->modules_right_.clear(); -} - auto waybar::Bar::setVisible(bool nvis) -> void { visible = nvis; if (!visible) { From 13fbf81eb3d0675b34a9e537b71723ccf20b0659 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Mon, 13 Sep 2021 00:24:34 +0200 Subject: [PATCH 14/30] Bugfix, set_opacity statements lead to address boundary SIGSEGV. --- src/bar.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index 49c0e6d45..1e5f0f29f 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -594,15 +594,10 @@ auto waybar::Bar::setVisible(bool nvis) -> void { visible = nvis; if (!visible) { window.get_style_context()->add_class("hidden"); - window.set_opacity(0); } else { window.get_style_context()->remove_class("hidden"); - window.set_opacity(1); - } - setExclusiveZone(width_, height_); - if (!use_gls_) { - wl_surface_commit(surface); } + wl_surface_commit(surface); } auto waybar::Bar::toggle() -> void { From 1c7133c426902d4ebb46acddfffc60878a710163 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Mon, 13 Sep 2021 00:25:05 +0200 Subject: [PATCH 15/30] Updated layer settings. --- include/bar.hpp | 4 ++-- src/bar.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 6f3dfcf97..6ddda6621 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -58,8 +58,8 @@ class Bar { Bar(const Bar &) = delete; ~Bar() = default; - void setVisible(bool visible); - void toggle(); + auto setVisible(bool nvis) -> void; + auto toggle() -> void; void handleSignal(int); struct waybar_output *output; diff --git a/src/bar.cpp b/src/bar.cpp index 1e5f0f29f..ac4a72b3a 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -594,8 +594,10 @@ auto waybar::Bar::setVisible(bool nvis) -> void { visible = nvis; if (!visible) { window.get_style_context()->add_class("hidden"); + surface_impl_->setLayer(bar_layer::BOTTOM); } else { window.get_style_context()->remove_class("hidden"); + surface_impl_->setLayer(bar_layer::TOP); } wl_surface_commit(surface); } From 564e2311501fdd7957d5763a528d4adf6b6ae569 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Mon, 13 Sep 2021 00:25:30 +0200 Subject: [PATCH 16/30] Exclusive zone is now removed on intialization of the hide module. --- include/bar.hpp | 1 + src/bar.cpp | 4 ++++ src/modules/sway/hide.cpp | 2 ++ 3 files changed, 7 insertions(+) diff --git a/include/bar.hpp b/include/bar.hpp index 6ddda6621..75501212c 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -60,6 +60,7 @@ class Bar { auto setVisible(bool nvis) -> void; auto toggle() -> void; + auto removeExclusiveZone() const -> void; void handleSignal(int); struct waybar_output *output; diff --git a/src/bar.cpp b/src/bar.cpp index ac4a72b3a..6f6a3cc15 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -602,6 +602,10 @@ auto waybar::Bar::setVisible(bool nvis) -> void { wl_surface_commit(surface); } +auto waybar::Bar::removeExclusiveZone() const -> void { + surface_impl_->setExclusiveZone(false); +} + auto waybar::Bar::toggle() -> void { return setVisible(!visible); } diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index b8f6f7ab1..aaf783320 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -9,6 +9,8 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); + // Do not reserve space for the bar anymore + bar.removeExclusiveZone(); // Launch worker worker(); } From 2e2853199133e868c1069bae0e0200e92a223024 Mon Sep 17 00:00:00 2001 From: gammafn Date: Mon, 13 Sep 2021 16:53:10 -0500 Subject: [PATCH 17/30] sway/hide: Enable exclusive zone on {"mode":"dock"} --- include/bar.hpp | 1 + src/bar.cpp | 4 ++++ src/modules/sway/hide.cpp | 10 +++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/bar.hpp b/include/bar.hpp index 75501212c..22210929b 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -61,6 +61,7 @@ class Bar { auto setVisible(bool nvis) -> void; auto toggle() -> void; auto removeExclusiveZone() const -> void; + auto enableExclusiveZone() const -> void; void handleSignal(int); struct waybar_output *output; diff --git a/src/bar.cpp b/src/bar.cpp index 6f6a3cc15..b9f34c64e 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -606,6 +606,10 @@ auto waybar::Bar::removeExclusiveZone() const -> void { surface_impl_->setExclusiveZone(false); } +auto waybar::Bar::enableExclusiveZone() const -> void { + surface_impl_->setExclusiveZone(true); +} + auto waybar::Bar::toggle() -> void { return setVisible(!visible); } diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index aaf783320..637e9a127 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -23,10 +23,18 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { auto mode = payload["mode"].asString(); if (mode == "hide") { // Hide the bars when configuring the "hide" bar + spdlog::info("sway/hide: hiding bar(s)"); for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(false); + bar->removeExclusiveZone(); } - } + } else if (mode == "dock") { + spdlog::info("sway/hide: showing bar(s)"); + for (auto& bar : waybar::Client::inst()->bars) { + bar->setVisible(true); + bar->enableExclusiveZone(); + } + } } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); From 208351c1c7afdfc89bb5ff585973724f5dddc95f Mon Sep 17 00:00:00 2001 From: gammafn Date: Mon, 13 Sep 2021 16:54:49 -0500 Subject: [PATCH 18/30] sway/hide: Print at debug level when receiving visible_by_modifier --- src/modules/sway/hide.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 637e9a127..f5a0b70c4 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -38,7 +38,7 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { } else if (payload.isMember("visible_by_modifier")) { // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); - spdlog::info("WayBar Shown: {}", visible_by_modifier_); + spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_); for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(visible_by_modifier_); } From 24a8e858c17697de3a172221f9410e177ea31382 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 14 Sep 2021 15:06:34 +0200 Subject: [PATCH 19/30] Reset unnecessary change of function declaration. --- include/bar.hpp | 4 ++-- src/bar.cpp | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 75501212c..497aa54ef 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -58,8 +58,8 @@ class Bar { Bar(const Bar &) = delete; ~Bar() = default; - auto setVisible(bool nvis) -> void; - auto toggle() -> void; + void setVisible(bool visible); + void toggle(); auto removeExclusiveZone() const -> void; void handleSignal(int); diff --git a/src/bar.cpp b/src/bar.cpp index 6f6a3cc15..dae2bc5d3 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -590,8 +590,7 @@ void waybar::Bar::handleSignal(int signal) { } } -auto waybar::Bar::setVisible(bool nvis) -> void { - visible = nvis; +void waybar::Bar::setVisible(bool visible) { if (!visible) { window.get_style_context()->add_class("hidden"); surface_impl_->setLayer(bar_layer::BOTTOM); @@ -606,7 +605,7 @@ auto waybar::Bar::removeExclusiveZone() const -> void { surface_impl_->setExclusiveZone(false); } -auto waybar::Bar::toggle() -> void { +void waybar::Bar::toggle() { return setVisible(!visible); } From 11337dcad4093c885ae33bf3a27bce98cce3c3d7 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 14 Sep 2021 15:07:15 +0200 Subject: [PATCH 20/30] Fixed wl_surface_commit call. --- src/bar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bar.cpp b/src/bar.cpp index dae2bc5d3..37196aea2 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -598,7 +598,7 @@ void waybar::Bar::setVisible(bool visible) { window.get_style_context()->remove_class("hidden"); surface_impl_->setLayer(bar_layer::TOP); } - wl_surface_commit(surface); + surface_impl_->commit(); } auto waybar::Bar::removeExclusiveZone() const -> void { From 0aecb788008f997077a6f2f7ce198a59d95d8790 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 14 Sep 2021 15:34:25 +0200 Subject: [PATCH 21/30] Restored implementation of setVisible (to master branch state). --- src/bar.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index fda19821d..bfac65e32 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -590,14 +590,18 @@ void waybar::Bar::handleSignal(int signal) { } } -void waybar::Bar::setVisible(bool visible) { +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"); - surface_impl_->setLayer(bar_layer::TOP); + window.set_opacity(1); + surface_impl_->setLayer(layer_); } + surface_impl_->setExclusiveZone(exclusive && visible); surface_impl_->commit(); } From 6c3b7e4ec2721b2a86dd46b92c032619c9806161 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 14 Sep 2021 16:48:34 +0200 Subject: [PATCH 22/30] Replaced enable-/removeExclusiveZone by setExclusive. --- include/bar.hpp | 3 +-- src/bar.cpp | 8 ++++---- src/modules/sway/hide.cpp | 9 +++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 5f6def6ad..5e9dd24e4 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -60,8 +60,7 @@ class Bar { void setVisible(bool visible); void toggle(); - auto removeExclusiveZone() const -> void; - auto enableExclusiveZone() const -> void; + void setExclusive(bool value); void handleSignal(int); struct waybar_output *output; diff --git a/src/bar.cpp b/src/bar.cpp index bfac65e32..e5c1dcaf0 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -605,12 +605,12 @@ void waybar::Bar::setVisible(bool value) { surface_impl_->commit(); } -auto waybar::Bar::removeExclusiveZone() const -> void { - surface_impl_->setExclusiveZone(false); } -auto waybar::Bar::enableExclusiveZone() const -> void { - surface_impl_->setExclusiveZone(true); +void waybar::Bar::setExclusive(bool value) { + exclusive = value; + surface_impl_->setExclusiveZone(exclusive && visible); + surface_impl_->commit(); } void waybar::Bar::toggle() { diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index f5a0b70c4..8c5c3e546 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -9,8 +9,6 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); - // Do not reserve space for the bar anymore - bar.removeExclusiveZone(); // Launch worker worker(); } @@ -19,20 +17,19 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { auto payload = parser_.parse(res.payload); std::lock_guard lock(mutex_); if (payload.isMember("mode")) { - // barconfig_update: get mode auto mode = payload["mode"].asString(); if (mode == "hide") { // Hide the bars when configuring the "hide" bar - spdlog::info("sway/hide: hiding bar(s)"); + spdlog::debug("sway/hide: hiding bar(s)"); for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(false); - bar->removeExclusiveZone(); + bar->setExclusive(false); } } else if (mode == "dock") { spdlog::info("sway/hide: showing bar(s)"); for (auto& bar : waybar::Client::inst()->bars) { bar->setVisible(true); - bar->enableExclusiveZone(); + bar->setExclusive(true); } } } else if (payload.isMember("visible_by_modifier")) { From c11aecdb08e3a2a0a61003437c71922446c7e486 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 14 Sep 2021 16:51:02 +0200 Subject: [PATCH 23/30] Modifier key now sends the bar to TOP or BOTTOM layer, hidden class gets updated --- include/bar.hpp | 3 +++ src/bar.cpp | 16 ++++++++++++++++ src/modules/sway/hide.cpp | 12 +++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 5e9dd24e4..823a3eb6d 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -59,6 +59,9 @@ class Bar { ~Bar() = default; void setVisible(bool visible); + void setHiddenClass(bool value); + void moveToTopLayer(); + void moveToBottomLayer(); void toggle(); void setExclusive(bool value); void handleSignal(int); diff --git a/src/bar.cpp b/src/bar.cpp index e5c1dcaf0..ebaf0373c 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -605,6 +605,22 @@ void waybar::Bar::setVisible(bool value) { surface_impl_->commit(); } +void waybar::Bar::setHiddenClass(bool value) { + if (value) { + window.get_style_context()->add_class("hidden"); + } else { + window.get_style_context()->remove_class("hidden"); + } +} + +void waybar::Bar::moveToTopLayer() { + surface_impl_->setLayer(bar_layer::TOP); + surface_impl_->commit(); +} + +void waybar::Bar::moveToBottomLayer() { + surface_impl_->setLayer(bar_layer::BOTTOM); + surface_impl_->commit(); } void waybar::Bar::setExclusive(bool value) { diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 8c5c3e546..ac616f473 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -31,13 +31,19 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { bar->setVisible(true); bar->setExclusive(true); } - } + } } else if (payload.isMember("visible_by_modifier")) { - // bar_state_update: get visible_by_modifier visible_by_modifier_ = payload["visible_by_modifier"].asBool(); spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_); for (auto& bar : waybar::Client::inst()->bars) { - bar->setVisible(visible_by_modifier_); + if (visible_by_modifier_) { + bar->setHiddenClass(false); + bar->moveToTopLayer(); + } else { + bar->setHiddenClass(true); + bar->moveToBottomLayer(); + bar->setExclusive(false); + } } } } From 73de008a6a67a4e3c41001130d47756fcdece151 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Wed, 15 Sep 2021 23:08:46 +0200 Subject: [PATCH 24/30] The sway/hide module is now limited to the bar passed by the constructor. --- include/bar.hpp | 6 +++--- src/bar.cpp | 8 ++++---- src/modules/sway/hide.cpp | 34 +++++++++++++++------------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 823a3eb6d..d40910195 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -59,9 +59,9 @@ class Bar { ~Bar() = default; void setVisible(bool visible); - void setHiddenClass(bool value); - void moveToTopLayer(); - void moveToBottomLayer(); + void setHiddenClass(bool value) const; + void moveToTopLayer() const; + void moveToConfiguredLayer() const; void toggle(); void setExclusive(bool value); void handleSignal(int); diff --git a/src/bar.cpp b/src/bar.cpp index ebaf0373c..8794177bf 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -605,7 +605,7 @@ void waybar::Bar::setVisible(bool value) { surface_impl_->commit(); } -void waybar::Bar::setHiddenClass(bool value) { +void waybar::Bar::setHiddenClass(bool value) const { if (value) { window.get_style_context()->add_class("hidden"); } else { @@ -613,13 +613,13 @@ void waybar::Bar::setHiddenClass(bool value) { } } -void waybar::Bar::moveToTopLayer() { +void waybar::Bar::moveToTopLayer() const { surface_impl_->setLayer(bar_layer::TOP); surface_impl_->commit(); } -void waybar::Bar::moveToBottomLayer() { - surface_impl_->setLayer(bar_layer::BOTTOM); +void waybar::Bar::moveToConfiguredLayer() const { + surface_impl_->setLayer(layer_); surface_impl_->commit(); } diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index ac616f473..83008d23f 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -15,37 +15,33 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) void Hide::onEvent(const struct Ipc::ipc_response& res) { auto payload = parser_.parse(res.payload); - std::lock_guard lock(mutex_); + mutex_.lock(); + auto &bar = const_cast(bar_); if (payload.isMember("mode")) { auto mode = payload["mode"].asString(); if (mode == "hide") { // Hide the bars when configuring the "hide" bar spdlog::debug("sway/hide: hiding bar(s)"); - for (auto& bar : waybar::Client::inst()->bars) { - bar->setVisible(false); - bar->setExclusive(false); - } + bar.setVisible(false); + bar.setExclusive(false); } else if (mode == "dock") { - spdlog::info("sway/hide: showing bar(s)"); - for (auto& bar : waybar::Client::inst()->bars) { - bar->setVisible(true); - bar->setExclusive(true); - } + spdlog::debug("sway/hide: showing bar(s)"); + bar.setVisible(true); + bar.setExclusive(true); } } else if (payload.isMember("visible_by_modifier")) { visible_by_modifier_ = payload["visible_by_modifier"].asBool(); spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_); - for (auto& bar : waybar::Client::inst()->bars) { - if (visible_by_modifier_) { - bar->setHiddenClass(false); - bar->moveToTopLayer(); - } else { - bar->setHiddenClass(true); - bar->moveToBottomLayer(); - bar->setExclusive(false); - } + if (visible_by_modifier_) { + bar.setHiddenClass(false); + bar.moveToTopLayer(); + } else { + bar.setHiddenClass(true); + bar.moveToConfiguredLayer(); + bar.setExclusive(false); } } + mutex_.unlock(); } void Hide::worker() { From 09da1f03e59837107bdeb151c39e02741ee4c36d Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Mon, 20 Sep 2021 12:36:51 +0200 Subject: [PATCH 25/30] The mode value is now overridden to "hide" on construction of modules::sway::Hide. --- src/modules/sway/hide.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index 83008d23f..f74ec62da 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -9,6 +9,11 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["bar_state_update","barconfig_update"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); + + // override mode to "hide" + auto &bar_local = const_cast(bar_); + bar_local.config["mode"] = "hide"; + // Launch worker worker(); } From 55ff12aaefc9d7340f415442192f9b68d0d9da67 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 26 Oct 2021 15:08:58 +0200 Subject: [PATCH 26/30] Changed how mutex is locked. --- src/modules/sway/hide.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index f74ec62da..ab4a9759e 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -19,8 +19,8 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) } void Hide::onEvent(const struct Ipc::ipc_response& res) { + std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); - mutex_.lock(); auto &bar = const_cast(bar_); if (payload.isMember("mode")) { auto mode = payload["mode"].asString(); @@ -29,7 +29,7 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { spdlog::debug("sway/hide: hiding bar(s)"); bar.setVisible(false); bar.setExclusive(false); - } else if (mode == "dock") { + } else if (mode == "dock") { // enables toggling the bar using killall -USR2 waybar spdlog::debug("sway/hide: showing bar(s)"); bar.setVisible(true); bar.setExclusive(true); @@ -46,7 +46,6 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { bar.setExclusive(false); } } - mutex_.unlock(); } void Hide::worker() { @@ -61,4 +60,5 @@ void Hide::worker() { auto Hide::update() -> void { } + } // namespace waybar::modules::sway From cf2312f3e28598ea320d320e2fa5f5591a9cceca Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Wed, 27 Oct 2021 10:35:28 +0200 Subject: [PATCH 27/30] Added config parameter to hide the bar on startup. Set "hide-on-startup" to true in your sway/hide config to enable. --- src/modules/sway/hide.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index ab4a9759e..bf1042c46 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -14,6 +14,13 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) auto &bar_local = const_cast(bar_); bar_local.config["mode"] = "hide"; + if (config_["hide-on-startup"].asBool()) { + spdlog::debug("sway/hide: Hiding on startup enabled!"); + bar_local.setHiddenClass(true); + bar_local.moveToConfiguredLayer(); + bar_local.setExclusive(false); + } + // Launch worker worker(); } From d9de7c4d86362e359d2d1c128ad68430f9799e4d Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Wed, 3 Nov 2021 09:40:21 +0100 Subject: [PATCH 28/30] Refactoring sway/hide module, added hide-to-bottom-layer option --- include/bar.hpp | 2 ++ src/bar.cpp | 13 +++++++++++++ src/modules/sway/hide.cpp | 38 +++++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index d40910195..030e1e35b 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -60,7 +60,9 @@ class Bar { void setVisible(bool visible); void setHiddenClass(bool value) const; + void setBottomLayerClass(bool value) const; void moveToTopLayer() const; + void moveToBottomLayer() const; void moveToConfiguredLayer() const; void toggle(); void setExclusive(bool value); diff --git a/src/bar.cpp b/src/bar.cpp index d1809f63f..08adde8a6 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -620,11 +620,24 @@ void waybar::Bar::setHiddenClass(bool value) const { } } +void waybar::Bar::setBottomLayerClass(bool value) const { + if (value) { + window.get_style_context()->add_class("bottom-layer"); + } else { + window.get_style_context()->remove_class("bottom-layer"); + } +} + void waybar::Bar::moveToTopLayer() const { surface_impl_->setLayer(bar_layer::TOP); surface_impl_->commit(); } +void waybar::Bar::moveToBottomLayer() const { + surface_impl_->setLayer(bar_layer::BOTTOM); + surface_impl_->commit(); +} + void waybar::Bar::moveToConfiguredLayer() const { surface_impl_->setLayer(layer_); surface_impl_->commit(); diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index bf1042c46..f85e514de 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -13,12 +13,14 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) // override mode to "hide" auto &bar_local = const_cast(bar_); bar_local.config["mode"] = "hide"; + bar_local.setExclusive(false); if (config_["hide-on-startup"].asBool()) { - spdlog::debug("sway/hide: Hiding on startup enabled!"); - bar_local.setHiddenClass(true); - bar_local.moveToConfiguredLayer(); - bar_local.setExclusive(false); + spdlog::debug("sway/hide: Hiding on startup enabled!"); + bar_local.setHiddenClass(true); + bar_local.moveToConfiguredLayer(); + } else { + bar_local.moveToTopLayer(); } // Launch worker @@ -29,6 +31,7 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); auto &bar = const_cast(bar_); + if (payload.isMember("mode")) { auto mode = payload["mode"].asString(); if (mode == "hide") { @@ -41,17 +44,30 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { bar.setVisible(true); bar.setExclusive(true); } - } else if (payload.isMember("visible_by_modifier")) { + return; + } + + if (payload.isMember("visible_by_modifier")) { visible_by_modifier_ = payload["visible_by_modifier"].asBool(); spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_); + if (visible_by_modifier_) { - bar.setHiddenClass(false); - bar.moveToTopLayer(); - } else { - bar.setHiddenClass(true); - bar.moveToConfiguredLayer(); - bar.setExclusive(false); + bar.setHiddenClass(false); + bar.setBottomLayerClass(false); + bar.moveToTopLayer(); + return; } + + if (config_["hide-to-bottom-layer"].asBool()) { + spdlog::debug("sway/hide: Moving bar to bottom layer instead of hiding."); + bar.setBottomLayerClass(true); + bar.moveToBottomLayer(); + return; + } + + bar.setBottomLayerClass(false); + bar.setHiddenClass(true); + bar.moveToConfiguredLayer(); } } From 0cee530d363a64c7f1644fdbc0d7d1eb114fe1e2 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Wed, 3 Nov 2021 10:31:14 +0100 Subject: [PATCH 29/30] Config option hide-to-bottom-layer is now queried separately --- src/modules/sway/hide.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index f85e514de..ca3ee48a6 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -58,7 +58,8 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { return; } - if (config_["hide-to-bottom-layer"].asBool()) { + bool hide_to_bottom_layer_ = config_["hide-to-bottom-layer"].asBool(); + if (hide_to_bottom_layer_) { spdlog::debug("sway/hide: Moving bar to bottom layer instead of hiding."); bar.setBottomLayerClass(true); bar.moveToBottomLayer(); From 3e21eb8ebbb52a254d16a5161558f0eb417519c4 Mon Sep 17 00:00:00 2001 From: Lewin Probst Date: Tue, 9 Nov 2021 14:57:01 +0100 Subject: [PATCH 30/30] Replaced worker method by a call to ipc_.setWorker. --- src/modules/sway/hide.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/modules/sway/hide.cpp b/src/modules/sway/hide.cpp index ca3ee48a6..c5984e2db 100644 --- a/src/modules/sway/hide.cpp +++ b/src/modules/sway/hide.cpp @@ -23,8 +23,13 @@ Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config) bar_local.moveToTopLayer(); } - // Launch worker - worker(); + ipc_.setWorker([this] { + try { + ipc_.handleEvent(); + } catch (const std::exception& e) { + spdlog::error("Hide: {}", e.what()); + } + }); } void Hide::onEvent(const struct Ipc::ipc_response& res) { @@ -72,16 +77,6 @@ void Hide::onEvent(const struct Ipc::ipc_response& res) { } } -void Hide::worker() { - thread_ = [this] { - try { - ipc_.handleEvent(); - } catch (const std::exception& e) { - spdlog::error("Hide: {}", e.what()); - } - }; -} - auto Hide::update() -> void { }