layer-shell: improve configure handling

- don't send a new configure on commit if nothing has changed
- simplify code
This commit is contained in:
Isaac Freund 2020-08-12 11:59:54 +02:00
parent 7a6ac8eb6e
commit aabd85b028

View File

@ -31,7 +31,7 @@ output: *Output,
wlr_layer_surface: *c.wlr_layer_surface_v1, wlr_layer_surface: *c.wlr_layer_surface_v1,
box: Box, box: Box,
layer: c.zwlr_layer_shell_v1_layer, state: c.wlr_layer_surface_v1_state,
// Listeners active the entire lifetime of the layser surface // Listeners active the entire lifetime of the layser surface
listen_destroy: c.wl_listener, listen_destroy: c.wl_listener,
@ -49,20 +49,16 @@ pub fn init(
) void { ) void {
self.output = output; self.output = output;
self.wlr_layer_surface = wlr_layer_surface; self.wlr_layer_surface = wlr_layer_surface;
self.state = wlr_layer_surface.current;
wlr_layer_surface.data = self; wlr_layer_surface.data = self;
self.layer = wlr_layer_surface.client_pending.layer; // Temporarily add to the output's list to allow for inital arrangement
// which sends the first configure.
// Temporarily add to the output's list and apply the pending state to allow
// for inital arrangement which sends the first configure.
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
const list = &output.layers[@intCast(usize, @enumToInt(self.layer))]; const list = &output.layers[@intCast(usize, @enumToInt(self.state.layer))];
const stashed_state = wlr_layer_surface.current;
wlr_layer_surface.current = wlr_layer_surface.client_pending;
list.append(node); list.append(node);
output.arrangeLayers(); output.arrangeLayers();
list.remove(node); list.remove(node);
wlr_layer_surface.current = stashed_state;
// Set up listeners that are active for the entire lifetime of the layer surface // Set up listeners that are active for the entire lifetime of the layer surface
self.listen_destroy.notify = handleDestroy; self.listen_destroy.notify = handleDestroy;
@ -109,7 +105,7 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
); );
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.layer))].append(node); self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].append(node);
} }
fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@ -133,7 +129,7 @@ fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// Remove from the output's list of layer surfaces // Remove from the output's list of layer surfaces
const self_node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); const self_node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.layer))].remove(self_node); self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].remove(self_node);
// If the unmapped surface is focused, clear focus // If the unmapped surface is focused, clear focus
var it = self.output.root.server.input_manager.seats.first; var it = self.output.root.server.input_manager.seats.first;
@ -160,31 +156,27 @@ fn handleUnmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { fn handleCommit(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_commit", listener.?); const self = @fieldParentPtr(Self, "listen_commit", listener.?);
const wlr_layer_surface = self.wlr_layer_surface;
if (self.wlr_layer_surface.output == null) { if (self.wlr_layer_surface.output == null) {
log.err(.layer_shell, "layer surface committed with null output", .{}); log.err(.layer_shell, "layer surface committed with null output", .{});
return; return;
} }
const new_state = &self.wlr_layer_surface.current;
if (!std.meta.eql(self.state, new_state.*)) {
// If the layer changed, move the LayerSurface to the proper list // If the layer changed, move the LayerSurface to the proper list
if (self.layer != self.wlr_layer_surface.current.layer) { if (self.state.layer != new_state.layer) {
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self); const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
self.output.layers[@intCast(usize, @enumToInt(self.state.layer))].remove(node);
const old_layer_idx = @intCast(usize, @enumToInt(self.layer)); self.output.layers[@intCast(usize, @enumToInt(new_state.layer))].append(node);
self.output.layers[old_layer_idx].remove(node);
self.layer = self.wlr_layer_surface.current.layer;
const new_layer_idx = @intCast(usize, @enumToInt(self.layer));
self.output.layers[new_layer_idx].append(node);
} }
// TODO: only reconfigure if things haven't changed self.state = new_state.*;
// https://github.com/swaywm/wlroots/issues/1079
self.output.arrangeLayers(); self.output.arrangeLayers();
self.output.root.startTransaction(); self.output.root.startTransaction();
} }
}
fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const self = @fieldParentPtr(Self, "listen_new_popup", listener.?); const self = @fieldParentPtr(Self, "listen_new_popup", listener.?);