Add support for OSC 52 clipboard copies in conhost #23288

Closed
opened 2026-01-31 08:37:50 +00:00 by claunia · 2 comments
Owner

Originally created by @lhecker on GitHub (May 23, 2025).

Description of the new feature

Windows Terminal supports OSC 52 and so conhost should too.

Proposed technical implementation details

This is super easy to do and only requires us to fill out this function:
2d64a3a4ab/src/host/outputStream.cpp (L277-L286)

To do so, we need to extend the Clipboard class to expose this function (in a more convenient way though):
2d64a3a4ab/src/interactivity/win32/clipboard.hpp (L38)

(Note that you need to set Host.EXE as your startup project.)

Originally created by @lhecker on GitHub (May 23, 2025). ### Description of the new feature Windows Terminal supports OSC 52 and so conhost should too. ### Proposed technical implementation details This is super easy to do and only requires us to fill out this function: https://github.com/microsoft/terminal/blob/2d64a3a4ab0d0d1c5b9085a022f5319460ef68d7/src/host/outputStream.cpp#L277-L286 To do so, we need to extend the `Clipboard` class to expose this function (in a more convenient way though): https://github.com/microsoft/terminal/blob/2d64a3a4ab0d0d1c5b9085a022f5319460ef68d7/src/interactivity/win32/clipboard.hpp#L38 (Note that you need to set `Host.EXE` as your startup project.)
Author
Owner

@j4james commented on GitHub (May 25, 2025):

I actually have a old branch with an implementation for this, but it wasn't as easy as you might imagine. As far as I understand, you can only access the clipboard from the main window thread, so I had to post a custom message from the CopyToClipboard handler to pass on the content to the Window::ConsoleWindowProc, and then set the clipboard from there. It all seemed a bit hacky, which is why I abandoned it, but maybe there's an easier solution that I'm missing.

See also #13408, which was kind of tracking this issue amongst other things.

@j4james commented on GitHub (May 25, 2025): I actually have a old branch with an implementation for this, but it wasn't as easy as you might imagine. As far as I understand, you can only access the clipboard from the main window thread, so I had to post a custom message from the `CopyToClipboard` handler to pass on the content to the `Window::ConsoleWindowProc`, and then set the clipboard from there. It all seemed a bit hacky, which is why I abandoned it, but maybe there's an easier solution that I'm missing. See also #13408, which was kind of tracking this issue amongst other things.
Author
Owner

@lhecker commented on GitHub (May 26, 2025):

As far as I understand, you can only access the clipboard from the main window thread

Oh right! Yes, I think that's correct. Reading the clipboard without the HWND is possible but not writing it.

@lhecker commented on GitHub (May 26, 2025): > As far as I understand, you can only access the clipboard from the main window thread Oh right! Yes, I think that's correct. Reading the clipboard without the HWND is possible but not writing it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23288