[Interest] Prevent tabbing of Qt application on macOS Sierra

Jake Petroules Jake.Petroules at qt.io
Sat Dec 2 20:50:01 CET 2017


Actually, you shouldn't do this. Instead, use this:

#include <QtCore/qglobal_p.h> // includes an implementation of __builtin_available for compilers older than Xcode 9

// Disables auto window tabbing where supported, otherwise a no-op.
void disableWindowTabbing()
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
    if (__builtin_available(macOS 10.12, *)) {
        NSWindow.allowsAutomaticWindowTabbing = NO;
    }
#endif
}

...will build with any combination of any SDK version, compiler version, and deployment target.

The reason the original solution fails is because calling a non-existent selector will only cause a warning (-Wobjc-method-access), whereas accessing a non-existent selector via the dot-notation is an error (compiler error, not linker error, and there's actually no difference whatsoever in the generated code). The solution above doesn't have this issue, and lets the compiler *understand* (because of the scope of the __builtin_available) that that selector will be available in the context you're calling it - hence no warning with a deployment target < 10.12.

> On Dec 2, 2017, at 10:02 AM, René J.V. Bertin <rjvbertin at gmail.com> wrote:
> 
> Hi,
> 
> I came across this >1 yo mail from Morten saying
> 
>> Create disableWindowTabbbing.mm with:
>> 
>> #import <AppKit/AppKit.h>
>> 
>> // Disables auto window tabbing where supported, otherwise a no-op.
>> void disableWindowTabbing()
>> {
>> 
>>    if ([NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)]) {
>>        NSWindow.allowsAutomaticWindowTabbing = NO;
>>    }
>> 
>> }
> 
> This is an error I also make easily (and too often): checking for support for a given selector, and then invoking it directly instead of using that selector. This will fail in the linking stage with older Cocoa versions (pre 10.12 in this case). For the selector check to make sense you have to call [NSWindow setAllowsAutomaticWindowTabbing:NO] if it passes.
> 
> cf. https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html "What should an application which already has support for tabbing do? - The application should explicitly opt-out of automatic window tabbing by calling [NSWindow setAllowsAutomaticWindowTabbing:NO]."
> 
> Cheers,
> René
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-- 
Jake Petroules - jake.petroules at qt.io
The Qt Company - Silicon Valley
Qbs build tool evangelist - qbs.io



More information about the Interest mailing list