[Development] [OS X] does AA_MacDontSwapCtrlAndMeta really work as it should in Qt 5?

René J.V. Bertin rjvbertin at gmail.com
Tue Dec 29 15:32:52 CET 2015


I'm currently trying to get my head around how AA_MacDontSwapCtrlAndMeta is supposed to work on OS X, and the fact that setting the attribute in a Qt5-based terminal emulator doesn't appear to have the intended effect of allowing the usual Ctrl-C and family shell shortcuts to be issues using the Ctrl key.

When I scan the Qt code for AA_MacDontSwapCtrlAndMeta, I see things like

    if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
            && (macSymbol == kControlUnicode || macSymbol == kCommandUnicode)) {
        if (macSymbol == kControlUnicode)
            macSymbol = kCommandUnicode;
            macSymbol = kControlUnicode;


static inline int maybeSwapShortcut(int shortcut)
    if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
        uint oldshortcut = shortcut;
        shortcut &= ~(Qt::CTRL | Qt::META);
        if (oldshortcut & Qt::CTRL)
            shortcut |= Qt::META;
        if (oldshortcut & Qt::META)
            shortcut |= Qt::CTRL;


    if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
        int oldModifiers = ret;
        ret &= ~(controlKeyBit | cmdKeyBit);
        if (oldModifiers & controlKeyBit)
            ret |= cmdKeyBit;
        if (oldModifiers & cmdKeyBit)
            ret |= controlKeyBit;

and I cannot help but wonder why that appears to be the opposite of what should be done.

Hence my question: just how is this supposed to work, and more importantly, is there still support for not swapping the Command ("META") and Ctrl keys?

And as a bonus: wouldn't it have been better to provide a platform-specific Qt::ACCEL constant instead of swapping key modifiers back and forth at runtime (and probably the wrong number of times in some places; that's what the current issue looks like)?


More information about the Development mailing list