ui.backend.gtk: only use the timer when not io.backend.unix.
parent
2929cc21f5
commit
7d5df2c8a2
|
@ -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
|
||||||
|
@ -547,10 +520,8 @@ M: gtk-ui-backend (with-ui)
|
||||||
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 ;
|
||||||
|
|
|
@ -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 ;
|
||||||
|
|
Loading…
Reference in New Issue