ui.backend.gtk: fix a bug with endless error messages in a console after closing of UI;
io.thread: start-io-thread always starts io-thread even if it was stopped, fix line endings;db4
parent
f006b3482c
commit
090254d671
|
@ -1,23 +1,21 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: threads io.backend namespaces init math kernel ;
|
USING: init io.backend kernel namespaces threads ;
|
||||||
IN: io.thread
|
IN: io.thread
|
||||||
|
|
||||||
! The Cocoa UI backend stops the I/O thread and takes over
|
! The Cocoa and Gtk UI backend stops the I/O thread and takes
|
||||||
! completely.
|
! over completely.
|
||||||
SYMBOL: io-thread-running?
|
SYMBOL: io-thread-running?
|
||||||
|
|
||||||
: io-thread ( -- )
|
: io-thread ( -- )
|
||||||
sleep-time io-multiplex yield ;
|
sleep-time io-multiplex yield ;
|
||||||
|
|
||||||
: start-io-thread ( -- )
|
: start-io-thread ( -- )
|
||||||
|
t io-thread-running? set-global
|
||||||
[ [ io-thread-running? get-global ] [ io-thread ] while ]
|
[ [ io-thread-running? get-global ] [ io-thread ] while ]
|
||||||
"I/O wait" spawn drop ;
|
"I/O wait" spawn drop ;
|
||||||
|
|
||||||
: stop-io-thread ( -- )
|
: stop-io-thread ( -- )
|
||||||
f io-thread-running? set-global ;
|
f io-thread-running? set-global ;
|
||||||
|
|
||||||
[
|
[ start-io-thread ] "io.thread" add-startup-hook
|
||||||
t io-thread-running? set-global
|
|
||||||
start-io-thread
|
|
||||||
] "io.thread" add-startup-hook
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
! Copyright (C) 2010 Anton Gorenko, Philipp Brüschweiler.
|
! Copyright (C) 2010, 2011 Anton Gorenko, Philipp Brüschweiler.
|
||||||
! 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.accessors alien.c-types alien.data
|
||||||
alien.strings arrays assocs classes.struct command-line destructors
|
alien.strings arrays assocs classes.struct command-line continuations
|
||||||
gdk.ffi gdk.gl.ffi glib.ffi gobject-introspection.standard-types
|
destructors gdk.ffi gdk.gl.ffi glib.ffi
|
||||||
gobject.ffi gtk.ffi gtk.gl.ffi io.encodings.utf8 kernel libc literals
|
gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi
|
||||||
locals math math.bitwise math.order math.vectors namespaces sequences
|
io.encodings.utf8 kernel libc literals locals math math.bitwise
|
||||||
strings system threads ui ui.backend ui.backend.gtk.input-methods
|
math.order math.vectors namespaces sequences strings system threads ui
|
||||||
ui.backend.gtk.io ui.clipboards ui.event-loop ui.gadgets
|
ui.backend ui.backend.gtk.input-methods ui.backend.gtk.io
|
||||||
ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats
|
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 ;
|
ui.pixel-formats.private ui.private vocabs.loader ;
|
||||||
IN: ui.backend.gtk
|
IN: ui.backend.gtk
|
||||||
|
|
||||||
|
@ -51,33 +52,38 @@ M: gtk-clipboard set-clipboard-contents
|
||||||
gtk_clipboard_get <gtk-clipboard> swap set-global
|
gtk_clipboard_get <gtk-clipboard> swap set-global
|
||||||
] 2bi@ ;
|
] 2bi@ ;
|
||||||
|
|
||||||
! Timeouts
|
! Timer
|
||||||
|
|
||||||
SYMBOL: next-timeout
|
SYMBOL: next-fire-time
|
||||||
|
|
||||||
: set-timeout*-value ( alien value -- )
|
: set-timeout*-value ( alien value -- )
|
||||||
swap 0 set-alien-signed-4 ; inline
|
swap 0 set-alien-signed-4 ; inline
|
||||||
|
|
||||||
: timeout-prepare ( source timeout* -- ? )
|
: timer-prepare ( source timeout* -- ? )
|
||||||
nip next-timeout get-global nano-count [-]
|
nip next-fire-time get-global nano-count [-]
|
||||||
[ 1,000,000 /i set-timeout*-value ] keep 0 = ;
|
[ 1,000,000 /i set-timeout*-value ] keep 0 = ;
|
||||||
|
|
||||||
: timeout-check ( source -- ? )
|
: timer-check ( source -- ? )
|
||||||
drop next-timeout get-global nano-count [-] 0 = ;
|
drop next-fire-time get-global nano-count [-] 0 = ;
|
||||||
|
|
||||||
: timeout-dispatch ( source callback user_data -- ? )
|
: timer-dispatch ( source callback user_data -- ? )
|
||||||
3drop sleep-time [ 1,000,000,000 ] unless* nano-count +
|
3drop sleep-time [ 1,000,000,000 ] unless* nano-count +
|
||||||
next-timeout set-global
|
next-fire-time set-global
|
||||||
yield t ;
|
yield t ;
|
||||||
|
|
||||||
: init-timeout ( -- )
|
: <timer-funcs> ( -- timer-funcs )
|
||||||
GSourceFuncs malloc-struct &free
|
GSourceFuncs malloc-struct
|
||||||
[ timeout-prepare ] GSourceFuncsPrepareFunc >>prepare
|
[ timer-prepare ] GSourceFuncsPrepareFunc >>prepare
|
||||||
[ timeout-check ] GSourceFuncsCheckFunc >>check
|
[ timer-check ] GSourceFuncsCheckFunc >>check
|
||||||
[ timeout-dispatch ] GSourceFuncsDispatchFunc >>dispatch
|
[ timer-dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
|
||||||
GSource heap-size g_source_new &g_source_unref
|
|
||||||
f g_source_attach drop
|
:: with-timer ( quot -- )
|
||||||
nano-count next-timeout set-global ;
|
nano-count next-fire-time set-global
|
||||||
|
<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
|
||||||
|
|
||||||
|
@ -488,9 +494,7 @@ M: gtk-ui-backend (with-ui)
|
||||||
init-clipboard
|
init-clipboard
|
||||||
start-ui
|
start-ui
|
||||||
[
|
[
|
||||||
init-io-event-source
|
[ [ gtk_main ] with-timer ] with-event-loop
|
||||||
init-timeout
|
|
||||||
gtk_main
|
|
||||||
] with-destructors
|
] with-destructors
|
||||||
] ui-running ;
|
] ui-running ;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
USING: io.backend kernel ;
|
USING: io.backend kernel ;
|
||||||
IN: ui.backend.gtk.io
|
IN: ui.backend.gtk.io
|
||||||
|
|
||||||
HOOK: init-io-event-source io-backend ( -- )
|
HOOK: with-event-loop io-backend ( quot -- )
|
||||||
|
|
||||||
M: object init-io-event-source ;
|
M: object with-event-loop call( -- ) ;
|
|
@ -1,8 +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.c-types classes.struct glib.ffi
|
USING: accessors alien.c-types classes.struct continuations
|
||||||
io.backend.unix.multiplexers io.thread kernel libc literals namespaces
|
glib.ffi io.backend.unix.multiplexers io.thread kernel libc
|
||||||
system threads ui.backend.gtk.io ;
|
literals locals namespaces system threads ui.backend.gtk.io ;
|
||||||
IN: ui.backend.gtk.io.unix
|
IN: ui.backend.gtk.io.unix
|
||||||
|
|
||||||
: prepare ( source timeout -- ? )
|
: prepare ( source timeout -- ? )
|
||||||
|
@ -17,6 +17,12 @@ IN: ui.backend.gtk.io.unix
|
||||||
0 mx get wait-for-events
|
0 mx get wait-for-events
|
||||||
yield t ;
|
yield t ;
|
||||||
|
|
||||||
|
: <funcs> ( -- funcs )
|
||||||
|
GSourceFuncs malloc-struct
|
||||||
|
[ prepare ] GSourceFuncsPrepareFunc >>prepare
|
||||||
|
[ check ] GSourceFuncsCheckFunc >>check
|
||||||
|
[ dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
|
||||||
|
|
||||||
CONSTANT: poll-fd-events
|
CONSTANT: poll-fd-events
|
||||||
flags{
|
flags{
|
||||||
G_IO_IN
|
G_IO_IN
|
||||||
|
@ -32,12 +38,14 @@ CONSTANT: poll-fd-events
|
||||||
mx get fd>> >>fd
|
mx get fd>> >>fd
|
||||||
poll-fd-events >>events ;
|
poll-fd-events >>events ;
|
||||||
|
|
||||||
M: unix init-io-event-source
|
M:: unix with-event-loop ( quot -- )
|
||||||
stop-io-thread
|
stop-io-thread
|
||||||
GSourceFuncs malloc-struct &free
|
<funcs> &free
|
||||||
[ prepare ] GSourceFuncsPrepareFunc >>prepare
|
GSource heap-size g_source_new &g_source_unref :> source
|
||||||
[ check ] GSourceFuncsCheckFunc >>check
|
source <poll-fd> g_source_add_poll
|
||||||
[ dispatch ] GSourceFuncsDispatchFunc >>dispatch
|
source f g_source_attach drop
|
||||||
GSource heap-size g_source_new &g_source_unref
|
[ quot call( -- ) ]
|
||||||
[ <poll-fd> g_source_add_poll ]
|
[
|
||||||
[ f g_source_attach drop ] bi ;
|
source g_source_destroy
|
||||||
|
start-io-thread
|
||||||
|
] [ ] cleanup ;
|
||||||
|
|
Loading…
Reference in New Issue