## Input Devices

Input Devices — Functions for handling extended input devices

## Functions

GList * | gdk_devices_list ()
const gchar * | gdk_device_get_name ()
void | gdk_device_set_source ()
GdkInputSource | gdk_device_get_source ()
gboolean | gdk_device_set_mode ()
GdkInputMode | gdk_device_get_mode ()
void | gdk_device_set_key ()
void | gdk_device_get_key ()
void | gdk_device_set_axis_use ()
GdkAxisUse | gdk_device_get_axis_use ()
GdkDevice * | gdk_device_get_core_pointer ()
void | gdk_device_get_state ()
gboolean | gdk_device_get_history ()
void | gdk_device_free_history ()
gboolean | gdk_device_get_axis ()
gint | gdk_device_get_n_axes ()
void | gdk_input_set_extension_events ()

## Types and Values

struct | GdkDevice
enum | GdkInputSource
enum | GdkInputMode
struct | GdkDeviceKey
struct | GdkDeviceAxis
enum | GdkAxisUse
struct | GdkTimeCoord
enum | GdkExtensionMode

## Includes

    #include <gdk/gdk.h>

## 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_devices_list()`, 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 tilt 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 configuration of devices is queried using `gdk_devices_list()`. Each device must be activated using `gdk_device_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_device_set_axis_use()`. And the source type for each device can be set with `gdk_device_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_device_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`.

## Functions

### gdk_devices_list ()

    GList *
    gdk_devices_list (void);

Returns the list of available input devices for the default display. The list is statically allocated and should not be freed.

#### Returns

a list of GdkDevice.

[transfer none][element-type GdkDevice]

### gdk_device_get_name ()

    const gchar *
    gdk_device_get_name (GdkDevice *device);

Determines the name of the device.

#### Parameters

device | a GdkDevice |

#### Returns

a name

Since 2.22

### gdk_device_set_source ()

    void
    gdk_device_set_source (GdkDevice *device,
                           GdkInputSource source);

Sets the source type for an input device.

#### Parameters

device | a GdkDevice. |
source | the source type. |

### gdk_device_get_source ()

    GdkInputSource
    gdk_device_get_source (GdkDevice *device);

Determines the type of the device.

#### Parameters

device | a GdkDevice |

#### Returns

a GdkInputSource

Since 2.22

### gdk_device_set_mode ()

    gboolean
    gdk_device_set_mode (GdkDevice *device,
                         GdkInputMode mode);

Sets a the mode of an input device. The mode controls if the device is active and whether the device's range is mapped to the entire screen or to a single window.

#### Parameters

device | a GdkDevice. |
mode | the input mode. |

#### Returns

`TRUE` if the mode was successfully changed.

### gdk_device_get_mode ()

    GdkInputMode
    gdk_device_get_mode (GdkDevice *device);

Determines the mode of the device.

#### Parameters

device | a GdkDevice |

#### Returns

a GdkInputSource

Since 2.22

### gdk_device_set_key ()

    void
    gdk_device_set_key (GdkDevice *device,
                        guint index_,
                        guint keyval,
                        GdkModifierType modifiers);

Specifies the X key event to generate when a macro button of a device is pressed.

#### Parameters

device | a GdkDevice. |
index_ | the index of the macro button to set. |
keyval | the keyval to generate. |
modifiers | the modifiers to set. |

### gdk_device_get_key ()

    void
    gdk_device_get_key (GdkDevice *device,
                        guint index,
                        guint *keyval,
                        GdkModifierType *modifiers);

If `index` has a valid keyval, this function will fill in `keyval` and `modifiers` with the keyval settings.

#### Parameters

device | a GdkDevice. |
index | the index of the macro button to get. |
keyval | return value for the keyval. |
modifiers | return value for modifiers. |

Since 2.22

### gdk_device_set_axis_use ()

    void
    gdk_device_set_axis_use (GdkDevice *device,
                             guint index_,
                             GdkAxisUse use);

Specifies how an axis of a device is used.

#### Parameters

device | a GdkDevice. |
index_ | the index of the axis. |
use | specifies how the axis is used. |

### gdk_device_get_axis_use ()

    GdkAxisUse
    gdk_device_get_axis_use (GdkDevice *device,
                             guint index);

Returns the axis use for `index` .

#### Parameters

device | a GdkDevice. |
index | the index of the axis. |

#### Returns

a GdkAxisUse specifying how the axis is used.

Since 2.22

### gdk_device_get_core_pointer ()

    GdkDevice *
    gdk_device_get_core_pointer (void);

Returns the core pointer device for the default display.

#### Returns

the core pointer device; this is owned by the display and should not be freed.

### gdk_device_get_state ()

    void
    gdk_device_get_state (GdkDevice *device,
                          GdkWindow *window,
                          gdouble *axes,
                          GdkModifierType *mask);

Gets the current state of a device.

#### Parameters

device | a GdkDevice. |
window | a GdkWindow. |
axes | an array of doubles to store the values of the axes of `device` in, or `NULL`. |
mask | location to store the modifiers, or `NULL`. |

