Compare commits
5 Commits
753e2a850d
...
1093209328
| Author | SHA1 | Date | |
|---|---|---|---|
| 1093209328 | |||
| 08217a0256 | |||
| 0f6d1a0842 | |||
| fe7f845359 | |||
| 043d3e1c22 |
50
packages/xcb/build.zig
Normal file
50
packages/xcb/build.zig
Normal file
@@ -0,0 +1,50 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const mod = b.addModule("xcb", .{
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
});
|
||||
|
||||
mod.linkSystemLibrary("xcb", .{});
|
||||
|
||||
const mod_tests = b.addTest(.{
|
||||
.root_module = mod,
|
||||
});
|
||||
|
||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||
|
||||
const test_step = b.step("test", "Run tests");
|
||||
test_step.dependOn(&run_mod_tests.step);
|
||||
|
||||
const sample_module = b.createModule(.{
|
||||
.root_source_file = b.path("sample/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{
|
||||
.{ .name = "xcb", .module = mod },
|
||||
},
|
||||
});
|
||||
|
||||
const sample_exe = b.addExecutable(.{
|
||||
.name = "sample",
|
||||
.root_module = sample_module,
|
||||
});
|
||||
|
||||
const sample_install = b.addInstallArtifact(sample_exe, .{});
|
||||
|
||||
const run_sample = b.addRunArtifact(sample_exe);
|
||||
run_sample.step.dependOn(&sample_install.step);
|
||||
|
||||
if (b.args) |args| {
|
||||
run_sample.addArgs(args);
|
||||
}
|
||||
|
||||
const sample_step = b.step("sample", "Run sample");
|
||||
sample_step.dependOn(&run_sample.step);
|
||||
}
|
||||
11
packages/xcb/build.zig.zon
Normal file
11
packages/xcb/build.zig.zon
Normal file
@@ -0,0 +1,11 @@
|
||||
.{
|
||||
.name = .xcb,
|
||||
.version = "0.0.0",
|
||||
.minimum_zig_version = "0.16.0",
|
||||
.paths = .{
|
||||
"src",
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
},
|
||||
.fingerprint = 0x48cfd8ea06caab92,
|
||||
}
|
||||
84
packages/xcb/sample/root.zig
Normal file
84
packages/xcb/sample/root.zig
Normal file
@@ -0,0 +1,84 @@
|
||||
const std = @import("std");
|
||||
const xcb = @import("xcb");
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
_ = init;
|
||||
|
||||
const connection = xcb.Connection.connect(null, null);
|
||||
defer connection.disconnect();
|
||||
|
||||
{
|
||||
const error_code = connection.hasError();
|
||||
if (error_code != 0) {
|
||||
std.debug.print("Error: xcb_connection_has_error returned {}", .{error_code});
|
||||
return error.XcbConnection;
|
||||
}
|
||||
}
|
||||
|
||||
const setup = connection.getSetup();
|
||||
const screen = setup.rootsIterator().data;
|
||||
|
||||
const window = @as(xcb.Window, @enumFromInt(connection.generateId()));
|
||||
_ = connection.createWindow(
|
||||
xcb.COPY_FROM_PARENT,
|
||||
window,
|
||||
screen.root,
|
||||
0,
|
||||
0,
|
||||
640,
|
||||
360,
|
||||
1,
|
||||
.INPUT_OUTPUT,
|
||||
screen.root_visual,
|
||||
.{
|
||||
.BACK_PIXEL = true,
|
||||
},
|
||||
&[_]u32{
|
||||
screen.black_pixel,
|
||||
},
|
||||
);
|
||||
|
||||
const wm_protocols_atom_cookie = connection.internAtom(true, "WM_PROTOCOLS");
|
||||
const wm_delete_window_atom_cookie = connection.internAtom(false, "WM_DELETE_WINDOW");
|
||||
|
||||
const wm_protocols_atom_reply = connection.internAtomReply(wm_protocols_atom_cookie, null) orelse return error.XcbInternAtom;
|
||||
defer std.c.free(wm_protocols_atom_reply);
|
||||
const wm_protocols_atom = wm_protocols_atom_reply.atom;
|
||||
|
||||
const wm_delete_window_atom_reply = connection.internAtomReply(wm_delete_window_atom_cookie, null) orelse return error.XcbInternAtom;
|
||||
defer std.c.free(wm_delete_window_atom_reply);
|
||||
const wm_delete_window_atom = wm_delete_window_atom_reply.atom;
|
||||
|
||||
_ = connection.changeProperty(
|
||||
.REPLACE,
|
||||
window,
|
||||
wm_protocols_atom,
|
||||
.ATOM,
|
||||
32,
|
||||
1,
|
||||
&wm_delete_window_atom,
|
||||
);
|
||||
|
||||
_ = connection.mapWindow(window);
|
||||
_ = connection.flush();
|
||||
|
||||
var running = true;
|
||||
while (running) {
|
||||
if (connection.waitForEvent()) |event| {
|
||||
defer std.c.free(event);
|
||||
|
||||
switch (event.response_type & ~@as(u8, 0x80)) {
|
||||
xcb.CLIENT_MESSAGE => {
|
||||
const client_message_event = @as(*xcb.ClientMessageEvent, @ptrCast(event));
|
||||
if (client_message_event.data.data32[0] == @intFromEnum(wm_delete_window_atom_reply.atom)) {
|
||||
running = false;
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
} else {
|
||||
std.debug.print("Error: xcb_wait_for_event returned null", .{});
|
||||
return error.XcbWaitForEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
4383
packages/xcb/src/root.zig
Normal file
4383
packages/xcb/src/root.zig
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user