diff options
| -rw-r--r-- | shell.nix | 6 | ||||
| -rw-r--r-- | zig-x11/.clang-format | 4 | ||||
| -rw-r--r-- | zig-x11/Makefile | 8 | ||||
| -rw-r--r-- | zig-x11/main.zig | 32 | ||||
| -rw-r--r-- | zig-x11/window.c | 15 |
5 files changed, 65 insertions, 0 deletions
@@ -1,11 +1,17 @@ { pkgs ? import <nixpkgs> {} }: pkgs.mkShell { nativeBuildInputs = with pkgs.buildPackages; [ + # Compilers and tools. binutils gnumake nasm tinycc + clang zig zls + + # Dev libraries and deps. + xorg.libX11 + xorg.libX11.dev ]; } diff --git a/zig-x11/.clang-format b/zig-x11/.clang-format new file mode 100644 index 0000000..84ac618 --- /dev/null +++ b/zig-x11/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: LLVM +ColumnLimit: 120 +IndentWidth: 4 + diff --git a/zig-x11/Makefile b/zig-x11/Makefile new file mode 100644 index 0000000..910dd26 --- /dev/null +++ b/zig-x11/Makefile @@ -0,0 +1,8 @@ +default: + zig run main.zig -lX11 -lc + +window-test: + clang window.c -o window -lX11 + +window-test-zig: + zig cc window.c -o window -lX11 diff --git a/zig-x11/main.zig b/zig-x11/main.zig new file mode 100644 index 0000000..daa4cd5 --- /dev/null +++ b/zig-x11/main.zig @@ -0,0 +1,32 @@ +const std = @import("std"); +const xlib = @cImport({ + @cInclude("X11/Xlib.h"); +}); + +pub fn main() !void { + const display = xlib.XOpenDisplay(null); + if (display == null) { + return error.DisplayOpenFailed; + } + + const rootWindow = xlib.XDefaultRootWindow(display); + + const mainWindow = xlib.XCreateSimpleWindow( + display, + rootWindow, + 0, + 0, + 800, + 600, + 0, + 0, + 0xFF0000, + ); + + _ = xlib.XMapWindow(display, mainWindow); + _ = xlib.XFlush(display); + + while (true) { + std.time.sleep(1 * std.time.ns_per_s); + } +} diff --git a/zig-x11/window.c b/zig-x11/window.c new file mode 100644 index 0000000..80110c4 --- /dev/null +++ b/zig-x11/window.c @@ -0,0 +1,15 @@ +#include <X11/Xlib.h> +#include <unistd.h> + +int main() { + Display *MainDisplay = XOpenDisplay(0); + Window RootWindow = XDefaultRootWindow(MainDisplay); + + Window MainWindow = XCreateSimpleWindow(MainDisplay, RootWindow, 0, 0, 800, 600, 0, 0, 0xFF0000); + XMapWindow(MainDisplay, MainWindow); + XFlush(MainDisplay); + + for (;;) { + sleep(1); + } +} |
