mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
d7d1ebd736
This patch adds 3 new configuration options applicable for subclasses of ALabel. The options can be used to execute user defined code in response to the 3 mouse events: * on-click: The left mouse button click * on-scroll-up * on-scroll-down This patch also modifies the behaviour of the format-alt toggle such that when the on-click event is configured, format-alt is toggled on any mouse click other than left click. When on-click is not defined, any mouse button would toggle format-alt. Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
53 lines
1.0 KiB
C++
53 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <sys/wait.h>
|
|
|
|
namespace waybar::util::command {
|
|
|
|
struct res {
|
|
int exit_code;
|
|
std::string out;
|
|
};
|
|
|
|
inline struct res exec(const std::string cmd)
|
|
{
|
|
FILE* fp(popen(cmd.c_str(), "r"));
|
|
if (!fp) {
|
|
return { -1, "" };
|
|
}
|
|
|
|
std::array<char, 128> buffer = {0};
|
|
std::string output;
|
|
while (feof(fp) == 0) {
|
|
if (fgets(buffer.data(), 128, fp) != nullptr) {
|
|
output += buffer.data();
|
|
}
|
|
}
|
|
|
|
// Remove last newline
|
|
if (!output.empty() && output[output.length()-1] == '\n') {
|
|
output.erase(output.length()-1);
|
|
}
|
|
int exit_code = WEXITSTATUS(pclose(fp));
|
|
return {exit_code, output};
|
|
}
|
|
|
|
inline bool forkExec(std::string cmd) {
|
|
if (cmd == "") return true;
|
|
|
|
printf("fork exec command %s\n", cmd.c_str());
|
|
int32_t pid = fork();
|
|
|
|
if (pid < 0) {
|
|
printf("Unable to exec cmd %s, error %s", cmd.c_str(), strerror(errno));
|
|
return false;
|
|
}
|
|
|
|
// Child executes the command
|
|
if (!pid) execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace waybar::util::command
|