Index: editwin.c
===================================================================
--- editwin.c	(revision 4e33cb2f14d7abf604bd5fc271924e2a3000da09)
+++ editwin.c	(revision f6fae8d526ff0525c526bc767e88c386fde4f41b)
@@ -28,5 +28,7 @@
   int cursorx;
   int winlines, wincols, fillcol, wrapcol;
-  WINDOW *curswin;
+  owl_window *win;
+  gulong repaint_id;
+  gulong resized_id;
   int style;
   int lock;
@@ -40,4 +42,6 @@
 };
 
+static void oe_set_curswin(owl_editwin *e, owl_window *w, int winlines, int wincols);
+static void oe_redisplay(owl_window *win, WINDOW *curswin, void *user_data);
 static void oe_reframe(owl_editwin *e);
 static void oe_save_excursion(owl_editwin *e, oe_excursion *x);
@@ -58,4 +62,6 @@
 static char *oe_chunk(owl_editwin *e, int start, int end);
 static void oe_destroy_cbdata(owl_editwin *e);
+static void oe_dirty(owl_editwin *e);
+static void oe_window_resized(owl_window *w, owl_editwin *e);
 
 #define INCR 4096
@@ -73,4 +79,8 @@
 void owl_editwin_delete(owl_editwin *e)
 {
+  if (e->win) {
+    g_signal_handler_disconnect(e->win, e->repaint_id);
+    g_signal_handler_disconnect(e->win, e->resized_id);
+  }
   owl_free(e->buff);
   owl_free(e->killbuf);
@@ -91,4 +101,5 @@
   }
   e->index = index;
+  oe_dirty(e);
 }
 
@@ -105,5 +116,4 @@
 
 static void _owl_editwin_init(owl_editwin *e,
-                              WINDOW *win,
                               int winlines,
                               int wincols,
@@ -130,23 +140,27 @@
     e->style=OWL_EDITWIN_STYLE_MULTILINE;
   }
-  owl_editwin_set_curswin(e, win, winlines, wincols);
   e->lock=0;
   e->dotsend=0;
   e->echochar='\0';
-
-  if (win) werase(win);
-}
-
-owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
+}
+
+owl_editwin *owl_editwin_new(owl_window *win, int winlines, int wincols, int style, owl_history *hist)
 {
   owl_editwin *e = owl_editwin_allocate();
 
-  _owl_editwin_init(e, win, winlines, wincols, style, hist);
+  _owl_editwin_init(e, winlines, wincols, style, hist);
+  oe_set_curswin(e, win, winlines, wincols);
   return e;
 }
 
-void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
-{
-  e->curswin=w;
+static void oe_window_resized(owl_window *w, owl_editwin *e)
+{
+  /* update the sizes */
+  owl_window_get_position(w, &e->winlines, &e->wincols, NULL, NULL);
+}
+
+static void oe_set_curswin(owl_editwin *e, owl_window *w, int winlines, int wincols)
+{
+  e->win=w;
   e->winlines=winlines;
   e->wincols=wincols;
@@ -156,4 +170,9 @@
   else
     e->wrapcol = 0;
+  if (e->win) {
+    e->repaint_id = g_signal_connect(w, "redraw", G_CALLBACK(oe_redisplay), e);
+    e->resized_id = g_signal_connect(w, "resized", G_CALLBACK(oe_window_resized), e);
+    owl_window_dirty(e->win);
+  }
 }
 
@@ -165,9 +184,5 @@
 {
   e->echochar=ch;
-}
-
-WINDOW *owl_editwin_get_curswin(owl_editwin *e)
-{
-  return(e->curswin);
+  oe_dirty(e);
 }
 
@@ -239,5 +254,5 @@
   e->lock=e->bufflen;
   oe_set_index(e, e->lock);
-  owl_editwin_redisplay(e);
+  oe_dirty(e);
 }
 
@@ -265,5 +280,5 @@
 
   owl_free(e->buff);
-  _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
+  _owl_editwin_init(e, e->winlines, e->wincols, e->style, e->hist);
 
   if (lock > 0) {
@@ -286,4 +301,5 @@
 {
   e->topindex = -1;
+  oe_dirty(e);
 }
 
@@ -467,28 +483,30 @@
 
   oe_restore_excursion(e, &x);
-}
-
-static void oe_addnec(owl_editwin *e, int count)
+  oe_dirty(e);
+}
+
+static void oe_addnec(owl_editwin *e, WINDOW *curswin, int count)
 {
   int i;
 
   for (i = 0; i < count; i++)
-    waddch(e->curswin, e->echochar);
-}
-
-static void oe_mvaddnec(owl_editwin *e, int y, int x, int count)
-{
-  wmove(e->curswin, y, x);
-  oe_addnec(e, count);
+    waddch(curswin, e->echochar);
+}
+
+static void oe_mvaddnec(owl_editwin *e, WINDOW *curswin, int y, int x, int count)
+{
+  wmove(curswin, y, x);
+  oe_addnec(e, curswin, count);
 }
 
 /* regenerate the text on the curses window */
-void owl_editwin_redisplay(owl_editwin *e)
+static void oe_redisplay(owl_window *win, WINDOW *curswin, void *user_data)
 {
   int x = -1, y = -1, t, hard;
   int line, index, lineindex, times = 0;
+  owl_editwin *e = user_data;
 
   do {
-    werase(e->curswin);
+    werase(curswin);
 
     if (e->topindex == -1 || e->index < e->topindex)
@@ -505,22 +523,22 @@
       if (index - lineindex) {
 	if (!e->echochar)
-	  mvwaddnstr(e->curswin, line, 0,
+	  mvwaddnstr(curswin, line, 0,
 		     e->buff + lineindex,
 		     index - lineindex);
 	else {
 	  if(lineindex < e->lock) {
-	    mvwaddnstr(e->curswin, line, 0,
+	    mvwaddnstr(curswin, line, 0,
 		       e->buff + lineindex,
 		       MIN(index - lineindex,
 			   e->lock - lineindex));
 	    if (e->lock < index)
-	      oe_addnec(e,
+	      oe_addnec(e, curswin,
 			oe_region_width(e, e->lock, index,
 					oe_region_width(e, lineindex, e->lock, 0)));
 	  } else
-	    oe_mvaddnec(e, line, 0, oe_region_width(e, lineindex, index, 0));
+	    oe_mvaddnec(e, curswin, line, 0, oe_region_width(e, lineindex, index, 0));
 	}
         if (!hard)
-          waddch(e->curswin, '\\');
+          waddch(curswin, '\\');
       }
       line++;
@@ -531,7 +549,6 @@
   } while(x == -1 && times < 3);
 
-  wmove(e->curswin, y, x);
+  wmove(curswin, y, x);
   e->cursorx = x;
-  owl_global_set_needrefresh(&g);
 }
 
@@ -625,4 +642,6 @@
   if (start <= e->topindex)
     owl_editwin_recenter(e);
+
+  oe_dirty(e);
 
   return change;
@@ -858,4 +877,5 @@
 
   e->goal_column = goal_column;
+  oe_dirty(e);
 
   return distance;
@@ -1212,5 +1232,4 @@
     return;
   }
-  owl_editwin_redisplay(e);
 }
 
@@ -1347,4 +1366,9 @@
 }
 
+static void oe_dirty(owl_editwin *e)
+{
+  if (e->win) owl_window_dirty(e->win);
+}
+
 
 
