Window creation/X11: Difference between revisions
Content added Content deleted
No edit summary |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Minimal changes to make runnable) |
||
Line 824: | Line 824: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{trans|C}} |
{{trans|C}} |
||
{{broken|Perl 6}} |
|||
There is not yet a X11 library in Perl 6 but we can write the minimal C mappings for this task. |
There is not yet a X11 library in Perl 6 but we can write the minimal C mappings for this task. |
||
Notice that the mapping for XEvent requires a manual set up which depends on the number of bits of your machine. This is due to a current bug in NativeCall on MoarVM. |
|||
<lang perl6>use NativeCall; |
<lang perl6>use NativeCall; |
||
class Display is repr('CStruct') { |
class Display is repr('CStruct') { |
||
has int32 $!screen; |
|||
⚫ | |||
has int32 $!window; |
|||
} |
|||
⚫ | |||
has int32 $!context; |
|||
} |
|||
class XEvent is repr('CStruct') { |
class XEvent is repr('CStruct') { |
||
has int32 $.type; |
has int32 $.type; |
||
#has int $.type; # for 64 bits machine |
|||
method init { $!type = 0 } |
method init { $!type = 0 } |
||
} |
} |
||
sub XOpenDisplay(Str $name = ':0') returns Display is native(' |
sub XOpenDisplay(Str $name = ':0') returns Display is native('X11') { * } |
||
sub XDefaultScreen(Display $) returns |
sub XDefaultScreen(Display $) returns int32 is native('X11') { * } |
||
sub XRootWindow(Display $, |
sub XRootWindow(Display $, int32 $screen_number) returns int32 is native('X11') { * } |
||
sub XBlackPixel(Display $, |
sub XBlackPixel(Display $, int32 $screen_number) returns int32 is native('X11') { * } |
||
sub XWhitePixel(Display $, |
sub XWhitePixel(Display $, int32 $screen_number) returns int32 is native('X11') { * } |
||
sub XCreateSimpleWindow( |
sub XCreateSimpleWindow( |
||
Display $, |
Display $, int32 $parent_window, int32 $x, int32 $y, |
||
int32 $width, int32 $height, int32 $border_width, |
|||
int32 $border, int32 $background |
|||
) returns |
) returns int32 is native('X11') { * } |
||
sub XMapWindow(Display $, |
sub XMapWindow(Display $, int32 $window) is native('X11') { * } |
||
sub XSelectInput(Display $, |
sub XSelectInput(Display $, int32 $window, int32 $mask) is native('X11') { * } |
||
sub XFillRectangle( |
sub XFillRectangle( |
||
Display $, |
Display $, int32 $window, GC $, int32 $x, int32 $y, int32 $width, int32 $height |
||
) is native(' |
) is native('X11') { * } |
||
sub XDrawString( |
sub XDrawString( |
||
Display $, |
Display $, int32 $window, GC $, int32 $x, int32 $y, Str $, int32 $str_length |
||
) is native(' |
) is native('X11') { * } |
||
sub XDefaultGC(Display $, |
sub XDefaultGC(Display $, int32 $screen) returns GC is native('X11') { * } |
||
sub XNextEvent(Display $, XEvent $e) is native(' |
sub XNextEvent(Display $, XEvent $e) is native('X11') { * } |
||
sub XCloseDisplay(Display $) is native(' |
sub XCloseDisplay(Display $) is native('X11') { * } |
||
my Display $display = XOpenDisplay() |
my Display $display = XOpenDisplay() |
||
Line 879: | Line 881: | ||
XNextEvent($display, $e); |
XNextEvent($display, $e); |
||
if $e.type == 12 { |
if $e.type == 12 { |
||
XFillRectangle($display, $window, XDefaultGC($display, $screen), 20, 20, 10, 10); |
|||
XDrawString($display, $window, XDefaultGC($display, $screen), 10, 50, $msg, my int $ = $msg.chars); |
|||
} |
} |
||
elsif $e.type == 2 { |
elsif $e.type == 2 { |
||
last; |
|||
} |
} |
||
} |
} |