refactor: remove useless tmp variable
parent
0670225e69
commit
9d4048983d
|
@ -18,9 +18,6 @@ class ALabel : public IModule {
|
||||||
Gtk::Label label_;
|
Gtk::Label label_;
|
||||||
const Json::Value& config_;
|
const Json::Value& config_;
|
||||||
std::string format_;
|
std::string format_;
|
||||||
std::string button_press_cmd_ = "";
|
|
||||||
std::string scroll_up_cmd_ = "";
|
|
||||||
std::string scroll_down_cmd_ = "";
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -35,7 +35,6 @@ inline struct res exec(const std::string cmd)
|
||||||
inline bool forkExec(std::string cmd) {
|
inline bool forkExec(std::string cmd) {
|
||||||
if (cmd == "") return true;
|
if (cmd == "") return true;
|
||||||
|
|
||||||
printf("fork exec command %s\n", cmd.c_str());
|
|
||||||
int32_t pid = fork();
|
int32_t pid = fork();
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
|
|
@ -69,7 +69,8 @@
|
||||||
"portable": "",
|
"portable": "",
|
||||||
"car": "",
|
"car": "",
|
||||||
"default": ["", ""]
|
"default": ["", ""]
|
||||||
}
|
},
|
||||||
|
"on-click": "pavucontrol"
|
||||||
},
|
},
|
||||||
"custom/spotify": {
|
"custom/spotify": {
|
||||||
"format": " {}",
|
"format": " {}",
|
||||||
|
|
|
@ -21,28 +21,19 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string format)
|
||||||
|
|
||||||
// configure events' user commands
|
// configure events' user commands
|
||||||
if (config_["on-click"].isString()) {
|
if (config_["on-click"].isString()) {
|
||||||
std::string cmd = config_["on-click"].asString();
|
|
||||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||||
event_box_.signal_button_press_event().connect(
|
event_box_.signal_button_press_event().connect(
|
||||||
sigc::mem_fun(*this, &ALabel::handleToggle));
|
sigc::mem_fun(*this, &ALabel::handleToggle));
|
||||||
|
|
||||||
button_press_cmd_ = cmd;
|
|
||||||
}
|
}
|
||||||
if (config_["on-scroll-up"].isString()) {
|
if (config_["on-scroll-up"].isString()) {
|
||||||
std::string cmd = config_["on-scroll-up"].asString();
|
|
||||||
event_box_.add_events(Gdk::SCROLL_MASK);
|
event_box_.add_events(Gdk::SCROLL_MASK);
|
||||||
event_box_.signal_scroll_event().connect(
|
event_box_.signal_scroll_event().connect(
|
||||||
sigc::mem_fun(*this, &ALabel::handleScroll));
|
sigc::mem_fun(*this, &ALabel::handleScroll));
|
||||||
|
|
||||||
scroll_up_cmd_ = cmd;
|
|
||||||
}
|
}
|
||||||
if (config_["on-scroll-down"].isString()) {
|
if (config_["on-scroll-down"].isString()) {
|
||||||
std::string cmd = config_["on-scroll-down"].asString();
|
|
||||||
event_box_.add_events(Gdk::SCROLL_MASK);
|
event_box_.add_events(Gdk::SCROLL_MASK);
|
||||||
event_box_.signal_scroll_event().connect(
|
event_box_.signal_scroll_event().connect(
|
||||||
sigc::mem_fun(*this, &ALabel::handleScroll));
|
sigc::mem_fun(*this, &ALabel::handleScroll));
|
||||||
|
|
||||||
scroll_down_cmd_ = cmd;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +42,8 @@ auto waybar::ALabel::update() -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
||||||
if (button_press_cmd_ != "" && e->button == 1) {
|
if (config_["on-click"].isString() && e->button == 1) {
|
||||||
waybar::util::command::forkExec(button_press_cmd_);
|
waybar::util::command::forkExec(config_["on-click"].asString());
|
||||||
} else {
|
} else {
|
||||||
alt = !alt;
|
alt = !alt;
|
||||||
if (alt) {
|
if (alt) {
|
||||||
|
@ -69,7 +60,6 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
||||||
bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
||||||
|
|
||||||
// Avoid concurrent scroll event
|
// Avoid concurrent scroll event
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
bool direction_up = false;
|
bool direction_up = false;
|
||||||
|
|
||||||
|
@ -89,15 +79,12 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
||||||
direction_up = false;
|
direction_up = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (direction_up && config_["on-scroll-up"].isString()) {
|
||||||
if (direction_up)
|
waybar::util::command::forkExec(config_["on-scroll-up"].asString());
|
||||||
waybar::util::command::forkExec(scroll_up_cmd_);
|
} else if (config_["on-scroll-down"].isString()) {
|
||||||
else
|
waybar::util::command::forkExec(config_["on-scroll-down"].asString());
|
||||||
waybar::util::command::forkExec(scroll_down_cmd_);
|
|
||||||
|
|
||||||
dp.emit();
|
|
||||||
}
|
}
|
||||||
|
dp.emit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue