Drop events should use same co-ordinate system as mouse events

This commit is contained in:
Kovid Goyal 2026-02-13 10:08:25 +05:30
parent c4c31c3bc1
commit a99103d9a1
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 7 additions and 16 deletions

View file

@ -1611,9 +1611,6 @@ update_drop_state(_GLFWwindow *window, size_t mime_count) {
const NSPoint pos = [sender draggingLocation];
double xpos = pos.x;
double ypos = contentRect.size.height - pos.y;
float xscale = 1, yscale = 1;
_glfwPlatformGetWindowContentScale(window, &xscale, &yscale);
xpos *= xscale; ypos *= yscale;
free_drop_data(window);
// Get MIME types from the dragging pasteboard
@ -1685,9 +1682,6 @@ update_drop_state(_GLFWwindow *window, size_t mime_count) {
const NSPoint pos = [sender draggingLocation];
double xpos = pos.x;
double ypos = contentRect.size.height - pos.y;
float xscale = 1, yscale = 1;
_glfwPlatformGetWindowContentScale(window, &xscale, &yscale);
xpos *= xscale; ypos *= yscale;
bool from_self = ([sender draggingSource] != nil);
_GLFWDropData *d = &window->ns.drop_data;
@ -1712,9 +1706,6 @@ update_drop_state(_GLFWwindow *window, size_t mime_count) {
const NSPoint pos = [sender draggingLocation];
double xpos = pos.x;
double ypos = contentRect.size.height - pos.y;
float xscale = 1, yscale = 1;
_glfwPlatformGetWindowContentScale(window, &xscale, &yscale);
xpos *= xscale; ypos *= yscale;
bool from_self = ([sender draggingSource] != nil);
_GLFWDropData *d = &window->ns.drop_data;
size_t mime_count = _glfwInputDropEvent(window, GLFW_DROP_DROP, xpos, ypos, d->mimes, d->mimes_count, from_self);

4
glfw/glfw3.h vendored
View file

@ -1403,7 +1403,9 @@ typedef enum {
typedef struct GLFWDropEvent {
GLFWDropEventType type;
const char **mimes; size_t num_mimes;
double xpos, ypos; // Only valid for GLFW_DROP_ENTER and GLFW_DROP_MOVE
// Positions are only valid for GLFW_DROP_ENTER and GLFW_DROP_MOVE.
// They are in window co-ordinates same as for mouse events
double xpos, ypos;
bool from_self; // Only valid upto GLFW_DROP_DROP
ssize_t (*read_data)(GLFWwindow *w, struct GLFWDropEvent* ev, char *buffer, size_t sz); // Only valid for GLFW_DROP_DATA_AVAILABLE
void (*finish_drop)(GLFWwindow *w, GLFWDragOperationType op); // Only valid for GLFW_DROP_DROP and GLFW_DROP_DATA_AVAILABLE

6
glfw/wl_window.c vendored
View file

@ -2493,9 +2493,8 @@ drag_enter(void *data UNUSED, struct wl_data_device *wl_data_device UNUSED, uint
if (window->wl.surface == surface) {
double xpos = wl_fixed_to_double(x);
double ypos = wl_fixed_to_double(y);
double scale = _glfwWaylandWindowScale(window);
size_t mime_count = _glfwInputDropEvent(
window, GLFW_DROP_ENTER, scale * xpos, scale * ypos,
window, GLFW_DROP_ENTER, xpos, ypos,
offer->mimes, offer->mimes_count, offer->is_self_offer);
update_drop_state(offer, window, mime_count);
break;
@ -2633,9 +2632,8 @@ motion(void *data UNUSED, struct wl_data_device *wl_data_device UNUSED, uint32_t
if (window->wl.surface == offer->surface) {
double xpos = wl_fixed_to_double(x);
double ypos = wl_fixed_to_double(y);
double scale = _glfwWaylandWindowScale(window);
size_t mime_count = _glfwInputDropEvent(
window, GLFW_DROP_MOVE, scale * xpos, scale * ypos, offer->mimes, offer->mimes_count, offer->is_self_offer);
window, GLFW_DROP_MOVE, xpos, ypos, offer->mimes, offer->mimes_count, offer->is_self_offer);
update_drop_state(offer, window, mime_count);
break;
}

View file

@ -720,8 +720,8 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) {
switch (ev->type) {
case GLFW_DROP_ENTER:
case GLFW_DROP_MOVE:
global_state.callback_os_window->last_drag_event.x = (int)ev->xpos;
global_state.callback_os_window->last_drag_event.y = (int)ev->ypos;
global_state.callback_os_window->last_drag_event.x = (int)(ev->xpos * global_state.callback_os_window->viewport_x_ratio);
global_state.callback_os_window->last_drag_event.y = (int)(ev->ypos * global_state.callback_os_window->viewport_y_ratio);
/* fallthrough */
case GLFW_DROP_STATUS_UPDATE:
update_allowed_mimes_for_drop(ev);