## GdkDevice GdkDevice — Object representing an input device |

## Functions

const char * | gdk_device_get_name ()
const char * | gdk_device_get_vendor_id ()
const char * | gdk_device_get_product_id ()
GdkInputSource | gdk_device_get_source ()
GdkDisplay * | gdk_device_get_display ()
gboolean | gdk_device_get_has_cursor ()
GdkSeat * | gdk_device_get_seat ()
guint | gdk_device_get_num_touches ()
GdkDeviceTool * | gdk_device_get_device_tool ()
gboolean | gdk_device_get_caps_lock_state ()
PangoDirection | gdk_device_get_direction ()
GdkModifierType | gdk_device_get_modifier_state ()
gboolean | gdk_device_get_num_lock_state ()
gboolean | gdk_device_get_scroll_lock_state ()
gboolean | gdk_device_has_bidi_layouts ()
GdkSurface * | gdk_device_get_surface_at_position ()
guint64 | gdk_device_tool_get_serial ()
GdkDeviceToolType | gdk_device_tool_get_tool_type ()
guint64 | gdk_device_tool_get_hardware_id ()
GdkAxisFlags | gdk_device_tool_get_axes ()

## Properties

gboolean | caps-lock-state | Read
PangoDirection | direction | Read
GdkDisplay * | display | Read / Write / Construct Only
gboolean | has-bidi-layouts | Read
gboolean | has-cursor | Read / Write / Construct Only
GdkModifierType | modifier-state | Read
guint | n-axes | Read
char * | name | Read / Write / Construct Only
gboolean | num-lock-state | Read
guint | num-touches | Read / Write / Construct Only
char * | product-id | Read / Write / Construct Only
gboolean | scroll-lock-state | Read
GdkSeat * | seat | Read / Write
GdkInputSource | source | Read / Write / Construct Only
GdkDeviceTool * | tool | Read
char * | vendor-id | Read / Write / Construct Only
GdkAxisFlags | axes | Read / Write / Construct Only
guint64 | hardware-id | Read / Write / Construct Only
guint64 | serial | Read / Write / Construct Only
GdkDeviceToolType | tool-type | Read / Write / Construct Only

## Signals

void | changed | Run Last
void | tool-changed | Run Last

## Types and Values

| GdkDevice
enum | GdkInputSource
enum | GdkAxisUse
enum | GdkAxisFlags
| GdkDeviceTool
enum | GdkDeviceToolType
struct | GdkTimeCoord

## Object Hierarchy

        GObject
        ├── GdkDevice
        ╰── GdkDeviceTool

## Known Derived Interfaces

GdkDevice is required by GdkDevicePad.

## Includes

    #include <gdk/gdk.h>

## Description

The GdkDevice object represents a single input device, such as a keyboard, a mouse, a touchpad, etc.

See the GdkSeat documentation for more information about the various kinds of devices, and their relationships.

## Functions

### gdk_device_get_name ()

    const char *
    gdk_device_get_name (GdkDevice *device);

Determines the name of the device, suitable for showing in a user interface.

#### Parameters

device | a GdkDevice |

#### Returns

a name

### gdk_device_get_vendor_id ()

    const char *
    gdk_device_get_vendor_id (GdkDevice *device);

Returns the vendor ID of this device, or `NULL` if this information couldn't be obtained. This ID is retrieved from the device, and is thus constant for it.

This function, together with `gdk_device_get_product_id()`, can be used to eg. compose GSettings paths to store settings for this device.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    static GSettings *
    get_device_settings (GdkDevice *device)
    {
      const char *vendor, *product;
      GSettings *settings;
      GdkDevice *device;
      char *path;

      vendor = gdk_device_get_vendor_id (device);
      product = gdk_device_get_product_id (device);

      path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
      settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
      g_free (path);

      return settings;
    }

#### Parameters

device | a physical GdkDevice |

#### Returns

the vendor ID, or `NULL`.

[nullable]

### gdk_device_get_product_id ()

    const char *
    gdk_device_get_product_id (GdkDevice *device);

Returns the product ID of this device, or `NULL` if this information couldn't be obtained. This ID is retrieved from the device, and is thus constant for it. See `gdk_device_get_vendor_id()` for more information.

#### Parameters

device | a physical GdkDevice |

#### Returns

the product ID, or `NULL`.

[nullable]

### gdk_device_get_source ()

    GdkInputSource
    gdk_device_get_source (GdkDevice *device);

Determines the type of the device.

#### Parameters

device | a GdkDevice |

#### Returns

a GdkInputSource

### gdk_device_get_display ()

    GdkDisplay *
    gdk_device_get_display (GdkDevice *device);

Returns the GdkDisplay to which `device` pertains.

#### Parameters

device | a GdkDevice |

#### Returns

a GdkDisplay. This memory is owned by GTK, and must not be freed or unreffed.

[transfer none]

### gdk_device_get_has_cursor ()

    gboolean
    gdk_device_get_has_cursor (GdkDevice *device);

Determines whether the pointer follows device motion. This is not meaningful for keyboard devices, which don't have a pointer.

#### Parameters

device | a GdkDevice |

#### Returns

`TRUE` if the pointer follows device motion

### gdk_device_get_seat ()

    GdkSeat *
    gdk_device_get_seat (GdkDevice *device);

Returns the GdkSeat the device belongs to.

#### Parameters

device | A GdkDevice |

#### Returns

a GdkSeat.

[transfer none]

### gdk_device_get_num_touches ()

    guint
    gdk_device_get_num_touches (GdkDevice *device);

Retrieves the number of touch points associated to `device` .

#### Parameters

device | a GdkDevice |

#### Returns

the number of touch points

### gdk_device_get_device_tool ()

    GdkDeviceTool *
    gdk_device_get_device_tool (GdkDevice *device);

Retrieves the GdkDeviceTool associated to `device` .

#### Parameters

device | a GdkDevice |

#### Returns

the GdkDeviceTool.

[transfer none]

### gdk_device_get_caps_lock_state ()

    gboolean
    gdk_device_get_caps_lock_state (GdkDevice *device);

Retrieves whether the Caps Lock modifier of the keyboard is locked, if `device` is a keyboard device.

#### Parameters

device | a GdkDevice |

#### Returns

`TRUE` if Caps Lock is on for `device`

### gdk_device_get_direction ()

    PangoDirection
    gdk_device_get_direction (GdkDevice *device);

Returns the direction of effective layout of the keyboard, if `device` is a keyboard device.

The direction of a layout is the direction of the majority of its symbols. See `pango_unichar_direction()`.

#### Parameters

device | a GdkDevice |

#### Returns

`PANGO_DIRECTION_LTR` or `PANGO_DIRECTION_RTL` if it can determine the direction. `PANGO_DIRECTION_NEUTRAL` otherwise

### gdk_device_get_modifier_state ()

    GdkModifierType
    gdk_device_get_modifier_state (GdkDevice *device);

Retrieves the current modifier state of the keyboard, if `device` is a keyboard device.

#### Parameters

device | a GdkDevice |

#### Returns

the current modifier state

### gdk_device_get_num_lock_state ()

    gboolean
    gdk_device_get_num_lock_state (GdkDevice *device);

Retrieves whether the Num Lock modifier of the keyboard is locked, if `device` is a keyboard device.

#### Parameters

device | a GdkDevice |

#### Returns

`TRUE` if Num Lock is on for `device`

### gdk_device_get_scroll_lock_state ()

    gboolean
    gdk_device_get_scroll_lock_state (GdkDevice *device);

Retrieves whether the Scroll Lock modifier of the keyboard is locked, if `device` is a keyboard device.

#### Parameters

device | a GdkDevice |

#### Returns

`TRUE` if Scroll Lock is on for `device`

### gdk_device_has_bidi_layouts ()

    gboolean
    gdk_device_has_bidi_layouts (GdkDevice *device);

Determines if keyboard layouts for both right-to-left and left-to-right languages are in use on the keyboard, if `device` is a keyboard device.

#### Parameters

device | a GdkDevice |

#### Returns

`TRUE` if there are layouts with both directions, `FALSE` otherwise

### gdk_device_get_surface_at_position ()

    GdkSurface *
    gdk_device_get_surface_at_position (GdkDevice *device,
                                        double *win_x,
                                        double *win_y);

Obtains the surface underneath `device` , returning the location of the device in `win_x` and `win_y` in double precision. Returns `NULL` if the surface tree under `device` is not known to GDK (for example, belongs to another application).

#### Parameters

device | pointer GdkDevice to query info to. |
win_x | return location for the X coordinate of the device location, relative to the surface origin, or `NULL`. | [out][allow-none]
win_y | return location for the Y coordinate of the device location, relative to the surface origin, or `NULL`. | [out][allow-none]

#### Returns

the GdkSurface under the device position, or `NULL`.

[nullable][transfer none]

### gdk_device_tool_get_serial ()

    guint64
    gdk_device_tool_get_serial (GdkDeviceTool *tool);

Gets the serial of this tool, this value can be used to identify a physical tool (eg. a tablet pen) across program executions.

#### Parameters

tool | a GdkDeviceTool |

#### Returns

The serial ID for this tool

