forked from Alexays/Waybar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhide.cpp
83 lines (70 loc) · 2.41 KB
/
hide.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#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));
// override mode to "hide"
auto &bar_local = const_cast<Bar &>(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();
} else {
bar_local.moveToTopLayer();
}
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) {
std::lock_guard<std::mutex> lock(mutex_);
auto payload = parser_.parse(res.payload);
auto &bar = const_cast<Bar &>(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)");
bar.setVisible(false);
bar.setExclusive(false);
} 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);
}
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.setBottomLayerClass(false);
bar.moveToTopLayer();
return;
}
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();
return;
}
bar.setBottomLayerClass(false);
bar.setHiddenClass(true);
bar.moveToConfiguredLayer();
}
}
auto Hide::update() -> void {
}
} // namespace waybar::modules::sway