Module Name:    xsrc
Committed By:   mrg
Date:           Wed Mar 14 06:04:47 UTC 2018

Modified Files:
        xsrc/external/mit/xterm/dist: XTerm.ad fontutils.c misc.c ptyx.h
            xterm.man

Log Message:
merge xterm 330.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 xsrc/external/mit/xterm/dist/XTerm.ad
cvs rdiff -u -r1.6 -r1.7 xsrc/external/mit/xterm/dist/fontutils.c
cvs rdiff -u -r1.14 -r1.15 xsrc/external/mit/xterm/dist/misc.c
cvs rdiff -u -r1.13 -r1.14 xsrc/external/mit/xterm/dist/ptyx.h
cvs rdiff -u -r1.15 -r1.16 xsrc/external/mit/xterm/dist/xterm.man

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xterm/dist/XTerm.ad
diff -u xsrc/external/mit/xterm/dist/XTerm.ad:1.9 xsrc/external/mit/xterm/dist/XTerm.ad:1.10
--- xsrc/external/mit/xterm/dist/XTerm.ad:1.9	Wed Mar  8 02:55:12 2017
+++ xsrc/external/mit/xterm/dist/XTerm.ad	Wed Mar 14 06:04:47 2018
@@ -1,4 +1,4 @@
-! $XTermId: XTerm.ad,v 1.101 2016/01/28 02:15:29 tom Exp $
+! $XTermId: XTerm.ad,v 1.102 2016/12/22 02:07:39 tom Exp $
 ! -----------------------------------------------------------------------------
 ! this file is part of xterm
 !
@@ -135,6 +135,7 @@
 
 *fontMenu*allow-color-ops*Label:	Allow Color Ops
 *fontMenu*allow-font-ops*Label:	Allow Font Ops
+*fontMenu*allow-mouse-ops*Label:	Allow Mouse Ops
 *fontMenu*allow-tcap-ops*Label:	Allow Termcap Ops
 *fontMenu*allow-title-ops*Label:	Allow Title Ops
 *fontMenu*allow-window-ops*Label:	Allow Window Ops

Index: xsrc/external/mit/xterm/dist/fontutils.c
diff -u xsrc/external/mit/xterm/dist/fontutils.c:1.6 xsrc/external/mit/xterm/dist/fontutils.c:1.7
--- xsrc/external/mit/xterm/dist/fontutils.c:1.6	Wed Mar  8 02:55:12 2017
+++ xsrc/external/mit/xterm/dist/fontutils.c	Wed Mar 14 06:04:47 2018
@@ -1,7 +1,7 @@
-/* $XTermId: fontutils.c,v 1.453 2016/06/03 08:56:53 tom Exp $ */
+/* $XTermId: fontutils.c,v 1.531 2017/06/20 09:10:19 tom Exp $ */
 
 /*
- * Copyright 1998-2015,2016 by Thomas E. Dickey
+ * Copyright 1998-2016,2017 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -120,6 +120,13 @@ typedef struct {
     char *end;
 } FontNameProperties;
 
+#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
+static Boolean merge_sublist(char ***, char **);
+#endif
+
+static void save2FontList(XtermWidget, const char *, XtermFontNames *,
+			  VTFontEnum, const char *, Bool);
+
 #if OPT_RENDERFONT
 static void fillInFaceSize(XtermWidget, int);
 #endif
@@ -178,20 +185,18 @@ setupPackedFonts(XtermWidget xw)
     Bool value = False;
 
 #if OPT_RENDERFONT
-#define MIXED(name) screen->name[fontnum].map.mixed
     if (xw->work.render_font == True) {
-	int fontnum = screen->menu_font_number;
+	int e;
 
-	screen->allow_packing = (Boolean) (MIXED(renderFontNorm)
-					   || MIXED(renderFontBold)
-					   || MIXED(renderFontItal)
-#if OPT_RENDERWIDE
-					   || MIXED(renderWideNorm)
-					   || MIXED(renderWideBold)
-					   || MIXED(renderWideItal)
-#endif
-	    );
-#undef MIXED
+	for (e = 0; e < fMAX; ++e) {
+	    XTermXftFonts *data = getMyXftFont(xw, e, screen->menu_font_number);
+	    if (data != 0) {
+		if (data->map.mixed) {
+		    screen->allow_packing = True;
+		    break;
+		}
+	    }
+	}
     }
 #endif /* OPT_RENDERFONT */
 
