diff --git a/river/DragIcon.zig b/river/DragIcon.zig index 3ab4c34..ac2896c 100644 --- a/river/DragIcon.zig +++ b/river/DragIcon.zig @@ -1,6 +1,6 @@ // 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 // 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 // along with this program. If not, see . -const Self = @This(); +const DragIcon = @This(); const std = @import("std"); const wlr = @import("wlroots"); @@ -25,20 +25,72 @@ const server = &@import("main.zig").server; const util = @import("util.zig"); const Seat = @import("Seat.zig"); +const Subsurface = @import("Subsurface.zig"); seat: *Seat, wlr_drag_icon: *wlr.Drag.Icon, +// Always active 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 { - self.* = .{ .seat = seat, .wlr_drag_icon = wlr_drag_icon }; - wlr_drag_icon.events.destroy.add(&self.destroy); +// Only active while mapped +commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit), + +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 { - const self = @fieldParentPtr(Self, "destroy", listener); - const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self); + const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener); + + const node = @fieldParentPtr(std.SinglyLinkedList(DragIcon).Node, "data", drag_icon); 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); } + +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 }); +} diff --git a/river/Subsurface.zig b/river/Subsurface.zig index 0f6f544..e52307e 100644 --- a/river/Subsurface.zig +++ b/river/Subsurface.zig @@ -21,19 +21,26 @@ const std = @import("std"); const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; +const server = &@import("main.zig").server; const util = @import("util.zig"); +const DragIcon = @import("DragIcon.zig"); const LayerSurface = @import("LayerSurface.zig"); const View = @import("View.zig"); pub const Parent = union(enum) { view: *View, layer_surface: *LayerSurface, + drag_icon: *DragIcon, pub fn damageWholeOutput(parent: Parent) void { switch (parent) { .view => |view| view.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(); + }, } } }; diff --git a/river/XdgPopup.zig b/river/XdgPopup.zig index cb7740c..8918488 100644 --- a/river/XdgPopup.zig +++ b/river/XdgPopup.zig @@ -54,10 +54,12 @@ pub fn create(wlr_xdg_popup: *wlr.XdgPopup, parent: Parent) void { const parent_box = switch (parent) { .view => |view| &view.pending.box, .layer_surface => |layer_surface| &layer_surface.box, + .drag_icon => unreachable, }; const output_dimensions = switch (parent) { .view => |view| view.output.getEffectiveResolution(), .layer_surface => |layer_surface| layer_surface.output.getEffectiveResolution(), + .drag_icon => unreachable, }; // The output box relative to the parent of the popup