Input Devices

Name

Input Devices -- Functions for handling extended input devices.

Synopsis


#include <gdk/gdk.h>


#define     GDK_CORE_POINTER
GList*      gdk_input_list_devices          (void);
struct      GdkDeviceInfo;
struct      GdkDeviceKey;
void        gdk_input_set_extension_events  (GdkWindow *window,
                                             gint mask,
                                             GdkExtensionMode mode);
enum        GdkExtensionMode;
void        gdk_input_set_source            (guint32 deviceid,
                                             GdkInputSource source);
enum        GdkInputSource;
gint        gdk_input_set_mode              (guint32 deviceid,
                                             GdkInputMode mode);
enum        GdkInputMode;
void        gdk_input_set_axes              (guint32 deviceid,
                                             GdkAxisUse *axes);
enum        GdkAxisUse;
void        gdk_input_set_key               (guint32 deviceid,
                                             guint index,
                                             guint keyval,
                                             GdkModifierType modifiers);
void        gdk_input_window_get_pointer    (GdkWindow *window,
                                             guint32 deviceid,
                                             gdouble *x,
                                             gdouble *y,
                                             gdouble *pressure,
                                             gdouble *xtilt,
                                             gdouble *ytilt,
                                             GdkModifierType *mask);
GdkTimeCoord* gdk_input_motion_events       (GdkWindow *window,
                                             guint32 deviceid,
                                             guint32 start,
                                             guint32 stop,
                                             gint *nevents_return);
struct      GdkTimeCoord;

Description

In addition to the normal keyboard and mouse input devices, GTK+ also contains support for extended input devices. In particular, this support is targeted at graphics tablets. Graphics tablets typically return sub-pixel positioning information and possibly information about the pressure and tilt of the stylus. Under X, the support for extended devices is done through the XInput extension.

Because handling extended input devices may involve considerable overhead, they need to be turned on for each GdkWindow individually using gdk_input_set_extension_events(). (Or, more typically, for GtkWidgets, using gtk_widget_set_extension_events()). As an additional complication, depending on the support from the windowing system, its possible that a normal mouse cursor will not be displayed for a particular extension device. If an application does not want to deal with displaying a cursor itself, it can ask only to get extension events from devices that will display a cursor, by passing the GDK_EXTENSION_EVENTS_CURSOR value to gdk_input_set_extension_events(). Otherwise, the application must retrieve the device information using gdk_input_list_devices(), check the has_cursor field, and, if it is FALSE, draw a cursor itself when it receives motion events.

Each pointing device is assigned a unique integer ID; events from a particular device can be identified by the deviceid field in the event structure. The events generated by pointer devices have also been extended to contain pressure, xtilt and ytilt fields which contain the extended information reported as additional valuators from the device. The pressure field is a a double value ranging from 0.0 to 1.0, while the tilt fields are double values ranging from -1.0 to 1.0. (With -1.0 representing the maximum title to the left or up, and 1.0 representing the maximum tilt to the right or down.)

One additional field in each event is the source field, which contains an enumeration value describing the type of device; this currently can be one of GDK_SOURCE_MOUSE, GDK_SOURCE_PEN, GDK_SOURCE_ERASER, or GDK_SOURCE_CURSOR. This field is present to allow simple applications to (for instance) delete when they detect eraser devices without having to keep track of complicated per-device settings.

Various aspects of each device may be configured. The easiest way of creating a GUI to allow the user to conifigure such a device is to use to use the GtkInputDialog widget in GTK+. However, even when using this widget, application writers will need to directly query and set the configuration parameters in order to save the state between invocations of the application. The configuration of devices is queried using gdk_input_list_devices. Each device must is activated using gdk_input_set_mode(), which also controls whether the device's range is mapped to the entire screen or to a single window. The mapping of the valuators of the device onto the predefined valuator types is set using gdk_input_set_axes. And the source type for each device can be set with gdk_input_set_source().

Devices may also have associated keys or macro buttons. Such keys can be globally set to map into normal X keyboard events. The mapping is set using gdk_input_set_key().

The interfaces in this section will most likely be considerably modified in the future to accomodate devices that may have different sets of additional valuators than the pressure xtilt and ytilt.

