Made UI more responsive: if another thread invalidates a gadget, UI thread is woken up immediately
parent
fbaf6386b2
commit
d19fd8e111
|
@ -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 ;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
] [
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ( -- )
|
||||
|
|
Loading…
Reference in New Issue