From patchwork Tue Mar 5 11:05:59 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: 777969 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c8:0:b0:33e:474f:8c56 with SMTP id p8csp372077wrs; Tue, 5 Mar 2024 03:07:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX2ynoMRT/JWI+JGPasUHh/cTWmVIuZ2RbZau3Dm8e5blabkFZfBGK8M8zlKFQTqQcUO6eQ17OVXxmxkYSyN09w X-Google-Smtp-Source: AGHT+IETvsksQaNX2bUfd2jNDqa23uBI+9TGbnVuiwsFV34E0vaiUfbyQKdHPmr4YAId/Nm4AhvF X-Received: by 2002:a0c:e64f:0:b0:68f:ecde:f13b with SMTP id c15-20020a0ce64f000000b0068fecdef13bmr1662117qvn.62.1709636864776; Tue, 05 Mar 2024 03:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709636864; cv=none; d=google.com; s=arc-20160816; b=ghnbaXeJ7ikqhsMpDEeo2w4fyO8BhMhrPGvtnADucbLyEZbYZ2JLMck4mVXnTCHM8f KnOj7yzZuKh84XNfgvTObRU4jyyvgxhpORoLqTH2151QPF/LaRXwHbLqI1/KrBiOhREN i4CmTNgmBwpQkwJ5nFjPy2ibZeURnnf8LgCpbvXGyLo9334gYT9WdGnfjqAJ/OjdXsC6 taLICVgUHdxpq4Nnw3LpVpiCfQ/uMxpS2g7+ts8J7wsXaIUW2Qtdkyof0cdKJh3lZLbn 7tFOCbXVLUrEsyNnW3eFRaJj2d9lVsViXTsKP7ivITfdttZ/XS2MKfAaFkr+ajjqSbtb b+Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=YcMZ2wZGvgIXnfKqMdotL5RtUlqFDTHW5fA4eDcdqEc=; fh=tK/W4RaLE17XRjbSJYnFJv8/opvalIcV7yKc21wdriw=; b=irCJUvEVab/giPBq1FeXlnEfWlygrhWqDj516jP+LZ7phNq/mTaO6SQ46U9LHjTuq6 tSD7vkBfqsnkJDuC+/JMjW1C466T4aEIlA1452lYdMZcln8vMSAsBv8xZce9XmpAlNXM Nd4wlFyvvZGbFt4+gnypjIYWNMCjOrvJTYKY/51ToY1xEnqZ0rkCdFfo7szRC9v2rfZ6 xoqVllwa8vBpHoiWUdeE645fSm162R3h1fqs/264sEC83RND31lwQqEbVklFCiooE1oJ OK+Js7ZsZw9d1bWv5g6ZoyQC+T1QITcHhR+Fi2Z6QFMA9oiS/JpFvvpM1hH6PVZyjWBC y6YQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CjnwW2QL; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gs11-20020a056214226b00b0068fff3e72ccsi11647589qvb.372.2024.03.05.03.07.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Mar 2024 03:07:44 -0800 (PST) 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=CjnwW2QL; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhSdM-0007va-V6; Tue, 05 Mar 2024 06:06:57 -0500 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 1rhSdB-0007kJ-AM for qemu-devel@nongnu.org; Tue, 05 Mar 2024 06:06:46 -0500 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhSd2-0002lv-KG for qemu-devel@nongnu.org; Tue, 05 Mar 2024 06:06:45 -0500 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-563c595f968so8191737a12.0 for ; Tue, 05 Mar 2024 03:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709636794; x=1710241594; 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=YcMZ2wZGvgIXnfKqMdotL5RtUlqFDTHW5fA4eDcdqEc=; b=CjnwW2QLx3Djf0SsoP0rzi7iAFmrQb5TNCVC5zHA3jkvm++aXjmOfki/i10wA1bvbn SHJmvnEirX61CQ9q7KnyxvasTSp1RvhnqkSC+NhD406daZTcB9G2HzVmSPFbQe6fErfN e+JF0Kb1WArODkOrS8Pfayjb6/Qh0Q2eRDzJ1WKm2E2uZRvmRDa41PY4t8YzOblUl6ND 6l8xx89/BA7HToTey8RFqgmpJ2kIzOHwKoCSSUHIGxRzy/+D4vEcYA/mwOjN39II375n sxQDZ5Ike23TVbswhPwQ74ykFNo0uDgFtCxNXBsgri1V7FDww0e7GqxAWkBahkJloymV Mwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709636794; x=1710241594; 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=YcMZ2wZGvgIXnfKqMdotL5RtUlqFDTHW5fA4eDcdqEc=; b=cvqFnvrILZ8fOwe0QuWc/CsqPu5dhV/2OG3qpjbogNQic+isYFfFh5QD7rNbsI9Bvq is4VOrtICIdy8s61kKUmI00nVGByd0pfjumtbDDiwDCcr8EnznH55ETSCyaKygM8+TCa Chtt/f4aayEPwCgjygGqS6hCcK3mtFFgrOVTC13csG7ITGsfQze2XcmjrqqHPzRsvpua j0msDKeodd6JjNNy3Yo/4Y9/Xxu6RScW/rsDqNX9W985NYHOdZSQ7d+Kci5u8GaYHs/q df22hWEfVL/0ZdPxM8vhhMW8e3SgdzSjImsuNAgLwCO5AJ3vEmDyfjlJYOtqieRtl7/j XfHw== X-Gm-Message-State: AOJu0Yw9euMNTEyGVyEpcvTxUZLn9AZ2V+tiUV8z6W8C+3IFOqU3FIxl JcoGPXkTFJpnjcm3dVxCU5V10SN3NIxoFs0lAITguvyVKGoDeRjmar27anDEcAF6SZP17zrpjVw / X-Received: by 2002:a17:906:8301:b0:a43:dae8:d43c with SMTP id j1-20020a170906830100b00a43dae8d43cmr7634044ejx.32.1709636794677; Tue, 05 Mar 2024 03:06:34 -0800 (PST) Received: from m1x-phil.lan ([176.176.177.70]) by smtp.gmail.com with ESMTPSA id ag3-20020a1709069a8300b00a44790d06d3sm4990914ejc.71.2024.03.05.03.06.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 05 Mar 2024 03:06:34 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Peter Maydell , Rene Engel , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PULL 04/12] ui/cocoa: Immediately call [-QemuCocoaView handleMouseEvent:buttons:] Date: Tue, 5 Mar 2024 12:05:59 +0100 Message-ID: <20240305110608.21618-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240305110608.21618-1-philmd@linaro.org> References: <20240305110608.21618-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=philmd@linaro.org; helo=mail-ed1-x52e.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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Instead of using mouse_event variable to tell to handle a mouse event later, immediately call [-QemuCocoaView handleMouseEvent:buttons:]. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Tested-by: Rene Engel Message-ID: <20240224-cocoa-v12-2-e89f70bdda71@daynix.com> Signed-off-by: Philippe Mathieu-Daudé --- ui/cocoa.m | 87 +++++++++++++++++++----------------------------------- 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index aecd60df2a..ff6486093c 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -807,9 +807,8 @@ - (bool) handleEventLocked:(NSEvent *)event { /* Return true if we handled the event, false if it should be given to OSX */ COCOA_DEBUG("QemuCocoaView: handleEvent\n"); - int buttons = 0; + InputButton button; int keycode = 0; - bool mouse_event = false; // Location of event in virtual screen coordinates NSPoint p = [self screenLocationOfEvent:event]; NSUInteger modifiers = [event modifierFlags]; @@ -955,7 +954,7 @@ - (bool) handleEventLocked:(NSEvent *)event } break; } - break; + return true; case NSEventTypeKeyDown: keycode = cocoa_keycode_to_qemu([event keyCode]); @@ -991,7 +990,7 @@ - (bool) handleEventLocked:(NSEvent *)event } else { [self handleMonitorInput: event]; } - break; + return true; case NSEventTypeKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]); @@ -1004,7 +1003,7 @@ - (bool) handleEventLocked:(NSEvent *)event if (qemu_console_is_graphic(NULL)) { qkbd_state_key_event(kbd, keycode, false); } - break; + return true; case NSEventTypeMouseMoved: if (isAbsoluteEnabled) { // Cursor re-entered into a window might generate events bound to screen coordinates @@ -1020,34 +1019,20 @@ - (bool) handleEventLocked:(NSEvent *)event } } } - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:0]; case NSEventTypeLeftMouseDown: - buttons |= MOUSE_EVENT_LBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_LBUTTON]; case NSEventTypeRightMouseDown: - buttons |= MOUSE_EVENT_RBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_RBUTTON]; case NSEventTypeOtherMouseDown: - buttons |= MOUSE_EVENT_MBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_MBUTTON]; case NSEventTypeLeftMouseDragged: - buttons |= MOUSE_EVENT_LBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_LBUTTON]; case NSEventTypeRightMouseDragged: - buttons |= MOUSE_EVENT_RBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_RBUTTON]; case NSEventTypeOtherMouseDragged: - buttons |= MOUSE_EVENT_MBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:MOUSE_EVENT_MBUTTON]; case NSEventTypeLeftMouseUp: - mouse_event = true; if (!isMouseGrabbed && [self screenContainsPoint:p]) { /* * In fullscreen mode, the window of cocoaView may not be the @@ -1058,53 +1043,41 @@ - (bool) handleEventLocked:(NSEvent *)event [self grabMouse]; } } - break; + return [self handleMouseEvent:event buttons:0]; case NSEventTypeRightMouseUp: - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:0]; case NSEventTypeOtherMouseUp: - mouse_event = true; - break; + return [self handleMouseEvent:event buttons:0]; case NSEventTypeScrollWheel: /* * Send wheel events to the guest regardless of window focus. * This is in-line with standard Mac OS X UI behaviour. */ - /* - * We shouldn't have got a scroll event when deltaY and delta Y - * are zero, hence no harm in dropping the event - */ - if ([event deltaY] != 0 || [event deltaX] != 0) { /* Determine if this is a scroll up or scroll down event */ - if ([event deltaY] != 0) { - buttons = ([event deltaY] > 0) ? + if ([event deltaY] != 0) { + button = ([event deltaY] > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN; - } else if ([event deltaX] != 0) { - buttons = ([event deltaX] > 0) ? + } else if ([event deltaX] != 0) { + button = ([event deltaX] > 0) ? INPUT_BUTTON_WHEEL_LEFT : INPUT_BUTTON_WHEEL_RIGHT; - } - - qemu_input_queue_btn(dcl.con, buttons, true); - qemu_input_event_sync(); - qemu_input_queue_btn(dcl.con, buttons, false); - qemu_input_event_sync(); + } else { + /* + * We shouldn't have got a scroll event when deltaY and delta Y + * are zero, hence no harm in dropping the event + */ + return true; } - /* - * Since deltaX/deltaY also report scroll wheel events we prevent mouse - * movement code from executing. - */ - mouse_event = false; - break; + qemu_input_queue_btn(dcl.con, button, true); + qemu_input_event_sync(); + qemu_input_queue_btn(dcl.con, button, false); + qemu_input_event_sync(); + + return true; default: return false; } - - if (mouse_event) { - return [self handleMouseEvent:event buttons:buttons]; - } - return true; } - (bool) handleMouseEvent:(NSEvent *)event buttons:(uint32_t)buttons