aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig11
-rw-r--r--src/wl/compositor.zig54
-rw-r--r--src/wl/output/root.zig28
-rw-r--r--src/wl/root.zig1
4 files changed, 74 insertions, 20 deletions
diff --git a/src/main.zig b/src/main.zig
index a9a5ef6..db68ee3 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -8,12 +8,19 @@ pub fn main() !void {
var display: wl.Display = try .open_default(allocator);
defer display.deinit(allocator);
- try display.init(allocator, &.{wl.Output.handler});
+ try display.init(allocator, &.{
+ wl.Output.handler,
+ wl.Compositor.handler,
+ });
try display.roundtrip(allocator);
try display.roundtrip(allocator);
- for (wl.Output.all()) |output| {
+ for (wl.Output.instances.items) |output| {
std.debug.print("{}\n", .{output});
}
+
+ for (wl.Compositor.instances.items) |compositor| {
+ std.debug.print("{}\n", .{compositor});
+ }
}
diff --git a/src/wl/compositor.zig b/src/wl/compositor.zig
new file mode 100644
index 0000000..6951446
--- /dev/null
+++ b/src/wl/compositor.zig
@@ -0,0 +1,54 @@
+const std = @import("std");
+const wayland = @import("../root.zig");
+const wl = wayland.wl;
+
+const Self = @This();
+
+pub const Events = wayland.EventSet(Self, .{});
+pub const Requests = union(enum) {
+ create_surface: struct { wayland.Object.Ref },
+ create_region: struct { wayland.Object.Ref },
+};
+
+handle: wayland.Object.Ref,
+
+pub var instances: std.ArrayListUnmanaged(*Self) = .empty;
+
+pub const handler: wl.Registry.GlobalHandler = .{
+ .interface = "wl_compositor",
+ .version = 6,
+ .handler = register,
+};
+
+pub fn init(
+ self: *Self,
+ ctx: *wayland.Context
+) !void {
+ self.* = .{
+ .handle = try ctx.display.registry.add_object(
+ ctx.allocator,
+ wayland.Object.from_self(self),
+ ),
+ };
+}
+
+fn register(ctx: *wayland.Context) ?wayland.Object.Ref {
+ const compositor = ctx.allocator.create(Self) catch return null;
+ compositor.init(ctx) catch return null;
+
+ instances.append(ctx.allocator, compositor) catch return null;
+ return compositor.handle;
+}
+
+pub fn format(
+ self: *const Self,
+ comptime fmt: []const u8,
+ options: std.fmt.FormatOptions,
+ writer: anytype,
+) !void {
+ _ = self;
+ _ = fmt;
+ _ = options;
+
+ try writer.print("wl.compositor", .{});
+}
diff --git a/src/wl/output/root.zig b/src/wl/output/root.zig
index fca2ecc..ce2169f 100644
--- a/src/wl/output/root.zig
+++ b/src/wl/output/root.zig
@@ -30,7 +30,7 @@ pub const Info = struct {
description: []const u8,
};
-var outputs: std.ArrayListUnmanaged(*Self) = .empty;
+pub var instances: std.ArrayListUnmanaged(*Self) = .empty;
staging: Info = undefined,
info: ?Info = null,
@@ -38,12 +38,11 @@ handle: wayland.Object.Ref,
pub fn init(
self: *Self,
- allocator: std.mem.Allocator,
- display: *wl.Display,
+ ctx: *wayland.Context,
) !void {
self.* = .{
- .handle = try display.registry.add_object(
- allocator,
+ .handle = try ctx.display.registry.add_object(
+ ctx.allocator,
wayland.Object.from_self(self),
),
};
@@ -59,10 +58,11 @@ pub const handler: wl.Registry.GlobalHandler = .{
.handler = register,
};
-pub fn register(ctx: *wayland.Context) ?wayland.Object.Ref {
+fn register(ctx: *wayland.Context) ?wayland.Object.Ref {
const output = ctx.allocator.create(Self) catch return null;
- output.init(ctx.allocator, ctx.display) catch return null;
- outputs.append(ctx.allocator, output) catch return null;
+ output.init(ctx) catch return null;
+
+ instances.append(ctx.allocator, output) catch return null;
return output.handle;
}
@@ -132,14 +132,6 @@ fn description(self: *Self, ctx: *wayland.Context, d: []const u8) !void {
@memcpy(@constCast(self.staging.description), d);
}
-pub fn get(index: usize) *Self {
- return outputs.items[index];
-}
-
-pub fn all() []*Self {
- return outputs.items;
-}
-
pub fn format(
self: *const Self,
comptime fmt: []const u8,
@@ -149,8 +141,8 @@ pub fn format(
_ = fmt;
_ = options;
if (self.info) |info| {
- try writer.print("output({s}) [ {} ]", .{ info.name, info.mode});
+ try writer.print("wl.output({s}) [ {} ]", .{ info.name, info.mode});
} else {
- try writer.print("output(?)", .{});
+ try writer.print("wl.output(?)", .{});
}
}
diff --git a/src/wl/root.zig b/src/wl/root.zig
index 778b085..d08c19b 100644
--- a/src/wl/root.zig
+++ b/src/wl/root.zig
@@ -2,3 +2,4 @@ pub const Display = @import("display.zig");
pub const Registry = @import("registry.zig");
pub const Callback = @import("callback.zig");
pub const Output = @import("output/root.zig");
+pub const Compositor = @import("compositor.zig");