From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130224; cv=none; d=zohomail.com; s=zohoarc; b=SHBBqXp5norM37LmrOegmBgMQzxevuLzamrO24EUYgdPvLluJmn4A3rKRxx4CKxn3Y0e16O0DhEDi9nRppnnED+/wQKrgbAUVG9jADVxUjp7WjR+3oDVNHWxMFeHS6HrIZd0G9j451yAWwdeErMkHtkWB1sQUxRbfIphQlZXOOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130224; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A+jCT1srzkiU114lsj7BnmbRqKFkNb+yMqW70UM/kqc=; b=GW1bmA/ObnqgTdwbhwaJuwXKDwqWOrmGFRkKvZyAmz0/xwIuuRZn2LP7zfRSEPHR8LfBtJQYHfF32iirFKfYgVWzVIxcOyPrLCZBEXSUYwupVk8/anaEzUosZ05/Dc830QWn3Dc5rfERFgKyCV5xEHPRS1W9/4czb8hYQcHhGzc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130224020665.2208313296182; Tue, 27 Oct 2026 12:43:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn4p-0006lg-He; Tue, 27 Oct 2026 15:43:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn4i-0006lB-GM for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:12 -0400 Received: from mail-dy2-x0b.google.com ([2607:f8b0:4864:36::b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn4g-0003rw-84 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:12 -0400 Received: by mail-dy2-x0b.google.com with SMTP id 5a478bee46e88-3535a54c09bso162528eec.0 for ; Tue, 27 Oct 2026 12:43:09 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130189; x=1793734989; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A+jCT1srzkiU114lsj7BnmbRqKFkNb+yMqW70UM/kqc=; b=w0hBJ39zldRcx6YkBu72GjUVjKk5CS76MMx+h0HaDx7oBBE1GrOjBje+mgYoQ2UYO8 QbWDkxdngRVUmvpQlkNcQaYdiQT6M6pF4ds4/1Ti//fftqCWVOZpDaDxaEWegPDGwiud 9tti4CYxFuNlvAg4JjLT2y0puku9D1gn60DXMNgIg0iYaFacGQgOpVxanJ1VRCzAGy1g hTccj3y2Bpg+o5wAlBED+STnJWLnS6E874Yu0Tncz/5vGsZvzq49trgX+FwFrWy0w1H8 v6gRGO0QU8FVkM4azv7u0w6ihnaSgV5THHAqKJEFd0g0xfBgT6+rmQzMArubjI5D5BxO Lcug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130189; x=1793734989; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A+jCT1srzkiU114lsj7BnmbRqKFkNb+yMqW70UM/kqc=; b=zU2dcuxUV9EUqCjFnMNSw1WisewrWR3Edtxy7U+3z7gpmVzXnTwe5XpJDg2MUUnTzA m+altyG+jyO7aMhRg99+diH7eYfahRxt1+0gXc1u3yMM/zDQZ8xBOQ79TVd2dw4RnW5n jqiLuhI7Bqyl3z2+179xjHnS3ChqywWwNRaOpSajvNPK4ov1XzCBL2Aha/yEhcXAwkSC FPxM93ee+ILYyd+x0OUV6ZUB66djbUIBJC9tMz+IBlh6JStkMiyJGbGp1JBzZDs0sKDf mWaWkZ0KnwMMICR6BwAxbwEQTNnyX/44U0K7dYhU6JY5++ucHeD1RYHzN51lNg0pnKk5 jRrA== X-Forwarded-Encrypted: i=1; AKwUvBx0l71qLE3goP/lNGAmxsDR78+ydsPO9Y3Si6dL9Juzxt79F4KIe5LUjJzukY4B8IDA/ZMZDh7u+y8P@nongnu.org X-Gm-Message-State: AFq9FYJb0Ycel6plilQGKIq7rL/lzydYNAQLFUTdFb7xHRdUCXtrlbqF K0v2gPfwbDwkYQYB1bAum4mg1V1CyeEPpiAPO1Hrmlf4aJ0QgqrAm+uO X-Gm-Gg: AYBFou1noBeWabysbPw42RScBAjKSJG8jaE0IsikQdmzUg+wb5XG3r3ojcaHHEtWvTK QaN59j+NZp1lfNHH5kQecuHDtfk9mDprn0RGzbyL4zTr6sys0xumR8gN/T1GmP3KZEVAxqzQGxl I/7VhKdJsUTCiGaL+grE/eaaPdcPSijuvPZfBIvuntRwSGboyq/7RLZtELyfrftP8t9WYkWdpft GRnrikGkugNP3al9uE/pzGeYv89HMq/ih8Lxx3pHbjULqVAYsPhV/+d05u33+mu79hxtp4SH93t KVW1nZX/MT4Of4oQSjAJ+wzVxBVQKlvTMKb8BAjynUgWsIPrb3N28unnsrsUq3bw6mBTXmJ25O5 cjqoO/+5O21Px5AMj6eve0qg6jnaI1Q9yrfe6g2sd6OuoXctq1Z/wRZe85LaM+dQfT1ErjC+W3h vQ95pJW8uTC6Ti0UBKjaKeEoYYJGPggH+HvFRL1uoEB2doSM9xPD5VCGu1H0SivKuQIeFh5wK7p fmq7jdHQ155x+DK/EZoMfpt4cjbwq+HMKYAHaRiBYd7sW2ryv3IqLAtWG2z6k1UG5z3jcS1nx6e WEdZPY78eUyPLZorB/I0Wm52Tnlf1mm0Ioay8uzQcpFhpuevrt0WvacQOoaG53OBd/WyE3erIeE DsRp+lCt8JpOMFPisdeZKyeYb2NffzfgSctfewI4+573wI4KuTQ== X-Received: by 2002:a05:7300:b196:b0:36a:30b:5dc0 with SMTP id 5a478bee46e88-36a203bb12amr539789eec.24.1793130188467; Tue, 27 Oct 2026 12:43:08 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 1/8] ui/input: add high-resolution scroll input event Date: Wed, 28 Oct 2026 01:12:49 +0530 Message-ID: <20261027194256.76031-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::b; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x0b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130224926158500 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar The input layer can only describe wheel movement as WHEEL_UP/DOWN/ LEFT/RIGHT button clicks, one per detent. Host UIs that receive smooth scroll deltas (touchpads, free-spinning or high-resolution wheels) have to round them to whole clicks and the guest never sees the finer movement. Add a new 'scroll' input event kind carrying a scroll axis (vertical or horizontal) and a distance in 1/120 of a wheel detent, the same unit Windows uses for WHEEL_DELTA and Linux for REL_WHEEL_HI_RES. Positive values scroll down or right. Scroll events are routed to the handler that receives pointer button events for the console. Handlers that do not set INPUT_EVENT_MASK_SCROLL keep working unchanged: the input core accumulates the distance and emits one wheel button click per full detent. Also wire the new event into input-send-event, tracing and record/replay. Signed-off-by: Soumyajyotii Ssarkar --- include/ui/input.h | 6 ++++ qapi/ui.json | 45 ++++++++++++++++++++++-- replay/replay-input.c | 8 +++++ ui/input.c | 82 ++++++++++++++++++++++++++++++++++++++++++- ui/trace-events | 1 + 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/include/ui/input.h b/include/ui/input.h index a1560cac0f..daedb547ff 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -9,6 +9,9 @@ #define INPUT_EVENT_MASK_REL (1<mtt.axis); replay_put_qword(evt->mtt.value); break; + case INPUT_EVENT_KIND_SCROLL: + replay_put_dword(evt->scroll.axis); + replay_put_qword(evt->scroll.value); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; @@ -80,6 +84,10 @@ QemuInputEvent *replay_read_input_event(void) evt->mtt.axis =3D (InputAxis)replay_get_dword(); evt->mtt.value =3D replay_get_qword(); break; + case INPUT_EVENT_KIND_SCROLL: + evt->scroll.axis =3D (InputScrollAxis)replay_get_dword(); + evt->scroll.value =3D replay_get_qword(); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; diff --git a/ui/input.c b/ui/input.c index f40a988370..f9ae49e275 100644 --- a/ui/input.c +++ b/ui/input.c @@ -181,7 +181,12 @@ void qmp_input_send_event(const char *device, for (e =3D events; e !=3D NULL; e =3D e->next) { InputEvent *event =3D e->value; =20 - if (!qemu_input_find_handler(1 << event->type, con)) { + uint32_t mask =3D 1 << event->type; + + if (event->type =3D=3D INPUT_EVENT_KIND_SCROLL) { + mask |=3D INPUT_EVENT_MASK_BTN; + } + if (!qemu_input_find_handler(mask, con)) { error_setg(errp, "Input handler not found for " "event type %s", InputEventKind_str(event->type)); @@ -217,6 +222,10 @@ void qmp_input_send_event(const char *device, evt.mtt =3D *qapi->u.mtt.data; break; =20 + case INPUT_EVENT_KIND_SCROLL: + evt.scroll =3D *qapi->u.scroll.data; + break; + default: g_assert_not_reached(); } @@ -235,6 +244,7 @@ static void qemu_input_event_trace(QemuConsole *src, Qe= muInputEvent *evt) InputBtnEvent *btn; InputMoveEvent *move; InputMultiTouchEvent *mtt; + InputScrollEvent *scroll; =20 if (src) { idx =3D qemu_console_get_index(src); @@ -265,6 +275,12 @@ static void qemu_input_event_trace(QemuConsole *src, Q= emuInputEvent *evt) name =3D mtt->axis < INPUT_AXIS__MAX ? InputAxis_str(mtt->axis) : = "invalid"; trace_input_event_mtt(idx, name, mtt->value); break; + case INPUT_EVENT_KIND_SCROLL: + scroll =3D &evt->scroll; + name =3D scroll->axis < INPUT_SCROLL_AXIS__MAX ? + InputScrollAxis_str(scroll->axis) : "invalid"; + trace_input_event_scroll(idx, name, scroll->value); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; @@ -342,12 +358,62 @@ static void qemu_input_queue_sync(QemuInputEventQueue= Head *queue) queue_count++; } =20 +static void qemu_input_scroll_to_btn(QemuInputHandlerState *s, + QemuConsole *src, QemuInputEvent *evt) +{ + static int residual[INPUT_SCROLL_AXIS__MAX]; + QemuInputEvent btn =3D { .type =3D INPUT_EVENT_KIND_BTN }; + InputScrollAxis axis =3D evt->scroll.axis; + + if (axis >=3D INPUT_SCROLL_AXIS__MAX) { + return; + } + + residual[axis] +=3D evt->scroll.value; + while (abs(residual[axis]) >=3D INPUT_EVENT_SCROLL_DETENT) { + bool fwd =3D residual[axis] > 0; + + if (axis =3D=3D INPUT_SCROLL_AXIS_VERTICAL) { + btn.btn.button =3D fwd ? INPUT_BUTTON_WHEEL_DOWN + : INPUT_BUTTON_WHEEL_UP; + } else { + btn.btn.button =3D fwd ? INPUT_BUTTON_WHEEL_RIGHT + : INPUT_BUTTON_WHEEL_LEFT; + } + residual[axis] -=3D fwd ? INPUT_EVENT_SCROLL_DETENT + : -INPUT_EVENT_SCROLL_DETENT; + + btn.btn.down =3D true; + qemu_input_event_trace(src, &btn); + s->handler->event(s->dev, src, &btn); + btn.btn.down =3D false; + qemu_input_event_trace(src, &btn); + s->handler->event(s->dev, src, &btn); + s->events++; + } +} + void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt) { QemuInputHandlerState *s; =20 qemu_input_event_trace(src, evt); =20 + if (evt->type =3D=3D INPUT_EVENT_KIND_SCROLL) { + s =3D qemu_input_find_handler(INPUT_EVENT_MASK_BTN | + INPUT_EVENT_MASK_SCROLL, src); + if (!s) { + return; + } + if (s->handler->mask & INPUT_EVENT_MASK_SCROLL) { + s->handler->event(s->dev, src, evt); + s->events++; + } else { + qemu_input_scroll_to_btn(s, src, evt); + } + return; + } + /* send event */ s =3D qemu_input_find_handler(1 << evt->type, src); if (!s) { @@ -518,6 +584,20 @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis = axis, int value) qemu_input_event_send(src, &evt); } =20 +void qemu_input_queue_scroll(QemuConsole *src, InputScrollAxis axis, + int value) +{ + QemuInputEvent evt =3D { + .type =3D INPUT_EVENT_KIND_SCROLL, + .scroll =3D { + .axis =3D axis, + .value =3D value, + }, + }; + + qemu_input_event_send(src, &evt); +} + void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int min_in, int max_in) { diff --git a/ui/trace-events b/ui/trace-events index 339a61f341..638096607a 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -132,6 +132,7 @@ input_event_btn(int conidx, const char *btn, bool down)= "con %d, button %s, down input_event_rel(int conidx, const char *axis, int value) "con %d, axis %s,= value %d" input_event_abs(int conidx, const char *axis, int value) "con %d, axis %s,= value 0x%x" input_event_mtt(int conidx, const char *axis, int value) "con %d, axis %s,= value 0x%x" +input_event_scroll(int conidx, const char *axis, int value) "con %d, axis = %s, value %d" input_event_sync(void) "" =20 # sdl2-input.c --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130223; cv=none; d=zohomail.com; s=zohoarc; b=dvaClPzYsQtf4KufK09lGzUQfkWWdZtx4vkyRwgQYljFesjWAhQQJU5ioHaBrN3BDTPKknFJISBjtnmC5LvpyZ6o6/9NzK43mou8GbX/RqkxlJdC6Nzw01Vp2bPxJFm5jQtDkBn+sE2fAqhz5Sviji+TnRp4+RDkCe96lUxT3Ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130223; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0xdUelrc8I+7zBA0sQy4UOI4d0EQ/9eh6GrStrVCQ10=; b=gz3nmTnyKfZKxMAEMWr98M7VkPqAu2p5NnF7/SJsVjbMLWD4b3i7FZkdJxWMRCqEJty96XjrilxSiMbHvwG+kZ9wvtunZvUPMSpQilMp5dMcorhdJ2maS6SawNkxPzOLf4Wr8iBFTyk/c4UXFMF7ByMW9RP0pnuR25IIYsBoJZQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130223610710.7000493979206; Tue, 27 Oct 2026 12:43:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn4t-0006nD-Kl; Tue, 27 Oct 2026 15:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn4o-0006m3-Uu for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:19 -0400 Received: from mail-dy2-x09.google.com ([2607:f8b0:4864:36::9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn4m-0003sM-3A for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:17 -0400 Received: by mail-dy2-x09.google.com with SMTP id 5a478bee46e88-35adc681e1aso369477eec.0 for ; Tue, 27 Oct 2026 12:43:14 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130193; x=1793734993; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0xdUelrc8I+7zBA0sQy4UOI4d0EQ/9eh6GrStrVCQ10=; b=LL9oC5mJju1Fj2vaqXXg8a8BI7a3jA+ZOjoonUHpcYAjU3ftziE5gYY6Khz6powAw9 6ibZce700Qtn8sZY0OXV+7vFUZI7C0Gev33afEe4s/64rGbjpt/yAKIQy5vphQUwalXs Ax3/Ij9BY3rEnAYtI/ELoB7zGMyxxOi+vWHbYoNlHLAxhyXs+VD9mJ12K6BS3aBqvnfu ajsT+QTa1+FN8uQ3c00rQNAPiYqS9v+6dBCGGXmZXgdceiWO/db9vZKFrOotbKd0Y9Fb Br+KRxIwQm4KyY1AnB6X3jOQCgkHSL0/i9ZBeMOa31FNJ8+nhCBcBT76pm4nPvbHXb7Q mVFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130193; x=1793734993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=0xdUelrc8I+7zBA0sQy4UOI4d0EQ/9eh6GrStrVCQ10=; b=O51w2fEaViDhJiXbiga2vuqMtxZy2K8tHRsq/h05+DdfdOLSFG7hg1sdaT7UpqWKPK 55iu7yCYzn2DINRqqpyLKcS79LpuWEAOQgvGMLy0zkeAKZbpfzQmDjo1F0kuDyxEhwMy 4g1XTCl0k0Dq/e7PwQdM5Qvovj+6h82zC3eBJJEgSKXsnPL+/zXwgPX1V5p5SUSxYqMS yONZd2kfY/wVOyWeF5unzm7PHvoyYr95P5Iz/ki5X5Oof+KZNuQYtyReceSQMvgMksor E/wAfPcp4H2UI19uTrvcXEsNFE+izoN4y6QJ9EZNHs0MhlmNfv/Iotdx/+WOl132OEgs ivwg== X-Forwarded-Encrypted: i=1; AKwUvBwQM/fqi+spCGgKKSnLuHeVprgJt4HWsk71J123/rTQvFdCDvx7m7lWppK5Bpl+SaL8T6+C6888jUk2@nongnu.org X-Gm-Message-State: AFq9FYI4Z+3rN3NagdCawWthCRGUUlCVU5ItSsZhzQJta1NKwEN3wMHP YeDwsdt4zP0VSdGO6dxlJNHIy0syQwB9zUBL4iTL4NIu2sF4aD9E2mBR X-Gm-Gg: AYBFou01PeWzGvACbaoHRX+TfYFqO0Atf72cp4NJPfHYJAzEatPBGbri98LXES+RZch ROJ3w2IOKmOmaBK6eIckDBgTculQFkiKD+1I9vwnaHOF12qCL96Prb9m8goZqYAY8tELESicKvE wDVIooBu0Gz8sGlYGaXYGLvGGq7nJePTUoJ204D0MLybERSc1QKsgskhzWXXojkx5WRBdjwNQ+L N29ebEdCQsL19vmGacasxAWpe3ClFNtAJEOiIKVagT2Nwwxb29RXG3oSMniFW4JrAALfp1ekujH NxslFPeO83ijohf6sNh3J16UIvkzqav5jCwegQrpti9brjEDRYYaa1ITXqW1LJBphOp/gyO39+n Mo6mlD+1IvhV39IJTx+Lx5q8iI7Bz0OKK8lfuU5X9KffV2FM+T7ligRe/XeyXXjfoHbNL71Ch36 5+uw8siKLE/2zfjStpO+D2sLE3sKhHRghKTUeWv8P526GHSEewI48N+9A2o8nPN+jP9Xkdvz5hA ClFw/GuuexZvvnCrAx0HXPfTTybBBrVelhQWUmt976ODzue/6MXYMWFJTo0Lo/F3xncc6NQOOAi myjybCxIYiYaul7k8X+cCa5Zhn/vv8mDoZ/IAXKu+nNBrSI6h2EQAnll2N+hwhxL8qS/y8Ohn/2 oMJK/U2nLQi2afdjG3xrkEYqnr1ThmbVUrpTbK6akHOrBzLO2Dw== X-Received: by 2002:a05:693c:4008:b0:369:9af5:7bcc with SMTP id 5a478bee46e88-36a203ac768mr616302eec.8.1793130192904; Tue, 27 Oct 2026 12:43:12 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 2/8] ui/gtk: forward smooth scroll deltas as high-resolution scroll events Date: Wed, 28 Oct 2026 01:12:50 +0530 Message-ID: <20261027194256.76031-3-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::9; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x09.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130227305154101 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar For GDK_SCROLL_SMOOTH events gd_scroll_event() only looked at the sign of the deltas and sent a single wheel button click, so any amount of scrolling became one detent. It also dropped the horizontal delta whenever there was vertical movement. Convert the deltas, which GDK reports in detents, into 1/120 detent units and send them as scroll events on both axes. Fractions are carried over to the next event so slow scrolling is not lost. Discrete GDK_SCROLL_UP/DOWN/LEFT/RIGHT events still send button clicks. Signed-off-by: Soumyajyotii Ssarkar --- ui/gtk.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 8d312d6a4b..9df83b6225 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1152,27 +1152,33 @@ static gboolean gd_scroll_event(GtkWidget *widget, = GdkEventScroll *scroll, btn_horizontal =3D INPUT_BUTTON_WHEEL_RIGHT; has_horizontal =3D true; } else if (scroll->direction =3D=3D GDK_SCROLL_SMOOTH) { + static double residual_x, residual_y; gdouble delta_x, delta_y; + int units; + if (!gdk_event_get_scroll_deltas((GdkEvent *)scroll, &delta_x, &delta_y)) { return TRUE; } =20 - if (delta_y > 0) { - btn_vertical =3D INPUT_BUTTON_WHEEL_DOWN; - has_vertical =3D true; - } else if (delta_y < 0) { - btn_vertical =3D INPUT_BUTTON_WHEEL_UP; - has_vertical =3D true; - } else if (delta_x > 0) { - btn_horizontal =3D INPUT_BUTTON_WHEEL_RIGHT; - has_horizontal =3D true; - } else if (delta_x < 0) { - btn_horizontal =3D INPUT_BUTTON_WHEEL_LEFT; - has_horizontal =3D true; - } else { - return TRUE; + residual_y +=3D delta_y * INPUT_EVENT_SCROLL_DETENT; + units =3D (int)residual_y; + residual_y -=3D units; + if (units) { + qemu_input_queue_scroll(vc->gfx.dcl.con, + INPUT_SCROLL_AXIS_VERTICAL, units); + } + + residual_x +=3D delta_x * INPUT_EVENT_SCROLL_DETENT; + units =3D (int)residual_x; + residual_x -=3D units; + if (units) { + qemu_input_queue_scroll(vc->gfx.dcl.con, + INPUT_SCROLL_AXIS_HORIZONTAL, units); } + + qemu_input_event_sync(); + return TRUE; } else { return TRUE; } --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130225; cv=none; d=zohomail.com; s=zohoarc; b=KZu8b4zshJuY9ToOdqA9idWfz4L6QWVFdD7oN9u0GYjX33ToMtMtrWeh9SPAJBszXzpZnod3llAJTC/to6TEzKKRJi8YlVeMgQEXQhCpIx2luCMcmTjnWItyGEvyyrKWujJwombBIJf372BIKC+NqWiwXGfl97FMmgRauUCJc28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130225; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zILaURUC9gi1c0UUUvY3rQWxg5TmKzPKSbRxjgbExNQ=; b=GeW/pI9B3fL/N2+pucTeHVnb+zSha8JDwXT012u3cOjWX6ZUPe93VFQ+O0LJr6w6VkJqyg6gWBRXEoguGxN4+fb7QqVbdN237ikKp3Ibv+SlKEZWnNee4YOVPtR6iqVZP6MF+SQnAEZdtrxDD3psUSqCpJ36yqHnIvu8JBZvMk4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130225574464.33718421254537; Tue, 27 Oct 2026 12:43:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn4y-0006oc-OG; Tue, 27 Oct 2026 15:43:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn4r-0006mm-4G for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:22 -0400 Received: from mail-dy2-x0a.google.com ([2607:f8b0:4864:36::a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn4p-0003sp-Gx for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:20 -0400 Received: by mail-dy2-x0a.google.com with SMTP id 5a478bee46e88-33e48934fa8so62492eec.0 for ; Tue, 27 Oct 2026 12:43:19 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130198; x=1793734998; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zILaURUC9gi1c0UUUvY3rQWxg5TmKzPKSbRxjgbExNQ=; b=m5wkq31OfpzQ/4OVf3aI+n96fPdAEEwhSmi+tw/qLpxLuVxJq523jADphBQyo6dsA+ VukoqgZfxsw5T1lUaZb/9oDCIl3y94uHE/s34sjLQQ0mlqJc1W1I6wF2S5GfASK0JIol O8RYPy2mCKuwHt4TpaHcV3OpP3cQxSuNlTnKIdrRKDiIluj4E+s1TkpVAUOa8R5FBqly L4lbBVtEj2MV/fzaHgc+jzs3FmLk+aD4bSXmmvc2BMyB9VGw8HTsT9fq8lkhWc0tJqnT TWyMINa2HYSfKzkK/S9dFTREE3EPoF1urjr+qMrVeBcYnGKLKU5AodtZUxA0fpjFk/TJ EfFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130198; x=1793734998; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zILaURUC9gi1c0UUUvY3rQWxg5TmKzPKSbRxjgbExNQ=; b=P52kMmOegiUBJIBzgJhGXMAxDqd41ytM2IdR1MTiLGpTra+Wd9P89P9cDf6amKGfFW reMav5n0H0MNTA0w1tLkhVIh6/Op0bOS51gbnnW39G4IacQr6AF8HkVLNVgmB+rwsF5P k/F6B/0esni8k0tICEmjAm9LoAjQU88IjmGkR3sDz8xHVmfZTi/tYlF4TI6Crg9BoIGz GFp6oFwbqHMT51h/bDqrq/MPt8tNs/wcuA66MA5t/4/vLVjQsPJT6U/QBtQY767u4ssB sc0IHPElGwsqavdi2VNKOLzy0kLx7vhiHPEpogrjQ440L0ytiHnji+pyqG6V+ITr4xH9 p9nA== X-Forwarded-Encrypted: i=1; AKwUvBxOvzYa10K7FWaY54P0xScGBVwCCiB4BL3EGsajfWuDfLaJNYBaMk38Bt0QiPyIf1NdK6QqoENagABy@nongnu.org X-Gm-Message-State: AFq9FYJLALx1+s2NOl/n5LkrNH5I7z+hLQ+m1QC6nTavh8teomhqDcx7 HvYWL6gjr+4O93J+JX4AYr4axewkdp8MVscgAd3kqf9B6XTtfbe5reXT X-Gm-Gg: AYBFou236h2upFKrno3twjdwsJTgXGqona7+aob/6l4qrxR/LGQ8vPDMQAIErTQOYJW fnWlsmpLiZVN+c2HzcrT6NUB2HVFfpyTZ+SgK6S/ZO8VtryZkRf3UjDpJPrd8zO8VbcGN4MR8g6 affOb655UHPHIBWqs/ims91v4k3ALiMtr6Dl+R+j0Djkjq8Lu5+6iQhqVNWtvQHUViiXUwlWn3u 7aOuQCfi5TrpF8ToCXzy4UoB34xYrfPVgLnxou9AMiTduNTztEdhYsvDvYj75Z6suI2BbtFueX3 tB5TCrsMnkhJvx/0Yjdwg7EyL8RJbijLhlMtvY/Q8TRTkxv7WgAuuYXyjoOGKGuWZfujlqQIzeg CwZHpzdUV0TG9QVltOcXHhwKNZTP8/o4R/2xJWWiK+M9OfMAWFQi4gD03Phct8v6GIIxInNmqvz 4ZWjThEgZRXISH4YVRp6MwV58eOQJWCtccpIaaQdI56C5yf+5jEKzIxF0Yl+jJcmJnT6Jbf0xdX 2wtQ59pkHWzubOsVE01rm2uwWtqHP0xj7f2EngfnIKFPvEMZETukyLM+p4KWw003ACWWdRNpTx9 9Rsy3qOgVcA1gG153C9ccz0nm2OmmlvEsAZ/CxN7MqrAR48f3yQ5p+zTsuIk/n/x/0oaQ1qDqLC qli+7NLKqP2oN1XUbn8JHvWiBsTZtcPSsaPCznAD1jGqS5mSfoteZo4A5wlNOCb9lnpTpJOL3 X-Received: by 2002:a05:693c:894b:10b0:36a:1b23:a1cd with SMTP id 5a478bee46e88-36a20112454mr533988eec.9.1793130197546; Tue, 27 Oct 2026 12:43:17 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 3/8] ui/sdl2: forward precise wheel deltas as high-resolution scroll events Date: Wed, 28 Oct 2026 01:12:51 +0530 Message-ID: <20261027194256.76031-4-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::a; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x0a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130227305154100 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar handle_mousewheel() only looked at the sign of the integer wheel deltas and sent a single wheel button click, so any amount of scrolling became one detent and the horizontal axis was dropped whenever there was vertical movement. SDL 2.0.18 added preciseX and preciseY, which carry the wheel movement in fractions of a detent. When building against SDL 2.0.18 or newer, convert them into 1/120 detent units and send them as scroll events on both axes, carrying fractions over to the next event. The direction follows SDL's convention (positive x scrolls right, positive y scrolls up) and honours SDL_MOUSEWHEEL_FLIPPED. Older SDL versions keep the existing button behaviour. Signed-off-by: Soumyajyotii Ssarkar --- ui/sdl2.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ui/sdl2.c b/ui/sdl2.c index 1c97d23a47..0a052a8f2d 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -566,12 +566,39 @@ static void handle_mousewheel(SDL_Event *ev) { struct sdl2_console *scon =3D get_scon_from_window(ev->wheel.windowID); SDL_MouseWheelEvent *wev =3D &ev->wheel; +#if SDL_VERSION_ATLEAST(2, 0, 18) + static float residual_x, residual_y; + float flip; + int units; +#else InputButton btn; +#endif =20 if (!scon || !qemu_console_is_graphic(scon->dcl.con)) { return; } =20 +#if SDL_VERSION_ATLEAST(2, 0, 18) + flip =3D wev->direction =3D=3D SDL_MOUSEWHEEL_FLIPPED ? -1.0f : 1.0f; + + residual_y -=3D flip * wev->preciseY * INPUT_EVENT_SCROLL_DETENT; + units =3D (int)residual_y; + residual_y -=3D units; + if (units) { + qemu_input_queue_scroll(scon->dcl.con, + INPUT_SCROLL_AXIS_VERTICAL, units); + } + + residual_x +=3D flip * wev->preciseX * INPUT_EVENT_SCROLL_DETENT; + units =3D (int)residual_x; + residual_x -=3D units; + if (units) { + qemu_input_queue_scroll(scon->dcl.con, + INPUT_SCROLL_AXIS_HORIZONTAL, units); + } + + qemu_input_event_sync(); +#else if (wev->y > 0) { btn =3D INPUT_BUTTON_WHEEL_UP; } else if (wev->y < 0) { @@ -588,6 +615,7 @@ static void handle_mousewheel(SDL_Event *ev) qemu_input_event_sync(); qemu_input_queue_btn(scon->dcl.con, btn, false); qemu_input_event_sync(); +#endif } =20 static void handle_windowevent(SDL_Event *ev) --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130238; cv=none; d=zohomail.com; s=zohoarc; b=KlTkkb3qPCGnIQefEgbbzedvh8ibcdzk2M0F37ZVoyeIgDaubF3YDhIKpqk6tReA5CBpgsRyw1gmP9g2th+BR7dgFCvORXWmmj1rVuX+Ah01wqV+dl8XcwggxIwJT9ecjFMnGZx6S7m2iTI1QLjmVGnZ4HyH7hjaTPaAYo4CDxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130238; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MqmKANFmF1KWHkD0zN0BNlsIh1qC7oBV5bQeH+b1K10=; b=Vn/FPg3emBW0hzM75drf/AfAXvPQJ+6KdT/BRqH+thO+QQXZTgWhJxNC4dkw9lvRNc3AzoG+Fs2bNcY1grHzOypEHMnv8OPxXHaNAIp8imGBJXyBM8axLKsGl8VfIVBdFWO4iDJ0FES3Gbv8p6dfcvG7m6k/JMyTq+vm1QU0VtA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179313023878671.97657777174811; Tue, 27 Oct 2026 12:43:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn51-0006p8-Kb; Tue, 27 Oct 2026 15:43:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn4x-0006oW-1z for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:27 -0400 Received: from mail-dy2-x0b.google.com ([2607:f8b0:4864:36::b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn4t-0003tK-TW for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:25 -0400 Received: by mail-dy2-x0b.google.com with SMTP id 5a478bee46e88-36a1e794908so45730eec.1 for ; Tue, 27 Oct 2026 12:43:23 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130202; x=1793735002; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=MqmKANFmF1KWHkD0zN0BNlsIh1qC7oBV5bQeH+b1K10=; b=0oisvVMdCRnSKaT7+BlT7He8mluZRL5wau4rKoE4/mMX9G+e6k4LyNqj2wOYKL3j8Z NQlMU0NFdki45JGDqkyRifToaL2MS5KVH4/WmKJ8FtY4Ni0Ca8bmRHqYdeAIv7zzQu9l asHoHrtiBq6FSb4OJg1UWyqz75uUAN36pZoB9tUUwsVQpmg5ntLfC96q9xKiBN6vPFfk dYyjMB1fRin/Xaw0wDVvf9/l037+Dtnf8lZGepvWP5nU3D3n1R6rUO4KkR9ChLiTcdYk K9s5v9Y1xReuvqdjbhnoUanSV5E6hmSZfSWGsWlHNFz9jcqwkCusVC9D6NFaczwq6GWv KIDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130202; x=1793735002; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MqmKANFmF1KWHkD0zN0BNlsIh1qC7oBV5bQeH+b1K10=; b=0599HysPBaJIzIcVSCAuBZyvb9Y5M1c+Iy0Vs8C3rNd2hqV+vNViH3XmXda16pUBTj fwhSZw/r02Ea0dpyLmyRk6Kas0VHf3Jaw8tEKoqBwDg6EGZ5WA3GFTRqH1rnUsRzu2/c 01KMABdT8d2q67PIrKtXAacI29dsNHoVhpRDh7vxccG0gj/U+0UXGNEePw1RAit2nuze rkCu6evyQQce1Ypm4jWaazQRQ7ff9zQ2/pSjfDJje3Ts1Ctmjf3zXmxrPF9T2oUITzbq oZfbSY9FAbBkQXFgjOFj5xqVNBJb1ZGk8wkXpqaahYCXmhNoQjYRf49JxmAOVI2wvecU kPrw== X-Forwarded-Encrypted: i=1; AKwUvByry4zDd01adyxtPmsDQ/CWk+3Lk84tjuKoFAQAWuxUu1MtH9kP1N5YIUeq7O4wCIA1qnLwyoMDB5M+@nongnu.org X-Gm-Message-State: AFq9FYIEULUUVzbp3Z0l8OoZL8Vft6fLQkCAL85SRoennOUnmDTs4iIg j8veioiz+fTJlViFzcW1rRCF4TIuUiRpd1oqBaFP9PIVpR3AWGzP2Jxc X-Gm-Gg: AYBFou3j8BsUnpi3JG5Xi/fwA5MDZVVe/1DN+qFF6sruY98Iaij2FjO64Ln0ysMHL3Z Xg9b7GJil1ufN8JjWRm0f+z2eFbPQxgqu8TVkm1CjeqaUu7kZaBmYwuvpEEkq/GHV+E9RuwWOqL IKc1UOAIPYb5Ux3EG5BuFp2bkK9nzo8dGeuFdzLAt8RxZb8LWgx90yAFyH/o8MdqNFiQLwsC/x4 aGpmtEGbVksC1sYWKYFgbCqbHUeu9py5YP85LmJ+ZTMmriIlOUBelSRqLPO1HjYF0F3ibuf/tDu lEGre1SS55/wfmQTKeNiVIajDKbjEnBqmWcSWJ1uq9ZEDofje90V22FGRTipuIMLp9t6D1pHtYR rZiQVVqqTvqr38R2OE2PinNwq23b2mlWhvYKR3lQFRdFTXlcrZQfzOYbsqGVvxcPRfchGyOgr58 GfXpPw9rT3c0wxWNOgDp14sDm2w7XT6ouJIgnsWQRkiJMOivFugi+n9Qj+m2Rqoq3NYxGYCnHWf Y1gax9JY8lR6sLUOVf+++TCgcZzUA65klMvw4LrnRgqsXlG4jJOFOTQ1osFQtF+DmhHEbrqspg+ dbcLLpZ1yYkFb1FtRy0iitfszUhPV1OO3DyU4WiwARLy/uE8vzwQNKIDvpezCXvJF/l65vsuBIt DxL1cEahauH4a91gGCZspTUZWivEnRbkT5EWIQXbjFqyaKFcnlCoV3Mjy5wMYECXtBSn/+jO781 Iaxc5oDT+W8PuxkEtevIjQZvw= X-Received: by 2002:a05:7300:d0a5:b0:351:31c7:ab1d with SMTP id 5a478bee46e88-36a200bea37mr557271eec.16.1793130202415; Tue, 27 Oct 2026 12:43:22 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar , Helge Deller Subject: [PATCH v2 4/8] hw/usb/dev-hid: derive the mouse report descriptor length with sizeof() Date: Wed, 28 Oct 2026 01:12:52 +0530 Message-ID: <20261027194256.76031-5-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::b; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x0b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130239869154100 From: Soumyajyotii Ssarkar The HID class descriptors of the mouse interfaces carry the length of the report descriptor as a hard-coded 52. Any change to the report descriptor then has to update both copies by hand, and Windows stops recognising the mouse if the advertised length does not match the descriptor exactly. Move qemu_mouse_hid_report_descriptor above the interface descriptors and compute the length with sizeof().=20 No functional change. Suggested-by: Alex Benn=C3=A9e Suggested-by: Helge Deller Signed-off-by: Soumyajyotii Ssarkar --- hw/usb/dev-hid.c | 74 +++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index ae19d60203..2c10e88c85 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -76,6 +76,42 @@ static const USBDescStrings desc_strings =3D { [STR_SERIAL_KEYBOARD] =3D "68284", }; =20 +/* + * The interface descriptors below advertise the length of this report + * descriptor. + * Note: Windows stops recognising the mouse if it does not match + * exactly. + */ +static const uint8_t qemu_mouse_hid_report_descriptor[] =3D { + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x02, /* Usage (Mouse) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x09, 0x01, /* Usage (Pointer) */ + 0xa1, 0x00, /* Collection (Physical) */ + 0x05, 0x09, /* Usage Page (Button) */ + 0x19, 0x01, /* Usage Minimum (1) */ + 0x29, 0x05, /* Usage Maximum (5) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x95, 0x05, /* Report Count (5) */ + 0x75, 0x01, /* Report Size (1) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0x95, 0x01, /* Report Count (1) */ + 0x75, 0x03, /* Report Size (3) */ + 0x81, 0x01, /* Input (Constant) */ + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x30, /* Usage (X) */ + 0x09, 0x31, /* Usage (Y) */ + 0x09, 0x38, /* Usage (Wheel) */ + 0x15, 0x81, /* Logical Minimum (-0x7f) */ + 0x25, 0x7f, /* Logical Maximum (0x7f) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x03, /* Report Count (3) */ + 0x81, 0x06, /* Input (Data, Variable, Relative) */ + 0xc0, /* End Collection */ + 0xc0, /* End Collection */ +}; + static const USBDescIface desc_iface_mouse =3D { .bInterfaceNumber =3D 0, .bNumEndpoints =3D 1, @@ -93,7 +129,9 @@ static const USBDescIface desc_iface_mouse =3D { 0x00, /* u8 country_code */ 0x01, /* u8 num_descriptors */ USB_DT_REPORT, /* u8 type: Report */ - 52, 0, /* u16 len */ + /* u16 len */ + sizeof(qemu_mouse_hid_report_descriptor) & 0xff, + sizeof(qemu_mouse_hid_report_descriptor) >> 8, }, }, }, @@ -124,7 +162,9 @@ static const USBDescIface desc_iface_mouse2 =3D { 0x00, /* u8 country_code */ 0x01, /* u8 num_descriptors */ USB_DT_REPORT, /* u8 type: Report */ - 52, 0, /* u16 len */ + /* u16 len */ + sizeof(qemu_mouse_hid_report_descriptor) & 0xff, + sizeof(qemu_mouse_hid_report_descriptor) >> 8, }, }, }, @@ -453,36 +493,6 @@ static const USBDesc desc_keyboard2 =3D { .msos =3D &desc_msos_suspend, }; =20 -static const uint8_t qemu_mouse_hid_report_descriptor[] =3D { - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x02, /* Usage (Mouse) */ - 0xa1, 0x01, /* Collection (Application) */ - 0x09, 0x01, /* Usage (Pointer) */ - 0xa1, 0x00, /* Collection (Physical) */ - 0x05, 0x09, /* Usage Page (Button) */ - 0x19, 0x01, /* Usage Minimum (1) */ - 0x29, 0x05, /* Usage Maximum (5) */ - 0x15, 0x00, /* Logical Minimum (0) */ - 0x25, 0x01, /* Logical Maximum (1) */ - 0x95, 0x05, /* Report Count (5) */ - 0x75, 0x01, /* Report Size (1) */ - 0x81, 0x02, /* Input (Data, Variable, Absolute) */ - 0x95, 0x01, /* Report Count (1) */ - 0x75, 0x03, /* Report Size (3) */ - 0x81, 0x01, /* Input (Constant) */ - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x30, /* Usage (X) */ - 0x09, 0x31, /* Usage (Y) */ - 0x09, 0x38, /* Usage (Wheel) */ - 0x15, 0x81, /* Logical Minimum (-0x7f) */ - 0x25, 0x7f, /* Logical Maximum (0x7f) */ - 0x75, 0x08, /* Report Size (8) */ - 0x95, 0x03, /* Report Count (3) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0xc0, /* End Collection */ - 0xc0, /* End Collection */ -}; - static const uint8_t qemu_tablet_hid_report_descriptor[] =3D { 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x02, /* Usage (Mouse) */ --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130287; cv=none; d=zohomail.com; s=zohoarc; b=OguPZ1Adh/PxpRkJjZQiiIrhF1SajjTnR4VyULoKX+YvbzRmV+OSDn8H+byhzBvIaY0aTg2vrjAy2Kxr6Q48JpKHx+C3VdJpd/6c/TJdALE/NO1ynPcIwm9smKOjcNcjhQe7h9vBmz2MSM6T0j6xdNQbE/HL3mgqs2rxfjulllo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130287; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kV9MGrhLfQt8+CvLTa6nad43g4dkqoltiDEq1TElRZs=; b=cJYKstjMQDVryaJre3ap4FuSHzCyHIh1nH/A/kpcRbEJaDAY1Z9NmzGhxDOXvp5vplRlCYO06CO0DFyy2rSQg+qtOZqIiKta6zMAIYaiaH2FinfPwsyAqG3AkKL/Vd6/Jd2P+GD0PfwkqBkmg+c2oX8QdA+NrOhKx8IB5CjSrs4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130287753435.51769594832; Tue, 27 Oct 2026 12:44:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn54-0006qh-3G; Tue, 27 Oct 2026 15:43:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn51-0006pQ-RO for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:33 -0400 Received: from mail-dl2-x04.google.com ([2607:f8b0:4864:38::4]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn4y-0003tc-Jq for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:30 -0400 Received: by mail-dl2-x04.google.com with SMTP id a92af1059eb24-1922a6f0d23so30335c88.0 for ; Tue, 27 Oct 2026 12:43:28 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130207; x=1793735007; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kV9MGrhLfQt8+CvLTa6nad43g4dkqoltiDEq1TElRZs=; b=JbVRppq86K5HxTn/+d1A0d3ZhkuGEfuzt+In68u3uZg2SaC9yAkQOcmDM6gIYcq0/K PKfJUmlK4hCbbD2E1oLVrhF+k4M/MOQLfUaXxfd97GuGAQGooAMzcqJBit45pEjDZoho Mc8eJlQhd6DYXDZbaUqLsWjkQRcipS1wEeYOBQlvZTj+N8w2wG+vKSxgGwBF+di8vcG9 d0zUKY//jEjarGkk3p97yoKo+X3VCVOrLKKy4k07/en9zenr2bsE+H8Gj9diHd2WSFqP AOmXYiJgppJxbN/pGxboay8silsH7vS3xSUj2P2/Q1xbZahrgkzad9x7XPMTnE2Lp4pw kuEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130207; x=1793735007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kV9MGrhLfQt8+CvLTa6nad43g4dkqoltiDEq1TElRZs=; b=yZ2VQghshrrnqxERlSVZFAPFrHyIoOe2Peci2nyUttR7OCIIUAyUUr360qayJSdzCP OPstpt4OHOQacmu0YLL5SMDEw7HQ1oCrqSdVsCSLPypN9TBgaxkE5G13omor+oZte+GX cjj5H2vpkFqgg1S3XZ+54r8YuRPOlMjOwm5jRmwznXgCXwRP53WYwEHB2RyHmgu4hiZe vSfBRSBQjHjiaY7ssfcJ92FW2zabgSxaUXdBiZrRrdeYotuIBj94STBskvJbsZIWtDPi c5/dWzaKtuJBtu9sXEAHFSI/26aaAsIPRYzxp+cVdAbRO5dzYCefmq5MnTtcCSCxc+yi zIlA== X-Forwarded-Encrypted: i=1; AKwUvBxaVy6812dXGK0bFxBsFXb64YLK4ZhAhWWfKnsQQ0ocRT69A37IppPMae1VOM9rBb7VE9n8LP6QbUeh@nongnu.org X-Gm-Message-State: AFq9FYJDjTQ5wtKP0qq8XVqmsTWCUUsKcLFPZWfc1ApAPGklvXpo/eM6 5u9KgGSjTWS5uoMRbQiL98lmqQ+FE6eIDcpcp0r/phFLs0Cj2AXpgG9y X-Gm-Gg: AYBFou3uv14DNkVHTJ9noXZDh48nfUOk3zmKXVvFiRaRAbZ5NgUb52PX2s30IsIkIcY DdiwyH6JZvqS69J1XCs9kRQzrJw+h9Dg/wDyV2LMCnsQWOHlyKlmKabXX+t7G50FqcifutlEvJm Ryb3V3I8GdhrraaOXJrGepIHrw76zmOs1N1xOJRI9f9WtxZ2oCuNCciIpLumsxPtdsJr2WUpo/X PDwD+kmTuC+8GVMNIjleXBLDFLLbKWdpGEkdHt98bQ2wiXuHNmnZ6eGJmgnMedtWZVDRFr6HYkm rAZFjtxVixu0AbwdXTCco+FPVu0USbqh08nOxq5V175bfXxKCKy6ODOhzigwsJHKd1yeX2ArrJ0 hn/+9lPksAaFWVEWb7bahIZkQ4mm6EJMboNgNlUZabvVSoYjC3AZxkt0ICExqT3bpBkzqJAKYTR 2/mxe6S/QFEgg5IaOFZIma1uNwaVLBgUFwa3/8ZDyiz7Dx/YDVDAtfdqV/8a7K2t61GsG3Q3Mx9 p5g/Z8IXixCZpJe8FXc5qYGNt4TYw6rY3/9hBgVSxRh9NVlc1rhtOWfvfBlvpdo3WtpaaWGIS2C xXvgQWhaN5hhtc5OaoO9M7dtFocdRveSwUGHyfdu5a82dFY/HzH4pAgrrZdDailWHSnbWUMn+ah XxtCOTg5phrsOf7UwifmC+mIut4ttSPbprBgjfG3SqIoJndq+pA== X-Received: by 2002:a05:693c:23c4:b0:36a:15c3:2aaa with SMTP id 5a478bee46e88-36a200d82ccmr935861eec.29.1793130206717; Tue, 27 Oct 2026 12:43:26 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 5/8] hw/input/hid: accept high-resolution vertical scroll events Date: Wed, 28 Oct 2026 01:12:53 +0530 Message-ID: <20261027194256.76031-6-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:38::4; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dl2-x04.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130287934158500 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar Keep the pending vertical wheel movement in 1/120 detent units instead of whole detents and let the HID mouse receive scroll events directly by setting INPUT_EVENT_MASK_SCROLL. Wheel button clicks now add a full detent (120 units). hid_pointer_poll() still reports whole detents, so the guest-visible behaviour does not change yet. The sub-detent remainder is kept in a per-device residual so that slow scrolling adds up instead of being dropped and whole detents that do not fit into the 8-bit report field stay queued for the next poll as before. The residual is migrated in a new optional subsection, which is only sent while wheel movement is pending. Because the unit of the queued dz values changes an incoming stream without the subsection (from an older QEMU, or with no wheel movement pending) has its queued dz values converted from detents to 1/120 units in post_load. Signed-off-by: Soumyajyotii Ssarkar --- hw/input/hid.c | 97 +++++++++++++++++++++++++++++++++++++++--- include/hw/input/hid.h | 2 + 2 files changed, 93 insertions(+), 6 deletions(-) diff --git a/hw/input/hid.c b/hw/input/hid.c index 0f28827554..2855f6a3d9 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -145,15 +145,21 @@ static void hid_pointer_event(DeviceState *dev, QemuC= onsole *src, if (evt->btn.down) { e->buttons_state |=3D bmap[evt->btn.button]; if (evt->btn.button =3D=3D INPUT_BUTTON_WHEEL_UP) { - e->dz--; + e->dz -=3D INPUT_EVENT_SCROLL_DETENT; } else if (evt->btn.button =3D=3D INPUT_BUTTON_WHEEL_DOWN) { - e->dz++; + e->dz +=3D INPUT_EVENT_SCROLL_DETENT; } } else { e->buttons_state &=3D ~bmap[evt->btn.button]; } break; =20 + case INPUT_EVENT_KIND_SCROLL: + if (evt->scroll.axis =3D=3D INPUT_SCROLL_AXIS_VERTICAL) { + e->dz +=3D evt->scroll.value; + } + break; + default: /* keep gcc happy */ break; @@ -349,6 +355,18 @@ void hid_pointer_activate(HIDState *hs) } } =20 +static int hid_scroll_counts(int32_t *pending, int32_t *residual, int mult) +{ + int unit =3D INPUT_EVENT_SCROLL_DETENT / mult; + int32_t acc =3D *pending + *residual; + int counts =3D int_clamp(acc / unit, -127, 127); + + acc -=3D counts * unit; + *residual =3D acc % unit; + *pending =3D acc - *residual; + return counts; +} + int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len) { int dx, dy, dz, l; @@ -373,8 +391,7 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int le= n) dx =3D e->xdx; dy =3D e->ydy; } - dz =3D int_clamp(e->dz, -127, 127); - e->dz -=3D dz; + dz =3D hid_scroll_counts(&e->dz, &hs->ptr.wheel_residual, 1); =20 if (hs->n && !e->dz && @@ -513,7 +530,8 @@ static const QemuInputHandler hid_keyboard_handler =3D { =20 static const QemuInputHandler hid_mouse_handler =3D { .name =3D "QEMU HID Mouse", - .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL | + INPUT_EVENT_MASK_SCROLL, .event =3D hid_pointer_event, .sync =3D hid_pointer_sync, }; @@ -585,11 +603,74 @@ static const VMStateDescription vmstate_hid_ptr_queue= =3D { } }; =20 +/* + * Wheel movement used to be queued in whole detents and is now kept in + * 1/120 detent units. Without this subsection the source either was an + * older QEMU or had no wheel state pending, so rescaling dz is safe. + */ +static bool hid_ptr_wheel_needed(void *opaque) +{ + HIDState *s =3D opaque; + int i; + + if (s->ptr.wheel_residual) { + return true; + } + for (i =3D 0; i < QUEUE_LENGTH; i++) { + if (s->ptr.queue[i].dz) { + return true; + } + } + return false; +} + +static int hid_ptr_pre_load(void *opaque) +{ + HIDState *s =3D opaque; + + s->ptr.wheel_state_loaded =3D false; + return 0; +} + +static int hid_ptr_wheel_post_load(void *opaque, int version_id) +{ + HIDState *s =3D opaque; + + s->ptr.wheel_state_loaded =3D true; + return 0; +} + +static int hid_ptr_post_load(void *opaque, int version_id) +{ + HIDState *s =3D opaque; + int i; + + if (!s->ptr.wheel_state_loaded) { + for (i =3D 0; i < QUEUE_LENGTH; i++) { + s->ptr.queue[i].dz *=3D INPUT_EVENT_SCROLL_DETENT; + } + } + return hid_post_load(opaque, version_id); +} + +static const VMStateDescription vmstate_hid_ptr_wheel =3D { + .name =3D "HIDPointerDevice/wheel", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D hid_ptr_wheel_needed, + .post_load =3D hid_ptr_wheel_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_INT32(ptr.wheel_residual, HIDState), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_hid_ptr_device =3D { .name =3D "HIDPointerDevice", .version_id =3D 1, .minimum_version_id =3D 1, - .post_load =3D hid_post_load, + .pre_load =3D hid_ptr_pre_load, + .post_load =3D hid_ptr_post_load, .fields =3D (const VMStateField[]) { VMSTATE_STRUCT_ARRAY(ptr.queue, HIDState, QUEUE_LENGTH, 0, vmstate_hid_ptr_queue, HIDPointerEvent), @@ -598,6 +679,10 @@ const VMStateDescription vmstate_hid_ptr_device =3D { VMSTATE_INT32(protocol, HIDState), VMSTATE_UINT8(idle, HIDState), VMSTATE_END_OF_LIST(), + }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_hid_ptr_wheel, + NULL } }; =20 diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h index 6a9d7bf466..1e29f4ada4 100644 --- a/include/hw/input/hid.h +++ b/include/hw/input/hid.h @@ -22,6 +22,8 @@ typedef void (*HIDEventFunc)(HIDState *s); typedef struct HIDMouseState { HIDPointerEvent queue[QUEUE_LENGTH]; int mouse_grabbed; + int32_t wheel_residual; + bool wheel_state_loaded; } HIDMouseState; =20 typedef struct HIDKeyboardState { --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130234; cv=none; d=zohomail.com; s=zohoarc; b=XLrlX8A0gu06rwjOfkT/9MncORtKgul7C/zTo9JBMGlfhsoVRs64qB05Chh98uzSUcZ1GmyNEr81NfYThIwN42sUY4J6TgpAWITzQycwswNgDgJXLq7Az3bKVq8rUmA74xdrXIN7tf5EcpyOdYCnKM74++T7a2tigpwFVFZAR3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130234; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SdfoF/OwK31Vto+fkLrSnBQEp5sDuc7DP41XnDQoJqc=; b=UpvB/OdvquJAU+TbaqmmOGawxrMS5CGiwFehGuVYC2WEP0+ROO24T/EkSUYAqDZYYf7MysvQ+VYvRS9mJx1RPH3W7lc4AjQW+q44ENU84nbqQ89DlThDAeAqCNhpngfXpuc8q12TVBYgic713QjXfnAvUE22MosYsU+WTy+k25Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130234255821.9223426993709; Tue, 27 Oct 2026 12:43:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn59-0006rd-VY; Tue, 27 Oct 2026 15:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn58-0006rN-7d for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:38 -0400 Received: from mail-dy2-x0a.google.com ([2607:f8b0:4864:36::a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn52-0003tv-QJ for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:34 -0400 Received: by mail-dy2-x0a.google.com with SMTP id 5a478bee46e88-33e5ae86ff2so65678eec.0 for ; Tue, 27 Oct 2026 12:43:32 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130211; x=1793735011; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SdfoF/OwK31Vto+fkLrSnBQEp5sDuc7DP41XnDQoJqc=; b=bTMwfP1VE+QNHxXSn2HE2DVWRt9VsEdxoxoLzD5xYmQT7GrI2d2eWQ3DvnmAx+/jNA nwyzxOrnW5+gTsR9nyM1i9iTX1Z7gNJEaI0+XSe7vcQeGYrBvi45kFy6KNtTao/Ol1m9 bb9ydoaf+6HmD+9fsCeFSJVZn0bGSxKZP6WWdv/0nBkM0kM9td3lOAXtA7BgB3GQAg2q P+fVXuyc3iR1bTXjsFy/lgpPLj5aag1ZEljhJ31Ukhc/2/ieIcFBomNxAD8HS+phRZDz umHnntk10+bFCC1uladU5SPReJoXyC7yaH6pNNJs5Q5TLz191OdWPigk5wG2w0WW/O83 OObA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130211; x=1793735011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SdfoF/OwK31Vto+fkLrSnBQEp5sDuc7DP41XnDQoJqc=; b=c+nC061W3MOur6gynv85PoYfj88Mv0moPQ7TR73AJvc02uQ7s22ib60IhNEFin6T/0 EqnrW+q8oXY3lS5hzqPHGFjKwb5X/Uk9HQ21Fzftt5bPu0mjcbc7OE5vB9CotoKnnWmq PxLzCd3TA9FqeMyhiC+EKah0lBqGTaqLiMoG4PaZV1n1C3YRS+QJ4iHcHKj08Q780TzO oNVDUoWlnhg087Vl7iR3bARp3ucH3KUcxj0vZ1Jxg9r9G37h004nyyjA8AyzAeZOYxOa 2AD500asbxhVJ2WB8IsX7/0tZt4ufi2jih91uSaxDCs8w+1clwo6HiPIkbVppRDORUQ9 rtkA== X-Forwarded-Encrypted: i=1; AKwUvBzRHlL9eLm5MHf9ofMKtszaeSWymAaGSr4QuSEHOdoTpk2sfdH3IljBYmgkgVkxHXSgh5Y6j1uqr4Kt@nongnu.org X-Gm-Message-State: AFq9FYLSclfVlZAc4FgfJTlLAecK8sFp9O7JxGNIIBxsUoxz8nHx2SCo pH6XhTc7+sabQwnDEmyKgPf1D/dNagu2vobQb5YA5QsOI13HH68rz/nxxBdhJZsTmZ0= X-Gm-Gg: AYBFou140Vvdbcp+EYTeFd23EG2UANHlByR+0bmEinj466inhom2hCyNwmzfLSMhVMO gsaFB25LkxvbYEl5D/edA3lOVzIqQiif1mKeJ+C3/bsf5LpQG93BrSkyzqRj1T0n5hdDFte1XM4 1C/nrwaH0H3MQzwd6A64JTMFoLt80SCAT8MHGWbynGHn7YyvoD9AjFnKBTScbUmxC1belKHk/pW jbJkaMlGoDd08uUWYbzI+s6CTK3TXDwceV/QzHSHXOg78om/eg0cxVVwMWk36+gCclUjB8+13jc p2nkO9fxCp/NlVCpAEAXY3UZLQ90h+SF7OpSQaHD0x4j5XosXxbVNY4JTqJGFzTP6qraegUcx26 bNSyNJDe16WWmrswoZnuOd37WA7IDGn+Zettor9Z8gDGM1zosHINxWc0gjC3fVxK6VGj1b3AswR /7SxIeSF4Rdf44tCOaMooKAx0kFY4iZ/noRvmYB/S+JR2h7QxHGo0o+au3NkTuUId//2eg5kCwA Q3W2RYiBPin1tKb9RoOAaKOtNjvxs6lt3zl24/PjdcBlPeobj9wd0pDGiT3aj3Jea9szlRol2gG pToJ2/Rs5U7/k0j+3j6aNi7NU9s4Psgkjyi6rf6eeI8Zc/yg62kag4VXUcoRh6VnSi7frkHBP2Q nSJ2RTMmf54NPO++SLmyqoc2w+cmnPafpKRRY3aKQfr/U1BZOTg== X-Received: by 2002:a05:693c:20c6:20b0:369:f9da:a70f with SMTP id 5a478bee46e88-36a200beebcmr635777eec.17.1793130211068; Tue, 27 Oct 2026 12:43:31 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 6/8] hw/usb/dev-hid: report horizontal wheel through AC Pan Date: Wed, 28 Oct 2026 01:12:54 +0530 Message-ID: <20261027194256.76031-7-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::a; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x0a.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130237458154100 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar The USB mouse report descriptor only describes buttons, X, Y and a vertical wheel, so horizontal scrolling from the host never reaches the guest. Rework the descriptor following the layout in Microsoft's "Enhanced Wheel Support in Windows" paper: the pointer fields move into input report 1 and the vertical Wheel and the Consumer AC Pan usages each get their own logical collection. The report descriptor grows from 52 to 90 bytes and the interrupt endpoint packet size from 4 to 6 bytes. On the HID side, track horizontal movement in a new 'pan' field of the pointer event queue, fed from WHEEL_LEFT/RIGHT button clicks and from horizontal scroll events, with the same residual handling as the vertical wheel. In report protocol hid_pointer_poll() now emits a 6-byte report: report ID, buttons, X, Y, wheel and one pan byte. Boot protocol keeps the 4-byte layout without report ID and pan. The pan value is not inverted: a positive AC Pan value means scrolling right, which matches the sign of the input layer's horizontal scroll. The queued pan values and the pan residual are migrated in the optional wheel subsection. Signed-off-by: Soumyajyotii Ssarkar --- hw/input/hid.c | 75 ++++++++++++++++++++++++++++------- hw/usb/dev-hid.c | 88 +++++++++++++++++++++++++++++------------- include/hw/input/hid.h | 2 + 3 files changed, 124 insertions(+), 41 deletions(-) diff --git a/hw/input/hid.c b/hw/input/hid.c index 2855f6a3d9..9f26850112 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -148,6 +148,10 @@ static void hid_pointer_event(DeviceState *dev, QemuCo= nsole *src, e->dz -=3D INPUT_EVENT_SCROLL_DETENT; } else if (evt->btn.button =3D=3D INPUT_BUTTON_WHEEL_DOWN) { e->dz +=3D INPUT_EVENT_SCROLL_DETENT; + } else if (evt->btn.button =3D=3D INPUT_BUTTON_WHEEL_LEFT) { + e->pan -=3D INPUT_EVENT_SCROLL_DETENT; + } else if (evt->btn.button =3D=3D INPUT_BUTTON_WHEEL_RIGHT) { + e->pan +=3D INPUT_EVENT_SCROLL_DETENT; } } else { e->buttons_state &=3D ~bmap[evt->btn.button]; @@ -157,6 +161,8 @@ static void hid_pointer_event(DeviceState *dev, QemuCon= sole *src, case INPUT_EVENT_KIND_SCROLL: if (evt->scroll.axis =3D=3D INPUT_SCROLL_AXIS_VERTICAL) { e->dz +=3D evt->scroll.value; + } else if (evt->scroll.axis =3D=3D INPUT_SCROLL_AXIS_HORIZONTAL) { + e->pan +=3D evt->scroll.value; } break; =20 @@ -210,6 +216,8 @@ static void hid_pointer_sync(DeviceState *dev) } prev->dz +=3D curr->dz; curr->dz =3D 0; + prev->pan +=3D curr->pan; + curr->pan =3D 0; } else { /* prepare next (clear rel, copy abs + btns) */ if (hs->kind =3D=3D HID_MOUSE) { @@ -220,6 +228,7 @@ static void hid_pointer_sync(DeviceState *dev) next->ydy =3D curr->ydy; } next->dz =3D 0; + next->pan =3D 0; next->buttons_state =3D curr->buttons_state; /* make current guest visible, notify guest */ hs->n++; @@ -369,7 +378,7 @@ static int hid_scroll_counts(int32_t *pending, int32_t = *residual, int mult) =20 int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len) { - int dx, dy, dz, l; + int dx, dy, dz, pan, l; int index; HIDPointerEvent *e; =20 @@ -392,9 +401,11 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int l= en) dy =3D e->ydy; } dz =3D hid_scroll_counts(&e->dz, &hs->ptr.wheel_residual, 1); + pan =3D hid_scroll_counts(&e->pan, &hs->ptr.pan_residual, 1); =20 if (hs->n && !e->dz && + !e->pan && (hs->kind =3D=3D HID_TABLET || (!e->xdx && !e->ydy))) { /* that deals with this event */ QUEUE_INCR(hs->head); @@ -406,17 +417,40 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int = len) l =3D 0; switch (hs->kind) { case HID_MOUSE: - if (len > l) { - buf[l++] =3D e->buttons_state; - } - if (len > l) { - buf[l++] =3D dx; - } - if (len > l) { - buf[l++] =3D dy; - } - if (len > l) { - buf[l++] =3D dz; + if (hs->protocol =3D=3D 0) { + /* boot protocol (0) */ + if (len > l) { + buf[l++] =3D e->buttons_state; + } + if (len > l) { + buf[l++] =3D dx; + } + if (len > l) { + buf[l++] =3D dy; + } + if (len > l) { + buf[l++] =3D dz; + } + } else { + /* report protocol (1) */ + if (len > l) { + buf[l++] =3D 0x01; + } + if (len > l) { + buf[l++] =3D e->buttons_state; + } + if (len > l) { + buf[l++] =3D dx; + } + if (len > l) { + buf[l++] =3D dy; + } + if (len > l) { + buf[l++] =3D dz; + } + if (len > l) { + buf[l++] =3D pan; + } } break; =20 @@ -603,6 +637,16 @@ static const VMStateDescription vmstate_hid_ptr_queue = =3D { } }; =20 +static const VMStateDescription vmstate_hid_ptr_queue_pan =3D { + .name =3D "HIDPointerEventQueue/pan", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_INT32(pan, HIDPointerEvent), + VMSTATE_END_OF_LIST() + } +}; + /* * Wheel movement used to be queued in whole detents and is now kept in * 1/120 detent units. Without this subsection the source either was an @@ -613,11 +657,11 @@ static bool hid_ptr_wheel_needed(void *opaque) HIDState *s =3D opaque; int i; =20 - if (s->ptr.wheel_residual) { + if (s->ptr.wheel_residual || s->ptr.pan_residual) { return true; } for (i =3D 0; i < QUEUE_LENGTH; i++) { - if (s->ptr.queue[i].dz) { + if (s->ptr.queue[i].dz || s->ptr.queue[i].pan) { return true; } } @@ -660,7 +704,10 @@ static const VMStateDescription vmstate_hid_ptr_wheel = =3D { .needed =3D hid_ptr_wheel_needed, .post_load =3D hid_ptr_wheel_post_load, .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_ARRAY(ptr.queue, HIDState, QUEUE_LENGTH, 0, + vmstate_hid_ptr_queue_pan, HIDPointerEvent), VMSTATE_INT32(ptr.wheel_residual, HIDState), + VMSTATE_INT32(ptr.pan_residual, HIDState), VMSTATE_END_OF_LIST() } }; diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index 2c10e88c85..804119006b 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -85,31 +85,65 @@ static const USBDescStrings desc_strings =3D { static const uint8_t qemu_mouse_hid_report_descriptor[] =3D { 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x02, /* Usage (Mouse) */ - 0xa1, 0x01, /* Collection (Application) */ - 0x09, 0x01, /* Usage (Pointer) */ - 0xa1, 0x00, /* Collection (Physical) */ - 0x05, 0x09, /* Usage Page (Button) */ - 0x19, 0x01, /* Usage Minimum (1) */ - 0x29, 0x05, /* Usage Maximum (5) */ - 0x15, 0x00, /* Logical Minimum (0) */ - 0x25, 0x01, /* Logical Maximum (1) */ - 0x95, 0x05, /* Report Count (5) */ - 0x75, 0x01, /* Report Size (1) */ - 0x81, 0x02, /* Input (Data, Variable, Absolute) */ - 0x95, 0x01, /* Report Count (1) */ - 0x75, 0x03, /* Report Size (3) */ - 0x81, 0x01, /* Input (Constant) */ - 0x05, 0x01, /* Usage Page (Generic Desktop) */ - 0x09, 0x30, /* Usage (X) */ - 0x09, 0x31, /* Usage (Y) */ - 0x09, 0x38, /* Usage (Wheel) */ - 0x15, 0x81, /* Logical Minimum (-0x7f) */ - 0x25, 0x7f, /* Logical Maximum (0x7f) */ - 0x75, 0x08, /* Report Size (8) */ - 0x95, 0x03, /* Report Count (3) */ - 0x81, 0x06, /* Input (Data, Variable, Relative) */ - 0xc0, /* End Collection */ - 0xc0, /* End Collection */ + 0xA1, 0x01, /* Collection (Application) */ + + 0x09, 0x02, /* Usage (Mouse) */ + 0xA1, 0x02, /* Collection (Logical) */ + + 0x85, 0x01, /* Report ID (0x01) */ + 0x09, 0x01, /* Usage (Pointer) */ + 0xA1, 0x00, /* Collection (Physical) */ + + 0x05, 0x09, /* Usage Page (Button) */ + 0x19, 0x01, /* Usage Minimum (1) */ + 0x29, 0x05, /* Usage Maximum (5) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x95, 0x05, /* Report Count (5) */ + 0x75, 0x01, /* Report Size (1) */ + 0x81, 0x02, /* Input (Data,Var,Abs) */ + + 0x95, 0x01, /* Report Count (1) */ + 0x75, 0x03, /* Report Size (3) */ + 0x81, 0x01, /* Input (Const) */ + + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x30, /* Usage (X) */ + 0x09, 0x31, /* Usage (Y) */ + 0x95, 0x02, /* Report Count (2) */ + 0x75, 0x08, /* Report Size (8) */ + 0x15, 0x81, /* Logical Minimum (-127) */ + 0x25, 0x7F, /* Logical Maximum (127) */ + 0x81, 0x06, /* Input (Data,Var,Rel) */ + + /* Vertical wheel logical collection */ + 0xA1, 0x02, /* Collection (Logical) */ + + 0x09, 0x38, /* Usage (Wheel) */ + 0x15, 0x81, /* Logical Minimum (-0x7f) */ + 0x25, 0x7F, /* Logical Maximum (0x7f) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x01, /* Report Count (1) */ + 0x81, 0x06, /* Input (Data,Var,Rel) */ + + 0xC0, /* End Collection */ + + /* Horizontal wheel logical collection */ + 0xA1, 0x02, /* Collection (Logical) */ + + 0x05, 0x0C, /* Usage Page (Consumer Devices) */ + 0x0A, 0x38, 0x02, /* Usage (AC Pan) */ + 0x15, 0x81, /* Logical Minimum (-0x7f) */ + 0x25, 0x7F, /* Logical Maximum (0x7f) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x01, /* Report Count (1) */ + 0x81, 0x06, /* Input (Data,Var,Rel) */ + + 0xC0, /* End Collection */ + + 0xC0, /* End Collection (Physical) */ + 0xC0, /* End Collection (Logical) */ + 0xC0 /* End Collection (Application) */ }; =20 static const USBDescIface desc_iface_mouse =3D { @@ -139,7 +173,7 @@ static const USBDescIface desc_iface_mouse =3D { { .bEndpointAddress =3D USB_DIR_IN | 0x01, .bmAttributes =3D USB_ENDPOINT_XFER_INT, - .wMaxPacketSize =3D 4, + .wMaxPacketSize =3D 6, .bInterval =3D 0x0a, }, }, @@ -172,7 +206,7 @@ static const USBDescIface desc_iface_mouse2 =3D { { .bEndpointAddress =3D USB_DIR_IN | 0x01, .bmAttributes =3D USB_ENDPOINT_XFER_INT, - .wMaxPacketSize =3D 4, + .wMaxPacketSize =3D 6, .bInterval =3D 7, /* 2 ^ (8-1) * 125 usecs =3D 8 m= s */ }, }, diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h index 1e29f4ada4..b7cdeb54c2 100644 --- a/include/hw/input/hid.h +++ b/include/hw/input/hid.h @@ -10,6 +10,7 @@ typedef struct HIDPointerEvent { int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */ int32_t dz, buttons_state; + int32_t pan; } HIDPointerEvent; =20 #define QUEUE_LENGTH 16 /* should be enough for a triple-click */ @@ -23,6 +24,7 @@ typedef struct HIDMouseState { HIDPointerEvent queue[QUEUE_LENGTH]; int mouse_grabbed; int32_t wheel_residual; + int32_t pan_residual; bool wheel_state_loaded; } HIDMouseState; =20 --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130230; cv=none; d=zohomail.com; s=zohoarc; b=C5H9gFE1T3dxokke9IDzLjH+TsULLIsKZdLJ5J5peexVas8dKDvkVZ+5c3T4QZ+3EAvTDL+rKu5QMUae6U2RCT00gBpubp4pBpZeOz/p96u4uWeke5G6ebPEKM6EadBoM/oMOzpMSToAt1WRUH/VuNGVBoWWFxBKspayzB1ieY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130230; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iD/yZnopZ26jXY6NfunmdxdiTNNYDEqf2sjNrQDEsuA=; b=KF0zoTJuHsg7DOjZQyzMiyyL79DOnyA9DbkcGp8vfStmtH/QFt+i768MlXXhCDYAN8XMkVhciVByyv7igAK/GNwGzifM56b/dvMFnPPya5lKm2KWwunGytHghh7jy7REJEqiL/8UzlzR/axZlcIO46MJXdzfwNl1PAwpAjEJGts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130230334484.73522666541965; Tue, 27 Oct 2026 12:43:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn5B-0006sJ-U1; Tue, 27 Oct 2026 15:43:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn5A-0006s5-6n for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:40 -0400 Received: from mail-dy2-x07.google.com ([2607:f8b0:4864:36::7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn58-0003uG-0I for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:39 -0400 Received: by mail-dy2-x07.google.com with SMTP id 5a478bee46e88-369ef2c6802so29046eec.1 for ; Tue, 27 Oct 2026 12:43:36 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130216; x=1793735016; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iD/yZnopZ26jXY6NfunmdxdiTNNYDEqf2sjNrQDEsuA=; b=Ytoj8nHiWFQqfoLb1yjoQBXFWa0P1XcBdrIwVMpwCy/mcYlCjwbP4D+8qZ424bjwnj dFC80QFJbxsaw7a6ghY9toCELea4MyGf0PYfk+I3DcYtD70UAtovCOgR9X1mcAnGMkmP eK5I/wrWTgoURG1njqwBXQd2ZyF4kHEGfv6r7R4HskXT2v4e6xvUtHOwxEbMGOCEY9zy /gFlmzoUdyXxtA3ge0szedCZtRS9wKIxAptuQ/ukaSnZpu8IAbVnIhnYbyAf01PV7wg+ Z0lUiPj8WBK7cpUHfrh6ioWY+dDGw6MHC5jr2Zvg9iZ0rXoVq+XL1iEJb5FKo5hSS2UZ qyqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130216; x=1793735016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=iD/yZnopZ26jXY6NfunmdxdiTNNYDEqf2sjNrQDEsuA=; b=eIn7D816/foB9+sksOPYysoLnboEMZl1pEkHwoTX/6dE3q/U7PXS0PQAJZvsV/Yl37 5MH+uMa6xufqGYK0urMMWbYMlLFR5XY0FLsT5zqUMlyqMXi+YFWkW9wQBpgxHJm55fN1 A7y6CvWq16MRuANlPLCh+3+8UXQDl6q6ap52zV6pjVsmJF5UiYEds4Jah6PiJaUrin8h YWNa8H0ImAPVxxmoPSkTlplxcufq2U8+BzBQuMIf5TEQNxuruiZYvht1yrdgvp2Qm9pw NeOBHtKArgVJb6O4KTS64duHYymk/HgVTB76VHasc99XIPHK9l/ndYG6fgi+sQa1RJ7u nWEw== X-Forwarded-Encrypted: i=1; AKwUvBzGuoh9VkMIfEjDroRT6aChr1RRZVm2GFjkhYBGLUvkld/bVimEwCw2H7cMS+2jwXJNBfnRm/FGiJRr@nongnu.org X-Gm-Message-State: AFq9FYLzgRnLqmkc5Ab+a7iVb8+gKRf7SwUtYtjZ3TMxK2jL7EHaXGyN 3/mEgEzSLfce3m4WqBjLGtKcnPWQdN3FsLgGaXg0qOB5hTLopZqazTky X-Gm-Gg: AYBFou3vX6YLEoUUVqmh+3rKca6lCJaVsF1KtL7sD01k8oXDS9bRjSuMv+f/6f8J5bP wM0aOTciNE7DHsoG8UGHA5XE5p33+z7TqOX8nRZmB+geLW9yHTtK6TBG8UX5vscgov6t7uhCxAq i+akgnLVvuD/XQ4Ztd5j5iC38fDZ6XXCN0krDavYWOaDbpwYgrO/mVZKv94QzlAO+vemKkBDjvW wVZ/f+KQl+tpOFqiUlpmRKy29aaiOuzYQq0DgOJqzb8+yKGPrpJC6E0hrBpW6PLPWX4nA8kr35R 8zR8DmfC7hJhQ07My74z/8HzCnV6xGncCzE2KgDEJ1o0HYGkQtQa9NeyORwLeQE9/ZEsPsgn9pz VHtgpcZXHhFHaBLLx47dxLc5uCkicHrrCVDA8AOexW9ZpaS0BllIYQkAmxteIohekfPaX5c/way Lwegv1FvNr2tzfi4n+hshPO9aIyWT2q0ACyWmkoLt2tJDCEkY/tIXhN/UBeteBFqKMjwzMTYB+S likfXKKwdxmBFz9OVQRhDKwyTEtNalkVTxYbhhEzzFecOencoYPDkKEojPM+F6XRmXGL4rUOyxG 4WvKMWQF7183Rc84fCiQwTdk/Ga9BZ5n/P2Z6dYFn8pP1UzAY+WKrJe1fcO8A917kNWSy7Dwl/N JgRY/STLkNnQ8Smq5mZZDoHgwGnCS/i+YRyBU1IPIcXg4ii45rPvLqSSvtcrHRGZ9FVj6iOk= X-Received: by 2002:a05:7301:2422:b0:35a:3b98:b428 with SMTP id 5a478bee46e88-36a0f7d0250mr4566226eec.12.1793130215442; Tue, 27 Oct 2026 12:43:35 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar Subject: [PATCH v2 7/8] hw/usb/dev-hid: support the wheel Resolution Multiplier feature report Date: Wed, 28 Oct 2026 01:12:55 +0530 Message-ID: <20261027194256.76031-8-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::7; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x07.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130231514154100 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar Even with high-resolution scroll events reaching the HID mouse, each wheel report count is still a whole detent, so guests see the same coarse steps as before. Add a Resolution Multiplier feature (report ID 2) to the vertical wheel and AC Pan logical collections, as described in Microsoft's "Enhanced Wheel Support in Windows" docs. The feature byte holds the wheel multiplier in bits [1:0] and the pan multiplier in bits [3:2], each with logical range 0..1 and physical range 1..120. The report descriptor grows to 144 bytes. Handle GET_REPORT and SET_REPORT for the feature report, accepting the payload with or without the leading report ID byte. Windows (Vista and later) and Linux set each multiplier to its logical maximum. While a multiplier is enabled in report protocol, hid_pointer_poll() reports that axis in counts of 1/120 detent, so one count reaches applications as one WHEEL_DELTA unit. Boot protocol and guests that never enable the multiplier keep getting whole detents. The multiplier state is migrated in the optional wheel subsection. Signed-off-by: Soumyajyotii Ssarkar --- hw/input/hid.c | 22 ++++++++-- hw/usb/dev-hid.c | 97 ++++++++++++++++++++++++++++++++++++++---- include/hw/input/hid.h | 4 ++ 3 files changed, 111 insertions(+), 12 deletions(-) diff --git a/hw/input/hid.c b/hw/input/hid.c index 9f26850112..bc84e99dbc 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -378,7 +378,7 @@ static int hid_scroll_counts(int32_t *pending, int32_t = *residual, int mult) =20 int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len) { - int dx, dy, dz, pan, l; + int dx, dy, dz, pan, l, mult; int index; HIDPointerEvent *e; =20 @@ -400,8 +400,19 @@ int hid_pointer_poll(HIDState *hs, uint8_t *buf, int l= en) dx =3D e->xdx; dy =3D e->ydy; } - dz =3D hid_scroll_counts(&e->dz, &hs->ptr.wheel_residual, 1); - pan =3D hid_scroll_counts(&e->pan, &hs->ptr.pan_residual, 1); + mult =3D 1; + if (hs->kind =3D=3D HID_MOUSE && hs->protocol =3D=3D 1 && + hs->ptr.wheel_multiplier) { + mult =3D HID_WHEEL_RESOLUTION_MULTIPLIER; + } + dz =3D hid_scroll_counts(&e->dz, &hs->ptr.wheel_residual, mult); + + mult =3D 1; + if (hs->kind =3D=3D HID_MOUSE && hs->protocol =3D=3D 1 && + hs->ptr.pan_multiplier) { + mult =3D HID_WHEEL_RESOLUTION_MULTIPLIER; + } + pan =3D hid_scroll_counts(&e->pan, &hs->ptr.pan_residual, mult); =20 if (hs->n && !e->dz && @@ -657,7 +668,8 @@ static bool hid_ptr_wheel_needed(void *opaque) HIDState *s =3D opaque; int i; =20 - if (s->ptr.wheel_residual || s->ptr.pan_residual) { + if (s->ptr.wheel_multiplier || s->ptr.pan_multiplier || + s->ptr.wheel_residual || s->ptr.pan_residual) { return true; } for (i =3D 0; i < QUEUE_LENGTH; i++) { @@ -706,6 +718,8 @@ static const VMStateDescription vmstate_hid_ptr_wheel = =3D { .fields =3D (const VMStateField[]) { VMSTATE_STRUCT_ARRAY(ptr.queue, HIDState, QUEUE_LENGTH, 0, vmstate_hid_ptr_queue_pan, HIDPointerEvent), + VMSTATE_UINT8(ptr.wheel_multiplier, HIDState), + VMSTATE_UINT8(ptr.pan_multiplier, HIDState), VMSTATE_INT32(ptr.wheel_residual, HIDState), VMSTATE_INT32(ptr.pan_residual, HIDState), VMSTATE_END_OF_LIST() diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index 804119006b..ffe07ff68b 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -81,6 +81,8 @@ static const USBDescStrings desc_strings =3D { * descriptor. * Note: Windows stops recognising the mouse if it does not match * exactly. + * The enhanced wheel support grew the descriptor from 52 to 144 + * bytes. */ static const uint8_t qemu_mouse_hid_report_descriptor[] =3D { 0x05, 0x01, /* Usage Page (Generic Desktop) */ @@ -119,7 +121,20 @@ static const uint8_t qemu_mouse_hid_report_descriptor[= ] =3D { /* Vertical wheel logical collection */ 0xA1, 0x02, /* Collection (Logical) */ =20 + 0x85, 0x02, /* Report ID (0x02) */ + 0x09, 0x48, /* Usage (Resolution Multiplier) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x35, 0x01, /* Physical Minimum (1) */ + 0x45, 0x78, /* Physical Maximum (120) */ + 0x75, 0x02, /* Report Size (2) */ + 0x95, 0x01, /* Report Count (1) */ + 0xB1, 0x02, /* Feature (Data,Var,Abs) */ + + 0x85, 0x01, /* Report ID (0x01) */ 0x09, 0x38, /* Usage (Wheel) */ + 0x35, 0x00, /* Physical Minimum (0) */ + 0x45, 0x00, /* Physical Maximum (0) */ 0x15, 0x81, /* Logical Minimum (-0x7f) */ 0x25, 0x7F, /* Logical Maximum (0x7f) */ 0x75, 0x08, /* Report Size (8) */ @@ -131,6 +146,23 @@ static const uint8_t qemu_mouse_hid_report_descriptor[= ] =3D { /* Horizontal wheel logical collection */ 0xA1, 0x02, /* Collection (Logical) */ =20 + 0x85, 0x02, /* Report ID (0x02) */ + 0x09, 0x48, /* Usage (Resolution Multiplier) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x35, 0x01, /* Physical Minimum (1) */ + 0x45, 0x78, /* Physical Maximum (120) */ + 0x75, 0x02, /* Report Size (2) */ + 0x95, 0x01, /* Report Count (1) */ + 0xB1, 0x02, /* Feature (Data,Var,Abs) */ + + 0x35, 0x00, /* Physical Minimum (0) */ + 0x45, 0x00, /* Physical Maximum (0) */ + 0x75, 0x04, /* Report Size (4) */ + 0x95, 0x01, /* Report Count (1) */ + 0xB1, 0x01, /* Feature (Const) */ + + 0x85, 0x01, /* Report ID (0x01) */ 0x05, 0x0C, /* Usage Page (Consumer Devices) */ 0x0A, 0x38, 0x02, /* Usage (AC Pan) */ 0x15, 0x81, /* Logical Minimum (-0x7f) */ @@ -652,17 +684,66 @@ static void usb_hid_handle_control(USBDevice *dev, US= BPacket *p, } break; case HID_GET_REPORT: - if (hs->kind =3D=3D HID_MOUSE || hs->kind =3D=3D HID_TABLET) { - p->actual_length =3D hid_pointer_poll(hs, data, length); - } else if (hs->kind =3D=3D HID_KEYBOARD) { - p->actual_length =3D hid_keyboard_poll(hs, data, length); + { + uint8_t mult; + uint8_t report_type =3D (value >> 8) & 0xFF; + uint8_t report_id =3D value & 0xFF; + + if (report_type =3D=3D 0x03 && report_id =3D=3D 0x02 && + hs->kind =3D=3D HID_MOUSE) { + + if (length < 1) { + goto fail; + } + + mult =3D ((hs->ptr.pan_multiplier & 0x03) << 2) | + (hs->ptr.wheel_multiplier & 0x03); + if (length >=3D 2) { + data[0] =3D 0x02; + data[1] =3D mult; + p->actual_length =3D 2; + } else { + data[0] =3D mult; + p->actual_length =3D 1; + } + + } else if (hs->kind =3D=3D HID_MOUSE || hs->kind =3D=3D HID_TA= BLET) { + p->actual_length =3D hid_pointer_poll(hs, data, length); + } else if (hs->kind =3D=3D HID_KEYBOARD) { + p->actual_length =3D hid_keyboard_poll(hs, data, length); + } else { + goto fail; + } } break; case HID_SET_REPORT: - if (hs->kind =3D=3D HID_KEYBOARD) { - p->actual_length =3D hid_keyboard_write(hs, data, length); - } else { - goto fail; + { + uint8_t mult; + uint8_t report_type =3D (value >> 8) & 0xFF; + uint8_t report_id =3D value & 0xFF; + + if (report_type =3D=3D 0x03 && report_id =3D=3D 0x02 && + hs->kind =3D=3D HID_MOUSE) { + + if (length < 1) { + goto fail; + } + + if (length >=3D 2 && data[0] =3D=3D 0x02) { + mult =3D data[1]; + } else { + mult =3D data[0]; + } + + hs->ptr.wheel_multiplier =3D mult & 0x03; + hs->ptr.pan_multiplier =3D (mult >> 2) & 0x03; + p->actual_length =3D length; + + } else if (hs->kind =3D=3D HID_KEYBOARD) { + p->actual_length =3D hid_keyboard_write(hs, data, length); + } else { + goto fail; + } } break; case HID_GET_PROTOCOL: diff --git a/include/hw/input/hid.h b/include/hw/input/hid.h index b7cdeb54c2..458aa07cae 100644 --- a/include/hw/input/hid.h +++ b/include/hw/input/hid.h @@ -7,6 +7,8 @@ #define HID_TABLET 2 #define HID_KEYBOARD 3 =20 +#define HID_WHEEL_RESOLUTION_MULTIPLIER 120 + typedef struct HIDPointerEvent { int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */ int32_t dz, buttons_state; @@ -23,6 +25,8 @@ typedef void (*HIDEventFunc)(HIDState *s); typedef struct HIDMouseState { HIDPointerEvent queue[QUEUE_LENGTH]; int mouse_grabbed; + uint8_t wheel_multiplier; + uint8_t pan_multiplier; int32_t wheel_residual; int32_t pan_residual; bool wheel_state_loaded; --=20 2.56.0 From nobody Mon Nov 23 04:29:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1793130256; cv=none; d=zohomail.com; s=zohoarc; b=ABl5A6nEVxXM4/yDmdxgCtcyxlEZKdR/KCeLMnVQ80jrrvs2NzLwQIV4fItUAbAv4Ou+O/3VyD9tWAtHCLJRe7kkhIiNAz3S98/pRJv16Xf0yXc/rYzdF4pLU7HDWO3fbkSjQwVFeNtCYJOwCakPXprwrhAtqYHRcrfWo1r9DyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793130256; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hLIiTwiniZVNxB7/lQ0mjV3mimZDp0FZmcqxP3kuF9k=; b=Db5bfMv2OIZACTNbPyA0rIprlnIYLwvtnm84Y7mxrK2+pGhEDB5ajnXFbQlUCnGR1yld9pT9px3y6ALkr/RZ9yiIMKB0JbdrFc91dHvSgXY97W+nE8gEjnWLZj4fuDyeKuPQVOCKh73Pg+VPpROVQTCnAL60c/TO2+/d3p1WUQg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793130256924767.4820820890747; Tue, 27 Oct 2026 12:44:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLn5F-00070K-3p; Tue, 27 Oct 2026 15:43:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLn5D-0006wW-0c for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:43 -0400 Received: from mail-dy2-x0b.google.com ([2607:f8b0:4864:36::b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLn5B-0003up-G3 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 15:43:42 -0400 Received: by mail-dy2-x0b.google.com with SMTP id 5a478bee46e88-36a1e794908so45900eec.1 for ; Tue, 27 Oct 2026 12:43:41 -0700 (PDT) Received: from fedora.tail9bb79b.ts.net ([119.82.106.50]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36a064510b0sm20446558eec.2.2026.10.27.12.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 12:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793130220; x=1793735020; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hLIiTwiniZVNxB7/lQ0mjV3mimZDp0FZmcqxP3kuF9k=; b=FzQH8AVPmaS0fL//kA7WURn8J2TWRal2d0w3tfi1IIt8SD0A5HVZT8srpyp/3RXBKG vQ+JUbGutFpxw3AlVxnuRsr8ciqZRQDnVB9Gw+KA4/Q6EMTJl7Wccp5uuOHhkLoEd89A JY9YGlt6TL8ZLrAOL71HPx7e1ysWmzQvQSNaU+qkzcm9ymMqSmvunMLE7WdGsVUwyqq0 zQUFXfwet05no+vCO39AxzZbmTHL1Y+fS1hrJrjg0C/hGCrMYCd8IYjxqaRbvI8FrbnL 6xQXrCM47OZ/8G4CGUhwCDa+cVoAZJba7QFW92StKMyHjN31Z1/OnttXJ75zFjYYxIzu MXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793130220; x=1793735020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=hLIiTwiniZVNxB7/lQ0mjV3mimZDp0FZmcqxP3kuF9k=; b=keC23C3S/igc9mjl1RpxTY2yaUeFP76zOm3kZKFLEn+In0EOic1Vj1lZHtqSRr4ubg 1fEd7mURGIsOlNeywieNF8PvQ3limCltFXPU7LHHVi08lOxC61WG6U+whmkG7y6STSkq FxlQJfkiUvP5K/dHKRPFKIgvtVYVrWqKXtwomlY5khjMyt+K+Bve2HkxwFHkZkrMkSUN NNCm/QIB6oSYTUkD/4ymc/bJIuXaQFI5N0vO+oDiEX7anJF3HhqOr1cKDXqWnAf56CUp LvUPu8RqED5HxUHOC0w1gnSg+fcRDnR1dLjEgCTeIuAC5FynOuBWrRiTBxbIo0PJURwB L8ag== X-Forwarded-Encrypted: i=1; AKwUvBw5T+JeS4SJbVLcLPqmDsy0W0013bRk4YWfJDCmh4RorhAN2nqZS4Knq/qAzYySg3f50TlS/YAA0dGA@nongnu.org X-Gm-Message-State: AFq9FYJ7ucS48uY76O+pNZHvEdGTh+2O8aCIeIRt/FYjzx/ETjLzsH8R RgNyXVSe8nODk8B259Wg2Bx/C5rMZeOs2jbLQrrO8OBbGE65osvQwCFT7VwmDPVapl4= X-Gm-Gg: AYBFou20FZtACepCVfpqGP7ULX1y8blsZnN/edakJm4sd3vCS7thybYTGAlAsFPxahr dAXy8F23bKK+Pp868KgPFQpBSqEVgGBPokTvbU2m2OT23+01+YJb1qFU8Ge8AbyiX49ZTbp0hfn K8w4v1CaRj++ZlEqA8xj3XoqrUFa7PbS1DAsoIFNPNvosDHng8bpULZT0a3+It1WK9HSdtztzPk uUddM3NZn03CRAJrML5oGnv69RWkE6CB6RZ2omlcdM5dlyOUkdAjiCV5xLU5lakDGNG/tk4HPR1 tmh9a4us9uQ/TM5TVn3LP52bjKVCA39PO7NG38G2tmX9WbxqeBef4VQp8H8kwi/GhPxM6sOL5Rg 2e9NuJQRh+fBBS3nJd2szcbUYqrCcEz4XoK/Ad2yVWKHpoGKMB2y2Ngauur9x8DtDBbxG3LJ8IK Ym5T3HMrWS21uBmRrMicc5EHNHs/rrk4NZFP3SddPKKFBPmFVO858ycmLNQAoI0TDUw6uC7ILHj 3qYfaFGOAKIzLCPy3XaCdLHTo+I9nqvejXjd+Bvq4QGoXIzWaoXVm1ObhLtHoYN+teGcfdR8w97 gkLaqDRXA8BUtUMCZUzxrLiswWbO/aqjAPVSpTHf2hjrkLtVWBWMVKCDkmbhIUZmlhsY6Rbwtvr bz+ABhv4W9xMcCYehWI3spEXTxttfLIoOluSnBFQawHtzTsVtwQ== X-Received: by 2002:a05:7301:4b09:b0:36a:1938:8508 with SMTP id 5a478bee46e88-36a2016e243mr540962eec.38.1793130219959; Tue, 27 Oct 2026 12:43:39 -0700 (PDT) From: soumyajyotisarkar23@gmail.com To: sarkarsoumyajyoti23@gmail.com, qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Helge Deller , Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Soumyajyotii Ssarkar , Helge Deller Subject: [PATCH v2 8/8] hw/input/hid: clear wheel state and mouse_grabbed on reset Date: Wed, 28 Oct 2026 01:12:56 +0530 Message-ID: <20261027194256.76031-9-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> References: <20261027194256.76031-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:36::b; envelope-from=soumyajyotisarkar23@gmail.com; helo=mail-dy2-x0b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793130257252158500 Content-Type: text/plain; charset="utf-8" From: Soumyajyotii Ssarkar hid_reset() clears the pointer event queue but leaves the rest of the mouse state alone. After a guest reboot the wheel and pan multipliers the previous guest enabled would stay in effect and leftover residuals would leak into the first reports of the new boot. Reset the multipliers and residuals together with the queue. Also clear mouse_grabbed, so that hid_pointer_activate() activates the input handler again when the rebooted guest first polls the device, instead of keeping the state from before the reset. Suggested-by: Helge Deller Signed-off-by: Soumyajyotii Ssarkar --- hw/input/hid.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/input/hid.c b/hw/input/hid.c index bc84e99dbc..403cac127e 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -551,6 +551,11 @@ void hid_reset(HIDState *hs) case HID_MOUSE: case HID_TABLET: memset(hs->ptr.queue, 0, sizeof(hs->ptr.queue)); + hs->ptr.mouse_grabbed =3D 0; + hs->ptr.wheel_multiplier =3D 0; + hs->ptr.pan_multiplier =3D 0; + hs->ptr.wheel_residual =3D 0; + hs->ptr.pan_residual =3D 0; break; } hs->head =3D 0; --=20 2.56.0