Compare commits

..

3 Commits

Author SHA1 Message Date
5420c48b5d minor fixes 2026-10-15 23:50:27 +02:00
ecbf1020c5 xcb: update to zig 0.17.0 2026-10-15 23:46:57 +02:00
2f92305d7e Update README 2026-10-15 02:18:08 +02:00
6 changed files with 52 additions and 28 deletions

View File

@@ -21,6 +21,22 @@ come after x86_64 is fully implemented and actually works.
You can see an example of how this library is supposed to be used in You can see an example of how this library is supposed to be used in
[test/root.zig](packages/cjit/test/root.zig). [test/root.zig](packages/cjit/test/root.zig).
## glfw
Zig bindings for [GLFW](https://www.glfw.org/), an open source, multi-platform
library for OpenGL, OpenGL ES and Vulkan development, providing support for
window and context creation and receiving keyboard, mouse and gamepad inputs.
Original C sources are included and compiled with Zig's build system. Bindings
are complete and lightly ziggified, providing simplified names, method syntax
and some constants grouped into enums.
I initially relied on bindings available in the wild, but they eventually fell
behind both Zig and GLFW versions. That said, these bindings do not support
MacOS at all, as I do not have means to test them on MacOS nor do I want to.
This package is actually used by my other project, codenamed
[voxel-game](/:root/renati/voxel-game).
## js ## js
Zig bindings for Fabrice Bellard's QuickJS. Original C sources are included and Zig bindings for Fabrice Bellard's QuickJS. Original C sources are included and
@@ -56,8 +72,8 @@ Vector math library with support for vectors, matrices and ×8 SIMD operations
(utilizing SOA layout). (utilizing SOA layout).
This package is actually used by my other project, codenamed This package is actually used by my other project, codenamed
[voxel-game](/:root/renati/voxel-game) and is probably the most complete package [voxel-game](/:root/renati/voxel-game) and is probably the most complete
in this repository. original package in this repository.
## web ## web
@@ -86,3 +102,12 @@ The other utilities include:
Zig bindings for Xlib (aka libX11), a C library implementing a client of the X Zig bindings for Xlib (aka libX11), a C library implementing a client of the X
Window System protocol. The bindings are not complete. Window System protocol. The bindings are not complete.
## xcb
Zig bindings for XCB (aka libxcb), a C library implementing the X protocol and a
lightweight replacement for Xlib. Not every import is typed accurately, but
enough to make the sample application work.
The sample creates an empty window with a Vulkan surface using
`VK_KHR_xcb_surface` extension.

View File

@@ -175,9 +175,9 @@ pub fn isCompatible(comptime ZigType: type, c_type: Type) bool {
else => false, else => false,
}, },
.float => |zig_float| switch (c_type) { .float => |zig_float| switch (c_type) {
.float => zig_float.bits = 32, .float => zig_float.bits == 32,
.double => zig_float.bits = 64, .double => zig_float.bits == 64,
.long_double => zig_float.bits = 64, .long_double => zig_float.bits == 64,
}, },
.pointer => @compileError("TODO"), .pointer => @compileError("TODO"),
.array => @compileError("TODO"), .array => @compileError("TODO"),

View File

