Hi again.

Another day, another patch ;) Most of the fancy bits are in the last
one. It lets the user define a name for the tool and define if its
created either as stylus, eraser(there are no tools that specifically
have just eraser, but there may be people with pens that have a broken
stylus end or something ;) ) or both. Known problem is that the name
array isn't freed, because I was too stupid to figure out where/how
its supposed to be done.

The line I currently have in my 50-wacom.conf is:
Option "ToolSerials" "113246231,both,Airbrush;85983311,stylus,Artpen"
Resulting in following devices:
Wacom Intuos3 6x8 eraser ERASER
Wacom Intuos3 6x8 cursor CURSOR
Wacom Intuos3 6x8 pad PAD
Airbrush stylus  STYLUS
Airbrush eraser  ERASER
Artpen stylus    STYLUS
Wacom Intuos3 6x8 stylus STYLUS


The second patch had a little bug fixed. the first patch is the same
as posted earlier and just contains the serial query fix.

Any comments welcome.

-- 
--Alexia

P.S an option to override the terribly long default basename would be
really really neat :) Id even bring the code for it if there was no
opposition...
From f5f588af75feba750a67083538c69f0e333715a1 Mon Sep 17 00:00:00 2001
From: Alexia Death <[email protected]>
Date: Sat, 27 Nov 2010 19:18:10 +0200
Subject: [PATCH 1/3] Fix the driver and xsetwacom to return last ToolSerial

---
 src/wcmXCommand.c |   28 +++++++++++++++++++++++++++-
 src/xf86Wacom.c   |    2 +-
 src/xf86Wacom.h   |    1 +
 tools/xsetwacom.c |    2 +-
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c
index 1b36280..96d06a1 100644
--- a/src/wcmXCommand.c
+++ b/src/wcmXCommand.c
@@ -687,7 +687,7 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
 			wcmRotateTablet(pInfo, value);
 	} else if (property == prop_serials)
 	{
-		return BadValue; /* Read-only */
+		return Success; /* Read-only */
 	} else if (property == prop_strip_buttons)
 		return wcmSetStripProperty(dev, property, prop, checkonly);
 	else if (property == prop_wheel_buttons)
@@ -842,4 +842,30 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
 
 	return Success;
 }
+
+int wcmGetProperty (DeviceIntPtr dev, Atom property)
+{
+	InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
+	WacomDevicePtr priv = (WacomDevicePtr) pInfo->private;
+	WacomCommonPtr common = priv->common;
+	uint32_t values[4];
+
+	DBG(10, priv, "\n");
+
+	if (property == prop_serials)
+	{
+		DBG(10, priv, "Update to serial: %d\n", priv->old_serial);
+
+		values[0] = common->tablet_id;
+		values[1] = priv->old_serial;
+		values[2] = priv->old_device_id;
+		values[3] = priv->serial;
+
+		return XIChangeDeviceProperty(dev, property, XA_INTEGER, 32,
+			                      PropModeReplace, 4,
+			                      values, FALSE);
+	}
+
+	return Success;
+}
 /* vim: set noexpandtab tabstop=8 shiftwidth=8: */
diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
index 397d9fd..90d9d05 100644
--- a/src/xf86Wacom.c
+++ b/src/xf86Wacom.c
@@ -638,7 +638,7 @@ static int wcmDevInit(DeviceIntPtr pWcm)
 	}
 
 	InitWcmDeviceProperties(pInfo);
-	XIRegisterPropertyHandler(pInfo->dev, wcmSetProperty, NULL, wcmDeleteProperty);
+	XIRegisterPropertyHandler(pInfo->dev, wcmSetProperty, wcmGetProperty, wcmDeleteProperty);
 
 	return TRUE;
 }
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index dbd741c..d428f45 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -174,6 +174,7 @@ extern int wcmGetPhyDeviceID(WacomDevicePtr priv);
 
 /* device properties */
 extern int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly);
+extern int wcmGetProperty (DeviceIntPtr dev, Atom property);
 extern int wcmDeleteProperty(DeviceIntPtr dev, Atom property);
 extern void InitWcmDeviceProperties(InputInfoPtr pInfo);
 
diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index 84dd188..be5a662 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -571,7 +571,7 @@ static param_t parameters[] =
 		.desc = "Returns the serial number of the associated device. ",
 		.prop_name = WACOM_PROP_SERIALIDS,
 		.prop_format = 32,
