Skip to content

Commit 564c964

Browse files
committed
Add remote drag protocol
Needs to be implemented.
1 parent 01055d3 commit 564c964

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

docs/dnd-protocol.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,61 @@ If ``t=e`` or ``t=E`` escape codes are sent to the terminal before the drag is
352352
started and the terminal has responded with ``t=E ; OK``, the terminal must respond
353353
with ``t=E ; EINVAL`` and abort the drag.
354354

355+
Dragging to remote machines
356+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
357+
358+
To support dragging files to remote machines, when requesting the data for the
359+
``text/uri-list`` MIME type, terminal emulators can add the ``Y=1`` key. On
360+
receipt of this key, the client should first send the ``text/uri-list`` as
361+
normal and then a series of responses for every ``file://`` URL type in the
362+
list of the form::
363+
364+
OSC _dnd_code ; t=k:x=idx:m=0 or 1 ; base64 encoded file data ST
365+
OSC _dnd_code ; t=k:x=idx:X=1:m=0 or 1 ; base64 encoded symlink target ST
366+
OSC _dnd_code ; t=k:x=idx:X=handle:m=0 or 1 ; base64 encoded null separated list of directory entries ST
367+
368+
These represent possibly chunked data for files, symlinks and directories, as
369+
denoted by the ``X`` key. As always, end of data is indicated by an escape code
370+
with ``m=0`` and no payload. ``idx`` is the one based index into the list of
371+
entries in the ``text/uri-list`` MIME type. ``file://`` URLs that point to
372+
symlinks must be resolved to files or directories and sent. So actual symlinks
373+
will appear only when recursing through directories as described below. Only
374+
regular files should be sent.
375+
376+
Terminals should write the transmitted data into a temporary directory
377+
and replace the entries in the ``text/uri-list`` data with the transmitted
378+
files/directories.
379+
380+
Every directory must be transmitted with ``X=handle``. The payload
381+
is a null separated list of regular files, directories and symlinks in the
382+
directory. ``handle`` is an integer other than ``0`` or ``1``
383+
that serves as an identifier for the directory. Directories must be traversed
384+
in breadth first order. The children of a directory are reported by
385+
adding ``Y=parent-handle:y=num`` to the escape codes above. Here
386+
``parent-handle`` is the handle of the directory being traversed and ``num``
387+
is the one based index into the list of entries in the directory.
388+
389+
Once all data is transmitted, the client informs the terminal emulator of
390+
completion with::
391+
392+
OSC _dnd_code ; t=k ; ST
393+
394+
If any error occurs in the client while reading the data, it can inform
395+
the terminal using::
396+
397+
OSC _dnd_code ; t=E ; POSIX error name ST
398+
399+
The terminal must then abort the drag.
400+
401+
Terminals are free to impose resource limits on how much data they accept,
402+
if a limit is breached or some errors occurs, they can abort the drag and
403+
inform the client of it with::
404+
405+
OSC _dnd_code ; t=E ; POSIX error name ST
406+
407+
The error code for too many resources is ``EMFILE`` for IO errors is ``EIO``
408+
and so on.
409+
355410
Multiplexers
356411
-----------------
357412

@@ -383,6 +438,7 @@ Key Value Default Description
383438
``P`` - Change drag image or start drag
384439
``e`` - a drag offer event occurred
385440
``E`` - a drag offer data error occurred
441+
``k`` - data for uri-list items in drag offer
386442

387443
``m`` Chunking indicator ``0`` ``0`` or ``1``
388444

gen/apc_parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def parsers() -> None:
333333
write_header(text, 'kitty/parse-multicell-command.h')
334334

335335
keymap = {
336-
't': ('type', flag('aAmMrRoOpPeE')),
336+
't': ('type', flag('aAmMrRoOpPeEk')),
337337
'm': ('more', 'uint'),
338338
'i': ('client_id', 'uint'),
339339
'o': ('operation', 'uint'),

kitty/parse-dnd-command.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ static inline void parse_dnd_code(PS *self, uint8_t *parser_buf,
8888
g.type = parser_buf[pos++];
8989
if (g.type != 'A' && g.type != 'E' && g.type != 'M' && g.type != 'O' &&
9090
g.type != 'P' && g.type != 'R' && g.type != 'a' && g.type != 'e' &&
91-
g.type != 'm' && g.type != 'o' && g.type != 'p' && g.type != 'r') {
91+
g.type != 'k' && g.type != 'm' && g.type != 'o' && g.type != 'p' &&
92+
g.type != 'r') {
9293
REPORT_ERROR("Malformed DnDCommand control block, unknown flag value "
9394
"for type: 0x%x",
9495
g.type);

0 commit comments

Comments
 (0)