mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
switch to @This(); for output and server as they don't really have anything else
This commit is contained in:
parent
0f13973300
commit
d4efb73d5c
3 changed files with 110 additions and 112 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
|
|
||||||
const Server = @import("server.zig").Server;
|
const Server = @import("server.zig");
|
||||||
|
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
const Output = @This();
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const posix = std.posix;
|
const posix = std.posix;
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
|
|
@ -5,18 +7,17 @@ const gpa = std.heap.c_allocator;
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
|
|
||||||
const Server = @import("server.zig").Server;
|
const Server = @import("server.zig");
|
||||||
|
|
||||||
pub const Output = struct {
|
server: *Server,
|
||||||
server: *Server,
|
wlr_output: *wlr.Output,
|
||||||
wlr_output: *wlr.Output,
|
|
||||||
|
|
||||||
frame: wl.Listener(*wlr.Output) = .init(handleFrame),
|
frame: wl.Listener(*wlr.Output) = .init(handleFrame),
|
||||||
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
|
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
|
||||||
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
|
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
|
||||||
|
|
||||||
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
|
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
|
||||||
pub fn create(server: *Server, wlr_output: *wlr.Output) !void {
|
pub fn create(server: *Server, wlr_output: *wlr.Output) !void {
|
||||||
const output = try gpa.create(Output);
|
const output = try gpa.create(Output);
|
||||||
|
|
||||||
output.* = .{
|
output.* = .{
|
||||||
|
|
@ -33,9 +34,9 @@ pub const Output = struct {
|
||||||
|
|
||||||
const scene_output = try server.scene.createSceneOutput(wlr_output);
|
const scene_output = try server.scene.createSceneOutput(wlr_output);
|
||||||
server.scene_output_layout.addOutput(layout_output, scene_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 output: *Output = @fieldParentPtr("frame", listener);
|
||||||
|
|
||||||
const scene_output = output.server.scene.getSceneOutput(output.wlr_output).?;
|
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");
|
var now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
||||||
scene_output.sendFrameDone(&now);
|
scene_output.sendFrameDone(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handleRequestState(
|
pub fn handleRequestState(
|
||||||
listener: *wl.Listener(*wlr.Output.event.RequestState),
|
listener: *wl.Listener(*wlr.Output.event.RequestState),
|
||||||
event: *wlr.Output.event.RequestState,
|
event: *wlr.Output.event.RequestState,
|
||||||
) void {
|
) void {
|
||||||
const output: *Output = @fieldParentPtr("request_state", listener);
|
const output: *Output = @fieldParentPtr("request_state", listener);
|
||||||
|
|
||||||
if (!output.wlr_output.commitState(event.state)) {
|
if (!output.wlr_output.commitState(event.state)) {
|
||||||
std.log.warn("failed to set output state {}", .{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);
|
const output: *Output = @fieldParentPtr("destroy", listener);
|
||||||
|
|
||||||
std.log.debug("removing output: {s}", .{output.*.wlr_output.*.name});
|
std.log.debug("removing output: {s}", .{output.*.wlr_output.*.name});
|
||||||
|
|
@ -66,5 +67,4 @@ pub const Output = struct {
|
||||||
output.destroy.link.remove();
|
output.destroy.link.remove();
|
||||||
|
|
||||||
gpa.destroy(output);
|
gpa.destroy(output);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,31 @@
|
||||||
|
const Server = @This();
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
|
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
const wlr = @import("wlroots");
|
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,
|
// Listeners
|
||||||
event_loop: *wl.EventLoop,
|
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
|
||||||
shm: *wlr.Shm,
|
|
||||||
scene: *wlr.Scene,
|
|
||||||
output_layout: *wlr.OutputLayout,
|
|
||||||
scene_output_layout: *wlr.SceneOutputLayout,
|
|
||||||
xdg_shell: *wlr.XdgShell,
|
|
||||||
seat: *wlr.Seat,
|
|
||||||
|
|
||||||
session: ?*wlr.Session,
|
pub fn init(server: *Server) !void {
|
||||||
backend: *wlr.Backend,
|
|
||||||
renderer: *wlr.Renderer,
|
|
||||||
|
|
||||||
compositor: *wlr.Compositor,
|
|
||||||
|
|
||||||
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
|
|
||||||
|
|
||||||
pub fn init(server: *Server) !void {
|
|
||||||
const wl_server = try wl.Server.create();
|
const wl_server = try wl.Server.create();
|
||||||
const event_loop = wl_server.getEventLoop();
|
const event_loop = wl_server.getEventLoop();
|
||||||
|
|
||||||
|
|
@ -61,9 +60,9 @@ pub const Server = struct {
|
||||||
_ = try wlr.DataDeviceManager.create(server.wl_server);
|
_ = try wlr.DataDeviceManager.create(server.wl_server);
|
||||||
|
|
||||||
server.backend.events.new_output.add(&server.new_output);
|
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);
|
const server: *Server = @fieldParentPtr("new_output", listener);
|
||||||
|
|
||||||
if (!wlr_output.initRender(server.allocator, server.renderer)) return;
|
if (!wlr_output.initRender(server.allocator, server.renderer)) return;
|
||||||
|
|
@ -82,5 +81,4 @@ pub const Server = struct {
|
||||||
wlr_output.destroy();
|
wlr_output.destroy();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue