NSPanel loses focus although being modal - xcode

I have a strange problem with one of my NSPanels. Starting up my application, I use a simple panel with only an NSTextField and an NSButton to get the player's name. Working on some other stuff on my application, all of a sudden the panel does not get focused any longer when starting the app. The button does work, though, but the text field refuses to be focused and take any input.
Any ideas are appreciated.
Cheers,
Living

I found the solution myself, shame on me.
For the NSPanel, I had deselected "Title Bar" in the Appearance section of the Attribute Inspector. Unchecked, the panel does not have a title bar and thus cannot get the focus.
Checking it again, everything works as expected :-)

Related

How do you make a button automatically press without user interaction in Swift Cocoa

This sounds like a weird question, but I am using Swift 2.0 and Xcode to create a cocoa app, and I have a popover linked to an invisible button. I wan't to activate it so it pops up after the user has been on the page for a little while. I have a timer set, but I can't figure out the code to get the button to actually activate at that time, so that the popover will show. I am using a button so I can have an access spot for the popover to show at.
Right now, if you click the (invisible) button, everything shows perfectly. However, I need the click to activate programmatically. I would really appreciate any help!
Thanks!

NSStatusItem app focus

How can my menubar application achieve the same behaviours as 1Password or Dropbox:
clicking their menu bar icons or popovers does not steal focus, e.g. while I am in for example TextEdit and open 1Password/Dropbox, the blinking cursor disappears but the window itself does not go into the background, yet I can type into 1Password's text field.
even though they didn't take focus in the first place, they disappear when I click back into another application
I figured out how mouse over works in the Dropbox popover table view by using an NSTrackingArea with the options MouseEnteredAndExited, AssumeInside, and ActiveAlways.
I am trying to get the same behaviour to work in an NSPopover that opens from an NSStatusItem.
I found a workaround for now. I am able to get the same behaviour by using non-activating NSPanel with a window level kCGPopUpMenuWindowLevelKey and I had to override canBecomeKeyWindow to return true.
Unfortunately I haven't found a way yet to get a NSPopover to behave this way since it's not a subclass of NSWindow.
To set the kind of behavior you are describing you use:
yourPopover.behavior = .transient

StatusItem menu doesn't open on hover

I've got an NSStatusItem with a menu. My problem is that when you click on for example the wifi icon, the menu appears. When I move to the right (on my mac the battery status item is there) the menu for the battery automatically appears. That's what I mean with "on hover". This behaviour is implemented in pretty much all status items and/or menu's. But my NSStatusItem doesn't implement this behaviour. I don't see an option in IB to "assign" this behaviour, so I started searching the web and all I can come up with is this:
Status Item menus don't open on hover
The "answer" here is everything but satisfying. So my question is: is this true? Aren't there any ways to create this behaviour without using private API's?
Thanks a lot in advance,
Frans

NSWindow with NSWindowCollectionBehaviorStationary is visible on the Dashboard. Is this a bug?

I'm trying to get my NSWindow to:
Be visible on all Spaces
Be visible when showing the Desktop (by pressing F11)
Not be visible in Mission Control/Expose
The following does exactly that, but with a side effect:
[self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces
| NSWindowCollectionBehaviorStationary ];
When switching to the Dashboard on Mac OS X Lion, the window remains visible alone with Dashboard items for a second, then it is hidden.
Is this expected behavior or a bug? Users of my app find it confusing to see the window on the Dashboard before they disappear. I would have expected them to only show on Spaces and not the Dashboard.
I looked at http://cocoadev.com/wiki/DontExposeMe searching for workaround
nothing really worked except.
self.window.level = kCGDesktopWindowLevel;
now maybe DETECT changes to expose and set that then :) ...
see How can one detect Mission Control or Command-Tab switcher superseding one's program in OS X? for that :)
maybe an answer will come up there
I was able to reproduce this behaviour and I think it's just a bit of faulty animation on Apple's side.
Just so I can explain this better, create a new project, add these two lines to applicationDidFinishLaunching:, and run it.
[self.window setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorStationary ];
[self.window setHidesOnDeactivate: YES];
(self.window is the window that is created automatically when creating a new project. it doesn't really matter here anyway, just as long as it is a window that appears on the screen)
Now notice this behaviour: when changing from one space where you can see your window to another in which there are other windows from other apps (and so your window is supposed to disappear since your app will be deactivated), your window only disappears when the animation finishes. So, what is happening?
Here's what I think it happens: when switching from one space to another, windows that show on all spaces only react to the change after the animation, hence the brief appearence of your window on the dashboard. I think you'll notice it disappears exactly when the slide animation ends.
So, unfortunately, I don't know how to fix your problem. It just seems to happen this way.

Cocoa: NSPopover in statusbar unresponsive

An application has an NSPopover with some user inputs in the status bar and some windows. The windows work fine but when I open the popover in the status bar it opens inactive. I can see everything but it's all greyed out, like it's a background window. I've been trying everything I can find on activate, activateignoringotherapps, makekeyandorderfront, etc but none of these is having an effect. How can I shift the focus to the statusbar popover?
I also made a button in the window that showed the same popup to make sure it is working, when called from the window button it works perfectly from there. Then I click on the status bar, and it opens from there instead, but inactive.
Thanks for the help.
I've run into the same problem and haven't found a solution. Unfortunately, I believe this is a bug: http://www.openradar.me/radar?id=1226415
There's a framework called SFBPopovers which provides similar functionality and works fine with the menu bar.
It might help with your issue.

Resources