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.
 | 
			
		||||
! 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
 | 
			
		||||
 | 
			
		||||
! The Cocoa UI backend stops the I/O thread and takes over
 | 
			
		||||
! completely.
 | 
			
		||||
! The Cocoa and Gtk UI backend stops the I/O thread and takes
 | 
			
		||||
! over completely.
 | 
			
		||||
SYMBOL: io-thread-running?
 | 
			
		||||
 | 
			
		||||
: io-thread ( -- )
 | 
			
		||||
    sleep-time io-multiplex yield ;
 | 
			
		||||
 | 
			
		||||
: start-io-thread ( -- )
 | 
			
		||||
    t io-thread-running? set-global
 | 
			
		||||
    [ [ io-thread-running? get-global ] [ io-thread ] while ]
 | 
			
		||||
    "I/O wait" spawn drop ;
 | 
			
		||||
 | 
			
		||||
: stop-io-thread ( -- )
 | 
			
		||||
    f io-thread-running? set-global ;
 | 
			
		||||
 | 
			
		||||
[
 | 
			
		||||
    t io-thread-running? set-global
 | 
			
		||||
    start-io-thread
 | 
			
		||||
] "io.thread" add-startup-hook
 | 
			
		||||
[ 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.
 | 
			
		||||
USING: accessors alien.accessors alien.c-types alien.data
 | 
			
		||||
alien.strings arrays assocs classes.struct command-line destructors
 | 
			
		||||
gdk.ffi gdk.gl.ffi glib.ffi gobject-introspection.standard-types
 | 
			
		||||
gobject.ffi gtk.ffi gtk.gl.ffi io.encodings.utf8 kernel libc literals
 | 
			
		||||
locals math math.bitwise math.order 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
 | 
			
		||||
alien.strings arrays assocs classes.struct command-line continuations
 | 
			
		||||
destructors gdk.ffi gdk.gl.ffi glib.ffi
 | 
			
		||||
gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi
 | 
			
		||||
io.encodings.utf8 kernel libc literals locals math math.bitwise
 | 
			
		||||
math.order 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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,33 +52,38 @@ M: gtk-clipboard set-clipboard-contents
 | 
			
		|||
        gtk_clipboard_get <gtk-clipboard> swap set-global
 | 
			
		||||
    ] 2bi@ ;
 | 
			
		||||
 | 
			
		||||
! Timeouts
 | 
			
		||||
! Timer
 | 
			
		||||
 | 
			
		||||
SYMBOL: next-timeout
 | 
			
		||||
SYMBOL: next-fire-time
 | 
			
		||||
 | 
			
		||||
: set-timeout*-value ( alien value -- )
 | 
			
		||||
    swap 0 set-alien-signed-4 ; inline
 | 
			
		||||
 | 
			
		||||
: timeout-prepare ( source timeout* -- ? )
 | 
			
		||||
    nip next-timeout get-global nano-count [-]
 | 
			
		||||
: timer-prepare ( source timeout* -- ? )
 | 
			
		||||
    nip next-fire-time get-global nano-count [-]
 | 
			
		||||
    [ 1,000,000 /i set-timeout*-value ] keep 0 = ;
 | 
			
		||||
 | 
			
		||||
: timeout-check ( source -- ? )
 | 
			
		||||
    drop next-timeout get-global nano-count [-] 0 = ;
 | 
			
		||||
: timer-check ( source -- ? )
 | 
			
		||||
    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 +
 | 
			
		||||
    next-timeout set-global
 | 
			
		||||
    next-fire-time set-global
 | 
			
		||||
    yield t ;
 | 
			
		||||
 | 
			
		||||
: init-timeout ( -- )
 | 
			
		||||
    GSourceFuncs malloc-struct &free
 | 
			
		||||
        [ timeout-prepare ] GSourceFuncsPrepareFunc >>prepare
 | 
			
		||||
        [ timeout-check ] GSourceFuncsCheckFunc >>check
 | 
			
		||||
        [ timeout-dispatch ] GSourceFuncsDispatchFunc >>dispatch
 | 
			
		||||
    GSource heap-size g_source_new &g_source_unref
 | 
			
		||||
    f g_source_attach drop
 | 
			
		||||
    nano-count next-timeout set-global ;
 | 
			
		||||