### gdk_device_tool_get_tool_type ()

    GdkDeviceToolType
    gdk_device_tool_get_tool_type (GdkDeviceTool *tool);

Gets the GdkDeviceToolType of the tool.

#### Parameters

tool | a GdkDeviceTool |

#### Returns

The physical type for this tool. This can be used to figure out what sort of pen is being used, such as an airbrush or a pencil.

### gdk_device_tool_get_hardware_id ()

    guint64
    gdk_device_tool_get_hardware_id (GdkDeviceTool *tool);

Gets the hardware ID of this tool, or 0 if it's not known. When non-zero, the identificator is unique for the given tool model, meaning that two identical tools will share the same `hardware_id` , but will have different serial numbers (see `gdk_device_tool_get_serial()`).

This is a more concrete (and device specific) method to identify a GdkDeviceTool than `gdk_device_tool_get_tool_type()`, as a tablet may support multiple devices with the same GdkDeviceToolType, but having different hardware identificators.

#### Parameters

tool | a GdkDeviceTool |

#### Returns

The hardware identificator of this tool.

### gdk_device_tool_get_axes ()

    GdkAxisFlags
    gdk_device_tool_get_axes (GdkDeviceTool *tool);

Gets the axes of the tool.

#### Parameters

tool | a GdkDeviceTool |

#### Returns

the axes of `tool`

## Types and Values

### GdkDevice

    typedef struct _GdkDevice GdkDevice;

The GdkDevice struct contains only private fields and should not be accessed directly.

### 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_KEYBOARD | the device is a keyboard. |
GDK_SOURCE_TOUCHSCREEN | the device is a direct-input touch device, such as a touchscreen or tablet |
GDK_SOURCE_TOUCHPAD | the device is an indirect touch device, such as a touchpad |
GDK_SOURCE_TRACKPOINT | the device is a trackpoint |
GDK_SOURCE_TABLET_PAD | the device is a "pad", a collection of buttons, rings and strips found in drawing tablets |

### enum GdkAxisUse

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

Note that the X and Y axes are not really needed; pointer devices report their location via the x/y members of events regardless. Whether X and Y are present as axes depends on the GDK backend.

#### 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_DELTA_X | the axis is used as the scroll x delta |
GDK_AXIS_DELTA_Y | the axis is used as the scroll y delta |
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 y tilt information. |
GDK_AXIS_WHEEL | the axis is used for wheel information. |
GDK_AXIS_DISTANCE | the axis is used for pen/tablet distance information |
GDK_AXIS_ROTATION | the axis is used for pen rotation information |
GDK_AXIS_SLIDER | the axis is used for pen slider information |
GDK_AXIS_LAST | a constant equal to the numerically highest axis value. |

### enum GdkAxisFlags

Flags describing the current capabilities of a device/tool.

#### Members

GDK_AXIS_FLAG_X | X axis is present |
GDK_AXIS_FLAG_Y | Y axis is present |
GDK_AXIS_FLAG_DELTA_X | Scroll X delta axis is present |
GDK_AXIS_FLAG_DELTA_Y | Scroll Y delta axis is present |
GDK_AXIS_FLAG_PRESSURE | Pressure axis is present |
GDK_AXIS_FLAG_XTILT | X tilt axis is present |
GDK_AXIS_FLAG_YTILT | Y tilt axis is present |
GDK_AXIS_FLAG_WHEEL | Wheel axis is present |
GDK_AXIS_FLAG_DISTANCE | Distance axis is present |
GDK_AXIS_FLAG_ROTATION | Z-axis rotation is present |
GDK_AXIS_FLAG_SLIDER | Slider axis is present |

### GdkDeviceTool

    typedef struct _GdkDeviceTool GdkDeviceTool;

### enum GdkDeviceToolType

Indicates the specific type of tool being used being a tablet. Such as an airbrush, pencil, etc.

#### Members

GDK_DEVICE_TOOL_TYPE_UNKNOWN | Tool is of an unknown type. |
GDK_DEVICE_TOOL_TYPE_PEN | Tool is a standard tablet stylus. |
GDK_DEVICE_TOOL_TYPE_ERASER | Tool is standard tablet eraser. |
GDK_DEVICE_TOOL_TYPE_BRUSH | Tool is a brush stylus. |
GDK_DEVICE_TOOL_TYPE_PENCIL | Tool is a pencil stylus. |
GDK_DEVICE_TOOL_TYPE_AIRBRUSH | Tool is an airbrush stylus. |
GDK_DEVICE_TOOL_TYPE_MOUSE | Tool is a mouse. |
GDK_DEVICE_TOOL_TYPE_LENS | Tool is a lens cursor. |

