File n_01-Add-option-to-enable-logging.patch of Package xf86-input-wacom.9855

From: Egbert Eich <eich@suse.com>
Date: Fri Feb 7 23:06:26 2014 +0100
Subject: [PATCH 1/4]Add option to enable logging
Patch-Mainline: never
Git-commit: 9717547311abfe18b7edad9e0b45f16b902e2f2d
Git-repo: git://linuxwacom.git.sourceforge.net/gitroot/linuxwacom/xf86-input-wacom
References: FATE#
Signed-off-by: Egbert Eich <eich@suse.com>

This patch adds an option to set a bitmask marking events to be logged
to the Xserver log file.
Currently the list contains the following bits:
 PROXIMITY low level event  1
 PRESSURE low level event   2
 BUTTON high level event    7

Signed-off-by: Egbert Eich <eich@suse.com>
---
 configure.ac               | 11 +++++++++++
 include/wacom-properties.h |  9 +++++++++
 man/wacom.man              | 19 +++++++++++++++++++
 man/xsetwacom.man          | 19 ++++++++++++++++++-
 src/wcmCommon.c            | 35 +++++++++++++++++++++++++++++++++++
 src/wcmConfig.c            |  4 ++++
 src/wcmUSB.c               | 25 +++++++++++++++++++++++++
 src/wcmXCommand.c          | 22 +++++++++++++++++++++-
 src/xf86Wacom.h            | 22 ++++++++++++++++++++++
 src/xf86WacomDefs.h        |  4 +++-
 tools/xsetwacom.c          | 10 ++++++++++
 11 files changed, 177 insertions(+), 3 deletions(-)

Index: xf86-input-wacom-0.34.2/configure.ac
===================================================================
--- xf86-input-wacom-0.34.2.orig/configure.ac
+++ xf86-input-wacom-0.34.2/configure.ac
@@ -87,6 +87,17 @@ if test "x$DEBUGGING" = xyes; then
        AC_DEFINE(DEBUG, 1, [Enable debugging code])
 fi
 
