# ftp://ftp.invisible-island.net/xterm/patches/xterm-342.patch.gz
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Fri Jan  4 01:49:12 UTC 2019
# ------------------------------------------------------------------------------
# MANIFEST                 |    2 +-
# button.c                 |   16 ++++++++++++++--
# fontutils.c              |   11 +++++++----
# package/debian/changelog |    6 ++++++
# package/debian/copyright |    2 +-
# package/freebsd/Makefile |    2 +-
# package/xterm.spec       |    4 ++--
# version.h                |    8 ++++----
# vttests/mouse-codes      |   25 ++++++++++++++-----------
# xterm.log.html           |   24 ++++++++++++++++++++++--
# 10 files changed, 72 insertions(+), 28 deletions(-)
# ------------------------------------------------------------------------------
Index: MANIFEST
--- xterm-341+/MANIFEST	2018-12-18 10:25:26.000000000 +0000
+++ xterm-342/MANIFEST	2019-01-01 17:29:29.000000000 +0000
@@ -1,4 +1,4 @@
-MANIFEST for xterm-341, version xterm-341
+MANIFEST for xterm-342, version xterm-342
 --------------------------------------------------------------------------------
 MANIFEST                        this file
 256colres.h                     resource-definitions for 256-color mode
Index: button.c
--- xterm-341+/button.c	2018-12-24 15:07:40.000000000 +0000
+++ xterm-342/button.c	2019-01-04 01:07:36.000000000 +0000
@@ -1,7 +1,7 @@
-/* $XTermId: button.c,v 1.562 2018/12/24 15:07:40 tom Exp $ */
+/* $XTermId: button.c,v 1.564 2019/01/04 01:07:36 tom Exp $ */
 
 /*
- * Copyright 1999-2017,2018 by Thomas E. Dickey
+ * Copyright 1999-2018,2019 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -4806,6 +4806,18 @@
     if (button >= 3)
 	button++;
 
+    /* Ignore buttons that cannot be encoded */
+    if (screen->extend_coords == SET_SGR_EXT_MODE_MOUSE
+	|| screen->extend_coords == SET_URXVT_EXT_MODE_MOUSE) {
+	if (button > 15) {
+	    return;
+	}
+    } else {
+	if (button > 11) {
+	    return;
+	}
+    }
+
     /* Compute character position of mouse pointer */
     row = (event->y - screen->border) / FontHeight(screen);
     col = (event->x - OriginX(screen)) / FontWidth(screen);
Index: fontutils.c
--- xterm-341+/fontutils.c	2018-12-24 20:11:50.000000000 +0000
+++ xterm-342/fontutils.c	2019-01-03 23:50:16.000000000 +0000
@@ -1,7 +1,7 @@
-/* $XTermId: fontutils.c,v 1.619 2018/12/24 20:11:50 tom Exp $ */
+/* $XTermId: fontutils.c,v 1.621 2019/01/03 23:50:16 tom Exp $ */
 
 /*
- * Copyright 1998-2017,2018 by Thomas E. Dickey
+ * Copyright 1998-2018,2019 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -2319,7 +2319,8 @@
 /*
  * Check if this is a FC_COLOR font, which fontconfig misrepresents to "fix" a
  * problem with web browsers.  As of 2018/12 (4 years later), Xft does not work
- * with that.
+ * with that.  Even with this workaround, fontconfig has at least one bug which
+ * causes it to crash (Debian #917034).
  */
 #ifdef FC_COLOR
 #define GetFcBool(pattern, what) \
@@ -2336,7 +2337,9 @@
 	    result = True;
 	} else if (GetFcBool(font->pattern, FC_OUTLINE) && !fcbogus) {
 	    TRACE(("...matched non-outline font\n"));
-	    result = True;
+	    /* This is legal for regular bitmap fonts - fontconfig attempts to
+	     * find a match - but problematic for misencoded color-bitmap fonts.
+	     */
 	}
     }
     return result;
