Skip to content

Instantly share code, notes, and snippets.

@faissaloo
Created April 7, 2019 15:34
Show Gist options
  • Save faissaloo/ea82ae2b6bbc38a738f7dce6fcf2900e to your computer and use it in GitHub Desktop.
Save faissaloo/ea82ae2b6bbc38a738f7dce6fcf2900e to your computer and use it in GitHub Desktop.
D X11 example
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