2011-01-26 10:00:35 -05:00
|
|
|
! Copyright (C) 2011 Anton Gorenko.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2016-03-30 01:36:02 -04:00
|
|
|
USING: accessors alien.accessors alien.c-types classes.struct
|
|
|
|
continuations glib.ffi io.backend kernel libc locals math
|
|
|
|
threads ;
|
2011-01-26 10:00:35 -05:00
|
|
|
IN: ui.backend.gtk.io
|
|
|
|
|
2011-04-01 12:06:07 -04:00
|
|
|
HOOK: with-event-loop io-backend ( quot -- )
|
2011-01-26 10:00:35 -05:00
|
|
|
|
2016-03-30 01:36:02 -04:00
|
|
|
! Timer
|
|
|
|
|
|
|
|
: set-timeout*-value ( alien value -- )
|
|
|
|
swap 0 set-alien-signed-4 ; inline
|
|
|
|
|
|
|
|
: timer-prepare ( source timeout* -- ? )
|
|
|
|
nip sleep-time 1,000,000,000 or
|
|
|
|
[ 1,000,000 /i set-timeout*-value ] keep 0 = ;
|
|
|
|
|
|
|
|
: timer-check ( source -- ? )
|
|
|
|
drop sleep-time 0 = ;
|
|
|
|
|
|
|
|
: timer-dispatch ( source callback user_data -- ? )
|
|
|
|
3drop yield t ;
|
|
|
|
|
|
|
|
: <timer-funcs> ( -- timer-funcs )
|
|
|
|
GSourceFuncs malloc-struct
|
|
|
|
[ timer-prepare ] GSourceFuncsPrepareFunc >>prepare
|
|
|
|
[ timer-check ] GSourceFuncsCheckFunc >>check
|
|
|
|
[ timer-dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
|
|
|
|
|
|
|
|
M:: object with-event-loop ( quot -- )
|
|
|
|
<timer-funcs> &free
|
|
|
|
GSource heap-size g_source_new &g_source_unref :> source
|
|
|
|
source f g_source_attach drop
|
|
|
|
[ quot call( -- ) ]
|
|
|
|
[ source g_source_destroy ] [ ] cleanup ;
|