From 27ad4bc070c8b1e6e70a7e51b8ce05b1b8f60c91 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Mar 2026 15:23:27 +0530 Subject: [PATCH] Fix some more misc bugs in the DnD code --- kitty/glfw.c | 5 ++++- tools/cmd/mouse_demo/main.go | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index f7baa4efd..99beb9b92 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -794,6 +794,7 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) { case GLFW_DROP_ENTER: case GLFW_DROP_MOVE: global_state.drop_dest.drop_has_happened = false; + global_state.drop_dest.os_window_id = os_window->id; os_window->last_drag_event.x = (int)(ev->xpos * os_window->viewport_x_ratio); os_window->last_drag_event.y = (int)(ev->ypos * os_window->viewport_y_ratio); on_mouse_position_update(ev->xpos, ev->ypos); @@ -826,6 +827,7 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) { Py_CLEAR(global_state.drop_dest.data); global_state.drop_dest.drop_has_happened = true; global_state.drop_dest.client_window_data_request = 0; + global_state.drop_dest.os_window_id = os_window->id; if (is_kitty_ui_drag) { if (ev->from_self) { if (global_state.drag_source.drag_data) { @@ -864,8 +866,9 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) { void request_drop_status_update(OSWindow *osw) { - if (osw && osw->handle && !global_state.drop_dest.drop_has_happened && global_state.drop_dest.os_window_id == osw->id) + if (osw && osw->handle && !global_state.drop_dest.drop_has_happened && global_state.drop_dest.os_window_id == osw->id) { glfwRequestDropUpdate(osw->handle); + } } static void diff --git a/tools/cmd/mouse_demo/main.go b/tools/cmd/mouse_demo/main.go index acced44b7..a12aad226 100644 --- a/tools/cmd/mouse_demo/main.go +++ b/tools/cmd/mouse_demo/main.go @@ -11,10 +11,12 @@ import ( "strings" kitty "github.com/kovidgoyal/kitty" + "github.com/kovidgoyal/kitty/tools/tty" "github.com/kovidgoyal/kitty/tools/tui/loop" ) var _ = fmt.Print +var debugprintln = tty.DebugPrintln const dnd_accepted_mimes = "text/plain text/uri-list" @@ -301,15 +303,12 @@ func Run(args []string) (rc int, err error) { mimes := strings.Fields(payload) dnd.drop_mimes = mimes // Request data for text/plain first, then text/uri-list - if slices.Contains(mimes, "text/plain") { - dnd.collecting = "text/plain" - lp.QueueWriteString(dnd_request_data("text/plain")) - return nil - } - if slices.Contains(mimes, "text/uri-list") { - dnd.collecting = "text/uri-list" - lp.QueueWriteString(dnd_request_data("text/uri-list")) - return nil + for _, x := range []string{"text/plain", "text/uri-list"} { + if slices.Contains(mimes, x) { + dnd.collecting = x + lp.QueueWriteString(dnd_request_data(x)) + return nil + } } // Nothing to collect, signal done lp.QueueWriteString(dnd_finish())