mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-08 20:57:32 -04:00
merged
This commit is contained in:
commit
8cff29c795
5 changed files with 370 additions and 94 deletions
103
src/output.zig
103
src/output.zig
|
|
@ -1,3 +1,5 @@
|
|||
const Output = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const posix = std.posix;
|
||||
const gpa = std.heap.c_allocator;
|
||||
|
|
@ -5,60 +7,69 @@ const gpa = std.heap.c_allocator;
|
|||
const wl = @import("wayland").server.wl;
|
||||
const wlr = @import("wlroots");
|
||||
|
||||
const server = &@import("main.zig").server;
|
||||
const Server = @import("server.zig");
|
||||
|
||||
pub const Output = struct {
|
||||
wlr_output: *wlr.Output,
|
||||
scene_output: *wlr.SceneOutput,
|
||||
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(wlr_output: *wlr.Output) !*Output {
|
||||
const output = try gpa.create(Output);
|
||||
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
|
||||
pub fn create(server: *Server, wlr_output: *wlr.Output) !*Output {
|
||||
const output = try gpa.create(Output);
|
||||
|
||||
output.* = .{
|
||||
.wlr_output = wlr_output,
|
||||
.scene_output = try server.root.scene.createSceneOutput(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);
|
||||
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);
|
||||
|
||||
return output;
|
||||
std.log.debug("adding output: {s}", .{output.*.wlr_output.*.name});
|
||||
|
||||
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);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
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 handleFrame(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
||||
const scene_output = server.scene.getSceneOutput(wlr_output);
|
||||
|
||||
if(scene_output) |so| {
|
||||
std.log.info("Rendering commitin scene output\n", .{});
|
||||
_ = so.commit(null);
|
||||
|
||||
var now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
so.sendFrameDone(&now);
|
||||
}
|
||||
|
||||
pub fn handleFrame(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
||||
const scene_output = server.scene.getSceneOutput(wlr_output);
|
||||
}
|
||||
|
||||
if(scene_output) |so| {
|
||||
std.log.info("Rendering commitin scene output\n", .{});
|
||||
_ = so.commit(null);
|
||||
pub fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
const output: *Output = @fieldParentPtr("destroy", listener);
|
||||
|
||||
var now = posix.clock_gettime(posix.CLOCK.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
so.sendFrameDone(&now);
|
||||
}
|
||||
std.log.debug("removing output: {s}", .{output.*.wlr_output.*.name});
|
||||
|
||||
}
|
||||
output.frame.link.remove();
|
||||
output.request_state.link.remove();
|
||||
output.destroy.link.remove();
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
gpa.destroy(output);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue