diff --git a/basis/cocoa/cocoa.factor b/basis/cocoa/cocoa.factor index e92f0f9068..f90e6036cc 100644 --- a/basis/cocoa/cocoa.factor +++ b/basis/cocoa/cocoa.factor @@ -14,7 +14,7 @@ SYMBOL: sent-messages SYNTAX: -> scan-token dup remember-send suffix! \ send suffix! ; -SYNTAX: ?-> scan-token dup remember-send suffix! \ ?send suffix! ; +SYNTAX: ?-> dup last cache-stubs scan-token dup remember-send suffix! \ ?send suffix! ; SYNTAX: SEL: scan-token diff --git a/basis/cocoa/messages/messages.factor b/basis/cocoa/messages/messages.factor index 63cbe0224e..8e917975c3 100644 --- a/basis/cocoa/messages/messages.factor +++ b/basis/cocoa/messages/messages.factor @@ -4,8 +4,8 @@ USING: accessors alien alien.c-types alien.data alien.strings arrays assocs classes.struct cocoa.runtime cocoa.types combinators core-graphics.types fry generalizations io.encodings.utf8 kernel layouts libc locals macros make math -memoize namespaces quotations sequences specialized-arrays -stack-checker strings words ; +memoize namespaces quotations sequences sets specialized-arrays +splitting stack-checker strings words ; QUALIFIED-WITH: alien.c-types c IN: cocoa.messages @@ -44,7 +44,11 @@ super-message-senders [ H{ } clone ] initialize TUPLE: selector-tuple name object ; -MEMO: ( name -- sel ) f \ selector-tuple boa ; +: selector-name ( name -- name' ) + CHAR: . over index [ 0 > [ "." split1 nip ] when ] when* ; + +MEMO: ( name -- sel ) + selector-name f selector-tuple boa ; : selector ( selector -- alien ) dup object>> expired? [ @@ -90,7 +94,7 @@ MACRO:: (?send) ( effect selector super? -- quot ) selector dup ?lookup-method effect or super? [ make-prepare-send ] 2keep super-message-senders message-senders ? get at - [ 1quotation append ] [ effect selector sender-stub 1quotation append ] if* ; + 1quotation append ; : ?send ( receiver args... selector effect -- return... ) f (?send) ; inline @@ -234,16 +238,28 @@ ERROR: no-objc-type name ; : method-name ( method -- name ) method_getName sel_getName ; -: register-objc-method ( method -- ) - [ method-name ] - [ [ method-return-type ] [ method-arg-types ] bi 2array ] bi - [ nip cache-stubs ] [ swap objc-methods get set-at ] 2bi ; +:: register-objc-method ( classname method -- ) + method method-return-type + method method-arg-types 2array :> signature + method method-name :> name + classname "." name 3append :> fullname + signature cache-stubs + signature name objc-methods get set-at + signature fullname objc-methods get set-at ; -: each-method-in-class ( class quot -- ) - [ { uint } [ class_copyMethodList ] with-out-parameters ] dip - over 0 = [ 3drop ] [ +: method-collisions ( -- collisions ) + objc-methods get >alist + [ first CHAR: . swap member? ] filter + [ first "." split1 nip ] collect-by + [ nip values members length 1 > ] assoc-filter ; + +: each-method-in-class ( class quot: ( class method -- ) -- ) + [ + [ class_getName ] keep + { uint } [ class_copyMethodList ] with-out-parameters + ] dip over 0 = [ 4drop ] [ [ void* ] dip - [ each ] [ drop (free) ] 2bi + [ with each ] [ drop (free) ] 2bi ] if ; inline : register-objc-methods ( class -- ) diff --git a/basis/cocoa/touchbar/touchbar.factor b/basis/cocoa/touchbar/touchbar.factor index 56efe26978..e040840b93 100644 --- a/basis/cocoa/touchbar/touchbar.factor +++ b/basis/cocoa/touchbar/touchbar.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2017 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types cocoa cocoa.classes cocoa.messages -cocoa.runtime combinators compiler.units core-foundation.strings -init kernel locals namespaces sequences ; +cocoa.runtime combinators core-foundation.strings kernel locals +; IN: cocoa.touchbar : make-touchbar ( seq self -- touchbar ) @@ -21,25 +21,3 @@ IN: cocoa.touchbar action-string lookup-selector { id { id SEL id id SEL } } ?-> buttonWithTitle:target:action: :> button item button -> setView: item ; - -! 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. - -[ - imported? get-global [ - [ - { - "NSCustomTouchBarItem" - "NSTouchBar" - "NSTouchBarItem" - } [ [ ] import-objc-class ] each - ] with-compilation-unit - t imported? set-global - ] unless -] "cocoa.touchbar" add-startup-hook diff --git a/basis/ui/backend/cocoa/views/views.factor b/basis/ui/backend/cocoa/views/views.factor index b3a2f2f952..690269280c 100644 --- a/basis/ui/backend/cocoa/views/views.factor +++ b/basis/ui/backend/cocoa/views/views.factor @@ -189,11 +189,9 @@ M: send-touchbar-command send-queued-gesture self SEL: setWantsBestResolutionOpenGLSurface: -> respondsToSelector: c-bool> [ - self SEL: setWantsBestResolutionOpenGLSurface: 1 - void f "objc_msgSend" { id SEL char } f alien-invoke + self 1 { void { id SEL char } } ?-> setWantsBestResolutionOpenGLSurface: - self SEL: backingScaleFactor - double f "objc_msgSend" { id SEL } f alien-invoke + self { double { id SEL } } ?-> backingScaleFactor dup 1.0 > [ gl-scale-factor set-global t retina? set-global @@ -213,13 +211,13 @@ M: send-touchbar-command send-queued-gesture METHOD: void touchBarCommand6 [ 6 touchbar-invoke-command ] ; METHOD: void touchBarCommand7 [ 7 touchbar-invoke-command ] ; - METHOD: Class makeTouchBar [ + METHOD: id makeTouchBar [ touchbar-commands drop [ length 8 min [ number>string ] map ] [ { } ] if* self make-touchbar ] ; - METHOD: Class touchBar: Class touchbar makeItemForIdentifier: Class string [ + METHOD: id touchBar: id touchbar makeItemForIdentifier: id string [ touchbar-commands drop [ [ self string CF>string dup string>number ] dip nth second name>> "com-" ?head drop over @@ -271,29 +269,29 @@ M: send-touchbar-command send-queued-gesture ] [ 0 ] if* ] ; - METHOD: id undo: id event [ self event undo-action send-action$ f ] ; + METHOD: void undo: id event [ self event undo-action send-action$ ] ; - METHOD: id redo: id event [ self event redo-action send-action$ f ] ; + METHOD: void redo: id event [ self event redo-action send-action$ ] ; - METHOD: id cut: id event [ self event cut-action send-action$ f ] ; + METHOD: void cut: id event [ self event cut-action send-action$ ] ; - METHOD: id copy: id event [ self event copy-action send-action$ f ] ; + METHOD: void copy: id event [ self event copy-action send-action$ ] ; - METHOD: id paste: id event [ self event paste-action send-action$ f ] ; + METHOD: void paste: id event [ self event paste-action send-action$ ] ; - METHOD: id delete: id event [ self event delete-action send-action$ f ] ; + METHOD: void delete: id event [ self event delete-action send-action$ ] ; - METHOD: id selectAll: id event [ self event select-all-action send-action$ f ] ; + METHOD: void selectAll: id event [ self event select-all-action send-action$ ] ; - METHOD: id newDocument: id event [ self event new-action send-action$ f ] ; + METHOD: void newDocument: id event [ self event new-action send-action$ ] ; - METHOD: id openDocument: id event [ self event open-action send-action$ f ] ; + METHOD: void openDocument: id event [ self event open-action send-action$ ] ; - METHOD: id saveDocument: id event [ self event save-action send-action$ f ] ; + METHOD: void saveDocument: id event [ self event save-action send-action$ ] ; - METHOD: id saveDocumentAs: id event [ self event save-as-action send-action$ f ] ; + METHOD: void saveDocumentAs: id event [ self event save-as-action send-action$ ] ; - METHOD: id revertDocumentToSaved: id event [ self event revert-action send-action$ f ] ; + METHOD: void revertDocumentToSaved: id event [ self event revert-action send-action$ ] ; ! Multi-touch gestures METHOD: void magnifyWithEvent: id event