Index: package/debian/changelog
--- xterm-341+/package/debian/changelog	2018-12-18 10:25:26.000000000 +0000
+++ xterm-342/package/debian/changelog	2019-01-01 17:29:29.000000000 +0000
@@ -1,3 +1,9 @@
+xterm-dev (342) unstable; urgency=low
+
+  * maintenance updates
+
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Tue, 01 Jan 2019 12:29:29 -0500
+
 xterm-dev (341) unstable; urgency=low
 
   * maintenance updates
Index: package/debian/copyright
--- xterm-341+/package/debian/copyright	2018-02-04 17:29:13.000000000 +0000
+++ xterm-342/package/debian/copyright	2019-01-03 23:50:32.000000000 +0000
@@ -35,7 +35,7 @@
 Files: * */*
 License: MIT-X11
 
-Copyright 1996-2017,2018 by Thomas E. Dickey
+Copyright 1996-2018,2019 by Thomas E. Dickey
 
 (date ranges vary, depending on when the respective files were first changed
 significantly, and run through the most recent change date).
Index: package/freebsd/Makefile
--- xterm-341+/package/freebsd/Makefile	2018-12-18 10:25:26.000000000 +0000
+++ xterm-342/package/freebsd/Makefile	2019-01-01 17:29:29.000000000 +0000
@@ -5,7 +5,7 @@
 # and "make makesum".
 
 PORTNAME=	xterm
-PORTVERSION=	341
+PORTVERSION=	342
 CATEGORIES=	x11
 MASTER_SITES=	ftp://ftp.invisible-island.net/xterm/ \
 		CRITICAL
Index: package/xterm.spec
--- xterm-341+/package/xterm.spec	2018-12-18 10:25:26.000000000 +0000
+++ xterm-342/package/xterm.spec	2019-01-01 17:29:29.000000000 +0000
@@ -1,11 +1,11 @@
-# $XTermId: xterm.spec,v 1.111 2018/12/18 10:25:26 tom Exp $
+# $XTermId: xterm.spec,v 1.112 2019/01/01 17:29:29 tom Exp $
 Summary: X terminal emulator (development version)
 %global my_middle xterm
 %global my_suffix -dev
 %global fullname %{my_middle}%{my_suffix}
 %global my_class XTermDev
 Name: %{fullname}
-Version: 341
+Version: 342
 Release: 1
 License: X11
 Group: User Interface/X
Index: version.h
--- xterm-341+/version.h	2018-12-25 01:43:46.000000000 +0000
+++ xterm-342/version.h	2019-01-04 01:47:54.000000000 +0000
@@ -1,7 +1,7 @@
-/* $XTermId: version.h,v 1.460 2018/12/25 01:43:46 tom Exp $ */
+/* $XTermId: version.h,v 1.464 2019/01/04 01:47:54 tom Exp $ */
 
 /*
- * Copyright 1998-2017,2018 by Thomas E. Dickey
+ * Copyright 1998-2018,2019 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -38,8 +38,8 @@
  * version of X to which this version of xterm has been built.  The resulting
  * number in parentheses is my patch number (Thomas E. Dickey).
  */
-#define XTERM_PATCH   341
-#define XTERM_DATE    2018-12-24
+#define XTERM_PATCH   342
+#define XTERM_DATE    2019-01-03
 
 #ifndef __vendorversion__
 #define __vendorversion__ "XTerm"
Index: vttests/mouse-codes
--- xterm-341+/vttests/mouse-codes	2018-12-24 14:17:07.000000000 +0000
+++ xterm-342/vttests/mouse-codes	2019-01-04 00:49:41.000000000 +0000
@@ -1,9 +1,9 @@
 #!/usr/bin/env perl
-# $XTermId: mouse-codes,v 1.4 2018/12/24 14:17:07 tom Exp $
+# $XTermId: mouse-codes,v 1.6 2019/01/04 00:49:41 tom Exp $
 # -----------------------------------------------------------------------------
 # this file is part of xterm
 #
-# Copyright 2018 by Thomas E. Dickey
+# Copyright 2018,2019 by Thomas E. Dickey
 #
 #                         All Rights Reserved
 #
@@ -102,21 +102,24 @@
                     $result += 3;
                 }
                 else {
-                    if ( $button > 7 ) {
-                        $result += ( 128 - 4 );
+                    $result += $button & 3;
+                    if ( $button & 4 ) {
+                        $result += 64;
                     }
-                    elsif ( $button > 3 ) {
-                        $result += ( 64 - 4 );
+                    if ( $button & 8 ) {
+                        $result += 128;
                     }
-                    $result += $button;
                 }
                 my $code   = sprintf "%3d",    $result;
                 my $report = sprintf "%s%s%s", &ButtonName($button),
                   &KeyState($states), &Motion($motion);
-                printf "OOPS %s ->%s versus %s\n", $code, $report,
-                  $encoded{$code}
-                  if ( defined $encoded{$code}
-                    or ( $result > 255 and not defined $opt_x ) );
+                if ( defined $encoded{$code} ) {
+                    printf "OOPS %s ->%s versus %s\n", $code, $report,
+                      $encoded{$code};
+                }
+                elsif ( $result > 255 and not defined $opt_x ) {
+                    printf "OOPS %s ->%s\n", $code, $report;
+                }
                 $encoded{$code}   = $report;
                 $reports{$report} = $result;
             }
Index: xterm.log.html
--- xterm-341+/xterm.log.html	2018-12-25 01:43:53.000000000 +0000
+++ xterm-342/xterm.log.html	2019-01-04 01:48:12.000000000 +0000
@@ -2,7 +2,7 @@
  *****************************************************************************
  * this file is part of xterm                                                *
  *                                                                           *
- * Copyright 1997-2017,2018 by Thomas E. Dickey                              *
+ * Copyright 1997-2018,2019 by Thomas E. Dickey                              *
  *                                                                           *
  * All Rights Reserved                                                       *
  *                                                                           *
@@ -30,7 +30,7 @@
  * sale, use or other dealings in this Software without prior written        *
  * authorization.                                                            *
  *****************************************************************************
-  $XTermId: xterm.log.html,v 1.1971 2018/12/25 01:43:53 tom Exp $
+  $XTermId: xterm.log.html,v 1.1978 2019/01/04 01:48:12 tom Exp $
   -->
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
 
@@ -72,6 +72,8 @@
   CHANGELOG</a>).</p>
 
   <ul>
+    <li><a href="#xterm_342">Patch #342 - 2019/01/03</a></li>
+
     <li><a href="#xterm_341">Patch #341 - 2018/12/24</a></li>
 
     <li><a href="#xterm_340">Patch #340 - 2018/12/16</a></li>
@@ -967,6 +969,24 @@
     <li><a href="#xterm_01">Patch #1 - 1996/1/6</a></li>
   </ul>
 
+  <h1><a name="xterm_342" id="xterm_342">Patch #342 -
+  2019/01/03</a></h1>
+
+  <ul>
+    <li>limit mouse-button events to 11 buttons in the original
+    protocol, and 15 in the extended mouse-protocol (patch by
+    Martin Hostettler).</li>
+
+    <li>correct calculation for buttons past 11 in
+    <code>mouse-codes</code> sample script (patch by Martin
+    Hostettler).</li>
+
+    <li>disable a supplementary check added in <a href=
+    "#xterm_341">patch #341</a> which interferes with using
+    fontconfig to select different-sized bitmap fonts (Arch
+    #61237).</li>
+  </ul>
+
   <h1><a name="xterm_341" id="xterm_341">Patch #341 -
   2018/12/24</a></h1>
 
