xterm-18.patch.txt

XFree86 3.1.2Ec - xterm patch #18 - 1996/7/18 - T.Dickey
 
This implements the following:
 
        + escape sequences that act like the CDE dtterm's window operations
          (though I have implemented the default width and height -- I've seen
          a rather buggy dtterm running that seems to treat width=0 or height=0
          literally -- maybe that's a feature, not a bug?)
 
        + minor tweak to the screen-repainting when resizing (I still cannot
          entirely get rid of flicker).
 
        + still more fixes to terminfo & termcap (I corrected my error for
          the hpa code and added some other stuff by comparing to ncurses'
          description and rxvt's).
 
        + a tweak to the patch by Michael Rohleder for the color translation
 
        + re-order attribute codes to allow later implementation of protected
          fields (dtterm supposedly does this; it's probably more useful than
          blinking or invisible text -- that uses up all of the available bits
          without changing the attribute scheme radically).
 
My to-do list:
 
        + debug this on IRIX 5.2 (I've got lousy debugging aids there, and
          simply haven't had time til this week to spend the off-hours time
          I'll need to troubleshoot the problem).
 
        + try to reduce the memory usage of the savedLines (I think that it's
          feasible to suppress the memory allocated for fore/back color codes
          if the user hasn't enabled color).
 
        + time permitting, implement the protected fields (that's mainly
          by modifying the logic for the clear-line and clear-screen functions).
 
(I have a number of items beyond these that I won't have time to do before 3.2
is frozen).
 
--------------------------------------------------------------------------------
 VTPrsTbl.c  |   11 +-
 VTparse.def |    1 
 VTparse.h   |    1 
 charproc.c  |  268 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 ptyx.h      |   16 ++-
 screen.c    |   20 ++--
 termcap     |    4 
 terminfo    |   38 +++++---
 util.c      |    4 
 9 files changed, 284 insertions, 79 deletions
--------------------------------------------------------------------------------
Index: VTPrsTbl.c
--- xterm+/VTPrsTbl.c   Mon Jul  8 12:42:24 1996
+++ xterm_a/VTPrsTbl.c  Wed Jul 17 19:57:24 1996
@@ -36,7 +36,7 @@
 
 /*
  * Stupid Apollo C preprocessor can't handle long lines.  So... To keep
- * it happy, we put each onto a seperate line....  Sigh...
+ * it happy, we put each onto a separate line....  Sigh...
  */
 
 Const int groundtable[] =
@@ -486,7 +486,7 @@
 CASE_GROUND_STATE,
 CASE_GROUND_STATE,
 /*     `               a               b               c       */
-CASE_GROUND_STATE,
+CASE_HPA,
 CASE_GROUND_STATE,
 CASE_GROUND_STATE,
 CASE_DA1,
@@ -498,7 +498,7 @@
 /*     h               i               j               k       */
 CASE_SET,
 CASE_GROUND_STATE,
-CASE_HPA,
+CASE_GROUND_STATE,
 CASE_GROUND_STATE,
 /*     l               m               n               o       */
 CASE_RST,
@@ -511,7 +511,7 @@
 CASE_DECSTBM,
 CASE_DECSC,
 /*     t               u               v               w       */
-CASE_GROUND_STATE,
+CASE_XTERM_WINOPS,
 CASE_DECRC,
 CASE_GROUND_STATE,
 CASE_GROUND_STATE,
@@ -1068,8 +1068,7 @@
 CASE_IGNORE,
 CASE_IGNORE,
 CASE_IGNORE,
-/*     ,
-       -               .               /       */
+/*     ,               -               .               /       */
 CASE_IGNORE,
 CASE_IGNORE,
 CASE_IGNORE,
Index: VTparse.def
--- xterm+/VTparse.def  Mon Jul  8 12:42:24 1996
+++ xterm_a/VTparse.def Wed Jul 17 19:57:24 1996
@@ -79,3 +79,4 @@
 CASE_HP_BUGGY_LL
 CASE_HPA
 CASE_VPA
+CASE_XTERM_WINOPS
Index: VTparse.h
--- xterm+/VTparse.h    Mon Jul  8 12:42:24 1996
+++ xterm_a/VTparse.h   Wed Jul 17 19:57:24 1996
@@ -109,3 +109,4 @@
 #define CASE_HP_BUGGY_LL 70
 #define CASE_HPA 71
 #define CASE_VPA 72
+#define CASE_XTERM_WINOPS 73
Index: charproc.c
--- xterm+/charproc.c   Mon Jul  8 12:42:24 1996
+++ xterm_a/charproc.c  Thu Jul 18 21:39:16 1996
@@ -123,6 +123,7 @@
 static int set_character_class PROTO((char *s));
 static void DoSetSelectedFont PROTO_XT_SEL_CB_ARGS;
 static void FromAlternate PROTO((TScreen *screen));
+static void RequestResize PROTO((XtermWidget termw, int rows, int cols, int text));
 static void SwitchBufs PROTO((TScreen *screen));
 static void ToAlternate PROTO((TScreen *screen));
 static void VTGraphicsOrNoExpose PROTO((XEvent *event));
@@ -136,10 +137,12 @@
 static void dotext PROTO((TScreen *screen, unsigned flags, int charset, Char *buf, Char *ptr, unsigned fg, unsigned bg));
 static void dpmodes PROTO((XtermWidget termw, void (*func)(unsigned *p, int mask)));
 static void restoremodes PROTO((XtermWidget termw));
+static void report_win_label PROTO((TScreen *screen, int code, XTextProperty *text, Status ok));
 static void savemodes PROTO((XtermWidget termw));
 static void set_vt_box PROTO((TScreen *screen));
 static void unparseputn PROTO((unsigned int n, int fd));
 static void update_font_info PROTO((TScreen *screen, Bool doresize));
+static void window_ops PROTO((XtermWidget termw));
 
 #define        DEFAULT         -1
 #define        TEXT_BUF_SIZE   256
@@ -1435,6 +1438,11 @@
                        restoremodes(term);
                        parsestate = groundtable;
                        break;
+
+               case CASE_XTERM_WINOPS:
+                       window_ops(term);
+                       parsestate = groundtable;
+                       break;
                }
        }
 }
@@ -1953,28 +1961,8 @@
                                CursorSet(screen, 0, 0, termw->flags);
                                if((j = func == bitset ? 132 : 80) !=
                                 ((termw->flags & IN132COLUMNS) ? 132 : 80) ||
-                                j != screen->max_col + 1) {
-                                       Dimension replyWidth, replyHeight;
-                                       XtGeometryResult status;
-
-                                       status = XtMakeResizeRequest (
-                                           (Widget) termw, 
-                                           (Dimension) FontWidth(screen) * j
-                                               + 2*screen->border
-                                               + screen->scrollbar,
-                                           (Dimension) FontHeight(screen)
-                                               * (screen->max_row + 1)
-                                               + 2 * screen->border,
-                                           &replyWidth, &replyHeight);
-
-                                       if (status == XtGeometryYes ||
-                                           status == XtGeometryDone) {
-                                           ScreenResize (&termw->screen,
-                                                         replyWidth,
-                                                         replyHeight,
-                                                         &termw->flags);
-                                       }
-                               }
+                                j != screen->max_col + 1)
+                                       RequestResize(termw, 0, j, TRUE);
                                (*func)(&termw->flags, IN132COLUMNS);
                        }
                        break;
