Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable application activation on window click

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?

like image 264
user1204187 Avatar asked Apr 09 '26 04:04

user1204187


1 Answers

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:

  • Window Programming Guide - Explains the difference between main and key windows
  • NSWindow class reference - Jump to the sections on canBecomeKeyWindow and canBecomeMainWindow
like image 97
siannopollo Avatar answered Apr 10 '26 20:04

siannopollo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!