Skip to content

Gdk.Device

class — extends GObject.Object

Represents an input device, such as a keyboard, mouse or touchpad.

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

Methods

get_active_layout_index

def get_active_layout_index(self) -> int

Retrieves the index of the active layout of the keyboard.

If there is no valid active layout for the GdkDevice, this function will return -1;

This is only relevant for keyboard devices.

get_caps_lock_state

def get_caps_lock_state(self) -> bool

Retrieves whether the Caps Lock modifier of the keyboard is locked.

This is only relevant for keyboard devices.

get_device_tool

def get_device_tool(self) -> DeviceTool | None

Retrieves the current tool for device.

get_direction

def get_direction(self) -> Pango.Direction

Returns the direction of effective layout of the keyboard.

This is only relevant for keyboard devices.

The direction of a layout is the direction of the majority of its symbols. See Pango.unichar_direction.

get_display

def get_display(self) -> Display

Returns the GdkDisplay to which device pertains.

get_has_cursor

def get_has_cursor(self) -> bool

Determines whether the pointer follows device motion.

This is not meaningful for keyboard devices, which don't have a pointer.

get_layout_names

def get_layout_names(self) -> list[str] | None

Retrieves the names of the layouts of the keyboard.

This is only relevant for keyboard devices.

get_modifier_state

def get_modifier_state(self) -> ModifierType

Retrieves the current modifier state of the keyboard.

This is only relevant for keyboard devices.

get_name

def get_name(self) -> str

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

get_num_lock_state

def get_num_lock_state(self) -> bool

Retrieves whether the Num Lock modifier of the keyboard is locked.

This is only relevant for keyboard devices.

get_num_touches

def get_num_touches(self) -> int

Retrieves the number of touch points associated to device.

get_product_id

def get_product_id(self) -> str | None

Returns the product ID of this device.

This ID is retrieved from the device, and does not change. See Device.get_vendor_id for more information.

get_scroll_lock_state

def get_scroll_lock_state(self) -> bool

Retrieves whether the Scroll Lock modifier of the keyboard is locked.

This is only relevant for keyboard devices.

get_seat

def get_seat(self) -> Seat

Returns the GdkSeat the device belongs to.

get_source

def get_source(self) -> InputSource

Determines the type of the device.

get_surface_at_position

def get_surface_at_position(self) -> tuple[Surface | None, float, float]

Obtains the surface underneath device, returning the location of the device in win_x and win_y.

Returns None if the surface tree under device is not known to GDK (for example, belongs to another application).

get_timestamp

def get_timestamp(self) -> int

Returns the timestamp of the last activity for this device.

In practice, this means the timestamp of the last event that was received from the OS for this device. (GTK may occasionally produce events for a device that are not received from the OS, and will not update the timestamp).

get_vendor_id

def get_vendor_id(self) -> str | None

Returns the vendor ID of this device.

This ID is retrieved from the device, and does not change.

This function, together with Device.get_product_id, can be used to eg. compose GSettings paths to store settings for this device.

 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;
 }

has_bidi_layouts

def has_bidi_layouts(self) -> bool

Determines if layouts for both right-to-left and left-to-right languages are in use on the keyboard.

This is only relevant for keyboard devices.

Properties

active_layout_index

active_layout_index: int  # read-only

The index of the keyboard active layout of a GdkDevice.

Will be -1 if there is no valid active layout.

This is only relevant for keyboard devices.

caps_lock_state

caps_lock_state: bool  # read-only

Whether Caps Lock is on.

This is only relevant for keyboard devices.

direction

direction: Pango.Direction | int  # read-only

The direction of the current layout.

This is only relevant for keyboard devices.

display

display: Display  # read/write

The GdkDisplay the GdkDevice pertains to.

has_bidi_layouts

has_bidi_layouts: bool  # read-only

Whether the device has both right-to-left and left-to-right layouts.

This is only relevant for keyboard devices.

has_cursor

has_cursor: bool  # read/write

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

layout_names

layout_names: list[str]  # read-only

The names of the keyboard layouts of a GdkDevice.

This is only relevant for keyboard devices.

modifier_state

modifier_state: ModifierType | int  # read-only

The current modifier state of the device.

This is only relevant for keyboard devices.

n_axes

n_axes: int  # read-only

Number of axes in the device.

name

name: str  # read/write

The device name.

num_lock_state

num_lock_state: bool  # read-only

Whether Num Lock is on.

This is only relevant for keyboard devices.

num_touches

num_touches: int  # read/write

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.

product_id

product_id: str  # read/write

Product ID of this device.

See Device.get_product_id.

scroll_lock_state

scroll_lock_state: bool  # read-only

Whether Scroll Lock is on.

This is only relevant for keyboard devices.

seat

seat: Seat  # read/write

GdkSeat of this device.

source

source: InputSource | int  # read/write

Source type for the device.

tool

tool: DeviceTool  # read-only

The GdkDeviceTool that is currently used with this device.

vendor_id

vendor_id: str  # read/write

Vendor ID of this device.

See Device.get_vendor_id.

Signals

changed

def on_changed(self) -> None: ...

Emitted either when the number of either axes or keys changes.

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.

tool-changed

def on_tool_changed(self, tool: DeviceTool) -> None: ...

Emitted on pen/eraser devices whenever tools enter or leave proximity.