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

locals-and-roots
John Benediktsson 2016-03-29 22:36:02 -07:00
parent 2929cc21f5
commit 7d5df2c8a2
2 changed files with 43 additions and 44 deletions

View File

@ -1,15 +1,16 @@
! 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.accessors alien.c-types alien.data USING: accessors alien.c-types alien.data alien.strings arrays
alien.strings arrays assocs classes.struct combinators continuations assocs classes.struct combinators continuations destructors
destructors environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi gobject-introspection.standard-types gobject.ffi gtk.ffi
io.encodings.binary io.encodings.utf8 io.files kernel libc literals gtk.gl.ffi io.encodings.binary io.encodings.utf8 io.files kernel
locals math math.bitwise math.vectors namespaces sequences strings literals locals math math.bitwise math.vectors namespaces
system threads ui ui.backend ui.backend.gtk.input-methods sequences strings system threads ui ui.backend
ui.backend.gtk.io ui.clipboards ui.event-loop ui.gadgets ui.backend.gtk.input-methods ui.backend.gtk.io ui.clipboards
ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds
ui.pixel-formats.private ui.private vocabs.loader ; ui.gestures ui.pixel-formats ui.pixel-formats.private ui.private
vocabs.loader ;
IN: ui.backend.gtk IN: ui.backend.gtk
SINGLETON: gtk-ui-backend SINGLETON: gtk-ui-backend
@ -55,34 +56,6 @@ 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
@ -545,12 +518,10 @@ M: gtk-ui-backend (with-ui)
load-icon load-icon
init-clipboard init-clipboard
start-ui start-ui
[
[ [
[ [
<yield-callback> f g_idle_add drop <yield-callback> f g_idle_add drop
gtk_main gtk_main
] with-timer
] with-event-loop ] with-event-loop
] with-destructors ] with-destructors
] ui-running ; ] ui-running ;

View File

@ -1,8 +1,36 @@
! 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: io.backend kernel ; USING: accessors alien.accessors alien.c-types classes.struct
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 -- )
M: object with-event-loop call( -- ) ; ! 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 ;