Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect MacBook notch in macOS Monterey and higher

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.

like image 255
Pat_Morita Avatar asked Jan 29 '26 11:01

Pat_Morita


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:

  • Is safeAreaInsets.top non-zero?
  • Is auxiliaryTopLeftArea non-nil?
  • Is auxiliaryTopRightArea non-nil?

For example:

extension NSScreen {
    var hasTopNotchDesign: Bool {
        guard #available(macOS 12, *) else { return false }
        return safeAreaInsets.top != 0
    }
}
like image 135
rob mayoff Avatar answered Jan 31 '26 04:01

rob mayoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!