mirror of
https://github.com/polybar/polybar.git
synced 2024-11-11 13:50:56 -05:00
fix(bar): Remove double click
This commit is contained in:
parent
418dadf0b9
commit
1cccd100bb
3 changed files with 7 additions and 18 deletions
|
@ -68,7 +68,6 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
||||||
std::mutex m_mutex{};
|
std::mutex m_mutex{};
|
||||||
|
|
||||||
event_timer m_buttonpress{0L, 5L};
|
event_timer m_buttonpress{0L, 5L};
|
||||||
event_timer m_doubleclick{0L, 250L};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
|
|
@ -33,7 +33,7 @@ enum class syntaxtag : uint8_t {
|
||||||
u, // underline color
|
u, // underline color
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class mousebtn : uint8_t { NONE = 0U, LEFT, MIDDLE, RIGHT, SCROLL_UP, SCROLL_DOWN, DOUBLE_CLICK };
|
enum class mousebtn : uint8_t { NONE = 0U, LEFT, MIDDLE, RIGHT, SCROLL_UP, SCROLL_DOWN };
|
||||||
|
|
||||||
enum class strut : uint16_t {
|
enum class strut : uint16_t {
|
||||||
LEFT = 0U,
|
LEFT = 0U,
|
||||||
|
@ -96,6 +96,10 @@ struct action_block : public action {
|
||||||
uint16_t width() const {
|
uint16_t width() const {
|
||||||
return static_cast<uint16_t>(end_x - start_x + 0.5);
|
return static_cast<uint16_t>(end_x - start_x + 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool test(int16_t point) const {
|
||||||
|
return static_cast<int16_t>(start_x) < point && static_cast<int16_t>(end_x) >= point;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bar_settings {
|
struct bar_settings {
|
||||||
|
|
|
@ -150,7 +150,6 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
||||||
actions.emplace_back(action{mousebtn::RIGHT, m_conf.get<string>(bs, "click-right", "")});
|
actions.emplace_back(action{mousebtn::RIGHT, m_conf.get<string>(bs, "click-right", "")});
|
||||||
actions.emplace_back(action{mousebtn::SCROLL_UP, m_conf.get<string>(bs, "scroll-up", "")});
|
actions.emplace_back(action{mousebtn::SCROLL_UP, m_conf.get<string>(bs, "scroll-up", "")});
|
||||||
actions.emplace_back(action{mousebtn::SCROLL_DOWN, m_conf.get<string>(bs, "scroll-down", "")});
|
actions.emplace_back(action{mousebtn::SCROLL_DOWN, m_conf.get<string>(bs, "scroll-down", "")});
|
||||||
actions.emplace_back(action{mousebtn::DOUBLE_CLICK, m_conf.get<string>(bs, "click-double", "")});
|
|
||||||
|
|
||||||
for (auto&& act : actions) {
|
for (auto&& act : actions) {
|
||||||
if (!act.command.empty()) {
|
if (!act.command.empty()) {
|
||||||
|
@ -502,6 +501,7 @@ void bar::handle(const evt::button_press& evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> guard(m_mutex, std::adopt_lock);
|
std::lock_guard<std::mutex> guard(m_mutex, std::adopt_lock);
|
||||||
|
|
||||||
if (m_buttonpress.deny(evt->time)) {
|
if (m_buttonpress.deny(evt->time)) {
|
||||||
return m_log.trace_x("bar: Ignoring button press (throttled)...");
|
return m_log.trace_x("bar: Ignoring button press (throttled)...");
|
||||||
}
|
}
|
||||||
|
@ -509,22 +509,8 @@ void bar::handle(const evt::button_press& evt) {
|
||||||
m_log.trace("bar: Received button press: %i at pos(%i, %i)", evt->detail, evt->event_x, evt->event_y);
|
m_log.trace("bar: Received button press: %i at pos(%i, %i)", evt->detail, evt->event_x, evt->event_y);
|
||||||
mousebtn button{static_cast<mousebtn>(evt->detail)};
|
mousebtn button{static_cast<mousebtn>(evt->detail)};
|
||||||
|
|
||||||
// Using the event_timer so if the event gets denied
|
|
||||||
// we are within the double click time window
|
|
||||||
if (button == mousebtn::LEFT && m_doubleclick.deny(evt->time)) {
|
|
||||||
button = mousebtn::DOUBLE_CLICK;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto&& action : m_renderer->get_actions()) {
|
for (auto&& action : m_renderer->get_actions()) {
|
||||||
if (action.active) {
|
if (!action.active && action.button == button && action.test(evt->event_x)) {
|
||||||
continue;
|
|
||||||
} else if (action.button != button) {
|
|
||||||
continue;
|
|
||||||
} else if (action.start_x >= evt->event_x) {
|
|
||||||
continue;
|
|
||||||
} else if (action.end_x < evt->event_x) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
m_log.trace("Found matching input area");
|
m_log.trace("Found matching input area");
|
||||||
m_sig.emit(button_press{string{action.command}});
|
m_sig.emit(button_press{string{action.command}});
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue