Skip to content

Commit

Permalink
fallback to True for mouse detection if libinput is missing (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Oct 17, 2022
1 parent 62bed41 commit 700f750
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions ovos_utils/device_input.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import os
import subprocess
from distutils.spawn import find_executable

from ovos_utils.gui import is_gui_installed
from ovos_utils.log import LOG


class InputDeviceHelper:
def __init__(self) -> None:
self.libinput_devices_list = []
self.xinput_devices_list = []
self.dev_input_devices_list = []
if not find_executable("libinput") and not find_executable("xinput"):
LOG.warning("Could not find libinput or xinput, input device detection will be inaccurate")
LOG.warning("Could not find libinput, input device detection will be inaccurate")

# ToDo: add support for discovring the input device based of a connected
# monitors, currently linux only supports input listing directly from the
Expand Down Expand Up @@ -97,30 +95,21 @@ def _get_xinput_devices_list(self):
self._build_xinput_devices_list()
return self.xinput_devices_list

def _build_dev_input_devices_list(self):
# Always clear the list before building it
self.dev_input_devices_list.clear()

# Get the list of devices from naive scanning of /dev/input
for d in os.listdir("/dev/input"):
if d.startswith("mouse") or d.startswith("mice"):
dev = {"Device": d,
"Capabilities": ["mouse"]}
self.dev_input_devices_list.append(dev)

def get_input_device_list(self):
# check if any of the devices support touch or mouse
if find_executable("libinput"):
self._build_linput_devices_list()
if find_executable("xinput"):
self._build_xinput_devices_list()
self._build_dev_input_devices_list()

return self.libinput_devices_list + \
self.xinput_devices_list + \
self.dev_input_devices_list
self.xinput_devices_list

def can_use_touch_mouse(self):
if not find_executable("libinput") and not find_executable("xinput"):
# if gui installed assume we have a mouse
# otherwise let's assume we are a server or something...
return is_gui_installed()
for device in self.get_input_device_list():
if "touch" in device["Capabilities"] or \
"mouse" in device["Capabilities"] or \
Expand Down

0 comments on commit 700f750

Please sign in to comment.