### gdk_device_get_history ()

    gboolean
    gdk_device_get_history (GdkDevice *device,
                            GdkWindow *window,
                            guint32 start,
                            guint32 stop,
                            GdkTimeCoord ***events,
                            gint *n_events);

Obtains the motion history for a device; given a starting and ending timestamp, return all events in the motion history for the device in the given range of time. Some windowing systems do not support motion history, in which case, `FALSE` will be returned. (This is not distinguishable from the case where motion history is supported and no events were found.)

#### Parameters

device | a GdkDevice |
window | the window with respect to which which the event coordinates will be reported |
start | starting timestamp for range of events to return |
stop | ending timestamp for the range of events to return |
events | location to store a newly-allocated array of GdkTimeCoord, or `NULL`. | [array length=n_events][out][transfer none]
n_events | location to store the length of `events` , or `NULL` |

#### Returns

`TRUE` if the windowing system supports motion history and at least one event was found.

### gdk_device_free_history ()

    void
    gdk_device_free_history (GdkTimeCoord **events,
                             gint n_events);

Frees an array of GdkTimeCoord that was returned by `gdk_device_get_history()`.

Frees an array of GdkTimeCoord that was returned by `gdk_device_get_history()`.

#### Parameters

events | an array of GdkTimeCoord. | [inout][transfer none]
n_events | the length of the array. |

### gdk_device_get_axis ()

    gboolean
    gdk_device_get_axis (GdkDevice *device,
                         gdouble *axes,
                         GdkAxisUse use,
                         gdouble *value);

Interprets an array of double as axis values for a given device, and locates the value in the array for a given axis use.

#### Parameters

device | a GdkDevice |
axes | pointer to an array of axes |
use | the use to look for |
value | location to store the found value. |

#### Returns

`TRUE` if the given axis use was found, otherwise `FALSE`

### gdk_device_get_n_axes ()

    gint
    gdk_device_get_n_axes (GdkDevice *device);

Gets the number of axes of a device.

#### Parameters

device | a GdkDevice. |

#### Returns

the number of axes of `device`

Since 2.22

### 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.

#### Parameters

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

## Types and Values

### struct GdkDevice

    struct GdkDevice {
      GObject parent_instance;
      /* All fields are read-only */

      gchar *GSEAL (name);
      GdkInputSource GSEAL (source);
      GdkInputMode GSEAL (mode);
      gboolean GSEAL (has_cursor);   /* TRUE if the X pointer follows device motion */

      gint GSEAL (num_axes);
      GdkDeviceAxis *GSEAL (axes);

      gint GSEAL (num_keys);
      GdkDeviceKey *GSEAL (keys);
    };

A GdkDevice structure contains a detailed description of an extended input device. All fields are read-only; but you can use `gdk_device_set_source()`, `gdk_device_set_mode()`, `gdk_device_set_key()` and `gdk_device_set_axis_use()` to configure various aspects of the device.

#### Members

GObject `parent_instance`; | the parent instance |

### enum GdkInputSource

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

#### Members

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

### enum GdkInputMode

An enumeration that describes the mode of an input device.

#### Members

GDK_MODE_DISABLED | the device is disabled and will not report any events. |
GDK_MODE_SCREEN | the device is enabled. The device's coordinate space maps to the entire screen. |
GDK_MODE_WINDOW | the 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. |

### 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:

#### Members

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

### struct GdkDeviceAxis

    struct GdkDeviceAxis {
      GdkAxisUse use;
      gdouble    min;
      gdouble    max;
    };

The GdkDeviceAxis structure contains information about the range and mapping of a device axis.

#### Members

GdkAxisUse `use`; | specifies how the axis is used. |
gdouble `min`; | the minimal value that will be reported by this axis. |
gdouble `max`; | the maximal value that will be reported by this axis. |

### enum GdkAxisUse

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

#### Members

GDK_AXIS_IGNORE | the axis is ignored. |
GDK_AXIS_X | the axis is used as the x axis. |
GDK_AXIS_Y | the axis is used as the y axis. |
GDK_AXIS_PRESSURE | the axis is used for pressure information. |
GDK_AXIS_XTILT | the axis is used for x tilt information. |
GDK_AXIS_YTILT | the axis is used for x tilt information. |
GDK_AXIS_WHEEL | the axis is used for wheel information. |
GDK_AXIS_LAST | a constant equal to the numerically highest axis value. |

### struct GdkTimeCoord

    struct GdkTimeCoord {
      guint32 time;
      gdouble axes[GDK_MAX_TIMECOORD_AXES];
    };

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

#### Members

guint32 `time`; | The timestamp for this event. |
gdouble `axes`[GDK_MAX_TIMECOORD_AXES]; | the values of the device's axes. |

### enum GdkExtensionMode

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

#### Members

GDK_EXTENSION_EVENTS_NONE | no extension events are desired. |
GDK_EXTENSION_EVENTS_ALL | all extension events are desired. |
GDK_EXTENSION_EVENTS_CURSOR | extension events are desired only if a cursor will be displayed for the device. |