Fix drag-scrolling not working when the mouse leaves the window confines

Fixes #917
This commit is contained in:
Kovid Goyal 2018-09-09 14:30:32 +05:30
parent a08b945124
commit 2ec84969dd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 26 additions and 19 deletions

View File

@ -17,6 +17,9 @@ Changelog
fullscreen/maximized/minimized. This replaces the ``--start-in-fullscreen``
flag introduced in the previous release (:iss:`935`)
- Fix drag-scrolling not working when the mouse leaves the window confines
(:iss:`917`)
- Linux: Ensure that the python embedded in the kitty binary build uses
UTF-8 mode to process command-line arguments (:iss:`924`)

View File

@ -281,7 +281,7 @@ void colorprofile_pop_dynamic_colors(ColorProfile*);
void set_mouse_cursor(MouseShape);
void enter_event();
void mouse_event(int, int);
void mouse_event(int, int, int);
void focus_in_event();
void wakeup_io_loop(bool);
void scroll_event(double, double, int);

View File

@ -157,9 +157,9 @@ mouse_button_callback(GLFWwindow *w, int button, int action, int mods) {
show_mouse_cursor(w);
double now = monotonic();
global_state.callback_os_window->last_mouse_activity_at = now;
if (button >= 0 && (unsigned int)button < sizeof(global_state.callback_os_window->mouse_button_pressed)/sizeof(global_state.callback_os_window->mouse_button_pressed[0])) {
if (button >= 0 && (unsigned int)button < arraysz(global_state.callback_os_window->mouse_button_pressed)) {
global_state.callback_os_window->mouse_button_pressed[button] = action == GLFW_PRESS ? true : false;
if (is_window_ready_for_callbacks()) mouse_event(button, mods);
if (is_window_ready_for_callbacks()) mouse_event(button, mods, action);
}
global_state.callback_os_window = NULL;
}
@ -173,7 +173,7 @@ cursor_pos_callback(GLFWwindow *w, double x, double y) {
global_state.callback_os_window->cursor_blink_zero_time = now;
global_state.callback_os_window->mouse_x = x * global_state.callback_os_window->viewport_x_ratio;
global_state.callback_os_window->mouse_y = y * global_state.callback_os_window->viewport_y_ratio;
if (is_window_ready_for_callbacks()) mouse_event(-1, 0);
if (is_window_ready_for_callbacks()) mouse_event(-1, 0, -1);
global_state.callback_os_window = NULL;
}

View File

@ -179,10 +179,7 @@ update_drag(bool from_button, Window *w, bool is_release, int modifiers) {
bool
drag_scroll(Window *w, OSWindow *frame) {
unsigned int margin = frame->fonts_data->cell_height / 2;
double left = window_left(w, frame), top = window_top(w, frame), right = window_right(w, frame), bottom = window_bottom(w, frame);
double x = frame->mouse_x, y = frame->mouse_y;
if (y < top || y > bottom) return false;
if (x < left || x > right) return false;
double y = frame->mouse_y;
bool upwards = y <= (w->geometry.top + margin);
if (upwards || y >= w->geometry.bottom - margin) {
Screen *screen = w->render_data.screen;
@ -488,23 +485,30 @@ enter_event() {
}
void
mouse_event(int button, int modifiers) {
mouse_event(int button, int modifiers, int action) {
MouseShape old_cursor = mouse_cursor_shape;
bool in_tab_bar;
unsigned int window_idx = 0;
Window *w = NULL;
if (button == -1 && global_state.active_drag_in_window) { // drag move
w = window_for_id(global_state.active_drag_in_window);
if (w) {
button = currently_pressed_button();
if (button == GLFW_MOUSE_BUTTON_LEFT) {
clamp_to_window = true;
handle_move_event(w, button, modifiers, window_idx);
clamp_to_window = false;
return;
if (global_state.active_drag_in_window) {
if (button == -1) { // drag move
w = window_for_id(global_state.active_drag_in_window);
if (w) {
button = currently_pressed_button();
if (button == GLFW_MOUSE_BUTTON_LEFT) {
clamp_to_window = true;
handle_move_event(w, button, modifiers, window_idx);
clamp_to_window = false;
return;
}
}
}
else if (action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_LEFT) {
w = window_for_id(global_state.active_drag_in_window);
if (w) {
update_drag(true, w, true, modifiers);
}
}
}
w = window_for_event(&window_idx, &in_tab_bar);
if (in_tab_bar) {