Index: functions.c
===================================================================
--- functions.c	(revision 8bba1aed9c99b38e86fab76c25d3b415be31afdb)
+++ functions.c	(revision d12a8c71f5d91653b1bffd9fa566448eb52b5d43)
@@ -216,4 +216,5 @@
   /* redisplay etc. */
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+  owl_global_set_needrefresh(&g);
 }
 
@@ -292,5 +293,5 @@
   owl_editwin_set_cbdata(e, data, cleanup);
   owl_editwin_set_callback(e, callback);
-  owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti", owl_global_get_typwin_window(&g));
+  owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti");
 }
 
@@ -807,4 +808,6 @@
 {
   owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10);
+  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+  owl_global_set_needrefresh(&g);
 }
 
@@ -816,4 +819,6 @@
   if (shift > 0) {
     owl_global_set_rightshift(&g, MAX(shift - 10, 0));
+    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+    owl_global_set_needrefresh(&g);
   } else {
     owl_function_beep();
@@ -1199,5 +1204,5 @@
     return;
 
-  file = fopen(owl_global_get_debug_file(&g), "a");
+  file = owl_global_get_debug_file_handle(&g);
   if (!file) /* XXX should report this */
     return;
@@ -1209,5 +1214,5 @@
   vfprintf(file, fmt, ap);
   putc('\n', file);
-  fclose(file);
+  fflush(file);
 
   va_end(ap);
@@ -1218,4 +1223,5 @@
   if (owl_global_is_bell(&g)) {
     beep();
+    owl_global_set_needrefresh(&g); /* do we really need this? */
   }
 }
@@ -1246,14 +1252,25 @@
 }
 
-static void _dirty_everything(owl_window *w) {
-  if (!owl_window_is_realized(w))
-    return;
-  owl_window_dirty(w);
-  owl_window_children_foreach(w, (GFunc)_dirty_everything, NULL);
+void owl_function_set_cursor(WINDOW *win)
+{
+  /* Be careful that this window is actually empty, otherwise panels get confused */
+  if (is_wintouched(win)) {
+    owl_function_debugmsg("Warning: owl_function_set_cursor called on dirty window");
+    update_panels();
+  }
+  wnoutrefresh(win);
 }
 
 void owl_function_full_redisplay(void)
 {
-  _dirty_everything(owl_window_get_screen());
+  touchwin(owl_global_get_curs_recwin(&g));
+  touchwin(owl_global_get_curs_sepwin(&g));
+  touchwin(owl_global_get_curs_typwin(&g));
+  touchwin(owl_global_get_curs_msgwin(&g));
+
+  sepbar("");
+  owl_function_makemsg("");
+
+  owl_global_set_needrefresh(&g);
 }
 
@@ -1267,6 +1284,10 @@
 
   owl_popwin_up(pw);
-  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL);
-  owl_viewwin_init_text(v, owl_popwin_get_content(pw), text);
+  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
+  owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
+			owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
+			text);
+  owl_viewwin_redisplay(v);
+  owl_global_set_needrefresh(&g);
 }
 
@@ -1280,6 +1301,10 @@
 
   owl_popwin_up(pw);
-  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL);
-  owl_viewwin_init_fmtext(v, owl_popwin_get_content(pw), fm);
+  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
+  owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
+		   owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
+		   fm);
+  owl_viewwin_redisplay(v);
+  owl_global_set_needrefresh(&g);
 }
 
@@ -1541,4 +1566,5 @@
   /* redisplay */
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+  owl_global_set_needrefresh(&g);
 }
 
@@ -1546,5 +1572,5 @@
 {
   owl_global_set_typwin_lines(&g, newsize);
-  owl_mainpanel_layout_contents(&g.mainpanel);
+  owl_global_set_relayout_pending(&g);
 }
 
@@ -1660,4 +1686,5 @@
     }
     owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+    owl_global_set_needrefresh(&g);
   } else {
     owl_function_error("No message with id %d: unable to mark for (un)delete",id);
@@ -1695,4 +1722,5 @@
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
   owl_function_makemsg("%i messages marked for deletion", count);
+  owl_global_set_needrefresh(&g);
 }
 
@@ -1899,8 +1927,10 @@
 
   owl_editwin_set_locktext(tw, "command: ");
+  owl_global_set_needrefresh(&g);
 
   owl_editwin_insert_string(tw, line);
-
-  owl_global_push_context(&g, OWL_CTX_EDITLINE, tw, "editline", owl_global_get_typwin_window(&g));
+  owl_editwin_redisplay(tw);
+
+  owl_global_push_context(&g, OWL_CTX_EDITLINE, tw, "editline");
   owl_editwin_set_callback(tw, owl_callback_command);
 }
