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
|
2022-01-31 10:33:22 -08:00
|
|
|
// 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/>.
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
seat: *Seat,
|
2020-11-03 15:23:21 -08:00
|
|
|
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,
|
|
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-27 10:51:56 -08:00
|
|
|
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void {
|
2021-06-07 11:34:54 -07:00
|
|
|
const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);
|
|
|
|
|
2022-12-30 13:03:10 -08:00
|
|
|
drag_icon.seat.drag_icon = null;
|
2021-06-07 11:34:54 -07:00
|
|
|
|
|
|
|
drag_icon.destroy.link.remove();
|
2022-12-30 13:03:10 -08:00
|
|
|
drag_icon.commit.link.remove();
|
2021-07-28 04:19:19 -07:00
|
|
|
|
2022-12-30 13:03:10 -08:00
|
|
|
util.gpa.destroy(drag_icon);
|
2020-09-09 16:13:47 -07:00
|
|
|
}
|
2021-06-07 11:34:54 -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;
|
2021-06-07 11:34:54 -07:00
|
|
|
}
|