mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
move output into it's own file
This commit is contained in:
parent
2305c967cf
commit
9cb148e3b1
2 changed files with 62 additions and 60 deletions
|
|
@ -1,6 +1,64 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const posix = std.posix;
|
||||||
|
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");
|
||||||
|
|
||||||
pub const Ouput = struct {
|
const Server = @import("server.zig").Server;
|
||||||
|
|
||||||
|
pub const Output = struct {
|
||||||
|
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),
|
||||||
|
|
||||||
|
// 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.* = .{
|
||||||
|
.server = server,
|
||||||
|
.wlr_output = wlr_output,
|
||||||
|
};
|
||||||
|
wlr_output.events.frame.add(&output.frame);
|
||||||
|
wlr_output.events.request_state.add(&output.request_state);
|
||||||
|
wlr_output.events.destroy.add(&output.destroy);
|
||||||
|
|
||||||
|
const layout_output = try server.output_layout.addAuto(wlr_output);
|
||||||
|
|
||||||
|
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 {
|
||||||
|
const output: *Output = @fieldParentPtr("frame", listener);
|
||||||
|
|
||||||
|
const scene_output = output.server.scene.getSceneOutput(output.wlr_output).?;
|
||||||
|
_ = scene_output.commit(null);
|
||||||
|
|
||||||
|
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,
|
||||||
|
) void {
|
||||||
|
const output: *Output = @fieldParentPtr("request_state", listener);
|
||||||
|
|
||||||
|
_ = output.wlr_output.commitState(event.state);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||||
|
const output: *Output = @fieldParentPtr("destroy", listener);
|
||||||
|
|
||||||
|
output.frame.link.remove();
|
||||||
|
output.request_state.link.remove();
|
||||||
|
output.destroy.link.remove();
|
||||||
|
|
||||||
|
gpa.destroy(output);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,10 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const posix = std.posix;
|
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 gpa = std.heap.c_allocator;
|
const Output = @import("output.zig").Output;
|
||||||
|
|
||||||
const Output = struct {
|
|
||||||
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),
|
|
||||||
|
|
||||||
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
|
|
||||||
fn create(server: *Server, wlr_output: *wlr.Output) !void {
|
|
||||||
const output = try gpa.create(Output);
|
|
||||||
|
|
||||||
output.* = .{
|
|
||||||
.server = server,
|
|
||||||
.wlr_output = wlr_output,
|
|
||||||
};
|
|
||||||
wlr_output.events.frame.add(&output.frame);
|
|
||||||
wlr_output.events.request_state.add(&output.request_state);
|
|
||||||
wlr_output.events.destroy.add(&output.destroy);
|
|
||||||
|
|
||||||
const layout_output = try server.output_layout.addAuto(wlr_output);
|
|
||||||
|
|
||||||
const scene_output = try server.scene.createSceneOutput(wlr_output);
|
|
||||||
server.scene_output_layout.addOutput(layout_output, scene_output);
|
|
||||||
}
|
|
||||||
|
|
||||||
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).?;
|
|
||||||
_ = scene_output.commit(null);
|
|
||||||
|
|
||||||
var now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
|
||||||
scene_output.sendFrameDone(&now);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handleRequestState(
|
|
||||||
listener: *wl.Listener(*wlr.Output.event.RequestState),
|
|
||||||
event: *wlr.Output.event.RequestState,
|
|
||||||
) void {
|
|
||||||
const output: *Output = @fieldParentPtr("request_state", listener);
|
|
||||||
|
|
||||||
_ = output.wlr_output.commitState(event.state);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
|
||||||
const output: *Output = @fieldParentPtr("destroy", listener);
|
|
||||||
|
|
||||||
output.frame.link.remove();
|
|
||||||
output.request_state.link.remove();
|
|
||||||
output.destroy.link.remove();
|
|
||||||
|
|
||||||
gpa.destroy(output);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Server = struct {
|
pub const Server = struct {
|
||||||
allocator: *wlr.Allocator,
|
allocator: *wlr.Allocator,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue