-
-
Save faissaloo/ea82ae2b6bbc38a738f7dce6fcf2900e to your computer and use it in GitHub Desktop.
D X11 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import x11.X; | |
import x11.Xlib; | |
import std.algorithm; | |
import std.traits; | |
int main() | |
{ | |
Display *display; | |
Window w; | |
XEvent last_event; | |
string msg = "Hello, World!"; | |
int screen; | |
display = XOpenDisplay(null); | |
if (display == null) { | |
puts("Cannot open display"); | |
return 1; | |
} | |
screen = DefaultScreen(display); | |
w = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 100, 100, 1, | |
BlackPixel(display, screen), WhitePixel(display, screen)); | |
XSelectInput(display, w, ExposureMask | KeyPressMask); | |
XMapWindow(display, w); | |
while (true) { | |
XNextEvent(display, &last_event); | |
if (last_event.type == Expose) { | |
XDrawString(display, w, DefaultGC(display, screen), 10, 50, cast(char*)msg, cast(int)msg.length); | |
} | |
if (last_event.type == KeyPress) | |
break; | |
} | |
XCloseDisplay(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment