Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/screen.c @ 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 | 16b04d64ec88 |
children | 113d3b96ae3e |
comparison
equal
deleted
inserted
replaced
2091:e06054423a60 | 2098:c4a68361883f |
---|---|
1136 hbb_line **lines, *line; | 1136 hbb_line **lines, *line; |
1137 GList *hbuf_head; | 1137 GList *hbuf_head; |
1138 int color = COLOR_GENERAL; | 1138 int color = COLOR_GENERAL; |
1139 bool readmark = FALSE; | 1139 bool readmark = FALSE; |
1140 bool skipline = FALSE; | 1140 bool skipline = FALSE; |
1141 int autolock; | |
1142 | |
1143 autolock = settings_opt_get_int("buffer_smart_scrolling"); | |
1141 | 1144 |
1142 prefixwidth = scr_getprefixwidth(); | 1145 prefixwidth = scr_getprefixwidth(); |
1143 prefixwidth = MIN(prefixwidth, sizeof pref); | 1146 prefixwidth = MIN(prefixwidth, sizeof pref); |
1144 | 1147 |
1145 // Should the window be empty? | 1148 // Should the window be empty? |
1146 if (win_entry->bd->cleared) { | 1149 if (win_entry->bd->cleared) { |
1147 werase(win_entry->win); | 1150 werase(win_entry->win); |
1151 if (autolock && win_entry->bd->lock) | |
1152 scr_buffer_scroll_lock(0); | |
1148 return; | 1153 return; |
1149 } | 1154 } |
1150 | 1155 |
1151 // win_entry->bd->top is the top message of the screen. If it set to NULL, | 1156 // win_entry->bd->top is the top message of the screen. If it set to NULL, |
1152 // we are displaying the last messages. | 1157 // we are displaying the last messages. |
1168 if (win_entry->bd->lock) | 1173 if (win_entry->bd->lock) |
1169 win_entry->bd->top = hbuf_head; | 1174 win_entry->bd->top = hbuf_head; |
1170 } else | 1175 } else |
1171 hbuf_head = win_entry->bd->top; | 1176 hbuf_head = win_entry->bd->top; |
1172 | 1177 |
1173 // Get the last CHAT_WIN_HEIGHT lines. | 1178 // Get the last CHAT_WIN_HEIGHT lines, and one more to detect scroll. |
1174 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); | 1179 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT+1); |
1175 | 1180 |
1176 if (CHAT_WIN_HEIGHT > 1) { | 1181 if (CHAT_WIN_HEIGHT > 1) { |
1177 // Do we have a read mark? | 1182 // Do we have a read mark? |
1178 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | 1183 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
1179 line = *(lines+n); | 1184 line = *(lines+n); |
1325 } else { | 1330 } else { |
1326 wclrtobot(win_entry->win); | 1331 wclrtobot(win_entry->win); |
1327 break; | 1332 break; |
1328 } | 1333 } |
1329 } | 1334 } |
1335 line = *(lines+CHAT_WIN_HEIGHT); //line is scrolled out and never written | |
1336 if (line) { | |
1337 if (autolock && !win_entry->bd->lock) { | |
1338 if (!hbuf_jump_readmark(hbuf_head)) | |
1339 scr_buffer_readmark(TRUE); | |
1340 scr_buffer_scroll_lock(1); | |
1341 } | |
1342 g_free(line->text); | |
1343 g_free(line); | |
1344 } else if (autolock && win_entry->bd->lock) { | |
1345 scr_buffer_scroll_lock(0); | |
1346 } | |
1347 | |
1330 g_free(lines); | 1348 g_free(lines); |
1331 } | 1349 } |
1332 | 1350 |
1333 static winbuf *scr_create_window(const char *winId, int special, int dont_show) | 1351 static winbuf *scr_create_window(const char *winId, int special, int dont_show) |
1334 { | 1352 { |
2905 // If action = -1, remove the readmark flag iff it is on the last line | 2923 // If action = -1, remove the readmark flag iff it is on the last line |
2906 void scr_buffer_readmark(gchar action) | 2924 void scr_buffer_readmark(gchar action) |
2907 { | 2925 { |
2908 winbuf *win_entry; | 2926 winbuf *win_entry; |
2909 guint isspe; | 2927 guint isspe; |
2928 int autolock; | |
2910 | 2929 |
2911 // Get win_entry | 2930 // Get win_entry |
2912 if (!current_buddy) return; | 2931 if (!current_buddy) return; |
2913 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; | 2932 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
2914 if (isspe) return; // Maybe not necessary | 2933 if (isspe) return; // Maybe not necessary |
2915 win_entry = scr_search_window(CURRENT_JID, isspe); | 2934 win_entry = scr_search_window(CURRENT_JID, isspe); |
2916 if (!win_entry) return; | 2935 if (!win_entry) return; |
2917 | 2936 |
2918 if (!win_entry->bd->lock) { | 2937 autolock = settings_opt_get_int("buffer_smart_scrolling"); |
2938 if (!win_entry->bd->lock || autolock) { | |
2919 if (action >= 0) | 2939 if (action >= 0) |
2920 hbuf_set_readmark(win_entry->bd->hbuf, action); | 2940 hbuf_set_readmark(win_entry->bd->hbuf, action); |
2921 else | 2941 else |
2922 hbuf_remove_trailing_readmark(win_entry->bd->hbuf); | 2942 hbuf_remove_trailing_readmark(win_entry->bd->hbuf); |
2923 } | 2943 } |