40 lines
2 KiB
C++
40 lines
2 KiB
C++
//SPDX-License-Identifier: LGPL-3.0-only
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
export module Crafter.Graphics:Clipboard;
|
|
import std;
|
|
|
|
// Native system-clipboard reads and writes. No popen, no helper
|
|
// binaries — just the platform's own clipboard API. Implementation
|
|
// lives next to the other window-backend code (Wayland data_device on
|
|
// Linux, Win32 in the Windows build, navigator.clipboard +
|
|
// `paste` event in the DOM build); callers don't pick a backend.
|
|
export namespace Crafter::Clipboard {
|
|
|
|
// One-time backend setup. Currently only the Wayland path uses it
|
|
// (attaches a wl_data_device listener so we observe selection
|
|
// offers from other apps). Win32 and the DOM build are no-ops.
|
|
// Called from Device::Initialize after the Wayland registry
|
|
// roundtrip — calling it again is harmless.
|
|
void Initialize();
|
|
|
|
// Place `text` on the system clipboard as UTF-8 plain text. Returns
|
|
// true if the platform accepted the request — false means the
|
|
// backend isn't initialised, no input event has been seen yet
|
|
// (Wayland needs a recent serial), or the OS API failed. On
|
|
// success the ownership of the clipboard contents is held until
|
|
// either another app replaces the selection or the application
|
|
// exits; the caller doesn't need to keep `text` alive.
|
|
bool SetText(std::string_view text);
|
|
|
|
// Read the current clipboard contents as UTF-8 plain text. Returns
|
|
// nullopt if the clipboard is empty, holds no text-typed payload,
|
|
// the platform read failed, or — on the DOM build — the latched
|
|
// buffer is empty because the user hasn't pasted yet and
|
|
// navigator.clipboard.readText() has not resolved. The Wayland
|
|
// path negotiates one of the standard text mime types in order
|
|
// (text/plain;charset=utf-8, text/plain, UTF8_STRING, TEXT) and
|
|
// pumps the wl_display event loop while reading so the call also
|
|
// works when the source of the selection is our own process.
|
|
std::optional<std::string> GetText();
|
|
}
|