| 1 |
/* this an example for this binding*/ |
|---|
| 2 |
/* please read README file before */ |
|---|
| 3 |
|
|---|
| 4 |
import std.c.linux.X11.Xlib; |
|---|
| 5 |
import std.c.stdio; |
|---|
| 6 |
|
|---|
| 7 |
int main(char[][] args) |
|---|
| 8 |
{ |
|---|
| 9 |
Display* display = XOpenDisplay(null); //Open default display |
|---|
| 10 |
Window window = XCreateSimpleWindow( //create a simple windows |
|---|
| 11 |
display, // display |
|---|
| 12 |
DefaultRootWindow(display), // parent window |
|---|
| 13 |
0, 0, 200, 100, // x, y, w, h |
|---|
| 14 |
0,0x0,0x000000FF // border_width,boder_color,back_color |
|---|
| 15 |
); |
|---|
| 16 |
XMapWindow(display, window); //map the window |
|---|
| 17 |
XRaiseWindow(display, window); //show the window |
|---|
| 18 |
XStoreName(display,window,"Hello Window\0"); //set window name , don't forget /0 term char ! |
|---|
| 19 |
XFlush(display); // flush X server |
|---|
| 20 |
|
|---|
| 21 |
//wait for a enter pressed (in fact you need to wait for MapNotify event before drawing...) |
|---|
| 22 |
printf("press enter to show window content\0"); |
|---|
| 23 |
getchar(); |
|---|
| 24 |
|
|---|
| 25 |
XGCValues values; |
|---|
| 26 |
values.foreground=0xFFFFFF; |
|---|
| 27 |
values.background=0x00FF00; |
|---|
| 28 |
GC gc=XCreateGC(display,window,GCMask.GCForeground | GCMask.GCBackground,&values); //create zone for drawing |
|---|
| 29 |
char* chaine="hello world"; |
|---|
| 30 |
XDrawString(display, window,gc, 30,50,chaine, 11); //draw string |
|---|
| 31 |
XDrawRectangle(display,window,gc,20,20,150,50); //draw rectangle |
|---|
| 32 |
XFlush(display); //flush X server |
|---|
| 33 |
printf("press enter to show window content\0"); |
|---|
| 34 |
getchar(); //wait for a enter pressed to close program |
|---|
| 35 |
XUnmapWindow(display, window); // unmap the window |
|---|
| 36 |
XDestroyWindow(display, window); //destroy the window |
|---|
| 37 |
XCloseDisplay(display); //close the display |
|---|
| 38 |
return 0; |
|---|
| 39 |
}; |
|---|