From 69dccf4a676c8dba9be01787fa478b3b9178f6b5 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 20 Oct 2001 10:35:42 +0000 Subject: When resizing terminal smaller, destroy some split windows if they don't fit into screen otherwise. Also, irssi doesn't crash anymore or mess up the screen even if terminal is resized to 1x1 size (not sure of 0x0, my terminal doesn't resize that small, and maybe I shouldn't bother with it anyway :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1855 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-text/mainwindows.c | 68 ++++++++++++++++--------------------------- src/fe-text/screen.c | 9 +++++- src/fe-text/textbuffer-view.c | 4 +-- 3 files changed, 35 insertions(+), 46 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/mainwindows.c b/src/fe-text/mainwindows.c index 603f6226..b2f84217 100644 --- a/src/fe-text/mainwindows.c +++ b/src/fe-text/mainwindows.c @@ -93,7 +93,7 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff) window->width += xdiff; window->height = window->last_line-window->first_line+1; - mainwindow_set_screen_size(window); + mainwindow_set_screen_size(window); mainwindow_resize_windows(window); textbuffer_view_set_window(WINDOW_GUI(window->active)->view, @@ -337,59 +337,41 @@ GSList *mainwindows_get_sorted(int reverse) return list; } -static void mainwindows_resize_too_small(int xdiff, int ydiff) -{ - GSList *sorted, *tmp; - int space, moved; - - /* terminal is too small - just take the space whereever possible */ - sorted = mainwindows_get_sorted(FALSE); - moved = 0; - for (tmp = sorted; tmp != NULL; tmp = tmp->next) { - MAIN_WINDOW_REC *rec = tmp->data; - - space = rec->height; - if (ydiff == 0 || space <= 0) { - if (moved > 0) { - rec->first_line -= moved; - rec->last_line -= moved; - signal_emit("mainwindow moved", 1, rec); - } - continue; - } - - if (space > -ydiff) space = -ydiff; - ydiff += space; - rec->first_line -= moved; - moved += space; - rec->last_line -= space; - mainwindow_resize(rec, xdiff, -space); - } - g_slist_free(sorted); -} - static void mainwindows_resize_smaller(int xdiff, int ydiff) { + MAIN_WINDOW_REC *rec; GSList *sorted, *tmp; int space; - space = 0; - for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { - MAIN_WINDOW_REC *rec = tmp->data; + for (;;) { + sorted = mainwindows_get_sorted(TRUE); + space = 0; + for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) { + rec = tmp->data; + space += MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE; + } - space += MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE; - } + if (space >= -ydiff) + break; - if (space < -ydiff) { - /* not enough space, use different algorithm */ - mainwindows_resize_too_small(xdiff, ydiff); - return; + rec = sorted->data; + sorted = g_slist_remove(sorted, rec); + + if (sorted != NULL) { + /* terminal is too small - destroy the + uppest window and try again */ + mainwindow_destroy(rec); + } else { + /* only one window in screen.. just force the resize */ + rec->last_line += ydiff; + mainwindow_resize(rec, xdiff, ydiff); + return; + } } /* resize windows that have space */ - sorted = mainwindows_get_sorted(TRUE); for (tmp = sorted; tmp != NULL && ydiff < 0; tmp = tmp->next) { - MAIN_WINDOW_REC *rec = tmp->data; + rec = tmp->data; space = MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE; if (space <= 0) { diff --git a/src/fe-text/screen.c b/src/fe-text/screen.c index f04fd905..dff77c64 100644 --- a/src/fe-text/screen.c +++ b/src/fe-text/screen.c @@ -282,8 +282,15 @@ void screen_window_clear(SCREEN_WINDOW *window) void screen_window_move(SCREEN_WINDOW *window, int x, int y, int width, int height) { + /* some checks to make sure the window is visible in screen, + otherwise curses could get nasty and not show our window anymore. */ + if (width < 1) width = 1; + if (height < 1) height = 1; + if (x+width > screen_width) x = screen_width-width; + if (y+height > screen_height) y = screen_height-height; + #ifdef HAVE_CURSES_WRESIZE - if (window->width != width || window->height != height) + if (window->width != width || window->height != height) wresize(window->win, height, width); if (window->x != x || window->y != y) mvwin(window->win, y, x); diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index 1ae85fbf..12191f05 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -601,8 +601,8 @@ void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height) view->cache = textbuffer_cache_get(view->siblings, width); } - view->width = width; - view->height = height; + view->width = width > 10 ? width : 10; + view->height = height > 1 ? height : 1; if (view->buffer->first_line == NULL) { view->empty_linecount = height; -- cgit v1.2.3