NSHUDWindowMask Deprecated. Are they out of fashion?

I was looking at implementing some small utility style dialogs in my app, and wanted to use a HUD style window.

MBS has some good examples, but I discovered the NSHUDWindowMask constant was deprecated back when 10.12 (Sierra) came out.

Are macOS HUD style windows out of fashion? If so, does anyone have a good replacement suggestion?

Of course, I tried googling about it, but couldn’t find any useful information about the deprecation. Am I really late to the party, or what?

Don’t know how much you care for answers by our (maybe one day) technology overlords :wink:, but here’s what ChatGPT (GPT-4o) says about this…

The modern alternative to NSHUDWindowMask for creating HUD-style windows in macOS is to use the NSPanel class with specific configuration. Here’s how you can achieve a similar HUD-style effect in contemporary macOS development:

  1. Use NSPanel:
    An NSPanel is a subclass of NSWindow that is intended for utility or floating windows. It can be configured to look like a HUD.
  2. Set Appearance to NSAppearanceNamedVibrantDark:
    Assign the window’s appearance to the dark, vibrant style to give it the semi-transparent, HUD-like look.
  3. Configure as Non-Closable or Non-Resizable:
    To maintain the traditional HUD behavior, you can set the appropriate flags to disable resizing and other unnecessary functionality.
  4. Use styleMask:
    Add NSWindow.StyleMask.utilityWindow and NSWindow.StyleMask.fullSizeContentView for a utility-like appearance.
  5. Example Code in Swift:
import Cocoa

class HUDWindow: NSWindow {
    convenience init(contentRect: NSRect) {
        self.init(
            contentRect: contentRect,
            styleMask: [.titled, .utilityWindow, .fullSizeContentView],
            backing: .buffered,
            defer: false
        )
        self.titleVisibility = .hidden
        self.titlebarAppearsTransparent = true
        self.isOpaque = false
        self.backgroundColor = NSColor.clear
        self.appearance = NSAppearance(named: .vibrantDark)
    }
}
  1. Add Your Custom Content:
    Once you’ve created your custom NSPanel, you can add your content views as needed.

By doing this, you can replicate the HUD look and functionality in a way that aligns with modern macOS design principles. Using the vibrant dark appearance ensures compatibility with macOS’s system-wide light/dark mode settings.

So within Xojo, it’s probably just a matter of selecting the closest looking DesktopWidow.Type and then doing declares for the various look/feel and functional differences. But as it looks like you’re an MBS user, my guess is that NSPanelMBS will be your easiest go to.

1 Like

The constant was replaced by a new one:

NSWindowStyleMaskHUDWindow

static const NSWindowStyleMask NSHUDWindowMask API_DEPRECATED_WITH_REPLACEMENT(“NSWindowStyleMaskHUDWindow”, macos(10.0,10.12)) = NSWindowStyleMaskHUDWindow;

NSWindowStyleMaskHUDWindow API_AVAILABLE(macos(10.6)) = 1 << 13

So just update the name.

2 Likes

Thank you Christian, that solves my initial problem, assuming HUD windows are not altogether deprecated.

If I try the following, I get what is pictured below:

// Window Type: Floating Window
// Has Close Button: True (all others False)

// in the Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titlebarAppearsTransparent = True
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
// HUD and other properties
w.isMovableByWindowBackground = True
Var NSWindowStyleMaskHUDWindow As UInt64 = Bitwise.ShiftLeft(1, 13) // 8192
w.styleMask = BitwiseOr(w.styleMask, NSWindowStyleMaskHUDWindow)

The HUD looks nice (including some vibrancy), but I don’t like how the TextField looks when it has focus.

Thank you Patrick, for your efforts. I’ve had my reservations about the AI overlords and so far I have not indulged, much, but I tried to replicate the overlord’s suggestion as best I could, with the following pictured results (which did not endear me to favour our future overlords…):

// Window Type: Floating Window
// Has Close Button: True (all others False)

// in the Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
w.titlebarAppearsTransparent = True
// other properties
w.isMovableByWindowBackground = True
Const NSWindowStyleMaskUtilityWindow As Integer = 16
w.styleMask = BitwiseOr(w.styleMask, w.NSFullSizeContentViewWindowMask + NSWindowStyleMaskUtilityWindow)
w.isOpaque = False
w.backgroundColor = NSColorMBS.clearColor
NSAppearanceMBS.setAppearance(Self, NSAppearanceMBS.appearanceNamed(NSAppearanceMBS.NSAppearanceNameVibrantDark))

Xojo-HUD-alternative

Also note: NSUtilityWindowMask is also deprecated, but I’m assuming the replacement is NSWindowStyleMaskUtilityWindow with a value of 16 (same as the old constant?)

Because of the TextField focus problem with the HUD window, I’m going to think about this further. Maybe what I want is a hybrid?

Thank you both, but to be continued…

1 Like

Apple just renamed all the constants when they started with Swift to make them enums there.

The functionality doesn’t change.

2 Likes

Thank you @Christian_Schmitz, this answers my initial question. HUD Windows are still a thing :nerd_face:

And thank you @Patrick_Salo for your contributions.

As for my final implementation, I fiddled quite a bit to make the numbers in the TextField more readable, when the input has focus. But the HUD state appears to override the background and text colour assignments in strange ways. I was almost resigned to thinking that a custom control would be required, then I came up with the following in the Opening event of the DesktopTextField:

If Not Color.IsDarkMode Then
  NSAppearanceMBS.setAppearance(Me, NSAppearanceMBS.appearanceNamed(NSAppearanceMBS.NSAppearanceNameAqua))
End If

It might be overkill, but it works nicely to revert the TextField back to its normal appearance. And fortunately in dark mode, the focus issue is not so much a problem.

The final code I’m using to create the HUD Window is the following:

// Window Type: Floating Window
// Has Close Button: True (all others False)

// in the DesktopWindow.Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titlebarAppearsTransparent = True
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
// other properties
w.isMovableByWindowBackground = True
Var NSWindowStyleMaskHUDWindow As UInt64 = Bitwise.ShiftLeft(1, 13) // 8192
w.styleMask = BitwiseOr(w.styleMask, NSWindowStyleMaskHUDWindow)
1 Like