1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org>
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun * the above copyright notice appear in all copies and that both that
7*4882a593Smuzhiyun * copyright notice and this permission notice appear in supporting
8*4882a593Smuzhiyun * documentation, and that the name of Frederic Lepied not be used in
9*4882a593Smuzhiyun * advertising or publicity pertaining to distribution of the software without
10*4882a593Smuzhiyun * specific, written prior permission. Frederic Lepied makes no
11*4882a593Smuzhiyun * representations about the suitability of this software for any purpose. It
12*4882a593Smuzhiyun * is provided "as is" without express or implied warranty.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20*4882a593Smuzhiyun * PERFORMANCE OF THIS SOFTWARE.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun * Copyright (c) 2000-2002 by The XFree86 Project, Inc.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
27*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
28*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
29*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
30*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
31*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
34*4882a593Smuzhiyun * all copies or substantial portions of the Software.
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
40*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
41*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * Except as contained in this notice, the name of the copyright holder(s)
44*4882a593Smuzhiyun * and author(s) shall not be used in advertising or otherwise to promote
45*4882a593Smuzhiyun * the sale, use or other dealings in this Software without prior written
46*4882a593Smuzhiyun * authorization from the copyright holder(s) and author(s).
47*4882a593Smuzhiyun */
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #ifdef HAVE_XORG_CONFIG_H
50*4882a593Smuzhiyun #include <xorg-config.h>
51*4882a593Smuzhiyun #endif
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #include <X11/Xfuncproto.h>
54*4882a593Smuzhiyun #include <X11/Xmd.h>
55*4882a593Smuzhiyun #include <X11/extensions/XI.h>
56*4882a593Smuzhiyun #include <X11/extensions/XIproto.h>
57*4882a593Smuzhiyun #include <X11/Xatom.h>
58*4882a593Smuzhiyun #include "xf86.h"
59*4882a593Smuzhiyun #include "xf86Priv.h"
60*4882a593Smuzhiyun #include "xf86Config.h"
61*4882a593Smuzhiyun #include "xf86Xinput.h"
62*4882a593Smuzhiyun #include "xf86Optrec.h"
63*4882a593Smuzhiyun #include "mipointer.h"
64*4882a593Smuzhiyun #include "extinit.h"
65*4882a593Smuzhiyun #include "loaderProcs.h"
66*4882a593Smuzhiyun #include "systemd-logind.h"
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #include "exevents.h" /* AddInputDevice */
69*4882a593Smuzhiyun #include "exglobals.h"
70*4882a593Smuzhiyun #include "eventstr.h"
71*4882a593Smuzhiyun #include "inpututils.h"
72*4882a593Smuzhiyun #include "optionstr.h"
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #include <string.h> /* InputClassMatches */
75*4882a593Smuzhiyun #ifdef HAVE_FNMATCH_H
76*4882a593Smuzhiyun #include <fnmatch.h>
77*4882a593Smuzhiyun #endif
78*4882a593Smuzhiyun #ifdef HAVE_SYS_UTSNAME_H
79*4882a593Smuzhiyun #include <sys/utsname.h>
80*4882a593Smuzhiyun #endif
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun #include <stdarg.h>
83*4882a593Smuzhiyun #include <stdint.h> /* for int64_t */
84*4882a593Smuzhiyun #include <sys/types.h>
85*4882a593Smuzhiyun #include <sys/stat.h>
86*4882a593Smuzhiyun #include <unistd.h>
87*4882a593Smuzhiyun #ifdef HAVE_SYS_SYSMACROS_H
88*4882a593Smuzhiyun #include <sys/sysmacros.h>
89*4882a593Smuzhiyun #endif
90*4882a593Smuzhiyun #ifdef HAVE_SYS_MKDEV_H
91*4882a593Smuzhiyun #include <sys/mkdev.h> /* for major() & minor() on Solaris */
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun #include "mi.h"
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun #include <ptrveloc.h> /* dix pointer acceleration */
97*4882a593Smuzhiyun #include <xserver-properties.h>
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun #ifdef XFreeXDGA
100*4882a593Smuzhiyun #include "dgaproc.h"
101*4882a593Smuzhiyun #endif
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #include "xkbsrv.h"
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /* Valuator verification macro */
106*4882a593Smuzhiyun #define XI_VERIFY_VALUATORS(num_valuators) \
107*4882a593Smuzhiyun if (num_valuators > MAX_VALUATORS) { \
108*4882a593Smuzhiyun xf86Msg(X_ERROR, "%s: num_valuator %d is greater than" \
109*4882a593Smuzhiyun " MAX_VALUATORS\n", __FUNCTION__, num_valuators); \
110*4882a593Smuzhiyun return; \
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun static int
114*4882a593Smuzhiyun xf86InputDevicePostInit(DeviceIntPtr dev);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun typedef struct {
117*4882a593Smuzhiyun struct xorg_list node;
118*4882a593Smuzhiyun InputInfoPtr pInfo;
119*4882a593Smuzhiyun } PausedInputDeviceRec;
120*4882a593Smuzhiyun typedef PausedInputDeviceRec *PausedInputDevicePtr;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun static struct xorg_list new_input_devices_list = {
123*4882a593Smuzhiyun .next = &new_input_devices_list,
124*4882a593Smuzhiyun .prev = &new_input_devices_list,
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun /**
128*4882a593Smuzhiyun * Eval config and modify DeviceVelocityRec accordingly
129*4882a593Smuzhiyun */
130*4882a593Smuzhiyun static void
ProcessVelocityConfiguration(DeviceIntPtr pDev,const char * devname,void * list,DeviceVelocityPtr s)131*4882a593Smuzhiyun ProcessVelocityConfiguration(DeviceIntPtr pDev, const char *devname, void *list,
132*4882a593Smuzhiyun DeviceVelocityPtr s)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun int tempi;
135*4882a593Smuzhiyun float tempf;
136*4882a593Smuzhiyun Atom float_prop = XIGetKnownProperty(XATOM_FLOAT);
137*4882a593Smuzhiyun Atom prop;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun if (!s)
140*4882a593Smuzhiyun return;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /* common settings (available via device properties) */
143*4882a593Smuzhiyun tempf = xf86SetRealOption(list, "ConstantDeceleration", 1.0);
144*4882a593Smuzhiyun if (tempf != 1.0) {
145*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) constant deceleration by %.1f\n",
146*4882a593Smuzhiyun devname, tempf);
147*4882a593Smuzhiyun prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
148*4882a593Smuzhiyun XIChangeDeviceProperty(pDev, prop, float_prop, 32,
149*4882a593Smuzhiyun PropModeReplace, 1, &tempf, FALSE);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun tempf = xf86SetRealOption(list, "AdaptiveDeceleration", 1.0);
153*4882a593Smuzhiyun if (tempf > 1.0) {
154*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) adaptive deceleration by %.1f\n",
155*4882a593Smuzhiyun devname, tempf);
156*4882a593Smuzhiyun prop = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
157*4882a593Smuzhiyun XIChangeDeviceProperty(pDev, prop, float_prop, 32,
158*4882a593Smuzhiyun PropModeReplace, 1, &tempf, FALSE);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /* select profile by number */
162*4882a593Smuzhiyun tempi = xf86SetIntOption(list, "AccelerationProfile",
163*4882a593Smuzhiyun s->statistics.profile_number);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
166*4882a593Smuzhiyun if (XIChangeDeviceProperty(pDev, prop, XA_INTEGER, 32,
167*4882a593Smuzhiyun PropModeReplace, 1, &tempi, FALSE) == Success) {
168*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i\n", devname,
169*4882a593Smuzhiyun tempi);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun else {
172*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i is unknown\n",
173*4882a593Smuzhiyun devname, tempi);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /* set scaling */
177*4882a593Smuzhiyun tempf = xf86SetRealOption(list, "ExpectedRate", 0);
178*4882a593Smuzhiyun prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
179*4882a593Smuzhiyun if (tempf > 0) {
180*4882a593Smuzhiyun tempf = 1000.0 / tempf;
181*4882a593Smuzhiyun XIChangeDeviceProperty(pDev, prop, float_prop, 32,
182*4882a593Smuzhiyun PropModeReplace, 1, &tempf, FALSE);
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun else {
185*4882a593Smuzhiyun tempf = xf86SetRealOption(list, "VelocityScale", s->corr_mul);
186*4882a593Smuzhiyun XIChangeDeviceProperty(pDev, prop, float_prop, 32,
187*4882a593Smuzhiyun PropModeReplace, 1, &tempf, FALSE);
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun tempi = xf86SetIntOption(list, "VelocityTrackerCount", -1);
191*4882a593Smuzhiyun if (tempi > 1)
192*4882a593Smuzhiyun InitTrackers(s, tempi);
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun s->initial_range = xf86SetIntOption(list, "VelocityInitialRange",
195*4882a593Smuzhiyun s->initial_range);
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun s->max_diff = xf86SetRealOption(list, "VelocityAbsDiff", s->max_diff);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun tempf = xf86SetRealOption(list, "VelocityRelDiff", -1);
200*4882a593Smuzhiyun if (tempf >= 0) {
201*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) max rel. velocity difference: %.1f%%\n",
202*4882a593Smuzhiyun devname, tempf * 100.0);
203*4882a593Smuzhiyun s->max_rel_diff = tempf;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /* Configure softening. If const deceleration is used, this is expected
207*4882a593Smuzhiyun * to provide better subpixel information so we enable
208*4882a593Smuzhiyun * softening by default only if ConstantDeceleration is not used
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun s->use_softening = xf86SetBoolOption(list, "Softening",
211*4882a593Smuzhiyun s->const_acceleration == 1.0);
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun s->average_accel = xf86SetBoolOption(list, "AccelerationProfileAveraging",
214*4882a593Smuzhiyun s->average_accel);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun s->reset_time = xf86SetIntOption(list, "VelocityReset", s->reset_time);
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun static void
ApplyAccelerationSettings(DeviceIntPtr dev)220*4882a593Smuzhiyun ApplyAccelerationSettings(DeviceIntPtr dev)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun int scheme, i;
223*4882a593Smuzhiyun DeviceVelocityPtr pVel;
224*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
225*4882a593Smuzhiyun char *schemeStr;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun if (dev->valuator && dev->ptrfeed) {
228*4882a593Smuzhiyun schemeStr = xf86SetStrOption(pInfo->options, "AccelerationScheme", "");
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun scheme = dev->valuator->accelScheme.number;
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun if (!xf86NameCmp(schemeStr, "predictable"))
233*4882a593Smuzhiyun scheme = PtrAccelPredictable;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun if (!xf86NameCmp(schemeStr, "lightweight"))
236*4882a593Smuzhiyun scheme = PtrAccelLightweight;
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun if (!xf86NameCmp(schemeStr, "none"))
239*4882a593Smuzhiyun scheme = PtrAccelNoOp;
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun /* reinit scheme if needed */
242*4882a593Smuzhiyun if (dev->valuator->accelScheme.number != scheme) {
243*4882a593Smuzhiyun if (dev->valuator->accelScheme.AccelCleanupProc) {
244*4882a593Smuzhiyun dev->valuator->accelScheme.AccelCleanupProc(dev);
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun if (InitPointerAccelerationScheme(dev, scheme)) {
248*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) selected scheme %s/%i\n",
249*4882a593Smuzhiyun pInfo->name, schemeStr, scheme);
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun else {
252*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) could not init scheme %s\n",
253*4882a593Smuzhiyun pInfo->name, schemeStr);
254*4882a593Smuzhiyun scheme = dev->valuator->accelScheme.number;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun else {
258*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) keeping acceleration scheme %i\n",
259*4882a593Smuzhiyun pInfo->name, scheme);
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun free(schemeStr);
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun /* process special configuration */
265*4882a593Smuzhiyun switch (scheme) {
266*4882a593Smuzhiyun case PtrAccelPredictable:
267*4882a593Smuzhiyun pVel = GetDevicePredictableAccelData(dev);
268*4882a593Smuzhiyun ProcessVelocityConfiguration(dev, pInfo->name, pInfo->options,
269*4882a593Smuzhiyun pVel);
270*4882a593Smuzhiyun break;
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun i = xf86SetIntOption(pInfo->options, "AccelerationNumerator",
274*4882a593Smuzhiyun dev->ptrfeed->ctrl.num);
275*4882a593Smuzhiyun if (i >= 0)
276*4882a593Smuzhiyun dev->ptrfeed->ctrl.num = i;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun i = xf86SetIntOption(pInfo->options, "AccelerationDenominator",
279*4882a593Smuzhiyun dev->ptrfeed->ctrl.den);
280*4882a593Smuzhiyun if (i > 0)
281*4882a593Smuzhiyun dev->ptrfeed->ctrl.den = i;
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun i = xf86SetIntOption(pInfo->options, "AccelerationThreshold",
284*4882a593Smuzhiyun dev->ptrfeed->ctrl.threshold);
285*4882a593Smuzhiyun if (i >= 0)
286*4882a593Smuzhiyun dev->ptrfeed->ctrl.threshold = i;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) acceleration factor: %.3f\n",
289*4882a593Smuzhiyun pInfo->name, ((float) dev->ptrfeed->ctrl.num) /
290*4882a593Smuzhiyun ((float) dev->ptrfeed->ctrl.den));
291*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: (accel) acceleration threshold: %i\n",
292*4882a593Smuzhiyun pInfo->name, dev->ptrfeed->ctrl.threshold);
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun static void
ApplyTransformationMatrix(DeviceIntPtr dev)297*4882a593Smuzhiyun ApplyTransformationMatrix(DeviceIntPtr dev)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
300*4882a593Smuzhiyun char *str;
301*4882a593Smuzhiyun int rc;
302*4882a593Smuzhiyun float matrix[9] = { 0 };
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun if (!dev->valuator)
305*4882a593Smuzhiyun return;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun str = xf86SetStrOption(pInfo->options, "TransformationMatrix", NULL);
308*4882a593Smuzhiyun if (!str)
309*4882a593Smuzhiyun return;
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun rc = sscanf(str, "%f %f %f %f %f %f %f %f %f", &matrix[0], &matrix[1],
312*4882a593Smuzhiyun &matrix[2], &matrix[3], &matrix[4], &matrix[5], &matrix[6],
313*4882a593Smuzhiyun &matrix[7], &matrix[8]);
314*4882a593Smuzhiyun if (rc != 9) {
315*4882a593Smuzhiyun xf86Msg(X_ERROR,
316*4882a593Smuzhiyun "%s: invalid format for transformation matrix. Ignoring configuration.\n",
317*4882a593Smuzhiyun pInfo->name);
318*4882a593Smuzhiyun return;
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM),
322*4882a593Smuzhiyun XIGetKnownProperty(XATOM_FLOAT), 32,
323*4882a593Smuzhiyun PropModeReplace, 9, matrix, FALSE);
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /***********************************************************************
327*4882a593Smuzhiyun *
328*4882a593Smuzhiyun * xf86ProcessCommonOptions --
329*4882a593Smuzhiyun *
330*4882a593Smuzhiyun * Process global options.
331*4882a593Smuzhiyun *
332*4882a593Smuzhiyun ***********************************************************************
333*4882a593Smuzhiyun */
334*4882a593Smuzhiyun void
xf86ProcessCommonOptions(InputInfoPtr pInfo,XF86OptionPtr list)335*4882a593Smuzhiyun xf86ProcessCommonOptions(InputInfoPtr pInfo, XF86OptionPtr list)
336*4882a593Smuzhiyun {
337*4882a593Smuzhiyun if (xf86SetBoolOption(list, "Floating", 0) ||
338*4882a593Smuzhiyun !xf86SetBoolOption(list, "AlwaysCore", 1) ||
339*4882a593Smuzhiyun !xf86SetBoolOption(list, "SendCoreEvents", 1) ||
340*4882a593Smuzhiyun !xf86SetBoolOption(list, "CorePointer", 1) ||
341*4882a593Smuzhiyun !xf86SetBoolOption(list, "CoreKeyboard", 1)) {
342*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: doesn't report core events\n", pInfo->name);
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun else {
345*4882a593Smuzhiyun pInfo->flags |= XI86_ALWAYS_CORE;
346*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: always reports core events\n", pInfo->name);
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /***********************************************************************
351*4882a593Smuzhiyun *
352*4882a593Smuzhiyun * xf86ActivateDevice --
353*4882a593Smuzhiyun *
354*4882a593Smuzhiyun * Initialize an input device.
355*4882a593Smuzhiyun *
356*4882a593Smuzhiyun * Returns TRUE on success, or FALSE otherwise.
357*4882a593Smuzhiyun ***********************************************************************
358*4882a593Smuzhiyun */
359*4882a593Smuzhiyun static DeviceIntPtr
xf86ActivateDevice(InputInfoPtr pInfo)360*4882a593Smuzhiyun xf86ActivateDevice(InputInfoPtr pInfo)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun DeviceIntPtr dev;
363*4882a593Smuzhiyun Atom atom;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun dev = AddInputDevice(serverClient, pInfo->device_control, TRUE);
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun if (dev == NULL) {
368*4882a593Smuzhiyun xf86Msg(X_ERROR, "Too many input devices. Ignoring %s\n", pInfo->name);
369*4882a593Smuzhiyun pInfo->dev = NULL;
370*4882a593Smuzhiyun return NULL;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun atom = MakeAtom(pInfo->type_name, strlen(pInfo->type_name), TRUE);
374*4882a593Smuzhiyun AssignTypeAndName(dev, atom, pInfo->name);
375*4882a593Smuzhiyun dev->public.devicePrivate = pInfo;
376*4882a593Smuzhiyun pInfo->dev = dev;
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun dev->coreEvents = pInfo->flags & XI86_ALWAYS_CORE;
379*4882a593Smuzhiyun dev->type = SLAVE;
380*4882a593Smuzhiyun dev->spriteInfo->spriteOwner = FALSE;
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun dev->config_info = xf86SetStrOption(pInfo->options, "config_info", NULL);
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun if (serverGeneration == 1)
385*4882a593Smuzhiyun xf86Msg(X_INFO,
386*4882a593Smuzhiyun "XINPUT: Adding extended input device \"%s\" (type: %s, id %d)\n",
387*4882a593Smuzhiyun pInfo->name, pInfo->type_name, dev->id);
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun return dev;
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun /****************************************************************************
393*4882a593Smuzhiyun *
394*4882a593Smuzhiyun * Caller: ProcXSetDeviceMode
395*4882a593Smuzhiyun *
396*4882a593Smuzhiyun * Change the mode of an extension device.
397*4882a593Smuzhiyun * This function is used to change the mode of a device from reporting
398*4882a593Smuzhiyun * relative motion to reporting absolute positional information, and
399*4882a593Smuzhiyun * vice versa.
400*4882a593Smuzhiyun * The default implementation below is that no such devices are supported.
401*4882a593Smuzhiyun *
402*4882a593Smuzhiyun ***********************************************************************
403*4882a593Smuzhiyun */
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun int
SetDeviceMode(ClientPtr client,DeviceIntPtr dev,int mode)406*4882a593Smuzhiyun SetDeviceMode(ClientPtr client, DeviceIntPtr dev, int mode)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun if (pInfo->switch_mode) {
411*4882a593Smuzhiyun return (*pInfo->switch_mode) (client, dev, mode);
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun else
414*4882a593Smuzhiyun return BadMatch;
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun /***********************************************************************
418*4882a593Smuzhiyun *
419*4882a593Smuzhiyun * Caller: ProcXSetDeviceValuators
420*4882a593Smuzhiyun *
421*4882a593Smuzhiyun * Set the value of valuators on an extension input device.
422*4882a593Smuzhiyun * This function is used to set the initial value of valuators on
423*4882a593Smuzhiyun * those input devices that are capable of reporting either relative
424*4882a593Smuzhiyun * motion or an absolute position, and allow an initial position to be set.
425*4882a593Smuzhiyun * The default implementation below is that no such devices are supported.
426*4882a593Smuzhiyun *
427*4882a593Smuzhiyun ***********************************************************************
428*4882a593Smuzhiyun */
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun int
SetDeviceValuators(ClientPtr client,DeviceIntPtr dev,int * valuators,int first_valuator,int num_valuators)431*4882a593Smuzhiyun SetDeviceValuators(ClientPtr client, DeviceIntPtr dev, int *valuators,
432*4882a593Smuzhiyun int first_valuator, int num_valuators)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun if (pInfo->set_device_valuators)
437*4882a593Smuzhiyun return (*pInfo->set_device_valuators) (pInfo, valuators, first_valuator,
438*4882a593Smuzhiyun num_valuators);
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun return BadMatch;
441*4882a593Smuzhiyun }
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun /***********************************************************************
444*4882a593Smuzhiyun *
445*4882a593Smuzhiyun * Caller: ProcXChangeDeviceControl
446*4882a593Smuzhiyun *
447*4882a593Smuzhiyun * Change the specified device controls on an extension input device.
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun ***********************************************************************
450*4882a593Smuzhiyun */
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun int
ChangeDeviceControl(ClientPtr client,DeviceIntPtr dev,xDeviceCtl * control)453*4882a593Smuzhiyun ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, xDeviceCtl * control)
454*4882a593Smuzhiyun {
455*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate;
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun if (!pInfo->control_proc) {
458*4882a593Smuzhiyun switch (control->control) {
459*4882a593Smuzhiyun case DEVICE_CORE:
460*4882a593Smuzhiyun case DEVICE_ABS_CALIB:
461*4882a593Smuzhiyun case DEVICE_ABS_AREA:
462*4882a593Smuzhiyun return BadMatch;
463*4882a593Smuzhiyun case DEVICE_RESOLUTION:
464*4882a593Smuzhiyun case DEVICE_ENABLE:
465*4882a593Smuzhiyun return Success;
466*4882a593Smuzhiyun default:
467*4882a593Smuzhiyun return BadMatch;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun else {
471*4882a593Smuzhiyun return (*pInfo->control_proc) (pInfo, control);
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun }
474*4882a593Smuzhiyun
475*4882a593Smuzhiyun /*
476*4882a593Smuzhiyun * Get the operating system name from uname and store it statically to avoid
477*4882a593Smuzhiyun * repeating the system call each time MatchOS is checked.
478*4882a593Smuzhiyun */
479*4882a593Smuzhiyun static const char *
HostOS(void)480*4882a593Smuzhiyun HostOS(void)
481*4882a593Smuzhiyun {
482*4882a593Smuzhiyun #ifdef HAVE_SYS_UTSNAME_H
483*4882a593Smuzhiyun struct utsname name;
484*4882a593Smuzhiyun static char host_os[sizeof(name.sysname)] = "";
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun if (*host_os == '\0') {
487*4882a593Smuzhiyun if (uname(&name) >= 0)
488*4882a593Smuzhiyun strlcpy(host_os, name.sysname, sizeof(host_os));
489*4882a593Smuzhiyun else {
490*4882a593Smuzhiyun strlcpy(host_os, "unknown", sizeof(host_os));
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun return host_os;
494*4882a593Smuzhiyun #else
495*4882a593Smuzhiyun return "";
496*4882a593Smuzhiyun #endif
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun static int
match_substring(const char * attr,const char * pattern)500*4882a593Smuzhiyun match_substring(const char *attr, const char *pattern)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun return (strstr(attr, pattern)) ? 0 : -1;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun #ifdef HAVE_FNMATCH_H
506*4882a593Smuzhiyun static int
match_pattern(const char * attr,const char * pattern)507*4882a593Smuzhiyun match_pattern(const char *attr, const char *pattern)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun return fnmatch(pattern, attr, 0);
510*4882a593Smuzhiyun }
511*4882a593Smuzhiyun #else
512*4882a593Smuzhiyun #define match_pattern match_substring
513*4882a593Smuzhiyun #endif
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun #ifdef HAVE_FNMATCH_H
516*4882a593Smuzhiyun static int
match_path_pattern(const char * attr,const char * pattern)517*4882a593Smuzhiyun match_path_pattern(const char *attr, const char *pattern)
518*4882a593Smuzhiyun {
519*4882a593Smuzhiyun return fnmatch(pattern, attr, FNM_PATHNAME);
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun #else
522*4882a593Smuzhiyun #define match_path_pattern match_substring
523*4882a593Smuzhiyun #endif
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun /*
526*4882a593Smuzhiyun * If no Layout section is found, xf86ServerLayout.id becomes "(implicit)"
527*4882a593Smuzhiyun * It is convenient that "" in patterns means "no explicit layout"
528*4882a593Smuzhiyun */
529*4882a593Smuzhiyun static int
match_string_implicit(const char * attr,const char * pattern)530*4882a593Smuzhiyun match_string_implicit(const char *attr, const char *pattern)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun if (strlen(pattern)) {
533*4882a593Smuzhiyun return strcmp(attr, pattern);
534*4882a593Smuzhiyun }
535*4882a593Smuzhiyun else {
536*4882a593Smuzhiyun return strcmp(attr, "(implicit)");
537*4882a593Smuzhiyun }
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun /*
541*4882a593Smuzhiyun * Match an attribute against a list of NULL terminated arrays of patterns.
542*4882a593Smuzhiyun * If a pattern in each list entry is matched, return TRUE.
543*4882a593Smuzhiyun */
544*4882a593Smuzhiyun static Bool
MatchAttrToken(const char * attr,struct xorg_list * patterns,int (* compare)(const char * attr,const char * pattern))545*4882a593Smuzhiyun MatchAttrToken(const char *attr, struct xorg_list *patterns,
546*4882a593Smuzhiyun int (*compare) (const char *attr, const char *pattern))
547*4882a593Smuzhiyun {
548*4882a593Smuzhiyun const xf86MatchGroup *group;
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /* If there are no patterns, accept the match */
551*4882a593Smuzhiyun if (xorg_list_is_empty(patterns))
552*4882a593Smuzhiyun return TRUE;
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun /*
555*4882a593Smuzhiyun * Iterate the list of patterns ensuring each entry has a
556*4882a593Smuzhiyun * match. Each list entry is a separate Match line of the same type.
557*4882a593Smuzhiyun */
558*4882a593Smuzhiyun xorg_list_for_each_entry(group, patterns, entry) {
559*4882a593Smuzhiyun char *const *cur;
560*4882a593Smuzhiyun Bool is_negated = group->is_negated;
561*4882a593Smuzhiyun Bool match = is_negated;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun /* If there's a pattern but no attribute, we reject the match for a
564*4882a593Smuzhiyun * MatchFoo directive, and accept it for a NoMatchFoo directive
565*4882a593Smuzhiyun */
566*4882a593Smuzhiyun if (!attr)
567*4882a593Smuzhiyun return is_negated;
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun for (cur = group->values; *cur; cur++)
570*4882a593Smuzhiyun if ((*compare) (attr, *cur) == 0) {
571*4882a593Smuzhiyun match = !is_negated;
572*4882a593Smuzhiyun break;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun if (!match)
575*4882a593Smuzhiyun return FALSE;
576*4882a593Smuzhiyun }
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun /* All the entries in the list matched the attribute */
579*4882a593Smuzhiyun return TRUE;
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /*
583*4882a593Smuzhiyun * Classes without any Match statements match all devices. Otherwise, all
584*4882a593Smuzhiyun * statements must match.
585*4882a593Smuzhiyun */
586*4882a593Smuzhiyun static Bool
InputClassMatches(const XF86ConfInputClassPtr iclass,const InputInfoPtr idev,const InputAttributes * attrs)587*4882a593Smuzhiyun InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev,
588*4882a593Smuzhiyun const InputAttributes * attrs)
589*4882a593Smuzhiyun {
590*4882a593Smuzhiyun /* MatchProduct substring */
591*4882a593Smuzhiyun if (!MatchAttrToken
592*4882a593Smuzhiyun (attrs->product, &iclass->match_product, match_substring))
593*4882a593Smuzhiyun return FALSE;
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /* MatchVendor substring */
596*4882a593Smuzhiyun if (!MatchAttrToken(attrs->vendor, &iclass->match_vendor, match_substring))
597*4882a593Smuzhiyun return FALSE;
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun /* MatchDevicePath pattern */
600*4882a593Smuzhiyun if (!MatchAttrToken
601*4882a593Smuzhiyun (attrs->device, &iclass->match_device, match_path_pattern))
602*4882a593Smuzhiyun return FALSE;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun /* MatchOS case-insensitive string */
605*4882a593Smuzhiyun if (!MatchAttrToken(HostOS(), &iclass->match_os, strcasecmp))
606*4882a593Smuzhiyun return FALSE;
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun /* MatchPnPID pattern */
609*4882a593Smuzhiyun if (!MatchAttrToken(attrs->pnp_id, &iclass->match_pnpid, match_pattern))
610*4882a593Smuzhiyun return FALSE;
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun /* MatchUSBID pattern */
613*4882a593Smuzhiyun if (!MatchAttrToken(attrs->usb_id, &iclass->match_usbid, match_pattern))
614*4882a593Smuzhiyun return FALSE;
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun /* MatchDriver string */
617*4882a593Smuzhiyun if (!MatchAttrToken(idev->driver, &iclass->match_driver, strcmp))
618*4882a593Smuzhiyun return FALSE;
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /*
621*4882a593Smuzhiyun * MatchTag string
622*4882a593Smuzhiyun * See if any of the device's tags match any of the MatchTag tokens.
623*4882a593Smuzhiyun */
624*4882a593Smuzhiyun if (!xorg_list_is_empty(&iclass->match_tag)) {
625*4882a593Smuzhiyun char *const *tag;
626*4882a593Smuzhiyun Bool match;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun if (!attrs->tags)
629*4882a593Smuzhiyun return FALSE;
630*4882a593Smuzhiyun for (tag = attrs->tags, match = FALSE; *tag; tag++) {
631*4882a593Smuzhiyun if (MatchAttrToken(*tag, &iclass->match_tag, strcmp)) {
632*4882a593Smuzhiyun match = TRUE;
633*4882a593Smuzhiyun break;
634*4882a593Smuzhiyun }
635*4882a593Smuzhiyun }
636*4882a593Smuzhiyun if (!match)
637*4882a593Smuzhiyun return FALSE;
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun /* MatchLayout string */
641*4882a593Smuzhiyun if (!xorg_list_is_empty(&iclass->match_layout)) {
642*4882a593Smuzhiyun if (!MatchAttrToken(xf86ConfigLayout.id,
643*4882a593Smuzhiyun &iclass->match_layout, match_string_implicit))
644*4882a593Smuzhiyun return FALSE;
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun /* MatchIs* booleans */
648*4882a593Smuzhiyun if (iclass->is_keyboard.set &&
649*4882a593Smuzhiyun iclass->is_keyboard.val != ! !(attrs->flags & (ATTR_KEY|ATTR_KEYBOARD)))
650*4882a593Smuzhiyun return FALSE;
651*4882a593Smuzhiyun if (iclass->is_pointer.set &&
652*4882a593Smuzhiyun iclass->is_pointer.val != ! !(attrs->flags & ATTR_POINTER))
653*4882a593Smuzhiyun return FALSE;
654*4882a593Smuzhiyun if (iclass->is_joystick.set &&
655*4882a593Smuzhiyun iclass->is_joystick.val != ! !(attrs->flags & ATTR_JOYSTICK))
656*4882a593Smuzhiyun return FALSE;
657*4882a593Smuzhiyun if (iclass->is_tablet.set &&
658*4882a593Smuzhiyun iclass->is_tablet.val != ! !(attrs->flags & ATTR_TABLET))
659*4882a593Smuzhiyun return FALSE;
660*4882a593Smuzhiyun if (iclass->is_tablet_pad.set &&
661*4882a593Smuzhiyun iclass->is_tablet_pad.val != ! !(attrs->flags & ATTR_TABLET_PAD))
662*4882a593Smuzhiyun return FALSE;
663*4882a593Smuzhiyun if (iclass->is_touchpad.set &&
664*4882a593Smuzhiyun iclass->is_touchpad.val != ! !(attrs->flags & ATTR_TOUCHPAD))
665*4882a593Smuzhiyun return FALSE;
666*4882a593Smuzhiyun if (iclass->is_touchscreen.set &&
667*4882a593Smuzhiyun iclass->is_touchscreen.val != ! !(attrs->flags & ATTR_TOUCHSCREEN))
668*4882a593Smuzhiyun return FALSE;
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun return TRUE;
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun /*
674*4882a593Smuzhiyun * Merge in any InputClass configurations. Options in each InputClass
675*4882a593Smuzhiyun * section have more priority than the original device configuration as
676*4882a593Smuzhiyun * well as any previous InputClass sections.
677*4882a593Smuzhiyun */
678*4882a593Smuzhiyun static int
MergeInputClasses(const InputInfoPtr idev,const InputAttributes * attrs)679*4882a593Smuzhiyun MergeInputClasses(const InputInfoPtr idev, const InputAttributes * attrs)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun XF86ConfInputClassPtr cl;
682*4882a593Smuzhiyun XF86OptionPtr classopts;
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) {
685*4882a593Smuzhiyun if (!InputClassMatches(cl, idev, attrs))
686*4882a593Smuzhiyun continue;
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun /* Collect class options and driver settings */
689*4882a593Smuzhiyun classopts = xf86optionListDup(cl->option_lst);
690*4882a593Smuzhiyun if (cl->driver) {
691*4882a593Smuzhiyun free((void *) idev->driver);
692*4882a593Smuzhiyun idev->driver = xstrdup(cl->driver);
693*4882a593Smuzhiyun if (!idev->driver) {
694*4882a593Smuzhiyun xf86Msg(X_ERROR, "Failed to allocate memory while merging "
695*4882a593Smuzhiyun "InputClass configuration");
696*4882a593Smuzhiyun return BadAlloc;
697*4882a593Smuzhiyun }
698*4882a593Smuzhiyun classopts = xf86ReplaceStrOption(classopts, "driver", idev->driver);
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun /* Apply options to device with InputClass settings preferred. */
702*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: Applying InputClass \"%s\"\n",
703*4882a593Smuzhiyun idev->name, cl->identifier);
704*4882a593Smuzhiyun idev->options = xf86optionListMerge(idev->options, classopts);
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun return Success;
708*4882a593Smuzhiyun }
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun /*
711*4882a593Smuzhiyun * Iterate the list of classes and look for Option "Ignore". Return the
712*4882a593Smuzhiyun * value of the last matching class and holler when returning TRUE.
713*4882a593Smuzhiyun */
714*4882a593Smuzhiyun static Bool
IgnoreInputClass(const InputInfoPtr idev,const InputAttributes * attrs)715*4882a593Smuzhiyun IgnoreInputClass(const InputInfoPtr idev, const InputAttributes * attrs)
716*4882a593Smuzhiyun {
717*4882a593Smuzhiyun XF86ConfInputClassPtr cl;
718*4882a593Smuzhiyun Bool ignore = FALSE;
719*4882a593Smuzhiyun const char *ignore_class;
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) {
722*4882a593Smuzhiyun if (!InputClassMatches(cl, idev, attrs))
723*4882a593Smuzhiyun continue;
724*4882a593Smuzhiyun if (xf86findOption(cl->option_lst, "Ignore")) {
725*4882a593Smuzhiyun ignore = xf86CheckBoolOption(cl->option_lst, "Ignore", FALSE);
726*4882a593Smuzhiyun ignore_class = cl->identifier;
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun }
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun if (ignore)
731*4882a593Smuzhiyun xf86Msg(X_CONFIG, "%s: Ignoring device from InputClass \"%s\"\n",
732*4882a593Smuzhiyun idev->name, ignore_class);
733*4882a593Smuzhiyun return ignore;
734*4882a593Smuzhiyun }
735*4882a593Smuzhiyun
736*4882a593Smuzhiyun InputInfoPtr
xf86AllocateInput(void)737*4882a593Smuzhiyun xf86AllocateInput(void)
738*4882a593Smuzhiyun {
739*4882a593Smuzhiyun InputInfoPtr pInfo;
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun pInfo = calloc(sizeof(*pInfo), 1);
742*4882a593Smuzhiyun if (!pInfo)
743*4882a593Smuzhiyun return NULL;
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun pInfo->fd = -1;
746*4882a593Smuzhiyun pInfo->type_name = "UNKNOWN";
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun return pInfo;
749*4882a593Smuzhiyun }
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun /* Append InputInfoRec to the tail of xf86InputDevs. */
752*4882a593Smuzhiyun static void
xf86AddInput(InputDriverPtr drv,InputInfoPtr pInfo)753*4882a593Smuzhiyun xf86AddInput(InputDriverPtr drv, InputInfoPtr pInfo)
754*4882a593Smuzhiyun {
755*4882a593Smuzhiyun InputInfoPtr *prev = NULL;
756*4882a593Smuzhiyun
757*4882a593Smuzhiyun pInfo->drv = drv;
758*4882a593Smuzhiyun pInfo->module = DuplicateModule(drv->module, NULL);
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next);
761*4882a593Smuzhiyun
762*4882a593Smuzhiyun *prev = pInfo;
763*4882a593Smuzhiyun pInfo->next = NULL;
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun xf86CollectInputOptions(pInfo, (const char **) drv->default_options);
766*4882a593Smuzhiyun xf86OptionListReport(pInfo->options);
767*4882a593Smuzhiyun xf86ProcessCommonOptions(pInfo, pInfo->options);
768*4882a593Smuzhiyun }
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun /*
771*4882a593Smuzhiyun * Remove an entry from xf86InputDevs and free all the device's information.
772*4882a593Smuzhiyun */
773*4882a593Smuzhiyun void
xf86DeleteInput(InputInfoPtr pInp,int flags)774*4882a593Smuzhiyun xf86DeleteInput(InputInfoPtr pInp, int flags)
775*4882a593Smuzhiyun {
776*4882a593Smuzhiyun /* First check if the inputdev is valid. */
777*4882a593Smuzhiyun if (pInp == NULL)
778*4882a593Smuzhiyun return;
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun if (pInp->module)
781*4882a593Smuzhiyun UnloadModule(pInp->module);
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun /* This should *really* be handled in drv->UnInit(dev) call instead, but
784*4882a593Smuzhiyun * if the driver forgets about it make sure we free it or at least crash
785*4882a593Smuzhiyun * with flying colors */
786*4882a593Smuzhiyun free(pInp->private);
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun FreeInputAttributes(pInp->attrs);
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun if (pInp->flags & XI86_SERVER_FD)
791*4882a593Smuzhiyun systemd_logind_release_fd(pInp->major, pInp->minor, pInp->fd);
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun /* Remove the entry from the list. */
794*4882a593Smuzhiyun if (pInp == xf86InputDevs)
795*4882a593Smuzhiyun xf86InputDevs = pInp->next;
796*4882a593Smuzhiyun else {
797*4882a593Smuzhiyun InputInfoPtr p = xf86InputDevs;
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun while (p && p->next != pInp)
800*4882a593Smuzhiyun p = p->next;
801*4882a593Smuzhiyun if (p)
802*4882a593Smuzhiyun p->next = pInp->next;
803*4882a593Smuzhiyun /* Else the entry wasn't in the xf86InputDevs list (ignore this). */
804*4882a593Smuzhiyun }
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun free((void *) pInp->driver);
807*4882a593Smuzhiyun free((void *) pInp->name);
808*4882a593Smuzhiyun xf86optionListFree(pInp->options);
809*4882a593Smuzhiyun free(pInp);
810*4882a593Smuzhiyun }
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun /*
813*4882a593Smuzhiyun * Apply backend-specific initialization. Invoked after ActivateDevice(),
814*4882a593Smuzhiyun * i.e. after the driver successfully completed DEVICE_INIT and the device
815*4882a593Smuzhiyun * is advertised.
816*4882a593Smuzhiyun * @param dev the device
817*4882a593Smuzhiyun * @return Success or an error code
818*4882a593Smuzhiyun */
819*4882a593Smuzhiyun static int
xf86InputDevicePostInit(DeviceIntPtr dev)820*4882a593Smuzhiyun xf86InputDevicePostInit(DeviceIntPtr dev)
821*4882a593Smuzhiyun {
822*4882a593Smuzhiyun ApplyAccelerationSettings(dev);
823*4882a593Smuzhiyun ApplyTransformationMatrix(dev);
824*4882a593Smuzhiyun return Success;
825*4882a593Smuzhiyun }
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun static void
xf86stat(const char * path,int * maj,int * min)828*4882a593Smuzhiyun xf86stat(const char *path, int *maj, int *min)
829*4882a593Smuzhiyun {
830*4882a593Smuzhiyun struct stat st;
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun if (stat(path, &st) == -1)
833*4882a593Smuzhiyun return;
834*4882a593Smuzhiyun
835*4882a593Smuzhiyun *maj = major(st.st_rdev);
836*4882a593Smuzhiyun *min = minor(st.st_rdev);
837*4882a593Smuzhiyun }
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun static inline InputDriverPtr
xf86LoadInputDriver(const char * driver_name)840*4882a593Smuzhiyun xf86LoadInputDriver(const char *driver_name)
841*4882a593Smuzhiyun {
842*4882a593Smuzhiyun InputDriverPtr drv = NULL;
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /* Memory leak for every attached device if we don't
845*4882a593Smuzhiyun * test if the module is already loaded first */
846*4882a593Smuzhiyun drv = xf86LookupInputDriver(driver_name);
847*4882a593Smuzhiyun if (!drv) {
848*4882a593Smuzhiyun if (xf86LoadOneModule(driver_name, NULL))
849*4882a593Smuzhiyun drv = xf86LookupInputDriver(driver_name);
850*4882a593Smuzhiyun }
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun return drv;
853*4882a593Smuzhiyun }
854*4882a593Smuzhiyun
855*4882a593Smuzhiyun /**
856*4882a593Smuzhiyun * Create a new input device, activate and enable it.
857*4882a593Smuzhiyun *
858*4882a593Smuzhiyun * Possible return codes:
859*4882a593Smuzhiyun * BadName .. a bad driver name was supplied.
860*4882a593Smuzhiyun * BadImplementation ... The driver does not have a PreInit function. This
861*4882a593Smuzhiyun * is a driver bug.
862*4882a593Smuzhiyun * BadMatch .. device initialization failed.
863*4882a593Smuzhiyun * BadAlloc .. too many input devices
864*4882a593Smuzhiyun *
865*4882a593Smuzhiyun * @param idev The device, already set up with identifier, driver, and the
866*4882a593Smuzhiyun * options.
867*4882a593Smuzhiyun * @param pdev Pointer to the new device, if Success was reported.
868*4882a593Smuzhiyun * @param enable Enable the device after activating it.
869*4882a593Smuzhiyun *
870*4882a593Smuzhiyun * @return Success or an error code
871*4882a593Smuzhiyun */
872*4882a593Smuzhiyun _X_INTERNAL int
xf86NewInputDevice(InputInfoPtr pInfo,DeviceIntPtr * pdev,BOOL enable)873*4882a593Smuzhiyun xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
874*4882a593Smuzhiyun {
875*4882a593Smuzhiyun InputDriverPtr drv = NULL;
876*4882a593Smuzhiyun DeviceIntPtr dev = NULL;
877*4882a593Smuzhiyun Bool paused;
878*4882a593Smuzhiyun int rval;
879*4882a593Smuzhiyun char *path = NULL;
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun drv = xf86LoadInputDriver(pInfo->driver);
882*4882a593Smuzhiyun if (!drv) {
883*4882a593Smuzhiyun xf86Msg(X_ERROR, "No input driver matching `%s'\n", pInfo->driver);
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun if (strlen(FALLBACK_INPUT_DRIVER) > 0) {
886*4882a593Smuzhiyun xf86Msg(X_INFO, "Falling back to input driver `%s'\n",
887*4882a593Smuzhiyun FALLBACK_INPUT_DRIVER);
888*4882a593Smuzhiyun drv = xf86LoadInputDriver(FALLBACK_INPUT_DRIVER);
889*4882a593Smuzhiyun if (drv) {
890*4882a593Smuzhiyun free(pInfo->driver);
891*4882a593Smuzhiyun pInfo->driver = strdup(FALLBACK_INPUT_DRIVER);
892*4882a593Smuzhiyun }
893*4882a593Smuzhiyun }
894*4882a593Smuzhiyun if (!drv) {
895*4882a593Smuzhiyun rval = BadName;
896*4882a593Smuzhiyun goto unwind;
897*4882a593Smuzhiyun }
898*4882a593Smuzhiyun }
899*4882a593Smuzhiyun
900*4882a593Smuzhiyun xf86Msg(X_INFO, "Using input driver '%s' for '%s'\n", drv->driverName,
901*4882a593Smuzhiyun pInfo->name);
902*4882a593Smuzhiyun
903*4882a593Smuzhiyun if (!drv->PreInit) {
904*4882a593Smuzhiyun xf86Msg(X_ERROR,
905*4882a593Smuzhiyun "Input driver `%s' has no PreInit function (ignoring)\n",
906*4882a593Smuzhiyun drv->driverName);
907*4882a593Smuzhiyun rval = BadImplementation;
908*4882a593Smuzhiyun goto unwind;
909*4882a593Smuzhiyun }
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun path = xf86CheckStrOption(pInfo->options, "Device", NULL);
912*4882a593Smuzhiyun if (path && pInfo->major == 0 && pInfo->minor == 0)
913*4882a593Smuzhiyun xf86stat(path, &pInfo->major, &pInfo->minor);
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun if (path && (drv->capabilities & XI86_DRV_CAP_SERVER_FD)){
916*4882a593Smuzhiyun int fd = systemd_logind_take_fd(pInfo->major, pInfo->minor,
917*4882a593Smuzhiyun path, &paused);
918*4882a593Smuzhiyun if (fd != -1) {
919*4882a593Smuzhiyun if (paused) {
920*4882a593Smuzhiyun /* Put on new_input_devices list for delayed probe */
921*4882a593Smuzhiyun PausedInputDevicePtr new_device = xnfalloc(sizeof *new_device);
922*4882a593Smuzhiyun new_device->pInfo = pInfo;
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun xorg_list_append(&new_device->node, &new_input_devices_list);
925*4882a593Smuzhiyun systemd_logind_release_fd(pInfo->major, pInfo->minor, fd);
926*4882a593Smuzhiyun free(path);
927*4882a593Smuzhiyun return BadMatch;
928*4882a593Smuzhiyun }
929*4882a593Smuzhiyun pInfo->fd = fd;
930*4882a593Smuzhiyun pInfo->flags |= XI86_SERVER_FD;
931*4882a593Smuzhiyun pInfo->options = xf86ReplaceIntOption(pInfo->options, "fd", fd);
932*4882a593Smuzhiyun }
933*4882a593Smuzhiyun }
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun free(path);
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun xf86AddInput(drv, pInfo);
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun input_lock();
940*4882a593Smuzhiyun rval = drv->PreInit(drv, pInfo, 0);
941*4882a593Smuzhiyun input_unlock();
942*4882a593Smuzhiyun
943*4882a593Smuzhiyun if (rval != Success) {
944*4882a593Smuzhiyun xf86Msg(X_ERROR, "PreInit returned %d for \"%s\"\n", rval, pInfo->name);
945*4882a593Smuzhiyun goto unwind;
946*4882a593Smuzhiyun }
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun if (!(dev = xf86ActivateDevice(pInfo))) {
949*4882a593Smuzhiyun rval = BadAlloc;
950*4882a593Smuzhiyun goto unwind;
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun rval = ActivateDevice(dev, TRUE);
954*4882a593Smuzhiyun if (rval != Success) {
955*4882a593Smuzhiyun xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name);
956*4882a593Smuzhiyun RemoveDevice(dev, TRUE);
957*4882a593Smuzhiyun goto unwind;
958*4882a593Smuzhiyun }
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun rval = xf86InputDevicePostInit(dev);
961*4882a593Smuzhiyun if (rval != Success) {
962*4882a593Smuzhiyun xf86Msg(X_ERROR, "Couldn't post-init device \"%s\"\n", pInfo->name);
963*4882a593Smuzhiyun RemoveDevice(dev, TRUE);
964*4882a593Smuzhiyun goto unwind;
965*4882a593Smuzhiyun }
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun /* Enable it if it's properly initialised and we're currently in the VT */
968*4882a593Smuzhiyun if (enable && dev->inited && dev->startup && xf86VTOwner()) {
969*4882a593Smuzhiyun input_lock();
970*4882a593Smuzhiyun EnableDevice(dev, TRUE);
971*4882a593Smuzhiyun if (!dev->enabled) {
972*4882a593Smuzhiyun xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name);
973*4882a593Smuzhiyun RemoveDevice(dev, TRUE);
974*4882a593Smuzhiyun rval = BadMatch;
975*4882a593Smuzhiyun input_unlock();
976*4882a593Smuzhiyun goto unwind;
977*4882a593Smuzhiyun }
978*4882a593Smuzhiyun /* send enter/leave event, update sprite window */
979*4882a593Smuzhiyun CheckMotion(NULL, dev);
980*4882a593Smuzhiyun input_unlock();
981*4882a593Smuzhiyun }
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun *pdev = dev;
984*4882a593Smuzhiyun return Success;
985*4882a593Smuzhiyun
986*4882a593Smuzhiyun unwind:
987*4882a593Smuzhiyun if (pInfo) {
988*4882a593Smuzhiyun if (drv && drv->UnInit)
989*4882a593Smuzhiyun drv->UnInit(drv, pInfo, 0);
990*4882a593Smuzhiyun else
991*4882a593Smuzhiyun xf86DeleteInput(pInfo, 0);
992*4882a593Smuzhiyun }
993*4882a593Smuzhiyun return rval;
994*4882a593Smuzhiyun }
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun int
NewInputDeviceRequest(InputOption * options,InputAttributes * attrs,DeviceIntPtr * pdev)997*4882a593Smuzhiyun NewInputDeviceRequest(InputOption *options, InputAttributes * attrs,
998*4882a593Smuzhiyun DeviceIntPtr *pdev)
999*4882a593Smuzhiyun {
1000*4882a593Smuzhiyun InputInfoPtr pInfo = NULL;
1001*4882a593Smuzhiyun InputOption *option = NULL;
1002*4882a593Smuzhiyun int rval = Success;
1003*4882a593Smuzhiyun int is_auto = 0;
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun pInfo = xf86AllocateInput();
1006*4882a593Smuzhiyun if (!pInfo)
1007*4882a593Smuzhiyun return BadAlloc;
1008*4882a593Smuzhiyun
1009*4882a593Smuzhiyun nt_list_for_each_entry(option, options, list.next) {
1010*4882a593Smuzhiyun const char *key = input_option_get_key(option);
1011*4882a593Smuzhiyun const char *value = input_option_get_value(option);
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun if (strcasecmp(key, "driver") == 0) {
1014*4882a593Smuzhiyun if (pInfo->driver) {
1015*4882a593Smuzhiyun rval = BadRequest;
1016*4882a593Smuzhiyun goto unwind;
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun pInfo->driver = xstrdup(value);
1019*4882a593Smuzhiyun if (!pInfo->driver) {
1020*4882a593Smuzhiyun rval = BadAlloc;
1021*4882a593Smuzhiyun goto unwind;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun }
1024*4882a593Smuzhiyun
1025*4882a593Smuzhiyun if (strcasecmp(key, "name") == 0 || strcasecmp(key, "identifier") == 0) {
1026*4882a593Smuzhiyun if (pInfo->name) {
1027*4882a593Smuzhiyun rval = BadRequest;
1028*4882a593Smuzhiyun goto unwind;
1029*4882a593Smuzhiyun }
1030*4882a593Smuzhiyun pInfo->name = xstrdup(value);
1031*4882a593Smuzhiyun if (!pInfo->name) {
1032*4882a593Smuzhiyun rval = BadAlloc;
1033*4882a593Smuzhiyun goto unwind;
1034*4882a593Smuzhiyun }
1035*4882a593Smuzhiyun }
1036*4882a593Smuzhiyun
1037*4882a593Smuzhiyun if (strcmp(key, "_source") == 0 &&
1038*4882a593Smuzhiyun (strcmp(value, "server/hal") == 0 ||
1039*4882a593Smuzhiyun strcmp(value, "server/udev") == 0 ||
1040*4882a593Smuzhiyun strcmp(value, "server/wscons") == 0)) {
1041*4882a593Smuzhiyun is_auto = 1;
1042*4882a593Smuzhiyun if (!xf86Info.autoAddDevices) {
1043*4882a593Smuzhiyun rval = BadMatch;
1044*4882a593Smuzhiyun goto unwind;
1045*4882a593Smuzhiyun }
1046*4882a593Smuzhiyun }
1047*4882a593Smuzhiyun
1048*4882a593Smuzhiyun if (strcmp(key, "major") == 0)
1049*4882a593Smuzhiyun pInfo->major = atoi(value);
1050*4882a593Smuzhiyun
1051*4882a593Smuzhiyun if (strcmp(key, "minor") == 0)
1052*4882a593Smuzhiyun pInfo->minor = atoi(value);
1053*4882a593Smuzhiyun }
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun nt_list_for_each_entry(option, options, list.next) {
1056*4882a593Smuzhiyun /* Copy option key/value strings from the provided list */
1057*4882a593Smuzhiyun pInfo->options = xf86AddNewOption(pInfo->options,
1058*4882a593Smuzhiyun input_option_get_key(option),
1059*4882a593Smuzhiyun input_option_get_value(option));
1060*4882a593Smuzhiyun }
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun /* Apply InputClass settings */
1063*4882a593Smuzhiyun if (attrs) {
1064*4882a593Smuzhiyun if (IgnoreInputClass(pInfo, attrs)) {
1065*4882a593Smuzhiyun rval = BadIDChoice;
1066*4882a593Smuzhiyun goto unwind;
1067*4882a593Smuzhiyun }
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun rval = MergeInputClasses(pInfo, attrs);
1070*4882a593Smuzhiyun if (rval != Success)
1071*4882a593Smuzhiyun goto unwind;
1072*4882a593Smuzhiyun
1073*4882a593Smuzhiyun pInfo->attrs = DuplicateInputAttributes(attrs);
1074*4882a593Smuzhiyun }
1075*4882a593Smuzhiyun
1076*4882a593Smuzhiyun if (!pInfo->name) {
1077*4882a593Smuzhiyun xf86Msg(X_INFO, "No identifier specified, ignoring this device.\n");
1078*4882a593Smuzhiyun rval = BadRequest;
1079*4882a593Smuzhiyun goto unwind;
1080*4882a593Smuzhiyun }
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun if (!pInfo->driver) {
1083*4882a593Smuzhiyun xf86Msg(X_INFO, "No input driver specified, ignoring this device.\n");
1084*4882a593Smuzhiyun xf86Msg(X_INFO,
1085*4882a593Smuzhiyun "This device may have been added with another device file.\n");
1086*4882a593Smuzhiyun rval = BadRequest;
1087*4882a593Smuzhiyun goto unwind;
1088*4882a593Smuzhiyun }
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun rval = xf86NewInputDevice(pInfo, pdev,
1091*4882a593Smuzhiyun (!is_auto ||
1092*4882a593Smuzhiyun (is_auto && xf86Info.autoEnableDevices)));
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun return rval;
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun unwind:
1097*4882a593Smuzhiyun if (is_auto && !xf86Info.autoAddDevices)
1098*4882a593Smuzhiyun xf86Msg(X_INFO, "AutoAddDevices is off - not adding device.\n");
1099*4882a593Smuzhiyun xf86DeleteInput(pInfo, 0);
1100*4882a593Smuzhiyun return rval;
1101*4882a593Smuzhiyun }
1102*4882a593Smuzhiyun
1103*4882a593Smuzhiyun void
DeleteInputDeviceRequest(DeviceIntPtr pDev)1104*4882a593Smuzhiyun DeleteInputDeviceRequest(DeviceIntPtr pDev)
1105*4882a593Smuzhiyun {
1106*4882a593Smuzhiyun InputInfoPtr pInfo = (InputInfoPtr) pDev->public.devicePrivate;
1107*4882a593Smuzhiyun InputDriverPtr drv = NULL;
1108*4882a593Smuzhiyun Bool isMaster = IsMaster(pDev);
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun if (pInfo) /* need to get these before RemoveDevice */
1111*4882a593Smuzhiyun drv = pInfo->drv;
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun input_lock();
1114*4882a593Smuzhiyun RemoveDevice(pDev, TRUE);
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun if (!isMaster && pInfo != NULL) {
1117*4882a593Smuzhiyun if (drv->UnInit)
1118*4882a593Smuzhiyun drv->UnInit(drv, pInfo, 0);
1119*4882a593Smuzhiyun else
1120*4882a593Smuzhiyun xf86DeleteInput(pInfo, 0);
1121*4882a593Smuzhiyun }
1122*4882a593Smuzhiyun input_unlock();
1123*4882a593Smuzhiyun }
1124*4882a593Smuzhiyun
1125*4882a593Smuzhiyun void
RemoveInputDeviceTraces(const char * config_info)1126*4882a593Smuzhiyun RemoveInputDeviceTraces(const char *config_info)
1127*4882a593Smuzhiyun {
1128*4882a593Smuzhiyun PausedInputDevicePtr d, tmp;
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun xorg_list_for_each_entry_safe(d, tmp, &new_input_devices_list, node) {
1131*4882a593Smuzhiyun const char *ci = xf86findOptionValue(d->pInfo->options, "config_info");
1132*4882a593Smuzhiyun if (!ci || strcmp(ci, config_info) != 0)
1133*4882a593Smuzhiyun continue;
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun xorg_list_del(&d->node);
1136*4882a593Smuzhiyun free(d);
1137*4882a593Smuzhiyun }
1138*4882a593Smuzhiyun }
1139*4882a593Smuzhiyun
1140*4882a593Smuzhiyun /*
1141*4882a593Smuzhiyun * convenient functions to post events
1142*4882a593Smuzhiyun */
1143*4882a593Smuzhiyun
1144*4882a593Smuzhiyun void
xf86PostMotionEvent(DeviceIntPtr device,int is_absolute,int first_valuator,int num_valuators,...)1145*4882a593Smuzhiyun xf86PostMotionEvent(DeviceIntPtr device,
1146*4882a593Smuzhiyun int is_absolute, int first_valuator, int num_valuators, ...)
1147*4882a593Smuzhiyun {
1148*4882a593Smuzhiyun va_list var;
1149*4882a593Smuzhiyun int i = 0;
1150*4882a593Smuzhiyun ValuatorMask mask;
1151*4882a593Smuzhiyun
1152*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun valuator_mask_zero(&mask);
1155*4882a593Smuzhiyun va_start(var, num_valuators);
1156*4882a593Smuzhiyun for (i = 0; i < num_valuators; i++)
1157*4882a593Smuzhiyun valuator_mask_set(&mask, first_valuator + i, va_arg(var, int));
1158*4882a593Smuzhiyun
1159*4882a593Smuzhiyun va_end(var);
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun xf86PostMotionEventM(device, is_absolute, &mask);
1162*4882a593Smuzhiyun }
1163*4882a593Smuzhiyun
1164*4882a593Smuzhiyun void
xf86PostMotionEventP(DeviceIntPtr device,int is_absolute,int first_valuator,int num_valuators,const int * valuators)1165*4882a593Smuzhiyun xf86PostMotionEventP(DeviceIntPtr device,
1166*4882a593Smuzhiyun int is_absolute,
1167*4882a593Smuzhiyun int first_valuator,
1168*4882a593Smuzhiyun int num_valuators, const int *valuators)
1169*4882a593Smuzhiyun {
1170*4882a593Smuzhiyun ValuatorMask mask;
1171*4882a593Smuzhiyun
1172*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1173*4882a593Smuzhiyun
1174*4882a593Smuzhiyun valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators);
1175*4882a593Smuzhiyun xf86PostMotionEventM(device, is_absolute, &mask);
1176*4882a593Smuzhiyun }
1177*4882a593Smuzhiyun
1178*4882a593Smuzhiyun static int
xf86CheckMotionEvent4DGA(DeviceIntPtr device,int is_absolute,const ValuatorMask * mask)1179*4882a593Smuzhiyun xf86CheckMotionEvent4DGA(DeviceIntPtr device, int is_absolute,
1180*4882a593Smuzhiyun const ValuatorMask *mask)
1181*4882a593Smuzhiyun {
1182*4882a593Smuzhiyun int stolen = 0;
1183*4882a593Smuzhiyun
1184*4882a593Smuzhiyun #ifdef XFreeXDGA
1185*4882a593Smuzhiyun ScreenPtr scr = NULL;
1186*4882a593Smuzhiyun int idx = 0, i;
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun /* The evdev driver may not always send all axes across. */
1189*4882a593Smuzhiyun if (valuator_mask_isset(mask, 0) || valuator_mask_isset(mask, 1)) {
1190*4882a593Smuzhiyun scr = miPointerGetScreen(device);
1191*4882a593Smuzhiyun if (scr) {
1192*4882a593Smuzhiyun int dx = 0, dy = 0;
1193*4882a593Smuzhiyun
1194*4882a593Smuzhiyun idx = scr->myNum;
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun if (valuator_mask_isset(mask, 0)) {
1197*4882a593Smuzhiyun dx = valuator_mask_get(mask, 0);
1198*4882a593Smuzhiyun if (is_absolute)
1199*4882a593Smuzhiyun dx -= device->last.valuators[0];
1200*4882a593Smuzhiyun else if (valuator_mask_has_unaccelerated(mask))
1201*4882a593Smuzhiyun dx = valuator_mask_get_unaccelerated(mask, 0);
1202*4882a593Smuzhiyun }
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun if (valuator_mask_isset(mask, 1)) {
1205*4882a593Smuzhiyun dy = valuator_mask_get(mask, 1);
1206*4882a593Smuzhiyun if (is_absolute)
1207*4882a593Smuzhiyun dy -= device->last.valuators[1];
1208*4882a593Smuzhiyun else if (valuator_mask_has_unaccelerated(mask))
1209*4882a593Smuzhiyun dy = valuator_mask_get_unaccelerated(mask, 1);
1210*4882a593Smuzhiyun }
1211*4882a593Smuzhiyun
1212*4882a593Smuzhiyun if (DGAStealMotionEvent(device, idx, dx, dy))
1213*4882a593Smuzhiyun stolen = 1;
1214*4882a593Smuzhiyun }
1215*4882a593Smuzhiyun }
1216*4882a593Smuzhiyun
1217*4882a593Smuzhiyun for (i = 2; i < valuator_mask_size(mask); i++) {
1218*4882a593Smuzhiyun AxisInfoPtr ax;
1219*4882a593Smuzhiyun double incr;
1220*4882a593Smuzhiyun int val, button;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun if (i >= device->valuator->numAxes)
1223*4882a593Smuzhiyun break;
1224*4882a593Smuzhiyun
1225*4882a593Smuzhiyun if (!valuator_mask_isset(mask, i))
1226*4882a593Smuzhiyun continue;
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun ax = &device->valuator->axes[i];
1229*4882a593Smuzhiyun
1230*4882a593Smuzhiyun if (ax->scroll.type == SCROLL_TYPE_NONE)
1231*4882a593Smuzhiyun continue;
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun if (!scr) {
1234*4882a593Smuzhiyun scr = miPointerGetScreen(device);
1235*4882a593Smuzhiyun if (!scr)
1236*4882a593Smuzhiyun break;
1237*4882a593Smuzhiyun idx = scr->myNum;
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun
1240*4882a593Smuzhiyun incr = ax->scroll.increment;
1241*4882a593Smuzhiyun val = valuator_mask_get(mask, i);
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun if (ax->scroll.type == SCROLL_TYPE_VERTICAL) {
1244*4882a593Smuzhiyun if (incr * val < 0)
1245*4882a593Smuzhiyun button = 4; /* up */
1246*4882a593Smuzhiyun else
1247*4882a593Smuzhiyun button = 5; /* down */
1248*4882a593Smuzhiyun } else { /* SCROLL_TYPE_HORIZONTAL */
1249*4882a593Smuzhiyun if (incr * val < 0)
1250*4882a593Smuzhiyun button = 6; /* left */
1251*4882a593Smuzhiyun else
1252*4882a593Smuzhiyun button = 7; /* right */
1253*4882a593Smuzhiyun }
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun if (DGAStealButtonEvent(device, idx, button, 1) &&
1256*4882a593Smuzhiyun DGAStealButtonEvent(device, idx, button, 0))
1257*4882a593Smuzhiyun stolen = 1;
1258*4882a593Smuzhiyun }
1259*4882a593Smuzhiyun
1260*4882a593Smuzhiyun #endif
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun return stolen;
1263*4882a593Smuzhiyun }
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun void
xf86PostMotionEventM(DeviceIntPtr device,int is_absolute,const ValuatorMask * mask)1266*4882a593Smuzhiyun xf86PostMotionEventM(DeviceIntPtr device,
1267*4882a593Smuzhiyun int is_absolute, const ValuatorMask *mask)
1268*4882a593Smuzhiyun {
1269*4882a593Smuzhiyun int flags = 0;
1270*4882a593Smuzhiyun
1271*4882a593Smuzhiyun if (xf86CheckMotionEvent4DGA(device, is_absolute, mask))
1272*4882a593Smuzhiyun return;
1273*4882a593Smuzhiyun
1274*4882a593Smuzhiyun if (valuator_mask_num_valuators(mask) > 0) {
1275*4882a593Smuzhiyun if (is_absolute)
1276*4882a593Smuzhiyun flags = POINTER_ABSOLUTE;
1277*4882a593Smuzhiyun else
1278*4882a593Smuzhiyun flags = POINTER_RELATIVE | POINTER_ACCELERATE;
1279*4882a593Smuzhiyun }
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun QueuePointerEvents(device, MotionNotify, 0, flags, mask);
1282*4882a593Smuzhiyun }
1283*4882a593Smuzhiyun
1284*4882a593Smuzhiyun void
xf86PostProximityEvent(DeviceIntPtr device,int is_in,int first_valuator,int num_valuators,...)1285*4882a593Smuzhiyun xf86PostProximityEvent(DeviceIntPtr device,
1286*4882a593Smuzhiyun int is_in, int first_valuator, int num_valuators, ...)
1287*4882a593Smuzhiyun {
1288*4882a593Smuzhiyun va_list var;
1289*4882a593Smuzhiyun int i;
1290*4882a593Smuzhiyun ValuatorMask mask;
1291*4882a593Smuzhiyun
1292*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1293*4882a593Smuzhiyun
1294*4882a593Smuzhiyun valuator_mask_zero(&mask);
1295*4882a593Smuzhiyun va_start(var, num_valuators);
1296*4882a593Smuzhiyun for (i = 0; i < num_valuators; i++)
1297*4882a593Smuzhiyun valuator_mask_set(&mask, first_valuator + i, va_arg(var, int));
1298*4882a593Smuzhiyun
1299*4882a593Smuzhiyun va_end(var);
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun xf86PostProximityEventM(device, is_in, &mask);
1302*4882a593Smuzhiyun }
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun void
xf86PostProximityEventP(DeviceIntPtr device,int is_in,int first_valuator,int num_valuators,const int * valuators)1305*4882a593Smuzhiyun xf86PostProximityEventP(DeviceIntPtr device,
1306*4882a593Smuzhiyun int is_in,
1307*4882a593Smuzhiyun int first_valuator,
1308*4882a593Smuzhiyun int num_valuators, const int *valuators)
1309*4882a593Smuzhiyun {
1310*4882a593Smuzhiyun ValuatorMask mask;
1311*4882a593Smuzhiyun
1312*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators);
1315*4882a593Smuzhiyun xf86PostProximityEventM(device, is_in, &mask);
1316*4882a593Smuzhiyun }
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun void
xf86PostProximityEventM(DeviceIntPtr device,int is_in,const ValuatorMask * mask)1319*4882a593Smuzhiyun xf86PostProximityEventM(DeviceIntPtr device,
1320*4882a593Smuzhiyun int is_in, const ValuatorMask *mask)
1321*4882a593Smuzhiyun {
1322*4882a593Smuzhiyun QueueProximityEvents(device, is_in ? ProximityIn : ProximityOut, mask);
1323*4882a593Smuzhiyun }
1324*4882a593Smuzhiyun
1325*4882a593Smuzhiyun void
xf86PostButtonEvent(DeviceIntPtr device,int is_absolute,int button,int is_down,int first_valuator,int num_valuators,...)1326*4882a593Smuzhiyun xf86PostButtonEvent(DeviceIntPtr device,
1327*4882a593Smuzhiyun int is_absolute,
1328*4882a593Smuzhiyun int button,
1329*4882a593Smuzhiyun int is_down, int first_valuator, int num_valuators, ...)
1330*4882a593Smuzhiyun {
1331*4882a593Smuzhiyun va_list var;
1332*4882a593Smuzhiyun ValuatorMask mask;
1333*4882a593Smuzhiyun int i = 0;
1334*4882a593Smuzhiyun
1335*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1336*4882a593Smuzhiyun
1337*4882a593Smuzhiyun valuator_mask_zero(&mask);
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun va_start(var, num_valuators);
1340*4882a593Smuzhiyun for (i = 0; i < num_valuators; i++)
1341*4882a593Smuzhiyun valuator_mask_set(&mask, first_valuator + i, va_arg(var, int));
1342*4882a593Smuzhiyun
1343*4882a593Smuzhiyun va_end(var);
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun xf86PostButtonEventM(device, is_absolute, button, is_down, &mask);
1346*4882a593Smuzhiyun }
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun void
xf86PostButtonEventP(DeviceIntPtr device,int is_absolute,int button,int is_down,int first_valuator,int num_valuators,const int * valuators)1349*4882a593Smuzhiyun xf86PostButtonEventP(DeviceIntPtr device,
1350*4882a593Smuzhiyun int is_absolute,
1351*4882a593Smuzhiyun int button,
1352*4882a593Smuzhiyun int is_down,
1353*4882a593Smuzhiyun int first_valuator,
1354*4882a593Smuzhiyun int num_valuators, const int *valuators)
1355*4882a593Smuzhiyun {
1356*4882a593Smuzhiyun ValuatorMask mask;
1357*4882a593Smuzhiyun
1358*4882a593Smuzhiyun XI_VERIFY_VALUATORS(num_valuators);
1359*4882a593Smuzhiyun
1360*4882a593Smuzhiyun valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators);
1361*4882a593Smuzhiyun xf86PostButtonEventM(device, is_absolute, button, is_down, &mask);
1362*4882a593Smuzhiyun }
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun void
xf86PostButtonEventM(DeviceIntPtr device,int is_absolute,int button,int is_down,const ValuatorMask * mask)1365*4882a593Smuzhiyun xf86PostButtonEventM(DeviceIntPtr device,
1366*4882a593Smuzhiyun int is_absolute,
1367*4882a593Smuzhiyun int button, int is_down, const ValuatorMask *mask)
1368*4882a593Smuzhiyun {
1369*4882a593Smuzhiyun int flags = 0;
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun if (valuator_mask_num_valuators(mask) > 0) {
1372*4882a593Smuzhiyun if (is_absolute)
1373*4882a593Smuzhiyun flags = POINTER_ABSOLUTE;
1374*4882a593Smuzhiyun else
1375*4882a593Smuzhiyun flags = POINTER_RELATIVE | POINTER_ACCELERATE;
1376*4882a593Smuzhiyun }
1377*4882a593Smuzhiyun
1378*4882a593Smuzhiyun #ifdef XFreeXDGA
1379*4882a593Smuzhiyun if (miPointerGetScreen(device)) {
1380*4882a593Smuzhiyun int index = miPointerGetScreen(device)->myNum;
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun if (DGAStealButtonEvent(device, index, button, is_down))
1383*4882a593Smuzhiyun return;
1384*4882a593Smuzhiyun }
1385*4882a593Smuzhiyun #endif
1386*4882a593Smuzhiyun
1387*4882a593Smuzhiyun QueuePointerEvents(device,
1388*4882a593Smuzhiyun is_down ? ButtonPress : ButtonRelease, button,
1389*4882a593Smuzhiyun flags, mask);
1390*4882a593Smuzhiyun }
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun void
xf86PostKeyEvent(DeviceIntPtr device,unsigned int key_code,int is_down)1393*4882a593Smuzhiyun xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down)
1394*4882a593Smuzhiyun {
1395*4882a593Smuzhiyun xf86PostKeyEventM(device, key_code, is_down);
1396*4882a593Smuzhiyun }
1397*4882a593Smuzhiyun
1398*4882a593Smuzhiyun void
xf86PostKeyEventP(DeviceIntPtr device,unsigned int key_code,int is_down)1399*4882a593Smuzhiyun xf86PostKeyEventP(DeviceIntPtr device,
1400*4882a593Smuzhiyun unsigned int key_code,
1401*4882a593Smuzhiyun int is_down)
1402*4882a593Smuzhiyun {
1403*4882a593Smuzhiyun xf86PostKeyEventM(device, key_code, is_down);
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun void
xf86PostKeyEventM(DeviceIntPtr device,unsigned int key_code,int is_down)1407*4882a593Smuzhiyun xf86PostKeyEventM(DeviceIntPtr device, unsigned int key_code, int is_down)
1408*4882a593Smuzhiyun {
1409*4882a593Smuzhiyun #ifdef XFreeXDGA
1410*4882a593Smuzhiyun DeviceIntPtr pointer;
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun /* Some pointers send key events, paired device is wrong then. */
1413*4882a593Smuzhiyun pointer = GetMaster(device, POINTER_OR_FLOAT);
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun if (miPointerGetScreen(pointer)) {
1416*4882a593Smuzhiyun int index = miPointerGetScreen(pointer)->myNum;
1417*4882a593Smuzhiyun
1418*4882a593Smuzhiyun if (DGAStealKeyEvent(device, index, key_code, is_down))
1419*4882a593Smuzhiyun return;
1420*4882a593Smuzhiyun }
1421*4882a593Smuzhiyun #endif
1422*4882a593Smuzhiyun
1423*4882a593Smuzhiyun QueueKeyboardEvents(device, is_down ? KeyPress : KeyRelease, key_code);
1424*4882a593Smuzhiyun }
1425*4882a593Smuzhiyun
1426*4882a593Smuzhiyun void
xf86PostKeyboardEvent(DeviceIntPtr device,unsigned int key_code,int is_down)1427*4882a593Smuzhiyun xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, int is_down)
1428*4882a593Smuzhiyun {
1429*4882a593Smuzhiyun ValuatorMask mask;
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun valuator_mask_zero(&mask);
1432*4882a593Smuzhiyun xf86PostKeyEventM(device, key_code, is_down);
1433*4882a593Smuzhiyun }
1434*4882a593Smuzhiyun
1435*4882a593Smuzhiyun InputInfoPtr
xf86FirstLocalDevice(void)1436*4882a593Smuzhiyun xf86FirstLocalDevice(void)
1437*4882a593Smuzhiyun {
1438*4882a593Smuzhiyun return xf86InputDevs;
1439*4882a593Smuzhiyun }
1440*4882a593Smuzhiyun
1441*4882a593Smuzhiyun /*
1442*4882a593Smuzhiyun * Cx - raw data from touch screen
1443*4882a593Smuzhiyun * to_max - scaled highest dimension
1444*4882a593Smuzhiyun * (remember, this is of rows - 1 because of 0 origin)
1445*4882a593Smuzhiyun * to_min - scaled lowest dimension
1446*4882a593Smuzhiyun * from_max - highest raw value from touch screen calibration
1447*4882a593Smuzhiyun * from_min - lowest raw value from touch screen calibration
1448*4882a593Smuzhiyun *
1449*4882a593Smuzhiyun * This function is the same for X or Y coordinates.
1450*4882a593Smuzhiyun * You may have to reverse the high and low values to compensate for
1451*4882a593Smuzhiyun * different orgins on the touch screen vs X.
1452*4882a593Smuzhiyun *
1453*4882a593Smuzhiyun * e.g. to scale from device coordinates into screen coordinates, call
1454*4882a593Smuzhiyun * xf86ScaleAxis(x, 0, screen_width, dev_min, dev_max);
1455*4882a593Smuzhiyun */
1456*4882a593Smuzhiyun
1457*4882a593Smuzhiyun int
xf86ScaleAxis(int Cx,int to_max,int to_min,int from_max,int from_min)1458*4882a593Smuzhiyun xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min)
1459*4882a593Smuzhiyun {
1460*4882a593Smuzhiyun int X;
1461*4882a593Smuzhiyun int64_t to_width = to_max - to_min;
1462*4882a593Smuzhiyun int64_t from_width = from_max - from_min;
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun if (from_width) {
1465*4882a593Smuzhiyun X = (int) (((to_width * (Cx - from_min)) / from_width) + to_min);
1466*4882a593Smuzhiyun }
1467*4882a593Smuzhiyun else {
1468*4882a593Smuzhiyun X = 0;
1469*4882a593Smuzhiyun ErrorF("Divide by Zero in xf86ScaleAxis\n");
1470*4882a593Smuzhiyun }
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun if (X > to_max)
1473*4882a593Smuzhiyun X = to_max;
1474*4882a593Smuzhiyun if (X < to_min)
1475*4882a593Smuzhiyun X = to_min;
1476*4882a593Smuzhiyun
1477*4882a593Smuzhiyun return X;
1478*4882a593Smuzhiyun }
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun Bool
xf86InitValuatorAxisStruct(DeviceIntPtr dev,int axnum,Atom label,int minval,int maxval,int resolution,int min_res,int max_res,int mode)1481*4882a593Smuzhiyun xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
1482*4882a593Smuzhiyun int maxval, int resolution, int min_res, int max_res,
1483*4882a593Smuzhiyun int mode)
1484*4882a593Smuzhiyun {
1485*4882a593Smuzhiyun if (!dev || !dev->valuator)
1486*4882a593Smuzhiyun return FALSE;
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution,
1489*4882a593Smuzhiyun min_res, max_res, mode);
1490*4882a593Smuzhiyun }
1491*4882a593Smuzhiyun
1492*4882a593Smuzhiyun /*
1493*4882a593Smuzhiyun * Set the valuator values to be in sync with dix/event.c
1494*4882a593Smuzhiyun * DefineInitialRootWindow().
1495*4882a593Smuzhiyun */
1496*4882a593Smuzhiyun void
xf86InitValuatorDefaults(DeviceIntPtr dev,int axnum)1497*4882a593Smuzhiyun xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum)
1498*4882a593Smuzhiyun {
1499*4882a593Smuzhiyun if (axnum == 0) {
1500*4882a593Smuzhiyun dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
1501*4882a593Smuzhiyun dev->last.valuators[0] = dev->valuator->axisVal[0];
1502*4882a593Smuzhiyun }
1503*4882a593Smuzhiyun else if (axnum == 1) {
1504*4882a593Smuzhiyun dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
1505*4882a593Smuzhiyun dev->last.valuators[1] = dev->valuator->axisVal[1];
1506*4882a593Smuzhiyun }
1507*4882a593Smuzhiyun }
1508*4882a593Smuzhiyun
1509*4882a593Smuzhiyun /**
1510*4882a593Smuzhiyun * Deactivate a device. Call this function from the driver if you receive a
1511*4882a593Smuzhiyun * read error or something else that spoils your day.
1512*4882a593Smuzhiyun * Device will be moved to the off_devices list, but it will still be there
1513*4882a593Smuzhiyun * until you really clean up after it.
1514*4882a593Smuzhiyun * Notifies the client about an inactive device.
1515*4882a593Smuzhiyun *
1516*4882a593Smuzhiyun * @param panic True if device is unrecoverable and needs to be removed.
1517*4882a593Smuzhiyun */
1518*4882a593Smuzhiyun void
xf86DisableDevice(DeviceIntPtr dev,Bool panic)1519*4882a593Smuzhiyun xf86DisableDevice(DeviceIntPtr dev, Bool panic)
1520*4882a593Smuzhiyun {
1521*4882a593Smuzhiyun if (!panic) {
1522*4882a593Smuzhiyun DisableDevice(dev, TRUE);
1523*4882a593Smuzhiyun }
1524*4882a593Smuzhiyun else {
1525*4882a593Smuzhiyun SendDevicePresenceEvent(dev->id, DeviceUnrecoverable);
1526*4882a593Smuzhiyun DeleteInputDeviceRequest(dev);
1527*4882a593Smuzhiyun }
1528*4882a593Smuzhiyun }
1529*4882a593Smuzhiyun
1530*4882a593Smuzhiyun /**
1531*4882a593Smuzhiyun * Reactivate a device. Call this function from the driver if you just found
1532*4882a593Smuzhiyun * out that the read error wasn't quite that bad after all.
1533*4882a593Smuzhiyun * Device will be re-activated, and an event sent to the client.
1534*4882a593Smuzhiyun */
1535*4882a593Smuzhiyun void
xf86EnableDevice(DeviceIntPtr dev)1536*4882a593Smuzhiyun xf86EnableDevice(DeviceIntPtr dev)
1537*4882a593Smuzhiyun {
1538*4882a593Smuzhiyun EnableDevice(dev, TRUE);
1539*4882a593Smuzhiyun }
1540*4882a593Smuzhiyun
1541*4882a593Smuzhiyun /**
1542*4882a593Smuzhiyun * Post a touch event with optional valuators. If this is the first touch in
1543*4882a593Smuzhiyun * the sequence, at least x & y valuators must be provided. The driver is
1544*4882a593Smuzhiyun * responsible for maintaining the correct event sequence (TouchBegin, TouchUpdate,
1545*4882a593Smuzhiyun * TouchEnd). Submitting an update or end event for a unregistered touchid will
1546*4882a593Smuzhiyun * result in errors.
1547*4882a593Smuzhiyun * Touch IDs may be reused by the driver but only after a TouchEnd has been
1548*4882a593Smuzhiyun * submitted for that touch ID.
1549*4882a593Smuzhiyun *
1550*4882a593Smuzhiyun * @param dev The device to post the event for
1551*4882a593Smuzhiyun * @param touchid The touchid of the current touch event. Must be an
1552*4882a593Smuzhiyun * existing ID for TouchUpdate or TouchEnd events
1553*4882a593Smuzhiyun * @param type One of XI_TouchBegin, XI_TouchUpdate, XI_TouchEnd
1554*4882a593Smuzhiyun * @param flags Flags for this event
1555*4882a593Smuzhiyun * @param The valuator mask with all valuators set for this event.
1556*4882a593Smuzhiyun */
1557*4882a593Smuzhiyun void
xf86PostTouchEvent(DeviceIntPtr dev,uint32_t touchid,uint16_t type,uint32_t flags,const ValuatorMask * mask)1558*4882a593Smuzhiyun xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid, uint16_t type,
1559*4882a593Smuzhiyun uint32_t flags, const ValuatorMask *mask)
1560*4882a593Smuzhiyun {
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun QueueTouchEvents(dev, type, touchid, flags, mask);
1563*4882a593Smuzhiyun }
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun void
xf86InputEnableVTProbe(void)1566*4882a593Smuzhiyun xf86InputEnableVTProbe(void)
1567*4882a593Smuzhiyun {
1568*4882a593Smuzhiyun int is_auto = 0;
1569*4882a593Smuzhiyun DeviceIntPtr pdev;
1570*4882a593Smuzhiyun PausedInputDevicePtr d, tmp;
1571*4882a593Smuzhiyun
1572*4882a593Smuzhiyun xorg_list_for_each_entry_safe(d, tmp, &new_input_devices_list, node) {
1573*4882a593Smuzhiyun InputInfoPtr pInfo = d->pInfo;
1574*4882a593Smuzhiyun const char *value = xf86findOptionValue(pInfo->options, "_source");
1575*4882a593Smuzhiyun
1576*4882a593Smuzhiyun is_auto = 0;
1577*4882a593Smuzhiyun if (value &&
1578*4882a593Smuzhiyun (strcmp(value, "server/hal") == 0 ||
1579*4882a593Smuzhiyun strcmp(value, "server/udev") == 0 ||
1580*4882a593Smuzhiyun strcmp(value, "server/wscons") == 0))
1581*4882a593Smuzhiyun is_auto = 1;
1582*4882a593Smuzhiyun
1583*4882a593Smuzhiyun xf86NewInputDevice(pInfo, &pdev,
1584*4882a593Smuzhiyun (!is_auto ||
1585*4882a593Smuzhiyun (is_auto && xf86Info.autoEnableDevices)));
1586*4882a593Smuzhiyun xorg_list_del(&d->node);
1587*4882a593Smuzhiyun free(d);
1588*4882a593Smuzhiyun }
1589*4882a593Smuzhiyun }
1590*4882a593Smuzhiyun
1591*4882a593Smuzhiyun /* end of xf86Xinput.c */
1592