Redo how Cocoa event loop is done; fixes problem with expose, focus issue when closing windows
parent
12c8ffc194
commit
0e0e79eb7e
|
@ -27,17 +27,19 @@ IN: cocoa.application
|
||||||
|
|
||||||
: NSApp ( -- app ) NSApplication -> sharedApplication ;
|
: NSApp ( -- app ) NSApplication -> sharedApplication ;
|
||||||
|
|
||||||
|
: NSAnyEventMask ( -- mask ) HEX: ffffffff ; inline
|
||||||
|
|
||||||
FUNCTION: void NSBeep ( ) ;
|
FUNCTION: void NSBeep ( ) ;
|
||||||
|
|
||||||
: with-cocoa ( quot -- )
|
: with-cocoa ( quot -- )
|
||||||
[ NSApp drop call ] with-autorelease-pool ; inline
|
[ NSApp drop call ] with-autorelease-pool ; inline
|
||||||
|
|
||||||
: next-event ( app -- event )
|
: next-event ( app -- event )
|
||||||
0 f CFRunLoopDefaultMode 1
|
NSAnyEventMask f CFRunLoopDefaultMode 1
|
||||||
-> nextEventMatchingMask:untilDate:inMode:dequeue: ;
|
-> nextEventMatchingMask:untilDate:inMode:dequeue: ;
|
||||||
|
|
||||||
: do-event ( app -- ? )
|
: do-event ( app -- ? )
|
||||||
dup next-event [ -> sendEvent: t ] [ drop f ] if* ;
|
dup next-event [ dupd -> sendEvent: -> updateWindows t ] [ drop f ] if* ;
|
||||||
|
|
||||||
: add-observer ( observer selector name object -- )
|
: add-observer ( observer selector name object -- )
|
||||||
[
|
[
|
||||||
|
@ -49,14 +51,7 @@ FUNCTION: void NSBeep ( ) ;
|
||||||
[ NSNotificationCenter -> defaultCenter ] dip
|
[ NSNotificationCenter -> defaultCenter ] dip
|
||||||
-> removeObserver: ;
|
-> removeObserver: ;
|
||||||
|
|
||||||
: finish-launching ( -- ) NSApp -> finishLaunching ;
|
: cocoa-app ( quot -- ) [ call NSApp -> run ] with-cocoa ; inline
|
||||||
|
|
||||||
: cocoa-app ( quot -- )
|
|
||||||
[
|
|
||||||
call
|
|
||||||
finish-launching
|
|
||||||
NSApp -> run
|
|
||||||
] with-cocoa ; inline
|
|
||||||
|
|
||||||
: install-delegate ( receiver delegate -- )
|
: install-delegate ( receiver delegate -- )
|
||||||
-> alloc -> init -> setDelegate: ;
|
-> alloc -> init -> setDelegate: ;
|
||||||
|
@ -81,6 +76,6 @@ M: objc-error summary ( error -- )
|
||||||
running.app? [
|
running.app? [
|
||||||
drop
|
drop
|
||||||
] [
|
] [
|
||||||
"The " swap " requires you to run Factor from an application bundle."
|
"The " " requires you to run Factor from an application bundle."
|
||||||
3append throw
|
surround throw
|
||||||
] if ;
|
] if ;
|
||||||
|
|
|
@ -85,9 +85,17 @@ MACRO: (send) ( selector super? -- quot )
|
||||||
\ super-send soft "break-after" set-word-prop
|
\ super-send soft "break-after" set-word-prop
|
||||||
|
|
||||||
! Runtime introspection
|
! Runtime introspection
|
||||||
: (objc-class) ( string word -- class )
|
SYMBOL: class-init-hooks
|
||||||
dupd execute
|
|
||||||
[ ] [ "No such class: " prepend throw ] ?if ; inline
|
class-init-hooks global [ H{ } clone or ] change-at
|
||||||
|
|
||||||
|
: (objc-class) ( name word -- class )
|
||||||
|
2dup execute dup [ 2nip ] [
|
||||||
|
drop over class-init-hooks get at [ call ] when*
|
||||||
|
2dup execute dup [ 2nip ] [
|
||||||
|
2drop "No such class: " prepend throw
|
||||||
|
] if
|
||||||
|
] if ; inline
|
||||||
|
|
||||||
: objc-class ( string -- class )
|
: objc-class ( string -- class )
|
||||||
\ objc_getClass (objc-class) ;
|
\ objc_getClass (objc-class) ;
|
||||||
|
@ -221,23 +229,19 @@ assoc-union alien>objc-types set-global
|
||||||
|
|
||||||
: class-exists? ( string -- class ) objc_getClass >boolean ;
|
: class-exists? ( string -- class ) objc_getClass >boolean ;
|
||||||
|
|
||||||
: unless-defined ( class quot -- )
|
: define-objc-class-word ( quot name -- )
|
||||||
[ class-exists? ] dip unless ; inline
|
[ class-init-hooks get set-at ]
|
||||||
|
|
||||||
: define-objc-class-word ( name quot -- )
|
|
||||||
[
|
[
|
||||||
over , , \ unless-defined , dup , \ objc-class ,
|
[ "cocoa.classes" create ] [ '[ _ objc-class ] ] bi
|
||||||
] [ ] make [ "cocoa.classes" create ] dip
|
(( -- class )) define-declared
|
||||||
(( -- class )) define-declared ;
|
] bi ;
|
||||||
|
|
||||||
: import-objc-class ( name quot -- )
|
: import-objc-class ( name quot -- )
|
||||||
2dup unless-defined
|
over define-objc-class-word
|
||||||
dupd define-objc-class-word
|
|
||||||
'[
|
'[
|
||||||
_
|
_
|
||||||
dup
|
[ objc-class register-objc-methods ]
|
||||||
objc-class register-objc-methods
|
[ objc-meta-class register-objc-methods ] bi
|
||||||
objc-meta-class register-objc-methods
|
|
||||||
] try ;
|
] try ;
|
||||||
|
|
||||||
: root-class ( class -- root )
|
: root-class ( class -- root )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2006, 2008 Slava Pestov.
|
! Copyright (C) 2006, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors math arrays cocoa cocoa.application
|
USING: accessors math arrays assocs cocoa cocoa.application
|
||||||
command-line kernel memory namespaces cocoa.messages
|
command-line kernel memory namespaces cocoa.messages
|
||||||
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
||||||
cocoa.windows cocoa.classes cocoa.application sequences system
|
cocoa.windows cocoa.classes cocoa.application sequences system
|
||||||
|
@ -96,16 +96,29 @@ M: cocoa-ui-backend flush-gl-context ( handle -- )
|
||||||
M: cocoa-ui-backend beep ( -- )
|
M: cocoa-ui-backend beep ( -- )
|
||||||
NSBeep ;
|
NSBeep ;
|
||||||
|
|
||||||
|
CLASS: {
|
||||||
|
{ +superclass+ "NSObject" }
|
||||||
|
{ +name+ "FactorApplicationDelegate" }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ "applicationDidFinishLaunching:" "void" { "id" "SEL" "id" }
|
||||||
|
[ 3drop event-loop ]
|
||||||
|
} ;
|
||||||
|
|
||||||
|
: install-app-delegate ( -- )
|
||||||
|
NSApp FactorApplicationDelegate install-delegate ;
|
||||||
|
|
||||||
SYMBOL: cocoa-init-hook
|
SYMBOL: cocoa-init-hook
|
||||||
|
|
||||||
|
cocoa-init-hook global [ [ install-app-delegate ] or ] change-at
|
||||||
|
|
||||||
M: cocoa-ui-backend ui
|
M: cocoa-ui-backend ui
|
||||||
"UI" assert.app [
|
"UI" assert.app [
|
||||||
[
|
[
|
||||||
init-clipboard
|
init-clipboard
|
||||||
cocoa-init-hook get [ call ] when*
|
cocoa-init-hook get call
|
||||||
start-ui
|
start-ui
|
||||||
finish-launching
|
NSApp -> run
|
||||||
event-loop
|
|
||||||
] ui-running
|
] ui-running
|
||||||
] with-cocoa ;
|
] with-cocoa ;
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ IN: ui.cocoa.tools
|
||||||
|
|
||||||
! Handle Open events from the Finder
|
! Handle Open events from the Finder
|
||||||
CLASS: {
|
CLASS: {
|
||||||
{ +superclass+ "NSObject" }
|
{ +superclass+ "FactorApplicationDelegate" }
|
||||||
{ +name+ "FactorApplicationDelegate" }
|
{ +name+ "FactorWorkspaceApplicationDelegate" }
|
||||||
}
|
}
|
||||||
|
|
||||||
{ "application:openFiles:" "void" { "id" "SEL" "id" "id" }
|
{ "application:openFiles:" "void" { "id" "SEL" "id" "id" }
|
||||||
|
@ -49,7 +49,7 @@ CLASS: {
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: install-app-delegate ( -- )
|
: install-app-delegate ( -- )
|
||||||
NSApp FactorApplicationDelegate install-delegate ;
|
NSApp FactorWorkspaceApplicationDelegate install-delegate ;
|
||||||
|
|
||||||
! Service support; evaluate Factor code from other apps
|
! Service support; evaluate Factor code from other apps
|
||||||
:: do-service ( pboard error quot -- )
|
:: do-service ( pboard error quot -- )
|
||||||
|
|
Loading…
Reference in New Issue