mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05: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:
parent
113486564f
commit
69dccf4a67
@ -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;
|
||||
|
||||
for (;;) {
|
||||
sorted = mainwindows_get_sorted(TRUE);
|
||||
space = 0;
|
||||
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
rec = tmp->data;
|
||||
space += MAIN_WINDOW_TEXT_HEIGHT(rec)-WINDOW_MIN_SIZE;
|
||||
}
|
||||
|
||||
if (space < -ydiff) {
|
||||
/* not enough space, use different algorithm */
|
||||
mainwindows_resize_too_small(xdiff, ydiff);
|
||||
if (space >= -ydiff)
|
||||
break;
|
||||
|
||||
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) {
|
||||
|
@ -282,6 +282,13 @@ 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)
|
||||
wresize(window->win, height, width);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user