Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/insidegui/CustomStatusBarWindow
Demonstrates a custom NSWindowController that can be attached to a NSStatusItem on macOS.
https://github.com/insidegui/CustomStatusBarWindow
Last synced: 4 months ago
JSON representation
Demonstrates a custom NSWindowController that can be attached to a NSStatusItem on macOS.
- Host: GitHub
- URL: https://github.com/insidegui/CustomStatusBarWindow
- Owner: insidegui
- License: bsd-2-clause
- Created: 2021-02-02T12:39:28.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-03T16:07:08.000Z (about 4 years ago)
- Last Synced: 2024-08-01T16:56:08.325Z (7 months ago)
- Language: Swift
- Size: 206 KB
- Stars: 116
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This sample project demonstrates a custom `NSWindowController` that can be attached to a `NSStatusItem` on macOS, such that it behaves similarly to `NSPopover`, but without the popover animations and pointy bit. The code was extracted from my app [AirBuddy](https://airbuddy.app).

Creating the controller is easy, it needs a status item to be its "target", and a view controller for its contents:
```swift
windowController = StatusBarMenuWindowController(
statusItem: // your status item,
contentViewController: // any view controller
)
```**Important: the contentViewController must have its `preferredContentSize` set, the window will automatically resize itself based on that (including if it changes while visible).**
To present the window attached to the status item:
```swift
windowController.showWindow(sender)
```If the status item's underlying window can't be found, the window will be positioned centered on screen as a fallback.
The implementation of `StatusBarMenuWindowController` also does a few things to make it behave more like system items like Control Center on macOS 11+, such as posting menu tracking notifications which cause the Menu Bar to stay expanded while it's visible on top of a full screen application.