CI / test (push) Canceled after 4m0s
The compositor ignored wl_data_device.start_drag, so no drag ever reached a window: Dolphin, GNOME Files, Chrome tabs and text could not be dropped anywhere, not even inside the window they started in. Now (compositor/wayland/dnd.mbt, compositor/host/dnd.mbt): - start_drag while a button is held on the client turns the pointer into the drag (the origin gets wl_pointer.leave); a request that arrives after the release is cancelled at once. - The surface under the pointer (windows, subsurfaces, menus) gets data_offer + offer + source_actions + enter, then motion and leave; a drag without a source stays inside its own client. - accept -> source.target, set_actions -> copy/move/ask agreed and sent as offer.action and source.action (version 3), version 1/2 clients copy. - Release drops when the target accepted a type and an action: drop, dnd_drop_performed, and finish -> dnd_finished; otherwise cancelled + leave. Escape cancels. The window dropped on becomes active, so Dolphin's Copy/Move Here menu opens as a menu of a focused window. - The drag icon is drawn under the pointer at its hotspot (attach offsets and wl_surface.offset), above windows and menus. - A source, icon or client going away ends or updates the drag. Tests: compositor/host/dnd_test.mbt (fail on the previous commit). Checked headless with real Dolphin 23.08 (Qt 5.15) and GNOME Files 46 on both the native build and the wasm build: Files -> Dolphin, Dolphin -> Files, Dolphin -> Dolphin (Move/Copy/Link menu) and a move into a folder inside Files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjWb2dWbR1K7qoMgWP
138 lines
4.7 KiB
MoonBit
138 lines
4.7 KiB
MoonBit
///| Drag and drop on the host side (the protocol is compositor/wayland/dnd.mbt): once a client
|
|
/// starts a drag with a button held, the pointer stops going to clients as wl_pointer events and
|
|
/// becomes the drag: the surface under it is the drag focus, the drag icon follows it, Escape
|
|
/// cancels and the release drops.
|
|
|
|
///| A client asked to start a drag from window `win` (0: unknown). It is only real while a button
|
|
/// pressed on that client is still held; otherwise (a click that was already released) it is
|
|
/// cancelled at once, so the app doesn't wait for a drop that can't come.
|
|
fn ChandraCompositor::dnd_start(self : ChandraCompositor, win : UInt64, time_ms : UInt) -> Unit {
|
|
let held = self.ptr_grab && self.grab_buttons > 0 || self.press_fwd
|
|
let same_client = win == 0UL ||
|
|
(match self.ptr_win {
|
|
Some(w) => w == win || self.server.same_client(w, win)
|
|
None => false
|
|
})
|
|
if !held || !same_client {
|
|
self.server.drag_cancel()
|
|
return
|
|
}
|
|
// The origin loses the pointer (wl_pointer.leave) and gets the drag instead.
|
|
self.dnd = true
|
|
self.leave_pointer()
|
|
self.press_fwd = false
|
|
self.dnd_motion(time_ms)
|
|
}
|
|
|
|
///| The pointer moved during a drag: move the drag focus to what is under it.
|
|
fn ChandraCompositor::dnd_motion(self : ChandraCompositor, time_ms : UInt) -> Unit {
|
|
let xi = self.ptr_x.to_int()
|
|
let yi = self.ptr_y.to_int()
|
|
let over = match self.popup_at(xi, yi) {
|
|
Some(p) => {
|
|
let (ox, oy) = { let r = self.popup_rect(p); (r.x, r.y) }
|
|
Some((p.id, 0U, self.ptr_x - ox.to_double(), self.ptr_y - oy.to_double()))
|
|
}
|
|
None =>
|
|
if self.shell.hit(xi, yi) {
|
|
None // the panel, the launcher: nothing there takes a drop
|
|
} else {
|
|
match self.window_at(xi, yi) {
|
|
Some((wid, true)) =>
|
|
match self.windows.get(wid) {
|
|
Some(win) => {
|
|
let (sub, lx, ly) = win.surface_at(self.ptr_x, self.ptr_y)
|
|
Some((wid, sub, lx, ly))
|
|
}
|
|
None => None
|
|
}
|
|
_ => None
|
|
}
|
|
}
|
|
}
|
|
self.dnd_over = match over {
|
|
Some((wid, _, _, _)) => Some(wid)
|
|
None => None
|
|
}
|
|
match over {
|
|
Some((wid, sub, lx, ly)) => {
|
|
self.server.drag_focus(Some(wid), sub, lx, ly)
|
|
self.server.drag_motion(time_ms, lx, ly)
|
|
}
|
|
None => self.server.drag_focus(None, 0U, 0.0, 0.0)
|
|
}
|
|
if self.dnd_icon is Some(_) {
|
|
self.damage.mark_full()
|
|
}
|
|
}
|
|
|
|
///| The drag is over (dropped, cancelled, or ended by the client): back to normal pointer
|
|
/// routing, the pointer entering whatever is under it.
|
|
fn ChandraCompositor::dnd_finish(self : ChandraCompositor, time_ms : UInt) -> Unit {
|
|
self.dnd = false
|
|
self.dnd_over = None
|
|
release_snapshot(self.dnd_icon)
|
|
self.dnd_icon = None
|
|
self.ptr_grab = false
|
|
self.grab_buttons = 0
|
|
self.press_fwd = false
|
|
self.damage.mark_full()
|
|
self.handle_input(PointerMove(self.ptr_x, self.ptr_y), time_ms)
|
|
}
|
|
|
|
///| Input while a drag is going: true when it was the drag's (motion, release, Escape, wheel).
|
|
fn ChandraCompositor::dnd_input(self : ChandraCompositor, ev : @nested.InputEvent, time_ms : UInt) -> Bool {
|
|
if !self.dnd {
|
|
return false
|
|
}
|
|
if !self.server.drag_active() {
|
|
// The client ended it (its source or the client went away).
|
|
self.dnd_finish(time_ms)
|
|
return false
|
|
}
|
|
match ev {
|
|
PointerMove(x, y) => {
|
|
self.ptr_x = x
|
|
self.ptr_y = y
|
|
self.dnd_motion(time_ms)
|
|
true
|
|
}
|
|
PointerButton(_, false) => {
|
|
let target = self.dnd_over
|
|
let dropped = self.server.drag_drop()
|
|
self.dnd_finish(time_ms)
|
|
if dropped {
|
|
// The window it was dropped on becomes the active one: the drop is now its work, and
|
|
// what it shows next (Dolphin's Copy Here / Move Here menu) is a menu of a focused
|
|
// window, not a window of its own.
|
|
let wid = match target {
|
|
Some(w) => match self.popup_root(w) { Some(r) => r; None => w }
|
|
None => 0UL
|
|
}
|
|
if self.windows.contains(wid) {
|
|
self.activate_window(wid)
|
|
}
|
|
}
|
|
true
|
|
}
|
|
PointerButton(_, true) => true
|
|
Scroll(_, _, _) => true
|
|
Key(1U, true) => {
|
|
// Escape cancels the drag.
|
|
self.server.drag_cancel()
|
|
self.dnd_finish(time_ms)
|
|
true
|
|
}
|
|
Key(1U, false) => true
|
|
_ => false
|
|
}
|
|
}
|
|
|
|
///| Scene: the drag icon, above everything clients draw, its hotspot at the pointer.
|
|
fn ChandraCompositor::dnd_icon_node(self : ChandraCompositor) -> (@scene.Rect, @scene.ShmBufferSnapshot)? {
|
|
guard self.dnd && self.dnd_icon is Some(snap) else { return None }
|
|
let x = self.ptr_x.to_int() + self.dnd_icon_x
|
|
let y = self.ptr_y.to_int() + self.dnd_icon_y
|
|
Some((@scene.Rect::new(x, y, snap.width, snap.height), snap))
|
|
}
|