]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.backend.gtk: fix a bug with endless error messages in a console after closing...
authorAnton Gorenko <ex.rzrjck@gmail.com>
Fri, 1 Apr 2011 16:06:07 +0000 (22:06 +0600)
committerAnton Gorenko <ex.rzrjck@gmail.com>
Fri, 1 Apr 2011 16:06:07 +0000 (22:06 +0600)
io.thread: start-io-thread always starts io-thread even if it was stopped, fix line endings;

basis/io/thread/thread.factor
basis/ui/backend/gtk/gtk.factor
basis/ui/backend/gtk/io/io.factor
basis/ui/backend/gtk/io/unix/unix.factor

index 519dec3567715f92588c4a9267bd1c48abb4c736..75eb46791a9c8f5fe986c62bc069abc9453e521a 100644 (file)
@@ -1,23 +1,21 @@
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: threads io.backend namespaces init math kernel ;\r
-IN: io.thread\r
-\r
-! The Cocoa UI backend stops the I/O thread and takes over\r
-! completely.\r
-SYMBOL: io-thread-running?\r
-\r
-: io-thread ( -- )\r
-    sleep-time io-multiplex yield ;\r
-\r
-: start-io-thread ( -- )\r
-    [ [ io-thread-running? get-global ] [ io-thread ] while ]\r
-    "I/O wait" spawn drop ;\r
-\r
-: stop-io-thread ( -- )\r
-    f io-thread-running? set-global ;\r
-\r
-[\r
-    t io-thread-running? set-global\r
-    start-io-thread\r
-] "io.thread" add-startup-hook\r
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: init io.backend kernel namespaces threads ;
+IN: io.thread
+
+! 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 ;
+
+[ start-io-thread ] "io.thread" add-startup-hook
index 378a2b56c283dad08aa2b042ef7261d3a0dec03a..5f219ec20c8c7b2084a7950fcd28cc56000a15fa 100644 (file)
@@ -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 ;
 
index 8288c893ccd192870578196eedbb7579f89a311e..c2284a3d135a4f44940065aa5a8bcaeff030bf1c 100644 (file)
@@ -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 ;
\ No newline at end of file
+M: object with-event-loop call( -- ) ;
\ No newline at end of file
index 50a1059678941e99f760aaf97085c6d492e95665..56a38d5bf1ff0ebb25ce3043132b7b010affd846 100644 (file)
@@ -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 ;