From 8bb2c476dfadd4bcb30e8a962443dae318c95fea Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 6 Jul 2012 19:39:07 -0400 Subject: [PATCH] AtkText -> vte_terminal_select_text vte requires a patch to expose this for now, but it's the only way to do this since AtkText is completely broken --- README.rst | 12 +++------ expose_select_text.patch | 57 ++++++++++++++++++++++++++++++++++++++++ termite.c | 16 +++++------ 3 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 expose_select_text.patch diff --git a/README.rst b/README.rst index f72d1b5..c59d22f 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,8 @@ unset) and then falls back to ``$XDG_CONFIG_DIRS``. DEPENDENCIES ============ -A vte version >= 0.30. +A vte version >= 0.30. A patch is currently required to expose the +``vte-terminal-select-text`` function which is used for keyboard selection. KEYBINDINGS =========== @@ -46,12 +47,7 @@ TODO * scrollback search needs to be improved upstream [1]_ * expose keybindings in ``termite.cfg`` -TEXT SELECTION --------------- - -* _vte_terminal_select_text would be perfect for extending this, but it isn't - exposed in the API -* does not currently work in ncurses applications -* needs to be extended to more than just the basic ``h``/``j``/``k``/``l`` +* text selection needs to be extended to more than just the basic + ``h``/``j``/``k``/``l`` .. [1] https://bugzilla.gnome.org/show_bug.cgi?id=627886 diff --git a/expose_select_text.patch b/expose_select_text.patch new file mode 100644 index 0000000..9ce5f61 --- /dev/null +++ b/expose_select_text.patch @@ -0,0 +1,57 @@ +diff -aur vte-0.32.2-old/src/vteaccess.c vte-0.32.2/src/vteaccess.c +--- vte-0.32.2-old/src/vteaccess.c 2012-07-06 19:26:00.615978048 -0400 ++++ vte-0.32.2/src/vteaccess.c 2012-07-06 19:26:52.543297289 -0400 +@@ -1666,7 +1666,7 @@ + VTE_TERMINAL_ACCESSIBLE_PRIVATE_DATA); + xy_from_offset (priv, start_offset, &start_x, &start_y); + xy_from_offset (priv, end_offset, &end_x, &end_y); +- _vte_terminal_select_text (terminal, start_x, start_y, end_x, end_y, start_offset, end_offset); ++ vte_terminal_select_text (terminal, start_x, start_y, end_x, end_y, start_offset, end_offset); + return TRUE; + } + +diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c +--- vte-0.32.2-old/src/vte.c 2012-07-06 19:26:00.612644674 -0400 ++++ vte-0.32.2/src/vte.c 2012-07-06 19:26:52.479963159 -0400 +@@ -14568,7 +14568,7 @@ + } + + void +-_vte_terminal_select_text(VteTerminal *terminal, ++vte_terminal_select_text(VteTerminal *terminal, + long start_col, long start_row, + long end_col, long end_row, + int start_offset, int end_offset) +@@ -14603,7 +14603,7 @@ + _vte_terminal_select_empty_at(VteTerminal *terminal, + long col, long row) + { +- _vte_terminal_select_text(terminal, col, row, col - 1, row, 0, 0); ++ vte_terminal_select_text(terminal, col, row, col - 1, row, 0, 0); + } + + static void +@@ -15293,7 +15293,7 @@ + g_free (row_text); + g_match_info_free (match_info); + +- _vte_terminal_select_text (terminal, start_col, start_row, end_col, end_row, 0, 0); ++ vte_terminal_select_text (terminal, start_col, start_row, end_col, end_row, 0, 0); + /* Quite possibly the math here should not access adjustment directly... */ + value = gtk_adjustment_get_value(terminal->adjustment); + page_size = gtk_adjustment_get_page_size(terminal->adjustment); +diff -aur vte-0.32.2-old/src/vte.h vte-0.32.2/src/vte.h +--- vte-0.32.2-old/src/vte.h 2012-07-06 19:26:00.612644674 -0400 ++++ vte-0.32.2/src/vte.h 2012-07-06 19:28:06.264224798 -0400 +@@ -485,6 +485,11 @@ + + char *vte_get_user_shell (void); + ++void vte_terminal_select_text(VteTerminal *terminal, ++ long start_col, long start_row, ++ long end_col, long end_row, ++ int start_offset, int end_offset); ++ + /* Accessors for bindings. */ + #if !GTK_CHECK_VERSION (2, 91, 2) + GtkAdjustment *vte_terminal_get_adjustment(VteTerminal *terminal); diff --git a/termite.c b/termite.c index 65e09ae..daa3233 100644 --- a/termite.c +++ b/termite.c @@ -6,7 +6,6 @@ #include #include #include -#include #ifndef __GNUC__ # define __attribute__(x) @@ -30,9 +29,9 @@ typedef enum select_mode { } select_mode; typedef struct select_info { - AtkText *text; select_mode mode; - int begin; + long begin_col; + long begin_row; } select_info; typedef struct search_panel_info { @@ -83,11 +82,10 @@ static void cursor_moved_cb(VteTerminal *vte, select_info *select) { vte_terminal_select_none(vte); - int offset = atk_text_get_caret_offset(select->text); + long end_row, end_col; + vte_terminal_get_cursor_position(vte, &end_col, &end_row); - atk_text_add_selection(select->text, - MIN(select->begin, offset), - MAX(select->begin, offset)); + vte_terminal_select_text(vte, select->begin_col, select->begin_row, end_col, end_row, 0, 0); vte_terminal_copy_primary(vte); } @@ -108,7 +106,7 @@ static void toggle_visual(VteTerminal *vte, select_info *select) { vte_terminal_select_none(vte); } else { select->mode = SELECT_VISUAL; - select->begin = atk_text_get_caret_offset(select->text); + vte_terminal_get_cursor_position(vte, &select->begin_col, &select->begin_row); } } @@ -641,7 +639,7 @@ int main(int argc, char **argv) { gtk_container_add(GTK_CONTAINER(overlay), vte); gtk_container_add(GTK_CONTAINER(window), overlay); - select_info select = {ATK_TEXT(vte_terminal_accessible_new(VTE_TERMINAL(vte))), SELECT_OFF, 0}; + select_info select = {SELECT_OFF, 0, 0}; search_panel_info info = {vte, entry, alignment, OVERLAY_HIDDEN, select}; g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);