Кажется, работает следующее:
use v6;
use NativeCall;
constant GdkAtom := uint64;
constant GDK_NONE = 0x0;
sub gtk_init(Pointer $argc, Pointer $argv) is native('gtk-3') { * };
sub gdk_display_get_default() returns Pointer is native('gdk-3') { * };
sub gtk_clipboard_get_for_display(Pointer $display, GdkAtom $selection)
returns Pointer is native('gtk-3') { * };
sub gtk_clipboard_request_text(
Pointer $clipboard,
&callback ( Pointer $clipbrd, Str $text, Pointer $data),
Pointer $user_data) is native('gtk-3') { * };
sub gtk_main() is native('gtk-3') { * };
sub gtk_main_quit() is native('gtk-3') { * };
gtk_init(Pointer, Pointer); # Pass NULL for arguments
my $display = gdk_display_get_default();
my $clipboard = gtk_clipboard_get_for_display( $display, GDK_NONE );
my $callback = my sub (Pointer $clipboard, Str $text, Pointer $data) {
say "In callback: Text = $text";
gtk_main_quit();
}
gtk_clipboard_request_text( $clipboard, &$callback, Pointer );
gtk_main();
Это напечатает текст, который в данный момент находится в буфере обмена системы по умолчанию.