summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2011-03-03 15:06:45 +0000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-09-29 12:24:34 +1000
commit626f487b97c99b48bf1d8c8ef4367a686639c3e6 (patch)
treea52dbf70296dd2c5c0a1b9be582774e2d3cc9831
parent3b7fb0f68dc0d40c968c2cfc9bb74b1d0fb48bc8 (diff)
Input: Make RawDeviceEvent use doubles internally
Change RawDeviceEvent to use doubles for valuators internally, rather than data(_raw) and data(_raw)_frac. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--dix/eventconvert.c13
-rw-r--r--dix/getevents.c20
-rw-r--r--include/eventstr.h6
-rw-r--r--test/xi2/protocol-eventconvert.c14
4 files changed, 22 insertions, 31 deletions
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index fa8ba9ec0..54e902081 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -649,7 +649,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
int vallen, nvals;
int i, len = sizeof(xXIRawEvent);
char *ptr;
- FP3232 *axisval;
+ FP3232 *axisval, *axisval_raw;
nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask));
len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once
@@ -671,16 +671,19 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
ptr = (char*)&raw[1];
axisval = (FP3232*)(ptr + raw->valuators_len * 4);
+ axisval_raw = axisval + nvals;
for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++)
{
if (BitIsOn(ev->valuators.mask, i))
{
SetBit(ptr, i);
- axisval->integral = ev->valuators.data[i];
- axisval->frac = ev->valuators.data_frac[i];
- (axisval + nvals)->integral = ev->valuators.data_raw[i];
- (axisval + nvals)->frac = ev->valuators.data_raw_frac[i];
+ axisval->integral = trunc(ev->valuators.data[i]);
+ axisval->frac = ev->valuators.data[i] - axisval->integral;
+ axisval_raw->integral = trunc(ev->valuators.data_raw[i]);
+ axisval_raw->frac = ev->valuators.data_raw[i] -
+ axisval_raw->integral;
axisval++;
+ axisval_raw++;
}
}
diff --git a/dix/getevents.c b/dix/getevents.c
index ec79fcffe..d04f4125e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -167,20 +167,16 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
}
static void
-set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, int32_t* data,
- int32_t* data_frac)
+set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, double* data)
{
int i;
- double val;
for (i = 0; i < valuator_mask_size(mask); i++)
{
if (valuator_mask_isset(mask, i))
{
SetBit(event->valuators.mask, i);
- val = valuator_mask_get_double(mask, i);
- data[i] = trunc(val);
- data_frac[i] = (val - data[i]) * (1UL << 32);
+ data[i] = valuator_mask_get_double(mask, i);
}
}
}
@@ -950,13 +946,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
valuator_mask_copy(&mask, mask_in);
init_raw(pDev, raw, ms, type, key_code);
- set_raw_valuators(raw, &mask, raw->valuators.data_raw,
- raw->valuators.data_raw_frac);
+ set_raw_valuators(raw, &mask, raw->valuators.data_raw);
clipValuators(pDev, &mask);
- set_raw_valuators(raw, &mask, raw->valuators.data,
- raw->valuators.data_frac);
+ set_raw_valuators(raw, &mask, raw->valuators.data);
event = &events->device_event;
init_device_event(event, pDev, ms);
@@ -1128,8 +1122,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
num_events++;
init_raw(pDev, raw, ms, type, buttons);
- set_raw_valuators(raw, &mask, raw->valuators.data_raw,
- raw->valuators.data_raw_frac);
+ set_raw_valuators(raw, &mask, raw->valuators.data_raw);
}
if (flags & POINTER_ABSOLUTE)
@@ -1163,8 +1156,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
}
if ((flags & POINTER_NORAW) == 0)
- set_raw_valuators(raw, &mask, raw->valuators.data,
- raw->valuators.data_frac);
+ set_raw_valuators(raw, &mask, raw->valuators.data);
positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, scr,
&mask, &screenx, &screeny);
diff --git a/include/eventstr.h b/include/eventstr.h
index ecaeddcb6..0645585a3 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -199,10 +199,8 @@ struct _RawDeviceEvent
} detail;
struct {
uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
- int32_t data[MAX_VALUATORS]; /**< Valuator data */
- int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */
- int32_t data_raw[MAX_VALUATORS]; /**< Valuator data as posted */
- int32_t data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
+ double data[MAX_VALUATORS]; /**< Valuator data */
+ double data_raw[MAX_VALUATORS]; /**< Valuator data as posted */
} valuators;
uint32_t flags; /**< Flags to be copied into the generated event */
};
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 80c47b06f..6df9af0fe 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -93,8 +93,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
value += nvals;
- vi.integral = in->valuators.data[i];
- vi.frac = in->valuators.data_frac[i];
+ vi.integral = trunc(in->valuators.data[i]);
+ vi.frac = in->valuators.data[i] - vi.integral;
vo.integral = value->integral;
vo.frac = value->frac;
@@ -109,8 +109,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
raw_value = value + bits_set;
- vi.integral = in->valuators.data_raw[i];
- vi.frac = in->valuators.data_raw_frac[i];
+ vi.integral = trunc(in->valuators.data_raw[i]);
+ vi.frac = in->valuators.data_raw[i] - vi.integral;
vo.integral = raw_value->integral;
vo.frac = raw_value->frac;
@@ -248,10 +248,8 @@ static void test_convert_XIRawEvent(void)
{
XISetMask(in.valuators.mask, i);
- in.valuators.data[i] = i;
- in.valuators.data_raw[i] = i + 10;
- in.valuators.data_frac[i] = i + 20;
- in.valuators.data_raw_frac[i] = i + 30;
+ in.valuators.data[i] = i + (i * 0.0010);
+ in.valuators.data_raw[i] = (i + 10) + (i * 0.0030);
test_XIRawEvent(&in);
XIClearMask(in.valuators.mask, i);
}