MakeKeyAndOrderFront does not

I have an application that starts when launched as a menu in the OS X menu bar (i.e. as a background application). When you select an option from the menu, it transforms into a foreground application (creates a dock icon) and displays a window.

Here is the background / foreground code I'm using:

+(void) TransformToForegroundApplication { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); } +(void) TransformToBackgroundApplication { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToUIElementApplication); } 

Pretty standard stuff in terms of things. And it works great, except for one small problem.

The problem is that after calling TransformToForegroundApplication I call makeKeyAndOrderFront: in the window so that it gets to the beginning of the Z-order and gets focus, but it does not. He appears in the background, under everything else. I need to either click on the dock icon or minimize all the windows in front of it, and then click on that window to bring it to the front.

Any ideas?

+4
source share
1 answer

Perhaps you need to activate an application that I assume TransformProcessType() will not do automatically, and you won’t know -makeKeyAndOrderFront: .

Have you tried calling [NSApp activateIgnoringOtherApps:YES] ?

+5
source

Source: https://habr.com/ru/post/1491770/


All Articles