foreground and background windows
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 29 Mar 1984 15:03:14 +0000 (07:03 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 29 Mar 1984 15:03:14 +0000 (07:03 -0800)
SCCS-vsn: usr.bin/window/main.c 3.17
SCCS-vsn: usr.bin/window/cmd.c 3.22
SCCS-vsn: usr.bin/window/defs.h 3.10
SCCS-vsn: usr.bin/window/lcmd.c 3.13
SCCS-vsn: usr.bin/window/lcmd1.c 3.16
SCCS-vsn: usr.bin/window/win.c 3.4

usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/defs.h
usr/src/usr.bin/window/lcmd.c
usr/src/usr.bin/window/lcmd1.c
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/win.c

index 5bd1b60..f3b6d1b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.21 84/03/03";
+static char *sccsid = "@(#)cmd.c       3.22 84/03/29";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -233,63 +233,3 @@ struct ww *w;
        }
        return 0;
 }
        }
        return 0;
 }
-
-setselwin(w)
-struct ww *w;
-{
-       if (selwin == w)
-               return;
-       lastselwin = selwin;
-       front(selwin = w, 1);
-}
-
-/*
- * wwvisible() doesn't work for tinted windows.
- * But anything to make it faster.
- */
-front(w, doreframe)
-register struct ww *w;
-{
-       if (!wwvisible(w) && w->ww_back != framewin) {
-               wwdelete(w);
-               wwadd(w, framewin);
-               reframe();
-       } else if (doreframe)
-               reframe();
-}
-
-reframe()
-{
-       register struct ww *w;
-
-       wwunframe(framewin);
-       for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
-               if (w->ww_hasframe) {
-                       wwframe(w, framewin);
-                       labelwin(w);
-               }
-}
-
-labelwin(w)
-register struct ww *w;
-{
-       int mode = w == selwin ? WWM_REV : 0;
-
-       if (w->ww_id >= 0) {
-               char buf[2];
-
-               buf[0] = w->ww_id + '1';
-               buf[1] = 0;
-               wwlabel(w, framewin, 1, buf, mode);
-       }
-       if (w->ww_label) {
-               int col;
-
-               if (w->ww_center) {
-                       col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
-                       col = MAX(3, col);
-               } else
-                       col = 3;
-               wwlabel(w, framewin, col, w->ww_label, mode);
-       }
-}
index b849ce8..d62e14b 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)defs.h      3.9 84/03/03    
+ *     @(#)defs.h      3.10 84/03/29   
  */
 
 #include "ww.h"
  */
 
 #include "ww.h"
@@ -20,6 +20,11 @@ struct ww *lastselwin;               /* the last selected window */
 struct ww *cmdwin;             /* the command window */
 struct ww *framewin;           /* the window for framing */
 struct ww *boxwin;             /* the window for the box */
 struct ww *cmdwin;             /* the command window */
 struct ww *framewin;           /* the window for framing */
 struct ww *boxwin;             /* the window for the box */
+struct ww *fgwin;              /* the last foreground window */
+struct ww *bgwin;              /* the first background window */
+
+#define isfg(w)                ((w)->ww_order <= fgwin->ww_order)
+#define isbg(w)                ((w)->ww_order >= bgwin->ww_order)
 
 char *shell;                   /* the shell program */
 char *shellname;               /* the shell program name (for argv[0]) */
 
 char *shell;                   /* the shell program */
 char *shellname;               /* the shell program name (for argv[0]) */
index d87354f..4cb8d65 100644 (file)
@@ -1,16 +1,18 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd.c      3.12 84/03/23";
+static char *sccsid = "@(#)lcmd.c      3.13 84/03/29";
 #endif
 
 #include "defs.h"
 #include "value.h"
 #include "lcmd.h"
 
 #endif
 
 #include "defs.h"
 #include "value.h"
 #include "lcmd.h"
 
+int l_background();
 int l_buffer();
 int l_close();
 int l_cursormodes();
 int l_debug();
 int l_escape();
 int l_buffer();
 int l_close();
 int l_cursormodes();
 int l_debug();
 int l_escape();
+int l_foreground();
 int l_label();
 int l_select();
 int l_source();
 int l_label();
 int l_select();
 int l_source();
@@ -19,11 +21,13 @@ int l_unset();
 int l_window();
 int l_write();
 
 int l_window();
 int l_write();
 
+struct lcmd_arg arg_background[];
 struct lcmd_arg arg_buffer[];
 struct lcmd_arg arg_close[];
 struct lcmd_arg arg_cursormodes[];
 struct lcmd_arg arg_debug[];
 struct lcmd_arg arg_escape[];
 struct lcmd_arg arg_buffer[];
 struct lcmd_arg arg_close[];
 struct lcmd_arg arg_cursormodes[];
 struct lcmd_arg arg_debug[];
 struct lcmd_arg arg_escape[];
+struct lcmd_arg arg_foreground[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_select[];
 struct lcmd_arg arg_source[];
 struct lcmd_arg arg_label[];
 struct lcmd_arg arg_select[];
 struct lcmd_arg arg_source[];
@@ -34,11 +38,13 @@ struct lcmd_arg arg_write[];
 
 struct lcmd_tab lcmd_tab[] = {
        "%",            1,      l_select,       arg_select,
 
 struct lcmd_tab lcmd_tab[] = {
        "%",            1,      l_select,       arg_select,
-       "buffer",       1,      l_buffer,       arg_buffer,
+       "background",   2,      l_background,   arg_background,
+       "buffer",       2,      l_buffer,       arg_buffer,
        "close",        2,      l_close,        arg_close,
        "cursormodes",  2,      l_cursormodes,  arg_cursormodes,
        "debug",        1,      l_debug,        arg_debug,
        "escape",       1,      l_escape,       arg_escape,
        "close",        2,      l_close,        arg_close,
        "cursormodes",  2,      l_cursormodes,  arg_cursormodes,
        "debug",        1,      l_debug,        arg_debug,
        "escape",       1,      l_escape,       arg_escape,
+       "foreground",   1,      l_foreground,   arg_foreground,
        "label",        1,      l_label,        arg_label,
        "select",       2,      l_select,       arg_select,
        "source",       2,      l_source,       arg_source,
        "label",        1,      l_label,        arg_label,
        "select",       2,      l_select,       arg_select,
        "source",       2,      l_source,       arg_source,
@@ -46,7 +52,7 @@ struct lcmd_tab lcmd_tab[] = {
        "unset",        1,      l_unset,        arg_unset,
        "window",       2,      l_window,       arg_window,
        "write",        2,      l_write,        arg_write,
        "unset",        1,      l_unset,        arg_unset,
        "window",       2,      l_window,       arg_window,
        "write",        2,      l_write,        arg_write,
-       0,              0,      0,              0,
+       0
 };
 
 struct lcmd_tab *
 };
 
 struct lcmd_tab *
index 864d380..b5372e8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lcmd1.c     3.15 84/03/23";
+static char *sccsid = "@(#)lcmd1.c     3.16 84/03/29";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -119,6 +119,54 @@ register struct value *v, *a;
        reframe();
 }
 
        reframe();
 }
 
+struct lcmd_arg arg_foreground[] = {
+       { "window",     1,      ARG_NUM },
+       { "flag",       1,      ARG_ANY },
+       0
+};
+
+l_foreground(v, a)
+register struct value *v, *a;
+{
+       struct ww *w;
+       char flag;
+
+       if ((w = vtowin(a)) == 0)
+               return;
+       v->v_type = V_NUM;
+       v->v_num = isfg(w);
+       flag = vtobool(++a, 1, v->v_num);
+       if (flag == v->v_num)
+               return;
+       deletewin(w);
+       addwin(w, flag ? 0 : 1);
+       reframe();
+}
+
+struct lcmd_arg arg_background[] = {
+       { "window",     1,      ARG_NUM },
+       { "flag",       1,      ARG_ANY },
+       0
+};
+
+l_background(v, a)
+register struct value *v, *a;
+{
+       struct ww *w;
+       char flag;
+
+       if ((w = vtowin(a)) == 0)
+               return;
+       v->v_type = V_NUM;
+       v->v_num = isbg(w);
+       flag = vtobool(++a, 1, v->v_num);
+       if (flag == v->v_num)
+               return;
+       deletewin(w);
+       addwin(w, flag ? 3 : 2);
+       reframe();
+}
+
 struct lcmd_arg arg_terse[] = {
        { "flag",       1,      ARG_ANY },
        0
 struct lcmd_arg arg_terse[] = {
        { "flag",       1,      ARG_ANY },
        0
@@ -142,7 +190,6 @@ struct lcmd_arg arg_source[] = {
        0
 };
 
        0
 };
 
-/*ARGSUSED*/
 l_source(v, a)
 register struct value *v, *a;
 {
 l_source(v, a)
 register struct value *v, *a;
 {
index d9cd975..48b008d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      3.16 84/03/23";
+static char *sccsid = "@(#)main.c      3.17 84/03/29";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -91,6 +91,8 @@ char **argv;
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
+       fgwin = framewin;
+       bgwin = &wwhead;
 
        wwupdate();
        wwflush();
 
        wwupdate();
        wwflush();
index 89c73d3..61b431d 100644 (file)
@@ -1,11 +1,23 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)win.c       3.3 84/03/03";
+static char *sccsid = "@(#)win.c       3.4 84/03/29";
 #endif
 
 #include "defs.h"
 
 /*
 #endif
 
 #include "defs.h"
 
 /*
- * Routines for opening and closing windows
+ * Higher level routines for dealing with windows.
+ *
+ * There are two types of windows: user window, and information window.
+ * User windows are the ones with a pty and shell.  Information windows
+ * are for displaying error messages, and other information.
+ *
+ * The windows are stacked in overlapping order and divided into
+ * three groups: foreground, normal, and background.  Information
+ * windows are always foreground.  User windows can be anywhere.
+ * Addwin() adds a window to one of the three groups.
+ * Deletewin() deletes a window.  Front() moves a window to the front
+ * of its group.  Wwadd() and wwdelete() should never be called
+ * directly.
  */
 
 /*
  */
 
 /*
@@ -36,7 +48,7 @@ char *label;
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
-       wwadd(w, framewin);
+       addwin(w, 1);
        selwin = w;
        reframe();
        wwupdate();
        selwin = w;
        reframe();
        wwupdate();
@@ -64,6 +76,7 @@ findid()
 
 /*
  * Close a user window.
 
 /*
  * Close a user window.
+ * May leave selwin == 0.
  */
 closewin(w)
 register struct ww *w;
  */
 closewin(w)
 register struct ww *w;
@@ -76,7 +89,7 @@ register struct ww *w;
                window[w->ww_id] = 0;
        if (w->ww_label)
                str_free(w->ww_label);
                window[w->ww_id] = 0;
        if (w->ww_label)
                str_free(w->ww_label);
-       wwdelete(w);
+       deletewin(w);
        wwclose(w);
 }
 
        wwclose(w);
 }
 
@@ -97,7 +110,7 @@ char *label;
        w->ww_id = -1;
        w->ww_center = 1;
        (void) setlabel(w, label);
        w->ww_id = -1;
        w->ww_center = 1;
        (void) setlabel(w, label);
-       wwadd(w, framewin);
+       addwin(w, 0);
        reframe();
        wwupdate();
        return w;
        reframe();
        wwupdate();
        return w;
@@ -113,6 +126,131 @@ struct ww *w;
        reframe();
 }
 
        reframe();
 }
 
