OSX Lion -- NSEvent when Launchpad is entered - objective-c

I am writing a Mac app that uses a window which is glued to the foreground of the screen. I am listening for the NSWindowDidResignKeyNotification to detect when it is appropriate to hide the window.
For almost every purpose -- including when a different application enters focus -- this works perfectly.
On OSX Lion there is an idiosyncrasy. When my window is open and glued to the foreground, and then the user selects the Launchpad icon from the dock to expand the Launchpad, my window stays in the foreground, even over Launchpad. It appears that Launchpad is implemented as some sort of screen overlay rather than a window that would take focus.
Does anyone have any solution to detect when Launchpad enters focus so that I can dismiss my window?

Related

Activate all windows from background when clicking on main window

I have an Objective-C application with a main window and a small progress window with a stack view to show the current progress.
If the application is put in the background by activating any other application and then clicking on the Dock icon, both the Main and secondary windows is brought to the front and shown.
But, if I just click one of the windows when in the background, only that window is activated and brought to the front, the other stays in the back.
I want to implement so that when I click on the main window it does the same thing as clicking on the Dock icon, it should show both windows on top with the Main window activated.
But if I click on the progress window, I don't want the main window to be brought to the front.
I haven't been able to find a way to do this, how should I go about achieving this?
You can detect the window being clicked with the window delegate's -windowDidBecomeKey: or -becomeKeyWindow, or the app delegate's -didBecomeActive:.
Then depending on your exact needs, you can use [NSApp activateIgnoringOtherApps:] or [[NSRunningApplication currentApplication] activateWithOptions:] (and possibly NSApplicationActivateAllWindows).

Hide app icon in dock when minimized

I am new at Mac OSx development.
The app that I am creating requires removing the app icon from the dock throughout the application. The app allows minimizing and closing of the app window. Relaunching or reopening of the closed or minimized app window is done by clicking the app's icon from the status bar.
I was able to set the dock icon to be disabled during app launching; however, when the app is minimized (clicking the minimize button), it captures the image of the app's current window and adds it to the dock. I don't want that to occur. The app should not add any item to the dock.
Questions:
Does Apple allow removal of the app's re-launcher image from the dock when minimized?
If Apple allows this, how can I hide or remove the app from the dock?
Any help would be a big help! Thanks!
You cannot disable the display of a proxy tile when your window is minimized -- that's the primary way that users will restore a minimized window. If you'd rather that the window disappear entirely when it's not being used, disable minimization (in the window's flags) and have the user close the window instead.

Force showing keyboard in metro?

I'd like to be able to force the keyboard to show on screen in my Metro app. My goal is to test out different layouts/controls and get a feel for the interaction. My problem is that I'm running Win8 on a MacBook Pro (Parallels) and I don't know how to override the physical keyboard and show it on screen instead.
Similarly, I'd like to be able to force rotation if possible.
You could run your app the Simulator. You can put the Simulator in "Touch Mode" and that will interpret mouse clicks as touch events in the on screen controls like Text Boxes and you can choose to rotate the Simulator into profile as well.

Cocoa put window in the foreground

I am building a Cocoa Mac application that runs in the background but has a main window.
To make it run in the background I've set "Application is background only" to "YES".
I built a system tray:
If you close the main window, you can re-open it by clicking "open".
I have however some issues with the layering of windows:
When I start the application, the main window opens however it appears in the background, behind any other windows or applications I have open at the time.
Clicking on "open" doesn't bring the window to the foreground. It opens it correctly if it was closed, however it stays behind any windows.
Clicking on preferences or about has the same issue. It opens the correct window but it appears behind any other windows.
On my main window there is a textfield. I can click on it, the cursor blinks as if I am ready to type. But when I type it actually types in some other background window! For example if I have TextWrangler open in the background, it will type there instead of the textfield...
Here is my code for handling the "open":
- (IBAction)show:(id)sender {
[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:sender];
}
Note that IF I set "Application is background only" to "NO" (which means I have a dock icon appearing), then clicking on "open" brings the window to the foreground as expected. And typing in the textfield works as expected.
Instead of background only, I think you want Application is agent (UIElement) set to YES. Background only is for application not intended to be visible for users.
Background only (LSBackgroundOnly YES) is intended for faceless background applications, Accessory (LSUIElement YES) is intended for background applications with a UI and status menu (menu extra/accessory menu/etc. - the name changes...).
An accessory will not appear in the dock, have a standard menu bar, or appear in the Finder's Force Quit dialog. It can be "active" and can have the key window.
Though it does not have a standard menu bar bizarrely (maybe a bug) if a MainMenu is declared in the XIB then it will respond to key shortcuts when it is active. To avoid this make sure you have no MainMenu or use [NSApp setMainMenu:nil] when you wish to disable the shortcuts.
The whole background/accessory/application/active/etc. area is not exactly well-defined, be prepared for "fun"...

menubar app behavior vs full screen app spaces (mac os 10.7/lion)

When you have an app in fullscreen mode (in a fullscreen space) the menubar is hidden unless you "nudge" the top of the screen. However if you hit the spotlight hotkey the menubar politely shifts down into the screen with the spotlight search bar. Excellent.
I am migrating a statusbar/faceless application that I wish to have emulate this spotlight's menubar handling. Under snow leopard the app responds to a system hotkey by displaying a menu (it has a NSStatusBar item and I call popUpStatusItemMenu). Under Lion when the app is in fullscreen mode/space however, the menubar remains hidden for the fullscreen app (note however that the hot key IS bringing up the statusbar item and using the keyboard I can activate individual actions on the menu -- I just can't see the menu pop up).
To reiterate - anyone know how spotlight (under lion) displays the menubar in response to a hotkey? Or should I be asking when a better way to handle my UI would be under Lion?
thanks,
I feel reasonably certain that Spotlight is using private interfaces to change the presentation mode of the login session. You can change the presentation mode for an application using -[NSApplication setPresentationOptions:] (or the deprecated-but-still-available Carbon equivalent SetSystemUIMode()), but these explicitly only propagate to the login session from the “frontmost faceful application”.
I suggest filing a suggestion for an API to request that certain UI elements (menu bar, dock) are shown if they’re currently in autohide mode from the background.