diff --git a/basis/ui/backend/cocoa/cocoa.factor b/basis/ui/backend/cocoa/cocoa.factor index 42ce071171..93798fca78 100644 --- a/basis/ui/backend/cocoa/cocoa.factor +++ b/basis/ui/backend/cocoa/cocoa.factor @@ -215,15 +215,13 @@ cocoa-startup-hook [ M: cocoa-ui-backend (with-ui) "UI" assert.app [ - [ - init-clipboard - cocoa-startup-hook get call( -- ) - start-ui - stop-io-thread - init-thread-timer - reset-thread-timer - NSApp -> run - ] with-ui-running + init-clipboard + cocoa-startup-hook get call( -- ) + start-ui + stop-io-thread + init-thread-timer + reset-thread-timer + NSApp -> run ] with-cocoa ; cocoa-ui-backend ui-backend set-global diff --git a/basis/ui/backend/gtk/gtk.factor b/basis/ui/backend/gtk/gtk.factor index 0db4697367..32cdca039f 100644 --- a/basis/ui/backend/gtk/gtk.factor +++ b/basis/ui/backend/gtk/gtk.factor @@ -503,16 +503,14 @@ M:: gtk-ui-backend system-alert ( caption text -- ) ] with-destructors ; M: gtk-ui-backend (with-ui) + f f gtk_init + f f gtk_gl_init + load-icon + init-clipboard + start-ui [ - f f gtk_init - f f gtk_gl_init - load-icon - init-clipboard - start-ui - [ - [ [ gtk_main ] with-timer ] with-event-loop - ] with-destructors - ] with-ui-running ; + [ [ gtk_main ] with-timer ] with-event-loop + ] with-destructors ; M: gtk-ui-backend stop-event-loop gtk_main_quit ; diff --git a/basis/ui/backend/windows/windows.factor b/basis/ui/backend/windows/windows.factor index 436f26b745..dcae45f1d1 100755 --- a/basis/ui/backend/windows/windows.factor +++ b/basis/ui/backend/windows/windows.factor @@ -706,13 +706,11 @@ M: windows-ui-backend set-title ( string world -- ) M: windows-ui-backend (with-ui) [ - [ - init-clipboard - init-win32-ui - start-ui - event-loop - ] [ cleanup-win32-ui ] [ ] cleanup - ] with-ui-running ; + init-clipboard + init-win32-ui + start-ui + event-loop + ] [ cleanup-win32-ui ] [ ] cleanup ; M: windows-ui-backend beep ( -- ) 0 MessageBeep drop ; diff --git a/basis/ui/backend/x11/x11.factor b/basis/ui/backend/x11/x11.factor index 38a4cb5cd1..6b2210704e 100644 --- a/basis/ui/backend/x11/x11.factor +++ b/basis/ui/backend/x11/x11.factor @@ -319,15 +319,13 @@ M: x11-handle flush-gl-context ( handle -- ) dpy get swap window>> glXSwapBuffers ; M: x11-ui-backend (with-ui) ( quot -- ) - [ - f [ - [ - init-clipboard - start-ui - event-loop - ] with-xim - ] with-x - ] with-ui-running ; + f [ + [ + init-clipboard + start-ui + event-loop + ] with-xim + ] with-x ; M: x11-ui-backend beep ( -- ) dpy get 100 XBell drop ; diff --git a/basis/ui/ui-docs.factor b/basis/ui/ui-docs.factor index 5d4220b6fa..75b9cc5dbc 100644 --- a/basis/ui/ui-docs.factor +++ b/basis/ui/ui-docs.factor @@ -3,7 +3,6 @@ math.rectangles namespaces quotations sequences strings ui.backend ui.gadgets ui.gadgets.books ui.gadgets.grids ui.gadgets.packs ui.gadgets.private ui.gadgets.tracks ui.gadgets.worlds ui.private ui.text vocabs.loader ; - IN: ui HELP: close-window @@ -91,7 +90,10 @@ HELP: raise-window HELP: with-ui { $values { "quot" { $quotation ( -- ) } } } -{ $description "Calls the quotation, starting the UI if necessary. If starting the UI is necessary, this word does not return and the UI will start after the quotation returns." } +{ $description + "Calls the quotation, starting the UI if necessary. If starting the UI is necessary, this word does not return and the UI will start after the quotation returns." $nl + "While the combinator is running, " { $link ui-running? } " can be used by user code to determine whether it is running in a UI context or not." +} { $notes "This word should be used in the " { $link POSTPONE: MAIN: } " word of an application that uses the UI in order for the vocabulary to work when run from either the UI listener (" { $snippet "\"my-app\" run" } ") and the command line (" { $snippet "./factor -run=my-app" } ")." } { $examples "The " { $vocab-link "hello-ui" } " vocabulary implements a simple UI application which uses this word." } ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index a38f4f9b1c..d23416ca19 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -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 ) @@ -225,7 +221,11 @@ 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 ] [ ] cleanup + ] if ; HOOK: beep ui-backend ( -- )