mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/embedded: allow noting that selection clipboard is not supported
This commit is contained in:
@ -253,6 +253,7 @@ typedef void (*ghostty_runtime_toggle_fullscreen_cb)(void *, bool);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *userdata;
|
void *userdata;
|
||||||
|
bool supports_selection_clipboard;
|
||||||
ghostty_runtime_wakeup_cb wakeup_cb;
|
ghostty_runtime_wakeup_cb wakeup_cb;
|
||||||
ghostty_runtime_reload_config_cb reload_config_cb;
|
ghostty_runtime_reload_config_cb reload_config_cb;
|
||||||
ghostty_runtime_set_title_cb set_title_cb;
|
ghostty_runtime_set_title_cb set_title_cb;
|
||||||
|
@ -54,6 +54,7 @@ extension Ghostty {
|
|||||||
// uses to interface with the application runtime environment.
|
// uses to interface with the application runtime environment.
|
||||||
var runtime_cfg = ghostty_runtime_config_s(
|
var runtime_cfg = ghostty_runtime_config_s(
|
||||||
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
||||||
|
supports_selection_clipboard: false,
|
||||||
wakeup_cb: { userdata in AppState.wakeup(userdata) },
|
wakeup_cb: { userdata in AppState.wakeup(userdata) },
|
||||||
reload_config_cb: { userdata in AppState.reloadConfig(userdata) },
|
reload_config_cb: { userdata in AppState.reloadConfig(userdata) },
|
||||||
set_title_cb: { userdata, title in AppState.setTitle(userdata, title: title) },
|
set_title_cb: { userdata, title in AppState.setTitle(userdata, title: title) },
|
||||||
|
@ -849,6 +849,14 @@ fn setSelection(self: *Surface, sel_: ?terminal.Selection) void {
|
|||||||
const sel = sel_ orelse return;
|
const sel = sel_ orelse return;
|
||||||
if (prev_) |prev| if (std.meta.eql(sel, prev)) return;
|
if (prev_) |prev| if (std.meta.eql(sel, prev)) return;
|
||||||
|
|
||||||
|
// Check if our runtime supports the selection clipboard at all.
|
||||||
|
// We can save a lot of work if it doesn't.
|
||||||
|
if (@hasDecl(apprt.runtime.Surface, "supportsClipboard")) {
|
||||||
|
if (!self.rt_surface.supportsClipboard(clipboard)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var buf = self.io.terminal.screen.selectionString(
|
var buf = self.io.terminal.screen.selectionString(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
sel,
|
sel,
|
||||||
|
@ -32,6 +32,9 @@ pub const App = struct {
|
|||||||
/// Userdata that is passed to all the callbacks.
|
/// Userdata that is passed to all the callbacks.
|
||||||
userdata: AppUD = null,
|
userdata: AppUD = null,
|
||||||
|
|
||||||
|
/// True if the selection clipboard is supported.
|
||||||
|
supports_selection_clipboard: bool = false,
|
||||||
|
|
||||||
/// Callback called to wakeup the event loop. This should trigger
|
/// Callback called to wakeup the event loop. This should trigger
|
||||||
/// a full tick of the app loop.
|
/// a full tick of the app loop.
|
||||||
wakeup: *const fn (AppUD) callconv(.C) void,
|
wakeup: *const fn (AppUD) callconv(.C) void,
|
||||||
@ -239,6 +242,16 @@ pub const Surface = struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn supportsClipboard(
|
||||||
|
self: *const Surface,
|
||||||
|
clipboard_type: apprt.Clipboard,
|
||||||
|
) bool {
|
||||||
|
return switch (clipboard_type) {
|
||||||
|
.standard => true,
|
||||||
|
.selection => self.app.opts.supports_selection_clipboard,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getClipboardString(
|
pub fn getClipboardString(
|
||||||
self: *const Surface,
|
self: *const Surface,
|
||||||
clipboard_type: apprt.Clipboard,
|
clipboard_type: apprt.Clipboard,
|
||||||
|
Reference in New Issue
Block a user