From nobody Sun Nov 24 08:02:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725446636536898.1630067752765; Wed, 4 Sep 2024 03:43:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slnRN-00040Q-DU; Wed, 04 Sep 2024 06:40:45 -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 1slnRI-0003KN-8p; Wed, 04 Sep 2024 06:40:40 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slnRE-0000HO-4l; Wed, 04 Sep 2024 06:40:39 -0400 Received: from [2a02:8012:c93d:0:260e:bf57:a4e9:8142] (helo=cheesecake.fritz.box) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1slnQo-0002Ly-Tb; Wed, 04 Sep 2024 11:40:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: Message-Id:Date:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=q5vrSqwIdUHVmeZ5blcGcrtyUoI6ExqoUNdJbrXQlrI=; b=EkjLcihPptEioJ8CFCEv04PCHF 9mT9m1azkrSZ9Byfvv4+IBuC2G7ScUY3Kk+DD5SqSQWKhPZdEBWNP83d2JFu2IsIq7QroZYRAcL7R kYWukpKLdwpRZ+LH3fBk2rJo+sk8uqZjzhRQCaPILvSbkgowc9mN4oEYXLOV9zAWeAp4C4ErducxM 7NPkM0RbXrlm+glMig1Bh2uxQMgTZqIPOauJ2LzAyRCTWcN2OMmtisCHCYi8gDXjpvlIZ+XGPgtZR gqcqoJlgu6z+sFihs/hS6PwLUXznDGNzmu0MVNbZvtjXdIJkTufvO22J87KGX5BWv+jpygOHa6bRE S4sppV9lkmqL7SpciE5U4hsu7OBi7ORTEEDv6HiOrGGfgxZq6QHvQ/yJuP2Wb6SQH0Lku2OnmEgiK IWOEoZhBo5H339om45sfLA+Dt5GSVzcIjdu573Zqf8dLpyn3Bea5dcYVWDFBdI0W9O5u6vYfz93FI f1acM7ZvAded9OCx6Xg3A+KaJ1pquD6xEHGqKmxQbFE4CGmdr8yDbwsLorHVyBUkF7NOM+JmchqCB BTjCw8v6uWLAsXi22u7PuFBR9Kt+MfZowdJA/B1/pZoOoPHAyoYhKkFaLwZ+0dQPXUbv4vOAaOcDW s7ZEq7QwIPNGNj22nCc1kEkiwPIix73tJfZcyua5Q=; From: Mark Cave-Ayland To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, hsp.cat7@gmail.com Date: Wed, 4 Sep 2024 11:40:07 +0100 Message-Id: <20240904104007.177239-1-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a02:8012:c93d:0:260e:bf57:a4e9:8142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH] adb-mouse: convert to use QemuInputHandler X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=lists.gnu.org; Received-SPF: pass client-ip=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1725446637215116600 Content-Type: text/plain; charset="utf-8" Update the ADB mouse implementation to use QemuInputHandler instead of the legacy qemu_add_mouse_event_handler() function. Signed-off-by: Mark Cave-Ayland --- hw/input/adb-mouse.c | 56 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/hw/input/adb-mouse.c b/hw/input/adb-mouse.c index 144a0ccce7..7aa36caf2f 100644 --- a/hw/input/adb-mouse.c +++ b/hw/input/adb-mouse.c @@ -38,6 +38,7 @@ struct MouseState { ADBDevice parent_obj; /*< private >*/ =20 + QemuInputHandlerState *hs; int buttons_state, last_buttons_state; int dx, dy, dz; }; @@ -51,17 +52,52 @@ struct ADBMouseClass { DeviceRealize parent_realize; }; =20 -static void adb_mouse_event(void *opaque, - int dx1, int dy1, int dz1, int buttons_state) +#define ADB_MOUSE_BUTTON_LEFT 0x01 +#define ADB_MOUSE_BUTTON_RIGHT 0x02 + +static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - MouseState *s =3D opaque; + MouseState *s =3D (MouseState *)dev; + InputMoveEvent *move; + InputBtnEvent *btn; + static const int bmap[INPUT_BUTTON__MAX] =3D { + [INPUT_BUTTON_LEFT] =3D ADB_MOUSE_BUTTON_LEFT, + [INPUT_BUTTON_RIGHT] =3D ADB_MOUSE_BUTTON_RIGHT, + }; + + switch (evt->type) { + case INPUT_EVENT_KIND_REL: + move =3D evt->u.rel.data; + if (move->axis =3D=3D INPUT_AXIS_X) { + s->dx +=3D move->value; + } else if (move->axis =3D=3D INPUT_AXIS_Y) { + s->dy +=3D move->value; + } + break; + + case INPUT_EVENT_KIND_BTN: + btn =3D evt->u.btn.data; + if (bmap[btn->button]) { + if (btn->down) { + s->buttons_state |=3D bmap[btn->button]; + } else { + s->buttons_state &=3D ~bmap[btn->button]; + } + } + break; =20 - s->dx +=3D dx1; - s->dy +=3D dy1; - s->dz +=3D dz1; - s->buttons_state =3D buttons_state; + default: + /* keep gcc happy */ + break; + } } =20 +static const QemuInputHandler adb_mouse_handler =3D { + .name =3D "QEMU ADB Mouse", + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, + .event =3D adb_mouse_handle_event, +}; =20 static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) { @@ -94,10 +130,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) dx &=3D 0x7f; dy &=3D 0x7f; =20 - if (!(s->buttons_state & MOUSE_EVENT_LBUTTON)) { + if (!(s->buttons_state & ADB_MOUSE_BUTTON_LEFT)) { dy |=3D 0x80; } - if (!(s->buttons_state & MOUSE_EVENT_RBUTTON)) { + if (!(s->buttons_state & ADB_MOUSE_BUTTON_RIGHT)) { dx |=3D 0x80; } =20 @@ -236,7 +272,7 @@ static void adb_mouse_realizefn(DeviceState *dev, Error= **errp) =20 amc->parent_realize(dev, errp); =20 - qemu_add_mouse_event_handler(adb_mouse_event, s, 0, "QEMU ADB Mouse"); + s->hs =3D qemu_input_handler_register((DeviceState *)s, &adb_mouse_han= dler); } =20 static void adb_mouse_initfn(Object *obj) --=20 2.39.2