From 5870c4ba0e85911160b04d99793989de2586eefc Mon Sep 17 00:00:00 2001 From: Aksel Lunde Aase Date: Fri, 9 Jan 2026 13:22:48 +0100 Subject: [PATCH 1/2] feat(clock): Add action to execute external command --- include/modules/clock.hpp | 3 +++ man/waybar-clock.5.scd | 2 ++ src/modules/clock.cpp | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index c3548063..4ac91d61 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -80,6 +80,7 @@ class Clock final : public ALabel { void cldShift_reset(); void tz_up(); void tz_down(); + void action_exec(const std::string& action); // Module Action Map static inline std::map actionMap_{ {"mode", &waybar::modules::Clock::cldModeSwitch}, @@ -88,6 +89,8 @@ class Clock final : public ALabel { {"shift_reset", &waybar::modules::Clock::cldShift_reset}, {"tz_up", &waybar::modules::Clock::tz_up}, {"tz_down", &waybar::modules::Clock::tz_down}}; + static inline std::map actionWithArgsMap_{ + {"exec", &waybar::modules::Clock::action_exec}}; }; } // namespace waybar::modules diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index b4b5d5b7..440c3447 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -180,6 +180,8 @@ View all valid format options in *strftime(3)* or have a look https://en.cpprefe :[ Switch to the next calendar month/year |[ *shift_down* :[ Switch to the previous calendar month/year +|[ *exec * +:[ Execute the specified command # FORMAT REPLACEMENTS diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5fe5407b..2bc99764 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -9,6 +9,7 @@ #include #include +#include "util/command.hpp" #include "util/ustring_clen.hpp" #ifdef HAVE_LANGINFO_1STDAY @@ -472,6 +473,8 @@ auto waybar::modules::Clock::local_zone() -> const time_zone* { auto waybar::modules::Clock::doAction(const std::string& name) -> void { if (actionMap_[name]) { (this->*actionMap_[name])(); + } else if (auto key = name.substr(0, name.find(" ")); actionWithArgsMap_[key]) { + (this->*actionWithArgsMap_[key])(name); } else spdlog::error("Clock. Unsupported action \"{0}\"", name); } @@ -498,6 +501,11 @@ void waybar::modules::Clock::tz_down() { if (tzSize == 1) return; tzCurrIdx_ = (tzCurrIdx_ == 0) ? tzSize - 1 : tzCurrIdx_ - 1; } +void waybar::modules::Clock::action_exec(const std::string& action) { + auto cmd = action.substr(strlen("exec ")); + pid_children_.push_back(util::command::forkExec(cmd)); +} + #ifdef HAVE_LANGINFO_1STDAY template From 331fe0e963ea867eb60dde2ebb6c98de6b0a1080 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 3 Jul 2026 23:52:24 +0200 Subject: [PATCH 2/2] Fix clang-format --- include/modules/clock.hpp | 5 +++-- src/modules/clock.cpp | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index 4ac91d61..5fd9df54 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -89,8 +89,9 @@ class Clock final : public ALabel { {"shift_reset", &waybar::modules::Clock::cldShift_reset}, {"tz_up", &waybar::modules::Clock::tz_up}, {"tz_down", &waybar::modules::Clock::tz_down}}; - static inline std::map actionWithArgsMap_{ - {"exec", &waybar::modules::Clock::action_exec}}; + static inline std::map + actionWithArgsMap_{{"exec", &waybar::modules::Clock::action_exec}}; }; } // namespace waybar::modules diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index b92f2264..6050df31 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -550,7 +550,6 @@ void waybar::modules::Clock::action_exec(const std::string& action) { pid_children_.push_back(util::command::forkExec(cmd)); } - #ifdef HAVE_LANGINFO_1STDAY template using deleter_from_fn = std::integral_constant;