[vte] widget: Simplify mouse event translation
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Simplify mouse event translation
- Date: Tue, 6 Oct 2020 17:46:25 +0000 (UTC)
commit 6495f3e0c05468f3a85fbceef34ed8122146688c
Author: Christian Persch <chpe src gnome org>
Date: Tue Oct 6 19:46:17 2020 +0200
widget: Simplify mouse event translation
Just throw on unexpected event type.
src/widget.cc | 8 ++++----
src/widget.hh | 30 +++++++++++-------------------
2 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/src/widget.cc b/src/widget.cc
index b516c07f..86337055 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -372,8 +372,8 @@ Widget::key_event_from_gdk(GdkEventKey* event) const
event->is_modifier != 0};
}
-std::optional<MouseEvent>
-Widget::mouse_event_from_gdk(GdkEvent* event) const
+MouseEvent
+Widget::mouse_event_from_gdk(GdkEvent* event) const /* throws */
{
auto type = EventBase::Type{};
switch (gdk_event_get_event_type(event)) {
@@ -386,14 +386,14 @@ Widget::mouse_event_from_gdk(GdkEvent* event) const
case GDK_MOTION_NOTIFY: type = MouseEvent::Type::eMOUSE_MOTION; break;
case GDK_SCROLL: type = MouseEvent::Type::eMOUSE_SCROLL; break;
default:
- return std::nullopt;
+ throw std::runtime_error{"Unexpected event type"};
}
auto x = double{};
auto y = double{};
if (gdk_event_get_window(event) != m_event_window ||
!gdk_event_get_coords(event, &x, &y))
- x = y = -1.; // FIXMEchpe or return std::nullopt?
+ x = y = -1.; // FIXMEchpe or throw?
auto button = unsigned{0};
(void)gdk_event_get_button(event, &button);
diff --git a/src/widget.hh b/src/widget.hh
index f3aa1a89..5defe310 100644
--- a/src/widget.hh
+++ b/src/widget.hh
@@ -294,12 +294,12 @@ public:
void focus_out(GdkEventFocus *event) noexcept { m_terminal->widget_focus_out(); }
bool key_press(GdkEventKey *event) noexcept { return
m_terminal->widget_key_press(key_event_from_gdk(event)); }
bool key_release(GdkEventKey *event) noexcept { return
m_terminal->widget_key_release(key_event_from_gdk(event)); }
- bool button_press(GdkEventButton *event) noexcept { return
m_terminal->widget_mouse_press(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
- bool button_release(GdkEventButton *event) noexcept { return
m_terminal->widget_mouse_release(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
- void enter(GdkEventCrossing *event) noexcept {
m_terminal->widget_mouse_enter(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
- void leave(GdkEventCrossing *event) noexcept {
m_terminal->widget_mouse_leave(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
- bool scroll(GdkEventScroll *event) noexcept { return
m_terminal->widget_mouse_scroll(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
- bool motion_notify(GdkEventMotion *event) noexcept { return
m_terminal->widget_mouse_motion(*mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ bool button_press(GdkEventButton *event) noexcept { return
m_terminal->widget_mouse_press(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ bool button_release(GdkEventButton *event) noexcept { return
m_terminal->widget_mouse_release(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ void enter(GdkEventCrossing *event) noexcept {
m_terminal->widget_mouse_enter(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ void leave(GdkEventCrossing *event) noexcept {
m_terminal->widget_mouse_leave(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ bool scroll(GdkEventScroll *event) noexcept { return
m_terminal->widget_mouse_scroll(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
+ bool motion_notify(GdkEventMotion *event) noexcept { return
m_terminal->widget_mouse_motion(mouse_event_from_gdk(reinterpret_cast<GdkEvent*>(event))); }
void grab_focus() noexcept { gtk_widget_grab_focus(gtk()); }
@@ -368,10 +368,7 @@ public:
char* regex_match_check(GdkEvent* event,
int* tag)
{
- if (auto mouse_event = mouse_event_from_gdk(event))
- return terminal()->regex_match_check(*mouse_event, tag);
- else
- return nullptr;
+ return terminal()->regex_match_check(mouse_event_from_gdk(event), tag);
}
bool regex_match_check_extra(GdkEvent* event,
@@ -380,18 +377,13 @@ public:
uint32_t match_flags,
char** matches)
{
- if (auto mouse_event = mouse_event_from_gdk(event))
- return terminal()->regex_match_check_extra(*mouse_event, regexes, n_regexes,
match_flags, matches);
- else
- return false;
+ return terminal()->regex_match_check_extra(mouse_event_from_gdk(event),
+ regexes, n_regexes, match_flags, matches);
}
char* hyperlink_check(GdkEvent* event)
{
- if (auto mouse_event = mouse_event_from_gdk(event))
- return terminal()->hyperlink_check(*mouse_event);
- else
- return nullptr;
+ return terminal()->hyperlink_check(mouse_event_from_gdk(event));
}
bool should_emit_signal(int id) noexcept;
@@ -444,7 +436,7 @@ public: // FIXMEchpe
private:
unsigned read_modifiers_from_gdk(GdkEvent* event) const noexcept;
KeyEvent key_event_from_gdk(GdkEventKey* event) const;
- std::optional<MouseEvent> mouse_event_from_gdk(GdkEvent* event) const;
+ MouseEvent mouse_event_from_gdk(GdkEvent* event) const /* throws */;
GtkWidget* m_widget;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]