Details

GDK_CORE_POINTER

#define GDK_CORE_POINTER 0xfedc

This macro contains an integer value representing the device ID for the core pointer device.


gdk_input_list_devices ()

GList*      gdk_input_list_devices          (void);

Lists all available input devices, along with their configuration information.

Returns :A GList of GdkDeviceInfo structures. This list is internal data of GTK+ and should not be modified or freed.


struct GdkDeviceInfo

struct GdkDeviceInfo
{
  guint32 deviceid;
  gchar *name;
  GdkInputSource source;
  GdkInputMode mode;
  gint has_cursor;	/* TRUE if the X pointer follows device motion */
  gint num_axes;
  GdkAxisUse *axes;    /* Specifies use for each axis */
  gint num_keys;
  GdkDeviceKey *keys;
};

The GdkDeviceInfo structure contains information about a device. It has the following fields:

guint32 deviceida unique integer ID for this device.
gchar *namethe human-readable name for the device.
GdkInputSource sourcethe type of device.
GdkInputMode modea value indicating whether the device is enabled and how the device coordinates map to the screen.
gint has_cursorif TRUE, a cursor will be displayed indicating the current on-screen location to the user. Otherwise, the application is responsible for drawing a cursor itself.
gint num_axesthe number of axes for this device.
GdkAxisUse *axesa pointer to an array of GdkAxisUse values which give the mapping of axes onto the possible valuators for a GDK device.
gint num_keysthe number of macro buttons.
GdkDeviceKey *keysa pointer to an array of GdkDeviceKey structures which describe what key press events are generated for each macro button.


struct GdkDeviceKey

struct GdkDeviceKey
{
  guint keyval;
  GdkModifierType modifiers;
};

The GdkDeviceKey structure contains information about the mapping of one device macro button onto a normal X key event. It has the following fields:

guint keyvalthe keyval to generate when the macro button is pressed. If this is 0, no keypress will be generated.
GdkModifierType modifiersthe modifiers set for the generated key event.


gdk_input_set_extension_events ()

void        gdk_input_set_extension_events  (GdkWindow *window,
                                             gint mask,
                                             GdkExtensionMode mode);

Turns extension events on or off for a particular window, and specifies the event mask for extension events.

window :a GdkWindow.
mask :the event mask
mode :the type of extension events that are desired.


enum GdkExtensionMode

typedef enum
{
  GDK_EXTENSION_EVENTS_NONE,
  GDK_EXTENSION_EVENTS_ALL,
  GDK_EXTENSION_EVENTS_CURSOR
} GdkExtensionMode;

An enumeration used to specify which extension events are desired for a particular widget.

GDK_EXTENSION_EVENTS_NONEno extension events are desired.
GDK_EXTENSION_EVENTS_ALLall extension events are desired.
GDK_EXTENSION_EVENTS_CURSORextension events are desired only if a cursor will be displayed for the device.


gdk_input_set_source ()

void        gdk_input_set_source            (guint32 deviceid,
                                             GdkInputSource source);

Sets the source type for a device.

deviceid :the device to configure
source :the new source type.


enum GdkInputSource

typedef enum
{
  GDK_SOURCE_MOUSE,
  GDK_SOURCE_PEN,
  GDK_SOURCE_ERASER,
  GDK_SOURCE_CURSOR
} GdkInputSource;

An enumeration describing the type of an input device in general terms.

GDK_SOURCE_MOUSEthe device is a mouse. (This will be reported for the core pointer, even if it is something else, such as a trackball.)
GDK_SOURCE_PENthe device is a stylus of a graphics tablet or similar device.
GDK_SOURCE_ERASERthe device is an eraser. Typically, this would be the other end of a stylus on a graphics tablet.
GDK_SOURCE_CURSORthe device is a graphics tablet "puck" or similar device.


gdk_input_set_mode ()

gint        gdk_input_set_mode              (guint32 deviceid,
                                             GdkInputMode mode);

Enables or disables a device, and determines how the device maps onto the screen.

deviceid :the device to configure.
mode :the new mode.
Returns :TRUE if the device supports the given mode, otherwise FALSE and the device's mode is unchanged.


