[gnome-terminal] all: Insert text as paste



commit f5f15e67492ac61ebe664c5ea12377eedb41f112
Author: Christian Persch <chpe src gnome org>
Date:   Mon Mar 7 20:27:16 2022 +0100

    all: Insert text as paste
    
    Use new API vte_terminal_paste_text() to insert text.

 meson.build            |  2 +-
 src/terminal-screen.cc | 30 ++++++++++++++++++++++++++----
 src/terminal-screen.hh |  6 ++++++
 src/terminal-window.cc |  2 +-
 4 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/meson.build b/meson.build
index 639a19c2..7876cf86 100644
--- a/meson.build
+++ b/meson.build
@@ -45,7 +45,7 @@ clangxx_req_version       = '3.3'
 # Requirements
 
 vte_req                      = 'vte-2.91'
-vte_req_version              = '0.63.0'
+vte_req_version              = '0.67.90'
 
 glib_req_version             = '2.52.0'
 glib_min_req_version         = '2.52'
diff --git a/src/terminal-screen.cc b/src/terminal-screen.cc
index e1e8529e..a023aba7 100644
--- a/src/terminal-screen.cc
+++ b/src/terminal-screen.cc
@@ -1939,7 +1939,7 @@ terminal_screen_drag_data_received (GtkWidget        *widget,
       terminal_util_transform_uris_to_quoted_fuse_paths (uris);
 
       text = terminal_util_concat_uris (uris, &len);
-      vte_terminal_feed_child (VTE_TERMINAL (screen), text, len);
+      terminal_screen_paste_text (screen, text, len);
     }
   else if (gtk_targets_include_text (&selection_data_target, 1))
     {
@@ -1947,7 +1947,7 @@ terminal_screen_drag_data_received (GtkWidget        *widget,
 
       text = (char *) gtk_selection_data_get_text (selection_data);
       if (text && text[0])
-        vte_terminal_feed_child (VTE_TERMINAL (screen), text, strlen (text));
+        terminal_screen_paste_text (screen, text, -1);
     }
   else switch (info)
     {
@@ -2006,7 +2006,7 @@ terminal_screen_drag_data_received (GtkWidget        *widget,
         terminal_util_transform_uris_to_quoted_fuse_paths (uris); /* This may replace uris[0] */
 
         text = terminal_util_concat_uris (uris, &len);
-        vte_terminal_feed_child (VTE_TERMINAL (screen), text, len);
+        terminal_screen_paste_text (screen, text, len);
         g_free (text);
         g_free (uris[0]);
       }
@@ -2034,7 +2034,7 @@ terminal_screen_drag_data_received (GtkWidget        *widget,
         terminal_util_transform_uris_to_quoted_fuse_paths (uris); /* This may replace uris[0] */
 
         text = terminal_util_concat_uris (uris, &len);
-        vte_terminal_feed_child (VTE_TERMINAL (screen), text, len);
+        terminal_screen_paste_text (screen, text, len);
         g_free (text);
         g_free (uris[0]);
       }
@@ -2305,3 +2305,25 @@ terminal_screen_get_uuid (TerminalScreen *screen)
 
   return screen->priv->uuid;
 }
+
+/**
+ * terminal_screen_paste_text:
+ * @screen:
+ * @text: a NUL-terminated string
+ * @len: length of @text, or -1
+ *
+ * Inserts @text to @terminal as if pasted.
+ */
+void
+terminal_screen_paste_text (TerminalScreen* screen,
+                            char const* text,
+                            gssize len)
+{
+  g_return_if_fail (text != nullptr);
+  g_return_if_fail (len >= -1);
+
+  /* This is just an API hack until vte 0.69 adds vte_terminal_paste_text_len() */
+  /* Note that @text MUST be NUL-terminated */
+
+  vte_terminal_paste_text (VTE_TERMINAL (screen), text);
+}
diff --git a/src/terminal-screen.hh b/src/terminal-screen.hh
index df59b1a5..ded6b8ca 100644
--- a/src/terminal-screen.hh
+++ b/src/terminal-screen.hh
@@ -160,6 +160,12 @@ TerminalScreenPopupInfo *terminal_screen_popup_info_ref (TerminalScreenPopupInfo
 
 void terminal_screen_popup_info_unref (TerminalScreenPopupInfo *info);
 
+/* API hack */
+
+void terminal_screen_paste_text (TerminalScreen* screen,
+                                 char const* text,
+                                 gssize len);
+
 G_END_DECLS
 
 #endif /* TERMINAL_SCREEN_H */
diff --git a/src/terminal-window.cc b/src/terminal-window.cc
index 60f49500..76f18000 100644
--- a/src/terminal-window.cc
+++ b/src/terminal-window.cc
@@ -692,7 +692,7 @@ clipboard_uris_received_cb (GtkClipboard *clipboard,
     terminal_util_transform_uris_to_quoted_fuse_paths (uris);
     text = terminal_util_concat_uris (uris, &len);
 
-    vte_terminal_feed_child (VTE_TERMINAL (screen), text, len);
+    terminal_screen_paste_text (screen, text, len);
   }
 
   g_weak_ref_clear (&data->screen_weak_ref);


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