mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
ALabel: Add support for configurable mouse events
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>
This commit is contained in:
@ -6,21 +6,28 @@
|
||||
namespace waybar {
|
||||
|
||||
class ALabel : public IModule {
|
||||
public:
|
||||
ALabel(const Json::Value&, const std::string format);
|
||||
virtual ~ALabel() = default;
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string& alt = "");
|
||||
virtual operator Gtk::Widget &();
|
||||
protected:
|
||||
Gtk::EventBox event_box_;
|
||||
Gtk::Label label_;
|
||||
const Json::Value& config_;
|
||||
std::string format_;
|
||||
private:
|
||||
bool handleToggle(GdkEventButton* const& ev);
|
||||
bool alt = false;
|
||||
const std::string default_format_;
|
||||
public:
|
||||
ALabel(const Json::Value&, const std::string format);
|
||||
virtual ~ALabel() = default;
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string& alt = "");
|
||||
virtual operator Gtk::Widget&();
|
||||
|
||||
protected:
|
||||
Gtk::EventBox event_box_;
|
||||
Gtk::Label label_;
|
||||
const Json::Value& config_;
|
||||
std::string format_;
|
||||
std::string button_press_cmd_ = "";
|
||||
std::string scroll_up_cmd_ = "";
|
||||
std::string scroll_down_cmd_ = "";
|
||||
std::mutex mutex_;
|
||||
|
||||
private:
|
||||
bool handleToggle(GdkEventButton* const& ev);
|
||||
bool handleScroll(GdkEventScroll*);
|
||||
bool alt = false;
|
||||
const std::string default_format_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar
|
||||
|
@ -29,7 +29,24 @@ inline struct res exec(const std::string cmd)
|
||||
output.erase(output.length()-1);
|
||||
}
|
||||
int exit_code = WEXITSTATUS(pclose(fp));
|
||||
return { exit_code, output };
|
||||
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
|
||||
|
Reference in New Issue
Block a user