aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2023-08-27 17:10:39 +0200
committerWolfgang Müller2023-08-27 17:10:39 +0200
commit2fdbf96d6ff9828c946197e17d803f45510c2aa4 (patch)
treecea25d8fc647f6da16db5d468970dbb9cb8f2eaa
parent39b2c7e8c41945ea95ffd51791cc18490bc73875 (diff)
downloadweltschmerz-2fdbf96d6ff9828c946197e17d803f45510c2aa4.tar.gz
Act as a drop destination for drag & drop
For now we support text and URIs. If file:// URIs are dropped, the file:// prefix will be removed from each, and they will be unescaped and quoted for use in the shell.
-rw-r--r--terminal.ui1
-rw-r--r--terminal.vala34
2 files changed, 35 insertions, 0 deletions
diff --git a/terminal.ui b/terminal.ui
index 6d5d206..af94317 100644
--- a/terminal.ui
+++ b/terminal.ui
@@ -139,6 +139,7 @@
<signal name="button-press-event" handler="vte_button_press" swapped="no"/>
<signal name="button-release-event" handler="vte_button_release" swapped="no"/>
<signal name="child-exited" handler="gtk_main_quit" swapped="no"/>
+ <signal name="drag-data-received" handler="vte_drag_data_received" swapped="no"/>
<signal name="hyperlink-hover-uri-changed" handler="vte_hyperlink_hover" swapped="no"/>
<signal name="key-press-event" handler="vte_key_press" swapped="no"/>
<signal name="scroll-event" handler="vte_scroll" swapped="no"/>
diff --git a/terminal.vala b/terminal.vala
index 67256d4..fcb456c 100644
--- a/terminal.vala
+++ b/terminal.vala
@@ -70,6 +70,13 @@ class Terminal : Gtk.Overlay {
uri_context_menu.attach_to_widget(vte, null);
standard_context_menu.attach_to_widget(vte, null);
+ Gtk.TargetList targets = new Gtk.TargetList({});
+ targets.add_text_targets(0);
+ targets.add_uri_targets(1);
+
+ Gtk.drag_dest_set(vte, Gtk.DestDefaults.ALL, {}, Gdk.DragAction.COPY);
+ Gtk.drag_dest_set_target_list(vte, targets);
+
clipboard = Gtk.Clipboard.get_default(window.get_display());
primary = Gtk.Clipboard.get_for_display(window.get_display(), Gdk.SELECTION_PRIMARY);
@@ -591,4 +598,31 @@ class Terminal : Gtk.Overlay {
window.set_urgency_hint(false);
window.set_urgency_hint(true);
}
+
+ [GtkCallback]
+ void vte_drag_data_received(Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint info, uint time_) {
+ if (info == 0) {
+ string text = selection_data.get_text();
+
+ if (text != null) {
+ vte.paste_text(text);
+ }
+ } else if (info == 1) {
+ string[] uris = selection_data.get_uris();
+ string text = "";
+
+ foreach (var uri in uris) {
+ if (uri == null || uri.length == 0)
+ continue;
+
+ if (uri.has_prefix("file://")) {
+ uri = Shell.quote(Uri.unescape_string(uri.substring(7)));
+ }
+
+ text = string.join(" ", text, uri);
+ }
+
+ vte.paste_text(text.strip());
+ }
+ }
}