ui/cocoa: Fix switched_to_fullscreen warning

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: 6d73bb643a ("ui/cocoa: Clear modifiers whenever possible")
Signed-off-by: Peter Delevoryas <peter@pjd.dev>
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220702044304.90553-1-peter@pjd.dev>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
Peter Delevoryas 2022-07-01 21:43:04 -07:00 committed by Philippe Mathieu-Daudé
parent 7630156d34
commit 713911a107

View File

@ -800,7 +800,6 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
int buttons = 0; int buttons = 0;
int keycode = 0; int keycode = 0;
bool mouse_event = false; bool mouse_event = false;
static bool switched_to_fullscreen = false;
// Location of event in virtual screen coordinates // Location of event in virtual screen coordinates
NSPoint p = [self screenLocationOfEvent:event]; NSPoint p = [self screenLocationOfEvent:event];
NSUInteger modifiers = [event modifierFlags]; 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 // forward command key combos to the host UI unless the mouse is grabbed
if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) { 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; return false;
} }