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");
|
|
|
|
|
2023-10-25 13:01:05 -07:00
|
|
|
const Cursor = @import("Cursor.zig");
|
2023-02-16 07:54:53 -08:00
|
|
|
const SceneNodeData = @import("SceneNodeData.zig");
|
2020-09-09 16:13:47 -07:00
|
|
|
|
2020-11-03 15:23:21 -08:00
|
|
|
wlr_drag_icon: *wlr.Drag.Icon,
|
2023-12-01 05:57:18 -08:00
|
|
|
scene_drag_icon: *wlr.SceneTree,
|
2022-12-30 13:03:10 -08:00
|
|
|
|
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
|
|
|
|
2023-10-25 13:01:05 -07:00
|
|
|
pub fn create(wlr_drag_icon: *wlr.Drag.Icon, cursor: *Cursor) error{OutOfMemory}!void {
|
2023-12-01 05:57:18 -08:00
|
|
|
const scene_drag_icon = try server.root.drag_icons.createSceneDragIcon(wlr_drag_icon);
|
|
|
|
errdefer scene_drag_icon.node.destroy();
|
2023-02-16 07:54:53 -08:00
|
|
|
|
|
|
|
const drag_icon = try util.gpa.create(DragIcon);
|
|
|
|
errdefer util.gpa.destroy(drag_icon);
|
|
|
|
|
|
|
|
drag_icon.* = .{
|
|
|
|
.wlr_drag_icon = wlr_drag_icon,
|
2023-12-01 05:57:18 -08:00
|
|
|
.scene_drag_icon = scene_drag_icon,
|
2023-02-16 07:54:53 -08:00
|
|
|
};
|
2023-12-01 05:57:18 -08:00
|
|
|
scene_drag_icon.node.data = @intFromPtr(drag_icon);
|
2023-02-16 07:54:53 -08:00
|
|
|
|
2023-10-25 13:01:05 -07:00
|
|
|
drag_icon.updatePosition(cursor);
|
2021-06-07 11:34:54 -07:00
|
|
|
|
|
|
|
wlr_drag_icon.events.destroy.add(&drag_icon.destroy);
|
2020-09-09 16:13:47 -07:00
|
|
|
}
|
|
|
|
|
2023-10-25 13:01:05 -07:00
|
|
|
pub fn updatePosition(drag_icon: *DragIcon, cursor: *Cursor) void {
|
|
|
|
switch (drag_icon.wlr_drag_icon.drag.grab_type) {
|
|
|
|
.keyboard => unreachable,
|
|
|
|
.keyboard_pointer => {
|
2023-12-01 05:57:18 -08:00
|
|
|
drag_icon.scene_drag_icon.node.setPosition(
|
2023-10-25 13:01:05 -07:00
|
|
|
@intFromFloat(cursor.wlr_cursor.x),
|
|
|
|
@intFromFloat(cursor.wlr_cursor.y),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
.keyboard_touch => {
|
|
|
|
const touch_id = drag_icon.wlr_drag_icon.drag.touch_id;
|
|
|
|
if (cursor.touch_points.get(touch_id)) |point| {
|
2023-12-01 05:57:18 -08:00
|
|
|
drag_icon.scene_drag_icon.node.setPosition(
|
2023-10-25 13:01:05 -07:00
|
|
|
@intFromFloat(point.lx),
|
|
|
|
@intFromFloat(point.ly),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
drag_icon.destroy.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
|
|
|
}
|