river/river/DragIcon.zig

63 lines
2.0 KiB
Zig
Raw Normal View History

2020-09-09 16:13:47 -07:00
// This file is part of river, a dynamic tiling wayland compositor.
//
// 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, version 3.
2020-09-09 16:13:47 -07:00
//
// 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/>.
const DragIcon = @This();
2020-09-09 16:13:47 -07:00
const std = @import("std");
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
2020-09-09 16:13:47 -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");
seat: *Seat,
wlr_drag_icon: *wlr.Drag.Icon,
2020-09-09 16:13:47 -07:00
2022-12-30 13:03:10 -08:00
// Accumulated x/y surface offset from the cursor/touch point position.
sx: i32 = 0,
sy: i32 = 0,
// Always active
2020-12-31 06:35:35 -08:00
destroy: wl.Listener(*wlr.Drag.Icon) = wl.Listener(*wlr.Drag.Icon).init(handleDestroy),
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);
2022-12-30 13:03:10 -08:00
wlr_drag_icon.surface.events.commit.add(&drag_icon.commit);
2020-09-09 16:13:47 -07:00
}
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void {
const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);
2022-12-30 13:03:10 -08:00
drag_icon.seat.drag_icon = null;
drag_icon.destroy.link.remove();
2022-12-30 13:03:10 -08:00
drag_icon.commit.link.remove();
2022-12-30 13:03:10 -08:00
util.gpa.destroy(drag_icon);
2020-09-09 16:13:47 -07:00
}
2022-12-30 13:03:10 -08:00
fn handleCommit(listener: *wl.Listener(*wlr.Surface), surface: *wlr.Surface) void {
const drag_icon = @fieldParentPtr(DragIcon, "commit", listener);
drag_icon.sx += surface.current.dx;
drag_icon.sy += surface.current.dy;
}