diff --git a/kitty/mouse.c b/kitty/mouse.c index ef279f185..7fc8d1fd1 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -320,9 +320,19 @@ handle_tab_bar_mouse(int button, int UNUSED modifiers) { call_boss(activate_tab_at, "Kd", global_state.callback_os_window->id, global_state.callback_os_window->mouse_x); } +static inline bool +mouse_in_region(Region *r) { + 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; + if (global_state.callback_os_window->mouse_x < r->left || global_state.callback_os_window->mouse_x > r->right) return false; + return true; +} + static inline Window* window_for_event(unsigned int *window_idx, bool *in_tab_bar) { - *in_tab_bar = global_state.callback_os_window->num_tabs > 1 && global_state.callback_os_window->mouse_y >= global_state.callback_os_window->viewport_height - global_state.cell_height; + Region central, tab_bar; + os_window_regions(global_state.callback_os_window, ¢ral, &tab_bar); + *in_tab_bar = mouse_in_region(&tab_bar); if (!*in_tab_bar && global_state.callback_os_window->num_tabs > 0) { Tab *t = global_state.callback_os_window->tabs + global_state.callback_os_window->active_tab; for (unsigned int i = 0; i < t->num_windows; i++) { diff --git a/kitty/state.c b/kitty/state.c index 9c9255b50..b84593446 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -242,6 +242,21 @@ add_borders_rect(id_type os_window_id, id_type tab_id, uint32_t left, uint32_t t } +void +os_window_regions(OSWindow *os_window, Region *central, Region *tab_bar) { + if (os_window->num_tabs > 1) { + central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1; + central->bottom = os_window->viewport_height - global_state.cell_height - 1; + tab_bar->left = central->left; tab_bar->right = central->right; tab_bar->top = central->bottom + 1; + tab_bar->bottom = os_window->viewport_height - 1; + } else { + memset(tab_bar, 0, sizeof(Region)); + central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1; + central->bottom = os_window->viewport_height - 1; + } +} + + // Python API {{{ #define PYWRAP0(name) static PyObject* py##name(PyObject UNUSED *self) #define PYWRAP1(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args) diff --git a/kitty/state.h b/kitty/state.h index 6c93ca75f..8e196c899 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -160,6 +160,7 @@ void set_os_window_title(OSWindow *w, const char *title); OSWindow* os_window_for_kitty_window(id_type); OSWindow* add_os_window(); OSWindow* current_os_window(); +void os_window_regions(OSWindow*, Region *main, Region *tab_bar); bool drag_scroll(Window *, OSWindow*); void draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height); ssize_t create_cell_vao();