diff options
author | Christian Persch <chpe@src.gnome.org> | 2021-03-06 23:08:54 +0100 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2021-03-06 23:08:54 +0100 |
commit | c346a0dd6a149f93ffd63bc4b36dbaa34a02bafe (patch) | |
tree | dfce398d3cb9dbece7e4fd6bc462642903f26544 | |
parent | 80e45218ab4962f1b0e282de91e9814d45eca7e3 (diff) | |
download | vte-c346a0dd6a149f93ffd63bc4b36dbaa34a02bafe.tar.gz |
widget: gtk4: Add focus event handling
Only local focus for now; need to hook up toplevel focus still.
-rw-r--r-- | src/widget.cc | 47 | ||||
-rw-r--r-- | src/widget.hh | 2 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/widget.cc b/src/widget.cc index 951189e4..08c61593 100644 --- a/src/widget.cc +++ b/src/widget.cc @@ -195,6 +195,30 @@ catch (...) return false; } +static void +focus_enter_cb(GtkEventControllerFocus* controller, + Widget* that) noexcept +try +{ + that->event_focus_enter(controller); +} +catch (...) +{ + vte::log_exception(); +} + +static void +focus_leave_cb(GtkEventControllerFocus* controller, + Widget* that) noexcept +try +{ + that->event_focus_leave(controller); +} +catch (...) +{ + vte::log_exception(); +} + #endif /* VTE_GTK == 4 */ Widget::Widget(VteTerminal* t) @@ -423,6 +447,13 @@ Widget::constructed() noexcept G_CALLBACK(key_modifiers_cb), this); gtk_widget_add_controller(m_widget, controller.release()); + controller = vte::glib::take_ref(gtk_event_controller_focus_new()); + g_signal_connect(controller.get(), "enter", + G_CALLBACK(focus_enter_cb), this); + g_signal_connect(controller.get(), "leave", + G_CALLBACK(focus_leave_cb), this); + gtk_widget_add_controller(m_widget, controller.release()); + #endif /* VTE_GTK == 4 */ #if VTE_GTK == 3 @@ -647,6 +678,22 @@ Widget::event_key_modifiers(GtkEventControllerKey* controller, return terminal()->widget_key_modifiers(modifiers); } +void +Widget::event_focus_enter(GtkEventControllerFocus* controller) +{ + _vte_debug_print(VTE_DEBUG_EVENTS, "Focus In"); + + terminal()->widget_focus_in(); +} + +void +Widget::event_focus_leave(GtkEventControllerFocus* controller) +{ + _vte_debug_print(VTE_DEBUG_EVENTS, "Focus Out"); + + terminal()->widget_focus_out(); +} + #endif /* VTE_GTK == 4 */ void diff --git a/src/widget.hh b/src/widget.hh index e644fca5..a44ae303 100644 --- a/src/widget.hh +++ b/src/widget.hh @@ -334,6 +334,8 @@ public: unsigned modifiers); bool event_key_modifiers(GtkEventControllerKey* controller, unsigned modifiers); + void event_focus_enter(GtkEventControllerFocus* controller); + void event_focus_leave(GtkEventControllerFocus* controller); #endif /* VTE_GTK == 4 */ void grab_focus() noexcept { gtk_widget_grab_focus(gtk()); } |