2017-05-30 13:09:02 -04:00
|
|
|
! Copyright (C) 2017 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2018-01-01 18:01:04 -05:00
|
|
|
USING: alien.c-types cocoa cocoa.classes cocoa.messages
|
2018-03-12 12:38:05 -04:00
|
|
|
cocoa.runtime combinators compiler.units core-foundation.strings
|
|
|
|
init kernel locals namespaces sequences ;
|
2017-05-30 13:09:02 -04:00
|
|
|
IN: cocoa.touchbar
|
|
|
|
|
2018-01-01 18:01:04 -05:00
|
|
|
: make-touchbar ( seq self -- touchbar )
|
2017-05-30 13:09:02 -04:00
|
|
|
[ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
|
2018-01-28 14:21:23 -05:00
|
|
|
[ swap <CFStringArray> { void { id SEL id } } ?-> setDefaultItemIdentifiers: ]
|
|
|
|
[ swap <CFStringArray> { void { id SEL id } } ?-> setCustomizationAllowedItemIdentifiers: ]
|
2017-05-30 13:09:02 -04:00
|
|
|
[ nip ]
|
|
|
|
} 2cleave ;
|
|
|
|
|
|
|
|
:: make-NSTouchBar-button ( self identifier label-string action-string -- button )
|
|
|
|
NSCustomTouchBarItem -> alloc
|
2018-01-28 14:21:23 -05:00
|
|
|
identifier <CFString> { id { id SEL id } } ?-> initWithIdentifier: :> item
|
2017-05-30 13:09:02 -04:00
|
|
|
NSButton
|
|
|
|
label-string <CFString>
|
|
|
|
self
|
2018-01-28 14:21:23 -05:00
|
|
|
action-string lookup-selector { id { id SEL id id SEL } } ?-> buttonWithTitle:target:action: :> button
|
2017-05-30 13:09:02 -04:00
|
|
|
item button -> setView:
|
2017-06-01 14:46:32 -04:00
|
|
|
item ;
|
2018-03-12 12:38:05 -04:00
|
|
|
|
|
|
|
! Temporary hack to support new touchbar API on old macOS build
|
|
|
|
! machines by attempting to re-import the objc-class which
|
|
|
|
! causes re-registering of the objc-methods which were not
|
|
|
|
! present on the macOS 10.11 build machine. We use a flag
|
|
|
|
! to cause this delay only the first time the image is run
|
|
|
|
! and then saved.
|
|
|
|
<PRIVATE
|
|
|
|
SYMBOL: imported?
|
|
|
|
PRIVATE>
|
|
|
|
[
|
|
|
|
imported? get-global [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"NSCustomTouchBarItem"
|
|
|
|
"NSTouchBar"
|
|
|
|
"NSTouchBarItem"
|
|
|
|
} [ [ ] import-objc-class ] each
|
|
|
|
] with-compilation-unit
|
|
|
|
t imported? set-global
|
|
|
|
] unless
|
|
|
|
] "cocoa.touchbar" add-startup-hook
|