Fix spurious drag start on initial click

This commit is contained in:
Kovid Goyal
2026-05-14 07:59:53 +05:30
parent 5064608879
commit bfc3646868

View File

@@ -193,7 +193,7 @@ set_currently_hovered_window(id_type window_id, int modifiers) {
if (sz > 0) { if (sz > 0) {
mouse_event_buf[sz] = 0; mouse_event_buf[sz] = 0;
write_escape_code_to_child(left_window->render_data.screen, ESC_CSI, mouse_event_buf); write_escape_code_to_child(left_window->render_data.screen, ESC_CSI, mouse_event_buf);
debug("Sent mouse leave event to window: %llu\n", left_window->id); debug("Sent mouse leave event to window: %llu currently hovering: %llu\n", left_window->id, window_id);
} }
} }
if (window_id && OPT(focus_follows_mouse).on_cross && global_state.callback_os_window && global_state.callback_os_window->num_tabs) { if (window_id && OPT(focus_follows_mouse).on_cross && global_state.callback_os_window && global_state.callback_os_window->num_tabs) {
@@ -867,7 +867,10 @@ HANDLER(handle_button_event) {
if (button == GLFW_MOUSE_BUTTON_LEFT && osw->suppress_left_mouse_release) { if (button == GLFW_MOUSE_BUTTON_LEFT && osw->suppress_left_mouse_release) {
osw->suppress_left_mouse_release = false; osw->suppress_left_mouse_release = false;
if (is_release) return; if (is_release) {
zero_at_ptr(&w->drag_source.initial_left_press);
return;
}
} }
if (handle_scrollbar_mouse(w, button, is_release ? RELEASE : PRESS, modifiers)) return; if (handle_scrollbar_mouse(w, button, is_release ? RELEASE : PRESS, modifiers)) return;
@@ -895,7 +898,7 @@ HANDLER(handle_button_event) {
zero_at_ptr(&w->drag_source.initial_left_press); zero_at_ptr(&w->drag_source.initial_left_press);
} else { } else {
w->drag_source.initial_left_press.x = w->mouse_pos.global_x; w->drag_source.initial_left_press.x = w->mouse_pos.global_x;
w->drag_source.initial_left_press.y = w->mouse_pos.global_x; w->drag_source.initial_left_press.y = w->mouse_pos.global_y;
w->drag_source.initial_left_press.at = monotonic(); w->drag_source.initial_left_press.at = monotonic();
} }
} }
@@ -958,8 +961,10 @@ handle_tab_bar_mouse(int button, int modifiers, int action) {
static bool static bool
mouse_in_region(Region *r) { mouse_in_region(Region *r) {
if (r->left == r->right) return false; if (r->left == r->right) return false;
if (global_state.callback_os_window->mouse_y < r->top || global_state.callback_os_window->mouse_y >= r->bottom) return false; OSWindow *w = global_state.callback_os_window;
if (global_state.callback_os_window->mouse_x < r->left || global_state.callback_os_window->mouse_x >= r->right) return false; if (!w) return false;
if (w->mouse_y < r->top || w->mouse_y >= r->bottom) return false;
if (w->mouse_x < r->left || w->mouse_x >= r->right) return false;
return true; return true;
} }
@@ -1319,7 +1324,9 @@ mouse_event(const int button, int modifiers, int action) {
} }
} else if (action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_LEFT) { } else if (action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_LEFT) {
w = window_for_id(global_state.tracked_drag_in_window); w = window_for_id(global_state.tracked_drag_in_window);
if (w && w->render_data.screen->modes.mouse_tracking_mode >= BUTTON_MODE && w->render_data.screen->modes.mouse_tracking_protocol >= SGR_PROTOCOL) { if (w) {
zero_at_ptr(&w->drag_source.initial_left_press);
if (w->render_data.screen->modes.mouse_tracking_mode >= BUTTON_MODE && w->render_data.screen->modes.mouse_tracking_protocol >= SGR_PROTOCOL) {
global_state.tracked_drag_in_window = 0; global_state.tracked_drag_in_window = 0;
clamp_to_window = true; clamp_to_window = true;
Tab *t = osw->tabs + osw->active_tab; Tab *t = osw->tabs + osw->active_tab;
@@ -1331,6 +1338,7 @@ mouse_event(const int button, int modifiers, int action) {
} }
} }
} }
}
if (global_state.active_drag_resize) { if (global_state.active_drag_resize) {
if (button < 0) { if (button < 0) {
call_boss(drag_resize_update, "dd", osw->mouse_x, osw->mouse_y); call_boss(drag_resize_update, "dd", osw->mouse_x, osw->mouse_y);