2020-09-09 16:13:47 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2021-06-07 11:34:54 -07:00
|
|
|
// Copyright 2020-2021 The River Developers
|
2020-09-09 16:13:47 -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/>.
|
|
|
|
|
2021-06-07 11:34:54 -07:00
|
|
|
const DragIcon = @This();
|
2020-09-09 16:13:47 -07:00
|
|
|
|
|
|
|
const std = @import("std");
|
2020-11-03 15:23:21 -08:00
|
|
|
const wlr = @import("wlroots");
|
|
|
|
const wl = @import("wayland").server.wl;
|
2020-09-09 16:13:47 -07:00
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
const server = &@import("main.zig").server;
|
2020-09-09 16:13:47 -07:00
|
|
|
const util = @import("util.zig");
|
|
|
|
|
|
|
|
const Seat = @import("Seat.zig");
|
2021-06-07 11:34:54 -07:00
|
|
|
const Subsurface = @import("Subsurface.zig");
|
2020-09-09 16:13:47 -07:00
|
|
|
|
|
|
|
seat: *Seat,
|
2020-11-03 15:23:21 -08:00
|
|
|
wlr_drag_icon: *wlr.Drag.Icon,
|
2020-09-09 16:13:47 -07:00
|
|
|
|
2021-06-07 11:34:54 -07:00
|
|
|
// Always active
|
2020-12-31 06:35:35 -08:00
|
|
|
destroy: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleDestroy),
|
2021-06-07 11:34:54 -07:00
|
|
|
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),
|
2020-09-09 16:13:47 -07:00
|
|
|
|
2021-06-07 11:34:54 -07:00
|
|
|
// 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);
|
|
|
|
|
2021-06-14 13:27:08 -07:00
|
|
|
Subsurface.handleExisting(wlr_drag_icon.surface, .{ .drag_icon = drag_icon });
|
2020-09-09 16:13:47 -07:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), wlr_drag_icon: *wlr.Drag.Icon) void {
|
2021-06-07 11:34:54 -07:00
|
|
|
const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);
|
|
|
|
|
|
|
|
const node = @fieldParentPtr(std.SinglyLinkedList(DragIcon).Node, "data", drag_icon);
|
2021-05-13 05:53:08 -07:00
|
|
|
server.root.drag_icons.remove(node);
|
2021-06-07 11:34:54 -07:00
|
|
|
|
|
|
|
drag_icon.destroy.link.remove();
|
|
|
|
drag_icon.map.link.remove();
|
|
|
|
drag_icon.unmap.link.remove();
|
|
|
|
drag_icon.new_subsurface.link.remove();
|
|
|
|
|
2021-07-28 04:19:19 -07:00
|
|
|
Subsurface.destroySubsurfaces(wlr_drag_icon.surface);
|
|
|
|
|
2020-09-09 16:13:47 -07:00
|
|
|
util.gpa.destroy(node);
|
|
|
|
}
|
2021-06-07 11:34:54 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleUnmap(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void {
|
2021-06-07 11:34:54 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-11 03:44:46 -07:00
|
|
|
fn handleCommit(_: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
2021-06-07 11:34:54 -07:00
|
|
|
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 });
|
|
|
|
}
|