-
-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add module "sway/hide" for swaybar integration #860
Changes from all commits
013bfb9
0840184
0e32cff
4ecb22b
4ec1718
551973a
2253f3e
f1cd85f
af0b182
d427a5b
3b15645
979a478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
#include <tuple> | ||
#include <mutex> | ||
#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(); | ||
|
||
std::string current_mode_; | ||
bool visible_by_modifier_; | ||
const Bar& bar_; | ||
std::string window_; | ||
int windowId_; | ||
util::JsonParser parser_; | ||
|
||
util::SleeperThread thread_; | ||
std::mutex mutex_; | ||
Ipc ipc_; | ||
}; | ||
|
||
} // namespace waybar::modules::sway |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "modules/sway/hide.hpp" | ||
#include <spdlog/spdlog.h> | ||
#include "client.hpp" | ||
#include "wlr-layer-shell-unstable-v1-client-protocol.h" | ||
|
||
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","barconfig_update"])"); | ||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent)); | ||
// Launch worker | ||
worker(); | ||
} | ||
|
||
void Hide::onEvent(const struct Ipc::ipc_response& res) { | ||
auto payload = parser_.parse(res.payload); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a mutex here, might fix your crash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My C++ knowledge is almost 0, I just copy pasted some bits from other places that looked correct. 😞 2253f3e crashes less, but it still fails. Logs:
Sounds like hiding a painting bar is a no-no. I think the mutex should be on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rebased this to the latest master and force-pushed |
||
std::lock_guard<std::mutex> lock(mutex_); | ||
if (payload.isMember("mode")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that each waybar instance supposed to have bar id ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to use just call |
||
// barconfig_update: get mode | ||
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(); | ||
spdlog::info("WayBar Shown: {}", visible_by_modifier_); | ||
for (auto& bar : waybar::Client::inst()->bars) { | ||
bar->setVisible(visible_by_modifier_); | ||
} | ||
} | ||
} | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that be a module?
Maybe we can implement it as a generic SwayBarConfigHandler class that is created by the
waybar::Client
instance when the SWAYSOCK is defined and controls all the bars.The benefit is that on multi-monitor configurations bar events would be handled once.