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
63
64
65
66
67
68
69
70
71
|
const std = @import("std");
const wayland = @import("wayland");
const wl = wayland.wl;
const xdg = wayland.xdg;
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,
xdg.WmBase.handler,
});
try display.roundtrip(allocator);
try display.roundtrip(allocator);
const ctx: wayland.Context = .{
.allocator = allocator,
.display = &display,
};
try display.roundtrip(allocator);
for (wl.Output.globals.as_slice()) |output| {
log.debug("{}", .{output});
}
for (wl.Compositor.globals.as_slice()) |compositor| {
log.debug("{}", .{compositor});
}
for (wl.Shm.globals.as_slice()) |shm| {
log.debug("{}", .{shm});
}
for (xdg.WmBase.globals.as_slice()) |wm_base| {
log.debug("{}", .{wm_base});
}
const pool = try wl.Shm
.globals
.get(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.globals.get(0).?.create_surface(ctx);
defer surface.deinit(ctx);
try display.roundtrip(allocator);
log.debug("{}", .{buffer});
log.debug("{}", .{surface});
}
|