apprt/gtk-ng: emit signal when clipboard read/write

This commit is contained in:
Mitchell Hashimoto
2025-07-22 13:15:24 -07:00
parent a6e0878b11
commit 58a5f3f1f8

View File

@ -190,6 +190,30 @@ pub const Surface = extern struct {
void, void,
); );
}; };
/// Emitted whenever the clipboard has been written.
pub const @"clipboard-write" = struct {
pub const name = "clipboard-write";
pub const connect = impl.connect;
const impl = gobject.ext.defineSignal(
name,
Self,
&.{},
void,
);
};
/// Emitted whenever the surface reads the clipboard.
pub const @"clipboard-read" = struct {
pub const name = "clipboard-read";
pub const connect = impl.connect;
const impl = gobject.ext.defineSignal(
name,
Self,
&.{},
void,
);
};
}; };
const Private = struct { const Private = struct {
@ -1288,7 +1312,7 @@ pub const Surface = extern struct {
_ = glib.idleAddOnce(idleFocus, self.ref()); _ = glib.idleAddOnce(idleFocus, self.ref());
} }
/// The focus callback must be triggerd on an idle loop source because /// The focus callback must be triggered on an idle loop source because
/// there are actions within libghostty callbacks (such as showing close /// there are actions within libghostty callbacks (such as showing close
/// confirmation dialogs) that can trigger focus loss and cause a deadlock /// confirmation dialogs) that can trigger focus loss and cause a deadlock
/// because the lock may be held during the callback. /// because the lock may be held during the callback.
@ -1927,6 +1951,8 @@ pub const Surface = extern struct {
// Signals // Signals
signals.@"close-request".impl.register(.{}); signals.@"close-request".impl.register(.{});
signals.@"clipboard-read".impl.register(.{});
signals.@"clipboard-write".impl.register(.{});
// Virtual methods // Virtual methods
gobject.Object.virtual_methods.dispose.implement(class, &dispose); gobject.Object.virtual_methods.dispose.implement(class, &dispose);
@ -1998,6 +2024,14 @@ const Clipboard = struct {
clipboard_type, clipboard_type,
) orelse return; ) orelse return;
clipboard.setText(val); clipboard.setText(val);
Surface.signals.@"clipboard-write".impl.emit(
self,
null,
.{},
null,
);
return; return;
} }
@ -2163,17 +2197,30 @@ const Clipboard = struct {
) catch |err| switch (err) { ) catch |err| switch (err) {
error.UnsafePaste, error.UnsafePaste,
error.UnauthorizedPaste, error.UnauthorizedPaste,
=> showClipboardConfirmation( => {
self, showClipboardConfirmation(
req.state, self,
str, req.state,
), str,
);
return;
},
else => log.warn( else => {
"failed to complete clipboard request err={}", log.warn(
.{err}, "failed to complete clipboard request err={}",
), .{err},
);
return;
},
}; };
Surface.signals.@"clipboard-read".impl.emit(
self,
null,
.{},
null,
);
} }
/// The request we send as userdata to the clipboard read. /// The request we send as userdata to the clipboard read.