diff options
author | Christian Persch <chpe@src.gnome.org> | 2020-10-29 20:23:57 +0100 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2020-10-29 20:23:57 +0100 |
commit | 499898451d35cd84caa12c795a3108dd7c631025 (patch) | |
tree | 70fdc4cbbec12d7d14d374a3d06955e5cdd0bbde | |
parent | d2d7d0e6e9bd92347d5e38e3c25a5979922f2f33 (diff) | |
download | vte-499898451d35cd84caa12c795a3108dd7c631025.tar.gz |
widget: Record the press count for button press events
Replace double/triple click events with a press_count on the generic
button press event.
[gtk4 preparation]
-rw-r--r-- | src/vte.cc | 16 | ||||
-rw-r--r-- | src/widget.cc | 42 | ||||
-rw-r--r-- | src/widget.hh | 9 |
3 files changed, 41 insertions, 26 deletions
@@ -5645,17 +5645,17 @@ Terminal::maybe_send_mouse_button(vte::grid::coords const& unconfined_rowcol, { switch (event.type()) { case vte::platform::EventBase::Type::eMOUSE_PRESS: - if (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_CLICK) { + if (event.press_count() != 1 || + (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_CLICK)) { return false; } break; case vte::platform::EventBase::Type::eMOUSE_RELEASE: - if (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_BUTTON) { + if (event.press_count() != 1 || + (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_BUTTON)) { return false; } break; - case vte::platform::EventBase::Type::eMOUSE_DOUBLE_PRESS: - case vte::platform::EventBase::Type::eMOUSE_TRIPLE_PRESS: default: return false; } @@ -6770,8 +6770,8 @@ Terminal::widget_mouse_press(vte::platform::MouseEvent const& event) m_modifiers = event.modifiers(); - switch (event.type()) { - case vte::platform::EventBase::Type::eMOUSE_PRESS: + switch (event.press_count()) { + case 1: /* single click */ _vte_debug_print(VTE_DEBUG_EVENTS, "Button %d single-click at %s\n", event.button_value(), @@ -6844,7 +6844,7 @@ Terminal::widget_mouse_press(vte::platform::MouseEvent const& event) handled = maybe_send_mouse_button(rowcol, event); } break; - case vte::platform::EventBase::Type::eMOUSE_DOUBLE_PRESS: + case 2: /* double click */ _vte_debug_print(VTE_DEBUG_EVENTS, "Button %d double-click at %s\n", event.button_value(), @@ -6868,7 +6868,7 @@ Terminal::widget_mouse_press(vte::platform::MouseEvent const& event) break; } break; - case vte::platform::EventBase::Type::eMOUSE_TRIPLE_PRESS: + case 3: /* triple click */ _vte_debug_print(VTE_DEBUG_EVENTS, "Button %d triple-click at %s\n", event.button_value(), diff --git a/src/widget.cc b/src/widget.cc index c774ec29..ae825c10 100644 --- a/src/widget.cc +++ b/src/widget.cc @@ -444,15 +444,31 @@ MouseEvent Widget::mouse_event_from_gdk(GdkEvent* event) const /* throws */ { auto type = EventBase::Type{}; + auto press_count = 0u; switch (gdk_event_get_event_type(event)) { - case GDK_2BUTTON_PRESS: type = MouseEvent::Type::eMOUSE_DOUBLE_PRESS; break; - case GDK_3BUTTON_PRESS: type = MouseEvent::Type::eMOUSE_TRIPLE_PRESS; break; - case GDK_BUTTON_PRESS: type = MouseEvent::Type::eMOUSE_PRESS; break; - case GDK_BUTTON_RELEASE: type = MouseEvent::Type::eMOUSE_RELEASE; break; + case GDK_2BUTTON_PRESS: + type = MouseEvent::Type::eMOUSE_PRESS; + press_count = 2; + break; + case GDK_3BUTTON_PRESS: + type = MouseEvent::Type::eMOUSE_PRESS; + press_count = 3; + break; + case GDK_BUTTON_PRESS: + type = MouseEvent::Type::eMOUSE_PRESS; + press_count = 1; + break; + case GDK_BUTTON_RELEASE: + type = MouseEvent::Type::eMOUSE_RELEASE; + press_count = 1; + break; case GDK_ENTER_NOTIFY: type = MouseEvent::Type::eMOUSE_ENTER; break; case GDK_LEAVE_NOTIFY: type = MouseEvent::Type::eMOUSE_LEAVE; break; case GDK_MOTION_NOTIFY: type = MouseEvent::Type::eMOUSE_MOTION; break; - case GDK_SCROLL: type = MouseEvent::Type::eMOUSE_SCROLL; break; + case GDK_SCROLL: + type = MouseEvent::Type::eMOUSE_SCROLL; + press_count = 1; + break; default: throw std::runtime_error{"Unexpected event type"}; } @@ -466,14 +482,14 @@ Widget::mouse_event_from_gdk(GdkEvent* event) const /* throws */ auto button = unsigned{0}; (void)gdk_event_get_button(event, &button); - auto mouse_event = MouseEvent{event, - type, - gdk_event_get_time(event), - read_modifiers_from_gdk(event), - MouseEvent::Button(button), - x, - y}; - return mouse_event; + return {event, + type, + gdk_event_get_time(event), + press_count, + read_modifiers_from_gdk(event), + MouseEvent::Button(button), + x, + y}; } void diff --git a/src/widget.hh b/src/widget.hh index 10345d8a..f88177d2 100644 --- a/src/widget.hh +++ b/src/widget.hh @@ -51,14 +51,12 @@ public: enum class Type { eKEY_PRESS, eKEY_RELEASE, - eMOUSE_DOUBLE_PRESS, eMOUSE_ENTER, eMOUSE_LEAVE, eMOUSE_MOTION, eMOUSE_PRESS, eMOUSE_RELEASE, eMOUSE_SCROLL, - eMOUSE_TRIPLE_PRESS, }; protected: @@ -175,6 +173,7 @@ protected: constexpr MouseEvent(GdkEvent* gdk_event, Type type, unsigned timestamp, + unsigned press_count, unsigned modifiers, Button button, double x, @@ -182,6 +181,7 @@ protected: : EventBase{gdk_event, type, timestamp}, + m_press_count{press_count}, m_modifiers{modifiers}, m_button{button}, m_x{x}, @@ -199,19 +199,17 @@ public: constexpr auto button() const noexcept { return m_button; } constexpr auto button_value() const noexcept { return unsigned(m_button); } + constexpr auto press_count() const noexcept { return m_press_count; } constexpr auto modifiers() const noexcept { return m_modifiers; } constexpr auto x() const noexcept { return m_x; } constexpr auto y() const noexcept { return m_y; } - constexpr auto is_mouse_double_press() const noexcept { return type() == Type::eMOUSE_DOUBLE_PRESS; } constexpr auto is_mouse_enter() const noexcept { return type() == Type::eMOUSE_ENTER; } constexpr auto is_mouse_leave() const noexcept { return type() == Type::eMOUSE_LEAVE; } constexpr auto is_mouse_motion() const noexcept { return type() == Type::eMOUSE_MOTION; } constexpr auto is_mouse_press() const noexcept { return type() == Type::eMOUSE_PRESS; } constexpr auto is_mouse_release() const noexcept { return type() == Type::eMOUSE_RELEASE; } constexpr auto is_mouse_scroll() const noexcept { return type() == Type::eMOUSE_SCROLL; } - constexpr auto is_mouse_single_press() const noexcept { return type() == Type::eMOUSE_PRESS; } - constexpr auto is_mouse_triple_press() const noexcept { return type() == Type::eMOUSE_TRIPLE_PRESS; } ScrollDirection scroll_direction() const noexcept { @@ -248,6 +246,7 @@ public: } private: + unsigned m_press_count; unsigned m_modifiers; Button m_button; double m_x; |