-
Notifications
You must be signed in to change notification settings - Fork 48
/
example.d
66 lines (54 loc) · 1.63 KB
/
example.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Compile with:
// rdmd -L-lX11 example.d
import deimos.X11.X, deimos.X11.Xlib;
import std.stdio;
int main()
{
Display *display = XOpenDisplay(null);
if (!display)
{
writeln("XOpenDisplay failed");
return 1;
}
int screen = DefaultScreen(display);
Window window = XCreateSimpleWindow(
display,
DefaultRootWindow(display), //parent window
0, 0, 323, 200, 0, //x, y, width, height, border_width
BlackPixel(display, screen), //border_color
WhitePixel(display,screen) //back_color
);
XStoreName(display, window, cast(char*) "Example window");
XSelectInput(display, window, ExposureMask);
XMapWindow(display, window);
Atom wmDeleteMessage = XInternAtom(display, cast(char*) "WM_DELETE_WINDOW", False);
XSetWMProtocols(display, window, &wmDeleteMessage, 1);
GC gc = DefaultGC(display, screen);
bool running = true;
while (running)
{
XEvent event;
KeySym keySym;
while (XPending(display))
{
XNextEvent(display, &event);
switch (event.type)
{
case ClientMessage:
if (cast(Atom) event.xclient.data.l[0] == wmDeleteMessage)
{
running = false;
}
break;
case Expose:
XDrawString(display, window, gc, 10, 16, cast(char*) "Hello world !", 13);
break;
default:
}
}
}
XUnmapWindow(display, window);
XDestroyWindow(display, window);
XCloseDisplay(display);
return 0;
}