tools/testing/selftests/hid/tests/test_mouse.py

Source file repositories/reference/linux-study-clean/tools/testing/selftests/hid/tests/test_mouse.py

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/hid/tests/test_mouse.py
Extension
.py
Size
46030 bytes
Lines
1048
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/env python3
# SPDX-License-Identifier: GPL-2.0
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com>
# Copyright (c) 2017 Red Hat, Inc.
#

from . import base
import hidtools.hid
from hidtools.util import BusType
import libevdev
import logging
import pytest

logger = logging.getLogger("hidtools.test.mouse")

# workaround https://gitlab.freedesktop.org/libevdev/python-libevdev/issues/6
try:
    libevdev.EV_REL.REL_WHEEL_HI_RES
except AttributeError:
    libevdev.EV_REL.REL_WHEEL_HI_RES = libevdev.EV_REL.REL_0B
    libevdev.EV_REL.REL_HWHEEL_HI_RES = libevdev.EV_REL.REL_0C


class InvalidHIDCommunication(Exception):
    pass


class MouseData(object):
    pass


class BaseMouse(base.UHIDTestDevice):
    def __init__(self, rdesc, name=None, input_info=None):
        assert rdesc is not None
        super().__init__(name, "Mouse", input_info=input_info, rdesc=rdesc)
        self.left = False
        self.right = False
        self.middle = False

    def create_report(self, x, y, buttons=None, wheels=None, reportID=None):
        """
        Return an input report for this device.

        :param x: relative x
        :param y: relative y
        :param buttons: a (l, r, m) tuple of bools for the button states,
            where ``None`` is "leave unchanged"
        :param wheels: a single value for the vertical wheel or a (vertical, horizontal) tuple for
            the two wheels
        :param reportID: the numeric report ID for this report, if needed
        """
        if buttons is not None:
            left, right, middle = buttons
            if left is not None:
                self.left = left
            if right is not None:
                self.right = right
            if middle is not None:
                self.middle = middle
        left = self.left
        right = self.right
        middle = self.middle
        # Note: the BaseMouse doesn't actually have a wheel but the
        # create_report magic only fills in those fields exist, so let's
        # make this generic here.
        wheel, acpan = 0, 0
        if wheels is not None:
            if isinstance(wheels, tuple):

Annotation

Implementation Notes