From patchwork Wed Sep 11 12:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 827405 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp763930wrc; Wed, 11 Sep 2024 05:20:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUDTXXwDhi+MmsewcIq1HZE/xs1jMRPPjiewsBoM+NdhgwYoAmuAENGUNpiRDUKg93d96coiQ==@linaro.org X-Google-Smtp-Source: AGHT+IEx/9DcpUmMTH3pGBjLj6GMChW9IilL7O1+NtpUsHknapqTHYXtRS9H5+szZoFo0O74wtva X-Received: by 2002:a05:622a:1313:b0:458:4465:d6b4 with SMTP id d75a77b69052e-4584465d962mr77555671cf.13.1726057216275; Wed, 11 Sep 2024 05:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726057216; cv=none; d=google.com; s=arc-20240605; b=jXowWSaoF9dF3ULo6RKuq7EnJEgEddydb92qt/Vz0z0otiyCGkS851GeMxxevye+sy GOlR0AAZ3d526d9lF2bWBeX+X2deqpBn+xCBQ/wtPsv1LpP7n9rKJKvBmQVBSgoBhj3u zUCgeaZhbMH4mGoUcRiM4H6rrBN/sBaGwO0ziwMr9hx21Cn7eeRE5mKt6qnTGrWlyzPI tMEgpO7S64X8aWewGEpHNs3wE9fu3riipxx8dlXb0KDH5CuQhOPOLb/Im/XkPlu+H+Cu aeIlxsl7q03aLO7TTayOTigXkZFdGo15mCACApkC09WZ9aX7HQmMKXc0wH0SsUy17xrM io8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5uAYQOz0f3NUUgtgEDr3l2InET86j9EqdXcrrlozEfg=; fh=J4M4Z4TZxvAT8lkmK1LtxqMjpO7Qiod4IMBL2bk0hxA=; b=FxFg9SBBuihOAVuf4lAA6tz5kSq8goWnr124O6nuhamPwgp0g5FBtQdkLo70fsQO22 19a/eee7/+M5ooliWHKkyLPp0vQDhJoDuj4UIwAKnSciGpXHvI4npErIylCH+LcnE2V1 h6BgIE24yOvkSd5f7ltjbziwAG70BDhukARarGxuRFD9HZfiKXkk9cOLIDffQuGrnFI6 X7570z7LLCMh8PsacTiDmkj52OGO7iWYh419wZZ1Rz6tZwdIo0K92WSpO6pcZQhoCIVU mh0UwaFAEeExhk5ETepXkDCRKy2+1tVRT786Opo0f1vIGlrhCtR8N7fOABa/kXs4Ck+J ES/A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hGImCzJs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822f809a6si100731231cf.414.2024.09.11.05.20.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2024 05:20:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hGImCzJs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMJz-0003lw-9L; Wed, 11 Sep 2024 08:19:43 -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 1soMJx-0003Mr-HH for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:19:41 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1soMJu-0007im-CE for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:19:41 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42cb58d810eso5117355e9.0 for ; Wed, 11 Sep 2024 05:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726057176; x=1726661976; 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; bh=5uAYQOz0f3NUUgtgEDr3l2InET86j9EqdXcrrlozEfg=; b=hGImCzJso1mf2mVeCB3eK/igCaUIZ4WxW4YNgxDAhXtGlQkleug2jAly+NguD2AgtR bKyOZ9YzY3LVBXjps0uhw6Xjr+m9z/IPNLdJXkdoF/XQ8WZLdTN/+di89NdIkOWi/Vy4 ine97XlS4rhTUFtn8H0GbHybmZ4Kx1XjxE8Pc9z3JQ6w5xzwqrekjGPMvJL2oSoMCMDJ qxyyREwrpGI3ojBhsFGVxPCYQLg6o9tmkhQS6CsgFf2i71L1CbqLydprNZR9/Sx0LRBY SlJlsg+trXE/1fZikQX05LQ2RvqwfI1Dc9ywU8yScRurd+9HU73k2mUYBbZwOJl8NVkE mE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726057176; x=1726661976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5uAYQOz0f3NUUgtgEDr3l2InET86j9EqdXcrrlozEfg=; b=BzlBlxAWmsdKou8E7sP26xl77X8x5cpDLpdqSFKCv1x52XLg6LacSuGtpMt+yIFS/W P2MVUKOqNE+2DI31Bw4JpOrejHE0CMgrDAgO6Cu8GMhLNRc7KuyFXHw0W9eUpXaAJ/94 lZbfUPvwW0tWgdlFpeoN3axXKoifZH0hn8U2MH/OGi3gDR4L1v0CNZhwGSHkbgz0cOPw u2MRKsDccYteDp4UXBeIoCBxaAnkZmSuI01gS+S0fHVQlESI7dNXKum0rdW3lfTVYl3Z 0e+NeTeoSRGypis9yzI7UTQ+EhFMiB3+jSD/MNW5zYSaNQFO61eBhZDAmQn0QXrTD1jj bzqw== X-Gm-Message-State: AOJu0YyXDOirHH6WSAvUD61AvnZhCPkgOLVxVtlsJSv3gphIYy8HJhFe kqZYFtERHivNDufTUGfCxvFLK1a9vNk2i2O/YrKGhIK+olJBlZ1m6jH5LF8mPkkEYeNvAVgwL3f Q X-Received: by 2002:a05:600c:450d:b0:426:5c36:f57a with SMTP id 5b1f17b1804b1-42cbde01a6emr39184285e9.14.1726057176347; Wed, 11 Sep 2024 05:19:36 -0700 (PDT) Received: from m1x-phil.lan ([176.187.196.107]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42caeb4444asm140839205e9.22.2024.09.11.05.19.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 11 Sep 2024 05:19:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= Subject: [PULL 45/56] hw/input/adb-mouse: convert to use QemuInputHandler Date: Wed, 11 Sep 2024 14:14:10 +0200 Message-ID: <20240911121422.52585-46-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240911121422.52585-1-philmd@linaro.org> References: <20240911121422.52585-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=philmd@linaro.org; helo=mail-wm1-x336.google.com 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, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mark Cave-Ayland Update the ADB mouse implementation to use QemuInputHandler instead of the legacy qemu_add_mouse_event_handler() function. Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20240907173700.348818-1-mark.cave-ayland@ilande.co.uk> [PMD: Add comment about .sync handler] Signed-off-by: Philippe Mathieu-Daudé --- hw/input/adb-mouse.c | 63 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/hw/input/adb-mouse.c b/hw/input/adb-mouse.c index 144a0ccce7..15e6e91804 100644 --- a/hw/input/adb-mouse.c +++ b/hw/input/adb-mouse.c @@ -38,6 +38,7 @@ struct MouseState { ADBDevice parent_obj; /*< private >*/ + QemuInputHandlerState *hs; int buttons_state, last_buttons_state; int dx, dy, dz; }; @@ -51,17 +52,57 @@ struct ADBMouseClass { DeviceRealize parent_realize; }; -static void adb_mouse_event(void *opaque, - int dx1, int dy1, int dz1, int buttons_state) -{ - MouseState *s = opaque; +#define ADB_MOUSE_BUTTON_LEFT 0x01 +#define ADB_MOUSE_BUTTON_RIGHT 0x02 - s->dx += dx1; - s->dy += dy1; - s->dz += dz1; - s->buttons_state = buttons_state; +static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) +{ + MouseState *s = (MouseState *)dev; + InputMoveEvent *move; + InputBtnEvent *btn; + static const int bmap[INPUT_BUTTON__MAX] = { + [INPUT_BUTTON_LEFT] = ADB_MOUSE_BUTTON_LEFT, + [INPUT_BUTTON_RIGHT] = ADB_MOUSE_BUTTON_RIGHT, + }; + + switch (evt->type) { + case INPUT_EVENT_KIND_REL: + move = evt->u.rel.data; + if (move->axis == INPUT_AXIS_X) { + s->dx += move->value; + } else if (move->axis == INPUT_AXIS_Y) { + s->dy += move->value; + } + break; + + case INPUT_EVENT_KIND_BTN: + btn = evt->u.btn.data; + if (bmap[btn->button]) { + if (btn->down) { + s->buttons_state |= bmap[btn->button]; + } else { + s->buttons_state &= ~bmap[btn->button]; + } + } + break; + + default: + /* keep gcc happy */ + break; + } } +static const QemuInputHandler adb_mouse_handler = { + .name = "QEMU ADB Mouse", + .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, + .event = adb_mouse_handle_event, + /* + * We do not need the .sync handler because unlike e.g. PS/2 where async + * mouse events are sent over the serial port, an ADB mouse is constantly + * polled by the host via the adb_mouse_poll() callback. + */ +}; static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) { @@ -94,10 +135,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) dx &= 0x7f; dy &= 0x7f; - if (!(s->buttons_state & MOUSE_EVENT_LBUTTON)) { + if (!(s->buttons_state & ADB_MOUSE_BUTTON_LEFT)) { dy |= 0x80; } - if (!(s->buttons_state & MOUSE_EVENT_RBUTTON)) { + if (!(s->buttons_state & ADB_MOUSE_BUTTON_RIGHT)) { dx |= 0x80; } @@ -236,7 +277,7 @@ static void adb_mouse_realizefn(DeviceState *dev, Error **errp) amc->parent_realize(dev, errp); - qemu_add_mouse_event_handler(adb_mouse_event, s, 0, "QEMU ADB Mouse"); + s->hs = qemu_input_handler_register(dev, &adb_mouse_handler); } static void adb_mouse_initfn(Object *obj)