Cocoa: add/show NSBorderlessWindowMask window in window list - macos

I've created a custom NSWindow which is borderless (Using NSBorderlessWindowMask style mask)
I want the window to be listed on the Window Menu (the list of windows shown when you right click on the app icon on the tray)
Note: Titled window with borders is automagically added to this list.
Do you know a way to solve this ?
Is it NSApp related thing ?

OK, i found a way to add window to the window menu manually using NSApp.
[NSApp addWindowsItem:window title:[window title] filename:NO];

Related

How to create an arrow pointing to my app's icon on the menu bar?

I have a menu bar only application. On the first time the user runs the app I want to create an animated arrow pointing to my app's icon on the menu bar.
The first idea I had was to create a NSPopover showing the arrow but that is obtrusive per se because I don't think I can make the popover invisible at all. I just want to make an arrow moving up and down pointing to my app's icon on the menubar and that must be App Store compatible.
Is that possible? How?
You can create a borderless transparent window and set its level to screen saver and set it to ignore mouse clicks. Within this window you can draw your arrow, again use a transparent content view. Look up the docs on NSWindow, NSView etc. to construct this.
Alternatively you can change the menu bar icon of your app itself - switch it, highlight it, animate it. This is the typical way a menu bar app attracts attention. Look up NSStatusItem and NSStatusBarButton.
HTH

Hide/Show the application icon of the Windows taskbar (LabVIEW - WINAPI)

I have an application created with LabVIEW and I need to show/hide the application icon on the Windows taskbar at run time.
I think that WINAPI can be used for this purpose and I tried to use the ShowWindow function (user32.dll)
ShowWindow(hWnd,SW_HIDE) -> hides the application window. The taskbar icon disappears for a second than re-appears.
ShowWindow(hWnd,SW_SHOWMINIMIZED) -> It simply minimizes the application window, so the taskbar icon remains
By default a "normal" visible un-owned window gets a taskbar button and the taskbar button is visible in every state except SW_HIDE.
MSDN also documents a couple of tricks you can use to override the button:
The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.
... If you want to dynamically change a window's style to one that does not support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.
Another alternative is to use the ITaskbarList interface, it gives you full control over your taskbar button.

How can I hide the dock and menubar in my fullscreen game?

I'm writing a game that will run in a fullscreen window. I'm using Xojo to code it (therefore any boolean window properties that might be availble in Xcode / Interface Builder are not an option).
Is there a plist key/value I can set in my app that will hide the application menubar and the dock when my window is set to full screen?
Needs to work on Yosemite.
Get the macoslib
It contains extensions for NSWindow that can do this. Just search the project for "fullscreen".
There is also a demo. If you run the project, open the menu bar: Examples -> Cocoa -> NSWindow. That window has a "Toggle Fullscreen" button for testing.
Here is what you need to place in the window Open event :
self.LiveResize = False
self.MenuBarVisible = false
self.FullScreen = true
First line turns off animation,
Second line turns off UI elements (dock and menu bar),
Third line makes the window full screen

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

All controls disabled in title-less window

In my app I've got a secondary NSWindow that's created from .xib in my NSWindowController in my initWithWindowNibName: method. The window is a plain NSWindow with the title bar switched off.
After creating the window it's shown using makeKeyAndOrderFront: -
and all controls are disabled (text field, combo box).
I have (more than..) triple checked all flags in the window and the view hierarchy of the controls: everything is enabled, allowing editing and not refusing to be first responder.
Totally clueless. Any ideas?
Update #1:
I appears the problem is related to the window not having a title bar. When the title bar is switched on the window - and the controls in the window - behave as expected.
As pointed out by Ken the framework will automatically refuse becoming a key window if the window title is switched off:
Attempts to make the window the key window are abandoned if this
method returns NO. The NSWindow implementation returns YES if the
window has a title bar or a resize bar, or NO otherwise.
A simple subclass did the trick.

Resources