From 11badac95db3677b5224932847e5c656c9b1ef8b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 5 Dec 2021 18:26:25 +0530 Subject: [PATCH] Ensure cell start position is clamped to a pixel --- kitty/graphics.h | 12 ++++++++++++ kitty/state.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kitty/graphics.h b/kitty/graphics.h index daad0bb45..760f8f272 100644 --- a/kitty/graphics.h +++ b/kitty/graphics.h @@ -138,6 +138,18 @@ clamp_position_to_nearest_pixel(float pos, const unsigned int viewport_size) { return -1.f + num_of_pixels * px; } +static inline float +gl_pos_x(const unsigned int px_from_left_margin, const unsigned int viewport_size) { + const float px = 2.f / viewport_size; + return -1.f + px_from_left_margin * px; +} + +static inline float +gl_pos_y(const unsigned int px_from_top_margin, const unsigned int viewport_size) { + const float px = 2.f / viewport_size; + return 1.f - px_from_top_margin * px; +} + GraphicsManager* grman_alloc(void); void grman_clear(GraphicsManager*, bool, CellPixelSize fg); diff --git a/kitty/state.c b/kitty/state.c index 57ff6e3cd..0b50c83c2 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -709,8 +709,8 @@ static void init_screen_render_data(OSWindow *osw, const WindowGeometry *g, ScreenRenderData *d) { d->dx = gl_size(osw->fonts_data->cell_width, osw->viewport_width); d->dy = gl_size(osw->fonts_data->cell_height, osw->viewport_height); - d->xstart = -1.f + gl_size(g->left, osw->viewport_width); - d->ystart = 1.f - gl_size(g->top, osw->viewport_height); + d->xstart = gl_pos_x(g->left, osw->viewport_width); + d->ystart = gl_pos_y(g->top, osw->viewport_height); } PYWRAP1(set_tab_bar_render_data) {