Detect MacBook notch in macOS Monterey and higher

Viewed 445

This is a question for macOS, not iOS.

macOS Monterey on MacBook pro 2021 provides a notch for the first time, which hides parts of the menu when in full screen mode or maximized state. In order to apply a modified menu in that case, I'd like to to detect the notch programmatically.

How can I do this? Didn't find anything in the documentation.

1 Answers

First, check whether you're running on macOS 12 or later, because the APIs are only available on macOS 12 or later. You can use if #available(macOS 12, *) to check.

Then, for the NSScreen of interest, check one of these properties. They should also give the same (yes/no) answer:

For example:

extension NSScreen {
    var hasTopNotchDesign: Bool {
        guard #available(macOS 12, *) else { return false }
        return safeAreaInsets.top != 0
    }
}
Related