From 713911a10752642564ff9b7c9c0bd1a5498105a5 Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Fri, 1 Jul 2022 21:43:04 -0700 Subject: ui/cocoa: Fix switched_to_fullscreen warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I noticed this error while building QEMU on Mac OS X: [1040/1660] Compiling Objective-C object libcommon.fa.p/ui_cocoa.m.o ../ui/cocoa.m:803:17: warning: variable 'switched_to_fullscreen' set but not used [-Wunused-but-set-variable] static bool switched_to_fullscreen = false; ^ 1 warning generated. I think the behavior is fine if you remove "switched_to_fullscreen", I can still switch in and out of mouse grabbed mode and fullscreen mode with this change, and Command keycodes will only be passed to the guest if the mouse is grabbed, which I think is the right behavior. I'm not sure why a static piece of state was needed to handle that in the first place. Perhaps the refactoring of the flags-state-change fixed that by toggling the Command keycode on. I tested this with an Ubuntu core image on macOS 12.4 wget https://cdimage.ubuntu.com/ubuntu-core/18/stable/current/ubuntu-core-18-i386.img.xz xz -d ubuntu-core-18-i386.img.xz qemu-system-x86_64 -drive file=ubuntu-core-18.i386.img,format=raw Fixes: 6d73bb643aa7 ("ui/cocoa: Clear modifiers whenever possible") Signed-off-by: Peter Delevoryas Reviewed-by: Akihiko Odaki Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20220702044304.90553-1-peter@pjd.dev> Signed-off-by: Philippe Mathieu-Daudé --- ui/cocoa.m | 8 -------- 1 file changed, 8 deletions(-) (limited to 'ui') diff --git a/ui/cocoa.m b/ui/cocoa.m index 6a4dccff..e883c74 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -800,7 +800,6 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven int buttons = 0; int keycode = 0; bool mouse_event = false; - static bool switched_to_fullscreen = false; // Location of event in virtual screen coordinates NSPoint p = [self screenLocationOfEvent:event]; NSUInteger modifiers = [event modifierFlags]; @@ -952,13 +951,6 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven // forward command key combos to the host UI unless the mouse is grabbed if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) { - /* - * Prevent the command key from being stuck down in the guest - * when using Command-F to switch to full screen mode. - */ - if (keycode == Q_KEY_CODE_F) { - switched_to_fullscreen = true; - } return false; } -- cgit v1.1 From 52eaefd36c33d17c5c52de0d02f1edf7400c0abb Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Sat, 2 Jul 2022 23:25:19 +0900 Subject: ui/cocoa: Take refresh rate into account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Retrieve the refresh rate of the display and reflect it with dpy_set_ui_info() and update_displaychangelistener(), allowing the guest and DisplayChangeListener to consume the information. The information will be used as a hint how often the display should be updated. For example, when we run 30 Hz physical display updates it is pointless for the guest to update the screen at 60Hz frequency, the guest can spare some work instead. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Message-Id: <20220702142519.12188-1-akihiko.odaki@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- ui/cocoa.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ui') diff --git a/ui/cocoa.m b/ui/cocoa.m index e883c74..5a8bd5d 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -561,8 +561,20 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]; NSSize screenSize = [[[self window] screen] frame].size; CGSize screenPhysicalSize = CGDisplayScreenSize(display); + CVDisplayLinkRef displayLink; frameSize = isFullscreen ? screenSize : [self frame].size; + + if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) { + CVTime period = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); + CVDisplayLinkRelease(displayLink); + if (!(period.flags & kCVTimeIsIndefinite)) { + update_displaychangelistener(&dcl, + 1000 * period.timeValue / period.timeScale); + info.refresh_rate = (int64_t)1000 * period.timeScale / period.timeValue; + } + } + info.width_mm = frameSize.width / screenSize.width * screenPhysicalSize.width; info.height_mm = frameSize.height / screenSize.height * screenPhysicalSize.height; } else { -- cgit v1.1