@@ -2181,27 +2169,8 @@
                                CursorSet(screen, 0, 0, termw->flags);
                                if((j = (screen->save_modes[1] & IN132COLUMNS)
                                 ? 132 : 80) != ((termw->flags & IN132COLUMNS)
-                                ? 132 : 80) || j != screen->max_col + 1) {
-                                       Dimension replyWidth, replyHeight;
-                                       XtGeometryResult status;
-                                       status = XtMakeResizeRequest (
-                                           (Widget) termw,
-                                           (Dimension) FontWidth(screen) * j 
-                                               + 2*screen->border
-                                               + screen->scrollbar,
-                                           (Dimension) FontHeight(screen)
-                                               * (screen->max_row + 1)
-                                               + 2*screen->border,
-                                           &replyWidth, &replyHeight);
-
-                                       if (status == XtGeometryYes ||
-                                           status == XtGeometryDone) {
-                                           ScreenResize (&termw->screen,
-                                                         replyWidth,
-                                                         replyHeight,
-                                                         &termw->flags);
-                                       }
-                               }
+                                ? 132 : 80) || j != screen->max_col + 1)
+                                       RequestResize(termw, 0, j, TRUE);
                                termw->flags &= ~IN132COLUMNS;
                                termw->flags |= screen->save_modes[1] &
                                 IN132COLUMNS;
