Skip to content

Commit 9a198b4

Browse files
committed
apprt/gtk: support new set clipboard API
1 parent 26bdb12 commit 9a198b4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

‎src/apprt/gtk/Surface.zig‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ pub fn clipboardRequest(
8080
);
8181
}
8282

83-
pub fn setClipboardString(
83+
pub fn setClipboard(
8484
self: *Self,
85-
val: [:0]const u8,
8685
clipboard_type: apprt.Clipboard,
86+
contents: []const apprt.ClipboardContent,
8787
confirm: bool,
8888
) !void {
89-
self.surface.setClipboardString(
90-
val,
89+
self.surface.setClipboard(
9190
clipboard_type,
91+
contents,
9292
confirm,
9393
);
9494
}

‎src/apprt/gtk/class/surface.zig‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,16 +1553,16 @@ pub const Surface = extern struct {
15531553
);
15541554
}
15551555

1556-
pub fn setClipboardString(
1556+
pub fn setClipboard(
15571557
self: *Self,
1558-
val: [:0]const u8,
15591558
clipboard_type: apprt.Clipboard,
1559+
contents: []const apprt.ClipboardContent,
15601560
confirm: bool,
15611561
) void {
15621562
Clipboard.set(
15631563
self,
1564-
val,
15651564
clipboard_type,
1565+
contents,
15661566
confirm,
15671567
);
15681568
}
@@ -3334,12 +3334,19 @@ const Clipboard = struct {
33343334
/// Set the clipboard contents.
33353335
pub fn set(
33363336
self: *Surface,
3337-
val: [:0]const u8,
33383337
clipboard_type: apprt.Clipboard,
3338+
contents: []const apprt.ClipboardContent,
33393339
confirm: bool,
33403340
) void {
33413341
const priv = self.private();
33423342

3343+
// For GTK, we only support text/plain type to set strings currently.
3344+
const val: [:0]const u8 = for (contents) |content| {
3345+
if (std.mem.eql(u8, content.mime, "text/plain")) {
3346+
break content.data;
3347+
}
3348+
} else return;
3349+
33433350
// If no confirmation is necessary, set the clipboard.
33443351
if (!confirm) {
33453352
const clipboard = get(

0 commit comments

Comments
 (0)