render: fix damage tracking of drag icons

This commit is contained in:
Isaac Freund 2021-06-07 18:34:54 +00:00
parent 0e9dc089d1
commit cef6d5a0be
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
3 changed files with 68 additions and 7 deletions

View File

@ -1,6 +1,6 @@
// This file is part of river, a dynamic tiling wayland compositor. // This file is part of river, a dynamic tiling wayland compositor.
// //
// Copyright 2020 The River Developers // Copyright 2020-2021 The River Developers
// //
// This program is free software: you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License as published by
@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const Self = @This(); const DragIcon = @This();
const std = @import("std"); const std = @import("std");
const wlr = @import("wlroots"); const wlr = @import("wlroots");
@ -25,20 +25,72 @@ const server = &@import("main.zig").server;
const util = @import("util.zig"); const util = @import("util.zig");
const Seat = @import("Seat.zig"); const Seat = @import("Seat.zig");
const Subsurface = @import("Subsurface.zig");
seat: *Seat, seat: *Seat,
wlr_drag_icon: *wlr.Drag.Icon, wlr_drag_icon: *wlr.Drag.Icon,
// Always active
destroy: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleDestroy), destroy: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleDestroy),
map: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleMap),
unmap: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleUnmap),
new_subsurface: wl.Listener(*wlr.Subsurface) = wl.Listener(*wlr.Subsurface).init(handleNewSubsurface),
pub fn init(self: *Self, seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon) void { // Only active while mapped
self.* = .{ .seat = seat, .wlr_drag_icon = wlr_drag_icon }; commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
wlr_drag_icon.events.destroy.add(&self.destroy);
pub fn init(drag_icon: *DragIcon, seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon) void {
drag_icon.* = .{ .seat = seat, .wlr_drag_icon = wlr_drag_icon };
wlr_drag_icon.events.destroy.add(&drag_icon.destroy);
wlr_drag_icon.events.map.add(&drag_icon.map);
wlr_drag_icon.events.unmap.add(&drag_icon.unmap);
wlr_drag_icon.surface.events.new_subsurface.add(&drag_icon.new_subsurface);
// 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_drag_icon.surface.subsurfaces.iterator(.forward);
while (it.next()) |s| Subsurface.create(s, .{ .drag_icon = drag_icon });
} }
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void { fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void {
const self = @fieldParentPtr(Self, "destroy", listener); const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
const node = @fieldParentPtr(std.SinglyLinkedList(DragIcon).Node, "data", drag_icon);
server.root.drag_icons.remove(node); server.root.drag_icons.remove(node);
drag_icon.destroy.link.remove();
drag_icon.map.link.remove();
drag_icon.unmap.link.remove();
drag_icon.new_subsurface.link.remove();
util.gpa.destroy(node); util.gpa.destroy(node);
} }
fn handleMap(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void {
const drag_icon = @fieldParentPtr(DragIcon, "map", listener);
wlr_drag_icon.surface.events.commit.add(&drag_icon.commit);
var it = server.root.outputs.first;
while (it) |node| : (it = node.next) node.data.damage.addWhole();
}
fn handleUnmap(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void {
const drag_icon = @fieldParentPtr(DragIcon, "unmap", listener);
drag_icon.commit.link.remove();
var it = server.root.outputs.first;
while (it) |node| : (it = node.next) node.data.damage.addWhole();
}
fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) void {
const drag_icon = @fieldParentPtr(DragIcon, "commit", listener);
var it = server.root.outputs.first;
while (it) |node| : (it = node.next) node.data.damage.addWhole();
}
fn handleNewSubsurface(listener: *wl.Listener(*wlr.Subsurface), wlr_subsurface: *wlr.Subsurface) void {
const drag_icon = @fieldParentPtr(DragIcon, "new_subsurface", listener);
Subsurface.create(wlr_subsurface, .{ .drag_icon = drag_icon });
}

View File

@ -21,19 +21,26 @@ const std = @import("std");
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const wl = @import("wayland").server.wl; const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig"); const util = @import("util.zig");
const DragIcon = @import("DragIcon.zig");
const LayerSurface = @import("LayerSurface.zig"); const LayerSurface = @import("LayerSurface.zig");
const View = @import("View.zig"); const View = @import("View.zig");
pub const Parent = union(enum) { pub const Parent = union(enum) {
view: *View, view: *View,
layer_surface: *LayerSurface, layer_surface: *LayerSurface,
drag_icon: *DragIcon,
pub fn damageWholeOutput(parent: Parent) void { pub fn damageWholeOutput(parent: Parent) void {
switch (parent) { switch (parent) {
.view => |view| view.output.damage.addWhole(), .view => |view| view.output.damage.addWhole(),
.layer_surface => |layer_surface| layer_surface.output.damage.addWhole(), .layer_surface => |layer_surface| layer_surface.output.damage.addWhole(),
.drag_icon => |drag_icon| {
var it = server.root.outputs.first;
while (it) |node| : (it = node.next) node.data.damage.addWhole();
},
} }
} }
}; };

View File

@ -54,10 +54,12 @@ pub fn create(wlr_xdg_popup: *wlr.XdgPopup, parent: Parent) void {
const parent_box = switch (parent) { const parent_box = switch (parent) {
.view => |view| &view.pending.box, .view => |view| &view.pending.box,
.layer_surface => |layer_surface| &layer_surface.box, .layer_surface => |layer_surface| &layer_surface.box,
.drag_icon => unreachable,
}; };
const output_dimensions = switch (parent) { const output_dimensions = switch (parent) {
.view => |view| view.output.getEffectiveResolution(), .view => |view| view.output.getEffectiveResolution(),
.layer_surface => |layer_surface| layer_surface.output.getEffectiveResolution(), .layer_surface => |layer_surface| layer_surface.output.getEffectiveResolution(),
.drag_icon => unreachable,
}; };
// The output box relative to the parent of the popup // The output box relative to the parent of the popup