|
Lines 41-51
Link Here
|
| 41 |
#include <stdio.h> /* debugging only, we've got no business output text */ |
41 |
#include <stdio.h> /* debugging only, we've got no business output text */ |
| 42 |
#include <ctype.h> |
42 |
#include <ctype.h> |
| 43 |
#include <stdlib.h> |
43 |
#include <stdlib.h> |
|
|
44 |
#include <stdarg.h> |
| 44 |
#include <errno.h> |
45 |
#include <errno.h> |
| 45 |
#include <string.h> |
46 |
#include <string.h> |
| 46 |
#include <memory.h> |
47 |
#include <memory.h> |
| 47 |
#include <assert.h> |
48 |
#include <assert.h> |
| 48 |
|
49 |
|
|
|
50 |
#include "xf86Parser.h" |
| 51 |
|
| 52 |
WACOMDEVICETYPE checkIfWacomDevice (XF86ConfigPtr, const char* ); |
| 53 |
WACOMDEVICETYPE mapStringToType (const char*); |
| 54 |
XF86ConfigPtr readConfig (char *); |
| 55 |
void VErrorF(const char*, va_list); |
| 56 |
void ErrorF (const char*, ...); |
| 57 |
|
| 49 |
/***************************************************************************** |
58 |
/***************************************************************************** |
| 50 |
** Internal structures |
59 |
** Internal structures |
| 51 |
*****************************************************************************/ |
60 |
*****************************************************************************/ |
|
Lines 123-128
Link Here
|
| 123 |
unsigned char* pReq; |
132 |
unsigned char* pReq; |
| 124 |
WACOMDEVICEINFO* pInfo; |
133 |
WACOMDEVICEINFO* pInfo; |
| 125 |
XDeviceInfo* info; |
134 |
XDeviceInfo* info; |
|
|
135 |
XF86ConfigPtr conf; |
| 126 |
char devName[64]; |
136 |
char devName[64]; |
| 127 |
|
137 |
|
| 128 |
if (!hConfig || !ppInfo || !puCount) |
138 |
if (!hConfig || !ppInfo || !puCount) |
|
Lines 132-143
Link Here
|
| 132 |
if (!hConfig->pDevs && CfgGetDevs(hConfig)) |
142 |
if (!hConfig->pDevs && CfgGetDevs(hConfig)) |
| 133 |
return -1; |
143 |
return -1; |
| 134 |
|
144 |
|
|
|
145 |
/* read the config in for wacom devices which don'T use the commnon identifier */ |
| 146 |
conf = readConfig ("/etc/X11/xorg.conf"); |
| 147 |
|
| 135 |
/* estimate size of memory needed to hold structures */ |
148 |
/* estimate size of memory needed to hold structures */ |
| 136 |
nSize = nCount = 0; |
149 |
nSize = nCount = 0; |
| 137 |
for (i=0; i<hConfig->nDevCnt; ++i) |
150 |
for (i=0; i<hConfig->nDevCnt; ++i) |
| 138 |
{ |
151 |
{ |
| 139 |
info = hConfig->pDevs + i; |
152 |
info = hConfig->pDevs + i; |
| 140 |
if (info->use != IsXExtensionDevice) continue; |
153 |
if (info->use != IsXExtensionDevice && info->use != IsXExtensionPointer) continue; |
| 141 |
if (!info->num_classes) continue; |
154 |
if (!info->num_classes) continue; |
| 142 |
nSize += sizeof(WACOMDEVICEINFO); |
155 |
nSize += sizeof(WACOMDEVICEINFO); |
| 143 |
nSize += strlen(info->name) + 1; |
156 |
nSize += strlen(info->name) + 1; |
|
Lines 146-153
Link Here
|
| 146 |
|
159 |
|
| 147 |
/* allocate memory and zero */ |
160 |
/* allocate memory and zero */ |
| 148 |
pReq = (unsigned char*)malloc(nSize); |
161 |
pReq = (unsigned char*)malloc(nSize); |
| 149 |
if (!pReq) return CfgError(hConfig,errno, |
162 |
|
| 150 |
"WacomConfigListDevices: failed to allocate memory"); |
163 |
if (!pReq) |
|
|
164 |
return CfgError(hConfig,errno, "WacomConfigListDevices: failed to allocate memory"); |
| 165 |
|
| 151 |
memset(pReq,0,nSize); |
166 |
memset(pReq,0,nSize); |
| 152 |
|
167 |
|
| 153 |
/* populate data */ |
168 |
/* populate data */ |
|
Lines 158-164
Link Here
|
| 158 |
{ |
173 |
{ |
| 159 |
info = hConfig->pDevs + i; |
174 |
info = hConfig->pDevs + i; |
| 160 |
/* ignore non-extension devices */ |
175 |
/* ignore non-extension devices */ |
| 161 |
if (info->use != IsXExtensionDevice) continue; |
176 |
if (info->use != IsXExtensionDevice && info->use != IsXExtensionPointer) continue; |
| 162 |
/* ignore uninitialized tools */ |
177 |
/* ignore uninitialized tools */ |
| 163 |
if (!info->num_classes) continue; |
178 |
if (!info->num_classes) continue; |
| 164 |
/* copy name */ |
179 |
/* copy name */ |
|
Lines 170-185
Link Here
|
| 170 |
for (j=0; j<strlen(pInfo->pszName); j++) |
185 |
for (j=0; j<strlen(pInfo->pszName); j++) |
| 171 |
devName[j] = tolower(pInfo->pszName[j]); |
186 |
devName[j] = tolower(pInfo->pszName[j]); |
| 172 |
devName[j] = '\0'; |
187 |
devName[j] = '\0'; |
| 173 |
if (strstr(devName,"cursor") != NULL) |
188 |
|
| 174 |
pInfo->type = WACOMDEVICETYPE_CURSOR; |
189 |
pInfo->type = mapStringToType (devName); |
| 175 |
else if (strstr(devName,"stylus") != NULL) |
190 |
|
| 176 |
pInfo->type = WACOMDEVICETYPE_STYLUS; |
191 |
if ( pInfo->type == WACOMDEVICETYPE_UNKNOWN ) { |
| 177 |
else if (strstr(devName,"eraser") != NULL) |
192 |
pInfo->type = checkIfWacomDevice (conf, pInfo->pszName); |
| 178 |
pInfo->type = WACOMDEVICETYPE_ERASER; |
193 |
} |
| 179 |
else if (strstr(devName,"pad") != NULL) |
|
|
| 180 |
pInfo->type = WACOMDEVICETYPE_PAD; |
| 181 |
else |
| 182 |
pInfo->type = WACOMDEVICETYPE_UNKNOWN; |
| 183 |
|
194 |
|
| 184 |
if ( pInfo->type != WACOMDEVICETYPE_UNKNOWN ) |
195 |
if ( pInfo->type != WACOMDEVICETYPE_UNKNOWN ) |
| 185 |
{ |
196 |
{ |
|
Lines 196-201
Link Here
|
| 196 |
return 0; |
207 |
return 0; |
| 197 |
} |
208 |
} |
| 198 |
|
209 |
|
|
|
210 |
WACOMDEVICETYPE checkIfWacomDevice (XF86ConfigPtr conf, const char* pszDeviceName) { |
| 211 |
XF86ConfInputPtr ip; |
| 212 |
|
| 213 |
if (!conf || !pszDeviceName) { |
| 214 |
return WACOMDEVICETYPE_UNKNOWN; |
| 215 |
} |
| 216 |
|
| 217 |
ip = (XF86ConfInputPtr) conf->conf_input_lst; |
| 218 |
if (! ip) { |
| 219 |
return WACOMDEVICETYPE_UNKNOWN; |
| 220 |
} |
| 221 |
|
| 222 |
for (;ip;ip=ip->list.next) { |
| 223 |
XF86OptionPtr op = (XF86OptionPtr) ip->inp_option_lst; |
| 224 |
char* type = 0; |
| 225 |
|
| 226 |
if (! op) { |
| 227 |
return WACOMDEVICETYPE_UNKNOWN; |
| 228 |
} |
| 229 |
|
| 230 |
if (strcasecmp(ip->inp_identifier, pszDeviceName) != 0) { |
| 231 |
continue; |
| 232 |
} |
| 233 |
|
| 234 |
if (strcasecmp(ip->inp_driver,"wacom") != 0) { |
| 235 |
continue; |
| 236 |
} |
| 237 |
|
| 238 |
for (;op;op=op->list.next) { |
| 239 |
if (strcasecmp(op->opt_name,"Type") == 0) { |
| 240 |
type = op->opt_val; |
| 241 |
return mapStringToType(type); |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
return WACOMDEVICETYPE_UNKNOWN; |
| 247 |
} |
| 248 |
|
| 249 |
WACOMDEVICETYPE mapStringToType (const char* name) { |
| 250 |
if (!name) |
| 251 |
return WACOMDEVICETYPE_UNKNOWN; |
| 252 |
|
| 253 |
if (strstr(name,"cursor") != NULL) |
| 254 |
return WACOMDEVICETYPE_CURSOR; |
| 255 |
else if (strstr(name,"stylus") != NULL) |
| 256 |
return WACOMDEVICETYPE_STYLUS; |
| 257 |
else if (strstr(name,"eraser") != NULL) |
| 258 |
return WACOMDEVICETYPE_ERASER; |
| 259 |
else if (strstr(name,"pad") != NULL) |
| 260 |
return WACOMDEVICETYPE_PAD; |
| 261 |
else |
| 262 |
return WACOMDEVICETYPE_UNKNOWN; |
| 263 |
|
| 264 |
} |
| 265 |
|
| 199 |
WACOMDEVICE * WacomConfigOpenDevice(WACOMCONFIG * hConfig, |
266 |
WACOMDEVICE * WacomConfigOpenDevice(WACOMCONFIG * hConfig, |
| 200 |
const char* pszDeviceName) |
267 |
const char* pszDeviceName) |
| 201 |
{ |
268 |
{ |
|
Lines 381-383
Link Here
|
| 381 |
|
448 |
|
| 382 |
free(pvData); |
449 |
free(pvData); |
| 383 |
} |
450 |
} |
|
|
451 |
|
| 452 |
XF86ConfigPtr readConfig (char *filename) { |
| 453 |
XF86ConfigPtr conf = 0; |
| 454 |
const char *file = 0; |
| 455 |
char CONFPATH[]= "%A,%R,/etc/%R,%P/etc/X11/%R,%E,%F,/etc/X11/%F," \ |
| 456 |
"%P/etc/X11/%F,%D/%X,/etc/X11/%X,/etc/%X,%P/etc/X11/%X.%H," \ |
| 457 |
"%P/etc/X11/%X,%P/lib/X11/%X.%H,%P/lib/X11/%X"; |
| 458 |
|
| 459 |
if (!(file = (char*)xf86openConfigFile (CONFPATH, filename, 0))) { |
| 460 |
fprintf (stderr, "Unable to open config file\n"); |
| 461 |
return 0; |
| 462 |
} |
| 463 |
|
| 464 |
if ((conf = (XF86ConfigPtr)xf86readConfigFile ()) == 0) { |
| 465 |
fprintf (stderr, "Problem when parsing config file\n"); |
| 466 |
xf86closeConfigFile (); |
| 467 |
return 0; |
| 468 |
} |
| 469 |
|
| 470 |
xf86closeConfigFile (); |
| 471 |
return conf; |
| 472 |
} |
| 473 |
|
| 474 |
void VErrorF(const char *f, va_list args) { |
| 475 |
vfprintf(stderr, f, args); |
| 476 |
} |
| 477 |
|
| 478 |
void ErrorF(const char *f, ...) { |
| 479 |
va_list args; |
| 480 |
va_start(args, f); |
| 481 |
vfprintf(stderr, f, args); |
| 482 |
va_end(args); |
| 483 |
} |