+# Define a configure option for event logging
+AC_ARG_ENABLE(logging,
+              AS_HELP_STRING([--enable-logging],
+                             [Enable logging (default: disabled)]),
+                             [LOGGING=$enableval], [LOGGING=yes])
+
+# Define the C preprocessor macro LOGGING in config.h
+if test "x$LOGGING" = xyes; then
+       AC_DEFINE(LOGGING, 1, [Enable logging code])
+fi
+
 # Define a configure option for an alternate input module directory
 AC_ARG_WITH(xorg-module-dir,
             AS_HELP_STRING([--with-xorg-module-dir=DIR],
Index: xf86-input-wacom-0.34.2/include/wacom-properties.h
===================================================================
--- xf86-input-wacom-0.34.2.orig/include/wacom-properties.h
+++ xf86-input-wacom-0.34.2/include/wacom-properties.h
@@ -111,6 +111,15 @@
 */
 #define WACOM_PROP_PRESSURE_RECAL "Wacom Pressure Recalibration"
 
+/* 8 bit, values:
+  Type                       bit
+  PROXIMITY_LOW_LEVEL event  1
+  PRESSURE_LOW_LEVEL event   2
+  BUTTON_HIGH_LEVEL event    7
+  Log event of the types specified in the type mask.
+*/
+#define WACOM_PROP_LOGMASK "Wacom Log Mask"
+
 /* The following are tool types used by the driver in WACOM_PROP_TOOL_TYPE
  * or in the 'type' field for XI1 clients. Clients may check for one of
  * these types to identify tool types.
Index: xf86-input-wacom-0.34.2/man/wacom.man
===================================================================
--- xf86-input-wacom-0.34.2.orig/man/wacom.man
+++ xf86-input-wacom-0.34.2/man/wacom.man
@@ -269,6 +269,25 @@ initial pressure reading may be unequal
 good pen. If the consecutive pressure readings are not higher than
 the initial pressure by a threshold no button event will be generated.
 This option allows to disable the recalibration.
+.TP 4
+.B Option \fI"LogMask" \fI"number"\fP
+bitmask that enables logging of a group of events.
+.RS
+.PD 0
+.TP
+Bit
+Event
+.TP
+0
+proximity low level
+.TP
+1
+pressure low level
+.TP
+7
+button high level
+.PD
+
 .RE
 .SH "TOUCH GESTURES"
 .SS Single finger (1FG)
Index: xf86-input-wacom-0.34.2/man/xsetwacom.man
===================================================================
--- xf86-input-wacom-0.34.2.orig/man/xsetwacom.man
+++ xf86-input-wacom-0.34.2/man/xsetwacom.man
@@ -273,7 +273,24 @@ initial pressure reading may be unequal
 good pen. If the consecutive pressure readings are not higher than
 the initial pressure by a threshold no button event will be generated.
 This option allows to disable the recalibration.  Default:  on
-
+.TP
+\fBLogMask\fR mask
+bitmask that enables logging of a group of events.
+.RS
+.PD 0
+.TP
+Bit
+Event
+.TP
+0
+proximity low level
+.TP
+1
+pressure low level
+.TP
+7
+button high level
+.PD
 
 .SH "AUTHORS"
 Peter Hutterer <peter.hutterer@redhat.com>
Index: xf86-input-wacom-0.34.2/src/wcmCommon.c
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/wcmCommon.c
+++ xf86-input-wacom-0.34.2/src/wcmCommon.c
@@ -27,6 +27,9 @@
 #include "wcmTouchFilter.h"
 #include <xkbsrv.h>
 #include <xf86_OSproc.h>
+#ifdef LOGGING
+#include <time.h>
+#endif
 
 
 struct _WacomDriverRec WACOM_DRIVER = {
@@ -89,6 +92,35 @@ void set_absolute(InputInfoPtr pInfo, Bo
 		priv->flags &= ~ABSOLUTE_FLAG;
 }
 
+#ifdef LOGGING
+void wcm_timestr(char *str, int str_n)
+{
+	struct timespec tp;
+	struct tm tm;
+	static char wday_name[7][3] = {
+			"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+	};
+	static char mon_name[12][3] = {
+			"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+			"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+	};
+
+	str[0] = '\0';
+	if (clock_gettime(CLOCK_REALTIME, &tp) < 0)
+		return;
+	localtime_r(&tp.tv_sec, &tm);
+
+	snprintf(str, str_n, " %.3s %.3s%3d %.2d:%.2d:%.2d.%.6d - ",
+		 wday_name[tm.tm_wday],
+		 mon_name[tm.tm_mon],
+		 tm.tm_mday, tm.tm_hour,
+		 tm.tm_min, tm.tm_sec, (int)tp.tv_nsec);
+
+	return;
+
+}
+#endif
+
 /*****************************************************************************
  * wcmSendButtons --
  *   Send button events by comparing the current button mask with the
@@ -1469,6 +1501,9 @@ WacomCommonPtr wcmNewCommon(void)
 	common->wcmRawSample = DEFAULT_SAMPLES;
 			/* number of raw data to be used to for filtering */
 	common->wcmPressureRecalibration = 1;
+#ifdef LOGGING
+	common->LogMask = 0;
+#endif
 	return common;
 }
 
Index: xf86-input-wacom-0.34.2/src/wcmConfig.c
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/wcmConfig.c
+++ xf86-input-wacom-0.34.2/src/wcmConfig.c
@@ -646,6 +646,10 @@ static int wcmPreInit(InputDriverPtr drv
 
 	common->debugLevel = xf86SetIntOption(pInfo->options,
 					      "CommonDBG", common->debugLevel);
+#ifdef LOGGING
+	common->LogMask = xf86SetIntOption(pInfo->options,
+					   "LogMask", common->LogMask);
+#endif
 	oldname = strdup(pInfo->name);
 
 	if (wcmIsHotpluggedDevice(pInfo))
Index: xf86-input-wacom-0.34.2/src/wcmUSB.c
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/wcmUSB.c
+++ xf86-input-wacom-0.34.2/src/wcmUSB.c
@@ -1138,6 +1138,31 @@ static int usbIdToType(int id)
 	return type;
 }
 
+#ifdef LOGGING
+/**
+ * Return type name string.
+ * @param type
+ * @return string
+ */
+static const char *usbTypeName(unsigned long type)
+{
+	switch (type) {
+	case STYLUS_ID:
+		return "PEN";
+	case ERASER_ID:
+		return "RUBBER";
+	case CURSOR_ID:
+		return "MOUSE";
+	case TOUCH_ID:
+		return "TOUCH";
+	case PAD_ID:
+		return "PAD";
+	default:
+		return "UNKNOWN";
+	}
+}
+#endif
+
 /**
  * Find the tool type (STYLUS_ID, etc.) based on the device_id.
  *
Index: xf86-input-wacom-0.34.2/src/wcmXCommand.c
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/wcmXCommand.c
+++ xf86-input-wacom-0.34.2/src/wcmXCommand.c
@@ -99,6 +99,9 @@ static Atom prop_tooltype;
 static Atom prop_btnactions;
 static Atom prop_product_id;
 static Atom prop_pressure_recal;
+#ifdef LOGGING
+static Atom prop_logmask;
+#endif
 #ifdef DEBUG
 static Atom prop_debuglevels;
 #endif
@@ -337,7 +340,10 @@ void InitWcmDeviceProperties(InputInfoPt
 	values[0] = common->vendor_id;
 	values[1] = common->tablet_id;
 	prop_product_id = InitWcmAtom(pInfo->dev, XI_PROP_PRODUCT_ID, XA_INTEGER, 32, 2, values);
-
+#ifdef LOGGING
+	values[0] = common->LogMask;
+	prop_logmask = InitWcmAtom(pInfo->dev, WACOM_PROP_LOGMASK, XA_INTEGER, 8, 1, values);
+#endif
 #ifdef DEBUG
 	values[0] = priv->debugLevel;
 	values[1] = common->debugLevel;
@@ -951,6 +957,20 @@ int wcmSetProperty(DeviceIntPtr dev, Ato
 			common->debugLevel = values[1];
 		}
 #endif
+#ifdef LOGGING
+	} else if (property == prop_logmask) {
+		CARD8 *values;
+
+		if (prop->size != 1 || prop->format != 8)
+			return BadMatch;
+
+		values = (CARD8*)prop->data;
+
+		if (!checkonly)
+		{
+			common->LogMask = values[0];
+		}
+#endif
 	} else if (property == prop_btnactions)
 	{
 		int nbuttons = priv->nbuttons < 4 ? priv->nbuttons : priv->nbuttons + 4;
Index: xf86-input-wacom-0.34.2/src/xf86Wacom.h
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/xf86Wacom.h
+++ xf86-input-wacom-0.34.2/src/xf86Wacom.h
@@ -69,6 +69,28 @@
 #define DBG(lvl, priv, ...)
 #endif
 
+#ifdef LOG
+#undef LOG
+#endif
+#ifdef LOGGING
+void wcm_timestr(char *str, int str_n);
+#define DO_LOG(m, v) (m->LogMask & v)
+#define LOG(m, v, f, ...) do {			\
+	if (DO_LOG(m, v)) { \
+		char tstr[30]; \
+		wcm_timestr(tstr, sizeof(tstr));	\
+		LogMessageVerbSigSafe(X_NONE, -1, "[LOG]%s " f, tstr, __VA_ARGS__); \
+	} \
+} while (0)
+#define LOG_PROXIMITY_LOW 1 << 0
+#define LOG_PRESSURE_LOW  1 << 1
+#define LOG_BUTTON_HIGH   1 << 7
+#else
+#define DO_LOG(m, v) (0)
+#define LOG(m, v, f, ...) do {			\
+	} while (0)
+#endif
+
 /******************************************************************************
  * WacomModule - all globals are packed in a single structure to keep the
  *               global namespaces as clean as possible.
Index: xf86-input-wacom-0.34.2/src/xf86WacomDefs.h
===================================================================
--- xf86-input-wacom-0.34.2.orig/src/xf86WacomDefs.h
+++ xf86-input-wacom-0.34.2/src/xf86WacomDefs.h
@@ -460,7 +460,9 @@ struct _WacomCommonRec
 	int wcmRawSample;	     /* Number of raw data used to filter an event */
 	int wcmPressureRecalibration; /* Determine if pressure recalibration of
 					 worn pens should be performed */
-
+#ifdef LOGGING
+	int LogMask;		     /* Mask to determine which event types to log. */
+#endif
 	int bufpos;                        /* position with buffer */
 	unsigned char buffer[BUFFER_SIZE]; /* data read from device */
 
Index: xf86-input-wacom-0.34.2/tools/xsetwacom.c
===================================================================
--- xf86-input-wacom-0.34.2.orig/tools/xsetwacom.c
+++ xf86-input-wacom-0.34.2/tools/xsetwacom.c
@@ -158,6 +158,16 @@ static param_t parameters[] =
 		.arg_count = 1,
 	},
 	{
+		.name = "LogMask",
+		.desc = "Mask whose bits determine which events to log: "
+		"0  PROXIMITY event, 1  BUTTON event, 2  MOTION event, "
+		"3  PRESSURE event",
+		.prop_name = WACOM_PROP_LOGMASK,
+		.prop_format = 8,
+		.prop_offset = 0,
+		.arg_count = 1,
+	},
+	{
 		.name = "Suppress",
 		.x11name = "Suppress",
 		.desc = "Number of points trimmed (default is 2). ",
@@ -2974,7 +2984,7 @@ static void test_parameter_number(void)
 	 * deprecated them.
 	 * Numbers include trailing NULL entry.
 	 */
-	assert(ARRAY_SIZE(parameters) == 39);
+	assert(ARRAY_SIZE(parameters) == 40);
 	assert(ARRAY_SIZE(deprecated_parameters) == 17);
 }
 
openSUSE Build Service is sponsored by