From patchwork Sat Feb 17 11:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C3B0C48BF5 for ; Sat, 17 Feb 2024 11:20:09 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = { .ops = &dcl_ops, }; -static int last_buttons; static int cursor_hide = 1; static int left_command_key_enabled = 1; static bool swap_opt_cmd; @@ -801,8 +800,6 @@ - (bool) handleEventLocked:(NSEvent *)event COCOA_DEBUG("QemuCocoaView: handleEvent\n"); int buttons = 0; int keycode = 0; - bool mouse_event = false; - // Location of event in virtual screen coordinates NSPoint p = [self screenLocationOfEvent:event]; NSUInteger modifiers = [event modifierFlags]; @@ -883,25 +880,25 @@ - (bool) handleEventLocked:(NSEvent *)event if (!!(modifiers & NSEventModifierFlagShift)) { [self toggleKey:Q_KEY_CODE_SHIFT]; } - break; + return true; case kVK_RightShift: if (!!(modifiers & NSEventModifierFlagShift)) { [self toggleKey:Q_KEY_CODE_SHIFT_R]; } - break; + return true; case kVK_Control: if (!!(modifiers & NSEventModifierFlagControl)) { [self toggleKey:Q_KEY_CODE_CTRL]; } - break; + return true; case kVK_RightControl: if (!!(modifiers & NSEventModifierFlagControl)) { [self toggleKey:Q_KEY_CODE_CTRL_R]; } - break; + return true; case kVK_Option: if (!!(modifiers & NSEventModifierFlagOption)) { @@ -911,7 +908,7 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_ALT]; } } - break; + return true; case kVK_RightOption: if (!!(modifiers & NSEventModifierFlagOption)) { @@ -921,7 +918,7 @@ - (bool) handleEventLocked:(NSEvent *)event [self toggleKey:Q_KEY_CODE_ALT_R]; } } - break; + return true; /* 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; 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 = cocoa_keycode_to_qemu([event keyCode]); @@ -983,7 +982,7 @@ - (bool) handleEventLocked:(NSEvent *)event } else { [self handleMonitorInput: event]; } - break; + return true; case NSEventTypeKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]); @@ -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 bound to screen coordinates @@ -1012,34 +1011,18 @@ - (bool) handleEventLocked:(NSEvent *)event } } } - mouse_event = true; - break; + return [self handleMouseEvent:event]; case NSEventTypeLeftMouseDown: - buttons |= MOUSE_EVENT_LBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON down:true]; case NSEventTypeRightMouseDown: - buttons |= MOUSE_EVENT_RBUTTON; - mouse_event = true; - break; - case NSEventTypeOtherMouseDown: - buttons |= MOUSE_EVENT_MBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON down:true]; case NSEventTypeLeftMouseDragged: - buttons |= MOUSE_EVENT_LBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_LBUTTON down:true]; case NSEventTypeRightMouseDragged: - buttons |= MOUSE_EVENT_RBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON down:true]; case NSEventTypeOtherMouseDragged: - buttons |= MOUSE_EVENT_MBUTTON; - mouse_event = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_MBUTTON down:true]; case NSEventTypeLeftMouseUp: - mouse_event = 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 = true; - break; + return [self handleMouseEvent:event button:MOUSE_EVENT_RBUTTON down:false]; case NSEventTypeOtherMouseUp: - mouse_event = 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 prevent mouse * movement code from executing. */ - mouse_event = false; - break; + return true; default: return false; } +} + +- (bool) handleMouseEvent:(NSEvent *)event +{ + if (!isMouseGrabbed) { + return false; + } - 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 = [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 range values for + * clicks in the titlebar. */ - if ((isMouseGrabbed || [[self window] isKeyWindow]) && - (last_buttons != buttons)) { - static uint32_t bmap[INPUT_BUTTON__MAX] = { - [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, - [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON, - [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON - }; - qemu_input_update_buttons(dcl.con, bmap, last_buttons, buttons); - last_buttons = buttons; - } - if (isMouseGrabbed) { - if (isAbsoluteEnabled) { - /* Note that the origin for Cocoa mouse coords is bottom left, not top left. - * The check on screenContainsPoint is to avoid sending out of range values for - * clicks in the titlebar. - */ - if ([self screenContainsPoint:p]) { - qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.width); - qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.y, 0, screen.height); - } - } 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]); - } - } else { - return false; + if ([self screenContainsPoint:p]) { + qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.width); + 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; } +- (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"); From patchwork Sat Feb 17 11:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 688A0C5475B for ; Sat, 17 Feb 2024 11:20:36 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 [self getRectsBeingDrawn:&rectList count:&rectCount]; for (i = 0; i < rectCount; i++) { - clipRect.origin.x = rectList[i].origin.x / cdx; - clipRect.origin.y = (float)h - (rectList[i].origin.y + rectList[i].size.height) / cdy; - clipRect.size.width = rectList[i].size.width / cdx; - clipRect.size.height = rectList[i].size.height / cdy; + clipRect = rectList[i]; + clipRect.origin.y = (float)h - (clipRect.origin.y + clipRect.size.height); clipImageRef = CGImageCreateWithImageInRect( imageRef, clipRect @@ -545,6 +543,11 @@ - (void) setContentDimensions } } +- (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 = h; [self setContentDimensions]; [self setFrame:NSMakeRect(cx, cy, cw, ch)]; + [self updateBounds]; } // update screenBuffer @@ -1292,6 +1296,7 @@ - (void)windowDidChangeScreen:(NSNotification *)notification - (void)windowDidResize:(NSNotification *)notification { + [cocoaView updateBounds]; [cocoaView updateUIInfo]; } @@ -1940,16 +1945,7 @@ static void cocoa_update(DisplayChangeListener *dcl, COCOA_DEBUG("qemu_cocoa: cocoa_update\n"); dispatch_async(dispatch_get_main_queue(), ^{ - NSRect rect; - if ([cocoaView cdx] == 1.0) { - rect = NSMakeRect(x, [cocoaView gscreen].height - y - h, w, h); - } else { - rect = NSMakeRect( - x * [cocoaView cdx], - ([cocoaView gscreen].height - y - h) * [cocoaView cdy], - w * [cocoaView cdx], - h * [cocoaView cdy]); - } + NSRect rect = NSMakeRect(x, [cocoaView gscreen].height - y - h, w, h); [cocoaView setNeedsDisplayInRect:rect]; }); } From patchwork Sat Feb 17 11:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78EA9C54764 for ; Sat, 17 Feb 2024 11:20:36 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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; } -- (BOOL) screenContainsPoint:(NSPoint) p +- (void) removeTrackingRect { - return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height); + if (trackingArea) { + [self removeTrackingArea:trackingArea]; + [trackingArea release]; + trackingArea = nil; + } } -/* Get location of event and convert to virtual screen coordinate */ -- (CGPoint) screenLocationOfEvent:(NSEvent *)ev +- (void) frameUpdated { - NSWindow *eventWindow = [ev window]; - // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10 - CGRect r = CGRectZero; - r.origin = [ev locationInWindow]; - if (!eventWindow) { - if (!isFullscreen) { - return [[self window] convertRectFromScreen:r].origin; - } else { - CGPoint locationInSelfWindow = [[self window] convertRectFromScreen:r].origin; - CGPoint loc = [self convertPoint:locationInSelfWindow fromView:nil]; - if (stretch_video) { - loc.x /= cdx; - loc.y /= cdy; - } - return loc; - } - } else if ([[self window] isEqual:eventWindow]) { - if (!isFullscreen) { - return r.origin; - } else { - CGPoint loc = [self convertPoint:r.origin fromView:nil]; - if (stretch_video) { - loc.x /= cdx; - loc.y /= cdy; - } - return loc; - } - } else { - return [[self window] convertRectFromScreen:[eventWindow convertRectToScreen:r]].origin; + [self removeTrackingRect]; + + if ([self window]) { + NSTrackingAreaOptions options = NSTrackingActiveInKeyWindow | + NSTrackingMouseEnteredAndExited | + NSTrackingMouseMoved; + trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] + options:options + owner:self + userInfo:nil]; + [self addTrackingArea:trackingArea]; + [self updateUIInfo]; } } +- (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 } } -- (void) setContentDimensions +- (NSSize) fixZoomedFullScreenSize:(NSSize)proposedSize { - COCOA_DEBUG("QemuCocoaView: setContentDimensions\n"); + NSSize size; - if (isFullscreen) { - cdx = [[NSScreen mainScreen] frame].size.width / (float)screen.width; - cdy = [[NSScreen mainScreen] frame].size.height / (float)screen.height; + size.width = (CGFloat)screen.width * proposedSize.height; + size.height = (CGFloat)screen.height * proposedSize.width; - /* stretches video, but keeps same aspect ratio */ - if (stretch_video == true) { - /* use smallest stretch value - prevents clipping on sides */ - if (MIN(cdx, cdy) == cdx) { - cdy = cdx; - } else { - cdx = cdy; - } - } else { /* No stretching */ - cdx = cdy = 1; - } - cw = screen.width * cdx; - ch = screen.height * cdy; - cx = ([[NSScreen mainScreen] frame].size.width - cw) / 2.0; - cy = ([[NSScreen mainScreen] frame].size.height - ch) / 2.0; + if (size.width < size.height) { + size.width /= screen.height; + size.height = proposedSize.height; } else { - cx = 0; - cy = 0; - cw = screen.width; - ch = screen.height; - cdx = 1.0; - cdy = 1.0; + size.width = proposedSize.width; + size.height /= screen.width; + } + + return size; +} + +- (NSSize) screenSafeAreaSize +{ + NSSize size = [[[self window] screen] frame].size; + NSEdgeInsets insets = [[[self window] screen] safeAreaInsets]; + size.width -= insets.left + insets.right; + size.height -= insets.top + insets.bottom; + return size; +} + +- (void) resizeWindow +{ + [[self window] setContentAspectRatio:NSMakeSize(screen.width, screen.height)]; + + if (!stretch_video) { + [[self window] setContentSize:NSMakeSize(screen.width, screen.height)]; + [[self window] center]; + } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { + [[self window] setContentSize:[self fixZoomedFullScreenSize:[self screenSafeAreaSize]]]; + [[self window] center]; } } @@ -563,9 +562,10 @@ - (void) updateUIInfoLocked CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]; NSSize screenSize = [[[self window] screen] frame].size; CGSize screenPhysicalSize = CGDisplayScreenSize(display); + bool isFullscreen = ([[self window] styleMask] & NSWindowStyleMaskFullScreen) != 0; CVDisplayLinkRef displayLink; - frameSize = isFullscreen ? screenSize : [self frame].size; + frameSize = isFullscreen ? [self screenSafeAreaSize] : [self frame].size; if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) { CVTime period = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); @@ -612,31 +612,19 @@ - (void) updateUIInfo }); } -- (void)viewDidMoveToWindow -{ - [self updateUIInfo]; -} - - (void) switchSurface:(pixman_image_t *)image { COCOA_DEBUG("QemuCocoaView: switchSurface\n"); int w = pixman_image_get_width(image); int h = pixman_image_get_height(image); - /* cdx == 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 = (w != screen.width || h != screen.height || cdx == 0.0); - int oldh = screen.height; - if (isResize) { + if (w != screen.width || h != screen.height) { // Resize before we trigger the redraw, or we'll redraw at the wrong size COCOA_DEBUG("switchSurface: new size %d x %d\n", w, h); screen.width = w; screen.height = h; - [self setContentDimensions]; - [self setFrame:NSMakeRect(cx, cy, cw, ch)]; + [self resizeWindow]; [self updateBounds]; } @@ -646,51 +634,6 @@ - (void) switchSurface:(pixman_image_t *)image } pixman_image = image; - - // update windows - if (isFullscreen) { - [[fullScreenWindow contentView] setFrame:[[NSScreen mainScreen] frame]]; - [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.height - 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.height - 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 = FALSE; - [self ungrabMouse]; - [self setContentDimensions]; - [fullScreenWindow close]; - [normalWindow setContentView: self]; - [normalWindow makeKeyAndOrderFront: self]; - [NSMenu setMenuBarVisible:YES]; - } else { // switch from desktop to fullscreen - isFullscreen = TRUE; - [normalWindow orderOut: nil]; /* Hide the window */ - [self grabMouse]; - [self setContentDimensions]; - [NSMenu setMenuBarVisible:NO]; - fullScreenWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen 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]; - } } - (void) setFullGrab:(id)sender @@ -804,7 +747,6 @@ - (bool) handleEventLocked:(NSEvent *)event COCOA_DEBUG("QemuCocoaView: handleEvent\n"); int buttons = 0; int keycode = 0; - NSPoint p = [self screenLocationOfEvent:event]; NSUInteger modifiers = [event modifierFlags]; /* @@ -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 bound to screen coordinates - // and `nil` window property, and in full screen mode, current window might not be - // key window, where event location alone should suffice. - if (![self screenContainsPoint:p] || !([[self window] isKeyWindow] || 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 virtual - * 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 } } -- (bool) handleMouseEvent:(NSEvent *)event +- (void) handleMouseEvent:(NSEvent *)event { if (!isMouseGrabbed) { - return false; + return; } - if (isAbsoluteEnabled) { - NSPoint p = [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 range values for - * clicks in the titlebar. - */ - if ([self screenContainsPoint:p]) { - qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.width); - qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.y, 0, screen.height); + with_bql(^{ + if (isAbsoluteEnabled) { + CGFloat d = (CGFloat)screen.height / [self frame].size.height; + NSPoint p = [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; } - qemu_input_event_sync(); + with_bql(^{ + qemu_input_queue_btn(dcl.con, button, down); + }); - return true; + [self handleMouseEvent:event]; } -- (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]; } +} - 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]; +} - return [self handleMouseEvent:event]; +- (void) otherMouseUp:(NSEvent *)event +{ + [self handleMouseEvent:event button:INPUT_BUTTON_MIDDLE down:false]; } - (void) grabMouse { COCOA_DEBUG("QemuCocoaView: grabMouse\n"); - 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_ALT_KEY " G to release Mouse)"]; - } + 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_ALT_KEY " G to release Mouse)"]; [self hideCursor]; CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); isMouseGrabbed = TRUE; // while isMouseGrabbed = TRUE, QemuCocoaApp sends all events to [cocoaView handleEvent:] @@ -1134,15 +1098,14 @@ - (void) ungrabMouse { COCOA_DEBUG("QemuCocoaView: ungrabMouse\n"); - 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 = FALSE; + [self raiseAllButtons]; } - (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;} /* @@ -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 @@ -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:NSWindowCollectionBehaviorFullScreenPrimary]; + [normalWindow setTitle:qemu_name ? [NSString stringWithFormat:@"QEMU %s", qemu_name] : @"QEMU"]; [normalWindow setContentView:cocoaView]; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; @@ -1294,10 +1264,21 @@ - (void)windowDidChangeScreen:(NSNotification *)notification [cocoaView updateUIInfo]; } +- (void)windowDidEnterFullScreen:(NSNotification *)notification +{ + [cocoaView grabMouse]; +} + +- (void)windowDidExitFullScreen:(NSNotification *)notification +{ + [cocoaView resizeWindow]; + [cocoaView ungrabMouse]; +} + - (void)windowDidResize:(NSNotification *)notification { [cocoaView updateBounds]; - [cocoaView updateUIInfo]; + [cocoaView frameUpdated]; } /* Called when the user clicks on a window's close button */ @@ -1313,6 +1294,23 @@ - (BOOL)windowShouldClose:(id)sender return NO; } +- (NSSize) window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize +{ + if (stretch_video) { + return [cocoaView fixZoomedFullScreenSize:proposedSize]; + } + + return NSMakeSize([cocoaView gscreen].width, [cocoaView gscreen].height); +} + +- (NSApplicationPresentationOptions) window:(NSWindow *)window + willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions; + +{ + return (proposedOptions & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)) | + NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar; +} + /* * Called when QEMU goes into the background. Note that * [-NSWindowDelegate windowDidResignKey:] is used here instead of @@ -1332,14 +1330,7 @@ - (void) windowDidResignKey: (NSNotification *)aNotification */ - (void) doToggleFullScreen:(id)sender { - [self toggleFullScreen:(id)sender]; -} - -- (void)toggleFullScreen:(id)sender -{ - COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n"); - - [cocoaView toggleFullScreen:sender]; + [normalWindow toggleFullScreen:sender]; } - (void) setFullGrab:(id)sender @@ -1390,6 +1381,7 @@ - (void)zoomToFit:(id) sender if (stretch_video == true) { [sender setState: NSControlStateValueOn]; } else { + [cocoaView resizeWindow]; [sender setState: NSControlStateValueOff]; } } @@ -2022,8 +2014,7 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) /* 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]; From patchwork Sat Feb 17 11:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1E13C48BC4 for ; Sat, 17 Feb 2024 11:20:09 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = !stretch_video; if (stretch_video == true) { + [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyleMaskResizable]; [sender setState: NSControlStateValueOn]; } else { + [normalWindow setStyleMask:[normalWindow styleMask] & ~NSWindowStyleMaskResizable]; [cocoaView resizeWindow]; [sender setState: NSControlStateValueOff]; } @@ -2033,6 +2035,7 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) { stretch_video = true; + [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyleMaskResizable]; } create_initial_menus(); From patchwork Sat Feb 17 11:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62943C48BC4 for ; Sat, 17 Feb 2024 11:20:36 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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]); + }); } /* Pause the guest */ From patchwork Sat Feb 17 11:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13561327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A9BCC48BC3 for ; Sat, 17 Feb 2024 11:20:36 +0000 (UTC) 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) 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) 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) 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 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-Dau?= =?utf-8?q?d=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: 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = 1; static bool swap_opt_cmd; -static bool stretch_video; static NSTextField *pauseLabel; static bool allow_events; @@ -533,7 +532,7 @@ - (void) resizeWindow { [[self window] setContentAspectRatio:NSMakeSize(screen.width, screen.height)]; - if (!stretch_video) { + if (!([[self window] styleMask] & NSWindowStyleMaskResizable)) { [[self window] setContentSize:NSMakeSize(screen.width, screen.height)]; [[self window] center]; } else if ([[self window] styleMask] & NSWindowStyleMaskFullScreen) { @@ -1296,7 +1295,7 @@ - (BOOL)windowShouldClose:(id)sender - (NSSize) window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize { - if (stretch_video) { + if ([normalWindow styleMask] & NSWindowStyleMaskResizable) { return [cocoaView fixZoomedFullScreenSize:proposedSize]; } @@ -1377,8 +1376,7 @@ - (void)showQEMUDoc:(id)sender /* Stretches video to fit host monitor size */ - (void)zoomToFit:(id) sender { - stretch_video = !stretch_video; - if (stretch_video == true) { + if (([normalWindow styleMask] & NSWindowStyleMaskResizable) == 0) { [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyleMaskResizable]; [sender setState: NSControlStateValueOn]; } else { @@ -1650,7 +1648,7 @@ static void create_initial_menus(void) menu = [[NSMenu alloc] initWithTitle:@"View"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen menuItem = [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]; - [menuItem setState: stretch_video ? NSControlStateValueOn : NSControlStateValueOff]; + [menuItem setState: [normalWindow styleMask] & NSWindowStyleMaskResizable ? NSControlStateValueOn : NSControlStateValueOff]; [menu addItem: menuItem]; menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease]; [menuItem setSubmenu:menu]; @@ -2036,7 +2034,6 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) } if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) { - stretch_video = true; [normalWindow setStyleMask:[normalWindow styleMask] | NSWindowStyleMaskResizable]; }