From e9515c1a9c9be1005fe1a1ed76eb45695c756279 Mon Sep 17 00:00:00 2001 From: Anton Gorenko Date: Wed, 26 Jan 2011 21:00:35 +0600 Subject: [PATCH] ui.backend.gtk: split off unix io support into ui.backend.gtk.io.unix; --- basis/ui/backend/gtk/gtk.factor | 59 ++++-------------------- basis/ui/backend/gtk/io/authors.txt | 1 + basis/ui/backend/gtk/io/io.factor | 8 ++++ basis/ui/backend/gtk/io/unix/authors.txt | 1 + basis/ui/backend/gtk/io/unix/unix.factor | 43 +++++++++++++++++ 5 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 basis/ui/backend/gtk/io/authors.txt create mode 100644 basis/ui/backend/gtk/io/io.factor create mode 100644 basis/ui/backend/gtk/io/unix/authors.txt create mode 100644 basis/ui/backend/gtk/io/unix/unix.factor diff --git a/basis/ui/backend/gtk/gtk.factor b/basis/ui/backend/gtk/gtk.factor index a5e9a14173..d012de8e18 100644 --- a/basis/ui/backend/gtk/gtk.factor +++ b/basis/ui/backend/gtk/gtk.factor @@ -3,12 +3,12 @@ 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.backend io.backend.unix.multiplexers -io.encodings.utf8 io.thread kernel libc literals locals math -math.bitwise math.order math.vectors namespaces sequences strings -system threads ui ui.backend ui.clipboards ui.event-loop ui.gadgets -ui.gadgets.editors ui.gadgets.private ui.gadgets.worlds ui.gestures -ui.pixel-formats ui.pixel-formats.private ui.private ; +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.io ui.clipboards +ui.event-loop ui.gadgets ui.gadgets.editors ui.gadgets.private +ui.gadgets.worlds ui.gestures ui.pixel-formats +ui.pixel-formats.private ui.private vocabs.loader ; IN: ui.backend.gtk SINGLETON: gtk-ui-backend @@ -51,48 +51,7 @@ M: gtk-clipboard set-clipboard-contents gtk_clipboard_get swap set-global ] 2bi@ ; -! IO events - -: io-source-prepare ( source timeout -- ? ) - 2drop f ; - -: io-source-check ( source -- ? ) - poll_fds>> 0 g_slist_nth_data GPollFD memory>struct - revents>> 0 = not ; - -: io-source-dispatch ( source callback user_data -- ? ) - 3drop - 0 mx get wait-for-events - yield t ; - -CONSTANT: poll-fd-events - flags{ - G_IO_IN - G_IO_OUT - G_IO_PRI - G_IO_ERR - G_IO_HUP - G_IO_NVAL - } - -: create-poll-fd ( -- poll-fd ) - GPollFD malloc-struct &free - mx get fd>> >>fd - poll-fd-events >>events ; - -HOOK: init-io-event-source io-backend ( -- ) - -M: f init-io-event-source ; -M: c-io-backend init-io-event-source ; - -M: object init-io-event-source - GSourceFuncs malloc-struct &free - [ io-source-prepare ] GSourceFuncsPrepareFunc >>prepare - [ io-source-check ] GSourceFuncsCheckFunc >>check - [ io-source-dispatch ] GSourceFuncsDispatchFunc >>dispatch - GSource heap-size g_source_new &g_source_unref - [ create-poll-fd g_source_add_poll ] - [ f g_source_attach drop ] bi ; +! Timeouts SYMBOL: next-timeout @@ -546,7 +505,6 @@ M: gtk-ui-backend (with-ui) 0 gint f void* gtk_gl_init init-clipboard start-ui - stop-io-thread [ init-io-event-source init-timeout @@ -557,4 +515,7 @@ M: gtk-ui-backend (with-ui) gtk-ui-backend ui-backend set-global +{ "ui.backend.gtk" "io.backend.unix" } +"ui.backend.gtk.io.unix" require-when + [ "ui.tools" ] main-vocab-hook set-global diff --git a/basis/ui/backend/gtk/io/authors.txt b/basis/ui/backend/gtk/io/authors.txt new file mode 100644 index 0000000000..4af9fbeb0a --- /dev/null +++ b/basis/ui/backend/gtk/io/authors.txt @@ -0,0 +1 @@ +Anton Gorenko diff --git a/basis/ui/backend/gtk/io/io.factor b/basis/ui/backend/gtk/io/io.factor new file mode 100644 index 0000000000..8288c893cc --- /dev/null +++ b/basis/ui/backend/gtk/io/io.factor @@ -0,0 +1,8 @@ +! Copyright (C) 2011 Anton Gorenko. +! See http://factorcode.org/license.txt for BSD license. +USING: io.backend kernel ; +IN: ui.backend.gtk.io + +HOOK: init-io-event-source io-backend ( -- ) + +M: object init-io-event-source ; \ No newline at end of file diff --git a/basis/ui/backend/gtk/io/unix/authors.txt b/basis/ui/backend/gtk/io/unix/authors.txt new file mode 100644 index 0000000000..4af9fbeb0a --- /dev/null +++ b/basis/ui/backend/gtk/io/unix/authors.txt @@ -0,0 +1 @@ +Anton Gorenko diff --git a/basis/ui/backend/gtk/io/unix/unix.factor b/basis/ui/backend/gtk/io/unix/unix.factor new file mode 100644 index 0000000000..50a1059678 --- /dev/null +++ b/basis/ui/backend/gtk/io/unix/unix.factor @@ -0,0 +1,43 @@ +! 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 ; +IN: ui.backend.gtk.io.unix + +: prepare ( source timeout -- ? ) + 2drop f ; + +: check ( source -- ? ) + poll_fds>> 0 g_slist_nth_data GPollFD memory>struct + revents>> 0 = not ; + +: dispatch ( source callback user-data -- ? ) + 3drop + 0 mx get wait-for-events + yield t ; + +CONSTANT: poll-fd-events + flags{ + G_IO_IN + G_IO_OUT + G_IO_PRI + G_IO_ERR + G_IO_HUP + G_IO_NVAL + } + +: ( -- poll-fd ) + GPollFD malloc-struct &free + mx get fd>> >>fd + poll-fd-events >>events ; + +M: unix init-io-event-source + 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 + [ g_source_add_poll ] + [ f g_source_attach drop ] bi ;