@@ -50,9 +50,7 @@ pub fn build(b: *std.Build) void {
const run_sample = b.addRunArtifact(sample_exe); const run_sample = b.addRunArtifact(sample_exe);
run_sample.step.dependOn(&sample_install.step); run_sample.step.dependOn(&sample_install.step);
if (b.args) |args| { run_sample.addPassthruArgs();
run_sample.addArgs(args);
}
const sample_step = b.step("sample", "Run sample"); const sample_step = b.step("sample", "Run sample");
sample_step.dependOn(&run_sample.step); sample_step.dependOn(&run_sample.step);

View File

@@ -1,14 +1,15 @@
.{ .{
.name = .xcb, .name = .xcb,
.version = "0.0.0", .version = "0.0.0",
.minimum_zig_version = "0.16.0", .minimum_zig_version = "0.17.0",
.dependencies = .{ .dependencies = .{
.vulkan_zig = .{ .vulkan_zig = .{
.url = "git+https://github.com/Snektron/vulkan-zig#b496a6a561ffbbeb530b0f9ed4e059f88c0723a5", .url = "git+https://github.com/Snektron/vulkan-zig.git#f9688c6f4ebcb930f67044698ddd1322442e714b",
.hash = "vulkan-0.0.0-r7Ytx7N9AwD7IZt5_XNHtkJ4G9qY0pCH-cpcOsbL8wzD", .hash = "vulkan-0.0.0-r7Ytx4yGAwDZf0XsT6_L1ol_XUAkyOgOyBqamf8begA0",
}, },
}, },
.paths = .{ .paths = .{
"sample",
"src", "src",
"build.zig", "build.zig",
"build.zig.zon", "build.zig.zon",

View File

@@ -73,11 +73,11 @@ pub fn init(allocator: std.mem.Allocator, connection: *xcb.Connection, window: x
const queue_families_properties = try instance.getPhysicalDeviceQueueFamilyPropertiesAlloc(physical_device, allocator); const queue_families_properties = try instance.getPhysicalDeviceQueueFamilyPropertiesAlloc(physical_device, allocator);
defer allocator.free(queue_families_properties); defer allocator.free(queue_families_properties);
// Look for the first family that has the `graphics_bit` set and // Look for the first family that has the `graphics` bit set and
// supports presentation to a given surface. // supports presentation to a given surface.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const graphics_bit = queue_family_properties.queue_flags.graphics_bit; const graphics_bit = queue_family_properties.queue_flags.graphics;
const supports_presentation = try instance.getPhysicalDeviceSurfaceSupportKHR(physical_device, @intCast(i), surface) != .false; const supports_presentation = try instance.getPhysicalDeviceSurfaceSupportKHR(physical_device, @intCast(i), surface) != .false;
if (graphics_bit and supports_presentation) { if (graphics_bit and supports_presentation) {
@@ -118,7 +118,7 @@ pub fn init(allocator: std.mem.Allocator, connection: *xcb.Connection, window: x
const queue = device.getDeviceQueue(queue_family, 0); const queue = device.getDeviceQueue(queue_family, 0);
const command_pool = try device.createCommandPool(&.{ const command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true }, .flags = .{ .transient = true },
.queue_family_index = queue_family, .queue_family_index = queue_family,
}, null); }, null);
errdefer device.destroyCommandPool(command_pool, null); errdefer device.destroyCommandPool(command_pool, null);

View File

@@ -1482,7 +1482,7 @@ pub const Atom = enum(u32) {
WM_TRANSIENT_FOR = 68, WM_TRANSIENT_FOR = 68,
_, _,
pub const ANY: Atom = @enumFromInt(0); pub const ANY: Atom = @fromBackingInt(0);
}; };
pub const AtomIterator = extern struct { pub const AtomIterator = extern struct {
@@ -1526,7 +1526,7 @@ pub const Bool32 = enum(u32) {
} }
pub inline fn toBool(self: Bool32) bool { pub inline fn toBool(self: Bool32) bool {
return @intFromEnum(self) != 0; return @backingInt(self) != 0;
} }
}; };
@@ -1680,7 +1680,7 @@ pub const VisualClass = enum(c_uint) {
}; };
pub const Visualtype = extern struct { pub const Visualtype = extern struct {
visual_id: Visualid = @enumFromInt(0), visual_id: Visualid = @fromBackingInt(0),
_class: u8 = 0, _class: u8 = 0,
bits_per_rgb_value: u8 = 0, bits_per_rgb_value: u8 = 0,
colormap_entries: u16 = 0, colormap_entries: u16 = 0,
@@ -1767,7 +1767,7 @@ pub const Screen = extern struct {
height_in_millimeters: u16 = 0, height_in_millimeters: u16 = 0,
min_installed_maps: u16 = 0, min_installed_maps: u16 = 0,
max_installed_maps: u16 = 0, max_installed_maps: u16 = 0,
root_visual: Visualid = @enumFromInt(0), root_visual: Visualid = @fromBackingInt(0),
backing_stores: u8 = 0, backing_stores: u8 = 0,
save_unders: u8 = 0, save_unders: u8 = 0,
root_depth: u8 = 0, root_depth: u8 = 0,
@@ -1850,8 +1850,8 @@ pub const Setup = extern struct {
bitmap_format_bit_order: u8 = 0, bitmap_format_bit_order: u8 = 0,
bitmap_format_scanline_unit: u8 = 0, bitmap_format_scanline_unit: u8 = 0,
bitmap_format_scanline_pad: u8 = 0, bitmap_format_scanline_pad: u8 = 0,
min_keycode: Keycode = @enumFromInt(0), min_keycode: Keycode = @fromBackingInt(0),
max_keycode: Keycode = @enumFromInt(0), max_keycode: Keycode = @fromBackingInt(0),
pad1: [4]u8 = @splat(0), pad1: [4]u8 = @splat(0),
pub const vendor = import.xcb_setup_vendor; pub const vendor = import.xcb_setup_vendor;
@@ -1906,7 +1906,7 @@ pub const KeyButMask = packed struct(c_uint) {
pub const KeyPressEvent = extern struct { pub const KeyPressEvent = extern struct {
response_type: u8 = 0, response_type: u8 = 0,
detail: Keycode = @enumFromInt(0), detail: Keycode = @fromBackingInt(0),
sequence: u16 = 0, sequence: u16 = 0,
time: Timestamp = .CURRENT_TIME, time: Timestamp = .CURRENT_TIME,
root: Window = .NONE, root: Window = .NONE,
@@ -1937,7 +1937,7 @@ pub const ButtonMask = packed struct(c_uint) {
pub const ButtonPressEvent = extern struct { pub const ButtonPressEvent = extern struct {
response_type: u8 = 0, response_type: u8 = 0,
detail: Button = @enumFromInt(0), detail: Button = @fromBackingInt(0),
sequence: u16 = 0, sequence: u16 = 0,
time: Timestamp = .CURRENT_TIME, time: Timestamp = .CURRENT_TIME,
root: Window = .NONE, root: Window = .NONE,
@@ -2049,7 +2049,7 @@ pub const GraphicsExposureEvent = extern struct {
response_type: u8 = 0, response_type: u8 = 0,
pad0: u8 = 0, pad0: u8 = 0,
sequence: u16 = 0, sequence: u16 = 0,
drawable: Drawable = @enumFromInt(0), drawable: Drawable = @fromBackingInt(0),
x: u16 = 0, x: u16 = 0,
y: u16 = 0, y: u16 = 0,
width: u16 = 0, width: u16 = 0,
@@ -2064,7 +2064,7 @@ pub const NoExposureEvent = extern struct {
response_type: u8 = 0, response_type: u8 = 0,
pad0: u8 = 0, pad0: u8 = 0,
sequence: u16 = 0, sequence: u16 = 0,
drawable: Drawable = @enumFromInt(0), drawable: Drawable = @fromBackingInt(0),
minor_opcode: u16 = 0, minor_opcode: u16 = 0,
major_opcode: u8 = 0, major_opcode: u8 = 0,
pad1: u8 = 0, pad1: u8 = 0,
@@ -2321,7 +2321,7 @@ pub const MappingNotifyEvent = extern struct {
pad0: u8 = 0, pad0: u8 = 0,
sequence: u16 = 0, sequence: u16 = 0,
request: u8 = 0, request: u8 = 0,
first_keycode: Keycode = @enumFromInt(0), first_keycode: Keycode = @fromBackingInt(0),
count: u8 = 0, count: u8 = 0,
pad1: u8 = 0, pad1: u8 = 0,
}; };
@@ -2473,7 +2473,7 @@ pub const GetWindowAttributesReply = extern struct {
backing_store: u8 = 0, backing_store: u8 = 0,
sequence: u16 = 0, sequence: u16 = 0,
length: u32 = 0, length: u32 = 0,
visual: Visualid = @enumFromInt(0), visual: Visualid = @fromBackingInt(0),
_class: WindowClass = .COPY_FROM_PARENT, _class: WindowClass = .COPY_FROM_PARENT,
bit_gravity: u8 = 0, bit_gravity: u8 = 0,
win_gravity: u8 = 0, win_gravity: u8 = 0,
@@ -3186,7 +3186,7 @@ pub const GetImageReply = extern struct {
depth: u8 = 0, depth: u8 = 0,
sequence: u16 = 0, sequence: u16 = 0,
length: u32 = 0, length: u32 = 0,
visual: Visualid = @enumFromInt(0), visual: Visualid = @fromBackingInt(0),
pad0: [20]u8 = @splat(0), pad0: [20]u8 = @splat(0),
pub const data = import.xcb_get_image_data; pub const data = import.xcb_get_image_data;
@@ -3466,7 +3466,7 @@ pub const ChangeKeyboardControlValueList = extern struct {
bell_duration: i32 = 0, bell_duration: i32 = 0,
led: u32 = 0, led: u32 = 0,
led_mode: u32 = 0, led_mode: u32 = 0,
key: Keycode32 = @enumFromInt(0), key: Keycode32 = @fromBackingInt(0),
auto_repeat_mode: u32 = 0, auto_repeat_mode: u32 = 0,
}; };