Clipboard: implement wl_data_device selection (copy/paste between clients)
The data-device manager was accepted but ignored. Now set_selection is tracked, the focused client is offered the selection (data_offer/offer/selection) on focus change and on update, receive() forwards the fd to the owner as source.send, and the selection is cleared when its owner goes away. Drag-and-drop is still unsupported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
82cac8a915
commit
306a7c121e
2 files changed
+235
-6
No files matched your search
@@ -697,3 +697,69 @@ test "the dock module magnifies the tile under the pointer and shows nothing whe
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(640.0, 300.0), 2U)
|
||||
assert_eq(comp.shell.hover_slot, "")
|
||||
}
|
||||
|
||||
///| Bind wl_data_device_manager and get a data device; returns (manager, device).
|
||||
fn data_device_for(c : TestWaylandClient) -> (UInt, UInt) {
|
||||
let mgr = bind_global(c, 2U, "wl_data_device_manager", 3U)
|
||||
let seat = bind_global(c, 2U, "wl_seat", 7U)
|
||||
let dev = c.alloc_id()
|
||||
let w = @wayland.WireWriter::new()
|
||||
w.u32(dev)
|
||||
w.u32(seat)
|
||||
c.send(w.finish_msg(mgr, 1U))
|
||||
(mgr, dev)
|
||||
}
|
||||
|
||||
///|
|
||||
test "copy in one client, paste in another" {
|
||||
let socket_path = "/tmp/wayland-moon-clip-" + @sys.getpid().to_string() + ".sock"
|
||||
let theme = @scene.ThemeTokens::moon_night()
|
||||
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
||||
let (a, _, _, _, _, _) = open_and_configure_client(comp, socket_path, "A", "a")
|
||||
let (b, _, _, _, _, _) = open_and_configure_client(comp, socket_path, "B", "b")
|
||||
let (mgr_a, dev_a) = data_device_for(a)
|
||||
let (_, dev_b) = data_device_for(b)
|
||||
// A creates a source offering text and makes it the selection.
|
||||
let src = a.alloc_id()
|
||||
let w1 = @wayland.WireWriter::new()
|
||||
w1.u32(src)
|
||||
a.send(w1.finish_msg(mgr_a, 0U))
|
||||
let w2 = @wayland.WireWriter::new()
|
||||
w2.str("text/plain;charset=utf-8")
|
||||
a.send(w2.finish_msg(src, 0U))
|
||||
let w3 = @wayland.WireWriter::new()
|
||||
w3.u32(src)
|
||||
w3.u32(1U)
|
||||
a.send(w3.finish_msg(dev_a, 1U))
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
@sys.sleep_ms(2)
|
||||
}
|
||||
// Focus B's window by clicking it; B is then offered the clipboard.
|
||||
let bg = comp.windows.get(2UL).unwrap().geometry
|
||||
comp.handle_input(
|
||||
@nested.InputEvent::PointerMove((bg.x + bg.w / 2).to_double(), (bg.y + bg.h / 2).to_double()),
|
||||
1U,
|
||||
)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 3U)
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
@sys.sleep_ms(2)
|
||||
}
|
||||
let msgs_b = drain_msgs(b)
|
||||
assert_true(has_msg(msgs_b, dev_b, 0U)) // data_offer
|
||||
assert_true(has_msg(msgs_b, 0xff000000U, 0U)) // offer(mime) on the new wl_data_offer
|
||||
assert_true(has_msg(msgs_b, dev_b, 5U)) // selection
|
||||
// B pastes: receive(mime, fd) on the offer reaches A as source.send.
|
||||
let fd = @sys.memfd_create("paste", 16)
|
||||
let w4 = @wayland.WireWriter::new()
|
||||
w4.str("text/plain;charset=utf-8")
|
||||
b.send(w4.finish_msg(0xff000000U, 1U), send_fd=fd)
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
@sys.sleep_ms(2)
|
||||
}
|
||||
assert_true(has_msg(drain_msgs(a), src, 1U))
|
||||
@sys.close_fd(fd)
|
||||
}
|
||||
Reference in new issue
Block a user