aboutsummaryrefslogtreecommitdiff
path: root/ui/input.c
diff options
context:
space:
mode:
authorPhilippe Voinov <philippevoinov@gmail.com>2017-05-05 15:39:52 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-05-11 09:42:16 +0200
commit9cfa7ab939f27ffca845ffb9a28c3fa1856c92e7 (patch)
treeca01d59a8b973d15eccc8521cd480dd98497f680 /ui/input.c
parent76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb (diff)
ui: Support non-zero minimum values for absolute input axes
This patch refactors ui/input.c to support absolute axis minimum values other than 0. All dependent calls to qemu_input_queue_abs have been updated to explicitly supply 0 as the axis minimum value. Signed-off-by: Philippe Voinov <philippevoinov@gmail.com> Message-id: 20170505133952.29885-1-philippevoinov@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui/input.c')
-rw-r--r--ui/input.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/ui/input.c b/ui/input.c
index 830f912f99..290ca9f54d 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -166,6 +166,11 @@ void qmp_input_send_event(bool has_device, const char *device,
qemu_input_event_sync();
}
+static int qemu_input_transform_invert_abs_value(int value)
+{
+ return (int64_t)INPUT_EVENT_ABS_MAX - value + INPUT_EVENT_ABS_MIN;
+}
+
static void qemu_input_transform_abs_rotate(InputEvent *evt)
{
InputMoveEvent *move = evt->u.abs.data;
@@ -175,16 +180,16 @@ static void qemu_input_transform_abs_rotate(InputEvent *evt)
move->axis = INPUT_AXIS_Y;
} else if (move->axis == INPUT_AXIS_Y) {
move->axis = INPUT_AXIS_X;
- move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value;
+ move->value = qemu_input_transform_invert_abs_value(move->value);
}
break;
case 180:
- move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value;
+ move->value = qemu_input_transform_invert_abs_value(move->value);
break;
case 270:
if (move->axis == INPUT_AXIS_X) {
move->axis = INPUT_AXIS_Y;
- move->value = INPUT_EVENT_ABS_SIZE - 1 - move->value;
+ move->value = qemu_input_transform_invert_abs_value(move->value);
} else if (move->axis == INPUT_AXIS_Y) {
move->axis = INPUT_AXIS_X;
}
@@ -467,12 +472,17 @@ bool qemu_input_is_absolute(void)
return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
}
-int qemu_input_scale_axis(int value, int size_in, int size_out)
+int qemu_input_scale_axis(int value,
+ int min_in, int max_in,
+ int min_out, int max_out)
{
- if (size_in < 2) {
- return size_out / 2;
+ int64_t range_in = (int64_t)max_in - min_in;
+ int64_t range_out = (int64_t)max_out - min_out;
+
+ if (range_in < 1) {
+ return min_out + range_out / 2;
}
- return (int64_t)value * (size_out - 1) / (size_in - 1);
+ return ((int64_t)value - min_in) * range_out / range_in + min_out;
}
InputEvent *qemu_input_event_new_move(InputEventKind kind,
@@ -496,10 +506,13 @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value)
qapi_free_InputEvent(evt);
}
-void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size)
+void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value,
+ int min_in, int max_in)
{
InputEvent *evt;
- int scaled = qemu_input_scale_axis(value, size, INPUT_EVENT_ABS_SIZE);
+ int scaled = qemu_input_scale_axis(value, min_in, max_in,
+ INPUT_EVENT_ABS_MIN,
+ INPUT_EVENT_ABS_MAX);
evt = qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled);
qemu_input_event_send(src, evt);
qapi_free_InputEvent(evt);