@@ -2290,6 +2259,173 @@
 }
 
 /*
+ * Report window label (icon or title) in dtterm protocol
+ * ESC ] code label ESC backslash
+ */
+static void
+report_win_label(screen, code, text, ok)
+       TScreen *screen;
+       int code;
+       XTextProperty *text;
+       Status ok;
+{
+       char **list;
+       int length = 0;
+
+       reply.a_type = ESC;
+       unparseputc(ESC, screen->respond);
+       unparseputc(']', screen->respond);
+       unparseputc(code, screen->respond);
+
+       if (ok
+        && XTextPropertyToStringList(text, &list, &length)) {
+               int n, c;
+               for (n = 0; n < length; n++) {
+                       char *s = list[n];
+                       while ((c = *s++) != '\0')
+                               unparseputc(c, screen->respond);
+               }
+               XFreeStringList(list);
+       }
+
+       unparseputc(ESC, screen->respond);
+       unparseputc('\\', screen->respond);
+}
+
+/*
+ * Window operations (from CDE dtterm description)
+ */
+static void
+window_ops(termw)
+    XtermWidget termw;
+{
+       register TScreen        *screen = &termw->screen;
+       XWindowChanges values;
+       XWindowAttributes win_attrs;
+       XTextProperty text;
+       unsigned int value_mask;
+       Position x, y;
+
+       switch (param[0]) {
+       case 1:         /* Restore (de-iconify) window */
+               XMapWindow(screen->display,
+                       VShellWindow);
+               break;
+
+       case 2:         /* Minimize (iconify) window */
+               XIconifyWindow(screen->display,
+                       VShellWindow,
+                       DefaultScreen(screen->display));
+               break;
+
+       case 3:         /* Move the window to the given position */
+               values.x   = param[1];
+               values.y   = param[2];
+               value_mask = (CWX | CWY);
+               XReconfigureWMWindow(
+                       screen->display,
+                       VShellWindow,
+                       DefaultScreen(screen->display),
+                       value_mask,
+                       &values);
+               break;
+
+       case 4:         /* Resize the window to given size in pixels */
+               RequestResize(termw, param[1], param[2], FALSE);
+               break;
+
+       case 5:         /* Raise the window to the front of the stack */
+               XRaiseWindow(screen->display, VShellWindow);
+               break;
+
+       case 6:         /* Lower the window to the bottom of the stack */
+               XLowerWindow(screen->display, VShellWindow);
+               break;
+
+       case 7:         /* Refresh the window */
+               Redraw();
+               break;
+
+       case 8:         /* Resize the text-area, in characters */
+               RequestResize(termw, param[1], param[2], TRUE);
+               break;
+
+       case 11:        /* Report the window's state */
+               XGetWindowAttributes(screen->display,
+                       VWindow(screen),
+                       &win_attrs);
+               reply.a_type = CSI;
+               reply.a_pintro = 0;
+               reply.a_nparam = 1;
+               reply.a_param[0] = (win_attrs.map_state == IsViewable) ? 1 : 2;
+               reply.a_inters = 0;
+               reply.a_final  = 't';
+               unparseseq(&reply, screen->respond);
+               break;
+
+       case 13:        /* Report the window's position */
+               XtTranslateCoords(toplevel, 0, 0, &x, &y);
+               reply.a_type = CSI;
+               reply.a_pintro = 0;
+               reply.a_nparam = 3;
+               reply.a_param[0] = 3;
+               reply.a_param[1] = x;
+               reply.a_param[2] = y;
+               reply.a_inters = 0;
+               reply.a_final  = 't';
+               unparseseq(&reply, screen->respond);
+               break;
+
+       case 14:        /* Report the window's size in pixels */
+               XGetWindowAttributes(screen->display,
+                       VWindow(screen),
+                       &win_attrs);
+               reply.a_type = CSI;
+               reply.a_pintro = 0;
+               reply.a_nparam = 3;
+               reply.a_param[0] = 4;
+               /*FIXME: find if dtterm uses
+                *      win_attrs.height or Height
+                *      win_attrs.width  or Width
+                */
+               reply.a_param[1] = Height(screen);
+               reply.a_param[2] = Width(screen);
+               reply.a_inters = 0;
+               reply.a_final  = 't';
+               unparseseq(&reply, screen->respond);
+               break;
+
+       case 18:        /* Report the text's size in characters */
+               reply.a_type = CSI;
+               reply.a_pintro = 0;
+               reply.a_nparam = 3;
+               reply.a_param[0] = 8;
+               reply.a_param[1] = screen->max_row + 1;
+               reply.a_param[2] = screen->max_col + 1;
+               reply.a_inters = 0;
+               reply.a_final  = 't';
+               unparseseq(&reply, screen->respond);
+               break;
+
+       case 20:        /* Report the icon's label */
+               report_win_label(screen, 'L', &text,
+                       XGetWMIconName(
+                               screen->display,
+                               VShellWindow,
+                               &text));
+               break;
+
+       case 21:        /* Report the window's title */
+               report_win_label(screen, 'l', &text,
+                       XGetWMName(
+                               screen->display,
+                               VShellWindow,
+                               &text));
+               break;
+       }
+}
+
+/*
  * set a bit in a word given a pointer to the word and a mask.
  */
 static void bitset(p, mask)
