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

View File

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

View File

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