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.
factor-shell
Björn Lindqvist 2018-01-18 17:30:51 +01:00
parent 9f1935c7f1
commit f93da595f5
2 changed files with 21 additions and 14 deletions

View 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." } ;

View 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 ;