@@ -2542,6 +2678,52 @@
                    &term->flags);
 }
 
+
+static void RequestResize(termw, rows, cols, text)
+       XtermWidget termw;
+       int rows;
+       int cols;
+       int text;
+{
+       register TScreen        *screen = &termw->screen;
+       Dimension replyWidth, replyHeight;
+       Dimension askedWidth, askedHeight;
+       XtGeometryResult status;
+
+       askedWidth  = cols;
+       askedHeight = rows;
+       if (text) {
+               if (askedHeight <= 0)
+                       askedHeight = screen->max_row + 1;
+               if (askedWidth <= 0)
+                       askedWidth = screen->max_col + 1;
+
+               askedWidth  *= FontWidth(screen);
+               askedHeight *= FontHeight(screen);
+
+               askedWidth  += (2 * screen->border) + screen->scrollbar;
+               askedHeight += (2 * screen->border);
+
+       } else {
+               if (askedHeight <= 0)
+                       askedHeight = FullHeight(screen);
+               if (askedWidth <= 0)
+                       askedWidth = FullWidth(screen);
+       }
+
+       status = XtMakeResizeRequest (
+           (Widget) termw, 
+            askedWidth,  askedHeight,
+           &replyWidth, &replyHeight);
+
+       if (status == XtGeometryYes ||
+           status == XtGeometryDone) {
+           ScreenResize (&termw->screen,
+                         replyWidth,
+                         replyHeight,
+                         &termw->flags);
+       }
+}
                                
 extern Atom wm_delete_window;  /* for ICCCM delete window */
 
Index: ptyx.h
--- xterm+/ptyx.h       Mon Jun 10 13:03:46 1996
+++ xterm_a/ptyx.h      Thu Jul 18 21:22:57 1996
@@ -591,13 +591,17 @@
  * term->flags and screen->save_modes.  This need only fit in an unsigned.
  */
 
-#define        ATTRIBUTES      0x67    /* mask: user-visible attributes */
 /* global flags and character flags (visible character attributes) */
 #define INVERSE                0x01    /* invert the characters to be output */
 #define UNDERLINE      0x02    /* true if underlining */
 #define BOLD           0x04
+/* global flags (also character attributes) */
+#define BG_COLOR       0x08  /* true if background set */
+#define FG_COLOR       0x10  /* true if foreground set */
+
 /* character flags (internal attributes) */
