mcabber/src/screen.c
changeset 220 8dfdc6f1778e
parent 197 c289e3c39c48
child 232 9a6ba4b38e63
--- a/mcabber/src/screen.c	Tue May 31 16:56:49 2005 +0000
+++ b/mcabber/src/screen.c	Sat Jun 04 11:44:55 2005 +0000
@@ -391,12 +391,27 @@
     win_entry = scr_CreateBuddyPanel(winId, dont_show);
   }
 
+  // The message must be displayed -> update top pointer
+  if (win_entry->cleared)
+    win_entry->top = g_list_last(win_entry->hbuf);
+
   hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags,
                 maxX - ROSTER_WIDTH - PREFIX_WIDTH);
 
   if (win_entry->cleared) {
-    win_entry->cleared = 0; // The message must be displayed
-    win_entry->top = g_list_last(win_entry->hbuf);
+    win_entry->cleared = FALSE;
+    if (g_list_next(win_entry->top))
+      win_entry->top = g_list_next(win_entry->top);
+  }
+
+  // Make sure the last line appears in the window; update top if necessary
+  if (win_entry->top) {
+    int dist;
+    GList *first = g_list_first(win_entry->hbuf);
+    dist = g_list_position(first, g_list_last(win_entry->hbuf)) -
+           g_list_position(first, win_entry->top);
+    if (dist >= CHAT_WIN_HEIGHT)
+      win_entry->top = NULL;
   }
 
   if (!dont_show) {