From 38af4a6f16bb24086a5e50f73dea3b589aad15b3 Mon Sep 17 00:00:00 2001 From: "Ruan E. Formigoni" Date: Thu, 10 Nov 2022 02:36:54 -0300 Subject: [PATCH 001/104] exec runs after on-* events --- include/AModule.hpp | 2 +- src/AModule.cpp | 10 +++++----- src/modules/custom.cpp | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/AModule.hpp b/include/AModule.hpp index 357f70ec..d3009af1 100644 --- a/include/AModule.hpp +++ b/include/AModule.hpp @@ -25,6 +25,7 @@ class AModule : public IModule { SCROLL_DIR getScrollDir(GdkEventScroll *e); bool tooltipEnabled(); + std::vector pid_children_; const std::string name_; const Json::Value &config_; Gtk::EventBox event_box_; @@ -33,7 +34,6 @@ class AModule : public IModule { virtual bool handleScroll(GdkEventScroll *); private: - std::vector pid_; gdouble distance_scrolled_y_; gdouble distance_scrolled_x_; static const inline std::map, std::string> eventMap_{ diff --git a/src/AModule.cpp b/src/AModule.cpp index b19594a1..79f25654 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -35,7 +35,7 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std:: } AModule::~AModule() { - for (const auto& pid : pid_) { + for (const auto& pid : pid_children_) { if (pid != -1) { killpg(pid, SIGTERM); } @@ -45,7 +45,7 @@ AModule::~AModule() { auto AModule::update() -> void { // Run user-provided update handler if configured if (config_["on-update"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-update"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-update"].asString())); } } @@ -62,7 +62,7 @@ bool AModule::handleToggle(GdkEventButton* const& e) { } if (!format.empty()) { - pid_.push_back(util::command::forkExec(format)); + pid_children_.push_back(util::command::forkExec(format)); } dp.emit(); return true; @@ -123,9 +123,9 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) { bool AModule::handleScroll(GdkEventScroll* e) { auto dir = getScrollDir(e); if (dir == SCROLL_DIR::UP && config_["on-scroll-up"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-scroll-up"].asString())); } else if (dir == SCROLL_DIR::DOWN && config_["on-scroll-down"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-scroll-down"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-scroll-down"].asString())); } dp.emit(); return true; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 397298b2..cf66e44b 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -27,6 +27,9 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { + std::for_each(this->pid_children_.cbegin(), this->pid_children_.cend(), + [](int i){ wait(&i); }); + bool can_update = true; if (config_["exec-if"].isString()) { output_ = util::command::execNoRead(config_["exec-if"].asString()); From 15132aeec304bf85a27f0d8cd55079671bcb1013 Mon Sep 17 00:00:00 2001 From: "Ruan E. Formigoni" Date: Tue, 15 Nov 2022 01:19:51 -0300 Subject: [PATCH 002/104] Fix for leftover pids --- src/modules/custom.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index cf66e44b..458228c5 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -27,8 +27,13 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { - std::for_each(this->pid_children_.cbegin(), this->pid_children_.cend(), - [](int i){ wait(&i); }); + for( int i : this->pid_children_ ) + { + int status; + waitpid(i, &status, 0); + } + + this->pid_children_.clear(); bool can_update = true; if (config_["exec-if"].isString()) { From 2de8a83d845c97bf6bb4848cf9d592bbb2439c62 Mon Sep 17 00:00:00 2001 From: Alessio Molinari Date: Sun, 4 Feb 2024 17:20:45 +0100 Subject: [PATCH 003/104] feat: fetch battery percentage from upower if not found from bluez --- include/modules/bluetooth.hpp | 2 +- src/modules/bluetooth.cpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index 89658dcf..b0ed10ba 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -55,7 +55,7 @@ class Bluetooth : public ALabel { GDBusProxy*, GVariant*, const gchar* const*, gpointer) -> void; - auto getDeviceBatteryPercentage(GDBusObject*) -> std::optional; + auto getDeviceBatteryPercentage(GDBusObject*, GDBusProxy*) -> std::optional; auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool; auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool; diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 80e4731b..7b94e59e 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -1,6 +1,7 @@ #include "modules/bluetooth.hpp" #include +#include #include #include @@ -335,7 +336,8 @@ auto waybar::modules::Bluetooth::onInterfaceProxyPropertiesChanged( } } -auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object) +auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object, + GDBusProxy* proxy_device) -> std::optional { GDBusProxy* proxy_device_bat = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Battery1")); @@ -345,6 +347,29 @@ auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object) return battery_percentage; } + if (proxy_device != nullptr) { + auto serial = getStringProperty(proxy_device, "Address"); + std::transform(serial.begin(), serial.end(), serial.begin(), + [](unsigned char c) { return std::tolower(c); }); + + auto* client = up_client_new(); + if (client == nullptr) return std::nullopt; + + auto* devices = up_client_get_devices2(client); + UpDevice* dev; + char* udev_serial; + double percentage; + for (int i = 0; i < devices->len; i++) { + dev = (UpDevice*)g_ptr_array_index(devices, i); + g_object_get(dev, "serial", &udev_serial, nullptr); + if (serial == udev_serial) { + g_object_get(dev, "percentage", &percentage, nullptr); + g_ptr_array_unref(devices); + g_object_unref(client); + return percentage; + } + } + } return std::nullopt; } @@ -367,7 +392,7 @@ auto waybar::modules::Bluetooth::getDeviceProperties(GDBusObject* object, Device g_object_unref(proxy_device); - device_info.battery_percentage = getDeviceBatteryPercentage(object); + device_info.battery_percentage = getDeviceBatteryPercentage(object, proxy_device); return true; } From d831a45622d8497b292188291d8dfa4c67fce52a Mon Sep 17 00:00:00 2001 From: Alessio Molinari Date: Sun, 4 Feb 2024 18:01:26 +0100 Subject: [PATCH 004/104] fix: restore signature --- include/modules/bluetooth.hpp | 2 +- src/modules/bluetooth.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index b0ed10ba..89658dcf 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -55,7 +55,7 @@ class Bluetooth : public ALabel { GDBusProxy*, GVariant*, const gchar* const*, gpointer) -> void; - auto getDeviceBatteryPercentage(GDBusObject*, GDBusProxy*) -> std::optional; + auto getDeviceBatteryPercentage(GDBusObject*) -> std::optional; auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool; auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool; diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 7b94e59e..0bfc4ac3 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -336,11 +336,11 @@ auto waybar::modules::Bluetooth::onInterfaceProxyPropertiesChanged( } } -auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object, - GDBusProxy* proxy_device) +auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object) -> std::optional { GDBusProxy* proxy_device_bat = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Battery1")); + GDBusProxy* proxy_device = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Device1")); if (proxy_device_bat != NULL) { unsigned char battery_percentage = getUcharProperty(proxy_device_bat, "Percentage"); g_object_unref(proxy_device_bat); @@ -392,7 +392,7 @@ auto waybar::modules::Bluetooth::getDeviceProperties(GDBusObject* object, Device g_object_unref(proxy_device); - device_info.battery_percentage = getDeviceBatteryPercentage(object, proxy_device); + device_info.battery_percentage = getDeviceBatteryPercentage(object); return true; } From ea4b95fdd2434ea8cffcf24e9ff36e990815af15 Mon Sep 17 00:00:00 2001 From: Alessio Molinari Date: Mon, 4 Mar 2024 16:34:45 +0100 Subject: [PATCH 005/104] Fix: move init gdbusproxy after proxy_device_bat nullcheck Co-authored-by: Alexis Rouillard --- src/modules/bluetooth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 0bfc4ac3..735866d8 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -340,13 +340,13 @@ auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object) -> std::optional { GDBusProxy* proxy_device_bat = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Battery1")); - GDBusProxy* proxy_device = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Device1")); if (proxy_device_bat != NULL) { unsigned char battery_percentage = getUcharProperty(proxy_device_bat, "Percentage"); g_object_unref(proxy_device_bat); return battery_percentage; } + GDBusProxy* proxy_device = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Device1")); if (proxy_device != nullptr) { auto serial = getStringProperty(proxy_device, "Address"); std::transform(serial.begin(), serial.end(), serial.begin(), From 5c859bf520fe91d37127937e9a0af534b487d4ea Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 00:06:24 +1000 Subject: [PATCH 006/104] temp: changed window -> windowcount --- include/modules/hyprland/windowcount.hpp | 65 +++++++ man/waybar-hyprland-windowcount.5.scd | 89 +++++++++ meson.build | 1 + src/factory.cpp | 4 + src/modules/hyprland/windowcount.cpp | 233 +++++++++++++++++++++++ 5 files changed, 392 insertions(+) create mode 100644 include/modules/hyprland/windowcount.hpp create mode 100644 man/waybar-hyprland-windowcount.5.scd create mode 100644 src/modules/hyprland/windowcount.cpp diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp new file mode 100644 index 00000000..3972c66a --- /dev/null +++ b/include/modules/hyprland/windowcount.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include + +#include + +#include "AAppIconLabel.hpp" +#include "bar.hpp" +#include "modules/hyprland/backend.hpp" +#include "util/json.hpp" + +namespace waybar::modules::hyprland { + +class WindowCount : public waybar::AAppIconLabel, public EventHandler { + public: + WindowCount(const std::string&, const waybar::Bar&, const Json::Value&); + ~WindowCount() override; + + auto update() -> void override; + + private: + struct Workspace { + int id; + int windows; + std::string last_window; + std::string last_window_title; + + static auto parse(const Json::Value& value) -> Workspace; + }; + + struct WindowCountData { + bool floating; + int monitor = -1; + std::string class_name; + std::string initial_class_name; + std::string title; + std::string initial_title; + bool fullscreen; + bool grouped; + + static auto parse(const Json::Value&) -> WindowCountData; + }; + + static auto getActiveWorkspace(const std::string&) -> Workspace; + static auto getActiveWorkspace() -> Workspace; + void onEvent(const std::string& ev) override; + void queryActiveWorkspace(); + void setClass(const std::string&, bool enable); + + bool separateOutputs_; + std::mutex mutex_; + const Bar& bar_; + util::JsonParser parser_; + WindowCountData windowData_; + Workspace workspace_; + std::string soloClass_; + std::string lastSoloClass_; + bool solo_; + bool allFloating_; + bool swallowing_; + bool fullscreen_; + bool focused_; +}; + +} // namespace waybar::modules::hyprland diff --git a/man/waybar-hyprland-windowcount.5.scd b/man/waybar-hyprland-windowcount.5.scd new file mode 100644 index 00000000..4e9c5d18 --- /dev/null +++ b/man/waybar-hyprland-windowcount.5.scd @@ -0,0 +1,89 @@ +waybar-hyprland-window(5) + +# NAME + +waybar - hyprland window module + +# DESCRIPTION + +The *window* module displays the title of the currently focused window in Hyprland. + +# CONFIGURATION + +Addressed by *hyprland/window* + +*format*: ++ + typeof: string ++ + default: {title} ++ + The format, how information should be displayed. On {} the current window title is displayed. + +*rewrite*: ++ + typeof: object ++ + Rules to rewrite window title. See *rewrite rules*. + +*separate-outputs*: ++ + typeof: bool ++ + Show the active window of the monitor the bar belongs to, instead of the focused window. + +*icon*: ++ + typeof: bool ++ + default: false ++ + Option to hide the application icon. + +*icon-size*: ++ + typeof: integer ++ + default: 24 ++ + Option to change the size of the application icon. + +# FORMAT REPLACEMENTS +See the output of "hyprctl clients" for examples + +*{title}*: The current title of the focused window. + +*{initialTitle}*: The initial title of the focused window. + +*{class}*: The current class of the focused window. + +*{initialClass}*: The initial class of the focused window. + +# REWRITE RULES + +*rewrite* is an object where keys are regular expressions and values are +rewrite rules if the expression matches. Rules may contain references to +captures of the expression. + +Regular expression and replacement follow ECMA-script rules. + +If no expression matches, the title is left unchanged. + +Invalid expressions (e.g., mismatched parentheses) are skipped. + +# EXAMPLES + +``` +"hyprland/window": { + "format": "{}", + "rewrite": { + "(.*) - Mozilla Firefox": "🌎 $1", + "(.*) - zsh": "> [$1]" + } +} +``` + +# STYLE + +- *#window* +- *window#waybar.empty #window* When no windows are in the workspace + +The following classes are applied to the entire Waybar rather than just the +window widget: + +- *window#waybar.empty* When no windows are in the workspace +- *window#waybar.solo* When one tiled window is visible in the workspace + (floating windows may be present) +- *window#waybar.* Where ** is the *class* (e.g. *chromium*) of + the solo tiled window in the workspace (use *hyprctl clients* to see classes) +- *window#waybar.floating* When there are only floating windows in the workspace +- *window#waybar.fullscreen* When there is a fullscreen window in the workspace; + useful with Hyprland's *fullscreen, 1* mode +- *window#waybar.swallowing* When there is a swallowed window in the workspace diff --git a/meson.build b/meson.build index 8daa6c9c..1a7a94df 100644 --- a/meson.build +++ b/meson.build @@ -306,6 +306,7 @@ if true 'src/modules/hyprland/language.cpp', 'src/modules/hyprland/submap.cpp', 'src/modules/hyprland/window.cpp', + 'src/modules/hyprland/windowcount.cpp', 'src/modules/hyprland/workspace.cpp', 'src/modules/hyprland/workspaces.cpp', 'src/modules/hyprland/windowcreationpayload.cpp', diff --git a/src/factory.cpp b/src/factory.cpp index ca10ef95..2344160f 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -34,6 +34,7 @@ #include "modules/hyprland/language.hpp" #include "modules/hyprland/submap.hpp" #include "modules/hyprland/window.hpp" +#include "modules/hyprland/windowcount.hpp" #include "modules/hyprland/workspaces.hpp" #endif #if defined(__FreeBSD__) || defined(__linux__) @@ -196,6 +197,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, if (ref == "hyprland/window") { return new waybar::modules::hyprland::Window(id, bar_, config_[name]); } + if (ref == "hyprland/windowcount") { + return new waybar::modules::hyprland::WindowCount(id, bar_, config_[name]); + } if (ref == "hyprland/language") { return new waybar::modules::hyprland::Language(id, bar_, config_[name]); } diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp new file mode 100644 index 00000000..52c25978 --- /dev/null +++ b/src/modules/hyprland/windowcount.cpp @@ -0,0 +1,233 @@ +#include "modules/hyprland/windowcount.hpp" + +#include +#include +#include +#include + +#include +#include + +#include "modules/hyprland/backend.hpp" +#include "util/rewrite_string.hpp" +#include "util/sanitize_str.hpp" + +namespace waybar::modules::hyprland { + +WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config) + : AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) { + modulesReady = true; + separateOutputs_ = config["separate-outputs"].asBool(); + + if (!gIPC) { + gIPC = std::make_unique(); + } + + queryActiveWorkspace(); + update(); + dp.emit(); + + // register for hyprland ipc + gIPC->registerForIPC("activewindow", this); + gIPC->registerForIPC("closewindow", this); + gIPC->registerForIPC("movewindow", this); + gIPC->registerForIPC("changefloatingmode", this); + gIPC->registerForIPC("fullscreen", this); +} + +WindowCount::~WindowCount() { + gIPC->unregisterForIPC(this); + // wait for possible event handler to finish + std::lock_guard lg(mutex_); +} + +auto WindowCount::update() -> void { + // fix ampersands + std::lock_guard lg(mutex_); + + std::string windowName = waybar::util::sanitize_string(workspace_.last_window_title); + std::string windowAddress = workspace_.last_window; + + windowData_.title = windowName; + + if (!format_.empty()) { + label_.show(); + label_.set_markup(waybar::util::rewriteString( + fmt::format(fmt::runtime(format_), fmt::arg("title", windowName), + fmt::arg("initialTitle", windowData_.initial_title), + fmt::arg("class", windowData_.class_name), + fmt::arg("initialClass", windowData_.initial_class_name)), + config_["rewrite"])); + } else { + label_.hide(); + } + + if (focused_) { + image_.show(); + } else { + image_.hide(); + } + + setClass("empty", workspace_.windows == 0); + setClass("solo", solo_); + setClass("floating", allFloating_); + setClass("swallowing", swallowing_); + setClass("fullscreen", fullscreen_); + + if (!lastSoloClass_.empty() && soloClass_ != lastSoloClass_) { + if (bar_.window.get_style_context()->has_class(lastSoloClass_)) { + bar_.window.get_style_context()->remove_class(lastSoloClass_); + spdlog::trace("Removing solo class: {}", lastSoloClass_); + } + } + + if (!soloClass_.empty() && soloClass_ != lastSoloClass_) { + bar_.window.get_style_context()->add_class(soloClass_); + spdlog::trace("Adding solo class: {}", soloClass_); + } + lastSoloClass_ = soloClass_; + + AAppIconLabel::update(); +} + +auto WindowCount::getActiveWorkspace() -> Workspace { + const auto workspace = gIPC->getSocket1JsonReply("activeworkspace"); + + if (workspace.isObject()) { + return Workspace::parse(workspace); + } + + return {}; +} + +auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspace { + const auto monitors = gIPC->getSocket1JsonReply("monitors"); + if (monitors.isArray()) { + auto monitor = std::find_if(monitors.begin(), monitors.end(), [&](Json::Value monitor) { + return monitor["name"] == monitorName; + }); + if (monitor == std::end(monitors)) { + spdlog::warn("Monitor not found: {}", monitorName); + return Workspace{-1, 0, "", ""}; + } + const int id = (*monitor)["activeWorkspace"]["id"].asInt(); + + const auto workspaces = gIPC->getSocket1JsonReply("workspaces"); + if (workspaces.isArray()) { + auto workspace = std::find_if(workspaces.begin(), workspaces.end(), + [&](Json::Value workspace) { return workspace["id"] == id; }); + if (workspace == std::end(workspaces)) { + spdlog::warn("No workspace with id {}", id); + return Workspace{-1, 0, "", ""}; + } + return Workspace::parse(*workspace); + }; + }; + + return {}; +} + +auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Workspace { + return Workspace{ + value["id"].asInt(), + value["windows"].asInt(), + value["lastwindow"].asString(), + value["lastwindowtitle"].asString(), + }; +} + +auto WindowCount::WindowCountData::parse(const Json::Value& value) -> WindowCount::WindowCountData { + return WindowCountData{value["floating"].asBool(), value["monitor"].asInt(), + value["class"].asString(), value["initialClass"].asString(), + value["title"].asString(), value["initialTitle"].asString(), + value["fullscreen"].asBool(), !value["grouped"].empty()}; +} + +void WindowCount::queryActiveWorkspace() { + std::lock_guard lg(mutex_); + + if (separateOutputs_) { + workspace_ = getActiveWorkspace(this->bar_.output->name); + } else { + workspace_ = getActiveWorkspace(); + } + + focused_ = true; + if (workspace_.windows > 0) { + const auto clients = gIPC->getSocket1JsonReply("clients"); + if (clients.isArray()) { + auto activeWindowCount = std::find_if(clients.begin(), clients.end(), [&](Json::Value window) { + return window["address"] == workspace_.last_window; + }); + + if (activeWindowCount == std::end(clients)) { + focused_ = false; + return; + } + + windowData_ = WindowCountData::parse(*activeWindowCount); + updateAppIconName(windowData_.class_name, windowData_.initial_class_name); + std::vector workspaceWindowCounts; + std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspaceWindowCounts), + [&](Json::Value window) { + return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool(); + }); + swallowing_ = + std::any_of(workspaceWindowCounts.begin(), workspaceWindowCounts.end(), [&](Json::Value window) { + return !window["swallowing"].isNull() && window["swallowing"].asString() != "0x0"; + }); + std::vector visibleWindowCounts; + std::copy_if(workspaceWindowCounts.begin(), workspaceWindowCounts.end(), + std::back_inserter(visibleWindowCounts), + [&](Json::Value window) { return !window["hidden"].asBool(); }); + solo_ = 1 == std::count_if(visibleWindowCounts.begin(), visibleWindowCounts.end(), + [&](Json::Value window) { return !window["floating"].asBool(); }); + allFloating_ = std::all_of(visibleWindowCounts.begin(), visibleWindowCounts.end(), + [&](Json::Value window) { return window["floating"].asBool(); }); + fullscreen_ = windowData_.fullscreen; + + // Fullscreen windows look like they are solo + if (fullscreen_) { + solo_ = true; + } + + // Grouped windows have a tab bar and therefore don't look fullscreen or solo + if (windowData_.grouped) { + fullscreen_ = false; + solo_ = false; + } + + if (solo_) { + soloClass_ = windowData_.class_name; + } else { + soloClass_ = ""; + } + }; + } else { + focused_ = false; + windowData_ = WindowCountData{}; + allFloating_ = false; + swallowing_ = false; + fullscreen_ = false; + solo_ = false; + soloClass_ = ""; + } +} + +void WindowCount::onEvent(const std::string& ev) { + queryActiveWorkspace(); + + dp.emit(); +} + +void WindowCount::setClass(const std::string& classname, bool enable) { + if (enable) { + if (!bar_.window.get_style_context()->has_class(classname)) { + bar_.window.get_style_context()->add_class(classname); + } + } else { + bar_.window.get_style_context()->remove_class(classname); + } +} + +} // namespace waybar::modules::hyprland From d64c80e234e69872239d3a2d4c24e8077771014f Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 00:14:30 +1000 Subject: [PATCH 007/104] temp: working implementation --- include/modules/hyprland/windowcount.hpp | 24 +---- src/modules/hyprland/windowcount.cpp | 115 +++-------------------- 2 files changed, 14 insertions(+), 125 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index 3972c66a..d5fd9565 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -28,19 +28,6 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { static auto parse(const Json::Value& value) -> Workspace; }; - struct WindowCountData { - bool floating; - int monitor = -1; - std::string class_name; - std::string initial_class_name; - std::string title; - std::string initial_title; - bool fullscreen; - bool grouped; - - static auto parse(const Json::Value&) -> WindowCountData; - }; - static auto getActiveWorkspace(const std::string&) -> Workspace; static auto getActiveWorkspace() -> Workspace; void onEvent(const std::string& ev) override; @@ -50,16 +37,9 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { bool separateOutputs_; std::mutex mutex_; const Bar& bar_; - util::JsonParser parser_; - WindowCountData windowData_; Workspace workspace_; - std::string soloClass_; - std::string lastSoloClass_; - bool solo_; - bool allFloating_; - bool swallowing_; - bool fullscreen_; bool focused_; + int windowCount_; }; -} // namespace waybar::modules::hyprland +} // namespace waybar::modules::hyprland \ No newline at end of file diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index 52c25978..da600379 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -15,7 +15,7 @@ namespace waybar::modules::hyprland { WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config) - : AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) { + : AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar) { modulesReady = true; separateOutputs_ = config["separate-outputs"].asBool(); @@ -28,11 +28,12 @@ WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Valu dp.emit(); // register for hyprland ipc - gIPC->registerForIPC("activewindow", this); + gIPC->registerForIPC("fullscreen", this); + gIPC->registerForIPC("workspace", this); + gIPC->registerForIPC("focusedmon", this); + gIPC->registerForIPC("openwindow", this); gIPC->registerForIPC("closewindow", this); gIPC->registerForIPC("movewindow", this); - gIPC->registerForIPC("changefloatingmode", this); - gIPC->registerForIPC("fullscreen", this); } WindowCount::~WindowCount() { @@ -42,50 +43,19 @@ WindowCount::~WindowCount() { } auto WindowCount::update() -> void { - // fix ampersands std::lock_guard lg(mutex_); - std::string windowName = waybar::util::sanitize_string(workspace_.last_window_title); - std::string windowAddress = workspace_.last_window; - - windowData_.title = windowName; - if (!format_.empty()) { label_.show(); label_.set_markup(waybar::util::rewriteString( - fmt::format(fmt::runtime(format_), fmt::arg("title", windowName), - fmt::arg("initialTitle", windowData_.initial_title), - fmt::arg("class", windowData_.class_name), - fmt::arg("initialClass", windowData_.initial_class_name)), + fmt::format(fmt::runtime(format_), fmt::arg("count", workspace_.windows)), config_["rewrite"])); } else { label_.hide(); } - if (focused_) { - image_.show(); - } else { - image_.hide(); - } - - setClass("empty", workspace_.windows == 0); - setClass("solo", solo_); - setClass("floating", allFloating_); - setClass("swallowing", swallowing_); - setClass("fullscreen", fullscreen_); - - if (!lastSoloClass_.empty() && soloClass_ != lastSoloClass_) { - if (bar_.window.get_style_context()->has_class(lastSoloClass_)) { - bar_.window.get_style_context()->remove_class(lastSoloClass_); - spdlog::trace("Removing solo class: {}", lastSoloClass_); - } - } - - if (!soloClass_.empty() && soloClass_ != lastSoloClass_) { - bar_.window.get_style_context()->add_class(soloClass_); - spdlog::trace("Adding solo class: {}", soloClass_); - } - lastSoloClass_ = soloClass_; + // Display the count as the label text + label_.set_text(fmt::format("{}", workspace_.windows)); AAppIconLabel::update(); } @@ -136,13 +106,6 @@ auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Wor }; } -auto WindowCount::WindowCountData::parse(const Json::Value& value) -> WindowCount::WindowCountData { - return WindowCountData{value["floating"].asBool(), value["monitor"].asInt(), - value["class"].asString(), value["initialClass"].asString(), - value["title"].asString(), value["initialTitle"].asString(), - value["fullscreen"].asBool(), !value["grouped"].empty()}; -} - void WindowCount::queryActiveWorkspace() { std::lock_guard lg(mutex_); @@ -153,70 +116,16 @@ void WindowCount::queryActiveWorkspace() { } focused_ = true; - if (workspace_.windows > 0) { - const auto clients = gIPC->getSocket1JsonReply("clients"); - if (clients.isArray()) { - auto activeWindowCount = std::find_if(clients.begin(), clients.end(), [&](Json::Value window) { - return window["address"] == workspace_.last_window; - }); + windowCount_ = workspace_.windows; - if (activeWindowCount == std::end(clients)) { - focused_ = false; - return; - } - - windowData_ = WindowCountData::parse(*activeWindowCount); - updateAppIconName(windowData_.class_name, windowData_.initial_class_name); - std::vector workspaceWindowCounts; - std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspaceWindowCounts), - [&](Json::Value window) { - return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool(); - }); - swallowing_ = - std::any_of(workspaceWindowCounts.begin(), workspaceWindowCounts.end(), [&](Json::Value window) { - return !window["swallowing"].isNull() && window["swallowing"].asString() != "0x0"; - }); - std::vector visibleWindowCounts; - std::copy_if(workspaceWindowCounts.begin(), workspaceWindowCounts.end(), - std::back_inserter(visibleWindowCounts), - [&](Json::Value window) { return !window["hidden"].asBool(); }); - solo_ = 1 == std::count_if(visibleWindowCounts.begin(), visibleWindowCounts.end(), - [&](Json::Value window) { return !window["floating"].asBool(); }); - allFloating_ = std::all_of(visibleWindowCounts.begin(), visibleWindowCounts.end(), - [&](Json::Value window) { return window["floating"].asBool(); }); - fullscreen_ = windowData_.fullscreen; - - // Fullscreen windows look like they are solo - if (fullscreen_) { - solo_ = true; - } - - // Grouped windows have a tab bar and therefore don't look fullscreen or solo - if (windowData_.grouped) { - fullscreen_ = false; - solo_ = false; - } - - if (solo_) { - soloClass_ = windowData_.class_name; - } else { - soloClass_ = ""; - } - }; - } else { + if (workspace_.windows == 0) { focused_ = false; - windowData_ = WindowCountData{}; - allFloating_ = false; - swallowing_ = false; - fullscreen_ = false; - solo_ = false; - soloClass_ = ""; } } void WindowCount::onEvent(const std::string& ev) { queryActiveWorkspace(); - + update(); dp.emit(); } @@ -230,4 +139,4 @@ void WindowCount::setClass(const std::string& classname, bool enable) { } } -} // namespace waybar::modules::hyprland +} // namespace waybar::modules::hyprland \ No newline at end of file From 58e4f89a82057612ea12b688dc099203899f1d32 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 00:40:22 +1000 Subject: [PATCH 008/104] fix: allow custom format --- src/modules/hyprland/windowcount.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index da600379..f5b180a0 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -45,18 +45,21 @@ WindowCount::~WindowCount() { auto WindowCount::update() -> void { std::lock_guard lg(mutex_); - if (!format_.empty()) { - label_.show(); + std::string format = config_["format"].asString(); + std::string formattedText; + + if (!format.empty()) { + formattedText = fmt::format(fmt::runtime(format), workspace_.windows); label_.set_markup(waybar::util::rewriteString( - fmt::format(fmt::runtime(format_), fmt::arg("count", workspace_.windows)), + formattedText, config_["rewrite"])); + label_.show(); } else { + // Default display + label_.set_text(fmt::format("{}", workspace_.windows)); label_.hide(); } - // Display the count as the label text - label_.set_text(fmt::format("{}", workspace_.windows)); - AAppIconLabel::update(); } @@ -125,7 +128,6 @@ void WindowCount::queryActiveWorkspace() { void WindowCount::onEvent(const std::string& ev) { queryActiveWorkspace(); - update(); dp.emit(); } From e40bc27257d1c9699e3291b8406c68e3da575e8b Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 00:40:41 +1000 Subject: [PATCH 009/104] fix: default separate-outputs to true --- src/modules/hyprland/windowcount.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index f5b180a0..04c62153 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -17,7 +17,7 @@ namespace waybar::modules::hyprland { WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config) : AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar) { modulesReady = true; - separateOutputs_ = config["separate-outputs"].asBool(); + separateOutputs_ = config.isMember("separate-outputs") ? config["separate-outputs"].asBool() : true; if (!gIPC) { gIPC = std::make_unique(); From 1806edcb06c167a5e75993ecbb36b7a5867d6920 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 01:04:58 +1000 Subject: [PATCH 010/104] fix: remove unused variable --- include/modules/hyprland/windowcount.hpp | 1 - src/modules/hyprland/windowcount.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index d5fd9565..f9644f5a 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -39,7 +39,6 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { const Bar& bar_; Workspace workspace_; bool focused_; - int windowCount_; }; } // namespace waybar::modules::hyprland \ No newline at end of file diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index 04c62153..d1429c25 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -119,7 +119,6 @@ void WindowCount::queryActiveWorkspace() { } focused_ = true; - windowCount_ = workspace_.windows; if (workspace_.windows == 0) { focused_ = false; From 1b282e67a7fd2ef1abad474574e13efcdd1b5ffa Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 01:06:00 +1000 Subject: [PATCH 011/104] fix: remove unused attributes --- include/modules/hyprland/windowcount.hpp | 3 --- src/modules/hyprland/windowcount.cpp | 6 ++---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index f9644f5a..1d283b67 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -22,9 +22,6 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { struct Workspace { int id; int windows; - std::string last_window; - std::string last_window_title; - static auto parse(const Json::Value& value) -> Workspace; }; diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index d1429c25..e6e36238 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -81,7 +81,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac }); if (monitor == std::end(monitors)) { spdlog::warn("Monitor not found: {}", monitorName); - return Workspace{-1, 0, "", ""}; + return Workspace{-1, 0}; } const int id = (*monitor)["activeWorkspace"]["id"].asInt(); @@ -91,7 +91,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac [&](Json::Value workspace) { return workspace["id"] == id; }); if (workspace == std::end(workspaces)) { spdlog::warn("No workspace with id {}", id); - return Workspace{-1, 0, "", ""}; + return Workspace{-1, 0}; } return Workspace::parse(*workspace); }; @@ -104,8 +104,6 @@ auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Wor return Workspace{ value["id"].asInt(), value["windows"].asInt(), - value["lastwindow"].asString(), - value["lastwindowtitle"].asString(), }; } From 38ffb24c526bb9cd88dbd078d9e4618a5bea9e84 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 01:25:50 +1000 Subject: [PATCH 012/104] feat: format-fullscreen and format-windowed override added --- include/modules/hyprland/windowcount.hpp | 1 + src/modules/hyprland/windowcount.cpp | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index 1d283b67..c8cfcf6d 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -22,6 +22,7 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { struct Workspace { int id; int windows; + bool hasfullscreen; static auto parse(const Json::Value& value) -> Workspace; }; diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index e6e36238..8e9e77bc 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -46,20 +46,27 @@ auto WindowCount::update() -> void { std::lock_guard lg(mutex_); std::string format = config_["format"].asString(); + std::string formatFullscreen = config_["format-fullscreen"].asString(); + std::string formatWindowed = config_["format-windowed"].asString(); std::string formattedText; - if (!format.empty()) { - formattedText = fmt::format(fmt::runtime(format), workspace_.windows); + if (workspace_.hasfullscreen && !formatFullscreen.empty()) { label_.set_markup(waybar::util::rewriteString( - formattedText, + fmt::format(fmt::runtime(formatFullscreen), workspace_.windows), + config_["rewrite"])); + } else if (!workspace_.hasfullscreen && !formatWindowed.empty()) { + label_.set_markup(waybar::util::rewriteString( + fmt::format(fmt::runtime(formatWindowed), workspace_.windows), + config_["rewrite"])); + } else if (!format.empty()) { + label_.set_markup(waybar::util::rewriteString( + fmt::format(fmt::runtime(format), workspace_.windows), config_["rewrite"])); - label_.show(); } else { - // Default display label_.set_text(fmt::format("{}", workspace_.windows)); - label_.hide(); } + label_.show(); AAppIconLabel::update(); } @@ -81,7 +88,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac }); if (monitor == std::end(monitors)) { spdlog::warn("Monitor not found: {}", monitorName); - return Workspace{-1, 0}; + return Workspace{-1, 0, false}; } const int id = (*monitor)["activeWorkspace"]["id"].asInt(); @@ -91,7 +98,7 @@ auto WindowCount::getActiveWorkspace(const std::string& monitorName) -> Workspac [&](Json::Value workspace) { return workspace["id"] == id; }); if (workspace == std::end(workspaces)) { spdlog::warn("No workspace with id {}", id); - return Workspace{-1, 0}; + return Workspace{-1, 0, false}; } return Workspace::parse(*workspace); }; @@ -104,6 +111,7 @@ auto WindowCount::Workspace::parse(const Json::Value& value) -> WindowCount::Wor return Workspace{ value["id"].asInt(), value["windows"].asInt(), + value["hasfullscreen"].asBool(), }; } From f7e1d3425153feb99981af66962df3745bc1b045 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 01:33:07 +1000 Subject: [PATCH 013/104] feat: added empty and fullscreen style classes --- src/modules/hyprland/windowcount.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index 8e9e77bc..d6fff2c1 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -48,7 +48,9 @@ auto WindowCount::update() -> void { std::string format = config_["format"].asString(); std::string formatFullscreen = config_["format-fullscreen"].asString(); std::string formatWindowed = config_["format-windowed"].asString(); - std::string formattedText; + + setClass("empty", workspace_.windows == 0); + setClass("fullscreen", workspace_.hasfullscreen); if (workspace_.hasfullscreen && !formatFullscreen.empty()) { label_.set_markup(waybar::util::rewriteString( From 6aa8aa3b2279fce790b68766b60b38a2905594f4 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 12:57:10 +1000 Subject: [PATCH 014/104] fix: remove focused_ --- include/modules/hyprland/windowcount.hpp | 1 - src/modules/hyprland/windowcount.cpp | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index c8cfcf6d..1b89d1a3 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -36,7 +36,6 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { std::mutex mutex_; const Bar& bar_; Workspace workspace_; - bool focused_; }; } // namespace waybar::modules::hyprland \ No newline at end of file diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index d6fff2c1..b8142f72 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -125,12 +125,6 @@ void WindowCount::queryActiveWorkspace() { } else { workspace_ = getActiveWorkspace(); } - - focused_ = true; - - if (workspace_.windows == 0) { - focused_ = false; - } } void WindowCount::onEvent(const std::string& ev) { From a5e322ee66752307996c2fa8e6ca9e2c9add7830 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 12:59:57 +1000 Subject: [PATCH 015/104] fix: remove rewrite --- src/modules/hyprland/windowcount.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index b8142f72..c9fc3050 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -9,7 +9,6 @@ #include #include "modules/hyprland/backend.hpp" -#include "util/rewrite_string.hpp" #include "util/sanitize_str.hpp" namespace waybar::modules::hyprland { @@ -53,17 +52,11 @@ auto WindowCount::update() -> void { setClass("fullscreen", workspace_.hasfullscreen); if (workspace_.hasfullscreen && !formatFullscreen.empty()) { - label_.set_markup(waybar::util::rewriteString( - fmt::format(fmt::runtime(formatFullscreen), workspace_.windows), - config_["rewrite"])); + label_.set_markup(fmt::format(fmt::runtime(formatFullscreen), workspace_.windows)); } else if (!workspace_.hasfullscreen && !formatWindowed.empty()) { - label_.set_markup(waybar::util::rewriteString( - fmt::format(fmt::runtime(formatWindowed), workspace_.windows), - config_["rewrite"])); + label_.set_markup(fmt::format(fmt::runtime(formatWindowed), workspace_.windows)); } else if (!format.empty()) { - label_.set_markup(waybar::util::rewriteString( - fmt::format(fmt::runtime(format), workspace_.windows), - config_["rewrite"])); + label_.set_markup(fmt::format(fmt::runtime(format), workspace_.windows)); } else { label_.set_text(fmt::format("{}", workspace_.windows)); } From 9254ef6f2f909130d3ad2dabbe9ebc479a662484 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 13:29:46 +1000 Subject: [PATCH 016/104] docs: updated scd man pages --- man/waybar-hyprland-windowcount.5.scd | 75 ++++----------------------- 1 file changed, 10 insertions(+), 65 deletions(-) diff --git a/man/waybar-hyprland-windowcount.5.scd b/man/waybar-hyprland-windowcount.5.scd index 4e9c5d18..0b6b2171 100644 --- a/man/waybar-hyprland-windowcount.5.scd +++ b/man/waybar-hyprland-windowcount.5.scd @@ -1,89 +1,34 @@ -waybar-hyprland-window(5) +waybar-hyprland-windowcount(5) # NAME -waybar - hyprland window module +waybar - hyprland window count module # DESCRIPTION -The *window* module displays the title of the currently focused window in Hyprland. +The *windowcount* module displays the number of windows in the current Hyprland workspace. # CONFIGURATION -Addressed by *hyprland/window* +Addressed by *hyprland/windowcount* *format*: ++ typeof: string ++ - default: {title} ++ - The format, how information should be displayed. On {} the current window title is displayed. - -*rewrite*: ++ - typeof: object ++ - Rules to rewrite window title. See *rewrite rules*. + default: {} ++ + The format, how information should be displayed. On {} the current window count is displayed. *separate-outputs*: ++ typeof: bool ++ - Show the active window of the monitor the bar belongs to, instead of the focused window. - -*icon*: ++ - typeof: bool ++ - default: false ++ - Option to hide the application icon. - -*icon-size*: ++ - typeof: integer ++ - default: 24 ++ - Option to change the size of the application icon. - -# FORMAT REPLACEMENTS -See the output of "hyprctl clients" for examples - -*{title}*: The current title of the focused window. - -*{initialTitle}*: The initial title of the focused window. - -*{class}*: The current class of the focused window. - -*{initialClass}*: The initial class of the focused window. - -# REWRITE RULES - -*rewrite* is an object where keys are regular expressions and values are -rewrite rules if the expression matches. Rules may contain references to -captures of the expression. - -Regular expression and replacement follow ECMA-script rules. - -If no expression matches, the title is left unchanged. - -Invalid expressions (e.g., mismatched parentheses) are skipped. - -# EXAMPLES - -``` -"hyprland/window": { - "format": "{}", - "rewrite": { - "(.*) - Mozilla Firefox": "🌎 $1", - "(.*) - zsh": "> [$1]" - } -} -``` + default: true ++ + Show the active window count of the monitor the bar belongs to, instead of the focused window. # STYLE -- *#window* -- *window#waybar.empty #window* When no windows are in the workspace +- *#windowcount* The following classes are applied to the entire Waybar rather than just the -window widget: +windowcount widget: - *window#waybar.empty* When no windows are in the workspace -- *window#waybar.solo* When one tiled window is visible in the workspace - (floating windows may be present) -- *window#waybar.* Where ** is the *class* (e.g. *chromium*) of - the solo tiled window in the workspace (use *hyprctl clients* to see classes) -- *window#waybar.floating* When there are only floating windows in the workspace - *window#waybar.fullscreen* When there is a fullscreen window in the workspace; useful with Hyprland's *fullscreen, 1* mode -- *window#waybar.swallowing* When there is a swallowed window in the workspace From 8254bd72b72f16c37d1dad11a0e5d9045e1c423a Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 13:36:00 +1000 Subject: [PATCH 017/104] style: applied clang-format on windowcount.cpp --- src/modules/hyprland/windowcount.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index c9fc3050..001cdf6c 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -16,7 +16,8 @@ namespace waybar::modules::hyprland { WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config) : AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar) { modulesReady = true; - separateOutputs_ = config.isMember("separate-outputs") ? config["separate-outputs"].asBool() : true; + separateOutputs_ = + config.isMember("separate-outputs") ? config["separate-outputs"].asBool() : true; if (!gIPC) { gIPC = std::make_unique(); From 13bc497abd9bad3e46c4f3832d1d57b201e2b5d3 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 15:21:04 +1000 Subject: [PATCH 018/104] style: clang-format --- include/modules/hyprland/windowcount.hpp | 2 +- src/modules/hyprland/windowcount.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index 1b89d1a3..195e6a34 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -38,4 +38,4 @@ class WindowCount : public waybar::AAppIconLabel, public EventHandler { Workspace workspace_; }; -} // namespace waybar::modules::hyprland \ No newline at end of file +} // namespace waybar::modules::hyprland diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index 001cdf6c..68f7c3b4 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -46,16 +46,19 @@ auto WindowCount::update() -> void { std::lock_guard lg(mutex_); std::string format = config_["format"].asString(); - std::string formatFullscreen = config_["format-fullscreen"].asString(); + std::string formatEmpty = config_["format-empty"].asString(); std::string formatWindowed = config_["format-windowed"].asString(); + std::string formatFullscreen = config_["format-fullscreen"].asString(); setClass("empty", workspace_.windows == 0); setClass("fullscreen", workspace_.hasfullscreen); - if (workspace_.hasfullscreen && !formatFullscreen.empty()) { - label_.set_markup(fmt::format(fmt::runtime(formatFullscreen), workspace_.windows)); + if (workspace_.windows == 0 && !formatEmpty.empty()) { + label_.set_markup(fmt::format(fmt::runtime(formatEmpty), workspace_.windows)); } else if (!workspace_.hasfullscreen && !formatWindowed.empty()) { label_.set_markup(fmt::format(fmt::runtime(formatWindowed), workspace_.windows)); + } else if (workspace_.hasfullscreen && !formatFullscreen.empty()) { + label_.set_markup(fmt::format(fmt::runtime(formatFullscreen), workspace_.windows)); } else if (!format.empty()) { label_.set_markup(fmt::format(fmt::runtime(format), workspace_.windows)); } else { @@ -136,4 +139,4 @@ void WindowCount::setClass(const std::string& classname, bool enable) { } } -} // namespace waybar::modules::hyprland \ No newline at end of file +} // namespace waybar::modules::hyprland From b82bcdb515b9b74cdd5f69745eac151e97439c39 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sat, 24 Aug 2024 15:21:33 +1000 Subject: [PATCH 019/104] docs: updated documentation for windowcount.5.scd --- man/waybar-hyprland-windowcount.5.scd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/man/waybar-hyprland-windowcount.5.scd b/man/waybar-hyprland-windowcount.5.scd index 0b6b2171..0ea7de09 100644 --- a/man/waybar-hyprland-windowcount.5.scd +++ b/man/waybar-hyprland-windowcount.5.scd @@ -15,7 +15,19 @@ Addressed by *hyprland/windowcount* *format*: ++ typeof: string ++ default: {} ++ - The format, how information should be displayed. On {} the current window count is displayed. + The format for how information should be displayed. On {} the current workspace window count is displayed. + +*format-empty*: ++ + typeof: string ++ + Override the format when the workspace contains no windows window + +*format-windowed*: ++ + typeof: string ++ + Override the format when the workspace contains no fullscreen windows + +*format-fullscreen*: ++ + typeof: string ++ + Override the format when the workspace contains a fullscreen window *separate-outputs*: ++ typeof: bool ++ From fd67c6e9157464207a22bcd4021d5c3d81234c75 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Sun, 25 Aug 2024 00:05:41 +1000 Subject: [PATCH 020/104] docs: rewording of separate-outputs in man page --- man/waybar-hyprland-windowcount.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/waybar-hyprland-windowcount.5.scd b/man/waybar-hyprland-windowcount.5.scd index 0ea7de09..6a4f87d1 100644 --- a/man/waybar-hyprland-windowcount.5.scd +++ b/man/waybar-hyprland-windowcount.5.scd @@ -32,7 +32,7 @@ Addressed by *hyprland/windowcount* *separate-outputs*: ++ typeof: bool ++ default: true ++ - Show the active window count of the monitor the bar belongs to, instead of the focused window. + Show the active workspace window count of the monitor the bar belongs to, instead of the focused workspace. # STYLE From ddb30164405b169cca3f726c1a0c2cb195a8c0f2 Mon Sep 17 00:00:00 2001 From: Ricardo Nogueira Date: Tue, 12 Nov 2024 17:10:05 -0300 Subject: [PATCH 021/104] add rewrite to wlr tooltip --- src/modules/wlr/taskbar.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 30e4ee48..e5be88d8 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -682,6 +682,9 @@ void Task::update() { fmt::format(fmt::runtime(format_tooltip_), fmt::arg("title", title), fmt::arg("name", name), fmt::arg("app_id", app_id), fmt::arg("state", state_string()), fmt::arg("short_state", state_string(true))); + + txt = waybar::util::rewriteString(txt, config_["rewrite"]); + if (markup) button.set_tooltip_markup(txt); else From d7e4a7d91ff8d8005d1fb0f6159f84c3ec783a8d Mon Sep 17 00:00:00 2001 From: YamaD Date: Wed, 30 Oct 2024 16:54:24 +0900 Subject: [PATCH 022/104] add module wayfire/window, wayfire/workspaces --- include/modules/wayfire/backend.hpp | 122 +++++++ include/modules/wayfire/window.hpp | 24 ++ include/modules/wayfire/workspaces.hpp | 32 ++ man/waybar-wayfire-window.5.scd | 82 +++++ man/waybar-wayfire-workspaces.5.scd | 86 +++++ meson.build | 9 + src/factory.cpp | 12 + src/modules/wayfire/backend.cpp | 445 +++++++++++++++++++++++++ src/modules/wayfire/window.cpp | 77 +++++ src/modules/wayfire/workspaces.cpp | 183 ++++++++++ 10 files changed, 1072 insertions(+) create mode 100644 include/modules/wayfire/backend.hpp create mode 100644 include/modules/wayfire/window.hpp create mode 100644 include/modules/wayfire/workspaces.hpp create mode 100644 man/waybar-wayfire-window.5.scd create mode 100644 man/waybar-wayfire-workspaces.5.scd create mode 100644 src/modules/wayfire/backend.cpp create mode 100644 src/modules/wayfire/window.cpp create mode 100644 src/modules/wayfire/workspaces.cpp diff --git a/include/modules/wayfire/backend.hpp b/include/modules/wayfire/backend.hpp new file mode 100644 index 00000000..9d55c820 --- /dev/null +++ b/include/modules/wayfire/backend.hpp @@ -0,0 +1,122 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace waybar::modules::wayfire { + +using EventHandler = std::function; + +struct State { + /* + ┌───────────┐ ┌───────────┐ + │ output #1 │ │ output #2 │ + └─────┬─────┘ └─────┬─────┘ + └─┐ └─────┐─ ─ ─ ─ ─ ─ ─ ─ ┐ + ┌───────┴───────┐ ┌───────┴──────┐ ┌───────┴───────┐ + │ wset #1 │ │ wset #2 │ │ wset #3 │ + │┌────────────┐ │ │┌────────────┐│ │┌────────────┐ │ + ││ workspaces │ │ ││ workspaces ││ ││ workspaces │ │ + │└─┬──────────┘ │ │└────────────┘│ │└─┬──────────┘ │ + │ │ ┌─────────┐│ └──────────────┘ │ │ ┌─────────┐│ + │ ├─┤ view #1 ││ │ └─┤ view #3 ││ + │ │ └─────────┘│ │ └─────────┘│ + │ │ ┌─────────┐│ └───────────────┘ + │ └─┤ view #2 ││ + │ └─────────┘│ + └───────────────┘ + */ + + struct Output { + size_t id; + size_t w, h; + size_t wset_idx; + }; + + struct Workspace { + size_t num_views; + size_t num_sticky_views; + }; + + struct Wset { + std::optional> output; + std::vector wss; + size_t ws_w, ws_h, ws_x, ws_y; + size_t focused_view_id; + + auto ws_idx() const { return ws_w * ws_y + ws_x; } + auto count_ws(const Json::Value& pos) -> Workspace&; + auto locate_ws(const Json::Value& geo) -> Workspace&; + auto locate_ws(const Json::Value& geo) const -> const Workspace&; + }; + + std::unordered_map outputs; + std::unordered_map wsets; + std::unordered_map views; + std::string focused_output_name; + size_t maybe_empty_focus_wset_idx = {}; + size_t vswitch_sticky_view_id = {}; + bool new_output_detected = {}; + bool vswitching = {}; + + auto update_view(const Json::Value& view) -> void; +}; + +struct Sock { + int fd; + + Sock(int fd) : fd{fd} {} + ~Sock() { close(fd); } + Sock(const Sock&) = delete; + auto operator=(const Sock&) = delete; + Sock(Sock&& rhs) noexcept { + fd = rhs.fd; + rhs.fd = -1; + } + auto& operator=(Sock&& rhs) noexcept { + fd = rhs.fd; + rhs.fd = -1; + return *this; + } +}; + +class IPC { + static std::weak_ptr instance; + Json::CharReaderBuilder reader_builder; + Json::StreamWriterBuilder writer_builder; + std::list>> handlers; + std::mutex handlers_mutex; + State state; + std::mutex state_mutex; + + IPC() { start(); } + + static auto connect() -> Sock; + auto receive(Sock& sock) -> Json::Value; + auto start() -> void; + auto root_event_handler(const std::string& event, const Json::Value& data) -> void; + auto update_state_handler(const std::string& event, const Json::Value& data) -> void; + + public: + static auto get_instance() -> std::shared_ptr; + auto send(const std::string& method, Json::Value&& data) -> Json::Value; + auto register_handler(const std::string& event, const EventHandler& handler) -> void; + auto unregister_handler(EventHandler& handler) -> void; + + auto lock_state() -> std::lock_guard { return std::lock_guard{state_mutex}; } + auto& get_outputs() const { return state.outputs; } + auto& get_wsets() const { return state.wsets; } + auto& get_views() const { return state.views; } + auto& get_focused_output_name() const { return state.focused_output_name; } +}; + +} // namespace waybar::modules::wayfire diff --git a/include/modules/wayfire/window.hpp b/include/modules/wayfire/window.hpp new file mode 100644 index 00000000..3e8cb291 --- /dev/null +++ b/include/modules/wayfire/window.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "AAppIconLabel.hpp" +#include "bar.hpp" +#include "modules/wayfire/backend.hpp" + +namespace waybar::modules::wayfire { + +class Window : public AAppIconLabel { + std::shared_ptr ipc; + EventHandler handler; + + const Bar& bar_; + std::string old_app_id_; + + public: + Window(const std::string& id, const Bar& bar, const Json::Value& config); + ~Window() override; + + auto update() -> void override; + auto update_icon_label() -> void; +}; + +} // namespace waybar::modules::wayfire diff --git a/include/modules/wayfire/workspaces.hpp b/include/modules/wayfire/workspaces.hpp new file mode 100644 index 00000000..ab7cac44 --- /dev/null +++ b/include/modules/wayfire/workspaces.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include +#include + +#include "AModule.hpp" +#include "bar.hpp" +#include "modules/wayfire/backend.hpp" + +namespace waybar::modules::wayfire { + +class Workspaces : public AModule { + std::shared_ptr ipc; + EventHandler handler; + + const Bar& bar_; + Gtk::Box box_; + std::vector buttons_; + + auto handleScroll(GdkEventScroll* e) -> bool override; + auto update() -> void override; + auto update_box() -> void; + + public: + Workspaces(const std::string& id, const Bar& bar, const Json::Value& config); + ~Workspaces() override; +}; + +} // namespace waybar::modules::wayfire diff --git a/man/waybar-wayfire-window.5.scd b/man/waybar-wayfire-window.5.scd new file mode 100644 index 00000000..290b0c65 --- /dev/null +++ b/man/waybar-wayfire-window.5.scd @@ -0,0 +1,82 @@ +waybar-wayfire-window(5) + +# NAME + +waybar - wayfire window module + +# DESCRIPTION + +The *window* module displays the title of the currently focused window in wayfire. + +# CONFIGURATION + +Addressed by *wayfire/window* + +*format*: ++ + typeof: string ++ + default: {title} ++ + The format, how information should be displayed. On {} the current window title is displayed. + +*rewrite*: ++ + typeof: object ++ + Rules to rewrite window title. See *rewrite rules*. + +*icon*: ++ + typeof: bool ++ + default: false ++ + Option to hide the application icon. + +*icon-size*: ++ + typeof: integer ++ + default: 24 ++ + Option to change the size of the application icon. + +*expand*: ++ + typeof: bool ++ + default: false ++ + Enables this module to consume all left over space dynamically. + +# FORMAT REPLACEMENTS + +See the output of "wayfire msg windows" for examples + +*{title}*: The current title of the focused window. + +*{app_id}*: The current app ID of the focused window. + +# REWRITE RULES + +*rewrite* is an object where keys are regular expressions and values are +rewrite rules if the expression matches. Rules may contain references to +captures of the expression. + +Regular expression and replacement follow ECMA-script rules. + +If no expression matches, the title is left unchanged. + +Invalid expressions (e.g., mismatched parentheses) are skipped. + +# EXAMPLES + +``` +"wayfire/window": { + "format": "{}", + "rewrite": { + "(.*) - Mozilla Firefox": "🌎 $1", + "(.*) - zsh": "> [$1]" + } +} +``` + +# STYLE + +- *#window* +- *window#waybar.empty #window* When no windows are on the workspace + +The following classes are applied to the entire Waybar rather than just the +window widget: + +- *window#waybar.empty* When no windows are in the workspace +- *window#waybar.solo* When only one window is on the workspace +- *window#waybar.* Where *app-id* is the app ID of the only window on + the workspace diff --git a/man/waybar-wayfire-workspaces.5.scd b/man/waybar-wayfire-workspaces.5.scd new file mode 100644 index 00000000..53a179e8 --- /dev/null +++ b/man/waybar-wayfire-workspaces.5.scd @@ -0,0 +1,86 @@ +waybar-wayfire-workspaces(5) + +# NAME + +waybar - wayfire workspaces module + +# DESCRIPTION + +The *workspaces* module displays the currently used workspaces in wayfire. + +# CONFIGURATION + +Addressed by *wayfire/workspaces* + +*format*: ++ + typeof: string ++ + default: {value} ++ + The format, how information should be displayed. + +*format-icons*: ++ + typeof: array ++ + Based on the workspace name, index and state, the corresponding icon gets selected. See *icons*. + +*disable-click*: ++ + typeof: bool ++ + default: false ++ + If set to false, you can click to change workspace. If set to true this behaviour is disabled. + +*disable-markup*: ++ + typeof: bool ++ + default: false ++ + If set to true, button label will escape pango markup. + +*current-only*: ++ + typeof: bool ++ + default: false ++ + If set to true, only the active or focused workspace will be shown. + +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + +*expand*: ++ + typeof: bool ++ + default: false ++ + Enables this module to consume all left over space dynamically. + +# FORMAT REPLACEMENTS + +*{icon}*: Icon, as defined in *format-icons*. + +*{index}*: Index of the workspace on its output. + +*{output}*: Output where the workspace is located. + +# ICONS + +Additional to workspace name matching, the following *format-icons* can be set. + +- *default*: Will be shown, when no string matches are found. +- *focused*: Will be shown, when workspace is focused. + +# EXAMPLES + +``` +"wayfire/workspaces": { + "format": "{icon}", + "format-icons": { + "1": "", + "2": "", + "3": "", + "4": "", + "5": "", + "focused": "", + "default": "" + } +} +``` + +# Style + +- *#workspaces button* +- *#workspaces button.focused*: The single focused workspace. +- *#workspaces button.empty*: The workspace is empty. +- *#workspaces button.current_output*: The workspace is from the same output as + the bar that it is displayed on. diff --git a/meson.build b/meson.build index 726d492b..2610a67c 100644 --- a/meson.build +++ b/meson.build @@ -333,6 +333,15 @@ if get_option('niri') ) endif +if true + add_project_arguments('-DHAVE_WAYFIRE', language: 'cpp') + src_files += files( + 'src/modules/wayfire/backend.cpp', + 'src/modules/wayfire/window.cpp', + 'src/modules/wayfire/workspaces.cpp', + ) +endif + if libnl.found() and libnlgen.found() add_project_arguments('-DHAVE_LIBNL', language: 'cpp') src_files += files('src/modules/network.cpp') diff --git a/src/factory.cpp b/src/factory.cpp index 6c2313e3..cdeba3e3 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -41,6 +41,10 @@ #include "modules/niri/window.hpp" #include "modules/niri/workspaces.hpp" #endif +#ifdef HAVE_WAYFIRE +#include "modules/wayfire/window.hpp" +#include "modules/wayfire/workspaces.hpp" +#endif #if defined(__FreeBSD__) || defined(__linux__) #include "modules/battery.hpp" #endif @@ -221,6 +225,14 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, if (ref == "niri/workspaces") { return new waybar::modules::niri::Workspaces(id, bar_, config_[name]); } +#endif +#ifdef HAVE_WAYFIRE + if (ref == "wayfire/window") { + return new waybar::modules::wayfire::Window(id, bar_, config_[name]); + } + if (ref == "wayfire/workspaces") { + return new waybar::modules::wayfire::Workspaces(id, bar_, config_[name]); + } #endif if (ref == "idle_inhibitor") { return new waybar::modules::IdleInhibitor(id, bar_, config_[name]); diff --git a/src/modules/wayfire/backend.cpp b/src/modules/wayfire/backend.cpp new file mode 100644 index 00000000..5a9c0c1a --- /dev/null +++ b/src/modules/wayfire/backend.cpp @@ -0,0 +1,445 @@ +#include "modules/wayfire/backend.hpp" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace waybar::modules::wayfire { + +std::weak_ptr IPC::instance; + +// C++23: std::byteswap +inline auto byteswap(uint32_t x) -> uint32_t { + return (x & 0xff000000) >> 24 | (x & 0x00ff0000) >> 8 | (x & 0x0000ff00) << 8 | + (x & 0x000000ff) << 24; +} + +auto pack_and_write(Sock& sock, std::string&& buf) -> void { + uint32_t len = buf.size(); + if constexpr (std::endian::native != std::endian::little) len = byteswap(len); + (void)write(sock.fd, &len, 4); + (void)write(sock.fd, buf.data(), buf.size()); +} + +auto read_exact(Sock& sock, size_t n) -> std::string { + auto buf = std::string(n, 0); + for (size_t i = 0; i < n;) i += read(sock.fd, &buf[i], n - i); + return buf; +} + +// https://github.com/WayfireWM/pywayfire/blob/69b7c21/wayfire/ipc.py#L438 +inline auto is_mapped_toplevel_view(const Json::Value& view) -> bool { + return view["mapped"].asBool() && view["role"] != "desktop-environment" && + view["pid"].asInt() != -1; +} + +auto State::Wset::count_ws(const Json::Value& pos) -> Workspace& { + auto x = pos["x"].asInt(); + auto y = pos["y"].asInt(); + return wss.at(ws_w * y + x); +} + +auto State::Wset::locate_ws(const Json::Value& geo) -> Workspace& { + return const_cast(std::as_const(*this).locate_ws(geo)); +} + +auto State::Wset::locate_ws(const Json::Value& geo) const -> const Workspace& { + const auto& out = output.value().get(); + auto [qx, rx] = std::div(geo["x"].asInt(), out.w); + auto [qy, ry] = std::div(geo["y"].asInt(), out.h); + auto x = std::max(0, (int)ws_x + qx - int{rx < 0}); + auto y = std::max(0, (int)ws_y + qy - int{ry < 0}); + return wss.at(ws_w * y + x); +} + +auto State::update_view(const Json::Value& view) -> void { + auto id = view["id"].asUInt(); + + // erase old view information + if (views.contains(id)) { + auto& old_view = views.at(id); + auto& ws = wsets.at(old_view["wset-index"].asUInt()).locate_ws(old_view["geometry"]); + ws.num_views--; + if (old_view["sticky"].asBool()) ws.num_sticky_views--; + views.erase(id); + } + + // insert or assign new view information + if (is_mapped_toplevel_view(view)) { + try { + // view["wset-index"] could be messed up + auto& ws = wsets.at(view["wset-index"].asUInt()).locate_ws(view["geometry"]); + ws.num_views++; + if (view["sticky"].asBool()) ws.num_sticky_views++; + views.emplace(id, view); + } catch (const std::exception&) { + } + } +} + +auto IPC::get_instance() -> std::shared_ptr { + auto p = instance.lock(); + if (!p) instance = p = std::shared_ptr(new IPC); + return p; +} + +auto IPC::connect() -> Sock { + auto* path = std::getenv("WAYFIRE_SOCKET"); + if (path == nullptr) { + throw std::runtime_error{"Wayfire IPC: ipc not available"}; + } + + auto sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) { + throw std::runtime_error{"Wayfire IPC: socket() failed"}; + } + + auto addr = sockaddr_un{.sun_family = AF_UNIX}; + std::strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); + addr.sun_path[sizeof(addr.sun_path) - 1] = 0; + + if (::connect(sock, (const sockaddr*)&addr, sizeof(addr)) == -1) { + close(sock); + throw std::runtime_error{"Wayfire IPC: connect() failed"}; + } + + return {sock}; +} + +auto IPC::receive(Sock& sock) -> Json::Value { + auto len = *reinterpret_cast(read_exact(sock, 4).data()); + if constexpr (std::endian::native != std::endian::little) len = byteswap(len); + auto buf = read_exact(sock, len); + + Json::Value json; + std::string err; + auto* reader = reader_builder.newCharReader(); + if (!reader->parse(&*buf.begin(), &*buf.end(), &json, &err)) { + throw std::runtime_error{"Wayfire IPC: parse json failed: " + err}; + } + return json; +} + +auto IPC::send(const std::string& method, Json::Value&& data) -> Json::Value { + spdlog::debug("Wayfire IPC: send method \"{}\"", method); + auto sock = connect(); + + Json::Value json; + json["method"] = method; + json["data"] = std::move(data); + + pack_and_write(sock, Json::writeString(writer_builder, json)); + auto res = receive(sock); + root_event_handler(method, res); + return res; +} + +auto IPC::start() -> void { + spdlog::info("Wayfire IPC: starting"); + + // init state + send("window-rules/list-outputs", {}); + send("window-rules/list-wsets", {}); + send("window-rules/list-views", {}); + send("window-rules/get-focused-view", {}); + send("window-rules/get-focused-output", {}); + + std::thread([&] { + auto sock = connect(); + + { + Json::Value json; + json["method"] = "window-rules/events/watch"; + + pack_and_write(sock, Json::writeString(writer_builder, json)); + if (receive(sock)["result"] != "ok") { + spdlog::error( + "Wayfire IPC: method \"window-rules/events/watch\"" + " have failed"); + return; + } + } + + while (auto json = receive(sock)) { + auto ev = json["event"].asString(); + spdlog::debug("Wayfire IPC: received event \"{}\"", ev); + root_event_handler(ev, json); + } + }).detach(); +} + +auto IPC::register_handler(const std::string& event, const EventHandler& handler) -> void { + auto _ = std::lock_guard{handlers_mutex}; + handlers.emplace_back(event, handler); +} + +auto IPC::unregister_handler(EventHandler& handler) -> void { + auto _ = std::lock_guard{handlers_mutex}; + handlers.remove_if([&](auto& e) { return &e.second.get() == &handler; }); +} + +auto IPC::root_event_handler(const std::string& event, const Json::Value& data) -> void { + bool new_output_detected; + { + auto _ = lock_state(); + update_state_handler(event, data); + new_output_detected = state.new_output_detected; + state.new_output_detected = false; + } + if (new_output_detected) { + send("window-rules/list-outputs", {}); + send("window-rules/list-wsets", {}); + } + { + auto _ = std::lock_guard{handlers_mutex}; + for (const auto& [_event, handler] : handlers) + if (_event == event) handler(event); + } +} + +auto IPC::update_state_handler(const std::string& event, const Json::Value& data) -> void { + // IPC events + // https://github.com/WayfireWM/wayfire/blob/053b222/plugins/ipc-rules/ipc-events.hpp#L108-L125 + /* + [x] view-mapped + [x] view-unmapped + [-] view-set-output // for detect new output + [ ] view-geometry-changed // -> view-workspace-changed + [x] view-wset-changed + [x] view-focused + [x] view-title-changed + [x] view-app-id-changed + [x] plugin-activation-state-changed + [x] output-gain-focus + + [ ] view-tiled + [ ] view-minimized + [ ] view-fullscreened + [x] view-sticky + [x] view-workspace-changed + [x] output-wset-changed + [x] wset-workspace-changed + */ + + if (event == "view-mapped") { + // data: { event, view } + state.update_view(data["view"]); + return; + } + + if (event == "view-unmapped") { + // data: { event, view } + try { + // data["view"]["wset-index"] could be messed up + state.update_view(data["view"]); + state.maybe_empty_focus_wset_idx = data["view"]["wset-index"].asUInt(); + } catch (const std::exception&) { + } + return; + } + + if (event == "view-set-output") { + // data: { event, output?, view } + // new output event + if (!state.outputs.contains(data["view"]["output-name"].asString())) { + state.new_output_detected = true; + } + return; + } + + if (event == "view-wset-changed") { + // data: { event, old-wset: wset, new-wset: wset, view } + state.maybe_empty_focus_wset_idx = data["old-wset"]["index"].asUInt(); + state.update_view(data["view"]); + return; + } + + if (event == "view-focused") { + // data: { event, view? } + if (const auto& view = data["view"]) { + try { + // view["wset-index"] could be messed up + auto& wset = state.wsets.at(view["wset-index"].asUInt()); + wset.focused_view_id = view["id"].asUInt(); + } catch (const std::exception&) { + } + } else { + // focused to null + if (state.wsets.contains(state.maybe_empty_focus_wset_idx)) + state.wsets.at(state.maybe_empty_focus_wset_idx).focused_view_id = {}; + } + return; + } + + if (event == "view-title-changed" || event == "view-app-id-changed" || event == "view-sticky") { + // data: { event, view } + state.update_view(data["view"]); + return; + } + + if (event == "plugin-activation-state-changed") { + // data: { event, plugin: name, state: bool, output: id, output-data: output } + auto plugin = data["plugin"].asString(); + auto plugin_state = data["state"].asBool(); + + if (plugin == "vswitch") { + state.vswitching = plugin_state; + if (plugin_state) { + state.maybe_empty_focus_wset_idx = data["output-data"]["wset-index"].asUInt(); + } + } + + return; + } + + if (event == "output-gain-focus") { + // data: { event, output } + state.focused_output_name = data["output"]["name"].asString(); + return; + } + + if (event == "view-workspace-changed") { + // data: { event, from: point, to: point, view } + if (state.vswitching) { + if (state.vswitch_sticky_view_id == 0) { + auto& wset = state.wsets.at(data["view"]["wset-index"].asUInt()); + auto& old_ws = wset.locate_ws(state.views.at(data["view"]["id"].asUInt())["geometry"]); + auto& new_ws = wset.count_ws(data["to"]); + old_ws.num_views--; + new_ws.num_views++; + if (data["view"]["sticky"].asBool()) { + old_ws.num_sticky_views--; + new_ws.num_sticky_views++; + } + state.update_view(data["view"]); + state.vswitch_sticky_view_id = data["view"]["id"].asUInt(); + } else { + state.vswitch_sticky_view_id = {}; + } + return; + } + state.update_view(data["view"]); + return; + } + + if (event == "output-wset-changed") { + // data: { event, new-wset: wset.name, output: id, new-wset-data: wset, output-data: output } + auto& output = state.outputs.at(data["output-data"]["name"].asString()); + auto wset_idx = data["new-wset-data"]["index"].asUInt(); + state.wsets.at(wset_idx).output = output; + output.wset_idx = wset_idx; + return; + } + + if (event == "wset-workspace-changed") { + // data: { event, previous-workspace: point, new-workspace: point, + // output: id, wset: wset.name, output-data: output, wset-data: wset } + auto wset_idx = data["wset-data"]["index"].asUInt(); + auto& wset = state.wsets.at(wset_idx); + wset.ws_x = data["new-workspace"]["x"].asUInt(); + wset.ws_y = data["new-workspace"]["y"].asUInt(); + + // correct existing views geometry + auto& out = wset.output.value().get(); + auto dx = (int)out.w * ((int)wset.ws_x - data["previous-workspace"]["x"].asInt()); + auto dy = (int)out.h * ((int)wset.ws_y - data["previous-workspace"]["y"].asInt()); + for (auto& [_, view] : state.views) { + if (view["wset-index"].asUInt() == wset_idx && + view["id"].asUInt() != state.vswitch_sticky_view_id) { + view["geometry"]["x"] = view["geometry"]["x"].asInt() - dx; + view["geometry"]["y"] = view["geometry"]["y"].asInt() - dy; + } + } + return; + } + + // IPC responses + // https://github.com/WayfireWM/wayfire/blob/053b222/plugins/ipc-rules/ipc-rules.cpp#L27-L37 + + if (event == "window-rules/list-views") { + // data: [ view ] + state.views.clear(); + for (auto& [_, wset] : state.wsets) std::ranges::fill(wset.wss, State::Workspace{}); + for (const auto& view : data | std::views::filter(is_mapped_toplevel_view)) { + state.update_view(view); + } + return; + } + + if (event == "window-rules/list-outputs") { + // data: [ output ] + state.outputs.clear(); + for (const auto& output_data : data) { + state.outputs.emplace(output_data["name"].asString(), + State::Output{ + .id = output_data["id"].asUInt(), + .w = output_data["geometry"]["width"].asUInt(), + .h = output_data["geometry"]["height"].asUInt(), + .wset_idx = output_data["wset-index"].asUInt(), + }); + } + return; + } + + if (event == "window-rules/list-wsets") { + // data: [ wset ] + std::unordered_map wsets; + for (const auto& wset_data : data) { + auto wset_idx = wset_data["index"].asUInt(); + + auto output_name = wset_data["output-name"].asString(); + auto output = state.outputs.contains(output_name) + ? std::optional{std::ref(state.outputs.at(output_name))} + : std::nullopt; + + const auto& ws_data = wset_data["workspace"]; + auto ws_w = ws_data["grid_width"].asUInt(); + auto ws_h = ws_data["grid_height"].asUInt(); + + wsets.emplace(wset_idx, State::Wset{ + .output = output, + .wss = std::vector(ws_w * ws_h), + .ws_w = ws_w, + .ws_h = ws_h, + .ws_x = ws_data["x"].asUInt(), + .ws_y = ws_data["y"].asUInt(), + }); + + if (state.wsets.contains(wset_idx)) { + auto& old_wset = state.wsets.at(wset_idx); + auto& new_wset = wsets.at(wset_idx); + new_wset.wss = std::move(old_wset.wss); + new_wset.focused_view_id = old_wset.focused_view_id; + } + } + state.wsets = std::move(wsets); + return; + } + + if (event == "window-rules/get-focused-view") { + // data: { ok, info: view? } + if (const auto& view = data["info"]) { + auto& wset = state.wsets.at(view["wset-index"].asUInt()); + wset.focused_view_id = view["id"].asUInt(); + state.update_view(view); + } + return; + } + + if (event == "window-rules/get-focused-output") { + // data: { ok, info: output } + state.focused_output_name = data["info"]["name"].asString(); + return; + } +} + +} // namespace waybar::modules::wayfire diff --git a/src/modules/wayfire/window.cpp b/src/modules/wayfire/window.cpp new file mode 100644 index 00000000..fbcde6ec --- /dev/null +++ b/src/modules/wayfire/window.cpp @@ -0,0 +1,77 @@ +#include "modules/wayfire/window.hpp" + +#include +#include +#include + +#include "util/rewrite_string.hpp" +#include "util/sanitize_str.hpp" + +namespace waybar::modules::wayfire { + +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) + : AAppIconLabel(config, "window", id, "{title}", 0, true), + ipc{IPC::get_instance()}, + handler{[this](const auto&) { dp.emit(); }}, + bar_{bar} { + ipc->register_handler("view-unmapped", handler); + ipc->register_handler("view-focused", handler); + ipc->register_handler("view-title-changed", handler); + ipc->register_handler("view-app-id-changed", handler); + + ipc->register_handler("window-rules/get-focused-view", handler); + + dp.emit(); +} + +Window::~Window() { ipc->unregister_handler(handler); } + +auto Window::update() -> void { + update_icon_label(); + AAppIconLabel::update(); +} + +auto Window::update_icon_label() -> void { + auto _ = ipc->lock_state(); + + const auto& output = ipc->get_outputs().at(bar_.output->name); + const auto& wset = ipc->get_wsets().at(output.wset_idx); + const auto& views = ipc->get_views(); + auto ctx = bar_.window.get_style_context(); + + if (views.contains(wset.focused_view_id)) { + const auto& view = views.at(wset.focused_view_id); + auto title = view["title"].asString(); + auto app_id = view["app-id"].asString(); + + // update label + label_.set_markup(waybar::util::rewriteString( + fmt::format(fmt::runtime(format_), fmt::arg("title", waybar::util::sanitize_string(title)), + fmt::arg("app_id", waybar::util::sanitize_string(app_id))), + config_["rewrite"])); + + // update window#waybar.solo + if (wset.locate_ws(view["geometry"]).num_views > 1) + ctx->remove_class("solo"); + else + ctx->add_class("solo"); + + // update window#waybar. + ctx->remove_class(old_app_id_); + ctx->add_class(old_app_id_ = app_id); + + // update window#waybar.empty + ctx->remove_class("empty"); + + // + updateAppIconName(app_id, ""); + label_.show(); + } else { + ctx->add_class("empty"); + + updateAppIconName("", ""); + label_.hide(); + } +} + +} // namespace waybar::modules::wayfire diff --git a/src/modules/wayfire/workspaces.cpp b/src/modules/wayfire/workspaces.cpp new file mode 100644 index 00000000..6814004e --- /dev/null +++ b/src/modules/wayfire/workspaces.cpp @@ -0,0 +1,183 @@ +#include "modules/wayfire/workspaces.hpp" + +#include +#include +#include + +#include +#include + +#include "modules/wayfire/backend.hpp" + +namespace waybar::modules::wayfire { + +Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config) + : AModule{config, "workspaces", id, false, !config["disable-scroll"].asBool()}, + ipc{IPC::get_instance()}, + handler{[this](const auto&) { dp.emit(); }}, + bar_{bar} { + // init box_ + box_.set_name("workspaces"); + if (!id.empty()) box_.get_style_context()->add_class(id); + box_.get_style_context()->add_class(MODULE_CLASS); + event_box_.add(box_); + + // scroll events + if (!config_["disable-scroll"].asBool()) { + auto& target = config_["enable-bar-scroll"].asBool() ? const_cast(bar_).window + : dynamic_cast(box_); + target.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); + target.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll)); + } + + // listen events + ipc->register_handler("view-mapped", handler); + ipc->register_handler("view-unmapped", handler); + ipc->register_handler("view-wset-changed", handler); + ipc->register_handler("output-gain-focus", handler); + ipc->register_handler("view-sticky", handler); + ipc->register_handler("view-workspace-changed", handler); + ipc->register_handler("output-wset-changed", handler); + ipc->register_handler("wset-workspace-changed", handler); + + ipc->register_handler("window-rules/list-views", handler); + ipc->register_handler("window-rules/list-outputs", handler); + ipc->register_handler("window-rules/list-wsets", handler); + ipc->register_handler("window-rules/get-focused-output", handler); + + // initial render + dp.emit(); +} + +Workspaces::~Workspaces() { ipc->unregister_handler(handler); } + +auto Workspaces::handleScroll(GdkEventScroll* e) -> bool { + // Ignore emulated scroll events on window + if (gdk_event_get_pointer_emulated((GdkEvent*)e) != 0) return false; + + auto dir = AModule::getScrollDir(e); + if (dir == SCROLL_DIR::NONE) return true; + + int delta; + if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) + delta = 1; + else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) + delta = -1; + else + return true; + + // cycle workspace + Json::Value data; + { + auto _ = ipc->lock_state(); + const auto& output = ipc->get_outputs().at(bar_.output->name); + const auto& wset = ipc->get_wsets().at(output.wset_idx); + auto n = wset.ws_w * wset.ws_h; + auto i = (wset.ws_idx() + delta + n) % n; + data["x"] = i % wset.ws_w; + data["y"] = i / wset.ws_h; + data["output-id"] = output.id; + } + ipc->send("vswitch/set-workspace", std::move(data)); + + return true; +} + +auto Workspaces::update() -> void { + update_box(); + AModule::update(); +} + +auto Workspaces::update_box() -> void { + auto _ = ipc->lock_state(); + + const auto& output_name = bar_.output->name; + const auto& output = ipc->get_outputs().at(output_name); + const auto& wset = ipc->get_wsets().at(output.wset_idx); + + auto output_focused = ipc->get_focused_output_name() == output_name; + auto ws_w = wset.ws_w; + auto ws_h = wset.ws_h; + auto num_wss = ws_w * ws_h; + + // add buttons for new workspaces + for (auto i = buttons_.size(); i < num_wss; i++) { + auto& btn = buttons_.emplace_back(""); + box_.pack_start(btn, false, false, 0); + btn.set_relief(Gtk::RELIEF_NONE); + if (!config_["disable-click"].asBool()) { + btn.signal_pressed().connect([=, this] { + Json::Value data; + data["x"] = i % ws_w; + data["y"] = i / ws_h; + data["output-id"] = output.id; + ipc->send("vswitch/set-workspace", std::move(data)); + }); + } + } + + // remove buttons for removed workspaces + buttons_.resize(num_wss); + + // update buttons + for (size_t i = 0; i < num_wss; i++) { + const auto& ws = wset.wss[i]; + auto& btn = buttons_[i]; + auto ctx = btn.get_style_context(); + auto ws_focused = i == wset.ws_idx(); + auto ws_empty = ws.num_views == 0; + + // update #workspaces button.focused + if (ws_focused) + ctx->add_class("focused"); + else + ctx->remove_class("focused"); + + // update #workspaces button.empty + if (ws_empty) + ctx->add_class("empty"); + else + ctx->remove_class("empty"); + + // update #workspaces button.current_output + if (output_focused) + ctx->add_class("current_output"); + else + ctx->remove_class("current_output"); + + // update label + auto label = std::to_string(i + 1); + if (config_["format"].isString()) { + auto format = config_["format"].asString(); + auto ws_idx = std::to_string(i + 1); + + const auto& icons = config_["format-icons"]; + std::string icon; + if (!icons) + icon = ws_idx; + else if (ws_focused && icons["focused"]) + icon = icons["focused"].asString(); + else if (icons[ws_idx]) + icon = icons[ws_idx].asString(); + else if (icons["default"]) + icon = icons["default"].asString(); + else + icon = ws_idx; + + label = fmt::format(fmt::runtime(format), fmt::arg("icon", icon), fmt::arg("index", ws_idx), + fmt::arg("output", output_name)); + } + if (!config_["disable-markup"].asBool()) + static_cast(btn.get_children()[0])->set_markup(label); + else + btn.set_label(label); + + // + if (config_["current-only"].asBool() && i != wset.ws_idx()) + btn.hide(); + else + btn.show(); + } +} + +} // namespace waybar::modules::wayfire From 6004316f1a13217313a2bce9403c261e7fe941e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20Huseb=C3=B8?= Date: Thu, 16 Jan 2025 13:24:13 +0100 Subject: [PATCH 023/104] Fix typos in function, variable names and in documentation --- include/modules/hyprland/windowcreationpayload.hpp | 2 +- include/modules/hyprland/workspace.hpp | 4 ++-- include/modules/hyprland/workspaces.hpp | 2 +- include/modules/sway/language.hpp | 4 ++-- include/modules/sway/workspaces.hpp | 2 +- include/util/prepare_for_sleep.h | 2 +- man/waybar-menu.5.scd | 2 +- man/waybar.5.scd.in | 2 +- src/AModule.cpp | 4 ++-- src/modules/hyprland/submap.cpp | 2 +- src/modules/hyprland/windowcreationpayload.cpp | 2 +- src/modules/hyprland/workspace.cpp | 14 +++++++------- src/modules/hyprland/workspaces.cpp | 2 +- src/modules/power_profiles_daemon.cpp | 4 ++-- src/modules/sway/language.cpp | 4 ++-- src/modules/sway/workspaces.cpp | 8 ++++---- src/modules/temperature.cpp | 4 ++-- 17 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/modules/hyprland/windowcreationpayload.hpp b/include/modules/hyprland/windowcreationpayload.hpp index 45229ed4..e4180ed9 100644 --- a/include/modules/hyprland/windowcreationpayload.hpp +++ b/include/modules/hyprland/windowcreationpayload.hpp @@ -42,7 +42,7 @@ class WindowCreationPayload { std::string getWorkspaceName() const { return m_workspaceName; } WindowAddress getAddress() const { return m_windowAddress; } - void moveToWorksace(std::string& new_workspace_name); + void moveToWorkspace(std::string& new_workspace_name); private: void clearAddr(); diff --git a/include/modules/hyprland/workspace.hpp b/include/modules/hyprland/workspace.hpp index f1fea4e8..b67d8e14 100644 --- a/include/modules/hyprland/workspace.hpp +++ b/include/modules/hyprland/workspace.hpp @@ -55,11 +55,11 @@ class Workspace { void setName(std::string const& value) { m_name = value; }; void setOutput(std::string const& value) { m_output = value; }; bool containsWindow(WindowAddress const& addr) const { return m_windowMap.contains(addr); } - void insertWindow(WindowCreationPayload create_window_paylod); + void insertWindow(WindowCreationPayload create_window_payload); std::string removeWindow(WindowAddress const& addr); void initializeWindowMap(const Json::Value& clients_data); - bool onWindowOpened(WindowCreationPayload const& create_window_paylod); + bool onWindowOpened(WindowCreationPayload const& create_window_payload); std::optional closeWindow(WindowAddress const& addr); void update(const std::string& format, const std::string& icon); diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index a9d56b79..a2a8558c 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -118,7 +118,7 @@ class Workspaces : public AModule, public EventHandler { // Map for windows stored in workspaces not present in the current bar. // This happens when the user has multiple monitors (hence, multiple bars) - // and doesn't share windows accross bars (a.k.a `all-outputs` = false) + // and doesn't share windows across bars (a.k.a `all-outputs` = false) std::map m_orphanWindowMap; enum class SortMethod { ID, NAME, NUMBER, DEFAULT }; diff --git a/include/modules/sway/language.hpp b/include/modules/sway/language.hpp index ea58c4f0..91aa181d 100644 --- a/include/modules/sway/language.hpp +++ b/include/modules/sway/language.hpp @@ -21,7 +21,7 @@ class Language : public ALabel, public sigc::trackable { auto update() -> void override; private: - enum class DispayedShortFlag { None = 0, ShortName = 1, ShortDescription = 1 << 1 }; + enum class DisplayedShortFlag { None = 0, ShortName = 1, ShortDescription = 1 << 1 }; struct Layout { std::string full_name; @@ -58,7 +58,7 @@ class Language : public ALabel, public sigc::trackable { std::map layouts_map_; bool hide_single_; bool is_variant_displayed; - std::byte displayed_short_flag = static_cast(DispayedShortFlag::None); + std::byte displayed_short_flag = static_cast(DisplayedShortFlag::None); util::JsonParser parser_; std::mutex mutex_; diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 58c173ec..d8a9e18a 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -48,7 +48,7 @@ class Workspaces : public AModule, public sigc::trackable { std::vector high_priority_named_; std::vector workspaces_order_; Gtk::Box box_; - std::string m_formatWindowSeperator; + std::string m_formatWindowSeparator; util::RegexCollection m_windowRewriteRules; util::JsonParser parser_; std::unordered_map buttons_; diff --git a/include/util/prepare_for_sleep.h b/include/util/prepare_for_sleep.h index 68db8d8e..82f3b627 100644 --- a/include/util/prepare_for_sleep.h +++ b/include/util/prepare_for_sleep.h @@ -4,6 +4,6 @@ namespace waybar::util { -// Get a signal emited with value true when entering sleep, and false when exiting +// Get a signal emitted with value true when entering sleep, and false when exiting SafeSignal& prepare_for_sleep(); } // namespace waybar::util diff --git a/man/waybar-menu.5.scd b/man/waybar-menu.5.scd index 19790ed4..47e10432 100644 --- a/man/waybar-menu.5.scd +++ b/man/waybar-menu.5.scd @@ -7,7 +7,7 @@ waybar - menu property # OVERVIEW -Some modules support a 'menu', which allows to have a popup menu whan a defined +Some modules support a 'menu', which allows to have a popup menu when a defined click is done over the module. # PROPERTIES diff --git a/man/waybar.5.scd.in b/man/waybar.5.scd.in index 5bb62724..e2e0627d 100644 --- a/man/waybar.5.scd.in +++ b/man/waybar.5.scd.in @@ -86,7 +86,7 @@ The visual display elements for waybar use a CSS stylesheet, see *waybar-styles( *no-center* ++ typeof: bool ++ default: false ++ - Option to disable the center modules fully usefull together with expand-\*. + Option to disable the center modules fully useful together with expand-\*. *spacing* ++ typeof: integer ++ diff --git a/src/AModule.cpp b/src/AModule.cpp index 5abb779a..7de1ad9a 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -97,11 +97,11 @@ auto AModule::update() -> void { } } // Get mapping between event name and module action name -// Then call overrided doAction in order to call appropriate module action +// Then call overridden doAction in order to call appropriate module action auto AModule::doAction(const std::string& name) -> void { if (!name.empty()) { const std::map::const_iterator& recA{eventActionMap_.find(name)}; - // Call overrided action if derrived class has implemented it + // Call overridden action if derived class has implemented it if (recA != eventActionMap_.cend() && name != recA->second) this->doAction(recA->second); } } diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index 96677d12..67aaeac0 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -20,7 +20,7 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config) ALabel::update(); // Displays widget immediately if always_on_ assuming default submap - // Needs an actual way to retrive current submap on startup + // Needs an actual way to retrieve current submap on startup if (always_on_) { submap_ = default_submap_; label_.get_style_context()->add_class(submap_); diff --git a/src/modules/hyprland/windowcreationpayload.cpp b/src/modules/hyprland/windowcreationpayload.cpp index df7fe784..2a62ac12 100644 --- a/src/modules/hyprland/windowcreationpayload.cpp +++ b/src/modules/hyprland/windowcreationpayload.cpp @@ -88,7 +88,7 @@ bool WindowCreationPayload::isEmpty(Workspaces &workspace_manager) { int WindowCreationPayload::incrementTimeSpentUncreated() { return m_timeSpentUncreated++; } -void WindowCreationPayload::moveToWorksace(std::string &new_workspace_name) { +void WindowCreationPayload::moveToWorkspace(std::string &new_workspace_name) { m_workspaceName = new_workspace_name; } diff --git a/src/modules/hyprland/workspace.cpp b/src/modules/hyprland/workspace.cpp index e575d1c4..048d50c1 100644 --- a/src/modules/hyprland/workspace.cpp +++ b/src/modules/hyprland/workspace.cpp @@ -90,19 +90,19 @@ void Workspace::initializeWindowMap(const Json::Value &clients_data) { } } -void Workspace::insertWindow(WindowCreationPayload create_window_paylod) { - if (!create_window_paylod.isEmpty(m_workspaceManager)) { - auto repr = create_window_paylod.repr(m_workspaceManager); +void Workspace::insertWindow(WindowCreationPayload create_window_payload) { + if (!create_window_payload.isEmpty(m_workspaceManager)) { + auto repr = create_window_payload.repr(m_workspaceManager); if (!repr.empty()) { - m_windowMap[create_window_paylod.getAddress()] = repr; + m_windowMap[create_window_payload.getAddress()] = repr; } } }; -bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_paylod) { - if (create_window_paylod.getWorkspaceName() == name()) { - insertWindow(create_window_paylod); +bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payload) { + if (create_window_payload.getWorkspaceName() == name()) { + insertWindow(create_window_payload); return true; } return false; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 13364f3f..1cf8a184 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -487,7 +487,7 @@ void Workspaces::onWindowMoved(std::string const &payload) { // and exit for (auto &window : m_windowsToCreate) { if (window.getAddress() == windowAddress) { - window.moveToWorksace(workspaceName); + window.moveToWorkspace(workspaceName); return; } } diff --git a/src/modules/power_profiles_daemon.cpp b/src/modules/power_profiles_daemon.cpp index 3ae3ae83..abad763d 100644 --- a/src/modules/power_profiles_daemon.cpp +++ b/src/modules/power_profiles_daemon.cpp @@ -29,14 +29,14 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu // method on the proxy to see whether or not something's responding // on the other side. - // NOTE: the DBus adresses are under migration. They should be + // NOTE: the DBus addresses are under migration. They should be // changed to org.freedesktop.UPower.PowerProfiles at some point. // // See // https://gitlab.freedesktop.org/upower/power-profiles-daemon/-/releases/0.20 // // The old name is still announced for now. Let's rather use the old - // adresses for compatibility sake. + // addresses for compatibility sake. // // Revisit this in 2026, systems should be updated by then. diff --git a/src/modules/sway/language.cpp b/src/modules/sway/language.cpp index a005df17..f4cfa6c3 100644 --- a/src/modules/sway/language.cpp +++ b/src/modules/sway/language.cpp @@ -22,10 +22,10 @@ Language::Language(const std::string& id, const Json::Value& config) hide_single_ = config["hide-single-layout"].isBool() && config["hide-single-layout"].asBool(); is_variant_displayed = format_.find("{variant}") != std::string::npos; if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) { - displayed_short_flag |= static_cast(DispayedShortFlag::ShortName); + displayed_short_flag |= static_cast(DisplayedShortFlag::ShortName); } if (format_.find("{shortDescription}") != std::string::npos) { - displayed_short_flag |= static_cast(DispayedShortFlag::ShortDescription); + displayed_short_flag |= static_cast(DisplayedShortFlag::ShortDescription); } if (config.isMember("tooltip-format")) { tooltip_format_ = config["tooltip-format"].asString(); diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index dec5cddf..6349d6cc 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -57,9 +57,9 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value box_.get_style_context()->add_class(MODULE_CLASS); event_box_.add(box_); if (config_["format-window-separator"].isString()) { - m_formatWindowSeperator = config_["format-window-separator"].asString(); + m_formatWindowSeparator = config_["format-window-separator"].asString(); } else { - m_formatWindowSeperator = " "; + m_formatWindowSeparator = " "; } const Json::Value &windowRewrite = config["window-rewrite"]; if (windowRewrite.isObject()) { @@ -271,7 +271,7 @@ void Workspaces::updateWindows(const Json::Value &node, std::string &windows) { window = fmt::format(fmt::runtime(window), fmt::arg("name", title), fmt::arg("class", windowClass)); windows.append(window); - windows.append(m_formatWindowSeperator); + windows.append(m_formatWindowSeparator); } } for (const Json::Value &child : node["nodes"]) { @@ -340,7 +340,7 @@ auto Workspaces::update() -> void { fmt::runtime(format), fmt::arg("icon", getIcon(output, *it)), fmt::arg("value", output), fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString()), fmt::arg("windows", - windows.substr(0, windows.length() - m_formatWindowSeperator.length())), + windows.substr(0, windows.length() - m_formatWindowSeparator.length())), fmt::arg("output", (*it)["output"].asString())); } if (!config_["disable-markup"].asBool()) { diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 89d3db2d..2904417b 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -45,7 +45,7 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); } - // check if file_path_ can be used to retrive the temperature + // check if file_path_ can be used to retrieve the temperature std::ifstream temp(file_path_); if (!temp.is_open()) { throw std::runtime_error("Can't open " + file_path_); @@ -148,4 +148,4 @@ bool waybar::modules::Temperature::isWarning(uint16_t temperature_c) { bool waybar::modules::Temperature::isCritical(uint16_t temperature_c) { return config_["critical-threshold"].isInt() && temperature_c >= config_["critical-threshold"].asInt(); -} \ No newline at end of file +} From 8a15cbad5cf1e116c331108e9ed168e20ef041b4 Mon Sep 17 00:00:00 2001 From: Lars Niesen Date: Mon, 13 Jan 2025 09:10:25 +0100 Subject: [PATCH 024/104] Fixes: Add stretching of modules and modules-center toggling Thanks to tmccombs this commit fixes some inconsitencies in #3730. These inconsitencies were: - Fixed the oversight of missing the implementation of expand_center for center_ and right_ - Removes a last minut printf debugging statment I missed. --- src/bar.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index b7737d36..3c3ab690 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -545,7 +545,6 @@ auto waybar::Bar::setupWidgets() -> void { if (config["fixed-center"].isBool() ? config["fixed-center"].asBool() : true) { box_.set_center_widget(center_); } else { - spdlog::error("No fixed center_"); box_.pack_start(center_, true, expand_center); } } @@ -569,13 +568,13 @@ auto waybar::Bar::setupWidgets() -> void { if (!no_center) { for (auto const& module : modules_center_) { - center_.pack_start(*module, false, false); + center_.pack_start(*module, module->expandEnabled(), module->expandEnabled()); } } std::reverse(modules_right_.begin(), modules_right_.end()); for (auto const& module : modules_right_) { - right_.pack_end(*module, false, false); + right_.pack_end(*module, module->expandEnabled(), module->expandEnabled()); } } From 633bf9e00fab791084682d4442a47f5d739d9b82 Mon Sep 17 00:00:00 2001 From: Corey Doughty Date: Thu, 10 Apr 2025 06:56:00 -0400 Subject: [PATCH 025/104] Hyprland submap allow pango markup. --- src/modules/hyprland/submap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index 97c4bb62..9ded789b 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -68,8 +68,9 @@ void Submap::onEvent(const std::string& ev) { return; } - auto submapName = ev.substr(ev.find_last_of('>') + 1); - submapName = waybar::util::sanitize_string(submapName); + //auto submapName = ev.substr(ev.find_last_of('>') + 1); + //submapName = waybar::util::sanitize_string(submapName); + auto submapName = ev.substr(ev.find_first_of('>') + 2 ); if (!submap_.empty()) { label_.get_style_context()->remove_class(submap_); From 682492f7a93331e930f9f57dd82dd681e0f78f49 Mon Sep 17 00:00:00 2001 From: Corey Doughty Date: Thu, 10 Apr 2025 07:05:45 -0400 Subject: [PATCH 026/104] This commit fixes #4023 --- src/modules/hyprland/submap.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index 9ded789b..33de79f5 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -68,8 +68,6 @@ void Submap::onEvent(const std::string& ev) { return; } - //auto submapName = ev.substr(ev.find_last_of('>') + 1); - //submapName = waybar::util::sanitize_string(submapName); auto submapName = ev.substr(ev.find_first_of('>') + 2 ); if (!submap_.empty()) { From b03ecb3d744a6d60d01ff1ace0c01b08eef01307 Mon Sep 17 00:00:00 2001 From: literallyvoid Date: Sat, 12 Apr 2025 17:21:57 -0700 Subject: [PATCH 027/104] Move signal handling to main thread --- src/main.cpp | 130 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 25 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 045b2cd4..94355e1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,6 +8,7 @@ #include #include "client.hpp" +#include "util/SafeSignal.hpp" std::mutex reap_mtx; std::list reap; @@ -70,37 +72,115 @@ void startSignalThread() { } } +static int signal_pipe_write_fd; + +// Write a single signal to `signal_pipe_write_fd`. +// This function is set as a signal handler, so it must be async-signal-safe. +static void writeSignalToPipe(int signum) { + ssize_t amt = write(signal_pipe_write_fd, &signum, sizeof(int)); + + // There's not much we can safely do inside of a signal handler. + // Let's just ignore any errors. + (void) amt; +} + +// This initializes `signal_pipe_write_fd`, and sets up signal handlers. +// +// This function will run forever, emitting every `SIGUSR1`, `SIGUSR2`, +// `SIGINT`, and `SIGRTMIN + 1`...`SIGRTMAX` signal received to +// `signal_handler`. +static void catchSignals(waybar::SafeSignal &signal_handler) { + int fd[2]; + pipe(fd); + + int signal_pipe_read_fd = fd[0]; + signal_pipe_write_fd = fd[1]; + + // This pipe should be able to buffer ~thousands of signals. If it fills up, + // we'll drop signals instead of blocking. + + // We can't allow the write end to block because we'll be writing to it in a + // signal handler, which could interrupt the loop that's reading from it and + // deadlock. + + fcntl(signal_pipe_write_fd, F_SETFL, O_NONBLOCK); + + std::signal(SIGUSR1, writeSignalToPipe); + std::signal(SIGUSR2, writeSignalToPipe); + std::signal(SIGINT, writeSignalToPipe); + + for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) { + std::signal(sig, writeSignalToPipe); + } + + while (true) { + int signum; + ssize_t amt = read(signal_pipe_read_fd, &signum, sizeof(int)); + if (amt < 0) { + spdlog::error("read from signal pipe failed with error {}, closing thread", strerror(errno)); + break; + } + + if (amt != sizeof(int)) { + continue; + } + + signal_handler.emit(signum); + } +} + +// Must be called on the main thread. +static void handleSignalMainThread(int signum) { + if (signum >= SIGRTMIN + 1 && signum <= SIGRTMAX) { + for (auto& bar : waybar::Client::inst()->bars) { + bar->handleSignal(signum); + } + + return; + } + + switch (signum) { + case SIGUSR1: + spdlog::debug("Visibility toggled"); + for (auto& bar : waybar::Client::inst()->bars) { + bar->toggle(); + } + break; + case SIGUSR2: + spdlog::info("Reloading..."); + reload = true; + waybar::Client::inst()->reset(); + break; + case SIGINT: + spdlog::info("Quitting."); + reload = false; + waybar::Client::inst()->reset(); + break; + default: + spdlog::debug("Received signal with number {}, but not handling", signum); + break; + } +} + int main(int argc, char* argv[]) { try { auto* client = waybar::Client::inst(); - std::signal(SIGUSR1, [](int /*signal*/) { - for (auto& bar : waybar::Client::inst()->bars) { - bar->toggle(); - } - }); - - std::signal(SIGUSR2, [](int /*signal*/) { - spdlog::info("Reloading..."); - reload = true; - waybar::Client::inst()->reset(); - }); - - std::signal(SIGINT, [](int /*signal*/) { - spdlog::info("Quitting."); - reload = false; - waybar::Client::inst()->reset(); - }); - - for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) { - std::signal(sig, [](int sig) { - for (auto& bar : waybar::Client::inst()->bars) { - bar->handleSignal(sig); - } - }); - } startSignalThread(); + waybar::SafeSignal posix_signal_received; + posix_signal_received.connect([&](int signum) { + handleSignalMainThread(signum); + }); + + std::thread signal_thread([&]() { + catchSignals(posix_signal_received); + }); + + // Every `std::thread` must be joined or detached. + // This thread should run forever, so detach it. + signal_thread.detach(); + auto ret = 0; do { reload = false; From 97591c825a394fc3bedde47b26bed9d605459cdc Mon Sep 17 00:00:00 2001 From: literallyvoid Date: Sat, 12 Apr 2025 16:41:18 -0700 Subject: [PATCH 028/104] Remove `signalThread` and move reaping to `catchSignals` --- src/main.cpp | 78 +++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 62 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 94355e1b..ba6e00dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,64 +14,6 @@ std::mutex reap_mtx; std::list reap; volatile bool reload; -void* signalThread(void* args) { - int err; - int signum; - sigset_t mask; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - - while (true) { - err = sigwait(&mask, &signum); - if (err != 0) { - spdlog::error("sigwait failed: {}", strerror(errno)); - continue; - } - - switch (signum) { - case SIGCHLD: - spdlog::debug("Received SIGCHLD in signalThread"); - if (!reap.empty()) { - reap_mtx.lock(); - for (auto it = reap.begin(); it != reap.end(); ++it) { - if (waitpid(*it, nullptr, WNOHANG) == *it) { - spdlog::debug("Reaped child with PID: {}", *it); - it = reap.erase(it); - } - } - reap_mtx.unlock(); - } - break; - default: - spdlog::debug("Received signal with number {}, but not handling", signum); - break; - } - } -} - -void startSignalThread() { - int err; - sigset_t mask; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - - // Block SIGCHLD so it can be handled by the signal thread - // Any threads created by this one (the main thread) should not - // modify their signal mask to unblock SIGCHLD - err = pthread_sigmask(SIG_BLOCK, &mask, nullptr); - if (err != 0) { - spdlog::error("pthread_sigmask failed in startSignalThread: {}", strerror(err)); - exit(1); - } - - pthread_t thread_id; - err = pthread_create(&thread_id, nullptr, signalThread, nullptr); - if (err != 0) { - spdlog::error("pthread_create failed in startSignalThread: {}", strerror(err)); - exit(1); - } -} - static int signal_pipe_write_fd; // Write a single signal to `signal_pipe_write_fd`. @@ -87,8 +29,8 @@ static void writeSignalToPipe(int signum) { // This initializes `signal_pipe_write_fd`, and sets up signal handlers. // // This function will run forever, emitting every `SIGUSR1`, `SIGUSR2`, -// `SIGINT`, and `SIGRTMIN + 1`...`SIGRTMAX` signal received to -// `signal_handler`. +// `SIGINT`, `SIGCHLD`, and `SIGRTMIN + 1`...`SIGRTMAX` signal received +// to `signal_handler`. static void catchSignals(waybar::SafeSignal &signal_handler) { int fd[2]; pipe(fd); @@ -108,6 +50,7 @@ static void catchSignals(waybar::SafeSignal &signal_handler) { std::signal(SIGUSR1, writeSignalToPipe); std::signal(SIGUSR2, writeSignalToPipe); std::signal(SIGINT, writeSignalToPipe); + std::signal(SIGCHLD, writeSignalToPipe); for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) { std::signal(sig, writeSignalToPipe); @@ -156,6 +99,19 @@ static void handleSignalMainThread(int signum) { reload = false; waybar::Client::inst()->reset(); break; + case SIGCHLD: + spdlog::debug("Received SIGCHLD in signalThread"); + if (!reap.empty()) { + reap_mtx.lock(); + for (auto it = reap.begin(); it != reap.end(); ++it) { + if (waitpid(*it, nullptr, WNOHANG) == *it) { + spdlog::debug("Reaped child with PID: {}", *it); + it = reap.erase(it); + } + } + reap_mtx.unlock(); + } + break; default: spdlog::debug("Received signal with number {}, but not handling", signum); break; @@ -166,8 +122,6 @@ int main(int argc, char* argv[]) { try { auto* client = waybar::Client::inst(); - startSignalThread(); - waybar::SafeSignal posix_signal_received; posix_signal_received.connect([&](int signum) { handleSignalMainThread(signum); From dbd3ffd73217506ce519179f460820a870b334b6 Mon Sep 17 00:00:00 2001 From: literallyvoid Date: Sat, 12 Apr 2025 17:48:16 -0700 Subject: [PATCH 029/104] Convert `reload` to a local --- src/main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ba6e00dc..ce493ca1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,6 @@ std::mutex reap_mtx; std::list reap; -volatile bool reload; static int signal_pipe_write_fd; @@ -73,7 +72,10 @@ static void catchSignals(waybar::SafeSignal &signal_handler) { } // Must be called on the main thread. -static void handleSignalMainThread(int signum) { +// +// If this signal should restart or close the bar, this function will write +// `true` or `false`, respectively, into `reload`. +static void handleSignalMainThread(int signum, bool &reload) { if (signum >= SIGRTMIN + 1 && signum <= SIGRTMAX) { for (auto& bar : waybar::Client::inst()->bars) { bar->handleSignal(signum); @@ -122,9 +124,11 @@ int main(int argc, char* argv[]) { try { auto* client = waybar::Client::inst(); + bool reload; + waybar::SafeSignal posix_signal_received; posix_signal_received.connect([&](int signum) { - handleSignalMainThread(signum); + handleSignalMainThread(signum, reload); }); std::thread signal_thread([&]() { From 517eb7651e3ea6c7d731e7d9e21d216350d39150 Mon Sep 17 00:00:00 2001 From: literallyvoid Date: Mon, 14 Apr 2025 12:30:08 -0700 Subject: [PATCH 030/104] Run `clang-format` on main.cpp --- src/main.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ce493ca1..6e7650a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ static void writeSignalToPipe(int signum) { // There's not much we can safely do inside of a signal handler. // Let's just ignore any errors. - (void) amt; + (void)amt; } // This initializes `signal_pipe_write_fd`, and sets up signal handlers. @@ -30,7 +30,7 @@ static void writeSignalToPipe(int signum) { // This function will run forever, emitting every `SIGUSR1`, `SIGUSR2`, // `SIGINT`, `SIGCHLD`, and `SIGRTMIN + 1`...`SIGRTMAX` signal received // to `signal_handler`. -static void catchSignals(waybar::SafeSignal &signal_handler) { +static void catchSignals(waybar::SafeSignal& signal_handler) { int fd[2]; pipe(fd); @@ -72,10 +72,10 @@ static void catchSignals(waybar::SafeSignal &signal_handler) { } // Must be called on the main thread. -// +// // If this signal should restart or close the bar, this function will write // `true` or `false`, respectively, into `reload`. -static void handleSignalMainThread(int signum, bool &reload) { +static void handleSignalMainThread(int signum, bool& reload) { if (signum >= SIGRTMIN + 1 && signum <= SIGRTMAX) { for (auto& bar : waybar::Client::inst()->bars) { bar->handleSignal(signum); @@ -114,7 +114,7 @@ static void handleSignalMainThread(int signum, bool &reload) { reap_mtx.unlock(); } break; - default: + default: spdlog::debug("Received signal with number {}, but not handling", signum); break; } @@ -127,13 +127,9 @@ int main(int argc, char* argv[]) { bool reload; waybar::SafeSignal posix_signal_received; - posix_signal_received.connect([&](int signum) { - handleSignalMainThread(signum, reload); - }); + posix_signal_received.connect([&](int signum) { handleSignalMainThread(signum, reload); }); - std::thread signal_thread([&]() { - catchSignals(posix_signal_received); - }); + std::thread signal_thread([&]() { catchSignals(posix_signal_received); }); // Every `std::thread` must be joined or detached. // This thread should run forever, so detach it. From 45ebf4534316c75c318aece87440e46d8ef1b21f Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 20 Sep 2024 17:40:43 +0200 Subject: [PATCH 031/104] Start GPS module --- include/modules/gps.hpp | 31 ++++++++++++ man/waybar-gps.5.scd | 41 ++++++++++++++++ meson.build | 10 +++- meson_options.txt | 1 + src/factory.cpp | 8 ++++ src/modules/gps.cpp | 101 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 include/modules/gps.hpp create mode 100644 man/waybar-gps.5.scd create mode 100644 src/modules/gps.cpp diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp new file mode 100644 index 00000000..20bf02e4 --- /dev/null +++ b/include/modules/gps.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +#include +#include + +#include "ALabel.hpp" +#include "util/format.hpp" +#include "util/sleeper_thread.hpp" + +namespace waybar::modules { + + class Gps : public ALabel { + public: + Gps(const std::string&, const Json::Value&); + virtual ~Gps(); + auto update() -> void override; + + private: + const int getFixState() const; + const std::string getFixStateName() const; + const std::string getFixStateString() const; + + util::SleeperThread thread_; + gps_data_t gps_data_; + std::string state_; + }; + +} // namespace waybar::modules diff --git a/man/waybar-gps.5.scd b/man/waybar-gps.5.scd new file mode 100644 index 00000000..dfa91c27 --- /dev/null +++ b/man/waybar-gps.5.scd @@ -0,0 +1,41 @@ +waybar-gps(5) "waybar-gps" "User Manual" + +# NAME + +waybar - gps module + +# DESCRIPTION + +*gps* module for gpsd. + + +# FILES + +$XDG_CONFIG_HOME/waybar/config ++ + Per user configuration file + +# ADDITIONAL FILES + +libgps lives in: + +. /usr/lib/libgps.so or /usr/lib64/libgps.so +. /usr/lib/pkgconfig/libgps.pc or /usr/lib64/pkgconfig/libgps.pc +. /usr/include/gps + +# CONFIGURATION + + + +# EXAMPLES + +``` +"gps": { + +}, +``` +# STYLE + +- *#gps* +- *#gps.fix-none* Applied when GPS is present, but there is no fix. +- *#gps.fix-2d* Applied when there is a 2D fix. +- *#gps.fix-3d* Applied when there is a 3D fix. diff --git a/meson.build b/meson.build index 7f9854d5..a9d6b6e1 100644 --- a/meson.build +++ b/meson.build @@ -93,6 +93,7 @@ libmpdclient = dependency('libmpdclient', required: get_option('mpd')) xkbregistry = dependency('xkbregistry') libjack = dependency('jack', required: get_option('jack')) libwireplumber = dependency('wireplumber-0.5', required: get_option('wireplumber')) +libgps = dependency('libgps', required: get_option('gps')) libsndio = compiler.find_library('sndio', required: get_option('sndio')) if libsndio.found() @@ -497,6 +498,12 @@ if cava.found() man_files += files('man/waybar-cava.5.scd') endif +if libgps.found() + add_project_arguments('-DHAVE_LIBGPS', language: 'cpp') + src_files += files('src/modules/gps.cpp') + man_files += files('man/waybar-gps.5.scd') +endif + subdir('protocol') app_resources = [] @@ -535,7 +542,8 @@ executable( libsndio, tz_dep, xkbregistry, - cava + cava, + libgps ], include_directories: inc_dirs, install: true, diff --git a/meson_options.txt b/meson_options.txt index d83fe01f..c0f63f28 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -21,3 +21,4 @@ option('wireplumber', type: 'feature', value: 'auto', description: 'Enable suppo option('cava', type: 'feature', value: 'auto', description: 'Enable support for Cava') option('niri', type: 'boolean', description: 'Enable support for niri') option('login-proxy', type: 'boolean', description: 'Enable interfacing with dbus login interface') +option('gps', type: 'feature', value: 'auto', description: 'Enable support for gps') diff --git a/src/factory.cpp b/src/factory.cpp index 1483397d..cfc12fbe 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -109,6 +109,9 @@ #ifdef HAVE_SYSTEMD_MONITOR #include "modules/systemd_failed_units.hpp" #endif +#ifdef HAVE_LIBGPS +#include "modules/gps.hpp" +#endif #include "modules/cffi.hpp" #include "modules/custom.hpp" #include "modules/image.hpp" @@ -331,6 +334,11 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, if (ref == "systemd-failed-units") { return new waybar::modules::SystemdFailedUnits(id, config_[name]); } +#endif +#ifdef HAVE_LIBCAVA + if (ref == "gps") { + return new waybar::modules::Gps(id, config_[name]); + } #endif if (ref == "temperature") { return new waybar::modules::Temperature(id, config_[name]); diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp new file mode 100644 index 00000000..52217e0a --- /dev/null +++ b/src/modules/gps.cpp @@ -0,0 +1,101 @@ +#include "modules/gps.hpp" + +#include + +// In the 80000 version of fmt library authors decided to optimize imports +// and moved declarations required for fmt::dynamic_format_arg_store in new +// header fmt/args.h +#if (FMT_VERSION >= 80000) +#include +#else +#include +#endif + +namespace { + using namespace waybar::util; + constexpr const char *DEFAULT_FORMAT = "{status}"; +} // namespace + + +waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) +: ALabel(config, "gps", id, "{}", 30) { + thread_ = [this] { + dp.emit(); + thread_.sleep_for(interval_); + }; + // TODO: connect to gpsd socket + + if (0 != gps_open("localhost", "2947", &gps_data_)) { + throw std::runtime_error("Can't open gpsd socket"); + } + +} + +const int waybar::modules::Gps::getFixState() const { +0 +} + +const std::string waybar::modules::Gps::getFixStateName() const { + switch (getFixState()) { + case 1: + return "fix-2d"; + case 2: + return "fix-3d"; + default: + return "fix-none"; + } +} + +const std::string waybar::modules::Gps::getFixStateString() const { + switch (getFixState()) { + case 1: + return "2D Fix"; + case 2: + return "3D Fix"; + default: + return "No fix"; + } +} + +auto waybar::modules::Gps::update() -> void { + + std::string tooltip_format; + + if (!alt_) { + auto state = getFixStateName(); + if (!state_.empty() && label_.get_style_context()->has_class(state_)) { + label_.get_style_context()->remove_class(state_); + } + if (config_["format-" + state].isString()) { + default_format_ = config_["format-" + state].asString(); + } else if (config_["format"].isString()) { + default_format_ = config_["format"].asString(); + } else { + default_format_ = DEFAULT_FORMAT; + } + if (config_["tooltip-format-" + state].isString()) { + tooltip_format = config_["tooltip-format-" + state].asString(); + } + if (!label_.get_style_context()->has_class(state)) { + label_.get_style_context()->add_class(state); + } + format_ = default_format_; + state_ = state; + } + + + auto format = format_; + + fmt::dynamic_format_arg_store store; + store.push_back(fmt::arg("status", getFixStateString())); + + label_.set_markup(fmt::vformat(format, store)); +// Call parent update +ALabel::update(); +} + +waybar::modules::Gps::~Gps() { + gps_close(&gps_data_); +} + + From dfa40d6a00439c0d3cf57dba51ca5b30bb4d01dc Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 20 Sep 2024 19:05:26 +0200 Subject: [PATCH 032/104] add all arguments --- include/modules/gps.hpp | 7 +-- src/modules/gps.cpp | 106 ++++++++++++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 23 deletions(-) diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index 20bf02e4..a3335a10 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -19,9 +19,10 @@ namespace waybar::modules { auto update() -> void override; private: - const int getFixState() const; - const std::string getFixStateName() const; - const std::string getFixStateString() const; + const std::string getFixModeName() const; + const std::string getFixModeString() const; + + const std::string getFixStatusString() const; util::SleeperThread thread_; gps_data_t gps_data_; diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index 52217e0a..e2367c41 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -1,6 +1,8 @@ #include "modules/gps.hpp" +#include #include +#include // In the 80000 version of fmt library authors decided to optimize imports // and moved declarations required for fmt::dynamic_format_arg_store in new @@ -13,56 +15,84 @@ namespace { using namespace waybar::util; - constexpr const char *DEFAULT_FORMAT = "{status}"; + constexpr const char *DEFAULT_FORMAT = "{mode}"; } // namespace waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) -: ALabel(config, "gps", id, "{}", 30) { +: ALabel(config, "gps", id, "{}", 1) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); }; - // TODO: connect to gpsd socket if (0 != gps_open("localhost", "2947", &gps_data_)) { throw std::runtime_error("Can't open gpsd socket"); } + gps_stream(&gps_data_, WATCH_ENABLE, NULL); } -const int waybar::modules::Gps::getFixState() const { -0 -} - -const std::string waybar::modules::Gps::getFixStateName() const { - switch (getFixState()) { - case 1: +const std::string waybar::modules::Gps::getFixModeName() const { + switch (gps_data_.fix.mode) { + case MODE_NO_FIX: + return "fix-none"; + case MODE_2D: return "fix-2d"; - case 2: + case MODE_3D: return "fix-3d"; default: - return "fix-none"; + return "disconnected"; } } -const std::string waybar::modules::Gps::getFixStateString() const { - switch (getFixState()) { - case 1: +const std::string waybar::modules::Gps::getFixModeString() const { + switch (gps_data_.fix.mode) { + case MODE_NO_FIX: + return "No fix"; + case MODE_2D: return "2D Fix"; - case 2: + case MODE_3D: return "3D Fix"; default: - return "No fix"; + return "Disconnected"; + } +} + +const std::string waybar::modules::Gps::getFixStatusString() const { + switch (gps_data_.fix.status) { + case STATUS_UNK: + return "Unknown"; + case STATUS_GPS: + return "GPS"; + case STATUS_DGPS: + return "DGPS"; + case STATUS_RTK_FIX: + return "RTK Fixed"; + case STATUS_RTK_FLT: + return "RTK Float"; + case STATUS_DR: + return "Dead Reckoning"; + case STATUS_GNSSDR: + return "GNSS + Dead Reckoning"; + case STATUS_TIME: + return "Time Only"; + case STATUS_PPS_FIX: + return "PPS Fix"; + default: + return "Unknown"; } } auto waybar::modules::Gps::update() -> void { + if (gps_read(&gps_data_, NULL, 0) == -1) { + throw std::runtime_error("Can't read data from gpsd."); + } std::string tooltip_format; if (!alt_) { - auto state = getFixStateName(); + auto state = getFixModeName(); if (!state_.empty() && label_.get_style_context()->has_class(state_)) { label_.get_style_context()->remove_class(state_); } @@ -87,14 +117,50 @@ auto waybar::modules::Gps::update() -> void { auto format = format_; fmt::dynamic_format_arg_store store; - store.push_back(fmt::arg("status", getFixStateString())); + store.push_back(fmt::arg("mode", getFixModeString())); + store.push_back(fmt::arg("status", getFixStatusString())); - label_.set_markup(fmt::vformat(format, store)); + store.push_back(fmt::arg("latitude", gps_data_.fix.latitude)); + store.push_back(fmt::arg("latitude_error", gps_data_.fix.epy)); + + store.push_back(fmt::arg("longitude", gps_data_.fix.longitude)); + store.push_back(fmt::arg("longitude_error", gps_data_.fix.epx)); + + store.push_back(fmt::arg("altitude_hae", gps_data_.fix.altHAE)); + store.push_back(fmt::arg("altitude_msl", gps_data_.fix.altMSL)); + store.push_back(fmt::arg("altitude_error", gps_data_.fix.epv)); + + store.push_back(fmt::arg("speed", gps_data_.fix.speed)); + store.push_back(fmt::arg("speed_error", gps_data_.fix.eps)); + + store.push_back(fmt::arg("climb", gps_data_.fix.climb)); + store.push_back(fmt::arg("climb_error", gps_data_.fix.epc)); + + store.push_back(fmt::arg("satellites_used", gps_data_.satellites_used)); + store.push_back(fmt::arg("satellites_visible", gps_data_.satellites_visible)); + + auto text = fmt::vformat(format, store); + + if (tooltipEnabled()) { + if (tooltip_format.empty() && config_["tooltip-format"].isString()) { + tooltip_format = config_["tooltip-format"].asString(); + } + if (!tooltip_format.empty()) { + auto tooltip_text = fmt::vformat(tooltip_format, store); + if (label_.get_tooltip_text() != tooltip_text) { + label_.set_tooltip_markup(tooltip_text); + } + } else if (label_.get_tooltip_text() != text) { + label_.set_tooltip_markup(text); + } + } + label_.set_markup(text); // Call parent update ALabel::update(); } waybar::modules::Gps::~Gps() { + gps_stream(&gps_data_, WATCH_DISABLE, NULL); gps_close(&gps_data_); } From d331331b76a6ff0e45a371a0ff29d7931e11fada Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 20 Sep 2024 19:56:16 +0200 Subject: [PATCH 033/104] add manpage --- include/modules/gps.hpp | 3 ++ man/waybar-gps.5.scd | 71 +++++++++++++++++++++++++++++++++++++++-- src/modules/gps.cpp | 18 ++++++++++- 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index a3335a10..6c2e980e 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -27,6 +27,9 @@ namespace waybar::modules { util::SleeperThread thread_; gps_data_t gps_data_; std::string state_; + + bool hideDisconnected = true; + bool hideNoFix = false; }; } // namespace waybar::modules diff --git a/man/waybar-gps.5.scd b/man/waybar-gps.5.scd index dfa91c27..cf5faf42 100644 --- a/man/waybar-gps.5.scd +++ b/man/waybar-gps.5.scd @@ -24,14 +24,81 @@ libgps lives in: # CONFIGURATION +*format*: ++ + typeof: string ++ + default: {glyph} ++ + The text format. +*tooltip*: ++ + typeof: bool ++ + default: true ++ + Option to disable tooltip on hover. + +*tooltip-format*: ++ + typeof: string ++ + default: Games running: {glyph} ++ + The text format of the tooltip. + +*interval*: ++ + typeof: integer ++ + default: 5 ++ + The interval in which the GPS information gets polled (e.g. fix status). + +*hide-disconnected*: ++ + typeof: bool ++ + default: true ++ + Defines if the module should be hidden if there is no GPS receiver. + +*hide-no-fix*: ++ + typeof: bool ++ + default: false ++ + Defines if the module should be hidden if there is no GPS fix. + +# FORMAT REPLACEMENTS + +*{mode}*: Fix mode + +*{status}*: Technology used for GPS fix. Not all GPS receivers report this. + +*{latitude}*: Latitude, decimal degrees. Can be NaN. + +*{latitude_error}*: Latitude uncertainty, meters. Can be NaN. + +*{longitude}*: Longitude, decimal degrees. Can be NaN. + +*{longitude_error}*: Longitude uncertainty, meters. Can be NaN. + +*{altitude_hae}*: Altitude, height above ellipsoid, meters. Can be NaN. + +*{altitude_msl}*: Longitude, MSL, meters. Can be NaN. + +*{altitude_error}*: Altitude uncertainty, meters. Can be NaN. + +*{speed}*: Speed over ground, meters/sec. Can be NaN. + +*{speed_error}*: Speed uncertainty, meters/sec. Can be NaN. + +*{climb}*: Vertical speed, meters/sec. Can be NaN. + +*{climb_error}*: Vertical speed uncertainty, meters/sec. Can be NaN. + +*{satellites_visible}*: Number of satellites visible from the GPS receiver. + +*{satellites_used}*: Number of satellites used for the GPS fix. # EXAMPLES ``` "gps": { - -}, + "format": "{mode}", + "format-no-fix": "No fix", + "format-fix-3d": "{status}", + "tooltip-format": "{mode}", + "tooltip-format-no-fix": "{satellites_visible} satellites visible", + "tooltip-format-fix-2d": "{satellites_used}/{satellites_visible} satellites used", + "tooltip-format-fix-3d": "Altitude: {altitude_hae}m", + "hide-disconnected": false +} ``` # STYLE diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index e2367c41..12e01ac4 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -20,7 +20,7 @@ namespace { waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) -: ALabel(config, "gps", id, "{}", 1) { +: ALabel(config, "gps", id, "{}", 5) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); @@ -30,6 +30,14 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) throw std::runtime_error("Can't open gpsd socket"); } + if (config_["hide-disconnected"].isBool()) { + hideDisconnected = config_["hide-disconnected"].asBool(); + } + + if (config_["hide-no-fix"].isBool()) { + hideNoFix = config_["hide-no-fix"].asBool(); + } + gps_stream(&gps_data_, WATCH_ENABLE, NULL); } @@ -89,6 +97,14 @@ auto waybar::modules::Gps::update() -> void { throw std::runtime_error("Can't read data from gpsd."); } + if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) { + event_box_.set_visible(false); + return; + } + + // Show the module + if (!event_box_.get_visible()) event_box_.set_visible(true); + std::string tooltip_format; if (!alt_) { From 22ec8e077036b69ba691537acb1d330d85358be0 Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 8 Nov 2024 16:38:51 +0100 Subject: [PATCH 034/104] fix factory copy&paste typo --- src/factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factory.cpp b/src/factory.cpp index cfc12fbe..11ca14fd 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -335,7 +335,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, return new waybar::modules::SystemdFailedUnits(id, config_[name]); } #endif -#ifdef HAVE_LIBCAVA +#ifdef HAVE_LIBGPS if (ref == "gps") { return new waybar::modules::Gps(id, config_[name]); } From 956e39d3d3eedd287b14aa82fbc6313246a64b9e Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 8 Nov 2024 23:40:12 +0100 Subject: [PATCH 035/104] make gpsd receiver not poll --- include/modules/gps.hpp | 2 +- man/waybar-gps.5.scd | 3 ++- src/modules/gps.cpp | 28 ++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index 6c2e980e..500614a4 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -24,7 +24,7 @@ namespace waybar::modules { const std::string getFixStatusString() const; - util::SleeperThread thread_; + util::SleeperThread thread_, gps_thread_; gps_data_t gps_data_; std::string state_; diff --git a/man/waybar-gps.5.scd b/man/waybar-gps.5.scd index cf5faf42..3b2c2cac 100644 --- a/man/waybar-gps.5.scd +++ b/man/waybar-gps.5.scd @@ -42,7 +42,8 @@ libgps lives in: *interval*: ++ typeof: integer ++ default: 5 ++ - The interval in which the GPS information gets polled (e.g. fix status). + The interval in which the GPS information gets polled (e.g. current speed). + Significant updates (e.g. the current fix mode) are updated immediately. *hide-disconnected*: ++ typeof: bool ++ diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index 12e01ac4..85726876 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -1,4 +1,5 @@ #include "modules/gps.hpp" +#include #include #include @@ -38,7 +39,28 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) hideNoFix = config_["hide-no-fix"].asBool(); } - gps_stream(&gps_data_, WATCH_ENABLE, NULL); + gps_thread_ = [this] { + dp.emit(); + gps_stream(&gps_data_, WATCH_ENABLE, NULL); + int last_gps_mode = 0; + + while (gps_waiting(&gps_data_, 5000000)) { + if (gps_read(&gps_data_, NULL, 0) == -1) { + throw std::runtime_error("Can't read data from gpsd."); + } + + if (MODE_SET != (MODE_SET & gps_data_.set)) { + // did not even get mode, nothing to see here + continue; + } + + if (gps_data_.fix.mode != last_gps_mode) { + // significant update + dp.emit(); + } + last_gps_mode = gps_data_.fix.mode; + } + }; } const std::string waybar::modules::Gps::getFixModeName() const { @@ -93,9 +115,7 @@ const std::string waybar::modules::Gps::getFixStatusString() const { } auto waybar::modules::Gps::update() -> void { - if (gps_read(&gps_data_, NULL, 0) == -1) { - throw std::runtime_error("Can't read data from gpsd."); - } + sleep(0); // Wait for gps status change if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) { event_box_.set_visible(false); From d0c6e9109449851b1eb082c00254b6aa6dbf87fc Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 9 Nov 2024 11:58:08 +0100 Subject: [PATCH 036/104] gps: add rfkill support --- include/modules/gps.hpp | 9 +++++++-- man/waybar-gps.5.scd | 2 ++ src/modules/gps.cpp | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index 500614a4..3701634b 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -3,11 +3,13 @@ #include #include -#include +#ifdef WANT_RFKILL +#include "util/rfkill.hpp" +#endif + #include #include "ALabel.hpp" -#include "util/format.hpp" #include "util/sleeper_thread.hpp" namespace waybar::modules { @@ -19,6 +21,9 @@ namespace waybar::modules { auto update() -> void override; private: + #ifdef WANT_RFKILL + util::Rfkill rfkill_; + #endif const std::string getFixModeName() const; const std::string getFixModeString() const; diff --git a/man/waybar-gps.5.scd b/man/waybar-gps.5.scd index 3b2c2cac..e7473601 100644 --- a/man/waybar-gps.5.scd +++ b/man/waybar-gps.5.scd @@ -92,6 +92,7 @@ libgps lives in: ``` "gps": { "format": "{mode}", + "format-disabled": "", // an empty format will hide the module "format-no-fix": "No fix", "format-fix-3d": "{status}", "tooltip-format": "{mode}", @@ -104,6 +105,7 @@ libgps lives in: # STYLE - *#gps* +- *#gps.disabled* Applied when GPS is disabled. - *#gps.fix-none* Applied when GPS is present, but there is no fix. - *#gps.fix-2d* Applied when there is a 2D fix. - *#gps.fix-3d* Applied when there is a 3D fix. diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index 85726876..f075b44c 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -21,7 +21,11 @@ namespace { waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) -: ALabel(config, "gps", id, "{}", 5) { +: ALabel(config, "gps", id, "{}", 5) +#ifdef WANT_RFKILL +,rfkill_{RFKILL_TYPE_GPS} +#endif +{ thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); @@ -61,6 +65,10 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) last_gps_mode = gps_data_.fix.mode; } }; + + #ifdef WANT_RFKILL + rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Gps::update))); + #endif } const std::string waybar::modules::Gps::getFixModeName() const { @@ -72,6 +80,9 @@ const std::string waybar::modules::Gps::getFixModeName() const { case MODE_3D: return "fix-3d"; default: + #ifdef WANT_RFKILL + if (rfkill_.getState()) return "disabled"; + #endif return "disconnected"; } } @@ -91,8 +102,6 @@ const std::string waybar::modules::Gps::getFixModeString() const { const std::string waybar::modules::Gps::getFixStatusString() const { switch (gps_data_.fix.status) { - case STATUS_UNK: - return "Unknown"; case STATUS_GPS: return "GPS"; case STATUS_DGPS: @@ -110,6 +119,11 @@ const std::string waybar::modules::Gps::getFixStatusString() const { case STATUS_PPS_FIX: return "PPS Fix"; default: + + #ifdef WANT_RFKILL + if (rfkill_.getState()) return "Disabled"; + #endif + return "Unknown"; } } From 20642f47df9fbdd02fa869f83348c99e431a1092 Mon Sep 17 00:00:00 2001 From: Rimsoo <50300684+Rimsoo@users.noreply.github.com> Date: Tue, 22 Apr 2025 11:41:45 +0200 Subject: [PATCH 037/104] Fixed variant bug --- src/modules/hyprland/language.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index da56e578..2371a397 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -66,7 +66,7 @@ auto Language::update() -> void { void Language::onEvent(const std::string& ev) { std::lock_guard lg(mutex_); std::string kbName(begin(ev) + ev.find_last_of('>') + 1, begin(ev) + ev.find_first_of(',')); - auto layoutName = ev.substr(ev.find_last_of(',') + 1); + auto layoutName = ev.substr(ev.find_first_of(',') + 1); if (config_.isMember("keyboard-name") && kbName != config_["keyboard-name"].asString()) return; // ignore From afeea62214872689fa39068655c8c6ca663b78a5 Mon Sep 17 00:00:00 2001 From: Rimsoo <50300684+Rimsoo@users.noreply.github.com> Date: Thu, 24 Apr 2025 23:32:47 +0200 Subject: [PATCH 038/104] fixes #3676 including #3224 --- src/modules/hyprland/language.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 2371a397..1dbdfeba 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -66,7 +66,11 @@ auto Language::update() -> void { void Language::onEvent(const std::string& ev) { std::lock_guard lg(mutex_); std::string kbName(begin(ev) + ev.find_last_of('>') + 1, begin(ev) + ev.find_first_of(',')); - auto layoutName = ev.substr(ev.find_first_of(',') + 1); + + // Last comma before variants parenthesis, eg: + // activelayout>>micro-star-int'l-co.,-ltd.-msi-gk50-elite-gaming-keyboard,English (US, intl., with dead keys) + std::string beforParenthesis(begin(ev), begin(ev) + ev.find_last_of('(')); + auto layoutName = ev.substr(beforParenthesis.find_last_of(',') + 1); if (config_.isMember("keyboard-name") && kbName != config_["keyboard-name"].asString()) return; // ignore From 72184b2205355452037725c96a6f7ce681635af2 Mon Sep 17 00:00:00 2001 From: "Rene D. Obermueller" Date: Fri, 2 May 2025 09:53:11 +0200 Subject: [PATCH 039/104] Issue 3981: try and fix memory leak --- src/modules/privacy/privacy_item.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/privacy/privacy_item.cpp b/src/modules/privacy/privacy_item.cpp index 54e61b43..36efd3e5 100644 --- a/src/modules/privacy/privacy_item.cpp +++ b/src/modules/privacy/privacy_item.cpp @@ -1,5 +1,7 @@ #include "modules/privacy/privacy_item.hpp" +#include + #include #include "glibmm/main.h" @@ -94,22 +96,22 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac } void PrivacyItem::update_tooltip() { + spdlog::trace("update privacy tooltip"); // Removes all old nodes for (auto *child : tooltip_window.get_children()) { - delete child; + tooltip_window.remove(*child); } - for (auto *node : *nodes) { Gtk::Box *box = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 4); // Set device icon - Gtk::Image *node_icon = new Gtk::Image(); + Gtk::Image *node_icon = Gtk::make_managed(); node_icon->set_pixel_size(tooltipIconSize); node_icon->set_from_icon_name(node->getIconName(), Gtk::ICON_SIZE_INVALID); box->add(*node_icon); // Set model - auto *nodeName = new Gtk::Label(node->getName()); + auto *nodeName = Gtk::make_managed(node->getName()); box->add(*nodeName); tooltip_window.add(*box); From ff4ed826931209ac333cb270f2463027718c668f Mon Sep 17 00:00:00 2001 From: "Rene D. Obermueller" Date: Sat, 3 May 2025 11:26:03 +0200 Subject: [PATCH 040/104] memory leak: 2nd attempt --- src/modules/privacy/privacy_item.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/privacy/privacy_item.cpp b/src/modules/privacy/privacy_item.cpp index 36efd3e5..536c9180 100644 --- a/src/modules/privacy/privacy_item.cpp +++ b/src/modules/privacy/privacy_item.cpp @@ -100,12 +100,15 @@ void PrivacyItem::update_tooltip() { // Removes all old nodes for (auto *child : tooltip_window.get_children()) { tooltip_window.remove(*child); + // despite the remove, still needs a delete to prevent memory leak. Speculating that this might + // work differently in GTK4. + delete child; } for (auto *node : *nodes) { - Gtk::Box *box = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 4); + auto *box = Gtk::make_managed(Gtk::ORIENTATION_HORIZONTAL, 4); // Set device icon - Gtk::Image *node_icon = Gtk::make_managed(); + auto *node_icon = Gtk::make_managed(); node_icon->set_pixel_size(tooltipIconSize); node_icon->set_from_icon_name(node->getIconName(), Gtk::ICON_SIZE_INVALID); box->add(*node_icon); From 9bf8c8277add598e62e7d16a8676505cfc09eab0 Mon Sep 17 00:00:00 2001 From: Fengerros <83514190+Fengerros@users.noreply.github.com> Date: Sat, 3 May 2025 15:52:05 +0200 Subject: [PATCH 041/104] Update mediaplayer.py - Fix artist name display in mediaplayer.py Fixed an issue where artist names like Earth, Wind & Fire were not displayed correctly. The change ensures that artist names containing commas or special characters are now shown properly. --- resources/custom_modules/mediaplayer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/custom_modules/mediaplayer.py b/resources/custom_modules/mediaplayer.py index d1bb72b4..524d4d2a 100755 --- a/resources/custom_modules/mediaplayer.py +++ b/resources/custom_modules/mediaplayer.py @@ -112,6 +112,7 @@ class PlayerManager: logger.debug(f"Metadata changed for player {player.props.player_name}") player_name = player.props.player_name artist = player.get_artist() + artist = artist.replace("&", "&") title = player.get_title() title = title.replace("&", "&") From 7b5206128ce7960791b97fe0212f5e95e8575a88 Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sat, 3 May 2025 10:41:07 -0700 Subject: [PATCH 042/104] Add idle_inhibitor style docs. --- man/waybar-idle-inhibitor.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 6d5a2170..405c8fc5 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -125,3 +125,9 @@ screensaver, also known as "presentation mode". "timeout": 30.5 } ``` + +# STYLE + +- *#idle_inhibitor* +- *#idle_inhibitor.activated* +- *#idle_inhibitor.deactivated* From f4b68f41e6d58e9659705d58d1fef7bd154ada38 Mon Sep 17 00:00:00 2001 From: "Rene D. Obermueller" Date: Sun, 4 May 2025 07:26:55 +0200 Subject: [PATCH 043/104] feat: sway/window: provide {marks} format replacement --- include/modules/sway/window.hpp | 6 ++-- man/waybar-sway-window.5.scd | 7 ++++ src/modules/sway/window.cpp | 57 ++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index 427c2e81..60cd2679 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -19,10 +19,11 @@ class Window : public AAppIconLabel, public sigc::trackable { auto update() -> void override; private: - void setClass(std::string classname, bool enable); + void setClass(const std::string& classname, bool enable); void onEvent(const struct Ipc::ipc_response&); void onCmd(const struct Ipc::ipc_response&); - std::tuple + std::tuple getFocusedNode(const Json::Value& nodes, std::string& output); void getTree(); @@ -35,6 +36,7 @@ class Window : public AAppIconLabel, public sigc::trackable { std::string old_app_id_; std::size_t app_nb_; std::string shell_; + std::string marks_; int floating_count_; util::JsonParser parser_; std::mutex mutex_; diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index a7eb4f05..6fa9170b 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -89,6 +89,11 @@ Addressed by *sway/window* default: false ++ If the workspace itself is focused and the workspace contains nodes or floating_nodes, show the workspace name. If not set, text remains empty but styles according to nodes in the workspace are still applied. +*show-hidden-marks*: ++ + typeof: bool ++ + default: false ++ + For the *{marks}* format replacement, include hidden marks that start with an underscore. + *rewrite*: ++ typeof: object ++ Rules to rewrite the module format output. See *rewrite rules*. @@ -117,6 +122,8 @@ Addressed by *sway/window* *{shell}*: The shell of the focused window. It's 'xwayland' when the window is running through xwayland, otherwise, it's 'xdg-shell'. +*{marks}*: Marks of the window. + # REWRITE RULES *rewrite* is an object where keys are regular expressions and values are diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 25e430a7..68655a76 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -41,8 +41,8 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { std::lock_guard lock(mutex_); auto payload = parser_.parse(res.payload); auto output = payload["output"].isString() ? payload["output"].asString() : ""; - std::tie(app_nb_, floating_count_, windowId_, window_, app_id_, app_class_, shell_, layout_) = - getFocusedNode(payload["nodes"], output); + std::tie(app_nb_, floating_count_, windowId_, window_, app_id_, app_class_, shell_, layout_, + marks_) = getFocusedNode(payload["nodes"], output); updateAppIconName(app_id_, app_class_); dp.emit(); } catch (const std::exception& e) { @@ -96,7 +96,7 @@ auto Window::update() -> void { label_.set_markup(waybar::util::rewriteString( fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_), - fmt::arg("shell", shell_)), + fmt::arg("shell", shell_), fmt::arg("marks", marks_)), config_["rewrite"])); if (tooltipEnabled()) { label_.set_tooltip_text(window_); @@ -108,7 +108,7 @@ auto Window::update() -> void { AAppIconLabel::update(); } -void Window::setClass(std::string classname, bool enable) { +void Window::setClass(const std::string& classname, bool enable) { if (enable) { if (!bar_.window.get_style_context()->has_class(classname)) { bar_.window.get_style_context()->add_class(classname); @@ -169,17 +169,31 @@ std::optional> getSingleChildNode( return {getSingleChildNode(child)}; } -std::tuple getWindowInfo(const Json::Value& node) { +std::tuple getWindowInfo( + const Json::Value& node, bool showHidden) { const auto app_id = node["app_id"].isString() ? node["app_id"].asString() : node["window_properties"]["instance"].asString(); const auto app_class = node["window_properties"]["class"].isString() ? node["window_properties"]["class"].asString() : ""; const auto shell = node["shell"].isString() ? node["shell"].asString() : ""; - return {app_id, app_class, shell}; + std::string marks = ""; + if (node["marks"].isArray()) { + for (const auto& m : node["marks"]) { + if (!m.isString() || (!showHidden && m.asString().at(0) == '_')) { + continue; + } + if (!marks.empty()) { + marks += ','; + } + marks += m.asString(); + } + } + return {app_id, app_class, shell, marks}; } -std::tuple +std::tuple gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Value& config_, const Bar& bar_, Json::Value& parentWorkspace, const Json::Value& immediateParent) { @@ -207,7 +221,8 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu "", "", "", - node["layout"].asString()}; + node["layout"].asString(), + ""}; } parentWorkspace = node; } else if ((node["type"].asString() == "con" || node["type"].asString() == "floating_con") && @@ -215,7 +230,8 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu // found node spdlog::trace("actual output {}, output found {}, node (focused) found {}", bar_.output->name, output, node["name"].asString()); - const auto [app_id, app_class, shell] = getWindowInfo(node); + const auto [app_id, app_class, shell, marks] = + getWindowInfo(node, config_["show-hidden-marks"].asBool()); int nb = node.size(); int floating_count = 0; std::string workspace_layout = ""; @@ -232,20 +248,21 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu app_id, app_class, shell, - workspace_layout}; + workspace_layout, + marks}; } // iterate - auto [nb, f, id, name, app_id, app_class, shell, workspace_layout] = + auto [nb, f, id, name, app_id, app_class, shell, workspace_layout, marks] = gfnWithWorkspace(node["nodes"], output, config_, bar_, parentWorkspace, node); - auto [nb2, f2, id2, name2, app_id2, app_class2, shell2, workspace_layout2] = + auto [nb2, f2, id2, name2, app_id2, app_class2, shell2, workspace_layout2, marks2] = gfnWithWorkspace(node["floating_nodes"], output, config_, bar_, parentWorkspace, node); // if ((id > 0 || ((id2 < 0 || name2.empty()) && id > -1)) && !name.empty()) { if ((id > 0) || (id2 < 0 && id > -1)) { - return {nb, f, id, name, app_id, app_class, shell, workspace_layout}; + return {nb, f, id, name, app_id, app_class, shell, workspace_layout, marks}; } else if (id2 > 0 && !name2.empty()) { - return {nb2, f2, id2, name2, app_id2, app_class, shell2, workspace_layout2}; + return {nb2, f2, id2, name2, app_id2, app_class, shell2, workspace_layout2, marks2}; } } @@ -258,10 +275,12 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu std::string app_id = ""; std::string app_class = ""; std::string workspace_layout = ""; + std::string marks = ""; if (all_leaf_nodes.first == 1) { const auto single_child = getSingleChildNode(immediateParent); if (single_child.has_value()) { - std::tie(app_id, app_class, workspace_layout) = getWindowInfo(single_child.value()); + std::tie(app_id, app_class, workspace_layout, marks) = + getWindowInfo(single_child.value(), config_["show-hidden-marks"].asBool()); } } return {all_leaf_nodes.first, @@ -273,13 +292,15 @@ gfnWithWorkspace(const Json::Value& nodes, std::string& output, const Json::Valu app_id, app_class, workspace_layout, - immediateParent["layout"].asString()}; + immediateParent["layout"].asString(), + marks}; } - return {0, 0, -1, "", "", "", "", ""}; + return {0, 0, -1, "", "", "", "", "", ""}; } -std::tuple +std::tuple Window::getFocusedNode(const Json::Value& nodes, std::string& output) { Json::Value placeholder = Json::Value::null; return gfnWithWorkspace(nodes, output, config_, bar_, placeholder, placeholder); From 0340760e12829239078c0d21fa6d227561e30ff2 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 7 May 2025 16:57:54 +0800 Subject: [PATCH 044/104] Use load_symbolic for gtk icon instead of load_icon. --- include/util/gtk_icon.hpp | 4 +++- src/modules/sni/item.cpp | 15 +++++++++------ src/util/gtk_icon.cpp | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/util/gtk_icon.hpp b/include/util/gtk_icon.hpp index 44555f65..06f15abe 100644 --- a/include/util/gtk_icon.hpp +++ b/include/util/gtk_icon.hpp @@ -10,5 +10,7 @@ class DefaultGtkIconThemeWrapper { public: static bool has_icon(const std::string&); - static Glib::RefPtr load_icon(const char*, int, Gtk::IconLookupFlags); + static Glib::RefPtr load_icon( + const char*, int, Gtk::IconLookupFlags, + Glib::RefPtr style = Glib::RefPtr()); }; diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 9dc13158..407d7e72 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -388,14 +388,17 @@ Glib::RefPtr Item::getIconPixbuf() { Glib::RefPtr Item::getIconByName(const std::string& name, int request_size) { icon_theme->rescan_if_needed(); - if (!icon_theme_path.empty() && - icon_theme->lookup_icon(name.c_str(), request_size, - Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE)) { - return icon_theme->load_icon(name.c_str(), request_size, - Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + if (!icon_theme_path.empty()) { + auto icon_info = icon_theme->lookup_icon(name.c_str(), request_size, + Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + if (icon_info) { + bool is_sym = false; + return icon_info.load_symbolic(event_box.get_style_context(), is_sym); + } } return DefaultGtkIconThemeWrapper::load_icon(name.c_str(), request_size, - Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); + Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE, + event_box.get_style_context()); } double Item::getScaledIconSize() { diff --git a/src/util/gtk_icon.cpp b/src/util/gtk_icon.cpp index 5dd741f9..4b4d3d69 100644 --- a/src/util/gtk_icon.cpp +++ b/src/util/gtk_icon.cpp @@ -15,11 +15,20 @@ bool DefaultGtkIconThemeWrapper::has_icon(const std::string& value) { return Gtk::IconTheme::get_default()->has_icon(value); } -Glib::RefPtr DefaultGtkIconThemeWrapper::load_icon(const char* name, int tmp_size, - Gtk::IconLookupFlags flags) { +Glib::RefPtr DefaultGtkIconThemeWrapper::load_icon( + const char* name, int tmp_size, Gtk::IconLookupFlags flags, + Glib::RefPtr style) { const std::lock_guard lock(default_theme_mutex); auto default_theme = Gtk::IconTheme::get_default(); default_theme->rescan_if_needed(); - return default_theme->load_icon(name, tmp_size, flags); + + auto icon_info = default_theme->lookup_icon(name, tmp_size, flags); + + if (style.get() == nullptr) { + return icon_info.load_icon(); + } + + bool is_sym = false; + return icon_info.load_symbolic(style, is_sym); } From 47e0f4252338cd51544a6229a495c24c35b442cf Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Tue, 13 May 2025 21:34:24 +0200 Subject: [PATCH 045/104] niri: add support for urgency indicators to workspaces --- man/waybar-niri-workspaces.5.scd | 2 ++ src/modules/niri/backend.cpp | 11 +++++++++++ src/modules/niri/workspaces.cpp | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/man/waybar-niri-workspaces.5.scd b/man/waybar-niri-workspaces.5.scd index 0c0249ca..3afd1172 100644 --- a/man/waybar-niri-workspaces.5.scd +++ b/man/waybar-niri-workspaces.5.scd @@ -70,6 +70,7 @@ Additional to workspace name matching, the following *format-icons* can be set. - *default*: Will be shown, when no string matches are found. - *focused*: Will be shown, when workspace is focused. - *active*: Will be shown, when workspace is active on its output. +- *urgent*: Will be shown, when workspace has urgent windows. # EXAMPLES @@ -95,6 +96,7 @@ Additional to workspace name matching, the following *format-icons* can be set. - *#workspaces button* - *#workspaces button.focused*: The single focused workspace. - *#workspaces button.active*: The workspace is active (visible) on its output. +- *#workspaces button.urgent*: The workspace has one or more urgent windows. - *#workspaces button.empty*: The workspace is empty. - *#workspaces button.current_output*: The workspace is from the same output as the bar that it is displayed on. diff --git a/src/modules/niri/backend.cpp b/src/modules/niri/backend.cpp index 383bf113..fa4dc287 100644 --- a/src/modules/niri/backend.cpp +++ b/src/modules/niri/backend.cpp @@ -147,6 +147,17 @@ void IPC::parseIPC(const std::string &line) { } else { spdlog::error("Active window changed on unknown workspace"); } + } else if (const auto &payload = ev["WorkspaceUrgencyChanged"]) { + const auto id = payload["id"].asUInt64(); + const auto urgent = payload["urgent"].asBool(); + auto it = std::find_if(workspaces_.begin(), workspaces_.end(), + [id](const auto &ws) { return ws["id"].asUInt64() == id; }); + if (it != workspaces_.end()) { + auto &ws = *it; + ws["is_urgent"] = urgent; + } else { + spdlog::error("Urgency changed for unknown workspace"); + } } else if (const auto &payload = ev["KeyboardLayoutsChanged"]) { const auto &layouts = payload["keyboard_layouts"]; const auto &names = layouts["names"]; diff --git a/src/modules/niri/workspaces.cpp b/src/modules/niri/workspaces.cpp index d2fcad5d..02e9d57a 100644 --- a/src/modules/niri/workspaces.cpp +++ b/src/modules/niri/workspaces.cpp @@ -20,6 +20,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value gIPC->registerForIPC("WorkspacesChanged", this); gIPC->registerForIPC("WorkspaceActivated", this); gIPC->registerForIPC("WorkspaceActiveWindowChanged", this); + gIPC->registerForIPC("WorkspaceUrgencyChanged", this); dp.emit(); } @@ -67,6 +68,11 @@ void Workspaces::doUpdate() { else style_context->remove_class("active"); + if (ws["is_urgent"].asBool()) + style_context->add_class("urgent"); + else + style_context->remove_class("urgent"); + if (ws["output"]) { if (ws["output"].asString() == bar_.output->name) style_context->add_class("current_output"); @@ -166,6 +172,8 @@ std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) const auto &icons = config_["format-icons"]; if (!icons) return value; + if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString(); + if (ws["is_focused"].asBool() && icons["focused"]) return icons["focused"].asString(); if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString(); From 19d243051646f0772e14295d8f4204900cea2f0f Mon Sep 17 00:00:00 2001 From: Illia Ostapyshyn Date: Mon, 19 May 2025 23:01:19 +0200 Subject: [PATCH 046/104] niri/workspaces: Add empty icon --- man/waybar-niri-workspaces.5.scd | 1 + src/modules/niri/workspaces.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/man/waybar-niri-workspaces.5.scd b/man/waybar-niri-workspaces.5.scd index 0c0249ca..48022096 100644 --- a/man/waybar-niri-workspaces.5.scd +++ b/man/waybar-niri-workspaces.5.scd @@ -70,6 +70,7 @@ Additional to workspace name matching, the following *format-icons* can be set. - *default*: Will be shown, when no string matches are found. - *focused*: Will be shown, when workspace is focused. - *active*: Will be shown, when workspace is active on its output. +- *empty*: Will be shown, when workspace is empty. # EXAMPLES diff --git a/src/modules/niri/workspaces.cpp b/src/modules/niri/workspaces.cpp index d2fcad5d..db4ac32b 100644 --- a/src/modules/niri/workspaces.cpp +++ b/src/modules/niri/workspaces.cpp @@ -166,6 +166,8 @@ std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) const auto &icons = config_["format-icons"]; if (!icons) return value; + if (ws["active_window_id"].isNull() && icons["empty"]) return icons["empty"].asString(); + if (ws["is_focused"].asBool() && icons["focused"]) return icons["focused"].asString(); if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString(); From cdf3ca910d0d9db4e5fb14f7d12fcc369981ed23 Mon Sep 17 00:00:00 2001 From: belcaik Date: Mon, 19 May 2025 22:52:01 -0400 Subject: [PATCH 047/104] feat: Add support for side buttons mouse navigation in handleToggle mapped buttons config on-click-backward and on-click-forward on mpris module to previous/next handle GTK codes are 9 and 8 --- src/modules/mpris/mpris.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index ed383b0c..59600ca0 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -14,7 +14,7 @@ extern "C" { #include #include - +#include // <-- agrega esta línea namespace waybar::modules::mpris { const std::string DEFAULT_FORMAT = "{player} ({status}): {dynamic}"; @@ -614,6 +614,18 @@ bool Mpris::handleToggle(GdkEventButton* const& e) { } playerctl_player_next(player, &error); break; + case 8: // side button mouse back on browser + if (config_["on-click-backward"].isString()) { + return ALabel::handleToggle(e); + } + playerctl_player_previous(player, &error); + break; + case 9: // side button mouse forward on browser + if (config_["on-click-forward"].isString()) { + return ALabel::handleToggle(e); + } + playerctl_player_next(player, &error); + break; } } if (error) { From d41a66477956ed2d9f1045250ede1f2ebb44da9b Mon Sep 17 00:00:00 2001 From: belcaik Date: Mon, 19 May 2025 23:12:42 -0400 Subject: [PATCH 048/104] refactor: use command pattern for button actions --- src/modules/mpris/mpris.cpp | 66 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 59600ca0..f57d4765 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -14,7 +14,6 @@ extern "C" { #include #include -#include // <-- agrega esta línea namespace waybar::modules::mpris { const std::string DEFAULT_FORMAT = "{player} ({status}): {dynamic}"; @@ -584,50 +583,45 @@ errorexit: } bool Mpris::handleToggle(GdkEventButton* const& e) { + if (!e || e->type != GdkEventType::GDK_BUTTON_PRESS) { + return false; + } + + auto info = getPlayerInfo(); + if (!info) return false; + + struct ButtonAction { + guint button; + const char* config_key; + std::function builtin_action; + }; + GError* error = nullptr; - waybar::util::ScopeGuard error_deleter([error]() { + waybar::util::ScopeGuard error_deleter([&error]() { if (error) { g_error_free(error); } }); - auto info = getPlayerInfo(); - if (!info) return false; + // Command pattern: encapsulate each button's action + const ButtonAction actions[] = { + {1, "on-click", [&]() { playerctl_player_play_pause(player, &error); }}, + {2, "on-click-middle", [&]() { playerctl_player_previous(player, &error); }}, + {3, "on-click-right", [&]() { playerctl_player_next(player, &error); }}, + {8, "on-click-backward", [&]() { playerctl_player_previous(player, &error); }}, + {9, "on-click-forward", [&]() { playerctl_player_next(player, &error); }}, + }; - if (e->type == GdkEventType::GDK_BUTTON_PRESS) { - switch (e->button) { - case 1: // left-click - if (config_["on-click"].isString()) { - return ALabel::handleToggle(e); - } - playerctl_player_play_pause(player, &error); - break; - case 2: // middle-click - if (config_["on-click-middle"].isString()) { - return ALabel::handleToggle(e); - } - playerctl_player_previous(player, &error); - break; - case 3: // right-click - if (config_["on-click-right"].isString()) { - return ALabel::handleToggle(e); - } - playerctl_player_next(player, &error); - break; - case 8: // side button mouse back on browser - if (config_["on-click-backward"].isString()) { - return ALabel::handleToggle(e); - } - playerctl_player_previous(player, &error); - break; - case 9: // side button mouse forward on browser - if (config_["on-click-forward"].isString()) { - return ALabel::handleToggle(e); - } - playerctl_player_next(player, &error); - break; + for (const auto& action : actions) { + if (e->button == action.button) { + if (config_[action.config_key].isString()) { + return ALabel::handleToggle(e); + } + action.builtin_action(); + break; } } + if (error) { spdlog::error("mpris[{}]: error running builtin on-click action: {}", (*info).name, error->message); From 4f55d7da9004a40dbac704c5053186b7ea6fc423 Mon Sep 17 00:00:00 2001 From: gred Date: Tue, 20 May 2025 22:45:36 +0300 Subject: [PATCH 049/104] Add persistent-only setting for hyprland/workspaces --- include/modules/hyprland/workspaces.hpp | 2 ++ src/modules/hyprland/workspace.cpp | 4 ++++ src/modules/hyprland/workspaces.cpp | 1 + 3 files changed, 7 insertions(+) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 6b33baea..db0f5114 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -37,6 +37,7 @@ class Workspaces : public AModule, public EventHandler { auto showSpecial() const -> bool { return m_showSpecial; } auto activeOnly() const -> bool { return m_activeOnly; } auto specialVisibleOnly() const -> bool { return m_specialVisibleOnly; } + auto persistentOnly() const -> bool { return m_persistentOnly; } auto moveToMonitor() const -> bool { return m_moveToMonitor; } auto getBarOutput() const -> std::string { return m_bar.output->name; } @@ -122,6 +123,7 @@ class Workspaces : public AModule, public EventHandler { bool m_showSpecial = false; bool m_activeOnly = false; bool m_specialVisibleOnly = false; + bool m_persistentOnly = false; bool m_moveToMonitor = false; Json::Value m_persistentWorkspaceConfig; diff --git a/src/modules/hyprland/workspace.cpp b/src/modules/hyprland/workspace.cpp index 4655096f..fdbb96aa 100644 --- a/src/modules/hyprland/workspace.cpp +++ b/src/modules/hyprland/workspace.cpp @@ -173,6 +173,10 @@ std::string &Workspace::selectIcon(std::map &icons_map } void Workspace::update(const std::string &format, const std::string &icon) { + if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) { + m_button.hide(); + return; + } // clang-format off if (this->m_workspaceManager.activeOnly() && \ !this->isActive() && \ diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 0e225935..734f4a3a 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -600,6 +600,7 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void { populateBoolConfig(config, "all-outputs", m_allOutputs); populateBoolConfig(config, "show-special", m_showSpecial); populateBoolConfig(config, "special-visible-only", m_specialVisibleOnly); + populateBoolConfig(config, "persistent-only", m_persistentOnly); populateBoolConfig(config, "active-only", m_activeOnly); populateBoolConfig(config, "move-to-monitor", m_moveToMonitor); From 24a30b7ffd9d9907cd912ee9c533ff330d21a252 Mon Sep 17 00:00:00 2001 From: gred Date: Wed, 21 May 2025 01:01:23 +0300 Subject: [PATCH 050/104] Add sorting with centered special workspaces --- include/modules/hyprland/workspaces.hpp | 4 +++- src/modules/hyprland/workspaces.cpp | 32 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 6b33baea..21a9dc22 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -50,6 +50,7 @@ class Workspaces : public AModule, public EventHandler { private: void onEvent(const std::string& e) override; void updateWindowCount(); + void sortSpecialCentered(); void sortWorkspaces(); void createWorkspace(Json::Value const& workspace_data, Json::Value const& clients_data = Json::Value::nullRef); @@ -130,12 +131,13 @@ class Workspaces : public AModule, public EventHandler { // and doesn't share windows accross bars (a.k.a `all-outputs` = false) std::map m_orphanWindowMap; - enum class SortMethod { ID, NAME, NUMBER, DEFAULT }; + enum class SortMethod { ID, NAME, NUMBER, SPECIAL_CENTERED, DEFAULT }; util::EnumParser m_enumParser; SortMethod m_sortBy = SortMethod::DEFAULT; std::map m_sortMap = {{"ID", SortMethod::ID}, {"NAME", SortMethod::NAME}, {"NUMBER", SortMethod::NUMBER}, + {"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED}, {"DEFAULT", SortMethod::DEFAULT}}; std::string m_format; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 0e225935..d8ae3c32 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -770,7 +770,36 @@ void Workspaces::setCurrentMonitorId() { } } +void Workspaces::sortSpecialCentered() { + std::vector> specialWorkspaces; + std::vector> normalWorkspaces; + + for (auto &workspace : m_workspaces) { + if (workspace->isSpecial()) { + specialWorkspaces.push_back(std::move(workspace)); + } else { + normalWorkspaces.push_back(std::move(workspace)); + } + } + m_workspaces.clear(); + + size_t center = normalWorkspaces.size() / 2; + + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(normalWorkspaces.begin()), + std::make_move_iterator(normalWorkspaces.begin() + center)); + + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(specialWorkspaces.begin()), + std::make_move_iterator(specialWorkspaces.end())); + + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(normalWorkspaces.begin() + center), + std::make_move_iterator(normalWorkspaces.end())); +} + void Workspaces::sortWorkspaces() { + std::ranges::sort( // m_workspaces, [&](std::unique_ptr &a, std::unique_ptr &b) { // Helper comparisons @@ -828,6 +857,9 @@ void Workspaces::sortWorkspaces() { // Return a default value if none of the cases match. return isNameLess; // You can adjust this to your specific needs. }); + if (m_sortBy == SortMethod::SPECIAL_CENTERED) { + this->sortSpecialCentered(); + } for (size_t i = 0; i < m_workspaces.size(); ++i) { m_box.reorder_child(m_workspaces[i]->button(), i); From 15f54cd6ef63c0c1507961582f161661339be01b Mon Sep 17 00:00:00 2001 From: gred Date: Wed, 21 May 2025 01:38:03 +0300 Subject: [PATCH 051/104] Fix hidden buttons --- src/modules/hyprland/workspaces.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index d8ae3c32..9caf6c6e 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -772,30 +772,39 @@ void Workspaces::setCurrentMonitorId() { void Workspaces::sortSpecialCentered() { std::vector> specialWorkspaces; + std::vector> hidedWorkspaces; std::vector> normalWorkspaces; for (auto &workspace : m_workspaces) { if (workspace->isSpecial()) { specialWorkspaces.push_back(std::move(workspace)); } else { - normalWorkspaces.push_back(std::move(workspace)); + if (workspace->button().is_visible()) { + normalWorkspaces.push_back(std::move(workspace)); + } else { + hidedWorkspaces.push_back(std::move(workspace)); + } } } m_workspaces.clear(); size_t center = normalWorkspaces.size() / 2; - m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(normalWorkspaces.begin()), + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(normalWorkspaces.begin()), std::make_move_iterator(normalWorkspaces.begin() + center)); m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(specialWorkspaces.begin()), + std::make_move_iterator(specialWorkspaces.begin()), std::make_move_iterator(specialWorkspaces.end())); - m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(normalWorkspaces.begin() + center), + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(normalWorkspaces.begin() + center), std::make_move_iterator(normalWorkspaces.end())); + + m_workspaces.insert(m_workspaces.end(), + std::make_move_iterator(hidedWorkspaces.begin()), + std::make_move_iterator(hidedWorkspaces.end())); } void Workspaces::sortWorkspaces() { From d53135f834fea98fa0ef140f30d048e7cfa0d228 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Sat, 31 May 2025 23:07:26 +0200 Subject: [PATCH 052/104] Fix Description= in systemd service file Description= should be a noun phrase, and not a full sentence, according to man 5 systemd.unit. In particular, using a dot at the end result in messages like this in journalctl when running as a user service (not the superfluous dot at the end): May 31 16:03:38 framework systemd[1180]: Started Highly customizable Wayland bar for Sway and Wlroots based compositors.. May 31 16:20:39 framework systemd[1180]: Stopping Highly customizable Wayland bar for Sway and Wlroots based compositors.... May 31 16:20:39 framework systemd[1180]: Stopped Highly customizable Wayland bar for Sway and Wlroots based compositors.. --- resources/waybar.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/waybar.service.in b/resources/waybar.service.in index 81ac6779..18bac54c 100644 --- a/resources/waybar.service.in +++ b/resources/waybar.service.in @@ -1,5 +1,5 @@ [Unit] -Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. +Description=Highly customizable Wayland bar for Sway and Wlroots based compositors Documentation=https://github.com/Alexays/Waybar/wiki/ PartOf=graphical-session.target After=graphical-session.target From c0e7aad60e69381062fb8d2b82c42dba6bc11726 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 1 Jun 2025 00:14:43 +0000 Subject: [PATCH 053/104] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'flake-compat': 'github:edolstra/flake-compat/ff81ac966bb2cae68946d5ed5fc4994f96d0ffec?narHash=sha256-NeCCThCEP3eCl2l/%2B27kNNK7QrwZB1IJCrXfrbv5oqU%3D' (2024-12-04) → 'github:edolstra/flake-compat/9100a0f413b0c601e0533d1d94ffd501ce2e7885?narHash=sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX%2BfjA8Xf8PUmqCY%3D' (2025-05-12) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/8a2f738d9d1f1d986b5a4cd2fd2061a7127237d7?narHash=sha256-sPwcCYuiEopaafePqlG826tBhctuJsLx/mhKKM5Fmjo%3D' (2025-04-23) → 'github:NixOS/nixpkgs/96ec055edbe5ee227f28cdbc3f1ddf1df5965102?narHash=sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg%3D' (2025-05-28) --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 480f004f..34545ed4 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", "owner": "edolstra", "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", "type": "github" }, "original": { @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1745391562, - "narHash": "sha256-sPwcCYuiEopaafePqlG826tBhctuJsLx/mhKKM5Fmjo=", + "lastModified": 1748460289, + "narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8a2f738d9d1f1d986b5a4cd2fd2061a7127237d7", + "rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102", "type": "github" }, "original": { From 05cfd738045d5da918a9d8bbbe65cb69da4d8854 Mon Sep 17 00:00:00 2001 From: Mateus Eto Date: Sun, 1 Jun 2025 21:27:37 +0900 Subject: [PATCH 054/104] Fix calendar extra padding if there are wide characters --- src/modules/clock.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 269fa765..0ef63c7b 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,5 +1,6 @@ #include "modules/clock.hpp" +#include #include #include @@ -358,10 +359,23 @@ auto waybar::modules::Clock::get_calendar(const year_month_day& today, const yea } } - os << Glib::ustring::format((cldWPos_ != WS::LEFT || line == 0) ? std::left : std::right, - std::setfill(L' '), - std::setw(cldMonColLen_ + ((line < 2) ? cldWnLen_ : 0)), - getCalendarLine(today, ymTmp, line, firstdow, &m_locale_)); + // Count wide characters to avoid extra padding + size_t wideCharCount = 0; + std::string calendarLine = getCalendarLine(today, ymTmp, line, firstdow, &m_locale_); + if (line < 2) { + for (gchar *data = calendarLine.data(), *end = data + calendarLine.size(); + data != nullptr;) { + gunichar c = g_utf8_get_char_validated(data, end - data); + if (g_unichar_iswide(c)) { + wideCharCount++; + } + data = g_utf8_find_next_char(data, end); + } + } + os << Glib::ustring::format( + (cldWPos_ != WS::LEFT || line == 0) ? std::left : std::right, std::setfill(L' '), + std::setw(cldMonColLen_ + ((line < 2) ? cldWnLen_ - wideCharCount : 0)), + calendarLine); // Week numbers on the right if (cldWPos_ == WS::RIGHT && line > 0) { From 34484919d6c2b1c808cdf43f9bd8cb9a32d44412 Mon Sep 17 00:00:00 2001 From: Davide Manini Date: Mon, 2 Jun 2025 17:23:06 +0300 Subject: [PATCH 055/104] AIconLabel: honour `rotation' option; add `swap-icon-label' option --- src/AIconLabel.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/AIconLabel.cpp b/src/AIconLabel.cpp index d7ee666e..130ba60c 100644 --- a/src/AIconLabel.cpp +++ b/src/AIconLabel.cpp @@ -1,6 +1,7 @@ #include "AIconLabel.hpp" #include +#include namespace waybar { @@ -17,14 +18,37 @@ AIconLabel::AIconLabel(const Json::Value &config, const std::string &name, const box_.get_style_context()->add_class(id); } - box_.set_orientation(Gtk::Orientation::ORIENTATION_HORIZONTAL); + int rot = 0; + + if (config_["rotate"].isUInt()) { + rot = config["rotate"].asUInt() % 360; + if ((rot % 90) != 00) + rot = 0; + rot /= 90; + } + + if ((rot % 2) == 0) + box_.set_orientation(Gtk::Orientation::ORIENTATION_HORIZONTAL); + else + box_.set_orientation(Gtk::Orientation::ORIENTATION_VERTICAL); box_.set_name(name); int spacing = config_["icon-spacing"].isInt() ? config_["icon-spacing"].asInt() : 8; box_.set_spacing(spacing); - box_.add(image_); - box_.add(label_); + bool swap_icon_label = false; + if (not config_["swap-icon-label"].isBool()) + spdlog::warn("'swap-icon-label' must be a bool."); + else + swap_icon_label = config_["swap-icon-label"].asBool(); + + if ( (rot == 0 || rot == 3) ^ swap_icon_label ) { + box_.add(image_); + box_.add(label_); + } else { + box_.add(label_); + box_.add(image_); + } event_box_.add(box_); } From c26978eca8e2e0e7e609085a7af0c9097d73717b Mon Sep 17 00:00:00 2001 From: Davide Manini Date: Mon, 2 Jun 2025 20:38:49 +0300 Subject: [PATCH 056/104] Update documentation --- man/waybar.5.scd.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/man/waybar.5.scd.in b/man/waybar.5.scd.in index 5bb62724..a9b76f8d 100644 --- a/man/waybar.5.scd.in +++ b/man/waybar.5.scd.in @@ -272,6 +272,17 @@ When positioning Waybar on the left or right side of the screen, sometimes it's Valid options for the "rotate" property are: 0, 90, 180, and 270. +## Swapping icon and label + +If a module displays both a label and an icon, it might be desirable to swap them (for instance, for panels on the left or right of the screen, or for user adopting a right-to-left script). This can be achieved with the "swap-icon-label" property, taking a boolean. Example: +``` +{ + "sway/window": { + "swap-icon-label": true + } +} +``` + ## Grouping modules Module groups allow stacking modules in any direction. By default, when the bar is positioned on the top or bottom of the screen, modules in a group are stacked vertically. Likewise, when positioned on the left or right, modules in a group are stacked horizontally. This can be changed with the "orientation" property. From 715503ec3ed14683114df50496267a28968009fd Mon Sep 17 00:00:00 2001 From: gred Date: Sat, 7 Jun 2025 10:50:29 +0300 Subject: [PATCH 057/104] Rename vector to hiddenWorkspaces --- src/modules/hyprland/workspaces.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 9caf6c6e..50727d61 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -772,7 +772,7 @@ void Workspaces::setCurrentMonitorId() { void Workspaces::sortSpecialCentered() { std::vector> specialWorkspaces; - std::vector> hidedWorkspaces; + std::vector> hiddenWorkspaces; std::vector> normalWorkspaces; for (auto &workspace : m_workspaces) { @@ -782,7 +782,7 @@ void Workspaces::sortSpecialCentered() { if (workspace->button().is_visible()) { normalWorkspaces.push_back(std::move(workspace)); } else { - hidedWorkspaces.push_back(std::move(workspace)); + hiddenWorkspaces.push_back(std::move(workspace)); } } } @@ -803,8 +803,8 @@ void Workspaces::sortSpecialCentered() { std::make_move_iterator(normalWorkspaces.end())); m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(hidedWorkspaces.begin()), - std::make_move_iterator(hidedWorkspaces.end())); + std::make_move_iterator(hiddenWorkspaces.begin()), + std::make_move_iterator(hiddenWorkspaces.end())); } void Workspaces::sortWorkspaces() { From b36a283f8324d7cd3772acc2bed1a4dfc817369a Mon Sep 17 00:00:00 2001 From: gred Date: Sat, 7 Jun 2025 11:06:06 +0300 Subject: [PATCH 058/104] Update man --- man/waybar-hyprland-workspaces.5.scd | 1 + 1 file changed, 1 insertion(+) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 18c39898..17b6e3fe 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -76,6 +76,7 @@ Addressed by *hyprland/workspaces* If set to number, workspaces will sort by number. If set to name, workspaces will sort by name. If set to id, workspaces will sort by id. + If set to special-centered, workspaces will sort by default with special workspaces in the center. If none of those, workspaces will sort with default behavior. *expand*: ++ From 35c6e9c21c6d2e0c8200a2177f5ab977f5ecbc86 Mon Sep 17 00:00:00 2001 From: gred Date: Sat, 7 Jun 2025 11:23:19 +0300 Subject: [PATCH 059/104] Update man page --- man/waybar-hyprland-workspaces.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 18c39898..85446715 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -48,6 +48,11 @@ Addressed by *hyprland/workspaces* default: false ++ If this and show-special are to true, special workspaces will be shown only if visible. +*persistent-only*: ++ + typeof: bool ++ + default: false ++ + TIf set to true only persistent workspaces will be shown on bar. + *all-outputs*: ++ typeof: bool ++ default: false ++ From fca159ad014b0189c4d530a5ec783f07c64f8b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= <88423841+Roc25@users.noreply.github.com> Date: Sat, 7 Jun 2025 12:19:13 +0300 Subject: [PATCH 060/104] Update man page Co-authored-by: Tuur Vanhoutte <4633209+zjeffer@users.noreply.github.com> --- man/waybar-hyprland-workspaces.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 85446715..b76be108 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -51,7 +51,7 @@ Addressed by *hyprland/workspaces* *persistent-only*: ++ typeof: bool ++ default: false ++ - TIf set to true only persistent workspaces will be shown on bar. + If set to true, only persistent workspaces will be shown on bar. *all-outputs*: ++ typeof: bool ++ From 703be13b002342625debbab9b3393d7cb8e50e16 Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:11:07 +0200 Subject: [PATCH 061/104] privacy: introduce `ignore` option --- include/modules/privacy/privacy.hpp | 1 + src/modules/privacy/privacy.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/modules/privacy/privacy.hpp b/include/modules/privacy/privacy.hpp index 6179098c..3ea41d12 100644 --- a/include/modules/privacy/privacy.hpp +++ b/include/modules/privacy/privacy.hpp @@ -31,6 +31,7 @@ class Privacy : public AModule { uint iconSpacing = 4; uint iconSize = 20; uint transition_duration = 250; + std::set> ignore; std::shared_ptr backend = nullptr; }; diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 48bba888..42875976 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -74,6 +74,18 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, Gtk::Orientat } } + for (const auto& ignore_item : config_["ignore"]) { + if (!ignore_item.isObject() || !ignore_item["type"].isString() || !ignore_item["name"].isString()) continue; + const std::string type = ignore_item["type"].asString(); + const std::string name = ignore_item["name"].asString(); + + auto iter = typeMap.find(type); + if (iter != typeMap.end()) { + auto& [_, nodeType] = iter->second; + ignore.emplace(nodeType, std::move(name)); + } + } + backend = util::PipewireBackend::PipewireBackend::getInstance(); backend->privacy_nodes_changed_signal_event.connect( sigc::mem_fun(*this, &Privacy::onPrivacyNodesChanged)); @@ -88,6 +100,10 @@ void Privacy::onPrivacyNodesChanged() { nodes_screenshare.clear(); for (auto& node : backend->privacy_nodes) { + auto iter = ignore.find(std::pair(node.second->type, node.second->node_name)); + if (iter != ignore.end()) + continue; + switch (node.second->state) { case PW_NODE_STATE_RUNNING: switch (node.second->type) { From 831602a9134deced66c3d4b8c4caa8a068a80cba Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:09:22 +0200 Subject: [PATCH 062/104] privacy: default to ignoring all stream.monitor pw nodes --- include/modules/privacy/privacy.hpp | 1 + include/util/pipewire/privacy_node_info.hpp | 1 + src/modules/privacy/privacy.cpp | 7 +++++++ src/util/pipewire/privacy_node_info.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/include/modules/privacy/privacy.hpp b/include/modules/privacy/privacy.hpp index 3ea41d12..cb6a34da 100644 --- a/include/modules/privacy/privacy.hpp +++ b/include/modules/privacy/privacy.hpp @@ -32,6 +32,7 @@ class Privacy : public AModule { uint iconSize = 20; uint transition_duration = 250; std::set> ignore; + bool ignore_monitor = true; std::shared_ptr backend = nullptr; }; diff --git a/include/util/pipewire/privacy_node_info.hpp b/include/util/pipewire/privacy_node_info.hpp index 7b8df018..54da7d16 100644 --- a/include/util/pipewire/privacy_node_info.hpp +++ b/include/util/pipewire/privacy_node_info.hpp @@ -25,6 +25,7 @@ class PrivacyNodeInfo { std::string media_name; std::string node_name; std::string application_name; + bool is_monitor = false; std::string pipewire_access_portal_app_id; std::string application_icon_name; diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 42875976..6f6d1395 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -86,6 +86,10 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, Gtk::Orientat } } + if (config_["ignore-monitor"].isBool()) { + ignore_monitor = config_["ignore-monitor"].asBool(); + } + backend = util::PipewireBackend::PipewireBackend::getInstance(); backend->privacy_nodes_changed_signal_event.connect( sigc::mem_fun(*this, &Privacy::onPrivacyNodesChanged)); @@ -100,6 +104,9 @@ void Privacy::onPrivacyNodesChanged() { nodes_screenshare.clear(); for (auto& node : backend->privacy_nodes) { + if (ignore_monitor && node.second->is_monitor) + continue; + auto iter = ignore.find(std::pair(node.second->type, node.second->node_name)); if (iter != ignore.end()) continue; diff --git a/src/util/pipewire/privacy_node_info.cpp b/src/util/pipewire/privacy_node_info.cpp index 739dc528..ec110b86 100644 --- a/src/util/pipewire/privacy_node_info.cpp +++ b/src/util/pipewire/privacy_node_info.cpp @@ -49,6 +49,8 @@ void PrivacyNodeInfo::handleNodeEventInfo(const struct pw_node_info *info) { pipewire_access_portal_app_id = item->value; } else if (strcmp(item->key, PW_KEY_APP_ICON_NAME) == 0) { application_icon_name = item->value; + } else if (strcmp(item->key, "stream.monitor") == 0) { + is_monitor = strcmp(item->value, "true") == 0; } } } From 6cfaf4ff63b9f30bdcd9c0fc3247ff537ae78966 Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:18:04 +0200 Subject: [PATCH 063/104] privacy: document ignore options --- man/waybar-privacy.5.scd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/man/waybar-privacy.5.scd b/man/waybar-privacy.5.scd index 946fe136..28b55f1a 100644 --- a/man/waybar-privacy.5.scd +++ b/man/waybar-privacy.5.scd @@ -37,6 +37,17 @@ the screen or playing audio. default: false ++ Enables this module to consume all left over space dynamically. +*ignore-monitor* ++ + typeof: bool ++ + default: true ++ + Ignore streams with *stream.monitor* property. + +*ignore* ++ + typeof: array of objects ++ + default: [] ++ + Additional streams to be ignored. See *IGNORE CONFIGURATION* for++ + more information. + # MODULES CONFIGURATION *type*: ++ @@ -54,6 +65,14 @@ the screen or playing audio. default: 24 ++ The size of each icon in the tooltip. +# IGNORE CONFIGURATION + +*type*: ++ + typeof: string + +*name*: ++ + typeof: string + # EXAMPLES ``` From f73d26722c58b9a27b8390cfb37c5a07333a2732 Mon Sep 17 00:00:00 2001 From: Sonter <108224581+S0nter@users.noreply.github.com> Date: Sun, 8 Jun 2025 12:39:10 +0300 Subject: [PATCH 064/104] privacy: add example configuration --- man/waybar-privacy.5.scd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/man/waybar-privacy.5.scd b/man/waybar-privacy.5.scd index 28b55f1a..1c4ef59d 100644 --- a/man/waybar-privacy.5.scd +++ b/man/waybar-privacy.5.scd @@ -96,6 +96,17 @@ the screen or playing audio. "tooltip": true, "tooltip-icon-size": 24 } + ], + "ignore-monitor": true, + "ignore": [ + { + "type": "audio-in", + "name": "cava" + }, + { + "type": "screenshare", + "name": "obs" + } ] }, ``` From 4d9403601a621b947aba81bc27b89431b173e709 Mon Sep 17 00:00:00 2001 From: Sonter <108224581+S0nter@users.noreply.github.com> Date: Sun, 8 Jun 2025 12:53:46 +0300 Subject: [PATCH 065/104] privacy: format with clang-format --- src/modules/privacy/privacy.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 6f6d1395..904c8fd9 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -75,7 +75,9 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, Gtk::Orientat } for (const auto& ignore_item : config_["ignore"]) { - if (!ignore_item.isObject() || !ignore_item["type"].isString() || !ignore_item["name"].isString()) continue; + if (!ignore_item.isObject() || !ignore_item["type"].isString() || + !ignore_item["name"].isString()) + continue; const std::string type = ignore_item["type"].asString(); const std::string name = ignore_item["name"].asString(); @@ -104,12 +106,10 @@ void Privacy::onPrivacyNodesChanged() { nodes_screenshare.clear(); for (auto& node : backend->privacy_nodes) { - if (ignore_monitor && node.second->is_monitor) - continue; + if (ignore_monitor && node.second->is_monitor) continue; auto iter = ignore.find(std::pair(node.second->type, node.second->node_name)); - if (iter != ignore.end()) - continue; + if (iter != ignore.end()) continue; switch (node.second->state) { case PW_NODE_STATE_RUNNING: From 3ebf2d96e529c0ccba05273805693adbd863527d Mon Sep 17 00:00:00 2001 From: Taimase Date: Wed, 11 Jun 2025 01:12:08 -0600 Subject: [PATCH 066/104] fix continuousWorker in the custom module by capturing the buffer by reference. --- src/modules/custom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index e023aaf6..052247e0 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -62,7 +62,7 @@ void waybar::modules::Custom::continuousWorker() { } thread_ = [this, cmd] { char* buff = nullptr; - waybar::util::ScopeGuard buff_deleter([buff]() { + waybar::util::ScopeGuard buff_deleter([&buff]() { if (buff) { free(buff); } From 5e14698b4eb824189513bdbbd57484316453c6b4 Mon Sep 17 00:00:00 2001 From: peelz Date: Thu, 12 Jun 2025 17:01:05 -0400 Subject: [PATCH 067/104] fix: network frequency is reported in GHz --- man/waybar-network.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index 15f15395..3b63e3ee 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -171,7 +171,7 @@ Addressed by *network* *{signaldBm}*: Signal strength of the wireless network in dBm. -*{frequency}*: Frequency of the wireless network in MHz. +*{frequency}*: Frequency of the wireless network in GHz. *{bandwidthUpBits}*: Instant up speed in bits/seconds. From 07468357f478c42fabc85e5ca849bba9e4c2df70 Mon Sep 17 00:00:00 2001 From: peelz Date: Thu, 12 Jun 2025 19:19:43 -0400 Subject: [PATCH 068/104] fix: network module not displaying rfkill state --- src/modules/network.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 0a77c00e..c46b8188 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -223,8 +223,8 @@ void waybar::modules::Network::worker() { std::lock_guard lock(mutex_); if (ifid_ > 0) { getInfo(); - dp.emit(); } + dp.emit(); } thread_timer_.sleep_for(interval_); }; @@ -271,10 +271,10 @@ void waybar::modules::Network::worker() { } const std::string waybar::modules::Network::getNetworkState() const { - if (ifid_ == -1) { #ifdef WANT_RFKILL if (rfkill_.getState()) return "disabled"; #endif + if (ifid_ == -1) { return "disconnected"; } if (!carrier_) return "disconnected"; From f4496c9648bf651b871eb6fa61ddb115c25cd90a Mon Sep 17 00:00:00 2001 From: peelz Date: Fri, 13 Jun 2025 22:51:03 -0400 Subject: [PATCH 069/104] fix: length_error thrown in handleOutputDescription --- src/client.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 63a9276a..b4fe2a8b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -106,11 +106,11 @@ void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * auto *client = waybar::Client::inst(); try { auto &output = client->getOutput(data); - const char *open_paren = strrchr(description, '('); // Description format: "identifier (name)" - size_t identifier_length = open_paren - description; - output.identifier = std::string(description, identifier_length - 1); + auto s = std::string(description); + auto pos = s.find(" ("); + output.identifier = pos != std::string::npos ? s.substr(0, pos) : s; } catch (const std::exception &e) { std::cerr << e.what() << '\n'; } From bd28bb959fdcd06685e9f4848c11dbf2b056d14b Mon Sep 17 00:00:00 2001 From: peelz Date: Fri, 13 Jun 2025 22:57:31 -0400 Subject: [PATCH 070/104] fix: use spdlog in zxdg_output_v1_listener callbacks --- src/client.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index b4fe2a8b..e363f236 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -86,7 +86,7 @@ void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_ } } } catch (const std::exception &e) { - std::cerr << e.what() << '\n'; + spdlog::warn("caught exception in zxdg_output_v1_listener::done: {}", e.what()); } } @@ -97,7 +97,7 @@ void waybar::Client::handleOutputName(void *data, struct zxdg_output_v1 * /*xdg_ auto &output = client->getOutput(data); output.name = name; } catch (const std::exception &e) { - std::cerr << e.what() << '\n'; + spdlog::warn("caught exception in zxdg_output_v1_listener::name: {}", e.what()); } } @@ -112,7 +112,7 @@ void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * auto pos = s.find(" ("); output.identifier = pos != std::string::npos ? s.substr(0, pos) : s; } catch (const std::exception &e) { - std::cerr << e.what() << '\n'; + spdlog::warn("caught exception in zxdg_output_v1_listener::description: {}", e.what()); } } From af9d61fa8f150317d2de908600a14ac856ee740d Mon Sep 17 00:00:00 2001 From: markx86 <25851052+markx86@users.noreply.github.com> Date: Thu, 19 Jun 2025 00:35:12 +0200 Subject: [PATCH 071/104] fix: `cldMonShift_` not getting initialized in `Clock()` constructor Initialize `cldMonShift_` member in the `clock` module constructor. This fixes a bug where the calendar tooltip would break after a reload, when in month mode. --- src/modules/clock.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 269fa765..f00d79fc 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -25,6 +25,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) m_tooltip_{new Gtk::Label()}, cldInTooltip_{m_tlpFmt_.find("{" + kCldPlaceholder + "}") != std::string::npos}, cldYearShift_{January / 1 / 1900}, + cldMonShift_{1900y / January}, tzInTooltip_{m_tlpFmt_.find("{" + kTZPlaceholder + "}") != std::string::npos}, tzCurrIdx_{0}, ordInTooltip_{m_tlpFmt_.find("{" + kOrdPlaceholder + "}") != std::string::npos} { From bdcab011ee9daa316452a8764f67b2aca699103e Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Thu, 19 Jun 2025 15:55:35 +0000 Subject: [PATCH 072/104] modules: memory: Add swapState format argument Add an argument to the memory module which displays the state of the swap configuration of the local system. Usage of swap does not necessarily indicate if swap is on or off. Signed-off-by: Steffen Kothe --- man/waybar-memory.5.scd | 2 ++ src/modules/memory/common.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index cc42d5a3..567c2c72 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -120,6 +120,8 @@ Addressed by *memory* *{swapAvail}*: Amount of available swap in GiB. +*{swapState}*: Signals if swap is activated or not + # EXAMPLES ``` diff --git a/src/modules/memory/common.cpp b/src/modules/memory/common.cpp index 544d7814..18600cd2 100644 --- a/src/modules/memory/common.cpp +++ b/src/modules/memory/common.cpp @@ -60,6 +60,7 @@ auto waybar::modules::Memory::update() -> void { fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("percentage", used_ram_percentage), + fmt::arg("swapState", swaptotal == 0 ? "Off" : "On"), fmt::arg("swapPercentage", used_swap_percentage), fmt::arg("used", used_ram_gigabytes), fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes), fmt::arg("swapAvail", available_swap_gigabytes))); @@ -72,6 +73,7 @@ auto waybar::modules::Memory::update() -> void { fmt::runtime(tooltip_format), used_ram_percentage, fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("percentage", used_ram_percentage), + fmt::arg("swapState", swaptotal == 0 ? "Off" : "On"), fmt::arg("swapPercentage", used_swap_percentage), fmt::arg("used", used_ram_gigabytes), fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes), fmt::arg("swapAvail", available_swap_gigabytes))); From 76d0b44214751cf334dae07072e1f7cff9a45661 Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Thu, 19 Jun 2025 18:57:59 +0000 Subject: [PATCH 073/104] Dockerfiles: Use debian-slim for container Slim images of Debian tend to be smaller even during development. Hence replace the full-fledged variant with the slim one. Signed-off-by: Steffen Kothe --- Dockerfiles/debian | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfiles/debian b/Dockerfiles/debian index f479062d..c2584ccf 100644 --- a/Dockerfiles/debian +++ b/Dockerfiles/debian @@ -1,6 +1,6 @@ # vim: ft=Dockerfile -FROM debian:sid +FROM debian:sid-slim RUN apt update && \ apt install --no-install-recommends --no-install-suggests -y \ From c266befe0a9b80109d4b19c2a7482e19a16c0679 Mon Sep 17 00:00:00 2001 From: markx86 <25851052+markx86@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:02:01 +0200 Subject: [PATCH 074/104] fix: MPRIS widget not hiding when no player is active --- src/modules/mpris/mpris.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index ed383b0c..47bb9c05 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -425,9 +425,11 @@ auto Mpris::onPlayerNameVanished(PlayerctlPlayerManager* manager, PlayerctlPlaye auto* mpris = static_cast(data); if (!mpris) return; - spdlog::debug("mpris: player-vanished callback: {}", player_name->name); + spdlog::debug("mpris: name-vanished callback: {}", player_name->name); - if (std::string(player_name->name) == mpris->player_) { + if (mpris->player_ == "playerctld") { + mpris->dp.emit(); + } else if (mpris->player_ == player_name->name) { mpris->player = nullptr; mpris->event_box_.set_visible(false); mpris->dp.emit(); @@ -499,6 +501,7 @@ auto Mpris::getPlayerInfo() -> std::optional { // https://github.com/altdesktop/playerctl/blob/b19a71cb9dba635df68d271bd2b3f6a99336a223/playerctl/playerctl-common.c#L248-L249 players = g_list_first(players); if (players) player_name = static_cast(players->data)->name; + else return std::nullopt; // no players found, hide the widget } if (std::any_of(ignored_players_.begin(), ignored_players_.end(), From b8a985d606d8f33c92a8e539d4978c32ace3e9df Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 21 Jun 2025 10:54:16 -0400 Subject: [PATCH 075/104] style: fix formatting --- src/modules/network.cpp | 2 +- src/modules/sway/workspaces.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index c46b8188..955f9f1d 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -272,7 +272,7 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { #ifdef WANT_RFKILL - if (rfkill_.getState()) return "disabled"; + if (rfkill_.getState()) return "disabled"; #endif if (ifid_ == -1) { return "disconnected"; diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index b8ed73d4..86c2029b 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -494,7 +494,7 @@ std::string Workspaces::trimWorkspaceName(std::string name) { return name; } -bool is_focused_recursive(const Json::Value& node) { +bool is_focused_recursive(const Json::Value &node) { // If a workspace has a focused container then get_tree will say // that the workspace itself isn't focused. Therefore we need to // check if any of its nodes are focused as well. @@ -504,13 +504,13 @@ bool is_focused_recursive(const Json::Value& node) { return true; } - for (const auto& child : node["nodes"]) { + for (const auto &child : node["nodes"]) { if (is_focused_recursive(child)) { return true; } } - for (const auto& child : node["floating_nodes"]) { + for (const auto &child : node["floating_nodes"]) { if (is_focused_recursive(child)) { return true; } From 37a6106d3e62efc19861f1ea80f04bf145d4252b Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:17:59 +0000 Subject: [PATCH 076/104] modules: systemd_failed_units: Introduce nr_failed as member Keeping nr_failed as member allows to split-out calculation of overall failed units into updateData. Signed-off-by: Steffen Kothe --- include/modules/systemd_failed_units.hpp | 2 +- src/modules/systemd_failed_units.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/modules/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp index 9c3fbcee..df78a5bb 100644 --- a/include/modules/systemd_failed_units.hpp +++ b/include/modules/systemd_failed_units.hpp @@ -19,7 +19,7 @@ class SystemdFailedUnits : public ALabel { std::string format_ok; bool update_pending; - uint32_t nr_failed_system, nr_failed_user; + uint32_t nr_failed_system, nr_failed_user, nr_failed; std::string last_status; Glib::RefPtr system_proxy, user_proxy; diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 56e624cf..e2cad8f9 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -16,6 +16,7 @@ SystemdFailedUnits::SystemdFailedUnits(const std::string& id, const Json::Value& update_pending(false), nr_failed_system(0), nr_failed_user(0), + nr_failed(0), last_status() { if (config["hide-on-ok"].isBool()) { hide_on_ok = config["hide-on-ok"].asBool(); @@ -100,7 +101,7 @@ void SystemdFailedUnits::updateData() { } auto SystemdFailedUnits::update() -> void { - uint32_t nr_failed = nr_failed_system + nr_failed_user; + nr_failed = nr_failed_system + nr_failed_user; // Hide if needed. if (nr_failed == 0 && hide_on_ok) { From dcbbe3bb97b973fe792e313dbddd4b8709f96d86 Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:19:43 +0000 Subject: [PATCH 077/104] modules: systemd_failed_units: Move nr_failed calculation to updateData Signed-off-by: Steffen Kothe --- src/modules/systemd_failed_units.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index e2cad8f9..2518b5cc 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -97,12 +97,12 @@ void SystemdFailedUnits::updateData() { if (user_proxy) { nr_failed_user = load("user", user_proxy); } + + nr_failed = nr_failed_system + nr_failed_user; dp.emit(); } auto SystemdFailedUnits::update() -> void { - nr_failed = nr_failed_system + nr_failed_user; - // Hide if needed. if (nr_failed == 0 && hide_on_ok) { event_box_.set_visible(false); From 5c2cf4c65c5e8138db7206664d292165b9aad32f Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:22:24 +0000 Subject: [PATCH 078/104] modules: systemd_failed_units: Fail early if state did not change Prefer early exit if last status matches the current status. Signed-off-by: Steffen Kothe --- src/modules/systemd_failed_units.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 2518b5cc..8ca183ae 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -103,6 +103,10 @@ void SystemdFailedUnits::updateData() { } auto SystemdFailedUnits::update() -> void { + const std::string status = nr_failed == 0 ? "ok" : "degraded"; + + if (last_status == status) return; + // Hide if needed. if (nr_failed == 0 && hide_on_ok) { event_box_.set_visible(false); @@ -113,7 +117,6 @@ auto SystemdFailedUnits::update() -> void { } // Set state class. - const std::string status = nr_failed == 0 ? "ok" : "degraded"; if (!last_status.empty() && label_.get_style_context()->has_class(last_status)) { label_.get_style_context()->remove_class(last_status); } From 74255d0c7e6cd23bf29bfd51b1254576b65d01f5 Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:25:21 +0000 Subject: [PATCH 079/104] modules: systemd_failed_units: Move DBUS proxy check into lambda function Checking for the availability of a given proxy member can be done in the lambda function as well. Signed-off-by: Steffen Kothe --- src/modules/systemd_failed_units.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 8ca183ae..3ff3c2ee 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -73,6 +73,7 @@ void SystemdFailedUnits::updateData() { auto load = [](const char* kind, Glib::RefPtr& proxy) -> uint32_t { try { + if (!proxy) return 0; auto parameters = Glib::VariantContainerBase( g_variant_new("(ss)", "org.freedesktop.systemd1.Manager", "NFailedUnits")); Glib::VariantContainerBase data = proxy->call_sync("Get", parameters); @@ -91,13 +92,8 @@ void SystemdFailedUnits::updateData() { return 0; }; - if (system_proxy) { - nr_failed_system = load("systemwide", system_proxy); - } - if (user_proxy) { - nr_failed_user = load("user", user_proxy); - } - + nr_failed_system = load("systemwide", system_proxy); + nr_failed_user = load("user", user_proxy); nr_failed = nr_failed_system + nr_failed_user; dp.emit(); } From 4bb06b86bccccdceaa55828a2de9c84c874ccf21 Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:27:43 +0000 Subject: [PATCH 080/104] modules: systemd_failed_units: Use explicit g_variant_get_uint32 Determining of failed units can be done by usage of explicit uint32 function with direct return due to auto lambda expression. Signed-off-by: Steffen Kothe --- src/modules/systemd_failed_units.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 3ff3c2ee..a4457671 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -81,9 +81,7 @@ void SystemdFailedUnits::updateData() { Glib::VariantBase variant; g_variant_get(data.gobj_copy(), "(v)", &variant); if (variant && variant.is_of_type(Glib::VARIANT_TYPE_UINT32)) { - uint32_t value = 0; - g_variant_get(variant.gobj_copy(), "u", &value); - return value; + return g_variant_get_uint32(variant.gobj_copy()); } } } catch (Glib::Error& e) { From 07311176797cf476e7a51bb774a1eb4d4326ad8a Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:34:44 +0000 Subject: [PATCH 081/104] modules: systemd_failed_units: Introduce RequestFailedUnits member Split-out request of failed units from systemd into a separate member function. This increases the readability and extendability, but preserves the current functionality (non-functional change). Signed-off-by: Steffen Kothe --- include/modules/systemd_failed_units.hpp | 1 + src/modules/systemd_failed_units.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/modules/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp index df78a5bb..7801a5d6 100644 --- a/include/modules/systemd_failed_units.hpp +++ b/include/modules/systemd_failed_units.hpp @@ -25,6 +25,7 @@ class SystemdFailedUnits : public ALabel { void notify_cb(const Glib::ustring &sender_name, const Glib::ustring &signal_name, const Glib::VariantContainerBase &arguments); + void RequestFailedUnits(); void updateData(); }; diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index a4457671..f3f04fae 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -68,9 +68,7 @@ auto SystemdFailedUnits::notify_cb(const Glib::ustring& sender_name, } } -void SystemdFailedUnits::updateData() { - update_pending = false; - +void SystemdFailedUnits::RequestFailedUnits() { auto load = [](const char* kind, Glib::RefPtr& proxy) -> uint32_t { try { if (!proxy) return 0; @@ -93,6 +91,11 @@ void SystemdFailedUnits::updateData() { nr_failed_system = load("systemwide", system_proxy); nr_failed_user = load("user", user_proxy); nr_failed = nr_failed_system + nr_failed_user; +} + +void SystemdFailedUnits::updateData() { + update_pending = false; + RequestFailedUnits(); dp.emit(); } From d5e3a9f894e5e5ed160a9329d198d5f0f81d494c Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 16:19:51 +0000 Subject: [PATCH 082/104] modules: systemd_failed_units: Enforce visibility of event box on every update Instead if guarding visibility in if condition, enforce visibility regardless of the state of the current update. Signed-off-by: Steffen Kothe --- src/modules/systemd_failed_units.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index f3f04fae..92f4105c 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -109,9 +109,8 @@ auto SystemdFailedUnits::update() -> void { event_box_.set_visible(false); return; } - if (!event_box_.get_visible()) { - event_box_.set_visible(true); - } + + event_box_.set_visible(true); // Set state class. if (!last_status.empty() && label_.get_style_context()->has_class(last_status)) { From cfb47790adaafd9508072632d35612e578f3ad84 Mon Sep 17 00:00:00 2001 From: Steffen Kothe Date: Sat, 21 Jun 2025 15:09:05 +0000 Subject: [PATCH 083/104] modules: systemd_failed_units: Introduce systemd state variables Systemd provides the status of a given user and system session as a human readable string. Retrieve this information via RequestSystemState and guard the retrieve of failed units depending on this request. The functionality is extended but does not change, which means that failed units in any granularity are displayed as before. Update documentation in the meantime. Signed-off-by: Steffen Kothe --- include/modules/systemd_failed_units.hpp | 2 + man/waybar-systemd-failed-units.5.scd | 6 +++ src/modules/systemd_failed_units.cpp | 50 +++++++++++++++++++----- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/include/modules/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp index 7801a5d6..48b0074e 100644 --- a/include/modules/systemd_failed_units.hpp +++ b/include/modules/systemd_failed_units.hpp @@ -19,6 +19,7 @@ class SystemdFailedUnits : public ALabel { std::string format_ok; bool update_pending; + std::string system_state, user_state, overall_state; uint32_t nr_failed_system, nr_failed_user, nr_failed; std::string last_status; Glib::RefPtr system_proxy, user_proxy; @@ -26,6 +27,7 @@ class SystemdFailedUnits : public ALabel { void notify_cb(const Glib::ustring &sender_name, const Glib::ustring &signal_name, const Glib::VariantContainerBase &arguments); void RequestFailedUnits(); + void RequestSystemState(); void updateData(); }; diff --git a/man/waybar-systemd-failed-units.5.scd b/man/waybar-systemd-failed-units.5.scd index 92e74e9d..8d7c980a 100644 --- a/man/waybar-systemd-failed-units.5.scd +++ b/man/waybar-systemd-failed-units.5.scd @@ -62,6 +62,12 @@ Addressed by *systemd-failed-units* *{nr_failed}*: Number of total failed units. +*{systemd_state}:* State of the systemd system session + +*{user_state}:* State of the systemd user session + +*{overall_state}:* Overall state of the systemd and user session. ("Ok" or "Degraded") + # EXAMPLES ``` diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 92f4105c..90f33be7 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -68,6 +68,34 @@ auto SystemdFailedUnits::notify_cb(const Glib::ustring& sender_name, } } +void SystemdFailedUnits::RequestSystemState() { + auto load = [](const char* kind, Glib::RefPtr& proxy) -> std::string { + try { + if (!proxy) return "unknown"; + auto parameters = Glib::VariantContainerBase( + g_variant_new("(ss)", "org.freedesktop.systemd1.Manager", "SystemState")); + Glib::VariantContainerBase data = proxy->call_sync("Get", parameters); + if (data && data.is_of_type(Glib::VariantType("(v)"))) { + Glib::VariantBase variant; + g_variant_get(data.gobj_copy(), "(v)", &variant); + if (variant && variant.is_of_type(Glib::VARIANT_TYPE_STRING)) { + return g_variant_get_string(variant.gobj_copy(), NULL); + } + } + } catch (Glib::Error& e) { + spdlog::error("Failed to get {} state: {}", kind, e.what().c_str()); + } + return "unknown"; + }; + + system_state = load("systemwide", system_proxy); + user_state = load("user", user_proxy); + if (system_state == "running" && user_state == "running") + overall_state = "ok"; + else + overall_state = "degraded"; +} + void SystemdFailedUnits::RequestFailedUnits() { auto load = [](const char* kind, Glib::RefPtr& proxy) -> uint32_t { try { @@ -95,17 +123,18 @@ void SystemdFailedUnits::RequestFailedUnits() { void SystemdFailedUnits::updateData() { update_pending = false; - RequestFailedUnits(); + + RequestSystemState(); + if (overall_state == "degraded") RequestFailedUnits(); + dp.emit(); } auto SystemdFailedUnits::update() -> void { - const std::string status = nr_failed == 0 ? "ok" : "degraded"; - - if (last_status == status) return; + if (last_status == overall_state) return; // Hide if needed. - if (nr_failed == 0 && hide_on_ok) { + if (overall_state == "ok" && hide_on_ok) { event_box_.set_visible(false); return; } @@ -116,14 +145,17 @@ auto SystemdFailedUnits::update() -> void { if (!last_status.empty() && label_.get_style_context()->has_class(last_status)) { label_.get_style_context()->remove_class(last_status); } - if (!label_.get_style_context()->has_class(status)) { - label_.get_style_context()->add_class(status); + if (!label_.get_style_context()->has_class(overall_state)) { + label_.get_style_context()->add_class(overall_state); } - last_status = status; + + last_status = overall_state; label_.set_markup(fmt::format( fmt::runtime(nr_failed == 0 ? format_ok : format_), fmt::arg("nr_failed", nr_failed), - fmt::arg("nr_failed_system", nr_failed_system), fmt::arg("nr_failed_user", nr_failed_user))); + fmt::arg("nr_failed_system", nr_failed_system), fmt::arg("nr_failed_user", nr_failed_user), + fmt::arg("system_state", system_state), fmt::arg("user_state", user_state), + fmt::arg("overall_state", overall_state))); ALabel::update(); } From c6fceb03c8dfb8d2254534d96b777d94a6b9d33a Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 21 Jun 2025 16:05:00 -0400 Subject: [PATCH 084/104] ci: relax gentoo gtkmm dependency requirement --- Dockerfiles/gentoo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfiles/gentoo b/Dockerfiles/gentoo index f2ec0dc9..f7023825 100644 --- a/Dockerfiles/gentoo +++ b/Dockerfiles/gentoo @@ -6,6 +6,6 @@ RUN export FEATURES="-ipc-sandbox -network-sandbox -pid-sandbox -sandbox -usersa emerge --sync && \ eselect news read --quiet new 1>/dev/null 2>&1 && \ emerge --verbose --update --deep --with-bdeps=y --backtrack=30 --newuse @world && \ - USE="wayland gtk3 gtk -doc X pulseaudio minimal" emerge dev-vcs/git dev-libs/wayland dev-libs/wayland-protocols =dev-cpp/gtkmm-3.24.6 x11-libs/libxkbcommon \ + USE="wayland gtk3 gtk -doc X pulseaudio minimal" emerge dev-vcs/git dev-libs/wayland dev-libs/wayland-protocols dev-cpp/gtkmm:3.0 x11-libs/libxkbcommon \ x11-libs/gtk+:3 dev-libs/libdbusmenu dev-libs/libnl sys-power/upower media-libs/libpulse dev-libs/libevdev media-libs/libmpdclient \ media-sound/sndio gui-libs/gtk-layer-shell app-text/scdoc media-sound/playerctl dev-libs/iniparser sci-libs/fftw From d4f61ad2717aa31ab2bf21e0b0175c5726f4ff8a Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 21 Jun 2025 16:05:00 -0400 Subject: [PATCH 085/104] ci: allow manual triggering of docker workflow --- .github/workflows/docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 66c465ba..c84b3c29 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,6 +1,7 @@ name: Build and Push Docker Image on: + workflow_dispatch: schedule: # run every night at midnight - cron: '0 0 * * *' @@ -8,7 +9,7 @@ on: jobs: build-and-push: runs-on: ubuntu-latest - if: github.repository == 'Alexays/Waybar' + if: github.event_name != 'schedule' || github.repository == 'Alexays/Waybar' strategy: fail-fast: false # don't fail the other jobs if one of the images fails to build matrix: From 84bd0d452ef80ade073632982081f519bb90c2d3 Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 21 Jun 2025 16:05:00 -0400 Subject: [PATCH 086/104] ci: run the docker workflow monthly instead of daily Rebuilding the gentoo docker image daily is most definitely going to bust through the free CI tier limits. --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c84b3c29..0e7e2944 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,8 +3,8 @@ name: Build and Push Docker Image on: workflow_dispatch: schedule: - # run every night at midnight - - cron: '0 0 * * *' + # run monthly + - cron: '0 0 1 * *' jobs: build-and-push: From e4dd2ecc5a2ee8752b4ce664037aa7dee38501a9 Mon Sep 17 00:00:00 2001 From: peelz Date: Sun, 22 Jun 2025 00:50:25 -0400 Subject: [PATCH 087/104] refactor: avoid namespace pollution in util/date.hpp --- include/modules/clock.hpp | 44 +++++++++++++++++++-------------------- include/util/date.hpp | 4 +--- src/modules/clock.cpp | 9 ++++---- test/utils/date.cpp | 2 ++ 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index 40b4f80e..e34b7a8e 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -38,39 +38,39 @@ class Clock final : public ALabel { 5 - tooltip-format */ std::map fmtMap_; - uint cldMonCols_{3}; // calendar count month columns - int cldWnLen_{3}; // calendar week number length - const int cldMonColLen_{20}; // calendar month column length - WS cldWPos_{WS::HIDDEN}; // calendar week side to print - months cldCurrShift_{0}; // calendar months shift - int cldShift_{1}; // calendar months shift factor - year_month_day cldYearShift_; // calendar Year mode. Cached ymd - std::string cldYearCached_; // calendar Year mode. Cached calendar - year_month cldMonShift_; // calendar Month mode. Cached ym - std::string cldMonCached_; // calendar Month mode. Cached calendar - day cldBaseDay_{0}; // calendar Cached day. Is used when today is changing(midnight) - std::string cldText_{""}; // calendar text to print + uint cldMonCols_{3}; // calendar count month columns + int cldWnLen_{3}; // calendar week number length + const int cldMonColLen_{20}; // calendar month column length + WS cldWPos_{WS::HIDDEN}; // calendar week side to print + date::months cldCurrShift_{0}; // calendar months shift + int cldShift_{1}; // calendar months shift factor + date::year_month_day cldYearShift_; // calendar Year mode. Cached ymd + std::string cldYearCached_; // calendar Year mode. Cached calendar + date::year_month cldMonShift_; // calendar Month mode. Cached ym + std::string cldMonCached_; // calendar Month mode. Cached calendar + date::day cldBaseDay_{0}; // calendar Cached day. Is used when today is changing(midnight) + std::string cldText_{""}; // calendar text to print CldMode cldMode_{CldMode::MONTH}; - auto get_calendar(const year_month_day& today, const year_month_day& ymd, const time_zone* tz) - -> const std::string; + auto get_calendar(const date::year_month_day& today, const date::year_month_day& ymd, + const date::time_zone* tz) -> const std::string; // get local time zone - auto local_zone() -> const time_zone*; + auto local_zone() -> const date::time_zone*; // time zoned time in tooltip - const bool tzInTooltip_; // if need to print time zones text - std::vector tzList_; // time zones list - int tzCurrIdx_; // current time zone index for tzList_ - std::string tzText_{""}; // time zones text to print + const bool tzInTooltip_; // if need to print time zones text + std::vector tzList_; // time zones list + int tzCurrIdx_; // current time zone index for tzList_ + std::string tzText_{""}; // time zones text to print util::SleeperThread thread_; // ordinal date in tooltip const bool ordInTooltip_; std::string ordText_{""}; - auto get_ordinal_date(const year_month_day& today) -> std::string; + auto get_ordinal_date(const date::year_month_day& today) -> std::string; - auto getTZtext(sys_seconds now) -> std::string; - auto first_day_of_week() -> weekday; + auto getTZtext(date::sys_seconds now) -> std::string; + auto first_day_of_week() -> date::weekday; // Module actions void cldModeSwitch(); void cldShift_up(); diff --git a/include/util/date.hpp b/include/util/date.hpp index a467cc56..d8653faf 100644 --- a/include/util/date.hpp +++ b/include/util/date.hpp @@ -15,7 +15,7 @@ namespace date { #if HAVE_CHRONO_TIMEZONES using namespace std::chrono; -using namespace std; +using std::format; #else using system_clock = std::chrono::system_clock; @@ -73,5 +73,3 @@ struct fmt::formatter> { } }; #endif - -using namespace date; diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index f00d79fc..42c52dfd 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -16,6 +16,7 @@ #include #endif +using namespace date; namespace fmt_lib = waybar::util::date::format; waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) @@ -349,9 +350,9 @@ auto waybar::modules::Clock::get_calendar(const year_month_day& today, const yea m_locale_, fmtMap_[4], fmt_lib::make_format_args( (line == 2) - ? static_cast( + ? static_cast( zoned_seconds{tz, local_days{ymTmp / 1}}) - : static_cast(zoned_seconds{ + : static_cast(zoned_seconds{ tz, local_days{cldGetWeekForLine(ymTmp, firstdow, line)}}))) << ' '; } else @@ -372,9 +373,9 @@ auto waybar::modules::Clock::get_calendar(const year_month_day& today, const yea << fmt_lib::vformat( m_locale_, fmtMap_[4], fmt_lib::make_format_args( - (line == 2) ? static_cast( + (line == 2) ? static_cast( zoned_seconds{tz, local_days{ymTmp / 1}}) - : static_cast( + : static_cast( zoned_seconds{tz, local_days{cldGetWeekForLine( ymTmp, firstdow, line)}}))); else diff --git a/test/utils/date.cpp b/test/utils/date.cpp index d317f98a..576a4799 100644 --- a/test/utils/date.cpp +++ b/test/utils/date.cpp @@ -18,8 +18,10 @@ return #endif +using namespace date; using namespace std::literals::chrono_literals; namespace fmt_lib = waybar::util::date::format; + /* * Check that the date/time formatter with locale and timezone support is working as expected. */ From 25f432b0ceb8e89321f7be3b07e779176e3cb049 Mon Sep 17 00:00:00 2001 From: peelz Date: Sun, 22 Jun 2025 00:50:25 -0400 Subject: [PATCH 088/104] refactor: avoid Gio namespace pollution --- include/util/portal.hpp | 4 +--- src/util/portal.cpp | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/util/portal.hpp b/include/util/portal.hpp index 23619169..bff74b11 100644 --- a/include/util/portal.hpp +++ b/include/util/portal.hpp @@ -6,14 +6,12 @@ namespace waybar { -using namespace Gio; - enum class Appearance { UNKNOWN = 0, DARK = 1, LIGHT = 2, }; -class Portal : private DBus::Proxy { +class Portal : private Gio::DBus::Proxy { public: Portal(); void refreshAppearance(); diff --git a/src/util/portal.cpp b/src/util/portal.cpp index 5874871b..6df2a6b6 100644 --- a/src/util/portal.cpp +++ b/src/util/portal.cpp @@ -17,8 +17,6 @@ static constexpr const char* PORTAL_NAMESPACE = "org.freedesktop.appearance"; static constexpr const char* PORTAL_KEY = "color-scheme"; } // namespace waybar -using namespace Gio; - auto fmt::formatter::format(waybar::Appearance c, format_context& ctx) const { string_view name; switch (c) { @@ -36,8 +34,8 @@ auto fmt::formatter::format(waybar::Appearance c, format_con } waybar::Portal::Portal() - : DBus::Proxy(DBus::Connection::get_sync(DBus::BusType::BUS_TYPE_SESSION), PORTAL_BUS_NAME, - PORTAL_OBJ_PATH, PORTAL_INTERFACE), + : Gio::DBus::Proxy(Gio::DBus::Connection::get_sync(Gio::DBus::BusType::BUS_TYPE_SESSION), + PORTAL_BUS_NAME, PORTAL_OBJ_PATH, PORTAL_INTERFACE), currentMode(Appearance::UNKNOWN) { refreshAppearance(); }; From 8daaad1e1396d8084a2f05c9cd8cefca71e2ba60 Mon Sep 17 00:00:00 2001 From: peelz Date: Sun, 22 Jun 2025 00:56:56 -0400 Subject: [PATCH 089/104] fix: don't use c++20 chrono literals Unfortunately we can't use these yet because the freebsd build (clang) still uses HowardHinnant/date, which doesn't provide literal suffixes. --- src/modules/clock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index f00d79fc..a1bd1d1f 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -25,7 +25,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) m_tooltip_{new Gtk::Label()}, cldInTooltip_{m_tlpFmt_.find("{" + kCldPlaceholder + "}") != std::string::npos}, cldYearShift_{January / 1 / 1900}, - cldMonShift_{1900y / January}, + cldMonShift_{year(1900) / January}, tzInTooltip_{m_tlpFmt_.find("{" + kTZPlaceholder + "}") != std::string::npos}, tzCurrIdx_{0}, ordInTooltip_{m_tlpFmt_.find("{" + kOrdPlaceholder + "}") != std::string::npos} { From 0bdea1e46fa9ced094fb6d0c6ab0df57e80f0471 Mon Sep 17 00:00:00 2001 From: peelz Date: Sun, 22 Jun 2025 01:02:53 -0400 Subject: [PATCH 090/104] ci: bump FreeBSD to 14.3 --- .github/workflows/freebsd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index ca0dcbc8..e45a8dc4 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -21,7 +21,7 @@ jobs: LDFLAGS: '-L/usr/local/lib' with: operating_system: freebsd - version: "14.1" + version: "14.3" environment_variables: CPPFLAGS LDFLAGS sync_files: runner-to-vm run: | From bef539e4de9a3ea5c62c2de34b88d55f13345fd1 Mon Sep 17 00:00:00 2001 From: Alexis Rouillard Date: Sun, 22 Jun 2025 09:30:46 +0200 Subject: [PATCH 091/104] Update privacy_item.cpp --- src/modules/privacy/privacy_item.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/privacy/privacy_item.cpp b/src/modules/privacy/privacy_item.cpp index 536c9180..6424da9e 100644 --- a/src/modules/privacy/privacy_item.cpp +++ b/src/modules/privacy/privacy_item.cpp @@ -96,7 +96,6 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac } void PrivacyItem::update_tooltip() { - spdlog::trace("update privacy tooltip"); // Removes all old nodes for (auto *child : tooltip_window.get_children()) { tooltip_window.remove(*child); From d6b6158ae97651cb556ad388b365069843877ed0 Mon Sep 17 00:00:00 2001 From: Alexis Rouillard Date: Sun, 22 Jun 2025 09:42:14 +0200 Subject: [PATCH 092/104] Update custom.cpp --- src/modules/custom.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 3179e2bc..0220e348 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -35,8 +35,7 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { - for( int i : this->pid_children_ ) - { + for (int i: this->pid_children_) { int status; waitpid(i, &status, 0); } From 286cff2e3daf4234cce8f3f0b72ad38ee1b68249 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Jun 2025 09:44:35 +0200 Subject: [PATCH 093/104] fix: lint --- src/AIconLabel.cpp | 5 ++--- src/modules/hyprland/submap.cpp | 2 +- src/modules/mpris/mpris.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/AIconLabel.cpp b/src/AIconLabel.cpp index 130ba60c..79cd5fe1 100644 --- a/src/AIconLabel.cpp +++ b/src/AIconLabel.cpp @@ -22,8 +22,7 @@ AIconLabel::AIconLabel(const Json::Value &config, const std::string &name, const if (config_["rotate"].isUInt()) { rot = config["rotate"].asUInt() % 360; - if ((rot % 90) != 00) - rot = 0; + if ((rot % 90) != 00) rot = 0; rot /= 90; } @@ -42,7 +41,7 @@ AIconLabel::AIconLabel(const Json::Value &config, const std::string &name, const else swap_icon_label = config_["swap-icon-label"].asBool(); - if ( (rot == 0 || rot == 3) ^ swap_icon_label ) { + if ((rot == 0 || rot == 3) ^ swap_icon_label) { box_.add(image_); box_.add(label_); } else { diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index d1060447..a2b3f460 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -68,7 +68,7 @@ void Submap::onEvent(const std::string& ev) { return; } - auto submapName = ev.substr(ev.find_first_of('>') + 2 ); + auto submapName = ev.substr(ev.find_first_of('>') + 2); if (!submap_.empty()) { label_.get_style_context()->remove_class(submap_); diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 47bb9c05..8782b9b2 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -500,8 +500,10 @@ auto Mpris::getPlayerInfo() -> std::optional { // > get the list of players [..] in order of activity // https://github.com/altdesktop/playerctl/blob/b19a71cb9dba635df68d271bd2b3f6a99336a223/playerctl/playerctl-common.c#L248-L249 players = g_list_first(players); - if (players) player_name = static_cast(players->data)->name; - else return std::nullopt; // no players found, hide the widget + if (players) + player_name = static_cast(players->data)->name; + else + return std::nullopt; // no players found, hide the widget } if (std::any_of(ignored_players_.begin(), ignored_players_.end(), From 373fd77f7a89554fc254ac7825813c866dd30605 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Jun 2025 09:54:41 +0200 Subject: [PATCH 094/104] chore: update cross-platform-actions/action --- .github/workflows/freebsd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index e45a8dc4..5b1515b2 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Test in FreeBSD VM - uses: cross-platform-actions/action@v0.25.0 + uses: cross-platform-actions/action@v0.28.0 timeout-minutes: 180 env: CPPFLAGS: '-isystem/usr/local/include' From df138e12c4dfe3f4f2a8d97cbc158283b0d77267 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Jun 2025 09:55:57 +0200 Subject: [PATCH 095/104] fix: compat freebsd --- .github/workflows/freebsd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 5b1515b2..b9114c31 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -21,7 +21,7 @@ jobs: LDFLAGS: '-L/usr/local/lib' with: operating_system: freebsd - version: "14.3" + version: "14.2" environment_variables: CPPFLAGS LDFLAGS sync_files: runner-to-vm run: | From ee91d18ad9a7eee1305b5018d2010e44327bde91 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Jun 2025 10:01:36 +0200 Subject: [PATCH 096/104] fix: lint --- include/modules/gps.hpp | 36 ++++++++++++++-------------- src/modules/custom.cpp | 2 +- src/modules/gps.cpp | 37 ++++++++++++++--------------- src/modules/hyprland/language.cpp | 5 ++-- src/modules/hyprland/workspaces.cpp | 12 ++++------ src/modules/mpris/mpris.cpp | 10 ++++---- src/modules/niri/workspaces.cpp | 1 - src/modules/wlr/taskbar.cpp | 2 +- 8 files changed, 50 insertions(+), 55 deletions(-) diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index 3701634b..80df12ba 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -14,27 +14,27 @@ namespace waybar::modules { - class Gps : public ALabel { - public: - Gps(const std::string&, const Json::Value&); - virtual ~Gps(); - auto update() -> void override; +class Gps : public ALabel { + public: + Gps(const std::string&, const Json::Value&); + virtual ~Gps(); + auto update() -> void override; - private: - #ifdef WANT_RFKILL - util::Rfkill rfkill_; - #endif - const std::string getFixModeName() const; - const std::string getFixModeString() const; + private: +#ifdef WANT_RFKILL + util::Rfkill rfkill_; +#endif + const std::string getFixModeName() const; + const std::string getFixModeString() const; - const std::string getFixStatusString() const; + const std::string getFixStatusString() const; - util::SleeperThread thread_, gps_thread_; - gps_data_t gps_data_; - std::string state_; + util::SleeperThread thread_, gps_thread_; + gps_data_t gps_data_; + std::string state_; - bool hideDisconnected = true; - bool hideNoFix = false; - }; + bool hideDisconnected = true; + bool hideNoFix = false; +}; } // namespace waybar::modules diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 0220e348..db5c6db3 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -35,7 +35,7 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { - for (int i: this->pid_children_) { + for (int i : this->pid_children_) { int status; waitpid(i, &status, 0); } diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index f075b44c..a7bab659 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -1,4 +1,5 @@ #include "modules/gps.hpp" + #include #include @@ -15,15 +16,15 @@ #endif namespace { - using namespace waybar::util; - constexpr const char *DEFAULT_FORMAT = "{mode}"; +using namespace waybar::util; +constexpr const char* DEFAULT_FORMAT = "{mode}"; } // namespace - waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) -: ALabel(config, "gps", id, "{}", 5) + : ALabel(config, "gps", id, "{}", 5) #ifdef WANT_RFKILL -,rfkill_{RFKILL_TYPE_GPS} + , + rfkill_{RFKILL_TYPE_GPS} #endif { thread_ = [this] { @@ -66,9 +67,9 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) } }; - #ifdef WANT_RFKILL +#ifdef WANT_RFKILL rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Gps::update))); - #endif +#endif } const std::string waybar::modules::Gps::getFixModeName() const { @@ -80,9 +81,9 @@ const std::string waybar::modules::Gps::getFixModeName() const { case MODE_3D: return "fix-3d"; default: - #ifdef WANT_RFKILL +#ifdef WANT_RFKILL if (rfkill_.getState()) return "disabled"; - #endif +#endif return "disconnected"; } } @@ -120,18 +121,19 @@ const std::string waybar::modules::Gps::getFixStatusString() const { return "PPS Fix"; default: - #ifdef WANT_RFKILL +#ifdef WANT_RFKILL if (rfkill_.getState()) return "Disabled"; - #endif +#endif return "Unknown"; } } auto waybar::modules::Gps::update() -> void { - sleep(0); // Wait for gps status change + sleep(0); // Wait for gps status change - if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) { + if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || + (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) { event_box_.set_visible(false); return; } @@ -163,7 +165,6 @@ auto waybar::modules::Gps::update() -> void { state_ = state; } - auto format = format_; fmt::dynamic_format_arg_store store; @@ -191,7 +192,7 @@ auto waybar::modules::Gps::update() -> void { auto text = fmt::vformat(format, store); - if (tooltipEnabled()) { + if (tooltipEnabled()) { if (tooltip_format.empty() && config_["tooltip-format"].isString()) { tooltip_format = config_["tooltip-format"].asString(); } @@ -205,13 +206,11 @@ auto waybar::modules::Gps::update() -> void { } } label_.set_markup(text); -// Call parent update -ALabel::update(); + // Call parent update + ALabel::update(); } waybar::modules::Gps::~Gps() { gps_stream(&gps_data_, WATCH_DISABLE, NULL); gps_close(&gps_data_); } - - diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 1dbdfeba..2989926a 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -66,9 +66,10 @@ auto Language::update() -> void { void Language::onEvent(const std::string& ev) { std::lock_guard lg(mutex_); std::string kbName(begin(ev) + ev.find_last_of('>') + 1, begin(ev) + ev.find_first_of(',')); - + // Last comma before variants parenthesis, eg: - // activelayout>>micro-star-int'l-co.,-ltd.-msi-gk50-elite-gaming-keyboard,English (US, intl., with dead keys) + // activelayout>>micro-star-int'l-co.,-ltd.-msi-gk50-elite-gaming-keyboard,English (US, intl., + // with dead keys) std::string beforParenthesis(begin(ev), begin(ev) + ev.find_last_of('(')); auto layoutName = ev.substr(beforParenthesis.find_last_of(',') + 1); diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index b5801759..bb03f707 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -791,25 +791,21 @@ void Workspaces::sortSpecialCentered() { size_t center = normalWorkspaces.size() / 2; - m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(normalWorkspaces.begin()), + m_workspaces.insert(m_workspaces.end(), std::make_move_iterator(normalWorkspaces.begin()), std::make_move_iterator(normalWorkspaces.begin() + center)); - m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(specialWorkspaces.begin()), + m_workspaces.insert(m_workspaces.end(), std::make_move_iterator(specialWorkspaces.begin()), std::make_move_iterator(specialWorkspaces.end())); m_workspaces.insert(m_workspaces.end(), std::make_move_iterator(normalWorkspaces.begin() + center), std::make_move_iterator(normalWorkspaces.end())); - - m_workspaces.insert(m_workspaces.end(), - std::make_move_iterator(hiddenWorkspaces.begin()), + + m_workspaces.insert(m_workspaces.end(), std::make_move_iterator(hiddenWorkspaces.begin()), std::make_move_iterator(hiddenWorkspaces.end())); } void Workspaces::sortWorkspaces() { - std::ranges::sort( // m_workspaces, [&](std::unique_ptr &a, std::unique_ptr &b) { // Helper comparisons diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 30dd31ea..2b345fc5 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -610,11 +610,11 @@ bool Mpris::handleToggle(GdkEventButton* const& e) { // Command pattern: encapsulate each button's action const ButtonAction actions[] = { - {1, "on-click", [&]() { playerctl_player_play_pause(player, &error); }}, - {2, "on-click-middle", [&]() { playerctl_player_previous(player, &error); }}, - {3, "on-click-right", [&]() { playerctl_player_next(player, &error); }}, - {8, "on-click-backward", [&]() { playerctl_player_previous(player, &error); }}, - {9, "on-click-forward", [&]() { playerctl_player_next(player, &error); }}, + {1, "on-click", [&]() { playerctl_player_play_pause(player, &error); }}, + {2, "on-click-middle", [&]() { playerctl_player_previous(player, &error); }}, + {3, "on-click-right", [&]() { playerctl_player_next(player, &error); }}, + {8, "on-click-backward", [&]() { playerctl_player_previous(player, &error); }}, + {9, "on-click-forward", [&]() { playerctl_player_next(player, &error); }}, }; for (const auto& action : actions) { diff --git a/src/modules/niri/workspaces.cpp b/src/modules/niri/workspaces.cpp index 73f81dc0..7dfc0b35 100644 --- a/src/modules/niri/workspaces.cpp +++ b/src/modules/niri/workspaces.cpp @@ -172,7 +172,6 @@ std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) const auto &icons = config_["format-icons"]; if (!icons) return value; - if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString(); if (ws["active_window_id"].isNull() && icons["empty"]) return icons["empty"].asString(); diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 5e497516..589638e8 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -712,7 +712,7 @@ void Task::update() { fmt::format(fmt::runtime(format_tooltip_), fmt::arg("title", title), fmt::arg("name", name), fmt::arg("app_id", app_id), fmt::arg("state", state_string()), fmt::arg("short_state", state_string(true))); - + txt = waybar::util::rewriteString(txt, config_["rewrite"]); if (markup) From 35d5203b4e774acf13b91d2c49e45db0d2776047 Mon Sep 17 00:00:00 2001 From: Alexis Rouillard Date: Sun, 22 Jun 2025 12:24:22 +0200 Subject: [PATCH 097/104] Revert "Bluetooth module: fetch battery percentage from upower if not found from bluez" --- src/modules/bluetooth.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 85486cc0..06475a2e 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -1,7 +1,6 @@ #include "modules/bluetooth.hpp" #include -#include #include #include @@ -393,30 +392,6 @@ auto waybar::modules::Bluetooth::getDeviceBatteryPercentage(GDBusObject* object) return battery_percentage; } - GDBusProxy* proxy_device = G_DBUS_PROXY(g_dbus_object_get_interface(object, "org.bluez.Device1")); - if (proxy_device != nullptr) { - auto serial = getStringProperty(proxy_device, "Address"); - std::transform(serial.begin(), serial.end(), serial.begin(), - [](unsigned char c) { return std::tolower(c); }); - - auto* client = up_client_new(); - if (client == nullptr) return std::nullopt; - - auto* devices = up_client_get_devices2(client); - UpDevice* dev; - char* udev_serial; - double percentage; - for (int i = 0; i < devices->len; i++) { - dev = (UpDevice*)g_ptr_array_index(devices, i); - g_object_get(dev, "serial", &udev_serial, nullptr); - if (serial == udev_serial) { - g_object_get(dev, "percentage", &percentage, nullptr); - g_ptr_array_unref(devices); - g_object_unref(client); - return percentage; - } - } - } return std::nullopt; } From 2b9601b9a44092b740448ee691a923573f1597ed Mon Sep 17 00:00:00 2001 From: yuannan <1994977-yuannan@users.noreply.gitlab.com> Date: Sun, 22 Jun 2025 13:15:18 +0100 Subject: [PATCH 098/104] added IPC fix and Nix GPS fix --- include/modules/hyprland/backend.hpp | 1 + nix/default.nix | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/modules/hyprland/backend.hpp b/include/modules/hyprland/backend.hpp index cfd0b258..d9f16526 100644 --- a/include/modules/hyprland/backend.hpp +++ b/include/modules/hyprland/backend.hpp @@ -46,4 +46,5 @@ class IPC { }; inline bool modulesReady = false; +inline std::unique_ptr gIPC; }; // namespace waybar::modules::hyprland diff --git a/nix/default.nix b/nix/default.nix index 4cfd75c0..2c97c20d 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -30,8 +30,12 @@ in # nixpkgs checks version, no need when building locally nativeInstallCheckInputs = [ ]; - buildInputs = (builtins.filter (p: p.pname != "wireplumber") oldAttrs.buildInputs) ++ [ + buildInputs = (builtins.filter (p: + p.pname != "wireplumber" && + p.pname != "gps" + ) oldAttrs.buildInputs) ++ [ pkgs.wireplumber + pkgs.gpsd ]; postUnpack = '' From 0fcda9afa519eb84deda68c051f7938a6c6bdbce Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 23 Jun 2025 09:10:48 +0200 Subject: [PATCH 099/104] chore: 0.13.0 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9481cc93..8832a55e 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'waybar', 'cpp', 'c', - version: '0.12.0', + version: '0.13.0', license: 'MIT', meson_version: '>= 0.59.0', default_options : [ From 460b19ba1b83b873795e2e65ce60efadc7a3a906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Maciulevi=C4=8Dius?= Date: Thu, 26 Jun 2025 20:34:18 +0300 Subject: [PATCH 100/104] Fix default icon in tray module --- src/util/gtk_icon.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/gtk_icon.cpp b/src/util/gtk_icon.cpp index 4b4d3d69..73f77284 100644 --- a/src/util/gtk_icon.cpp +++ b/src/util/gtk_icon.cpp @@ -25,6 +25,10 @@ Glib::RefPtr DefaultGtkIconThemeWrapper::load_icon( auto icon_info = default_theme->lookup_icon(name, tmp_size, flags); + if (icon_info == nullptr) { + return default_theme->load_icon(name, tmp_size, flags); + } + if (style.get() == nullptr) { return icon_info.load_icon(); } From 7505e2c3f3cc92bdbc1ef3a2650a2c32170f8b9e Mon Sep 17 00:00:00 2001 From: mexanoz Date: Fri, 27 Jun 2025 20:54:38 +0500 Subject: [PATCH 101/104] fix hyprland/language layout parsing --- src/modules/hyprland/language.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 2989926a..3f141bbd 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -70,8 +70,14 @@ void Language::onEvent(const std::string& ev) { // Last comma before variants parenthesis, eg: // activelayout>>micro-star-int'l-co.,-ltd.-msi-gk50-elite-gaming-keyboard,English (US, intl., // with dead keys) - std::string beforParenthesis(begin(ev), begin(ev) + ev.find_last_of('(')); - auto layoutName = ev.substr(beforParenthesis.find_last_of(',') + 1); + std::string beforeParenthesis; + auto parenthesisPos = ev.find_last_of('('); + if (parenthesisPos == std::string::npos) { + beforeParenthesis = ev; + } else { + beforeParenthesis = std::string(begin(ev), begin(ev) + parenthesisPos); + } + auto layoutName = ev.substr(beforeParenthesis.find_last_of(',') + 1); if (config_.isMember("keyboard-name") && kbName != config_["keyboard-name"].asString()) return; // ignore From e7a4bafede17a8daeed6014b235226cc8558ae87 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Jul 2025 00:14:02 +0000 Subject: [PATCH 102/104] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/96ec055edbe5ee227f28cdbc3f1ddf1df5965102?narHash=sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg%3D' (2025-05-28) → 'github:NixOS/nixpkgs/30e2e2857ba47844aa71991daa6ed1fc678bcbb7?narHash=sha256-krGXKxvkBhnrSC/kGBmg5MyupUUT5R6IBCLEzx9jhMM%3D' (2025-06-27) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 34545ed4..5c08338e 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1748460289, - "narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=", + "lastModified": 1751011381, + "narHash": "sha256-krGXKxvkBhnrSC/kGBmg5MyupUUT5R6IBCLEzx9jhMM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102", + "rev": "30e2e2857ba47844aa71991daa6ed1fc678bcbb7", "type": "github" }, "original": { From b6c13ba58be6eb68e446c4bda9cf981ab20a5b7d Mon Sep 17 00:00:00 2001 From: peelz Date: Tue, 1 Jul 2025 10:37:31 -0400 Subject: [PATCH 103/104] fix: 'ethernet' network state should have precedence over 'disabled' --- src/modules/network.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 955f9f1d..cc096f72 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -272,11 +272,9 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { #ifdef WANT_RFKILL - if (rfkill_.getState()) return "disabled"; + if (rfkill_.getState() && ifid_ == -1) return "disabled"; #endif - if (ifid_ == -1) { - return "disconnected"; - } + if (ifid_ == -1) return "disconnected"; if (!carrier_) return "disconnected"; if (ipaddr_.empty() && ipaddr6_.empty()) return "linked"; if (essid_.empty()) return "ethernet"; From 10c116e54a3efa7f2956b84017d9eabecffceff2 Mon Sep 17 00:00:00 2001 From: tpaau-17DB Date: Fri, 4 Jul 2025 19:02:10 +0200 Subject: [PATCH 104/104] Change default tooltip for the battery module. --- src/modules/battery.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 44481448..32488d53 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -687,8 +687,11 @@ auto waybar::modules::Battery::update() -> void { std::string tooltip_text_default; std::string tooltip_format = "{timeTo}"; if (time_remaining != 0) { - std::string time_to = std::string("Time to ") + ((time_remaining > 0) ? "empty" : "full"); - tooltip_text_default = time_to + ": " + time_remaining_formatted; + if (time_remaining > 0) { + tooltip_text_default = std::string("Empty in ") + time_remaining_formatted; + } else { + tooltip_text_default = std::string("Full in ") + time_remaining_formatted; + } } else { tooltip_text_default = status_pretty; }