enum GdkInputMode

typedef enum
{
  GDK_MODE_DISABLED,
  GDK_MODE_SCREEN,
  GDK_MODE_WINDOW
} GdkInputMode;

An enumeration that describes the mode of an input device.

GDK_MODE_DISABLEDthe device is disabled and will not report any events.
GDK_MODE_SCREENthe device is enabled. The device's coordinate space maps to the entire screen.
GDK_MODE_WINDOWthe device is enabled. The device's coordinate space is mapped to a single window. The manner in which this window is chosen is undefined, but it will typically be the same way in which the focus window for key events is determined.


gdk_input_set_axes ()

void        gdk_input_set_axes              (guint32 deviceid,
                                             GdkAxisUse *axes);

Sets the mapping of the axes (valuators) of a device onto the predefined valuator types that GTK+ understands.

deviceid :the device to configure.
axes :an array of GdkAxisUse. This length of this array must match the number of axes for the device.


enum GdkAxisUse

typedef enum
{
  GDK_AXIS_IGNORE,
  GDK_AXIS_X,
  GDK_AXIS_Y,
  GDK_AXIS_PRESSURE,
  GDK_AXIS_XTILT,
  GDK_AXIS_YTILT,
  GDK_AXIS_LAST
} GdkAxisUse;

An enumeration describing the way in which a device axis (valuator) maps onto the predefined valuator types that GTK+ understands.

GDK_AXIS_IGNOREthe axis is ignored.
GDK_AXIS_Xthe axis is used as the x axis.
GDK_AXIS_Ythe axis is used as the y axis.
GDK_AXIS_PRESSUREthe axis is used for pressure information.
GDK_AXIS_XTILTthe axis is used for x tilt information.
GDK_AXIS_YTILTthe axis is used for x tilt information.
GDK_AXIS_LASTa constant equal to the numerically highest axis value.


gdk_input_set_key ()

void        gdk_input_set_key               (guint32 deviceid,
                                             guint index,
                                             guint keyval,
                                             GdkModifierType modifiers);

Sets the key event generated when a macro button is pressed.

deviceid :the device to configure.
index :the index of the macro button.
keyval :the key value for the GdkKeypressEvent to generate. (a value of 0 means no event will be generated.)
modifiers :the modifier field for the generated GdkKeyPressEvent.


gdk_input_window_get_pointer ()

void        gdk_input_window_get_pointer    (GdkWindow *window,
                                             guint32 deviceid,
                                             gdouble *x,
                                             gdouble *y,
                                             gdouble *pressure,
                                             gdouble *xtilt,
                                             gdouble *ytilt,
                                             GdkModifierType *mask);

Returns information about the current position of the pointer within a window, including extended device information. Any of the return parameters may be NULL, in which case, they will be ignored.

window :a GdkWindow.
deviceid :a device ID.
x :location to store current x postion.
y :location to store current y postion.
pressure :location to store current pressure.
xtilt :location to store current tilt in the x direction.
ytilt :location to store current tilt in the y direction.
mask :location to store the current modifier state.


gdk_input_motion_events ()

GdkTimeCoord* gdk_input_motion_events       (GdkWindow *window,
                                             guint32 deviceid,
                                             guint32 start,
                                             guint32 stop,
                                             gint *nevents_return);

Retrieves the motion history for a given device/window pair.

window :a GdkWindow.
deviceid :the device for which to retrieve motion history.
start :the start time.
stop :the stop time.
nevents_return :location to store the number of events returned.
Returns :a newly allocated array containing all the events from start to stop. This array should be freed with g_free() when you are finished using it.


struct GdkTimeCoord

struct GdkTimeCoord
{
  guint32 time;
  gdouble x;
  gdouble y;
  gdouble pressure;
  gdouble xtilt;
  gdouble ytilt;
};

The GdkTimeCoord structure stores a single event in a motion history. It contains the following fields:

guint32 timeThe timestamp for this event.
gdouble xthe x position.
gdouble ythe y position.
gdouble pressurethe pressure.
gdouble xtiltthe tilt in the x direction.
gdouble ytiltthe tilt in the y direction.