[2873] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 2/2] Don't reset colorpairs in the middle of drawing

daemon@ATHENA.MIT.EDU (David Benjamin)
Tue Jan 25 17:51:06 2011

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Tue, 25 Jan 2011 17:50:17 -0500
In-Reply-To: <1295995817-17581-1-git-send-email-davidben@mit.edu>

Resetting colorpairs while drawing the mainwin causes the existing
contents in a popwin to refer to invalid color pairs. We used to draw
the mainwin first and redraw the contents of each window from scratch.
Moving to libpanel in 1.6 changed this, so background colors
occasionally bled into your popwin.

This changes the colorpair logic to only trigger when we need to, and to
forcibly dirty every window if needed. NOTE: if we don't have enough
color-pairs to draw the current screen, this will possibly needlessly
draw everything twice. But I suspect it will really never happen anyway.

Reported-by: Alex Dehnert <adehnert@mit.edu>
---
 mainwin.c |    1 -
 owl.c     |   14 ++++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/mainwin.c b/mainwin.c
index 5d78135..8414317 100644
--- a/mainwin.c
+++ b/mainwin.c
@@ -52,7 +52,6 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
   curmsg = owl_global_get_curmsg(&g);
   markedmsgid = owl_global_get_markedmsgid(&g);
   v = owl_global_get_current_view(&g);
-  owl_fmtext_reset_colorpairs(owl_global_get_colorpair_mgr(&g));
 
   if (v==NULL) {
     owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
diff --git a/owl.c b/owl.c
index 4230595..6b0daa5 100644
--- a/owl.c
+++ b/owl.c
@@ -443,10 +443,24 @@ void stderr_redirect_handler(const owl_io_dispatch *d, void *data)
 
 static int owl_refresh_pre_select_action(owl_ps_action *a, void *data)
 {
+  owl_colorpair_mgr *cpmgr;
+
   /* if a resize has been scheduled, deal with it */
   owl_global_check_resize(&g);
   /* update the terminal if we need to */
   owl_window_redraw_scheduled();
+  /* If we somehow managed to run out of colorpairs, reset them and
+   * redraw /everything/. NOTE: if we don't have enough color-pairs to
+   * draw the current screen, this will possibly needlessly draw
+   * everything twice. But I suspect it will pretty much never happen
+   * anyway. */
+  cpmgr = owl_global_get_colorpair_mgr(&g);
+  if (cpmgr->next >= COLOR_PAIRS) {
+    owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);
+    owl_fmtext_reset_colorpairs(cpmgr);
+    owl_function_full_redisplay();
+    owl_window_redraw_scheduled();
+  }
   return 0;
 }
 
-- 
1.7.3.3.399.g06ddf


home help back first fref pref prev next nref lref last post