From nobody Fri May 10 19:34:14 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1711104936; cv=none; d=zohomail.com; s=zohoarc; b=nuudDrKY7tg7dEgwPIv67AjExdhy8sHHP4vEfmVQqemMTfmALortK0xVhaDrAVpT/4QGh6ID4FYBOhdAoXoAaJMKJ0bP0MxAAkYVX5RO8W6W7vq+YbHaqFkb2QjDYS+t8FL6cre8wufOkbzdck7USZ3oJ8WiJOzON5bqQfqpOMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711104936; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=VTLbnQPEPDwoXUWi2uYp+x2vsIJP3Gey84NQIdKmYME=; b=Keyeu9M8u37nmVHQ/YbawiCzQoTlE8ZQfwblfQq3J2310hn7r9S2Ro/xll1xPmqhhKA8Ad0IuRE1IK/soR/in+PPkd3RCSJmt4BkUKkFKmHUE7TRuhqTTV3D7YdOvFijBCmEWXVzPYEQeX52V6ca2vMz9qYUP4Z2oPrxyO3ibE0= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1711104936445221.05678841970678; Fri, 22 Mar 2024 03:55:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rncXi-0001J5-Cw; Fri, 22 Mar 2024 06:54:34 -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 1rncXg-0001Id-ML for qemu-devel@nongnu.org; Fri, 22 Mar 2024 06:54:32 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rncXe-0005P2-R1 for qemu-devel@nongnu.org; Fri, 22 Mar 2024 06:54:32 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1e00896dfdcso12822565ad.1 for ; Fri, 22 Mar 2024 03:54:30 -0700 (PDT) Received: from localhost ([157.82.200.213]) by smtp.gmail.com with UTF8SMTPSA id k12-20020a170902f28c00b001def088c036sm1616860plc.19.2024.03.22.03.54.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 03:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1711104869; x=1711709669; darn=nongnu.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=VTLbnQPEPDwoXUWi2uYp+x2vsIJP3Gey84NQIdKmYME=; b=vRuFdnk7WGSeEz6UhaFKZBqgw7k5T6XYDHKBscK3DP9+dZyilvUJ/scxGY/qcmHedX sUMBVhLP8k10TzF130Bpu7bIAOK1SaEB6z/GkpeWrk4pJo7hdmdd8SB7KrtMn3MPoPNF /g04XV6PXz8pSC/WAkq31lYY7BttibD1UEbbyxxma5ztSYLrEJ+rOe7bldU87rpZTWlV QJGPRXAIc9zV0MWfbdx9NM5KqF8H64nCAJDbq9BGcm2bcbqZRip1vhrktstAvBID1TOL hAP9EEy30616ltZELkDpaMCH1bm+D3Qum1nl2JgZe7vsf4Tq7IPSMBcLhF3t5S93e3SN w3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711104869; x=1711709669; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VTLbnQPEPDwoXUWi2uYp+x2vsIJP3Gey84NQIdKmYME=; b=dvof88I8vHGx5zkAJor/JEZE/LmDG8kxrOJNq4mZLX75M5glKLDX4s/vLL7cWX8I11 dfGUcAHdh9JO+4JhfRhBSZDJdQ9Dob7b+l2P/9aazlLgGzWMUjt/v/45p4bv1CyuV1nv noRTybeOsa/HxC1zRppHCENzOpxo3lWnBQ579iHHH6q5xh5LZkByXOzFnB4yqjx8nnss DLRsUUt33NOCjg9/Mxpmg4KSN3pUFSY85qutY8OocRUaGKsQ5+KMwpTZcBg4/AtPtPGm WNh5UlRQ0TQOeFH9Lb+XgHwL+PInqR1gZfGG2QOfoVgZnI5yf94uzVb9U8ajHp8s6LO5 qdWg== X-Gm-Message-State: AOJu0YzlzuC6FhrXLY9TN2pINpPZFqPQPIYxlYAjWf/zJhlwhN919nox E+LVzPMIg12WqOC3Wwi12KOPKWLHu6IrU9iEy8Zl5sFfDUeX5S6lhCEt7yrowo8= X-Google-Smtp-Source: AGHT+IFHFfW4r4qcv8ugH6c0W5g2PL41y5qxRdnc8hhQgPEOGCaQSL2rleGSI1g6rC4gfsbx1H+t9g== X-Received: by 2002:a17:903:2448:b0:1dd:c93c:580c with SMTP id l8-20020a170903244800b001ddc93c580cmr2532422pls.4.1711104868887; Fri, 22 Mar 2024 03:54:28 -0700 (PDT) From: Akihiko Odaki Date: Fri, 22 Mar 2024 19:54:25 +0900 Subject: [PATCH] ui/cocoa: Use qemu_add_mouse_change_notifier MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240322-mouse-v1-1-0b7d4d9bdfbf@daynix.com> X-B4-Tracking: v=1; b=H4sIAGBj/WUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDYyMj3dz80uJU3aSkZIO0REuDVIuUZCWg2oKi1LTMCrA50bG1tQDrqZw KVwAAAA== To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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: none client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1711104938224100003 This eliminates the polling in cocoa_refresh and implements the propagation of the mouse mode change from absolute to relative. Signed-off-by: Akihiko Odaki --- ui/cocoa.m | 62 ++++++++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 810751cf2644..b53920b8814c 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -310,6 +310,14 @@ @interface QemuCocoaView : NSView NSTrackingArea *trackingArea; QEMUScreen screen; pixman_image_t *pixman_image; + /* The state surrounding mouse grabbing is potentially confusing. + * isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emula= ted + * pointing device an absolute-position one?"], but is only updated = on + * next refresh. + * isMouseGrabbed tracks whether GUI events are directed to the guest; + * it controls whether special keys like Cmd get sent to the guest, + * and whether we capture the mouse when in non-absolute mode. + */ BOOL isMouseGrabbed; BOOL isAbsoluteEnabled; CFMachPortRef eventsTap; @@ -321,17 +329,8 @@ - (void) setFullGrab:(id)sender; - (void) handleMonitorInput:(NSEvent *)event; - (bool) handleEvent:(NSEvent *)event; - (bool) handleEventLocked:(NSEvent *)event; -- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled; -/* The state surrounding mouse grabbing is potentially confusing. - * isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated - * pointing device an absolute-position one?"], but is only updated on - * next refresh. - * isMouseGrabbed tracks whether GUI events are directed to the guest; - * it controls whether special keys like Cmd get sent to the guest, - * and whether we capture the mouse when in non-absolute mode. - */ +- (void) notifyMouseModeChange; - (BOOL) isMouseGrabbed; -- (BOOL) isAbsoluteEnabled; - (QEMUScreen) gscreen; - (void) raiseAllKeys; @end @@ -437,6 +436,7 @@ - (void) selectConsoleLocked:(unsigned int)index qkbd_state_switch_console(kbd, con); dcl.con =3D con; register_displaychangelistener(&dcl); + [self notifyMouseModeChange]; [self updateUIInfo]; } =20 @@ -1103,14 +1103,26 @@ - (void) ungrabMouse [self raiseAllButtons]; } =20 -- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled { +- (void) notifyMouseModeChange { + bool tIsAbsoluteEnabled =3D bool_with_bql(^{ + return qemu_input_is_absolute(dcl.con); + }); + + if (tIsAbsoluteEnabled =3D=3D isAbsoluteEnabled) { + return; + } + isAbsoluteEnabled =3D tIsAbsoluteEnabled; + if (isMouseGrabbed) { - CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); + if (isAbsoluteEnabled) { + [self ungrabMouse]; + } else { + CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); + } } } - (BOOL) isMouseGrabbed {return isMouseGrabbed;} -- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;} - (QEMUScreen) gscreen {return screen;} =20 /* @@ -1784,6 +1796,17 @@ static void addRemovableDevicesMenuItems(void) qapi_free_BlockInfoList(pointerToFree); } =20 +static void cocoa_mouse_mode_change_notify(Notifier *notifier, void *data) +{ + dispatch_async(dispatch_get_main_queue(), ^{ + [cocoaView notifyMouseModeChange]; + }); +} + +static Notifier mouse_mode_change_notifier =3D { + .notify =3D cocoa_mouse_mode_change_notify +}; + @interface QemuCocoaPasteboardTypeOwner : NSObject @end =20 @@ -1968,17 +1991,6 @@ static void cocoa_refresh(DisplayChangeListener *dcl) COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n"); graphic_hw_update(dcl->con); =20 - if (qemu_input_is_absolute(dcl->con)) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (![cocoaView isAbsoluteEnabled]) { - if ([cocoaView isMouseGrabbed]) { - [cocoaView ungrabMouse]; - } - } - [cocoaView setAbsoluteEnabled:YES]; - }); - } - if (cbchangecount !=3D [[NSPasteboard generalPasteboard] changeCount])= { qemu_clipboard_info_unref(cbinfo); cbinfo =3D qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTI= ON_CLIPBOARD); @@ -2055,6 +2067,8 @@ static void cocoa_display_init(DisplayState *ds, Disp= layOptions *opts) =20 // register vga output callbacks register_displaychangelistener(&dcl); + qemu_add_mouse_mode_change_notifier(&mouse_mode_change_notifier); + [cocoaView notifyMouseModeChange]; [cocoaView updateUIInfo]; =20 qemu_event_init(&cbevent, false); --- base-commit: fea445e8fe9acea4f775a832815ee22bdf2b0222 change-id: 20240322-mouse-bbc0fa90e8dc Best regards, --=20 Akihiko Odaki