NSBorderlessWindow not responding CMD-W / CMD-M

I have a subclass of NSBorderlessWindow NSWindow with a transparent and opaque background (so it is not rectangular in appearance). I added my own buttons to function as the close and minimize buttons when I click on them, but for some reason the window will not respond to CMD-W or CMD-M, as usual. I have a set of NSWindow subclasses to return YES in canBecomeKeyWindow and canBecomeMainWindow.

My NIB still has all the standard menu items that are when you create a new project, including the Minimize item in the Window menu with the default CMD-M shortcut. He connected to send performMiniaturize: to the first responder. However, it is not turned on when the application is running, so it seems that it should request a window if it can be minimized and the window says β€œno” or something like that. (I'm still very new to OSX / Cocoa.)

What am I missing?

In addition, and perhaps this is related, my borderless window has an included shadow, but unlike the usual captioned window, when I make my window an active / front window by clicking on it, the shadow does not change. Typically, an OSX-oriented window has a slightly larger / darker shadow to highlight it more, but mine never changes the shadow. It is like I am missing something so that the OS sees this window as a real / normal / main window or something else, and as a result I lose the shadow change and CMD-W / CMD-M.

+4
source share
3 answers

What you are missing is that when you create a borderless window, you delete the FrameView, which includes standard windows that actually implement the -keyDown: method, which receives these keystrokes and miniaturizes or closes the window.

NSWindow itself is a fairly lightweight class, and most of what we consider to be standard window behavior is done using a frame view.

+3
source

Maybe you deleted the menu item "File"> "Close"?

By default, this has the Cmd-W key combination and connects to the performClose target in the first responder.

We fixed this by dragging the standard File menu in the Library panel to the Interface Builder.

+1
source

At first I tried to implement keyDown: for each NSResponder sentence, but that didn't help.

I solved this by simply creating my own IBActions for Close and Minimize. Note that you want to call close and miniaturize: in your NSBorderlessWindow, not performClose: or performMiniaturize:

0
source

All Articles