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,66 +7,64 @@ 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.* = .{
|
||||||
.server = server,
|
.server = server,
|
||||||
.wlr_output = wlr_output,
|
.wlr_output = wlr_output,
|
||||||
};
|
};
|
||||||
wlr_output.events.frame.add(&output.frame);
|
wlr_output.events.frame.add(&output.frame);
|
||||||
wlr_output.events.request_state.add(&output.request_state);
|
wlr_output.events.request_state.add(&output.request_state);
|
||||||
wlr_output.events.destroy.add(&output.destroy);
|
wlr_output.events.destroy.add(&output.destroy);
|
||||||
|
|
||||||
std.log.debug("adding output: {s}", .{output.*.wlr_output.*.name});
|
std.log.debug("adding output: {s}", .{output.*.wlr_output.*.name});
|
||||||
|
|
||||||
const layout_output = try server.output_layout.addAuto(wlr_output);
|
const layout_output = try server.output_layout.addAuto(wlr_output);
|
||||||
|
|
||||||
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).?;
|
||||||
_ = scene_output.commit(null);
|
_ = scene_output.commit(null);
|
||||||
|
|
||||||
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});
|
||||||
|
|
||||||
output.frame.link.remove();
|
output.frame.link.remove();
|
||||||
output.request_state.link.remove();
|
output.request_state.link.remove();
|
||||||
output.destroy.link.remove();
|
output.destroy.link.remove();
|
||||||
|
|
||||||
gpa.destroy(output);
|
gpa.destroy(output);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
|
||||||
130
src/server.zig
130
src/server.zig
|
|
@ -1,86 +1,84 @@
|
||||||
|
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,
|
const wl_server = try wl.Server.create();
|
||||||
renderer: *wlr.Renderer,
|
const event_loop = wl_server.getEventLoop();
|
||||||
|
|
||||||
compositor: *wlr.Compositor,
|
var session: ?*wlr.Session = undefined;
|
||||||
|
const backend = try wlr.Backend.autocreate(event_loop, &session);
|
||||||
|
const renderer = try wlr.Renderer.autocreate(backend);
|
||||||
|
const output_layout = try wlr.OutputLayout.create(wl_server);
|
||||||
|
const scene = try wlr.Scene.create();
|
||||||
|
|
||||||
new_output: wl.Listener(*wlr.Output) = .init(newOutput),
|
// Do we need to fail if session is NULL
|
||||||
|
|
||||||
pub fn init(server: *Server) !void {
|
server.* = .{
|
||||||
const wl_server = try wl.Server.create();
|
.wl_server = wl_server,
|
||||||
const event_loop = wl_server.getEventLoop();
|
.backend = backend,
|
||||||
|
.renderer = renderer,
|
||||||
|
.allocator = try wlr.Allocator.autocreate(backend, renderer),
|
||||||
|
.scene = scene,
|
||||||
|
.output_layout = output_layout,
|
||||||
|
.scene_output_layout = try scene.attachOutputLayout(output_layout),
|
||||||
|
.xdg_shell = try wlr.XdgShell.create(wl_server, 2),
|
||||||
|
.event_loop = event_loop,
|
||||||
|
.session = session,
|
||||||
|
.compositor = try wlr.Compositor.create(wl_server, 6, renderer),
|
||||||
|
.shm = try wlr.Shm.createWithRenderer(wl_server, 1, renderer),
|
||||||
|
.seat = try wlr.Seat.create(wl_server, "default"),
|
||||||
|
};
|
||||||
|
|
||||||
var session: ?*wlr.Session = undefined;
|
try server.renderer.initServer(wl_server);
|
||||||
const backend = try wlr.Backend.autocreate(event_loop, &session);
|
|
||||||
const renderer = try wlr.Renderer.autocreate(backend);
|
|
||||||
const output_layout = try wlr.OutputLayout.create(wl_server);
|
|
||||||
const scene = try wlr.Scene.create();
|
|
||||||
|
|
||||||
// Do we need to fail if session is NULL
|
_ = try wlr.Compositor.create(server.wl_server, 6, server.renderer);
|
||||||
|
_ = try wlr.Subcompositor.create(server.wl_server);
|
||||||
|
_ = try wlr.DataDeviceManager.create(server.wl_server);
|
||||||
|
|
||||||
server.* = .{
|
server.backend.events.new_output.add(&server.new_output);
|
||||||
.wl_server = wl_server,
|
}
|
||||||
.backend = backend,
|
|
||||||
.renderer = renderer,
|
|
||||||
.allocator = try wlr.Allocator.autocreate(backend, renderer),
|
|
||||||
.scene = scene,
|
|
||||||
.output_layout = output_layout,
|
|
||||||
.scene_output_layout = try scene.attachOutputLayout(output_layout),
|
|
||||||
.xdg_shell = try wlr.XdgShell.create(wl_server, 2),
|
|
||||||
.event_loop = event_loop,
|
|
||||||
.session = session,
|
|
||||||
.compositor = try wlr.Compositor.create(wl_server, 6, renderer),
|
|
||||||
.shm = try wlr.Shm.createWithRenderer(wl_server, 1, renderer),
|
|
||||||
.seat = try wlr.Seat.create(wl_server, "default"),
|
|
||||||
};
|
|
||||||
|
|
||||||
try server.renderer.initServer(wl_server);
|
fn newOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
||||||
|
const server: *Server = @fieldParentPtr("new_output", listener);
|
||||||
|
|
||||||
_ = try wlr.Compositor.create(server.wl_server, 6, server.renderer);
|
if (!wlr_output.initRender(server.allocator, server.renderer)) return;
|
||||||
_ = try wlr.Subcompositor.create(server.wl_server);
|
|
||||||
_ = try wlr.DataDeviceManager.create(server.wl_server);
|
|
||||||
|
|
||||||
server.backend.events.new_output.add(&server.new_output);
|
var state = wlr.Output.State.init();
|
||||||
|
defer state.finish();
|
||||||
|
|
||||||
|
state.setEnabled(true);
|
||||||
|
if (wlr_output.preferredMode()) |mode| {
|
||||||
|
state.setMode(mode);
|
||||||
}
|
}
|
||||||
|
if (!wlr_output.commitState(&state)) return;
|
||||||
|
|
||||||
fn newOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
Output.create(server, wlr_output) catch {
|
||||||
const server: *Server = @fieldParentPtr("new_output", listener);
|
std.log.err("failed to allocate new output", .{});
|
||||||
|
wlr_output.destroy();
|
||||||
if (!wlr_output.initRender(server.allocator, server.renderer)) return;
|
return;
|
||||||
|
};
|
||||||
var state = wlr.Output.State.init();
|
}
|
||||||
defer state.finish();
|
|
||||||
|
|
||||||
state.setEnabled(true);
|
|
||||||
if (wlr_output.preferredMode()) |mode| {
|
|
||||||
state.setMode(mode);
|
|
||||||
}
|
|
||||||
if (!wlr_output.commitState(&state)) return;
|
|
||||||
|
|
||||||
Output.create(server, wlr_output) catch {
|
|
||||||
std.log.err("failed to allocate new output", .{});
|
|
||||||
wlr_output.destroy();
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue