river/river/XdgDecoration.zig
Isaac Freund b2b2c9ed13
river: add rules system
This is a breaking change and replaces the previous
csd-filter-add/remove and float-filter-add/remove commands.

See the riverctl(1) man page for documentation on the new system.
2023-03-12 16:44:19 +01:00

92 lines
3.3 KiB
Zig

// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2023 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
// the Free Software Foundation, version 3.
//
// 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 XdgDecoration = @This();
const std = @import("std");
const assert = std.debug.assert;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig");
const XdgToplevel = @import("XdgToplevel.zig");
wlr_decoration: *wlr.XdgToplevelDecorationV1,
destroy: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleDestroy),
request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
const xdg_toplevel = @intToPtr(*XdgToplevel, wlr_decoration.surface.data);
xdg_toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
const decoration = &xdg_toplevel.decoration.?;
wlr_decoration.events.destroy.add(&decoration.destroy);
wlr_decoration.events.request_mode.add(&decoration.request_mode);
const ssd = server.config.ssd_rules.match(xdg_toplevel.view) orelse
(decoration.wlr_decoration.requested_mode != .client_side);
// TODO(wlroots): make sure this is properly batched in a single configure
// with all other initial state when wlroots makes this possible.
_ = wlr_decoration.setMode(if (ssd) .server_side else .client_side);
xdg_toplevel.view.pending.ssd = ssd;
}
// TODO(wlroots): remove this function when updating to 0.17.0
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4051
pub fn deinit(decoration: *XdgDecoration) void {
decoration.destroy.link.remove();
decoration.request_mode.link.remove();
}
fn handleDestroy(
listener: *wl.Listener(*wlr.XdgToplevelDecorationV1),
_: *wlr.XdgToplevelDecorationV1,
) void {
const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data);
decoration.deinit();
assert(xdg_toplevel.decoration != null);
xdg_toplevel.decoration = null;
}
fn handleRequestMode(
listener: *wl.Listener(*wlr.XdgToplevelDecorationV1),
_: *wlr.XdgToplevelDecorationV1,
) void {
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
const xdg_toplevel = @intToPtr(*XdgToplevel, decoration.wlr_decoration.surface.data);
const view = xdg_toplevel.view;
const ssd = server.config.ssd_rules.match(xdg_toplevel.view) orelse
(decoration.wlr_decoration.requested_mode != .client_side);
if (view.pending.ssd != ssd) {
view.pending.ssd = ssd;
server.root.applyPending();
}
}