-2

I want to make application unactivable.

I mean its must be inactive and non-foreground even by click on it. Active window must be the same app as it was before click on my app.

How can I do this?


upd:

  1. Let's imagine some window/panel. Like a Dock. Let's call it "Docky"
  2. Docky is inactive, Active window is Safari:

    NSRunningApplicationSafari.isActive == true
    NSRunningApplicationDocky.isActive == false
    
  3. I'm clicking on ANY empty point of Docky.

Expected result:

  1. Safari is still active window. Like before click:

    NSRunningApplicationSafari.isActive == true
    NSRunningApplicationDocky.isActive == false
    

Actual result:

  1. Docky is active window, Safari is inactive:

    NSRunningApplicationSafari.isActive == false
    NSRunningApplicationDocky.isActive == true
    

Another sample is Keyboard Viewer. You are clicking on the virtual keyboard, but active window is another app. Ant exactly active window getting keyPress events.

Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101
  • 1
    Maybe you want to explain the goal of your app in more detail as it does not seem to be clear what your are trying to achieve. – simibac Dec 03 '19 at 02:31
  • @SimonBachmann the same behaviour as have Dock. It's always inactive. It's cannot be "top most" or "active" application even if you click on it. – Andrew_STOP_RU_WAR_IN_UA Dec 03 '19 at 02:33

1 Answers1

2

Actually all you need is .nonactivatingPanel style panel. Everything else is details, like level of this window, custom views with overridden acceptsFirstMouse:, needsPanelToBecomeKey, etc. Btw, button accepts first click by default, non activating app in this case.

So your AppDelegate, for example, might look like the following:

class AppDelegate: NSObject, NSApplicationDelegate {

    var docky: NSPanel!

    func applicationDidFinishLaunching(_ aNotification: Notification) {

        // Create the window and set the content view. 
        docky = NSPanel(
            contentRect: NSRect(x: 0, y: 0, width: 120, height: 600),
            styleMask: [.nonactivatingPanel],
            backing: .buffered, defer: false)
        docky.level = .mainMenu
        ....
        docky.orderFrontRegardless()
    }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690