diff options
author | Wolfgang Müller | 2023-08-27 17:10:39 +0200 |
---|---|---|
committer | Wolfgang Müller | 2023-08-27 17:10:39 +0200 |
commit | 2fdbf96d6ff9828c946197e17d803f45510c2aa4 (patch) | |
tree | cea25d8fc647f6da16db5d468970dbb9cb8f2eaa /terminal.vala | |
parent | 39b2c7e8c41945ea95ffd51791cc18490bc73875 (diff) | |
download | weltschmerz-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.
Diffstat (limited to 'terminal.vala')
-rw-r--r-- | terminal.vala | 34 |
1 files changed, 34 insertions, 0 deletions
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()); + } + } } |