From 046eb86091820c66137dc6a763e53d7f0a7be573 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 May 2023 15:40:41 +0530 Subject: [PATCH] Only move graphics on resize if the actual num of content lines chages Avoids spurious moves when the window is not full and therefore text does not move on vertical resize --- kitty/graphics.c | 6 +++--- kitty/graphics.h | 2 +- kitty/screen.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kitty/graphics.c b/kitty/graphics.c index 542ae6413..3fe289b8e 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -1791,11 +1791,11 @@ handle_delete_command(GraphicsManager *self, const GraphicsCommand *g, Cursor *c // }}} void -grman_resize(GraphicsManager *self, index_type old_lines, index_type lines, index_type old_columns, index_type columns) { +grman_resize(GraphicsManager *self, index_type old_lines UNUSED, index_type lines UNUSED, index_type old_columns, index_type columns, index_type num_content_lines_before, index_type num_content_lines_after) { ImageRef *ref; Image *img; self->layers_dirty = true; - if (columns == old_columns && old_lines > lines) { - const unsigned int vertical_shrink_size = old_lines - lines; + if (columns == old_columns && num_content_lines_before > num_content_lines_after) { + const unsigned int vertical_shrink_size = num_content_lines_before - num_content_lines_after; for (size_t i = self->image_count; i-- > 0;) { img = self->images + i; for (size_t j = img->refcnt; j-- > 0;) { diff --git a/kitty/graphics.h b/kitty/graphics.h index 9b4efca9a..448dfe923 100644 --- a/kitty/graphics.h +++ b/kitty/graphics.h @@ -164,7 +164,7 @@ const char* grman_handle_command(GraphicsManager *self, const GraphicsCommand *g Image* grman_put_cell_image(GraphicsManager *self, uint32_t row, uint32_t col, uint32_t image_id, uint32_t placement_id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, CellPixelSize cell); bool grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float screen_left, float screen_top, float dx, float dy, unsigned int num_cols, unsigned int num_rows, CellPixelSize); void grman_scroll_images(GraphicsManager *self, const ScrollData*, CellPixelSize fg); -void grman_resize(GraphicsManager*, index_type, index_type, index_type, index_type); +void grman_resize(GraphicsManager*, index_type, index_type, index_type, index_type, index_type, index_type); void grman_rescale(GraphicsManager *self, CellPixelSize fg); void grman_remove_cell_images(GraphicsManager *self, int32_t top, int32_t bottom); void grman_remove_all_cell_images(GraphicsManager *self); diff --git a/kitty/screen.c b/kitty/screen.c index 65aa88179..ffa0e9f94 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -389,7 +389,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { /* printf("old_cursor: (%u, %u) new_cursor: (%u, %u) beyond_content: %d\n", self->cursor->x, self->cursor->y, cursor.after.x, cursor.after.y, cursor.is_beyond_content); */ setup_cursor(main_saved_cursor); grman_remove_all_cell_images(self->main_grman); - grman_resize(self->main_grman, self->lines, lines, self->columns, columns); + grman_resize(self->main_grman, self->lines, lines, self->columns, columns, num_content_lines_before, num_content_lines_after); // Resize alt linebuf n = realloc_lb(self->alt_linebuf, lines, columns, &num_content_lines_before, &num_content_lines_after, NULL, &cursor, &alt_saved_cursor, &self->as_ansi_buf); @@ -398,7 +398,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { if (!is_main) setup_cursor(cursor); setup_cursor(alt_saved_cursor); grman_remove_all_cell_images(self->alt_grman); - grman_resize(self->alt_grman, self->lines, lines, self->columns, columns); + grman_resize(self->alt_grman, self->lines, lines, self->columns, columns, num_content_lines_before, num_content_lines_after); #undef setup_cursor self->linebuf = is_main ? self->main_linebuf : self->alt_linebuf;