diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-03-18 04:10:10 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-03-18 04:10:10 +0100 |
| commit | 4236ea42a15aaebeb6d1a872f78fafb2b1804c5a (patch) | |
| tree | 7521c310a663fa9f892dc9f9bd4b66a81bcdea2a | |
| parent | 40ec7848c853e6d76794fb70c6cff57a0c078d76 (diff) | |
| download | probe-4236ea42a15aaebeb6d1a872f78fafb2b1804c5a.tar.gz | |
Added X11 basic window in D language
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | d-x11/.gitignore | 2 | ||||
| -rw-r--r-- | d-x11/Makefile | 2 | ||||
| -rw-r--r-- | d-x11/main.d | 40 |
4 files changed, 45 insertions, 0 deletions
@@ -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); + } +} |
