Merge pull request #2917 from alttabber/master
Add always on option for hyprland/submap
This commit is contained in:
commit
32e241dc47
|
@ -19,12 +19,15 @@ class Submap : public waybar::ALabel, public EventHandler {
|
||||||
auto update() -> void override;
|
auto update() -> void override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
auto parseConfig(const Json::Value&) -> void;
|
||||||
void onEvent(const std::string& ev) override;
|
void onEvent(const std::string& ev) override;
|
||||||
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
std::string submap_;
|
std::string submap_;
|
||||||
|
bool always_on_ = false;
|
||||||
|
std::string default_submap_ = "Default";
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::hyprland
|
} // namespace waybar::modules::hyprland
|
||||||
|
|
|
@ -70,6 +70,16 @@ Addressed by *hyprland/submap*
|
||||||
default: true ++
|
default: true ++
|
||||||
Option to disable tooltip on hover.
|
Option to disable tooltip on hover.
|
||||||
|
|
||||||
|
*always-on*: ++
|
||||||
|
typeof: bool ++
|
||||||
|
default: false ++
|
||||||
|
Option to display the widget even when there's no active submap.
|
||||||
|
|
||||||
|
*default-submap* ++
|
||||||
|
typeof: string ++
|
||||||
|
default: Default ++
|
||||||
|
Option to set the submap name to display when not in an active submap.
|
||||||
|
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar) {
|
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar) {
|
||||||
modulesReady = true;
|
modulesReady = true;
|
||||||
|
|
||||||
|
parseConfig(config);
|
||||||
|
|
||||||
if (!gIPC) {
|
if (!gIPC) {
|
||||||
gIPC = std::make_unique<IPC>();
|
gIPC = std::make_unique<IPC>();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +19,13 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
label_.hide();
|
label_.hide();
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
|
|
||||||
|
// Displays widget immediately if always_on_ assuming default submap
|
||||||
|
// Needs an actual way to retrive current submap on startup
|
||||||
|
if (always_on_) {
|
||||||
|
submap_ = default_submap_;
|
||||||
|
label_.get_style_context()->add_class(submap_);
|
||||||
|
}
|
||||||
|
|
||||||
// register for hyprland ipc
|
// register for hyprland ipc
|
||||||
gIPC->registerForIPC("submap", this);
|
gIPC->registerForIPC("submap", this);
|
||||||
dp.emit();
|
dp.emit();
|
||||||
|
@ -28,6 +37,18 @@ Submap::~Submap() {
|
||||||
std::lock_guard<std::mutex> lg(mutex_);
|
std::lock_guard<std::mutex> lg(mutex_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Submap::parseConfig(const Json::Value& config) -> void {
|
||||||
|
auto const alwaysOn = config["always-on"];
|
||||||
|
if (alwaysOn.isBool()) {
|
||||||
|
always_on_ = alwaysOn.asBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const defaultSubmap = config["default-submap"];
|
||||||
|
if (defaultSubmap.isString()) {
|
||||||
|
default_submap_ = defaultSubmap.asString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Submap::update() -> void {
|
auto Submap::update() -> void {
|
||||||
std::lock_guard<std::mutex> lg(mutex_);
|
std::lock_guard<std::mutex> lg(mutex_);
|
||||||
|
|
||||||
|
@ -60,6 +81,10 @@ void Submap::onEvent(const std::string& ev) {
|
||||||
|
|
||||||
submap_ = submapName;
|
submap_ = submapName;
|
||||||
|
|
||||||
|
if (submap_.empty() && always_on_) {
|
||||||
|
submap_ = default_submap_;
|
||||||
|
}
|
||||||
|
|
||||||
label_.get_style_context()->add_class(submap_);
|
label_.get_style_context()->add_class(submap_);
|
||||||
|
|
||||||
spdlog::debug("hyprland submap onevent with {}", submap_);
|
spdlog::debug("hyprland submap onevent with {}", submap_);
|
||||||
|
|
Loading…
Reference in New Issue