3

In my Cocoa/Objective-C application I have a utility panel floating "always on top" to be accessible even when my application is not active. I am trying to disable the "switching to my application when a user clicks on that panel".

The behaviour I would like to achieve is similar to OSX's Keyboard Viewer, (which is also a never activating panel), so that some other application remained active after clicking on my app's panel. i.e. Safari stays active when typing an address using Keyboard Viewer. Even third-party onscreen keyboards have this functionality (for example the one from CORALLO Software), which means this behavior is not reserved system-only.

I was messing around with NSApplicationActivationPolicy, but without positive results. In which direction should I go?

Justin Boo
  • 10,132
  • 8
  • 50
  • 71

1 Answers1

1

You should take a look at the canBecomeKeyWindow and canBecomeMainWindow methods on NSWindow. It sounds like you want your window to maintain key status while not being able to be the main window. Here are some resources to help you:

jscs
  • 63,694
  • 13
  • 151
  • 195
siannopollo
  • 1,464
  • 11
  • 24
  • I have created a subclass of NSPanel with hardcoded returns of `canBecomeKeyWindow` and `canBecomeMainWindow`. The best results are with both returning NO – Buttons on the panel can be clicked and the **window** never gets activated. The only problem is that the **application** does get activated (its name appears in the top left corner) on clicking. After overriding it with UIElement = YES in Info.plist the app itself does not get activated, but the window, which was active before clicking the panel, gets deactivated. Is there a way to avoid this to happen? – user1204187 Feb 11 '12 at 21:37
  • It looks like you should be able to set `[panel setHidesOnDeactivate:NO]` to fix that. Documentation [here](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/cl/NSWindow). – siannopollo Feb 12 '12 at 03:49
  • I have already overridden the panel's hiding with `[panel setFloatingPanel: YES];` so the panel floats above all applications, but even after adding (or replacing _setFloatingPanel_ with) `setHidesOnDeactivate:NO`, the problem persists: when I click my panel when another application is active, that applicatieon deactivates and my application gets active. Is it possible to avoid deactivation of other applciation when clicking on my application's panel? – user1204187 Feb 12 '12 at 20:21
  • Also, NSControl's `setRefusesFirstResponder` can have an effect on controls moving to the front when clicked. – Jeff Sep 23 '14 at 22:04