-		.prop_offset = 3,
+		.prop_offset = 1,
 		.prop_flags = PROP_FLAG_READONLY
 	},
 	{
-- 
1.7.1

From d7543278bf1e32711f3cb1bc085ab1bca70b1809 Mon Sep 17 00:00:00 2001
From: Alexia Death <[email protected]>
Date: Fri, 26 Nov 2010 21:04:12 +0200
Subject: [PATCH 2/3] Add basic tool serial hotplug support

---
 src/wcmValidateDevice.c |   72 ++++++++++++++++++++++++++++++++++++++++++----
 src/xf86WacomDefs.h     |    4 ++
 2 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
index b2ec79e..8f01212 100644
--- a/src/wcmValidateDevice.c
+++ b/src/wcmValidateDevice.c
@@ -289,8 +289,10 @@ int wcmDeviceTypeKeys(InputInfoPtr pInfo)
 /**
  * Duplicate xf86 options, replace the "type" option with the given type
  * (and the name with "$name $type" and convert them to InputOption */
-static InputOption *wcmOptionDupConvert(InputInfoPtr pInfo, const char* basename, const char *type)
+static InputOption *wcmOptionDupConvert(InputInfoPtr pInfo, const char* basename, const char *type, int serial_id)
 {
+	WacomDevicePtr priv = pInfo->private;
+	WacomCommonPtr common = priv->common;
 	pointer original = pInfo->options;
 	InputOption *iopts = NULL, *new;
 	char *name;
@@ -307,11 +309,17 @@ static InputOption *wcmOptionDupConvert(InputInfoPtr pInfo, const char* basename
 		options = dummy.options;
 	}
 #endif
-
-	name = Xprintf("%s %s", basename, type);
+	if (serial_id > -1)
+		name = Xprintf("%s %s %d", basename, type, common->serials[serial_id]);
+	else
+		name = Xprintf("%s %s", basename, type);
 
 	options = xf86ReplaceStrOption(options, "Type", type);
 	options = xf86ReplaceStrOption(options, "Name", name);
+
+	if (serial_id > -1)
+		options = xf86ReplaceIntOption(options, "Serial", common->serials[serial_id]);
+
 	free(name);
 
 	while(options)
@@ -362,7 +370,7 @@ static InputAttributes* wcmDuplicateAttributes(InputInfoPtr pInfo,
  * erasor, stylus, pad, touch, cursor, etc.
  * Name of the new device is set automatically to "<device name> <type>".
  */
-static void wcmHotplug(InputInfoPtr pInfo, const char* basename, const char *type)
+static void wcmHotplug(InputInfoPtr pInfo, const char* basename, const char *type, int serial_id)
 {
 	DeviceIntPtr dev; /* dummy */
 	InputOption *input_options;
@@ -370,7 +378,7 @@ static void wcmHotplug(InputInfoPtr pInfo, const char* basename, const char *typ
 	InputAttributes *attrs = NULL;
 #endif
 
-	input_options = wcmOptionDupConvert(pInfo, basename, type);
+	input_options = wcmOptionDupConvert(pInfo, basename, type, serial_id);
 
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 11
 	attrs = wcmDuplicateAttributes(pInfo, type);
@@ -390,7 +398,9 @@ static void wcmHotplug(InputInfoPtr pInfo, const char* basename, const char *typ
 
 void wcmHotplugOthers(InputInfoPtr pInfo, const char *basename)
 {
-	int i, skip = 1;
+	WacomDevicePtr  priv = (WacomDevicePtr)pInfo->private;
+	WacomCommonPtr  common = priv->common;
+	int i, j, skip = 1;
 	char*		device;
 
         xf86Msg(X_INFO, "%s: hotplugging dependent devices.\n", pInfo->name);
@@ -404,9 +414,28 @@ void wcmHotplugOthers(InputInfoPtr pInfo, const char *basename)
 			if (skip)
 				skip = 0;
 			else
-				wcmHotplug(pInfo, basename, wcmType[i].type);
+				wcmHotplug(pInfo, basename, wcmType[i].type, -1);
 		}
 	}
+
+	if (common->nserials > 0)
+	{
+		for (j = 0; j < common->nserials; j++)
+		{
+			xf86Msg(X_INFO, "%s: hotplugging serial %d.\n", pInfo->name, common->serials[j]);
+
+			if (wcmIsAValidType(pInfo, "stylus"))
+			{
+				wcmHotplug(pInfo, basename, "stylus", j);
+			}
+
+			if (wcmIsAValidType(pInfo, "eraser"))
+			{
+				wcmHotplug(pInfo, basename, "eraser", j);
+			}
+		}
+	}
+
         xf86Msg(X_INFO, "%s: hotplugging completed.\n", pInfo->name);
 }
 
@@ -550,6 +579,35 @@ int wcmParseOptions(InputInfoPtr pInfo, int hotplugged)
 			wcmSetPressureCurve(priv,a,b,c,d);
 	}
 
+	/*Serials of tools we want hotpluged*/
+	s = xf86SetStrOption(pInfo->options, "ToolSerials", NULL);
+	if (s)
+	{
+		int i = 0;
+		char* tok = strtok(s, ";");
+		while ((tok != NULL) && (i < WCM_MAX_SERIALS))
+		{
+			int serial;
+
+			sscanf(tok,"%d",&serial);
+
+			xf86Msg(X_CONFIG, "%s: Tool serial %d found.\n",
+				pInfo->name, serial);
+
+			common->serials[i] = serial;
+
+			tok = strtok(NULL,";");
+			i++;
+		}
+		common->nserials = i;
+
+		if ((i == WCM_MAX_SERIALS) && (tok != NULL))
+			xf86Msg(X_CONFIG, "%s: Only %d tool serials supported, you had more listed.\n",
+				pInfo->name, WCM_MAX_SERIALS);
+
+	}
+
+
 	if (IsCursor(priv))
 	{
 		common->wcmCursorProxoutDist = xf86SetIntOption(pInfo->options, "CursorProx", 0);
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 8cdc9e2..5135a4d 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -152,6 +152,8 @@ struct _WacomModel
 					 * For backword compability support, 
 					 * tablet buttons besides the strips are
 					 * treated as buttons */
+#define WCM_MAX_SERIALS		32	/* maximum number of tablet buttons */
+
 /* get/set/property */
 typedef struct _PROPINFO PROPINFO;
 
@@ -443,6 +445,8 @@ struct _WacomCommonRec
 	void *private;		     /* backend-specific information */
 
 	WacomToolPtr wcmTool; /* List of unique tools */
+        int serials[WCM_MAX_SERIALS];/* Serial numbers provided at startup*/
+        int nserials;                /*Number of serials configured*/
 
 	/* DO NOT TOUCH THIS. use wcmRefCommon() instead */
 	int refcnt;			/* number of devices sharing this struct */
-- 
1.7.1

From 979affe6273d3d9d81668cd4900ef94895d43bf6 Mon Sep 17 00:00:00 2001
From: Alexia Death <[email protected]>
Date: Sun, 28 Nov 2010 15:23:12 +0200
Subject: [PATCH 3/3] Allow for defining type and giving names for serial tools

---
 src/wcmConfig.c         |    2 +
 src/wcmValidateDevice.c |   60 +++++++++++++++++++++++++++++++++++++++-------
 src/xf86WacomDefs.h     |    5 ++++
 3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index d660088..98fea1b 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -142,6 +142,8 @@ static int wcmAllocate(InputInfoPtr pInfo)
 	area->next = NULL;    /* next area in list */
 	area->device = pInfo; /* associated WacomDevice */
 
+	common->nserials = 0;
+
 	return 1;
 
 error:
diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
index 8f01212..57be80d 100644
--- a/src/wcmValidateDevice.c
+++ b/src/wcmValidateDevice.c
@@ -310,7 +310,12 @@ static InputOption *wcmOptionDupConvert(InputInfoPtr pInfo, const char* basename
 	}
 #endif
 	if (serial_id > -1)
-		name = Xprintf("%s %s %d", basename, type, common->serials[serial_id]);
+	{
+		if (strlen(common->serial_names[serial_id]) > 0)
+			name = Xprintf("%s %s", common->serial_names[serial_id], type);
+		else
+			name = Xprintf("%s %s %d", basename, type, common->serials[serial_id]);
+	}
 	else
 		name = Xprintf("%s %s", basename, type);
 
@@ -424,12 +429,14 @@ void wcmHotplugOthers(InputInfoPtr pInfo, const char *basename)
 		{
 			xf86Msg(X_INFO, "%s: hotplugging serial %d.\n", pInfo->name, common->serials[j]);
 
-			if (wcmIsAValidType(pInfo, "stylus"))
+			if (wcmIsAValidType(pInfo, "stylus") &&
+			    (common->serial_types[j] & SERIAL_HAS_STYLUS))
 			{
 				wcmHotplug(pInfo, basename, "stylus", j);
 			}
 
-			if (wcmIsAValidType(pInfo, "eraser"))
+			if (wcmIsAValidType(pInfo, "eraser") &&
+			    (common->serial_types[j] & SERIAL_HAS_ERASER))
 			{
 				wcmHotplug(pInfo, basename, "eraser", j);
 			}
@@ -581,20 +588,55 @@ int wcmParseOptions(InputInfoPtr pInfo, int hotplugged)
 
 	/*Serials of tools we want hotpluged*/
 	s = xf86SetStrOption(pInfo->options, "ToolSerials", NULL);
-	if (s)
+	if (s && (common->nserials == 0)) /*Dont parse again, if the commons have values already*/
 	{
 		int i = 0;
 		char* tok = strtok(s, ";");
 		while ((tok != NULL) && (i < WCM_MAX_SERIALS))
 		{
-			int serial;
+			int serial, mcnt;
+			char type[strlen(tok) + 1];
+			char name[strlen(tok) + 1];
 
-			sscanf(tok,"%d",&serial);
+			mcnt = sscanf(tok,"%d,%[a-z],%[A-Za-z ]",&serial, type, name);
 
-			xf86Msg(X_CONFIG, "%s: Tool serial %d found.\n",
-				pInfo->name, serial);
+			if (mcnt < 1)
+			{
+				xf86Msg(X_ERROR, "%s: %s is invalid serial string.\n",
+					pInfo->name, tok);
+				goto error;
+			}
+
+			if (mcnt >= 1)
+			{
+				xf86Msg(X_CONFIG, "%s: Tool serial %d found.\n",
+					pInfo->name, serial);
 
-			common->serials[i] = serial;
+				common->serials[i] = serial;
+
+				common->serial_types[i] = SERIAL_HAS_STYLUS | SERIAL_HAS_ERASER; /*Default to both tools*/
+			}
+
+			if (mcnt >= 2)
+			{
+				xf86Msg(X_CONFIG, "%s: Tool %d has type %s.\n",
+					pInfo->name, serial, type);
+				if (strcmp(type, "stylus") == 0)
+					common->serial_types[i] = SERIAL_HAS_STYLUS;
+				else if (strcmp(type, "eraser") == 0)
+					common->serial_types[i] = SERIAL_HAS_ERASER;
+				else if (!(strcmp(type, "both") == 0))
+					xf86Msg(X_CONFIG, "%s: Invalid type %s, defaulting to both.\n",
+					pInfo->name, type);
+			}
+                      
+			if (mcnt == 3)
+			{
+				xf86Msg(X_CONFIG, "%s: Tool %d is named %s.\n",
+					pInfo->name, serial, name);
+				common->serial_names[i] = strdup(name);
+			}
+			else common->serial_names[i] = ""; /*no name yet*/
 
 			tok = strtok(NULL,";");
 			i++;
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 5135a4d..467bce3 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -374,6 +374,9 @@ enum WacomProtocol {
 	WCM_PROTOCOL_5
 };
 
+#define SERIAL_HAS_ERASER 1
+#define SERIAL_HAS_STYLUS 2
+
 struct _WacomCommonRec 
 {
 	/* Do not move device_path, same offset as priv->name. Used by DBG macro */
@@ -446,6 +449,8 @@ struct _WacomCommonRec
 
 	WacomToolPtr wcmTool; /* List of unique tools */
         int serials[WCM_MAX_SERIALS];/* Serial numbers provided at startup*/
+        int serial_types[WCM_MAX_SERIALS]; /* Eraser, Stylus Or both*/
+        char *serial_names[WCM_MAX_SERIALS]; /* Names of serials*/
         int nserials;                /*Number of serials configured*/
 
 	/* DO NOT TOUCH THIS. use wcmRefCommon() instead */
-- 
1.7.1

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to