+/*
+ * Set the current window.
+ */
+setselwin(w)
+struct ww *w;
+{
+       if (selwin == w)
+               return;
+       lastselwin = selwin;
+       front(selwin = w, 1);
+}
+
+/*
+ * Move the window to the top of its group.
+ * Don't do it, if already fully visible.
+ * Wwvisible() doesn't work for tinted windows.
+ * But anything to make it faster.
+ * Always reframe() if doreframe is true.
+ */
+front(w, doreframe)
+register struct ww *w;
+char doreframe;
+{
+       if (isfg(w)) {
+               if (w->ww_back != framewin && !wwvisible(w)) {
+                       deletewin(w);
+                       addwin(w, 0);
+                       doreframe = 1;
+               }
+       } else if (isbg(w)) {
+               if (w != bgwin && !wwvisible(w)) {
+                       deletewin(w);
+                       addwin(w, 3);
+                       doreframe = 1;
+               }
+       } else {
+               if (w->ww_back != fgwin && !wwvisible(w)) {
+                       deletewin(w);
+                       addwin(w, 1);
+                       doreframe = 1;
+               }
+       }
+       if (doreframe)
+               reframe();
+}
+
+/*
+ * Add a window at one of four places.
+ */
+addwin(w, where)
+register struct ww *w;
+{
+       switch (where) {
+       case 0:         /* top of foreground windows */
+               wwadd(w, framewin);
+               if (fgwin == framewin)
+                       fgwin = w;
+               break;
+       case 1:         /* top of normal windows */
+               wwadd(w, fgwin);
+               break;
+       case 2:         /* bottom of normal windows */
+               wwadd(w, bgwin->ww_back);
+               break;
+       case 3:         /* top of background windows */
+               wwadd(w, bgwin->ww_back);
+               bgwin = w;
+               break;
+       }
+}
+
+/*
+ * Delete a window.
+ */
+deletewin(w)
+register struct ww *w;
+{
+       if (isfg(w)) {
+               if (fgwin == w)
+                       fgwin = w->ww_back;
+       } else if (isbg(w)) {
+               if (bgwin == w)
+                       bgwin = w->ww_forw;
+       }
+       wwdelete(w);
+}
+
+reframe()
+{
+       register struct ww *w;
+
+       wwunframe(framewin);
+       for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
+               if (w->ww_hasframe) {
+                       wwframe(w, framewin);
+                       labelwin(w);
+               }
+}
+
+labelwin(w)
+register struct ww *w;
+{
+       int mode = w == selwin ? WWM_REV : 0;
+
+       if (!w->ww_hasframe)
+               return;
+       if (w->ww_id >= 0) {
+               char buf[2];
+
+               buf[0] = w->ww_id + '1';
+               buf[1] = 0;
+               wwlabel(w, framewin, 1, buf, mode);
+       }
+       if (w->ww_label) {
+               int col;
+
+               if (w->ww_center) {
+                       col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
+                       col = MAX(3, col);
+               } else
+                       col = 3;
+               wwlabel(w, framewin, col, w->ww_label, mode);
+       }
+}
+
 waitnl(w)
 struct ww *w;
 {
 waitnl(w)
 struct ww *w;
 {