diff --git a/extra/ui/cocoa/cocoa.factor b/extra/ui/cocoa/cocoa.factor index 53ed62252d..b719556cba 100755 --- a/extra/ui/cocoa/cocoa.factor +++ b/extra/ui/cocoa/cocoa.factor @@ -19,7 +19,7 @@ SYMBOL: stop-after-last-window? : event-loop ( -- ) event-loop? [ [ - [ NSApp do-events ui-step 10 sleep ] ui-try + [ NSApp do-events ui-step ui-wait ] ui-try ] with-autorelease-pool event-loop ] when ; diff --git a/extra/ui/gadgets/gadgets.factor b/extra/ui/gadgets/gadgets.factor index 37c5684cc9..3db3b9c270 100755 --- a/extra/ui/gadgets/gadgets.factor +++ b/extra/ui/gadgets/gadgets.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays hashtables kernel models math namespaces sequences quotations math.vectors combinators sorting vectors dlists -models ; +models threads ; IN: ui.gadgets TUPLE: rect loc dim ; @@ -178,13 +178,17 @@ M: array gadget-text* : forget-pref-dim ( gadget -- ) f swap set-gadget-pref-dim ; +SYMBOL: ui-thread + +: notify-ui-thread ( -- ) ui-thread get interrupt ; + : layout-queue ( -- queue ) \ layout-queue get ; : layout-later ( gadget -- ) #! When unit testing gadgets without the UI running, the #! invalid queue is not initialized and we simply ignore #! invalidation requests. - layout-queue [ push-front ] [ drop ] if* ; + layout-queue [ push-front notify-ui-thread ] [ drop ] if* ; DEFER: relayout @@ -256,11 +260,11 @@ M: gadget layout* drop ; : queue-graft ( gadget -- ) { f t } over set-gadget-graft-state - graft-queue push-front ; + graft-queue push-front notify-ui-thread ; : queue-ungraft ( gadget -- ) { t f } over set-gadget-graft-state - graft-queue push-front ; + graft-queue push-front notify-ui-thread ; : graft-later ( gadget -- ) dup gadget-graft-state { diff --git a/extra/ui/ui.factor b/extra/ui/ui.factor index 1de0dac6f0..adff223bc7 100755 --- a/extra/ui/ui.factor +++ b/extra/ui/ui.factor @@ -133,6 +133,9 @@ SYMBOL: ui-hook : ui-step ( -- ) [ notify-queued layout-queued redraw-worlds ] assert-depth ; +: ui-wait ( -- ) + 10 sleep ; + : open-world-window ( world -- ) dup pref-dim over set-gadget-dim dup relayout graft ui-step ; @@ -155,6 +158,7 @@ M: object close-window find-world [ ungraft ] when* ; : start-ui ( -- ) + self ui-thread set-global restore-windows? [ restore-windows ] [ diff --git a/extra/ui/windows/windows.factor b/extra/ui/windows/windows.factor index b5e3fa6814..b7040c875d 100755 --- a/extra/ui/windows/windows.factor +++ b/extra/ui/windows/windows.factor @@ -354,7 +354,7 @@ M: windows-ui-backend (close-window) { { [ windows get empty? ] [ drop ] } { [ dup peek-message? ] [ - >r [ ui-step 10 sleep ] ui-try + >r [ ui-step ui-wait ] ui-try r> event-loop ] } { [ dup MSG-message WM_QUIT = ] [ drop ] } @@ -459,8 +459,8 @@ M: windows-ui-backend raise-window* ( world -- ) M: windows-ui-backend set-title ( string world -- ) world-handle [ nip win-hWnd WM_SETTEXT 0 ] 2keep dup win-title [ free ] when* - >r malloc-u16-string r> - dupd set-win-title alien-address + >r malloc-u16-string dup r> + set-win-title alien-address SendMessage drop ; M: windows-ui-backend ui diff --git a/extra/ui/x11/x11.factor b/extra/ui/x11/x11.factor index 9156089a2f..d56bd8e119 100755 --- a/extra/ui/x11/x11.factor +++ b/extra/ui/x11/x11.factor @@ -178,7 +178,7 @@ M: world client-event next-event dup None XFilterEvent zero? [ drop wait-event ] unless ] [ - ui-step 10 sleep wait-event + ui-step ui-wait wait-event ] if ; : do-events ( -- )