feat(clock): Add action to execute external command
This commit is contained in:
@@ -80,6 +80,7 @@ class Clock final : public ALabel {
|
|||||||
void cldShift_reset();
|
void cldShift_reset();
|
||||||
void tz_up();
|
void tz_up();
|
||||||
void tz_down();
|
void tz_down();
|
||||||
|
void action_exec(const std::string& action);
|
||||||
// Module Action Map
|
// Module Action Map
|
||||||
static inline std::map<const std::string, void (waybar::modules::Clock::* const)()> actionMap_{
|
static inline std::map<const std::string, void (waybar::modules::Clock::* const)()> actionMap_{
|
||||||
{"mode", &waybar::modules::Clock::cldModeSwitch},
|
{"mode", &waybar::modules::Clock::cldModeSwitch},
|
||||||
@@ -88,6 +89,8 @@ class Clock final : public ALabel {
|
|||||||
{"shift_reset", &waybar::modules::Clock::cldShift_reset},
|
{"shift_reset", &waybar::modules::Clock::cldShift_reset},
|
||||||
{"tz_up", &waybar::modules::Clock::tz_up},
|
{"tz_up", &waybar::modules::Clock::tz_up},
|
||||||
{"tz_down", &waybar::modules::Clock::tz_down}};
|
{"tz_down", &waybar::modules::Clock::tz_down}};
|
||||||
|
static inline std::map<const std::string, void (waybar::modules::Clock::* const)(const std::string& action)> actionWithArgsMap_{
|
||||||
|
{"exec", &waybar::modules::Clock::action_exec}};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|||||||
@@ -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
|
:[ Switch to the next calendar month/year
|
||||||
|[ *shift_down*
|
|[ *shift_down*
|
||||||
:[ Switch to the previous calendar month/year
|
:[ Switch to the previous calendar month/year
|
||||||
|
|[ *exec <cmd>*
|
||||||
|
:[ Execute the specified command
|
||||||
|
|
||||||
# FORMAT REPLACEMENTS
|
# FORMAT REPLACEMENTS
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "util/command.hpp"
|
||||||
#include "util/ustring_clen.hpp"
|
#include "util/ustring_clen.hpp"
|
||||||
|
|
||||||
#ifdef HAVE_LANGINFO_1STDAY
|
#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 {
|
auto waybar::modules::Clock::doAction(const std::string& name) -> void {
|
||||||
if (actionMap_[name]) {
|
if (actionMap_[name]) {
|
||||||
(this->*actionMap_[name])();
|
(this->*actionMap_[name])();
|
||||||
|
} else if (auto key = name.substr(0, name.find(" ")); actionWithArgsMap_[key]) {
|
||||||
|
(this->*actionWithArgsMap_[key])(name);
|
||||||
} else
|
} else
|
||||||
spdlog::error("Clock. Unsupported action \"{0}\"", name);
|
spdlog::error("Clock. Unsupported action \"{0}\"", name);
|
||||||
}
|
}
|
||||||
@@ -498,6 +501,11 @@ void waybar::modules::Clock::tz_down() {
|
|||||||
if (tzSize == 1) return;
|
if (tzSize == 1) return;
|
||||||
tzCurrIdx_ = (tzCurrIdx_ == 0) ? tzSize - 1 : tzCurrIdx_ - 1;
|
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
|
#ifdef HAVE_LANGINFO_1STDAY
|
||||||
template <auto fn>
|
template <auto fn>
|
||||||
|
|||||||
Reference in New Issue
Block a user