dnkl/foot
41
2.0k
Fork
You've already forked foot
242

Add support for OSC-5522, kitty's extended variant of OSC-52, with full mime-type access #2341

Open
dnkl wants to merge 6 commits from osc-5522 into master
pull from: osc-5522
merge into: dnkl:master
dnkl:master
dnkl:sixel-heap-buffer-overflow
dnkl:releases/1.27
dnkl:releases/1.26
dnkl:releases/1.25
dnkl:releases/1.24
dnkl:multi-cursor
dnkl:releases/1.23
dnkl:pixman-16f-2
dnkl:releases/1.22
dnkl:releases/1.21
dnkl:releases/1.20
dnkl:releases/1.19
dnkl:releases/1.18
dnkl:releases/1.17
dnkl:releases/1.16
dnkl:releases/1.15
dnkl:releases/1.14
dnkl:releases/1.13
dnkl:releases/1.12
dnkl:releases/1.11
dnkl:releases/1.10
dnkl:releases/1.9
dnkl:releases/1.8
dnkl:releases/1.7
dnkl:releases/1.6
dnkl:releases/1.5
dnkl:releases/1.4
dnkl:releases/1.3
dnkl:releases/1.2
dnkl:releases/1.1
dnkl:releases/1.0
Owner
Copy link

This implements OSC-5522, kitty's extended version of OSC-52, where all mime-types are made available to the terminal application. This means you can, for example, copy and paste image data.

Also supported is the "event extension", where paste actions (i.e. ctrl+shift+v etc) emit OSC-5522 mime-type listings instead of actually pasting anything. The terminal application can then request whichever mime-type it wants, or ignore the paste. This mode is activated by enabling private mode 5522.

kitten clipboard can be used to test the implementation.

