From dfbe1bd234ebbb9e72bdb86476023233c95d8c00 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 11 May 2021 10:22:30 +0530 Subject: [PATCH] Add debug prints for mouse events --- kitty/boss.py | 2 +- kitty/cli.py | 3 ++- kitty/keys.c | 2 +- kitty/mouse.c | 9 ++++++++- kitty/state.h | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index f976b34a4..ca0ae2cc9 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -746,7 +746,7 @@ class Boss: f = getattr(self, key_action.func, None) if f is not None: if self.args.debug_keyboard: - print(f'{dispatch_type} matched action:', func_name(f)) + print(f'{dispatch_type} matched action:', func_name(f), flush=True) passthrough = f(*key_action.args) if passthrough is not True: return True diff --git a/kitty/cli.py b/kitty/cli.py index 903b44fec..c67627800 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -690,7 +690,8 @@ instead of ignoring them. Also prints out miscellaneous debug information. Useful when debugging rendering problems ---debug-keyboard +--debug-input --debug-keyboard +dest=debug_keyboard type=bool-set This option will cause kitty to print out key events as they are received diff --git a/kitty/keys.c b/kitty/keys.c index a2a3810dc..1ef0eb89d 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -90,7 +90,7 @@ update_ime_position(OSWindow *os_window, Window* w, Screen *screen) { glfwUpdateIMEState(global_state.callback_os_window->handle, &ev); } -static inline const char* +const char* format_mods(unsigned mods) { static char buf[128]; char *p = buf, *s; diff --git a/kitty/mouse.c b/kitty/mouse.c index 271a688d9..120761914 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -19,6 +19,7 @@ extern PyTypeObject Screen_Type; static MouseShape mouse_cursor_shape = BEAM; typedef enum MouseActions { PRESS, RELEASE, DRAG, MOVE } MouseAction; +#define debug(...) if (OPT(debug_keyboard)) printf(__VA_ARGS__); // Encoding of mouse events {{{ #define SHIFT_INDICATOR (1 << 2) @@ -626,6 +627,7 @@ mouse_event(int button, int modifiers, int action) { bool in_tab_bar; unsigned int window_idx = 0; Window *w = NULL; + debug("%s mouse_button: %d %s", action == GLFW_RELEASE ? "\x1b[32mRelease\x1b[m" : "\x1b[31mPress\x1b[m", button, format_mods(modifiers)); if (global_state.active_drag_in_window) { if (button == -1) { // drag move w = window_for_id(global_state.active_drag_in_window); @@ -637,6 +639,7 @@ mouse_event(int button, int modifiers, int action) { for (window_idx = 0; window_idx < t->num_windows && t->windows[window_idx].id != w->id; window_idx++); handle_move_event(w, button, modifiers, window_idx); clamp_to_window = false; + debug("handled as drag move\n"); return; } } @@ -645,6 +648,7 @@ mouse_event(int button, int modifiers, int action) { w = window_for_id(global_state.active_drag_in_window); if (w) { end_drag(w); + debug("handled as drag end\n"); return; } } @@ -653,16 +657,19 @@ mouse_event(int button, int modifiers, int action) { if (in_tab_bar) { mouse_cursor_shape = HAND; handle_tab_bar_mouse(button, modifiers); + debug("handled by tab bar\n"); } else if (w) { + debug("grabbed: %d\n", w->render_data.screen->modes.mouse_tracking_mode != 0); handle_event(w, button, modifiers, window_idx); } else if (button == GLFW_MOUSE_BUTTON_LEFT && global_state.callback_os_window->mouse_button_pressed[button]) { // initial click, clamp it to the closest window w = closest_window_for_event(&window_idx); if (w) { clamp_to_window = true; + debug("grabbed: %d\n", w->render_data.screen->modes.mouse_tracking_mode != 0); handle_event(w, button, modifiers, window_idx); clamp_to_window = false; - } + } else debug("no window for event\n"); } if (mouse_cursor_shape != old_cursor) { set_mouse_cursor(mouse_cursor_shape); diff --git a/kitty/state.h b/kitty/state.h index d60de6f65..18c93e891 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -291,3 +291,4 @@ void fake_scroll(Window *w, int amount, bool upwards); Window* window_for_window_id(id_type kitty_window_id); void mouse_open_url(Window *w); void mouse_selection(Window *w, int code, int button); +const char* format_mods(unsigned mods);