From 9ae198ef8f314901187825c801021e3a6eeff413 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 Jan 2021 11:45:18 +0530 Subject: [PATCH] Double clicking on empty tab bar area now opens a new tab Fixes #3201 --- docs/changelog.rst | 2 ++ kitty/boss.py | 4 ++-- kitty/mouse.c | 6 +++++- kitty/tabs.py | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index dcb35c01f..540d4d259 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,8 @@ To update |kitty|, :doc:`follow the instructions `. run. The system-wide PATH is used first, then system specific default paths, and finally the PATH inside the shell. +- Double clicking on empty tab bar area now opens a new tab (:iss:`3201`) + 0.19.3 [2020-12-19] ------------------- diff --git a/kitty/boss.py b/kitty/boss.py index 4119575ed..1b907ce65 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -520,10 +520,10 @@ class Boss: run_update_check(self.opts.update_check_interval * 60 * 60) self.update_check_started = True - def activate_tab_at(self, os_window_id: int, x: int) -> int: + def activate_tab_at(self, os_window_id: int, x: int, is_double: bool = False) -> int: tm = self.os_window_map.get(os_window_id) if tm is not None: - tm.activate_tab_at(x) + tm.activate_tab_at(x, is_double) def on_window_resize(self, os_window_id: int, w: int, h: int, dpi_changed: bool) -> None: if dpi_changed: diff --git a/kitty/mouse.c b/kitty/mouse.c index 73cfc2232..628ce1713 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -516,8 +516,12 @@ HANDLER(handle_event) { static inline void handle_tab_bar_mouse(int button, int UNUSED modifiers) { + static monotonic_t last_click_at = 0; if (button != GLFW_MOUSE_BUTTON_LEFT || !global_state.callback_os_window->mouse_button_pressed[button]) return; - call_boss(activate_tab_at, "Kd", global_state.callback_os_window->id, global_state.callback_os_window->mouse_x); + monotonic_t now = monotonic(); + bool is_double = now - last_click_at <= OPT(click_interval); + last_click_at = is_double ? 0 : now; + call_boss(activate_tab_at, "KdO", global_state.callback_os_window->id, global_state.callback_os_window->mouse_x, is_double ? Py_True : Py_False); } static inline bool diff --git a/kitty/tabs.py b/kitty/tabs.py index 2e73bbfa7..98db16f0d 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -753,9 +753,12 @@ class TabManager: # {{{ )) return ans - def activate_tab_at(self, x: int) -> None: + def activate_tab_at(self, x: int, is_double: bool = False) -> None: i = self.tab_bar.tab_at(x) - if i is not None: + if i is None: + if is_double: + self.new_tab() + else: self.set_active_tab_idx(i) @property