@@ -1913,6 +1943,9 @@
 
   owl_editwin_set_locktext(tw, line);
-
-  owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse", owl_global_get_typwin_window(&g));
+  owl_global_set_needrefresh(&g);
+
+  owl_editwin_redisplay(tw);
+
+  owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse");
   return tw;
 }
@@ -1927,6 +1960,9 @@
 
   owl_editwin_set_locktext(tw, line);
-
-  owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse", owl_global_get_typwin_window(&g));
+  owl_global_set_needrefresh(&g);
+
+  owl_editwin_redisplay(tw);
+
+  owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse");
   return tw;
 }
@@ -1963,9 +1999,13 @@
     pclose(p);
     
-    if (type == OWL_OUTPUT_RETURN) {
+    if (type == OWL_OUTPUT_POPUP) {
+      owl_function_popless_text(out);
+    } else if (type == OWL_OUTPUT_RETURN) {
       owl_free(newbuff);
       return out;
     } else if (type == OWL_OUTPUT_ADMINMSG) {
       owl_function_adminmsg(buff, out);
+    } else {
+      owl_function_popless_text(out);
     }
     owl_free(out);
@@ -2000,4 +2040,6 @@
     } else if (type == OWL_OUTPUT_RETURN) {
       return perlout;
+    } else {
+      owl_function_popless_text(perlout);
     }
     owl_free(perlout);
@@ -2091,4 +2133,5 @@
     }
     owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3]));
+    owl_global_set_needrefresh(&g);
     owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     return;
@@ -2105,4 +2148,5 @@
     }
     owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3]));
+    owl_global_set_needrefresh(&g);
     owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     return;
@@ -2133,4 +2177,5 @@
     owl_function_change_currentview_filter(argv[1]);
   }
+  owl_global_set_needrefresh(&g);
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
 }
@@ -2460,32 +2505,4 @@
 
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));  
-}
-
-static char *owl_function_smartfilter_cc(const owl_message *m) {
-  const char *ccs;
-  char *filtname;
-  char *text;
-  owl_filter *f;
-
-  ccs = owl_message_get_attribute_value(m, "zephyr_ccs");
-
-  filtname = owl_sprintf("conversation-%s", ccs);
-  owl_text_tr(filtname, ' ', '-');
-
-  if (owl_global_get_filter(&g, filtname)) {
-    return filtname;
-  }
-
-  text = owl_sprintf("type ^zephyr$ and filter personal and "
-                     "zephyr_ccs ^%s%s%s$",
-                     owl_getquoting(ccs), ccs, owl_getquoting(ccs));
-
-  f = owl_filter_new_fromstring(filtname, text);
-
-  owl_global_add_filter(&g, f);
-
-  owl_free(text);
-
-  return filtname;
 }
 
@@ -2543,8 +2560,4 @@
   if (owl_message_is_type_zephyr(m)) {
     if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
-      if (owl_message_get_attribute_value(m, "zephyr_ccs") != NULL) {
-        return owl_function_smartfilter_cc(m);
-      }
-
       if (owl_message_is_direction_in(m)) {
         zperson=short_zuser(owl_message_get_sender(m));
@@ -2676,4 +2689,5 @@
   owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor));
   
+  owl_global_set_needrefresh(&g);
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
   return(0);
@@ -2839,5 +2853,5 @@
     km = owl_keyhandler_get_keymap(kh, kmname);
     owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
-    owl_keymap_get_details(km, &fm, 0);
+    owl_keymap_get_details(km, &fm);    
   }
   owl_fmtext_append_normal(&fm, "\n");
@@ -2865,5 +2879,5 @@
   km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
   if (km) {
-    owl_keymap_get_details(km, &fm, 1);
+    owl_keymap_get_details(km, &fm);
   } else {
     owl_fmtext_append_normal(&fm, "No such keymap...\n");
@@ -3389,12 +3403,16 @@
 {
   va_list ap;
-  char *str;
+  char buff[2048];
+
+  if (!owl_global_get_curs_msgwin(&g)) return;
 
   va_start(ap, fmt);
-  str = g_strdup_vprintf(fmt, ap);
+  werase(owl_global_get_curs_msgwin(&g));
+  
+  vsnprintf(buff, 2048, fmt, ap);
+  owl_function_debugmsg("makemsg: %s", buff);
+  waddstr(owl_global_get_curs_msgwin(&g), buff);  
+  owl_global_set_needrefresh(&g);
   va_end(ap);
-
-  owl_function_debugmsg("makemsg: %s", str);
-  owl_msgwin_set_text(&g.msgwin, str);
 }
 
