switch to @This(); for output and server as they don't really have anything else

This commit is contained in:
Squibid 2025-10-16 18:15:21 -04:00
parent 0f13973300
commit d4efb73d5c
Signed by: squibid
GPG key ID: BECE5684D3C4005D
3 changed files with 110 additions and 112 deletions

View file

@ -1,7 +1,7 @@
const std = @import("std");
const wlr = @import("wlroots");
const Server = @import("server.zig").Server;
const Server = @import("server.zig");
const gpa = std.heap.c_allocator;

View file

@ -1,3 +1,5 @@
const Output = @This();
const std = @import("std");
const posix = std.posix;
const gpa = std.heap.c_allocator;
@ -5,18 +7,17 @@ const gpa = std.heap.c_allocator;
const wl = @import("wayland").server.wl;
const wlr = @import("wlroots");
const Server = @import("server.zig").Server;
const Server = @import("server.zig");
pub const Output = struct {
server: *Server,
wlr_output: *wlr.Output,
server: *Server,
wlr_output: *wlr.Output,
frame: wl.Listener(*wlr.Output) = .init(handleFrame),
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
frame: wl.Listener(*wlr.Output) = .init(handleFrame),
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
pub fn create(server: *Server, wlr_output: *wlr.Output) !void {
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
pub fn create(server: *Server, wlr_output: *wlr.Output) !void {
const output = try gpa.create(Output);
output.* = .{
@ -33,9 +34,9 @@ pub const Output = struct {
const scene_output = try server.scene.createSceneOutput(wlr_output);
server.scene_output_layout.addOutput(layout_output, scene_output);
}
}
pub fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
pub fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
const output: *Output = @fieldParentPtr("frame", listener);
const scene_output = output.server.scene.getSceneOutput(output.wlr_output).?;
@ -43,20 +44,20 @@ pub const Output = struct {
var now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
scene_output.sendFrameDone(&now);
}
}
pub fn handleRequestState(
listener: *wl.Listener(*wlr.Output.event.RequestState),
event: *wlr.Output.event.RequestState,
pub fn handleRequestState(
listener: *wl.Listener(*wlr.Output.event.RequestState),
event: *wlr.Output.event.RequestState,
) void {
const output: *Output = @fieldParentPtr("request_state", listener);
if (!output.wlr_output.commitState(event.state)) {
std.log.warn("failed to set output state {}", .{event.state});
}
}
}
pub fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
pub fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
const output: *Output = @fieldParentPtr("destroy", listener);
std.log.debug("removing output: {s}", .{output.*.wlr_output.*.name});
@ -66,5 +67,4 @@ pub const Output = struct {
output.destroy.link.remove();
gpa.destroy(output);
}
};
}

View file

@ -1,32 +1,31 @@
const Server = @This();
const std = @import("std");
const gpa = std.heap.c_allocator;
const wl = @import("wayland").server.wl;
const wlr = @import("wlroots");
const Output = @import("output.zig").Output;
const Output = @import("output.zig");
pub const Server = struct {
allocator: *wlr.Allocator,
allocator: *wlr.Allocator,
backend: *wlr.Backend,
compositor: *wlr.Compositor,
event_loop: *wl.EventLoop,
output_layout: *wlr.OutputLayout,
renderer: *wlr.Renderer,
scene: *wlr.Scene,
scene_output_layout: *wlr.SceneOutputLayout,
seat: *wlr.Seat,
session: ?*wlr.Session,
shm: *wlr.Shm,
wl_server: *wl.Server,
xdg_shell: *wlr.XdgShell,
wl_server: *wl.Server,
event_loop: *wl.EventLoop,
shm: *wlr.Shm,
scene: *wlr.Scene,
output_layout: *wlr.OutputLayout,
scene_output_layout: *wlr.SceneOutputLayout,
xdg_shell: *wlr.XdgShell,
seat: *wlr.Seat,
// Listeners
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
session: ?*wlr.Session,
backend: *wlr.Backend,
renderer: *wlr.Renderer,
compositor: *wlr.Compositor,
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
pub fn init(server: *Server) !void {
pub fn init(server: *Server) !void {
const wl_server = try wl.Server.create();
const event_loop = wl_server.getEventLoop();
@ -61,9 +60,9 @@ pub const Server = struct {
_ = try wlr.DataDeviceManager.create(server.wl_server);
server.backend.events.new_output.add(&server.new_output);
}
}
fn newOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
fn newOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
const server: *Server = @fieldParentPtr("new_output", listener);
if (!wlr_output.initRender(server.allocator, server.renderer)) return;
@ -82,5 +81,4 @@ pub const Server = struct {
wlr_output.destroy();
return;
};
}
};
}