[PATCH] input: constify valuators passed in by input drivers.
Peter Hutterer
peter.hutterer at who-t.net
Sun Aug 8 17:27:50 PDT 2010
GPE modifies the valuators array passed in. Which means any driver using
e.g. xf86PostButtonEventP(..., valuators) twice to emulate a button click
will provide garbage data on the second run.
Constify the argument, and do the same for keyboard and proximity events.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
I guess this is technically an API break but not really...
dix/getevents.c | 17 +++++++++++++----
hw/xfree86/common/xf86Xinput.c | 8 ++++----
hw/xfree86/common/xf86Xinput.h | 8 ++++----
include/input.h | 6 +++---
4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/dix/getevents.c b/dix/getevents.c
index a9b6e82..c3b5b2f 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -912,11 +912,12 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code)
int
GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type,
int key_code, int first_valuator,
- int num_valuators, int *valuators) {
+ int num_valuators, const int *valuators_in) {
int num_events = 0;
CARD32 ms = 0;
DeviceEvent *event;
RawDeviceEvent *raw;
+ int valuators[num_valuators];
/* refuse events from disabled devices */
if (!pDev->enabled)
@@ -947,6 +948,8 @@ GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type,
events++;
num_events++;
+ memcpy(valuators, valuators_in, num_valuators * sizeof(int));
+
init_raw(pDev, raw, ms, type, key_code);
set_raw_valuators(raw, first_valuator, num_valuators, valuators,
raw->valuators.data_raw);
@@ -1067,7 +1070,7 @@ transformAbsolute(DeviceIntPtr dev, int v[MAX_VALUATORS])
int
GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
int flags, int first_valuator, int num_valuators,
- int *valuators) {
+ const int *valuators_in) {
int num_events = 1;
CARD32 ms;
DeviceEvent *event;
@@ -1076,6 +1079,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
cx, cy; /* only screen coordinates */
float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac;
ScreenPtr scr = miPointerGetScreen(pDev);
+ int valuators[num_valuators];
/* refuse events from disabled devices */
if (!pDev->enabled)
@@ -1097,6 +1101,8 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
events++;
num_events++;
+ memcpy(valuators, valuators_in, num_valuators * sizeof(int));
+
init_raw(pDev, raw, ms, type, buttons);
set_raw_valuators(raw, first_valuator, num_valuators, valuators,
raw->valuators.data_raw);
@@ -1183,10 +1189,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
*/
int
GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type,
- int first_valuator, int num_valuators, int *valuators)
+ int first_valuator, int num_valuators, const int *valuators_in)
{
int num_events = 1;
DeviceEvent *event;
+ int valuators[num_valuators];
/* refuse events from disabled devices */
if (!pDev->enabled)
@@ -1212,8 +1219,10 @@ GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type,
init_event(pDev, event, GetTimeInMillis());
event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
- if (num_valuators)
+ if (num_valuators) {
+ memcpy(valuators, valuators_in, num_valuators * sizeof(int));
clipValuators(pDev, first_valuator, num_valuators, valuators);
+ }
set_valuators(pDev, event, first_valuator, num_valuators, valuators);
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 76d2d00..d140772 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1004,7 +1004,7 @@ xf86PostMotionEventP(DeviceIntPtr device,
int is_absolute,
int first_valuator,
int num_valuators,
- int *valuators)
+ const int *valuators)
{
int i = 0, nevents = 0;
Bool drag = xf86SendDragEvents(device);
@@ -1091,7 +1091,7 @@ xf86PostProximityEventP(DeviceIntPtr device,
int is_in,
int first_valuator,
int num_valuators,
- int *valuators)
+ const int *valuators)
{
int i, nevents;
@@ -1137,7 +1137,7 @@ xf86PostButtonEventP(DeviceIntPtr device,
int is_down,
int first_valuator,
int num_valuators,
- int *valuators)
+ const int *valuators)
{
int i = 0, nevents = 0;
int flags = 0;
@@ -1202,7 +1202,7 @@ xf86PostKeyEventP(DeviceIntPtr device,
int is_absolute,
int first_valuator,
int num_valuators,
- int *valuators)
+ const int *valuators)
{
int i = 0, nevents = 0;
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 20a3f1b..d8e69cf 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -164,23 +164,23 @@ extern _X_EXPORT InputInfoPtr xf86InputDevs;
extern _X_EXPORT void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute,
int first_valuator, int num_valuators, ...);
extern _X_EXPORT void xf86PostMotionEventP(DeviceIntPtr device, int is_absolute,
- int first_valuator, int num_valuators, int *valuators);
+ int first_valuator, int num_valuators, const int *valuators);
extern _X_EXPORT void xf86PostProximityEvent(DeviceIntPtr device, int is_in,
int first_valuator, int num_valuators, ...);
extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in, int first_valuator,
- int num_valuators, int *valuators);
+ int num_valuators, const int *valuators);
extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, int button,
int is_down, int first_valuator, int num_valuators,
...);
extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute, int button,
int is_down, int first_valuator, int num_valuators,
- int *valuators);
+ const int *valuators);
extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down,
int is_absolute, int first_valuator, int num_valuators,
...);
extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device, unsigned int key_code, int is_down,
int is_absolute, int first_valuator, int num_valuators,
- int *valuators);
+ const int *valuators);
extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code,
int is_down);
extern _X_EXPORT int xf86ActivateDevice(LocalDevicePtr local);
diff --git a/include/input.h b/include/input.h
index 55b1537..fd7f210 100644
--- a/include/input.h
+++ b/include/input.h
@@ -447,7 +447,7 @@ extern _X_EXPORT int GetPointerEvents(
int flags,
int first_valuator,
int num_valuators,
- int *valuators);
+ const int *valuators);
extern _X_EXPORT int GetKeyboardEvents(
EventListPtr events,
@@ -462,7 +462,7 @@ extern int GetKeyboardValuatorEvents(
int key_code,
int first_valuator,
int num_valuator,
- int *valuators);
+ const int *valuators);
extern int GetProximityEvents(
EventListPtr events,
@@ -470,7 +470,7 @@ extern int GetProximityEvents(
int type,
int first_valuator,
int num_valuators,
- int *valuators);
+ const int *valuators);
extern void PostSyntheticMotion(
DeviceIntPtr pDev,
--
1.7.2
More information about the xorg-devel
mailing list