layer-shell: handle commits before map

A client is free to change its mind and request a different
size/anchor/etc after recieving the initial configure but before
attaching and committing the first buffer. This means that we should
respond to such a situation with a new configure.

mako has been observed doing this in the wild for example.
This commit is contained in:
Isaac Freund
2021-06-21 19:02:24 +02:00
parent a2c81adba0
commit 3efcfedcf4
4 changed files with 46 additions and 36 deletions

View File

@ -18,6 +18,7 @@
const Self = @This();
const std = @import("std");
const assert = std.debug.assert;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
@ -37,14 +38,11 @@ wlr_layer_surface: *wlr.LayerSurfaceV1,
box: Box = undefined,
state: wlr.LayerSurfaceV1.State,
// Listeners active the entire lifetime of the layser surface
destroy: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleDestroy),
map: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleMap),
unmap: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleUnmap),
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
new_subsurface: wl.Listener(*wlr.Subsurface) = wl.Listener(*wlr.Subsurface).init(handleNewSubsurface),
// Listeners only active while the layer surface is mapped
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
pub fn init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1) void {
@ -55,21 +53,19 @@ pub fn init(self: *Self, output: *Output, wlr_layer_surface: *wlr.LayerSurfaceV1
};
wlr_layer_surface.data = @ptrToInt(self);
// Temporarily add to the output's list to allow for inital arrangement
// which sends the first configure.
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
const list = &output.layers[@intCast(usize, @enumToInt(self.state.layer))];
list.append(node);
output.arrangeLayers();
list.remove(node);
// Set up listeners that are active for the entire lifetime of the layer surface
wlr_layer_surface.events.destroy.add(&self.destroy);
wlr_layer_surface.events.map.add(&self.map);
wlr_layer_surface.events.unmap.add(&self.unmap);
wlr_layer_surface.events.new_popup.add(&self.new_popup);
wlr_layer_surface.surface.events.commit.add(&self.commit);
wlr_layer_surface.surface.events.new_subsurface.add(&self.new_subsurface);
// wlroots only informs us of the new surface after the first commit,
// so our listener does not get called for this first commit. However,
// we do want our listener called in order to send the initial configure.
handleCommit(&self.commit, wlr_layer_surface.surface);
// There may already be subsurfaces present on this surface that we
// aren't aware of and won't receive a new_subsurface event for.
var it = wlr_layer_surface.surface.subsurfaces.iterator(.forward);
@ -86,6 +82,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface:
self.map.link.remove();
self.unmap.link.remove();
self.new_popup.link.remove();
self.commit.link.remove();
self.new_subsurface.link.remove();
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
@ -97,13 +94,11 @@ fn handleMap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wl
log.debug("layer surface '{s}' mapped", .{wlr_layer_surface.namespace});
// Add listeners that are only active while mapped
wlr_layer_surface.surface.events.commit.add(&self.commit);
wlr_layer_surface.surface.sendEnter(wlr_layer_surface.output.?);
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].append(node);
self.output.getLayer(self.state.layer).append(node);
self.output.arrangeLayers(.mapped);
}
fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void {
@ -111,9 +106,6 @@ fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *
log.debug("layer surface '{s}' unmapped", .{self.wlr_layer_surface.namespace});
// remove listeners only active while the layer surface is mapped
self.commit.link.remove();
// Remove from the output's list of layer surfaces
const self_node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].remove(self_node);
@ -128,7 +120,7 @@ fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *
// This gives exclusive focus to a keyboard interactive top or overlay layer
// surface if there is one.
self.output.arrangeLayers();
self.output.arrangeLayers(.mapped);
// Ensure that focus is given to the appropriate view if there is no
// other top/overlay layer surface to grab focus.
@ -144,8 +136,14 @@ fn handleUnmap(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *
fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface) void {
const self = @fieldParentPtr(Self, "commit", listener);
if (self.wlr_layer_surface.output == null) {
log.err("layer surface committed with null output", .{});
assert(self.wlr_layer_surface.output != null);
// If a surface is committed while it is not mapped, we may need to send a configure.
if (!self.wlr_layer_surface.mapped) {
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.getLayer(self.state.layer).append(node);
self.output.arrangeLayers(.unmapped);
self.output.getLayer(self.state.layer).remove(node);
return;
}
@ -154,13 +152,13 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), wlr_surface: *wlr.Surface)
// If the layer changed, move the LayerSurface to the proper list
if (self.state.layer != new_state.layer) {
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].remove(node);
self.output.layers[@intCast(usize, @enumToInt(new_state.layer))].append(node);
self.output.getLayer(self.state.layer).remove(node);
self.output.getLayer(new_state.layer).append(node);
}
self.state = new_state.*;
self.output.arrangeLayers();
self.output.arrangeLayers(.mapped);
server.root.startTransaction();
}