From d70ec000ff9d713210be4ec03c111e974a1a77df Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 30 Apr 2026 15:06:22 +0530 Subject: [PATCH] Start work on drag source implementation --- kittens/dnd/drag.go | 11 +++++++++++ kittens/dnd/drop.go | 4 ++-- kittens/dnd/main.go | 15 +-------------- kittens/dnd/render.go | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 kittens/dnd/drag.go diff --git a/kittens/dnd/drag.go b/kittens/dnd/drag.go new file mode 100644 index 000000000..2887e94c2 --- /dev/null +++ b/kittens/dnd/drag.go @@ -0,0 +1,11 @@ +package dnd + +import ( + "fmt" +) + +var _ = fmt.Print + +type drag_status struct { + active bool +} diff --git a/kittens/dnd/drop.go b/kittens/dnd/drop.go index f1412f5dd..59f84fe3a 100644 --- a/kittens/dnd/drop.go +++ b/kittens/dnd/drop.go @@ -607,7 +607,7 @@ func (dnd *dnd) on_drop_move(cell_x, cell_y int, has_more bool, offered_mimes st } } dnd.drop_status.in_window = cell_x > -1 && cell_y > -1 - if !dnd.drop_status.in_window || dnd.drag_started { // disallow self drag and drop + if !dnd.drop_status.in_window || dnd.drag_status.active { // disallow self drag and drop dnd.reset_drop() } mimes_changed := !slices.Equal(prev_status.accepted_mimes, dnd.drop_status.accepted_mimes) @@ -622,7 +622,7 @@ func (dnd *dnd) on_drop_move(cell_x, cell_y int, has_more bool, offered_mimes st needs_rerender = needs_rerender || dnd.drop_status.in_window != prev_status.in_window if is_drop { needs_rerender = true - if dnd.drop_status.action == 0 || len(dnd.drop_status.accepted_mimes) == 0 || dnd.drag_started { + if dnd.drop_status.action == 0 || len(dnd.drop_status.accepted_mimes) == 0 || dnd.drag_status.active { dnd.end_drop(false) return } diff --git a/kittens/dnd/main.go b/kittens/dnd/main.go index 0f12cccb9..b68d98c7f 100644 --- a/kittens/dnd/main.go +++ b/kittens/dnd/main.go @@ -86,7 +86,7 @@ type dnd struct { tdir_counter int is_case_sensitive_filesystem bool data_has_been_dropped bool - drag_started bool + drag_status drag_status in_test_mode bool copy_button_region, move_button_region button_region confirm_drop struct { @@ -183,19 +183,6 @@ func (dnd *dnd) run_loop() (err error) { } dnd.lp.OnDnDData = func(cmd loop.DndCommand) error { - // TODO: Use lp.QueueDnDData to implement drag and drop protocol - // If allow_drags, start a drag when the terminal sends the t=o - // event. Presend data for any drag_source objects that have non nil - // data fields and whose data size is <= 1MB. Set drag_started to true. - // reset drag_started at the end of the drag. Use opts.DragAction to - // set what actions are allowed. - - // When acting as a drag source, dont forget to implement support for - // remote dragging, which means providing data for the text/uri-list - // mime type file:// entries when the terminal requests it using the - // dnd protocol. If the action chosen is move, delete the files - // corresponding to the drag sources, including the files in the - // uri-list and exit. switch cmd.Type { case 'T': switch string(cmd.Payload) { diff --git a/kittens/dnd/render.go b/kittens/dnd/render.go index 2bb3f15cb..7644a4522 100644 --- a/kittens/dnd/render.go +++ b/kittens/dnd/render.go @@ -48,7 +48,7 @@ func (dnd *dnd) render_screen() error { } lp.ClearScreen() dnd.copy_button_region, dnd.move_button_region = button_region{}, button_region{} - if dnd.drag_started { + if dnd.drag_status.active { lp.Println("Dragging data...") return nil }