wip: add clipboard support
This commit is contained in:
@@ -152,6 +152,12 @@ namespace Montauk {
|
||||
|
||||
/* CrashReport */
|
||||
static constexpr uint64_t SYS_CRASH_REPORT = 118;
|
||||
static constexpr uint64_t SYS_CLIPBOARD_SET_TEXT = 119;
|
||||
static constexpr uint64_t SYS_CLIPBOARD_GET_INFO = 120;
|
||||
static constexpr uint64_t SYS_CLIPBOARD_GET_TEXT = 121;
|
||||
static constexpr uint64_t SYS_CLIPBOARD_CLEAR = 122;
|
||||
|
||||
static constexpr uint32_t CLIPBOARD_MAX_TEXT_BYTES = 256 * 1024;
|
||||
|
||||
static constexpr uint32_t IPC_SIGNAL_READABLE = 1u << 0;
|
||||
static constexpr uint32_t IPC_SIGNAL_WRITABLE = 1u << 1;
|
||||
@@ -225,6 +231,12 @@ namespace Montauk {
|
||||
uint32_t signals;
|
||||
};
|
||||
|
||||
struct ClipboardInfo {
|
||||
uint32_t textBytes;
|
||||
uint32_t _pad;
|
||||
uint64_t serial;
|
||||
};
|
||||
|
||||
// Window server shared types
|
||||
struct WinEvent {
|
||||
uint8_t type; // 0=key, 1=mouse, 2=resize, 3=close, 4=scale
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* clipboard.hpp
|
||||
* Simple plain-text clipboard helpers for MontaukOS GUI apps
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/heap.h>
|
||||
|
||||
namespace gui {
|
||||
|
||||
inline bool clipboard_set_text(const char* text, int len) {
|
||||
if (len < 0) return false;
|
||||
if (len > 0 && text == nullptr) return false;
|
||||
return montauk::clipboard_set_text(text, (uint32_t)len) == 0;
|
||||
}
|
||||
|
||||
inline bool clipboard_set_text(const char* text) {
|
||||
return clipboard_set_text(text, text ? montauk::slen(text) : 0);
|
||||
}
|
||||
|
||||
inline bool clipboard_get_info(Montauk::ClipboardInfo* out) {
|
||||
if (out == nullptr) return false;
|
||||
return montauk::clipboard_get_info(out) == 0;
|
||||
}
|
||||
|
||||
inline bool clipboard_has_text() {
|
||||
Montauk::ClipboardInfo info = {};
|
||||
return clipboard_get_info(&info) && info.textBytes > 0;
|
||||
}
|
||||
|
||||
inline char* clipboard_get_text_alloc(int* out_len = nullptr, uint64_t* out_serial = nullptr) {
|
||||
if (out_len) *out_len = 0;
|
||||
if (out_serial) *out_serial = 0;
|
||||
|
||||
Montauk::ClipboardInfo info = {};
|
||||
if (!clipboard_get_info(&info) || info.textBytes == 0)
|
||||
return nullptr;
|
||||
|
||||
uint32_t cap = info.textBytes + 1;
|
||||
char* text = (char*)montauk::malloc(cap);
|
||||
if (text == nullptr) return nullptr;
|
||||
|
||||
uint32_t actual_len = 0;
|
||||
uint64_t serial = 0;
|
||||
if (montauk::clipboard_get_text(text, info.textBytes, &actual_len, &serial) != 0 ||
|
||||
actual_len > info.textBytes) {
|
||||
montauk::mfree(text);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
text[actual_len] = '\0';
|
||||
if (out_len) *out_len = (int)actual_len;
|
||||
if (out_serial) *out_serial = serial;
|
||||
return text;
|
||||
}
|
||||
|
||||
inline bool clipboard_clear() {
|
||||
return montauk::clipboard_clear() == 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -494,6 +494,22 @@ namespace montauk {
|
||||
return (int)syscall2(Montauk::SYS_GETUSER, (uint64_t)buf, maxLen);
|
||||
}
|
||||
|
||||
// Clipboard
|
||||
inline int clipboard_set_text(const char* data, uint32_t len) {
|
||||
return (int)syscall2(Montauk::SYS_CLIPBOARD_SET_TEXT, (uint64_t)data, (uint64_t)len);
|
||||
}
|
||||
inline int clipboard_get_info(Montauk::ClipboardInfo* out) {
|
||||
return (int)syscall1(Montauk::SYS_CLIPBOARD_GET_INFO, (uint64_t)out);
|
||||
}
|
||||
inline int clipboard_get_text(char* buf, uint32_t bufLen, uint32_t* outLen,
|
||||
uint64_t* outSerial = nullptr) {
|
||||
return (int)syscall4(Montauk::SYS_CLIPBOARD_GET_TEXT, (uint64_t)buf, (uint64_t)bufLen,
|
||||
(uint64_t)outLen, (uint64_t)outSerial);
|
||||
}
|
||||
inline int clipboard_clear() {
|
||||
return (int)syscall0(Montauk::SYS_CLIPBOARD_CLEAR);
|
||||
}
|
||||
|
||||
// Window server
|
||||
inline int win_create(const char* title, int w, int h, Montauk::WinCreateResult* result) {
|
||||
return (int)syscall4(Montauk::SYS_WINCREATE, (uint64_t)title, (uint64_t)w, (uint64_t)h, (uint64_t)result);
|
||||
|
||||
Reference in New Issue
Block a user