DragIcon: set position on creation

Currently if a drag icon is created but the cursor/touch point is not
moved river will render the drag icon at 0,0 instead of the cursor/touch
point location. This fixes that.
This commit is contained in:
Isaac Freund 2023-10-25 22:01:05 +02:00
parent 3fb229a71d
commit 4cb65f9e2e
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
3 changed files with 27 additions and 20 deletions

View File

@ -1104,24 +1104,8 @@ fn updateDragIcons(self: *Self) void {
while (it.next()) |node| {
const icon = @as(*DragIcon, @ptrFromInt(node.data));
if (icon.wlr_drag_icon.drag.seat != self.seat.wlr_seat) continue;
switch (icon.wlr_drag_icon.drag.grab_type) {
.keyboard => unreachable,
.keyboard_pointer => {
icon.tree.node.setPosition(
@intFromFloat(self.wlr_cursor.x),
@intFromFloat(self.wlr_cursor.y),
);
},
.keyboard_touch => {
const touch_id = icon.wlr_drag_icon.drag.touch_id;
const point = self.touch_points.get(touch_id) orelse continue;
icon.tree.node.setPosition(
@intFromFloat(point.lx),
@intFromFloat(point.ly),
);
},
if (icon.wlr_drag_icon.drag.seat == self.seat.wlr_seat) {
icon.updatePosition(self);
}
}
}

View File

@ -23,6 +23,7 @@ const wl = @import("wayland").server.wl;
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Cursor = @import("Cursor.zig");
const SceneNodeData = @import("SceneNodeData.zig");
wlr_drag_icon: *wlr.Drag.Icon,
@ -35,7 +36,7 @@ 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),
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
pub fn create(wlr_drag_icon: *wlr.Drag.Icon) error{OutOfMemory}!void {
pub fn create(wlr_drag_icon: *wlr.Drag.Icon, cursor: *Cursor) error{OutOfMemory}!void {
const tree = try server.root.drag_icons.createSceneTree();
errdefer tree.node.destroy();
@ -49,6 +50,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon) error{OutOfMemory}!void {
};
tree.node.data = @intFromPtr(drag_icon);
drag_icon.updatePosition(cursor);
tree.node.setEnabled(wlr_drag_icon.mapped);
wlr_drag_icon.events.destroy.add(&drag_icon.destroy);
@ -57,6 +59,27 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon) error{OutOfMemory}!void {
wlr_drag_icon.surface.events.commit.add(&drag_icon.commit);
}
pub fn updatePosition(drag_icon: *DragIcon, cursor: *Cursor) void {
switch (drag_icon.wlr_drag_icon.drag.grab_type) {
.keyboard => unreachable,
.keyboard_pointer => {
drag_icon.tree.node.setPosition(
@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| {
drag_icon.tree.node.setPosition(
@intFromFloat(point.lx),
@intFromFloat(point.ly),
);
}
},
}
}
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void {
const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);

View File

@ -555,7 +555,7 @@ fn handleStartDrag(listener: *wl.Listener(*wlr.Drag), wlr_drag: *wlr.Drag) void
wlr_drag.events.destroy.add(&self.drag_destroy);
if (wlr_drag.icon) |wlr_drag_icon| {
DragIcon.create(wlr_drag_icon) catch {
DragIcon.create(wlr_drag_icon, &self.cursor) catch {
log.err("out of memory", .{});
wlr_drag.seat_client.client.postNoMemory();
return;