: <timer-funcs> ( -- timer-funcs )
 | 
			
		||||
    GSourceFuncs malloc-struct
 | 
			
		||||
        [ timer-prepare ] GSourceFuncsPrepareFunc >>prepare
 | 
			
		||||
        [ timer-check ] GSourceFuncsCheckFunc >>check
 | 
			
		||||
        [ timer-dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
 | 
			
		||||
 | 
			
		||||
:: with-timer ( quot -- )
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -488,9 +494,7 @@ M: gtk-ui-backend (with-ui)
 | 
			
		|||
        init-clipboard
 | 
			
		||||
        start-ui
 | 
			
		||||
        [
 | 
			
		||||
            init-io-event-source
 | 
			
		||||
            init-timeout
 | 
			
		||||
            gtk_main
 | 
			
		||||
            [ [ gtk_main ] with-timer ] with-event-loop
 | 
			
		||||
        ] with-destructors
 | 
			
		||||
    ] ui-running ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,6 @@
 | 
			
		|||
USING: io.backend kernel ;
 | 
			
		||||
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.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: accessors alien.c-types classes.struct glib.ffi
 | 
			
		||||
io.backend.unix.multiplexers io.thread kernel libc literals namespaces
 | 
			
		||||
system threads ui.backend.gtk.io ;
 | 
			
		||||
USING: accessors alien.c-types classes.struct continuations
 | 
			
		||||
glib.ffi io.backend.unix.multiplexers io.thread kernel libc
 | 
			
		||||
literals locals namespaces system threads ui.backend.gtk.io ;
 | 
			
		||||
IN: ui.backend.gtk.io.unix
 | 
			
		||||
 | 
			
		||||
: prepare ( source timeout -- ? )
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +17,12 @@ IN: ui.backend.gtk.io.unix
 | 
			
		|||
     0 mx get wait-for-events
 | 
			
		||||
     yield t ;
 | 
			
		||||
 | 
			
		||||
: <funcs> ( -- funcs )
 | 
			
		||||
    GSourceFuncs malloc-struct
 | 
			
		||||
        [ prepare ] GSourceFuncsPrepareFunc >>prepare
 | 
			
		||||
        [ check ] GSourceFuncsCheckFunc >>check
 | 
			
		||||
        [ dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
 | 
			
		||||
 | 
			
		||||
CONSTANT: poll-fd-events
 | 
			
		||||
    flags{
 | 
			
		||||
        G_IO_IN
 | 
			
		||||
| 
						 | 
				
			
			@ -32,12 +38,14 @@ CONSTANT: poll-fd-events
 | 
			
		|||
        mx get fd>> >>fd
 | 
			
		||||
        poll-fd-events >>events ;
 | 
			
		||||
 | 
			
		||||
M: unix init-io-event-source
 | 
			
		||||
M:: unix with-event-loop ( quot -- )
 | 
			
		||||
    stop-io-thread
 | 
			
		||||
    GSourceFuncs malloc-struct &free
 | 
			
		||||
        [ prepare ] GSourceFuncsPrepareFunc >>prepare
 | 
			
		||||
        [ check ] GSourceFuncsCheckFunc >>check
 | 
			
		||||
        [ dispatch ] GSourceFuncsDispatchFunc >>dispatch
 | 
			
		||||
    GSource heap-size g_source_new &g_source_unref
 | 
			
		||||
    [ <poll-fd> g_source_add_poll ]
 | 
			
		||||
    [ f g_source_attach drop ] bi ;
 | 
			
		||||
    <funcs> &free
 | 
			
		||||
    GSource heap-size g_source_new &g_source_unref :> source
 | 
			
		||||
    source <poll-fd> g_source_add_poll
 | 
			
		||||
    source f g_source_attach drop
 | 
			
		||||
    [ quot call( -- ) ]
 | 
			
		||||
    [
 | 
			
		||||
        source g_source_destroy
 | 
			
		||||
        start-io-thread
 | 
			
		||||
    ] [ ] cleanup ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue