From 60611e9c2b098b3a7a63417de3624f399e0b8c0b Mon Sep 17 00:00:00 2001 From: KanuX-14 Date: Sun, 10 Sep 2023 14:41:40 -0300 Subject: [PATCH 01/19] Fix battery not showing for some devices Adds 'bat-compatibility' boolean checking from configuration file. --- src/modules/battery.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 3ced890d..96dbdbfa 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -100,9 +100,11 @@ void waybar::modules::Battery::refreshBatteries() { } auto dir_name = node.path().filename(); auto bat_defined = config_["bat"].isString(); + bool bat_compatibility = config_["bat-compatibility"].asBool(); if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) && (fs::exists(node.path() / "capacity") || fs::exists(node.path() / "charge_now")) && - fs::exists(node.path() / "uevent") && fs::exists(node.path() / "status") && + fs::exists(node.path() / "uevent") && + (fs::exists(node.path() / "status") || bat_compatibility) && fs::exists(node.path() / "type")) { std::string type; std::ifstream(node.path() / "type") >> type; From 1ff4464b2f62c30bdfebffa71fc05fdc703ff828 Mon Sep 17 00:00:00 2001 From: KanuX-14 Date: Sun, 10 Sep 2023 15:16:43 -0300 Subject: [PATCH 02/19] Use adapter status if battery status is inexistent --- src/modules/battery.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 96dbdbfa..757a7ded 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -254,7 +254,13 @@ const std::tuple waybar::modules::Battery::g for (auto const& item : batteries_) { auto bat = item.first; std::string _status; - std::getline(std::ifstream(bat / "status"), _status); + + /* Check for adapter status if battery is not available */ + if(!std::ifstream(bat / "status")) { + std::getline(std::ifstream(adapter_ / "status"), _status); + } else { + std::getline(std::ifstream(bat / "status"), _status); + } // Some battery will report current and charge in μA/μAh. // Scale these by the voltage to get μW/μWh. From 28a2d15fef237019e3a55dc9e2d985a740166727 Mon Sep 17 00:00:00 2001 From: KanuX-14 Date: Tue, 12 Sep 2023 13:39:09 -0300 Subject: [PATCH 03/19] Update 'bat-compatibility' option to manual --- man/waybar-battery.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 52bc9f64..b13cee6e 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -100,6 +100,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y default: true ++ Option to disable tooltip on hover. +*bat-compatibility*: ++ + typeof: bool ++ + default: false ++ + Option to enable battery compatibility if not detected. + # FORMAT REPLACEMENTS *{capacity}*: Capacity in percentage From 7c28ffc856a3466269574eae4384269b84c21727 Mon Sep 17 00:00:00 2001 From: Evan Overman Date: Mon, 18 Sep 2023 14:55:50 -0700 Subject: [PATCH 04/19] add indefinite `sleep()` function to `SleeperThread` --- include/util/sleeper_thread.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/util/sleeper_thread.hpp b/include/util/sleeper_thread.hpp index 861d5f1f..3d8c05d1 100644 --- a/include/util/sleeper_thread.hpp +++ b/include/util/sleeper_thread.hpp @@ -58,6 +58,12 @@ class SleeperThread { bool isRunning() const { return do_run_; } + auto sleep() { + std::unique_lock lk(mutex_); + CancellationGuard cancel_lock; + return condvar_.wait(lk); + } + auto sleep_for(std::chrono::system_clock::duration dur) { std::unique_lock lk(mutex_); CancellationGuard cancel_lock; From bf371f70d1e7ea5a38388661d662ee849f46f08e Mon Sep 17 00:00:00 2001 From: Evan Overman Date: Mon, 18 Sep 2023 14:56:14 -0700 Subject: [PATCH 05/19] add `waitingWorker()` to `Custom` --- include/modules/custom.hpp | 1 + src/modules/custom.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index a6024a84..c9992695 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -22,6 +22,7 @@ class Custom : public ALabel { private: void delayWorker(); void continuousWorker(); + void waitingWorker(); void parseOutputRaw(); void parseOutputJson(); void handleEvent(); diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 5a246aff..6cbb5e1e 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -11,11 +11,13 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id, fp_(nullptr), pid_(-1) { dp.emit(); - if (interval_.count() > 0) { + if (!config_["signal"].empty() && config_["interval"].empty()) { + waitingWorker(); + } else if (interval_.count() > 0) { delayWorker(); } else if (config_["exec"].isString()) { continuousWorker(); - } + } } waybar::modules::Custom::~Custom() { @@ -92,6 +94,26 @@ void waybar::modules::Custom::continuousWorker() { }; } +void waybar::modules::Custom::waitingWorker() { + thread_ = [this] { + bool can_update = true; + if (config_["exec-if"].isString()) { + output_ = util::command::execNoRead(config_["exec-if"].asString()); + if (output_.exit_code != 0) { + can_update = false; + dp.emit(); + } + } + if (can_update) { + if (config_["exec"].isString()) { + output_ = util::command::exec(config_["exec"].asString()); + } + dp.emit(); + } + thread_.sleep(); + }; +} + void waybar::modules::Custom::refresh(int sig) { if (sig == SIGRTMIN + config_["signal"].asInt()) { thread_.wake_up(); From 388c024298bb81ee33052d61e69a72995c2b32ec Mon Sep 17 00:00:00 2001 From: idm1try Date: Tue, 19 Sep 2023 18:50:39 +0500 Subject: [PATCH 06/19] fix(backlight): wrong percentage numbers for device apple-panel-bl --- flake.nix | 1 + result | 1 + src/modules/backlight.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 120000 result diff --git a/flake.nix b/flake.nix index 24fcae9f..15e70b63 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ inherit (nixpkgs) lib; genSystems = lib.genAttrs [ "x86_64-linux" + "aarch64-linux" ]; pkgsFor = genSystems (system: diff --git a/result b/result new file mode 120000 index 00000000..a8f7089b --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/0pz53p83i16kv8ff5pwxhpp7zvmxapm9-waybar-0.9.22+date=2023-09-13_dirty \ No newline at end of file diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 27871048..40c63f07 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -244,7 +244,7 @@ void waybar::modules::Backlight::upsert_device(ForwardIt first, ForwardIt last, check_nn(name); const char *actual_brightness_attr = - strncmp(name, "amdgpu_bl", 9) == 0 ? "brightness" : "actual_brightness"; + strncmp(name, "amdgpu_bl", 9) == 0 ? "brightness" : strcmp(name, "apple-panel-bl") == 0 ? "brightness" : "actual_brightness"; const char *actual = udev_device_get_sysattr_value(dev, actual_brightness_attr); const char *max = udev_device_get_sysattr_value(dev, "max_brightness"); From 954bea36f4f7f9205e563d49c283f9e40d43af38 Mon Sep 17 00:00:00 2001 From: idm1try Date: Tue, 19 Sep 2023 18:52:00 +0500 Subject: [PATCH 07/19] chore: remove result dir by nix --- result | 1 - 1 file changed, 1 deletion(-) delete mode 120000 result diff --git a/result b/result deleted file mode 120000 index a8f7089b..00000000 --- a/result +++ /dev/null @@ -1 +0,0 @@ -/nix/store/0pz53p83i16kv8ff5pwxhpp7zvmxapm9-waybar-0.9.22+date=2023-09-13_dirty \ No newline at end of file From f14fe96e199af4bd8050c304ae5ea6c300ba28df Mon Sep 17 00:00:00 2001 From: Evan Overman Date: Tue, 19 Sep 2023 14:52:48 -0700 Subject: [PATCH 08/19] add info to `interval` and `signal` in manpage for custom modules --- man/waybar-custom.5.scd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index aeb419f9..a038e355 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -34,7 +34,8 @@ Addressed by *custom/* typeof: integer ++ The interval (in seconds) in which the information gets polled. ++ Use *once* if you want to execute the module only on startup. ++ - You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. + You can update it manually with a signal. If no *interval* or *signal* is defined, it is assumed that the out script loops it self. ++ + If a *signal* is defined then the script will run once on startup and will will only update with a signal. *restart-interval*: ++ typeof: integer ++ @@ -45,7 +46,8 @@ Addressed by *custom/* *signal*: ++ typeof: integer ++ The signal number used to update the module. ++ - The number is valid between 1 and N, where *SIGRTMIN+N* = *SIGRTMAX*. + The number is valid between 1 and N, where *SIGRTMIN+N* = *SIGRTMAX*. ++ + If no interval is defined then a signal will be the only way to update the module. *format*: ++ typeof: string ++ From 81ffeebfb1d7a761c7069627dd2462388043487c Mon Sep 17 00:00:00 2001 From: idm1try Date: Thu, 21 Sep 2023 09:03:13 +0500 Subject: [PATCH 09/19] fix: style Co-authored-by: Alexis Rouillard --- src/modules/backlight.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 40c63f07..dff10743 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -244,7 +244,7 @@ void waybar::modules::Backlight::upsert_device(ForwardIt first, ForwardIt last, check_nn(name); const char *actual_brightness_attr = - strncmp(name, "amdgpu_bl", 9) == 0 ? "brightness" : strcmp(name, "apple-panel-bl") == 0 ? "brightness" : "actual_brightness"; + strncmp(name, "amdgpu_bl", 9) == 0 || strcmp(name, "apple-panel-bl") == 0 ? "brightness" : "actual_brightness"; const char *actual = udev_device_get_sysattr_value(dev, actual_brightness_attr); const char *max = udev_device_get_sysattr_value(dev, "max_brightness"); From 3e2761e81f2415eaaf3cd7108bc317619fcbc4d0 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 16:37:26 -0300 Subject: [PATCH 10/19] feat: dynamically assign windows to workspaces Co-authored-by: Gabriel Fox --- include/modules/hyprland/workspaces.hpp | 35 ++++- src/modules/hyprland/workspaces.cpp | 175 ++++++++++++++++++++++-- 2 files changed, 200 insertions(+), 10 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 14b9ba0e..d010cb08 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -3,8 +3,11 @@ #include #include +#include +#include #include #include +#include #include #include @@ -13,13 +16,16 @@ #include "modules/hyprland/backend.hpp" #include "util/enum.hpp" +using WindowAddress = std::string; +using mywindowtype = std::string; namespace waybar::modules::hyprland { class Workspaces; class Workspace { public: - explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager); + explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager, + const Json::Value& clients_json = Json::Value::nullRef); std::string& select_icon(std::map& icons_map); Gtk::Button& button() { return button_; }; @@ -40,6 +46,21 @@ class Workspace { void set_visible(bool value = true) { is_visible_ = value; }; void set_windows(uint value) { windows_ = value; }; void set_name(std::string value) { name_ = value; }; + bool contains_window(WindowAddress addr) { return window_map_.contains(addr); } + void insert_window(WindowAddress addr, mywindowtype window_repr) { + window_map_.emplace(addr, window_repr); + }; + void remove_window(WindowAddress addr) { window_map_.erase(addr); } + void initialize_window_map(const Json::Value& clients_data); + + bool on_window_opened(WindowAddress& addr, std::string& workspace_name, + const Json::Value& clients_data); + bool on_window_opened(WindowAddress& addr, std::string& workspace_name, std::string& window_class, + std::string& window_title); + + bool on_window_closed(WindowAddress& addr); + bool on_window_moved(WindowAddress& addr, std::string& workspace_name, + const Json::Value& clients_data); void update(const std::string& format, const std::string& icon); @@ -56,6 +77,8 @@ class Workspace { bool is_urgent_ = false; bool is_visible_ = false; + std::map window_map_; + Gtk::Button button_; Gtk::Box content_; Gtk::Label label_; @@ -77,13 +100,19 @@ class Workspaces : public AModule, public EventHandler { private: void onEvent(const std::string&) override; void update_window_count(); + void initialize_window_maps(); void sort_workspaces(); - void create_workspace(Json::Value& value); + void create_workspace(Json::Value& workspace_data, + const Json::Value& clients_data = Json::Value::nullRef); void remove_workspace(std::string name); void set_urgent_workspace(std::string windowaddress); void parse_config(const Json::Value& config); void register_ipc(); + void on_window_opened(std::string payload); + void on_window_closed(std::string payload); + void on_window_moved(std::string payload); + bool all_outputs_ = false; bool show_special_ = false; bool active_only_ = false; @@ -103,6 +132,8 @@ class Workspaces : public AModule, public EventHandler { std::string format_; std::map icons_map_; + std::map window_rewrite_rules_; + std::string format_window_separator_; bool with_icon_; uint64_t monitor_id_; std::string active_workspace_name_; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index f38b5050..4176851a 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -1,5 +1,6 @@ #include "modules/hyprland/workspaces.hpp" +#include #include #include @@ -68,6 +69,18 @@ auto Workspaces::parse_config(const Json::Value &config) -> void { g_warning("Invalid string representation for sort-by. Falling back to default sort method."); } } + + Json::Value format_window_separator = config["format-window-separator"]; + format_window_separator_ = + format_window_separator.isString() ? format_window_separator.asString() : " "; + + Json::Value window_rewrite_map = config["window-rewrite-map"]; + + if (window_rewrite_map.isObject()) { + for (std::string &name : window_rewrite_map.getMemberNames()) { + window_rewrite_rules_.emplace(name, window_rewrite_map[name].asString()); + } + } } auto Workspaces::register_ipc() -> void { @@ -175,8 +188,15 @@ void Workspaces::onEvent(const std::string &ev) { } else { workspaces_to_remove_.push_back(workspace); } - } else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") { + } else if (eventName == "openwindow") { update_window_count(); + on_window_opened(payload); + } else if (eventName == "closewindow") { + update_window_count(); + on_window_closed(payload); + } else if (eventName == "movewindow") { + update_window_count(); + on_window_moved(payload); } else if (eventName == "urgent") { set_urgent_workspace(payload); } else if (eventName == "renameworkspace") { @@ -197,6 +217,71 @@ void Workspaces::onEvent(const std::string &ev) { dp.emit(); } +void Workspaces::on_window_opened(std::string payload) { + size_t last_comma_idx = 0; + size_t next_comma_idx = payload.find(','); + std::string window_address = payload.substr(last_comma_idx, next_comma_idx - last_comma_idx); + + last_comma_idx = next_comma_idx; + next_comma_idx = payload.find(',', next_comma_idx + 1); + std::string workspace_name = + payload.substr(last_comma_idx + 1, next_comma_idx - last_comma_idx - 1); + + last_comma_idx = next_comma_idx; + next_comma_idx = payload.find(',', next_comma_idx + 1); + std::string window_class = + payload.substr(last_comma_idx + 1, next_comma_idx - last_comma_idx - 1); + + std::string window_title = payload.substr(next_comma_idx + 1, payload.length() - next_comma_idx); + + fmt::println("> Inserting window [{}] [{}] [{}] [{}]", window_address, workspace_name, + window_class, window_title); + + for (auto &workspace : workspaces_) { + if (workspace->on_window_opened(window_address, workspace_name, window_class, window_title)) { + break; + } + } + + fmt::println("<"); +} + +void Workspaces::on_window_closed(std::string addr) { + fmt::println("> Removing window [{}]", addr); + for (auto &workspace : workspaces_) { + if (workspace->on_window_closed(addr)) { + break; + } + } + fmt::println("<"); +} + +void Workspaces::on_window_moved(std::string payload) { + size_t last_comma_idx = 0; + size_t next_comma_idx = payload.find(','); + std::string window_address = payload.substr(last_comma_idx, next_comma_idx - last_comma_idx); + + std::string workspace_name = + payload.substr(next_comma_idx + 1, payload.length() - next_comma_idx); + + int changes = 0; + + const Json::Value clients_json = gIPC->getSocket1JsonReply("clients"); + + fmt::println(">> Moving window [{}] [{}]", window_address, workspace_name); + + for (auto &workspace : workspaces_) { + if (workspace->on_window_moved(window_address, workspace_name, clients_json)) { + changes++; + if (changes == 2) { + break; + } + } + } + + fmt::println("<<"); +} + void Workspaces::update_window_count() { const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); for (auto &workspace : workspaces_) { @@ -215,22 +300,84 @@ void Workspaces::update_window_count() { } } -void Workspaces::create_workspace(Json::Value &value) { +void Workspaces::initialize_window_maps() { + Json::Value clients_data = gIPC->getSocket1JsonReply("clients"); + for (auto &workspace : workspaces_) { + workspace->initialize_window_map(clients_data); + } +} + +void Workspace::initialize_window_map(const Json::Value &clients_data) { + window_map_.clear(); + for (auto client : clients_data) { + if (client["workspace"]["id"].asInt() == id()) { + WindowAddress client_address = client["address"].asString(); + insert_window(client_address, client["class"].asString()); + } + } +} + +bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, + const Json::Value &clients_data) { + if (workspace_name == name()) { + fmt::println("\tInserting on workspace {}", id()); + for (auto client : clients_data) { + auto client_address = client["address"].asString().substr(2, addr.length()); + if (client_address == addr) { + std::string window_class = client["class"].asString(); + insert_window(addr, window_class); + return true; + } + } + fmt::println("\tERROR on workspace {}", id()); + return false; + } else { + return false; + } +} + +bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, + std::string &window_class, std::string &window_title) { + if (workspace_name == name()) { + fmt::println("\tInserting on workspace {}", id()); + insert_window(addr, window_class); + return true; + } else { + return false; + } +} + +bool Workspace::on_window_closed(WindowAddress &addr) { + if (window_map_.contains(addr)) { + fmt::println("\tRemoving on workspace {}", id()); + remove_window(addr); + return true; + } else { + return false; + } +} + +bool Workspace::on_window_moved(WindowAddress &addr, std::string &workspace_name, + const Json::Value &clients_data) { + return on_window_opened(addr, workspace_name, clients_data) || on_window_closed(addr); +} + +void Workspaces::create_workspace(Json::Value &workspace_data, const Json::Value &clients_data) { // replace the existing persistent workspace if it exists auto workspace = std::find_if( workspaces_.begin(), workspaces_.end(), [&](std::unique_ptr const &x) { - auto name = value["name"].asString(); + auto name = workspace_data["name"].asString(); return x->is_persistent() && ((name.starts_with("special:") && name.substr(8) == x->name()) || name == x->name()); }); if (workspace != workspaces_.end()) { // replace workspace, but keep persistent flag workspaces_.erase(workspace); - value["persistent"] = true; + workspace_data["persistent"] = true; } // create new workspace - workspaces_.emplace_back(std::make_unique(value, *this)); + workspaces_.emplace_back(std::make_unique(workspace_data, *this, clients_data)); Gtk::Button &new_workspace_button = workspaces_.back()->button(); box_.pack_start(new_workspace_button, false, false); sort_workspaces(); @@ -351,10 +498,12 @@ void Workspaces::init() { create_persistent_workspaces(); const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); + const Json::Value clients_json = gIPC->getSocket1JsonReply("clients"); + for (Json::Value workspace_json : workspaces_json) { if ((all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) && (!workspace_json["name"].asString().starts_with("special") || show_special())) { - create_workspace(workspace_json); + create_workspace(workspace_json, clients_json); } } @@ -371,7 +520,8 @@ Workspaces::~Workspaces() { std::lock_guard lg(mutex_); } -Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager) +Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager, + const Json::Value &clients_data) : workspace_manager_(workspace_manager), id_(workspace_data["id"].asInt()), name_(workspace_data["name"].asString()), @@ -396,6 +546,8 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma button_.set_relief(Gtk::RELIEF_NONE); content_.set_center_widget(label_); button_.add(content_); + + initialize_window_map(clients_data); } void add_or_remove_class(const Glib::RefPtr &context, bool condition, @@ -429,8 +581,15 @@ void Workspace::update(const std::string &format, const std::string &icon) { add_or_remove_class(style_context, is_urgent(), "urgent"); add_or_remove_class(style_context, is_visible(), "visible"); + std::string first_letters; + + for (auto &[_pid, window_repr] : window_map_) { + first_letters.append(window_repr.substr(0, 1)); + } + label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()), - fmt::arg("name", name()), fmt::arg("icon", icon))); + fmt::arg("name", name()), fmt::arg("icon", icon), + fmt::arg("windows", first_letters))); } void Workspaces::sort_workspaces() { From b9d5912a4f7d862ee64c8beea40cdc49665afc80 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 18:18:02 -0300 Subject: [PATCH 11/19] feat: rewrite window classes feat: cache window class rewrite resolution Co-authored-by: Gabriel Fox --- include/modules/hyprland/workspaces.hpp | 14 ++++--- src/modules/hyprland/workspaces.cpp | 55 ++++++++++++++----------- src/util/rewrite_string.cpp | 3 +- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index d010cb08..528bf933 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -17,7 +18,6 @@ #include "util/enum.hpp" using WindowAddress = std::string; -using mywindowtype = std::string; namespace waybar::modules::hyprland { class Workspaces; @@ -47,9 +47,7 @@ class Workspace { void set_windows(uint value) { windows_ = value; }; void set_name(std::string value) { name_ = value; }; bool contains_window(WindowAddress addr) { return window_map_.contains(addr); } - void insert_window(WindowAddress addr, mywindowtype window_repr) { - window_map_.emplace(addr, window_repr); - }; + void insert_window(WindowAddress addr, std::string window_repr); void remove_window(WindowAddress addr) { window_map_.erase(addr); } void initialize_window_map(const Json::Value& clients_data); @@ -77,7 +75,7 @@ class Workspace { bool is_urgent_ = false; bool is_visible_ = false; - std::map window_map_; + std::map window_map_; Gtk::Button button_; Gtk::Box content_; @@ -97,6 +95,9 @@ class Workspaces : public AModule, public EventHandler { auto get_bar_output() const -> std::string { return bar_.output->name; } + std::string get_rewrite(std::string window_class); + std::string& get_window_separator() { return format_window_separator_; } + private: void onEvent(const std::string&) override; void update_window_count(); @@ -132,7 +133,8 @@ class Workspaces : public AModule, public EventHandler { std::string format_; std::map icons_map_; - std::map window_rewrite_rules_; + Json::Value window_rewrite_rules_; + std::map regex_cache_; std::string format_window_separator_; bool with_icon_; uint64_t monitor_id_; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 4176851a..43cd7774 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -9,6 +9,8 @@ #include #include +#include "util/rewrite_string.hpp" + namespace waybar::modules::hyprland { Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) @@ -74,13 +76,7 @@ auto Workspaces::parse_config(const Json::Value &config) -> void { format_window_separator_ = format_window_separator.isString() ? format_window_separator.asString() : " "; - Json::Value window_rewrite_map = config["window-rewrite-map"]; - - if (window_rewrite_map.isObject()) { - for (std::string &name : window_rewrite_map.getMemberNames()) { - window_rewrite_rules_.emplace(name, window_rewrite_map[name].asString()); - } - } + window_rewrite_rules_ = config["window-rewrite"]; } auto Workspaces::register_ipc() -> void { @@ -234,26 +230,19 @@ void Workspaces::on_window_opened(std::string payload) { std::string window_title = payload.substr(next_comma_idx + 1, payload.length() - next_comma_idx); - fmt::println("> Inserting window [{}] [{}] [{}] [{}]", window_address, workspace_name, - window_class, window_title); - for (auto &workspace : workspaces_) { if (workspace->on_window_opened(window_address, workspace_name, window_class, window_title)) { break; } } - - fmt::println("<"); } void Workspaces::on_window_closed(std::string addr) { - fmt::println("> Removing window [{}]", addr); for (auto &workspace : workspaces_) { if (workspace->on_window_closed(addr)) { break; } } - fmt::println("<"); } void Workspaces::on_window_moved(std::string payload) { @@ -268,8 +257,6 @@ void Workspaces::on_window_moved(std::string payload) { const Json::Value clients_json = gIPC->getSocket1JsonReply("clients"); - fmt::println(">> Moving window [{}] [{}]", window_address, workspace_name); - for (auto &workspace : workspaces_) { if (workspace->on_window_moved(window_address, workspace_name, clients_json)) { changes++; @@ -278,8 +265,6 @@ void Workspaces::on_window_moved(std::string payload) { } } } - - fmt::println("<<"); } void Workspaces::update_window_count() { @@ -317,10 +302,13 @@ void Workspace::initialize_window_map(const Json::Value &clients_data) { } } +void Workspace::insert_window(WindowAddress addr, std::string window_class) { + window_map_.emplace(addr, workspace_manager_.get_rewrite(window_class)); +}; + bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, const Json::Value &clients_data) { if (workspace_name == name()) { - fmt::println("\tInserting on workspace {}", id()); for (auto client : clients_data) { auto client_address = client["address"].asString().substr(2, addr.length()); if (client_address == addr) { @@ -329,7 +317,6 @@ bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_nam return true; } } - fmt::println("\tERROR on workspace {}", id()); return false; } else { return false; @@ -339,7 +326,6 @@ bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_nam bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, std::string &window_class, std::string &window_title) { if (workspace_name == name()) { - fmt::println("\tInserting on workspace {}", id()); insert_window(addr, window_class); return true; } else { @@ -349,7 +335,6 @@ bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_nam bool Workspace::on_window_closed(WindowAddress &addr) { if (window_map_.contains(addr)) { - fmt::println("\tRemoving on workspace {}", id()); remove_window(addr); return true; } else { @@ -581,15 +566,22 @@ void Workspace::update(const std::string &format, const std::string &icon) { add_or_remove_class(style_context, is_urgent(), "urgent"); add_or_remove_class(style_context, is_visible(), "visible"); - std::string first_letters; + std::string windows; + auto window_separator = workspace_manager_.get_window_separator(); + + bool is_not_first = false; for (auto &[_pid, window_repr] : window_map_) { - first_letters.append(window_repr.substr(0, 1)); + if (is_not_first) { + windows.append(window_separator); + } + is_not_first = true; + windows.append(window_repr); } label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()), fmt::arg("name", name()), fmt::arg("icon", icon), - fmt::arg("windows", first_letters))); + fmt::arg("windows", windows))); } void Workspaces::sort_workspaces() { @@ -748,4 +740,17 @@ void Workspaces::set_urgent_workspace(std::string windowaddress) { } } +std::string Workspaces::get_rewrite(std::string window_class) { + if (regex_cache_.contains(window_class)) { + return regex_cache_[window_class]; + } + + std::string window_class_rewrite = + waybar::util::rewriteString(window_class, window_rewrite_rules_); + + regex_cache_.emplace(window_class, window_class_rewrite); + + return window_class_rewrite; +} + } // namespace waybar::modules::hyprland diff --git a/src/util/rewrite_string.cpp b/src/util/rewrite_string.cpp index 40c71e99..ec3e1673 100644 --- a/src/util/rewrite_string.cpp +++ b/src/util/rewrite_string.cpp @@ -1,5 +1,6 @@ #include "util/rewrite_string.hpp" +#include #include #include @@ -17,7 +18,7 @@ std::string rewriteString(const std::string& value, const Json::Value& rules) { try { // malformated regexes will cause an exception. // in this case, log error and try the next rule. - const std::regex rule{it.key().asString()}; + const std::regex rule{it.key().asString(), std::regex_constants::icase}; if (std::regex_match(value, rule)) { res = std::regex_replace(res, rule, it->asString()); } From fbe544984c0df828a1f6f3bbd6fb07eb3468dba1 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 18:38:18 -0300 Subject: [PATCH 12/19] fix: ipc vs json window addr format mismatch feat: ignore empty windows Co-authored-by: Gabriel Fox --- src/modules/hyprland/workspaces.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 43cd7774..e6edc4ac 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -296,20 +296,32 @@ void Workspace::initialize_window_map(const Json::Value &clients_data) { window_map_.clear(); for (auto client : clients_data) { if (client["workspace"]["id"].asInt() == id()) { + // substr(2, ...) is necessary because Hyprland's JSON follows this format: + // 0x{ADDR} + // While Hyprland's IPC follows this format: + // {ADDR} WindowAddress client_address = client["address"].asString(); + client_address = client_address.substr(2, client_address.length() - 2); insert_window(client_address, client["class"].asString()); } } } void Workspace::insert_window(WindowAddress addr, std::string window_class) { - window_map_.emplace(addr, workspace_manager_.get_rewrite(window_class)); + auto window_repr = workspace_manager_.get_rewrite(window_class); + if (!window_repr.empty()) { + window_map_.emplace(addr, window_repr); + } }; bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, const Json::Value &clients_data) { if (workspace_name == name()) { for (auto client : clients_data) { + // substr(2, ...) is necessary because Hyprland's JSON follows this format: + // 0x{ADDR} + // While Hyprland's IPC follows this format: + // {ADDR} auto client_address = client["address"].asString().substr(2, addr.length()); if (client_address == addr) { std::string window_class = client["class"].asString(); From adbc9d95de7e26ea8e518b72cc707d924e4dd00c Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 19:05:34 -0300 Subject: [PATCH 13/19] feat: optional default icon for 0-match classes Co-authored-by: Gabriel Fox --- include/modules/hyprland/workspaces.hpp | 1 + include/util/rewrite_string.hpp | 4 +++- src/modules/hyprland/workspaces.cpp | 12 ++++++++++- src/util/rewrite_string.cpp | 27 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 528bf933..75465994 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -136,6 +136,7 @@ class Workspaces : public AModule, public EventHandler { Json::Value window_rewrite_rules_; std::map regex_cache_; std::string format_window_separator_; + std::string window_rewrite_default_; bool with_icon_; uint64_t monitor_id_; std::string active_workspace_name_; diff --git a/include/util/rewrite_string.hpp b/include/util/rewrite_string.hpp index 2ab39ad8..3352a47a 100644 --- a/include/util/rewrite_string.hpp +++ b/include/util/rewrite_string.hpp @@ -5,4 +5,6 @@ namespace waybar::util { std::string rewriteString(const std::string&, const Json::Value&); -} +std::string rewriteStringOnce(const std::string& value, const Json::Value& rules, + bool& matched_any); +} // namespace waybar::util diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index e6edc4ac..526129e9 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -77,6 +77,10 @@ auto Workspaces::parse_config(const Json::Value &config) -> void { format_window_separator.isString() ? format_window_separator.asString() : " "; window_rewrite_rules_ = config["window-rewrite"]; + + Json::Value window_rewrite_default = config["window-rewrite-default"]; + window_rewrite_default_ = + window_rewrite_default.isString() ? window_rewrite_default.asString() : "?"; } auto Workspaces::register_ipc() -> void { @@ -757,8 +761,14 @@ std::string Workspaces::get_rewrite(std::string window_class) { return regex_cache_[window_class]; } + bool matched_any; + std::string window_class_rewrite = - waybar::util::rewriteString(window_class, window_rewrite_rules_); + waybar::util::rewriteStringOnce(window_class, window_rewrite_rules_, matched_any); + + if (!matched_any) { + window_class_rewrite = window_rewrite_default_; + } regex_cache_.emplace(window_class, window_class_rewrite); diff --git a/src/util/rewrite_string.cpp b/src/util/rewrite_string.cpp index ec3e1673..475f8a3d 100644 --- a/src/util/rewrite_string.cpp +++ b/src/util/rewrite_string.cpp @@ -30,4 +30,31 @@ std::string rewriteString(const std::string& value, const Json::Value& rules) { return res; } + +std::string rewriteStringOnce(const std::string& value, const Json::Value& rules, + bool& matched_any) { + if (!rules.isObject()) { + return value; + } + + matched_any = false; + + std::string res = value; + + for (auto it = rules.begin(); it != rules.end(); ++it) { + if (it.key().isString() && it->isString()) { + try { + const std::regex rule{it.key().asString(), std::regex_constants::icase}; + if (std::regex_match(value, rule)) { + matched_any = true; + return std::regex_replace(res, rule, it->asString()); + } + } catch (const std::regex_error& e) { + spdlog::error("Invalid rule {}: {}", it.key().asString(), e.what()); + } + } + } + + return value; +} } // namespace waybar::util From 6663ca3d754525a6e0e059f61b291d62a4e7af37 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 20:41:38 -0300 Subject: [PATCH 14/19] chore: document new properties --- man/waybar-hyprland-workspaces.5.scd | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 99d21804..02be176d 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -21,6 +21,21 @@ Addressed by *hyprland/workspaces* typeof: array ++ Based on the workspace id and state, the corresponding icon gets selected. See *icons*. +*window-rewrite*: ++ + typeof: object ++ + Regex rules to map window class to an icon or preferred method of representation for a workspace's window. + Keys are the rules, while the values are the methods of representation. + +*window-rewrite-default*: + typeof: string ++ + default: "?" ++ + The default method of representation for a workspace's window. This will be used for windows whose classes do not match any of the rules in *window-rewrite*. + +*format-window-separator*: ++ + typeof: string ++ + default: " " ++ + The separator to be used between windows in a workspace. + *show-special*: ++ typeof: bool ++ default: false ++ @@ -103,6 +118,19 @@ Additional to workspace name matching, the following *format-icons* can be set. } ``` +``` +"hyprland/workspaces": { + "format": "{name}\n{windows}", + "format-window-separator": "\n", + "window-rewrite-default": "", + "window-rewrite": { + "firefox": "", + "foot": "", + "code": "󰨞", + } +} +``` + # Style - *#workspaces* From 258ab8b1477a15c037c5b4a9157ab9b67c598955 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Fri, 22 Sep 2023 21:12:42 -0300 Subject: [PATCH 15/19] refactor: take window representation directly from old workspace on movewindow event --- include/modules/hyprland/workspaces.hpp | 9 ++-- src/modules/hyprland/workspaces.cpp | 60 ++++++++++++------------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 75465994..1a01758e 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -48,17 +48,14 @@ class Workspace { void set_name(std::string value) { name_ = value; }; bool contains_window(WindowAddress addr) { return window_map_.contains(addr); } void insert_window(WindowAddress addr, std::string window_repr); - void remove_window(WindowAddress addr) { window_map_.erase(addr); } + std::string remove_window(WindowAddress addr); void initialize_window_map(const Json::Value& clients_data); - bool on_window_opened(WindowAddress& addr, std::string& workspace_name, - const Json::Value& clients_data); + bool on_window_opened(WindowAddress& addr, std::string& workspace_name, std::string window_repr); bool on_window_opened(WindowAddress& addr, std::string& workspace_name, std::string& window_class, std::string& window_title); - bool on_window_closed(WindowAddress& addr); - bool on_window_moved(WindowAddress& addr, std::string& workspace_name, - const Json::Value& clients_data); + std::optional on_window_closed(WindowAddress& addr); void update(const std::string& format, const std::string& icon); diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 526129e9..9ed8c5aa 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "util/rewrite_string.hpp" @@ -257,16 +258,23 @@ void Workspaces::on_window_moved(std::string payload) { std::string workspace_name = payload.substr(next_comma_idx + 1, payload.length() - next_comma_idx); - int changes = 0; - - const Json::Value clients_json = gIPC->getSocket1JsonReply("clients"); + std::string window_repr; + // Take the window's representation from the old workspace... for (auto &workspace : workspaces_) { - if (workspace->on_window_moved(window_address, workspace_name, clients_json)) { - changes++; - if (changes == 2) { - break; - } + try { + window_repr = workspace->on_window_closed(window_address).value(); + break; + } catch (const std::bad_optional_access &e) { + // window was not found in this workspace + continue; + } + } + + // ...and add it to the new workspace + for (auto &workspace : workspaces_) { + if (workspace->on_window_opened(window_address, workspace_name, window_repr)) { + break; } } } @@ -318,22 +326,18 @@ void Workspace::insert_window(WindowAddress addr, std::string window_class) { } }; +std::string Workspace::remove_window(WindowAddress addr) { + std::string window_repr = window_map_[addr]; + window_map_.erase(addr); + + return window_repr; +} + bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_name, - const Json::Value &clients_data) { + std::string window_repr) { if (workspace_name == name()) { - for (auto client : clients_data) { - // substr(2, ...) is necessary because Hyprland's JSON follows this format: - // 0x{ADDR} - // While Hyprland's IPC follows this format: - // {ADDR} - auto client_address = client["address"].asString().substr(2, addr.length()); - if (client_address == addr) { - std::string window_class = client["class"].asString(); - insert_window(addr, window_class); - return true; - } - } - return false; + window_map_.emplace(addr, window_repr); + return true; } else { return false; } @@ -349,20 +353,14 @@ bool Workspace::on_window_opened(WindowAddress &addr, std::string &workspace_nam } } -bool Workspace::on_window_closed(WindowAddress &addr) { +std::optional Workspace::on_window_closed(WindowAddress &addr) { if (window_map_.contains(addr)) { - remove_window(addr); - return true; + return remove_window(addr); } else { - return false; + return {}; } } -bool Workspace::on_window_moved(WindowAddress &addr, std::string &workspace_name, - const Json::Value &clients_data) { - return on_window_opened(addr, workspace_name, clients_data) || on_window_closed(addr); -} - void Workspaces::create_workspace(Json::Value &workspace_data, const Json::Value &clients_data) { // replace the existing persistent workspace if it exists auto workspace = std::find_if( From d37954322a6102d3137ec40d2631cd8c3f63ab2c Mon Sep 17 00:00:00 2001 From: woojiq Date: Sat, 23 Sep 2023 21:55:18 +0300 Subject: [PATCH 16/19] fix(hyprland): use workspace `name` as default icon Wlr and Sway modules use the workspace `name` as the default icon if no icon is provided. This adds the same behavior for the `hyprland/workspace` module. Closes https://github.com/Alexays/Waybar/issues/2533 --- src/modules/hyprland/workspaces.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index f38b5050..8083ae88 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -549,7 +549,8 @@ std::string &Workspace::select_icon(std::map &icons_ma if (default_icon_it != icons_map.end()) { return default_icon_it->second; } - return icons_map[""]; + + return name_; } auto Workspace::handle_clicked(GdkEventButton *bt) -> bool { From 6e48b236a18606d46c0ffd9e053579ac45f4d6cb Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Mon, 25 Sep 2023 17:12:51 -0300 Subject: [PATCH 17/19] fix: workspace special wasn't removed fixes #2505 Co-authored-by: Gabriel Fox --- src/modules/hyprland/workspaces.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index f38b5050..331403d7 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -238,8 +238,10 @@ void Workspaces::create_workspace(Json::Value &value) { } void Workspaces::remove_workspace(std::string name) { - auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(), - [&](std::unique_ptr &x) { return x->name() == name; }); + auto workspace = + std::find_if(workspaces_.begin(), workspaces_.end(), [&](std::unique_ptr &x) { + return (name.starts_with("special:") && name.substr(8) == x->name()) || name == x->name(); + }); if (workspace == workspaces_.end()) { // happens when a workspace on another monitor is destroyed From 9a3238c20b3367a308e6d9d143916db1a64f5e00 Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Mon, 25 Sep 2023 17:13:26 -0300 Subject: [PATCH 18/19] chore: avoid the creation and deletion of doubled-special workspaces see hyprwm/Hyprland#3424 for more info Co-authored-by: Gabriel Fox --- src/modules/hyprland/workspaces.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 331403d7..14534000 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -134,6 +134,14 @@ auto Workspaces::update() -> void { AModule::update(); } +bool isDoubleSpecial(std::string &workspace_name) { + // Hyprland's IPC sometimes reports the creation of workspaces strangely named + // `special:special:`. This function checks for that and is used + // to avoid creating (and then removing) such workspaces. + // See hyprwm/Hyprland#3424 for more info. + return workspace_name.find("special:special:") != std::string::npos; +} + void Workspaces::onEvent(const std::string &ev) { std::lock_guard lock(mutex_); std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>')); @@ -143,15 +151,16 @@ void Workspaces::onEvent(const std::string &ev) { active_workspace_name_ = payload; } else if (eventName == "destroyworkspace") { - workspaces_to_remove_.push_back(payload); - + if (!isDoubleSpecial(payload)) { + workspaces_to_remove_.push_back(payload); + } } else if (eventName == "createworkspace") { const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces"); for (Json::Value workspace_json : workspaces_json) { std::string name = workspace_json["name"].asString(); if (name == payload && (all_outputs() || bar_.output->name == workspace_json["monitor"].asString()) && - (show_special() || !name.starts_with("special"))) { + (show_special() || !name.starts_with("special")) && !isDoubleSpecial(payload)) { workspaces_to_create_.push_back(workspace_json); break; } From 1b98a04c93657e03f9d3776cbe4cdb5ad9504e2a Mon Sep 17 00:00:00 2001 From: Brenno Lemos Date: Mon, 2 Oct 2023 12:33:28 -0300 Subject: [PATCH 19/19] chore: lint unrelated files so the CI passes --- src/modules/backlight.cpp | 4 +++- src/modules/battery.cpp | 2 +- src/modules/custom.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index dff10743..b3ca85fc 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -244,7 +244,9 @@ void waybar::modules::Backlight::upsert_device(ForwardIt first, ForwardIt last, check_nn(name); const char *actual_brightness_attr = - strncmp(name, "amdgpu_bl", 9) == 0 || strcmp(name, "apple-panel-bl") == 0 ? "brightness" : "actual_brightness"; + strncmp(name, "amdgpu_bl", 9) == 0 || strcmp(name, "apple-panel-bl") == 0 + ? "brightness" + : "actual_brightness"; const char *actual = udev_device_get_sysattr_value(dev, actual_brightness_attr); const char *max = udev_device_get_sysattr_value(dev, "max_brightness"); diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 757a7ded..70268c8a 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -256,7 +256,7 @@ const std::tuple waybar::modules::Battery::g std::string _status; /* Check for adapter status if battery is not available */ - if(!std::ifstream(bat / "status")) { + if (!std::ifstream(bat / "status")) { std::getline(std::ifstream(adapter_ / "status"), _status); } else { std::getline(std::ifstream(bat / "status"), _status); diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 6cbb5e1e..4889b7a3 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -17,7 +17,7 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id, delayWorker(); } else if (config_["exec"].isString()) { continuousWorker(); - } + } } waybar::modules::Custom::~Custom() {