Index: functions.c
===================================================================
--- functions.c	(revision 4cf7b1ba906e2b9d64025c6750d700a891d39a59)
+++ functions.c	(revision 03ca0054628460c6cc077c799c50e2dac636549a)
@@ -1237,11 +1237,13 @@
   owl_viewwin *v;
 
-  pw=owl_global_get_popwin(&g);
   v=owl_global_get_viewwin(&g);
 
-  if (owl_popwin_up(pw) != 0) {
+  if (owl_global_get_popwin(&g)) {
     owl_function_error("Popwin already in use.");
     return;
   }
+  pw = owl_popwin_new();
+  owl_global_set_popwin(&g, pw);
+  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);
@@ -1253,11 +1255,13 @@
   owl_viewwin *v;
 
-  pw=owl_global_get_popwin(&g);
   v=owl_global_get_viewwin(&g);
 
-  if (owl_popwin_up(pw) != 0) {
+  if (owl_global_get_popwin(&g)) {
     owl_function_error("Popwin already in use.");
     return;
   }
+  pw = owl_popwin_new();
+  owl_global_set_popwin(&g, pw);
+  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);
Index: global.c
===================================================================
--- global.c	(revision 5b68c059f37025221b7dfcd2825c7708e7de7315)
+++ global.c	(revision 03ca0054628460c6cc077c799c50e2dac636549a)
@@ -48,4 +48,5 @@
   g->rightshift=0;
 
+  g->pw = NULL;
   g->tw = NULL;
 
@@ -126,5 +127,4 @@
   /* Create the widgets */
   owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
-  owl_popwin_init(&(g->pw));
   owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
   owl_sepbar_init(g->mainpanel.sepwin);
@@ -255,5 +255,9 @@
 
 owl_popwin *owl_global_get_popwin(owl_global *g) {
-  return(&(g->pw));
+  return g->pw;
+}
+
+void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
+  g->pw = pw;
 }
 
Index: owl.h
===================================================================
--- owl.h	(revision b3b1b051937badd886da90647eade9934c74f17d)
+++ owl.h	(revision 03ca0054628460c6cc077c799c50e2dac636549a)
@@ -410,5 +410,4 @@
   gulong sig_redraw_id;
   gulong sig_resize_id;
-  int active;
 } owl_popwin;
   
@@ -563,5 +562,5 @@
 typedef struct _owl_global {
   owl_mainwin mw;
-  owl_popwin pw;
+  owl_popwin *pw;
   owl_msgwin msgwin;
   owl_history cmdhist;		/* command history */
Index: popexec.c
===================================================================
--- popexec.c	(revision 4cf7b1ba906e2b9d64025c6750d700a891d39a59)
+++ popexec.c	(revision 03ca0054628460c6cc077c799c50e2dac636549a)
@@ -17,4 +17,9 @@
   pid_t pid;
 
+  if (owl_global_get_popwin(&g)) {
+    owl_function_error("Popwin already in use.");
+    return NULL;
+  }
+
   pe = owl_malloc(sizeof(owl_popexec));
   if (!pe) return NULL;
@@ -23,11 +28,9 @@
   pe->refcount=0;
 
-  pw=owl_global_get_popwin(&g);
   pe->vwin=v=owl_global_get_viewwin(&g);
+  pw = owl_popwin_new();
+  owl_global_set_popwin(&g, pw);
+  owl_popwin_up(pw);
 
-  if (owl_popwin_up(pw) != 0) {
-    owl_function_error("Popwin already in use.");
-    return NULL;
-  }
   owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL);
   owl_viewwin_init_text(v, owl_popwin_get_content(pw), "");
Index: popwin.c
===================================================================
--- popwin.c	(revision b3b1b051937badd886da90647eade9934c74f17d)
+++ popwin.c	(revision 03ca0054628460c6cc077c799c50e2dac636549a)
@@ -1,14 +1,9 @@
 #include "owl.h"
 
-int owl_popwin_init(owl_popwin *pw)
+owl_popwin *owl_popwin_new(void)
 {
-  pw->active=0;
-  return(0);
-}
+  owl_popwin *pw = owl_malloc(sizeof(owl_popwin));
+  memset(pw, 0, sizeof(*pw));
 
-int owl_popwin_up(owl_popwin *pw)
-{
-  if (pw->active)
-    return 1;
   pw->border = owl_window_new(NULL);
   pw->content = owl_window_new(pw->border);
@@ -23,8 +18,15 @@
   owl_popwin_size_border(owl_window_get_screen(), pw->border);
 
-  owl_window_show_all(pw->border);
+  owl_window_show(pw->content);
 
-  pw->active=1;
-  return(0);
+  return pw;
+}
+
+int owl_popwin_up(owl_popwin *pw)
+{
+  if (owl_window_is_shown(pw->border))
+    return 1;
+  owl_window_show(pw->border);
+  return 0;
 }
 
@@ -74,6 +76,15 @@
 int owl_popwin_close(owl_popwin *pw)
 {
-  if (!pw->active)
+  if (!owl_window_is_shown(pw->border))
     return 1;
+  owl_window_hide(pw->border);
+  return 0;
+}
+
+void owl_popwin_delete(owl_popwin *pw)
+{
+  owl_popwin_close(pw);
+
+  /* Remove everything that references us. */
   g_signal_handler_disconnect(pw->border, pw->sig_resize_id);
   g_signal_handler_disconnect(pw->border, pw->sig_redraw_id);
@@ -82,13 +93,10 @@
   g_object_unref(pw->content);
 
-  pw->border = 0;
-  pw->content = 0;
-  pw->active=0;
-  return(0);
+  owl_free(pw);
 }
 
 int owl_popwin_is_active(const owl_popwin *pw)
 {
-  return pw->active;
+  return owl_window_is_shown(pw->border);
 }
 