-#define LINEWRAPPED    0x08    /* used on the first character in a
+#define PROTECTED      0x20    /* a character is drawn that cannot be erased */
+#define LINEWRAPPED    0x40    /* used on the first character in a
                                 * line to indicate that it wraps onto
                                 * the next line so we can tell the
                                 * difference between lines that have
@@ -605,12 +609,12 @@
                                 * ended naturally with a CR at column
                                 * max_col.
                                 */
-#define CHARDRAWN      0x10    /* a character has been drawn here on the
+#define CHARDRAWN      0x80    /* a character has been drawn here on the
                                   screen.  Used to distinguish blanks from
                                   empty parts of the screen when selecting */
-/* global flags */
-#define BG_COLOR       0x20  /* true if background set */
-#define FG_COLOR       0x40  /* true if foreground set */
+
+                       /* mask: user-visible attributes */
+#define        ATTRIBUTES      (INVERSE|UNDERLINE|BOLD|BG_COLOR|FG_COLOR|PROTECTED)
 
 #define WRAPAROUND     0x400   /* true if auto wraparound mode */
 #define        REVERSEWRAP     0x800   /* true if reverse wraparound mode */
Index: screen.c
--- xterm+/screen.c     Sun Feb 18 12:46:26 1996
+++ xterm_a/screen.c    Thu Jul 18 21:41:51 1996
@@ -597,14 +597,18 @@
 
        /* clear the right and bottom internal border because of NorthWest
           gravity might have left junk on the right and bottom edges */
-       XClearArea (screen->display, tw,
-                   width - screen->border, 0,                /* right edge */
-                   screen->border, height,           /* from top to bottom */
-                   False);
-       XClearArea (screen->display, tw, 
-                   0, height - screen->border,                   /* bottom */
-                   width, screen->border,         /* all across the bottom */
-                   False);
+       if (width >= FullWidth(screen)) {
+               XClearArea (screen->display, tw,
+                           FullWidth(screen), 0,             /* right edge */
+                           0, height,                /* from top to bottom */
+                           False);
+       }
+       if (height >= FullHeight(screen)) {
+               XClearArea (screen->display, tw, 
+                       0, FullHeight(screen),                    /* bottom */
+                       width, 0,                  /* all across the bottom */
+                       False);
+       }
 
        /* round so that it is unlikely the screen will change size on  */
        /* small mouse movements.                                       */
