Drag and drop: files can be dragged between windows and within one
CI / test (push) Canceled after 4m0s
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
This commit is contained in:
5 files changed
+1046
-4
No files matched your search
@@ -176,6 +176,16 @@ pub(all) struct ChandraCompositor {
|
||||
/// pointer (`leave_pointer`: a window move, the overview, a screenshot).
|
||||
mut ptr_grab : Bool
|
||||
mut grab_buttons : Int
|
||||
/// A client's drag and drop is going (dnd.mbt): the pointer is the drag until the release.
|
||||
/// Its icon (drawn with its top-left at pointer + (dnd_icon_x, dnd_icon_y)).
|
||||
mut dnd : Bool
|
||||
mut dnd_icon : @scene.ShmBufferSnapshot?
|
||||
mut dnd_icon_x : Int
|
||||
mut dnd_icon_y : Int
|
||||
/// The window (or menu) the drag is over.
|
||||
mut dnd_over : UInt64?
|
||||
/// Time of the last input event (wl_pointer / wl_data_device times).
|
||||
mut input_time : UInt
|
||||
mut kbd_win : UInt64?
|
||||
mut mods : UInt
|
||||
/// A Super key is down and nothing else was pressed since: releasing it is a Super tap (the
|
||||
@@ -357,6 +367,12 @@ pub fn ChandraCompositor::new(
|
||||
press_fwd: false,
|
||||
ptr_grab: false,
|
||||
grab_buttons: 0,
|
||||
dnd: false,
|
||||
dnd_icon: None,
|
||||
dnd_icon_x: 0,
|
||||
dnd_icon_y: 0,
|
||||
dnd_over: None,
|
||||
input_time: 0U,
|
||||
kbd_win: None,
|
||||
mods: 0U,
|
||||
super_solo: false,
|
||||
@@ -714,6 +730,23 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
}
|
||||
None => release_snapshot(snap)
|
||||
}
|
||||
@wayland.CompositorEvent::DragStarted(win) => self.dnd_start(win, self.input_time)
|
||||
@wayland.CompositorEvent::DragIcon(snap, dx, dy) =>
|
||||
if self.dnd {
|
||||
release_snapshot(self.dnd_icon)
|
||||
self.dnd_icon = snap
|
||||
self.dnd_icon_x = dx
|
||||
self.dnd_icon_y = dy
|
||||
self.damage.mark_full()
|
||||
} else {
|
||||
release_snapshot(snap)
|
||||
}
|
||||
@wayland.CompositorEvent::DragIconMoved(dx, dy) => {
|
||||
self.dnd_icon_x = dx
|
||||
self.dnd_icon_y = dy
|
||||
self.damage.mark_full()
|
||||
}
|
||||
@wayland.CompositorEvent::DragEnded => if self.dnd { self.dnd_finish(self.input_time) }
|
||||
@wayland.CompositorEvent::SubsurfaceUnmapped(wid, sid) =>
|
||||
match self.windows.get(wid) {
|
||||
Some(win) =>
|
||||
@@ -1048,6 +1081,11 @@ fn ChandraCompositor::build_scene(
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
// The drag icon, over every window and menu.
|
||||
match self.dnd_icon_node() {
|
||||
Some(n) => scene.popups.push(n)
|
||||
None => ()
|
||||
}
|
||||
|
||||
self.shell.layout_sel = match self.layout_mode {
|
||||
@wm.LayoutMode::Tiling => 0
|
||||
@@ -1877,6 +1915,11 @@ pub fn ChandraCompositor::handle_input(
|
||||
if self.grab_input(ev) {
|
||||
return
|
||||
}
|
||||
self.input_time = time_ms
|
||||
// A drag and drop has the pointer (and Escape) until it is dropped.
|
||||
if self.dnd_input(ev, time_ms) {
|
||||
return
|
||||
}
|
||||
match ev {
|
||||
Key(code, pressed) => {
|
||||
self.track_modifier_key(code, pressed)
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
///| 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))
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
///| Drag and drop (Dolphin, GNOME Files, Chrome): a client starts a drag with the button held,
|
||||
/// the window under the pointer gets enter / motion / drop with an offer of the dragged types,
|
||||
/// and the two agree on copy or move.
|
||||
|
||||
///| Like Dolphin dragging a file: a source offering text/uri-list that can be copied or moved,
|
||||
/// then start_drag from `surf` (with `icon`, 0 for none). Returns the source id.
|
||||
fn start_file_drag(c : TestWaylandClient, mgr : UInt, dev : UInt, surf : UInt, icon? : UInt = 0U) -> UInt {
|
||||
let src = c.alloc_id()
|
||||
let w1 = @wayland.WireWriter::new()
|
||||
w1.u32(src)
|
||||
c.send(w1.finish_msg(mgr, 0U)) // create_data_source
|
||||
let w2 = @wayland.WireWriter::new()
|
||||
w2.str("text/uri-list")
|
||||
c.send(w2.finish_msg(src, 0U)) // offer
|
||||
let w3 = @wayland.WireWriter::new()
|
||||
w3.u32(3U)
|
||||
c.send(w3.finish_msg(src, 2U)) // set_actions(copy | move)
|
||||
let w4 = @wayland.WireWriter::new()
|
||||
w4.u32(src)
|
||||
w4.u32(surf)
|
||||
w4.u32(icon)
|
||||
w4.u32(1U)
|
||||
c.send(w4.finish_msg(dev, 0U)) // start_drag
|
||||
src
|
||||
}
|
||||
|
||||
///|
|
||||
test "a file dragged from one window drops on another, which moves it" {
|
||||
let socket_path = "/tmp/wayland-moon-dnd1-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin")
|
||||
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
|
||||
let (b, shm_b, surf_b, xdg_b, _, _) = open_and_configure_client(comp, socket_path, "Files", "org.gnome.Nautilus")
|
||||
commit_shm_frame(comp, b, shm_b, surf_b, xdg_b, 2UL)
|
||||
let ptr_a = pointer_for(comp, a)
|
||||
let ptr_b = pointer_for(comp, b)
|
||||
let (mgr_a, dev_a) = data_device_for(a)
|
||||
let (_, dev_b) = data_device_for(b)
|
||||
pump(comp, 5)
|
||||
let g = comp.windows.get(1UL).unwrap().geometry
|
||||
let gb = comp.windows.get(2UL).unwrap().geometry
|
||||
// Press on a file in window 1 and move a little: Dolphin starts the drag.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y + 40).to_double()), 10U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 50).to_double(), (g.y + 45).to_double()), 12U)
|
||||
ignore(drain_args(a))
|
||||
ignore(drain_args(b))
|
||||
let src = start_file_drag(a, mgr_a, dev_a, surf_a)
|
||||
pump(comp, 5)
|
||||
let ma = drain_args(a)
|
||||
assert_eq(count_msgs(ma, ptr_a, 1U), 1) // wl_pointer.leave: the pointer is the drag now
|
||||
// The drag enters its own window first (Dolphin can drop into a folder in the same view).
|
||||
let own_enter = ma.iter().find_first(m => m.0 == dev_a && m.1 == 1U).unwrap()
|
||||
assert_eq(own_enter.2[1], surf_a)
|
||||
// Over window 2: it gets an offer of the file list, its actions, then enter.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((gb.x + 60).to_double(), (gb.y + 70).to_double()), 13U)
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(a), dev_a, 2U), 1) // window 1 got leave
|
||||
let mb = drain_args(b)
|
||||
assert_eq(count_msgs(mb, ptr_b, 0U), 0) // no wl_pointer.enter during the drag
|
||||
let offer = mb.iter().find_first(m => m.0 == dev_b && m.1 == 0U).unwrap().2[0]
|
||||
assert_eq(count_msgs(mb, offer, 0U), 1) // offer("text/uri-list")
|
||||
let sa = mb.iter().find_first(m => m.0 == offer && m.1 == 1U).unwrap()
|
||||
assert_eq(sa.2[0], 3U) // source_actions(copy | move)
|
||||
let enter = mb.iter().find_first(m => m.0 == dev_b && m.1 == 1U).unwrap()
|
||||
let (ox, oy) = comp.windows.get(2UL).unwrap().surface_origin()
|
||||
assert_eq(enter.2[1], surf_b)
|
||||
assert_eq(enter.2[2].reinterpret_as_int(), (gb.x + 60 - ox) * 256)
|
||||
assert_eq(enter.2[3].reinterpret_as_int(), (gb.y + 70 - oy) * 256)
|
||||
assert_eq(enter.2[4], offer)
|
||||
// Files accepts the list and prefers to move it.
|
||||
let wacc = @wayland.WireWriter::new()
|
||||
wacc.u32(enter.2[0])
|
||||
wacc.str("text/uri-list")
|
||||
b.send(wacc.finish_msg(offer, 0U))
|
||||
let wact = @wayland.WireWriter::new()
|
||||
wact.u32(3U)
|
||||
wact.u32(2U)
|
||||
b.send(wact.finish_msg(offer, 4U))
|
||||
pump(comp, 5)
|
||||
let ma2 = drain_args(a)
|
||||
assert_eq(count_msgs(ma2, src, 0U), 1) // target("text/uri-list")
|
||||
assert_eq(ma2.iter().find_first(m => m.0 == src && m.1 == 5U).unwrap().2[0], 2U) // action(move)
|
||||
let mb2 = drain_args(b)
|
||||
assert_eq(mb2.iter().find_first(m => m.0 == offer && m.1 == 2U).unwrap().2[0], 2U) // offer.action(move)
|
||||
// Motion inside window 2 reaches it as wl_data_device.motion.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((gb.x + 80).to_double(), (gb.y + 90).to_double()), 14U)
|
||||
pump(comp, 5)
|
||||
let mot = drain_args(b).iter().find_first(m => m.0 == dev_b && m.1 == 3U).unwrap()
|
||||
assert_eq(mot.2[0], 14U)
|
||||
assert_eq(mot.2[1].reinterpret_as_int(), (gb.x + 80 - ox) * 256)
|
||||
// Release: drop on window 2, drop_performed to the source.
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 15U)
|
||||
pump(comp, 5)
|
||||
let mb3 = drain_args(b)
|
||||
assert_eq(count_msgs(mb3, dev_b, 4U), 1) // drop
|
||||
assert_eq(count_msgs(mb3, dev_b, 2U), 0) // and no leave before it is read
|
||||
assert_eq(count_msgs(mb3, ptr_b, 0U), 1) // the pointer is back to normal, over window 2
|
||||
assert_eq(count_msgs(mb3, ptr_b, 3U), 0) // without a stray release
|
||||
let ma3 = drain_args(a)
|
||||
assert_eq(count_msgs(ma3, src, 3U), 1) // dnd_drop_performed
|
||||
assert_eq(count_msgs(ma3, src, 2U), 0) // not cancelled
|
||||
// Files reads the list: receive(mime, fd) reaches Dolphin as send(mime, fd).
|
||||
let fd = @sys.memfd_create("dnd-uri-list", 16)
|
||||
let wr = @wayland.WireWriter::new()
|
||||
wr.str("text/uri-list")
|
||||
b.send(wr.finish_msg(offer, 1U), send_fd=fd)
|
||||
@sys.close_fd(fd)
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(a), src, 1U), 1) // send
|
||||
// finish -> dnd_finished: Dolphin deletes the moved original.
|
||||
b.send(@wayland.WireWriter::new().finish_msg(offer, 3U))
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(a), src, 4U), 1)
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "a drag released where nothing takes it is cancelled" {
|
||||
let socket_path = "/tmp/wayland-moon-dnd2-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin")
|
||||
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
|
||||
let (b, shm_b, surf_b, xdg_b, _, _) = open_and_configure_client(comp, socket_path, "Files", "org.gnome.Nautilus")
|
||||
commit_shm_frame(comp, b, shm_b, surf_b, xdg_b, 2UL)
|
||||
ignore(pointer_for(comp, a))
|
||||
let (mgr_a, dev_a) = data_device_for(a)
|
||||
let (_, dev_b) = data_device_for(b)
|
||||
pump(comp, 5)
|
||||
let g = comp.windows.get(1UL).unwrap().geometry
|
||||
let gb = comp.windows.get(2UL).unwrap().geometry
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y + 40).to_double()), 1U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
let src = start_file_drag(a, mgr_a, dev_a, surf_a)
|
||||
pump(comp, 5)
|
||||
// Over window 2, which doesn't accept anything, then onto the panel and released there.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((gb.x + 60).to_double(), (gb.y + 70).to_double()), 3U)
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(b), dev_b, 1U), 1) // enter
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(640.0, 2.0), 4U)
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(b), dev_b, 2U), 1) // leave
|
||||
ignore(drain_args(a))
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 5U)
|
||||
pump(comp, 5)
|
||||
let ma = drain_args(a)
|
||||
assert_eq(count_msgs(ma, src, 2U), 1) // cancelled
|
||||
assert_eq(count_msgs(ma, src, 3U), 0) // no drop
|
||||
assert_eq(count_msgs(drain_args(b), dev_b, 4U), 0)
|
||||
// A drop over a window that never accepted the type is cancelled too.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y + 40).to_double()), 6U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 7U)
|
||||
let src2 = start_file_drag(a, mgr_a, dev_a, surf_a)
|
||||
pump(comp, 5)
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((gb.x + 60).to_double(), (gb.y + 70).to_double()), 8U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 9U)
|
||||
pump(comp, 5)
|
||||
assert_eq(count_msgs(drain_args(a), src2, 2U), 1)
|
||||
let mb = drain_args(b)
|
||||
assert_eq(count_msgs(mb, dev_b, 4U), 0) // no drop
|
||||
assert_eq(count_msgs(mb, dev_b, 2U), 1) // leave
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "Escape cancels a drag, and a drag asked for after the release never starts" {
|
||||
let socket_path = "/tmp/wayland-moon-dnd3-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin")
|
||||
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
|
||||
let ptr_a = pointer_for(comp, a)
|
||||
let (mgr_a, dev_a) = data_device_for(a)
|
||||
pump(comp, 5)
|
||||
let g = comp.windows.get(1UL).unwrap().geometry
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y + 40).to_double()), 1U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
let src = start_file_drag(a, mgr_a, dev_a, surf_a)
|
||||
pump(comp, 5)
|
||||
ignore(drain_args(a))
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, true), 3U)
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, false), 4U)
|
||||
pump(comp, 5)
|
||||
let ma = drain_args(a)
|
||||
assert_eq(count_msgs(ma, src, 2U), 1) // cancelled
|
||||
assert_eq(count_msgs(ma, dev_a, 2U), 1) // leave
|
||||
assert_eq(count_msgs(ma, ptr_a, 0U), 1) // the pointer is the window's again
|
||||
// The release that follows is not a drop and doesn't reach the window as a stray release.
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 5U)
|
||||
pump(comp, 5)
|
||||
let mr = drain_args(a)
|
||||
assert_eq(count_msgs(mr, dev_a, 4U), 0)
|
||||
// A click that was already released when the drag request arrives: cancelled at once.
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 6U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 7U)
|
||||
let late = start_file_drag(a, mgr_a, dev_a, surf_a)
|
||||
pump(comp, 5)
|
||||
let ml = drain_args(a)
|
||||
assert_eq(count_msgs(ml, late, 2U), 1) // cancelled
|
||||
assert_eq(count_msgs(ml, dev_a, 1U), 0) // never entered
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "the drag icon follows the pointer, its hotspot under it" {
|
||||
let socket_path = "/tmp/wayland-moon-dnd4-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin")
|
||||
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
|
||||
ignore(pointer_for(comp, a))
|
||||
let (mgr_a, dev_a) = data_device_for(a)
|
||||
let comp_id = bind_global(a, 2U, "wl_compositor", 5U)
|
||||
let icon = a.alloc_id()
|
||||
let wcs = @wayland.WireWriter::new()
|
||||
wcs.u32(icon)
|
||||
a.send(wcs.finish_msg(comp_id, 0U))
|
||||
pump(comp, 5)
|
||||
let g = comp.windows.get(1UL).unwrap().geometry
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y + 40).to_double()), 1U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
ignore(start_file_drag(a, mgr_a, dev_a, surf_a, icon~))
|
||||
pump(comp, 5)
|
||||
// A 32x24 icon whose hotspot is 16, 12 (wl_surface.offset(-16, -12), as Qt and GTK do).
|
||||
let memfd = @sys.memfd_create("dnd-icon", 32 * 24 * 4)
|
||||
ignore(@sys.pwrite_bytes(memfd, Bytes::make(32 * 24 * 4, b'\xff'), 0))
|
||||
let pool = a.alloc_id()
|
||||
let wp = @wayland.WireWriter::new()
|
||||
wp.u32(pool)
|
||||
wp.i32(32 * 24 * 4)
|
||||
a.send(wp.finish_msg(shm_a, 0U), send_fd=memfd)
|
||||
@sys.close_fd(memfd)
|
||||
let buf = a.alloc_id()
|
||||
let wb = @wayland.WireWriter::new()
|
||||
wb.u32(buf)
|
||||
wb.i32(0)
|
||||
wb.i32(32)
|
||||
wb.i32(24)
|
||||
wb.i32(32 * 4)
|
||||
wb.u32(0U)
|
||||
a.send(wb.finish_msg(pool, 0U))
|
||||
let wa = @wayland.WireWriter::new()
|
||||
wa.u32(buf)
|
||||
wa.i32(0)
|
||||
wa.i32(0)
|
||||
a.send(wa.finish_msg(icon, 1U)) // attach
|
||||
let wo = @wayland.WireWriter::new()
|
||||
wo.i32(-16)
|
||||
wo.i32(-12)
|
||||
a.send(wo.finish_msg(icon, 10U)) // offset
|
||||
a.send(@wayland.WireWriter::new().finish_msg(icon, 6U)) // commit
|
||||
pump(comp, 5)
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(500.0, 300.0), 3U)
|
||||
let scene = comp.compose_scene().unwrap()
|
||||
let r = scene.popups.last().unwrap().0
|
||||
assert_eq((r.x, r.y, r.w, r.h), (484, 288, 32, 24))
|
||||
// Dropped: the icon is gone.
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
|
||||
let scene2 = comp.compose_scene().unwrap()
|
||||
assert_eq(scene2.popups.length(), 0)
|
||||
comp.close()
|
||||
}
|
||||
Reference in new issue
Block a user