Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

Input Functions

Input functions are handled on the GDK level. They are invoked when a given file descriptor is ready for reading or writing. They're especially useful for networked applications.

To add an input function, you specify the file descriptor to monitor, the state you want to wait for (ready for reading or writing), and a callback/data pair. Figure 32 shows the API. Functions can be removed using the tag returned by gdk_input_add(). Unlike quit, timeout, and idle functions, it should be safe to call gdk_input_remove() from inside the input function; GTK+ will not be in the midst of iterating over the list of input functions.

To specify the condition(s) to wait for, use the GdkInputCondition flags: GDK_INPUT_READ, GDK_INPUT_WRITE, and GDK_INPUT_EXCEPTION. You can OR one or more flags together. These correspond to the three file descriptor sets passed to the select() system call; consult a good UNIX programming book for details. If any condition is met, the input function is invoked.

The callback should look like this:


typedef void (*GdkInputFunction) (gpointer data,
                                  gint source_fd,
                                  GdkInputCondition condition);

It receives your callback data, the file descriptor being watched, and the conditions that were met (possibly a subset of those you were watching for).

#include <gdk/gdk.h>

gint gdk_input_add(gint source_fd, GdkInputCondition condition, GdkInputFunction function, gpointer data);

void gdk_input_remove(gint tag);

Figure 32. Input Functions

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire