changeset 2098:c4a68361883f

Lock buffer automatically when scrolled up, unlock when at bottom ("buffer_smart_scrolling" setting)
author Hermitifier
date Mon, 07 Apr 2014 08:46:17 +0200
parents e06054423a60
children a9440a1d52e5
files mcabber/mcabber/screen.c mcabber/mcabberrc.example
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/screen.c	Fri Apr 04 13:54:22 2014 +0200
+++ b/mcabber/mcabber/screen.c	Mon Apr 07 08:46:17 2014 +0200
@@ -1138,6 +1138,9 @@
   int color = COLOR_GENERAL;
   bool readmark = FALSE;
   bool skipline = FALSE;
+  int autolock;
+
+  autolock = settings_opt_get_int("buffer_smart_scrolling");
 
   prefixwidth = scr_getprefixwidth();
   prefixwidth = MIN(prefixwidth, sizeof pref);
@@ -1145,6 +1148,8 @@
   // Should the window be empty?
   if (win_entry->bd->cleared) {
     werase(win_entry->win);
+    if (autolock && win_entry->bd->lock)
+      scr_buffer_scroll_lock(0);
     return;
   }
 
@@ -1170,8 +1175,8 @@
   } else
     hbuf_head = win_entry->bd->top;
 
-  // Get the last CHAT_WIN_HEIGHT lines.
-  lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
+  // Get the last CHAT_WIN_HEIGHT lines, and one more to detect scroll.
+  lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT+1);
 
   if (CHAT_WIN_HEIGHT > 1) {
     // Do we have a read mark?
@@ -1327,6 +1332,19 @@
       break;
     }
   }
+  line = *(lines+CHAT_WIN_HEIGHT); //line is scrolled out and never written
+  if (line) {
+    if (autolock && !win_entry->bd->lock) {
+      if (!hbuf_jump_readmark(hbuf_head))
+        scr_buffer_readmark(TRUE);
+      scr_buffer_scroll_lock(1);
+    }
+    g_free(line->text);
+    g_free(line);
+  } else if (autolock && win_entry->bd->lock) {
+    scr_buffer_scroll_lock(0);
+  }
+
   g_free(lines);
 }
 
@@ -2907,6 +2925,7 @@
 {
   winbuf *win_entry;
   guint isspe;
+  int autolock;
 
   // Get win_entry
   if (!current_buddy) return;
@@ -2915,7 +2934,8 @@
   win_entry = scr_search_window(CURRENT_JID, isspe);
   if (!win_entry) return;
 
-  if (!win_entry->bd->lock) {
+  autolock = settings_opt_get_int("buffer_smart_scrolling");
+  if (!win_entry->bd->lock || autolock) {
     if (action >= 0)
       hbuf_set_readmark(win_entry->bd->hbuf, action);
     else
--- a/mcabber/mcabberrc.example	Fri Apr 04 13:54:22 2014 +0200
+++ b/mcabber/mcabberrc.example	Mon Apr 07 08:46:17 2014 +0200
@@ -500,6 +500,14 @@
 # Useful when your buddies are chatting from their non-highest priority
 # resources, forcing you to use /say_to command.
 #set roster_autolock_resource = 1
+#
+# Automatic locking of buffer when scrolled up, and unlocking when scrolled
+# to bottom.
+# Set 'buffer_smart_scrolling' to 1 to enable.
+# Note: manual command "/buffer scroll_lock" will not work when smart scrolling
+# is enabled. Command "/buffer scroll_unlock" will only work if there is a new
+# message received.
+#set buffer_smart_scrolling = 0
 
 # Contacts PGP information
 # You can provide a PGP key to be used for a given Jabber user, or