forked from Alexays/Waybar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module sway/hide for swaybar integration
This allows auto-showing the bar when the modifier is pressed Closes Alexays#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
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
#include <tuple> | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "modules/sway/hide.hpp" | ||
#include <spdlog/spdlog.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"])"); | ||
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 |