June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -7,7 +7,7 @@ int main(void) {
|
|||
Display *d;
|
||||
Window w;
|
||||
XEvent e;
|
||||
char *msg = "Hello, World!";
|
||||
const char *msg = "Hello, World!";
|
||||
int s;
|
||||
|
||||
d = XOpenDisplay(NULL);
|
||||
|
|
|
|||
40
Task/Window-creation-X11/Julia/window-creation-x11.julia
Normal file
40
Task/Window-creation-X11/Julia/window-creation-x11.julia
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Xlib
|
||||
|
||||
function x11demo()
|
||||
# Open connection to the server.
|
||||
dpy = XOpenDisplay(C_NULL)
|
||||
dpy == C_NULL && error("unable to open display")
|
||||
scr = DefaultScreen(dpy)
|
||||
|
||||
# Create a window.
|
||||
win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 10, 10, 300, 100, 1,
|
||||
BlackPixel(dpy, scr), WhitePixel(dpy, scr))
|
||||
|
||||
# Select the kind of events we are interested in.
|
||||
XSelectInput(dpy, win, ExposureMask | KeyPressMask)
|
||||
|
||||
# Show or in x11 terms map window.
|
||||
XMapWindow(dpy, win)
|
||||
|
||||
# Run event loop.
|
||||
evt = Ref(XEvent())
|
||||
while true
|
||||
XNextEvent(dpy, evt)
|
||||
|
||||
# Draw or redraw the window.
|
||||
if EventType(evt) == Expose
|
||||
XFillRectangle(dpy, win, DefaultGC(dpy, scr), 24, 24, 16, 16)
|
||||
XDrawString(dpy, win, DefaultGC(dpy, scr), 50, 50, "Hello, World! Press any key to exit.")
|
||||
end
|
||||
|
||||
# Exit whenever a key is pressed.
|
||||
if EventType(evt) == KeyPress
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# Shutdown server connection
|
||||
XCloseDisplay(dpy)
|
||||
end
|
||||
|
||||
x11demo()
|
||||
|
|
@ -1,34 +1,38 @@
|
|||
use NativeCall;
|
||||
|
||||
class Display is repr('CStruct') {}
|
||||
class GC is repr('CStruct') {}
|
||||
class Display is repr('CStruct') {
|
||||
has int32 $!screen;
|
||||
has int32 $!window;
|
||||
}
|
||||
class GC is repr('CStruct') {
|
||||
has int32 $!context;
|
||||
}
|
||||
class XEvent is repr('CStruct') {
|
||||
has int32 $.type; # for 32 bits machine
|
||||
#has int $.type; # for 64 bits machine
|
||||
has int32 $.type;
|
||||
method init { $!type = 0 }
|
||||
}
|
||||
|
||||
sub XOpenDisplay(Str $name = ':0') returns Display is native('libX11') { * }
|
||||
sub XDefaultScreen(Display $) returns int is native('libX11') { * }
|
||||
sub XRootWindow(Display $, int $screen_number) returns int is native('libX11') { * }
|
||||
sub XBlackPixel(Display $, int $screen_number) returns int is native('libX11') { * }
|
||||
sub XWhitePixel(Display $, int $screen_number) returns int is native('libX11') { * }
|
||||
sub XOpenDisplay(Str $name = ':0') returns Display is native('X11') { * }
|
||||
sub XDefaultScreen(Display $) returns int32 is native('X11') { * }
|
||||
sub XRootWindow(Display $, int32 $screen_number) returns int32 is native('X11') { * }
|
||||
sub XBlackPixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
|
||||
sub XWhitePixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
|
||||
sub XCreateSimpleWindow(
|
||||
Display $, int $parent_window, int $x, int $y,
|
||||
int $width, int $height, int $border_width,
|
||||
int $border, int $background
|
||||
) returns int is native('libX11') { * }
|
||||
sub XMapWindow(Display $, int $window) is native('libX11') { * }
|
||||
sub XSelectInput(Display $, int $window, int $mask) is native('libX11') { * }
|
||||
Display $, int32 $parent_window, int32 $x, int32 $y,
|
||||
int32 $width, int32 $height, int32 $border_width,
|
||||
int32 $border, int32 $background
|
||||
) returns int32 is native('X11') { * }
|
||||
sub XMapWindow(Display $, int32 $window) is native('X11') { * }
|
||||
sub XSelectInput(Display $, int32 $window, int32 $mask) is native('X11') { * }
|
||||
sub XFillRectangle(
|
||||
Display $, int $window, GC $, int $x, int $y, int $width, int $height
|
||||
) is native('libX11') { * }
|
||||
Display $, int32 $window, GC $, int32 $x, int32 $y, int32 $width, int32 $height
|
||||
) is native('X11') { * }
|
||||
sub XDrawString(
|
||||
Display $, int $window, GC $, int $x, int $y, Str $, int $str_length
|
||||
) is native('libX11') { * }
|
||||
sub XDefaultGC(Display $, int $screen) returns GC is native('libX11') { * }
|
||||
sub XNextEvent(Display $, XEvent $e) is native('libX11') { * }
|
||||
sub XCloseDisplay(Display $) is native('libX11') { * }
|
||||
Display $, int32 $window, GC $, int32 $x, int32 $y, Str $, int32 $str_length
|
||||
) is native('X11') { * }
|
||||
sub XDefaultGC(Display $, int32 $screen) returns GC is native('X11') { * }
|
||||
sub XNextEvent(Display $, XEvent $e) is native('X11') { * }
|
||||
sub XCloseDisplay(Display $) is native('X11') { * }
|
||||
|
||||
my Display $display = XOpenDisplay()
|
||||
or die "Can not open display";
|
||||
|
|
@ -48,11 +52,11 @@ my XEvent $e .= new; $e.init;
|
|||
loop {
|
||||
XNextEvent($display, $e);
|
||||
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);
|
||||
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 {
|
||||
last;
|
||||
last;
|
||||
}
|
||||
}
|
||||
XCloseDisplay($display);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue