1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-29 04:45:57 -04:00

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
This commit is contained in:
Timo Sirainen 2001-10-20 10:35:42 +00:00 committed by cras
parent 113486564f
commit 69dccf4a67
3 changed files with 35 additions and 46 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;