How to make NSWindow always be active / focused?

I have a transparent NSWindowone that follows the user's screen wherever he goes ( NSWindowstays in front of every application, no matter what, even full-screen applications).
In this NSWindow, I have an event mouseDownthat shows a popup. Let's say I am in safari in full screen mode and I have my window in front of it, I click on safari and I click on my window again: nothing happens, mouseDown does not happen. I have to click again for the event to happen mouseDown.
How can I make my NSWindowbe always active, so I don’t need to click on 2x to call mouseDownit when I click on the background application and enter my window again?
Thank!

+5
source share
4 answers

If you add an borderless NSButton instance to the window and set the image as a button image (and as its alternative image to make it more beautiful), it will work out of the box: just connect the button action method for your application delegate (or object in which you want to handle the click action). Clicking on the image (i.e. Button) will then call the button's action method, regardless of which window is active.

+2
source

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

mouse-down , ; isnt NSView, . NSView , , acceptsFirstMouse:, YES.

mouse-down, , , . , , , , .

, , , mouseDown:, . , , .

- (void)sendEvent:(NSEvent *)theEvent

, -.

+2

, , . .

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

All Articles