xcb: sample-driven ziggification
This commit is contained in:
@@ -1,83 +1,75 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const xcb = @import("xcb");
|
const xcb = @import("xcb");
|
||||||
|
|
||||||
const WM_PROTOCOLS = "WM_PROTOCOLS";
|
|
||||||
const WM_DELETE_WINDOW = "WM_DELETE_WINDOW";
|
|
||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
pub fn main(init: std.process.Init) !void {
|
||||||
_ = init;
|
_ = init;
|
||||||
|
|
||||||
const connection = xcb.import.xcb_connect(null, null);
|
const connection = xcb.Connection.connect(null, null);
|
||||||
defer xcb.import.xcb_disconnect(connection);
|
defer connection.disconnect();
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = xcb.import.xcb_connection_has_error(connection);
|
const error_code = connection.hasError();
|
||||||
if (res != 0) {
|
if (error_code != 0) {
|
||||||
std.debug.print("Error: xcb_connection_has_error returned {}", .{res});
|
std.debug.print("Error: xcb_connection_has_error returned {}", .{error_code});
|
||||||
return error.XcbConnection;
|
return error.XcbConnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const screen = xcb.import.xcb_setup_roots_iterator(xcb.import.xcb_get_setup(connection)).data.?;
|
const setup = connection.getSetup();
|
||||||
|
const screen = setup.rootsIterator().data;
|
||||||
|
|
||||||
const mask: xcb.Cw = .{
|
const window = @as(xcb.Window, @enumFromInt(connection.generateId()));
|
||||||
.BACK_PIXEL = true,
|
_ = connection.createWindow(
|
||||||
.EVENT_MASK = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const values = [_]u32{
|
|
||||||
screen.white_pixel,
|
|
||||||
@bitCast(xcb.EventMask{
|
|
||||||
.KEY_PRESS = true,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
const window: xcb.Window = @enumFromInt(xcb.import.xcb_generate_id(connection));
|
|
||||||
_ = xcb.import.xcb_create_window(
|
|
||||||
connection,
|
|
||||||
xcb.COPY_FROM_PARENT,
|
xcb.COPY_FROM_PARENT,
|
||||||
window,
|
window,
|
||||||
screen.root,
|
screen.root,
|
||||||
10,
|
0,
|
||||||
10,
|
0,
|
||||||
640,
|
640,
|
||||||
480,
|
360,
|
||||||
1,
|
1,
|
||||||
@intFromEnum(xcb.WindowClass.INPUT_OUTPUT),
|
.INPUT_OUTPUT,
|
||||||
screen.root_visual,
|
screen.root_visual,
|
||||||
@bitCast(mask),
|
.{
|
||||||
&values,
|
.BACK_PIXEL = true,
|
||||||
|
},
|
||||||
|
&[_]u32{
|
||||||
|
screen.black_pixel,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const wm_protocols_atom_cookie = xcb.import.xcb_intern_atom(connection, 1, WM_PROTOCOLS.len, WM_PROTOCOLS);
|
const wm_protocols_atom_cookie = connection.internAtom(true, "WM_PROTOCOLS");
|
||||||
const wm_delete_window_atom_cookie = xcb.import.xcb_intern_atom(connection, 0, WM_DELETE_WINDOW.len, WM_DELETE_WINDOW);
|
const wm_delete_window_atom_cookie = connection.internAtom(false, "WM_DELETE_WINDOW");
|
||||||
|
|
||||||
const wm_protocols_atom_reply: *xcb.InternAtomReply = xcb.import.xcb_intern_atom_reply(connection, wm_protocols_atom_cookie, null) orelse return error.XcbInternAtom;
|
const wm_protocols_atom_reply = connection.internAtomReply(wm_protocols_atom_cookie, null) orelse return error.XcbInternAtom;
|
||||||
const wm_delete_window_atom_reply: *xcb.InternAtomReply = xcb.import.xcb_intern_atom_reply(connection, wm_delete_window_atom_cookie, null) orelse return error.XcbInternAtom;
|
defer std.c.free(wm_protocols_atom_reply);
|
||||||
|
const wm_protocols_atom = wm_protocols_atom_reply.atom;
|
||||||
|
|
||||||
_ = xcb.import.xcb_change_property(
|
const wm_delete_window_atom_reply = connection.internAtomReply(wm_delete_window_atom_cookie, null) orelse return error.XcbInternAtom;
|
||||||
connection,
|
defer std.c.free(wm_delete_window_atom_reply);
|
||||||
@intFromEnum(xcb.PropMode.REPLACE),
|
const wm_delete_window_atom = wm_delete_window_atom_reply.atom;
|
||||||
|
|
||||||
|
_ = connection.changeProperty(
|
||||||
|
.REPLACE,
|
||||||
window,
|
window,
|
||||||
wm_protocols_atom_reply.atom,
|
wm_protocols_atom,
|
||||||
.ATOM,
|
.ATOM,
|
||||||
32,
|
32,
|
||||||
1,
|
1,
|
||||||
&wm_delete_window_atom_reply.atom,
|
&wm_delete_window_atom,
|
||||||
);
|
);
|
||||||
|
|
||||||
_ = xcb.import.xcb_map_window(connection, window);
|
_ = connection.mapWindow(window);
|
||||||
_ = xcb.import.xcb_flush(connection);
|
_ = connection.flush();
|
||||||
|
|
||||||
var running = true;
|
var running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
const maybe_event: ?*xcb.GenericEvent = xcb.import.xcb_wait_for_event(connection);
|
if (connection.waitForEvent()) |event| {
|
||||||
if (maybe_event) |event| {
|
|
||||||
defer std.c.free(event);
|
defer std.c.free(event);
|
||||||
|
|
||||||
switch (event.response_type & ~@as(u8, 0x80)) {
|
switch (event.response_type & ~@as(u8, 0x80)) {
|
||||||
xcb.CLIENT_MESSAGE => {
|
xcb.CLIENT_MESSAGE => {
|
||||||
const client_message_event: *xcb.ClientMessageEvent = @ptrCast(event);
|
const client_message_event = @as(*xcb.ClientMessageEvent, @ptrCast(event));
|
||||||
if (client_message_event.data.data32[0] == @intFromEnum(wm_delete_window_atom_reply.atom)) {
|
if (client_message_event.data.data32[0] == @intFromEnum(wm_delete_window_atom_reply.atom)) {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user