From nobody Fri May 3 00:40:20 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=free.fr ARC-Seal: i=1; a=rsa-sha256; t=1686253751; cv=none; d=zohomail.com; s=zohoarc; b=RlgBFA3MxvOAmyyQgab2KouzQzhK7lq90/JCaK+apQsRE/dnc239WJaH9mw5LcnFgGxZ57MvUZW53ksgz5qRb4w8FJAQOVUdvHOB7piroWb/ldIOk5xG4jojD053pxSx7AGXfr5xL9URSt7v9/CubTg+WJ4Mk8b1L3urrw13rkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686253751; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=NPoWACTtG5snHvA5hqxUywSFObP2Y49FHiDgDLLrmNY=; b=hvjbsT9zetEF6nBrzU/Qj30QH/SC5ZLotwG9Ln4zhCFMseI59+6LIbu1xcYni0s1S+31z9bSyU4in2fpdatHOAjNmoxVLk7g2fyvWIPw2Huqyyx4gyJFge0f7eMZ5+f9EY9RGIKH6z0SMEvayLWMtc0lQp4a+fLANCMhzmH1+WI= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1686253751105964.2375780420914; Thu, 8 Jun 2023 12:49:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7Lcr-0005io-L6; Thu, 08 Jun 2023 15:48:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7Lcp-0005ZG-Lq for qemu-devel@nongnu.org; Thu, 08 Jun 2023 15:48:51 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7Lcm-0005ew-SG for qemu-devel@nongnu.org; Thu, 08 Jun 2023 15:48:51 -0400 Received: from asub.. (unknown [198.16.189.195]) (Authenticated sender: lucas.chollet@free.fr) by smtp2-g21.free.fr (Postfix) with ESMTPSA id BDF992003DD; Thu, 8 Jun 2023 21:48:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1686253726; bh=Uof9DIkGtWXRDu1ZoX5EIg56ovWdmJYmIrAd9zwy5mc=; h=From:To:Cc:Subject:Date:From; b=s+McuU2ee0i2Es4rIBBAuXIpi02q0GV93bHpG2qsFisiFhOG1Ebjzf4UDWdTmsLKl P4Q3tqKBr0BX+XmM4iQBABRSwnz9olR118XF2cE4Rqytuq4XZdqzqWLny8+ERq+rsK JZl+8tonGnmiF8E/C1W7LpO3z9TLL3wm78xON/82EzFtxF1K1ZxhvLkF4EjNV4UrCK dDHsSb+JVG41A9b4Oo2WA6OLOh+NaaVQOOFEbBRGyB4A7bf1/lBVAlpwMLaqm077gG 17Mo3J9a7Y9C1yt4VJDGHf/plTHc88Lgf3UF1BgFjaKLrknwO1lq1BgqAffZkhCHzL 5qfMnGQTJXI+Q== From: Lucas Chollet To: qemu-devel@nongnu.org Cc: Lucas Chollet , "Michael S. Tsirkin" , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH] hw/i386/vmmouse: use the new input api Date: Thu, 8 Jun 2023 15:47:00 -0400 Message-Id: <20230608194658.711387-1-lucas.chollet@free.fr> X-Mailer: git-send-email 2.39.2 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.27.42.2; envelope-from=lucas.chollet@free.fr; helo=smtp2-g21.free.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @free.fr) X-ZM-MESSAGEID: 1686253753270100007 Content-Type: text/plain; charset="utf-8" No functional changes intended. Signed-off-by: Lucas Chollet --- Hey, this is my first patch submission to QEMU so I made a small =20 patch to start with. I tried to make sure that I followed all rules to submit the patch, but I might have missed something, please tell me if something is wrong. I think that I have properly tested my patch but don't hesitate to ask me to do more test or verify edge cases. Have a nice day - and review :^) Lucas hw/i386/vmmouse.c | 95 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index a56c185f15..bdddbb64ac 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -24,7 +24,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" -#include "ui/console.h" +#include "ui/input.h" #include "hw/i386/vmport.h" #include "hw/input/i8042.h" #include "hw/qdev-properties.h" @@ -61,7 +61,10 @@ struct VMMouseState { uint16_t nb_queue; uint16_t status; uint8_t absolute; - QEMUPutMouseEntry *entry; + int32_t last_x; + int32_t last_y; + int32_t last_buttons; + QemuInputHandlerState *entry; ISAKBDState *i8042; }; =20 @@ -91,33 +94,72 @@ static uint32_t vmmouse_get_status(VMMouseState *s) return (s->status << 16) | s->nb_queue; } =20 -static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int bu= ttons_state) +static void vmmouse_mouse_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - VMMouseState *s =3D opaque; - int buttons =3D 0; + static const int bmap[INPUT_BUTTON__MAX] =3D { + [INPUT_BUTTON_LEFT] =3D 0x20, + [INPUT_BUTTON_MIDDLE] =3D 0x08, + [INPUT_BUTTON_RIGHT] =3D 0x10, + }; + + VMMouseState *s =3D VMMOUSE(dev); + InputMoveEvent *move; + InputBtnEvent *btn; + + int32_t dz =3D 0; =20 if (s->nb_queue > (VMMOUSE_QUEUE_SIZE - 4)) return; =20 - DPRINTF("vmmouse_mouse_event(%d, %d, %d, %d)\n", - x, y, dz, buttons_state); + switch (evt->type) { + case INPUT_EVENT_KIND_REL: + move =3D evt->u.rel.data; + if (move->axis =3D=3D INPUT_AXIS_X) { + s->last_x +=3D move->value; + } else if (move->axis =3D=3D INPUT_AXIS_Y) { + s->last_y -=3D move->value; + } + break; =20 - if ((buttons_state & MOUSE_EVENT_LBUTTON)) - buttons |=3D 0x20; - if ((buttons_state & MOUSE_EVENT_RBUTTON)) - buttons |=3D 0x10; - if ((buttons_state & MOUSE_EVENT_MBUTTON)) - buttons |=3D 0x08; + case INPUT_EVENT_KIND_ABS: + move =3D evt->u.rel.data; + if (move->axis =3D=3D INPUT_AXIS_X) { + s->last_x =3D move->value; + } else if (move->axis =3D=3D INPUT_AXIS_Y) { + s->last_y =3D move->value; + } + break; =20 - if (s->absolute) { - x <<=3D 1; - y <<=3D 1; + case INPUT_EVENT_KIND_BTN: + btn =3D evt->u.btn.data; + if (btn->down) { + s->last_buttons |=3D bmap[btn->button]; + if (btn->button =3D=3D INPUT_BUTTON_WHEEL_UP) { + dz--; + } else if (btn->button =3D=3D INPUT_BUTTON_WHEEL_DOWN) { + dz++; + } + + } else { + s->last_buttons &=3D ~bmap[btn->button]; + } + break; + + default: + /* keep gcc happy */ + break; } =20 - s->queue[s->nb_queue++] =3D buttons; - s->queue[s->nb_queue++] =3D x; - s->queue[s->nb_queue++] =3D y; + s->queue[s->nb_queue++] =3D s->last_buttons; + s->queue[s->nb_queue++] =3D s->absolute ? s->last_x << 1 : s->last_x; + s->queue[s->nb_queue++] =3D s->absolute ? s->last_y << 1 : s->last_y; s->queue[s->nb_queue++] =3D dz; +} + +static void vmmouse_mouse_sync(DeviceState *dev) +{ + VMMouseState *s =3D VMMOUSE(dev); =20 /* need to still generate PS2 events to notify driver to read from queue */ @@ -127,11 +169,18 @@ static void vmmouse_mouse_event(void *opaque, int x, = int y, int dz, int buttons_ static void vmmouse_remove_handler(VMMouseState *s) { if (s->entry) { - qemu_remove_mouse_event_handler(s->entry); + qemu_input_handler_unregister(s->entry); s->entry =3D NULL; } } =20 +static QemuInputHandler vm_mouse_handler =3D { + .name =3D "vmmouse", + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_ABS, + .event =3D vmmouse_mouse_event, + .sync =3D vmmouse_mouse_sync, +}; + static void vmmouse_update_handler(VMMouseState *s, int absolute) { if (s->status !=3D 0) { @@ -142,10 +191,8 @@ static void vmmouse_update_handler(VMMouseState *s, in= t absolute) vmmouse_remove_handler(s); } if (s->entry =3D=3D NULL) { - s->entry =3D qemu_add_mouse_event_handler(vmmouse_mouse_event, - s, s->absolute, - "vmmouse"); - qemu_activate_mouse_event_handler(s->entry); + s->entry =3D qemu_input_handler_register(DEVICE(s), &vm_mouse_hand= ler); + qemu_input_handler_activate(s->entry); } } =20 --=20 2.39.2