summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--d-x11/.gitignore2
-rw-r--r--d-x11/Makefile2
-rw-r--r--d-x11/main.d40
4 files changed, 45 insertions, 0 deletions
diff --git a/README.md b/README.md
index df3e8a3..01c639e 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,7 @@ running it.
| [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 0000000..87e54c2
--- /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 0000000..3c2fc3b
--- /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 0000000..5f21f25
--- /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);
+ }
+}