]> gitweb.factorcode.org Git - factor.git/commitdiff
ui: undoing 9e9b70005b9cea57b87cd9bfbee94cee600b50c1
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 18 Jan 2018 16:30:51 +0000 (17:30 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 18 Jan 2018 16:30:51 +0000 (17:30 +0100)
The ui-thread variable absolutely is needed to ensure that only one UI
thread is running at the same time. If more than one UI thread runs,
they will be competing for events which causes all sorts of problems.

basis/ui/ui-docs.factor
basis/ui/ui.factor

index c97354e18bcdd822e68e80741ec3214aeb28de05..29078d5206dd192b62ef160959cccb7d502fa090 100644 (file)
@@ -6,10 +6,26 @@ vocabs.loader ;
 
 IN: ui
 
+HELP: close-window
+{ $values { "gadget" gadget } }
+{ $description "Close the native window containing " { $snippet "gadget" } "." } ;
+
 HELP: open-window
 { $values { "gadget" gadget } { "title/attributes" { "a " { $link string } " or a " { $link world-attributes } " tuple" } } }
 { $description "Opens a native window containing " { $snippet "gadget" } " with the specified attributes. If a string is provided, it is used as the window title; otherwise, the window attributes are specified in a " { $link world-attributes } " tuple." } ;
 
+HELP: set-fullscreen
+{ $values { "gadget" gadget } { "?" boolean } }
+{ $description "Sets and unsets fullscreen mode for the gadget's world." } ;
+
+HELP: set-up-window
+{ $values { "world" world } }
+{ $description "Initializes the window that shows the world." } ;
+
+HELP: ui-thread
+{ $var-description "Holds a reference to the running UI thread. This variable is used to ensure that there can only be one UI thread running at the same time." }
+{ $see-also start-ui-thread } ;
+
 HELP: ui-running?
 { $values { "?" boolean } }
 { $description "Whether the UI is running or not." } ;
@@ -19,10 +35,6 @@ HELP: ui-windows
 
 { ui-windows open-window find-window world-attributes } related-words
 
-HELP: close-window
-{ $values { "gadget" gadget } }
-{ $description "Close the native window containing " { $snippet "gadget" } "." } ;
-
 HELP: world-attributes
 { $values { "world-class" class } { "title" string } { "status" gadget } { "gadgets" sequence } { "pixel-format-attributes" sequence } { "window-controls" sequence } }
 { $class-description "Tuples of this class can be passed to " { $link open-window } " to control attributes of the window opened. The following attributes can be set:" }
@@ -35,14 +47,6 @@ HELP: world-attributes
     { { $snippet "window-controls" } " is a sequence of " { $link "ui.gadgets.worlds-window-controls" } " that will be placed in the window." }
 } ;
 
-HELP: set-fullscreen
-{ $values { "gadget" gadget } { "?" boolean } }
-{ $description "Sets and unsets fullscreen mode for the gadget's world." } ;
-
-HELP: set-up-window
-{ $values { "world" world } }
-{ $description "Initializes the window that shows the world." } ;
-
 HELP: fullscreen?
 { $values { "gadget" gadget } { "?" boolean } }
 { $description "Queries the gadget's world to see if it is running in fullscreen mode." } ;
index 5cce30ac93a3e1c25b0bafb7315b1fc0fe590174..6d2739970f843dcbd0a3d52343608970979eaf2f 100644 (file)
@@ -150,12 +150,14 @@ PRIVATE>
 
 <PRIVATE
 
+SYMBOL: ui-thread
+
 : update-ui-loop ( -- )
     ! Note the logic: if update-ui fails, we open an error window and
     ! run one iteration of update-ui. If that also fails, well, the
     ! whole UI subsystem is broken so we throw the error to terminate
     ! the update-ui-loop.
-    [ ui-running? ]
+    [ { [ ui-running? ] [ ui-thread get-global self eq? ] } 0&& ]
     [
         ui-notify-flag get lower-flag
         [ update-ui ] [
@@ -166,7 +168,8 @@ PRIVATE>
     ] while ;
 
 : start-ui-thread ( -- )
-    [ update-ui-loop ] "UI update" spawn drop ;
+    [ self ui-thread set-global update-ui-loop ]
+    "UI update" spawn drop ;
 
 : start-ui ( quot -- )
     call( -- ) notify-ui-thread start-ui-thread ;