Yosemite and Key Window

I have a menu bar (LSUIElement) app. StatusItem opens a window.

With Yosemite I’m unable to make my app’s window the key window. To show the window I’m using ActivateIgnoringOtherApps and MakeKeyAndOrderFront from MacOSLib. At first show the window works nicely, but when I click to another app (window hides on deactivate) and then open my app again from the StatusItem, it appears, receives keyboard events, but no mouse clicks. IsKeyWindow returns false so for some reason it’s not becoming the key window.

Any ideas?

The way we’ve done it in Backup To Go (which I haven’t yet checked with the actual release) was to use ActivateIgnoringOtherApps, and then simply window.show

Thanks for the help Sam.

I’m now using MacOSLib’s NSRunningApplication.CurrentApplication.Activate which seems to work. Had to change it a little to accept NSRunningApplication.NSApplicationActivateIgnoringOtherApps parameter.

I’m pretty sure I also had Window.Show in there also, but I’ll have to check later if it could be that simple.

I just tested a small project from Axel Schneider that uses ActivateIgnoringOtherApps and it works flawlessly. None of the reported issues from the OP.

Thanks Michel. Can I see it?

http://axel-erfurt.de/apps/scalepictureOSX.zip

That looks to be a very different kind of application.

What is important is the fact that the method does get the app window on top of the z order and it does not lose the mouse events. Is it not what you want to achieve ?

That example doesn’t have some of the elements that I believe might be part of the problem. Mainly hiding the window when it becomes unactive and then showing it again when StatusItem is clicked.

But I’ll get back to it when I’m able to test it. Have to do some actual work now :slight_smile:

[quote=135830:@Thomas White]That example doesn’t have some of the elements that I believe might be part of the problem. Mainly hiding the window when it becomes unactive and then showing it again when StatusItem is clicked.

But I’ll get back to it when I’m able to test it. Have to do some actual work now :)[/quote]

It’s just a lead…

Here’s a demo of my problem. Run it, click “Test” StatusItem, click another app, click StatusItem again and the window doesn’t become totally active. Titlebar is dimmed and TextField doesn’t get focus.

https://dl.dropboxusercontent.com/u/210280/Test.xojo_binary_project.zip

I am running Yosemite and don’t have that problem. Weird.

Wait. It works now. I see the issue.

Window1.ShowModal

That seems to create a new problem. Clicking StatusItem and then another app leaves the StatusItem active and you have to click it twice to make the window appear.

@Sam Rowlands Are you having this issue with Yosemite?

I’m not running Yosemite as my main OS, but you can check out Backup To Go (it’s free) and see if you’re having the same problem,
https://itunes.apple.com/gb/app/backup-to-go-protect-your/id882272017?mt=12

I’ll probably have to update my main machine, but I’m going to wait until I’ve finished this current project (11 days left).

Backup To Go opens the standard menu when clicking the StatusItem. My app opens a window (like Dropbox does). So I don’t think you’ll have any problems.

Ahh… Not that it helps, but it works in Mavericks :slight_smile:

Have you checked the console, incase the OS is logging any messages? Otherwise this may well be a Yosemite issue, and you my friend are then more than welcome to join my club of developers who’ve been hurt by Yosemite :slight_smile:

As far as I can tell, using Window1.ShowModal in StatusItemHandler and me.visible = false in Window1.deactivate instead of Hide improves things when clicking out of every app, in the desktop background.

Now clicking in another app, the window does go way, but the NSStatusItem remains selected. As if somehow it was not released the same way as it happens when clicking in the desktop background. As if Hide did not work the same way as it did in Mavericks. That may be where the problem lies, but since it is not Xojo code, a Cocoa specialist has to look into it.