mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 22:52:30 +02:00
Pass WAYBAR_OUTPUT_NAME environment variable to custom exec scripts
Signed-off-by: Jo De Boeck <deboeck.jo@gmail.com>
This commit is contained in:
@ -14,7 +14,7 @@ namespace waybar::modules {
|
||||
|
||||
class Custom : public ALabel {
|
||||
public:
|
||||
Custom(const std::string&, const std::string&, const Json::Value&);
|
||||
Custom(const std::string&, const std::string&, const Json::Value&, const std::string&);
|
||||
virtual ~Custom();
|
||||
auto update() -> void override;
|
||||
void refresh(int /*signal*/) override;
|
||||
@ -30,6 +30,7 @@ class Custom : public ALabel {
|
||||
bool handleToggle(GdkEventButton* const& e) override;
|
||||
|
||||
const std::string name_;
|
||||
const std::string output_name_;
|
||||
std::string text_;
|
||||
std::string id_;
|
||||
std::string alt_;
|
||||
|
@ -66,7 +66,7 @@ inline int close(FILE* fp, pid_t pid) {
|
||||
return stat;
|
||||
}
|
||||
|
||||
inline FILE* open(const std::string& cmd, int& pid) {
|
||||
inline FILE* open(const std::string& cmd, int& pid, const std::string& output_name) {
|
||||
if (cmd == "") return nullptr;
|
||||
int fd[2];
|
||||
// Open the pipe with the close-on-exec flag set, so it will not be inherited
|
||||
@ -109,6 +109,9 @@ inline FILE* open(const std::string& cmd, int& pid) {
|
||||
::close(fd[0]);
|
||||
dup2(fd[1], 1);
|
||||
setpgid(child_pid, child_pid);
|
||||
if (output_name != "") {
|
||||
setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1);
|
||||
}
|
||||
execlp("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
|
||||
exit(0);
|
||||
} else {
|
||||
@ -118,9 +121,9 @@ inline FILE* open(const std::string& cmd, int& pid) {
|
||||
return fdopen(fd[0], "r");
|
||||
}
|
||||
|
||||
inline struct res exec(const std::string& cmd) {
|
||||
inline struct res exec(const std::string& cmd, const std::string& output_name) {
|
||||
int pid;
|
||||
auto fp = command::open(cmd, pid);
|
||||
auto fp = command::open(cmd, pid, output_name);
|
||||
if (!fp) return {-1, ""};
|
||||
auto output = command::read(fp);
|
||||
auto stat = command::close(fp, pid);
|
||||
@ -129,7 +132,7 @@ inline struct res exec(const std::string& cmd) {
|
||||
|
||||
inline struct res execNoRead(const std::string& cmd) {
|
||||
int pid;
|
||||
auto fp = command::open(cmd, pid);
|
||||
auto fp = command::open(cmd, pid, "");
|
||||
if (!fp) return {-1, ""};
|
||||
auto stat = command::close(fp, pid);
|
||||
return {WEXITSTATUS(stat), ""};
|
||||
|
Reference in New Issue
Block a user