From nobody Fri Nov 1 05:30: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=1708168809; cv=none; d=zohomail.com; s=zohoarc; b=dkdYPxxxLpykOP3DxZs6zOGNDGTQGe0WAXdrUjhmWY6XFHBe0k87BCb7e5cv4T7+shKUmsL16eNmjUfOOR8sxfdewPG0riMwFS7dmFcWTo2Rzem7eOdPUFrG9KhLP/zPegUs/YvXpVnW7Z8ydgioaPGc5SfD2leScS7TyUHwJVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168809; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9aPF/raZCUaNWr2M962mTjozvtYefD2y4h/liBQ3bA8=; b=ii8voyvZX3p3u3MzQ48Q5fEkgBRWB+tl52ExGiWzk7HrEctQNgr55Lh6SFJ3qlMOiZ21tsnEUR5Q4x58kpwj++iux2VfbMb6G1rh1l/RVqUr5cTVZxqddgeagRpzgzCePl4djb6cj25SMSutqi0Wz3N8PTxb2q384DjfkNS+3DQ= 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 1708168809489846.4828399030503; Sat, 17 Feb 2024 03:20:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIik-0007Rh-Tq; Sat, 17 Feb 2024 06:19:02 -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 1rbIij-0007RE-9A for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:01 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIih-0002fP-C7 for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:01 -0500 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e38fbc0ee2so49747b3a.0 for ; Sat, 17 Feb 2024 03:18:59 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id h15-20020a056a00000f00b006dd843734c8sm937820pfk.81.2024.02.17.03.18.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:18:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168738; x=1708773538; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9aPF/raZCUaNWr2M962mTjozvtYefD2y4h/liBQ3bA8=; b=mYA7sJr4YQ2i+c1PIk0O4Lcf2bpy20pdCkpK9WyZD+kSj/kKk9fTtXzg+6kQUbW0kZ FOJbUpcTiCSCJIIGFpw+DdJbSUGr1jCExx/13E6vV+CqdhyCj6ZIOnD63+0ZV4FQpldb BJ1hzm1wqpfxW7mdXhuFWfsJjl7+qonxQ59WuQ+7PwkaEEVuY6n0mhejuIuKlD3K1gA7 EGFYkFXN6B6WixLY7sRA8uiPLNaqhcs4vkCVm0l3u5G8Cjs2JX8/7r2Yq882DVOMHklK tIsPG7q7fVtZfVMPSNV0OCg6xd5QrRaYgFTUEpvFHVBZz424sUp1Jm+Ct6TW2pkNwuIx guPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168738; x=1708773538; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9aPF/raZCUaNWr2M962mTjozvtYefD2y4h/liBQ3bA8=; b=KvKDlsImAzklzV2kuefd8ua6tufu7HQC218cr7MV9zXywuHtHjfTxZoU2I/acQpHi7 /BY6F6nZgOwWSOyIog+eHrvCLWXaoH3Tfx3g8A1Q2KN0qRZsWdwUoz0BPfudjddRiiqM gqbz50O/WAdFEFyoas7Pcyqz+B37uPOrcWJmeTLtomAPfy9zpdA+muDq0AenYmByinNz M4VyVyq+iXM/4MOzP4xUhhE7JfOf/aGyzbYWIAZCY8FnZ6dnp/zLCk7I/d4cRLAAaF1i z+C8U5gVNqYUUEIvUo4EoxU90CiLWpv8SJDIxcvMWSvau5c36/UG8TJWTHBL0OWECz/+ uE/w== X-Gm-Message-State: AOJu0YyUvftCkLH5UcV9uUX7JDTG5rvp6ZoDMLLLOXnijdGNp7b+mEY4 acgZ13cWP1sQcrVqxbdEQj0uYK1TVcNhrzC6vr5UisEgv8pYWzwRQKMCokBZCDM= X-Google-Smtp-Source: AGHT+IEFlqU5rS29zUHHPSf5rmHwiwOsdo6Vev7zEOegtvk0B/VRIMm8afF7bsm6oq8wtcc1q9v8ew== X-Received: by 2002:a05:6a20:d808:b0:19e:cf1a:5369 with SMTP id iv8-20020a056a20d80800b0019ecf1a5369mr10956717pzb.24.1708168737950; Sat, 17 Feb 2024 03:18:57 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:47 +0900 Subject: [PATCH v11 1/6] ui/cocoa: Release specific mouse buttons MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-1-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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, 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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168810427100003 ui/cocoa used to release all mouse buttons when it sees NSEventTypeLeftMouseUp, NSEventTypeRightMouseUp, or NSEventTypeOtherMouseUp, but it can instead release specific one according to the delivered event. Signed-off-by: Akihiko Odaki --- ui/cocoa.m | 132 ++++++++++++++++++++++++++-------------------------------= ---- 1 file changed, 55 insertions(+), 77 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index eb99064beeb4..fe0eb74b0743 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -99,7 +99,6 @@ static void cocoa_switch(DisplayChangeListener *dcl, static DisplayChangeListener dcl =3D { .ops =3D &dcl_ops, }; -static int last_buttons; static int cursor_hide =3D 1; static int left_command_key_enabled =3D 1; static bool swap_opt_cmd; @@ -801,8 +800,6 @@ - (bool) handleEventLocked:(NSEvent *)event COCOA_DEBUG("QemuCocoaView: handleEvent\n"); int buttons =3D 0; int keycode =3D 0; - bool mouse_event =3D false; - // Location of event in virtual screen coordinates NSPoint p =3D [self screenLocationOfEvent:event]; NSUInteger modifiers =3D [event modifierFlags]; =20 @@ -883,25 +880,25 @@ - (bool) handleEventLocked:(NSEvent *)event if (!!(modifiers & NSEventModifierFlagShift)) { [self toggleKey:Q_KEY_CODE_SHIFT]; } - break; + return true; =20 case kVK_RightShift: if (!!(modifiers & NSEventModifierFlagShift)) { [self toggleKey:Q_KEY_CODE_SHIFT_R]; } - break; + return true; =20 case kVK_Control: if (!!(modifiers & NSEventModifierFlagControl)) { [self toggleKey:Q_KEY_CODE_CTRL]; } - break; + return true; =20 case kVK_RightControl: if (!!(modifiers & NSEventModifierFlagControl)) { [self toggleKey:Q_KEY_CODE_CTRL_R]; } - break; + return true; =20 case kVK_Option: if (!!(modifiers & NSEventModifierFlagOption)) { @@ -911,7 +908,7 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_ALT]; } } - break; + return true; =20 case kVK_RightOption: if (!!(modifiers & NSEventModifierFlagOption)) { @@ -921,7 +918,7 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_ALT_R]; } } - break; + return true; =20 /* Don't pass command key changes to guest unless mouse is= grabbed */ case kVK_Command: @@ -934,7 +931,7 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_META_L]; } } - break; + return true; =20 case kVK_RightCommand: if (isMouseGrabbed && @@ -945,9 +942,11 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_META_R]; } } - break; + return true; + + default: + return true; } - break; case NSEventTypeKeyDown: keycode =3D cocoa_keycode_to_qemu([event keyCode]); =20 @@ -983,7 +982,7 @@ - (bool) handleEventLocked:(NSEvent *)event } else { [self handleMonitorInput: event]; } - break; + return true; case NSEventTypeKeyUp: keycode =3D cocoa_keycode_to_qemu([event keyCode]); =20 @@ -996,7 +995,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 b= ound to screen coordinates @@ -1012,34 +1011,18 @@ - (bool) handleEventLocked:(NSEvent *)event } } } - mouse_event =3D true; - break; + return [self handleMouseEvent:event]; case NSEventTypeLeftMouseDown: - buttons |=3D MOUSE_EVENT_LBUTTON; - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:true]; case NSEventTypeRightMouseDown: - buttons |=3D MOUSE_EVENT_RBUTTON; - mouse_event =3D true; - break; - case NSEventTypeOtherMouseDown: - buttons |=3D MOUSE_EVENT_MBUTTON; - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:true]; case NSEventTypeLeftMouseDragged: - buttons |=3D MOUSE_EVENT_LBUTTON; - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:true]; case NSEventTypeRightMouseDragged: - buttons |=3D MOUSE_EVENT_RBUTTON; - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:true]; case NSEventTypeOtherMouseDragged: - buttons |=3D MOUSE_EVENT_MBUTTON; - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_MBUTTON= down:true]; case NSEventTypeLeftMouseUp: - mouse_event =3D true; if (!isMouseGrabbed && [self screenContainsPoint:p]) { /* * In fullscreen mode, the window of cocoaView may not be = the @@ -1050,13 +1033,11 @@ - (bool) handleEventLocked:(NSEvent *)event [self grabMouse]; } } - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:false]; case NSEventTypeRightMouseUp: - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:false]; case NSEventTypeOtherMouseUp: - mouse_event =3D true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_MBUTTON= down:false]; case NSEventTypeScrollWheel: /* * Send wheel events to the guest regardless of window focus. @@ -1087,52 +1068,49 @@ - (bool) handleEventLocked:(NSEvent *)event * Since deltaX/deltaY also report scroll wheel events we prev= ent mouse * movement code from executing. */ - mouse_event =3D false; - break; + return true; default: return false; } +} + +- (bool) handleMouseEvent:(NSEvent *)event +{ + if (!isMouseGrabbed) { + return false; + } =20 - if (mouse_event) { - /* Don't send button events to the guest unless we've got a - * mouse grab or window focus. If we have neither then this event - * is the user clicking on the background window to activate and - * bring us to the front, which will be done by the sendEvent - * call below. We definitely don't want to pass that click through - * to the guest. + if (isAbsoluteEnabled) { + NSPoint p =3D [self screenLocationOfEvent:event]; + /* Note that the origin for Cocoa mouse coords is bottom left, not= top left. + * The check on screenContainsPoint is to avoid sending out of ran= ge values for + * clicks in the titlebar. */ - if ((isMouseGrabbed || [[self window] isKeyWindow]) && - (last_buttons !=3D buttons)) { - static uint32_t bmap[INPUT_BUTTON__MAX] =3D { - [INPUT_BUTTON_LEFT] =3D MOUSE_EVENT_LBUTTON, - [INPUT_BUTTON_MIDDLE] =3D MOUSE_EVENT_MBUTTON, - [INPUT_BUTTON_RIGHT] =3D MOUSE_EVENT_RBUTTON - }; - qemu_input_update_buttons(dcl.con, bmap, last_buttons, buttons= ); - last_buttons =3D buttons; - } - if (isMouseGrabbed) { - if (isAbsoluteEnabled) { - /* Note that the origin for Cocoa mouse coords is bottom l= eft, not top left. - * The check on screenContainsPoint is to avoid sending ou= t of range values for - * clicks in the titlebar. - */ - if ([self screenContainsPoint:p]) { - qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, sc= reen.width); - qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.hei= ght - p.y, 0, screen.height); - } - } else { - qemu_input_queue_rel(dcl.con, INPUT_AXIS_X, (int)[event de= ltaX]); - qemu_input_queue_rel(dcl.con, INPUT_AXIS_Y, (int)[event de= ltaY]); - } - } else { - return false; + if ([self screenContainsPoint:p]) { + qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.wid= th); + qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.= y, 0, screen.height); } - qemu_input_event_sync(); + } else { + qemu_input_queue_rel(dcl.con, INPUT_AXIS_X, (int)[event deltaX]); + qemu_input_queue_rel(dcl.con, INPUT_AXIS_Y, (int)[event deltaY]); } + + qemu_input_event_sync(); + return true; } =20 +- (bool) handleMouseEvent:(NSEvent *)event button:(InputButton)button down= :(bool)down +{ + if (!isMouseGrabbed && ![[self window] isKeyWindow]) { + return false; + } + + qemu_input_queue_btn(dcl.con, button, down); + + return [self handleMouseEvent:event]; +} + - (void) grabMouse { COCOA_DEBUG("QemuCocoaView: grabMouse\n"); --=20 2.43.1 From nobody Fri Nov 1 05:30: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=1708168836; cv=none; d=zohomail.com; s=zohoarc; b=D+mGqj8PIU36UTTsJNiQHeZAlRKQPYVSWvyX4aFVQLyqsAmcumFAsWmXa7bXWP4w3XkP+TTzoOD6NcBFVFeEI7YcUBCcOGprc64SJ5234/aBPijnzGos+SMmWL8agpwrA9WT/CsNIloPJUHpNCZRBLJq9M/oFupd13hD90G1z+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yg/3DKi4unIH0TlgItEfPow+9WhqClPSrzvHM4SKIdk=; b=AttDuGJSvZEs/Bf1dMKuw2CaGszAkyHF6kYB+lizB3fK0PGyGPh6eS3FzpqFrA/BavU9ZQYYVXzRqa0XBYZ98V9H5RCtWfGX1mz6usAz5dDBNkkgpQfnRCEGl6vHgxGJ+fQhYrctZk+82L/QNQj9yKfWeKandGRe4U12Slmlzts= 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 1708168836416398.38472306228346; Sat, 17 Feb 2024 03:20:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIio-0007SL-Tn; Sat, 17 Feb 2024 06:19:06 -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 1rbIim-0007S4-Rx for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:04 -0500 Received: from mail-oo1-xc2c.google.com ([2607:f8b0:4864:20::c2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIil-0002fi-Cq for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:04 -0500 Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-595d24ad466so1522308eaf.0 for ; Sat, 17 Feb 2024 03:19:03 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id c7-20020a62f847000000b006e0e35c1e55sm1424561pfm.79.2024.02.17.03.18.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:19:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168742; x=1708773542; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yg/3DKi4unIH0TlgItEfPow+9WhqClPSrzvHM4SKIdk=; b=QSyLEj5DvF626ZTMwOXnpjVd7RB8+j2dvUi46/2hcpzdq/c9FqQ7m2sUmD0wChgbhR zhzxdPbiHmCDFMopQjedHi0McSsYgE2s2RQjNCDj9qkw4/pBr9e6kuEZKNP1hYWOxSh0 qv8UQTBZFc2xCoVXWRV7rzzJqKoWcB7bRZFI4cS2TfNvP08rjgrMS76NoEdNYh2uroIF ajaKgFD7M6+4r7J3EslZrajA2u2AS52u34jezWwkP/uU1ifi7zOFMqGJes2yawTkiDJY 79G9Pt61WbkLK+Q70wS0yamklLZbOOgdTCRNlv9yeFgrsoAIes2mutFR5faBFh1bClpc CIeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168742; x=1708773542; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yg/3DKi4unIH0TlgItEfPow+9WhqClPSrzvHM4SKIdk=; b=d6V46tkbDeThptq5T7/ydfKQgYMdp0agCBVWjnHRWfVS3xnfCFe9Owa7veS0KLV23S eHBldomGYs4Bgg42voVEf7xH6C8YrwDdfjptEvZAS5mLg8yS66bQq7H1ZYI0qZfRhaKw 210tdHkbLBh5phHoKyDffjdo1xA/NgWaXqjOieTs/+AlkTvpuEFPloMrwdsy27RViMJ7 LmWQcTQwHk6qeSiWnQZ3aecYVN6ofZpbQ20yP922jxkqjEva/endGatPPbowUPxH2c+G /nKSECA8njuIlTszsTDXFWKpw85eUTG0CGSVCKscvWsDtHWnmhXY+2DIAr2KHzcTlrUU Noww== X-Gm-Message-State: AOJu0YxJ6MVAXydd/rnOpAjqVwCKl8gmNL01yafBe1BAmRu9lWrFEOyi 4YNiteeQCX6rIGzVmD4NRa5Rm9N5/zanY/Np63hS6iFfh/suwwUw2R+30VTkfNo= X-Google-Smtp-Source: AGHT+IHee+Bx8Sp5yrDNtZ7fsXUtkYBttm2lGxS4smTuySxEyYgAWt78/re0P0MeKtzw+l7Mrj+5KA== X-Received: by 2002:a05:6358:78b:b0:178:99cc:e52e with SMTP id n11-20020a056358078b00b0017899cce52emr8027763rwj.20.1708168741831; Sat, 17 Feb 2024 03:19:01 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:48 +0900 Subject: [PATCH v11 2/6] ui/cocoa: Scale with NSView instead of Core Graphics MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-2-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::c2c; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc2c.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, 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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168837989100004 Core Graphics is not accelerated and slow. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- ui/cocoa.m | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index fe0eb74b0743..b26669160300 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -496,10 +496,8 @@ - (void) drawRect:(NSRect) rect =20 [self getRectsBeingDrawn:&rectList count:&rectCount]; for (i =3D 0; i < rectCount; i++) { - clipRect.origin.x =3D rectList[i].origin.x / cdx; - clipRect.origin.y =3D (float)h - (rectList[i].origin.y + rectL= ist[i].size.height) / cdy; - clipRect.size.width =3D rectList[i].size.width / cdx; - clipRect.size.height =3D rectList[i].size.height / cdy; + clipRect =3D rectList[i]; + clipRect.origin.y =3D (float)h - (clipRect.origin.y + clipRect= .size.height); clipImageRef =3D CGImageCreateWithImageInRect( imageRef, clipRect @@ -545,6 +543,11 @@ - (void) setContentDimensions } } =20 +- (void) updateBounds +{ + [self setBoundsSize:NSMakeSize(screen.width, screen.height)]; +} + - (void) updateUIInfoLocked { /* Must be called with the BQL, i.e. via updateUIInfo */ @@ -634,6 +637,7 @@ - (void) switchSurface:(pixman_image_t *)image screen.height =3D h; [self setContentDimensions]; [self setFrame:NSMakeRect(cx, cy, cw, ch)]; + [self updateBounds]; } =20 // update screenBuffer @@ -1292,6 +1296,7 @@ - (void)windowDidChangeScreen:(NSNotification *)notif= ication =20 - (void)windowDidResize:(NSNotification *)notification { + [cocoaView updateBounds]; [cocoaView updateUIInfo]; } =20 @@ -1940,16 +1945,7 @@ static void cocoa_update(DisplayChangeListener *dcl, COCOA_DEBUG("qemu_cocoa: cocoa_update\n"); =20 dispatch_async(dispatch_get_main_queue(), ^{ - NSRect rect; - if ([cocoaView cdx] =3D=3D 1.0) { - rect =3D NSMakeRect(x, [cocoaView gscreen].height - y - h, w, = h); - } else { - rect =3D NSMakeRect( - x * [cocoaView cdx], - ([cocoaView gscreen].height - y - h) * [cocoaView cdy], - w * [cocoaView cdx], - h * [cocoaView cdy]); - } + NSRect rect =3D NSMakeRect(x, [cocoaView gscreen].height - y - h, = w, h); [cocoaView setNeedsDisplayInRect:rect]; }); } --=20 2.43.1 From nobody Fri Nov 1 05:30: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=1708168836; cv=none; d=zohomail.com; s=zohoarc; b=m/c+s4j3uZ0th6XNty7aRUdwwLKuZx8r3wRCXnsz0ekGyBhC/L388D+ZdCcn4cTlN8Dz+dYyjt/CMGbs0ypqTKpWxW8vjn6HwwmmRwUyAHF/HFqWk/Q/6e5vvtzGb/HkzAPag2XdCS20Swp6hPiBjilFBcCUdpu9e/mGsbfcrzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AMmJ7PeJfRPtYjwIp0Qs5NxA0dzRU5BTR7yYaBxY2Zo=; b=HJaWmqPUUPJshgspzONtl5WepWr6/+FINr7x92ypjUSknpxBtEDAqhkjtCssQcIn8/TNZKIcucT6uDCH2UA7YwUohuOIEFnovBY4G4O+2NHoAHuA93Py+Pv4HSTMqlu9GiAPbHLjZU8ZSYGSBG0v53tvxzi8v6dcdGB+vXFwT4Y= 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 1708168836245394.407104558834; Sat, 17 Feb 2024 03:20:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIit-0007Su-Mh; Sat, 17 Feb 2024 06:19:11 -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 1rbIis-0007Sl-By for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:10 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIip-0002g4-LQ for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:10 -0500 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6e11a779334so1810877b3a.0 for ; Sat, 17 Feb 2024 03:19:07 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id g14-20020aa7874e000000b006dddd5cc47csm1428794pfo.157.2024.02.17.03.19.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168746; x=1708773546; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AMmJ7PeJfRPtYjwIp0Qs5NxA0dzRU5BTR7yYaBxY2Zo=; b=IXB1DD4+ZguaPF16IfNIBZsUUvSUi5bQhGr8LYX+tat2dwWAzZrU7fSLO2/vEkJgml 7rlvM4Rntw8iDtNZ6IzU8hkN4FFMwfSOEJu3cN0sbLx4FM6VDtPQPXebER5QXO221tym i9LAJcxa496HqApda8E/rfjyPt/UYH3XgSNb+W5f7+P0lCwLMaLgJJ2mxooNtg4c750u 307h2/2MacpB+JaHquthBTl1PW56b+QDd5INgXOrTnjKux7WMWh3cICf0iIG6mbWuQIM E4mrDb68FiLuWT852NGE8MLUjlcfNGEXelOd0J32JrpfbB5h76I6+XBgOxYgEvhyqjNE Xlkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168746; x=1708773546; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AMmJ7PeJfRPtYjwIp0Qs5NxA0dzRU5BTR7yYaBxY2Zo=; b=T9rTWj+7MkJp6AhPLM7iKRtkJU6dVob1HBoG0KiWMDXUYieKQ8h8owglwVNEDCJNqv BEy+pb4wRjFKpnPtvx8FtUuka3o8mGczc9T/JyHMi6h6rbwR1Rn1icO83BG+2MuWLnYX M75Golih0ixP1Avbrml5EU+v6YAEq3HWCZ4JCh5D9ZQdqW/M1gdx6mx340FGlub8v6Vx EUe68Qt1KrKiik0orVYQN7T/vRUqeLRPnea9jkkHQcSehqP1sx0jFOJXBOlXJcmLOg/j AaS8RmNWxJ8kTQcLk90N/3w9fSuP78wIpYEv1MT2nfEaklof1jEduKc9W4nnYXkUXb1F OBEw== X-Gm-Message-State: AOJu0YzNpxQeyX9lzmFLzrsmAqs/fXI3/PDh8d45k2TZKHO6TFjNcVBe igneomuyKBYSwOekCykF1uLniPPPqY0VKScOWOPBUDRapN3maC+CST8OmXIPhl4= X-Google-Smtp-Source: AGHT+IH1pSIMBR67MJGbZOnwVycT5r67qzo8rBU5jjjKgD2eknCir8gyX11icmkCcTE8p3WuvmxCpA== X-Received: by 2002:a05:6a00:1898:b0:6e0:3d93:1bea with SMTP id x24-20020a056a00189800b006e03d931beamr12569530pfh.0.1708168746188; Sat, 17 Feb 2024 03:19:06 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:49 +0900 Subject: [PATCH v11 3/6] ui/cocoa: Let the platform toggle fullscreen MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-3-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::432; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x432.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, PDS_OTHER_BAD_TLD=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168838028100006 It allows making the window full screen by clicking full screen button provided by the platform (the left-top green button) and save some code. Signed-off-by: Akihiko Odaki --- ui/cocoa.m | 423 ++++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 207 insertions(+), 216 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index b26669160300..0ebe0f326373 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -303,20 +303,17 @@ static void handleAnyDeviceErrors(Error * err) */ @interface QemuCocoaView : NSView { + NSTrackingArea *trackingArea; QEMUScreen screen; - NSWindow *fullScreenWindow; - float cx,cy,cw,ch,cdx,cdy; pixman_image_t *pixman_image; QKbdState *kbd; BOOL isMouseGrabbed; - BOOL isFullscreen; BOOL isAbsoluteEnabled; CFMachPortRef eventsTap; } - (void) switchSurface:(pixman_image_t *)image; - (void) grabMouse; - (void) ungrabMouse; -- (void) toggleFullScreen:(id)sender; - (void) setFullGrab:(id)sender; - (void) handleMonitorInput:(NSEvent *)event; - (bool) handleEvent:(NSEvent *)event; @@ -332,8 +329,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled; */ - (BOOL) isMouseGrabbed; - (BOOL) isAbsoluteEnabled; -- (float) cdx; -- (float) cdy; - (QEMUScreen) gscreen; - (void) raiseAllKeys; @end @@ -391,46 +386,43 @@ - (BOOL) isOpaque return YES; } =20 -- (BOOL) screenContainsPoint:(NSPoint) p +- (void) removeTrackingRect { - return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.hei= ght); + if (trackingArea) { + [self removeTrackingArea:trackingArea]; + [trackingArea release]; + trackingArea =3D nil; + } } =20 -/* Get location of event and convert to virtual screen coordinate */ -- (CGPoint) screenLocationOfEvent:(NSEvent *)ev +- (void) frameUpdated { - NSWindow *eventWindow =3D [ev window]; - // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10 - CGRect r =3D CGRectZero; - r.origin =3D [ev locationInWindow]; - if (!eventWindow) { - if (!isFullscreen) { - return [[self window] convertRectFromScreen:r].origin; - } else { - CGPoint locationInSelfWindow =3D [[self window] convertRectFro= mScreen:r].origin; - CGPoint loc =3D [self convertPoint:locationInSelfWindow fromVi= ew:nil]; - if (stretch_video) { - loc.x /=3D cdx; - loc.y /=3D cdy; - } - return loc; - } - } else if ([[self window] isEqual:eventWindow]) { - if (!isFullscreen) { - return r.origin; - } else { - CGPoint loc =3D [self convertPoint:r.origin fromView:nil]; - if (stretch_video) { - loc.x /=3D cdx; - loc.y /=3D cdy; - } - return loc; - } - } else { - return [[self window] convertRectFromScreen:[eventWindow convertRe= ctToScreen:r]].origin; + [self removeTrackingRect]; + + if ([self window]) { + NSTrackingAreaOptions options =3D NSTrackingActiveInKeyWindow | + NSTrackingMouseEnteredAndExited | + NSTrackingMouseMoved; + trackingArea =3D [[NSTrackingArea alloc] initWithRect:[self frame] + options:options + owner:self + userInfo:nil]; + [self addTrackingArea:trackingArea]; + [self updateUIInfo]; } } =20 +- (void) viewDidMoveToWindow +{ + [self resizeWindow]; + [self frameUpdated]; +} + +- (void) viewWillMoveToWindow:(NSWindow *)newWindow +{ + [self removeTrackingRect]; +} + - (void) hideCursor { if (!cursor_hide) { @@ -510,36 +502,43 @@ - (void) drawRect:(NSRect) rect } } =20 -- (void) setContentDimensions +- (NSSize) fixZoomedFullScreenSize:(NSSize)proposedSize { - COCOA_DEBUG("QemuCocoaView: setContentDimensions\n"); + NSSize size; =20 - if (isFullscreen) { - cdx =3D [[NSScreen mainScreen] frame].size.width / (float)screen.w= idth; - cdy =3D [[NSScreen mainScreen] frame].size.height / (float)screen.= height; + size.width =3D (CGFloat)screen.width * proposedSize.height; + size.height =3D (CGFloat)screen.height * proposedSize.width; =20 - /* stretches video, but keeps same aspect ratio */ - if (stretch_video =3D=3D true) { - /* use smallest stretch value - prevents clipping on sides */ - if (MIN(cdx, cdy) =3D=3D cdx) { - cdy =3D cdx; - } else { - cdx =3D cdy; - } - } else { /* No stretching */ - cdx =3D cdy =3D 1; - } - cw =3D screen.width * cdx; - ch =3D screen.height * cdy; - cx =3D ([[NSScreen mainScreen] frame].size.width - cw) / 2.0; - cy =3D ([[NSScreen mainScreen] frame].size.height - ch) / 2.0; + if (size.width < size.height) { + size.width /=3D screen.height; + size.height =3D proposedSize.height; } else { - cx =3D 0; - cy =3D 0; - cw =3D screen.width; - ch =3D screen.height; - cdx =3D 1.0; - cdy =3D 1.0; + size.width =3D proposedSize.width; + size.height /=3D screen.width; + } + + return size; +} + +- (NSSize) screenSafeAreaSize +{ + NSSize size =3D [[[self window] screen] frame].size; + NSEdgeInsets insets =3D [[[self window] screen] safeAreaInsets]; + size.width -=3D insets.left + insets.right; + size.height -=3D insets.top + insets.bottom; + return size; +} + +- (void) resizeWindow +{ + [[self window] setContentAspectRatio:NSMakeSize(screen.width, screen.h= eight)]; + + if (!stretch_video) { + [[self window] setContentSize:NSMakeSize(screen.width, screen.heig= ht)]; + [[self window] center]; + } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { + [[self window] setContentSize:[self fixZoomedFullScreenSize:[self = screenSafeAreaSize]]]; + [[self window] center]; } } =20 @@ -563,9 +562,10 @@ - (void) updateUIInfoLocked CGDirectDisplayID display =3D [[description objectForKey:@"NSScree= nNumber"] unsignedIntValue]; NSSize screenSize =3D [[[self window] screen] frame].size; CGSize screenPhysicalSize =3D CGDisplayScreenSize(display); + bool isFullscreen =3D ([[self window] styleMask] & NSWindowStyleMa= skFullScreen) !=3D 0; CVDisplayLinkRef displayLink; =20 - frameSize =3D isFullscreen ? screenSize : [self frame].size; + frameSize =3D isFullscreen ? [self screenSafeAreaSize] : [self fra= me].size; =20 if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) { CVTime period =3D CVDisplayLinkGetNominalOutputVideoRefreshPer= iod(displayLink); @@ -612,31 +612,19 @@ - (void) updateUIInfo }); } =20 -- (void)viewDidMoveToWindow -{ - [self updateUIInfo]; -} - - (void) switchSurface:(pixman_image_t *)image { COCOA_DEBUG("QemuCocoaView: switchSurface\n"); =20 int w =3D pixman_image_get_width(image); int h =3D pixman_image_get_height(image); - /* cdx =3D=3D 0 means this is our very first surface, in which case we= need - * to recalculate the content dimensions even if it happens to be the = size - * of the initial empty window. - */ - bool isResize =3D (w !=3D screen.width || h !=3D screen.height || cdx = =3D=3D 0.0); =20 - int oldh =3D screen.height; - if (isResize) { + if (w !=3D screen.width || h !=3D screen.height) { // Resize before we trigger the redraw, or we'll redraw at the wro= ng size COCOA_DEBUG("switchSurface: new size %d x %d\n", w, h); screen.width =3D w; screen.height =3D h; - [self setContentDimensions]; - [self setFrame:NSMakeRect(cx, cy, cw, ch)]; + [self resizeWindow]; [self updateBounds]; } =20 @@ -646,51 +634,6 @@ - (void) switchSurface:(pixman_image_t *)image } =20 pixman_image =3D image; - - // update windows - if (isFullscreen) { - [[fullScreenWindow contentView] setFrame:[[NSScreen mainScreen] fr= ame]]; - [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [= normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.h= eight - oldh) display:NO animate:NO]; - } else { - if (qemu_name) - [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", = qemu_name]]; - [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [= normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.h= eight - oldh) display:YES animate:NO]; - } - - if (isResize) { - [normalWindow center]; - } -} - -- (void) toggleFullScreen:(id)sender -{ - COCOA_DEBUG("QemuCocoaView: toggleFullScreen\n"); - - if (isFullscreen) { // switch from fullscreen to desktop - isFullscreen =3D FALSE; - [self ungrabMouse]; - [self setContentDimensions]; - [fullScreenWindow close]; - [normalWindow setContentView: self]; - [normalWindow makeKeyAndOrderFront: self]; - [NSMenu setMenuBarVisible:YES]; - } else { // switch from desktop to fullscreen - isFullscreen =3D TRUE; - [normalWindow orderOut: nil]; /* Hide the window */ - [self grabMouse]; - [self setContentDimensions]; - [NSMenu setMenuBarVisible:NO]; - fullScreenWindow =3D [[NSWindow alloc] initWithContentRect:[[NSScr= een mainScreen] frame] - styleMask:NSWindowStyleMaskBorderless - backing:NSBackingStoreBuffered - defer:NO]; - [fullScreenWindow setAcceptsMouseMovedEvents: YES]; - [fullScreenWindow setHasShadow:NO]; - [fullScreenWindow setBackgroundColor: [NSColor blackColor]]; - [self setFrame:NSMakeRect(cx, cy, cw, ch)]; - [[fullScreenWindow contentView] addSubview: self]; - [fullScreenWindow makeKeyAndOrderFront:self]; - } } =20 - (void) setFullGrab:(id)sender @@ -804,7 +747,6 @@ - (bool) handleEventLocked:(NSEvent *)event COCOA_DEBUG("QemuCocoaView: handleEvent\n"); int buttons =3D 0; int keycode =3D 0; - NSPoint p =3D [self screenLocationOfEvent:event]; NSUInteger modifiers =3D [event modifierFlags]; =20 /* @@ -1000,48 +942,6 @@ - (bool) handleEventLocked:(NSEvent *)event qkbd_state_key_event(kbd, keycode, false); } return true; - case NSEventTypeMouseMoved: - if (isAbsoluteEnabled) { - // Cursor re-entered into a window might generate events b= ound to screen coordinates - // and `nil` window property, and in full screen mode, cur= rent window might not be - // key window, where event location alone should suffice. - if (![self screenContainsPoint:p] || !([[self window] isKe= yWindow] || isFullscreen)) { - if (isMouseGrabbed) { - [self ungrabMouse]; - } - } else { - if (!isMouseGrabbed) { - [self grabMouse]; - } - } - } - return [self handleMouseEvent:event]; - case NSEventTypeLeftMouseDown: - return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:true]; - case NSEventTypeRightMouseDown: - return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:true]; - case NSEventTypeLeftMouseDragged: - return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:true]; - case NSEventTypeRightMouseDragged: - return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:true]; - case NSEventTypeOtherMouseDragged: - return [self handleMouseEvent:event button:MOUSE_EVENT_MBUTTON= down:true]; - case NSEventTypeLeftMouseUp: - if (!isMouseGrabbed && [self screenContainsPoint:p]) { - /* - * In fullscreen mode, the window of cocoaView may not be = the - * key window, therefore the position relative to the virt= ual - * screen alone will be sufficient. - */ - if(isFullscreen || [[self window] isKeyWindow]) { - [self grabMouse]; - } - } - return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON= down:false]; - case NSEventTypeRightMouseUp: - return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON= down:false]; - case NSEventTypeOtherMouseUp: - return [self handleMouseEvent:event button:MOUSE_EVENT_MBUTTON= down:false]; case NSEventTypeScrollWheel: /* * Send wheel events to the guest regardless of window focus. @@ -1078,53 +978,117 @@ - (bool) handleEventLocked:(NSEvent *)event } } =20 -- (bool) handleMouseEvent:(NSEvent *)event +- (void) handleMouseEvent:(NSEvent *)event { if (!isMouseGrabbed) { - return false; + return; } =20 - if (isAbsoluteEnabled) { - NSPoint p =3D [self screenLocationOfEvent:event]; - /* Note that the origin for Cocoa mouse coords is bottom left, not= top left. - * The check on screenContainsPoint is to avoid sending out of ran= ge values for - * clicks in the titlebar. - */ - if ([self screenContainsPoint:p]) { - qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.wid= th); - qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.= y, 0, screen.height); + with_bql(^{ + if (isAbsoluteEnabled) { + CGFloat d =3D (CGFloat)screen.height / [self frame].size.heigh= t; + NSPoint p =3D [event locationInWindow]; + /* Note that the origin for Cocoa mouse coords is bottom left,= not top left. */ + qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x * d, 0, screen= .width); + qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.= y * d, 0, screen.height); + } else { + qemu_input_queue_rel(dcl.con, INPUT_AXIS_X, [event deltaX]); + qemu_input_queue_rel(dcl.con, INPUT_AXIS_Y, [event deltaY]); } - } else { - qemu_input_queue_rel(dcl.con, INPUT_AXIS_X, (int)[event deltaX]); - qemu_input_queue_rel(dcl.con, INPUT_AXIS_Y, (int)[event deltaY]); + + qemu_input_event_sync(); + }); +} + +- (void) handleMouseEvent:(NSEvent *)event button:(InputButton)button down= :(bool)down +{ + if (!isMouseGrabbed) { + return; } =20 - qemu_input_event_sync(); + with_bql(^{ + qemu_input_queue_btn(dcl.con, button, down); + }); =20 - return true; + [self handleMouseEvent:event]; } =20 -- (bool) handleMouseEvent:(NSEvent *)event button:(InputButton)button down= :(bool)down +- (void) mouseExited:(NSEvent *)event { - if (!isMouseGrabbed && ![[self window] isKeyWindow]) { - return false; + if (isAbsoluteEnabled && isMouseGrabbed) { + [self ungrabMouse]; } +} =20 - qemu_input_queue_btn(dcl.con, button, down); +- (void) mouseEntered:(NSEvent *)event +{ + if (isAbsoluteEnabled && !isMouseGrabbed) { + [self grabMouse]; + } +} + +- (void) mouseMoved:(NSEvent *)event +{ + [self handleMouseEvent:event]; +} + +- (void) mouseDown:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_LEFT down:true]; +} + +- (void) rightMouseDown:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_RIGHT down:true]; +} + +- (void) otherMouseDown:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_MIDDLE down:true]; +} + +- (void) mouseDragged:(NSEvent *)event +{ + [self handleMouseEvent:event]; +} + +- (void) rightMouseDragged:(NSEvent *)event +{ + [self handleMouseEvent:event]; +} + +- (void) otherMouseDragged:(NSEvent *)event +{ + [self handleMouseEvent:event]; +} + +- (void) mouseUp:(NSEvent *)event +{ + if (!isMouseGrabbed) { + [self grabMouse]; + } + + [self handleMouseEvent:event button:INPUT_BUTTON_LEFT down:false]; +} + +- (void) rightMouseUp:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_RIGHT down:false]; +} =20 - return [self handleMouseEvent:event]; +- (void) otherMouseUp:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_MIDDLE down:false]; } =20 - (void) grabMouse { COCOA_DEBUG("QemuCocoaView: grabMouse\n"); =20 - if (!isFullscreen) { - if (qemu_name) - [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - = (Press " UC_CTRL_KEY " " UC_ALT_KEY " G to release Mouse)", qemu_name]]; - else - [normalWindow setTitle:@"QEMU - (Press " UC_CTRL_KEY " " UC_A= LT_KEY " G to release Mouse)"]; - } + if (qemu_name) + [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Pre= ss " UC_CTRL_KEY " " UC_ALT_KEY " G to release Mouse)", qemu_name]]; + else + [normalWindow setTitle:@"QEMU - (Press " UC_CTRL_KEY " " UC_ALT_K= EY " G to release Mouse)"]; [self hideCursor]; CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); isMouseGrabbed =3D TRUE; // while isMouseGrabbed =3D TRUE, QemuCocoaAp= p sends all events to [cocoaView handleEvent:] @@ -1134,15 +1098,14 @@ - (void) ungrabMouse { COCOA_DEBUG("QemuCocoaView: ungrabMouse\n"); =20 - if (!isFullscreen) { - if (qemu_name) - [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", = qemu_name]]; - else - [normalWindow setTitle:@"QEMU"]; - } + if (qemu_name) + [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", qemu= _name]]; + else + [normalWindow setTitle:@"QEMU"]; [self unhideCursor]; CGAssociateMouseAndMouseCursorPosition(TRUE); isMouseGrabbed =3D FALSE; + [self raiseAllButtons]; } =20 - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled { @@ -1153,8 +1116,6 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled { } - (BOOL) isMouseGrabbed {return isMouseGrabbed;} - (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;} -- (float) cdx {return cdx;} -- (float) cdy {return cdy;} - (QEMUScreen) gscreen {return screen;} =20 /* @@ -1168,6 +1129,15 @@ - (void) raiseAllKeys qkbd_state_lift_all_keys(kbd); }); } + +- (void) raiseAllButtons +{ + with_bql(^{ + qemu_input_queue_btn(dcl.con, INPUT_BUTTON_LEFT, false); + qemu_input_queue_btn(dcl.con, INPUT_BUTTON_RIGHT, false); + qemu_input_queue_btn(dcl.con, INPUT_BUTTON_MIDDLE, false); + }); +} @end =20 =20 @@ -1182,7 +1152,6 @@ @interface QemuCocoaAppController : NSObject { } - (void)doToggleFullScreen:(id)sender; -- (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)zoomToFit:(id) sender; - (void)displayConsole:(id)sender; @@ -1224,7 +1193,8 @@ - (id) init exit(1); } [normalWindow setAcceptsMouseMovedEvents:YES]; - [normalWindow setTitle:@"QEMU"]; + [normalWindow setCollectionBehavior:NSWindowCollectionBehaviorFull= ScreenPrimary]; + [normalWindow setTitle:qemu_name ? [NSString stringWithFormat:@"QE= MU %s", qemu_name] : @"QEMU"]; [normalWindow setContentView:cocoaView]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; @@ -1294,10 +1264,21 @@ - (void)windowDidChangeScreen:(NSNotification *)not= ification [cocoaView updateUIInfo]; } =20 +- (void)windowDidEnterFullScreen:(NSNotification *)notification +{ + [cocoaView grabMouse]; +} + +- (void)windowDidExitFullScreen:(NSNotification *)notification +{ + [cocoaView resizeWindow]; + [cocoaView ungrabMouse]; +} + - (void)windowDidResize:(NSNotification *)notification { [cocoaView updateBounds]; - [cocoaView updateUIInfo]; + [cocoaView frameUpdated]; } =20 /* Called when the user clicks on a window's close button */ @@ -1313,6 +1294,23 @@ - (BOOL)windowShouldClose:(id)sender return NO; } =20 +- (NSSize) window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)= proposedSize +{ + if (stretch_video) { + return [cocoaView fixZoomedFullScreenSize:proposedSize]; + } + + return NSMakeSize([cocoaView gscreen].width, [cocoaView gscreen].heigh= t); +} + +- (NSApplicationPresentationOptions) window:(NSWindow *)window + willUseFullScreenPresentationOptions:= (NSApplicationPresentationOptions)proposedOptions; + +{ + return (proposedOptions & ~(NSApplicationPresentationAutoHideDock | NS= ApplicationPresentationAutoHideMenuBar)) | + NSApplicationPresentationHideDock | NSApplicationPresentationHi= deMenuBar; +} + /* * Called when QEMU goes into the background. Note that * [-NSWindowDelegate windowDidResignKey:] is used here instead of @@ -1332,14 +1330,7 @@ - (void) windowDidResignKey: (NSNotification *)aNoti= fication */ - (void) doToggleFullScreen:(id)sender { - [self toggleFullScreen:(id)sender]; -} - -- (void)toggleFullScreen:(id)sender -{ - COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n"); - - [cocoaView toggleFullScreen:sender]; + [normalWindow toggleFullScreen:sender]; } =20 - (void) setFullGrab:(id)sender @@ -1390,6 +1381,7 @@ - (void)zoomToFit:(id) sender if (stretch_video =3D=3D true) { [sender setState: NSControlStateValueOn]; } else { + [cocoaView resizeWindow]; [sender setState: NSControlStateValueOff]; } } @@ -2022,8 +2014,7 @@ static void cocoa_display_init(DisplayState *ds, Disp= layOptions *opts) =20 /* if fullscreen mode is to be used */ if (opts->has_full_screen && opts->full_screen) { - [NSApp activateIgnoringOtherApps: YES]; - [controller toggleFullScreen: nil]; + [normalWindow toggleFullScreen: nil]; } if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) { [controller setFullGrab: nil]; --=20 2.43.1 From nobody Fri Nov 1 05:30: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=1708168809; cv=none; d=zohomail.com; s=zohoarc; b=dpk+k8prakp74QeS20n07TwA954MpRBwTBc1iN7bkkZzIRZ8dIXr0WlT0xHdjZ0Ls0n2MsjSdXDr/0O4lO2EHzIgckwGqEcOF1PHwXNvzVk0SFs0yB9xtUXgAmnomi6+BU6J7ejzv/7HQMZ77kSzloO7PYCj9bE2n/kNIWdHSgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168809; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DO8YZPx6QrrKSNDeG/X3kChJmZWSkpzHJ3UAX5RJjfg=; b=UHDTdd+hGtzgW/c9E5USRNc3qVX1pROHDucEIJNDhI5L6isvN5ai+TDmrFHdpddjz7M6dEMA7r8ftOfHw7gTbbd83AMyHhgFt9Ov/xG8lYqmtccWNqcuVxnfIlGQAt+yRtaZ9VOP54un2JUdlHjMHQhukhDFJ1oKVeZtrLHrOFY= 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 1708168809975271.2708441613437; Sat, 17 Feb 2024 03:20:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIix-0007TU-QC; Sat, 17 Feb 2024 06:19:15 -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 1rbIiv-0007TG-1g for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:13 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIit-0002gJ-JE for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:12 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1d72f71f222so12185285ad.1 for ; Sat, 17 Feb 2024 03:19:11 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id e21-20020a17090ac21500b00298dd684b8csm1586463pjt.32.2024.02.17.03.19.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168750; x=1708773550; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DO8YZPx6QrrKSNDeG/X3kChJmZWSkpzHJ3UAX5RJjfg=; b=1B4IJk/wojUGS1K4+2dhsjv6K50nOXXg0ZwwEnEzyaMkpccISUsJN9p0fYHhcdIKEm xgAMNy8bhvZL/P4Yb4Q6517UXtvQCIXQiKtM/VG6uMbr7OWmp0Vxgu4mnej5VOsgeldO g/jo8GqKfsDlpk+8mTvRBz6ALkTEFPbGD00ihGgg8U+32Q3nQ1AdxYUvEIBWo5GWd7jq KbuqGp7jEtjIhTkfn74nm4iC+RhJVDWWoe2x0meOiWfomYfj8JHxXBRpHc2o0zlBs+LI F0Ht0NBnjqqP9hri78nvRA3JS/Eyy8Ba5syXahmqxKaL/DP/y2NIMsLi7+2SB+5dp+KL iRPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168750; x=1708773550; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DO8YZPx6QrrKSNDeG/X3kChJmZWSkpzHJ3UAX5RJjfg=; b=AwJRTU9VzMZAPr/94pUriW3pL3WAGt7AjDRaGjl+KbO15qAkSp5eeFk0Rto0T1ly9i hsvTG0N26Oqa3BGYiRipEKNeCeKA4MnbOPAcdtY1KclwGmffAPqN431Kc3oByrBfBCL4 U13mZE2R1dFi4N0ikNvIcEwAA9lnf7L/j+/f1+UN7L9GyGm+pM2VPoYCwaq+s1ni3ETx Cf6KJJRw9/sMPb3t9C3jm1N/FwQW9rWE8pSFz9D+w5Hg8d1PBMGER0aBznateUQIpFzd gWu4uFzv9MV7+7klPFW/YdMMxcmPf/KtBSCr06cs0qiQ0cyrDkWsRvu4O82RkOvBR5CX 43Qg== X-Gm-Message-State: AOJu0Yxg+4GXtEckYtTo7+3fgF0uxqwSbZTyOYlxkZxyIXKYo1MtaHc5 PU9S0V4XVR7CCW1w9WMfa4Z+0FkDYasOxPWpLhCDDMeTLDtNU8MnuKmCTeIrOdc= X-Google-Smtp-Source: AGHT+IEbAAC0ZrJ9krUDnZ8sltdpmoIrCjN6VBn1RqJXaLoogugpnsrnB58hAHjVlMN6JMMMbY3Fyw== X-Received: by 2002:a17:902:da87:b0:1db:28c4:b757 with SMTP id j7-20020a170902da8700b001db28c4b757mr8454048plx.0.1708168750434; Sat, 17 Feb 2024 03:19:10 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:50 +0900 Subject: [PATCH v11 4/6] ui/cocoa: Make window resizable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-4-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::632; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x632.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, 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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168811808100011 The window will be resizable when zoom-to-fit is on. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- ui/cocoa.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 0ebe0f326373..17f290987563 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1379,8 +1379,10 @@ - (void)zoomToFit:(id) sender { stretch_video =3D !stretch_video; if (stretch_video =3D=3D true) { + [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyl= eMaskResizable]; [sender setState: NSControlStateValueOn]; } else { + [normalWindow setStyleMask:[normalWindow styleMask] & ~NSWindowSty= leMaskResizable]; [cocoaView resizeWindow]; [sender setState: NSControlStateValueOff]; } @@ -2033,6 +2035,7 @@ static void cocoa_display_init(DisplayState *ds, Disp= layOptions *opts) =20 if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) { stretch_video =3D true; + [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyl= eMaskResizable]; } =20 create_initial_menus(); --=20 2.43.1 From nobody Fri Nov 1 05:30: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=1708168836; cv=none; d=zohomail.com; s=zohoarc; b=B4wEuJ5v84Sre11qOeDDX5TBMWU8F3gyy7yWexateDDO82n2vK2lKR+w7QdnIuEH4KfMqB0encYmHPAiA+wKdanzMDNPmqTmuIppXa0BRrlyFUNY4UaGRQoDFkxSfN11faKcxPUdi3C08FoDavh0YoXou/oZrVSiuDQojzCxEuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cQV0Uu2y+Oze5LMvp7CVg9JHrPQPcJX0lu2SgQQmfr0=; b=nit1FvnW4hsb27Ks2faCx8QrArAE6IOULVQXVSCZZMMQOCMEAhxqpifIcFn7VTv95aQ6W+oPM9nIszJGhd9Lh0clYg+5xMimaOBJKupFcE4apuDHxZcA+iOKRJclzluaVOVpCq3pBF82mqBH7Mafsi2GKQl0FNMEvI59BQM2MAY= 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 1708168836563756.1882100715228; Sat, 17 Feb 2024 03:20:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIj2-0007UT-Ua; Sat, 17 Feb 2024 06:19:21 -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 1rbIiz-0007Tk-V8 for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:17 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIix-0002gm-Gs for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:16 -0500 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-29026523507so2205143a91.0 for ; Sat, 17 Feb 2024 03:19:15 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id w6-20020a17090a1b8600b002966a13f2e9sm1505548pjc.37.2024.02.17.03.19.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:19:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168754; x=1708773554; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cQV0Uu2y+Oze5LMvp7CVg9JHrPQPcJX0lu2SgQQmfr0=; b=MQxVjXMYhNaSGsEhPPGc+VZMf1eF5rojo7CCFxFBH5dcqVQowCqFQ9yDDzB3xCldS6 LVcyInc1u89M1Kvlmiku74Y0i6CVUOUem+la7RsrTTEeYdkP7w0+i2GpyekfqRt+Xis/ 5uS6vGpk2Mz+irOqv9+muryvNDnqi3la9iLp+jV03pRYPrUBbXDWWCqVvZ+jp5gLUwpk 8sQp2EbmKP6NFHVEc4T4x/8ce90St1arbJuctR6X0BxvckA4lnWF4Thz8QvSoybKjBmP 8aRDGRRbUadNmBqdBH1JxzH0vmBq9/6EmHJM30HCVMYB7CY14f6oHdwskScqzGJKRznt AWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168754; x=1708773554; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cQV0Uu2y+Oze5LMvp7CVg9JHrPQPcJX0lu2SgQQmfr0=; b=jOj9QOs+O5LSx3zqdj2sRxvBPtDlVDWngHzqOaoTotJlX+2arwGvObYB0ptSZJ4uLB NJIoJjdYf091pmdmqn3TD+SGISxBdETJcZbiztlnqxb4gNyWaYP9goK7azLoJmi+uDwa K8D2jM1M7mwO2T1xu06Ux6zcM2AK2eAXGjCyRO9Pm413Cfl5nT2Q5cmCln5LhxIHqH1R pX96tjkWiqc1fxtNpr5k/WG1I6N43gcVvexDs/rtGZ1BoCKVAc/I1STLZy5aVznoMv/h eTF+LlCMiBWuC+Lh48Ns1psxu5N10LEm71YNH/5a2+tNWl2bVNcs9BLNn6PWloLX/r1f 5fVg== X-Gm-Message-State: AOJu0YyqOCF1JoMfjvnvnzqsXVh9uURv62xR7bLHnqA6c1Y5mMJ11uCM T8jcmZxJMQk4qTkww5xKiTprRbdwtwTwjZVuzV3ceBnH8R+0pFODgn0FClkugu4= X-Google-Smtp-Source: AGHT+IG9eTn8rFlHd9xyVziFMfKVuG60Ok6JELkQibygCWt+xFKiapf8lIj7HCx04NLczNRAauX2RA== X-Received: by 2002:a17:90b:e8c:b0:299:3497:40d4 with SMTP id fv12-20020a17090b0e8c00b00299349740d4mr3617308pjb.35.1708168754176; Sat, 17 Feb 2024 03:19:14 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:51 +0900 Subject: [PATCH v11 5/6] ui/cocoa: Call console_select() with the BQL MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-5-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::1033; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1033.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, 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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168837955100003 console_select() can be called anytime so explicitly take the BQL. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- ui/cocoa.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 17f290987563..81de8d92669b 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1391,7 +1391,9 @@ - (void)zoomToFit:(id) sender /* Displays the console on the screen */ - (void)displayConsole:(id)sender { - console_select([sender tag]); + with_bql(^{ + console_select([sender tag]); + }); } =20 /* Pause the guest */ --=20 2.43.1 From nobody Fri Nov 1 05:30: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=1708168836; cv=none; d=zohomail.com; s=zohoarc; b=Rjd6d1uyg98NZ66La42zMLqp0nKDn/jPKvbzMtX5HITm21Y1fIWr2fGeY/AuXQfXRbGrzm9Njoq2NwKn7TPKVjk7vThpc1q4PBMbEdBNJpQFwOPOQQBY/TZzYR0y8OcR+TavkwQakn+iDhDG6lvEnJppCYGDO3iTDdonC6X4hgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708168836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Rh6E8zcXhleUApU9zQlOU01Crb6mmE2x6guB2DANNRU=; b=MyGWVd4MXFSH14HmspBAlPto72N6egdNHJIm3m27HX5hVRVxitTZ6GHHGZ+SpXZhPA5ZcoMkdR7l3Gr96XsihK9KflqeU3KQ7QERheQiOsTEuLswcs+LHGfHDjkujOaIhPPkkCQ1XVDRlOiT7+AaQfCGEzqj5615SnlhQENXlKc= 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 1708168836552846.1343082975957; Sat, 17 Feb 2024 03:20:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbIj8-0007Wj-9p; Sat, 17 Feb 2024 06:19:26 -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 1rbIj3-0007Uk-On for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:22 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbIj1-0002h4-Hy for qemu-devel@nongnu.org; Sat, 17 Feb 2024 06:19:21 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dba94f9201so13161295ad.0 for ; Sat, 17 Feb 2024 03:19:19 -0800 (PST) Received: from localhost ([157.82.200.138]) by smtp.gmail.com with UTF8SMTPSA id jw6-20020a170903278600b001d9620dd3fdsm1242592plb.206.2024.02.17.03.19.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Feb 2024 03:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1708168758; x=1708773558; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Rh6E8zcXhleUApU9zQlOU01Crb6mmE2x6guB2DANNRU=; b=VJWFjK2obYlqpLRU6QCuL+4eIp9Qv+Xggml9aaN2/YjB92A3ETco82OTcj8vBAdJ/7 DfATdrz0dxekXPRn1DPCegmFL2ie6YjJKSTZqKLrIj0xbthNfaCRFaeJ31RwiCOgRvR7 QuoX/rqlfURI7aap/y2lMbvI6cnyY5EO0auxP/2LfYSrfy2kWfQN9+k9hNaB13YDhxBw 7BmtISpMpmCUqFvl12zVsUg2q2xScnOG/5a+53NECXlxEydvyIjpPtx3ir9HXKDh1qNP feMBIdIE2bxZtq1qGQCNnJdIx4PxnTl+Yi+Hr2EbH/7CRwu2YIZpR00NdkFP5+CksU8c loJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708168758; x=1708773558; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rh6E8zcXhleUApU9zQlOU01Crb6mmE2x6guB2DANNRU=; b=jqEe8ssHTI+hJf/76sNWdssE2pPuuzhHfS3ZOhATY4DeaZrP4M2oTG5mpd7V3+pTnY CH3/5T2zN5uSGYd4ekkwXUelQA0C8bJvaGMq+l8Apdgb8nEdohkTH6k6L2a4aDXaCnfc xelYJYcY5TxMFRY0Y4ch2Kj0BYKrbF99q3LorCllmGbt0OFF9hbj34/2imoEkhaPYbbl 8DUI3C2kLQkcOCrxCdGsXN5mST63aB/jxTSADJrYfkxoNINJqXOf0njYkaki7/e6U8fX gFwh0A+lSYwVQBCJN+ZzsoIKiOxp5LofMWMDbw5Hamiqubzt5M14WRx73pzOU8sb5wyy 6H6g== X-Gm-Message-State: AOJu0Yy9aWVqp/BUHNucp2TTyLQdgcRWHEke7BU9AzizyghCtIC30sM1 gJp6lCyalNd+B9rvD0NKabc8B4ikvi2dsEBAbmUvfa3Oyjd6NDU/leC8aP7nbQY= X-Google-Smtp-Source: AGHT+IG5H0/MxAv32L/7aiqrpAU3y92JItd0nir3z896HPdvjyiO+V5cv0BQZh4i1BgVGLsdZryKTA== X-Received: by 2002:a17:902:ccc8:b0:1db:aef3:ac06 with SMTP id z8-20020a170902ccc800b001dbaef3ac06mr4666484ple.4.1708168758419; Sat, 17 Feb 2024 03:19:18 -0800 (PST) From: Akihiko Odaki Date: Sat, 17 Feb 2024 20:18:52 +0900 Subject: [PATCH v11 6/6] ui/cocoa: Remove stretch_video flag MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240217-cocoa-v11-6-0a17a7e534d4@daynix.com> References: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> In-Reply-To: <20240217-cocoa-v11-0-0a17a7e534d4@daynix.com> To: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Marek Glogowski , BALATON Zoltan , Rene Engel 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::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.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, 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: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1708168837994100005 Evaluate [normalWindow styleMask] & NSWindowStyleMaskResizable instead. Signed-off-by: Akihiko Odaki --- ui/cocoa.m | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 81de8d92669b..401ed0c3f1f5 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -103,7 +103,6 @@ static void cocoa_switch(DisplayChangeListener *dcl, static int left_command_key_enabled =3D 1; static bool swap_opt_cmd; =20 -static bool stretch_video; static NSTextField *pauseLabel; =20 static bool allow_events; @@ -533,7 +532,7 @@ - (void) resizeWindow { [[self window] setContentAspectRatio:NSMakeSize(screen.width, screen.h= eight)]; =20 - if (!stretch_video) { + if (!([[self window] styleMask] & NSWindowStyleMaskResizable)) { [[self window] setContentSize:NSMakeSize(screen.width, screen.heig= ht)]; [[self window] center]; } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { @@ -1296,7 +1295,7 @@ - (BOOL)windowShouldClose:(id)sender =20 - (NSSize) window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)= proposedSize { - if (stretch_video) { + if ([normalWindow styleMask] & NSWindowStyleMaskResizable) { return [cocoaView fixZoomedFullScreenSize:proposedSize]; } =20 @@ -1377,8 +1376,7 @@ - (void)showQEMUDoc:(id)sender /* Stretches video to fit host monitor size */ - (void)zoomToFit:(id) sender { - stretch_video =3D !stretch_video; - if (stretch_video =3D=3D true) { + if (([normalWindow styleMask] & NSWindowStyleMaskResizable) =3D=3D 0) { [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyl= eMaskResizable]; [sender setState: NSControlStateValueOn]; } else { @@ -1650,7 +1648,7 @@ static void create_initial_menus(void) menu =3D [[NSMenu alloc] initWithTitle:@"View"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" = action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; //= Fullscreen menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:= @selector(zoomToFit:) keyEquivalent:@""] autorelease]; - [menuItem setState: stretch_video ? NSControlStateValueOn : NSControlS= tateValueOff]; + [menuItem setState: [normalWindow styleMask] & NSWindowStyleMaskResiza= ble ? NSControlStateValueOn : NSControlStateValueOff]; [menu addItem: menuItem]; menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil key= Equivalent:@""] autorelease]; [menuItem setSubmenu:menu]; @@ -2036,7 +2034,6 @@ static void cocoa_display_init(DisplayState *ds, Disp= layOptions *opts) } =20 if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) { - stretch_video =3D true; [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyl= eMaskResizable]; } =20 --=20 2.43.1