### struct GdkTimeCoord

    struct GdkTimeCoord {
      guint32 time;
      GdkAxisFlags flags;
      double axes[GDK_AXIS_LAST];
    };

A GdkTimeCoord stores a single event in a motion history.

#### Members

guint32 `time`; | The timestamp for this event. |
GdkAxisFlags `flags`; | Flags indicating what axes are present |
double `axes`[GDK_AXIS_LAST]; | axis values |

## Property Details

### The `“caps-lock-state”` property

      “caps-lock-state”          gboolean

Whether the keyboard caps lock is on.

Owner: GdkDevice

Flags: Read

Default value: FALSE

### The `“direction”` property

      “direction”                PangoDirection

The direction of the current layout of the keyboard.

Owner: GdkDevice

Flags: Read

Default value: PANGO_DIRECTION_NEUTRAL

### The `“display”` property

      “display”                  GdkDisplay *

The GdkDisplay the GdkDevice pertains to.

Owner: GdkDevice

Flags: Read / Write / Construct Only

### The `“has-bidi-layouts”` property

      “has-bidi-layouts”         gboolean

Whether the keyboard has bidi layouts.

Owner: GdkDevice

Flags: Read

Default value: FALSE

### The `“has-cursor”` property

      “has-cursor”               gboolean

Whether the device is represented by a cursor on the screen.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: FALSE

### The `“modifier-state”` property

      “modifier-state”           GdkModifierType

The modifier state of the keyboard.

Owner: GdkDevice

Flags: Read

### The `“n-axes”` property

      “n-axes”                   guint

Number of axes in the device.

Owner: GdkDevice

Flags: Read

Default value: 0

### The `“name”` property

      “name”                     char *

The device name.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: NULL

### The `“num-lock-state”` property

      “num-lock-state”           gboolean

Whether the keyboard num lock is on.

Owner: GdkDevice

Flags: Read

Default value: FALSE

### The `“num-touches”` property

      “num-touches”              guint

The maximal number of concurrent touches on a touch device. Will be 0 if the device is not a touch device or if the number of touches is unknown.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: 0

### The `“product-id”` property

      “product-id”               char *

Product ID of this device, see `gdk_device_get_product_id()`.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: NULL

### The `“scroll-lock-state”` property

      “scroll-lock-state”        gboolean

Whether the keyboard scroll lock is on.

Owner: GdkDevice

Flags: Read

Default value: FALSE

### The `“seat”` property

      “seat”                     GdkSeat *

GdkSeat of this device.

Owner: GdkDevice

Flags: Read / Write

### The `“source”` property

      “source”                   GdkInputSource

Source type for the device.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: GDK_SOURCE_MOUSE

### The `“tool”` property

      “tool”                     GdkDeviceTool *

The tool that is currently used with this device.

Owner: GdkDevice

Flags: Read

### The `“vendor-id”` property

      “vendor-id”                char *

Vendor ID of this device, see `gdk_device_get_vendor_id()`.

Owner: GdkDevice

Flags: Read / Write / Construct Only

Default value: NULL

### The `“axes”` property

      “axes”                     GdkAxisFlags

Tool axes.

Owner: GdkDeviceTool

Flags: Read / Write / Construct Only

### The `“hardware-id”` property

      “hardware-id”              guint64

Hardware ID.

Owner: GdkDeviceTool

Flags: Read / Write / Construct Only

Default value: 0

### The `“serial”` property

      “serial”                   guint64

Serial number.

Owner: GdkDeviceTool

Flags: Read / Write / Construct Only

Default value: 0

### The `“tool-type”` property

      “tool-type”                GdkDeviceToolType

Tool type.

Owner: GdkDeviceTool

Flags: Read / Write / Construct Only

Default value: GDK_DEVICE_TOOL_TYPE_UNKNOWN

## Signal Details

### The `“changed”` signal

    void
    user_function (GdkDevice *device,
                   gpointer   user_data)

The ::changed signal is emitted either when the GdkDevice has changed the number of either axes or keys. For example on X11 this will normally happen when the physical device routing events through the logical device changes (for example, user switches from the USB mouse to a tablet); in that case the logical device will change to reflect the axes and keys on the new physical device.

#### Parameters

device | the GdkDevice that changed. |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“tool-changed”` signal

    void
    user_function (GdkDevice     *device,
                   GdkDeviceTool *tool,
                   gpointer       user_data)

The ::tool-changed signal is emitted on pen/eraser GdkDevices whenever tools enter or leave proximity.

#### Parameters

device | the GdkDevice that changed. |
tool | The new current tool |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

## See Also

GdkSeat