From a3465d99988c3b59efaca9e7cc33fa062dd79c2b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Aug 2025 17:30:30 +0530 Subject: [PATCH] The OS Window regions should have right/bottom edges not inclusive Currently it was a bit ambiguous some places assuming inclusive some not. Also there seemed to be one left over pixel at the bottom/right edges of the calculated regions compared to viewport size.This fixes that. Hopefully doesnt break anything else, we will see. --- kitty/data-types.h | 1 + kitty/mouse.c | 8 ++++---- kitty/state.c | 17 +++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index d1c9e7a3b..da05ae8bf 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -196,6 +196,7 @@ typedef struct ImageAnchorPosition { typedef enum UTF8State { UTF8_ACCEPT = 0, UTF8_REJECT = 1} UTF8State; typedef struct { + // right = left + width, bottom = top + height uint32_t left, top, right, bottom; } Region; diff --git a/kitty/mouse.c b/kitty/mouse.c index 790aa5d87..cbe6a5919 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -235,7 +235,7 @@ window_bottom(Window *w) { static bool contains_mouse(Window *w) { double x = global_state.callback_os_window->mouse_x, y = global_state.callback_os_window->mouse_y; - return (w->visible && window_left(w) <= x && x <= window_right(w) && window_top(w) <= y && y <= window_bottom(w)); + return (w->visible && window_left(w) <= x && x < window_right(w) && window_top(w) <= y && y < window_bottom(w)); } static double @@ -645,8 +645,8 @@ handle_tab_bar_mouse(int button, int modifiers, int action) { static 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; + 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; } @@ -659,7 +659,7 @@ window_for_event(unsigned int *window_idx, bool *in_tab_bar) { const OSWindow* w = global_state.callback_os_window; if (!in_central) { if ( - (tab_bar.top < central.top && w->mouse_y <= central.top) || + (tab_bar.top < central.top && w->mouse_y < central.top) || (tab_bar.bottom > central.bottom && w->mouse_y >= central.bottom) ) *in_tab_bar = true; } diff --git a/kitty/state.c b/kitty/state.c index 32622cbc8..da9d71993 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -595,27 +595,28 @@ os_window_regions(OSWindow *os_window, Region *central, Region *tab_bar) { if (!OPT(tab_bar_hidden) && os_window->num_tabs >= OPT(tab_bar_min_tabs)) { long margin_outer = pt_to_px_for_os_window(OPT(tab_bar_margin_height.outer), os_window); long margin_inner = pt_to_px_for_os_window(OPT(tab_bar_margin_height.inner), os_window); + central->left = 0; central->right = os_window->viewport_width; + unsigned tab_bar_height = os_window->fonts_data->fcm.cell_height + margin_inner + margin_outer; switch(OPT(tab_bar_edge)) { case TOP_EDGE: - central->left = 0; central->right = os_window->viewport_width - 1; - central->top = os_window->fonts_data->fcm.cell_height + margin_inner + margin_outer - 1; - central->bottom = os_window->viewport_height - 1; + central->top = tab_bar_height; + central->bottom = os_window->viewport_height; central->top = MIN(central->top, central->bottom); tab_bar->top = margin_outer; break; default: - central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1; - long bottom = os_window->viewport_height - os_window->fonts_data->fcm.cell_height - 1 - margin_inner - margin_outer; + central->top = 0; + long bottom = os_window->viewport_height - tab_bar_height; central->bottom = MAX(0, bottom); tab_bar->top = central->bottom + 1 + margin_inner; break; } tab_bar->left = central->left; tab_bar->right = central->right; - tab_bar->bottom = tab_bar->top + os_window->fonts_data->fcm.cell_height - 1; + tab_bar->bottom = tab_bar->top + tab_bar_height; } else { zero_at_ptr(tab_bar); - central->left = 0; central->top = 0; central->right = os_window->viewport_width - 1; - central->bottom = os_window->viewport_height - 1; + central->left = 0; central->top = 0; central->right = os_window->viewport_width; + central->bottom = os_window->viewport_height; } }