Contexts¶
LibInput¶
-
class
libinput.
LibInput
(context_type=<ContextType.PATH: 1>, grab=False, debug=False)¶ A base/factory class for libinput context.
Context is used to manage devices and get events.
-
__init__
(context_type=<ContextType.PATH: 1>, grab=False, debug=False)¶ Initialize context.
Parameters:
-
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.
Warning
Resuming udev context before assigning seat causes segfault.
-
get_event
(timeout=None)¶ Yield events from the internal libinput’s queue.
Yields device events that are subclasses of
Event
.If timeout is positive number, the generator will only block for timeout seconds when there are no events. If timeout is
None
(default) the generator will block indefinitely.Parameters: timeout (float) – Seconds to block when there are no events. Yields: Event
– A generic 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
get_event()
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()
andremove_device()
respectively.-
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 withremove_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.
-
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 toresume()
.Warning
This method may only be called once per context.
Parameters: seat (str) – A seat identifier.
-