I have a NSPopover
window which I would like to add touchbar support to. I've managed to implement touchbar support for a standard NSWindow
, but following the same procedure for my popover doesn't result in any touchbar items appearing in the xCode touchbar simulator.
I am implementing makeTouchbar
and the NSTouchBarDelegate
in a NSViewController
which is presented as a NSPopover
. makeTouchBar
and the delegate functions are being called, but nothing shows in the touchbar (in the below code blocks both Touchbar and hint are logging).
I'm worried that NSPopover windows do not trigger the touchbar as the active app, even though it has keyboard focus. How can I show touchbar items for a NSPopover
window?
//MARK: Touch bar
@available(OSX 10.12.1, *)
override func makeTouchBar() -> NSTouchBar? {
Swift.print("Touchbar.")
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .touchBar
touchBar.defaultItemIdentifiers = [.tbHint, .colourC]
return touchBar
}
@available(OSX 10.12.1, *)
extension RememberViewController: NSTouchBarDelegate {
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
switch identifier{
case NSTouchBarItemIdentifier .tbHint:
Swift.print("hint")
let buttonView = NSCustomTouchBarItem(identifier: identifier)
let button = NSButton(title: "Hint", target: self, action: #selector(showHint))
buttonView.view = button
return buttonView
case NSTouchBarItemIdentifier .colourC:
let colorPicker: NSColorPickerTouchBarItem
colorPicker = NSColorPickerTouchBarItem.colorPicker(withIdentifier: identifier)
colorPicker.customizationLabel = "Color Picker"
colorPicker.target = self
colorPicker.action = #selector(showHint)
return colorPicker
default:
return nil
}
}
}