This implements [OSC-5522](https://sw.kovidgoyal.net/kitty/clipboard/), kitty's extended version of OSC-52, where all mime-types are made available to the terminal application. This means you can, for example, copy and paste image data. Also supported is the [_"event extension"_](https://rockorager.dev/misc/bracketed-paste-mime/), where paste actions (i.e. ctrl+shift+v etc) emit OSC-5522 mime-type listings instead of actually pasting anything. The terminal application can then request whichever mime-type it wants, or ignore the paste. This mode is activated by enabling private mode 5522. [`kitten clipboard`](https://sw.kovidgoyal.net/kitty/kittens/clipboard/) can be used to test the implementation.
wip: osc-5522: initial parsing + reply to mime-type list query
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
1c8a5dc79e
wip: osc-5522: implement type=read, add private mode 5522
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
593b429784
wip: osc-5522: support reading multiple mime-types, support chunking
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
696f385f18
wip: osc-5522: parse write+wdata+walias, but do nothing with it yet
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
f29ab9da0f
wip: osc-5522: add support for 'write' + 'wdata'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
c1b7d9162c
'walias' is still missing
wip: osc-5522: fix handling of multiple 'wdata' chunks
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
a8344038d9
Data wasn't being appended correctly
wip: osc-5522: implement 'walias'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
328b2debaa
wip: osc-5522: error out on final wdata packet if there's no focused seat
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
bca7cdd812
wip: osc-5522: refactor: break out handling of the final wdata packet
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ab40ea2683
Convenience function for base64_encode() + base64_encode_final().
For now, not optimized at all, but implemented as
 base64_encode() + xrealloc() + base64_encode_final()
wip: osc-5522: query: hardcode the base64 encoded "." mime-type
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
434c72eea4
wip: osc-5522: query: include loc=primary when querying the primary selection
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
2a8a6dafd9
When replying to a mime-type query of the primary selection, include
loc=primary in the first type=read:status=OK response.
This is not (yet) covered by the specification, but will be necessary
when emitting unsolicited events in response to paste actions.
wip: osc-5522: emit unsolicited events on paste actions when private mode 5522 is enabled
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
0b4cd4742d
wip: osc-5522: don't allow enabling private mode 5522 if pasting has been disabled
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pull_request_metadata/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ea60fd5f4a
If security.osc52 disables paste requests, don't allow enabling
private mode 5522. This ensures we don't try to send unsolicited
mime-type listings when the user pastes (e.g. ctrl+shift+v).
Currently, that would result in a type=read:status=EPERM "event" being
sent to the terminal application, which it is unlikely to understand.
Even if we changed our implementation to allow sending the mime-type
list in events, actually trying to read the clipboard would just
result in EPERM anyway.
So, don't even allow the events to be enabled.
dnkl force-pushed osc-5522 from ea60fd5f4a
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pull_request_metadata/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
to 333c7a30da
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
2026年05月17日 08:49:05 +02:00
Compare
wip: osc-5522: add term_osc_{copy,paste}_allowed()
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
1678cffe1f
Returns the first seat that focuses the specified terminal
instance. Use this everywhere where we need to lookup a seat given a
terminal instance.
wip: osc-5522: add more comments, rename a few structs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
7695acb9b5
dnkl force-pushed osc-5522 from 7695acb9b5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
to 262de322ce
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
2026年05月17日 11:57:50 +02:00
Compare
This is an internal function that encodes a multiple-of-three long
input into a user allocated buffer.
base64_encode() and base64_encode_oneshot() uses the new function to
do the bulk of the encoding. This allows base64_encode_oneshot() to do
a single allocation - no need to xrealloc() anymore.
wip: osc-5522: we no longer need to cast the data argument in base64_encode_oneshot()
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
1aa77533be
dnkl force-pushed osc-5522 from 1aa77533be
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
to d7c683758f
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pull_request_metadata/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
2026年05月17日 13:15:28 +02:00
Compare
dnkl changed title from (削除) WIP: add support for OSC-5522, kitty's extended variant of OSC-52, with full mime-type access (削除ここまで) to Add support for OSC-5522, kitty's extended variant of OSC-52, with full mime-type access 2026年05月17日 13:15:39 +02:00
changelog: OSC-5522
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
604ea244a2
dnkl force-pushed osc-5522 from 604ea244a2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
to aee0c1863b
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
2026年05月17日 14:44:41 +02:00
Compare
dnkl force-pushed osc-5522 from aee0c1863b
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
to 3b50a97982
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_metadata/woodpecker Pipeline was successful
2026年05月17日 15:06:26 +02:00
Compare
First-time contributor
Copy link

kitty_clipboard_query() doesn't check term_osc_paste_allowed() here, unlike kitty_clipboard_read(), so the mime-type list is exposed even when osc52 is disabled.

If a walias references a target mime-type that was never sent via wdata, idx stays -1 in the lookup loop. The xasserts compiles out under NDEBUG, so data_idx ends up as (size_t)-1 and gets used as an array index when the selection is read.

kitty_clipboard_query() doesn't check term_osc_paste_allowed() here, unlike kitty_clipboard_read(), so the mime-type list is exposed even when osc52 is disabled. If a walias references a target mime-type that was never sent via wdata, idx stays -1 in the lookup loop. The xasserts compiles out under NDEBUG, so data_idx ends up as (size_t)-1 and gets used as an array index when the selection is read.
dnkl force-pushed osc-5522 from 3b50a97982
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_metadata/woodpecker Pipeline was successful
to 4b64ed0a49
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
2026年05月22日 11:58:59 +02:00
Compare
This is already being done in when reading and writing the clipboard,
but we had missed the query code path.
osc: kitty_clipboard_write_finish(): fix walias handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
1067b9bf69
* 'i' was never incremented, meaning we stored the *last* walias in
 the *first alias position in the mime-type list passed to the
 clipboard handling. The remaining elements were uninitialized and
 invalid.
* We only asserted that we'd found the target mime-type of a
 walias. But we need to handle it NOT being found, as it's perfectly
 possible for a user to send an "invalid" walias, where the target
 mime-type has NOT been sent in a wdata packet.
Author
Owner
Copy link

kitty_clipboard_query() doesn't check term_osc_paste_allowed() here, unlike kitty_clipboard_read(), so the mime-type list is exposed even when osc52 is disabled.

Fixed. Check was originally done in the OSC-5522 entry point, but got lost for the query code path in a refactor.

If a walias references a target mime-type that was never sent via wdata, idx stays -1 in the lookup loop. The xasserts compiles out under NDEBUG, so data_idx ends up as (size_t)-1 and gets used as an array index when the selection is read.

Fixed. Invalid waliases are now ignored.

> kitty_clipboard_query() doesn't check term_osc_paste_allowed() here, unlike kitty_clipboard_read(), so the mime-type list is exposed even when osc52 is disabled. Fixed. Check was originally done in the OSC-5522 entry point, but got lost for the query code path in a refactor. > If a walias references a target mime-type that was never sent via wdata, idx stays -1 in the lookup loop. The xasserts compiles out under NDEBUG, so data_idx ends up as (size_t)-1 and gets used as an array index when the selection is read. Fixed. Invalid waliases are now ignored.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pr/woodpecker Pipeline was successful
This pull request has changes conflicting with the target branch.
  • CHANGELOG.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin osc-5522:osc-5522
git switch osc-5522

Merge

Merge the changes and update on Forgejo.
git switch master
git merge --no-ff osc-5522
git switch osc-5522
git rebase master
git switch master
git merge --ff-only osc-5522
git switch osc-5522
git rebase master
git switch master
git merge --no-ff osc-5522
git switch master
git merge --squash osc-5522
git switch master
git merge --ff-only osc-5522
git switch master
git merge osc-5522
git push origin master
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot!2341
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "osc-5522"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?