Commit 7a198417 authored by Peter Hutterer's avatar Peter Hutterer

examples: fix the uinput example so it actually does what users expect

The previous one was technically correct, but a device with just EV_REL won't
get tagged by udev as mouse and won't get picked up by anything proper. And
likewise, without a delay before sending the event, the events won't get
picked up by userspace. Change that, so the example moves the pointer a bit
which is what a user would expect.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 0190c912
......@@ -3,6 +3,7 @@
import sys
import libevdev
from libevdev import InputEvent
import time
def main(args):
......@@ -10,14 +11,24 @@ def main(args):
dev.name = "test device"
dev.enable(libevdev.EV_REL.REL_X)
dev.enable(libevdev.EV_REL.REL_Y)
dev.enable(libevdev.EV_KEY.BTN_LEFT)
dev.enable(libevdev.EV_KEY.BTN_RIGHT)
try:
uinput = dev.create_uinput_device()
print("New device at {} ({})".format(uinput.devnode, uinput.syspath))
events = [InputEvent(libevdev.EV_REL.REL_X, -1),
InputEvent(libevdev.EV_REL.REL_Y, 1),
InputEvent(libevdev.EV_SYN.SYN_REPORT, 0)]
uinput.send_events(events)
# Sleep for a bit so udev, libinput, Xorg, Wayland, ... all have had
# a chance to see the device and initialize it. Otherwise the event
# will be sent by the kernel but nothing is ready to listen to the
# device yet.
time.sleep(1)
for _ in range(5):
events = [InputEvent(libevdev.EV_REL.REL_X, -1),
InputEvent(libevdev.EV_REL.REL_Y, 1),
InputEvent(libevdev.EV_SYN.SYN_REPORT, 0)]
time.sleep(0.012)
uinput.send_events(events)
except OSError as e:
print(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment