[gtksourceview/wip/chergert/vim: 186/363] add event capture API




commit a6e46ce8faa47bff9f1a8962207fadd1c8dd402f
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 1 15:17:56 2021 -0700

    add event capture API

 gtksourceview/vim/gtk-source-vim-state.c | 27 +++++++++++++++++++++++++++
 gtksourceview/vim/gtk-source-vim-state.h |  4 ++++
 gtksourceview/vim/gtk-source-vim.c       |  6 ++++++
 3 files changed, 37 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 86067bc3..bb4b1a7e 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -919,3 +919,30 @@ gtk_source_vim_state_get_registers (GtkSourceVimState *self)
 
        return priv->registers;
 }
+
+gboolean
+gtk_source_vim_state_capture (GtkSourceVimState *self,
+                              GdkEvent          *event)
+{
+       GtkSourceVimState *child;
+
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
+       g_return_val_if_fail (event != NULL, FALSE);
+
+       if (GTK_SOURCE_VIM_STATE_GET_CLASS (self)->capture)
+       {
+               if (GTK_SOURCE_VIM_STATE_GET_CLASS (self)->capture (self, event))
+               {
+                       return TRUE;
+               }
+       }
+
+       child = gtk_source_vim_state_get_child (self);
+
+       if (child != NULL)
+       {
+               return gtk_source_vim_state_capture (child, event);
+       }
+
+       return FALSE;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index b8ec2e04..71297d4c 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -45,6 +45,8 @@ struct _GtkSourceVimStateClass
        void        (*resume)               (GtkSourceVimState *self,
                                             GtkSourceVimState *from);
        void        (*leave)                (GtkSourceVimState *self);
+       gboolean    (*capture)              (GtkSourceVimState *self,
+                                            GdkEvent          *event);
        gboolean    (*handle_event)         (GtkSourceVimState *self,
                                             GdkEvent          *event);
        gboolean    (*handle_keypress)      (GtkSourceVimState *self,
@@ -83,6 +85,8 @@ void               gtk_source_vim_state_set_can_repeat        (GtkSourceVimState
                                                                gboolean           can_repeat);
 void               gtk_source_vim_state_begin_user_action     (GtkSourceVimState *self);
 void               gtk_source_vim_state_end_user_action       (GtkSourceVimState *self);
+gboolean           gtk_source_vim_state_capture               (GtkSourceVimState *self,
+                                                               GdkEvent          *event);
 gboolean           gtk_source_vim_state_handle_event          (GtkSourceVimState *self,
                                                                GdkEvent          *event);
 void               gtk_source_vim_state_set_overwrite         (GtkSourceVimState *self,
diff --git a/gtksourceview/vim/gtk-source-vim.c b/gtksourceview/vim/gtk-source-vim.c
index 6a995c34..9a8f5276 100644
--- a/gtksourceview/vim/gtk-source-vim.c
+++ b/gtksourceview/vim/gtk-source-vim.c
@@ -80,6 +80,12 @@ gtk_source_vim_handle_event (GtkSourceVimState *state,
        g_assert (GTK_SOURCE_IS_VIM (self));
        g_assert (event != NULL);
 
+       /* Allow parent states to capture input before current state */
+       if (gtk_source_vim_state_capture (state, event))
+       {
+               return TRUE;
+       }
+
        current = gtk_source_vim_state_get_current (state);
 
        if (current == state)


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