diff --git a/README.md b/README.md index df3e8a333c2b5fcd07e1621bc6566d4cf48e8700..01c639e07306ed29bc727aec3b2ef4e0fbffd7d9 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ | [zig-embed](./zig-embed) | zig-0.13.0 | Embedding external resources in compiled binary. | | [zig-struct-bin](./zig-struct-bin) | zig-0.13.0 | Save a struct into binary file and then reading it back. | | [zig-elf](./zig-elf) | zig-0.14.0 | Read execution header of Elf64 format in Zig. | | [c-bluetooth](./c-bluetooth) | clang-17 | Scans for all Bluetooth devices. | +| [d-x11](./d-x11) | dmd-2.110 | Uses X11 to create a basic window without any bindings needed. | ## License diff --git a/d-x11/.gitignore b/d-x11/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..87e54c2147f89ced7b95a4aaad6dcdbc3f5f1f7a --- /dev/null +++ b/d-x11/.gitignore @@ -0,0 +1,2 @@ +main +*.o diff --git a/d-x11/Makefile b/d-x11/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3c2fc3bd466cc4b39777779e9f56027ae607c2c1 --- /dev/null +++ b/d-x11/Makefile @@ -0,0 +1,2 @@ +main: main.d + dmd main.d -L-lX11 diff --git a/d-x11/main.d b/d-x11/main.d new file mode 100644 index 0000000000000000000000000000000000000000..5f21f2545b5dfbaf2979c403a5fce0a17858112e --- /dev/null +++ b/d-x11/main.d @@ -0,0 +1,40 @@ +import core.sys.posix.unistd; +import core.stdc.stdlib; + +extern(C) { + struct Display; + struct Screen; + alias Window = ulong; + + Display* XOpenDisplay(const char*); + Window XDefaultRootWindow(Display*); + Window XCreateSimpleWindow(Display*, Window, int, int, uint, uint, uint, ulong, ulong); + int XMapWindow(Display*, Window); + int XFlush(Display*); + int XCloseDisplay(Display*); +} + +void main() { + Display* mainDisplay = XOpenDisplay(null); + if (mainDisplay is null) { + exit(1); + } + + Window rootWindow = XDefaultRootWindow(mainDisplay); + + Window mainWindow = XCreateSimpleWindow( + mainDisplay, rootWindow, + 0, 0, // x, y position + 800, 600, // width, height + 0, // border width + 0, // border color (ignored) + 0xFF0000 // background color (red) + ); + + XMapWindow(mainDisplay, mainWindow); + XFlush(mainDisplay); + + while(true) { + sleep(1); + } +}