@@ -455,11 +460,58 @@ bold_font_name(FontNameProperties *props
 
 #if OPT_WIDE_ATTRS
 static char *
-italic_font_name(FontNameProperties *props, int use_average_width)
+italic_font_name(FontNameProperties *props, const char *slant)
 {
     FontNameProperties myprops = *props;
-    myprops.slant = "o";
-    return derive_font_name(&myprops, props->weight, use_average_width, props->end);
+    myprops.slant = slant;
+    return derive_font_name(&myprops, props->weight, myprops.average_width, props->end);
+}
+
+static Boolean
+open_italic_font(XtermWidget xw, int n, FontNameProperties *fp, XTermFonts * data)
+{
+    static const char *slant[] =
+    {
+	"o",
+	"i"
+    };
+    char *name;
+    Cardinal pass;
+    Boolean result = False;
+
+    for (pass = 0; pass < XtNumber(slant); ++pass) {
+	if ((name = italic_font_name(fp, slant[pass])) != 0) {
+	    TRACE(("open_italic_font %s %s\n",
+		   whichFontEnum((VTFontEnum) n), name));
+	    if (xtermOpenFont(xw, name, data, False)) {
+		result = (data->fs != 0);
+#if OPT_REPORT_FONTS
+		if (resource.reportFonts) {
+		    printf("opened italic version of %s:\n\t%s\n",
+			   whichFontEnum(n),
+			   name);
+		}
+#endif
+	    }
+	    free(name);
+	    if (result)
+		break;
+	}
+    }
+#if OPT_TRACE
+    if (result) {
+	XFontStruct *fs = data->fs;
+	if (fs != 0) {
+	    TRACE(("...actual size %dx%d (ascent %d, descent %d)\n",
+		   fs->ascent +
+		   fs->descent,
+		   fs->max_bounds.width,
+		   fs->ascent,
+		   fs->descent));
+	}
+    }
+#endif
+    return result;
 }
 #endif
 
@@ -489,8 +541,9 @@ widebold_font_name(FontNameProperties *p
  * fonts we double the pixel-size and Y-resolution
  */
 char *
-xtermSpecialFont(TScreen *screen, unsigned attr_flags, unsigned draw_flags, unsigned chrset)
+xtermSpecialFont(XtermWidget xw, unsigned attr_flags, unsigned draw_flags, unsigned chrset)
 {
+    TScreen *screen = TScreenOf(xw);
 #if OPT_TRACE
     static char old_spacing[80];
     static FontNameProperties old_props;
@@ -502,7 +555,8 @@ xtermSpecialFont(TScreen *screen, unsign
     int res_x;
     int res_y;
 
-    props = get_font_name_props(screen->display, screen->fnts[fNorm].fs, 0);
+    props = get_font_name_props(screen->display,
+				getNormalFont(screen, fNorm)->fs, 0);
     if (props == 0)
 	return result;
 
@@ -628,7 +682,9 @@ comparable_metrics(XFontStruct *normal, 
 #define DATA "comparable_metrics: "
     int result = 0;
 
-    if (normal->all_chars_exist) {
+    if (normal == 0 || bold == 0) {
+	;
+    } else if (normal->all_chars_exist) {
 	if (bold->all_chars_exist) {
 	    result = 1;
 	} else {
@@ -657,17 +713,22 @@ static int
 same_font_size(XtermWidget xw, XFontStruct *nfs, XFontStruct *bfs)
 {
     TScreen *screen = TScreenOf(xw);
-    TRACE(("same_font_size height %d/%d, min %d/%d max %d/%d\n",
-	   nfs->ascent + nfs->descent,
-	   bfs->ascent + bfs->descent,
-	   nfs->min_bounds.width, bfs->min_bounds.width,
-	   nfs->max_bounds.width, bfs->max_bounds.width));
-    return screen->free_bold_box
-	|| ((nfs->ascent + nfs->descent) == (bfs->ascent + bfs->descent)
-	    && (nfs->min_bounds.width == bfs->min_bounds.width
-		|| nfs->min_bounds.width == bfs->min_bounds.width + 1)
-	    && (nfs->max_bounds.width == bfs->max_bounds.width
-		|| nfs->max_bounds.width == bfs->max_bounds.width + 1));
+    int result = 0;
+
+    if (nfs != 0 && bfs != 0) {
+	TRACE(("same_font_size height %d/%d, min %d/%d max %d/%d\n",
+	       nfs->ascent + nfs->descent,
+	       bfs->ascent + bfs->descent,
+	       nfs->min_bounds.width, bfs->min_bounds.width,
+	       nfs->max_bounds.width, bfs->max_bounds.width));
+	result = screen->free_bold_box
+	    || ((nfs->ascent + nfs->descent) == (bfs->ascent + bfs->descent)
+		&& (nfs->min_bounds.width == bfs->min_bounds.width
+		    || nfs->min_bounds.width == bfs->min_bounds.width + 1)
+		&& (nfs->max_bounds.width == bfs->max_bounds.width
+		    || nfs->max_bounds.width == bfs->max_bounds.width + 1));
+    }
+    return result;
 }
 
 /*
@@ -775,7 +836,22 @@ xtermFontName(const char *normal)
     static VTFontNames data;
     FREE_STRING(data.f_n);
     memset(&data, 0, sizeof(data));
-    data.f_n = x_strdup(normal);
+    if (normal)
+	data.f_n = x_strdup(normal);
+    return &data;
+}
+
+const VTFontNames *
+defaultVTFontNames(XtermWidget xw)
+{
+    static VTFontNames data;
+    memset(&data, 0, sizeof(data));
+    data.f_n = DefaultFontN(xw);
+    data.f_b = DefaultFontB(xw);
+#if OPT_WIDE_CHARS
+    data.f_w = DefaultFontW(xw);
+    data.f_wb = DefaultFontWB(xw);
+#endif
     return &data;
 }
 
@@ -797,6 +873,39 @@ cache_menu_font_name(TScreen *screen, in
     }
 }
 
+typedef struct _cannotFont {
+    struct _cannotFont *next;
+    char *where;
+} CannotFont;
+
+static void
+cannotFont(XtermWidget xw, const char *who, const char *what, const char *where)
+{
+    static CannotFont *ignored;
+    CannotFont *list;
+
+    switch (xw->misc.fontWarnings) {
+    case fwNever:
+	return;
+    case fwResource:
+	for (list = ignored; list != 0; list = list->next) {
+	    if (!strcmp(where, list->where)) {
+		return;
+	    }
+	}
+	if ((list = TypeMalloc(CannotFont)) != 0) {
+	    list->where = x_strdup(where);
+	    list->next = ignored;
+	    ignored = list;
+	}
+	break;
+    case fwAlways:
+	break;
+    }
+    TRACE(("OOPS: cannot %s%s%s font \"%s\"\n", who, *what ? " " : "", what, where));
+    xtermWarning("cannot %s%s%s font \"%s\"\n", who, *what ? " " : "", what, where);
+}
+
 /*
  * Open the given font and verify that it is non-empty.  Return a null on
  * failure.
@@ -805,7 +914,6 @@ Bool
 xtermOpenFont(XtermWidget xw,
 	      const char *name,
 	      XTermFonts * result,
-	      fontWarningTypes warn,
 	      Bool force)
 {
     Bool code = False;
@@ -815,44 +923,36 @@ xtermOpenFont(XtermWidget xw,
 	if ((result->fs = XLoadQueryFont(screen->display, name)) != 0) {
 	    code = True;
 	    if (EmptyFont(result->fs)) {
-		(void) xtermCloseFont(xw, result);
+		xtermCloseFont(xw, result);
 		code = False;
 	    } else {
 		result->fn = x_strdup(name);
 	    }
 	} else if (XmuCompareISOLatin1(name, DEFFONT) != 0) {
-	    if (warn <= xw->misc.fontWarnings
+	    if (result->warn <= xw->misc.fontWarnings
 #if OPT_RENDERFONT
 		&& !UsingRenderFont(xw)
 #endif
 		) {
 		TRACE(("OOPS: cannot load font %s\n", name));
-		xtermWarning("cannot load font '%s'\n", name);
-#if OPT_RENDERFONT
-		/*
-		 * Do a sanity check in case someone's mixed up xterm with
-		 * one of those programs that read their resource data from
-		 * xterm's namespace.
-		 */
-		if (strchr(name, ':') != 0 || strchr(name, '=') != 0) {
-		    xtermWarning("Use the \"-fa\" option for the Xft fonts\n");
-		}
-#endif
+		cannotFont(xw, "load", "", name);
 	    } else {
 		TRACE(("xtermOpenFont: cannot load font '%s'\n", name));
 	    }
 	    if (force) {
-		code = xtermOpenFont(xw, DEFFONT, result, fwAlways, True);
+		result->warn = fwAlways;
+		code = xtermOpenFont(xw, DEFFONT, result, True);
 	    }
 	}
     }
+    result->warn = fwAlways;
     return code;
 }
 
 /*
  * Close the font and free the font info.
  */
-XTermFonts *
+void
 xtermCloseFont(XtermWidget xw, XTermFonts * fnt)
 {
     if (fnt != 0 && fnt->fs != 0) {
@@ -862,7 +962,6 @@ xtermCloseFont(XtermWidget xw, XTermFont
 	XFreeFont(screen->display, fnt->fs);
 	xtermFreeFontInfo(fnt);
     }
-    return 0;
 }
 
 /*
@@ -912,6 +1011,7 @@ xtermCopyFontInfo(XTermFonts * target, X
     target->flags = source->flags;
     target->fn = x_strdup(source->fn);
     target->fs = source->fs;
+    target->warn = source->warn;
 }
 
 void
@@ -942,7 +1042,7 @@ static void
 reportOneVTFont(const char *tag,
 		XTermFonts * fnt)
 {
-    if (!IsEmpty(fnt->fn)) {
+    if (!IsEmpty(fnt->fn) && fnt->fs != 0) {
 	XFontStruct *fs = fnt->fs;
 	unsigned first_char = 0;
 	unsigned last_char = 0;
@@ -998,54 +1098,66 @@ reportVTFontInfo(XtermWidget xw, int fon
 	} else {
 	    printf("Loaded VTFonts(default)\n");
 	}
-	reportOneVTFont("fNorm", &screen->fnts[fNorm]);
-	reportOneVTFont("fBold", &screen->fnts[fBold]);
+
+	reportOneVTFont("fNorm", getNormalFont(screen, fNorm));
+	reportOneVTFont("fBold", getNormalFont(screen, fBold));
 #if OPT_WIDE_CHARS
-	reportOneVTFont("fWide", &screen->fnts[fWide]);
-	reportOneVTFont("fWBold", &screen->fnts[fWBold]);
+	reportOneVTFont("fWide", getNormalFont(screen, fWide));
+	reportOneVTFont("fWBold", getNormalFont(screen, fWBold));
 #endif
     }
 }
 #endif
 
+typedef XTermFonts *(*MyGetFont) (TScreen *, int);
+
 void
-xtermUpdateFontGCs(XtermWidget xw, XTermFonts * fnts)
+xtermUpdateFontGCs(XtermWidget xw, Bool italic)
 {
     TScreen *screen = TScreenOf(xw);
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+    MyGetFont myfunc = italic ? getItalicFont : getNormalFont;
+#else
+    MyGetFont myfunc = getNormalFont;
+#endif
     VTwin *win = WhichVWin(screen);
     Pixel new_normal = getXtermForeground(xw, xw->flags, xw->cur_foreground);
     Pixel new_revers = getXtermBackground(xw, xw->flags, xw->cur_background);
 
+    (void) italic;
+
     setCgsFore(xw, win, gcNorm, new_normal);
     setCgsBack(xw, win, gcNorm, new_revers);
-    setCgsFont(xw, win, gcNorm, &(fnts[fNorm]));
+    setCgsFont(xw, win, gcNorm, myfunc(screen, fNorm));
 
     copyCgs(xw, win, gcBold, gcNorm);
-    setCgsFont(xw, win, gcBold, &(fnts[fBold]));
+    setCgsFont(xw, win, gcBold, myfunc(screen, fBold));
 
     setCgsFore(xw, win, gcNormReverse, new_revers);
     setCgsBack(xw, win, gcNormReverse, new_normal);
-    setCgsFont(xw, win, gcNormReverse, &(fnts[fNorm]));
+    setCgsFont(xw, win, gcNormReverse, myfunc(screen, fNorm));
 
     copyCgs(xw, win, gcBoldReverse, gcNormReverse);
-    setCgsFont(xw, win, gcBoldReverse, &(fnts[fBold]));
+    setCgsFont(xw, win, gcBoldReverse, myfunc(screen, fBold));
 
     if_OPT_WIDE_CHARS(screen, {
-	if (fnts[fWide].fs != 0
-	    && fnts[fWBold].fs != 0) {
+	XTermFonts *wide_xx = myfunc(screen, fWide);
+	XTermFonts *bold_xx = myfunc(screen, fWBold);
+	if (wide_xx->fs != 0
+	    && bold_xx->fs != 0) {
 	    setCgsFore(xw, win, gcWide, new_normal);
 	    setCgsBack(xw, win, gcWide, new_revers);
-	    setCgsFont(xw, win, gcWide, &(fnts[fWide]));
+	    setCgsFont(xw, win, gcWide, wide_xx);
 
 	    copyCgs(xw, win, gcWBold, gcWide);
-	    setCgsFont(xw, win, gcWBold, &(fnts[fWBold]));
+	    setCgsFont(xw, win, gcWBold, bold_xx);
 
 	    setCgsFore(xw, win, gcWideReverse, new_revers);
 	    setCgsBack(xw, win, gcWideReverse, new_normal);
-	    setCgsFont(xw, win, gcWideReverse, &(fnts[fWide]));
+	    setCgsFont(xw, win, gcWideReverse, wide_xx);
 
 	    copyCgs(xw, win, gcWBoldReverse, gcWideReverse);
-	    setCgsFont(xw, win, gcWBoldReverse, &(fnts[fWBold]));
+	    setCgsFont(xw, win, gcWBoldReverse, bold_xx);
 	}
     });
 }
@@ -1068,6 +1180,219 @@ show_font_misses(const char *name, XTerm
 }
 #endif
 
+static Bool
+loadNormFP(XtermWidget xw,
+	   char **nameOutP,
+	   XTermFonts * infoOut,
+	   int fontnum)
+{
+    Bool status = True;
+
+    TRACE(("loadNormFP (%s)\n", NonNull(*nameOutP)));
+
+    if (!xtermOpenFont(xw,
+		       *nameOutP,
+		       infoOut,
+		       (fontnum == fontMenu_default))) {
+	/*
+	 * If we are opening the default font, and it happens to be missing,
+	 * force that to the compiled-in default font, e.g., "fixed".  If we
+	 * cannot open the font, disable it from the menu.
+	 */
+	if (fontnum != fontMenu_fontsel) {
+	    SetItemSensitivity(fontMenuEntries[fontnum].widget, False);
+	}
+	status = False;
+    }
+    return status;
+}
+
+static Bool
+loadBoldFP(XtermWidget xw,
+	   char **nameOutP,
+	   XTermFonts * infoOut,
+	   const char *nameRef,
+	   XTermFonts * infoRef,
+	   int fontnum)
+{
+    TScreen *screen = TScreenOf(xw);
+    Bool status = True;
+
+    TRACE(("loadBoldFP (%s)\n", NonNull(*nameOutP)));
+
+    if (!check_fontname(*nameOutP)) {
+	FontNameProperties *fp;
+	char *normal = x_strdup(nameRef);
+
+	fp = get_font_name_props(screen->display, infoRef->fs, &normal);
+	if (fp != 0) {
+	    *nameOutP = bold_font_name(fp, fp->average_width);
+	    if (!xtermOpenFont(xw, *nameOutP, infoOut, False)) {
+		free(*nameOutP);
+		*nameOutP = bold_font_name(fp, -1);
+		xtermOpenFont(xw, *nameOutP, infoOut, False);
+	    }
+	    TRACE(("...derived bold '%s'\n", NonNull(*nameOutP)));
+	}
+	if (fp == 0 || infoOut->fs == 0) {
+	    xtermCopyFontInfo(infoOut, infoRef);
+	    TRACE(("...cannot load a matching bold font\n"));
+	} else if (comparable_metrics(infoRef->fs, infoOut->fs)
+		   && same_font_size(xw, infoRef->fs, infoOut->fs)
+		   && got_bold_font(screen->display, infoOut->fs, *nameOutP)) {
+	    TRACE(("...got a matching bold font\n"));
+	    cache_menu_font_name(screen, fontnum, fBold, *nameOutP);
+	} else {
+	    xtermCloseFont2(xw, infoOut - fBold, fBold);
+	    *infoOut = *infoRef;
+	    TRACE(("...did not get a matching bold font\n"));
+	}
+	free(normal);
+    } else if (!xtermOpenFont(xw, *nameOutP, infoOut, False)) {
+	xtermCopyFontInfo(infoOut, infoRef);
+	TRACE(("...cannot load bold font '%s'\n", NonNull(*nameOutP)));
+    } else {
+	cache_menu_font_name(screen, fontnum, fBold, *nameOutP);
+    }
+
+    /*
+     * Most of the time this call to load the font will succeed, even if
+     * there is no wide font :  the X server doubles the width of the
+     * normal font, or similar.
+     *
+     * But if it did fail for some reason, then nevermind.
+     */
+    if (EmptyFont(infoOut->fs))
+	status = False;		/* can't use a 0-sized font */
+
+    if (!same_font_size(xw, infoRef->fs, infoOut->fs)
+	&& (is_fixed_font(infoRef->fs) && is_fixed_font(infoOut->fs))) {
+	TRACE(("...ignoring mismatched normal/bold fonts\n"));
+	xtermCloseFont2(xw, infoOut - fBold, fBold);
+	xtermCopyFontInfo(infoOut, infoRef);
+    }
+
+    return status;
+}
+
+#if OPT_WIDE_CHARS
+static Bool
+loadWideFP(XtermWidget xw,
+	   char **nameOutP,
+	   XTermFonts * infoOut,
+	   const char *nameRef,
+	   XTermFonts * infoRef,
+	   int fontnum)
+{
+    TScreen *screen = TScreenOf(xw);
+    FontNameProperties *fp;
+    Bool status = True;
+
+    TRACE(("loadWideFP (%s)\n", NonNull(*nameOutP)));
+
+    if (check_fontname(*nameOutP)) {
+	cache_menu_font_name(screen, fontnum, fWide, *nameOutP);
+    } else if (screen->utf8_fonts && !is_double_width_font(infoRef->fs)) {
+	char *normal = x_strdup(nameRef);
+	fp = get_font_name_props(screen->display, infoRef->fs, &normal);
+	if (fp != 0) {
+	    *nameOutP = wide_font_name(fp);
+	    TRACE(("...derived wide %s\n", NonNull(*nameOutP)));
+	    cache_menu_font_name(screen, fontnum, fWide, *nameOutP);
+	}
+	free(normal);
+    }
+
+    if (check_fontname(*nameOutP)) {
+	if (!xtermOpenFont(xw, *nameOutP, infoOut, False)) {
+	    xtermCopyFontInfo(infoOut, infoRef);
+	}
+    } else {
+	xtermCopyFontInfo(infoOut, infoRef);
+    }
+    return status;
+}
+
+static Bool
+loadWBoldFP(XtermWidget xw,
+	    char **nameOutP,
+	    XTermFonts * infoOut,
+	    const char *wideNameRef, XTermFonts * wideInfoRef,
+	    const char *boldNameRef, XTermFonts * boldInfoRef,
+	    int fontnum)
+{
+    TScreen *screen = TScreenOf(xw);
+    Bool status = True;
+    Boolean derived;
+    char *bold = NULL;
+
+    TRACE(("loadWBoldFP (%s)\n", NonNull(*nameOutP)));
+
+    derived = False;
+    if (!check_fontname(*nameOutP)) {
+	FontNameProperties *fp;
+	fp = get_font_name_props(screen->display, boldInfoRef->fs, &bold);
+	if (fp != 0) {
+	    *nameOutP = widebold_font_name(fp);
+	    derived = True;
+	}
+    }
+
+    if (check_fontname(*nameOutP)) {
+
+	if (xtermOpenFont(xw, *nameOutP, infoOut, False)
+	    && derived
+	    && !compatibleWideCounts(wideInfoRef->fs, infoOut->fs)) {
+	    xtermCloseFont2(xw, infoOut - fWBold, fWBold);
+	}
+
+	if (infoOut->fs == 0) {
+	    if (derived)
+		free(*nameOutP);
+	    if (IsEmpty(wideNameRef)) {
+		*nameOutP = x_strdup(boldNameRef);
+		xtermCopyFontInfo(infoOut, boldInfoRef);
+		TRACE(("...cannot load wide-bold, use bold %s\n",
+		       NonNull(boldNameRef)));
+	    } else {
+		*nameOutP = x_strdup(wideNameRef);
+		xtermCopyFontInfo(infoOut, wideInfoRef);
+		TRACE(("...cannot load wide-bold, use wide %s\n",
+		       NonNull(wideNameRef)));
+	    }
+	} else {
+	    TRACE(("...%s wide/bold %s\n",
+		   derived ? "derived" : "given",
+		   NonNull(*nameOutP)));
+	    cache_menu_font_name(screen, fontnum, fWBold, *nameOutP);
+	}
+    } else if (is_double_width_font(boldInfoRef->fs)) {
+	xtermCopyFontInfo(infoOut, boldInfoRef);
+	TRACE(("...bold font is double-width, use it %s\n", NonNull(boldNameRef)));
+    } else {
+	xtermCopyFontInfo(infoOut, wideInfoRef);
+	TRACE(("...cannot load wide bold font, use wide %s\n", NonNull(wideNameRef)));
+    }
+
+    free(bold);
+
+    if (EmptyFont(infoOut->fs)) {
+	status = False;		/* can't use a 0-sized font */
+    } else {
+	if ((!comparable_metrics(wideInfoRef->fs, infoOut->fs)
+	     || (!same_font_size(xw, wideInfoRef->fs, infoOut->fs)
+		 && is_fixed_font(wideInfoRef->fs)
+		 && is_fixed_font(infoOut->fs)))) {
+	    TRACE(("...ignoring mismatched normal/bold wide fonts\n"));
+	    xtermCloseFont2(xw, infoOut - fWBold, fWBold);
+	    xtermCopyFontInfo(infoOut, wideInfoRef);
+	}
+    }
+
+    return status;
+}
+#endif
+
 int
 xtermLoadFont(XtermWidget xw,
 	      const VTFontNames * fonts,
@@ -1078,13 +1403,9 @@ xtermLoadFont(XtermWidget xw,
     VTwin *win = WhichVWin(screen);
 
     VTFontNames myfonts;
-    FontNameProperties *fp;
     XTermFonts fnts[fMAX];
     char *tmpname = NULL;
-    char *normal = NULL;
     Boolean proportional = False;
-    fontWarningTypes warn[fMAX];
-    int j;
 
     memset(&myfonts, 0, sizeof(myfonts));
     memset(fnts, 0, sizeof(fnts));
@@ -1094,27 +1415,6 @@ xtermLoadFont(XtermWidget xw,
     if (!check_fontname(myfonts.f_n))
 	return 0;
 
-    /*
-     * Check the font names against the resource values, to see which were
-     * derived in a previous call.  If so, we'll only warn about those if
-     * the warning level is set to "always".
-     */
-    for (j = 0; j < fMAX; ++j) {
-	warn[j] = fwAlways;
-    }
-#define CmpResource(field, index) \
-    if (same_font_name(screen->menu_font_names[fontnum][index], myfonts.field)) \
-	warn[index] = fwResource
-
-    CmpResource(f_n, fNorm);
-    if (fontnum == fontMenu_default) {
-	CmpResource(f_b, fBold);
-#if OPT_WIDE_CHARS
-	CmpResource(f_b, fWide);
-	CmpResource(f_b, fWBold);
-#endif
-    }
-
     if (fontnum == fontMenu_fontescape
 	&& myfonts.f_n != screen->MenuFontName(fontnum)) {
 	if ((tmpname = x_strdup(myfonts.f_n)) == 0)
@@ -1127,7 +1427,7 @@ xtermLoadFont(XtermWidget xw,
 #define DbgResource(name, field, index) \
     TRACE(("xtermLoadFont #%d "name" %s%s\n", \
     	   fontnum, \
-	   (warn[index] == fwResource) ? "*" : " ", \
+	   (fnts[index].warn == fwResource) ? "*" : " ", \
 	   NonNull(myfonts.field)))
     DbgResource("normal", f_n, fNorm);
     DbgResource("bold  ", f_b, fBold);
@@ -1136,56 +1436,19 @@ xtermLoadFont(XtermWidget xw,
     DbgResource("w/bold", f_wb, fWBold);
 #endif
 
-    /*
-     * If we are opening the default font, and it happens to be missing, force
-     * that to the compiled-in default font, e.g., "fixed".  If we cannot open
-     * the font, disable it from the menu.
-     */
-    if (!xtermOpenFont(xw,
-		       myfonts.f_n,
-		       &fnts[fNorm],
-		       warn[fNorm],
-		       (fontnum == fontMenu_default))) {
-	if (fontnum != fontMenu_fontsel) {
-	    SetItemSensitivity(fontMenuEntries[fontnum].widget, False);
-	}
+    if (!loadNormFP(xw,
+		    &myfonts.f_n,
+		    &fnts[fNorm],
+		    fontnum))
 	goto bad;
-    }
 
-    normal = x_strdup(myfonts.f_n);
-    if (!check_fontname(myfonts.f_b)) {
-	warn[fBold] = fwAlways;
-	fp = get_font_name_props(screen->display, fnts[fNorm].fs, &normal);
-	if (fp != 0) {
-	    FREE_FNAME(f_b);
-	    myfonts.f_b = bold_font_name(fp, fp->average_width);
-	    if (!xtermOpenFont(xw, myfonts.f_b, &fnts[fBold], fwAlways, False)) {
-		FREE_FNAME(f_b);
-		myfonts.f_b = bold_font_name(fp, -1);
-		xtermOpenFont(xw, myfonts.f_b, &fnts[fBold], fwAlways, False);
-	    }
-	    TRACE(("...derived bold '%s'\n", NonNull(myfonts.f_b)));
-	}
-	if (fp == 0 || fnts[fBold].fs == 0) {
-	    xtermCopyFontInfo(&fnts[fBold], &fnts[fNorm]);
-	    TRACE(("...cannot load a matching bold font\n"));
-	} else if (comparable_metrics(fnts[fNorm].fs, fnts[fBold].fs)
-		   && same_font_size(xw, fnts[fNorm].fs, fnts[fBold].fs)
-		   && got_bold_font(screen->display, fnts[fBold].fs, myfonts.f_b)) {
-	    TRACE(("...got a matching bold font\n"));
-	    cache_menu_font_name(screen, fontnum, fBold, myfonts.f_b);
-	} else {
-	    xtermCloseFont2(xw, fnts, fBold);
-	    fnts[fBold] = fnts[fNorm];
-	    TRACE(("...did not get a matching bold font\n"));
-	}
-    } else if (!xtermOpenFont(xw, myfonts.f_b, &fnts[fBold], warn[fBold], False)) {
-	xtermCopyFontInfo(&fnts[fBold], &fnts[fNorm]);
-	warn[fBold] = fwAlways;
-	TRACE(("...cannot load bold font '%s'\n", NonNull(myfonts.f_b)));
-    } else {
-	cache_menu_font_name(screen, fontnum, fBold, myfonts.f_b);
-    }
+    if (!loadBoldFP(xw,
+		    &myfonts.f_b,
+		    &fnts[fBold],
+		    myfonts.f_n,
+		    &fnts[fNorm],
+		    fontnum))
+	goto bad;
 
     /*
      * If there is no widefont specified, fake it by doubling AVERAGE_WIDTH
@@ -1193,118 +1456,25 @@ xtermLoadFont(XtermWidget xw,
      * and 12x13ja as the corresponding fonts for 9x18 and 6x13.
      */
     if_OPT_WIDE_CHARS(screen, {
-	Boolean derived;
-	char *bold = NULL;
-
-	if (check_fontname(myfonts.f_w)) {
-	    cache_menu_font_name(screen, fontnum, fWide, myfonts.f_w);
-	} else if (screen->utf8_fonts && !is_double_width_font(fnts[fNorm].fs)) {
-	    FREE_FNAME(f_w);
-	    fp = get_font_name_props(screen->display, fnts[fNorm].fs, &normal);
-	    if (fp != 0) {
-		myfonts.f_w = wide_font_name(fp);
-		warn[fWide] = fwAlways;
-		TRACE(("...derived wide %s\n", NonNull(myfonts.f_w)));
-		cache_menu_font_name(screen, fontnum, fWide, myfonts.f_w);
-	    }
-	}
-
-	if (check_fontname(myfonts.f_w)) {
-	    (void) xtermOpenFont(xw, myfonts.f_w, &fnts[fWide], warn[fWide], False);
-	} else {
-	    xtermCopyFontInfo(&fnts[fWide], &fnts[fNorm]);
-	    warn[fWide] = fwAlways;
-	}
-
-	derived = False;
-	if (!check_fontname(myfonts.f_wb)) {
-	    fp = get_font_name_props(screen->display, fnts[fBold].fs, &bold);
-	    if (fp != 0) {
-		myfonts.f_wb = widebold_font_name(fp);
-		warn[fWBold] = fwAlways;
-		derived = True;
-	    }
-	}
-
-	if (check_fontname(myfonts.f_wb)) {
-
-	    xtermOpenFont(xw,
-			  myfonts.f_wb,
-			  &fnts[fWBold],
-			  (screen->utf8_fonts
-			   ? warn[fWBold]
-			   : (fontWarningTypes) (xw->misc.fontWarnings + 1)),
-			  False);
-
-	    if (derived
-		&& !compatibleWideCounts(fnts[fWide].fs, fnts[fWBold].fs)) {
-		xtermCloseFont2(xw, fnts, fWBold);
-	    }
-	    if (fnts[fWBold].fs == 0) {
-		FREE_FNAME(f_wb);
-		if (IsEmpty(myfonts.f_w)) {
-		    myfonts.f_wb = x_strdup(myfonts.f_b);
-		    warn[fWBold] = fwAlways;
-		    xtermCopyFontInfo(&fnts[fWBold], &fnts[fBold]);
-		    TRACE(("...cannot load wide-bold, use bold %s\n",
-			   NonNull(myfonts.f_b)));
-		} else {
-		    myfonts.f_wb = x_strdup(myfonts.f_w);
-		    warn[fWBold] = fwAlways;
-		    xtermCopyFontInfo(&fnts[fWBold], &fnts[fWide]);
-		    TRACE(("...cannot load wide-bold, use wide %s\n",
-			   NonNull(myfonts.f_w)));
-		}
-	    } else {
-		TRACE(("...%s wide/bold %s\n",
-		       derived ? "derived" : "given",
-		       NonNull(myfonts.f_wb)));
-		cache_menu_font_name(screen, fontnum, fWBold, myfonts.f_wb);
-	    }
-	} else if (is_double_width_font(fnts[fBold].fs)) {
-	    xtermCopyFontInfo(&fnts[fWBold], &fnts[fBold]);
-	    warn[fWBold] = fwAlways;
-	    TRACE(("...bold font is double-width, use it %s\n", NonNull(myfonts.f_b)));
-	} else {
-	    xtermCopyFontInfo(&fnts[fWBold], &fnts[fWide]);
-	    warn[fWBold] = fwAlways;
-	    TRACE(("...cannot load wide bold font, use wide %s\n", NonNull(myfonts.f_w)));
-	}
 
-	free(bold);
+	if (!loadWideFP(xw,
+			&myfonts.f_w,
+			&fnts[fWide],
+			myfonts.f_n,
+			&fnts[fNorm],
+			fontnum))
+	    goto bad;
+
+	if (!loadWBoldFP(xw,
+			 &myfonts.f_wb,
+			 &fnts[fWBold],
+			 myfonts.f_w,
+			 &fnts[fWide],
+			 myfonts.f_b,
+			 &fnts[fBold],
+			 fontnum))
+	    goto bad;
 
-	if (EmptyFont(fnts[fWBold].fs))
-	    goto bad;		/* can't use a 0-sized font */
-    });
-
-    /*
-     * Most of the time this call to load the font will succeed, even if
-     * there is no wide font :  the X server doubles the width of the
-     * normal font, or similar.
-     *
-     * But if it did fail for some reason, then nevermind.
-     */
-    if (EmptyFont(fnts[fBold].fs))
-	goto bad;		/* can't use a 0-sized font */
-
-    if (!same_font_size(xw, fnts[fNorm].fs, fnts[fBold].fs)
-	&& (is_fixed_font(fnts[fNorm].fs) && is_fixed_font(fnts[fBold].fs))) {
-	TRACE(("...ignoring mismatched normal/bold fonts\n"));
-	xtermCloseFont2(xw, fnts, fBold);
-	xtermCopyFontInfo(&fnts[fBold], &fnts[fNorm]);
-    }
-
-    if_OPT_WIDE_CHARS(screen, {
-	if (fnts[fWide].fs != 0
-	    && fnts[fWBold].fs != 0
-	    && (!comparable_metrics(fnts[fWide].fs, fnts[fWBold].fs)
-		|| (!same_font_size(xw, fnts[fWide].fs, fnts[fWBold].fs)
-		    && is_fixed_font(fnts[fWide].fs)
-		    && is_fixed_font(fnts[fWBold].fs)))) {
-	    TRACE(("...ignoring mismatched normal/bold wide fonts\n"));
-	    xtermCloseFont2(xw, fnts, fWBold);
-	    xtermCopyFontInfo(&fnts[fWBold], &fnts[fWide]);
-	}
     });
 
     /*
@@ -1351,16 +1521,16 @@ xtermLoadFont(XtermWidget xw,
     screen->ifnts_ok = False;
 #endif
 
-    xtermCopyFontInfo(&(screen->fnts[fNorm]), &fnts[fNorm]);
-    xtermCopyFontInfo(&(screen->fnts[fBold]), &fnts[fBold]);
+    xtermCopyFontInfo(getNormalFont(screen, fNorm), &fnts[fNorm]);
+    xtermCopyFontInfo(getNormalFont(screen, fBold), &fnts[fBold]);
 #if OPT_WIDE_CHARS
-    xtermCopyFontInfo(&(screen->fnts[fWide]), &fnts[fWide]);
+    xtermCopyFontInfo(getNormalFont(screen, fWide), &fnts[fWide]);
     if (fnts[fWBold].fs == NULL)
-	xtermCopyFontInfo(&fnts[fWBold], &fnts[fWide]);
-    xtermCopyFontInfo(&(screen->fnts[fWBold]), &fnts[fWBold]);
+	xtermCopyFontInfo(getNormalFont(screen, fWide), &fnts[fWide]);
+    xtermCopyFontInfo(getNormalFont(screen, fWBold), &fnts[fWBold]);
 #endif
 
-    xtermUpdateFontGCs(xw, screen->fnts);
+    xtermUpdateFontGCs(xw, False);
 
 #if OPT_BOX_CHARS
     screen->allow_packing = proportional;
@@ -1427,7 +1597,7 @@ xtermLoadFont(XtermWidget xw,
     } else {
 	screen->enbolden = screen->bold_mode
 	    && ((fnts[fNorm].fs == fnts[fBold].fs)
-		|| same_font_name(normal, myfonts.f_b));
+		|| same_font_name(myfonts.f_n, myfonts.f_b));
     }
     TRACE(("Will %suse 1-pixel offset/overstrike to simulate bold\n",
 	   screen->enbolden ? "" : "not "));
@@ -1446,8 +1616,6 @@ xtermLoadFont(XtermWidget xw,
 	screen->menu_font_sizes[fontnum] = FontSize(fnts[fNorm].fs);
 #endif
     }
-    if (normal)
-	free(normal);
     set_cursor_gcs(xw);
     xtermUpdateFontInfo(xw, doresize);
     TRACE(("Success Cgs - xtermLoadFont\n"));
@@ -1470,11 +1638,10 @@ xtermLoadFont(XtermWidget xw,
     free(fnts[fWide].fn);
     free(fnts[fWBold].fn);
 #endif
+    xtermSetWinSize(xw);
     return 1;
 
   bad:
-    if (normal)
-	free(normal);
     if (tmpname)
 	free(tmpname);
 
@@ -1490,7 +1657,7 @@ xtermLoadFont(XtermWidget xw,
     } else if (x_strcasecmp(myfonts.f_n, DEFFONT)) {
 	int code;
 
-	myfonts.f_n = DEFFONT;
+	myfonts.f_n = x_strdup(DEFFONT);
 	TRACE(("...recovering for TrueType fonts\n"));
 	code = xtermLoadFont(xw, &myfonts, doresize, fontnum);
 	if (code) {
@@ -1525,44 +1692,44 @@ xtermLoadItalics(XtermWidget xw)
 
     if (!screen->ifnts_ok) {
 	int n;
+	FontNameProperties *fp;
+	XTermFonts *data;
 
 	screen->ifnts_ok = True;
 	for (n = 0; n < fMAX; ++n) {
-	    FontNameProperties *fp;
+	    switch (n) {
+	    case fNorm:
+		/* FALLTHRU */
+	    case fBold:
+		/* FALLTHRU */
+#if OPT_WIDE_CHARS
+	    case fWide:
+		/* FALLTHRU */
+	    case fWBold:
+#endif
+		/* FALLTHRU */
+		data = getItalicFont(screen, n);
 
-	    /*
-	     * FIXME - need to handle font-leaks
-	     */
-	    screen->ifnts[n].fs = 0;
-	    if (screen->fnts[n].fs != 0 &&
-		(fp = get_font_name_props(screen->display,
-					  screen->fnts[n].fs,
-					  0)) != 0) {
-		char *name;
-
-		if ((name = italic_font_name(fp, fp->average_width)) != 0) {
-		    TRACE(("xtermLoadItalics #%d %s\n", n, name));
-		    (void) xtermOpenFont(xw,
-					 name,
-					 &(screen->ifnts[n]),
-					 fwResource,
-					 False);
-#if OPT_TRACE
-		    {
-			XFontStruct *fs =
-			screen->ifnts[n].fs;
-			if (fs != 0) {
-			    TRACE(("...actual size %dx%d (ascent %d, descent %d)\n",
-				   fs->ascent +
-				   fs->descent,
-				   fs->max_bounds.width,
-				   fs->ascent,
-				   fs->descent));
+		/*
+		 * FIXME - need to handle font-leaks
+		 */
+		data->fs = 0;
+		if (getNormalFont(screen, n)->fs != 0 &&
+		    (fp = get_font_name_props(screen->display,
+					      getNormalFont(screen, n)->fs,
+					      0)) != 0) {
+		    if (!open_italic_font(xw, n, fp, data)) {
+			if (n > 0) {
+			    xtermCopyFontInfo(data,
+					      getItalicFont(screen, n - 1));
+			} else {
+			    xtermOpenFont(xw,
+					  getNormalFont(screen, n)->fn,
+					  data, False);
 			}
 		    }
-#endif
-		    free(name);
 		}
+		break;
 	    }
 	}
     }
@@ -1573,20 +1740,26 @@ xtermLoadItalics(XtermWidget xw)
 /*
  * Collect font-names that we can modify with the load-vt-fonts() action.
  */
-#define MERGE_SUBFONT(src,dst,name) \
+#define MERGE_SUBFONT(dst,src,name) \
 	if (IsEmpty(dst.name)) { \
-	    TRACE(("MERGE_SUBFONT " #dst "." #name " merge %s\n", NonNull(src.name))); \
+	    TRACE(("MERGE_SUBFONT " #dst "." #name " merge \"%s\"\n", NonNull(src.name))); \
 	    dst.name = x_strdup(src.name); \
 	} else { \
-	    TRACE(("MERGE_SUBFONT " #dst "." #name " found %s\n", NonNull(dst.name))); \
+	    TRACE(("MERGE_SUBFONT " #dst "." #name " found \"%s\"\n", NonNull(dst.name))); \
+	}
+#define MERGE_SUBLIST(dst,src,name) \
+	if (merge_sublist(&(dst.fonts.x11.name), src.fonts.x11.name)) { \
+	    TRACE(("MERGE_SUBLIST " #dst "." #name " merge \"%s\"\n", src.fonts.x11.name[0])); \
+	} else { \
+	    TRACE(("MERGE_SUBLIST " #dst "." #name " found \"%s\"\n", dst.fonts.x11.name[0])); \
 	}
 
-#define INFER_SUBFONT(src,dst,name) \
+#define INFER_SUBFONT(dst,src,name) \
 	if (IsEmpty(dst.name)) { \
 	    TRACE(("INFER_SUBFONT " #dst "." #name " will infer\n")); \
 	    dst.name = x_strdup(""); \
 	} else { \
-	    TRACE(("INFER_SUBFONT " #dst "." #name " found %s\n", NonNull(dst.name))); \
+	    TRACE(("INFER_SUBFONT " #dst "." #name " found \"%s\"\n", NonNull(dst.name))); \
 	}
 
 #define FREE_MENU_FONTS(dst) \
@@ -1598,7 +1771,7 @@ xtermLoadItalics(XtermWidget xw)
 	    } \
 	}
 
-#define COPY_MENU_FONTS(src,dst) \
+#define COPY_MENU_FONTS(dst,src) \
 	TRACE(("COPY_MENU_FONTS " #src " to " #dst "\n")); \
 	for (n = fontMenu_default; n <= fontMenu_lastBuiltin; ++n) { \
 	    for (m = 0; m < fMAX; ++m) { \
@@ -1609,17 +1782,56 @@ xtermLoadItalics(XtermWidget xw)
 	}
 
 #define COPY_DEFAULT_FONTS(target, source) \
+	TRACE(("COPY_DEFAULT_FONTS " #source " to " #target "\n")); \
 	xtermCopyVTFontNames(&target.default_font, &source.default_font)
 
+#define COPY_X11_FONTLISTS(target, source) \
+	TRACE(("COPY_X11_FONTLISTS " #source " to " #target "\n")); \
+	xtermCopyFontLists(xw, &target.fonts.x11, &source.fonts.x11)
+
 static void
 xtermCopyVTFontNames(VTFontNames * target, VTFontNames * source)
 {
-    target->f_n = x_strdup(source->f_n);
-    target->f_b = x_strdup(source->f_b);
+#define COPY_IT(name,field) \
+    TRACE((".. "#name" = %s\n", NonNull(source->field))); \
+    free(target->field); \
+    target->field = x_strdup(source->field)
+
+    TRACE(("xtermCopyVTFontNames\n"));
+
+    COPY_IT(font, f_n);
+    COPY_IT(boldFont, f_b);
+
+#if OPT_WIDE_CHARS
+    COPY_IT(wideFont, f_w);
+    COPY_IT(wideBoldFont, f_wb);
+#endif
+#undef COPY_IT
+}
+
+static void
+xtermCopyFontLists(XtermWidget xw, VTFontList * target, VTFontList * source)
+{
+#define COPY_IT(name,field) \
+    copyFontList(&(target->field), source->field); \
+    TRACE_ARGV(".. " #name, source->field)
+
+    (void) xw;
+    TRACE(("xtermCopyFontLists %s ->%s\n",
+	   whichFontList(xw, source),
+	   whichFontList(xw, target)));
+
+    COPY_IT(font, list_n);
+    COPY_IT(fontBold, list_b);
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+    COPY_IT(fontItal, list_i);
+#endif
 #if OPT_WIDE_CHARS
-    target->f_w = x_strdup(source->f_w);
-    target->f_wb = x_strdup(source->f_wb);
+    COPY_IT(wideFont, list_w);
+    COPY_IT(wideBoldFont, list_wb);
+    COPY_IT(wideItalFont, list_wi);
 #endif
+#undef COPY_IT
 }
 
 void
@@ -1633,7 +1845,8 @@ xtermSaveVTFonts(XtermWidget xw)
 	screen->savedVTFonts = True;
 	TRACE(("xtermSaveVTFonts saving original\n"));
 	COPY_DEFAULT_FONTS(screen->cacheVTFonts, xw->misc);
-	COPY_MENU_FONTS(xw->screen, screen->cacheVTFonts);
+	COPY_X11_FONTLISTS(screen->cacheVTFonts, xw->work);
+	COPY_MENU_FONTS(screen->cacheVTFonts, xw->screen);
     }
 }
 
@@ -1710,8 +1923,9 @@ xtermLoadVTFonts(XtermWidget xw, String 
     if (IsEmpty(myName)) {
 	TRACE(("xtermLoadVTFonts restoring original\n"));
 	COPY_DEFAULT_FONTS(xw->misc, screen->cacheVTFonts);
+	COPY_X11_FONTLISTS(xw->work, screen->cacheVTFonts);
 	FREE_MENU_FONTS(xw->screen);
-	COPY_MENU_FONTS(screen->cacheVTFonts, xw->screen);
+	COPY_MENU_FONTS(xw->screen, screen->cacheVTFonts);
     } else {
 	TRACE(("xtermLoadVTFonts(%s, %s)\n", myName, myClass));
 
@@ -1747,34 +1961,55 @@ xtermLoadVTFonts(XtermWidget xw, String 
 	    }
 
 	    /*
+	     * Now, save the string to a font-list for consistency
+	     */
+#define ALLOC_SUBLIST(which,field) \
+	    save2FontList(xw, "cached", \
+			  &(subresourceRec.fonts), \
+			  which, \
+			  subresourceRec.default_font.field, False)
+
+	    ALLOC_SUBLIST(fNorm, f_n);
+	    ALLOC_SUBLIST(fBold, f_b);
+#if OPT_WIDE_CHARS
+	    ALLOC_SUBLIST(fWide, f_w);
+	    ALLOC_SUBLIST(fWBold, f_wb);
+#endif
+
+	    /*
 	     * If a particular resource value was not found, use the original.
 	     */
-	    MERGE_SUBFONT(xw->misc, subresourceRec, default_font.f_n);
-	    INFER_SUBFONT(xw->misc, subresourceRec, default_font.f_b);
+	    MERGE_SUBFONT(subresourceRec, xw->misc, default_font.f_n);
+	    INFER_SUBFONT(subresourceRec, xw->misc, default_font.f_b);
+	    MERGE_SUBLIST(subresourceRec, xw->work, list_n);
+	    MERGE_SUBLIST(subresourceRec, xw->work, list_b);
 #if OPT_WIDE_CHARS
-	    INFER_SUBFONT(xw->misc, subresourceRec, default_font.f_w);
-	    INFER_SUBFONT(xw->misc, subresourceRec, default_font.f_wb);
+	    INFER_SUBFONT(subresourceRec, xw->misc, default_font.f_w);
+	    INFER_SUBFONT(subresourceRec, xw->misc, default_font.f_wb);
+	    MERGE_SUBLIST(subresourceRec, xw->work, list_w);
+	    MERGE_SUBLIST(subresourceRec, xw->work, list_wb);
 #endif
 	    for (n = fontMenu_font1; n <= fontMenu_lastBuiltin; ++n) {
-		MERGE_SUBFONT(xw->screen, subresourceRec, MenuFontName(n));
+		MERGE_SUBFONT(subresourceRec, xw->screen, MenuFontName(n));
 	    }
 
 	    /*
 	     * Finally, copy the subresource data to the widget.
 	     */
 	    COPY_DEFAULT_FONTS(xw->misc, subresourceRec);
+	    COPY_X11_FONTLISTS(xw->work, subresourceRec);
 	    FREE_MENU_FONTS(xw->screen);
-	    COPY_MENU_FONTS(subresourceRec, xw->screen);
+	    COPY_MENU_FONTS(xw->screen, subresourceRec);
 
 	    FREE_STRING(screen->MenuFontName(fontMenu_default));
 	    FREE_STRING(screen->menu_font_names[0][fBold]);
-	    screen->MenuFontName(fontMenu_default) = x_strdup(xw->misc.default_font.f_n);
-	    screen->menu_font_names[0][fBold] = x_strdup(xw->misc.default_font.f_b);
+	    screen->MenuFontName(fontMenu_default) = x_strdup(DefaultFontN(xw));
+	    screen->menu_font_names[0][fBold] = x_strdup(DefaultFontB(xw));
 #if OPT_WIDE_CHARS
 	    FREE_STRING(screen->menu_font_names[0][fWide]);
 	    FREE_STRING(screen->menu_font_names[0][fWBold]);
-	    screen->menu_font_names[0][fWide] = x_strdup(xw->misc.default_font.f_w);
-	    screen->menu_font_names[0][fWBold] = x_strdup(xw->misc.default_font.f_wb);
+	    screen->menu_font_names[0][fWide] = x_strdup(DefaultFontW(xw));
+	    screen->menu_font_names[0][fWBold] = x_strdup(DefaultFontWB(xw));
 #endif
 	    /*
 	     * And remove our copies of strings.
@@ -1793,6 +2028,7 @@ xtermLoadVTFonts(XtermWidget xw, String 
 	    status = False;
 	}
     }
+    TRACE((".. xtermLoadVTFonts: %d\n", status));
     return status;
 }
 
@@ -1828,15 +2064,17 @@ xtermLoadWideFonts(XtermWidget xw, Bool 
     TScreen *screen = TScreenOf(xw);
     Bool result;
 
-    if (EmptyFont(screen->fnts[fWide].fs)) {
-	result = (isWideFont(screen->fnts[fNorm].fs, "normal", nullOk)
-		  && isWideFont(screen->fnts[fBold].fs, "bold", nullOk));
+    if (EmptyFont(getNormalFont(screen, fWide)->fs)) {
+	result = (isWideFont(getNormalFont(screen, fNorm)->fs, "normal", nullOk)
+		  && isWideFont(getNormalFont(screen, fBold)->fs, "bold", nullOk));
     } else {
-	result = (isWideFont(screen->fnts[fWide].fs, "wide", nullOk)
-		  && isWideFont(screen->fnts[fWBold].fs, "wide-bold", nullOk));
+	result = (isWideFont(getNormalFont(screen, fWide)->fs, "wide", nullOk)
+		  && isWideFont(getNormalFont(screen, fWBold)->fs,
+				"wide-bold", nullOk));
 	if (result && !screen->utf8_latin1) {
-	    result = (isWideFont(screen->fnts[fNorm].fs, "normal", nullOk)
-		      && isWideFont(screen->fnts[fBold].fs, "bold", nullOk));
+	    result = (isWideFont(getNormalFont(screen, fNorm)->fs, "normal", nullOk)
+		      && isWideFont(getNormalFont(screen, fBold)->fs,
+				    "bold", nullOk));
 	}
     }
     if (!result) {
@@ -1904,10 +2142,11 @@ HandleLoadVTFonts(Widget w,
 		    for (n = 0; n < NMENUFONTS; ++n) {
 			screen->menu_font_sizes[n] = 0;
 		    }
-		    SetVTFont(xw, font_number, True,
-			      ((font_number == fontMenu_default)
-			       ? &(xw->misc.default_font)
-			       : NULL));
+		    if (font_number == fontMenu_default) {
+			SetVTFont(xw, font_number, True, defaultVTFontNames(xw));
+		    } else {
+			SetVTFont(xw, font_number, True, NULL);
+		    }
 		}
 		MyStackFree(myClass, class_buf);
 	    }
@@ -1955,6 +2194,7 @@ xtermSetCursorBox(TScreen *screen)
 
 #if OPT_RENDERFONT
 
+#if OPT_REPORT_FONTS
 static FcChar32
 xtermXftFirstChar(XftFont *xft)
 {
@@ -1999,8 +2239,9 @@ xtermXftLastChar(XftFont *xft)
 	    break;
 	}
     }
-    return (long) last;
+    return (FcChar32) last;
 }
+#endif /* OPT_REPORT_FONTS */
 
 #if OPT_TRACE > 1
 static void
@@ -2071,6 +2312,7 @@ checkXft(XtermWidget xw, XTermXftFonts *
     data->map.mixed = (data->map.max_width >= (data->map.min_width + 1));
 }
 
+#if OPT_REPORT_FONTS
 static void
 reportXftFonts(XtermWidget xw,
 	       XftFont *fp,
@@ -2107,6 +2349,9 @@ reportXftFonts(XtermWidget xw,
 	}
     }
 }
+#else
+#define reportXftFonts(xw, result, name, tag, match)	/* empty */
+#endif /* OPT_REPORT_FONTS */
 
 static XftFont *
 xtermOpenXft(XtermWidget xw, const char *name, XftPattern *pat, const char *tag)
@@ -2128,14 +2373,14 @@ xtermOpenXft(XtermWidget xw, const char 
 		XftPatternDestroy(match);
 		if (xw->misc.fontWarnings >= fwAlways) {
 		    TRACE(("OOPS cannot open %s font \"%s\"\n", tag, name));
-		    xtermWarning("cannot open %s font \"%s\"\n", tag, name);
+		    cannotFont(xw, "open", tag, name);
 		}
 	    }
 	} else {
 	    TRACE(("...did not match %s font\n", tag));
 	    if (xw->misc.fontWarnings >= fwResource) {
 		TRACE(("OOPS: cannot match %s font \"%s\"\n", tag, name));
-		xtermWarning("cannot match %s font \"%s\"\n", tag, name);
+		cannotFont(xw, "match", tag, name);
 	    }
 	}
     }
@@ -2241,21 +2486,18 @@ xtermCloseXft(TScreen *screen, XTermXftF
 }
 
 /*
- * Get the faceName/faceDoublesize resource setting.  Strip off "xft:", which
- * is not recognized by XftNameParse().
+ * Get the faceName/faceDoublesize resource setting.
  */
 String
 getFaceName(XtermWidget xw, Bool wideName GCC_UNUSED)
 {
 #if OPT_RENDERWIDE
     String result = (wideName
-		     ? xw->misc.face_wide_name
-		     : xw->misc.face_name);
+		     ? FirstItemOf(xw->work.fonts.xft.list_w)
+		     : CurrentXftFont(xw));
 #else
-    String result = xw->misc.face_name;
+    String result = CurrentXftFont(xw);
 #endif
-    if (!IsEmpty(result) && !strncmp(result, "xft:", (size_t) 4))
-	result += 4;
     return x_nonempty(result);
 }
 
@@ -2267,23 +2509,19 @@ void
 setFaceName(XtermWidget xw, const char *value)
 {
     TScreen *screen = TScreenOf(xw);
-    Boolean changed = (Boolean) ((xw->misc.face_name == 0)
-				 || strcmp(xw->misc.face_name, value));
+    Boolean changed = (Boolean) ((CurrentXftFont(xw) == 0)
+				 || strcmp(CurrentXftFont(xw), value));
 
     if (changed) {
 	int n;
 
-	xw->misc.face_name = x_strdup(value);
+	CurrentXftFont(xw) = x_strdup(value);
 	for (n = 0; n < NMENUFONTS; ++n) {
+	    int e;
 	    xw->misc.face_size[n] = -1.0;
-	    xtermCloseXft(screen, &(screen->renderFontNorm[n]));
-	    xtermCloseXft(screen, &(screen->renderFontBold[n]));
-	    xtermCloseXft(screen, &(screen->renderFontBold[n]));
-#if OPT_RENDERWIDE
-	    xtermCloseXft(screen, &(screen->renderWideNorm[n]));
-	    xtermCloseXft(screen, &(screen->renderWideBold[n]));
-	    xtermCloseXft(screen, &(screen->renderWideItal[n]));
-#endif
+	    for (e = 0; e < fMAX; ++e) {
+		xtermCloseXft(screen, getMyXftFont(xw, e, n));
+	    }
 	}
     }
 }
@@ -2342,8 +2580,7 @@ xtermComputeFontInfo(XtermWidget xw,
 	     */
 #define NormXftPattern \
 	    XFT_FAMILY, XftTypeString, "mono", \
-	    XFT_SIZE, XftTypeDouble, face_size, \
-	    XFT_SPACING, XftTypeInteger, XFT_MONO
+	    XFT_SIZE, XftTypeDouble, face_size
 
 #define BoldXftPattern(norm) \
 	    XFT_WEIGHT, XftTypeInteger, XFT_WEIGHT_BOLD, \
@@ -2412,7 +2649,7 @@ xtermComputeFontInfo(XtermWidget xw,
 	    if (norm != 0 && screen->wide_chars) {
 		int char_width = norm->max_advance_width * 2;
 #ifdef FC_ASPECT
-		double aspect = ((xw->misc.face_wide_name
+		double aspect = ((FirstItemOf(xw->work.fonts.xft.list_w)
 				  || screen->renderFontNorm[fontnum].map.mixed)
 				 ? 1.0
 				 : 2.0);
@@ -2553,8 +2790,8 @@ xtermUpdateFontInfo(XtermWidget xw, Bool
 		       ? (screen->scrollWidget->core.width +
 			  BorderWidth(screen->scrollWidget))
 		       : 0);
-    xtermComputeFontInfo(xw, win, screen->fnts[fNorm].fs, scrollbar_width);
-    xtermSaveFontInfo(screen, screen->fnts[fNorm].fs);
+    xtermComputeFontInfo(xw, win, getNormalFont(screen, fNorm)->fs, scrollbar_width);
+    xtermSaveFontInfo(screen, getNormalFont(screen, fNorm)->fs);
 
     if (doresize) {
 	if (VWindow(screen)) {
@@ -2601,8 +2838,8 @@ xtermMissingChar(unsigned ch, XTermFonts
 #endif
 
     if (pc == 0 || CI_NONEXISTCHAR(pc)) {
-	TRACE(("xtermMissingChar %#04x (!exists), %d cells\n",
-	       ch, my_wcwidth(ch)));
+	TRACE2(("xtermMissingChar %#04x (!exists), %d cells\n",
+		ch, my_wcwidth((wchar_t) ch)));
 	result = True;
     }
     if (ch < KNOWN_MISSING) {
@@ -2852,8 +3089,8 @@ xtermDrawBoxChar(XtermWidget xw,
 	for (n = 1; n < 32; n++) {
 	    if (dec2ucs(n) == ch
 		&& !((attr_flags & BOLD)
-		     ? IsXtermMissingChar(screen, n, &screen->fnts[fBold])
-		     : IsXtermMissingChar(screen, n, &screen->fnts[fNorm]))) {
+		     ? IsXtermMissingChar(screen, n, getNormalFont(screen, fBold))
+		     : IsXtermMissingChar(screen, n, getNormalFont(screen, fNorm)))) {
 		TRACE(("...use xterm-style linedrawing\n"));
 		ch = n;
 		break;
@@ -3003,10 +3240,10 @@ xtermXftMissing(XtermWidget xw, XftFont 
 	TScreen *screen = TScreenOf(xw);
 	if (!XftGlyphExists(screen->display, font, wc)) {
 #if OPT_WIDE_CHARS
-	    TRACE(("xtermXftMissing %d (dec=%#x, ucs=%#x)\n",
-		   wc, ucs2dec(wc), dec2ucs(wc)));
+	    TRACE2(("xtermXftMissing %d (dec=%#x, ucs=%#x)\n",
+		    wc, ucs2dec(wc), dec2ucs(wc)));
 #else
-	    TRACE(("xtermXftMissing %d\n", wc));
+	    TRACE2(("xtermXftMissing %d\n", wc));
 #endif
 	    result = True;
 	}
@@ -3120,13 +3357,7 @@ lookupOneFontSize(XtermWidget xw, int fo
 
 	memset(&fnt, 0, sizeof(fnt));
 	screen->menu_font_sizes[fontnum] = -1;
-	if (xtermOpenFont(xw,
-			  screen->MenuFontName(fontnum),
-			  &fnt,
-			  ((fontnum <= fontMenu_lastBuiltin)
-			   ? fwAlways
-			   : fwResource),
-			  True)) {
+	if (xtermOpenFont(xw, screen->MenuFontName(fontnum), &fnt, True)) {
 	    if (fontnum <= fontMenu_lastBuiltin
 		|| strcmp(fnt.fn, DEFFONT)) {
 		screen->menu_font_sizes[fontnum] = FontSize(fnt.fs);
@@ -3512,17 +3743,17 @@ HandleSetFont(Widget w GCC_UNUSED,
 	    switch (*param_count) {	/* assign 'em */
 #if OPT_WIDE_CHARS
 	    case 5:
-		fonts.f_wb = params[4];
+		fonts.f_wb = x_strdup(params[4]);
 		/* FALLTHRU */
 	    case 4:
-		fonts.f_w = params[3];
-		/* FALLTHRU */
+		fonts.f_w = x_strdup(params[3]);
 #endif
+		/* FALLTHRU */
 	    case 3:
-		fonts.f_b = params[2];
+		fonts.f_b = x_strdup(params[2]);
 		/* FALLTHRU */
 	    case 2:
-		fonts.f_n = params[1];
+		fonts.f_n = x_strdup(params[1]);
 		break;
 	    }
 	}
@@ -3613,3 +3844,561 @@ SetVTFont(XtermWidget xw,
     }
     return;
 }
+
+#if OPT_RENDERFONT
+static void
+trimSizeFromFace(char *face_name, float *face_size)
+{
+    char *first = strstr(face_name, ":size=");
+    if (first == 0) {
+	first = face_name;
+    } else {
+	first++;
+    }
+    if (!strncmp(first, "size=", (size_t) 5)) {
+	char *last = strchr(first, ':');
+	char mark;
+	float value;
+	char extra;
+	TRACE(("...before trimming, font = \"%s\"\n", face_name));
+	if (last == 0)
+	    last = first + strlen(first);
+	mark = *last;
+	*last = '\0';
+	if (sscanf(first, "size=%g%c", &value, &extra) == 1) {
+	    TRACE(("...trimmed size from font: %g\n", value));
+	    if (face_size != 0)
+		*face_size = value;
+	}
+	if (mark) {
+	    while ((*first++ = *++last) != '\0') {
+		;
+	    }
+	} else {
+	    if (first != face_name)
+		--first;
+	    *first = '\0';
+	}
+	TRACE(("...after trimming, font = \"%s\"\n", face_name));
+    }
+}
+#endif
+
+/*
+ * Save a font specification to the proper list.
+ */
+static void
+save2FontList(XtermWidget xw,
+	      const char *name,
+	      XtermFontNames * fontnames,
+	      VTFontEnum which,
+	      const char *source,
+	      Bool ttf)
+{
+    char *value;
+    size_t plen;
+    Bool marked = False;
+    Bool use_ttf = ttf;
+
+    (void) xw;
+
+    if (source == 0)
+	source = "";
+    while (isspace(CharOf(*source)))
+	++source;
+
+    /* fontconfig patterns can contain ':' separators, but we'll treat
+     * a leading prefix specially to denote whether the pattern might be
+     * XLFD ("x" or "xlfd") versus Xft ("xft").
+     */
+    for (plen = 0; source[plen] != '\0'; ++plen) {
+	if (source[plen] == ':') {
+	    marked = True;
+	    switch (plen) {
+	    case 0:
+		++plen;		/* trim leading ':' */
+		break;
+	    case 1:
+		if (!strncmp(source, "x", plen)) {
+		    ++plen;
+		    use_ttf = False;
+		} else {
+		    marked = False;
+		}
+		break;
+	    case 3:
+		if (!strncmp(source, "xft", plen)) {
+		    ++plen;
+		    use_ttf = True;
+		} else {
+		    marked = False;
+		}
+		break;
+	    case 4:
+		if (!strncmp(source, "xlfd", plen)) {
+		    ++plen;
+		    use_ttf = False;
+		} else {
+		    marked = False;
+		}
+		break;
+	    default:
+		marked = False;
+		plen = 0;
+		break;
+	    }
+	    break;
+	}
+    }
+    if (!marked)
+	plen = 0;
+    value = x_strtrim(source + plen);
+    if (value != 0) {
+	Bool success = False;
+#if OPT_RENDERFONT
+	VTFontList *target = (use_ttf
+			      ? &(fontnames->xft)
+			      : &(fontnames->x11));
+#else
+	VTFontList *target = &(fontnames->x11);
+#endif
+	char ***list = 0;
+	char **next = 0;
+	size_t count = 0;
+
+	(void) use_ttf;
+	switch (which) {
+	case fNorm:
+	    list = &(target->list_n);
+	    break;
+	case fBold:
+	    list = &(target->list_b);
+	    break;
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+	case fItal:
+	    list = &(target->list_i);
+	    break;
+#endif
+#if OPT_WIDE_CHARS
+	case fWide:
+	    list = &(target->list_w);
+	    break;
+	case fWBold:
+	    list = &(target->list_wb);
+	    break;
+	case fWItal:
+	    list = &(target->list_wi);
+	    break;
+#endif
+	case fMAX:
+	    list = 0;
+	    break;
+	}
+
+	if (list != 0) {
+	    success = True;
+	    if (*list != 0) {
+		while ((*list)[count] != 0) {
+		    if (IsEmpty((*list)[count])) {
+			TRACE(("... initial %s\n", value));
+			free((*list)[count]);
+			break;
+		    } else if (!strcmp(value, (*list)[count])) {
+			TRACE(("... duplicate %s\n", value));
+			success = False;
+			break;
+		    }
+		    ++count;
+		}
+	    }
+	    if (success) {
+		next = realloc(*list, sizeof(char *) * (count + 2));
+		if (next != 0) {
+#if OPT_RENDERFONT
+		    if (use_ttf) {
+			trimSizeFromFace(value,
+					 (count == 0 && which == fNorm)
+					 ? &(xw->misc.face_size[0])
+					 : (float *) 0);
+		    }
+#endif
+		    next[count++] = value;
+		    next[count] = 0;
+		    *list = next;
+		    TRACE(("... saved %s %s %lu:%s\n",
+			   whichFontList(xw, target),
+			   whichFontList2(xw, *list),
+			   (unsigned long) count,
+			   value));
+		} else {
+		    fprintf(stderr,
+			    "realloc failure in save2FontList(%s)\n",
+			    name);
+		    freeFontList(list);
+		    success = False;
+		}
+	    }
+	}
+	if (success) {
+	    size_t limit = use_ttf ? MAX_XFT_FONTS : MAX_XLFD_FONTS;
+	    if (count > limit && !IsEmpty(value)) {
+		fprintf(stderr, "%s: too many fonts for %s, ignoring %s\n",
+			ProgramName,
+			whichFontEnum(which),
+			value);
+		if (list && *list) {
+		    free((*list)[limit]);
+		    (*list)[limit] = 0;
+		}
+	    }
+	} else {
+	    free(value);
+	}
+    }
+}
+
+/*
+ * In principle, any of the font-name resources could be extended to be a list
+ * of font-names.  That would be bad for performance, but as a basis for an
+ * extension, parse the font-name as a comma-separated list, creating/updating
+ * an array of font-names.
+ */
+void
+allocFontList(XtermWidget xw,
+	      const char *name,
+	      XtermFontNames * target,
+	      VTFontEnum which,
+	      const char *source,
+	      Bool ttf)
+{
+    char *blob;
+
+    blob = x_strdup(source);
+    if (!IsEmpty(blob)) {
+	int n;
+	int pass;
+	char **list = 0;
+
+	TRACE(("allocFontList %s %s '%s'\n", whichFontEnum(which), name, blob));
+
+	for (pass = 0; pass < 2; ++pass) {
+	    unsigned count = 0;
+	    if (pass)
+		list[0] = blob;
+	    for (n = 0; blob[n] != '\0'; ++n) {
+		if (blob[n] == ',') {
+		    ++count;
+		    if (pass != 0) {
+			blob[n] = '\0';
+			list[count] = blob + n + 1;
+		    }
+		}
+	    }
+	    if (!pass) {
+		if (count == 0 && *blob == '\0')
+		    break;
+		list = TypeCallocN(char *, count + 2);
+		if (list == 0)
+		    break;
+	    }
+	}
+	if (list) {
+	    for (n = 0; list[n] != 0; ++n) {
+		if (*list[n]) {
+		    save2FontList(xw, name, target, which, list[n], ttf);
+		}
+	    }
+	    free(list);
+	}
+    }
+    free(blob);
+}
+
+static void
+initFontList(XtermWidget xw,
+	     const char *name,
+	     XtermFontNames * target,
+	     Bool ttf)
+{
+    int which;
+
+    TRACE(("initFontList(%s)\n", name));
+    for (which = 0; which < fMAX; ++which) {
+	save2FontList(xw, name, target, (VTFontEnum) which, "", ttf);
+    }
+}
+
+void
+initFontLists(XtermWidget xw)
+{
+    TRACE(("initFontLists\n"));
+    initFontList(xw, "x11 font", &(xw->work.fonts), False);
+#if OPT_RENDERFONT
+    initFontList(xw, "xft font", &(xw->work.fonts), True);
+#endif
+#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
+    initFontList(xw, "cached font",
+		 &(xw->screen.cacheVTFonts.fonts), False);
+#endif
+}
+
+void
+copyFontList(char ***targetp, char **source)
+{
+    freeFontList(targetp);
+
+    if (source != 0) {
+	int pass;
+	size_t count;
+
+	for (pass = 0; pass < 2; ++pass) {
+	    for (count = 0; source[count] != 0; ++count) {
+		if (pass)
+		    (*targetp)[count] = x_strdup(source[count]);
+	    }
+	    if (!pass) {
+		++count;
+		*targetp = TypeCallocN(char *, count);
+	    }
+	}
+    } else {
+	*targetp = TypeCallocN(char *, 2);
+	(*targetp)[0] = x_strdup("");
+    }
+}
+
+#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
+static Boolean
+merge_sublist(char ***targetp, char **source)
+{
+    Boolean result = False;
+    if ((*targetp == 0 || IsEmpty(**targetp)) && !IsEmpty(*source)) {
+	copyFontList(targetp, source);
+	result = True;
+    }
+    return result;
+}
+#endif
+
+void
+freeFontList(char ***targetp)
+{
+    if (targetp != 0) {
+	char **target = *targetp;
+	if (target != 0) {
+	    int n;
+	    for (n = 0; target[n] != 0; ++n) {
+		free(target[n]);
+	    }
+	    free(target);
+	    *targetp = 0;
+	}
+    }
+}
+
+void
+freeFontLists(VTFontList * lists)
+{
+    int which;
+
+    TRACE(("freeFontLists\n"));
+    for (which = 0; which < fMAX; ++which) {
+	char ***target = 0;
+	switch (which) {
+	case fNorm:
+	    target = &(lists->list_n);
+	    break;
+	case fBold:
+	    target = &(lists->list_b);
+	    break;
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+	case fItal:
+	    target = &(lists->list_i);
+	    break;
+#endif
+#if OPT_WIDE_CHARS
+	case fWide:
+	    target = &(lists->list_w);
+	    break;
+	case fWBold:
+	    target = &(lists->list_wb);
+	    break;
+	case fWItal:
+	    target = &(lists->list_wi);
+	    break;
+#endif
+	default:
+	    target = 0;
+	    break;
+	}
+	freeFontList(target);
+    }
+}
+
+/*
+ * Return a pointer to the XLFD font information for a given font class.
+ * XXX make this allocate the font on demand.
+ */
+XTermFonts *
+getNormalFont(TScreen *screen, int which)
+{
+    XTermFonts *result = 0;
+    if (which >= 0 && which < fMAX)
+	result = &(screen->fnts[which]);
+    return result;
+}
+
+#if OPT_DEC_CHRSET
+XTermFonts *
+getDoubleFont(TScreen *screen, int which)
+{
+    XTermFonts *result = 0;
+    if ((int) which >= 0 && which < NUM_CHRSET)
+	result = &(screen->double_fonts[which]);
+    return result;
+}
+#endif
+
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+XTermFonts *
+getItalicFont(TScreen *screen, int which)
+{
+    XTermFonts *result = 0;
+#if OPT_WIDE_ATTRS
+    if (which >= 0 && which < fMAX)
+	result = &(screen->ifnts[which]);
+#else
+    (void) screen;
+    (void) which;
+#endif
+    return result;
+}
+#endif
+
+#if OPT_RENDERFONT
+/*
+ * This returns a pointer to everything known about a given Xft font.
+ * XXX make this allocate the font on demand.
+ */
+XTermXftFonts *
+getMyXftFont(XtermWidget xw, int which, int fontnum)
+{
+    TScreen *screen = TScreenOf(xw);
+    XTermXftFonts *result = 0;
+    if (fontnum >= 0 && fontnum < NMENUFONTS) {
+	switch ((VTFontEnum) which) {
+	case fNorm:
+	    result = &(screen->renderFontNorm[fontnum]);
+	    break;
+	case fBold:
+	    result = &(screen->renderFontBold[fontnum]);
+	    break;
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+	case fItal:
+	    result = &(screen->renderFontItal[fontnum]);
+	    break;
+#endif
+#if OPT_WIDE_CHARS
+	case fWide:
+	    result = &(screen->renderWideNorm[fontnum]);
+	    break;
+	case fWBold:
+	    result = &(screen->renderWideBold[fontnum]);
+	    break;
+	case fWItal:
+	    result = &(screen->renderWideItal[fontnum]);
+	    break;
+#endif
+	case fMAX:
+	    break;
+	}
+    }
+    return result;
+}
+
+XftFont *
+getXftFont(XtermWidget xw, VTFontEnum which, int fontnum)
+{
+    XTermXftFonts *data = getMyXftFont(xw, which, fontnum);
+    XftFont *result = 0;
+    if (data != 0)
+	result = data->font;
+    return result;
+}
+#endif
+
+const char *
+whichFontEnum(VTFontEnum value)
+{
+    const char *result = "?";
+#define DATA(name) case name: result = #name; break
+    switch (value) {
+	DATA(fNorm);
+	DATA(fBold);
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+	DATA(fItal);
+#endif
+#if OPT_WIDE_CHARS
+	DATA(fWide);
+	DATA(fWBold);
+	DATA(fWItal);
+#endif
+	DATA(fMAX);
+    }
+#undef DATA
+    return result;
+}
+
+const char *
+whichFontList(XtermWidget xw, VTFontList * value)
+{
+    const char *result = "?";
+    if (value == &(xw->work.fonts.x11))
+	result = "x11_fontnames";
+#if OPT_RENDERFONT
+    else if (value == &(xw->work.fonts.xft))
+	result = "xft_fontnames";
+#endif
+#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
+    else if (value == &(xw->screen.cacheVTFonts.fonts.x11))
+	result = "cached_fontnames";
+#endif
+    return result;
+}
+
+static const char *
+whichFontList2s(VTFontList * list, char **value)
+{
+    const char *result = 0;
+#define DATA(name) if (value == (list->name)) result = #name
+    DATA(list_n);
+    DATA(list_b);
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+    DATA(list_i);
+#endif
+#if OPT_WIDE_CHARS
+    DATA(list_w);
+    DATA(list_wb);
+    DATA(list_wi);
+#endif
+#undef DATA
+    return result;
+}
+
+const char *
+whichFontList2(XtermWidget xw, char **value)
+{
+    const char *result = 0;
+#define DATA(name) (result = whichFontList2s(&(xw->name), value))
+    if (DATA(work.fonts.x11) == 0) {
+#if OPT_RENDERFONT
+	if (DATA(work.fonts.xft) == 0)
+#endif
+#if OPT_LOAD_VTFONTS || OPT_WIDE_CHARS
+	    if (DATA(screen.cacheVTFonts.fonts.x11) == 0)
+#endif
+		result = "?";
+    }
+#undef DATA
+    return result;
+}

Index: xsrc/external/mit/xterm/dist/misc.c
diff -u xsrc/external/mit/xterm/dist/misc.c:1.14 xsrc/external/mit/xterm/dist/misc.c:1.15
--- xsrc/external/mit/xterm/dist/misc.c:1.14	Wed Mar  8 02:55:12 2017
+++ xsrc/external/mit/xterm/dist/misc.c	Wed Mar 14 06:04:47 2018
@@ -1,7 +1,7 @@
-/* $XTermId: misc.c,v 1.743 2016/10/07 00:41:14 tom Exp $ */
+/* $XTermId: misc.c,v 1.757 2017/06/20 08:52:18 tom Exp $ */
 
 /*
- * Copyright 1999-2015,2016 by Thomas E. Dickey
+ * Copyright 1999-2016,2017 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -55,6 +55,7 @@
 #include <version.h>
 #include <main.h>
 #include <xterm.h>
+#include <xterm_io.h>
 
 #include <sys/stat.h>
 #include <stdio.h>
@@ -1309,6 +1310,7 @@ xtermWarning(const char *fmt,...)
     int save_err = errno;
     va_list ap;
 
+    fflush(stdout);
     TRACE(("xtermWarning fmt='%s'\n", fmt));
     fprintf(stderr, "%s: ", ProgramName);
     va_start(ap, fmt);
@@ -1326,6 +1328,7 @@ xtermPerror(const char *fmt,...)
     char *msg = strerror(errno);
     va_list ap;
 
+    fflush(stdout);
     TRACE(("xtermPerror fmt='%s', msg='%s'\n", fmt, NonNull(msg)));
     fprintf(stderr, "%s: ", ProgramName);
     va_start(ap, fmt);
@@ -2959,9 +2962,12 @@ ManipulateSelectionData(XtermWidget xw, 
 			screen->base64_paste = n;
 			screen->base64_final = final;
 
+			screen->selection_time =
+			    XtLastTimestampProcessed(TScreenOf(xw)->display);
+
 			/* terminator will be written in this call */
 			xtermGetSelection((Widget) xw,
-					  XtLastTimestampProcessed(TScreenOf(xw)->display),
+					  screen->selection_time,
 					  select_args, n,
 					  NULL);
 			/*
@@ -2974,6 +2980,8 @@ ManipulateSelectionData(XtermWidget xw, 
 		} else {
 		    if (AllowWindowOps(xw, ewSetSelection)) {
 			TRACE(("Setting selection with %s\n", buf));
+			screen->selection_time =
+			    XtLastTimestampProcessed(TScreenOf(xw)->display);
 			ClearSelectionBuffer(screen);
 			while (*buf != '\0')
 			    AppendToSelectionBuffer(screen, CharOf(*buf++));
@@ -3276,6 +3284,9 @@ ResetColorsRequest(XtermWidget xw,
 {
     Bool result = False;
 
+    (void) xw;
+    (void) code;
+
     TRACE(("ResetColorsRequest code=%d\n", code));
 
 #if OPT_COLOR_RES
@@ -3562,7 +3573,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
      * Check if the palette changed and there are no more immediate changes
      * that could be deferred to the next repaint.
      */
-    if (xw->misc.palette_changed) {
+    if (xw->work.palette_changed) {
 	switch (mode) {
 	case 3:		/* change X property */
 	case 30:		/* Konsole (unused) */
@@ -3573,7 +3584,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
 	case 52:		/* selection data */
 #endif
 	    TRACE(("forced repaint after palette changed\n"));
-	    xw->misc.palette_changed = False;
+	    xw->work.palette_changed = False;
 	    xtermRepaint(xw);
 	    break;
 	}
@@ -3654,7 +3665,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
 	/* FALLTHRU */
     case 4:
 	if (ChangeAnsiColorRequest(xw, buf, ansi_colors, final))
-	    xw->misc.palette_changed = True;
+	    xw->work.palette_changed = True;
 	break;
     case 6:
 	/* FALLTHRU */
@@ -3678,7 +3689,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
 		++buf;
 	    } else {
 		value = strtol(buf, &next, 10);
-		if (!PartS2L(buf, next) || (which < 0))
+		if (!PartS2L(buf, next) || (value < 0))
 		    break;
 		buf = next;
 		if (*buf == ';')
@@ -3714,7 +3725,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
 	/* FALLTHRU */
     case OSC_Reset(4):
 	if (ResetAnsiColorRequest(xw, buf, ansi_colors))
-	    xw->misc.palette_changed = True;
+	    xw->work.palette_changed = True;
 	break;
 #endif
     case OSC_TEXT_FG:
@@ -3768,8 +3779,7 @@ do_osc(XtermWidget xw, Char *oscbuf, siz
 	 */
 	if (strcmp(buf, "?")) {
 	    char *bp;
-	    if ((bp = CastMallocN(char, strlen(buf))) != NULL) {
-		strcpy(bp, buf);
+	    if ((bp = x_strdup(buf)) != NULL) {
 		if (screen->logfile)
 		    free(screen->logfile);
 		screen->logfile = bp;
@@ -3857,7 +3867,7 @@ parse_decudk(XtermWidget xw, const char 
 {
     while (*cp) {
 	const char *base = cp;
-	char *str = CastMallocN(char, strlen(cp) + 2);
+	char *str = TextAlloc(strlen(cp) + 2);
 	unsigned key = 0;
 	int len = 0;
 
@@ -5489,7 +5499,7 @@ xtermSetenv(const char *var, const char 
 	    environ = environ;
 	}
 
-	environ[found] = CastMallocN(char, 1 + len + strlen(value));
+	environ[found] = TextAlloc(1 + len + strlen(value));
 	if (environ[found] == 0) {
 	    xtermWarning("Cannot allocate environment %s\n", var);
 	    return;
@@ -5679,6 +5689,8 @@ end_tek_mode(void)
 
     if (TEK4014_ACTIVE(xw)) {
 	FlushLog(xw);
+	TEK4014_ACTIVE(xw) = False;
+	xtermSetWinSize(xw);
 	longjmp(Tekend, 1);
     }
     return;
@@ -5692,6 +5704,7 @@ end_vt_mode(void)
     if (!TEK4014_ACTIVE(xw)) {
 	FlushLog(xw);
 	TEK4014_ACTIVE(xw) = True;
+	TekSetWinSize(tekWidget);
 	longjmp(VTend, 1);
     }
     return;
@@ -5853,10 +5866,9 @@ sortedOpts(OptionHelp * options, XrmOpti
 			}
 			if (strncmp(mesg, opt_array[j].desc, strlen(mesg))) {
 			    if (strncmp(opt_array[j].desc, "turn ", (size_t) 5)) {
-				char *s = CastMallocN(char,
-						      strlen(mesg)
-						      + 1
-						      + strlen(opt_array[j].desc));
+				char *s = TextAlloc(strlen(mesg)
+						    + 1
+						    + strlen(opt_array[j].desc));
 				if (s != 0) {
 				    sprintf(s, "%s %s", mesg, opt_array[j].desc);
 				    opt_array[j].desc = s;
@@ -6178,3 +6190,45 @@ free_string(String value)
 {
     free((void *) value);
 }
+
+/* Set tty's idea of window size, using the given file descriptor 'fd'. */
+void
+update_winsize(int fd, int rows, int cols, int height, int width)
+{
+#ifdef TTYSIZE_STRUCT
+    TTYSIZE_STRUCT ts;
+    int code;
+
+    setup_winsize(ts, rows, cols, height, width);
+    TRACE_RC(code, SET_TTYSIZE(fd, ts));
+    trace_winsize(ts, "from SET_TTYSIZE");
+    (void) code;
+#endif
+
+    (void) rows;
+    (void) cols;
+    (void) height;
+    (void) width;
+}
+
+/*
+ * Update stty settings to match the values returned by dtterm window
+ * manipulation 18 and 19.
+ */
+void
+xtermSetWinSize(XtermWidget xw)
+{
+#if OPT_TEK4014
+    if (!TEK4014_ACTIVE(xw))
+#endif
+	if (XtIsRealized((Widget) xw)) {
+	    TScreen *screen = TScreenOf(xw);
+
+	    TRACE(("xtermSetWinSize\n"));
+	    update_winsize(screen->respond,
+			   MaxRows(screen),
+			   MaxCols(screen),
+			   Height(screen),
+			   Width(screen));
+	}
+}

Index: xsrc/external/mit/xterm/dist/ptyx.h
diff -u xsrc/external/mit/xterm/dist/ptyx.h:1.13 xsrc/external/mit/xterm/dist/ptyx.h:1.14
--- xsrc/external/mit/xterm/dist/ptyx.h:1.13	Wed Mar  8 02:55:12 2017
+++ xsrc/external/mit/xterm/dist/ptyx.h	Wed Mar 14 06:04:47 2018
@@ -1,7 +1,7 @@
-/* $XTermId: ptyx.h,v 1.830 2016/10/07 00:38:57 tom Exp $ */
+/* $XTermId: ptyx.h,v 1.854 2017/05/29 00:49:11 tom Exp $ */
 
 /*
- * Copyright 1999-2015,2016 by Thomas E. Dickey
+ * Copyright 1999-2016,2017 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -112,8 +112,8 @@
 #define TypeXtMalloc(type)	TypeXtMallocN(type, 1)
 
 /* use these to allocate partly-structured data */
-#define CastMallocN(type,n)	(type *)malloc(sizeof(type) + (size_t) (n))
-#define CastMalloc(type)	CastMallocN(type,0)
+#define TextAlloc(n)		(char *)malloc(sizeof(char) * (size_t) ((n) + 1))
+#define CastMalloc(type)	(type *)malloc(sizeof(type))
 
 #define BumpBuffer(type, buffer, size, want) \
 	if (want >= size) { \
@@ -397,7 +397,9 @@ typedef struct {
 
 #define TERMCAP_SIZE 1500		/* 1023 is standard; 'screen' exceeds */
 
-#define NMENUFONTS 9			/* font entries in fontMenu */
+#define MAX_XLFD_FONTS	1
+#define MAX_XFT_FONTS	1
+#define NMENUFONTS	9		/* font entries in fontMenu */
 
 #define	NBOX	5			/* Number of Points in box	*/
 #define	NPARAM	30			/* Max. parameters		*/
@@ -689,6 +691,10 @@ typedef struct {
 #endif
 #endif
 
+#ifndef OPT_REPORT_CCLASS
+#define OPT_REPORT_CCLASS  1 /* provide "-report-charclass" option */
+#endif
+
 #ifndef OPT_REPORT_COLORS
 #define OPT_REPORT_COLORS  1 /* provide "-report-colors" option */
 #endif
@@ -856,9 +862,13 @@ typedef struct {
 typedef enum {
     fNorm = 0			/* normal font */
     , fBold			/* bold font */
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+    , fItal			/* italic font */
+#endif
 #if OPT_WIDE_CHARS
     , fWide			/* double-width font */
     , fWBold			/* double-width bold font */
+    , fWItal			/* double-width italic font */
 #endif
     , fMAX
 } VTFontEnum;
@@ -1158,6 +1168,21 @@ typedef enum {
 #endif
 
 typedef enum {
+    emX10 = 1
+    , emLocator
+    , emVT200Click
+    , emVT200Hilite
+    , emAnyButton
+    , emAnyEvent
+    , emFocusEvent
+    , emExtended
+    , emSGR
+    , emURXVT
+    , emAlternateScroll
+    , emLAST
+} MouseOps;
+
+typedef enum {
     etSetTcap = 1
     , etGetTcap
     , etLAST
@@ -1619,9 +1644,16 @@ typedef struct {
 
 #define KNOWN_MISSING	256
 
+typedef enum {
+	fwNever = 0,
+	fwResource,
+	fwAlways
+} fontWarningTypes;
+
 typedef struct {
 	unsigned	chrset;
 	unsigned	flags;
+	fontWarningTypes warn;
 	XFontStruct *	fs;
 	char *		fn;
 	FontMap		map;
@@ -1731,12 +1763,12 @@ typedef enum {
 
 	/* index into vt_shell[] or tek_shell[] */
 typedef enum {
-	noMenu = -1,
-	mainMenu,
-	vtMenu,
-	fontMenu,
+	noMenu = -1
+	,mainMenu
+	,vtMenu
+	,fontMenu
 #if OPT_TEK4014
-	tekMenu
+	,tekMenu
 #endif
 } MenuIndex;
 
@@ -1797,6 +1829,7 @@ typedef struct {
 	Char		curgl;
 	Char		curgr;
 	int		gsets[4];
+	Boolean		wrap_flag;
 #if OPT_ISO_COLORS
 	int		cur_foreground; /* current foreground color	*/
 	int		cur_background; /* current background color	*/
@@ -1864,17 +1897,42 @@ typedef struct {
 } TKwin;
 
 typedef struct {
-    String f_n;			/* the normal font */
-    String f_b;			/* the bold font */
+    char *f_n;			/* the normal font */
+    char *f_b;			/* the bold font */
+#if OPT_WIDE_ATTRS
+    char *f_i;			/* italic font (Xft only) */
+#endif
 #if OPT_WIDE_CHARS
-    String f_w;			/* the normal wide font */
-    String f_wb;		/* the bold wide font */
+    char *f_w;			/* the normal wide font */
+    char *f_wb;			/* the bold wide font */
+    char *f_wi;			/* wide italic font (Xft only) */
 #endif
 } VTFontNames;
 
 typedef struct {
+    char **list_n;		/* the normal font */
+    char **list_b;		/* the bold font */
+#if OPT_WIDE_ATTRS || OPT_RENDERWIDE
+    char **list_i;		/* italic font (Xft only) */
+#endif
+#if OPT_WIDE_CHARS
+    char **list_w;		/* the normal wide font */
+    char **list_wb;		/* the bold wide font */
+    char **list_wi;		/* wide italic font (Xft only) */
+#endif
+} VTFontList;
+
+typedef struct {
+    VTFontList x11;
+#if OPT_RENDERFONT
+    VTFontList xft;
+#endif
+} XtermFontNames;
+
+typedef struct {
     VTFontNames default_font;
     String menu_font_names[NMENUFONTS][fMAX];
+    XtermFontNames fonts;
 } SubResourceRec;
 
 #if OPT_INPUT_METHOD
@@ -1993,7 +2051,9 @@ typedef struct {
 	unsigned	send_mouse_pos;	/* user wants mouse transition  */
 					/* and position information	*/
 	int		extend_coords;	/* support large terminals	*/
+#if OPT_FOCUS_EVENT
 	Boolean		send_focus_pos; /* user wants focus in/out info */
+#endif
 	Boolean		quiet_grab;	/* true if no cursor change on focus */
 #if OPT_PASTE64
 	Cardinal	base64_paste;	/* set to send paste in base64	*/
@@ -2033,9 +2093,14 @@ typedef struct {
 	Boolean		visualbell;	/* visual bell mode		*/
 	Boolean		poponbell;	/* pop on bell mode		*/
 
+	Boolean		eraseSavedLines; /* eraseSavedLines option	*/
+	Boolean		eraseSavedLines0; /* initial eraseSavedLines	*/
+	Boolean		tabCancelsWrap; /* tabCancelsWrap option	*/
+
 	Boolean		allowPasteControls; /* PasteControls mode	*/
 	Boolean		allowColorOps;	/* ColorOps mode		*/
 	Boolean		allowFontOps;	/* FontOps mode			*/
+	Boolean		allowMouseOps;	/* MouseOps mode		*/
 	Boolean		allowSendEvents;/* SendEvent mode		*/
 	Boolean		allowTcapOps;	/* TcapOps mode			*/
 	Boolean		allowTitleOps;	/* TitleOps mode		*/
@@ -2044,6 +2109,7 @@ typedef struct {
 	Boolean		allowPasteControl0; /* PasteControls mode	*/
 	Boolean		allowColorOp0;	/* initial ColorOps mode	*/
 	Boolean		allowFontOp0;	/* initial FontOps mode		*/
+	Boolean		allowMouseOp0;	/* initial MouseOps mode	*/
 	Boolean		allowSendEvent0;/* initial SendEvent mode	*/
 	Boolean		allowTcapOp0;	/* initial TcapOps mode		*/
 	Boolean		allowTitleOp0;	/* initial TitleOps mode	*/
@@ -2055,6 +2121,9 @@ typedef struct {
 	String		disallowedFontOps;
 	char		disallow_font_ops[efLAST];
 
+	String		disallowedMouseOps;
+	char		disallow_mouse_ops[emLAST];
+
 	String		disallowedTcapOps;
 	char		disallow_tcap_ops[etLAST];
 
@@ -2397,7 +2466,7 @@ typedef struct {
 	 */
 	Pixmap		menu_item_bitmap;	/* mask for checking items */
 	String		initial_font;
-	String		menu_font_names[NMENUFONTS][fMAX];
+	char *		menu_font_names[NMENUFONTS][fMAX];
 #define MenuFontName(n) menu_font_names[n][fNorm]
 #define EscapeFontName() MenuFontName(fontMenu_fontescape)
 #define SelectFontName() MenuFontName(fontMenu_fontsel)
@@ -2512,12 +2581,6 @@ typedef struct {
 } FlagList;
 
 typedef enum {
-    fwNever = 0,
-    fwResource,
-    fwAlways
-} fontWarningTypes;
-
-typedef enum {
     keyboardIsLegacy,		/* bogus vt220 codes for F1-F4, etc. */
     keyboardIsDefault,
     keyboardIsHP,
@@ -2644,7 +2707,6 @@ typedef struct _Misc {
     Boolean log_on;
 #endif
     Boolean login_shell;
-    Boolean palette_changed;
     Boolean re_verse;
     Boolean re_verse0;		/* initial value of "-rv" */
     XtGravity resizeGravity;
@@ -2672,11 +2734,7 @@ typedef struct _Misc {
     char* input_method;
     char* preedit_type;
     Boolean open_im;		/* true if input-method is opened */
-    Boolean cannot_im;		/* true if we cannot use input-method */
     int retry_im;
-    XFontSet xim_fs;		/* fontset for XIM preedit */
-    int xim_fs_ascent;		/* ascent of fs */
-    TInput inputs[NINPUTWIDGETS];
 #endif
     Boolean dynamicColors;
 #ifndef NO_ACTIVE_ICON
@@ -2698,8 +2756,7 @@ typedef struct _Misc {
     Boolean alwaysUseMods;	/* true if we always want f-key modifiers */
 #endif
 #if OPT_RENDERFONT
-    char *face_name;
-    char *face_wide_name;
+    VTFontNames default_xft;
     float face_size[NMENUFONTS];
     char *render_font_s;
 #endif
@@ -2719,6 +2776,12 @@ typedef struct _Work {
 #ifndef NO_ACTIVE_ICON
     int active_icon;		/* use application icon window  */
 #endif /* NO_ACTIVE_ICON */
+#if OPT_INPUT_METHOD
+    Boolean cannot_im;		/* true if we cannot use input-method */
+    XFontSet xim_fs;		/* fontset for XIM preedit */
+    int xim_fs_ascent;		/* ascent of fs */
+    TInput inputs[NINPUTWIDGETS];
+#endif
 #if OPT_MAXIMIZE
 #define MAX_EWMH_MODE 3
 #define MAX_EWMH_DATA (1 + OPT_TEK4014)
@@ -2733,6 +2796,7 @@ typedef struct _Work {
     unsigned alt_mods;		/* modifier for Alt_L or Alt_R */
     unsigned meta_mods;		/* modifier for Meta_L or Meta_R */
 #endif
+    XtermFontNames fonts;
 #if OPT_RENDERFONT
     Boolean render_font;
 #endif
@@ -2741,6 +2805,7 @@ typedef struct _Work {
     char dabbrev_data[MAX_DABBREV];
 #endif
     ScrnColors *oldColors;
+    Boolean palette_changed;
 } Work;
 
 typedef struct {int foo;} XtermClassPart, TekClassPart;
@@ -2812,6 +2877,7 @@ typedef struct _XtermWidgetRec {
 #if OPT_TEK4014
 typedef struct _TekWidgetRec {
     CorePart	core;
+    XtermWidget vt;		/* main widget has border, etc. */
     TekPart	tek;		/* contains resources */
     TekScreen	screen;		/* contains working data (no resources) */
     Bool	init_menu;
@@ -2972,11 +3038,11 @@ typedef struct _TekWidgetRec {
 #define WhichVWin(screen)	((screen)->whichVwin)
 #define WhichTWin(screen)	((screen)->whichTwin)
 
-#define WhichVFont(screen,name)	(IsIcon(screen) ? (screen)->fnt_icon.fs \
-						: (screen)->name)
-#define FontAscent(screen)	(IsIcon(screen) ? (screen)->fnt_icon.fs->ascent \
+#define WhichVFont(screen,name)	(IsIcon(screen) ? getIconicFont(screen) \
+						: getNormalFont(screen, name))->fs
+#define FontAscent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->ascent \
 						: WhichVWin(screen)->f_ascent)
-#define FontDescent(screen)	(IsIcon(screen) ? (screen)->fnt_icon.fs->descent \
+#define FontDescent(screen)	(IsIcon(screen) ? getIconicFont(screen)->fs->descent \
 						: WhichVWin(screen)->f_descent)
 #else /* NO_ACTIVE_ICON */
 
@@ -2985,7 +3051,7 @@ typedef struct _TekWidgetRec {
 #define WhichVWin(screen)	(&((screen)->fullVwin))
 #define WhichTWin(screen)	(&((screen)->fullTwin))
 
-#define WhichVFont(screen,name)	((screen)->name)
+#define WhichVFont(screen,name)	getNormalFont(screen, name)->fs
 #define FontAscent(screen)	WhichVWin(screen)->f_ascent
 #define FontDescent(screen)	WhichVWin(screen)->f_descent
 
@@ -3019,12 +3085,12 @@ typedef struct _TekWidgetRec {
 #define FontWidth(screen)	WhichVWin(screen)->f_width
 #define FontHeight(screen)	WhichVWin(screen)->f_height
 
-#define NormalFont(screen)	WhichVFont(screen, fnts[fNorm].fs)
-#define BoldFont(screen)	WhichVFont(screen, fnts[fBold].fs)
+#define NormalFont(screen)	WhichVFont(screen, fNorm)
+#define BoldFont(screen)	WhichVFont(screen, fBold)
 
 #if OPT_WIDE_CHARS
-#define NormalWFont(screen)	WhichVFont(screen, fnts[fWide].fs)
-#define BoldWFont(screen)	WhichVFont(screen, fnts[fWBold].fs)
+#define NormalWFont(screen)	WhichVFont(screen, fWide)
+#define BoldWFont(screen)	WhichVFont(screen, fWBold)
 #endif
 
 #define ScrollbarWidth(screen)	WhichVWin(screen)->sb_info.width
@@ -3040,6 +3106,10 @@ typedef struct _TekWidgetRec {
 #define TFullHeight(screen)	WhichTWin(screen)->fullheight
 #define TekScale(screen)	WhichTWin(screen)->tekscale
 
+/* use these before tek4014 is realized, good enough for default "9x15" font */
+#define TDefaultRows		37
+#define TDefaultCols		75
+
 #define BorderWidth(w)		((w)->core.border_width)
 #define BorderPixel(w)		((w)->core.border_pixel)
 
@@ -3051,6 +3121,9 @@ typedef struct _TekWidgetRec {
 #define AllowFontOps(w,name)	(AllowXtermOps(w, allowFontOps) || \
 				 !TScreenOf(w)->disallow_font_ops[name])
 
+#define AllowMouseOps(w,name)	(AllowXtermOps(w, allowMouseOps) || \
+				 !TScreenOf(w)->disallow_mouse_ops[name])
+
 #define AllowTcapOps(w,name)	(AllowXtermOps(w, allowTcapOps) || \
 				 !TScreenOf(w)->disallow_tcap_ops[name])
 

Index: xsrc/external/mit/xterm/dist/xterm.man
diff -u xsrc/external/mit/xterm/dist/xterm.man:1.15 xsrc/external/mit/xterm/dist/xterm.man:1.16
--- xsrc/external/mit/xterm/dist/xterm.man:1.15	Wed Mar  8 02:55:12 2017
+++ xsrc/external/mit/xterm/dist/xterm.man	Wed Mar 14 06:04:47 2018
@@ -1,7 +1,7 @@
 '\" t
-.\" $XTermId: xterm.man,v 1.690 2016/10/06 22:57:58 tom Exp $
+.\" $XTermId: xterm.man,v 1.715 2017/06/18 18:07:02 tom Exp $
 .\"
-.\" Copyright 1996-2015,2016 by Thomas E. Dickey
+.\" Copyright 1996-2016,2017 by Thomas E. Dickey
 .\"
 .\"                         All Rights Reserved
 .\"
@@ -61,13 +61,16 @@
 .\"
 .\" Bulleted paragraph
 .de bP
-.IP \(bu 4
+.ie \n(.IP \(bu 4
+.el    .IP \(bu 2
 ..
 .\" these would be fallbacks for DS/DE,
 .\" but groff changed the meaning of the macros.
 .de NS
-.sp
-.in +4
+.ie \n(.sp
+.el    .sp .5
+.ie \n(.in +4
+.el    .in +2
 .nf
 .ft C			\" Courier
 ..
@@ -125,17 +128,19 @@ and the \fBTek Options\fP menu in the 40
 .SH EMULATIONS
 \fI\*N\fP provides usable emulations of related DEC terminals:
 .bP
-The VT52 emulation is complete.
+VT52 emulation is complete.
 .bP
-The VT102 emulation is fairly complete, but does not support
-autorepeat.
+VT102 emulation is fairly complete, but does not support autorepeat
+(because that would affect the keyboard used by other X clients).
+.IP
 Double-size characters are displayed properly if your font server supports
 scalable fonts.
 .bP
-The VT220 emulation does not support soft fonts, it is otherwise complete.
+VT220 emulation does not support soft fonts, it is otherwise complete.
 .bP
-The VT420 emulation (the default) supports controls for manipulating rectangles
+VT420 emulation (the default) supports controls for manipulating rectangles
 of characters as well as left/right margins.
+.IP
 \fI\*N\fP does not support some other features which
 are not suitable for emulation, e.g., two-sessions.
 .PP
@@ -156,7 +161,8 @@ an optional platform-specific entry (\*(
 .PP
 \fI\*N\fP automatically searches the
 terminal database in this order for these entries and then
-sets the \*(``TERM\*('' and the \*(``TERMCAP\*('' environment variables.
+sets the \*(``TERM\*('' variable
+(and the \*(``TERMCAP\*('' environment variable on a few older systems).
 The alternatives after \*(``xterm\*('' are very old,
 from the late 1980s.
 .PP
@@ -276,15 +282,34 @@ See \fIXterm Control Sequences\fP for de
 .
 .\" ***************************************************************************
 .SH OPTIONS
-The \fI\*n\fP terminal emulator
-accepts the standard X Toolkit command line options as well as
-many application-specific options.
-If the option begins with a
-.RB ` + '
+Because \fI\*n\fP uses the X Toolkit library,
+it accepts the standard X Toolkit command line options.
+\fI\*N\fP also accepts many application-specific options.
+.PP
+By convention, if an option begins with a
+.RB \*(`` + \*(''
 instead of a
-.RB ` \- ',
+.RB \*(`` \- \*('',
 the option is restored to its default value.
 .\" ***************************************************************************
+.PP
+Most of the \fI\*n\fP options are actually parsed by the X Toolkit,
+which sets resource values, and
+overrides corresponding resource-settings in your X resource files.
+\fI\*N\fP provides the X Toolkit with a table of options.
+A few of these are marked, telling the X Toolkit to ignore them
+(\fB\-help\fP,
+\fB\-version\fP,
+\fB\-class\fP,
+\fB\-e\fP, and
+\fB\-into\fP).
+After the X Toolkit has parsed the command-line parameters,
+it removes those which it handles,
+leaving the specially-marked parameters for \fI\*n\fP to handle.
+.\" ***************************************************************************
+.PP
+These options do not set a resource value,
+and are handled specially:
 .TP 8
 .B \-version
 This causes \fI\*n\fP to print a version number to the standard output,
@@ -308,20 +333,6 @@ when an unknown option is used, e.g.,
 If the logic for a particular option such as logging is not compiled
 into \fI\*n\fP, the help text for that option also is not displayed
 by the \fB\-help\fP option.
-.\" ***************************************************************************
-.PP
-Most of the \fI\*n\fP options are actually parsed by the X Toolkit,
-which sets resource values.
-\fI\*N\fP provides the X Toolkit with a table of options.
-A few of these are marked, telling the X Toolkit to ignore them
-(\fB\-help\fP,
-\fB\-version\fP,
-\fB\-class\fP,
-\fB\-e\fP, and
-\fB\-into\fP).
-After the X Toolkit has parsed the command-line parameters,
-it removes those which it handles,
-leaving the specially-marked parameters for \fI\*n\fP to handle.
 .PP
 The \fB\-version\fP and \fB\-help\fP options are interpreted even if \fI\*n\fP
 cannot open the display, and are useful for testing and configuration scripts.
@@ -609,6 +620,9 @@ When a CJK
 double-width font is specified, you also need to turn
 on the \fBcjkWidth\fP resource.
 .IP
+If you specify both \fB\-fa\fP and the X Toolkit option \fB\-fn\fP,
+the \fB\-fa\fP setting overrides the latter.
+.IP
 See also the \fBrenderFont\fP resource,
 which combines with this to determine whether FreeType fonts are
 initially active.
@@ -986,6 +1000,10 @@ Control-G is received.
 This option indicates that the window should not be raised whenever a
 Control-G is received.
 .TP 8
+.B \-report\-charclass
+Print a report to the standard output showing information about the
+character-classes which can be altered using the \fBcharClass\fP resource.
+.TP 8
 .B \-report\-colors
 Print a report to the standard output showing information about colors
 as \fI\*n\fP allocates them.
@@ -1137,7 +1155,8 @@ entries that work with \fI\*n\fR are:
 .IP
 .I \*n
 automatically searches the terminal database in this order for these entries and then
-sets the \*(``TERM\*('' and the \*(``TERMCAP\*('' environment variables.
+sets the \*(``TERM\*('' variable
+(and the \*(``TERMCAP\*('' environment variable, if relevant).
 .TP 8
 .B +t
 This option indicates that \fI\*n\fP should start in VT\fIxxx\fP mode.
@@ -1435,10 +1454,21 @@ name.
 This option specifies a resource string to be used.
 This is especially
 useful for setting resources that do not have separate command line options.
+.PP
+X Toolkit accepts alternate names for a few of these options, e.g.,
+.bP
+\*(``\fB\-background\fP\*('' for \*(``\fB\-bg\fP\*(''
+.bP
+\*(``\fB\-font\fP\*('' for \*(``\fB\-fn\fP\*(''
+.bP
+\*(``\fB\-foreground\fP\*('' for \*(``\fB\-fg\fP\*(''
+.PP
+Abbreviated options also are supported, e.g.,
+\*(``\fB\-v\fP\*('' for \*(``\fB\-verbose\fP.\*(''
 .
 .
 .SH RESOURCES
-The program understands all of the core X Toolkit resource names and classes.
+\fI\*N\fP understands all of the core X Toolkit resource names and classes.
 Application specific resources (e.g., \*(``\fB__default_class__.\fP\fINAME\fP\*('') follow:
 .SS Application Resources
 .TP 8
@@ -1671,6 +1701,13 @@ maximize its layout on startup.
 The default is
 \*(``false\*(''.
 .TP 8
+.B "menuHeight\fP (class\fB MenuHeight\fP)"
+Specifies the height of the toolbar,
+which may be increased by the X toolkit layout widget depending upon
+the fontsize used.
+The default is
+\*(``25\*(''.
+.TP 8
 .B "messages\fP (class\fB Messages\fP)"
 Specifies whether write access to the terminal is allowed initially.
 See \fBmesg\fP(1).
@@ -1724,8 +1761,9 @@ value.
 If \*(``false\*('', \fI\*n\fP will set the \fIstty\fP erase value to match its own
 configuration, using the \fBkb\fP string from the termcap entry as
 a reference, if available.
+.IP
 In either case, the result is applied to the TERMCAP variable
-which \fI\*n\fP sets.
+which \fI\*n\fP sets, if the system uses TERMCAP.
 .IP
 See also the \fBttyModes\fP resource, which may override this.
 The default is \*(``__initial_erase__\*(''.
@@ -2004,6 +2042,11 @@ The default is \*(``true\*(''.
 .B "allowFontOps\fP (class\fB AllowFontOps\fP)"
 Specifies whether control sequences that set/query the font should be allowed.
 The default is \*(``true\*(''.
+.TP
+.B "allowMouseOps\fP (class\fB AllowMouseOps\fP)"
+Specifies whether control sequences that enable \fI\*n\fP to send
+escape sequences to the host on mouse-clicks and movement.
+The default is \*(``true\*(''.
 .TP 8
 .B "allowPasteControls\fP (class\fB AllowPasteControls\fP)"
 If true, allow control characters such as BEL and CAN to be pasted.
@@ -2399,7 +2442,10 @@ The default for this resource is \*(``fa
 .TP 8
 .B "charClass\fP (class\fB CharClass\fP)"
 Specifies comma-separated lists of character class bindings of the form
-[\fIlow\fP-]\fIhigh\fP:\fIvalue\fP.
+.NS
+\fIlow\fP[-\fIhigh]\fP[:\fIvalue\fP].
+.NE
+.IP
 These are used in determining which
 sets of characters should be treated the same when doing cut and paste.
 See the \fBCHARACTER CLASSES\fP section.
@@ -2637,16 +2683,16 @@ in milliseconds.
 The same timer is used for text blinking.
 The default is \*(``600\*(''.
 .TP 8
+.B "cursorUnderLine\fP (class\fB CursorUnderLine\fP)"
+Specifies whether to make the cursor underlined or a box.
+The default is \*(``false\*(''.
+.TP 8
 .B "cutNewline\fP (class\fB CutNewline\fP)"
 If \*(``false\*('', triple clicking to select a line does not include the Newline
 at the end of the line.
 If \*(``true\*('', the Newline is selected.
 The default is \*(``true\*(''.
 .TP 8
-.B "cursorUnderLine\fP (class\fB CursorUnderLine\fP)"
-Specifies whether to make the cursor underlined or a box.
-The default is \*(``false\*(''.
-.TP 8
 .B "cutToBeginningOfLine\fP (class\fB CutToBeginningOfLine\fP)"
 If \*(``false\*('', triple clicking to select a line selects only from the
 current word forward.
@@ -2723,6 +2769,53 @@ GetFont
 Report the specified font.
 .RE
 .TP 8
+.B "disallowedMouseOps\fP (class\fB DisallowedMouseOps\fP)"
+Specify which features will be disabled if \fBallowMouseOps\fP is false.
+This is a comma-separated list of names.
+The default value is \*(``*\*('' which matches all names.
+The names are listed below.
+\fI\*N\fP ignores capitalization, but
+they are shown in mixed-case for clarity.
+.RS
+.TP 5
+X10
+The original X10 mouse protocol.
+.TP 5
+Locator
+DEC locator mode
+.TP 5
+VT200Click
+X11 mouse-clicks only.
+.TP 5
+VT200Hilite
+X11 mouse-clicks and highlighting.
+.TP 5
+AnyButton
+XFree86 \fI\*n\fP any-button mode sends button-clicks as
+well as motion events while the button is pressed.
+.TP 5
+AnyEvent
+XFree86 \fI\*n\fP any-event mode sends button-clicks as
+well as motion events whether or not a button is pressed.
+.TP 5
+FocusEvent
+Send FocusIn/FocusOut events.
+.TP 5
+Extended
+The first extension beyond X11 mouse protocol, this encodes
+the coordinates in UTF-8.
+It is deprecated in favor of \fISGR\fP, but provided for compatibility.
+.TP 5
+SGR
+This is the recommended extension for mouse-coordinates
+.TP 5
+URXVT
+Like \fIExtended\fP, this is provided for compatibility.
+.TP 5
+AlternateScroll
+This overrides the \fBalternateScroll\fP resource.
+.RE
+.TP 8
 .B "disallowedTcapOps\fP (class\fB DisallowedTcapOps\fP)"
 Specify which features will be disabled if \fBallowTcapOps\fP is false.
 This is a comma-separated list of names.
@@ -2945,14 +3038,29 @@ Override \fI\*n\fP's default selection t
 The default is an empty string, i.e., \*(``\*('',
 which does not override anything.
 .TP 8
+.B "eraseSavedLines\fP (class\fB EraseSavedLines\fP)"
+Specifies whether or not to allow
+\fI\*n\fP extended ED/DECSED control sequences to erase the saved-line buffer.
+The default is \*(``true\*(''.
+.TP 8
 .B "faceName\fP (class\fB FaceName\fP)"
 Specify the pattern for scalable fonts selected from the FreeType
 library if support for that library was compiled into \fI\*n\fR.
 There is no default value.
 .IP
-If not specified,
-or if there is no match for both normal and bold fonts,
-\fI\*n\fR uses the bitmap \fBfont\fP and related resources.
+One or more fonts can be specified, separated by commas.
+If prefixed with \*(``x:\*('' or \*(``x11:\*('' the specification
+applies to the XLFD \fBfont\fP resource.
+A \*(``xft:\*('' prefix is accepted but unnecessary since
+a missing prefix for \fBfaceName\fP means that it will be used for TrueType.
+For example,
+.NS
+XTerm*faceName: x:fixed,xft:Bitstream Vera Sans Mono
+.NE
+.IP
+If no \fBfaceName\fP resource is specified,
+or if there is no match for both TrueType normal and bold fonts,
+\fI\*n\fR uses the XLFD (bitmap) \fBfont\fP and related resources.
 .IP
 It is possible to select suitable bitmap fonts using a script such as this:
 .NS
@@ -2977,6 +3085,9 @@ Specify a double-width scalable font for
 this, e.g., in CJK applications.
 There is no default value.
 .IP
+Like the \fBfaceName\fP resource, this allows one or more comma-separated
+font specifications to be applied to the \fIwide\fP TrueType or XLFD fonts.
+.IP
 If the application uses double-wide characters and this resource is not given,
 \fI\*n\fP will use a scaled version of the font given by \fBfaceName\fP.
 .TP 8
@@ -3217,7 +3328,7 @@ true	false	default	set	HFG/fg
 true	false	set	default	bg/HBG
 true	false	set	set	HFG/HBG
 =
-true	true	default	default	fg/fg (useless)
+true	true	default	default	bg/fg
 true	true	default	set	HFG/fg
 true	true	set	default	fg/HBG
 true	true	set	set	HFG/HBG
@@ -3303,7 +3414,7 @@ Specifies which of the VT100 fonts to us
 Values are the same as for the \fBset-vt-font\fP action.
 The default is \*(``d\*('', i.e., \*(``default\*(''.
 .TP 8
-.B "inputMethod\fP (class\fB XtCInputMethod\fP)"
+.B "inputMethod\fP (class\fB InputMethod\fP)"
 Tells \fI\*n\fP which type of input method to use.
 There is no default method.
 .TP 8
@@ -3392,6 +3503,7 @@ Regardless of your locale and encoding,
 you need an ISO-10646-1 font to display the result.
 Your configuration may not include this font,
 or locale-support by \fI\*n\fP may not be needed.
+.IP
 At startup, \fI\*n\fP uses a mechanism equivalent to
 the \fBload-vt-fonts(utf8Fonts,\ Utf8Fonts)\fP action
 to load font name subresources of the VT100 widget.
@@ -3400,6 +3512,17 @@ resource patterns such as \*(``\fB*vt100
 and (if this resource is enabled), override the normal fonts.
 If no subresources are found,
 the normal fonts such as \*(``\fB*vt100.font\fP\*('', etc., are used.
+.IP
+For instance, you could have this in your resource file:
+.NS
+*VT100.font: 12x24
+*VT100.utf8Fonts.font:9x15
+.NE
+.IP
+When started with a UTF-8 locale, \fI\*n\fP would use 9x15, but
+allow you to switch to the 12x24 font
+using the menu entry \*(``\fBUTF-8 Fonts\fP\*(''.
+.IP
 The resource files distributed with \fI\*n\fP use ISO-10646-1 fonts,
 but do not rely on them unless you are using the locale mechanism.
 .TP 8
@@ -3429,7 +3552,7 @@ Specifies whether or not the shell to be
 as a login shell.
 The default is \*(``false\*(''.
 .TP 8
-.B "logFile\fP (class\fB LogFile\fP)"
+.B "logFile\fP (class\fB Logfile\fP)"
 Specify the name for \fI\*n\fP's log-file.
 If no name is specified, \fI\*n\fP will generate a name when
 logging is enabled,
@@ -3441,7 +3564,7 @@ whether by the command-line option \fB\-
 or the menu entry \fBLog to File\fP.
 The default is \*(``false\*(''.
 .TP 8
-.B "logging\fP (class\fB logging\fP)"
+.B "logging\fP (class\fB Logging\fP)"
 If \*(``true\*('', (and if \fBlogInhibit\fP is not set)
 enable the logging feature.
 This resource is set/updated by the \fB\-l\fP option and the
@@ -3453,6 +3576,28 @@ Specifies whether or not the bell should
 right margin.
 The default is \*(``false\*(''.
 .TP 8
+.B "maxGraphicSize\fP (class\fB MaxGraphicSize\fP)"
+If \fI\*n\fR is configured to support ReGIS or SIXEL graphics,
+this resource controls the maximum size of a graph which can be displayed.
+.IP
+The default is \*(``1000x1000\*('' (given as \fIwidth\fP by \fIheight\fP).
+.IP
+If the resource is \*(``auto\*('' then \fI\*n\fR will use the 
+\fBdecTerminalID\fP resource:
+.TS
+l l
+_ _
+r r.
+\fBResult\fR	\fBdecTerminalID\fR
+768x400	125
+800x460	240
+800x460	241
+800x480	330
+800x480	340
+860x750	382
+800x480	\fIother\fP
+.TE
+.TP 8
 .B "metaSendsEscape\fP (class\fB MetaSendsEscape\fP)"
 If \*(``true\*('', Meta characters
 (a character combined with the \fIMeta\fP modifier key)
@@ -3471,12 +3616,13 @@ on startup \fI\*n\fP compares its built-
 wide character width data to decide if it will use the system's data.
 It tests the first \fBmkSampleSize\fP character values,
 and allows up to \fBmkSamplePass\fP mismatches before the test fails.
-The default (for the allowed number of mismatches) is 256.
+The default (for the allowed number of mismatches) is 655
+(one percent of the default value for \fBmkSampleSize\fP).
 .TP 8
 .B "mkSampleSize\fP (class\fB MkSampleSize\fP)"
 With \fBmkSamplePass\fP, this specifies a startup test used for
 initializing wide character width calculations.
-The default (number of characters to check) is 1024.
+The default (number of characters to check) is 65536.
 .TP 8
 .B "mkWidth\fP (class\fB MkWidth\fP)"
 Specifies whether \fI\*n\fP should use a built-in version of the wide
@@ -3631,6 +3777,26 @@ Specifies the number of characters from 
 bell should be rung, when enabled by the \fBmarginBell\fP resource.
 The default is \*(``10\*(''.
 .TP 8
+.B "numColorRegisters\fP (class\fB NumColorRegisters\fP)"
+If \fI\*n\fR is configured to support ReGIS or SIXEL graphics,
+this specifies the number of color-registers which are available.
+.IP
+If this resource is not specified, \fI\*n\fR uses a value determined
+by the \fBdecTerminalID\fP resource:
+.TS
+l l
+_ _
+r r.
+\fBResult\fR	\fBdecTerminalID\fR
+4	125
+4	240
+4	241
+4	330
+16	340
+2	382
+1024	\fIother\fP
+.TE
+.TP 8
 .B "numLock\fP (class\fB NumLock\fP)"
 If \*(``true\*('', \fI\*n\fR checks if NumLock is used as a modifier
 (see \fIxmodmap\fP(__mansuffix__)).
@@ -3706,7 +3872,7 @@ making those inactive.
 On startup, \fI\*n\fP determines the maximum number of clicks
 by the \fBon\fP\fIX\fP\fBClicks\fP resource values which are set.
 .TP 8
-.B "openIm\fP (class\fB XtCOpenIm\fP)"
+.B "openIm\fP (class\fB OpenIm\fP)"
 Tells \fI\*n\fP whether to open the input method at startup.
 The default is \*(``true\*(''.
 .TP 8
@@ -3749,13 +3915,13 @@ If the window is iconified, this has no 
 However, the \fBzIconBeep\fP resource provides you with the ability to
 see which iconified windows have sounded a bell.
 .TP 8
-.B "precompose\fP (class\fB XtCPrecompose\fP)"
+.B "precompose\fP (class\fB Precompose\fP)"
 Tells \fI\*n\fP whether to precompose UTF-8 data into Normalization Form C,
 which combines commonly-used accents onto base characters.
 If it does not do this, accents are left as separatate characters.
 The default is \*(``true\*(''.
 .TP 8
-.B "preeditType\fP (class\fB XtCPreeditType\fP)"
+.B "preeditType\fP (class\fB PreeditType\fP)"
 Tells \fI\*n\fP which types of preedit (preconversion) string to display.
 The default is \*(``OverTheSpot,Root\*(''.
 .TP 8
@@ -3897,11 +4063,14 @@ Controls whether a newline is sent to th
 page function.
 The default is \*(``true\*(''.
 .TP 8
-.B "privateColorRegisters\fP (class\fB privateColorRegisters\fP)"
-If true, allocate separate color registers for each sixel
+.B "privateColorRegisters\fP (class\fB PrivateColorRegisters\fP)"
+If \fI\*n\fR is configured to support ReGIS or SIXEL graphics,
+this controls whether \fI\*n\fR 
+allocates separate color registers for each sixel
 device control string, e.g., for DECGCI.
 If not true, color registers are allocated only once,
-when the terminal is reset.
+when the terminal is reset,
+and color changes  in  any  graphic  affect all graphics.
 The default is \*(``true\*(''.
 .TP 8
 .B "quietGrab\fP (class\fB QuietGrab\fP)"
@@ -3910,17 +4079,33 @@ when \fINotifyGrab\fP and \fINotifyUngra
 event types are received during change of focus.
 The default is \*(``false\*(''.
 .TP 8
+.B "regisDefaultFont\fP (class\fB RegisDefaultFont\fP)"
+If \fI\*n\fR is configured to support ReGIS graphics,
+this resource tells \fI\*n\fR which font to use if the ReGIS data does
+not specify one.
+No default value is specified;
+\fI\*n\fR accepts a TrueType font specification
+as in the \fBfaceName\fP resource.
+.IP
+If no value is specified,
+\fI\*n\fR draws a bitmap indicating a missing character.
+.TP 8
 .B "regisScreenSize\fP (class\fB RegisScreenSize\fP)"
 If \fI\*n\fR is configured to support ReGIS graphics,
-this resource tells \fI\*n\fR the maximum size (in pixels) for graphics.
+this resource tells \fI\*n\fR the default size (in pixels) for these graphics,
+which also sets the default coordinate space
+to [0,0] (upper-left) and [\fIwidth\fP,\fIheight\fP] (lower-right).
+.IP
+The application using ReGIS may use the \*(``A\*('' option of
+the \*(``S\*('' command to adjust the coordinate space or change the
+addressable portion of the screen.
+.IP
+The default is \*(``1000x1000\*('' (given as \fIwidth\fP by \fIheight\fP).
 .IP
 \fI\*N\fR accepts a special resource value \*(``auto\*('',
 which tells \fI\*n\fR to use the \fBdecTerminalID\fP resource to
-set the maximum size based on the hardware terminal's limits.
-Otherwise, \fI\*n\fR expects the size to be given as \fIheight\fPx\fIwidth\fP,
-e.g., \*(``800x1000\*(''.
-.IP
-The default resource value is \*(``800x1000\*(''.
+set the default size based on the hardware terminal's limits.
+Those limits are the same as for the \fBmaxGraphicSize\fP resource.
 .TP 8
 .B "renderFont\fP (class\fB RenderFont\fP)"
 If \fI\*n\fR is built with the Xft library,
@@ -3974,7 +4159,7 @@ made taller, additional saved lines will
 screen; if the window is made shorter, lines will be scrolled off the
 top of the screen, and the top saved lines will be dropped.
 .TP 8
-.B "retryInputMethod\fP (class\fB XtCRetryInputMethod\fP)"
+.B "retryInputMethod\fP (class\fB RetryInputMethod\fP)"
 Tells \fI\*n\fP how many times to retry,
 in case the input-method server is not responding.
 This is a different issue than unsupported preedit type, etc.
@@ -4082,12 +4267,12 @@ the scrollbar to go to the bottom of the
 The default is \*(``true\*(''.
 .TP
 .B "selectToClipboard\fP (class\fB SelectToClipboard\fP)"
-Tells \fI\*n\fP whether to use the PRIMARY or CLIPBOARD for
-SELECT tokens in the selection mechanism.
+Tells \fI\*n\fP whether to use the \fBPRIMARY\fP or \fBCLIPBOARD\fP for
+\fBSELECT\fP tokens in the selection mechanism.
 The \fBset-select\fP action can change this at runtime,
 allowing the user to work with programs that handle only one of these
 mechanisms.
-The default is \*(``false\*('', which tells it to use PRIMARY.
+The default is \*(``false\*('', which tells it to use \fBPRIMARY\fP.
 .TP 8
 .B "shiftFonts\fP (class\fB ShiftFonts\fP)"
 Specifies whether to enable the actions
@@ -4120,10 +4305,19 @@ signals to \fI\*n\fP should be disallowe
 The default is \*(``false\*(''.
 .TP 8
 .B "sixelScrolling\fP (class\fB SixelScrolling\fP)"
-If true, graphics scroll up one line at a time when sixels would be written
+If \fI\*n\fR is configured to support SIXEL graphics,
+this resource tells it whether to
+scroll up one line at a time when sixels would be written
 past the bottom line on the window.
 The default is \*(``false\*(''.
 .TP 8
+.B "sixelScrollsRight\fP (class\fB SixelScrollsRight\fP)"
+If \fI\*n\fR is configured to support SIXEL graphics,
+this resource tells it whether to
+scroll to the right as needed to keep the current position visible
+rather than truncate the plot on the on the right.
+The default is \*(``false\*(''.
+.TP 8
 .B "tekGeometry\fP (class\fB Geometry\fP)"
 Specifies the preferred size and position of the Tektronix window.
 There is no default for this resource.
@@ -4156,15 +4350,23 @@ would be shown before the application wa
 The default for this resource is \*(``false\*(''.
 .TP 8
 .B "titeInhibit\fP (class\fB TiteInhibit\fP)"
-Specifies whether or not \fI\*n\fP should remove \fIti\fP and \fIte\fP
+Originally specified whether or not \fI\*n\fP
+should remove \fIti\fP and \fIte\fP
 termcap entries (used to switch between alternate screens on startup of many
 screen-oriented programs) from the TERMCAP string.
+.IP
+TERMCAP is used rarely now, but \fI\*n\fP supports the feature on modern systems:
+.RS
+.bP
 If set,
 \fI\*n\fP also ignores the escape sequence to switch to the
 alternate screen.
+.bP
 \fI\*N\fP supports terminfo in a different way, supporting composite control
 sequences (also known as private modes) 1047, 1048 and 1049 which have the same
 effect as the original 47 control sequence.
+.RE
+.IP
 The default for this resource is \*(``false\*(''.
 .TP 8
 .B "titleModes\fP (class\fB TitleModes\fP)"
@@ -4268,7 +4470,7 @@ See the discussion of the \fBlocale\fP r
 This specifies whether \fI\*n\fP will use UTF-8 fonts specified via
 resource patterns such as \*(``\fB*vt100.utf8Fonts.font\fP\*(''
 or normal (ISO-8859-1) fonts via patterns such as \*(``\fB*vt100.font\fP\*(''.
-The resource can be set via the menu entry \*(``UTF-8 Fonts\*(''.
+The resource can be set via the menu entry \*(``\fBUTF-8 Fonts\fP\*(''.
 The default is \*(``default\*(''.
 .IP
 \fI\*N\fP accepts either a keyword (ignoring case)
@@ -4786,7 +4988,26 @@ foreground and background color.
 .PP
 Once the VT\fIxxx\fP window is created,
 .I \*n
-allows you to select text and copy it within the same or other windows.
+allows you to select text and copy it within the same or other windows
+using the \fIpointer\fP or the keyboard.
+.
+.PP
+A \*(``pointer\*('' could be a mouse, touchpad or similar device.
+X applications generally do not care,
+since they see only \fIbutton events\fP which have
+.bP
+position and
+.bP
+button up/down state
+.PP
+\fI\*N\fP can see these events as long as it has \fIfocus\fP.
+.PP
+The keyboard also supplies events, but it is less flexible than
+the pointer for selecting/copying text.
+.PP
+\fIEvents\fP are applied to \fIactions\fP using the \fBtranslations\fP resource.
+See \fBActions\fP for a complete list, and \fBDefault Key Bindings\fP
+for the built-in set of \fBtranslations\fP resources.
 .
 .SS "Selection Functions"
 .PP
@@ -4795,14 +5016,24 @@ modifiers, and when they are used with t
 The assignment of the functions described below to keys and buttons may
 be changed through the resource database; see \fBActions\fP below.
 .
-.PP
-Pointer button one (usually left) is used to save text into the cut buffer.
+.TP 5
+Pointer button one (usually left)
+is used to save text into the cut buffer:
+.NS
+~Meta <Btn1Down>:\fBselect-start\fP()
+.NE
+.IP
 Move the cursor to beginning of the text,
 and then hold the button down while moving the cursor to the end of the region
 and releasing the button.
-The selected text is highlighted and is saved in the global cut buffer
-and made the PRIMARY selection when the button is released.
+The selected text is highlighted and is saved in the global \fIcut buffer\fP
+and made the selection when the button is released:
+.NS
+<BtnUp>:\fBselect-end\fP(\fBSELECT\fP, CUT_BUFFER0) \n\
+.NE
+.IP
 Normally (but see the discussion of \fBon2Clicks\fP, etc):
+.RS
 .bP
 Double-clicking selects by words.
 .bP
@@ -4810,7 +5041,8 @@ Triple-clicking
 selects by lines.
 .bP
 Quadruple-clicking goes back to characters, etc.
-.PP
+.RE
+.IP
 Multiple-click is determined by the time from button up to
 button down, so you can change the selection unit in the middle of a selection.
 Logical words and lines selected by double- or triple-clicking may wrap
@@ -4820,14 +5052,22 @@ If the key/button bindings specify that 
 \fI\*n\fP will leave the selected text highlighted for as long as it
 is the selection owner.
 .
-.PP
-Pointer button two (usually middle) \*(``types\*('' (pastes) the text from
-the PRIMARY selection, if any, otherwise from
-the cut buffer,
-inserting it as keyboard input.
+.TP 5
+Pointer button two (usually middle)
+\*(``types\*('' (\fIpastes\fP) the text from
+the given selection, if any,
+otherwise from the cut buffer, inserting it as keyboard input:
+.NS
+~Ctrl ~Meta <Btn2Up>:\fB\fBinsert-selection\fP\fP(\fBSELECT\fP, CUT_BUFFER0)
+.NE
 .
-.PP
-Pointer button three (usually right) extends the current selection.
+.TP 5
+Pointer button three (usually right)
+\fIextends\fP the current selection.
+.NS
+~Ctrl ~Meta <Btn3Down>:\fB\fBstart-extend\fP\fP()
+.NE
+.IP
 (Without loss of generality,
 you can swap \*(``right\*('' and \*(``left\*('' everywhere in the rest of this
 paragraph.)  If pressed while closer to
@@ -4894,7 +5134,7 @@ for details).
 .SH SELECT/PASTE
 X clients provide select and paste support by responding to requests conveyed
 by the server.
-.SS Primary
+.SS PRIMARY
 When configured to use the primary selection,
 (the default) \fI\*n\fP can
 provide the selection data in ways which help to retain character
@@ -4911,25 +5151,26 @@ asserted ownership, it relies on cut-buf
 But cut-buffers handle only ISO-8859-1 data
 (officially \- some clients ignore the rules).
 .
-.SS Clipboard
+.SS CLIPBOARD
 When configured to use the clipboard (using the \fBselectToClipboard\fP resource),
 the problem with persistence of ownership is bypassed.
 Otherwise, there is no difference regarding the data which can be
 passed via selection.
 .PP
-The PRIMARY token is a standard X feature, documented in the ICCCM
+The \fBPRIMARY\fP token is a standard X feature, documented in the ICCCM
 (\fIInter-Client Communication Conventions Manual\fR),
 which states
 .RS
 .PP
-The selection named by the atom PRIMARY is used for all commands that take only a single argument and is the principal means of communication between clients that use the selection mechanism.
+The selection named by the atom \fBPRIMARY\fP is used for all commands that take only a single argument and is the principal means of communication between clients that use the selection mechanism.
 .RE
+.SS SELECT
 .PP
-However, many applications use CLIPBOARD in imitation of other windowing
+However, many applications use \fBCLIPBOARD\fP in imitation of other windowing
 systems.
 The \fBselectToClipboard\fP resource (and corresponding menu entry
 \fBSelect to Clipboard\fP) introduce the SELECT token (known only
-to \fI\*n\fP) which chooses between the PRIMARY and CLIPBOARD tokens.
+to \fI\*n\fP) which chooses between the \fBPRIMARY\fP and \fBCLIPBOARD\fP tokens.
 .PP
 Without using this feature, one can use workarounds such as the
 \fIxclip\fP program to show the contents of the X clipboard within an
@@ -4942,7 +5183,7 @@ These are termed \fIselection targets\fP
 .PP
 When asking for the selection data,
 \fI\*n\fP tries the following types in this order:
-.RS
+.RS 5
 .TP 5
 UTF8_STRING
 This is an XFree86 extension, which denotes that the data is encoded in UTF-8.
@@ -4993,6 +5234,28 @@ u,i,s
 .fi
 .RE
 .
+.SS Mouse Protocol
+.PP
+Applications can send escape sequences to \fI\*n\fP to cause it to send
+escape sequences back to the computer when you press a pointer button,
+or even (depending on which escape sequence) send escape sequences back
+to the computer as you move the pointer.
+.PP
+These escape sequences and the responses, called the \fImouse protocol\fP,
+are documented in \fIXTerm Control Sequences\fP.
+They do not appear in the \fIactions\fP invoked by the \fBtranslations\fP
+resource because the resource does not change while you run \fI\*n\fP,
+whereas applications can change the mouse prototol
+(i.e., enable, disable, use different modes).
+.PP
+However, the mouse protocol is interpreted within the \fIactions\fP
+that are usually associated with the pointer buttons.
+\fI\*N\fP ignores the mouse protocol in the \fBinsert-selection\fP action
+if the shift-key is pressed at the same time.
+It also modifies a few other actions if the shift-key is pressed,
+e.g., suppressing the response with the pointer position,
+though not eliminating changes to the selected text.
+.
 .SH MENUS
 .
 .PP
@@ -5354,8 +5617,8 @@ There is no corresponding command-line o
 .
 .TP
 .B Select to Clipboard\fP (resource \fBselectToClipboard\fP)
-Tell \fI\*n\fP whether to use the PRIMARY or CLIPBOARD
-for SELECT tokens in the \fBtranslations\fP resource which
+Tell \fI\*n\fP whether to use the \fBPRIMARY\fP or \fBCLIPBOARD\fP
+for \fBSELECT\fP tokens in the \fBtranslations\fP resource which
 maps keyboard and mouse actions to select/paste actions.
 This corresponds to the \fBselectToClipboard\fP resource.
 There is no corresponding command-line option.
@@ -5411,12 +5674,16 @@ There is no corresponding command-line o
 .
 .TP
 .B Private Color Registers\fP (resource \fBprivateColorRegisters\fP)
+If \fI\*n\fR is configured to support ReGIS graphics,
+this controls whether a private color palette can be used.
+.IP
 When enabled,
 each graphic image uses a separate set of color registers, so that it
 essentially has a private palette (this is the default).  If it is not set,
 all graphics images share a common set of registers which is how sixel and
 ReGIS graphics worked on actual hardware.  The default is likely a more
 useful mode on modern TrueColor hardware.
+.IP
 This corresponds to the \fBprivateColorRegisters\fP resource.
 There is no corresponding command-line option.
 .RE
@@ -5528,7 +5795,7 @@ Font escape sequence (see \fI\*N Control
 .TP
 .B Selection\fP (resource \fBfontsel\fP)
 This allows you to set the font specified
-the current selection as a font name (if the PRIMARY selection is owned).
+the current selection as a font name (if the \fBPRIMARY\fP selection is owned).
 .RE
 .PP
 The second section allows you to modify the way it is displayed:
@@ -5573,7 +5840,8 @@ It corresponds to the \fButf8\fP resourc
 This controls whether \fI\*n\fP uses UTF-8 fonts for display.
 It is useful for temporarily switching \fI\*n\fP to display
 text from an application which does not follow the locale settings.
-It combines the \fButf8\fP and \fButf8Fonts\fP resources.
+It combines the \fButf8\fP and \fButf8Fonts\fP resources,
+subject to the \fBlocale\fP resource.
 .TP
 .B UTF-8 Titles\fP (resource \fButf8-title\fP)
 This controls whether \fI\*n\fP accepts UTF-8 encoding for
@@ -5609,6 +5877,11 @@ Enable or disable control sequences that
 This corresponds to the \fBallowFontOps\fP resource.
 Enable or disable control sequences that set/query the font.
 .TP
+.B Allow Mouse Ops\fP (resource \fBallow-mouse-ops\fP)
+Enable or disable control sequences that cause the terminal to
+send escape sequences on pointer-clicks and movement.
+This corresponds to the \fBallowMouseOps\fP resource.
+.TP
 .B Allow Tcap Ops\fP (resource \fBallow-tcap-ops\fP)
 Enable or disable control sequences that query the terminal's
 notion of its function-key strings, as termcap or terminfo capabilities.
@@ -5760,14 +6033,16 @@ of the \fBcharClass\fP (class \fICharCla
 This resource is a
 series of comma-separated
 \fIrange\fP:\fIvalue\fP pairs.
+.bP
 The
 \fIrange\fP is either a single number or \fIlow\fP-\fIhigh\fP in the range of 0
 to 65535, corresponding to the code for the character or characters to be
 set.
-The \fIvalue\fP is arbitrary, although the default table uses the
+.bP
+The \fIvalue\fP is arbitrary.  For example, the default table uses the
 character number of the first character occurring in the set.
 When not in
-UTF-8 mode, only the first 256 bytes of this table will be used.
+UTF-8 mode, only the first 256 entries of this table will be used.
 .
 .PP
 The default table starts as follows \-
@@ -5832,7 +6107,7 @@ static int charClass[256] = {
     48,  48,  48,  48,  48,  48,  48,  48,
 /\(**  a`   a\*(AQ   a^   a~   a:   ao   ae   c, */
     48,  48,  48,  48,  48,  48,  48,  48,
-/\(**  e`   e\*(AQ   e^   e:    i`  i\*(AQ   i^   i: */
+/\(**  e`   e\*(AQ   e^   e:   i`   i\*(AQ   i^   i: */
     48,  48,  48,  48,  48,  48,  48,  48,
 /\(**   d   n~   o`   o\*(AQ   o^   o~   o:   \-: */
     48,  48,  48,  48,  48,  48,  48, 247,
@@ -5872,6 +6147,10 @@ invoked by the \fBallow-color-ops\fP ent
 This action sets, unsets or toggles the \fBallowFontOps\fP resource and is also
 invoked by the \fBallow-font-ops\fP entry in \fIfontMenu\fP.
 .TP 8
+.B "allow-mouse-ops(\fIon/off/toggle\fP)"
+This action sets, unsets or toggles the \fBallowMousepOps\fP resource and is also
+invoked by the \fBallow-mouse-ops\fP entry in \fIfontMenu\fP.
+.TP 8
 .B "allow-send-events(\fIon/off/toggle\fP)"
 This action sets, unsets or toggles the \fBallowSendEvents\fP resource and is also
 invoked by the \fBallowsends\fP entry in \fImainMenu\fP.
@@ -5930,7 +6209,7 @@ of \*(``dynamic abbreviation\*('' expans
 Here is a resource setting for \fI\*n\fP which will do the same thing:
 .NS
 *VT100*translations:    #override \\n\\\&
-        Meta <KeyPress> /:dabbrev-expand()
+        Meta <KeyPress> /:\fBdabbrev-expand\fP()
 .NE
 .TP 8
 .B "deiconify()"
@@ -6007,7 +6286,7 @@ to view a file whose name is selected wh
 The new process is started when the mouse button is released:
 .NS
 *VT100*translations: #override Shift \\
-    <Btn1Up>: exec-formatted("xterm -e view '%t'", SELECT)
+    <Btn1Up>:\fBexec-formatted\fP("xterm -e view '%t'", \fBSELECT\fP)
 .NE
 .TP 8
 .B "exec-selectable(\fIformat\fP, \fIonClicks\fP)"
@@ -6615,75 +6894,79 @@ This action sends the indicated graphics
 .
 .SS Default Key Bindings
 .PP
-The default bindings in the VT\fIxxx\fP window use the SELECT token,
+The default bindings in the VT\fIxxx\fP window use the \fBSELECT\fP token,
 which is set by the \fBselectToClipboard\fP resource.
 These are for the \fIvt100\fP widget:
 .NS
-          Shift <KeyPress> Prior:scroll-back(1,halfpage) \\n\\\&
-           Shift <KeyPress> Next:scroll-forw(1,halfpage) \\n\\\&
-         Shift <KeyPress> Select:select-cursor-start() \\\&
-                                 select-cursor-end(SELECT, CUT_BUFFER0) \\n\\\&
-         Shift <KeyPress> Insert:insert-selection(SELECT, CUT_BUFFER0) \\n\\\&
-                 Alt <Key>Return:fullscreen() \\n\\\&
-        <KeyRelease> Scroll_Lock:scroll-lock() \\n\\\&
-    Shift~Ctrl <KeyPress> KP_Add:larger-vt-font() \\n\\\&
-    Shift Ctrl <KeyPress> KP_Add:smaller-vt-font() \\n\\\&
-    Shift <KeyPress> KP_Subtract:smaller-vt-font() \\n\\\&
-                ~Meta <KeyPress>:insert-seven-bit() \\n\\\&
-                 Meta <KeyPress>:insert-eight-bit() \\n\\\&
-                !Ctrl <Btn1Down>:popup-menu(mainMenu) \\n\\\&
-           !Lock Ctrl <Btn1Down>:popup-menu(mainMenu) \\n\\\&
- !Lock Ctrl @Num_Lock <Btn1Down>:popup-menu(mainMenu) \\n\\\&
-     ! @Num_Lock Ctrl <Btn1Down>:popup-menu(mainMenu) \\n\\\&
-                ~Meta <Btn1Down>:select-start() \\n\\\&
-              ~Meta <Btn1Motion>:select-extend() \\n\\\&
-                !Ctrl <Btn2Down>:popup-menu(vtMenu) \\n\\\&
-           !Lock Ctrl <Btn2Down>:popup-menu(vtMenu) \\n\\\&
- !Lock Ctrl @Num_Lock <Btn2Down>:popup-menu(vtMenu) \\n\\\&
-     ! @Num_Lock Ctrl <Btn2Down>:popup-menu(vtMenu) \\n\\\&
-          ~Ctrl ~Meta <Btn2Down>:ignore() \\n\\\&
-                 Meta <Btn2Down>:clear-saved-lines() \\n\\\&
-            ~Ctrl ~Meta <Btn2Up>:insert-selection(SELECT, CUT_BUFFER0) \\n\\\&
-                !Ctrl <Btn3Down>:popup-menu(fontMenu) \\n\\\&
-           !Lock Ctrl <Btn3Down>:popup-menu(fontMenu) \\n\\\&
- !Lock Ctrl @Num_Lock <Btn3Down>:popup-menu(fontMenu) \\n\\\&
-     ! @Num_Lock Ctrl <Btn3Down>:popup-menu(fontMenu) \\n\\\&
-          ~Ctrl ~Meta <Btn3Down>:start-extend() \\n\\\&
-              ~Meta <Btn3Motion>:select-extend() \\n\\\&
-                 Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \\n\\\&
-            Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \\n\\\&
-  Lock @Num_Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \\n\\\&
-       @Num_Lock Ctrl <Btn4Down>:scroll-back(1,halfpage,m) \\n\\\&
-                      <Btn4Down>:scroll-back(5,line,m)     \\n\\\&
-                 Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \\n\\\&
-            Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \\n\\\&
-  Lock @Num_Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \\n\\\&
-       @Num_Lock Ctrl <Btn5Down>:scroll-forw(1,halfpage,m) \\n\\\&
-                      <Btn5Down>:scroll-forw(5,line,m)     \\n\\\&
-                         <BtnUp>:select-end(SELECT, CUT_BUFFER0) \\n\\\&
-                       <BtnDown>:ignore()
+          Shift <KeyPress> Prior:\fBscroll-back\fP(1,halfpage) \\n\\\&
+           Shift <KeyPress> Next:\fBscroll-forw\fP(1,halfpage) \\n\\\&
+         Shift <KeyPress> Select:\fBselect-cursor-start\fP() \\\&
+                                 \fBselect-cursor-end\fP(\fBSELECT\fP, CUT_BUFFER0) \\n\\\&
+         Shift <KeyPress> Insert:\fBinsert-selection\fP(\fBSELECT\fP, CUT_BUFFER0) \\n\\\&
+                 Alt <Key>Return:\fBfullscreen\fP() \\n\\\&
+        <KeyRelease> Scroll_Lock:\fBscroll-lock\fP() \\n\\\&
+    Shift~Ctrl <KeyPress> KP_Add:\fBlarger-vt-font\fP() \\n\\\&
+    Shift Ctrl <KeyPress> KP_Add:\fBsmaller-vt-font\fP() \\n\\\&
+    Shift <KeyPress> KP_Subtract:\fBsmaller-vt-font\fP() \\n\\\&
+                ~Meta <KeyPress>:\fBinsert-seven-bit\fP() \\n\\\&
+                 Meta <KeyPress>:\fBinsert-eight-bit\fP() \\n\\\&
+                !Ctrl <Btn1Down>:\fBpopup-menu\fP(mainMenu) \\n\\\&
+           !Lock Ctrl <Btn1Down>:\fBpopup-menu\fP(mainMenu) \\n\\\&
+ !Lock Ctrl @Num_Lock <Btn1Down>:\fBpopup-menu\fP(mainMenu) \\n\\\&
+     ! @Num_Lock Ctrl <Btn1Down>:\fBpopup-menu\fP(mainMenu) \\n\\\&
+                ~Meta <Btn1Down>:\fBselect-start\fP() \\n\\\&
+              ~Meta <Btn1Motion>:\fBselect-extend\fP() \\n\\\&
+                !Ctrl <Btn2Down>:\fBpopup-menu\fP(vtMenu) \\n\\\&
+           !Lock Ctrl <Btn2Down>:\fBpopup-menu\fP(vtMenu) \\n\\\&
+ !Lock Ctrl @Num_Lock <Btn2Down>:\fBpopup-menu\fP(vtMenu) \\n\\\&
+     ! @Num_Lock Ctrl <Btn2Down>:\fBpopup-menu\fP(vtMenu) \\n\\\&
+          ~Ctrl ~Meta <Btn2Down>:\fBignore\fP() \\n\\\&
+                 Meta <Btn2Down>:\fBclear-saved-lines\fP() \\n\\\&
+            ~Ctrl ~Meta <Btn2Up>:\fBinsert-selection\fP(\fBSELECT\fP, CUT_BUFFER0) \\n\\\&
+                !Ctrl <Btn3Down>:\fBpopup-menu\fP(fontMenu) \\n\\\&
+           !Lock Ctrl <Btn3Down>:\fBpopup-menu\fP(fontMenu) \\n\\\&
+ !Lock Ctrl @Num_Lock <Btn3Down>:\fBpopup-menu\fP(fontMenu) \\n\\\&
+     ! @Num_Lock Ctrl <Btn3Down>:\fBpopup-menu\fP(fontMenu) \\n\\\&
+          ~Ctrl ~Meta <Btn3Down>:\fBstart-extend\fP() \\n\\\&
+              ~Meta <Btn3Motion>:\fBselect-extend\fP() \\n\\\&
+                 Ctrl <Btn4Down>:\fBscroll-back\fP(1,halfpage,m) \\n\\\&
+            Lock Ctrl <Btn4Down>:\fBscroll-back\fP(1,halfpage,m) \\n\\\&
+  Lock @Num_Lock Ctrl <Btn4Down>:\fBscroll-back\fP(1,halfpage,m) \\n\\\&
+       @Num_Lock Ctrl <Btn4Down>:\fBscroll-back\fP(1,halfpage,m) \\n\\\&
+                      <Btn4Down>:\fBscroll-back\fP(5,line,m)     \\n\\\&
+                 Ctrl <Btn5Down>:\fBscroll-forw\fP(1,halfpage,m) \\n\\\&
+            Lock Ctrl <Btn5Down>:\fBscroll-forw\fP(1,halfpage,m) \\n\\\&
+  Lock @Num_Lock Ctrl <Btn5Down>:\fBscroll-forw\fP(1,halfpage,m) \\n\\\&
+       @Num_Lock Ctrl <Btn5Down>:\fBscroll-forw\fP(1,halfpage,m) \\n\\\&
+                      <Btn5Down>:\fBscroll-forw\fP(5,line,m)     \\n\\\&
+                         <BtnUp>:\fBselect-end\fP(\fBSELECT\fP, CUT_BUFFER0) \\n\\\&
+                       <BtnDown>:\fBignore\fP()
 .NE
 .PP
 The default bindings in the Tektronix window are analogous but less extensive.
 These are for the \fItek4014\fP widget:
 .NS
-                 ~Meta<KeyPress>: insert-seven-bit() \\n\\\&
-                  Meta<KeyPress>: insert-eight-bit() \\n\\\&
-                !Ctrl <Btn1Down>: popup-menu(mainMenu) \\n\\\&
-           !Lock Ctrl <Btn1Down>: popup-menu(mainMenu) \\n\\\&
- !Lock Ctrl @Num_Lock <Btn1Down>: popup-menu(mainMenu) \\n\\\&
-      !Ctrl @Num_Lock <Btn1Down>: popup-menu(mainMenu) \\n\\\&
-                !Ctrl <Btn2Down>: popup-menu(tekMenu) \\n\\\&
-           !Lock Ctrl <Btn2Down>: popup-menu(tekMenu) \\n\\\&
- !Lock Ctrl @Num_Lock <Btn2Down>: popup-menu(tekMenu) \\n\\\&
-      !Ctrl @Num_Lock <Btn2Down>: popup-menu(tekMenu) \\n\\\&
-           Shift ~Meta<Btn1Down>: gin-press(L) \\n\\\&
-                 ~Meta<Btn1Down>: gin-press(l) \\n\\\&
-           Shift ~Meta<Btn2Down>: gin-press(M) \\n\\\&
-                 ~Meta<Btn2Down>: gin-press(m) \\n\\\&
-           Shift ~Meta<Btn3Down>: gin-press(R) \\n\\\&
-                 ~Meta<Btn3Down>: gin-press(r)
+                 ~Meta<KeyPress>: \fBinsert-seven-bit\fP() \\n\\\&
+                  Meta<KeyPress>: \fBinsert-eight-bit\fP() \\n\\\&
+                !Ctrl <Btn1Down>: \fBpopup-menu\fP(mainMenu) \\n\\\&
+           !Lock Ctrl <Btn1Down>: \fBpopup-menu\fP(mainMenu) \\n\\\&
+ !Lock Ctrl @Num_Lock <Btn1Down>: \fBpopup-menu\fP(mainMenu) \\n\\\&
+      !Ctrl @Num_Lock <Btn1Down>: \fBpopup-menu\fP(mainMenu) \\n\\\&
+                !Ctrl <Btn2Down>: \fBpopup-menu\fP(tekMenu) \\n\\\&
+           !Lock Ctrl <Btn2Down>: \fBpopup-menu\fP(tekMenu) \\n\\\&
+ !Lock Ctrl @Num_Lock <Btn2Down>: \fBpopup-menu\fP(tekMenu) \\n\\\&
+      !Ctrl @Num_Lock <Btn2Down>: \fBpopup-menu\fP(tekMenu) \\n\\\&
+           Shift ~Meta<Btn1Down>: \fBgin-press\fP(L) \\n\\\&
+                 ~Meta<Btn1Down>: \fBgin-press\fP(l) \\n\\\&
+           Shift ~Meta<Btn2Down>: \fBgin-press\fP(M) \\n\\\&
+                 ~Meta<Btn2Down>: \fBgin-press\fP(m) \\n\\\&
+           Shift ~Meta<Btn3Down>: \fBgin-press\fP(R) \\n\\\&
+                 ~Meta<Btn3Down>: \fBgin-press\fP(r)
 .NE
+.SS Custom Key Bindings
+.PP
+You can modify the \fBtranslations\fP resource by overriding parts
+of it, or merging your resources with it.
 .PP
 Here is an example which uses shifted select/paste to copy to the clipboard,
 and unshifted select/paste for the primary selection.
@@ -6697,30 +6980,59 @@ When it loses the selection, it removes 
 But you can still paste from the corresponding cut buffer.
 .NS
 *VT100*translations:    #override \\n\\\&
-    ~Shift~Ctrl<Btn2Up>: insert-selection(PRIMARY, CUT_BUFFER0) \\n\\\&
-    Shift~Ctrl<Btn2Up>:  insert-selection(CLIPBOARD, CUT_BUFFER1) \\n\\\&
-    ~Shift<BtnUp>:       select-end(PRIMARY, CUT_BUFFER0) \\n\\\&
-    Shift<BtnUp>:        select-end(CLIPBOARD, CUT_BUFFER1)
+   ~Shift~Ctrl<Btn2Up>: \fBinsert-selection\fP(\fBPRIMARY\fP, CUT_BUFFER0) \\n\\\&
+    Shift~Ctrl<Btn2Up>: \fBinsert-selection\fP(\fBCLIPBOARD\fP, CUT_BUFFER1) \\n\\\&
+   ~Shift     <BtnUp> : \fBselect-end\fP(\fBPRIMARY\fP, CUT_BUFFER0) \\n\\\&
+    Shift     <BtnUp> : \fBselect-end\fP(\fBCLIPBOARD\fP, CUT_BUFFER1)
 .NE
 .PP
 In the example, the class name \fBVT100\fP is used rather than the widget name.
-These are different;
-the class name provides a more-specific match than the widget name.
+These are different; a class name could apply to more than one widget.
 A leading \*(``*\*('' is used because the widget hierarchy above the
 \fIvt100\fP widget depends on
 whether the toolbar support is compiled into \fI\*n\fP.
 .PP
-Below is shown a sample of
+Not everyone finds the three-button mouse bindings easy to use.
+In a wheel mouse, the middle button might be the wheel.
+As an alternative, you could add a binding shifted keys:
+.NS
+*VT100*translations:      #override \\n\\
+    Shift <Key>Home:    \fBcopy-selection\fP(\fBSELECT\fP) \\n\\
+    Shift <Key>Insert:  \fBcopy-selection\fP(\fBSELECT\fP) \\n\\
+    Ctrl Shift <Key>C:  \fBcopy-selection\fP(\fBSELECT\fP) \\n\\
+    Ctrl Shift <Key>V:  \fBinsert-selection\fP(\fBSELECT\fP)
+.NE
+.PP
+You would still use the left- and right-mouse buttons (typically 1 and 3)
+for beginning and extending selections. 
+.PP
+Besides mouse problems, there are also keyboards with inconvenient layouts.
+Some lack a numeric keypad, making it hard to use the shifted keypad plus
+and minus bindings for switching between font sizes.
+You can work around that by assigning the actions to more readily accessed
+keys:
+.NS
+*VT100*translations:      #override \\n\\
+    Ctrl <Key> +:       \fBlarger-vt-font\fP() \\n\\
+    Ctrl <Key> -:       \fBsmaller-vt-font\fP()
+.NE
+.PP
+The keymap feature allows you to switch between sets of translations.
+The sample below shows
 how the \fBkeymap()\fP action may be used to add special
 keys for entering commonly-typed words:
 .NS
 *VT100.Translations: #override <Key>F13: keymap(dbx)
 *VT100.dbxKeymap.translations: \\\&
-        <Key>F14:       keymap(None) \\n\\\&
-        <Key>F17:       string("next") string(0x0d) \\n\\\&
-        <Key>F18:       string("step") string(0x0d) \\n\\\&
-        <Key>F19:       string("continue") string(0x0d) \\n\\\&
-        <Key>F20:       string("print ") insert-selection(PRIMARY, CUT_BUFFER0)
+        <Key>F14:       \fBkeymap\fP(None) \\n\\\&
+        <Key>F17:       \fBstring\fP("next") \\n\\
+                        \fBstring\fP(0x0d) \\n\\\&
+        <Key>F18:       \fBstring\fP("step") \\n\\
+                        \fBstring\fP(0x0d) \\n\\\&
+        <Key>F19:       \fBstring\fP("continue") \\n\\
+                        \fBstring\fP(0x0d) \\n\\\&
+        <Key>F20:       \fBstring\fP("print ") \\n\\
+                        \fBinsert-selection\fP(\fBPRIMARY\fP, CUT_BUFFER0)
 .NE
 .SS Default Scrollbar Bindings
 .PP
@@ -6976,7 +7288,10 @@ and cannot be easily moved between diffe
 .
 .
 .SH ENVIRONMENT
-\fI\*N\fP sets several environment variables:
+\fI\*N\fP sets several environment variables.
+.SS System Independent
+.PP
+Some variables are used on every system:
 .TP 5
 .B DISPLAY
 is the display name,
@@ -7017,25 +7332,45 @@ build \fI\*n\fP, followed by
 The patch number is also part of the response to a Secondary Device Attributes
 (DA) control sequence (see \fIXterm Control Sequences\fP).
 .
+.SS System Dependent
+.
 .PP
 Depending on your system configuration, \fI\*n\fP may also set the
 following:
 .TP 5
 .B COLUMNS
 the width of the \fI\*n\fP in characters (cf: \*(``stty columns\*('').
+.IP
+When this variable is set, \fIcurses\fP applications (and most
+terminal programs) will assume that the terminal has this many columns.
+.IP
+\fI\*N\fP would do this for systems which have no ability
+to tell the size of the terminal.
+Those are very rare, none newer than the mid 1990s when SVR4 became prevalent.
 .TP 5
 .B HOME
 .br
-when \fI\*n\fP is configured to update utmp.
+when \fI\*n\fP is configured (at build-time) to update utmp.
 .TP 5
 .B LINES
 the height of the \fI\*n\fP in characters (cf: \*(``stty rows\*('').
+.IP
+When this variable is set, \fIcurses\fP applications (and most
+terminal programs) will assume that the terminal has this many lines (rows).
+.IP
+\fI\*N\fP would do this for systems which have no ability
+to tell the size of the terminal.
+Those are very rare, none newer than the mid 1990s when SVR4 became prevalent.
 .TP 5
 .B LOGNAME
-when \fI\*n\fP is configured to update utmp.
+when \fI\*n\fP is configured (at build-time) to update utmp.
+.IP
+Your configuration may have set \fBLOGNAME\fP; \fI\*n\fP does not modify that.
+If it is unset, \fI\*n\fP will use \fBUSER\fP if it is set.
+Finally, if neither is set, \fI\*n\fP will use the \fBgetlogin\fP(2) function.
 .TP 5
 .B SHELL
-when \fI\*n\fP is configured to update utmp.
+when \fI\*n\fP is configured (at build-time) to update utmp.
 It is also set if you provide a valid shell name as the optional parameter.
 .IP
 \fI\*N\fP sets this to an absolute pathname.
@@ -7049,9 +7384,14 @@ shell, \fI\*n\fP may unset it, to avoid 
 the contents of the termcap entry corresponding to \fB$TERM\fP,
 with lines and columns values substituted
 for the actual size window you have created.
+.IP
+This feature is, like \fBLINES\fP and \fBCOLUMNS\fP, used rarely.
+It addresses the same limitation of a few older systems
+by providing a way for \fItermcap\fP-based applications to get the initial
+screensize.
 .TP 5
 .B TERMINFO
-may be defined to a nonstandard location in the configure script.
+may be defined to a nonstandard location using the configure script.
 .\"
 .
 .

Reply via email to