From 511ef6db31ab06b8528898e494aa3febadf0c619 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 May 2026 08:06:44 +0530 Subject: [PATCH] More work on DnD kitten --- kittens/dnd/drag.go | 4 ++-- kittens/dnd/main.go | 6 +++++- kitty/dnd.c | 4 ---- kitty_tests/dnd_kitten.py | 17 ++++++++++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/kittens/dnd/drag.go b/kittens/dnd/drag.go index 45d93466e..42fc124ca 100644 --- a/kittens/dnd/drag.go +++ b/kittens/dnd/drag.go @@ -67,12 +67,12 @@ func (dnd *dnd) reset_drag() { dnd.drag_status = drag_status{} } -func (dnd *dnd) on_drag_event(x, y int) (err error) { +func (dnd *dnd) on_drag_event(x, y, operation int) (err error) { switch x { case 1: dnd.drag_status.accepted_mime = y case 2: - dnd.drag_status.accepted_operation = y + dnd.drag_status.accepted_operation = operation case 3: dnd.drag_status.dropped = true case 4: diff --git a/kittens/dnd/main.go b/kittens/dnd/main.go index 75e69a462..e151d87e8 100644 --- a/kittens/dnd/main.go +++ b/kittens/dnd/main.go @@ -222,6 +222,10 @@ func (dnd *dnd) run_loop() (err error) { dnd.send_test_response(strings.Join(dnd.drop_status.uri_list, "|")) case "DRAG_ACTIVE": dnd.send_test_response(utils.IfElse(dnd.drag_status.active, "DRAG_ACTIVE", "DRAG_INACTIVE")) + case "DRAG_OK": + dnd.send_test_response(utils.IfElse(dnd.drag_status.terminal_accepted_drag, "DRAG_OK", "DRAG_NOT_OK")) + case "DRAG_STATUS": + dnd.send_test_response(fmt.Sprintf("%s:%d:%v", dnd.drag_status.offered_mimes[dnd.drag_status.accepted_mime], dnd.drag_status.accepted_operation, dnd.drag_status.dropped)) default: dnd.send_test_response("UNKNOWN TEST COMMAND: " + string(cmd.Payload)) } @@ -249,7 +253,7 @@ func (dnd *dnd) run_loop() (err error) { case 'E': return dnd.on_drag_error(cmd) case 'e': - return dnd.on_drag_event(cmd.X, cmd.Y) + return dnd.on_drag_event(cmd.X, cmd.Y, cmd.Operation) } return nil } diff --git a/kitty/dnd.c b/kitty/dnd.c index f373016c8..fd0edd8b4 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -2125,10 +2125,6 @@ dnd_test_force_drag_dropped(PyObject *self UNUSED, PyObject *args) { if (!PyArg_ParseTuple(args, "K", &window_id)) return NULL; Window *w = window_for_window_id((id_type)window_id); if (!w) { PyErr_SetString(PyExc_ValueError, "Window not found"); return NULL; } - if (w->drag_source.state != DRAG_SOURCE_BEING_BUILT) { - PyErr_SetString(PyExc_ValueError, "Drag source state is not BEING_BUILT"); - return NULL; - } // Simulate what drag_start does on success, without calling start_window_drag for (size_t i = 0; i < w->drag_source.num_mimes; i++) { free(w->drag_source.items[i].optional_data); diff --git a/kitty_tests/dnd_kitten.py b/kitty_tests/dnd_kitten.py index 9e4e756e0..55d972347 100644 --- a/kitty_tests/dnd_kitten.py +++ b/kitty_tests/dnd_kitten.py @@ -22,8 +22,10 @@ dnd_test_cleanup_fake_window, dnd_test_create_fake_window, dnd_test_drag_finish, + dnd_test_drag_notify, dnd_test_fake_drop_data, dnd_test_fake_drop_event, + dnd_test_force_drag_dropped, dnd_test_probe_state, dnd_test_start_drag_offer, ) @@ -340,6 +342,9 @@ def dnd_kitten_drag(self, remote_client, img_drop_path): def wait_for_drag_active(active=True): self.send_dnd_command_to_kitten('DRAG_ACTIVE') self.wait_for_responses('DRAG_ACTIVE' if active else 'DRAG_INACTIVE') + if active: + self.send_dnd_command_to_kitten('DRAG_OK') + self.wait_for_responses('DRAG_OK') def start_drag(x, y, expected): dnd_test_start_drag_offer(self.capture.window_id, x, y) wait_for_drag_active() @@ -348,10 +353,16 @@ def end_drag(canceled=True): dnd_test_drag_finish(self.capture.window_id, canceled) wait_for_drag_active(False) self.wait_for_state('drag_operations', 0) - start_drag(1, 1, 3) + start_drag(move[0] + 1, move[1] + 1, 2) self.assertEqual(set(self.probe_state('drag_mimes')), {'image/png', 'text/uri-list'}) end_drag() start_drag(copy[0] + 1, copy[1] + 1, 1) end_drag() - start_drag(move[0] + 1, move[1] + 1, 2) - end_drag() + start_drag(1, 1, 3) + dnd_test_drag_notify(self.capture.window_id, 0, 'text/uri-list') + dnd_test_drag_notify(self.capture.window_id, 1, '', GLFW_DRAG_OPERATION_MOVE) + dnd_test_force_drag_dropped(self.capture.window_id) + dnd_test_drag_notify(self.capture.window_id, 2) + self.send_dnd_command_to_kitten('DRAG_STATUS') + self.wait_for_responses('text/uri-list:2:true') + end_drag(False)