Re: [gtk-list] gdk_input_add
- From: Des Herriott <des ops netcom net uk>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] gdk_input_add
- Date: Fri, 8 May 1998 13:52:15 +0100
On May 08, Sascha Ziemann wrote:
> Hi,
>
> Where can I find a description of gdk_input_add:
>
> gint gdk_input_add (gint source,
> GdkInputCondition condition,
> GdkInputFunction function,
> gpointer data);
>
> condition should be GDK_INPUT_READ for example but the rest is not
> clear. Is source the file descriptor? And how about function and data?
(See also http:/www.gtk.org/tutorial/, section 15)
Yep, source is a file descriptor. condition can be a bitmask of one or
more of GDK_INPUT_READ, GDK_INPUT_WRITE, and GDK_INPUT_EXCEPTION.
The function gets called when the descriptor is ready to read, write
or has an exceptional condition pending, and gets called depending on
the condition bitmask. It has this signature:
void handler_func(gpointer data, gint fd, GdkInputCondition cond);
data is a pointer to whatever data you passed to gdk_input_add().
condition is a bitmask of what conditions are true on the file descriptor,
so if you've selected more than one condition you should do something like:
if ((cond & GDK_INPUT_WRITE) == GDK_INPUT_WRITE) {
/* write some data to fd */
} else if ((cond & GDK_INPUT_READ) == GDK_INPUT_READ) {
/* read some data from fd */
}
> I want to play a video stream with 25 or 50 Hz. I think the easiest
> way to do that, is to write a simple timer program that can be used to
> feed Gtk's event loop via gdk_input_add. Or does anybody know a better
> way? Perhaps a way to tell gtk_main_iteration about alarm signals?
I'd avoid using alarm(), or signals in general with X-based applications.
There are too many reentrancy and general reliability issues with signals.
The most you should ever try to do with a signal handler is to set some
global flag which can be checked later as part of the event loop.
(How reentrancy-safe is Gtk? I know some versions of Xlib are safe,
but I don't count on it)
It sounds like you may want to use a timer rather than gdk_input_add() -
gdk_input_add() is best suited for communicating with external processes
where you want to receive data as it comes in. The file descriptor is
most likely to be a pipe or a socket.
--
Des Herriott
des@ops.netcom.net.uk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]