]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/ui/ui.factor
basis: use lint.vocabs tool to trim using lists
[factor.git] / basis / ui / ui.factor
index a38f4f9b1c951e4bba64ef796f7445407fc4d90a..b2b556a42635f108fb64d89004876d68653b15b6 100644 (file)
@@ -3,10 +3,10 @@
 USING: accessors arrays assocs boxes classes.tuple
 classes.tuple.parser combinators combinators.short-circuit
 concurrency.flags concurrency.promises continuations deques
-destructors dlists fry init kernel lexer make math
-math.functions namespaces parser sequences sets strings threads
-ui.backend ui.gadgets ui.gadgets.private ui.gadgets.worlds
-ui.gestures ui.render vectors vocabs.parser words ;
+destructors dlists kernel lexer make math math.functions
+namespaces parser sequences sets strings threads ui.backend
+ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
+ui.render vectors vocabs.parser words ;
 IN: ui
 
 <PRIVATE
@@ -111,7 +111,7 @@ M: world ungraft*
     dup hand-world get-global eq?
     [ hand-loc get-global swap move-hand ] [ drop ] if ;
 
-: slurp-vector ( .. seq quot: ( ... elt -- .. ) -- )
+: slurp-vector ( ... seq quot: ( ... elt -- ... ) -- ... )
     over '[ _ empty? not ] -rot '[ _ pop @ ] while ; inline
 
 : layout-queued ( -- seq )
@@ -134,10 +134,6 @@ M: world ungraft*
 
 SYMBOL: ui-running
 
-: with-ui-running ( quot -- )
-    t ui-running set-global
-    [ f ui-running set-global ] [ ] cleanup ; inline
-
 PRIVATE>
 
 : find-windows ( quot: ( world -- ? ) -- seq )
@@ -212,10 +208,10 @@ HOOK: close-window ui-backend ( gadget -- )
 M: object close-window
     find-world [ ungraft ] when* ;
 
-[
+STARTUP-HOOK: [
     f ui-running set-global
     <flag> ui-notify-flag set-global
-] "ui" add-startup-hook
+]
 
 HOOK: resize-window ui-backend ( world dim -- )
 M: object resize-window 2drop ;
@@ -225,7 +221,15 @@ M: object resize-window 2drop ;
     [ find-world [ dup pref-dim resize-window ] when* ] bi ;
 
 : with-ui ( quot: ( -- ) -- )
-    ui-running? [ call( -- ) ] [ '[ init-ui @ ] (with-ui) ] if ;
+    ui-running? [ call( -- ) ] [
+        t ui-running set-global '[
+            [ init-ui @ ] (with-ui)
+        ] [
+            f ui-running set-global
+            ! Give running ui threads a chance to finish.
+            notify-ui-thread yield
+        ] finally
+    ] if ;
 
 HOOK: beep ui-backend ( -- )