Skip to content

[API Proposal]: Unified, cross-platform Clipboard type #115041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
just-ero opened this issue Apr 25, 2025 · 3 comments
Closed

[API Proposal]: Unified, cross-platform Clipboard type #115041

just-ero opened this issue Apr 25, 2025 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@just-ero
Copy link
Contributor

just-ero commented Apr 25, 2025

Background and motivation

Currently, there exist the System.Windows.Clipboard and System.Windows.Forms.Clipboard types, which, of course, are only available on Windows. They also require enabling the UseWpf or UseWindowsForms MSBuild properties in the project.
A single cross-platform equivalent in the base library would introduce the ability to get and set the data in the user's clipboard regardless of the type of app being written and regardless of the OS being targeted.

I don't know the intricacies of clipboards on other operating systems, so the implementation may be a lot more daunting than I anticipate. It may also be relevant to know what versions of a certain OS support which clipboard features.

API Proposal

namespace System;

public static class Clipboard
{
    public static void Clear();

    public static T Get<T>() where T : unmanaged;
    public static void Set<T>(T value) where T : unmanaged;

    public static byte[] GetData();
    public static void SetData(ReadOnlySpan<byte> data);

    public static Stream GetDataStream();
    public static void SetDataStream(Stream dataStream);

    public static string GetString();
    public static void SetString(string value);

    public static byte[] GetAudio();
    public static void SetAudio(ReadOnlySpan<byte> audio);

    public static Stream GetAudioStream();
    public static void SetAudioStream(Stream audioStream);

    public static byte[] GetImage();
    public static void SetImage(ReadOnlySpan<byte> image);

    public static Stream GetImageStream();
    public static void SetImageStream(Stream imageStream);

    public static string GetFile();
    public static void SetFile(string path);

    public static Stream GetFileStream();
    public static void SetFileStream(Stream fileStream);

    public static string[] GetFiles();
    public static void SetFiles(ReadOnlySpan<string> paths);
}

API Usage

Clipboard.SetString("Hello, world!");
string str = Clipboard.GetString();

Alternative Designs

No response

Risks

No response

@just-ero just-ero added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 25, 2025
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 25, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 25, 2025
@jkotas
Copy link
Member

jkotas commented Apr 25, 2025

You may want to open this issue in https://github.com/dotnet/maui instead. MAUI Is the project that is concerned with multi-platform UI. UI related functionality is not developed in this repo.

@just-ero
Copy link
Contributor Author

This is not strictly a UI concern. Console apps may also want to copy data to or from the clipboard.

@huoyaoyuan
Copy link
Member

Clipboard is mostly a UI feature. On Linux it's provided by X11 or Wayland. On Windows, modern clipboard is provided by WinRT, which is closely integrated with UI.

Further more, the data types of clipboard are defined for UI, especially bitmap and rich text.

@just-ero just-ero closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 25, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

3 participants