changeset 1961:39021fd6b0e1

Try to improve readmarks in some cases This patch removes the readmark when entering chatmode if the mark is on the last line. This should hopefully fix weird behavior seen under some circumstances.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 15 Mar 2011 00:39:17 +0100
parents b596bcff758e
children d41623dd88ee
files mcabber/mcabber/hbuf.c mcabber/mcabber/hbuf.h mcabber/mcabber/screen.c mcabber/mcabber/screen.h
diffstat 4 files changed, 35 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/hbuf.c	Mon Mar 14 23:45:24 2011 +0100
+++ b/mcabber/mcabber/hbuf.c	Tue Mar 15 00:39:17 2011 +0100
@@ -554,6 +554,19 @@
   }
 }
 
+//  hbuf_remove_trailing_readmark(hbuf)
+// Unset the buffer readmark if it is on the last line
+void hbuf_remove_trailing_readmark(GList *hbuf)
+{
+  hbuf_block *blk;
+
+  if (!hbuf) return;
+
+  hbuf = g_list_last(hbuf);
+  blk = (hbuf_block*)(hbuf->data);
+  blk->prefix.flags &= ~HBB_PREFIX_READMARK;
+}
+
 //  hbuf_get_blocks_number()
 // Returns the number of allocated hbuf_block's.
 guint hbuf_get_blocks_number(GList *hbuf)
--- a/mcabber/mcabber/hbuf.h	Mon Mar 14 23:45:24 2011 +0100
+++ b/mcabber/mcabber/hbuf.h	Tue Mar 15 00:39:17 2011 +0100
@@ -52,6 +52,7 @@
 GList *hbuf_jump_readmark(GList *hbuf);
 gboolean hbuf_remove_receipt(GList *hbuf, gpointer xep184);
 void hbuf_set_readmark(GList *hbuf, gboolean action);
+void hbuf_remove_trailing_readmark(GList *hbuf);
 
 void hbuf_dump_to_file(GList *hbuf, const char *filename);
 
--- a/mcabber/mcabber/screen.c	Mon Mar 14 23:45:24 2011 +0100
+++ b/mcabber/mcabber/screen.c	Tue Mar 15 00:39:17 2011 +0100
@@ -1482,7 +1482,7 @@
     if (win_entry->bd->lock)
       setmsgflg = TRUE;
     else
-      // If this is an outgoing message, update readmark
+      // If this is an outgoing message, remove the readmark
       if (!special && (prefix_flags & (HBB_PREFIX_OUT|HBB_PREFIX_HLIGHT_OUT)))
         hbuf_set_readmark(win_entry->bd->hbuf, FALSE);
     // Show and refresh the window
@@ -2395,8 +2395,11 @@
   }
   current_buddy = newbuddy;
   // Lock the buddy in the buddylist if we're in chat mode
-  if (chatmode)
+  if (chatmode) {
     buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+    // Remove the readmark if it is at the end of the buffer
+    scr_buffer_readmark(-1);
+  }
   // We should rebuild the buddylist but not everytime
   if (!(buddylist_get_filter() & 1<<prev_st))
     buddylist_build();
@@ -2816,7 +2819,12 @@
   update_panels();
 }
 
-void scr_buffer_readmark(gboolean action)
+//  scr_buffer_readmark(action)
+// Update the readmark flag for the current buffer
+// If action = 1, set the readmark flag on the last message
+// If action = 0, reset the readmark flag
+// If action = -1, remove the readmark flag iff it is on the last line
+void scr_buffer_readmark(gchar action)
 {
   winbuf *win_entry;
   guint isspe;
@@ -2828,8 +2836,12 @@
   win_entry = scr_search_window(CURRENT_JID, isspe);
   if (!win_entry) return;
 
-  if (!win_entry->bd->lock)
-    hbuf_set_readmark(win_entry->bd->hbuf, action);
+  if (!win_entry->bd->lock) {
+    if (action >= 0)
+      hbuf_set_readmark(win_entry->bd->hbuf, action);
+    else
+      hbuf_remove_trailing_readmark(win_entry->bd->hbuf);
+  }
 }
 
 
@@ -3037,8 +3049,11 @@
 // Public function to (un)set chatmode...
 inline void scr_set_chatmode(int enable)
 {
+  gboolean enter_chatmode = enable && chatmode == FALSE;
   chatmode = enable;
   scr_update_chat_status(TRUE);
+  if (enter_chatmode)
+    scr_buffer_readmark(-1);
 }
 
 //  scr_get_chatmode()
--- a/mcabber/mcabber/screen.h	Mon Mar 14 23:45:24 2011 +0100
+++ b/mcabber/mcabber/screen.h	Tue Mar 15 00:39:17 2011 +0100
@@ -156,7 +156,7 @@
 void scr_buffer_dump(const char *file);
 void scr_buffer_list(void);
 void scr_buffer_scroll_up_down(int updown, unsigned int nblines);
-void scr_buffer_readmark(gboolean action);
+void scr_buffer_readmark(gchar action);
 void scr_buffer_jump_readmark(void);
 
 bool scr_roster_color(const char *status, const char *wildcard,