2020-05-11 04:46:29 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// 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");
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const wl = @import("wayland").server.wl;
|
2020-05-11 04:46:29 -07:00
|
|
|
|
2021-05-13 06:08:53 -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
|
2020-11-03 15:23:21 -08:00
|
|
|
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
|
|
|
request_configure: wl.Listener(*wlr.XwaylandSurface.event.Configure) =
|
|
|
|
wl.Listener(*wlr.XwaylandSurface.event.Configure).init(handleRequestConfigure),
|
|
|
|
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),
|
2021-05-23 08:10:26 -07:00
|
|
|
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
2020-05-11 04:46:29 -07:00
|
|
|
|
2021-05-13 06:08:53 -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
|
2020-11-03 15:23:21 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handleRequestConfigure(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *wl.Listener(*wlr.XwaylandSurface.event.Configure),
|
2020-11-03 15:23:21 -08:00
|
|
|
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
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleDestroy(listener: *wl.Listener(*wlr.XwaylandSurface), _: *wlr.XwaylandSurface) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
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();
|
2020-11-03 15:23:21 -08:00
|
|
|
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);
|
2020-06-19 05:31:53 -07:00
|
|
|
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.
|
2020-11-03 15:23:21 -08:00
|
|
|
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);
|
2021-05-13 06:08:53 -07:00
|
|
|
server.root.xwayland_unmanaged_views.prepend(node);
|
2020-05-11 04:46:29 -07:00
|
|
|
|
2021-05-23 08:10:26 -07:00
|
|
|
xwayland_surface.surface.?.events.commit.add(&self.commit);
|
|
|
|
|
2020-05-11 04:46:29 -07:00
|
|
|
// TODO: handle keyboard focus
|
2020-11-03 15:23:21 -08:00
|
|
|
// 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.
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleUnmap(listener: *wl.Listener(*wlr.XwaylandSurface), _: *wlr.XwaylandSurface) void {
|
2020-11-03 15:23:21 -08:00
|
|
|
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);
|
2021-05-13 06:08:53 -07:00
|
|
|
server.root.xwayland_unmanaged_views.remove(node);
|
2021-05-23 08:10:26 -07:00
|
|
|
|
|
|
|
self.commit.link.remove();
|
|
|
|
}
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleCommit(_: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
2021-05-23 08:10:26 -07:00
|
|
|
var it = server.root.outputs.first;
|
|
|
|
while (it) |node| : (it = node.next) node.data.damage.addWhole();
|
2020-05-11 04:46:29 -07:00
|
|
|
}
|