[vte] widget: gtk4: Add focus event handling



commit c346a0dd6a149f93ffd63bc4b36dbaa34a02bafe
Author: Christian Persch <chpe src gnome org>
Date:   Sat Mar 6 23:08:54 2021 +0100

    widget: gtk4: Add focus event handling
    
    Only local focus for now; need to hook up toplevel focus still.

 src/widget.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/widget.hh |  2 ++
 2 files changed, 49 insertions(+)
---
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()); }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]