Module: wine Branch: master Commit: a90017845d2f65ecd8c1bd32c3019bcd2b13ecd1 URL: https://source.winehq.org/git/wine.git/?a=commit;h=a90017845d2f65ecd8c1bd32c...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Oct 6 18:53:30 2020 +0200
conhost: Scroll window to cursor position when needed.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
programs/conhost/conhost.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index a54238c80f..7d3564a120 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -392,6 +392,24 @@ static void empty_update_rect( struct screen_buffer *screen_buffer, RECT *rect ) SetRect( rect, screen_buffer->width, screen_buffer->height, 0, 0 ); }
+static void scroll_to_cursor( struct screen_buffer *screen_buffer ) +{ + int w = screen_buffer->win.right - screen_buffer->win.left + 1; + int h = screen_buffer->win.bottom - screen_buffer->win.top + 1; + + if (screen_buffer->cursor_x < screen_buffer->win.left) + screen_buffer->win.left = min( screen_buffer->cursor_x, screen_buffer->width - w ); + else if (screen_buffer->cursor_x > screen_buffer->win.right) + screen_buffer->win.left = max( screen_buffer->cursor_x, w ) - w + 1; + screen_buffer->win.right = screen_buffer->win.left + w - 1; + + if (screen_buffer->cursor_y < screen_buffer->win.top) + screen_buffer->win.top = min( screen_buffer->cursor_y, screen_buffer->height - h ); + else if (screen_buffer->cursor_y > screen_buffer->win.bottom) + screen_buffer->win.top = max( screen_buffer->cursor_y, h ) - h + 1; + screen_buffer->win.bottom = screen_buffer->win.top + h - 1; +} + static void update_output( struct screen_buffer *screen_buffer, RECT *rect ) { int x, y, size, trailing_spaces; @@ -1237,6 +1255,7 @@ static void update_read_output( struct console *console ) if (console->is_unix) set_tty_cursor_relative( screen_buffer->console, update_rect.left, update_rect.top ); update_output( screen_buffer, &update_rect ); + scroll_to_cursor( screen_buffer ); } if (console->is_unix) set_tty_cursor_relative( screen_buffer->console, screen_buffer->cursor_x, screen_buffer->cursor_y ); @@ -1825,6 +1844,7 @@ static NTSTATUS set_output_info( struct screen_buffer *screen_buffer, { screen_buffer->cursor_x = info->cursor_x; screen_buffer->cursor_y = info->cursor_y; + scroll_to_cursor( screen_buffer ); } } if (params->mask & SET_CONSOLE_OUTPUT_INFO_SIZE) @@ -1972,6 +1992,7 @@ static NTSTATUS write_console( struct screen_buffer *screen_buffer, const WCHAR else screen_buffer->cursor_x = update_rect.left; }
+ scroll_to_cursor( screen_buffer ); update_output( screen_buffer, &update_rect ); tty_sync( screen_buffer->console ); return STATUS_SUCCESS;