Skip to content

Commit

Permalink
Add always on option for hyprland/submap
Browse files Browse the repository at this point in the history
  • Loading branch information
alttabber committed Feb 13, 2024
1 parent 77c7b91 commit 9ea4704
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/modules/hyprland/submap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class Submap : public waybar::ALabel, public EventHandler {
auto update() -> void override;

private:
auto parseConfig(const Json::Value&) -> void;
void onEvent(const std::string&) override;

std::mutex mutex_;
const Bar& bar_;
util::JsonParser parser_;
std::string submap_;
bool always_on_ = false;

Check warning on line 29 in include/modules/hyprland/submap.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/hyprland/submap.hpp:29:8 [readability-identifier-naming]

invalid case style for private member 'always_on_'
std::string default_submap_ = "Default";

Check warning on line 30 in include/modules/hyprland/submap.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/hyprland/submap.hpp:30:15 [readability-identifier-naming]

invalid case style for private member 'default_submap_'
};

} // namespace waybar::modules::hyprland
10 changes: 10 additions & 0 deletions man/waybar-hyprland-submap.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ Addressed by *hyprland/submap*
default: true ++
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

Expand Down
29 changes: 26 additions & 3 deletions src/modules/hyprland/submap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar) {
modulesReady = true;

parseConfig(config);

if (!gIPC.get()) {
gIPC = std::make_unique<IPC>();
}

label_.hide();
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
gIPC->registerForIPC("submap", this);
dp.emit();
Expand All @@ -28,6 +37,18 @@ Submap::~Submap() {
std::lock_guard<std::mutex> lg(mutex_);
}

auto Submap::parseConfig(const Json::Value& config) -> void {
auto const alwaysOn = config["always-on"];

Check warning on line 41 in src/modules/hyprland/submap.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/hyprland/submap.cpp:41:14 [performance-unnecessary-copy-initialization]

the const qualified variable 'alwaysOn' is copy-constructed from a const reference; consider making it a const reference
if (alwaysOn.isBool()) {
always_on_ = alwaysOn.asBool();
}

auto const defaultSubmap = config["default-submap"];

Check warning on line 46 in src/modules/hyprland/submap.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/hyprland/submap.cpp:46:14 [performance-unnecessary-copy-initialization]

the const qualified variable 'defaultSubmap' is copy-constructed from a const reference; consider making it a const reference
if (defaultSubmap.isString()) {
default_submap_ = defaultSubmap.asString();
}
}

auto Submap::update() -> void {
std::lock_guard<std::mutex> lg(mutex_);

Expand All @@ -54,15 +75,17 @@ void Submap::onEvent(const std::string& ev) {
auto submapName = ev.substr(ev.find_last_of('>') + 1);
submapName = waybar::util::sanitize_string(submapName);

if (!submap_.empty()){
if (!submap_.empty()) {
label_.get_style_context()->remove_class(submap_);
}

submap_ = submapName;

label_.get_style_context()->add_class(submap_);

if (submap_.empty() && always_on_) {
submap_ = default_submap_;
}

label_.get_style_context()->add_class(submap_);

spdlog::debug("hyprland submap onevent with {}", submap_);

Expand Down

0 comments on commit 9ea4704

Please sign in to comment.