From nobody Mon May 6 19:47:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14939916676041000.2178757682065; Fri, 5 May 2017 06:41:07 -0700 (PDT) Received: from localhost ([::1]:47172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6dTj-0002SC-Sv for importer@patchew.org; Fri, 05 May 2017 09:41:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6dSy-000282-JK for qemu-devel@nongnu.org; Fri, 05 May 2017 09:40:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6dSv-0003TC-GI for qemu-devel@nongnu.org; Fri, 05 May 2017 09:40:16 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33991) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6dSv-0003Sj-6d for qemu-devel@nongnu.org; Fri, 05 May 2017 09:40:13 -0400 Received: by mail-wm0-x242.google.com with SMTP id z129so1436570wmb.1 for ; Fri, 05 May 2017 06:40:13 -0700 (PDT) Received: from tupw.localdomain (pub082136102096.dh-hfc.datazug.ch. [82.136.102.96]) by smtp.gmail.com with ESMTPSA id y55sm1963771edb.12.2017.05.05.06.40.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 May 2017 06:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mehdIMHgCkxCK3HW4ns4SdTZ8Uuiq9ovDd766XeiIaI=; b=tZb0rnIuEeIv9NPjJEouoUuvmKR6a2XAO09qFExX94HlAKpP7+Satmd8qBjTAfq1yZ qTWgzXOpNaGXgZWx53NzbLPUvbqmXqafyi7aDzZurrEELrorg0ilJsHfxfHnh0tiqeJg Mux+F4aj6LyRk9klgRiG7hQG2LEgt1EkR6GsdbmzxNxwV+56e5FjTpWNBlWn84aMrdbW UrHkAW9/kcxAz7gEJ2bPq5j+GBE7YGaxJJZJWT0F6V7c3l/QrqKxY09Xgsg7RTbq2ZfE q/7/nQRrZe+TDBtRtJnLOWquMWO/cl6/LoKk0lRnh8Ukypi0ZPXioz7lRQjXUhIWhDTX qvMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mehdIMHgCkxCK3HW4ns4SdTZ8Uuiq9ovDd766XeiIaI=; b=CBZbVLDb3A3i30mShsI4KeDNwfOzPmRM8u1mB5SyPc37w5VnWQgSSQ2XvQj88xqxFF rJtkPEl0bPsu8fx3DdUrKfoZxB81/1Dp/ZOuvvh51f5jQ9bF3YOnyM5n0jJJkGs4wPdR WG4jixqJpQ5LF81iRjVRv63gV94GapGH4JXhW224ttKhexExNNdOob5b+2hkUznQtlZf eMZuRz9cADAF/x0blUycd8+BYVy2UcZB1K+W5gWiA43WDoc3fdCjcIdwp7Fie90UlJIn MJu/8hZZ3kgDKOTZSKeedUEhATt9GpR6KiGfndQKA6XAp41ZyprTMZr7HEdQRQzHa/x0 UNig== X-Gm-Message-State: AN3rC/7AcfhTXyLEYZDOveE3Zj35tv31DDQVSlZqdsGOyuTspZcz6D6A O+VvRcCVnicVEQ== X-Received: by 10.80.183.100 with SMTP id g91mr33991184ede.86.1493991612041; Fri, 05 May 2017 06:40:12 -0700 (PDT) From: Philippe Voinov To: qemu-devel@nongnu.org Date: Fri, 5 May 2017 15:39:52 +0200 Message-Id: <20170505133952.29885-1-philippevoinov@gmail.com> X-Mailer: git-send-email 2.12.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH] ui: Support non-zero minimum values for absolute input axes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Philippe Voinov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- hw/input/virtio-input-hid.c | 6 ++++-- include/ui/input.h | 11 +++++++---- ui/cocoa.m | 4 ++-- ui/gtk.c | 4 ++-- ui/input.c | 31 ++++++++++++++++++++++--------- ui/sdl.c | 4 ++-- ui/sdl2.c | 4 ++-- ui/spice-input.c | 4 ++-- ui/vnc.c | 4 ++-- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index 3ee0c18..46c0381 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -484,12 +484,14 @@ static struct virtio_input_config virtio_tablet_confi= g[] =3D { .select =3D VIRTIO_INPUT_CFG_ABS_INFO, .subsel =3D ABS_X, .size =3D sizeof(virtio_input_absinfo), - .u.abs.max =3D const_le32(INPUT_EVENT_ABS_SIZE - 1), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), },{ .select =3D VIRTIO_INPUT_CFG_ABS_INFO, .subsel =3D ABS_Y, .size =3D sizeof(virtio_input_absinfo), - .u.abs.max =3D const_le32(INPUT_EVENT_ABS_SIZE - 1), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), }, { /* end of list */ }, }; diff --git a/include/ui/input.h b/include/ui/input.h index d06a12d..3cfd0f3 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -8,7 +8,8 @@ #define INPUT_EVENT_MASK_REL (1<con, INPUT_AXIS_X, p.x, scre= en.width); - qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.he= ight - p.y, screen.height); + qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, 0, s= creen.width); + qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, screen.he= ight - p.y, 0, screen.height); } } else { qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, (int)[event d= eltaX]); diff --git a/ui/gtk.c b/ui/gtk.c index a86848f..0798d97 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -912,9 +912,9 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkE= ventMotion *motion, return TRUE; } qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_X, x, - surface_width(vc->gfx.ds)); + 0, surface_width(vc->gfx.ds)); qemu_input_queue_abs(vc->gfx.dcl.con, INPUT_AXIS_Y, y, - surface_height(vc->gfx.ds)); + 0, surface_height(vc->gfx.ds)); qemu_input_event_sync(); } else if (s->last_set && s->ptr_owner =3D=3D vc) { qemu_input_queue_rel(vc->gfx.dcl.con, INPUT_AXIS_X, x - s->last_x); diff --git a/ui/input.c b/ui/input.c index ed88cda..25e6e31 100644 --- a/ui/input.c +++ b/ui/input.c @@ -164,6 +164,11 @@ void qmp_input_send_event(bool has_device, const char = *device, qemu_input_event_sync(); } =20 +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 =3D evt->u.abs.data; @@ -173,16 +178,16 @@ static void qemu_input_transform_abs_rotate(InputEven= t *evt) move->axis =3D INPUT_AXIS_Y; } else if (move->axis =3D=3D INPUT_AXIS_Y) { move->axis =3D INPUT_AXIS_X; - move->value =3D INPUT_EVENT_ABS_SIZE - 1 - move->value; + move->value =3D qemu_input_transform_invert_abs_value(move->va= lue); } break; case 180: - move->value =3D INPUT_EVENT_ABS_SIZE - 1 - move->value; + move->value =3D qemu_input_transform_invert_abs_value(move->value); break; case 270: if (move->axis =3D=3D INPUT_AXIS_X) { move->axis =3D INPUT_AXIS_Y; - move->value =3D INPUT_EVENT_ABS_SIZE - 1 - move->value; + move->value =3D qemu_input_transform_invert_abs_value(move->va= lue); } else if (move->axis =3D=3D INPUT_AXIS_Y) { move->axis =3D INPUT_AXIS_X; } @@ -455,12 +460,17 @@ bool qemu_input_is_absolute(void) return (s !=3D NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS); } =20 -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 =3D (int64_t)max_in - min_in; + int64_t range_out =3D (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; } =20 InputEvent *qemu_input_event_new_move(InputEventKind kind, @@ -484,10 +494,13 @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis= axis, int value) qapi_free_InputEvent(evt); } =20 -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 =3D qemu_input_scale_axis(value, size, INPUT_EVENT_ABS_SIZE= ); + int scaled =3D qemu_input_scale_axis(value, min_in, max_in, + INPUT_EVENT_ABS_MIN, + INPUT_EVENT_ABS_MAX); evt =3D qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled); qemu_input_event_send(src, evt); qapi_free_InputEvent(evt); diff --git a/ui/sdl.c b/ui/sdl.c index 37c21a0..b35a678 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -490,9 +490,9 @@ static void sdl_send_mouse_event(int dx, int dy, int x,= int y, int state) =20 if (qemu_input_is_absolute()) { qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, x, - real_screen->w); + 0, real_screen->w); qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, y, - real_screen->h); + 0, real_screen->h); } else { if (guest_cursor) { x -=3D guest_x; diff --git a/ui/sdl2.c b/ui/sdl2.c index faf9bdf..21de052 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -298,8 +298,8 @@ static void sdl_send_mouse_event(struct sdl2_console *s= con, int dx, int dy, } } } - qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, max_w= ); - qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, max_h= ); + qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, 0, ma= x_w); + qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, 0, ma= x_h); } else { if (guest_cursor) { x -=3D guest_x; diff --git a/ui/spice-input.c b/ui/spice-input.c index 8eeebdb..86293dd 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -172,8 +172,8 @@ static void tablet_position(SpiceTabletInstance* sin, i= nt x, int y, QemuSpicePointer *pointer =3D container_of(sin, QemuSpicePointer, tabl= et); =20 spice_update_buttons(pointer, 0, buttons_state); - qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, pointer->width); - qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, pointer->height); + qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, 0, pointer->width); + qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, 0, pointer->height); qemu_input_event_sync(); } =20 diff --git a/ui/vnc.c b/ui/vnc.c index 349cfc9..60d358f 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1556,8 +1556,8 @@ static void pointer_event(VncState *vs, int button_ma= sk, int x, int y) } =20 if (vs->absolute) { - qemu_input_queue_abs(con, INPUT_AXIS_X, x, width); - qemu_input_queue_abs(con, INPUT_AXIS_Y, y, height); + qemu_input_queue_abs(con, INPUT_AXIS_X, x, 0, width); + qemu_input_queue_abs(con, INPUT_AXIS_Y, y, 0, height); } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { qemu_input_queue_rel(con, INPUT_AXIS_X, x - 0x7FFF); qemu_input_queue_rel(con, INPUT_AXIS_Y, y - 0x7FFF); --=20 2.12.2