Fedora 33 Raku
I am trying to use Raku's NativeCall to talk to libX11.so to print out both my screen and my display:
use NativeCall;
class Display is repr('CStruct') { has Pointer $.DisplayPtr };
# libX11.so --> X11
sub XOpenDisplay(Str $name = ':0') returns Display is native('X11') { * }
sub XDefaultScreen(Display $) returns int32 is native('X11') { * }
my Display $display = XOpenDisplay()
or die "Can not open display";
my int $screen = XDefaultScreen($display);
print "display = <" ~ $display ~ ">\n";
print "screen = <" ~ $screen ~ ">\n";
$ libX11.pl6
display = <Display<90201160>>
screen = <0>
Problem. I am missing something about the class syntax as it is showing me a pointer address instead of my display, which I presume to be ":0". Also I thing the class declaration should show a string somewhere.
In the comments
@hobbshas pointed me in the right direction, by suggesting a new function,XDisplayString, that can actually be used to turn a pointer into a string describing the display, without actually needing to go into the full structure of the pointer. So this is how it would go:That would return:
At least in my machine. The key here is that you're actually ising the right way of describing the screen, at least as far as
XDisplayStringis concerned, so you turn the original Pointer into aStr, and then you sna use it in whateverX*need a string description of the display.