diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-09-30 10:59:47 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-10-18 09:15:54 +1000 |
commit | 82c60232c07f50774ccc0198950f64c9338057a5 (patch) | |
tree | 91f77e7fe8f80b6047c4bcb3f24fc529754f154c | |
parent | fb84be47db7cdaff406792c08e34670e8e0cbda9 (diff) |
dix: add valuator_mask_fetch_double()
Using this call simplifies callers that don't know if the mask bit is set.
Before:
if (valuator_mask_isset(mask, valnum))
value = valuator_mask_get_double(mask, valnum));
else
value = someothervalue;
Now:
if (!valuator_mask_fetch_double(mask, valnum, &value))
value = someothervalue;
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r-- | dix/inpututils.c | 36 | ||||
-rw-r--r-- | include/input.h | 4 | ||||
-rw-r--r-- | test/input.c | 15 |
3 files changed, 54 insertions, 1 deletions
diff --git a/dix/inpututils.c b/dix/inpututils.c index eeae2a74f..c27894b81 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -539,6 +539,42 @@ valuator_mask_get(const ValuatorMask *mask, int valuator) } /** + * Set value to the requested valuator. If the mask bit is set for this + * valuator, value contains the requested valuator value and TRUE is + * returned. + * If the mask bit is not set for this valuator, value is unchanged and + * FALSE is returned. + */ +Bool +valuator_mask_fetch_double(const ValuatorMask *mask, int valuator, double *value) +{ + if (valuator_mask_isset(mask, valuator)) + { + *value = valuator_mask_get_double(mask, valuator); + return TRUE; + } else + return FALSE; +} + +/** + * Set value to the requested valuator. If the mask bit is set for this + * valuator, value contains the requested valuator value and TRUE is + * returned. + * If the mask bit is not set for this valuator, value is unchanged and + * FALSE is returned. + */ +Bool +valuator_mask_fetch(const ValuatorMask *mask, int valuator, int *value) +{ + if (valuator_mask_isset(mask, valuator)) + { + *value = valuator_mask_get(mask, valuator); + return TRUE; + } else + return FALSE; +} + +/** * Remove the valuator from the mask. */ void diff --git a/include/input.h b/include/input.h index b7de5ca3d..a1930bb66 100644 --- a/include/input.h +++ b/include/input.h @@ -597,6 +597,10 @@ extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest, extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum); extern _X_EXPORT double valuator_mask_get_double(const ValuatorMask *mask, int valnum); +extern _X_EXPORT Bool valuator_mask_fetch(const ValuatorMask *mask, + int valnum, int *val); +extern _X_EXPORT Bool valuator_mask_fetch_double(const ValuatorMask *mask, + int valnum, double *val); /* InputOption handling interface */ extern _X_EXPORT InputOption* input_option_new(InputOption *list, const char *key, const char *value); diff --git a/test/input.c b/test/input.c index afc4d4d99..5fb9a90a2 100644 --- a/test/input.c +++ b/test/input.c @@ -1199,14 +1199,19 @@ static void dix_input_valuator_masks(void) assert(valuator_mask_num_valuators(mask) == num_vals); for (i = 0; i < nvaluators; i++) { + double val; if (i < first_val || i >= first_val + num_vals) + { assert(!valuator_mask_isset(mask, i)); - else + assert(!valuator_mask_fetch_double(mask, i, &val)); + } else { assert(valuator_mask_isset(mask, i)); assert(valuator_mask_get(mask, i) == val_ranged[i - first_val]); assert(valuator_mask_get_double(mask, i) == val_ranged[i - first_val]); + assert(valuator_mask_fetch_double(mask, i, &val)); + assert(val_ranged[i - first_val] == val); } } @@ -1218,10 +1223,18 @@ static void dix_input_valuator_masks(void) for (i = 0; i < nvaluators; i++) { + double a, b; assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i)); + + if (!valuator_mask_isset(mask, i)) + continue; + assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i)); assert(valuator_mask_get_double(mask, i) == valuator_mask_get_double(copy, i)); + assert(valuator_mask_fetch_double(mask, i, &a)); + assert(valuator_mask_fetch_double(copy, i, &b)); + assert(a == b); } valuator_mask_free(&mask); |