river/river/XwaylandUnmanaged.zig

93 lines
3.7 KiB
Zig
Raw Normal View History

2020-05-11 04:46:29 -07:00
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 The River Developers
2020-05-11 04:46:29 -07:00
//
// 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, either version 3 of the License, or
// (at your option) any later version.
//
// 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 wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
2020-05-11 04:46:29 -07:00
const server = &@import("main.zig").server;
2020-06-16 11:54:05 -07:00
const util = @import("util.zig");
2020-05-11 04:46:29 -07:00
const Box = @import("Box.zig");
/// The corresponding wlroots object
xwayland_surface: *wlr.XwaylandSurface,
2020-05-11 04:46:29 -07:00
// Listeners that are always active over the view's lifetime
2020-12-31 06:35:35 -08:00
// zig fmt: off
request_configure: wl.Listener(*wlr.XwaylandSurface.event.Configure) =
wl.Listener(*wlr.XwaylandSurface.event.Configure).init(handleRequestConfigure),
// zig fmt: on
destroy: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleDestroy),
map: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleMap),
unmap: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleUnmap),
2020-05-11 04:46:29 -07:00
pub fn init(self: *Self, xwayland_surface: *wlr.XwaylandSurface) void {
self.* = .{ .xwayland_surface = xwayland_surface };
2020-05-11 04:46:29 -07:00
2021-01-07 12:48:55 -08:00
// Add listeners that are active over the the entire lifetime
xwayland_surface.events.request_configure.add(&self.request_configure);
xwayland_surface.events.destroy.add(&self.destroy);
xwayland_surface.events.map.add(&self.map);
xwayland_surface.events.unmap.add(&self.unmap);
2020-05-11 04:46:29 -07:00
}
fn handleRequestConfigure(
listener: *wl.Listener(*wlr.XwaylandSurface.event.Configure),
event: *wlr.XwaylandSurface.event.Configure,
) void {
2021-01-07 12:48:55 -08:00
event.surface.configure(event.x, event.y, event.width, event.height);
2020-05-11 04:46:29 -07:00
}
/// Called when the xwayland surface is destroyed
fn handleDestroy(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
const self = @fieldParentPtr(Self, "destroy", listener);
2020-05-11 04:46:29 -07:00
2021-01-07 12:48:55 -08:00
// Remove listeners that are active for the entire lifetime
self.request_configure.link.remove();
self.destroy.link.remove();
self.map.link.remove();
self.unmap.link.remove();
2020-05-11 04:46:29 -07:00
// Deallocate the node
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
util.gpa.destroy(node);
2020-05-11 04:46:29 -07:00
}
/// Called when the xwayland surface is mapped, or ready to display on-screen.
fn handleMap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
const self = @fieldParentPtr(Self, "map", listener);
2020-05-11 04:46:29 -07:00
// Add self to the list of unmanaged views in the root
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
server.root.xwayland_unmanaged_views.prepend(node);
2020-05-11 04:46:29 -07:00
// TODO: handle keyboard focus
// if (wlr_xwayland_or_surface_wants_focus(self.xwayland_surface)) { ...
2020-05-11 04:46:29 -07:00
}
/// Called when the surface is unmapped and will no longer be displayed.
fn handleUnmap(listener: *wl.Listener(*wlr.XwaylandSurface), xwayland_surface: *wlr.XwaylandSurface) void {
const self = @fieldParentPtr(Self, "unmap", listener);
2020-05-11 04:46:29 -07:00
// Remove self from the list of unmanged views in the root
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
server.root.xwayland_unmanaged_views.remove(node);
2020-05-11 04:46:29 -07:00
}