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." } ;
{ 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:" }
{ { $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." } ;
<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 ] [
] 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 ;