LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File n_01-Add-option-to-enable-logging.patch of Package xf86-input-wacom (Project home:mrbadguy:wacom)

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.30.0/configure.ac
===================================================================
--- xf86-input-wacom-0.30.0.orig/configure.ac
+++ xf86-input-wacom-0.30.0/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.30.0/include/wacom-properties.h
===================================================================
--- xf86-input-wacom-0.30.0.orig/include/wacom-properties.h
+++ xf86-input-wacom-0.30.0/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"
+
 /* 32 bit, 1 values */
 #define WACOM_PROP_PANSCROLL_THRESHOLD "Wacom Panscroll Threshold"
 
Index: xf86-input-wacom-0.30.0/man/wacom.man
===================================================================
--- xf86-input-wacom-0.30.0.orig/man/wacom.man
+++ xf86-input-wacom-0.30.0/man/wacom.man
@@ -269,6 +269,25 @@ scroll event is generated when using the "pan" action. Smaller values
 will require less distance and be more sensitive. Larger values will
 require more distance and be less sensitive.  Default: 1300 or 2600
 depending on tablet resolution (corresponds to 13 mm of distance).
+.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.30.0/man/xsetwacom.man
===================================================================
--- xf86-input-wacom-0.30.0.orig/man/xsetwacom.man
+++ xf86-input-wacom-0.30.0/man/xsetwacom.man
@@ -266,7 +266,24 @@ a scroll event is generated when using the "pan" action. Smaller values
 will require less distance and be more sensitive. Larger values will
 require more distance and be less sensitive.  Default: 1300 or 2600
 depending on tablet resolution (corresponds to 13 mm of distance).
-
+.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.30.0/src/wcmCommon.c
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/wcmCommon.c
+++ xf86-input-wacom-0.30.0/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
+
 static int wcmButtonPerNotch(WacomDevicePtr priv, int value, int threshold, int btn_positive, int btn_negative)
 {
 	int mode = is_absolute(priv->pInfo);
@@ -1468,6 +1500,9 @@ WacomCommonPtr wcmNewCommon(void)
 			/* number of raw data to be used to for filtering */
 	common->wcmPanscrollThreshold = 0;
 	common->wcmPressureRecalibration = 1;
+#ifdef LOGGING
+	common->LogMask = 0;
+#endif
 	return common;
 }
 
Index: xf86-input-wacom-0.30.0/src/wcmConfig.c
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/wcmConfig.c
+++ xf86-input-wacom-0.30.0/src/wcmConfig.c
@@ -637,6 +637,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.30.0/src/wcmUSB.c
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/wcmUSB.c
+++ xf86-input-wacom-0.30.0/src/wcmUSB.c
@@ -1128,6 +1128,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.30.0/src/wcmXCommand.c
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/wcmXCommand.c
+++ xf86-input-wacom-0.30.0/src/wcmXCommand.c
@@ -99,6 +99,9 @@ static Atom prop_btnactions;
 static Atom prop_product_id;
 static Atom prop_pressure_recal;
 static Atom prop_panscroll_threshold;
+#ifdef LOGGING
+static Atom prop_logmask;
+#endif
 #ifdef DEBUG
 static Atom prop_debuglevels;
 #endif
@@ -316,7 +319,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;
@@ -918,6 +924,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.30.0/src/xf86Wacom.h
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/xf86Wacom.h
+++ xf86-input-wacom-0.30.0/src/xf86Wacom.h
@@ -65,6 +65,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.30.0/src/xf86WacomDefs.h
===================================================================
--- xf86-input-wacom-0.30.0.orig/src/xf86WacomDefs.h
+++ xf86-input-wacom-0.30.0/src/xf86WacomDefs.h
@@ -462,7 +462,9 @@ struct _WacomCommonRec
 	int wcmPressureRecalibration; /* Determine if pressure recalibration of
 					 worn pens should be performed */
 	int wcmPanscrollThreshold;	/* distance pen must move to send a panscroll event */
-
+#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.30.0/tools/xsetwacom.c
===================================================================
--- xf86-input-wacom-0.30.0.orig/tools/xsetwacom.c
+++ xf86-input-wacom-0.30.0/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). ",