|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
const Self = @This();
|
|
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
|
|
const c = @import("c.zig");
|
|
|
|
|
|
|
|
|
|
const Config = @import("config.zig").Config;
|
|
|
|
@ -10,30 +13,27 @@ const Root = @import("root.zig").Root;
|
|
|
|
|
const View = @import("view.zig").View;
|
|
|
|
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
|
|
|
|
|
|
|
|
|
pub const Server = struct {
|
|
|
|
|
const Self = @This();
|
|
|
|
|
allocator: *std.mem.Allocator,
|
|
|
|
|
|
|
|
|
|
allocator: *std.mem.Allocator,
|
|
|
|
|
wl_display: *c.wl_display,
|
|
|
|
|
wl_event_loop: *c.wl_event_loop,
|
|
|
|
|
wlr_backend: *c.wlr_backend,
|
|
|
|
|
noop_backend: *c.wlr_backend,
|
|
|
|
|
wlr_renderer: *c.wlr_renderer,
|
|
|
|
|
|
|
|
|
|
wl_display: *c.wl_display,
|
|
|
|
|
wl_event_loop: *c.wl_event_loop,
|
|
|
|
|
wlr_backend: *c.wlr_backend,
|
|
|
|
|
noop_backend: *c.wlr_backend,
|
|
|
|
|
wlr_renderer: *c.wlr_renderer,
|
|
|
|
|
wlr_xdg_shell: *c.wlr_xdg_shell,
|
|
|
|
|
wlr_layer_shell: *c.wlr_layer_shell_v1,
|
|
|
|
|
|
|
|
|
|
wlr_xdg_shell: *c.wlr_xdg_shell,
|
|
|
|
|
wlr_layer_shell: *c.wlr_layer_shell_v1,
|
|
|
|
|
decoration_manager: DecorationManager,
|
|
|
|
|
input_manager: InputManager,
|
|
|
|
|
root: Root,
|
|
|
|
|
config: Config,
|
|
|
|
|
|
|
|
|
|
decoration_manager: DecorationManager,
|
|
|
|
|
input_manager: InputManager,
|
|
|
|
|
root: Root,
|
|
|
|
|
config: Config,
|
|
|
|
|
listen_new_output: c.wl_listener,
|
|
|
|
|
listen_new_xdg_surface: c.wl_listener,
|
|
|
|
|
listen_new_layer_surface: c.wl_listener,
|
|
|
|
|
|
|
|
|
|
listen_new_output: c.wl_listener,
|
|
|
|
|
listen_new_xdg_surface: c.wl_listener,
|
|
|
|
|
listen_new_layer_surface: c.wl_listener,
|
|
|
|
|
|
|
|
|
|
pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
|
|
|
|
|
pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
|
|
|
|
|
self.allocator = allocator;
|
|
|
|
|
|
|
|
|
|
// The Wayland display is managed by libwayland. It handles accepting
|
|
|
|
@ -98,19 +98,19 @@ pub const Server = struct {
|
|
|
|
|
|
|
|
|
|
self.listen_new_layer_surface.notify = handleNewLayerSurface;
|
|
|
|
|
c.wl_signal_add(&self.wlr_layer_shell.events.new_surface, &self.listen_new_layer_surface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Free allocated memory and clean up
|
|
|
|
|
pub fn deinit(self: *Self) void {
|
|
|
|
|
/// Free allocated memory and clean up
|
|
|
|
|
pub fn deinit(self: *Self) void {
|
|
|
|
|
// Note: order is important here
|
|
|
|
|
c.wl_display_destroy_clients(self.wl_display);
|
|
|
|
|
c.wl_display_destroy(self.wl_display);
|
|
|
|
|
self.input_manager.deinit();
|
|
|
|
|
self.root.deinit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create the socket, set WAYLAND_DISPLAY, and start the backend
|
|
|
|
|
pub fn start(self: Self) !void {
|
|
|
|
|
/// Create the socket, set WAYLAND_DISPLAY, and start the backend
|
|
|
|
|
pub fn start(self: Self) !void {
|
|
|
|
|
// Add a Unix socket to the Wayland display.
|
|
|
|
|
const socket = c.wl_display_add_socket_auto(self.wl_display) orelse
|
|
|
|
|
return error.CantAddSocket;
|
|
|
|
@ -125,21 +125,21 @@ pub const Server = struct {
|
|
|
|
|
if (c.setenv("WAYLAND_DISPLAY", socket, 1) == -1) {
|
|
|
|
|
return error.CantSetEnv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Enter the wayland event loop and block until the compositor is exited
|
|
|
|
|
pub fn run(self: Self) void {
|
|
|
|
|
/// Enter the wayland event loop and block until the compositor is exited
|
|
|
|
|
pub fn run(self: Self) void {
|
|
|
|
|
c.wl_display_run(self.wl_display);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handleNewOutput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
fn handleNewOutput(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
const self = @fieldParentPtr(Self, "listen_new_output", listener.?);
|
|
|
|
|
const wlr_output = @ptrCast(*c.wlr_output, @alignCast(@alignOf(*c.wlr_output), data));
|
|
|
|
|
Log.Debug.log("New output {}", .{wlr_output.name});
|
|
|
|
|
self.root.addOutput(wlr_output);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
// This event is raised when wlr_xdg_shell receives a new xdg surface from a
|
|
|
|
|
// client, either a toplevel (application window) or popup.
|
|
|
|
|
const self = @fieldParentPtr(Self, "listen_new_xdg_surface", listener.?);
|
|
|
|
@ -153,10 +153,10 @@ pub const Server = struct {
|
|
|
|
|
Log.Debug.log("New xdg_toplevel", .{});
|
|
|
|
|
|
|
|
|
|
self.input_manager.default_seat.focused_output.addView(wlr_xdg_surface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This event is raised when the layer_shell recieves a new surface from a client.
|
|
|
|
|
fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
/// This event is raised when the layer_shell recieves a new surface from a client.
|
|
|
|
|
fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
|
|
|
|
const self = @fieldParentPtr(Self, "listen_new_layer_surface", listener.?);
|
|
|
|
|
const wlr_layer_surface = @ptrCast(
|
|
|
|
|
*c.wlr_layer_surface_v1,
|
|
|
|
@ -201,5 +201,4 @@ pub const Server = struct {
|
|
|
|
|
|
|
|
|
|
const output = @ptrCast(*Output, @alignCast(@alignOf(*Output), wlr_layer_surface.output.*.data));
|
|
|
|
|
output.addLayerSurface(wlr_layer_surface) catch unreachable;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|