This is where all the recent I/O and core foundation work comes together: use core-foundation.run-loop to receive events on Mac OS X instead of weak-ass Squeak-style polling every 10ms

db4
Slava Pestov 2008-12-12 23:58:28 -06:00
parent 323de69e88
commit 053c15e476
6 changed files with 38 additions and 33 deletions

View File

@ -5,8 +5,6 @@ IN: ui.backend
SYMBOL: ui-backend SYMBOL: ui-backend
HOOK: do-events ui-backend ( -- )
HOOK: set-title ui-backend ( string world -- ) HOOK: set-title ui-backend ( string world -- )
HOOK: set-fullscreen* ui-backend ( ? world -- ) HOOK: set-fullscreen* ui-backend ( ? world -- )

View File

@ -3,10 +3,11 @@
USING: accessors math arrays assocs 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.nibs sequences system cocoa.windows cocoa.classes cocoa.nibs sequences system ui
ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
ui.cocoa.views core-foundation threads math.geometry.rect fry ui.cocoa.views core-foundation core-foundation.run-loop threads
libc generalizations alien.c-types cocoa.views combinators ; math.geometry.rect fry libc generalizations alien.c-types
cocoa.views combinators io.thread ;
IN: ui.cocoa IN: ui.cocoa
TUPLE: handle ; TUPLE: handle ;
@ -18,9 +19,6 @@ C: <offscreen-handle> offscreen-handle
SINGLETON: cocoa-ui-backend SINGLETON: cocoa-ui-backend
M: cocoa-ui-backend do-events ( -- )
[ NSApp '[ _ do-event ] loop ui-wait ] with-autorelease-pool ;
TUPLE: pasteboard handle ; TUPLE: pasteboard handle ;
C: <pasteboard> pasteboard C: <pasteboard> pasteboard
@ -134,8 +132,8 @@ CLASS: {
{ +name+ "FactorApplicationDelegate" } { +name+ "FactorApplicationDelegate" }
} }
{ "applicationDidFinishLaunching:" "void" { "id" "SEL" "id" } { "applicationDidUpdate:" "void" { "id" "SEL" "id" }
[ 3drop event-loop ] [ 3drop reset-run-loop ]
} ; } ;
: install-app-delegate ( -- ) : install-app-delegate ( -- )
@ -153,6 +151,9 @@ M: cocoa-ui-backend ui
init-clipboard init-clipboard
cocoa-init-hook get call cocoa-init-hook get call
start-ui start-ui
f io-thread-running? set-global
init-thread-timer
reset-run-loop
NSApp -> run NSApp -> run
] ui-running ] ui-running
] with-cocoa ; ] with-cocoa ;

View File

@ -0,0 +1,19 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: ui.backend kernel namespaces sequences deques calendar
threads ;
IN: ui.event-loop
: event-loop? ( -- ? )
{
{ [ stop-after-last-window? get not ] [ t ] }
{ [ graft-queue deque-empty? not ] [ t ] }
{ [ windows get-global empty? not ] [ t ] }
[ f ]
} cond ;
HOOK: do-events ui-backend ( -- )
: event-loop ( quot -- ) [ event-loop? ] [ do-events ] [ ] while ;
: ui-wait ( -- ) 10 milliseconds sleep ;

View File

@ -12,16 +12,6 @@ SYMBOL: windows
SYMBOL: stop-after-last-window? SYMBOL: stop-after-last-window?
: event-loop? ( -- ? )
{
{ [ stop-after-last-window? get not ] [ t ] }
{ [ graft-queue deque-empty? not ] [ t ] }
{ [ windows get-global empty? not ] [ t ] }
[ f ]
} cond ;
: event-loop ( -- ) [ event-loop? ] [ do-events ] [ ] while ;
: window ( handle -- world ) windows get-global at ; : window ( handle -- world ) windows get-global at ;
: window-focus ( handle -- gadget ) window world-focus ; : window-focus ( handle -- gadget ) window world-focus ;
@ -155,9 +145,6 @@ SYMBOL: ui-hook
] assert-depth ] assert-depth
] [ ui-error ] recover ; ] [ ui-error ] recover ;
: ui-wait ( -- )
10 milliseconds sleep ;
SYMBOL: ui-thread SYMBOL: ui-thread
: ui-running ( quot -- ) : ui-running ( quot -- )

View File

@ -3,14 +3,14 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.strings arrays assocs ui USING: alien alien.c-types alien.strings arrays assocs ui
ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds
ui.gestures io kernel math math.vectors namespaces make ui.gestures ui.event-loop io kernel math math.vectors namespaces
sequences strings vectors words windows.kernel32 windows.gdi32 make sequences strings vectors words windows.kernel32
windows.user32 windows.opengl32 windows.messages windows.types windows.gdi32 windows.user32 windows.opengl32 windows.messages
windows.nt windows threads libc combinators fry windows.types windows.nt windows threads libc combinators fry
combinators.short-circuit continuations command-line shuffle combinators.short-circuit continuations command-line shuffle
opengl ui.render ascii math.bitwise locals symbols accessors opengl ui.render ascii math.bitwise locals symbols accessors
math.geometry.rect math.order ascii calendar math.geometry.rect math.order ascii calendar io.encodings.utf16n
io.encodings.utf16n ; ;
IN: ui.windows IN: ui.windows
SINGLETON: windows-ui-backend SINGLETON: windows-ui-backend

View File

@ -2,9 +2,9 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays ui ui.gadgets USING: accessors alien alien.c-types arrays ui ui.gadgets
ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render
assocs kernel math namespaces opengl sequences strings x11.xlib ui.event-loop assocs kernel math namespaces opengl sequences
x11.events x11.xim x11.glx x11.clipboard x11.constants strings x11.xlib x11.events x11.xim x11.glx x11.clipboard
x11.windows io.encodings.string io.encodings.ascii x11.constants x11.windows io.encodings.string io.encodings.ascii
io.encodings.utf8 combinators command-line qualified io.encodings.utf8 combinators command-line qualified
math.vectors classes.tuple opengl.gl threads math.geometry.rect math.vectors classes.tuple opengl.gl threads math.geometry.rect
environment ascii ; environment ascii ;