[vte] widget: Add function to check for match at event coordinates



commit 1dc05b9b33acd0bfe21c2d8f00d7a78babc4af0a
Author: Christian Persch <chpe gnome org>
Date:   Mon Apr 14 21:01:52 2014 +0200

    widget: Add function to check for match at event coordinates
    
    This saves the caller from translating from event coordinates to
    grid coordinates himself.

 doc/reference/vte-sections.txt |    1 +
 src/Makefile.am                |    3 ++-
 src/app.vala                   |    7 +------
 src/vte.c                      |   40 ++++++++++++++++++++++++++++++++++++++++
 src/vte.h                      |    3 +++
 5 files changed, 47 insertions(+), 7 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 8878ef2..713ab60 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -60,6 +60,7 @@ vte_terminal_match_add_gregex
 vte_terminal_match_remove
 vte_terminal_match_remove_all
 vte_terminal_match_check
+vte_terminal_match_check_event
 vte_terminal_match_set_cursor
 vte_terminal_match_set_cursor_type
 vte_terminal_match_set_cursor_name
diff --git a/src/Makefile.am b/src/Makefile.am
index 9484374..7ad747a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -216,6 +216,8 @@ if ENABLE_TEST_APPLICATION
 
 bin_PROGRAMS = vte- VTE_API_MAJOR_VERSION@  VTE_API_MINOR_VERSION@
 
+vte- VTE_API_MAJOR_VERSION@  VTE_API_MINOR_VERSION@: vte-$(VTE_API_VERSION).vapi
+
 vte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_SOURCES = \
        app.vala \
        config.vapi \
@@ -229,7 +231,6 @@ vte_ VTE_API_MAJOR_VERSION@_ VTE_API_MINOR_VERSION@_VALAFLAGS = \
        --vapidir=. \
        --girdir=. \
        --pkg=posix \
-       --pkg=linux \
        --pkg=gio-2.0 \
        --pkg=gtk+-$(GTK_API_VERSION) \
        --pkg=vte-$(VTE_API_VERSION) \
diff --git a/src/app.vala b/src/app.vala
index 1693354..b9d7728 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -356,12 +356,7 @@ class Window : Gtk.ApplicationWindow
                if (App.Options.no_context_menu)
                        return false;
 
-               var padding = get_style_context().get_padding(get_state_flags());
-        var char_width = terminal.get_char_width();
-        var char_height = terminal.get_char_height();
-               var match = terminal.match_check(((int)event.x - padding.left) / (int)char_width,
-                                                                                ((int)event.y - padding.top) 
/ (int)char_height,
-                                                                                null);
+               var match = terminal.match_check_event(event, null);
 
                var menu = new GLib.Menu();
                menu.append("_Copy", "win.copy");
diff --git a/src/vte.c b/src/vte.c
index 61e1fb9..aa654fa 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -1709,6 +1709,46 @@ vte_terminal_match_check(VteTerminal *terminal, glong column, glong row,
        return ret;
 }
 
+/**
+ * vte_terminal_match_check_event:
+ * @terminal: a #VteTerminal
+ * @event: a #GdkEvent
+ * @tag: (out) (allow-none): a location to store the tag, or %NULL
+ *
+ * Checks if the text in and around the position of the event matches any of the
+ * regular expressions previously set using vte_terminal_match_add().  If a
+ * match exists, the text string is returned and if @tag is not %NULL, the number
+ * associated with the matched regular expression will be stored in @tag.
+ *
+ * If more than one regular expression has been set with
+ * vte_terminal_match_add(), then expressions are checked in the order in
+ * which they were added.
+ *
+ * Returns: (transfer full): a newly allocated string which matches one of the previously
+ *   set regular expressions
+ */
+char *
+vte_terminal_match_check_event(VteTerminal *terminal,
+                               GdkEvent *event,
+                               int *tag)
+{
+        double x, y;
+        long col, row;
+
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+
+        if (event == NULL)
+                return FALSE;
+        if (((GdkEventAny*)event)->window != gtk_widget_get_window(&terminal->widget))
+                return FALSE;
+        if (!gdk_event_get_coords(event, &x, &y))
+                return FALSE;
+        if (!_vte_terminal_xy_to_grid(terminal, x, y, &col, &row))
+                return FALSE;
+
+        return vte_terminal_match_check(terminal, col, row, tag);
+}
+
 /* Emit an adjustment changed signal on our adjustment object. */
 static void
 vte_terminal_emit_adjustment_changed(VteTerminal *terminal)
diff --git a/src/vte.h b/src/vte.h
index 26bf662..eb9c5e9 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -340,6 +340,9 @@ void vte_terminal_match_remove_all(VteTerminal *terminal);
 char *vte_terminal_match_check(VteTerminal *terminal,
                               glong column, glong row,
                               int *tag);
+char *vte_terminal_match_check_event(VteTerminal *terminal,
+                                     GdkEvent *event,
+                                     int *tag);
 
 void      vte_terminal_search_set_gregex      (VteTerminal *terminal,
                                               GRegex      *regex,


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