2020-10-02 06:53:08 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
|
|
|
// Copyright 2020 - 2021 The River Developers
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-10-02 06:53:08 -07:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
const Self = @This();
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
const mem = std.mem;
|
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const wayland = @import("wayland");
|
|
|
|
const wl = wayland.server.wl;
|
|
|
|
const river = wayland.server.river;
|
|
|
|
|
2021-05-13 06:06:00 -07:00
|
|
|
const server = &@import("main.zig").server;
|
2020-10-02 06:53:08 -07:00
|
|
|
const util = @import("util.zig");
|
|
|
|
|
|
|
|
const Layout = @import("Layout.zig");
|
|
|
|
const Server = @import("Server.zig");
|
|
|
|
const Output = @import("Output.zig");
|
|
|
|
|
|
|
|
const log = std.log.scoped(.layout);
|
|
|
|
|
|
|
|
global: *wl.Global,
|
|
|
|
server_destroy: wl.Listener(*wl.Server) = wl.Listener(*wl.Server).init(handleServerDestroy),
|
|
|
|
|
2021-05-13 06:06:00 -07:00
|
|
|
pub fn init(self: *Self) !void {
|
2020-10-02 06:53:08 -07:00
|
|
|
self.* = .{
|
2022-08-18 15:04:16 -07:00
|
|
|
.global = try wl.Global.create(server.wl_server, river.LayoutManagerV3, 2, ?*anyopaque, null, bind),
|
2020-10-02 06:53:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
server.wl_server.addDestroyListener(&self.server_destroy);
|
|
|
|
}
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void {
|
2020-10-02 06:53:08 -07:00
|
|
|
const self = @fieldParentPtr(Self, "server_destroy", listener);
|
|
|
|
self.global.destroy();
|
|
|
|
}
|
|
|
|
|
2022-11-04 16:29:51 -07:00
|
|
|
fn bind(client: *wl.Client, _: ?*anyopaque, version: u32, id: u32) void {
|
2021-10-11 03:44:46 -07:00
|
|
|
const layout_manager = river.LayoutManagerV3.create(client, version, id) catch {
|
2020-10-02 06:53:08 -07:00
|
|
|
client.postNoMemory();
|
2021-10-11 03:44:46 -07:00
|
|
|
log.err("out of memory", .{});
|
2020-10-02 06:53:08 -07:00
|
|
|
return;
|
|
|
|
};
|
2021-10-11 03:44:46 -07:00
|
|
|
layout_manager.setHandler(?*anyopaque, handleRequest, null, null);
|
2020-10-02 06:53:08 -07:00
|
|
|
}
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleRequest(
|
|
|
|
layout_manager: *river.LayoutManagerV3,
|
|
|
|
request: river.LayoutManagerV3.Request,
|
|
|
|
_: ?*anyopaque,
|
|
|
|
) void {
|
2020-10-02 06:53:08 -07:00
|
|
|
switch (request) {
|
|
|
|
.destroy => layout_manager.destroy(),
|
|
|
|
|
|
|
|
.get_layout => |req| {
|
|
|
|
// Ignore if the output is inert
|
|
|
|
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
|
|
|
|
const output = @intToPtr(*Output, wlr_output.data);
|
|
|
|
|
2021-12-20 19:18:03 -08:00
|
|
|
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name });
|
2020-10-02 06:53:08 -07:00
|
|
|
|
|
|
|
Layout.create(
|
|
|
|
layout_manager.getClient(),
|
|
|
|
layout_manager.getVersion(),
|
|
|
|
req.id,
|
|
|
|
output,
|
|
|
|
mem.span(req.namespace),
|
|
|
|
) catch {
|
|
|
|
layout_manager.getClient().postNoMemory();
|
2021-10-11 03:44:46 -07:00
|
|
|
log.err("out of memory", .{});
|
2020-10-02 06:53:08 -07:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|