1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
const std = @import("std");
const wayland = @import("wayland");
const wl = wayland.wl;
const log = std.log.scoped(.main);
pub const std_options = std.Options{
.log_scope_levels = &.{
.{ .scope = .registry, .level = .info },
}
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var display: wl.Display = try .open_default(allocator);
defer display.deinit(allocator);
try display.init(allocator, &.{
wl.Output.handler,
wl.Compositor.handler,
wl.Shm.handler,
});
try display.roundtrip(allocator);
try display.roundtrip(allocator);
const ctx: wayland.Context = .{
.allocator = allocator,
.display = &display,
};
try display.roundtrip(allocator);
for (wl.Output.instances.items) |output| {
log.debug("{}", .{output});
}
for (wl.Compositor.instances.items) |compositor| {
log.debug("{}", .{compositor});
}
for (wl.Shm.instances.items) |shm| {
log.debug("{}", .{shm});
}
const pool = try wl.Shm.instances.items[0].create_pool(&ctx, 800 * 600 * (wl.Shm.Format.argb8888).bytes_per_pixel());
defer pool.deinit(&ctx);
try display.roundtrip(allocator);
const buffer = try pool.create_buffer(&ctx, 0, 800, 600, .argb8888);
defer ctx.display.request(buffer, .{ .destroy = {} }) catch |e| log.err("error {}", .{e});
const surface = try wl.Compositor.instances.items[0].create_surface(&ctx);
defer surface.deinit(&ctx);
try display.roundtrip(allocator);
log.debug("{}", .{buffer});
log.debug("{}", .{surface});
}
|