I have a borderless NSPanel when I first launch it and it has focus, I can drag it and the mousedragged method starts correctly, however, when I switch focus to another application and then return to NSPanel (which is installed using NSNonactivatingPanelMask) I no longer receive mousedragged events.
I am still receiving mouseup and mousedown events, so I cannot understand why the mousedragged event is not executing.
Any ideas?
Here it is initialized:
_panel = [[MyPanel alloc] initWithContentRect:frame styleMask:NSBorderlessWindowMask | NSNonactivatingPanelMask backing:NSBackingStoreBuffered defer:NO];
I also tried adding all these methods to the panel class:
- (BOOL)canBecomeKeyWindow { return YES; } - (BOOL)canBecomeMainWindow { return YES; } - (BOOL)canBecomeFirstResponder { return YES; } - (BOOL)acceptsFirstResponder { return YES; } - (BOOL)acceptsFirstMouse { return YES; }
And making him the first responder in the mouse (which he still gets):
- (void)mouseDown:(NSEvent *)theEvent { [self makeFirstResponder:self]; [self makeKeyWindow]; [self setBackgroundColor:[NSColor redColor]]; [self display]; }
Mouse City simply contains this:
- (void)mouseDragged:(NSEvent *)theEvent { [self setBackgroundColor:[NSColor greenColor]]; [self display]; NSLog(@"dragged"); }
I do not want the window to focus. (The focus should be on the third-party application below).
Update: I added a sample project, download here: http://users.telenet.be/prullen/MovingPanel.zip
As you will see, the first time you launch the application and drag it, it will output "dragged" to console.log continuously (and the background color will be green). If you then move to another application, and then return to the carry application, dragging and dropping no longer displays anything. (and the background color will be red, which is set in the mousedown event handler).
Without NSNonactivatingPanelMask, this works as it should, but itβs very important that the window under my panel remains active. If there is another way to accomplish this, please share.
One thing that I also noticed, if you double-click on the panel (quickly) and then drag it, it will turn green (so called mousedragged :), but it does not move ... Not sure what to think of that.