Drag and drop: files can be dragged between windows and within one
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:
Claude committed 2026-11-26 05:31:33 +00:00
1 parent 80af76fb15
commit 76a23f7816
5 files changed
+1046 -4

No files matched your search

+43
View File
@@ -176,6 +176,16 @@ pub(all) struct ChandraCompositor {
/// pointer (`leave_pointer`: a window move, the overview, a screenshot). /// pointer (`leave_pointer`: a window move, the overview, a screenshot).
mut ptr_grab : Bool mut ptr_grab : Bool
mut grab_buttons : Int 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 kbd_win : UInt64?
mut mods : UInt mut mods : UInt
/// A Super key is down and nothing else was pressed since: releasing it is a Super tap (the /// 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, press_fwd: false,
ptr_grab: false, ptr_grab: false,
grab_buttons: 0, 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, kbd_win: None,
mods: 0U, mods: 0U,
super_solo: false, super_solo: false,
@@ -714,6 +730,23 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
} }
None => release_snapshot(snap) 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) => @wayland.CompositorEvent::SubsurfaceUnmapped(wid, sid) =>
match self.windows.get(wid) { match self.windows.get(wid) {
Some(win) => Some(win) =>
@@ -1048,6 +1081,11 @@ fn ChandraCompositor::build_scene(
None => () 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 { self.shell.layout_sel = match self.layout_mode {
@wm.LayoutMode::Tiling => 0 @wm.LayoutMode::Tiling => 0
@@ -1877,6 +1915,11 @@ pub fn ChandraCompositor::handle_input(
if self.grab_input(ev) { if self.grab_input(ev) {
return 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 { match ev {
Key(code, pressed) => { Key(code, pressed) => {
self.track_modifier_key(code, pressed) self.track_modifier_key(code, pressed)
+137
View File
@@ -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))
}
+260
View File
@@ -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()
}
+538
View File
@@ -0,0 +1,538 @@
///| Drag and drop (wl_data_device.start_drag): a file dragged out of Dolphin or GNOME Files, a
/// tab, a selection of text. The app that starts the drag offers a wl_data_source; while the
/// button is held the host moves the drag focus (`drag_focus`) to the surface under the pointer,
/// whose client gets enter / motion / leave with a wl_data_offer for the source's mime types,
/// and the release drops it (`drag_drop`). Copy / move / ask is agreed between the source's
/// actions and the target's (`set_actions`), as wl_data_device_manager version 3 describes.
///| wl_data_device_manager.dnd_action bits.
const DND_COPY : UInt = 1U
///|
const DND_MOVE : UInt = 2U
///|
const DND_ASK : UInt = 4U
///| The drag in progress.
struct DragState {
/// The client that started it, its wl_data_source (0: a drag inside that client only, which
/// never leaves its own surfaces and has no offer), and the surface it started on.
client_id : UInt
source : UInt
origin : UInt
/// The drag icon (a wl_surface of the dragging client; 0 for none) and its hotspot offset:
/// where its top-left goes relative to the pointer.
mut icon : UInt
mut icon_x : Int
mut icon_y : Int
/// The drag focus: (client id, wl_surface id), and the offers made to that client (one per
/// wl_data_device it has).
mut focus : (UInt, UInt)?
offers : Array[UInt]
/// The last mime type the target accepted ("" = none) and the actions it takes, with its
/// preferred one (dnd_action bits; set by wl_data_offer.set_actions).
mut accepted : String
mut target_actions : UInt
mut preferred : UInt
/// The action agreed with the target (0 = none), last sent to both sides.
mut action : UInt
}
///| A drop the target is still reading: its offer finishes it (wl_data_offer.finish ->
/// dnd_finished), or destroying the offer without finishing cancels it.
struct DropState {
target : UInt
offers : Array[UInt]
source_client : UInt
source : UInt
action : UInt
}
///|
fn dnd_pick_action(source : UInt, target : UInt, preferred : UInt) -> UInt {
let common = source & target
if common == 0U {
0U
} else if (preferred & common) != 0U && (preferred == DND_COPY || preferred == DND_MOVE || preferred == DND_ASK) {
preferred
} else if (common & DND_COPY) != 0U {
DND_COPY
} else if (common & DND_MOVE) != 0U {
DND_MOVE
} else {
DND_ASK
}
}
///| The actions a source offers. One from a client older than version 3 never says: copy.
fn WaylandServer::source_actions(self : WaylandServer, cid : UInt, sid : UInt) -> UInt {
match self.find_client(cid) {
Some(c) =>
match c.source_actions.get(sid) {
Some(a) => a
None => DND_COPY
}
None => 0U
}
}
///| Send an event to a live wl_data_source of client `cid`.
fn WaylandServer::to_source(self : WaylandServer, cid : UInt, sid : UInt, w : WireWriter, opcode : UInt) -> Unit {
match self.find_client(cid) {
Some(c) => if c.data_sources.contains(sid) { c.send_msg(w.finish_msg(sid, opcode)) }
None => ()
}
}
///| Whether a drag is in progress.
pub fn WaylandServer::drag_active(self : WaylandServer) -> Bool {
self.drag is Some(_)
}
///| The drag was started by a client-internal drag (no data source): it may only enter that
/// client's own surfaces.
pub fn WaylandServer::drag_client(self : WaylandServer) -> UInt {
match self.drag {
Some(d) => d.client_id
None => 0U
}
}
///| wl_data_device.start_drag(source, origin, icon, serial).
fn WaylandServer::start_drag(
self : WaylandServer,
c : ClientConn,
source : UInt,
origin : UInt,
icon : UInt,
events : Array[CompositorEvent],
) -> Unit {
// A new drag replaces one still going (a client that lost track of its own).
ignore(self.drag_end(DragCancel, events))
if source != 0U && !c.data_sources.contains(source) {
return
}
// The window the drag started on: the host checks it holds the pointer (a button down).
let win = match c.surfaces.get(origin) {
Some({ window_id: Some(w), .. }) => w
_ =>
match sub_root(c, origin) {
Some((w, _, _)) => w
None => 0UL
}
}
self.drag = Some({
client_id: c.client_id,
source,
origin,
icon: if c.surfaces.contains(icon) { icon } else { 0U },
icon_x: 0,
icon_y: 0,
focus: None,
offers: [],
accepted: "",
target_actions: 0U,
preferred: 0U,
action: 0U,
})
events.push(DragStarted(win))
}
///| Move the drag focus to surface `sub` of window `win_id` (0 for the window's own surface) at
/// surface-local (x, y), or off every client (None: the panel, the desktop, a frame).
pub fn WaylandServer::drag_focus(
self : WaylandServer,
win_id : UInt64?,
sub : UInt,
x : Double,
y : Double,
) -> Unit {
guard self.drag is Some(d) else { return }
let target : (ClientConn, UInt)? = match win_id {
Some(w) =>
match self.win_client(w) {
Some((c, tl)) => {
let sid = if sub != 0U && c.surfaces.contains(sub) { sub } else { tl.wl_surface_id }
// A drag with no source stays inside its own client.
if d.source == 0U && c.client_id != d.client_id { None } else { Some((c, sid)) }
}
None => None
}
None => None
}
let same = match (target, d.focus) {
(Some((c, sid)), Some((fc, fs))) => c.client_id == fc && sid == fs
(None, None) => true
_ => false
}
if same {
return
}
self.drag_leave_focus(d)
match target {
None => ()
Some((c, sid)) => {
d.focus = Some((c.client_id, sid))
d.accepted = ""
d.target_actions = 0U
d.preferred = 0U
d.action = 0U
let mimes : Array[String] = if d.source == 0U {
[]
} else {
match self.find_client(d.client_id) {
Some(oc) => oc.data_sources.get(d.source).unwrap_or([])
None => []
}
}
let src_actions = self.source_actions(d.client_id, d.source)
let serial = self.next_serial()
for dev in c.data_devices {
let mut oid = 0U
if d.source != 0U {
oid = c.next_offer
c.next_offer = c.next_offer + 1U
c.objects.set(oid, ObjDataOffer(d.client_id, d.source))
d.offers.push(oid)
let w = WireWriter::new()
w.u32(oid)
c.send_msg(w.finish_msg(dev, 0U)) // data_offer
for m in mimes {
let ow = WireWriter::new()
ow.str(m)
c.send_msg(ow.finish_msg(oid, 0U)) // offer
}
if c.data_ver >= 3U {
let aw = WireWriter::new()
aw.u32(src_actions)
c.send_msg(aw.finish_msg(oid, 1U)) // source_actions
}
}
let ew = WireWriter::new()
ew.u32(serial)
ew.u32(sid)
ew.i32(fixed(x))
ew.i32(fixed(y))
ew.u32(oid)
c.send_msg(ew.finish_msg(dev, 1U)) // enter
}
// A target older than version 3 never says which actions it takes: copy.
if c.data_ver < 3U {
d.target_actions = DND_COPY
d.preferred = DND_COPY
self.drag_update_action(d)
}
}
}
}
///| The drag leaves its focus: leave to the target, and its offers stop meaning anything.
fn WaylandServer::drag_leave_focus(self : WaylandServer, d : DragState) -> Unit {
match d.focus {
Some((cid, _)) =>
match self.find_client(cid) {
Some(c) =>
for dev in c.data_devices {
c.send_msg(WireWriter::new().finish_msg(dev, 2U)) // leave
}
None => ()
}
None => ()
}
d.focus = None
d.offers.clear()
if d.accepted != "" && d.source != 0U {
// The source shows "no target" again (wl_data_source.target(null)).
let w = WireWriter::new()
w.u32(0U)
self.to_source(d.client_id, d.source, w, 0U)
}
d.accepted = ""
if d.action != 0U {
d.action = 0U
if d.source != 0U && self.client_data_ver(d.client_id) >= 3U {
let w = WireWriter::new()
w.u32(0U)
self.to_source(d.client_id, d.source, w, 5U) // action(none)
}
}
}
///|
fn WaylandServer::client_data_ver(self : WaylandServer, cid : UInt) -> UInt {
match self.find_client(cid) {
Some(c) => c.data_ver
None => 0U
}
}
///| Pointer motion inside the drag focus, surface-local.
pub fn WaylandServer::drag_motion(self : WaylandServer, time_ms : UInt, x : Double, y : Double) -> Unit {
guard self.drag is Some({ focus: Some((cid, _)), .. }) else { return }
match self.find_client(cid) {
Some(c) =>
for dev in c.data_devices {
let w = WireWriter::new()
w.u32(time_ms)
w.i32(fixed(x))
w.i32(fixed(y))
c.send_msg(w.finish_msg(dev, 3U)) // motion
}
None => ()
}
}
///| Work out the action again and tell both sides if it changed.
fn WaylandServer::drag_update_action(self : WaylandServer, d : DragState) -> Unit {
guard d.focus is Some((cid, _)) else { return }
if d.source == 0U {
return
}
let a = dnd_pick_action(self.source_actions(d.client_id, d.source), d.target_actions, d.preferred)
if a == d.action {
return
}
d.action = a
match self.find_client(cid) {
Some(c) =>
if c.data_ver >= 3U {
for oid in d.offers {
let w = WireWriter::new()
w.u32(a)
c.send_msg(w.finish_msg(oid, 2U)) // offer.action
}
}
None => ()
}
if self.client_data_ver(d.client_id) >= 3U {
let w = WireWriter::new()
w.u32(a)
self.to_source(d.client_id, d.source, w, 5U) // source.action
}
}
///| How a drag ends.
enum DragEnd {
/// The button was released: drop if the target accepted, else cancel.
DragRelease
/// Escape, the source going away, the window closing: always cancel.
DragCancel
}
///| Release: drop on the target if it accepted something it can take, otherwise cancel.
/// Returns whether it dropped.
pub fn WaylandServer::drag_drop(self : WaylandServer) -> Bool {
let events : Array[CompositorEvent] = []
self.drag_end(DragRelease, events)
}
///| Cancel the drag (Escape, or the button went up before the client asked to drag).
pub fn WaylandServer::drag_cancel(self : WaylandServer) -> Unit {
let events : Array[CompositorEvent] = []
ignore(self.drag_end(DragCancel, events))
}
///|
fn WaylandServer::drag_end(self : WaylandServer, how : DragEnd, events : Array[CompositorEvent]) -> Bool {
guard self.drag is Some(d) else { return false }
self.drag = None
events.push(DragEnded)
let src_v3 = self.client_data_ver(d.client_id) >= 3U
let ok = match (how, d.focus) {
(DragRelease, Some((cid, _))) =>
if d.source == 0U {
cid == d.client_id
} else {
d.accepted != "" && (d.action != 0U || !src_v3)
}
_ => false
}
if ok {
let (cid, _) = d.focus.unwrap()
match self.find_client(cid) {
Some(c) =>
for dev in c.data_devices {
c.send_msg(WireWriter::new().finish_msg(dev, 4U)) // drop
}
None => ()
}
if d.source != 0U {
if src_v3 {
self.to_source(d.client_id, d.source, WireWriter::new(), 3U) // dnd_drop_performed
}
self.drop_pending = Some({
target: cid,
offers: d.offers.copy(),
source_client: d.client_id,
source: d.source,
action: d.action,
})
}
true
} else {
self.drag_leave_focus(d)
if d.source != 0U {
self.to_source(d.client_id, d.source, WireWriter::new(), 2U) // cancelled
}
false
}
}
///| wl_data_offer.accept(serial, mime or null) from the drag target.
fn WaylandServer::dnd_accept(self : WaylandServer, c : ClientConn, oid : UInt, mime : String) -> Unit {
guard self.drag is Some(d) else { return }
guard d.focus is Some((cid, _)) && cid == c.client_id && d.offers.contains(oid) else { return }
if d.accepted == mime {
return
}
d.accepted = mime
let w = WireWriter::new()
if mime == "" {
w.u32(0U)
} else {
w.str(mime)
}
self.to_source(d.client_id, d.source, w, 0U) // target(mime)
}
///| wl_data_offer.set_actions(dnd_actions, preferred_action) from the drag target.
fn WaylandServer::dnd_set_actions(
self : WaylandServer,
c : ClientConn,
oid : UInt,
actions : UInt,
preferred : UInt,
) -> Unit {
guard self.drag is Some(d) else { return }
guard d.focus is Some((cid, _)) && cid == c.client_id && d.offers.contains(oid) else { return }
d.target_actions = actions & (DND_COPY | DND_MOVE | DND_ASK)
d.preferred = preferred
self.drag_update_action(d)
}
///| wl_data_offer.finish: the target took the dropped data.
fn WaylandServer::dnd_finish(self : WaylandServer, c : ClientConn, oid : UInt) -> Unit {
guard self.drop_pending is Some(p) else { return }
guard p.target == c.client_id && p.offers.contains(oid) else { return }
self.drop_pending = None
if self.client_data_ver(p.source_client) >= 3U {
self.to_source(p.source_client, p.source, WireWriter::new(), 4U) // dnd_finished
}
}
///| A dnd offer was destroyed: a dropped one that never finished cancels the drop.
fn WaylandServer::dnd_offer_gone(self : WaylandServer, c : ClientConn, oid : UInt) -> Unit {
match self.drag {
Some(d) => if d.focus is Some((cid, _)) && cid == c.client_id { d.offers.retain(o => o != oid) }
None => ()
}
guard self.drop_pending is Some(p) else { return }
guard p.target == c.client_id && p.offers.contains(oid) else { return }
p.offers.retain(o => o != oid)
if p.offers.length() == 0 {
self.drop_pending = None
if self.client_data_ver(p.source_client) >= 3U {
self.to_source(p.source_client, p.source, WireWriter::new(), 2U) // cancelled
}
}
}
///| A wl_data_source was destroyed: a drag it fed ends.
fn WaylandServer::dnd_source_gone(self : WaylandServer, c : ClientConn, sid : UInt, events : Array[CompositorEvent]) -> Unit {
match self.drag {
Some(d) =>
if d.client_id == c.client_id && d.source == sid {
self.drag_leave_focus(d)
self.drag = None
events.push(DragEnded)
}
None => ()
}
match self.drop_pending {
Some(p) => if p.source_client == c.client_id && p.source == sid { self.drop_pending = None }
None => ()
}
}
///| A client went away: its drag ends, and a drag over it loses its target.
fn WaylandServer::dnd_client_gone(self : WaylandServer, cid : UInt, events : Array[CompositorEvent]) -> Unit {
match self.drag {
Some(d) =>
if d.client_id == cid {
// Its own target (the client itself) is gone with it; tell another target it left.
match d.focus {
Some((fc, _)) if fc != cid => self.drag_leave_focus(d)
_ => ()
}
self.drag = None
events.push(DragEnded)
} else if d.focus is Some((fc, _)) && fc == cid {
d.focus = None
d.offers.clear()
d.accepted = ""
d.action = 0U
}
None => ()
}
match self.drop_pending {
Some(p) =>
if p.source_client == cid {
self.drop_pending = None
} else if p.target == cid {
self.drop_pending = None
if self.client_data_ver(p.source_client) >= 3U {
self.to_source(p.source_client, p.source, WireWriter::new(), 2U) // cancelled
}
}
None => ()
}
}
///| A surface of the dragging client committed: if it is the drag icon, the host draws it under
/// the pointer, `dx`/`dy` being the hotspot moves (attach offset, wl_surface.offset) it carries.
fn WaylandServer::dnd_icon_commit(
self : WaylandServer,
c : ClientConn,
sid : UInt,
surf : SurfaceState,
events : Array[CompositorEvent],
) -> Unit {
guard self.drag is Some(d) && d.client_id == c.client_id && d.icon == sid && sid != 0U else {
return
}
d.icon_x = d.icon_x + surf.pend_dx
d.icon_y = d.icon_y + surf.pend_dy
if surf.attached_null {
events.push(DragIcon(None, d.icon_x, d.icon_y))
return
}
match surf.attached_buffer {
Some(bid) =>
match snapshot_shm_buffer(c, bid) {
Some(snap) => events.push(DragIcon(Some(snap), d.icon_x, d.icon_y))
None => ()
}
None => if surf.pend_dx != 0 || surf.pend_dy != 0 { events.push(DragIconMoved(d.icon_x, d.icon_y)) }
}
}
///| The drag icon surface was destroyed.
fn WaylandServer::dnd_icon_gone(self : WaylandServer, c : ClientConn, sid : UInt, events : Array[CompositorEvent]) -> Unit {
match self.drag {
Some(d) =>
if d.client_id == c.client_id && d.icon == sid {
d.icon = 0U
events.push(DragIcon(None, 0, 0))
}
None => ()
}
}
///| Whether two windows belong to the same client.
pub fn WaylandServer::same_client(self : WaylandServer, a : UInt64, b : UInt64) -> Bool {
match (self.win_to_client.get(a), self.win_to_client.get(b)) {
(Some(x), Some(y)) => x == y
_ => false
}
}
+68 -4
View File
@@ -40,6 +40,17 @@ pub(all) enum CompositorEvent {
SubsurfaceCommitted(UInt64, UInt, Int, Int, @scene.ShmBufferSnapshot?) SubsurfaceCommitted(UInt64, UInt, Int, Int, @scene.ShmBufferSnapshot?)
/// The subsurface was unmapped (null buffer) or destroyed: (window, child wl_surface id). /// The subsurface was unmapped (null buffer) or destroyed: (window, child wl_surface id).
SubsurfaceUnmapped(UInt64, UInt) SubsurfaceUnmapped(UInt64, UInt)
/// A client started a drag and drop (wl_data_device.start_drag) from this window (0 when its
/// origin surface has no window). The host checks a button is held on it, then moves the drag
/// focus with the pointer (`drag_focus`, `drag_motion`) and drops on release (`drag_drop`).
DragStarted(UInt64)
/// The drag icon's new buffer (None: no icon) and where its top-left goes relative to the
/// pointer.
DragIcon(@scene.ShmBufferSnapshot?, Int, Int)
/// The drag icon's hotspot moved without a new buffer.
DragIconMoved(Int, Int)
/// The drag ended on the client's side (its source or the client went away).
DragEnded
} }
///| wl_subsurface state, keyed by the child wl_surface id. ///| wl_subsurface state, keyed by the child wl_surface id.
@@ -129,6 +140,10 @@ struct SurfaceState {
/// org_kde_kwin_server_decoration mode Server: Chandra draws this window's frame (GTK 3 apps /// org_kde_kwin_server_decoration mode Server: Chandra draws this window's frame (GTK 3 apps
/// without their own header bar, like Webby). /// without their own header bar, like Webby).
mut kde_ssd : Bool mut kde_ssd : Bool
/// Pending surface offset since the last commit (attach x/y, wl_surface.offset): the drag
/// icon's hotspot moves by it.
mut pend_dx : Int
mut pend_dy : Int
} }
///| ///|
@@ -218,6 +233,10 @@ struct ClientConn {
prim_devices : Array[UInt] prim_devices : Array[UInt]
/// zwp_primary_selection_source_v1 id -> mime types it offers. /// zwp_primary_selection_source_v1 id -> mime types it offers.
prim_sources : Map[UInt, Array[String]] prim_sources : Map[UInt, Array[String]]
/// wl_data_device_manager version the client bound (dnd actions are since 3).
mut data_ver : UInt
/// wl_data_source id -> dnd actions it set (set_actions; missing = never set).
source_actions : Map[UInt, UInt]
/// Next server-allocated id for a wl_data_offer. /// Next server-allocated id for a wl_data_offer.
mut next_offer : UInt mut next_offer : UInt
/// wp_cursor_shape_v1 shape the client last asked for (0 = never set). /// wp_cursor_shape_v1 shape the client last asked for (0 = never set).
@@ -249,6 +268,8 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
data_sources: {}, data_sources: {},
prim_devices: [], prim_devices: [],
prim_sources: {}, prim_sources: {},
data_ver: 1U,
source_actions: {},
next_offer: 0xff000000U, next_offer: 0xff000000U,
cursor_shape: 0U, cursor_shape: 0U,
alive: true, alive: true,
@@ -335,6 +356,9 @@ pub(all) struct WaylandServer {
transfers : Array[(Int, Int, UInt64)] transfers : Array[(Int, Int, UInt64)]
/// CHANDRA_DEBUG_CONFIGURE=1: log each configure, ack and committed buffer size to stderr. /// CHANDRA_DEBUG_CONFIGURE=1: log each configure, ack and committed buffer size to stderr.
mut debug_configure : Bool mut debug_configure : Bool
/// Drag and drop in progress (dnd.mbt), and a drop its target is still taking.
mut drag : DragState?
mut drop_pending : DropState?
} }
///| ///|
@@ -366,6 +390,8 @@ pub fn WaylandServer::listen(
own_data: Bytes::from_array([]), own_data: Bytes::from_array([]),
transfers: [], transfers: [],
debug_configure: @sys.getenv("CHANDRA_DEBUG_CONFIGURE").length() > 0, debug_configure: @sys.getenv("CHANDRA_DEBUG_CONFIGURE").length() > 0,
drag: None,
drop_pending: None,
}) })
} }
@@ -621,6 +647,7 @@ fn WaylandServer::dispatch_msg(
c.objects.set(new_id, ObjCursorShapeMgr) c.objects.set(new_id, ObjCursorShapeMgr)
} else if iface == "wl_data_device_manager" { } else if iface == "wl_data_device_manager" {
c.objects.set(new_id, ObjDataManager) c.objects.set(new_id, ObjDataManager)
c.data_ver = ver
} else if iface == "zwp_primary_selection_device_manager_v1" { } else if iface == "zwp_primary_selection_device_manager_v1" {
c.objects.set(new_id, ObjPrimaryManager) c.objects.set(new_id, ObjPrimaryManager)
} else if iface == "wl_subcompositor" { } else if iface == "wl_subcompositor" {
@@ -643,6 +670,8 @@ fn WaylandServer::dispatch_msg(
buffer_scale: 1, buffer_scale: 1,
kde_ssd: false, kde_ssd: false,
attached_null: false, attached_null: false,
pend_dx: 0,
pend_dy: 0,
}) })
} else if opcode == 1U { } else if opcode == 1U {
let rid = reader.u32() let rid = reader.u32()
@@ -660,14 +689,17 @@ fn WaylandServer::dispatch_msg(
None => () None => ()
} }
} }
self.dnd_icon_gone(c, sid, events)
c.surfaces.remove(sid) c.surfaces.remove(sid)
c.objects.remove(sid) c.objects.remove(sid)
send_delete_id(c, sid) send_delete_id(c, sid)
} else if opcode == 1U { } else if opcode == 1U {
// attach(buffer, x, y) // attach(buffer, x, y)
let buf_id = reader.u32() let buf_id = reader.u32()
let _x = reader.i32() let ax = reader.i32()
let _y = reader.i32() let ay = reader.i32()
surf.pend_dx = surf.pend_dx + ax
surf.pend_dy = surf.pend_dy + ay
surf.attached_null = buf_id == 0U surf.attached_null = buf_id == 0U
surf.attached_buffer = if buf_id == 0U { surf.attached_buffer = if buf_id == 0U {
None None
@@ -678,12 +710,19 @@ fn WaylandServer::dispatch_msg(
// frame(callback) // frame(callback)
let cb_id = reader.u32() let cb_id = reader.u32()
surf.pending_frame_cb = Some(cb_id) surf.pending_frame_cb = Some(cb_id)
} else if opcode == 10U {
// offset(x, y) (version 5): moves the surface; for a drag icon, its hotspot.
surf.pend_dx = surf.pend_dx + reader.i32()
surf.pend_dy = surf.pend_dy + reader.i32()
} else if opcode == 8U { } else if opcode == 8U {
// set_buffer_scale(scale) // set_buffer_scale(scale)
let sc = reader.i32() let sc = reader.i32()
surf.buffer_scale = if sc > 0 { sc } else { 1 } surf.buffer_scale = if sc > 0 { sc } else { 1 }
} else if opcode == 6U { } else if opcode == 6U {
// commit // commit
self.dnd_icon_commit(c, sid, surf, events)
surf.pend_dx = 0
surf.pend_dy = 0
if surf.window_id is None && c.subsurfaces.contains(sid) { if surf.window_id is None && c.subsurfaces.contains(sid) {
match sub_root(c, sid) { match sub_root(c, sid) {
Some((wid, ax, ay)) => Some((wid, ax, ay)) =>
@@ -816,9 +855,14 @@ fn WaylandServer::dispatch_msg(
Some(m) => m.push(mime) Some(m) => m.push(mime)
None => () None => ()
} }
} else if opcode == 2U {
// set_actions(dnd_actions) (version 3)
c.source_actions.set(obj_id, reader.u32() & 7U)
} else if opcode == 1U { } else if opcode == 1U {
// destroy // destroy
self.dnd_source_gone(c, obj_id, events)
c.data_sources.remove(obj_id) c.data_sources.remove(obj_id)
c.source_actions.remove(obj_id)
c.objects.remove(obj_id) c.objects.remove(obj_id)
send_delete_id(c, obj_id) send_delete_id(c, obj_id)
if self.selection == Some((c.client_id, obj_id)) { if self.selection == Some((c.client_id, obj_id)) {
@@ -827,7 +871,13 @@ fn WaylandServer::dispatch_msg(
} }
} }
ObjDataDevice => ObjDataDevice =>
if opcode == 1U { if opcode == 0U {
// start_drag(source or null, origin, icon or null, serial)
let src = reader.u32()
let origin = reader.u32()
let icon = reader.u32()
self.start_drag(c, src, origin, icon, events)
} else if opcode == 1U {
// set_selection(source or null, serial) // set_selection(source or null, serial)
let src = reader.u32() let src = reader.u32()
let old = self.selection let old = self.selection
@@ -854,7 +904,19 @@ fn WaylandServer::dispatch_msg(
send_delete_id(c, obj_id) send_delete_id(c, obj_id)
} }
ObjDataOffer(ocid, osid) => ObjDataOffer(ocid, osid) =>
if opcode == 1U { if opcode == 0U {
// accept(serial, mime or null): the drag target can take this type here
let _serial = reader.u32()
self.dnd_accept(c, obj_id, reader.str())
} else if opcode == 3U {
// finish: the drop target has the data
self.dnd_finish(c, obj_id)
} else if opcode == 4U {
// set_actions(dnd_actions, preferred_action)
let actions = reader.u32()
let preferred = reader.u32()
self.dnd_set_actions(c, obj_id, actions, preferred)
} else if opcode == 1U {
// receive(mime_type, fd): ask the owner to write the data into the fd // receive(mime_type, fd): ask the owner to write the data into the fd
let mime = reader.str() let mime = reader.str()
let fd = c.take_fd() let fd = c.take_fd()
@@ -883,6 +945,7 @@ fn WaylandServer::dispatch_msg(
} }
} else if opcode == 2U { } else if opcode == 2U {
// destroy // destroy
self.dnd_offer_gone(c, obj_id)
c.objects.remove(obj_id) c.objects.remove(obj_id)
send_delete_id(c, obj_id) send_delete_id(c, obj_id)
} }
@@ -1563,6 +1626,7 @@ pub fn WaylandServer::poll_events(
events.push(ToplevelClosed(wid)) events.push(ToplevelClosed(wid))
} }
c.close_all() c.close_all()
self.dnd_client_gone(c.client_id, events)
if self.kbd_client == Some(c.client_id) { if self.kbd_client == Some(c.client_id) {
self.kbd_client = None self.kbd_client = None
} }