diff --git a/basis/ui/backend/backend.factor b/basis/ui/backend/backend.factor index aa84419d64..eaa0953d25 100755 --- a/basis/ui/backend/backend.factor +++ b/basis/ui/backend/backend.factor @@ -5,8 +5,6 @@ IN: ui.backend SYMBOL: ui-backend -HOOK: do-events ui-backend ( -- ) - HOOK: set-title ui-backend ( string world -- ) HOOK: set-fullscreen* ui-backend ( ? world -- ) diff --git a/basis/ui/cocoa/cocoa.factor b/basis/ui/cocoa/cocoa.factor index fecbb52a25..331c0a698c 100755 --- a/basis/ui/cocoa/cocoa.factor +++ b/basis/ui/cocoa/cocoa.factor @@ -3,10 +3,11 @@ USING: accessors math arrays assocs cocoa cocoa.application command-line kernel memory namespaces cocoa.messages cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types -cocoa.windows cocoa.classes cocoa.nibs sequences system -ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds -ui.cocoa.views core-foundation threads math.geometry.rect fry -libc generalizations alien.c-types cocoa.views combinators ; +cocoa.windows cocoa.classes cocoa.nibs sequences system ui +ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds +ui.cocoa.views core-foundation core-foundation.run-loop threads +math.geometry.rect fry libc generalizations alien.c-types +cocoa.views combinators io.thread ; IN: ui.cocoa TUPLE: handle ; @@ -18,9 +19,6 @@ C: offscreen-handle SINGLETON: cocoa-ui-backend -M: cocoa-ui-backend do-events ( -- ) - [ NSApp '[ _ do-event ] loop ui-wait ] with-autorelease-pool ; - TUPLE: pasteboard handle ; C: pasteboard @@ -134,8 +132,8 @@ CLASS: { { +name+ "FactorApplicationDelegate" } } -{ "applicationDidFinishLaunching:" "void" { "id" "SEL" "id" } - [ 3drop event-loop ] +{ "applicationDidUpdate:" "void" { "id" "SEL" "id" } + [ 3drop reset-run-loop ] } ; : install-app-delegate ( -- ) @@ -153,6 +151,9 @@ M: cocoa-ui-backend ui init-clipboard cocoa-init-hook get call start-ui + f io-thread-running? set-global + init-thread-timer + reset-run-loop NSApp -> run ] ui-running ] with-cocoa ; diff --git a/basis/ui/event-loop/event-loop.factor b/basis/ui/event-loop/event-loop.factor new file mode 100644 index 0000000000..fe6f4d7de5 --- /dev/null +++ b/basis/ui/event-loop/event-loop.factor @@ -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 ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 1ee860c974..b6bc172c21 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -12,16 +12,6 @@ SYMBOL: windows 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-focus ( handle -- gadget ) window world-focus ; @@ -155,9 +145,6 @@ SYMBOL: ui-hook ] assert-depth ] [ ui-error ] recover ; -: ui-wait ( -- ) - 10 milliseconds sleep ; - SYMBOL: ui-thread : ui-running ( quot -- ) diff --git a/basis/ui/windows/windows.factor b/basis/ui/windows/windows.factor index 35ee9f9a60..7f68bb5736 100755 --- a/basis/ui/windows/windows.factor +++ b/basis/ui/windows/windows.factor @@ -3,14 +3,14 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings arrays assocs ui ui.gadgets ui.backend ui.clipboards ui.gadgets.worlds -ui.gestures io kernel math math.vectors namespaces make -sequences strings vectors words windows.kernel32 windows.gdi32 -windows.user32 windows.opengl32 windows.messages windows.types -windows.nt windows threads libc combinators fry +ui.gestures ui.event-loop io kernel math math.vectors namespaces +make sequences strings vectors words windows.kernel32 +windows.gdi32 windows.user32 windows.opengl32 windows.messages +windows.types windows.nt windows threads libc combinators fry combinators.short-circuit continuations command-line shuffle opengl ui.render ascii math.bitwise locals symbols accessors -math.geometry.rect math.order ascii calendar -io.encodings.utf16n ; +math.geometry.rect math.order ascii calendar io.encodings.utf16n +; IN: ui.windows SINGLETON: windows-ui-backend diff --git a/basis/ui/x11/x11.factor b/basis/ui/x11/x11.factor index 817e356712..9be3c2fd10 100755 --- a/basis/ui/x11/x11.factor +++ b/basis/ui/x11/x11.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types arrays ui ui.gadgets ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render -assocs kernel math namespaces opengl sequences strings x11.xlib -x11.events x11.xim x11.glx x11.clipboard x11.constants -x11.windows io.encodings.string io.encodings.ascii +ui.event-loop assocs kernel math namespaces opengl sequences +strings x11.xlib x11.events x11.xim x11.glx x11.clipboard +x11.constants x11.windows io.encodings.string io.encodings.ascii io.encodings.utf8 combinators command-line qualified math.vectors classes.tuple opengl.gl threads math.geometry.rect environment ascii ;