Ticket #62164: patch-ui-cocoa-legacy-os.diff

File patch-ui-cocoa-legacy-os.diff, 11.1 KB (added by Ionic (Mihai Moldovan), 3 years ago)

This seems to compile, but somehow doesn't work properly. I cannot input anything. Whenever I press a key, I just get an audio bell signal. Also, I cannot uncapture the mouse pointer once captured (well, naturally, because the keyboard input doesn't seem to be getting processed correctly).

  • ui/cocoa.m

    diff -pNur qemu-5.2.0-orig/ui/cocoa.m qemu-5.2.0/ui/cocoa.m
    old new QemuCocoaView *cocoaView; 
    418418    COCOA_DEBUG("QemuCocoaView: drawRect\n");
    419419
    420420    // get CoreGraphic context
    421     CGContextRef viewContextRef = [[NSGraphicsContext currentContext] CGContext];
     421    CGContextRef viewContextRef = [[NSGraphicsContext currentContext] graphicsPort];
    422422
    423423    CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone);
    424424    CGContextSetShouldAntialias (viewContextRef, NO);
    QemuCocoaView *cocoaView; 
    585585        } else {
    586586            [NSMenu setMenuBarVisible:NO];
    587587            fullScreenWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame]
    588                 styleMask:NSWindowStyleMaskBorderless
     588                styleMask:NSBorderlessWindowMask
    589589                backing:NSBackingStoreBuffered
    590590                defer:NO];
    591591            [fullScreenWindow setAcceptsMouseMovedEvents: YES];
    QemuCocoaView *cocoaView; 
    620620    int control_key = 0;
    621621
    622622    // if the control key is down
    623     if ([event modifierFlags] & NSEventModifierFlagControl) {
     623    if ([event modifierFlags] & NSControlKeyMask) {
    624624        control_key = 1;
    625625    }
    626626
    QemuCocoaView *cocoaView; 
    706706    NSPoint p = [self screenLocationOfEvent:event];
    707707
    708708    switch ([event type]) {
    709         case NSEventTypeFlagsChanged:
     709        case NSFlagsChangedMask:
    710710            if ([event keyCode] == 0) {
    711711                // When the Cocoa keyCode is zero that means keys should be
    712712                // synthesized based on the values in in the eventModifiers
    QemuCocoaView *cocoaView; 
    715715                if (qemu_console_is_graphic(NULL)) {
    716716                    NSUInteger modifiers = [event modifierFlags];
    717717
    718                     if (!!(modifiers & NSEventModifierFlagCapsLock) != !!modifiers_state[Q_KEY_CODE_CAPS_LOCK]) {
     718                    if (!!(modifiers & NSAlphaShiftKeyMask) != !!modifiers_state[Q_KEY_CODE_CAPS_LOCK]) {
    719719                        [self toggleStatefulModifier:Q_KEY_CODE_CAPS_LOCK];
    720720                    }
    721                     if (!!(modifiers & NSEventModifierFlagShift) != !!modifiers_state[Q_KEY_CODE_SHIFT]) {
     721                    if (!!(modifiers & NSShiftKeyMask) != !!modifiers_state[Q_KEY_CODE_SHIFT]) {
    722722                        [self toggleModifier:Q_KEY_CODE_SHIFT];
    723723                    }
    724                     if (!!(modifiers & NSEventModifierFlagControl) != !!modifiers_state[Q_KEY_CODE_CTRL]) {
     724                    if (!!(modifiers & NSControlKeyMask) != !!modifiers_state[Q_KEY_CODE_CTRL]) {
    725725                        [self toggleModifier:Q_KEY_CODE_CTRL];
    726726                    }
    727                     if (!!(modifiers & NSEventModifierFlagOption) != !!modifiers_state[Q_KEY_CODE_ALT]) {
     727                    if (!!(modifiers & NSAlternateKeyMask) != !!modifiers_state[Q_KEY_CODE_ALT]) {
    728728                        [self toggleModifier:Q_KEY_CODE_ALT];
    729729                    }
    730                     if (!!(modifiers & NSEventModifierFlagCommand) != !!modifiers_state[Q_KEY_CODE_META_L]) {
     730                    if (!!(modifiers & NSCommandKeyMask) != !!modifiers_state[Q_KEY_CODE_META_L]) {
    731731                        [self toggleModifier:Q_KEY_CODE_META_L];
    732732                    }
    733733                }
    QemuCocoaView *cocoaView; 
    756756            }
    757757
    758758            break;
    759         case NSEventTypeKeyDown:
     759        case NSKeyDownMask:
    760760            keycode = cocoa_keycode_to_qemu([event keyCode]);
    761761
    762762            // forward command key combos to the host UI unless the mouse is grabbed
    763             if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
     763            if (!isMouseGrabbed && ([event modifierFlags] & NSCommandKeyMask)) {
    764764                /*
    765765                 * Prevent the command key from being stuck down in the guest
    766766                 * when using Command-F to switch to full screen mode.
    QemuCocoaView *cocoaView; 
    774774            // default
    775775
    776776            // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
    777             if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
     777            if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
    778778                NSString *keychar = [event charactersIgnoringModifiers];
    779779                if ([keychar length] == 1) {
    780780                    char key = [keychar characterAtIndex:0];
    QemuCocoaView *cocoaView; 
    799799                [self handleMonitorInput: event];
    800800            }
    801801            break;
    802         case NSEventTypeKeyUp:
     802        case NSKeyUpMask:
    803803            keycode = cocoa_keycode_to_qemu([event keyCode]);
    804804
    805805            // don't pass the guest a spurious key-up if we treated this
    806806            // command-key combo as a host UI action
    807             if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) {
     807            if (!isMouseGrabbed && ([event modifierFlags] & NSCommandKeyMask)) {
    808808                return true;
    809809            }
    810810
    QemuCocoaView *cocoaView; 
    812812                qemu_input_event_send_key_qcode(dcl->con, keycode, false);
    813813            }
    814814            break;
    815         case NSEventTypeMouseMoved:
     815        case NSMouseMovedMask:
    816816            if (isAbsoluteEnabled) {
    817817                // Cursor re-entered into a window might generate events bound to screen coordinates
    818818                // and `nil` window property, and in full screen mode, current window might not be
    QemuCocoaView *cocoaView; 
    829829            }
    830830            mouse_event = true;
    831831            break;
    832         case NSEventTypeLeftMouseDown:
    833             if ([event modifierFlags] & NSEventModifierFlagCommand) {
     832        case NSLeftMouseDownMask:
     833            if ([event modifierFlags] & NSCommandKeyMask) {
    834834                buttons |= MOUSE_EVENT_RBUTTON;
    835835            } else {
    836836                buttons |= MOUSE_EVENT_LBUTTON;
    837837            }
    838838            mouse_event = true;
    839839            break;
    840         case NSEventTypeRightMouseDown:
     840        case NSRightMouseDownMask:
    841841            buttons |= MOUSE_EVENT_RBUTTON;
    842842            mouse_event = true;
    843843            break;
    844         case NSEventTypeOtherMouseDown:
     844        case NSOtherMouseDownMask:
    845845            buttons |= MOUSE_EVENT_MBUTTON;
    846846            mouse_event = true;
    847847            break;
    848         case NSEventTypeLeftMouseDragged:
    849             if ([event modifierFlags] & NSEventModifierFlagCommand) {
     848        case NSLeftMouseDraggedMask:
     849            if ([event modifierFlags] & NSCommandKeyMask) {
    850850                buttons |= MOUSE_EVENT_RBUTTON;
    851851            } else {
    852852                buttons |= MOUSE_EVENT_LBUTTON;
    853853            }
    854854            mouse_event = true;
    855855            break;
    856         case NSEventTypeRightMouseDragged:
     856        case NSRightMouseDraggedMask:
    857857            buttons |= MOUSE_EVENT_RBUTTON;
    858858            mouse_event = true;
    859859            break;
    860         case NSEventTypeOtherMouseDragged:
     860        case NSOtherMouseDraggedMask:
    861861            buttons |= MOUSE_EVENT_MBUTTON;
    862862            mouse_event = true;
    863863            break;
    864         case NSEventTypeLeftMouseUp:
     864        case NSLeftMouseUpMask:
    865865            mouse_event = true;
    866866            if (!isMouseGrabbed && [self screenContainsPoint:p]) {
    867867                /*
    QemuCocoaView *cocoaView; 
    874874                }
    875875            }
    876876            break;
    877         case NSEventTypeRightMouseUp:
     877        case NSRightMouseUpMask:
    878878            mouse_event = true;
    879879            break;
    880         case NSEventTypeOtherMouseUp:
     880        case NSOtherMouseUpMask:
    881881            mouse_event = true;
    882882            break;
    883         case NSEventTypeScrollWheel:
     883        case NSScrollWheelMask:
    884884            /*
    885885             * Send wheel events to the guest regardless of window focus.
    886886             * This is in-line with standard Mac OS X UI behaviour.
    QemuCocoaView *cocoaView; 
    10641064
    10651065        // create a window
    10661066        normalWindow = [[NSWindow alloc] initWithContentRect:[cocoaView frame]
    1067             styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskClosable
     1067            styleMask:NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask
    10681068            backing:NSBackingStoreBuffered defer:NO];
    10691069        if(!normalWindow) {
    10701070            fprintf(stderr, "(cocoa) can't create window\n");
    QemuCocoaView *cocoaView; 
    13701370    int x = 0, y = 0, about_width = 400, about_height = 200;
    13711371    NSRect window_rect = NSMakeRect(x, y, about_width, about_height);
    13721372    about_window = [[NSWindow alloc] initWithContentRect:window_rect
    1373                     styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
    1374                     NSWindowStyleMaskMiniaturizable
     1373                    styleMask:NSTitledWindowMask | NSClosableWindowMask |
     1374                    NSMiniaturizableWindowMask
    13751375                    backing:NSBackingStoreBuffered
    13761376                    defer:NO];
    13771377    [about_window setTitle: @"About"];
    QemuCocoaView *cocoaView; 
    14101410    [name_label setEditable: NO];
    14111411    [name_label setBezeled: NO];
    14121412    [name_label setDrawsBackground: NO];
    1413     [name_label setAlignment: NSTextAlignmentCenter];
     1413    [name_label setAlignment: NSCenterTextAlignment];
    14141414    NSString *qemu_name = [[NSString alloc] initWithCString: gArgv[0]
    14151415                                            encoding: NSASCIIStringEncoding];
    14161416    qemu_name = [qemu_name lastPathComponent];
    QemuCocoaView *cocoaView; 
    14261426                                                      version_rect];
    14271427    [version_label setEditable: NO];
    14281428    [version_label setBezeled: NO];
    1429     [version_label setAlignment: NSTextAlignmentCenter];
     1429    [version_label setAlignment: NSCenterTextAlignment];
    14301430    [version_label setDrawsBackground: NO];
    14311431
    14321432    /* Create the version string*/
    QemuCocoaView *cocoaView; 
    14461446    [copyright_label setEditable: NO];
    14471447    [copyright_label setBezeled: NO];
    14481448    [copyright_label setDrawsBackground: NO];
    1449     [copyright_label setAlignment: NSTextAlignmentCenter];
     1449    [copyright_label setAlignment: NSCenterTextAlignment];
    14501450    [copyright_label setStringValue: [NSString stringWithFormat: @"%s",
    14511451                                     QEMU_COPYRIGHT]];
    14521452    [superView addSubview: copyright_label];
    static void create_initial_menus(void) 
    15111511    [menu addItem:[NSMenuItem separatorItem]]; //Separator
    15121512    [menu addItemWithTitle:@"Hide QEMU" action:@selector(hide:) keyEquivalent:@"h"]; //Hide QEMU
    15131513    menuItem = (NSMenuItem *)[menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; // Hide Others
    1514     [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
     1514    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
    15151515    [menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show All
    15161516    [menu addItem:[NSMenuItem separatorItem]]; //Separator
    15171517    [menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) keyEquivalent:@"q"];