Revert "ui.backend.gtk: only use the timer when not io.backend.unix."

This reverts commit 7d5df2c8a2.
locals-and-roots
John Benediktsson 2016-03-31 16:53:47 -07:00
parent 8c4e602973
commit 281ccddda8
2 changed files with 44 additions and 43 deletions
basis/ui/backend/gtk

View File

@ -1,16 +1,15 @@
! Copyright (C) 2010, 2011 Anton Gorenko, Philipp Bruschweiler.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.strings arrays
assocs classes.struct combinators continuations destructors
environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
gobject-introspection.standard-types gobject.ffi gtk.ffi
gtk.gl.ffi io.encodings.binary io.encodings.utf8 io.files kernel
literals locals math math.bitwise math.vectors namespaces
sequences strings system threads ui ui.backend
ui.backend.gtk.input-methods ui.backend.gtk.io ui.clipboards
ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds
ui.gestures ui.pixel-formats ui.pixel-formats.private ui.private
vocabs.loader ;
USING: accessors alien.accessors alien.c-types alien.data
alien.strings arrays assocs classes.struct combinators continuations
destructors environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi
io.encodings.binary io.encodings.utf8 io.files kernel libc literals
locals math math.bitwise math.vectors namespaces sequences strings
system threads ui ui.backend ui.backend.gtk.input-methods
ui.backend.gtk.io ui.clipboards ui.event-loop ui.gadgets
ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats
ui.pixel-formats.private ui.private vocabs.loader ;
IN: ui.backend.gtk
SINGLETON: gtk-ui-backend
@ -56,6 +55,34 @@ M: gtk-clipboard set-clipboard-contents
gtk_clipboard_get <gtk-clipboard> swap set-global
] 2bi@ ;
! 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 ;
:: with-timer ( 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 ;
! User input
CONSTANT: events-mask
@ -520,8 +547,10 @@ M: gtk-ui-backend (with-ui)
start-ui
[
[
<yield-callback> f g_idle_add drop
gtk_main
[
<yield-callback> f g_idle_add drop
gtk_main
] with-timer
] with-event-loop
] with-destructors
] ui-running ;

View File

@ -1,36 +1,8 @@
! Copyright (C) 2011 Anton Gorenko.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.accessors alien.c-types classes.struct
continuations glib.ffi io.backend kernel libc locals math
threads ;
USING: io.backend kernel ;
IN: ui.backend.gtk.io
HOOK: with-event-loop io-backend ( quot -- )
! 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 ;
M: object with-event-loop call( -- ) ;