Index: termcap
--- xterm+/termcap      Mon Jul  8 12:42:24 1996
+++ xterm_a/termcap     Wed Jul 17 19:57:24 1996
@@ -21,7 +21,7 @@
        :ho=\E[H:\
        :im=\E[4h:ei=\E[4l:mi:\
        :ks=\E[?1h\E=:ke=\E[?1l\E>:\
-       :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\
+       :k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:\
        :k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:\
        :k;=\E[21~:F1=\E[23~:F2=\E[24~:\
        :kn#12:\
@@ -38,7 +38,7 @@
        :ti=\E7\E[?47h:te=\E[2J\E[?47l\E8:\
        :vi=\E[?25l:ve=\E[?25h:\
        :up=\E[A:us=\E[4m:ue=\E[24m:xn:\
-       :ut:Co#8:NC#7:op=\E100m:AB=\E[4%dm:AF=\E[3%dm:
+       :ut:Co#8:op=\E100m:AB=\E[4%dm:AF=\E[3%dm:
 v2|xterm-65|xterm with tall window 65x80 (X Window System):\
        :li#65:tc=xterm:
 vb|xterm-bold|xterm with bold instead of underline (X Window System):\
Index: terminfo
--- xterm+/terminfo     Mon Jul  8 12:42:24 1996
+++ xterm_a/terminfo    Wed Jul 17 19:57:24 1996
@@ -11,8 +11,8 @@
        xenl,
        colors#8,
        cols#80,
+       it#8, 
        lines#24,
-       ncv#7,
        pairs#64,
        acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G,
@@ -31,31 +31,41 @@
        cup=\E[%i%p1%d;%p2%dH,
        cuu=\E[%p1%dA,
        cuu1=\E[A,
+       cvvis=\E[?25h,
        dch=\E[%p1%dP,
        dch1=\E[P,
        dl=\E[%p1%dM,
        dl1=\E[M,
        ed=\E[J,
        el=\E[K,
-       el1=\E[1K$<3>,
+       el1=\E[1K,
        enacs=\E(B\E)0,
+       flash=\E[?5h\E[?5l,
        home=\E[H,
-       hpa=\E[%i%p1%dj,
+       hpa=\E[%i%p1%dG,
        ht=^I,
        hts=\EH,
+       ich=\E[%p1%d@,
+       ich1=\E[@,
        il=\E[%p1%dL,
        il1=\E[L,
        ind=^J,
        is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
-       kbeg=\E[E,
+       ka1=\EOw,
+       ka3=\EOu,
+       kb2=\EOy,
+       kbeg=\EOE,
        kbs=^H,
+       kc1=\EOq,
+       kc3=\EOs,
        kcub1=\EOD,
        kcud1=\EOB,
        kcuf1=\EOC,
        kcuu1=\EOA,
-       kdch1=\E[3~,
+       kdch1=\177,
        kend=\EOF,
-       kf1=\EOP,
+       kent=\EOM,
+       kf1=\E[11~,
        kf10=\E[21~,
        kf11=\E[23~,
        kf12=\E[24~,
@@ -66,10 +76,10 @@
        kf17=\E[31~,
        kf18=\E[32~,
        kf19=\E[33~,
-       kf2=\EOQ,
+       kf2=\E[12~,
        kf20=\E[34~,
-       kf3=\EOR,
-       kf4=\EOS,
+       kf3=\E[13~,
+       kf4=\E[14~,
        kf5=\E[15~,
        kf6=\E[17~,
        kf7=\E[18~,
@@ -78,21 +88,24 @@
        kfnd=\E[1~,
        khome=\EOH,
        kich1=\E[2~,
+       kmous=\E[M,
        knp=\E[6~,
        kpp=\E[5~,
        kslt=\E[4~,
        meml=\El,
        memu=\Em,
-       op=\E[100m,
+       op=\E[39;49m,
        rc=\E8,
        rev=\E[7m,
        ri=\EM,
        rmacs=^O,
+       rmam=\E[?7l,
        rmcup=\E[2J\E[?47l\E8,
        rmir=\E[4l,
        rmkx=\E[?1l\E>,
        rmso=\E[27m,
        rmul=\E[24m,
+       rs1=^O,
        rs2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
        sc=\E7,
        setab=\E[4%p1%dm,
@@ -102,6 +115,7 @@
        sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;,
        sgr0=\E[m\017,
        smacs=^N,
+       smam=\E[?7h,
        smcup=\E7\E[?47h,
        smir=\E[4h,
        smkx=\E[?1h\E=,
@@ -113,8 +127,8 @@
        lines#65,
        use=xterm,
 xterm-bold|xterm with bold instead of underline (X Window System),
-       smul=\E[1m,
        rmul=\E[22m,
+       smul=\E[1m,
        use=xterm,
 xtermm|monochrome xterm (X Window System),
        colors@,
@@ -128,8 +142,8 @@
        sgr@,
        use=xterm,
 xterm-boldso|xterm with bold for standout (X Window System),
-       smso=\E[1m,
        rmso=\E[22m,
+       smso=\E[1m,
        use=xterm,
 #
 # vi may work better with this entry, because vi
Index: util.c
--- xterm+/util.c       Sun Jun 30 12:03:00 1996
+++ xterm_a/util.c      Thu Jul 18 21:27:03 1996
@@ -1207,7 +1207,7 @@
        int flags;
        int color;
 {
-       Pixel fg = (flags & FG_COLOR)
+       Pixel fg = (flags & FG_COLOR) && (color >= 0)
                        ? term->screen.Acolors[color]
                        : term->screen.foreground;
 
@@ -1223,7 +1223,7 @@
        int flags;
        int color;
 {
-       Pixel bg = (flags & BG_COLOR)
+       Pixel bg = (flags & BG_COLOR) && (color >= 0)
                        ? term->screen.Acolors[color]
                        : term->core.background_pixel;