]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/touchbar/touchbar.factor
cocoa.touchbar: quick hack to experiment with 10.11 build problem
[factor.git] / basis / cocoa / touchbar / touchbar.factor
1 ! Copyright (C) 2017 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types cocoa cocoa.classes cocoa.messages
4 cocoa.runtime combinators compiler.units core-foundation.strings
5 init kernel locals namespaces sequences ;
6 IN: cocoa.touchbar
7
8 : make-touchbar ( seq self -- touchbar )
9     [ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
10         [ swap <CFStringArray> { void { id SEL id } } ?-> setDefaultItemIdentifiers: ]
11         [ swap <CFStringArray> { void { id SEL id } } ?-> setCustomizationAllowedItemIdentifiers: ]
12         [ nip ]
13     } 2cleave ;
14
15 :: make-NSTouchBar-button ( self identifier label-string action-string -- button )
16     NSCustomTouchBarItem -> alloc
17         identifier <CFString> { id { id SEL id } } ?-> initWithIdentifier: :> item
18         NSButton
19             label-string <CFString>
20             self
21             action-string lookup-selector { id { id SEL id id SEL } } ?-> buttonWithTitle:target:action: :> button
22         item button -> setView:
23         item ;
24
25 ! Temporary hack to support new touchbar API on old macOS build
26 ! machines by attempting to re-import the objc-class which
27 ! causes re-registering of the objc-methods which were not
28 ! present on the macOS 10.11 build machine.  We use a flag
29 ! to cause this delay only the first time the image is run
30 ! and then saved.
31 <PRIVATE
32 SYMBOL: imported?
33 PRIVATE>
34 [
35     imported? get-global [
36         [
37             {
38                 "NSCustomTouchBarItem"
39                 "NSTouchBar"
40                 "NSTouchBarItem"
41             } [ [ ] import-objc-class ] each
42         ] with-compilation-unit
43         t imported? set-global
44     ] unless
45 ] "cocoa.touchbar" add-startup-hook