Contexts

LibInput

class libinput.LibInput(context_type=<ContextType.PATH: 1>, debug=False)

A base/factory class for libinput context.

Context is used to manage devices and get events.

__init__(context_type=<ContextType.PATH: 1>, debug=False)

Initialize context.

Parameters:
  • context_type (ContextType) – If UDEV devices are added/removed from udev seat. If PATH devices have to be added/removed manually.
  • debug (bool) – If false, only errors are printed.
log_handler

Callable that handles error/info/debug messages.

Parameters:
  • priority (LogPriority) – Message priority.
  • message (str) – The message.

Default handler prints messages to stdout.

suspend()

Suspend monitoring for new devices and close existing devices.

This all but terminates libinput but does keep the context valid to be resumed with resume().

resume()

Resume a suspended libinput context.

This re-enables device monitoring and adds existing devices.

events

Yield events from the internal libinput’s queue.

Yields device events that are subclasses of Event.

Yields:Event – Device event.
next_event_type()

Return the type of the next event in the internal queue.

This method does not pop the event off the queue and the next call to events returns that event.

Returns:The event type of the next available event or None if no event is available.
Return type:EventType

LibInputPath

class libinput.LibInputPath(*args, **kwargs)

libinput path context.

For a context of this type, devices have to be added/removed manually with add_device() and remove_device() respectively.

Note

Do not instanciate this class directly, instead call LibInput with context_type PATH.

add_device(path)

Add a device to a libinput context.

If successful, the device will be added to the internal list and re-opened on resume(). The device can be removed with remove_device(). If the device was successfully initialized, it is returned.

Parameters:path (str) – Path to an input device.
Returns:A device object or None.
Return type:Device
remove_device(device)

Remove a device from a libinput context.

Events already processed from this input device are kept in the queue, the DEVICE_REMOVED event marks the end of events for this device.

If no matching device exists, this method does nothing.

Parameters:Device (Device) – A previously added device.

LibInputUdev

class libinput.LibInputUdev(*args, **kwargs)

libinput udev context.

For a context of this type, devices are added/removed automatically from the assigned seat.

Note

Do not instanciate this class directly, instead call LibInput with context_type UDEV.

assign_seat(seat)

Assign a seat to this libinput context.

New devices or the removal of existing devices will appear as events when iterating over get_event().

assign_seat() succeeds even if no input devices are currently available on this seat, or if devices are available but fail to open. Devices that do not have the minimum capabilities to be recognized as pointer, keyboard or touch device are ignored. Such devices and those that failed to open are ignored until the next call to resume().

Warning

This method may only be called once per context.

Parameters:seat (str) – A seat identifier.