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 ( -- )
|
||||||
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
|
] with-autorelease-pool event-loop
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays hashtables kernel models math namespaces sequences
|
USING: arrays hashtables kernel models math namespaces sequences
|
||||||
quotations math.vectors combinators sorting vectors dlists
|
quotations math.vectors combinators sorting vectors dlists
|
||||||
models ;
|
models threads ;
|
||||||
IN: ui.gadgets
|
IN: ui.gadgets
|
||||||
|
|
||||||
TUPLE: rect loc dim ;
|
TUPLE: rect loc dim ;
|
||||||
|
@ -178,13 +178,17 @@ M: array gadget-text*
|
||||||
|
|
||||||
: forget-pref-dim ( gadget -- ) f swap set-gadget-pref-dim ;
|
: 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-queue ( -- queue ) \ layout-queue get ;
|
||||||
|
|
||||||
: layout-later ( gadget -- )
|
: layout-later ( gadget -- )
|
||||||
#! When unit testing gadgets without the UI running, the
|
#! When unit testing gadgets without the UI running, the
|
||||||
#! invalid queue is not initialized and we simply ignore
|
#! invalid queue is not initialized and we simply ignore
|
||||||
#! invalidation requests.
|
#! invalidation requests.
|
||||||
layout-queue [ push-front ] [ drop ] if* ;
|
layout-queue [ push-front notify-ui-thread ] [ drop ] if* ;
|
||||||
|
|
||||||
DEFER: relayout
|
DEFER: relayout
|
||||||
|
|
||||||
|
@ -256,11 +260,11 @@ M: gadget layout* drop ;
|
||||||
|
|
||||||
: queue-graft ( gadget -- )
|
: queue-graft ( gadget -- )
|
||||||
{ f t } over set-gadget-graft-state
|
{ f t } over set-gadget-graft-state
|
||||||
graft-queue push-front ;
|
graft-queue push-front notify-ui-thread ;
|
||||||
|
|
||||||
: queue-ungraft ( gadget -- )
|
: queue-ungraft ( gadget -- )
|
||||||
{ t f } over set-gadget-graft-state
|
{ t f } over set-gadget-graft-state
|
||||||
graft-queue push-front ;
|
graft-queue push-front notify-ui-thread ;
|
||||||
|
|
||||||
: graft-later ( gadget -- )
|
: graft-later ( gadget -- )
|
||||||
dup gadget-graft-state {
|
dup gadget-graft-state {
|
||||||
|
|
|
@ -133,6 +133,9 @@ SYMBOL: ui-hook
|
||||||
: ui-step ( -- )
|
: ui-step ( -- )
|
||||||
[ notify-queued layout-queued redraw-worlds ] assert-depth ;
|
[ notify-queued layout-queued redraw-worlds ] assert-depth ;
|
||||||
|
|
||||||
|
: ui-wait ( -- )
|
||||||
|
10 sleep ;
|
||||||
|
|
||||||
: open-world-window ( world -- )
|
: open-world-window ( world -- )
|
||||||
dup pref-dim over set-gadget-dim dup relayout graft ui-step ;
|
dup pref-dim over set-gadget-dim dup relayout graft ui-step ;
|
||||||
|
|
||||||
|
@ -155,6 +158,7 @@ M: object close-window
|
||||||
find-world [ ungraft ] when* ;
|
find-world [ ungraft ] when* ;
|
||||||
|
|
||||||
: start-ui ( -- )
|
: start-ui ( -- )
|
||||||
|
self ui-thread set-global
|
||||||
restore-windows? [
|
restore-windows? [
|
||||||
restore-windows
|
restore-windows
|
||||||
] [
|
] [
|
||||||
|
|
|
@ -354,7 +354,7 @@ M: windows-ui-backend (close-window)
|
||||||
{
|
{
|
||||||
{ [ windows get empty? ] [ drop ] }
|
{ [ windows get empty? ] [ drop ] }
|
||||||
{ [ dup peek-message? ] [
|
{ [ dup peek-message? ] [
|
||||||
>r [ ui-step 10 sleep ] ui-try
|
>r [ ui-step ui-wait ] ui-try
|
||||||
r> event-loop
|
r> event-loop
|
||||||
] }
|
] }
|
||||||
{ [ dup MSG-message WM_QUIT = ] [ drop ] }
|
{ [ 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 -- )
|
M: windows-ui-backend set-title ( string world -- )
|
||||||
world-handle [ nip win-hWnd WM_SETTEXT 0 ] 2keep
|
world-handle [ nip win-hWnd WM_SETTEXT 0 ] 2keep
|
||||||
dup win-title [ free ] when*
|
dup win-title [ free ] when*
|
||||||
>r malloc-u16-string r>
|
>r malloc-u16-string dup r>
|
||||||
dupd set-win-title alien-address
|
set-win-title alien-address
|
||||||
SendMessage drop ;
|
SendMessage drop ;
|
||||||
|
|
||||||
M: windows-ui-backend ui
|
M: windows-ui-backend ui
|
||||||
|
|
|
@ -178,7 +178,7 @@ M: world client-event
|
||||||
next-event dup
|
next-event dup
|
||||||
None XFilterEvent zero? [ drop wait-event ] unless
|
None XFilterEvent zero? [ drop wait-event ] unless
|
||||||
] [
|
] [
|
||||||
ui-step 10 sleep wait-event
|
ui-step ui-wait wait-event
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: do-events ( -- )
|
: do-events ( -- )
|
||||||
|
|
Loading…
Reference in New Issue