How to force an NSWindow to be always active/focused? How to force an NSWindow to be always active/focused? xcode xcode

How to force an NSWindow to be always active/focused?


I'm not sure if this is exactly what you want (it's not quite a window wide setting), but, from the documentation:

By default, a mouse-down event in a window that isn’t the key window simply brings the window forward and makes it key; the event isn’t sent to the NSView object over which the mouse click occurs. The NSView can claim an initial mouse-down event, however, by overriding acceptsFirstMouse: to return YES.

The argument of this method is the mouse-down event that occurred in the non-key window, which the view object can examine to determine whether it wants to receive the mouse event and potentially become first responder. You want the default behavior of this method in, for example, a control that affects the selected object in a window.

However, in certain cases it’s appropriate to override this behavior, such as for controls that should receive mouseDown: messages even when the window is inactive. Examples of controls that support this click-through behavior are the title-bar buttons of a window.

Or you could try fiddling with

- (void)sendEvent:(NSEvent *)theEvent

and see if you can handle events in a custom way.


If you add a borderless NSButton instance to your window's view and set your image as the button's image (and as its alternate image, to make it more beautiful), it will work out of the box: Just connect the button's action method to your app delegate (or the object where you want to process the click action). A click on the image (i.e. the button) will then trigger the button's action method, no matter which window is active.


This worked for me, hope that will be helpful, This will keep your window always on Top of all applications

[self.window makeKeyAndOrderFront:nil];[self.window setLevel:NSStatusWindowLevel];