[vte] widget: Move Event classes to platform
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Move Event classes to platform
- Date: Tue, 6 Oct 2020 17:46:25 +0000 (UTC)
commit 54daba14724d4afde4f00a2f23fe5698f23b663d
Author: Christian Persch <chpe src gnome org>
Date: Tue Oct 6 19:46:17 2020 +0200
widget: Move Event classes to platform
[gtk4 preparation]
src/fwd.hh | 3 +
src/vte.cc | 82 +++++++++---------
src/vteinternal.hh | 249 ++++-------------------------------------------------
src/widget.cc | 46 +++++-----
src/widget.hh | 221 ++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 302 insertions(+), 299 deletions(-)
---
diff --git a/src/fwd.hh b/src/fwd.hh
index 24d7eea7..74a0479b 100644
--- a/src/fwd.hh
+++ b/src/fwd.hh
@@ -27,6 +27,9 @@ class Pty;
namespace platform {
+class EventBase;
+class KeyEvent;
+class MouseEvent;
class Widget;
} // namespace platform
diff --git a/src/vte.cc b/src/vte.cc
index 07548b15..b51c54a9 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -1449,7 +1449,7 @@ Terminal::regex_match_check(vte::grid::column_t column,
* at that side; use view_coords_visible() to check for that.
*/
vte::view::coords
-Terminal::view_coords_from_event(MouseEvent const& event) const
+Terminal::view_coords_from_event(vte::platform::MouseEvent const& event) const
{
return vte::view::coords(event.x() - m_padding.left, event.y() - m_padding.top);
}
@@ -1471,7 +1471,7 @@ Terminal::widget_realized() const noexcept
* at that side; use grid_coords_visible() to check for that.
*/
vte::grid::coords
-Terminal::grid_coords_from_event(MouseEvent const& event) const
+Terminal::grid_coords_from_event(vte::platform::MouseEvent const& event) const
{
return grid_coords_from_view_coords(view_coords_from_event(event));
}
@@ -1484,7 +1484,7 @@ Terminal::grid_coords_from_event(MouseEvent const& event) const
* to an actual cell in the visible area.
*/
vte::grid::coords
-Terminal::confined_grid_coords_from_event(MouseEvent const& event) const
+Terminal::confined_grid_coords_from_event(vte::platform::MouseEvent const& event) const
{
auto pos = view_coords_from_event(event);
return confined_grid_coords_from_view_coords(pos);
@@ -1685,7 +1685,7 @@ Terminal::selection_maybe_swap_endpoints(vte::view::coords const& pos)
}
bool
-Terminal::rowcol_from_event(MouseEvent const& event,
+Terminal::rowcol_from_event(vte::platform::MouseEvent const& event,
long *column,
long *row)
{
@@ -1699,7 +1699,7 @@ Terminal::rowcol_from_event(MouseEvent const& event,
}
char *
-Terminal::hyperlink_check(MouseEvent const& event)
+Terminal::hyperlink_check(vte::platform::MouseEvent const& event)
{
long col, row;
const char *hyperlink;
@@ -1731,7 +1731,7 @@ Terminal::hyperlink_check(MouseEvent const& event)
}
char *
-Terminal::regex_match_check(MouseEvent const& event,
+Terminal::regex_match_check(vte::platform::MouseEvent const& event,
int *tag)
{
long col, row;
@@ -1748,7 +1748,7 @@ Terminal::regex_match_check(MouseEvent const& event,
}
bool
-Terminal::regex_match_check_extra(MouseEvent const& event,
+Terminal::regex_match_check_extra(vte::platform::MouseEvent const& event,
vte::base::Regex const** regexes,
size_t n_regexes,
uint32_t match_flags,
@@ -4489,7 +4489,7 @@ Terminal::beep()
}
bool
-Terminal::widget_key_press(KeyEvent const& event)
+Terminal::widget_key_press(vte::platform::KeyEvent const& event)
{
char *normal = NULL;
gsize normal_length = 0;
@@ -4952,7 +4952,7 @@ Terminal::widget_key_press(KeyEvent const& event)
}
bool
-Terminal::widget_key_release(KeyEvent const& event)
+Terminal::widget_key_release(vte::platform::KeyEvent const& event)
{
m_modifiers = event.modifiers();
@@ -5613,21 +5613,21 @@ Terminal::maybe_feed_focus_event(bool in)
*/
bool
Terminal::maybe_send_mouse_button(vte::grid::coords const& unconfined_rowcol,
- MouseEvent const& event)
+ vte::platform::MouseEvent const& event)
{
switch (event.type()) {
- case EventBase::Type::eMOUSE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_PRESS:
if (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_CLICK) {
return false;
}
break;
- case EventBase::Type::eMOUSE_RELEASE:
+ case vte::platform::EventBase::Type::eMOUSE_RELEASE:
if (m_mouse_tracking_mode < MouseTrackingMode::eSEND_XY_ON_BUTTON) {
return false;
}
break;
- case EventBase::Type::eMOUSE_DOUBLE_PRESS:
- case EventBase::Type::eMOUSE_TRIPLE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_DOUBLE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_TRIPLE_PRESS:
default:
return false;
}
@@ -5651,7 +5651,7 @@ Terminal::maybe_send_mouse_button(vte::grid::coords const& unconfined_rowcol,
*/
bool
Terminal::maybe_send_mouse_drag(vte::grid::coords const& unconfined_rowcol,
- MouseEvent const& event)
+ vte::platform::MouseEvent const& event)
{
/* Need to ensure the ringview is updated. */
ringview_update();
@@ -5660,7 +5660,7 @@ Terminal::maybe_send_mouse_drag(vte::grid::coords const& unconfined_rowcol,
/* First determine if we even want to send notification. */
switch (event.type()) {
- case EventBase::Type::eMOUSE_MOTION:
+ case vte::platform::EventBase::Type::eMOUSE_MOTION:
if (m_mouse_tracking_mode < MouseTrackingMode::eCELL_MOTION_TRACKING)
return false;
@@ -6793,7 +6793,7 @@ Terminal::start_autoscroll()
}
bool
-Terminal::widget_mouse_motion(MouseEvent const& event)
+Terminal::widget_mouse_motion(vte::platform::MouseEvent const& event)
{
/* Need to ensure the ringview is updated. */
ringview_update();
@@ -6850,7 +6850,7 @@ Terminal::widget_mouse_motion(MouseEvent const& event)
}
bool
-Terminal::widget_mouse_press(MouseEvent const& event)
+Terminal::widget_mouse_press(vte::platform::MouseEvent const& event)
{
bool handled = false;
gboolean start_selecting = FALSE, extend_selecting = FALSE;
@@ -6864,14 +6864,14 @@ Terminal::widget_mouse_press(MouseEvent const& event)
m_modifiers = event.modifiers();
switch (event.type()) {
- case EventBase::Type::eMOUSE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_PRESS:
_vte_debug_print(VTE_DEBUG_EVENTS,
"Button %d single-click at %s\n",
event.button_value(),
rowcol.to_string());
/* Handle this event ourselves. */
switch (event.button()) {
- case MouseEvent::Button::eLEFT:
+ case vte::platform::MouseEvent::Button::eLEFT:
_vte_debug_print(VTE_DEBUG_EVENTS,
"Handling click ourselves.\n");
/* Grab focus. */
@@ -6912,7 +6912,7 @@ Terminal::widget_mouse_press(MouseEvent const& event)
break;
/* Paste if the user pressed shift or we're not sending events
* to the app. */
- case MouseEvent::Button::eMIDDLE:
+ case vte::platform::MouseEvent::Button::eMIDDLE:
if ((m_modifiers & GDK_SHIFT_MASK) ||
m_mouse_tracking_mode == MouseTrackingMode::eNONE) {
if (widget()->primary_paste_enabled()) {
@@ -6921,7 +6921,7 @@ Terminal::widget_mouse_press(MouseEvent const& event)
}
}
break;
- case MouseEvent::Button::eRIGHT:
+ case vte::platform::MouseEvent::Button::eRIGHT:
default:
break;
}
@@ -6937,13 +6937,13 @@ Terminal::widget_mouse_press(MouseEvent const& event)
handled = maybe_send_mouse_button(rowcol, event);
}
break;
- case EventBase::Type::eMOUSE_DOUBLE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_DOUBLE_PRESS:
_vte_debug_print(VTE_DEBUG_EVENTS,
"Button %d double-click at %s\n",
event.button_value(),
rowcol.to_string());
switch (event.button()) {
- case MouseEvent::Button::eLEFT:
+ case vte::platform::MouseEvent::Button::eLEFT:
if (m_will_select_after_threshold) {
start_selection(pos,
SelectionType::eCHAR);
@@ -6955,27 +6955,27 @@ Terminal::widget_mouse_press(MouseEvent const& event)
handled = true;
}
break;
- case MouseEvent::Button::eMIDDLE:
- case MouseEvent::Button::eRIGHT:
+ case vte::platform::MouseEvent::Button::eMIDDLE:
+ case vte::platform::MouseEvent::Button::eRIGHT:
default:
break;
}
break;
- case EventBase::Type::eMOUSE_TRIPLE_PRESS:
+ case vte::platform::EventBase::Type::eMOUSE_TRIPLE_PRESS:
_vte_debug_print(VTE_DEBUG_EVENTS,
"Button %d triple-click at %s\n",
event.button_value(),
rowcol.to_string());
switch (event.button()) {
- case MouseEvent::Button::eLEFT:
+ case vte::platform::MouseEvent::Button::eLEFT:
if ((m_mouse_handled_buttons & 1) != 0) {
start_selection(pos,
SelectionType::eLINE);
handled = true;
}
break;
- case MouseEvent::Button::eMIDDLE:
- case MouseEvent::Button::eRIGHT:
+ case vte::platform::MouseEvent::Button::eMIDDLE:
+ case vte::platform::MouseEvent::Button::eRIGHT:
default:
break;
}
@@ -6997,7 +6997,7 @@ Terminal::widget_mouse_press(MouseEvent const& event)
}
bool
-Terminal::widget_mouse_release(MouseEvent const& event)
+Terminal::widget_mouse_release(vte::platform::MouseEvent const& event)
{
bool handled = false;
@@ -7012,20 +7012,20 @@ Terminal::widget_mouse_release(MouseEvent const& event)
m_modifiers = event.modifiers();
switch (event.type()) {
- case EventBase::Type::eMOUSE_RELEASE:
+ case vte::platform::EventBase::Type::eMOUSE_RELEASE:
_vte_debug_print(VTE_DEBUG_EVENTS,
"Button %d released at %s\n",
event.button_value(), rowcol.to_string());
switch (event.button()) {
- case MouseEvent::Button::eLEFT:
+ case vte::platform::MouseEvent::Button::eLEFT:
if ((m_mouse_handled_buttons & 1) != 0)
handled = maybe_end_selection();
break;
- case MouseEvent::Button::eMIDDLE:
+ case vte::platform::MouseEvent::Button::eMIDDLE:
handled = (m_mouse_handled_buttons & 2) != 0;
m_mouse_handled_buttons &= ~2;
break;
- case MouseEvent::Button::eRIGHT:
+ case vte::platform::MouseEvent::Button::eRIGHT:
default:
break;
}
@@ -7112,7 +7112,7 @@ Terminal::widget_focus_out()
}
void
-Terminal::widget_mouse_enter(MouseEvent const& event)
+Terminal::widget_mouse_enter(vte::platform::MouseEvent const& event)
{
auto pos = view_coords_from_event(event);
@@ -7130,7 +7130,7 @@ Terminal::widget_mouse_enter(MouseEvent const& event)
}
void
-Terminal::widget_mouse_leave(MouseEvent const& event)
+Terminal::widget_mouse_leave(vte::platform::MouseEvent const& event)
{
auto pos = view_coords_from_event(event);
@@ -9387,7 +9387,7 @@ vte_cairo_get_clip_region (cairo_t *cr)
}
bool
-Terminal::widget_mouse_scroll(MouseEvent const& event)
+Terminal::widget_mouse_scroll(vte::platform::MouseEvent const& event)
{
gdouble v;
gint cnt, i;
@@ -9401,15 +9401,15 @@ Terminal::widget_mouse_scroll(MouseEvent const& event)
m_modifiers = event.modifiers();
switch (event.scroll_direction()) {
- case MouseEvent::ScrollDirection::eUP:
+ case vte::platform::MouseEvent::ScrollDirection::eUP:
m_mouse_smooth_scroll_delta -= 1.;
_vte_debug_print(VTE_DEBUG_EVENTS, "Scroll up\n");
break;
- case MouseEvent::ScrollDirection::eDOWN:
+ case vte::platform::MouseEvent::ScrollDirection::eDOWN:
m_mouse_smooth_scroll_delta += 1.;
_vte_debug_print(VTE_DEBUG_EVENTS, "Scroll down\n");
break;
- case MouseEvent::ScrollDirection::eSMOOTH: {
+ case vte::platform::MouseEvent::ScrollDirection::eSMOOTH: {
auto const delta_y = event.scroll_delta_y();
m_mouse_smooth_scroll_delta += delta_y;
_vte_debug_print(VTE_DEBUG_EVENTS,
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index f2196d14..fa112f66 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -246,219 +246,6 @@ enum class ClipboardType;
namespace terminal {
-class EventBase {
- friend class vte::platform::Widget;
- friend class Terminal;
-
-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:
-
- EventBase() noexcept = default;
-
- constexpr EventBase(GdkEvent* gdk_event,
- Type type,
- unsigned timestamp) noexcept
- : m_platform_event{gdk_event},
- m_type{type},
- m_timestamp{timestamp}
- {
- }
-
- constexpr auto platform_event() const noexcept { return m_platform_event; }
-
-public:
- ~EventBase() noexcept = default;
-
- EventBase(EventBase const&) = default;
- EventBase(EventBase&&) = default;
- EventBase& operator=(EventBase const&) = delete;
- EventBase& operator=(EventBase&&) = delete;
-
- constexpr auto const timestamp() const noexcept { return m_timestamp; }
- constexpr auto const type() const noexcept { return m_type; }
-
-private:
- GdkEvent* m_platform_event;
- Type m_type;
- unsigned m_timestamp;
-}; // class EventBase
-
-class KeyEvent : public EventBase {
- friend class vte::platform::Widget;
- friend class Terminal;
-
-protected:
-
- KeyEvent() noexcept = default;
-
- constexpr KeyEvent(GdkEvent* gdk_event,
- Type type,
- unsigned timestamp,
- unsigned modifiers,
- unsigned keyval,
- unsigned keycode,
- uint8_t group,
- bool is_modifier) noexcept
- : EventBase{gdk_event,
- type,
- timestamp},
- m_modifiers{modifiers},
- m_keyval{keyval},
- m_keycode{keycode},
- m_group{group},
- m_is_modifier{is_modifier}
- {
- }
-
-public:
- ~KeyEvent() noexcept = default;
-
- KeyEvent(KeyEvent const&) = delete;
- KeyEvent(KeyEvent&&) = delete;
- KeyEvent& operator=(KeyEvent const&) = delete;
- KeyEvent& operator=(KeyEvent&&) = delete;
-
- constexpr auto const group() const noexcept { return m_group; }
- constexpr auto const is_modifier() const noexcept { return m_is_modifier; }
- constexpr auto const keycode() const noexcept { return m_keycode; }
- constexpr auto const keyval() const noexcept { return m_keyval; }
- constexpr auto const modifiers() const noexcept { return m_modifiers; }
-
- constexpr auto const is_key_press() const noexcept { return type() == Type::eKEY_PRESS; }
- constexpr auto const is_key_release() const noexcept { return type() == Type::eKEY_RELEASE; }
-
- auto const string() const noexcept
- {
- return reinterpret_cast<GdkEventKey*>(platform_event())->string;
- }
-
-private:
- unsigned m_modifiers;
- unsigned m_keyval;
- unsigned m_keycode;
- uint8_t m_group;
- bool m_is_modifier;
-}; // class KeyEvent
-
-class MouseEvent : public EventBase {
- friend class vte::platform::Widget;
- friend class Terminal;
-
-public:
- enum class Button {
- eNONE = 0,
- eLEFT = 1,
- eMIDDLE = 2,
- eRIGHT = 3,
- eFOURTH = 4,
- eFIFTH = 5,
- };
-
- enum class ScrollDirection {
- eUP,
- eDOWN,
- eLEFT,
- eRIGHT,
- eSMOOTH,
- eNONE,
- };
-
-protected:
-
- MouseEvent() noexcept = default;
-
- constexpr MouseEvent(GdkEvent* gdk_event,
- Type type,
- unsigned timestamp,
- unsigned modifiers,
- Button button,
- double x,
- double y) noexcept
- : EventBase{gdk_event,
- type,
- timestamp},
- m_modifiers{modifiers},
- m_button{button},
- m_x{x},
- m_y{y}
- {
- }
-
-public:
- ~MouseEvent() noexcept = default;
-
- MouseEvent(MouseEvent const&) = default;
- MouseEvent(MouseEvent&&) = default;
- MouseEvent& operator=(MouseEvent const&) = delete;
- MouseEvent& operator=(MouseEvent&&) = delete;
-
- constexpr auto const button() const noexcept { return m_button; }
- constexpr auto const button_value() const noexcept { return unsigned(m_button); }
- constexpr auto const modifiers() const noexcept { return m_modifiers; }
- constexpr auto const x() const noexcept { return m_x; }
- constexpr auto const y() const noexcept { return m_y; }
-
- constexpr auto const is_mouse_double_press() const noexcept { return type() ==
Type::eMOUSE_DOUBLE_PRESS; }
- constexpr auto const is_mouse_enter() const noexcept { return type() == Type::eMOUSE_ENTER;
}
- constexpr auto const is_mouse_leave() const noexcept { return type() == Type::eMOUSE_LEAVE;
}
- constexpr auto const is_mouse_motion() const noexcept { return type() == Type::eMOUSE_MOTION;
}
- constexpr auto const is_mouse_press() const noexcept { return type() == Type::eMOUSE_PRESS;
}
- constexpr auto const is_mouse_release() const noexcept { return type() == Type::eMOUSE_RELEASE;
}
- constexpr auto const is_mouse_scroll() const noexcept { return type() == Type::eMOUSE_SCROLL;
}
- constexpr auto const is_mouse_single_press() const noexcept { return type() == Type::eMOUSE_PRESS;
}
- constexpr auto const is_mouse_triple_press() const noexcept { return type() ==
Type::eMOUSE_TRIPLE_PRESS; }
-
- ScrollDirection scroll_direction() const noexcept
- {
- /* Note that we cannot use gdk_event_get_scroll_direction() here since it
- * returns false for smooth scroll events.
- */
- if (!is_mouse_scroll())
- return ScrollDirection::eNONE;
- switch (reinterpret_cast<GdkEventScroll*>(platform_event())->direction) {
- case GDK_SCROLL_UP: return ScrollDirection::eUP;
- case GDK_SCROLL_DOWN: return ScrollDirection::eDOWN;
- case GDK_SCROLL_LEFT: return ScrollDirection::eLEFT;
- case GDK_SCROLL_RIGHT: return ScrollDirection::eRIGHT;
- case GDK_SCROLL_SMOOTH: return ScrollDirection::eSMOOTH;
- default: return ScrollDirection::eNONE;
- }
- }
-
- auto scroll_delta_x() const noexcept
- {
- auto delta = double{0.};
- gdk_event_get_scroll_deltas(platform_event(), &delta, nullptr);
- return delta;
- }
-
- auto scroll_delta_y() const noexcept
- {
- auto delta = double{0.};
- gdk_event_get_scroll_deltas(platform_event(), nullptr, &delta);
- return delta;
- }
-
-private:
- unsigned m_modifiers;
- Button m_button;
- double m_x;
- double m_y;
-}; // class MouseEvent
-
class Terminal {
friend class vte::platform::Widget;
@@ -1091,8 +878,8 @@ public:
inline vte::view::coord_t get_allocated_width() const { return m_allocated_rect.width; }
inline vte::view::coord_t get_allocated_height() const { return m_allocated_rect.height; }
- vte::view::coords view_coords_from_event(MouseEvent const& event) const;
- vte::grid::coords grid_coords_from_event(MouseEvent const& event) const;
+ vte::view::coords view_coords_from_event(vte::platform::MouseEvent const& event) const;
+ vte::grid::coords grid_coords_from_event(vte::platform::MouseEvent const& event) const;
vte::view::coords view_coords_from_grid_coords(vte::grid::coords const& rowcol) const;
vte::grid::coords grid_coords_from_view_coords(vte::view::coords const& pos) const;
@@ -1105,7 +892,7 @@ public:
vte::grid::row_t confine_grid_row(vte::grid::row_t const& row) const;
vte::grid::coords confine_grid_coords(vte::grid::coords const& rowcol) const;
- vte::grid::coords confined_grid_coords_from_event(MouseEvent const&) const;
+ vte::grid::coords confined_grid_coords_from_event(vte::platform::MouseEvent const&) const;
vte::grid::coords confined_grid_coords_from_view_coords(vte::view::coords const& pos) const;
void confine_coordinates(long *xp,
@@ -1131,14 +918,14 @@ public:
void widget_style_updated();
void widget_focus_in();
void widget_focus_out();
- bool widget_key_press(KeyEvent const& event);
- bool widget_key_release(KeyEvent const& event);
- bool widget_mouse_motion(MouseEvent const& event);
- bool widget_mouse_press(MouseEvent const& event);
- bool widget_mouse_release(MouseEvent const& event);
- void widget_mouse_enter(MouseEvent const& event);
- void widget_mouse_leave(MouseEvent const& event);
- bool widget_mouse_scroll(MouseEvent const& event);
+ bool widget_key_press(vte::platform::KeyEvent const& event);
+ bool widget_key_release(vte::platform::KeyEvent const& event);
+ bool widget_mouse_motion(vte::platform::MouseEvent const& event);
+ bool widget_mouse_press(vte::platform::MouseEvent const& event);
+ bool widget_mouse_release(vte::platform::MouseEvent const& event);
+ void widget_mouse_enter(vte::platform::MouseEvent const& event);
+ void widget_mouse_leave(vte::platform::MouseEvent const& event);
+ bool widget_mouse_scroll(vte::platform::MouseEvent const& event);
void widget_draw(cairo_t *cr);
void widget_get_preferred_width(int *minimum_width,
int *natural_width);
@@ -1320,7 +1107,7 @@ public:
void vadjustment_value_changed();
- unsigned translate_ctrlkey(KeyEvent const& event) const noexcept;
+ unsigned translate_ctrlkey(vte::platform::KeyEvent const& event) const noexcept;
void apply_mouse_cursor();
void set_pointer_autohidden(bool autohidden);
@@ -1374,13 +1161,13 @@ public:
void match_hilite_clear();
void match_hilite_update();
- bool rowcol_from_event(MouseEvent const& event,
+ bool rowcol_from_event(vte::platform::MouseEvent const& event,
long *column,
long *row);
- char *hyperlink_check(MouseEvent const& event);
+ char *hyperlink_check(vte::platform::MouseEvent const& event);
- bool regex_match_check_extra(MouseEvent const& event,
+ bool regex_match_check_extra(vte::platform::MouseEvent const& event,
vte::base::Regex const** regexes,
size_t n_regexes,
uint32_t match_flags,
@@ -1389,7 +1176,7 @@ public:
char *regex_match_check(vte::grid::column_t column,
vte::grid::row_t row,
int *tag);
- char *regex_match_check(MouseEvent const& event,
+ char *regex_match_check(vte::platform::MouseEvent const& event,
int *tag);
void regex_match_remove(int tag) noexcept;
void regex_match_remove_all() noexcept;
@@ -1435,9 +1222,9 @@ public:
bool is_drag,
bool is_release);
bool maybe_send_mouse_button(vte::grid::coords const& rowcol,
- MouseEvent const& event);
+ vte::platform::MouseEvent const& event);
bool maybe_send_mouse_drag(vte::grid::coords const& rowcol,
- MouseEvent const& event);
+ vte::platform::MouseEvent const& event);
void feed_focus_event(bool in);
void feed_focus_event_initial();
diff --git a/src/widget.cc b/src/widget.cc
index 44a22717..b516c07f 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -255,7 +255,7 @@ Widget::emit_eof() noexcept
}
bool
-Widget::im_filter_keypress(vte::terminal::KeyEvent const& event) noexcept
+Widget::im_filter_keypress(KeyEvent const& event) noexcept
{
// FIXMEchpe this can only be called when realized, so the m_im_context check is redundant
return m_im_context &&
@@ -323,7 +323,7 @@ Widget::read_modifiers_from_gdk(GdkEvent* event) const noexcept
}
unsigned
-Widget::key_event_translate_ctrlkey(vte::terminal::KeyEvent const& event) const noexcept
+Widget::key_event_translate_ctrlkey(KeyEvent const& event) const noexcept
{
if (event.keyval() < 128)
return event.keyval();
@@ -351,13 +351,13 @@ Widget::key_event_translate_ctrlkey(vte::terminal::KeyEvent const& event) const
return keyval;
}
-vte::terminal::KeyEvent
+KeyEvent
Widget::key_event_from_gdk(GdkEventKey* event) const
{
- auto type = vte::terminal::EventBase::Type{};
+ auto type = EventBase::Type{};
switch (gdk_event_get_event_type(reinterpret_cast<GdkEvent*>(event))) {
- case GDK_KEY_PRESS: type = vte::terminal::KeyEvent::Type::eKEY_PRESS; break;
- case GDK_KEY_RELEASE: type = vte::terminal::KeyEvent::Type::eKEY_RELEASE; break;
+ case GDK_KEY_PRESS: type = KeyEvent::Type::eKEY_PRESS; break;
+ case GDK_KEY_RELEASE: type = KeyEvent::Type::eKEY_RELEASE; break;
default: g_assert_not_reached(); return {};
}
@@ -372,19 +372,19 @@ Widget::key_event_from_gdk(GdkEventKey* event) const
event->is_modifier != 0};
}
-std::optional<vte::terminal::MouseEvent>
+std::optional<MouseEvent>
Widget::mouse_event_from_gdk(GdkEvent* event) const
{
- auto type = vte::terminal::EventBase::Type{};
+ auto type = EventBase::Type{};
switch (gdk_event_get_event_type(event)) {
- case GDK_2BUTTON_PRESS: type = vte::terminal::MouseEvent::Type::eMOUSE_DOUBLE_PRESS; break;
- case GDK_3BUTTON_PRESS: type = vte::terminal::MouseEvent::Type::eMOUSE_TRIPLE_PRESS; break;
- case GDK_BUTTON_PRESS: type = vte::terminal::MouseEvent::Type::eMOUSE_PRESS; break;
- case GDK_BUTTON_RELEASE: type = vte::terminal::MouseEvent::Type::eMOUSE_RELEASE; break;
- case GDK_ENTER_NOTIFY: type = vte::terminal::MouseEvent::Type::eMOUSE_ENTER; break;
- case GDK_LEAVE_NOTIFY: type = vte::terminal::MouseEvent::Type::eMOUSE_LEAVE; break;
- case GDK_MOTION_NOTIFY: type = vte::terminal::MouseEvent::Type::eMOUSE_MOTION; break;
- case GDK_SCROLL: type = vte::terminal::MouseEvent::Type::eMOUSE_SCROLL; break;
+ 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_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;
default:
return std::nullopt;
}
@@ -398,13 +398,13 @@ Widget::mouse_event_from_gdk(GdkEvent* event) const
auto button = unsigned{0};
(void)gdk_event_get_button(event, &button);
- auto mouse_event = vte::terminal::MouseEvent{event,
- type,
- gdk_event_get_time(event),
- read_modifiers_from_gdk(event),
- vte::terminal::MouseEvent::Button(button),
- x,
- y};
+ auto mouse_event = MouseEvent{event,
+ type,
+ gdk_event_get_time(event),
+ read_modifiers_from_gdk(event),
+ MouseEvent::Button(button),
+ x,
+ y};
return mouse_event;
}
diff --git a/src/widget.hh b/src/widget.hh
index c5ccbeaa..f3aa1a89 100644
--- a/src/widget.hh
+++ b/src/widget.hh
@@ -45,6 +45,219 @@ enum class ClipboardType {
PRIMARY = 1
};
+class EventBase {
+ friend class vte::platform::Widget;
+ friend class Terminal;
+
+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:
+
+ EventBase() noexcept = default;
+
+ constexpr EventBase(GdkEvent* gdk_event,
+ Type type,
+ unsigned timestamp) noexcept
+ : m_platform_event{gdk_event},
+ m_type{type},
+ m_timestamp{timestamp}
+ {
+ }
+
+ constexpr auto platform_event() const noexcept { return m_platform_event; }
+
+public:
+ ~EventBase() noexcept = default;
+
+ EventBase(EventBase const&) = default;
+ EventBase(EventBase&&) = default;
+ EventBase& operator=(EventBase const&) = delete;
+ EventBase& operator=(EventBase&&) = delete;
+
+ constexpr auto const timestamp() const noexcept { return m_timestamp; }
+ constexpr auto const type() const noexcept { return m_type; }
+
+private:
+ GdkEvent* m_platform_event;
+ Type m_type;
+ unsigned m_timestamp;
+}; // class EventBase
+
+class KeyEvent : public EventBase {
+ friend class vte::platform::Widget;
+ friend class Terminal;
+
+protected:
+
+ KeyEvent() noexcept = default;
+
+ constexpr KeyEvent(GdkEvent* gdk_event,
+ Type type,
+ unsigned timestamp,
+ unsigned modifiers,
+ unsigned keyval,
+ unsigned keycode,
+ uint8_t group,
+ bool is_modifier) noexcept
+ : EventBase{gdk_event,
+ type,
+ timestamp},
+ m_modifiers{modifiers},
+ m_keyval{keyval},
+ m_keycode{keycode},
+ m_group{group},
+ m_is_modifier{is_modifier}
+ {
+ }
+
+public:
+ ~KeyEvent() noexcept = default;
+
+ KeyEvent(KeyEvent const&) = delete;
+ KeyEvent(KeyEvent&&) = delete;
+ KeyEvent& operator=(KeyEvent const&) = delete;
+ KeyEvent& operator=(KeyEvent&&) = delete;
+
+ constexpr auto const group() const noexcept { return m_group; }
+ constexpr auto const is_modifier() const noexcept { return m_is_modifier; }
+ constexpr auto const keycode() const noexcept { return m_keycode; }
+ constexpr auto const keyval() const noexcept { return m_keyval; }
+ constexpr auto const modifiers() const noexcept { return m_modifiers; }
+
+ constexpr auto const is_key_press() const noexcept { return type() == Type::eKEY_PRESS; }
+ constexpr auto const is_key_release() const noexcept { return type() == Type::eKEY_RELEASE; }
+
+ auto const string() const noexcept
+ {
+ return reinterpret_cast<GdkEventKey*>(platform_event())->string;
+ }
+
+private:
+ unsigned m_modifiers;
+ unsigned m_keyval;
+ unsigned m_keycode;
+ uint8_t m_group;
+ bool m_is_modifier;
+}; // class KeyEvent
+
+class MouseEvent : public EventBase {
+ friend class vte::platform::Widget;
+ friend class Terminal;
+
+public:
+ enum class Button {
+ eNONE = 0,
+ eLEFT = 1,
+ eMIDDLE = 2,
+ eRIGHT = 3,
+ eFOURTH = 4,
+ eFIFTH = 5,
+ };
+
+ enum class ScrollDirection {
+ eUP,
+ eDOWN,
+ eLEFT,
+ eRIGHT,
+ eSMOOTH,
+ eNONE,
+ };
+
+protected:
+
+ MouseEvent() noexcept = default;
+
+ constexpr MouseEvent(GdkEvent* gdk_event,
+ Type type,
+ unsigned timestamp,
+ unsigned modifiers,
+ Button button,
+ double x,
+ double y) noexcept
+ : EventBase{gdk_event,
+ type,
+ timestamp},
+ m_modifiers{modifiers},
+ m_button{button},
+ m_x{x},
+ m_y{y}
+ {
+ }
+
+public:
+ ~MouseEvent() noexcept = default;
+
+ MouseEvent(MouseEvent const&) = default;
+ MouseEvent(MouseEvent&&) = default;
+ MouseEvent& operator=(MouseEvent const&) = delete;
+ MouseEvent& operator=(MouseEvent&&) = delete;
+
+ constexpr auto const button() const noexcept { return m_button; }
+ constexpr auto const button_value() const noexcept { return unsigned(m_button); }
+ constexpr auto const modifiers() const noexcept { return m_modifiers; }
+ constexpr auto const x() const noexcept { return m_x; }
+ constexpr auto const y() const noexcept { return m_y; }
+
+ constexpr auto const is_mouse_double_press() const noexcept { return type() ==
Type::eMOUSE_DOUBLE_PRESS; }
+ constexpr auto const is_mouse_enter() const noexcept { return type() == Type::eMOUSE_ENTER;
}
+ constexpr auto const is_mouse_leave() const noexcept { return type() == Type::eMOUSE_LEAVE;
}
+ constexpr auto const is_mouse_motion() const noexcept { return type() == Type::eMOUSE_MOTION;
}
+ constexpr auto const is_mouse_press() const noexcept { return type() == Type::eMOUSE_PRESS;
}
+ constexpr auto const is_mouse_release() const noexcept { return type() == Type::eMOUSE_RELEASE;
}
+ constexpr auto const is_mouse_scroll() const noexcept { return type() == Type::eMOUSE_SCROLL;
}
+ constexpr auto const is_mouse_single_press() const noexcept { return type() == Type::eMOUSE_PRESS;
}
+ constexpr auto const is_mouse_triple_press() const noexcept { return type() ==
Type::eMOUSE_TRIPLE_PRESS; }
+
+ ScrollDirection scroll_direction() const noexcept
+ {
+ /* Note that we cannot use gdk_event_get_scroll_direction() here since it
+ * returns false for smooth scroll events.
+ */
+ if (!is_mouse_scroll())
+ return ScrollDirection::eNONE;
+ switch (reinterpret_cast<GdkEventScroll*>(platform_event())->direction) {
+ case GDK_SCROLL_UP: return ScrollDirection::eUP;
+ case GDK_SCROLL_DOWN: return ScrollDirection::eDOWN;
+ case GDK_SCROLL_LEFT: return ScrollDirection::eLEFT;
+ case GDK_SCROLL_RIGHT: return ScrollDirection::eRIGHT;
+ case GDK_SCROLL_SMOOTH: return ScrollDirection::eSMOOTH;
+ default: return ScrollDirection::eNONE;
+ }
+ }
+
+ auto scroll_delta_x() const noexcept
+ {
+ auto delta = double{0.};
+ gdk_event_get_scroll_deltas(platform_event(), &delta, nullptr);
+ return delta;
+ }
+
+ auto scroll_delta_y() const noexcept
+ {
+ auto delta = double{0.};
+ gdk_event_get_scroll_deltas(platform_event(), nullptr, &delta);
+ return delta;
+ }
+
+private:
+ unsigned m_modifiers;
+ Button m_button;
+ double m_x;
+ double m_y;
+}; // class MouseEvent
+
class Widget {
public:
friend class vte::terminal::Terminal;
@@ -208,7 +421,7 @@ protected:
void set_cursor(GdkCursor* cursor) noexcept;
void set_cursor(Cursor const& cursor) noexcept;
- bool im_filter_keypress(vte::terminal::KeyEvent const& event) noexcept;
+ bool im_filter_keypress(KeyEvent const& event) noexcept;
void im_focus_in() noexcept;
void im_focus_out() noexcept;
@@ -223,15 +436,15 @@ protected:
void unset_pty() noexcept;
- unsigned key_event_translate_ctrlkey(vte::terminal::KeyEvent const& event) const noexcept;
+ unsigned key_event_translate_ctrlkey(KeyEvent const& event) const noexcept;
public: // FIXMEchpe
void im_preedit_changed() noexcept;
private:
unsigned read_modifiers_from_gdk(GdkEvent* event) const noexcept;
- vte::terminal::KeyEvent key_event_from_gdk(GdkEventKey* event) const;
- std::optional<vte::terminal::MouseEvent> mouse_event_from_gdk(GdkEvent* event) const;
+ KeyEvent key_event_from_gdk(GdkEventKey* event) const;
+ std::optional<MouseEvent> mouse_event_from_gdk(GdkEvent* event) const;
GtkWidget* m_widget;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]