Crafter.Graphics/interfaces/Crafter.Graphics-Clipboard.cppm

40 lines
2 KiB
Text
Raw Normal View History

2026-07-22 18:09:06 +02:00
//SPDX-License-Identifier: LGPL-3.0-only
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
2026-05-12 00:24:48 +02:00
export module Crafter.Graphics:Clipboard;
import std;
2026-05-19 00:45:22 +02:00
// 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.
2026-05-12 00:24:48 +02:00
export namespace Crafter::Clipboard {
2026-05-19 00:45:22 +02:00
// 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();
2026-05-12 00:24:48 +02:00
// 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);
2026-05-19 00:45:22 +02:00
// 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();
2026-05-12 00:24:48 +02:00
}