pax_global_header00006660000000000000000000000064147726515570014535gustar00rootroot0000000000000052 comment=4f7b4ef0e4eb5d569df36be387579858eba349bb libinput-1.28.1/000077500000000000000000000000001477265155700134545ustar00rootroot00000000000000libinput-1.28.1/.dir-locals.el000066400000000000000000000001731477265155700161060ustar00rootroot00000000000000((nil . ((indent-tabs-mode . t) (tab-width . 8) (fill-column . 80))) (c-mode . ((c-basic-offset . 8)))) libinput-1.28.1/.editorconfig000066400000000000000000000005301477265155700161270ustar00rootroot00000000000000# https://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true [*.{c,h}] indent_size = 8 indent_style = tab [*.py] indent_size = 4 indent_style = space [{meson.build,meson_options.txt}] indent_size = 8 indent_style = tab [*.sym] indent_size = 8 indent_style = tab libinput-1.28.1/.gitignore000066400000000000000000000001231477265155700154400ustar00rootroot00000000000000*.swp *~ *.sig *.tar.* *.announce *.patch *.rej *.trs *.gcda *.gcno tags *.gnuplot libinput-1.28.1/.gitlab-ci.yml000066400000000000000000001032021477265155700161060ustar00rootroot00000000000000# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0 filetype=yaml: ######################################## # # # THIS FILE IS GENERATED, DO NOT EDIT # # # ######################################## # To change the gitlab CI, edit .gitlab-ci/ci.template and/or .gitlab-ci/config.yaml # and run ci-fairy generate-template. For details, see # https://freedesktop.pages.freedesktop.org/ci-templates/ci-fairy.html#templating-gitlab-ci-yml # This is a bit complicated for two reasons: # - we really want to run dnf/apt/... only once, updating on the test runner for # each job takes forever. So we create a container image for each distribution # tested, then run the tests on this container image. # # This is handled by the ci-templates, ensuring containers are only rebuilt # when the TAG changes. # # - GitLab only allows one script: set per job but we have a bunch of commands # we need to re-run for each build (meson && ninja && etc). YAML cannot merge # arrays so we're screwed. # # So instead we use a default_build template and override everything with # variables. The only two variables that matter: # MESON_ARGS=-Denable-something=true # NINJA_ARGS=dist ... to run 'ninja -C builddir dist' # Note that you cannot use scripts: in any target if you expect default_build # to work. # # # All jobs must follow the naming scheme of # :@activity: # e.g. fedora:31@build-default .templates_sha: &template_sha e195d80f35b45cc73668be3767b923fd76c70ed5 include: - project: 'freedesktop/ci-templates' ref: *template_sha file: - '/templates/ci-fairy.yml' # Alpine container builder template - '/templates/alpine.yml' # Arch container builder template - '/templates/arch.yml' # Debian container builder template - '/templates/debian.yml' # Fedora container builder template - '/templates/fedora.yml' # Freebsd container builder template - '/templates/freebsd.yml' # Ubuntu container builder template - '/templates/ubuntu.yml' workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH stages: - sanity check # CI/commit checks - prep # prep work like rebuilding the container images if there is a change - build # for actually building and testing things in a container - test-suite # for running the test suite in a VM - test-suite-no-libwacom # for running the test suite in a VM (libwacom disabled) - valgrind # for running the test suite under valgrind in a VM - distro # distribs test - deploy # trigger wayland's website generation - container_clean # clean up unused container images (scheduled jobs only) variables: ############################################################################### # This is the list of packages required to build libinput with the default # # configuration. # # # # Run dnf install/apt-get install/.. with the list of packages for your # # distribution # # # # See the documentation here: # # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html # ############################################################################### FEDORA_PACKAGES: 'git-core gcc gcc-c++ pkgconf-pkg-config meson check-devel libudev-devel libevdev-devel doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx_rtd_theme python3-pytest-xdist libwacom-devel cairo-devel gtk4-devel glib2-devel mtdev-devel diffutils wayland-protocols-devel black clang-analyzer jq rpmdevtools valgrind systemd-udev qemu-img qemu-system-x86-core qemu-system-aarch64-core jq python3-click python3-rich' DEBIAN_PACKAGES: 'git gcc g++ pkg-config meson check libudev-dev libevdev-dev doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx-rtd-theme python3-pytest-xdist libwacom-dev libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev curl' UBUNTU_PACKAGES: 'git gcc g++ pkg-config meson check libudev-dev libevdev-dev doxygen graphviz python3-sphinx python3-recommonmark python3-sphinx-rtd-theme python3-pytest-xdist libwacom-dev libcairo2-dev libgtk-3-dev libglib2.0-dev libmtdev-dev' ARCH_PACKAGES: 'git gcc pkgconfig meson check libsystemd libevdev doxygen graphviz python-sphinx python-recommonmark python-sphinx_rtd_theme python-pytest-xdist libwacom gtk4 mtdev diffutils wayland-protocols' ALPINE_PACKAGES: 'git gcc build-base pkgconfig meson check-dev eudev-dev libevdev-dev libwacom-dev cairo-dev gtk4.0-dev mtdev-dev bash' FREEBSD_PACKAGES: 'git pkgconf meson libepoll-shim libudev-devd libevdev libwacom gtk3 libmtdev bash wayland' ############################ end of package lists ############################# # these tags should be updated each time the list of packages is updated # changing these will force rebuilding the associated image # Note: these tags have no meaning and are not tied to a particular # libinput version FEDORA_TAG: '2024-05-13.0' DEBIAN_TAG: '2024-05-13.0' UBUNTU_TAG: '2024-05-13.0' ARCH_TAG: '2024-05-13.0' ALPINE_TAG: '2024-05-13.0' FREEBSD_TAG: '2024-05-13.0' FDO_UPSTREAM_REPO: libinput/libinput MESON_BUILDDIR: "build dir" NINJA_ARGS: '' MESON_ARGS: '' MESON_TEST_ARGS: '--no-suite=hardware' # udev isn't available/working properly in the containers UDEV_NOT_AVAILABLE: 1 GIT_DEPTH: 1 .policy: retry: max: 2 when: - runner_system_failure - stuck_or_timeout_failure # cancel run when a newer version is pushed to the branch interruptible: true dependencies: [] .default_artifacts: artifacts: name: "meson-logs-$CI_JOB_NAME" when: always expire_in: 1 week paths: - $MESON_BUILDDIR/meson-logs - $MESON_BUILDDIR/valgrind.*.log reports: junit: $MESON_BUILDDIR/*junit*.xml ################################################################# # # # sanity check stage # # # ################################################################# fail-if-fork-is-not-public: stage: sanity check script: - | if [ $CI_PROJECT_VISIBILITY != "public" ]; then echo "*************************************************************************************" echo "Project visibility must be set to 'public'" echo "Change this in $CI_PROJECT_URL/edit under 'Visibility, project features, permissions'" echo "*************************************************************************************" exit 1 fi except: - main@libinput/libinput # Re-generate the CI script and make sure it's the one currently checked in # If this job fails, re-generate the gitlab-ci.yml script, see # $SRCDIR/.gitlab-ci/generate-gitlab-ci.py # check-ci-script: extends: - .fdo.ci-fairy stage: sanity check script: - ci-fairy generate-template --verify && exit 0 || true - > printf "%s\n" \ "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify" \ "https://wayland.freedesktop.org/libinput/doc/latest/contributing.html" - exit 1 # # Verify that commit messages are as expected, etc. # check-commit: extends: - .fdo.ci-fairy stage: sanity check script: - ci-fairy -vv check-commits --junit-xml=results.xml && exit 0 || true - > printf "%s\n" \ "Error checking commit format. Please verify" \ "https://wayland.freedesktop.org/libinput/doc/latest/contributing.html" - exit 1 except: - main@libinput/libinput variables: GIT_DEPTH: 100 artifacts: reports: junit: results.xml # # Check for trailing whitespaces # check-whitespace: extends: - .fdo.ci-fairy stage: sanity check script: - .gitlab-ci/whitespace-check.py $(git ls-files) # # pre-commit hooks # pre-commit-hooks: extends: - .fdo.ci-fairy stage: sanity check script: - python3 -m venv venv - source venv/bin/activate - pip3 install pre-commit - pre-commit run --all-files || true - git diff --exit-code || (echo "ERROR - Code style errors found, please fix" && false) ################################################################# # # # prep stage # # # ################################################################# fedora:40@container-prep: extends: - .fdo.container-build@fedora - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: '40' FDO_DISTRIBUTION_PACKAGES: $FEDORA_PACKAGES FDO_DISTRIBUTION_TAG: $FEDORA_TAG fedora:41@container-prep: extends: - .fdo.container-build@fedora - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: '41' FDO_DISTRIBUTION_PACKAGES: $FEDORA_PACKAGES FDO_DISTRIBUTION_TAG: $FEDORA_TAG debian:stable@container-prep: extends: - .fdo.container-build@debian - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: 'stable' FDO_DISTRIBUTION_PACKAGES: $DEBIAN_PACKAGES FDO_DISTRIBUTION_TAG: $DEBIAN_TAG ubuntu:22.04@container-prep: extends: - .fdo.container-build@ubuntu - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: '22.04' FDO_DISTRIBUTION_PACKAGES: $UBUNTU_PACKAGES FDO_DISTRIBUTION_TAG: $UBUNTU_TAG arch:rolling@container-prep: extends: - .fdo.container-build@arch - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: 'rolling' FDO_DISTRIBUTION_PACKAGES: $ARCH_PACKAGES FDO_DISTRIBUTION_TAG: $ARCH_TAG alpine:latest@container-prep: extends: - .fdo.container-build@alpine - .policy stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: 'latest' FDO_DISTRIBUTION_PACKAGES: $ALPINE_PACKAGES FDO_DISTRIBUTION_TAG: $ALPINE_TAG freebsd:13.2@container-prep: extends: - .fdo.qemu-build@freebsd - .policy tags: - kvm stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: '13.2' FDO_DISTRIBUTION_PACKAGES: $FREEBSD_PACKAGES FDO_DISTRIBUTION_TAG: $FREEBSD_TAG ################################################################# # # # container clean stage # # run during the clean stage # # # ################################################################# # # This stage will look for the container images we currently have in # the registry and will remove any that are not tagged with the provided # $container_image:$tag # .container-clean: extends: - .policy - .fdo.ci-fairy stage: container_clean script: # Go to your Profile, Settings, Access Tokens # Create a personal token with 'api' scope, copy the value. # Go to CI/CD, Schedules, schedule a new monthly job (or edit the existing one) # Define a variable of type File named AUTHFILE. Content is that token # value. - ci-fairy -v --authfile $AUTHFILE delete-image --repository $FDO_DISTRIBUTION_NAME/$FDO_DISTRIBUTION_VERSION --exclude-tag $FDO_DISTRIBUTION_TAG allow_failure: true only: - schedules fedora:40@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: '40' FDO_DISTRIBUTION_TAG: $FEDORA_TAG fedora:41@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/fedora/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: '41' FDO_DISTRIBUTION_TAG: $FEDORA_TAG debian:stable@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/debian/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: 'stable' FDO_DISTRIBUTION_TAG: $DEBIAN_TAG ubuntu:22.04@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/ubuntu/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: '22.04' FDO_DISTRIBUTION_TAG: $UBUNTU_TAG arch:rolling@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/arch/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: 'rolling' FDO_DISTRIBUTION_TAG: $ARCH_TAG alpine:latest@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/alpine/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: 'latest' FDO_DISTRIBUTION_TAG: $ALPINE_TAG freebsd:13.2@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/freebsd/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: '13.2' FDO_DISTRIBUTION_TAG: $FREEBSD_TAG ################################################################# # # # build stage # # # ################################################################# .build@template: extends: - .policy - .default_artifacts stage: build script: - .gitlab-ci/meson-build.sh # Run meson and meson test in the container image through qemu .build-in-b2c@template: extends: - .policy - .default_artifacts tags: - kvm variables: MESON_BUILDDIR: build_dir B2C_KERNEL: https://gitlab.freedesktop.org/api/v4/projects/libevdev%2Fhid-tools/packages/generic/kernel-x86_64/v6.5/bzImage B2C_IMAGE: $FDO_DISTRIBUTION_IMAGE B2C_COMMAND: .gitlab-ci/start-in-systemd.sh script: # first build in the host container - .gitlab-ci/meson-build.sh --skip-test # pull b2c - curl -L -o /app/boot2container https://gitlab.freedesktop.org/gfx-ci/boot2container/-/raw/24beb454c62fe59143d7ceb4f5a7d25a3c029559/vm2c.py - chmod +x /app/boot2container # runs the test suite only - /app/boot2container # # Fedora # .check_tainted: &check_tainted | # make sure the kernel is not tainted if [[ "$(ssh localhost -p 5555 cat /proc/sys/kernel/tainted)" -gt 0 ]]; then echo tainted kernel ; exit 1 ; fi # Run meson and meson test in the qemu image .build-in-qemu@template: extends: - .policy tags: - kvm variables: MESON_BUILDDIR: build_dir script: # start our vm, no args required - /app/vmctl start || (echo "Error - Failed to start the VM." && exit 1) - *check_tainted - "scp -r $PWD vm:" - echo "CI_JOB_ID=\"$CI_JOB_ID\"" > sshenv - echo "CI_JOB_NAME=\"$CI_JOB_NAME\"" >> sshenv - echo "MESON_ARGS=\"$MESON_ARGS\"" >> sshenv - echo "MESON_BUILDDIR=\"$MESON_BUILDDIR\"" >> sshenv - echo "MESON_TEST_ARGS=\"$MESON_TEST_ARGS\"" >> sshenv - echo "NINJA_ARGS=\"$NINJA_ARGS\"" >> sshenv - "scp sshenv vm:~/$CI_PROJECT_NAME/.meson_environment" - /app/vmctl exec "cd $CI_PROJECT_NAME ; .gitlab-ci/meson-build.sh" && touch .success || true # no matter the results of the tests, we want to fetch the logs - scp -r vm:$CI_PROJECT_NAME/$MESON_BUILDDIR . - *check_tainted - /app/vmctl stop - if [[ ! -e .success ]] ; then exit 1 ; fi artifacts: name: "qemu-meson-logs-$CI_JOB_NAME" when: always expire_in: 1 week paths: - $MESON_BUILDDIR/meson-logs - console.out reports: junit: $MESON_BUILDDIR/*junit*.xml # Run in a test suite. Special variables: # - SUITES: the meson test suites to run, or # - SUITE_NAMES: all elements will be expanded to libinput-test-suite-$value # Set one or the other, not both. .test-suite-vm: extends: - .build-in-b2c@template stage: test-suite variables: # remove the global --no-suite=hardware MESON_TEST_ARGS: '' LITEST_JOBS: 4 before_script: - if ! [[ -z $SUITE_NAMES ]]; then SUITES=$(echo $SUITE_NAMES | sed 's/\([^ ]*\)/libinput-test-suite-\1/g'); fi - echo "Testing $SUITES" - export MESON_TEST_ARGS="$MESON_TEST_ARGS $SUITES" .fedora:41@test-suite-vm: extends: - .fdo.distribution-image@fedora - .test-suite-vm variables: FDO_DISTRIBUTION_VERSION: 41 FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:41@container-prep" vm-touchpad: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad' vm-touchpad-no-libwacom: extends: - vm-touchpad stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-touchpad_palm: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_palm' vm-touchpad_palm-no-libwacom: extends: - vm-touchpad_palm stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-touchpad_dwt: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_dwt' vm-touchpad_dwt-no-libwacom: extends: - vm-touchpad_dwt stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-tap: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_tap' vm-tap-no-libwacom: extends: - vm-tap stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-tap-drag: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_tap_drag' vm-tap-drag-no-libwacom: extends: - vm-tap-drag stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-tap-palm: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_tap_palm' vm-tap-palm-no-libwacom: extends: - vm-tap-palm stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-touchpad-buttons: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'touchpad_buttons' vm-touchpad-buttons-no-libwacom: extends: - vm-touchpad-buttons stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-tablet: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'tablet' vm-tablet-no-libwacom: extends: - vm-tablet stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-tablet_left_handed: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'tablet_left_handed' vm-tablet_left_handed-no-libwacom: extends: - vm-tablet_left_handed stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-gestures: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'gestures' vm-gestures-no-libwacom: extends: - vm-gestures stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-backends: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'path udev' vm-backends-no-libwacom: extends: - vm-backends stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-misc: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'log misc quirks device' vm-misc-no-libwacom: extends: - vm-misc stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-other devices: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'keyboard pad switch trackball trackpoint totem touch' vm-other devices-no-libwacom: extends: - vm-other devices stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-pointer: extends: - .fedora:41@test-suite-vm variables: SUITE_NAMES: 'pointer' vm-pointer-no-libwacom: extends: - vm-pointer stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' vm-valgrind-touchpad: stage: valgrind extends: - vm-touchpad variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-touchpad_palm: stage: valgrind extends: - vm-touchpad_palm variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-touchpad_dwt: stage: valgrind extends: - vm-touchpad_dwt variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-tap: stage: valgrind extends: - vm-tap variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-tap-drag: stage: valgrind extends: - vm-tap-drag variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-tap-palm: stage: valgrind extends: - vm-tap-palm variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-touchpad-buttons: stage: valgrind extends: - vm-touchpad-buttons variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-tablet: stage: valgrind extends: - vm-tablet variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-tablet_left_handed: stage: valgrind extends: - vm-tablet_left_handed variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-gestures: stage: valgrind extends: - vm-gestures variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-backends: stage: valgrind extends: - vm-backends variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-misc: stage: valgrind extends: - vm-misc variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-other devices: stage: valgrind extends: - vm-other devices variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" vm-valgrind-pointer: stage: valgrind extends: - vm-pointer variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" .fedora-build@template: extends: - .fdo.distribution-image@fedora - .build@template variables: FDO_DISTRIBUTION_VERSION: '41' FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:41@container-prep" default-build-release@fedora:41: stage: distro extends: - .fedora-build@template variables: MESON_ARGS: "-Dbuildtype=release" CFLAGS: "-Werror" scan-build@fedora:41: extends: - .fedora-build@template variables: NINJA_ARGS: '' MESON_TEST_ARGS: '' script: - .gitlab-ci/meson-build.sh - export SCANBUILD="$PWD/.gitlab-ci/scanbuild-wrapper.sh" - ninja -C "$MESON_BUILDDIR" scan-build after_script: - .gitlab-ci/scanbuild-plist-to-junit.py "$MESON_BUILDDIR"/meson-logs/scanbuild/ > "$MESON_BUILDDIR"/junit-scan-build.xml # Below jobs are build option combinations. We only # run them on one image, they shouldn't fail on one distro # when they succeed on another. build-no-libwacom@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Dlibwacom=false" build-no-libwacom-nodeps@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Dlibwacom=false" before_script: - dnf remove -y libwacom libwacom-devel build-docs@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Ddocumentation=true" build-no-docs-nodeps@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Ddocumentation=false" before_script: - dnf remove -y doxygen graphviz build-no-debuggui@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Ddebug-gui=false" build-no-debuggui-nodeps@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Ddebug-gui=false" before_script: - dnf remove -y gtk3-devel gtk4-devel build-no-tests@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Dtests=false" build-no-tests-nodeps@fedora:41: extends: - .fedora-build@template variables: MESON_ARGS: "-Dtests=false" before_script: - dnf remove -y check-devel valgrind@fedora:41: extends: - .fedora-build@template variables: MESON_TEST_ARGS: '--suite=valgrind --no-suite=hardware --setup=valgrind' # Python checks, only run on Fedora usr-bin-env-python@fedora:41: extends: - .fedora-build@template script: - | if git grep -l '^#!/usr/bin/python'; then echo "Use '/usr/bin/env python3' in the above files"; /bin/false fi python-format@fedora:41: extends: - .fedora-build@template script: - black $(git grep -l '^#!/usr/bin/env python3') - git diff --exit-code || (echo "Please run Black against all Python files" && false) # A job to check we're actually running all test suites in the CI check-test-suites: extends: - .fedora-build@template script: - meson setup builddir - meson introspect builddir --test | jq -r '.[].name' | grep 'libinput-test-suite' | sort > meson-testsuites - | cat < ci-testsuites ; libinput-test-suite-touchpad libinput-test-suite-touchpad_palm libinput-test-suite-touchpad_dwt libinput-test-suite-touchpad_tap libinput-test-suite-touchpad_tap_drag libinput-test-suite-touchpad_tap_palm libinput-test-suite-touchpad_buttons libinput-test-suite-tablet libinput-test-suite-tablet_left_handed libinput-test-suite-gestures libinput-test-suite-path libinput-test-suite-udev libinput-test-suite-log libinput-test-suite-misc libinput-test-suite-quirks libinput-test-suite-device libinput-test-suite-keyboard libinput-test-suite-pad libinput-test-suite-switch libinput-test-suite-trackball libinput-test-suite-trackpoint libinput-test-suite-totem libinput-test-suite-touch libinput-test-suite-pointer EOF - sort -o ci-testsuites ci-testsuites - diff -u8 -w ci-testsuites meson-testsuites || (echo "Some test suites are not run in the CI" && false) only: changes: - "meson.build" - ".gitlab-ci.yml" # # coverity run # # This requires the COVERITY_SCAN_TOKEN. Log into scan.coverity.com and get # the token from the respective project settings page. # Schedule a pipeline and set a variable COVERITY_SCAN_TOKEN with the token value. # https://gitlab.freedesktop.org/$CI_PROJECT_PATH/-/pipeline_schedules # Email from coverity will be sent to the GITLAB_USER_EMAIL that scheduled the # job. # # Coverity ratelimits submissions and the coverity tools download is about # 700M, do not run this too often. # coverity: extends: - .fdo.distribution-image@debian - .policy stage: build variables: FDO_DISTRIBUTION_VERSION: 'stable' FDO_DISTRIBUTION_TAG: $DEBIAN_TAG # so git-describe works, or should work GIT_DEPTH: 200 only: variables: - $COVERITY_SCAN_TOKEN script: - curl https://scan.coverity.com/download/linux64 -o /tmp/cov-analysis-linux64.tgz --form project=$CI_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN - tar xfz /tmp/cov-analysis-linux64.tgz # coverity has special build options in meson, make sure we enable those - meson coverity-build -Ddocumentation=false -Dcoverity=true - cov-analysis-linux64-*/bin/cov-build --dir cov-int ninja -C coverity-build - tar cfz cov-int.tar.gz cov-int - curl https://scan.coverity.com/builds?project=$CI_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN --form email=$GITLAB_USER_EMAIL --form file=@cov-int.tar.gz --form version="$(git describe --tags)" --form description="$(git describe --tags) / $CI_COMMIT_TITLE / $CI_COMMIT_REF_NAME:$CI_PIPELINE_ID" artifacts: name: "coverity-submit-data" when: always expire_in: 1 week paths: - cov-int.tar.gz needs: - "debian:stable@container-prep" ################################################################# # # # distro stage # # # ################################################################# fedora:40@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@fedora variables: FDO_DISTRIBUTION_VERSION: '40' FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:40@container-prep" fedora:41@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@fedora variables: FDO_DISTRIBUTION_VERSION: '41' FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:41@container-prep" debian:stable@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@debian variables: FDO_DISTRIBUTION_VERSION: 'stable' FDO_DISTRIBUTION_TAG: $DEBIAN_TAG needs: - "debian:stable@container-prep" ubuntu:22.04@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@ubuntu variables: FDO_DISTRIBUTION_VERSION: '22.04' FDO_DISTRIBUTION_TAG: $UBUNTU_TAG needs: - "ubuntu:22.04@container-prep" arch:rolling@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@arch variables: FDO_DISTRIBUTION_VERSION: 'rolling' FDO_DISTRIBUTION_TAG: $ARCH_TAG needs: - "arch:rolling@container-prep" alpine:latest@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@alpine variables: FDO_DISTRIBUTION_VERSION: 'latest' FDO_DISTRIBUTION_TAG: $ALPINE_TAG MESON_ARGS: '-Ddocumentation=false' # alpine does not have python-recommonmark MESON_TEST_ARGS: '' # litest-selftest fails on musl needs: - "alpine:latest@container-prep" freebsd:13.2@default-build: stage: distro extends: - .build-in-qemu@template - .fdo.distribution-image@freebsd variables: FDO_DISTRIBUTION_VERSION: '13.2' FDO_DISTRIBUTION_TAG: $FREEBSD_TAG MESON_ARGS: '-Dtests=false -Ddocumentation=false' # doxygen drags down too many deps MESON_TEST_ARGS: '' # test suite doesn't work on BSD yet needs: - "freebsd:13.2@container-prep" ################################################################# # # # deploy stage # # # ################################################################# # # Verify that the merge request has the allow-collaboration checkbox ticked # check-merge-request: extends: - .fdo.ci-fairy - .policy stage: deploy script: - ci-fairy check-merge-request --require-allow-collaboration --junit-xml=results.xml artifacts: when: on_failure reports: junit: results.xml allow_failure: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' build rpm: extends: - .fdo.distribution-image@fedora - .policy stage: deploy variables: FDO_DISTRIBUTION_VERSION: '41' FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:41@container-prep" script: - meson "$MESON_BUILDDIR" - VERSION=$(meson introspect "$MESON_BUILDDIR" --projectinfo | jq -r .version) - sed -e "s/@PIPELINEID@/${CI_PIPELINE_ID}/" -e "s/@GITVERSION@/${CI_COMMIT_SHA}/" -e "s/@VERSION@/${VERSION}/" .gitlab-ci/libinput.spec.in > libinput.spec - git config --local user.name 'gitlab CI' - git config --local user.email 'noreply@nowhere' - git add libinput.spec && git commit -m 'Add libinput.spec for build testing' libinput.spec - cd "$MESON_BUILDDIR" - meson dist --no-test - rpmbuild -ta meson-dist/libinput*.tar.xz wayland-web: stage: deploy trigger: wayland/wayland.freedesktop.org except: refs: - schedules variables: MESON_ARGS: '-Ddocumentation=true -Ddebug-gui=false -Dlibwacom=false -Dtests=false' MESON_BUILDDIR: 'builddir' only: refs: - main variables: - $CI_PROJECT_PATH == "libinput/libinput" libinput-1.28.1/.gitlab-ci/000077500000000000000000000000001477265155700153655ustar00rootroot00000000000000libinput-1.28.1/.gitlab-ci/ci.template000066400000000000000000000561061477265155700175250ustar00rootroot00000000000000# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0 filetype=yaml: {# You're looking at the template here, so you can ignore the below warning. This is the right file to edit #} ######################################## # # # THIS FILE IS GENERATED, DO NOT EDIT # # # ######################################## # To change the gitlab CI, edit .gitlab-ci/ci.template and/or .gitlab-ci/config.yaml # and run ci-fairy generate-template. For details, see # https://freedesktop.pages.freedesktop.org/ci-templates/ci-fairy.html#templating-gitlab-ci-yml # This is a bit complicated for two reasons: # - we really want to run dnf/apt/... only once, updating on the test runner for # each job takes forever. So we create a container image for each distribution # tested, then run the tests on this container image. # # This is handled by the ci-templates, ensuring containers are only rebuilt # when the TAG changes. # # - GitLab only allows one script: set per job but we have a bunch of commands # we need to re-run for each build (meson && ninja && etc). YAML cannot merge # arrays so we're screwed. # # So instead we use a default_build template and override everything with # variables. The only two variables that matter: # MESON_ARGS=-Denable-something=true # NINJA_ARGS=dist ... to run 'ninja -C builddir dist' # Note that you cannot use scripts: in any target if you expect default_build # to work. # # # All jobs must follow the naming scheme of # :@activity: # e.g. fedora:31@build-default .templates_sha: &template_sha e195d80f35b45cc73668be3767b923fd76c70ed5 include: - project: 'freedesktop/ci-templates' ref: *template_sha file: - '/templates/ci-fairy.yml' {% for distro in distributions|sort(attribute="name") %} # {{ distro.name.capitalize() }} container builder template - '/templates/{{distro.name}}.yml' {% endfor %} workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH stages: - sanity check # CI/commit checks - prep # prep work like rebuilding the container images if there is a change - build # for actually building and testing things in a container - test-suite # for running the test suite in a VM - test-suite-no-libwacom # for running the test suite in a VM (libwacom disabled) - valgrind # for running the test suite under valgrind in a VM - distro # distribs test - deploy # trigger wayland's website generation - container_clean # clean up unused container images (scheduled jobs only) variables: ############################################################################### # This is the list of packages required to build libinput with the default # # configuration. # # # # Run dnf install/apt-get install/.. with the list of packages for your # # distribution # # # # See the documentation here: # # https://wayland.freedesktop.org/libinput/doc/latest/building_libinput.html # ############################################################################### {% for distro in distributions %} {{"%-17s" | format(distro.name.upper() + '_PACKAGES:')}} '{{ distro.packages|join(' ')}}' {% endfor %} ############################ end of package lists ############################# # these tags should be updated each time the list of packages is updated # changing these will force rebuilding the associated image # Note: these tags have no meaning and are not tied to a particular # libinput version {% for distro in distributions %} {{"%-13s"| format(distro.name.upper() + '_TAG:')}}'{{distro.tag}}' {% endfor %} FDO_UPSTREAM_REPO: libinput/libinput MESON_BUILDDIR: "build dir" NINJA_ARGS: '' MESON_ARGS: '' MESON_TEST_ARGS: '--no-suite=hardware' # udev isn't available/working properly in the containers UDEV_NOT_AVAILABLE: 1 GIT_DEPTH: 1 .policy: retry: max: 2 when: - runner_system_failure - stuck_or_timeout_failure # cancel run when a newer version is pushed to the branch interruptible: true dependencies: [] .default_artifacts: artifacts: name: "meson-logs-$CI_JOB_NAME" when: always expire_in: 1 week paths: - $MESON_BUILDDIR/meson-logs - $MESON_BUILDDIR/valgrind.*.log reports: junit: $MESON_BUILDDIR/*junit*.xml ################################################################# # # # sanity check stage # # # ################################################################# fail-if-fork-is-not-public: stage: sanity check script: - | if [ $CI_PROJECT_VISIBILITY != "public" ]; then echo "*************************************************************************************" echo "Project visibility must be set to 'public'" echo "Change this in $CI_PROJECT_URL/edit under 'Visibility, project features, permissions'" echo "*************************************************************************************" exit 1 fi except: - main@libinput/libinput # Re-generate the CI script and make sure it's the one currently checked in # If this job fails, re-generate the gitlab-ci.yml script, see # $SRCDIR/.gitlab-ci/generate-gitlab-ci.py # check-ci-script: extends: - .fdo.ci-fairy stage: sanity check script: - ci-fairy generate-template --verify && exit 0 || true - > printf "%s\n" \ "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify" \ "https://wayland.freedesktop.org/libinput/doc/latest/contributing.html" - exit 1 # # Verify that commit messages are as expected, etc. # check-commit: extends: - .fdo.ci-fairy stage: sanity check script: - ci-fairy -vv check-commits --junit-xml=results.xml && exit 0 || true - > printf "%s\n" \ "Error checking commit format. Please verify" \ "https://wayland.freedesktop.org/libinput/doc/latest/contributing.html" - exit 1 except: - main@libinput/libinput variables: GIT_DEPTH: 100 artifacts: reports: junit: results.xml # # Check for trailing whitespaces # check-whitespace: extends: - .fdo.ci-fairy stage: sanity check script: - .gitlab-ci/whitespace-check.py $(git ls-files) # # pre-commit hooks # pre-commit-hooks: extends: - .fdo.ci-fairy stage: sanity check script: - python3 -m venv venv - source venv/bin/activate - pip3 install pre-commit - pre-commit run --all-files || true - git diff --exit-code || (echo "ERROR - Code style errors found, please fix" && false) ################################################################# # # # prep stage # # # ################################################################# {% for distro in distributions %} {% for version in distro.versions %} {{distro.name}}:{{version}}@container-prep: extends: {% if distro.qemu_based %} - .fdo.qemu-build@{{distro.name}} {% else %} - .fdo.container-build@{{distro.name}} {% endif %} - .policy {% if distro.qemu_based %} tags: - kvm {% endif %} stage: prep variables: GIT_STRATEGY: none FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_PACKAGES: ${{distro.name.upper()}}_PACKAGES FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG {% endfor %} {% endfor %} ################################################################# # # # container clean stage # # run during the clean stage # # # ################################################################# # # This stage will look for the container images we currently have in # the registry and will remove any that are not tagged with the provided # $container_image:$tag # .container-clean: extends: - .policy - .fdo.ci-fairy stage: container_clean script: # Go to your Profile, Settings, Access Tokens # Create a personal token with 'api' scope, copy the value. # Go to CI/CD, Schedules, schedule a new monthly job (or edit the existing one) # Define a variable of type File named AUTHFILE. Content is that token # value. - ci-fairy -v --authfile $AUTHFILE delete-image --repository $FDO_DISTRIBUTION_NAME/$FDO_DISTRIBUTION_VERSION --exclude-tag $FDO_DISTRIBUTION_TAG allow_failure: true only: - schedules {% for distro in distributions %} {% for version in distro.versions %} {{distro.name}}:{{version}}@container-clean: extends: - .policy - .container-clean variables: GIT_STRATEGY: none CURRENT_CONTAINER_IMAGE: $CI_REGISTRY_IMAGE/{{distro.name}}/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG {% endfor %} {% endfor %} ################################################################# # # # build stage # # # ################################################################# .build@template: extends: - .policy - .default_artifacts stage: build script: - .gitlab-ci/meson-build.sh # Run meson and meson test in the container image through qemu .build-in-b2c@template: extends: - .policy - .default_artifacts tags: - kvm variables: MESON_BUILDDIR: build_dir B2C_KERNEL: {{ b2c.kernel }} B2C_IMAGE: $FDO_DISTRIBUTION_IMAGE B2C_COMMAND: .gitlab-ci/start-in-systemd.sh script: # first build in the host container - .gitlab-ci/meson-build.sh --skip-test # pull b2c - curl -L -o /app/boot2container https://gitlab.freedesktop.org/gfx-ci/boot2container/-/raw/{{b2c.version}}/vm2c.py - chmod +x /app/boot2container # runs the test suite only - /app/boot2container # # Fedora # .check_tainted: &check_tainted | # make sure the kernel is not tainted if [[ "$(ssh localhost -p 5555 cat /proc/sys/kernel/tainted)" -gt 0 ]]; then echo tainted kernel ; exit 1 ; fi # Run meson and meson test in the qemu image .build-in-qemu@template: extends: - .policy tags: - kvm variables: MESON_BUILDDIR: build_dir script: # start our vm, no args required - /app/vmctl start || (echo "Error - Failed to start the VM." && exit 1) - *check_tainted - "scp -r $PWD vm:" - echo "CI_JOB_ID=\"$CI_JOB_ID\"" > sshenv - echo "CI_JOB_NAME=\"$CI_JOB_NAME\"" >> sshenv - echo "MESON_ARGS=\"$MESON_ARGS\"" >> sshenv - echo "MESON_BUILDDIR=\"$MESON_BUILDDIR\"" >> sshenv - echo "MESON_TEST_ARGS=\"$MESON_TEST_ARGS\"" >> sshenv - echo "NINJA_ARGS=\"$NINJA_ARGS\"" >> sshenv - "scp sshenv vm:~/$CI_PROJECT_NAME/.meson_environment" - /app/vmctl exec "cd $CI_PROJECT_NAME ; .gitlab-ci/meson-build.sh" && touch .success || true # no matter the results of the tests, we want to fetch the logs - scp -r vm:$CI_PROJECT_NAME/$MESON_BUILDDIR . - *check_tainted - /app/vmctl stop - if [[ ! -e .success ]] ; then exit 1 ; fi artifacts: name: "qemu-meson-logs-$CI_JOB_NAME" when: always expire_in: 1 week paths: - $MESON_BUILDDIR/meson-logs - console.out reports: junit: $MESON_BUILDDIR/*junit*.xml # Run in a test suite. Special variables: # - SUITES: the meson test suites to run, or # - SUITE_NAMES: all elements will be expanded to libinput-test-suite-$value # Set one or the other, not both. .test-suite-vm: extends: - .build-in-b2c@template stage: test-suite variables: # remove the global --no-suite=hardware MESON_TEST_ARGS: '' LITEST_JOBS: 4 before_script: - if ! [[ -z $SUITE_NAMES ]]; then SUITES=$(echo $SUITE_NAMES | sed 's/\([^ ]*\)/libinput-test-suite-\1/g'); fi - echo "Testing $SUITES" - export MESON_TEST_ARGS="$MESON_TEST_ARGS $SUITES" {# qemu tests are only done for the latest version of any distribution #} {% for distro in distributions if distro.use_for_qemu_tests %} {% set version = "{}".format(distro.versions|last()) %} .{{distro.name}}:{{version}}@test-suite-vm: extends: - .fdo.distribution-image@{{distro.name}} - .test-suite-vm variables: FDO_DISTRIBUTION_VERSION: {{version}} FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG needs: - "{{distro.name}}:{{version}}@container-prep" {% for suite in test_suites %} vm-{{suite.name}}: extends: - .{{distro.name}}:{{version}}@test-suite-vm variables: SUITE_NAMES: '{{suite.suites|join(' ')}}' vm-{{suite.name}}-no-libwacom: extends: - vm-{{suite.name}} stage: test-suite-no-libwacom variables: MESON_ARGS: '-Dlibwacom=false' {% endfor %} {% for suite in test_suites %} vm-valgrind-{{suite.name}}: stage: valgrind extends: - vm-{{suite.name}} variables: MESON_TEST_ARGS: '--setup=valgrind' LITEST_JOBS: 0 retry: max: 2 rules: - if: $GITLAB_USER_LOGIN != "marge-bot" {% endfor %} {% endfor %}{# for if distro.use_for_qemu_tests #} {% for distro in distributions if distro.use_for_custom_build_tests %} {% set version = "{}".format(distro.versions|last()) %} .{{distro.name}}-build@template: extends: - .fdo.distribution-image@{{distro.name}} - .build@template variables: FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG needs: - "{{distro.name}}:{{version}}@container-prep" default-build-release@{{distro.name}}:{{version}}: stage: distro extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Dbuildtype=release" CFLAGS: "-Werror" scan-build@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: NINJA_ARGS: '' MESON_TEST_ARGS: '' script: - .gitlab-ci/meson-build.sh - export SCANBUILD="$PWD/.gitlab-ci/scanbuild-wrapper.sh" - ninja -C "$MESON_BUILDDIR" scan-build after_script: - .gitlab-ci/scanbuild-plist-to-junit.py "$MESON_BUILDDIR"/meson-logs/scanbuild/ > "$MESON_BUILDDIR"/junit-scan-build.xml # Below jobs are build option combinations. We only # run them on one image, they shouldn't fail on one distro # when they succeed on another. build-no-libwacom@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Dlibwacom=false" build-no-libwacom-nodeps@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Dlibwacom=false" before_script: - dnf remove -y libwacom libwacom-devel build-docs@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Ddocumentation=true" build-no-docs-nodeps@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Ddocumentation=false" before_script: - dnf remove -y doxygen graphviz build-no-debuggui@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Ddebug-gui=false" build-no-debuggui-nodeps@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Ddebug-gui=false" before_script: - dnf remove -y gtk3-devel gtk4-devel build-no-tests@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Dtests=false" build-no-tests-nodeps@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_ARGS: "-Dtests=false" before_script: - dnf remove -y check-devel valgrind@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template variables: MESON_TEST_ARGS: '--suite=valgrind --no-suite=hardware --setup=valgrind' # Python checks, only run on Fedora usr-bin-env-python@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template script: - | if git grep -l '^#!/usr/bin/python'; then echo "Use '/usr/bin/env python3' in the above files"; /bin/false fi python-format@{{distro.name}}:{{version}}: extends: - .{{distro.name}}-build@template script: - black $(git grep -l '^#!/usr/bin/env python3') - git diff --exit-code || (echo "Please run Black against all Python files" && false) # A job to check we're actually running all test suites in the CI check-test-suites: extends: - .{{distro.name}}-build@template script: - meson setup builddir - meson introspect builddir --test | jq -r '.[].name' | grep 'libinput-test-suite' | sort > meson-testsuites - | cat < ci-testsuites ; {% for suite in test_suites %} {% for name in suite.suites %} libinput-test-suite-{{name}} {% endfor %} {% endfor %} EOF - sort -o ci-testsuites ci-testsuites - diff -u8 -w ci-testsuites meson-testsuites || (echo "Some test suites are not run in the CI" && false) only: changes: - "meson.build" - ".gitlab-ci.yml" {% endfor %} # # coverity run # # This requires the COVERITY_SCAN_TOKEN. Log into scan.coverity.com and get # the token from the respective project settings page. # Schedule a pipeline and set a variable COVERITY_SCAN_TOKEN with the token value. # https://gitlab.freedesktop.org/$CI_PROJECT_PATH/-/pipeline_schedules # Email from coverity will be sent to the GITLAB_USER_EMAIL that scheduled the # job. # # Coverity ratelimits submissions and the coverity tools download is about # 700M, do not run this too often. # coverity: extends: - .fdo.distribution-image@debian - .policy stage: build variables: FDO_DISTRIBUTION_VERSION: 'stable' FDO_DISTRIBUTION_TAG: $DEBIAN_TAG # so git-describe works, or should work GIT_DEPTH: 200 only: variables: - $COVERITY_SCAN_TOKEN script: - curl https://scan.coverity.com/download/linux64 -o /tmp/cov-analysis-linux64.tgz --form project=$CI_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN - tar xfz /tmp/cov-analysis-linux64.tgz # coverity has special build options in meson, make sure we enable those - meson coverity-build -Ddocumentation=false -Dcoverity=true - cov-analysis-linux64-*/bin/cov-build --dir cov-int ninja -C coverity-build - tar cfz cov-int.tar.gz cov-int - curl https://scan.coverity.com/builds?project=$CI_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN --form email=$GITLAB_USER_EMAIL --form file=@cov-int.tar.gz --form version="$(git describe --tags)" --form description="$(git describe --tags) / $CI_COMMIT_TITLE / $CI_COMMIT_REF_NAME:$CI_PIPELINE_ID" artifacts: name: "coverity-submit-data" when: always expire_in: 1 week paths: - cov-int.tar.gz needs: - "debian:stable@container-prep" ################################################################# # # # distro stage # # # ################################################################# {% for distro in distributions %} {% if not distro.qemu_based %} {% for version in distro.versions %} {{distro.name}}:{{version}}@default-build: stage: distro extends: - .build@template - .fdo.distribution-image@{{distro.name}} variables: FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG {# Where we have extra_variables defined, add them to the list #} {% if distro.build is defined and distro.build.extra_variables is defined %} {% for var in distro.build.extra_variables %} {{var}} {% endfor %} {% endif %} needs: - "{{distro.name}}:{{version}}@container-prep" {% endfor %} {% else %} {% set version = "{}".format(distro.versions|last()) %} {{distro.name}}:{{version}}@default-build: stage: distro extends: - .build-in-qemu@template - .fdo.distribution-image@{{distro.name}} variables: FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_TAG: ${{distro.name.upper()}}_TAG {# Where we have extra_variables defined, add them to the list #} {% if distro.build is defined and distro.build.extra_variables is defined %} {% for var in distro.build.extra_variables %} {{var}} {% endfor %} {% endif %} needs: - "{{distro.name}}:{{version}}@container-prep" {% endif %} {% endfor %} ################################################################# # # # deploy stage # # # ################################################################# # # Verify that the merge request has the allow-collaboration checkbox ticked # check-merge-request: extends: - .fdo.ci-fairy - .policy stage: deploy script: - ci-fairy check-merge-request --require-allow-collaboration --junit-xml=results.xml artifacts: when: on_failure reports: junit: results.xml allow_failure: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' {% for distro in distributions if distro.name == "fedora" %} {% set version = "{}".format(distro.versions|last()) %} build rpm: extends: - .fdo.distribution-image@fedora - .policy stage: deploy variables: FDO_DISTRIBUTION_VERSION: '{{version}}' FDO_DISTRIBUTION_TAG: $FEDORA_TAG needs: - "fedora:{{version}}@container-prep" script: - meson "$MESON_BUILDDIR" - VERSION=$(meson introspect "$MESON_BUILDDIR" --projectinfo | jq -r .version) - sed -e "s/@PIPELINEID@/${CI_PIPELINE_ID}/" -e "s/@GITVERSION@/${CI_COMMIT_SHA}/" -e "s/@VERSION@/${VERSION}/" .gitlab-ci/libinput.spec.in > libinput.spec - git config --local user.name 'gitlab CI' - git config --local user.email 'noreply@nowhere' - git add libinput.spec && git commit -m 'Add libinput.spec for build testing' libinput.spec - cd "$MESON_BUILDDIR" - meson dist --no-test - rpmbuild -ta meson-dist/libinput*.tar.xz {% endfor %} wayland-web: stage: deploy trigger: wayland/wayland.freedesktop.org except: refs: - schedules variables: MESON_ARGS: '-Ddocumentation=true -Ddebug-gui=false -Dlibwacom=false -Dtests=false' MESON_BUILDDIR: 'builddir' only: refs: - main variables: - $CI_PROJECT_PATH == "libinput/libinput" libinput-1.28.1/.gitlab-ci/config.yml000066400000000000000000000120251477265155700173550ustar00rootroot00000000000000# This file contains the configuration for the gitlab ci. # See the .gitlab-ci/generate-gitlab-ci.py file for more info # # We're happy to rebuild all containers when one changes. .default_tag: &default_tag '2024-05-13.0' distributions: - name: fedora tag: *default_tag versions: - '40' - '41' use_for_custom_build_tests: true use_for_qemu_tests: true packages: - git-core - gcc - gcc-c++ - pkgconf-pkg-config - meson - check-devel - libudev-devel - libevdev-devel - doxygen - graphviz - python3-sphinx - python3-recommonmark - python3-sphinx_rtd_theme - python3-pytest-xdist - libwacom-devel - cairo-devel - gtk4-devel - glib2-devel - mtdev-devel - diffutils - wayland-protocols-devel - black # for the Python black job, optional - clang-analyzer # for the scan-build job, optional - jq # for the test suite check job, optional - rpmdevtools # for the rpm build job, optional - valgrind # for the valgrind run, optional # below packages are for the qemu runs, so optional - systemd-udev # for the qemu run - qemu-img - qemu-system-x86-core - qemu-system-aarch64-core - jq - python3-click - python3-rich - name: debian tag: *default_tag versions: - 'stable' packages: - git - gcc - g++ - pkg-config - meson - check - libudev-dev - libevdev-dev - doxygen - graphviz - python3-sphinx - python3-recommonmark - python3-sphinx-rtd-theme - python3-pytest-xdist - libwacom-dev - libcairo2-dev - libgtk-3-dev - libglib2.0-dev - libmtdev-dev - curl # for the coverity job - name: ubuntu tag: *default_tag versions: - '22.04' packages: - git - gcc - g++ - pkg-config - meson - check - libudev-dev - libevdev-dev - doxygen - graphviz - python3-sphinx - python3-recommonmark - python3-sphinx-rtd-theme - python3-pytest-xdist - libwacom-dev - libcairo2-dev - libgtk-3-dev - libglib2.0-dev - libmtdev-dev - name: arch tag: *default_tag versions: - 'rolling' packages: - git - gcc - pkgconfig - meson - check - libsystemd - libevdev - doxygen - graphviz - python-sphinx - python-recommonmark - python-sphinx_rtd_theme - python-pytest-xdist - libwacom - gtk4 - mtdev - diffutils - wayland-protocols - name: alpine tag: *default_tag versions: - 'latest' packages: - git - gcc build-base - pkgconfig - meson - check-dev - eudev-dev - libevdev-dev - libwacom-dev - cairo-dev - gtk4.0-dev - mtdev-dev - bash build: extra_variables: - "MESON_ARGS: '-Ddocumentation=false' # alpine does not have python-recommonmark" # We don't run the tests on alpine. The litest-selftest fails # for any tcase_add_exit_test/tcase_add_test_raise_signal # but someone more invested in musl will have to figure that out. - "MESON_TEST_ARGS: '' # litest-selftest fails on musl" - name: freebsd tag: *default_tag qemu_based: true versions: - '13.2' packages: - git - pkgconf - meson - libepoll-shim - libudev-devd - libevdev - libwacom - gtk3 - libmtdev - bash - wayland build: extra_variables: - "MESON_ARGS: '-Dtests=false -Ddocumentation=false' # doxygen drags down too many deps" # We don't run the tests on FreeBSD, someone would have to fix the # test suite to work on BSD first. - "MESON_TEST_ARGS: '' # test suite doesn't work on BSD yet" test_suites: - name: touchpad suites: - touchpad - name: touchpad_palm suites: - touchpad_palm - name: touchpad_dwt suites: - touchpad_dwt - name: tap suites: - touchpad_tap - name: tap-drag suites: - touchpad_tap_drag - name: tap-palm suites: - touchpad_tap_palm - name: touchpad-buttons suites: - touchpad_buttons - name: tablet suites: - tablet - name: tablet_left_handed suites: - tablet_left_handed - name: gestures suites: - gestures - name: backends suites: - path - udev - name: misc suites: - log - misc - quirks - device - name: other devices suites: - keyboard - pad - switch - trackball - trackpoint - totem - touch - name: pointer suites: - pointer b2c: version: 24beb454c62fe59143d7ceb4f5a7d25a3c029559 kernel: https://gitlab.freedesktop.org/api/v4/projects/libevdev%2Fhid-tools/packages/generic/kernel-x86_64/v6.5/bzImage libinput-1.28.1/.gitlab-ci/libinput.spec.in000066400000000000000000000112121477265155700204710ustar00rootroot00000000000000# This specfile should not be used outside the CI # Its main purpose is to sound alarm if files disappear or are added that # weren't intended. %global udevdir %(pkg-config --variable=udevdir udev) %global pipelineid @PIPELINEID@ %global gitversion @GITVERSION@ Name: libinput Version: @VERSION@ Release: %{pipelineid}git%{gitversion}%{?dist} Summary: Input device library License: MIT URL: http://www.freedesktop.org/wiki/Software/libinput/ Source0: %{name}-%{version}.tar.xz # No BuildRequires, we rely on the container setup to have # all the requires installed %description libinput is a library that handles input devices for display servers and other applications that need to directly deal with input devices. It provides device detection, device handling, input device event processing and abstraction so minimize the amount of custom input code the user of libinput need to provide the common set of functionality that users expect. %package devel Summary: Development files for %{name} Requires: %{name}%{?_isa} = %{version}-%{release} %description devel The %{name}-devel package contains libraries and header files for developing applications that use %{name}. %package utils Summary: Utilities and tools for debugging %{name} Requires: %{name}%{?_isa} = %{version}-%{release} Requires: python3-pyudev python3-libevdev %description utils The %{name}-utils package contains tools to debug hardware and analyze %{name}. %package test Summary: libinput integration test suite Requires: %{name}%{?_isa} = %{version}-%{release} %description test The %{name}-test package contains the libinput test suite. It is not intended to be run by users. %prep %autosetup -S git -n %{name}-%{version} %build %meson -Dtests=true \ -Dinstall-tests=true \ -Dudev-dir=%{udevdir} %meson_build %install %meson_install %post %{?ldconfig} %ldconfig_postun %files %doc COPYING %dir %{_sysconfdir}/libinput %{_libdir}/libinput.so.* %{udevdir}/libinput-device-group %{udevdir}/libinput-fuzz-extract %{udevdir}/libinput-fuzz-to-zero %{udevdir}/rules.d/80-libinput-device-groups.rules %{udevdir}/rules.d/90-libinput-fuzz-override.rules %{_bindir}/libinput %dir %{_libexecdir}/libinput/ %{_libexecdir}/libinput/libinput-debug-events %{_libexecdir}/libinput/libinput-list-devices %{_mandir}/man1/libinput.1* %{_datadir}/libinput/*.quirks %dir %{_datadir}/zsh %dir %{_datadir}/zsh/site-functions %{_datadir}/zsh/site-functions/* %{_mandir}/man1/libinput-list-devices.1* %{_mandir}/man1/libinput-debug-events.1* %files devel %{_includedir}/libinput.h %{_libdir}/libinput.so %{_libdir}/pkgconfig/libinput.pc %files utils %{_libexecdir}/libinput/libinput-debug-gui %{_libexecdir}/libinput/libinput-debug-tablet %{_libexecdir}/libinput/libinput-list-kernel-devices %{_libexecdir}/libinput/libinput-measure %{_libexecdir}/libinput/libinput-measure-fuzz %{_libexecdir}/libinput/libinput-measure-touchpad-tap %{_libexecdir}/libinput/libinput-measure-touchpad-pressure %{_libexecdir}/libinput/libinput-measure-touch-size %{_libexecdir}/libinput/libinput-measure-touchpad-size %{_libexecdir}/libinput/libinput-quirks %{_libexecdir}/libinput/libinput-record %{_libexecdir}/libinput/libinput-replay %{_libexecdir}/libinput/libinput-analyze %{_libexecdir}/libinput/libinput-analyze-buttons %{_libexecdir}/libinput/libinput-analyze-per-slot-delta %{_libexecdir}/libinput/libinput-analyze-recording %{_libexecdir}/libinput/libinput-analyze-touch-down-state %{_mandir}/man1/libinput-debug-gui.1* %{_mandir}/man1/libinput-debug-tablet.1* %{_mandir}/man1/libinput-list-kernel-devices.1* %{_mandir}/man1/libinput-measure.1* %{_mandir}/man1/libinput-measure-fuzz.1* %{_mandir}/man1/libinput-measure-touchpad-tap.1* %{_mandir}/man1/libinput-measure-touch-size.1* %{_mandir}/man1/libinput-measure-touchpad-size.1* %{_mandir}/man1/libinput-measure-touchpad-pressure.1* %{_mandir}/man1/libinput-quirks.1* %{_mandir}/man1/libinput-quirks-list.1* %{_mandir}/man1/libinput-quirks-validate.1* %{_mandir}/man1/libinput-record.1* %{_mandir}/man1/libinput-replay.1* %{_mandir}/man1/libinput-analyze.1* %{_mandir}/man1/libinput-analyze-buttons.1* %{_mandir}/man1/libinput-analyze-per-slot-delta.1* %{_mandir}/man1/libinput-analyze-recording.1* %{_mandir}/man1/libinput-analyze-touch-down-state.1* %files test %{_libexecdir}/libinput/libinput-test %{_libexecdir}/libinput/libinput-test-suite %{_libexecdir}/libinput/libinput-test-utils %{_mandir}/man1/libinput-test.1* %{_mandir}/man1/libinput-test-suite.1* %changelog * Wed Jul 15 2020 Peter Hutterer - Add basic spec file for package build testing libinput-1.28.1/.gitlab-ci/meson-build.sh000077500000000000000000000036401477265155700201450ustar00rootroot00000000000000#!/usr/bin/env bash # # This script is sourced from here: # https://gitlab.freedesktop.org/whot/meson-helper # # SPDX-License-Identifier: MIT set -x if [[ -f .meson_environment ]]; then . .meson_environment fi # If test args are set, we assume we want to run the tests MESON_RUN_TEST="$MESON_TEST_ARGS" while [[ $# -gt 0 ]]; do case $1 in --skip-setup) shift MESON_SKIP_SETUP="1" ;; --skip-build) shift MESON_SKIP_BUILD="1" ;; --skip-test) shift MESON_RUN_TEST="" ;; --run-test) shift MESON_RUN_TEST="1" ;; *) echo "Unknow commandline argument $1" exit 1 ;; esac done if [[ -z "$MESON_BUILDDIR" ]]; then echo "\$MESON_BUILDDIR undefined." exit 1 fi # emulate a few gitlab variables to make it easier to # run and debug locally. if [[ -z "$CI_JOB_ID" ]] || [[ -z "$CI_JOB_NAME" ]]; then echo "Missing \$CI_JOB_ID or \$CI_JOB_NAME". CI_PROJECT_NAME=$(basename "$PWD") CI_JOB_ID=$(date +%s) CI_JOB_NAME="$CI_PROJECT_NAME-job-local" echo "Simulating gitlab environment: " echo " CI_JOB_ID=$CI_JOB_ID" echo " CI_JOB_NAME=$CI_JOB_NAME" fi if [[ -n "$FDO_CI_CONCURRENT" ]]; then jobcount="-j$FDO_CI_CONCURRENT" export MESON_TESTTHREADS="$FDO_CI_CONCURRENT" fi echo "*************************************************" echo "builddir: $MESON_BUILDDIR" echo "meson args: $MESON_ARGS" echo "ninja args: $NINJA_ARGS" echo "meson test args: $MESON_TEST_ARGS" echo "job count: ${jobcount-0}" echo "*************************************************" set -e if [[ -z "$MESON_SKIP_SETUP" ]]; then rm -rf "$MESON_BUILDDIR" meson setup "$MESON_BUILDDIR" $MESON_ARGS fi meson configure "$MESON_BUILDDIR" if [[ -z "$MESON_SKIP_BUILD" ]]; then if [[ -n "$NINJA_ARGS" ]]; then ninja_args="--ninja-args $NINJA_ARGS" fi meson compile -v -C "$MESON_BUILDDIR" $jobcount $ninja_args fi if [[ -n "$MESON_RUN_TEST" ]]; then meson test -C "$MESON_BUILDDIR" $MESON_TEST_ARGS --print-errorlogs fi libinput-1.28.1/.gitlab-ci/scanbuild-plist-to-junit.py000077500000000000000000000102731477265155700226110ustar00rootroot00000000000000#!/usr/bin/env python3 # # SPDX-License-Identifier: MIT # # Usage: # $ scanbuild-plist-to-junit.py /path/to/meson-logs/scanbuild/ > junit-report.xml # # Converts the plist output from scan-build into a JUnit-compatible XML. # # For use with meson, use a wrapper script with this content: # scan-build -v --status-bugs -plist-html "$@" # then build with # SCANBUILD="/abs/path/to/wrapper.sh" ninja -C builddir scan-build # # For file context, $PWD has to be the root source directory. # # Note that the XML format is tailored towards being useful in the gitlab # CI, the JUnit format supports more features. # # This file is formatted with Python Black import argparse import plistlib import re import sys from pathlib import Path errors = [] class Error(object): pass parser = argparse.ArgumentParser( description="This tool convers scan-build's plist format to JUnit XML" ) parser.add_argument( "directory", help="Path to a scan-build output directory", type=Path ) args = parser.parse_args() if not args.directory.exists(): print(f"Invalid directory: {args.directory}", file=sys.stderr) sys.exit(1) # Meson places scan-build runs into a timestamped directory. To make it # easier to invoke this script, we just glob everything on the assumption # that there's only one scanbuild/$timestamp/ directory anyway. for file in Path(args.directory).glob("**/*.plist"): with open(file, "rb") as fd: plist = plistlib.load(fd, fmt=plistlib.FMT_XML) try: sources = plist["files"] for elem in plist["diagnostics"]: e = Error() e.type = elem["type"] # Human-readable error type e.description = elem["description"] # Longer description e.func = elem["issue_context"] # function name e.lineno = elem["location"]["line"] filename = sources[elem["location"]["file"]] # Remove the ../../../ prefix from the file e.file = re.sub(r"^(\.\./)*", "", filename) errors.append(e) except KeyError: print( "Failed to access plist content, incompatible format?", file=sys.stderr ) sys.exit(1) # Add a few lines of context for each error that we can print in the xml # output. Note that e.lineno is 1-indexed. # # If one of the files fail, we stop doing this, we're probably in the wrong # directory. try: current_file = None lines = [] for e in sorted(errors, key=lambda x: x.file): if current_file != e.file: current_file = e.file lines = open(current_file).readlines() # e.lineno is 1-indexed, lineno is our 0-indexed line number lineno = e.lineno - 1 start = max(0, lineno - 4) end = min(len(lines), lineno + 5) # end is exclusive e.context = [ f"{'>' if line == e.lineno else ' '} {line}: {content}" for line, content in zip(range(start + 1, end), lines[start:end]) ] except FileNotFoundError: pass print('') print("") if errors: suites = sorted(set([s.type for s in errors])) # Use a counter to ensure test names are unique, otherwise the CI # display ignores duplicates. counter = 0 for suite in suites: errs = [e for e in errors if e.type == suite] # Note: the grouping by suites doesn't actually do anything in gitlab. Oh well print(f'') for error in errs: print( f"""\ """ ) counter += 1 print("") else: # In case of success, add one test case so that registers in the UI # properly print('') print('') print("") print("") libinput-1.28.1/.gitlab-ci/scanbuild-wrapper.sh000077500000000000000000000000671477265155700213510ustar00rootroot00000000000000#!/bin/sh scan-build -v --status-bugs -plist-html "$@" libinput-1.28.1/.gitlab-ci/start-in-systemd.sh000077500000000000000000000031651477265155700211600ustar00rootroot00000000000000#!/usr/bin/env bash set -x systemd_target=basic.target post_command="/usr/bin/systemctl exit \$EXIT_STATUS" while [[ $# -gt 0 ]]; do case $1 in --debug-mode) shift systemd_target=multi-user.target post_command="echo you can now log in as root (no password) and then turn off by running \'/usr/bin/systemctl exit \$EXIT_STATUS\'" ;; *) echo "Unknow commandline argument $1" exit 1 ;; esac done WORKDIR=${FDO_DISTRIBUTION_WORKINGDIR:-$PWD} B2C_WORKDIR=${FDO_B2C_WORKDIR:-/app} # remove root password for debugging sed -i 's/root:!locked::/root:::/' /etc/shadow # create a libinput test suite service cat < /etc/systemd/system/libinput-testsuite.service [Unit] Description=Libinput test suite After=$systemd_target [Service] Type=simple StandardOutput=journal+console EnvironmentFile=$B2C_WORKDIR/.b2c_env WorkingDirectory=$WORKDIR ExecStart=$WORKDIR/.gitlab-ci/meson-build.sh --skip-setup --skip-build --run-test # exit the container on termination ExecStopPost=$post_command [Install] WantedBy=default.target EOF cat /etc/systemd/system/libinput-testsuite.service # enable the service systemctl enable libinput-testsuite.service # disable some services we don't need in the CI systemctl mask network-online.target systemctl mask network-pre.target systemctl mask timers.target systemctl mask dnf-makecache.timer systemctl mask systemd-logind.service systemctl mask rpmdb-migrate.service systemctl mask systemd-network-generator.service systemctl mask cryptsetup-pre.target systemctl mask cryptsetup.target #change default target systemctl set-default $systemd_target # start the system exec /usr/sbin/init libinput-1.28.1/.gitlab-ci/whitespace-check.py000077500000000000000000000054521477265155700211570ustar00rootroot00000000000000#!/usr/bin/env python3 # SPDX-License-Identifier: MIT from pathlib import Path from dataclasses import dataclass import argparse import itertools import os import sys @dataclass class WhitespaceError: message: str lineno: int nlines: int = 1 column: None | int = None ncolumns: int = 1 def test_duplicate_empty_lines(lines: list[str]) -> list[WhitespaceError]: errors = [] for idx, (l1, l2) in enumerate(itertools.pairwise(lines)): if not l1 and not l2: errors.append(WhitespaceError("Duplicated empty lines", idx, nlines=2)) return errors def test_tab_after_space(lines: list[str]) -> list[WhitespaceError]: errors = [] for idx, l in enumerate(lines): index = l.find(" \t") if index > -1: errors.append( WhitespaceError( "Tab after space", idx, nlines=index, column=index, ncolumns=2 ) ) return errors def test_trailing_whitespace(lines: list[str]) -> list[WhitespaceError]: errors = [] for idx, l in enumerate(lines): if l.rstrip() != l: errors.append(WhitespaceError("Trailing whitespace", idx)) return errors def main(): parser = argparse.ArgumentParser(description="Whitespace checker script") parser.add_argument( "files", metavar="FILES", type=Path, nargs="+", help="The files to check", ) args = parser.parse_args() have_errors: bool = False if os.isatty(sys.stderr.fileno()): red = "\x1b[0;31m" reset = "\x1b[0m" else: red = "" reset = "" for file in args.files: lines = [l.rstrip("\n") for l in file.open().readlines()] errors = [] errors.extend(test_tab_after_space(lines)) errors.extend(test_trailing_whitespace(lines)) if any(file.name.endswith(suffix) for suffix in [".c", ".h"]): if not file.parts[0] == "include": errors.extend(test_duplicate_empty_lines(lines)) for e in errors: print(f"{red}ERROR: {e.message} in {file}:{reset}", file=sys.stderr) print(f"{'-' * 72}", file=sys.stderr) lineno = max(0, e.lineno - 5) for idx, l in enumerate(lines[lineno : lineno + 10]): if e.lineno <= lineno + idx < e.lineno + e.nlines: prefix = "->" hl = red nohl = reset else: prefix = " " hl = "" nohl = "" print(f"{hl}{lineno + idx:3d}: {prefix} {l.rstrip()}{nohl}") print(f"{'-' * 72}", file=sys.stderr) if errors: have_errors = True if have_errors: sys.exit(1) if __name__ == "__main__": main() libinput-1.28.1/.gitlab/000077500000000000000000000000001477265155700147745ustar00rootroot00000000000000libinput-1.28.1/.gitlab/issue_templates/000077500000000000000000000000001477265155700202025ustar00rootroot00000000000000libinput-1.28.1/.gitlab/issue_templates/FeatureRequest.md000066400000000000000000000014021477265155700234650ustar00rootroot00000000000000 ## Summary ## Feature details ## Affected Hardware ## Implementation in Other Systems /label ~enhancement ~"needs triage" libinput-1.28.1/.gitlab/issue_templates/default.md000066400000000000000000000017001477265155700221460ustar00rootroot00000000000000## Summary ## Steps to reproduce ## Required information - libinput version: - hardware information: - `libinput record` output: do not paste, **attach** the file - `libinput debug-events --verbose` output: do not paste, **attach the file** /label ~"bug" ~"needs triage" libinput-1.28.1/.pre-commit-config.yaml000066400000000000000000000013331477265155700177350ustar00rootroot00000000000000repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - id: no-commit-to-branch args: ['--branch', 'main'] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.8.1 hooks: - id: ruff args: ['--ignore=E741,E501', '--extend-exclude=subprojects', '.'] - id: ruff-format args: ['--check', '--diff'] - repo: https://gitlab.freedesktop.org/freedesktop/ci-templates.git rev: e195d80f35b45cc73668be3767b923fd76c70ed5 hooks: - id: check-commits - id: generate-template - repo: local hooks: - id: run-sed-script name: Check for whitespace errors entry: ./.gitlab-ci/whitespace-check.py language: system libinput-1.28.1/.triage-policies.yml000066400000000000000000000234701477265155700173430ustar00rootroot00000000000000# This is a set of bugbot commands for issues and merge requests - setting any of the # bugbot::foo labels will trigger gitlab-triage to run with this ruleset (well, the # one we have on the main branch at the time) # # Note that for adding labels, the label must first created in the project. # Re-used in issues and mrs .close_needinfo: &close_needinfo name: "Close stale needinfo bugs" conditions: labels: - "bugbot::needinfo-timeout" actions: remove_labels: - "bugbot::needinfo-timeout" comment: | I'm closing this bug because some information we requested a while ago was never supplied and we're not able to continue without this information. Please feel free to re-open. status: "close" .remind_needinfo: &remind_needinfo name: "Remind users of needinfo bugs" conditions: labels: - "bugbot::needinfo-reminder" actions: labels: - "waiting on reporter" remove_labels: - "bugbot::needinfo-reminder" comment: | Hi. This is a friendly reminder that the maintainers are waiting on some information by you (or maybe someone cc'd on this bug). If the information is not provided we may not be able to proceed with this issue or merge request. Please check the recent comments, thanks. .help_needed: &help_needed name: "Remind users help is needed" conditions: labels: - "bugbot::help-needed" actions: labels: - "help needed" remove_labels: - "bugbot::help-needed" comment: | Hi. This issue or merge request needs help. This simply means that for the foreseeable future, the maintainers will not have time to work on this. If this is a request for a new feature, then the feature is unlikely to be implemented unless you or another contributor files a merge request. If a merge request already exists maybe it needs finishing which often involves adding documentation or tests. If this is an issue affecting a specific device then it is unlikely to be fixed. This may be because it requires specific hardware to reproduce or it may be that the use case is niche enough that the maintainers do not have time to implement it. In short, to resolve this issue or get this merge request into libinput help is needed. .libinput_record: &libinput_record name: "Request libinput record output" conditions: labels: - "bugbot::libinput-record" actions: remove_labels: - "bugbot::libinput-record" comment: | Looks like we may need some extra information. Please **attach** (do not paste) the full output of `libinput record` and `libinput debug-events --verbose` (if you haven't yet). The [documentation](https://wayland.freedesktop.org/libinput/doc/latest/tools.html#libinput-record-and-libinput-replay) has some information on what we're looking for to be able to triage bugs. .hid_recorder: &hid_recorder name: "Request hid-recorder output" conditions: labels: - "bugbot::hid-recorder" actions: remove_labels: - "bugbot::hid-recorder" comment: | Looks like we may need some extra information that isn't yet available in this issue. Please **attach** (do not paste) the output of [`hid-recorder`](https://github.com/hidutils/hid-recorder/) for this device (run `sudo hid-recorder` without argument and it will let you pick the device). This should show the data the kernel receives from the device and may provide a hint on what's going on here. .udev_hid_bpf: &udev_hid_bpf name: "Punt to udev-hid-bpf" conditions: labels: - "bugbot::udev-hid-bpf" actions: remove_labels: - "bugbot::udev-hid-bpf" comment: | This issue looks like it could or should be fixed with [udev-hid-bpf](https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/). udev-hid-bpf is a collection of BPF programs that modify the HID Report Descriptor and/or HID Reports from the device, making it possible to change the properties of a device and/or the events to make them compatible with the expectations the kernel and userspace has of such devices. Please see the [udev-hid-bpf documentation](https://libevdev.pages.freedesktop.org/udev-hid-bpf/) for details and/or in particular the [udev-hid-bpf tutorial](https://libevdev.pages.freedesktop.org/udev-hid-bpf/tutorial.html) if you need to enable a new device. status: "close" resource_rules: issues: rules: - name: "Close kernel bugs" conditions: labels: - "bugbot::kernel" actions: labels: - "kernel" remove_labels: - "bugbot::kernel" comment: | This bug looks like a kernel issue and it cannot be fixed in libinput directly. I'm closing this bug but do feel free to continue discussing the issue here. Kernel bugs are usually best sent to the [`linux-input` list](https://lore.kernel.org/linux-input/). status: "close" - name: "Expect a merge request" conditions: labels: - "bugbot::expect-mr" actions: remove_labels: - "bugbot::expect-mr" comment: | I'm closing this bug in anticipation of a merge request that fixes this issue. If you are a new contributor, please see [the freedesktop.org wiki](https://gitlab.freedesktop.org/freedesktop/freedesktop/-/wikis/home) on how to get permissions to fork a project and file a merge request. The [libinput documentation](https://wayland.freedesktop.org/libinput/doc/latest/contributing.html) also has more details on how to get started. status: "close" - name: "Point to 60-evdev.hwdb" conditions: labels: - "bugbot::evdev-hwdb" actions: remove_labels: - "bugbot::evdev-hwdb" comment: | Looks like this issue may be solved with a device-specific entry in systemd's hwdb. You should have a /usr/lib/udev/hwdb.d/60-evdev.hwdb file which includes those quirks. Please see the top of the file for instructions and follow those. Once the quirk is confirmed working this issue (or parts thereof) should be fixed and you can submit a pull request to the [systemd](https://github.com/systemd/systemd/) repository to get that quirk included. Please link to the systemd issue here, thanks. I'm closing this issue now, if the hwdb entry does not fix this issue here, please re-open. status: "close" - name: "Close bug for reopening" conditions: labels: - "bugbot::close" actions: remove_labels: - "bugbot::close" comment: | I'm temporarily closing this bug. The bug may not be fixed yet (see any comments above) and we **want you to reopen it when/if it becomes actionable again**. This process may feel unfamiliar but unfortunately closing/re-opening is the only action all GitLab users are permitted to do. So we close it, you re-open it when whatever above has been addressed and then we know we need to look at it again. This issue may be closed more than once in a similar fashion but I only leave this comment once since now you understand how it works. :smile: For a detailed explanation on the how and why of this process please see the [Closed Issues wiki page](https://gitlab.freedesktop.org/libinput/libinput/-/wikis/Closed-Issues). status: "close" - *udev_hid_bpf - *libinput_record - *hid_recorder - *close_needinfo - *remind_needinfo - *help_needed merge_requests: rules: - name: "Remind contributor of commit rules" conditions: labels: - "bugbot::commit-rules" actions: remove_labels: - "bugbot::commit-rules" comment: | Hi. Looks like the pipeline failed because one or more of the commits in this MR do not meet our requirements. Most commonly this the format of the commit message itself. The "Test summary" above has the details. Please see [our docs for commit messages](https://wayland.freedesktop.org/libinput/doc/latest/contributing.html#commit-messages) and [our docs for submitting code](https://wayland.freedesktop.org/libinput/doc/latest/contributing.html#submitting-code) that explain how to amend and force-push to this repo. - name: "Remind contributor that info needs to be in commit messages" conditions: labels: - "bugbot::info-in-commit-message" actions: remove_labels: - "bugbot::info-in-commit-message" comment: | Hi. Thanks for the merge request. I'm here to request that you add some documentation about this merge request to the **commit message** (or messages). You may have already written some in the merge request description and in many cases it's fine to copy/paste that into the commit message(s). The reason is simple: once merged, no-one really looks at this this page here anymore. The git log on the other hand is what developers will use to understand the code so the information must be quickly accessible via git. Please see [our docs for submitting code](https://wayland.freedesktop.org/libinput/doc/latest/contributing.html#submitting-code) that explain how to amend and force-push to this repo. - *udev_hid_bpf - *libinput_record - *hid_recorder - *close_needinfo - *remind_needinfo - *help_needed libinput-1.28.1/.vimdir000066400000000000000000000000611477265155700147440ustar00rootroot00000000000000set noexpandtab shiftwidth=8 cinoptions=:0,+0,(0 libinput-1.28.1/CODING_STYLE.md000066400000000000000000000132061477265155700157230ustar00rootroot00000000000000# Coding style - Indentation in tabs, 8 characters wide, spaces after the tabs where vertical alignment is required (see below) **Note: this file uses spaces due to markdown rendering issues for tabs. Code must be implemented using tabs.** - Max line width 80ch, do not break up printed strings though - Break up long lines at logical groupings, one line for each logical group ```c int a = somelongname() + someotherlongname(); if (a < 0 && (b > 20 & d < 10) && d != 0.0) somelongfunctioncall(arg1, arg2, arg3); ``` - Function declarations: return type on separate line, {} on separate line, arguments broken up as above. ```c static inline int foobar(int a, int b) { } void somenamethatiswaytoolong(int a, int b, int c) { } ``` - `/* comments only */`, no `// comments` - `variable_name`, not `VariableName` or `variableName`. same for functions. - no typedefs of structs, enums, unions - if it generates a compiler warning, it needs to be fixed - if it generates a static checker warning, it needs to be fixed or commented - declare variables when they are used first and try to keep them as local as possible. Exception: basic loop variables, e.g. for (int i = 0; ...) should always be declared inside the loop even where multiple loops exist ```c int a; if (foo) { int b = 10; a = get_value(); usevalue(a, b); } if (bar) { a = get_value(); useit(a); } int c = a * 100; useit(c); ``` - avoid uninitialized variables where possible, declare them late instead. Note that most of libinput predates this style, try to stick with the code around you if in doubt. wrong: ```c int *a; int b = 7; ... some code ... a = zalloc(32); ``` right: ```c int b = 7; ... some code ... int *a = zalloc(32); ``` - avoid calling non-obvious functions inside declaration blocks for multiple variables. bad: ```c { int a = 7; int b = some_complicated_function(); int *c = zalloc(32); } ``` better: ```c { int a = 7; int *c = zalloc(32); int b = some_complicated_function(); } ``` There is a bit of gut-feeling involved with this, but the goal is to make the variable values immediately recognizable. - Where statements are near-identical and repeated, try to keep them identical: bad: ```c int a = get_some_value(x++); do_something(a); a = get_some_value(x++); do_something(a); a = get_some_value(x++); do_something(a); ``` better: ```c int a; a = = get_some_value(x++); do_something(a); a = get_some_value(x++); do_something(a); a = get_some_value(x++); do_something(a); ``` - if/else: { on the same line, no curly braces if both blocks are a single statement. If either if or else block are multiple statements, both must have curly braces. ```c if (foo) { blah(); bar(); } else { a = 10; } ``` - public functions MUST be doxygen-commented, use doxygen's `@foo` rather than `\foo` notation - `#include "config.h"` comes first, followed by system headers, followed by external library headers, followed by internal headers. sort alphabetically where it makes sense (specifically system headers) ```c #include "config.h" #include #include #include #include "libinput-private.h" ``` - goto jumps only to the end of the function, and only for good reasons (usually cleanup). goto never jumps backwards - Use stdbool.h's bool for booleans within the library (instead of `int`). Exception: the public API uses int, not bool. # Git commit message requirements Our CI will check the commit messages for a few requirements. Below is the list of what we expect from a git commit. ## Commit message content A [good commit message](http://who-t.blogspot.com/2009/12/on-commit-messages.html) needs to answer three questions: - Why is it necessary? It may fix a bug, it may add a feature, it may improve performance, reliabilty, stability, or just be a change for the sake of correctness. - How does it address the issue? For short obvious patches this part can be omitted, but it should be a high level description of what the approach was. - What effects does the patch have? (In addition to the obvious ones, this may include benchmarks, side effects, etc.) These three questions establish the context for the actual code changes, put reviewers and others into the frame of mind to look at the diff and check if the approach chosen was correct. A good commit message also helps maintainers to decide if a given patch is suitable for stable branches or inclusion in a distribution. ## Commit message format The canonical git commit message format is: ``` one line as the subject line with a high-level note full explanation of the patch follows after an empty line. This explanation can be multiple paragraphs and is largely free-form. Markdown is not supported. You can include extra data where required like: - benchmark one says 10s - benchmark two says 12s ``` The subject line is the first thing everyone sees about this commit, so make sure it's on point. ## Commit message technical requirements - The commit message should use present tense (not past tense). Do write "change foo to bar", not "changed foo to bar". - The text width of the commit should be 78 chars or less, especially the subject line. - The author must be the name you usually identify as and email address. We do not accept the default `@users.noreply` gitlab addresses. ``` git config --global user.name Your Name git config --global user.email your@email ``` libinput-1.28.1/CONTRIBUTING.md000066400000000000000000000003161477265155700157050ustar00rootroot00000000000000Thank you for your interest in contributing to libinput. Please find more information about how to contribute in [the documentation](https://wayland.freedesktop.org/libinput/doc/latest/contributing.html). libinput-1.28.1/COPYING000066400000000000000000000033121477265155700145060ustar00rootroot00000000000000Copyright © 2006-2009 Simon Thum Copyright © 2008-2012 Kristian Høgsberg Copyright © 2010-2012 Intel Corporation Copyright © 2010-2011 Benjamin Franzke Copyright © 2011-2012 Collabora, Ltd. Copyright © 2013-2014 Jonas Ådahl Copyright © 2013-2015 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libinput ships a copy of the GPL-licensed Linux kernel's linux/input.h header file. [1] This does not make libinput GPL. This copy is provided to provide consistent behavior regardless which kernel version libinput is compiled against. The header is used during compilation only, libinput does not link against GPL libraries. [1] https://gitlab.freedesktop.org/libinput/libinput/blob/main/include/linux/input.h libinput-1.28.1/README.md000066400000000000000000000062541477265155700147420ustar00rootroot00000000000000libinput ======== libinput is a library that provides a full input stack for display servers and other applications that need to handle input devices provided by the kernel. libinput provides device detection, event handling and abstraction to minimize the amount of custom input code the user of libinput needs to provide the common set of functionality that users expect. Input event processing includes scaling touch coordinates, generating relative pointer events from touchpads, pointer acceleration, etc. User documentation ------------------ Documentation explaining features available in libinput is available [here](https://wayland.freedesktop.org/libinput/doc/latest/features.html). This includes the [FAQ](https://wayland.freedesktop.org/libinput/doc/latest/faqs.html) and the instructions on [reporting bugs](https://wayland.freedesktop.org/libinput/doc/latest/reporting-bugs.html). Source code ----------- The source code of libinput can be found at: https://gitlab.freedesktop.org/libinput/libinput For a list of current and past releases visit: https://www.freedesktop.org/wiki/Software/libinput/ Build instructions: https://wayland.freedesktop.org/libinput/doc/latest/building.html Reporting Bugs -------------- Bugs can be filed on freedesktop.org GitLab: https://gitlab.freedesktop.org/libinput/libinput/issues/ Where possible, please provide the `libinput record` output of the input device and/or the event sequence in question. See https://wayland.freedesktop.org/libinput/doc/latest/reporting-bugs.html for more info. Documentation ------------- - Developer API documentation: https://wayland.freedesktop.org/libinput/doc/latest/development.html - High-level documentation about libinput's features: https://wayland.freedesktop.org/libinput/doc/latest/features.html - Build instructions: https://wayland.freedesktop.org/libinput/doc/latest/building.html - Documentation for previous versions of libinput: https://wayland.freedesktop.org/libinput/doc/ Examples of how to use libinput are the debugging tools in the libinput repository. Developers are encouraged to look at those tools for a real-world (yet simple) example on how to use libinput. - A commandline debugging tool: https://gitlab.freedesktop.org/libinput/libinput/tree/main/tools/libinput-debug-events.c - A GTK application that draws cursor/touch/tablet positions: https://gitlab.freedesktop.org/libinput/libinput/tree/main/tools/libinput-debug-gui.c License ------- libinput is licensed under the MIT license. > Permission is hereby granted, free of charge, to any person obtaining a > copy of this software and associated documentation files (the "Software"), > to deal in the Software without restriction, including without limitation > the rights to use, copy, modify, merge, publish, distribute, sublicense, > and/or sell copies of the Software, and to permit persons to whom the > Software is furnished to do so, subject to the following conditions: [...] See the [COPYING](https://gitlab.freedesktop.org/libinput/libinput/tree/main/COPYING) file for the full license information. About ----- Documentation generated from git commit [__GIT_VERSION__](https://gitlab.freedesktop.org/libinput/libinput/commit/__GIT_VERSION__) libinput-1.28.1/completion/000077500000000000000000000000001477265155700156255ustar00rootroot00000000000000libinput-1.28.1/completion/zsh/000077500000000000000000000000001477265155700164315ustar00rootroot00000000000000libinput-1.28.1/completion/zsh/_libinput000066400000000000000000000222261477265155700203450ustar00rootroot00000000000000#compdef libinput (( $+functions[_libinput_commands] )) || _libinput_commands() { local -a commands commands=( "list-devices:List all devices recognized by libinput" "debug-events:Print all events as seen by libinput" "debug-gui:Show a GUI to visualize libinput's events" "debug-tablet:Show tablet axis and button values" "measure:Measure various properties of devices" "analyze:Analyze device data" "record:Record the events from a device" "replay:Replay the events from a device" ) _describe -t commands 'command' commands } __all_seats() { # Obviously only works with logind local -a seats seats=${(f)"$(loginctl --no-legend --no-pager list-seats 2>/dev/null)"} if [[ -z $seats ]]; then # Can always offer seat0, even if we can't enumerate the seats compadd "$@" - seat0 else compadd "$@" - $seats fi } (( $+functions[_libinput_list-devices] )) || _libinput_list-devices() { _arguments \ '--help[Show help and exit]' \ '--version[show version information and exit]' } (( $+functions[_libinput_debug-events] )) || _libinput_debug-events() { _arguments \ '--help[Show debug-events help and exit]' \ '--quiet[Only print libinput messages and nothing from this tool]' \ '--verbose[Use verbose output]' \ '--show-keycodes[Make all keycodes visible]' \ '--grab[Exclusively grab all opened devices]' \ '--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \ '--udev=[Listen for notifications on the given seat]:seat:__all_seats' \ '--apply-to=[Apply configuration options where the device name matches the pattern]:pattern' \ '--disable-sendevents=[Disable send-events option for the devices matching the pattern]:pattern' \ '--set-area=[Set the desired area as "x1/y1 x2/y2" (within [0.0, 1.0]) ]' \ '--set-calibration=[Set the first 6 elements of the 3x3 calibration matrix ("1.0 0.0 0.0 0.0 1.0 0.0")]' \ '--set-click-method=[Set the desired click method]:click-method:(none clickfinger buttonareas)' \ '--set-clickfinger-map=[Set button mapping for clickfinger]:tap-map:(( \ lrm\:2-fingers\ right-click\ /\ 3-fingers\ middle-click \ lmr\:2-fingers\ middle-click\ /\ 3-fingers\ right-click \ ))' \ '--set-pressure-range=[Set the tablet tool pressure range (within range \[0.0, 1.0\])]' \ '--set-profile=[Set pointer acceleration profile]:accel-profile:(adaptive flat custom)' \ '--set-rotation-angle=[Set the rotation angle in degrees]' \ '--set-scroll-button=[Set the button to the given button code]' \ '--set-scroll-method=[Set the desired scroll method]:scroll-method:(none twofinger edge button)' \ '--set-speed=[Set pointer acceleration speed (within range \[-1, 1\])]' \ '--set-tap-map=[Set button mapping for tapping]:tap-map:(( \ lrm\:2-fingers\ right-click\ /\ 3-fingers\ middle-click \ lmr\:2-fingers\ middle-click\ /\ 3-fingers\ right-click \ ))' \ + '(custom pointer acceleration)' \ '--set-custom-points=[Set n points defining a custom acceleration function]' \ '--set-custom-step=[Set the distance along the x axis between the custom points]' \ '--set-custom-type=[Set the type of the acceleration function]:custom-type:(fallback motion scroll)' \ + '(drag)' \ '--enable-drag[Enable tap-and-drag]' \ '--disable-drag[Disable tap-and-drag]' \ + '(drag-lock)' \ '--enable-drag-lock[Enable drag-lock]' \ '--disable-drag-lock[Disable drag-lock]' \ + '(dwt)' \ '--enable-dwt[Enable disable-while-typing]' \ '--disable-dwt[Disable disable-while-typing]' \ + '(dwtp)' \ '--enable-dwtp[Enable disable-while-trackpointing]' \ '--disable-dwtp[Disable disable-while-trackpointing]' \ + '(left-handed)' \ '--enable-left-handed[Enable left handed button configuration]' \ '--disable-left-handed[Disable left handed button configuration]' \ + '(middlebutton)' \ '--enable-middlebutton[Enable middle button emulation]' \ '--disable-middlebutton[Disable middle button emulation]' \ + '(natural-scrolling)' \ '--enable-natural-scrolling[Enable natural scrolling]' \ '--disable-natural-scrolling[Disable natural scrolling]' \ + '(tap-to-click)' \ '--enable-tap[Enable tap-to-click]' \ '--disable-tap[Disable tap-to-click]' } (( $+functions[_libinput_debug-gui] )) || _libinput_debug-gui() { _arguments \ '--help[Show debug-gui help and exit]' \ '--verbose[Use verbose output]' \ '--grab[Exclusively grab all opened devices]' \ '--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \ '--udev=[Listen for notifications on the given seat]:seat:_libinput_all_seats' } (( $+functions[_libinput_debug-tablet] )) || _libinput_debug-tablet() { _arguments \ '--help[Show debug-tablet help and exit]' \ '--device=[Use the given device with the path backend]:device:_files -W /dev/input/ -P /dev/input/' \ '--udev=[Use the first tablet device on the given seat]:seat:_libinput_all_seats' } (( $+functions[_libinput_measure] )) || _libinput_measure() { local curcontext=$curcontext state line ret=1 local features features=( "fuzz:Measure touch fuzz to avoid pointer jitter" "touch-size:Measure touch size and orientation" "touchpad-tap:Measure tap-to-click time" "touchpad-pressure:Measure touch pressure" ) _arguments -C \ '--help[Print help and exit]' \ ':feature:->feature' \ '*:: :->option-or-argument' case $state in (feature) _describe -t features 'feature' features ;; (option-or-argument) curcontext=${curcontext%:*:*}:libinput-measure-$words[1]: if ! _call_function ret _libinput_measure_$words[1]; then _message "unknown feature: $words[1]" fi ;; esac return ret } (( $+functions[_libinput_measure_fuzz] )) || _libinput_measure_fuzz() { _arguments \ '--help[Show help message and exit]' \ ':device:_files -W /dev/input/ -P /dev/input/' } (( $+functions[_libinput_measure_touch-size] )) || _libinput_measure_touch-size() { _arguments \ '--help[Show help message and exit]' \ '--touch-threshold=[Assume a touch pressure threshold of "down:up"]' \ '--palm-threshold=[Assume a palm threshold of N]' \ ':device:_files -W /dev/input/ -P /dev/input/' } (( $+functions[_libinput_measure_touchpad-pressure] )) || _libinput_measure_touchpad-pressure() { _arguments \ '--help[Show help message and exit]' \ '--touch-threshold=[Assume a touch pressure threshold of "down:up"]' \ '--palm-threshold=[Assume a palm threshold of N]' \ ':device:_files -W /dev/input/ -P /dev/input/' } (( $+functions[_libinput_measure_touchpad-tap] )) || _libinput_measure_touchpad-tap() { _arguments \ '--help[Show help message and exit]' \ '--format=dat[Specify the data format to be printed. The default is "summary"]' ':device:_files -W /dev/input/ -P /dev/input/' } (( $+functions[_libinput_analyze_per-slot-delta] )) || _libinput_analyze_per-slot-delta() { _arguments \ '--help[Show help message and exit]' \ ':recording:_files' } (( $+functions[_libinput_analyze_touch-down-state] )) || _libinput_analyze_touch-down-state() { _arguments \ '--help[Show help message and exit]' \ ':recording:_files' } (( $+functions[_libinput_analyze_recording] )) || _libinput_analyze_recording() { _arguments \ '--help[Show help message and exit]' \ ':recording:_files' } (( $+functions[_libinput_analyze] )) || _libinput_analyze() { local curcontext=$curcontext state line ret=1 local features features=( "per-slot-delta:analyze relative movement per touch per slot" "recording:analyze a recording by printing a pretty table" "touch-down-state:analyze a recording for logical touch down states" ) _arguments -C \ '--help[Print help and exit]' \ ':feature:->feature' \ '*:: :->option-or-argument' case $state in (feature) _describe -t features 'feature' features ;; (option-or-argument) curcontext=${curcontext%:*:*}:libinput-analyze-$words[1]: if ! _call_function ret _libinput_analyze_$words[1]; then _message "unknown feature: $words[1]" fi ;; esac return ret } (( $+functions[_libinput_record] )) || _libinput_record() { _arguments \ '--help[Show help message and exit]' \ '--all[Record all /dev/input/event* devices available on the system]' \ '--autorestart=[Terminate the current recording after s seconds of device inactivity]' \ {-o+,--output=}'[Specify the output file to use]:file:_files -g "*.yml"' \ '--multiple[Record multiple devices at once]' \ '--show-keycodes[Show keycodes as-is in the recording]' \ '--with-libinput[Record libinput events alongside device events]' \ '--with-hidraw[Record hidraw events alongside device events]' \ '*::device:_files -W /dev/input/ -P /dev/input/' } (( $+functions[_libinput_replay] )) || _libinput_replay() { _arguments \ '--help[Show help message and exit]' \ ':recording:_files' } _libinput() { local curcontext=$curcontext state line ret=1 _arguments -C \ {-h,--help}'[Show help message and exit]' \ '--version[Show version information and exit]' \ ':command:->command' \ '*:: :->option-or-argument' && return case $state in (command) _libinput_commands && ret=0 ;; (option-or-argument) curcontext=${curcontext%:*:*}:libinput-$words[1]: if ! _call_function ret _libinput_$words[1]; then _message "unknown libinput command: $words[1]" fi ;; esac return ret } _libinput libinput-1.28.1/completion/zsh/meson.build000066400000000000000000000004321477265155700205720ustar00rootroot00000000000000zshcompletiondir = get_option('zshcompletiondir') if zshcompletiondir == '' zshcompletiondir = get_option('datadir') / 'zsh' / 'site-functions' endif if zshcompletiondir != 'no' install_data( '_libinput', install_dir: zshcompletiondir, install_mode: 'rw-r--r--', ) endif libinput-1.28.1/doc/000077500000000000000000000000001477265155700142215ustar00rootroot00000000000000libinput-1.28.1/doc/api/000077500000000000000000000000001477265155700147725ustar00rootroot00000000000000libinput-1.28.1/doc/api/libinput.doxygen.in000066400000000000000000000022551477265155700206300ustar00rootroot00000000000000PROJECT_NAME = @PACKAGE_NAME@ PROJECT_NUMBER = @PACKAGE_VERSION@ PROJECT_BRIEF = "A wrapper library for input devices" JAVADOC_AUTOBRIEF = YES TAB_SIZE = 8 OPTIMIZE_OUTPUT_FOR_C = YES EXTRACT_ALL = YES EXTRACT_STATIC = YES MAX_INITIALIZER_LINES = 0 WARNINGS = YES QUIET = YES INPUT = "@builddir@" IMAGE_PATH = "@builddir@" OUTPUT_DIRECTORY = doc GENERATE_HTML = YES HTML_OUTPUT = html SEARCHENGINE = NO USE_MATHJAX = YES MATHJAX_RELPATH = https://cdn.mathjax.org/mathjax/latest GENERATE_LATEX = NO MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES PREDEFINED = LIBINPUT_ATTRIBUTE_PRINTF(f, a)= \ LIBINPUT_ATTRIBUTE_DEPRECATED DOTFILE_DIRS = "@builddir@" EXAMPLE_PATH = "@builddir@" SHOW_NAMESPACES = NO HAVE_DOT = YES HTML_HEADER = "@builddir@/header.html" HTML_FOOTER = "@builddir@/footer.html" HTML_EXTRA_STYLESHEET = "@builddir@/bootstrap.css" \ "@builddir@/customdoxygen.css" \ "@builddir@/libinputdoxygen.css" libinput-1.28.1/doc/api/mainpage.dox000066400000000000000000000074741477265155700173030ustar00rootroot00000000000000/** @mainpage This is the libinput API reference. This documentation is aimed at developers of Wayland compositors. User documentation is available [here](https://wayland.freedesktop.org/libinput/doc/latest). @section concepts Concepts @subsection concepts_initialization Initialization of a libinput context libinput provides two different backends: - a @ref libinput_udev_create_context "udev backend" where notifications about new and removed devices are provided by udev, and - a @ref libinput_path_create_context "path backend" where @ref libinput_path_add_device "device addition" and @ref libinput_path_remove_device "device removal" need to be handled by the caller. See section @ref base for information about initializing a libinput context. @subsection concepts_events Monitoring for events libinput exposes a single @ref libinput_get_fd "file descriptor" to the caller. This file descriptor should be monitored by the caller, whenever data is available the caller **must** immediately call libinput_dispatch(). Failure to do so will result in erroneous behavior. libinput_dispatch() may result in one or more events being available to the caller. After libinput_dispatch() a caller **should** call libinput_get_event() to retrieve and process this event. Whenever libinput_get_event() returns `NULL`, no further events are available. See section @ref event for more information about events. @subsection concepts_seats Device grouping into seats All devices are grouped into physical and logical seats. Button and key states are available per-device and per-seat. See @ref seat for more information. @subsection concepts_devices Device capabilities libinput does not use device types. All devices have @ref libinput_device_has_capability "capabilities" that define which events may be generated. See @ref device for more information about devices. Specific event types include: - @ref event_keyboard - @ref event_pointer - @ref event_touch - @ref event_gesture - @ref event_tablet - @ref event_tablet_pad - @ref event_switch @subsection concepts_configuration Device configuration libinput relies on the caller for device configuration. See @ref config for more information. @subsection example An example libinput program The simplest libinput program looks like this: @code static int open_restricted(const char *path, int flags, void *user_data) { int fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *user_data) { close(fd); } const static struct libinput_interface interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; int main(void) { struct libinput *li; struct libinput_event *event; li = libinput_udev_create_context(&interface, NULL, udev); libinput_udev_assign_seat(li, "seat0"); libinput_dispatch(li); while ((event = libinput_get_event(li)) != NULL) { // handle the event here libinput_event_destroy(event); libinput_dispatch(li); } libinput_unref(li); return 0; } @endcode @section building_against Building against libinput libinput provides a [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) file. Software that uses libinput should use pkg-config and the `PKG_CHECK_MODULES` autoconf macro. Otherwise, the most rudimentary way to compile and link a program against libinput is: @verbatim gcc -o myprogram myprogram.c `pkg-config --cflags --libs libinput` @endverbatim For further information on using pkgconfig see the pkg-config documentation. @section stability Backwards-compatibility libinput promises backwards-compatibility across all the 1.x.y version. An application built against libinput 1.x.y will work with any future 1.*.* release. @section About Documentation generated from git commit [__GIT_VERSION__](https://gitlab.freedesktop.org/libinput/libinput/commit/__GIT_VERSION__) */ libinput-1.28.1/doc/api/meson.build000066400000000000000000000027251477265155700171420ustar00rootroot00000000000000prg_install = find_program('install') doxygen = find_program('doxygen', required : false) if not doxygen.found() error('Program "doxygen" not found or not executable. Try building with -Ddocumentation=false') endif dot = find_program('dot', required : false) if not dot.found() error('Program "dot" not found or not executable. Try building with -Ddocumentation=false') endif mainpage = vcs_tag(command : ['git', 'log', '-1', '--format=%h'], fallback : 'unknown', input : 'mainpage.dox', output : 'mainpage.dox', replace_string: '__GIT_VERSION__') src_doxygen = files( # source files '../../src/libinput.h', # style files 'style/header.html', 'style/footer.html', 'style/customdoxygen.css', 'style/bootstrap.css', 'style/libinputdoxygen.css', ) doxyfiles = [] foreach f : src_doxygen df = configure_file(input: f, output: '@PLAINNAME@', copy : true) doxyfiles += [ df ] endforeach doc_config = configuration_data() doc_config.set('PACKAGE_NAME', meson.project_name()) doc_config.set('PACKAGE_VERSION', meson.project_version()) doc_config.set('builddir', meson.current_build_dir()) doxyfile = configure_file(input : 'libinput.doxygen.in', output : 'libinput.doxygen', configuration : doc_config) custom_target('doxygen', input : [ doxyfiles, doxyfile, mainpage ] + src_doxygen, output : [ 'html' ], command : [ doxygen, doxyfile ], install : false, depends: [ mainpage ], build_by_default : true) libinput-1.28.1/doc/api/page-hierarchy.dox000066400000000000000000000000711477265155700203740ustar00rootroot00000000000000/** @page Tablets - @subpage tablet serial numbers */ libinput-1.28.1/doc/api/style/000077500000000000000000000000001477265155700161325ustar00rootroot00000000000000libinput-1.28.1/doc/api/style/LICENSE000066400000000000000000000275151477265155700171510ustar00rootroot00000000000000These licenses apply to the doxygen documentation HTML style only. They do not apply or affect libinput itself. Apache: https://github.com/Velron/doxygen-bootstrapped/ MIT: https://bootswatch.com/paper/bootstrap.css Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. The MIT License (MIT) Copyright (c) 2011-2015 Twitter, Inc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libinput-1.28.1/doc/api/style/bootstrap.css000066400000000000000000005061041477265155700206670ustar00rootroot00000000000000@import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"); /*! * bootswatch v3.3.5 * Homepage: http://bootswatch.com * Copyright 2012-2015 Thomas Park * Licensed under MIT * Based on Bootstrap */ /*! * Bootstrap v3.3.5 (http://getbootstrap.com) * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } body { margin: 0; } article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary { display: block; } audio, canvas, progress, video { display: inline-block; vertical-align: baseline; } audio:not([controls]) { display: none; height: 0; } [hidden], template { display: none; } a { background-color: transparent; } a:active, a:hover { outline: 0; } abbr[title] { border-bottom: 1px dotted; } b, strong { font-weight: bold; } dfn { font-style: italic; } h1 { font-size: 2em; margin: 0.67em 0; } mark { background: #ff0; color: #000; } small { font-size: 80%; } sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } img { border: 0; } svg:not(:root) { overflow: hidden; } figure { margin: 1em 40px; } hr { -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; height: 0; } pre { overflow: auto; } code, kbd, pre, samp { font-family: monospace, monospace; font-size: 1em; } button, input, optgroup, select, textarea { color: inherit; font: inherit; margin: 0; } button { overflow: visible; } button, select { text-transform: none; } button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; cursor: pointer; } button[disabled], html input[disabled] { cursor: default; } button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } input { line-height: normal; } input[type="checkbox"], input[type="radio"] { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 0; } input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { height: auto; } input[type="search"] { -webkit-appearance: textfield; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; } input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } legend { border: 0; padding: 0; } textarea { overflow: auto; } optgroup { font-weight: bold; } table { border-collapse: collapse; border-spacing: 0; } td, th { padding: 0; } /*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */ @media print { *, *:before, *:after { background: transparent !important; color: #000 !important; -webkit-box-shadow: none !important; box-shadow: none !important; text-shadow: none !important; } a, a:visited { text-decoration: underline; } a[href]:after { content: " (" attr(href) ")"; } abbr[title]:after { content: " (" attr(title) ")"; } a[href^="#"]:after, a[href^="javascript:"]:after { content: ""; } pre, blockquote { border: 1px solid #999; page-break-inside: avoid; } thead { display: table-header-group; } tr, img { page-break-inside: avoid; } img { max-width: 100% !important; } p, h2, h3 { orphans: 3; widows: 3; } h2, h3 { page-break-after: avoid; } .navbar { display: none; } .btn > .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px solid #000; } .table { border-collapse: collapse !important; } .table td, .table th { background-color: #fff !important; } .table-bordered th, .table-bordered td { border: 1px solid #ddd !important; } } @font-face { font-family: 'Glyphicons Halflings'; src: url('../fonts/glyphicons-halflings-regular.eot'); src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg'); } .glyphicon { position: relative; top: 1px; display: inline-block; font-family: 'Glyphicons Halflings'; font-style: normal; font-weight: normal; line-height: 1; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .glyphicon-asterisk:before { content: "\2a"; } .glyphicon-plus:before { content: "\2b"; } .glyphicon-euro:before, .glyphicon-eur:before { content: "\20ac"; } .glyphicon-minus:before { content: "\2212"; } .glyphicon-cloud:before { content: "\2601"; } .glyphicon-envelope:before { content: "\2709"; } .glyphicon-pencil:before { content: "\270f"; } .glyphicon-glass:before { content: "\e001"; } .glyphicon-music:before { content: "\e002"; } .glyphicon-search:before { content: "\e003"; } .glyphicon-heart:before { content: "\e005"; } .glyphicon-star:before { content: "\e006"; } .glyphicon-star-empty:before { content: "\e007"; } .glyphicon-user:before { content: "\e008"; } .glyphicon-film:before { content: "\e009"; } .glyphicon-th-large:before { content: "\e010"; } .glyphicon-th:before { content: "\e011"; } .glyphicon-th-list:before { content: "\e012"; } .glyphicon-ok:before { content: "\e013"; } .glyphicon-remove:before { content: "\e014"; } .glyphicon-zoom-in:before { content: "\e015"; } .glyphicon-zoom-out:before { content: "\e016"; } .glyphicon-off:before { content: "\e017"; } .glyphicon-signal:before { content: "\e018"; } .glyphicon-cog:before { content: "\e019"; } .glyphicon-trash:before { content: "\e020"; } .glyphicon-home:before { content: "\e021"; } .glyphicon-file:before { content: "\e022"; } .glyphicon-time:before { content: "\e023"; } .glyphicon-road:before { content: "\e024"; } .glyphicon-download-alt:before { content: "\e025"; } .glyphicon-download:before { content: "\e026"; } .glyphicon-upload:before { content: "\e027"; } .glyphicon-inbox:before { content: "\e028"; } .glyphicon-play-circle:before { content: "\e029"; } .glyphicon-repeat:before { content: "\e030"; } .glyphicon-refresh:before { content: "\e031"; } .glyphicon-list-alt:before { content: "\e032"; } .glyphicon-lock:before { content: "\e033"; } .glyphicon-flag:before { content: "\e034"; } .glyphicon-headphones:before { content: "\e035"; } .glyphicon-volume-off:before { content: "\e036"; } .glyphicon-volume-down:before { content: "\e037"; } .glyphicon-volume-up:before { content: "\e038"; } .glyphicon-qrcode:before { content: "\e039"; } .glyphicon-barcode:before { content: "\e040"; } .glyphicon-tag:before { content: "\e041"; } .glyphicon-tags:before { content: "\e042"; } .glyphicon-book:before { content: "\e043"; } .glyphicon-bookmark:before { content: "\e044"; } .glyphicon-print:before { content: "\e045"; } .glyphicon-camera:before { content: "\e046"; } .glyphicon-font:before { content: "\e047"; } .glyphicon-bold:before { content: "\e048"; } .glyphicon-italic:before { content: "\e049"; } .glyphicon-text-height:before { content: "\e050"; } .glyphicon-text-width:before { content: "\e051"; } .glyphicon-align-left:before { content: "\e052"; } .glyphicon-align-center:before { content: "\e053"; } .glyphicon-align-right:before { content: "\e054"; } .glyphicon-align-justify:before { content: "\e055"; } .glyphicon-list:before { content: "\e056"; } .glyphicon-indent-left:before { content: "\e057"; } .glyphicon-indent-right:before { content: "\e058"; } .glyphicon-facetime-video:before { content: "\e059"; } .glyphicon-picture:before { content: "\e060"; } .glyphicon-map-marker:before { content: "\e062"; } .glyphicon-adjust:before { content: "\e063"; } .glyphicon-tint:before { content: "\e064"; } .glyphicon-edit:before { content: "\e065"; } .glyphicon-share:before { content: "\e066"; } .glyphicon-check:before { content: "\e067"; } .glyphicon-move:before { content: "\e068"; } .glyphicon-step-backward:before { content: "\e069"; } .glyphicon-fast-backward:before { content: "\e070"; } .glyphicon-backward:before { content: "\e071"; } .glyphicon-play:before { content: "\e072"; } .glyphicon-pause:before { content: "\e073"; } .glyphicon-stop:before { content: "\e074"; } .glyphicon-forward:before { content: "\e075"; } .glyphicon-fast-forward:before { content: "\e076"; } .glyphicon-step-forward:before { content: "\e077"; } .glyphicon-eject:before { content: "\e078"; } .glyphicon-chevron-left:before { content: "\e079"; } .glyphicon-chevron-right:before { content: "\e080"; } .glyphicon-plus-sign:before { content: "\e081"; } .glyphicon-minus-sign:before { content: "\e082"; } .glyphicon-remove-sign:before { content: "\e083"; } .glyphicon-ok-sign:before { content: "\e084"; } .glyphicon-question-sign:before { content: "\e085"; } .glyphicon-info-sign:before { content: "\e086"; } .glyphicon-screenshot:before { content: "\e087"; } .glyphicon-remove-circle:before { content: "\e088"; } .glyphicon-ok-circle:before { content: "\e089"; } .glyphicon-ban-circle:before { content: "\e090"; } .glyphicon-arrow-left:before { content: "\e091"; } .glyphicon-arrow-right:before { content: "\e092"; } .glyphicon-arrow-up:before { content: "\e093"; } .glyphicon-arrow-down:before { content: "\e094"; } .glyphicon-share-alt:before { content: "\e095"; } .glyphicon-resize-full:before { content: "\e096"; } .glyphicon-resize-small:before { content: "\e097"; } .glyphicon-exclamation-sign:before { content: "\e101"; } .glyphicon-gift:before { content: "\e102"; } .glyphicon-leaf:before { content: "\e103"; } .glyphicon-fire:before { content: "\e104"; } .glyphicon-eye-open:before { content: "\e105"; } .glyphicon-eye-close:before { content: "\e106"; } .glyphicon-warning-sign:before { content: "\e107"; } .glyphicon-plane:before { content: "\e108"; } .glyphicon-calendar:before { content: "\e109"; } .glyphicon-random:before { content: "\e110"; } .glyphicon-comment:before { content: "\e111"; } .glyphicon-magnet:before { content: "\e112"; } .glyphicon-chevron-up:before { content: "\e113"; } .glyphicon-chevron-down:before { content: "\e114"; } .glyphicon-retweet:before { content: "\e115"; } .glyphicon-shopping-cart:before { content: "\e116"; } .glyphicon-folder-close:before { content: "\e117"; } .glyphicon-folder-open:before { content: "\e118"; } .glyphicon-resize-vertical:before { content: "\e119"; } .glyphicon-resize-horizontal:before { content: "\e120"; } .glyphicon-hdd:before { content: "\e121"; } .glyphicon-bullhorn:before { content: "\e122"; } .glyphicon-bell:before { content: "\e123"; } .glyphicon-certificate:before { content: "\e124"; } .glyphicon-thumbs-up:before { content: "\e125"; } .glyphicon-thumbs-down:before { content: "\e126"; } .glyphicon-hand-right:before { content: "\e127"; } .glyphicon-hand-left:before { content: "\e128"; } .glyphicon-hand-up:before { content: "\e129"; } .glyphicon-hand-down:before { content: "\e130"; } .glyphicon-circle-arrow-right:before { content: "\e131"; } .glyphicon-circle-arrow-left:before { content: "\e132"; } .glyphicon-circle-arrow-up:before { content: "\e133"; } .glyphicon-circle-arrow-down:before { content: "\e134"; } .glyphicon-globe:before { content: "\e135"; } .glyphicon-wrench:before { content: "\e136"; } .glyphicon-tasks:before { content: "\e137"; } .glyphicon-filter:before { content: "\e138"; } .glyphicon-briefcase:before { content: "\e139"; } .glyphicon-fullscreen:before { content: "\e140"; } .glyphicon-dashboard:before { content: "\e141"; } .glyphicon-paperclip:before { content: "\e142"; } .glyphicon-heart-empty:before { content: "\e143"; } .glyphicon-link:before { content: "\e144"; } .glyphicon-phone:before { content: "\e145"; } .glyphicon-pushpin:before { content: "\e146"; } .glyphicon-usd:before { content: "\e148"; } .glyphicon-gbp:before { content: "\e149"; } .glyphicon-sort:before { content: "\e150"; } .glyphicon-sort-by-alphabet:before { content: "\e151"; } .glyphicon-sort-by-alphabet-alt:before { content: "\e152"; } .glyphicon-sort-by-order:before { content: "\e153"; } .glyphicon-sort-by-order-alt:before { content: "\e154"; } .glyphicon-sort-by-attributes:before { content: "\e155"; } .glyphicon-sort-by-attributes-alt:before { content: "\e156"; } .glyphicon-unchecked:before { content: "\e157"; } .glyphicon-expand:before { content: "\e158"; } .glyphicon-collapse-down:before { content: "\e159"; } .glyphicon-collapse-up:before { content: "\e160"; } .glyphicon-log-in:before { content: "\e161"; } .glyphicon-flash:before { content: "\e162"; } .glyphicon-log-out:before { content: "\e163"; } .glyphicon-new-window:before { content: "\e164"; } .glyphicon-record:before { content: "\e165"; } .glyphicon-save:before { content: "\e166"; } .glyphicon-open:before { content: "\e167"; } .glyphicon-saved:before { content: "\e168"; } .glyphicon-import:before { content: "\e169"; } .glyphicon-export:before { content: "\e170"; } .glyphicon-send:before { content: "\e171"; } .glyphicon-floppy-disk:before { content: "\e172"; } .glyphicon-floppy-saved:before { content: "\e173"; } .glyphicon-floppy-remove:before { content: "\e174"; } .glyphicon-floppy-save:before { content: "\e175"; } .glyphicon-floppy-open:before { content: "\e176"; } .glyphicon-credit-card:before { content: "\e177"; } .glyphicon-transfer:before { content: "\e178"; } .glyphicon-cutlery:before { content: "\e179"; } .glyphicon-header:before { content: "\e180"; } .glyphicon-compressed:before { content: "\e181"; } .glyphicon-earphone:before { content: "\e182"; } .glyphicon-phone-alt:before { content: "\e183"; } .glyphicon-tower:before { content: "\e184"; } .glyphicon-stats:before { content: "\e185"; } .glyphicon-sd-video:before { content: "\e186"; } .glyphicon-hd-video:before { content: "\e187"; } .glyphicon-subtitles:before { content: "\e188"; } .glyphicon-sound-stereo:before { content: "\e189"; } .glyphicon-sound-dolby:before { content: "\e190"; } .glyphicon-sound-5-1:before { content: "\e191"; } .glyphicon-sound-6-1:before { content: "\e192"; } .glyphicon-sound-7-1:before { content: "\e193"; } .glyphicon-copyright-mark:before { content: "\e194"; } .glyphicon-registration-mark:before { content: "\e195"; } .glyphicon-cloud-download:before { content: "\e197"; } .glyphicon-cloud-upload:before { content: "\e198"; } .glyphicon-tree-conifer:before { content: "\e199"; } .glyphicon-tree-deciduous:before { content: "\e200"; } .glyphicon-cd:before { content: "\e201"; } .glyphicon-save-file:before { content: "\e202"; } .glyphicon-open-file:before { content: "\e203"; } .glyphicon-level-up:before { content: "\e204"; } .glyphicon-copy:before { content: "\e205"; } .glyphicon-paste:before { content: "\e206"; } .glyphicon-alert:before { content: "\e209"; } .glyphicon-equalizer:before { content: "\e210"; } .glyphicon-king:before { content: "\e211"; } .glyphicon-queen:before { content: "\e212"; } .glyphicon-pawn:before { content: "\e213"; } .glyphicon-bishop:before { content: "\e214"; } .glyphicon-knight:before { content: "\e215"; } .glyphicon-baby-formula:before { content: "\e216"; } .glyphicon-tent:before { content: "\26fa"; } .glyphicon-blackboard:before { content: "\e218"; } .glyphicon-bed:before { content: "\e219"; } .glyphicon-apple:before { content: "\f8ff"; } .glyphicon-erase:before { content: "\e221"; } .glyphicon-hourglass:before { content: "\231b"; } .glyphicon-lamp:before { content: "\e223"; } .glyphicon-duplicate:before { content: "\e224"; } .glyphicon-piggy-bank:before { content: "\e225"; } .glyphicon-scissors:before { content: "\e226"; } .glyphicon-bitcoin:before { content: "\e227"; } .glyphicon-btc:before { content: "\e227"; } .glyphicon-xbt:before { content: "\e227"; } .glyphicon-yen:before { content: "\00a5"; } .glyphicon-jpy:before { content: "\00a5"; } .glyphicon-ruble:before { content: "\20bd"; } .glyphicon-rub:before { content: "\20bd"; } .glyphicon-scale:before { content: "\e230"; } .glyphicon-ice-lolly:before { content: "\e231"; } .glyphicon-ice-lolly-tasted:before { content: "\e232"; } .glyphicon-education:before { content: "\e233"; } .glyphicon-option-horizontal:before { content: "\e234"; } .glyphicon-option-vertical:before { content: "\e235"; } .glyphicon-menu-hamburger:before { content: "\e236"; } .glyphicon-modal-window:before { content: "\e237"; } .glyphicon-oil:before { content: "\e238"; } .glyphicon-grain:before { content: "\e239"; } .glyphicon-sunglasses:before { content: "\e240"; } .glyphicon-text-size:before { content: "\e241"; } .glyphicon-text-color:before { content: "\e242"; } .glyphicon-text-background:before { content: "\e243"; } .glyphicon-object-align-top:before { content: "\e244"; } .glyphicon-object-align-bottom:before { content: "\e245"; } .glyphicon-object-align-horizontal:before { content: "\e246"; } .glyphicon-object-align-left:before { content: "\e247"; } .glyphicon-object-align-vertical:before { content: "\e248"; } .glyphicon-object-align-right:before { content: "\e249"; } .glyphicon-triangle-right:before { content: "\e250"; } .glyphicon-triangle-left:before { content: "\e251"; } .glyphicon-triangle-bottom:before { content: "\e252"; } .glyphicon-triangle-top:before { content: "\e253"; } .glyphicon-console:before { content: "\e254"; } .glyphicon-superscript:before { content: "\e255"; } .glyphicon-subscript:before { content: "\e256"; } .glyphicon-menu-left:before { content: "\e257"; } .glyphicon-menu-right:before { content: "\e258"; } .glyphicon-menu-down:before { content: "\e259"; } .glyphicon-menu-up:before { content: "\e260"; } * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } html { font-size: 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 1.846; color: #666666; background-color: #ffffff; } input, button, select, textarea { font-family: inherit; font-size: inherit; line-height: inherit; } a { color: #2196f3; text-decoration: none; } a:hover, a:focus { color: #0a6ebd; text-decoration: underline; } a:focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } figure { margin: 0; } img { vertical-align: middle; } .img-responsive, .thumbnail > img, .thumbnail a > img, .carousel-inner > .item > img, .carousel-inner > .item > a > img { display: block; max-width: 100%; height: auto; } .img-rounded { border-radius: 3px; } .img-thumbnail { padding: 4px; line-height: 1.846; background-color: #ffffff; border: 1px solid #dddddd; border-radius: 3px; -webkit-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; display: inline-block; max-width: 100%; height: auto; } .img-circle { border-radius: 50%; } hr { margin-top: 23px; margin-bottom: 23px; border: 0; border-top: 1px solid #eeeeee; } .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; } .sr-only-focusable:active, .sr-only-focusable:focus { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; } [role="button"] { cursor: pointer; } h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-family: inherit; font-weight: 400; line-height: 1.1; color: #444444; } h1 small, h2 small, h3 small, h4 small, h5 small, h6 small, .h1 small, .h2 small, .h3 small, .h4 small, .h5 small, .h6 small, h1 .small, h2 .small, h3 .small, h4 .small, h5 .small, h6 .small, .h1 .small, .h2 .small, .h3 .small, .h4 .small, .h5 .small, .h6 .small { font-weight: normal; line-height: 1; color: #bbbbbb; } h1, .h1, h2, .h2, h3, .h3 { margin-top: 23px; margin-bottom: 11.5px; } h1 small, .h1 small, h2 small, .h2 small, h3 small, .h3 small, h1 .small, .h1 .small, h2 .small, .h2 .small, h3 .small, .h3 .small { font-size: 65%; } h4, .h4, h5, .h5, h6, .h6 { margin-top: 11.5px; margin-bottom: 11.5px; } h4 small, .h4 small, h5 small, .h5 small, h6 small, .h6 small, h4 .small, .h4 .small, h5 .small, .h5 .small, h6 .small, .h6 .small { font-size: 75%; } h1, .h1 { font-size: 56px; } h2, .h2 { font-size: 45px; } h3, .h3 { font-size: 34px; } h4, .h4 { font-size: 24px; } h5, .h5 { font-size: 20px; } h6, .h6 { font-size: 14px; } p { margin: 0 0 11.5px; } .lead { margin-bottom: 23px; font-size: 14px; font-weight: 300; line-height: 1.4; } @media (min-width: 768px) { .lead { font-size: 19.5px; } } small, .small { font-size: 92%; } mark, .mark { background-color: #ffe0b2; padding: .2em; } .text-left { text-align: left; } .text-right { text-align: right; } .text-center { text-align: center; } .text-justify { text-align: justify; } .text-nowrap { white-space: nowrap; } .text-lowercase { text-transform: lowercase; } .text-uppercase { text-transform: uppercase; } .text-capitalize { text-transform: capitalize; } .text-muted { color: #bbbbbb; } .text-primary { color: #2196f3; } a.text-primary:hover, a.text-primary:focus { color: #0c7cd5; } .text-success { color: #4caf50; } a.text-success:hover, a.text-success:focus { color: #3d8b40; } .text-info { color: #9c27b0; } a.text-info:hover, a.text-info:focus { color: #771e86; } .text-warning { color: #ff9800; } a.text-warning:hover, a.text-warning:focus { color: #cc7a00; } .text-danger { color: #e51c23; } a.text-danger:hover, a.text-danger:focus { color: #b9151b; } .bg-primary { color: #fff; background-color: #2196f3; } a.bg-primary:hover, a.bg-primary:focus { background-color: #0c7cd5; } .bg-success { background-color: #dff0d8; } a.bg-success:hover, a.bg-success:focus { background-color: #c1e2b3; } .bg-info { background-color: #e1bee7; } a.bg-info:hover, a.bg-info:focus { background-color: #d099d9; } .bg-warning { background-color: #ffe0b2; } a.bg-warning:hover, a.bg-warning:focus { background-color: #ffcb7f; } .bg-danger { background-color: #f9bdbb; } a.bg-danger:hover, a.bg-danger:focus { background-color: #f5908c; } .page-header { padding-bottom: 10.5px; margin: 46px 0 23px; border-bottom: 1px solid #eeeeee; } ul, ol { margin-top: 0; margin-bottom: 11.5px; } ul ul, ol ul, ul ol, ol ol { margin-bottom: 0; } .list-unstyled { padding-left: 0; list-style: none; } .list-inline { padding-left: 0; list-style: none; margin-left: -5px; } .list-inline > li { display: inline-block; padding-left: 5px; padding-right: 5px; } dl { margin-top: 0; margin-bottom: 23px; } dt, dd { line-height: 1.846; } dt { font-weight: bold; } dd { margin-left: 0; } @media (min-width: 768px) { .dl-horizontal dt { float: left; width: 160px; clear: left; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .dl-horizontal dd { margin-left: 180px; } } abbr[title], abbr[data-original-title] { cursor: help; border-bottom: 1px dotted #bbbbbb; } .initialism { font-size: 90%; text-transform: uppercase; } blockquote { padding: 11.5px 23px; margin: 0 0 23px; font-size: 16.25px; border-left: 5px solid #eeeeee; } blockquote p:last-child, blockquote ul:last-child, blockquote ol:last-child { margin-bottom: 0; } blockquote footer, blockquote small, blockquote .small { display: block; font-size: 80%; line-height: 1.846; color: #bbbbbb; } blockquote footer:before, blockquote small:before, blockquote .small:before { content: '\2014 \00A0'; } .blockquote-reverse, blockquote.pull-right { padding-right: 15px; padding-left: 0; border-right: 5px solid #eeeeee; border-left: 0; text-align: right; } .blockquote-reverse footer:before, blockquote.pull-right footer:before, .blockquote-reverse small:before, blockquote.pull-right small:before, .blockquote-reverse .small:before, blockquote.pull-right .small:before { content: ''; } .blockquote-reverse footer:after, blockquote.pull-right footer:after, .blockquote-reverse small:after, blockquote.pull-right small:after, .blockquote-reverse .small:after, blockquote.pull-right .small:after { content: '\00A0 \2014'; } address { margin-bottom: 23px; font-style: normal; line-height: 1.846; } code, kbd, pre, samp { font-family: Menlo, Monaco, Consolas, "Courier New", monospace; } code { padding: 2px 4px; font-size: 90%; color: #c7254e; background-color: #f9f2f4; border-radius: 3px; } kbd { padding: 2px 4px; font-size: 90%; color: #ffffff; background-color: #333333; border-radius: 3px; -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25); } kbd kbd { padding: 0; font-size: 100%; font-weight: bold; -webkit-box-shadow: none; box-shadow: none; } pre { display: block; padding: 11px; margin: 0 0 11.5px; font-size: 12px; line-height: 1.846; word-break: break-all; word-wrap: break-word; color: #212121; background-color: #f5f5f5; border: 1px solid #cccccc; border-radius: 3px; } pre code { padding: 0; font-size: inherit; color: inherit; white-space: pre-wrap; background-color: transparent; border-radius: 0; } .pre-scrollable { max-height: 340px; overflow-y: scroll; } .container { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px; } @media (min-width: 768px) { .container { width: 750px; } } @media (min-width: 992px) { .container { width: 970px; } } @media (min-width: 1200px) { .container { width: 1170px; } } .container-fluid { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px; } .row { margin-left: -15px; margin-right: -15px; } .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 { position: relative; min-height: 1px; padding-left: 15px; padding-right: 15px; } .col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 { float: left; } .col-xs-12 { width: 100%; } .col-xs-11 { width: 91.66666667%; } .col-xs-10 { width: 83.33333333%; } .col-xs-9 { width: 75%; } .col-xs-8 { width: 66.66666667%; } .col-xs-7 { width: 58.33333333%; } .col-xs-6 { width: 50%; } .col-xs-5 { width: 41.66666667%; } .col-xs-4 { width: 33.33333333%; } .col-xs-3 { width: 25%; } .col-xs-2 { width: 16.66666667%; } .col-xs-1 { width: 8.33333333%; } .col-xs-pull-12 { right: 100%; } .col-xs-pull-11 { right: 91.66666667%; } .col-xs-pull-10 { right: 83.33333333%; } .col-xs-pull-9 { right: 75%; } .col-xs-pull-8 { right: 66.66666667%; } .col-xs-pull-7 { right: 58.33333333%; } .col-xs-pull-6 { right: 50%; } .col-xs-pull-5 { right: 41.66666667%; } .col-xs-pull-4 { right: 33.33333333%; } .col-xs-pull-3 { right: 25%; } .col-xs-pull-2 { right: 16.66666667%; } .col-xs-pull-1 { right: 8.33333333%; } .col-xs-pull-0 { right: auto; } .col-xs-push-12 { left: 100%; } .col-xs-push-11 { left: 91.66666667%; } .col-xs-push-10 { left: 83.33333333%; } .col-xs-push-9 { left: 75%; } .col-xs-push-8 { left: 66.66666667%; } .col-xs-push-7 { left: 58.33333333%; } .col-xs-push-6 { left: 50%; } .col-xs-push-5 { left: 41.66666667%; } .col-xs-push-4 { left: 33.33333333%; } .col-xs-push-3 { left: 25%; } .col-xs-push-2 { left: 16.66666667%; } .col-xs-push-1 { left: 8.33333333%; } .col-xs-push-0 { left: auto; } .col-xs-offset-12 { margin-left: 100%; } .col-xs-offset-11 { margin-left: 91.66666667%; } .col-xs-offset-10 { margin-left: 83.33333333%; } .col-xs-offset-9 { margin-left: 75%; } .col-xs-offset-8 { margin-left: 66.66666667%; } .col-xs-offset-7 { margin-left: 58.33333333%; } .col-xs-offset-6 { margin-left: 50%; } .col-xs-offset-5 { margin-left: 41.66666667%; } .col-xs-offset-4 { margin-left: 33.33333333%; } .col-xs-offset-3 { margin-left: 25%; } .col-xs-offset-2 { margin-left: 16.66666667%; } .col-xs-offset-1 { margin-left: 8.33333333%; } .col-xs-offset-0 { margin-left: 0%; } @media (min-width: 768px) { .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 { float: left; } .col-sm-12 { width: 100%; } .col-sm-11 { width: 91.66666667%; } .col-sm-10 { width: 83.33333333%; } .col-sm-9 { width: 75%; } .col-sm-8 { width: 66.66666667%; } .col-sm-7 { width: 58.33333333%; } .col-sm-6 { width: 50%; } .col-sm-5 { width: 41.66666667%; } .col-sm-4 { width: 33.33333333%; } .col-sm-3 { width: 25%; } .col-sm-2 { width: 16.66666667%; } .col-sm-1 { width: 8.33333333%; } .col-sm-pull-12 { right: 100%; } .col-sm-pull-11 { right: 91.66666667%; } .col-sm-pull-10 { right: 83.33333333%; } .col-sm-pull-9 { right: 75%; } .col-sm-pull-8 { right: 66.66666667%; } .col-sm-pull-7 { right: 58.33333333%; } .col-sm-pull-6 { right: 50%; } .col-sm-pull-5 { right: 41.66666667%; } .col-sm-pull-4 { right: 33.33333333%; } .col-sm-pull-3 { right: 25%; } .col-sm-pull-2 { right: 16.66666667%; } .col-sm-pull-1 { right: 8.33333333%; } .col-sm-pull-0 { right: auto; } .col-sm-push-12 { left: 100%; } .col-sm-push-11 { left: 91.66666667%; } .col-sm-push-10 { left: 83.33333333%; } .col-sm-push-9 { left: 75%; } .col-sm-push-8 { left: 66.66666667%; } .col-sm-push-7 { left: 58.33333333%; } .col-sm-push-6 { left: 50%; } .col-sm-push-5 { left: 41.66666667%; } .col-sm-push-4 { left: 33.33333333%; } .col-sm-push-3 { left: 25%; } .col-sm-push-2 { left: 16.66666667%; } .col-sm-push-1 { left: 8.33333333%; } .col-sm-push-0 { left: auto; } .col-sm-offset-12 { margin-left: 100%; } .col-sm-offset-11 { margin-left: 91.66666667%; } .col-sm-offset-10 { margin-left: 83.33333333%; } .col-sm-offset-9 { margin-left: 75%; } .col-sm-offset-8 { margin-left: 66.66666667%; } .col-sm-offset-7 { margin-left: 58.33333333%; } .col-sm-offset-6 { margin-left: 50%; } .col-sm-offset-5 { margin-left: 41.66666667%; } .col-sm-offset-4 { margin-left: 33.33333333%; } .col-sm-offset-3 { margin-left: 25%; } .col-sm-offset-2 { margin-left: 16.66666667%; } .col-sm-offset-1 { margin-left: 8.33333333%; } .col-sm-offset-0 { margin-left: 0%; } } @media (min-width: 992px) { .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { float: left; } .col-md-12 { width: 100%; } .col-md-11 { width: 91.66666667%; } .col-md-10 { width: 83.33333333%; } .col-md-9 { width: 75%; } .col-md-8 { width: 66.66666667%; } .col-md-7 { width: 58.33333333%; } .col-md-6 { width: 50%; } .col-md-5 { width: 41.66666667%; } .col-md-4 { width: 33.33333333%; } .col-md-3 { width: 25%; } .col-md-2 { width: 16.66666667%; } .col-md-1 { width: 8.33333333%; } .col-md-pull-12 { right: 100%; } .col-md-pull-11 { right: 91.66666667%; } .col-md-pull-10 { right: 83.33333333%; } .col-md-pull-9 { right: 75%; } .col-md-pull-8 { right: 66.66666667%; } .col-md-pull-7 { right: 58.33333333%; } .col-md-pull-6 { right: 50%; } .col-md-pull-5 { right: 41.66666667%; } .col-md-pull-4 { right: 33.33333333%; } .col-md-pull-3 { right: 25%; } .col-md-pull-2 { right: 16.66666667%; } .col-md-pull-1 { right: 8.33333333%; } .col-md-pull-0 { right: auto; } .col-md-push-12 { left: 100%; } .col-md-push-11 { left: 91.66666667%; } .col-md-push-10 { left: 83.33333333%; } .col-md-push-9 { left: 75%; } .col-md-push-8 { left: 66.66666667%; } .col-md-push-7 { left: 58.33333333%; } .col-md-push-6 { left: 50%; } .col-md-push-5 { left: 41.66666667%; } .col-md-push-4 { left: 33.33333333%; } .col-md-push-3 { left: 25%; } .col-md-push-2 { left: 16.66666667%; } .col-md-push-1 { left: 8.33333333%; } .col-md-push-0 { left: auto; } .col-md-offset-12 { margin-left: 100%; } .col-md-offset-11 { margin-left: 91.66666667%; } .col-md-offset-10 { margin-left: 83.33333333%; } .col-md-offset-9 { margin-left: 75%; } .col-md-offset-8 { margin-left: 66.66666667%; } .col-md-offset-7 { margin-left: 58.33333333%; } .col-md-offset-6 { margin-left: 50%; } .col-md-offset-5 { margin-left: 41.66666667%; } .col-md-offset-4 { margin-left: 33.33333333%; } .col-md-offset-3 { margin-left: 25%; } .col-md-offset-2 { margin-left: 16.66666667%; } .col-md-offset-1 { margin-left: 8.33333333%; } .col-md-offset-0 { margin-left: 0%; } } @media (min-width: 1200px) { .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 { float: left; } .col-lg-12 { width: 100%; } .col-lg-11 { width: 91.66666667%; } .col-lg-10 { width: 83.33333333%; } .col-lg-9 { width: 75%; } .col-lg-8 { width: 66.66666667%; } .col-lg-7 { width: 58.33333333%; } .col-lg-6 { width: 50%; } .col-lg-5 { width: 41.66666667%; } .col-lg-4 { width: 33.33333333%; } .col-lg-3 { width: 25%; } .col-lg-2 { width: 16.66666667%; } .col-lg-1 { width: 8.33333333%; } .col-lg-pull-12 { right: 100%; } .col-lg-pull-11 { right: 91.66666667%; } .col-lg-pull-10 { right: 83.33333333%; } .col-lg-pull-9 { right: 75%; } .col-lg-pull-8 { right: 66.66666667%; } .col-lg-pull-7 { right: 58.33333333%; } .col-lg-pull-6 { right: 50%; } .col-lg-pull-5 { right: 41.66666667%; } .col-lg-pull-4 { right: 33.33333333%; } .col-lg-pull-3 { right: 25%; } .col-lg-pull-2 { right: 16.66666667%; } .col-lg-pull-1 { right: 8.33333333%; } .col-lg-pull-0 { right: auto; } .col-lg-push-12 { left: 100%; } .col-lg-push-11 { left: 91.66666667%; } .col-lg-push-10 { left: 83.33333333%; } .col-lg-push-9 { left: 75%; } .col-lg-push-8 { left: 66.66666667%; } .col-lg-push-7 { left: 58.33333333%; } .col-lg-push-6 { left: 50%; } .col-lg-push-5 { left: 41.66666667%; } .col-lg-push-4 { left: 33.33333333%; } .col-lg-push-3 { left: 25%; } .col-lg-push-2 { left: 16.66666667%; } .col-lg-push-1 { left: 8.33333333%; } .col-lg-push-0 { left: auto; } .col-lg-offset-12 { margin-left: 100%; } .col-lg-offset-11 { margin-left: 91.66666667%; } .col-lg-offset-10 { margin-left: 83.33333333%; } .col-lg-offset-9 { margin-left: 75%; } .col-lg-offset-8 { margin-left: 66.66666667%; } .col-lg-offset-7 { margin-left: 58.33333333%; } .col-lg-offset-6 { margin-left: 50%; } .col-lg-offset-5 { margin-left: 41.66666667%; } .col-lg-offset-4 { margin-left: 33.33333333%; } .col-lg-offset-3 { margin-left: 25%; } .col-lg-offset-2 { margin-left: 16.66666667%; } .col-lg-offset-1 { margin-left: 8.33333333%; } .col-lg-offset-0 { margin-left: 0%; } } table { background-color: transparent; } caption { padding-top: 8px; padding-bottom: 8px; color: #bbbbbb; text-align: left; } th { text-align: left; } .table { width: 100%; max-width: 100%; margin-bottom: 23px; } .table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td { padding: 8px; line-height: 1.846; vertical-align: top; border-top: 1px solid #dddddd; } .table > thead > tr > th { vertical-align: bottom; border-bottom: 2px solid #dddddd; } .table > caption + thead > tr:first-child > th, .table > colgroup + thead > tr:first-child > th, .table > thead:first-child > tr:first-child > th, .table > caption + thead > tr:first-child > td, .table > colgroup + thead > tr:first-child > td, .table > thead:first-child > tr:first-child > td { border-top: 0; } .table > tbody + tbody { border-top: 2px solid #dddddd; } .table .table { background-color: #ffffff; } .table-condensed > thead > tr > th, .table-condensed > tbody > tr > th, .table-condensed > tfoot > tr > th, .table-condensed > thead > tr > td, .table-condensed > tbody > tr > td, .table-condensed > tfoot > tr > td { padding: 5px; } .table-bordered { border: 1px solid #dddddd; } .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td { border: 1px solid #dddddd; } .table-bordered > thead > tr > th, .table-bordered > thead > tr > td { border-bottom-width: 2px; } .table-striped > tbody > tr:nth-of-type(odd) { background-color: #f9f9f9; } .table-hover > tbody > tr:hover { background-color: #f5f5f5; } table col[class*="col-"] { position: static; float: none; display: table-column; } table td[class*="col-"], table th[class*="col-"] { position: static; float: none; display: table-cell; } .table > thead > tr > td.active, .table > tbody > tr > td.active, .table > tfoot > tr > td.active, .table > thead > tr > th.active, .table > tbody > tr > th.active, .table > tfoot > tr > th.active, .table > thead > tr.active > td, .table > tbody > tr.active > td, .table > tfoot > tr.active > td, .table > thead > tr.active > th, .table > tbody > tr.active > th, .table > tfoot > tr.active > th { background-color: #f5f5f5; } .table-hover > tbody > tr > td.active:hover, .table-hover > tbody > tr > th.active:hover, .table-hover > tbody > tr.active:hover > td, .table-hover > tbody > tr:hover > .active, .table-hover > tbody > tr.active:hover > th { background-color: #e8e8e8; } .table > thead > tr > td.success, .table > tbody > tr > td.success, .table > tfoot > tr > td.success, .table > thead > tr > th.success, .table > tbody > tr > th.success, .table > tfoot > tr > th.success, .table > thead > tr.success > td, .table > tbody > tr.success > td, .table > tfoot > tr.success > td, .table > thead > tr.success > th, .table > tbody > tr.success > th, .table > tfoot > tr.success > th { background-color: #dff0d8; } .table-hover > tbody > tr > td.success:hover, .table-hover > tbody > tr > th.success:hover, .table-hover > tbody > tr.success:hover > td, .table-hover > tbody > tr:hover > .success, .table-hover > tbody > tr.success:hover > th { background-color: #d0e9c6; } .table > thead > tr > td.info, .table > tbody > tr > td.info, .table > tfoot > tr > td.info, .table > thead > tr > th.info, .table > tbody > tr > th.info, .table > tfoot > tr > th.info, .table > thead > tr.info > td, .table > tbody > tr.info > td, .table > tfoot > tr.info > td, .table > thead > tr.info > th, .table > tbody > tr.info > th, .table > tfoot > tr.info > th { background-color: #e1bee7; } .table-hover > tbody > tr > td.info:hover, .table-hover > tbody > tr > th.info:hover, .table-hover > tbody > tr.info:hover > td, .table-hover > tbody > tr:hover > .info, .table-hover > tbody > tr.info:hover > th { background-color: #d8abe0; } .table > thead > tr > td.warning, .table > tbody > tr > td.warning, .table > tfoot > tr > td.warning, .table > thead > tr > th.warning, .table > tbody > tr > th.warning, .table > tfoot > tr > th.warning, .table > thead > tr.warning > td, .table > tbody > tr.warning > td, .table > tfoot > tr.warning > td, .table > thead > tr.warning > th, .table > tbody > tr.warning > th, .table > tfoot > tr.warning > th { background-color: #ffe0b2; } .table-hover > tbody > tr > td.warning:hover, .table-hover > tbody > tr > th.warning:hover, .table-hover > tbody > tr.warning:hover > td, .table-hover > tbody > tr:hover > .warning, .table-hover > tbody > tr.warning:hover > th { background-color: #ffd699; } .table > thead > tr > td.danger, .table > tbody > tr > td.danger, .table > tfoot > tr > td.danger, .table > thead > tr > th.danger, .table > tbody > tr > th.danger, .table > tfoot > tr > th.danger, .table > thead > tr.danger > td, .table > tbody > tr.danger > td, .table > tfoot > tr.danger > td, .table > thead > tr.danger > th, .table > tbody > tr.danger > th, .table > tfoot > tr.danger > th { background-color: #f9bdbb; } .table-hover > tbody > tr > td.danger:hover, .table-hover > tbody > tr > th.danger:hover, .table-hover > tbody > tr.danger:hover > td, .table-hover > tbody > tr:hover > .danger, .table-hover > tbody > tr.danger:hover > th { background-color: #f7a6a4; } .table-responsive { overflow-x: auto; min-height: 0.01%; } @media screen and (max-width: 767px) { .table-responsive { width: 100%; margin-bottom: 17.25px; overflow-y: hidden; -ms-overflow-style: -ms-autohiding-scrollbar; border: 1px solid #dddddd; } .table-responsive > .table { margin-bottom: 0; } .table-responsive > .table > thead > tr > th, .table-responsive > .table > tbody > tr > th, .table-responsive > .table > tfoot > tr > th, .table-responsive > .table > thead > tr > td, .table-responsive > .table > tbody > tr > td, .table-responsive > .table > tfoot > tr > td { white-space: nowrap; } .table-responsive > .table-bordered { border: 0; } .table-responsive > .table-bordered > thead > tr > th:first-child, .table-responsive > .table-bordered > tbody > tr > th:first-child, .table-responsive > .table-bordered > tfoot > tr > th:first-child, .table-responsive > .table-bordered > thead > tr > td:first-child, .table-responsive > .table-bordered > tbody > tr > td:first-child, .table-responsive > .table-bordered > tfoot > tr > td:first-child { border-left: 0; } .table-responsive > .table-bordered > thead > tr > th:last-child, .table-responsive > .table-bordered > tbody > tr > th:last-child, .table-responsive > .table-bordered > tfoot > tr > th:last-child, .table-responsive > .table-bordered > thead > tr > td:last-child, .table-responsive > .table-bordered > tbody > tr > td:last-child, .table-responsive > .table-bordered > tfoot > tr > td:last-child { border-right: 0; } .table-responsive > .table-bordered > tbody > tr:last-child > th, .table-responsive > .table-bordered > tfoot > tr:last-child > th, .table-responsive > .table-bordered > tbody > tr:last-child > td, .table-responsive > .table-bordered > tfoot > tr:last-child > td { border-bottom: 0; } } fieldset { padding: 0; margin: 0; border: 0; min-width: 0; } legend { display: block; width: 100%; padding: 0; margin-bottom: 23px; font-size: 19.5px; line-height: inherit; color: #212121; border: 0; border-bottom: 1px solid #e5e5e5; } label { display: inline-block; max-width: 100%; margin-bottom: 5px; font-weight: bold; } input[type="search"] { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } input[type="radio"], input[type="checkbox"] { margin: 4px 0 0; margin-top: 1px \9; line-height: normal; } input[type="file"] { display: block; } input[type="range"] { display: block; width: 100%; } select[multiple], select[size] { height: auto; } input[type="file"]:focus, input[type="radio"]:focus, input[type="checkbox"]:focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } output { display: block; padding-top: 7px; font-size: 13px; line-height: 1.846; color: #666666; } .form-control { display: block; width: 100%; height: 37px; padding: 6px 16px; font-size: 13px; line-height: 1.846; color: #666666; background-color: transparent; background-image: none; border: 1px solid transparent; border-radius: 3px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } .form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); } .form-control::-moz-placeholder { color: #bbbbbb; opacity: 1; } .form-control:-ms-input-placeholder { color: #bbbbbb; } .form-control::-webkit-input-placeholder { color: #bbbbbb; } .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { background-color: transparent; opacity: 1; } .form-control[disabled], fieldset[disabled] .form-control { cursor: not-allowed; } textarea.form-control { height: auto; } input[type="search"] { -webkit-appearance: none; } @media screen and (-webkit-min-device-pixel-ratio: 0) { input[type="date"].form-control, input[type="time"].form-control, input[type="datetime-local"].form-control, input[type="month"].form-control { line-height: 37px; } input[type="date"].input-sm, input[type="time"].input-sm, input[type="datetime-local"].input-sm, input[type="month"].input-sm, .input-group-sm input[type="date"], .input-group-sm input[type="time"], .input-group-sm input[type="datetime-local"], .input-group-sm input[type="month"] { line-height: 30px; } input[type="date"].input-lg, input[type="time"].input-lg, input[type="datetime-local"].input-lg, input[type="month"].input-lg, .input-group-lg input[type="date"], .input-group-lg input[type="time"], .input-group-lg input[type="datetime-local"], .input-group-lg input[type="month"] { line-height: 45px; } } .form-group { margin-bottom: 15px; } .radio, .checkbox { position: relative; display: block; margin-top: 10px; margin-bottom: 10px; } .radio label, .checkbox label { min-height: 23px; padding-left: 20px; margin-bottom: 0; font-weight: normal; cursor: pointer; } .radio input[type="radio"], .radio-inline input[type="radio"], .checkbox input[type="checkbox"], .checkbox-inline input[type="checkbox"] { position: absolute; margin-left: -20px; margin-top: 4px \9; } .radio + .radio, .checkbox + .checkbox { margin-top: -5px; } .radio-inline, .checkbox-inline { position: relative; display: inline-block; padding-left: 20px; margin-bottom: 0; vertical-align: middle; font-weight: normal; cursor: pointer; } .radio-inline + .radio-inline, .checkbox-inline + .checkbox-inline { margin-top: 0; margin-left: 10px; } input[type="radio"][disabled], input[type="checkbox"][disabled], input[type="radio"].disabled, input[type="checkbox"].disabled, fieldset[disabled] input[type="radio"], fieldset[disabled] input[type="checkbox"] { cursor: not-allowed; } .radio-inline.disabled, .checkbox-inline.disabled, fieldset[disabled] .radio-inline, fieldset[disabled] .checkbox-inline { cursor: not-allowed; } .radio.disabled label, .checkbox.disabled label, fieldset[disabled] .radio label, fieldset[disabled] .checkbox label { cursor: not-allowed; } .form-control-static { padding-top: 7px; padding-bottom: 7px; margin-bottom: 0; min-height: 36px; } .form-control-static.input-lg, .form-control-static.input-sm { padding-left: 0; padding-right: 0; } .input-sm { height: 30px; padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } select.input-sm { height: 30px; line-height: 30px; } textarea.input-sm, select[multiple].input-sm { height: auto; } .form-group-sm .form-control { height: 30px; padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } .form-group-sm select.form-control { height: 30px; line-height: 30px; } .form-group-sm textarea.form-control, .form-group-sm select[multiple].form-control { height: auto; } .form-group-sm .form-control-static { height: 30px; min-height: 35px; padding: 6px 10px; font-size: 12px; line-height: 1.5; } .input-lg { height: 45px; padding: 10px 16px; font-size: 17px; line-height: 1.3333333; border-radius: 3px; } select.input-lg { height: 45px; line-height: 45px; } textarea.input-lg, select[multiple].input-lg { height: auto; } .form-group-lg .form-control { height: 45px; padding: 10px 16px; font-size: 17px; line-height: 1.3333333; border-radius: 3px; } .form-group-lg select.form-control { height: 45px; line-height: 45px; } .form-group-lg textarea.form-control, .form-group-lg select[multiple].form-control { height: auto; } .form-group-lg .form-control-static { height: 45px; min-height: 40px; padding: 11px 16px; font-size: 17px; line-height: 1.3333333; } .has-feedback { position: relative; } .has-feedback .form-control { padding-right: 46.25px; } .form-control-feedback { position: absolute; top: 0; right: 0; z-index: 2; display: block; width: 37px; height: 37px; line-height: 37px; text-align: center; pointer-events: none; } .input-lg + .form-control-feedback, .input-group-lg + .form-control-feedback, .form-group-lg .form-control + .form-control-feedback { width: 45px; height: 45px; line-height: 45px; } .input-sm + .form-control-feedback, .input-group-sm + .form-control-feedback, .form-group-sm .form-control + .form-control-feedback { width: 30px; height: 30px; line-height: 30px; } .has-success .help-block, .has-success .control-label, .has-success .radio, .has-success .checkbox, .has-success .radio-inline, .has-success .checkbox-inline, .has-success.radio label, .has-success.checkbox label, .has-success.radio-inline label, .has-success.checkbox-inline label { color: #4caf50; } .has-success .form-control { border-color: #4caf50; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); } .has-success .form-control:focus { border-color: #3d8b40; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #92cf94; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #92cf94; } .has-success .input-group-addon { color: #4caf50; border-color: #4caf50; background-color: #dff0d8; } .has-success .form-control-feedback { color: #4caf50; } .has-warning .help-block, .has-warning .control-label, .has-warning .radio, .has-warning .checkbox, .has-warning .radio-inline, .has-warning .checkbox-inline, .has-warning.radio label, .has-warning.checkbox label, .has-warning.radio-inline label, .has-warning.checkbox-inline label { color: #ff9800; } .has-warning .form-control { border-color: #ff9800; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); } .has-warning .form-control:focus { border-color: #cc7a00; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ffc166; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ffc166; } .has-warning .input-group-addon { color: #ff9800; border-color: #ff9800; background-color: #ffe0b2; } .has-warning .form-control-feedback { color: #ff9800; } .has-error .help-block, .has-error .control-label, .has-error .radio, .has-error .checkbox, .has-error .radio-inline, .has-error .checkbox-inline, .has-error.radio label, .has-error.checkbox label, .has-error.radio-inline label, .has-error.checkbox-inline label { color: #e51c23; } .has-error .form-control { border-color: #e51c23; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); } .has-error .form-control:focus { border-color: #b9151b; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ef787c; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ef787c; } .has-error .input-group-addon { color: #e51c23; border-color: #e51c23; background-color: #f9bdbb; } .has-error .form-control-feedback { color: #e51c23; } .has-feedback label ~ .form-control-feedback { top: 28px; } .has-feedback label.sr-only ~ .form-control-feedback { top: 0; } .help-block { display: block; margin-top: 5px; margin-bottom: 10px; color: #a6a6a6; } @media (min-width: 768px) { .form-inline .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .form-inline .form-control { display: inline-block; width: auto; vertical-align: middle; } .form-inline .form-control-static { display: inline-block; } .form-inline .input-group { display: inline-table; vertical-align: middle; } .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, .form-inline .input-group .form-control { width: auto; } .form-inline .input-group > .form-control { width: 100%; } .form-inline .control-label { margin-bottom: 0; vertical-align: middle; } .form-inline .radio, .form-inline .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .form-inline .radio label, .form-inline .checkbox label { padding-left: 0; } .form-inline .radio input[type="radio"], .form-inline .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .form-inline .has-feedback .form-control-feedback { top: 0; } } .form-horizontal .radio, .form-horizontal .checkbox, .form-horizontal .radio-inline, .form-horizontal .checkbox-inline { margin-top: 0; margin-bottom: 0; padding-top: 7px; } .form-horizontal .radio, .form-horizontal .checkbox { min-height: 30px; } .form-horizontal .form-group { margin-left: -15px; margin-right: -15px; } @media (min-width: 768px) { .form-horizontal .control-label { text-align: right; margin-bottom: 0; padding-top: 7px; } } .form-horizontal .has-feedback .form-control-feedback { right: 15px; } @media (min-width: 768px) { .form-horizontal .form-group-lg .control-label { padding-top: 14.333333px; font-size: 17px; } } @media (min-width: 768px) { .form-horizontal .form-group-sm .control-label { padding-top: 6px; font-size: 12px; } } .btn { display: inline-block; margin-bottom: 0; font-weight: normal; text-align: center; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; background-image: none; border: 1px solid transparent; white-space: nowrap; padding: 6px 16px; font-size: 13px; line-height: 1.846; border-radius: 3px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .btn:focus, .btn:active:focus, .btn.active:focus, .btn.focus, .btn:active.focus, .btn.active.focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } .btn:hover, .btn:focus, .btn.focus { color: #666666; text-decoration: none; } .btn:active, .btn.active { outline: 0; background-image: none; -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); } .btn.disabled, .btn[disabled], fieldset[disabled] .btn { cursor: not-allowed; opacity: 0.65; filter: alpha(opacity=65); -webkit-box-shadow: none; box-shadow: none; } a.btn.disabled, fieldset[disabled] a.btn { pointer-events: none; } .btn-default { color: #666666; background-color: #ffffff; border-color: #eeeeee; } .btn-default:focus, .btn-default.focus { color: #666666; background-color: #e6e6e6; border-color: #aeaeae; } .btn-default:hover { color: #666666; background-color: #e6e6e6; border-color: #cfcfcf; } .btn-default:active, .btn-default.active, .open > .dropdown-toggle.btn-default { color: #666666; background-color: #e6e6e6; border-color: #cfcfcf; } .btn-default:active:hover, .btn-default.active:hover, .open > .dropdown-toggle.btn-default:hover, .btn-default:active:focus, .btn-default.active:focus, .open > .dropdown-toggle.btn-default:focus, .btn-default:active.focus, .btn-default.active.focus, .open > .dropdown-toggle.btn-default.focus { color: #666666; background-color: #d4d4d4; border-color: #aeaeae; } .btn-default:active, .btn-default.active, .open > .dropdown-toggle.btn-default { background-image: none; } .btn-default.disabled, .btn-default[disabled], fieldset[disabled] .btn-default, .btn-default.disabled:hover, .btn-default[disabled]:hover, fieldset[disabled] .btn-default:hover, .btn-default.disabled:focus, .btn-default[disabled]:focus, fieldset[disabled] .btn-default:focus, .btn-default.disabled.focus, .btn-default[disabled].focus, fieldset[disabled] .btn-default.focus, .btn-default.disabled:active, .btn-default[disabled]:active, fieldset[disabled] .btn-default:active, .btn-default.disabled.active, .btn-default[disabled].active, fieldset[disabled] .btn-default.active { background-color: #ffffff; border-color: #eeeeee; } .btn-default .badge { color: #ffffff; background-color: #666666; } .btn-primary { color: #ffffff; background-color: #2196f3; border-color: transparent; } .btn-primary:focus, .btn-primary.focus { color: #ffffff; background-color: #0c7cd5; border-color: rgba(0, 0, 0, 0); } .btn-primary:hover { color: #ffffff; background-color: #0c7cd5; border-color: rgba(0, 0, 0, 0); } .btn-primary:active, .btn-primary.active, .open > .dropdown-toggle.btn-primary { color: #ffffff; background-color: #0c7cd5; border-color: rgba(0, 0, 0, 0); } .btn-primary:active:hover, .btn-primary.active:hover, .open > .dropdown-toggle.btn-primary:hover, .btn-primary:active:focus, .btn-primary.active:focus, .open > .dropdown-toggle.btn-primary:focus, .btn-primary:active.focus, .btn-primary.active.focus, .open > .dropdown-toggle.btn-primary.focus { color: #ffffff; background-color: #0a68b4; border-color: rgba(0, 0, 0, 0); } .btn-primary:active, .btn-primary.active, .open > .dropdown-toggle.btn-primary { background-image: none; } .btn-primary.disabled, .btn-primary[disabled], fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, .btn-primary.disabled:focus, .btn-primary[disabled]:focus, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled.focus, .btn-primary[disabled].focus, fieldset[disabled] .btn-primary.focus, .btn-primary.disabled:active, .btn-primary[disabled]:active, fieldset[disabled] .btn-primary:active, .btn-primary.disabled.active, .btn-primary[disabled].active, fieldset[disabled] .btn-primary.active { background-color: #2196f3; border-color: transparent; } .btn-primary .badge { color: #2196f3; background-color: #ffffff; } .btn-success { color: #ffffff; background-color: #4caf50; border-color: transparent; } .btn-success:focus, .btn-success.focus { color: #ffffff; background-color: #3d8b40; border-color: rgba(0, 0, 0, 0); } .btn-success:hover { color: #ffffff; background-color: #3d8b40; border-color: rgba(0, 0, 0, 0); } .btn-success:active, .btn-success.active, .open > .dropdown-toggle.btn-success { color: #ffffff; background-color: #3d8b40; border-color: rgba(0, 0, 0, 0); } .btn-success:active:hover, .btn-success.active:hover, .open > .dropdown-toggle.btn-success:hover, .btn-success:active:focus, .btn-success.active:focus, .open > .dropdown-toggle.btn-success:focus, .btn-success:active.focus, .btn-success.active.focus, .open > .dropdown-toggle.btn-success.focus { color: #ffffff; background-color: #327334; border-color: rgba(0, 0, 0, 0); } .btn-success:active, .btn-success.active, .open > .dropdown-toggle.btn-success { background-image: none; } .btn-success.disabled, .btn-success[disabled], fieldset[disabled] .btn-success, .btn-success.disabled:hover, .btn-success[disabled]:hover, fieldset[disabled] .btn-success:hover, .btn-success.disabled:focus, .btn-success[disabled]:focus, fieldset[disabled] .btn-success:focus, .btn-success.disabled.focus, .btn-success[disabled].focus, fieldset[disabled] .btn-success.focus, .btn-success.disabled:active, .btn-success[disabled]:active, fieldset[disabled] .btn-success:active, .btn-success.disabled.active, .btn-success[disabled].active, fieldset[disabled] .btn-success.active { background-color: #4caf50; border-color: transparent; } .btn-success .badge { color: #4caf50; background-color: #ffffff; } .btn-info { color: #ffffff; background-color: #9c27b0; border-color: transparent; } .btn-info:focus, .btn-info.focus { color: #ffffff; background-color: #771e86; border-color: rgba(0, 0, 0, 0); } .btn-info:hover { color: #ffffff; background-color: #771e86; border-color: rgba(0, 0, 0, 0); } .btn-info:active, .btn-info.active, .open > .dropdown-toggle.btn-info { color: #ffffff; background-color: #771e86; border-color: rgba(0, 0, 0, 0); } .btn-info:active:hover, .btn-info.active:hover, .open > .dropdown-toggle.btn-info:hover, .btn-info:active:focus, .btn-info.active:focus, .open > .dropdown-toggle.btn-info:focus, .btn-info:active.focus, .btn-info.active.focus, .open > .dropdown-toggle.btn-info.focus { color: #ffffff; background-color: #5d1769; border-color: rgba(0, 0, 0, 0); } .btn-info:active, .btn-info.active, .open > .dropdown-toggle.btn-info { background-image: none; } .btn-info.disabled, .btn-info[disabled], fieldset[disabled] .btn-info, .btn-info.disabled:hover, .btn-info[disabled]:hover, fieldset[disabled] .btn-info:hover, .btn-info.disabled:focus, .btn-info[disabled]:focus, fieldset[disabled] .btn-info:focus, .btn-info.disabled.focus, .btn-info[disabled].focus, fieldset[disabled] .btn-info.focus, .btn-info.disabled:active, .btn-info[disabled]:active, fieldset[disabled] .btn-info:active, .btn-info.disabled.active, .btn-info[disabled].active, fieldset[disabled] .btn-info.active { background-color: #9c27b0; border-color: transparent; } .btn-info .badge { color: #9c27b0; background-color: #ffffff; } .btn-warning { color: #ffffff; background-color: #ff9800; border-color: transparent; } .btn-warning:focus, .btn-warning.focus { color: #ffffff; background-color: #cc7a00; border-color: rgba(0, 0, 0, 0); } .btn-warning:hover { color: #ffffff; background-color: #cc7a00; border-color: rgba(0, 0, 0, 0); } .btn-warning:active, .btn-warning.active, .open > .dropdown-toggle.btn-warning { color: #ffffff; background-color: #cc7a00; border-color: rgba(0, 0, 0, 0); } .btn-warning:active:hover, .btn-warning.active:hover, .open > .dropdown-toggle.btn-warning:hover, .btn-warning:active:focus, .btn-warning.active:focus, .open > .dropdown-toggle.btn-warning:focus, .btn-warning:active.focus, .btn-warning.active.focus, .open > .dropdown-toggle.btn-warning.focus { color: #ffffff; background-color: #a86400; border-color: rgba(0, 0, 0, 0); } .btn-warning:active, .btn-warning.active, .open > .dropdown-toggle.btn-warning { background-image: none; } .btn-warning.disabled, .btn-warning[disabled], fieldset[disabled] .btn-warning, .btn-warning.disabled:hover, .btn-warning[disabled]:hover, fieldset[disabled] .btn-warning:hover, .btn-warning.disabled:focus, .btn-warning[disabled]:focus, fieldset[disabled] .btn-warning:focus, .btn-warning.disabled.focus, .btn-warning[disabled].focus, fieldset[disabled] .btn-warning.focus, .btn-warning.disabled:active, .btn-warning[disabled]:active, fieldset[disabled] .btn-warning:active, .btn-warning.disabled.active, .btn-warning[disabled].active, fieldset[disabled] .btn-warning.active { background-color: #ff9800; border-color: transparent; } .btn-warning .badge { color: #ff9800; background-color: #ffffff; } .btn-danger { color: #ffffff; background-color: #e51c23; border-color: transparent; } .btn-danger:focus, .btn-danger.focus { color: #ffffff; background-color: #b9151b; border-color: rgba(0, 0, 0, 0); } .btn-danger:hover { color: #ffffff; background-color: #b9151b; border-color: rgba(0, 0, 0, 0); } .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger { color: #ffffff; background-color: #b9151b; border-color: rgba(0, 0, 0, 0); } .btn-danger:active:hover, .btn-danger.active:hover, .open > .dropdown-toggle.btn-danger:hover, .btn-danger:active:focus, .btn-danger.active:focus, .open > .dropdown-toggle.btn-danger:focus, .btn-danger:active.focus, .btn-danger.active.focus, .open > .dropdown-toggle.btn-danger.focus { color: #ffffff; background-color: #991216; border-color: rgba(0, 0, 0, 0); } .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger { background-image: none; } .btn-danger.disabled, .btn-danger[disabled], fieldset[disabled] .btn-danger, .btn-danger.disabled:hover, .btn-danger[disabled]:hover, fieldset[disabled] .btn-danger:hover, .btn-danger.disabled:focus, .btn-danger[disabled]:focus, fieldset[disabled] .btn-danger:focus, .btn-danger.disabled.focus, .btn-danger[disabled].focus, fieldset[disabled] .btn-danger.focus, .btn-danger.disabled:active, .btn-danger[disabled]:active, fieldset[disabled] .btn-danger:active, .btn-danger.disabled.active, .btn-danger[disabled].active, fieldset[disabled] .btn-danger.active { background-color: #e51c23; border-color: transparent; } .btn-danger .badge { color: #e51c23; background-color: #ffffff; } .btn-link { color: #2196f3; font-weight: normal; border-radius: 0; } .btn-link, .btn-link:active, .btn-link.active, .btn-link[disabled], fieldset[disabled] .btn-link { background-color: transparent; -webkit-box-shadow: none; box-shadow: none; } .btn-link, .btn-link:hover, .btn-link:focus, .btn-link:active { border-color: transparent; } .btn-link:hover, .btn-link:focus { color: #0a6ebd; text-decoration: underline; background-color: transparent; } .btn-link[disabled]:hover, fieldset[disabled] .btn-link:hover, .btn-link[disabled]:focus, fieldset[disabled] .btn-link:focus { color: #bbbbbb; text-decoration: none; } .btn-lg, .btn-group-lg > .btn { padding: 10px 16px; font-size: 17px; line-height: 1.3333333; border-radius: 3px; } .btn-sm, .btn-group-sm > .btn { padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } .btn-xs, .btn-group-xs > .btn { padding: 1px 5px; font-size: 12px; line-height: 1.5; border-radius: 3px; } .btn-block { display: block; width: 100%; } .btn-block + .btn-block { margin-top: 5px; } input[type="submit"].btn-block, input[type="reset"].btn-block, input[type="button"].btn-block { width: 100%; } .fade { opacity: 0; -webkit-transition: opacity 0.15s linear; -o-transition: opacity 0.15s linear; transition: opacity 0.15s linear; } .fade.in { opacity: 1; } .collapse { display: none; } .collapse.in { display: block; } tr.collapse.in { display: table-row; } tbody.collapse.in { display: table-row-group; } .collapsing { position: relative; height: 0; overflow: hidden; -webkit-transition-property: height, visibility; -o-transition-property: height, visibility; transition-property: height, visibility; -webkit-transition-duration: 0.35s; -o-transition-duration: 0.35s; transition-duration: 0.35s; -webkit-transition-timing-function: ease; -o-transition-timing-function: ease; transition-timing-function: ease; } .caret { display: inline-block; width: 0; height: 0; margin-left: 2px; vertical-align: middle; border-top: 4px dashed; border-top: 4px solid \9; border-right: 4px solid transparent; border-left: 4px solid transparent; } .dropup, .dropdown { position: relative; } .dropdown-toggle:focus { outline: 0; } .dropdown-menu { position: absolute; top: 100%; left: 0; z-index: 1000; display: none; float: left; min-width: 160px; padding: 5px 0; margin: 2px 0 0; list-style: none; font-size: 13px; text-align: left; background-color: #ffffff; border: 1px solid #cccccc; border: 1px solid rgba(0, 0, 0, 0.15); border-radius: 3px; -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); -webkit-background-clip: padding-box; background-clip: padding-box; } .dropdown-menu.pull-right { right: 0; left: auto; } .dropdown-menu .divider { height: 1px; margin: 10.5px 0; overflow: hidden; background-color: #e5e5e5; } .dropdown-menu > li > a { display: block; padding: 3px 20px; clear: both; font-weight: normal; line-height: 1.846; color: #666666; white-space: nowrap; } .dropdown-menu > li > a:hover, .dropdown-menu > li > a:focus { text-decoration: none; color: #141414; background-color: #eeeeee; } .dropdown-menu > .active > a, .dropdown-menu > .active > a:hover, .dropdown-menu > .active > a:focus { color: #ffffff; text-decoration: none; outline: 0; background-color: #2196f3; } .dropdown-menu > .disabled > a, .dropdown-menu > .disabled > a:hover, .dropdown-menu > .disabled > a:focus { color: #bbbbbb; } .dropdown-menu > .disabled > a:hover, .dropdown-menu > .disabled > a:focus { text-decoration: none; background-color: transparent; background-image: none; filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); cursor: not-allowed; } .open > .dropdown-menu { display: block; } .open > a { outline: 0; } .dropdown-menu-right { left: auto; right: 0; } .dropdown-menu-left { left: 0; right: auto; } .dropdown-header { display: block; padding: 3px 20px; font-size: 12px; line-height: 1.846; color: #bbbbbb; white-space: nowrap; } .dropdown-backdrop { position: fixed; left: 0; right: 0; bottom: 0; top: 0; z-index: 990; } .pull-right > .dropdown-menu { right: 0; left: auto; } .dropup .caret, .navbar-fixed-bottom .dropdown .caret { border-top: 0; border-bottom: 4px dashed; border-bottom: 4px solid \9; content: ""; } .dropup .dropdown-menu, .navbar-fixed-bottom .dropdown .dropdown-menu { top: auto; bottom: 100%; margin-bottom: 2px; } @media (min-width: 768px) { .navbar-right .dropdown-menu { left: auto; right: 0; } .navbar-right .dropdown-menu-left { left: 0; right: auto; } } .btn-group, .btn-group-vertical { position: relative; display: inline-block; vertical-align: middle; } .btn-group > .btn, .btn-group-vertical > .btn { position: relative; float: left; } .btn-group > .btn:hover, .btn-group-vertical > .btn:hover, .btn-group > .btn:focus, .btn-group-vertical > .btn:focus, .btn-group > .btn:active, .btn-group-vertical > .btn:active, .btn-group > .btn.active, .btn-group-vertical > .btn.active { z-index: 2; } .btn-group .btn + .btn, .btn-group .btn + .btn-group, .btn-group .btn-group + .btn, .btn-group .btn-group + .btn-group { margin-left: -1px; } .btn-toolbar { margin-left: -5px; } .btn-toolbar .btn, .btn-toolbar .btn-group, .btn-toolbar .input-group { float: left; } .btn-toolbar > .btn, .btn-toolbar > .btn-group, .btn-toolbar > .input-group { margin-left: 5px; } .btn-group > .btn:not(:first-child):not(:last-child):not(.dropdown-toggle) { border-radius: 0; } .btn-group > .btn:first-child { margin-left: 0; } .btn-group > .btn:first-child:not(:last-child):not(.dropdown-toggle) { border-bottom-right-radius: 0; border-top-right-radius: 0; } .btn-group > .btn:last-child:not(:first-child), .btn-group > .dropdown-toggle:not(:first-child) { border-bottom-left-radius: 0; border-top-left-radius: 0; } .btn-group > .btn-group { float: left; } .btn-group > .btn-group:not(:first-child):not(:last-child) > .btn { border-radius: 0; } .btn-group > .btn-group:first-child:not(:last-child) > .btn:last-child, .btn-group > .btn-group:first-child:not(:last-child) > .dropdown-toggle { border-bottom-right-radius: 0; border-top-right-radius: 0; } .btn-group > .btn-group:last-child:not(:first-child) > .btn:first-child { border-bottom-left-radius: 0; border-top-left-radius: 0; } .btn-group .dropdown-toggle:active, .btn-group.open .dropdown-toggle { outline: 0; } .btn-group > .btn + .dropdown-toggle { padding-left: 8px; padding-right: 8px; } .btn-group > .btn-lg + .dropdown-toggle { padding-left: 12px; padding-right: 12px; } .btn-group.open .dropdown-toggle { -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); } .btn-group.open .dropdown-toggle.btn-link { -webkit-box-shadow: none; box-shadow: none; } .btn .caret { margin-left: 0; } .btn-lg .caret { border-width: 5px 5px 0; border-bottom-width: 0; } .dropup .btn-lg .caret { border-width: 0 5px 5px; } .btn-group-vertical > .btn, .btn-group-vertical > .btn-group, .btn-group-vertical > .btn-group > .btn { display: block; float: none; width: 100%; max-width: 100%; } .btn-group-vertical > .btn-group > .btn { float: none; } .btn-group-vertical > .btn + .btn, .btn-group-vertical > .btn + .btn-group, .btn-group-vertical > .btn-group + .btn, .btn-group-vertical > .btn-group + .btn-group { margin-top: -1px; margin-left: 0; } .btn-group-vertical > .btn:not(:first-child):not(:last-child) { border-radius: 0; } .btn-group-vertical > .btn:first-child:not(:last-child) { border-top-right-radius: 3px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .btn-group-vertical > .btn:last-child:not(:first-child) { border-bottom-left-radius: 3px; border-top-right-radius: 0; border-top-left-radius: 0; } .btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn { border-radius: 0; } .btn-group-vertical > .btn-group:first-child:not(:last-child) > .btn:last-child, .btn-group-vertical > .btn-group:first-child:not(:last-child) > .dropdown-toggle { border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .btn-group-vertical > .btn-group:last-child:not(:first-child) > .btn:first-child { border-top-right-radius: 0; border-top-left-radius: 0; } .btn-group-justified { display: table; width: 100%; table-layout: fixed; border-collapse: separate; } .btn-group-justified > .btn, .btn-group-justified > .btn-group { float: none; display: table-cell; width: 1%; } .btn-group-justified > .btn-group .btn { width: 100%; } .btn-group-justified > .btn-group .dropdown-menu { left: auto; } [data-toggle="buttons"] > .btn input[type="radio"], [data-toggle="buttons"] > .btn-group > .btn input[type="radio"], [data-toggle="buttons"] > .btn input[type="checkbox"], [data-toggle="buttons"] > .btn-group > .btn input[type="checkbox"] { position: absolute; clip: rect(0, 0, 0, 0); pointer-events: none; } .input-group { position: relative; display: table; border-collapse: separate; } .input-group[class*="col-"] { float: none; padding-left: 0; padding-right: 0; } .input-group .form-control { position: relative; z-index: 2; float: left; width: 100%; margin-bottom: 0; } .input-group-lg > .form-control, .input-group-lg > .input-group-addon, .input-group-lg > .input-group-btn > .btn { height: 45px; padding: 10px 16px; font-size: 17px; line-height: 1.3333333; border-radius: 3px; } select.input-group-lg > .form-control, select.input-group-lg > .input-group-addon, select.input-group-lg > .input-group-btn > .btn { height: 45px; line-height: 45px; } textarea.input-group-lg > .form-control, textarea.input-group-lg > .input-group-addon, textarea.input-group-lg > .input-group-btn > .btn, select[multiple].input-group-lg > .form-control, select[multiple].input-group-lg > .input-group-addon, select[multiple].input-group-lg > .input-group-btn > .btn { height: auto; } .input-group-sm > .form-control, .input-group-sm > .input-group-addon, .input-group-sm > .input-group-btn > .btn { height: 30px; padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } select.input-group-sm > .form-control, select.input-group-sm > .input-group-addon, select.input-group-sm > .input-group-btn > .btn { height: 30px; line-height: 30px; } textarea.input-group-sm > .form-control, textarea.input-group-sm > .input-group-addon, textarea.input-group-sm > .input-group-btn > .btn, select[multiple].input-group-sm > .form-control, select[multiple].input-group-sm > .input-group-addon, select[multiple].input-group-sm > .input-group-btn > .btn { height: auto; } .input-group-addon, .input-group-btn, .input-group .form-control { display: table-cell; } .input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), .input-group .form-control:not(:first-child):not(:last-child) { border-radius: 0; } .input-group-addon, .input-group-btn { width: 1%; white-space: nowrap; vertical-align: middle; } .input-group-addon { padding: 6px 16px; font-size: 13px; font-weight: normal; line-height: 1; color: #666666; text-align: center; background-color: transparent; border: 1px solid transparent; border-radius: 3px; } .input-group-addon.input-sm { padding: 5px 10px; font-size: 12px; border-radius: 3px; } .input-group-addon.input-lg { padding: 10px 16px; font-size: 17px; border-radius: 3px; } .input-group-addon input[type="radio"], .input-group-addon input[type="checkbox"] { margin-top: 0; } .input-group .form-control:first-child, .input-group-addon:first-child, .input-group-btn:first-child > .btn, .input-group-btn:first-child > .btn-group > .btn, .input-group-btn:first-child > .dropdown-toggle, .input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle), .input-group-btn:last-child > .btn-group:not(:last-child) > .btn { border-bottom-right-radius: 0; border-top-right-radius: 0; } .input-group-addon:first-child { border-right: 0; } .input-group .form-control:last-child, .input-group-addon:last-child, .input-group-btn:last-child > .btn, .input-group-btn:last-child > .btn-group > .btn, .input-group-btn:last-child > .dropdown-toggle, .input-group-btn:first-child > .btn:not(:first-child), .input-group-btn:first-child > .btn-group:not(:first-child) > .btn { border-bottom-left-radius: 0; border-top-left-radius: 0; } .input-group-addon:last-child { border-left: 0; } .input-group-btn { position: relative; font-size: 0; white-space: nowrap; } .input-group-btn > .btn { position: relative; } .input-group-btn > .btn + .btn { margin-left: -1px; } .input-group-btn > .btn:hover, .input-group-btn > .btn:focus, .input-group-btn > .btn:active { z-index: 2; } .input-group-btn:first-child > .btn, .input-group-btn:first-child > .btn-group { margin-right: -1px; } .input-group-btn:last-child > .btn, .input-group-btn:last-child > .btn-group { z-index: 2; margin-left: -1px; } .nav { margin-bottom: 0; padding-left: 0; list-style: none; } .nav > li { position: relative; display: block; } .nav > li > a { position: relative; display: block; padding: 10px 15px; } .nav > li > a:hover, .nav > li > a:focus { text-decoration: none; background-color: #eeeeee; } .nav > li.disabled > a { color: #bbbbbb; } .nav > li.disabled > a:hover, .nav > li.disabled > a:focus { color: #bbbbbb; text-decoration: none; background-color: transparent; cursor: not-allowed; } .nav .open > a, .nav .open > a:hover, .nav .open > a:focus { background-color: #eeeeee; border-color: #2196f3; } .nav .nav-divider { height: 1px; margin: 10.5px 0; overflow: hidden; background-color: #e5e5e5; } .nav > li > a > img { max-width: none; } .nav-tabs { border-bottom: 1px solid transparent; } .nav-tabs > li { float: left; margin-bottom: -1px; } .nav-tabs > li > a { margin-right: 2px; line-height: 1.846; border: 1px solid transparent; border-radius: 3px 3px 0 0; } .nav-tabs > li > a:hover { border-color: #eeeeee #eeeeee transparent; } .nav-tabs > li.active > a, .nav-tabs > li.active > a:hover, .nav-tabs > li.active > a:focus { color: #666666; background-color: transparent; border: 1px solid transparent; border-bottom-color: transparent; cursor: default; } .nav-tabs.nav-justified { width: 100%; border-bottom: 0; } .nav-tabs.nav-justified > li { float: none; } .nav-tabs.nav-justified > li > a { text-align: center; margin-bottom: 5px; } .nav-tabs.nav-justified > .dropdown .dropdown-menu { top: auto; left: auto; } @media (min-width: 768px) { .nav-tabs.nav-justified > li { display: table-cell; width: 1%; } .nav-tabs.nav-justified > li > a { margin-bottom: 0; } } .nav-tabs.nav-justified > li > a { margin-right: 0; border-radius: 3px; } .nav-tabs.nav-justified > .active > a, .nav-tabs.nav-justified > .active > a:hover, .nav-tabs.nav-justified > .active > a:focus { border: 1px solid transparent; } @media (min-width: 768px) { .nav-tabs.nav-justified > li > a { border-bottom: 1px solid transparent; border-radius: 3px 3px 0 0; } .nav-tabs.nav-justified > .active > a, .nav-tabs.nav-justified > .active > a:hover, .nav-tabs.nav-justified > .active > a:focus { border-bottom-color: #ffffff; } } .nav-pills > li { float: left; } .nav-pills > li > a { border-radius: 3px; } .nav-pills > li + li { margin-left: 2px; } .nav-pills > li.active > a, .nav-pills > li.active > a:hover, .nav-pills > li.active > a:focus { color: #ffffff; background-color: #2196f3; } .nav-stacked > li { float: none; } .nav-stacked > li + li { margin-top: 2px; margin-left: 0; } .nav-justified { width: 100%; } .nav-justified > li { float: none; } .nav-justified > li > a { text-align: center; margin-bottom: 5px; } .nav-justified > .dropdown .dropdown-menu { top: auto; left: auto; } @media (min-width: 768px) { .nav-justified > li { display: table-cell; width: 1%; } .nav-justified > li > a { margin-bottom: 0; } } .nav-tabs-justified { border-bottom: 0; } .nav-tabs-justified > li > a { margin-right: 0; border-radius: 3px; } .nav-tabs-justified > .active > a, .nav-tabs-justified > .active > a:hover, .nav-tabs-justified > .active > a:focus { border: 1px solid transparent; } @media (min-width: 768px) { .nav-tabs-justified > li > a { border-bottom: 1px solid transparent; border-radius: 3px 3px 0 0; } .nav-tabs-justified > .active > a, .nav-tabs-justified > .active > a:hover, .nav-tabs-justified > .active > a:focus { border-bottom-color: #ffffff; } } .tab-content > .tab-pane { display: none; } .tab-content > .active { display: block; } .nav-tabs .dropdown-menu { margin-top: -1px; border-top-right-radius: 0; border-top-left-radius: 0; } .navbar { position: relative; min-height: 64px; margin-bottom: 23px; border: 1px solid transparent; } @media (min-width: 768px) { .navbar { border-radius: 3px; } } @media (min-width: 768px) { .navbar-header { float: left; } } .navbar-collapse { overflow-x: visible; padding-right: 15px; padding-left: 15px; border-top: 1px solid transparent; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); -webkit-overflow-scrolling: touch; } .navbar-collapse.in { overflow-y: auto; } @media (min-width: 768px) { .navbar-collapse { width: auto; border-top: 0; -webkit-box-shadow: none; box-shadow: none; } .navbar-collapse.collapse { display: block !important; height: auto !important; padding-bottom: 0; overflow: visible !important; } .navbar-collapse.in { overflow-y: visible; } .navbar-fixed-top .navbar-collapse, .navbar-static-top .navbar-collapse, .navbar-fixed-bottom .navbar-collapse { padding-left: 0; padding-right: 0; } } .navbar-fixed-top .navbar-collapse, .navbar-fixed-bottom .navbar-collapse { max-height: 340px; } @media (max-device-width: 480px) and (orientation: landscape) { .navbar-fixed-top .navbar-collapse, .navbar-fixed-bottom .navbar-collapse { max-height: 200px; } } .container > .navbar-header, .container-fluid > .navbar-header, .container > .navbar-collapse, .container-fluid > .navbar-collapse { margin-right: -15px; margin-left: -15px; } @media (min-width: 768px) { .container > .navbar-header, .container-fluid > .navbar-header, .container > .navbar-collapse, .container-fluid > .navbar-collapse { margin-right: 0; margin-left: 0; } } .navbar-static-top { z-index: 1000; border-width: 0 0 1px; } @media (min-width: 768px) { .navbar-static-top { border-radius: 0; } } .navbar-fixed-top, .navbar-fixed-bottom { position: fixed; right: 0; left: 0; z-index: 1030; } @media (min-width: 768px) { .navbar-fixed-top, .navbar-fixed-bottom { border-radius: 0; } } .navbar-fixed-top { top: 0; border-width: 0 0 1px; } .navbar-fixed-bottom { bottom: 0; margin-bottom: 0; border-width: 1px 0 0; } .navbar-brand { float: left; padding: 20.5px 15px; font-size: 17px; line-height: 23px; height: 64px; } .navbar-brand:hover, .navbar-brand:focus { text-decoration: none; } .navbar-brand > img { display: block; } @media (min-width: 768px) { .navbar > .container .navbar-brand, .navbar > .container-fluid .navbar-brand { margin-left: -15px; } } .navbar-toggle { position: relative; float: right; margin-right: 15px; padding: 9px 10px; margin-top: 15px; margin-bottom: 15px; background-color: transparent; background-image: none; border: 1px solid transparent; border-radius: 3px; } .navbar-toggle:focus { outline: 0; } .navbar-toggle .icon-bar { display: block; width: 22px; height: 2px; border-radius: 1px; } .navbar-toggle .icon-bar + .icon-bar { margin-top: 4px; } @media (min-width: 768px) { .navbar-toggle { display: none; } } .navbar-nav { margin: 10.25px -15px; } .navbar-nav > li > a { padding-top: 10px; padding-bottom: 10px; line-height: 23px; } @media (max-width: 767px) { .navbar-nav .open .dropdown-menu { position: static; float: none; width: auto; margin-top: 0; background-color: transparent; border: 0; -webkit-box-shadow: none; box-shadow: none; } .navbar-nav .open .dropdown-menu > li > a, .navbar-nav .open .dropdown-menu .dropdown-header { padding: 5px 15px 5px 25px; } .navbar-nav .open .dropdown-menu > li > a { line-height: 23px; } .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-nav .open .dropdown-menu > li > a:focus { background-image: none; } } @media (min-width: 768px) { .navbar-nav { float: left; margin: 0; } .navbar-nav > li { float: left; } .navbar-nav > li > a { padding-top: 20.5px; padding-bottom: 20.5px; } } .navbar-form { margin-left: -15px; margin-right: -15px; padding: 10px 15px; border-top: 1px solid transparent; border-bottom: 1px solid transparent; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); margin-top: 13.5px; margin-bottom: 13.5px; } @media (min-width: 768px) { .navbar-form .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .navbar-form .form-control { display: inline-block; width: auto; vertical-align: middle; } .navbar-form .form-control-static { display: inline-block; } .navbar-form .input-group { display: inline-table; vertical-align: middle; } .navbar-form .input-group .input-group-addon, .navbar-form .input-group .input-group-btn, .navbar-form .input-group .form-control { width: auto; } .navbar-form .input-group > .form-control { width: 100%; } .navbar-form .control-label { margin-bottom: 0; vertical-align: middle; } .navbar-form .radio, .navbar-form .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .navbar-form .radio label, .navbar-form .checkbox label { padding-left: 0; } .navbar-form .radio input[type="radio"], .navbar-form .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .navbar-form .has-feedback .form-control-feedback { top: 0; } } @media (max-width: 767px) { .navbar-form .form-group { margin-bottom: 5px; } .navbar-form .form-group:last-child { margin-bottom: 0; } } @media (min-width: 768px) { .navbar-form { width: auto; border: 0; margin-left: 0; margin-right: 0; padding-top: 0; padding-bottom: 0; -webkit-box-shadow: none; box-shadow: none; } } .navbar-nav > li > .dropdown-menu { margin-top: 0; border-top-right-radius: 0; border-top-left-radius: 0; } .navbar-fixed-bottom .navbar-nav > li > .dropdown-menu { margin-bottom: 0; border-top-right-radius: 3px; border-top-left-radius: 3px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .navbar-btn { margin-top: 13.5px; margin-bottom: 13.5px; } .navbar-btn.btn-sm { margin-top: 17px; margin-bottom: 17px; } .navbar-btn.btn-xs { margin-top: 21px; margin-bottom: 21px; } .navbar-text { margin-top: 20.5px; margin-bottom: 20.5px; } @media (min-width: 768px) { .navbar-text { float: left; margin-left: 15px; margin-right: 15px; } } @media (min-width: 768px) { .navbar-left { float: left !important; } .navbar-right { float: right !important; margin-right: -15px; } .navbar-right ~ .navbar-right { margin-right: 0; } } .navbar-default { background-color: #ffffff; border-color: transparent; } .navbar-default .navbar-brand { color: #666666; } .navbar-default .navbar-brand:hover, .navbar-default .navbar-brand:focus { color: #212121; background-color: transparent; } .navbar-default .navbar-text { color: #bbbbbb; } .navbar-default .navbar-nav > li > a { color: #666666; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { color: #212121; background-color: transparent; } .navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:focus { color: #212121; background-color: #eeeeee; } .navbar-default .navbar-nav > .disabled > a, .navbar-default .navbar-nav > .disabled > a:hover, .navbar-default .navbar-nav > .disabled > a:focus { color: #cccccc; background-color: transparent; } .navbar-default .navbar-toggle { border-color: transparent; } .navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus { background-color: transparent; } .navbar-default .navbar-toggle .icon-bar { background-color: rgba(0, 0, 0, 0.5); } .navbar-default .navbar-collapse, .navbar-default .navbar-form { border-color: transparent; } .navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus { background-color: #eeeeee; color: #212121; } @media (max-width: 767px) { .navbar-default .navbar-nav .open .dropdown-menu > li > a { color: #666666; } .navbar-default .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus { color: #212121; background-color: transparent; } .navbar-default .navbar-nav .open .dropdown-menu > .active > a, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus { color: #212121; background-color: #eeeeee; } .navbar-default .navbar-nav .open .dropdown-menu > .disabled > a, .navbar-default .navbar-nav .open .dropdown-menu > .disabled > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > .disabled > a:focus { color: #cccccc; background-color: transparent; } } .navbar-default .navbar-link { color: #666666; } .navbar-default .navbar-link:hover { color: #212121; } .navbar-default .btn-link { color: #666666; } .navbar-default .btn-link:hover, .navbar-default .btn-link:focus { color: #212121; } .navbar-default .btn-link[disabled]:hover, fieldset[disabled] .navbar-default .btn-link:hover, .navbar-default .btn-link[disabled]:focus, fieldset[disabled] .navbar-default .btn-link:focus { color: #cccccc; } .navbar-inverse { background-color: #2196f3; border-color: transparent; } .navbar-inverse .navbar-brand { color: #b2dbfb; } .navbar-inverse .navbar-brand:hover, .navbar-inverse .navbar-brand:focus { color: #ffffff; background-color: transparent; } .navbar-inverse .navbar-text { color: #bbbbbb; } .navbar-inverse .navbar-nav > li > a { color: #b2dbfb; } .navbar-inverse .navbar-nav > li > a:hover, .navbar-inverse .navbar-nav > li > a:focus { color: #ffffff; background-color: transparent; } .navbar-inverse .navbar-nav > .active > a, .navbar-inverse .navbar-nav > .active > a:hover, .navbar-inverse .navbar-nav > .active > a:focus { color: #ffffff; background-color: #0c7cd5; } .navbar-inverse .navbar-nav > .disabled > a, .navbar-inverse .navbar-nav > .disabled > a:hover, .navbar-inverse .navbar-nav > .disabled > a:focus { color: #444444; background-color: transparent; } .navbar-inverse .navbar-toggle { border-color: transparent; } .navbar-inverse .navbar-toggle:hover, .navbar-inverse .navbar-toggle:focus { background-color: transparent; } .navbar-inverse .navbar-toggle .icon-bar { background-color: rgba(0, 0, 0, 0.5); } .navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form { border-color: #0c84e4; } .navbar-inverse .navbar-nav > .open > a, .navbar-inverse .navbar-nav > .open > a:hover, .navbar-inverse .navbar-nav > .open > a:focus { background-color: #0c7cd5; color: #ffffff; } @media (max-width: 767px) { .navbar-inverse .navbar-nav .open .dropdown-menu > .dropdown-header { border-color: transparent; } .navbar-inverse .navbar-nav .open .dropdown-menu .divider { background-color: transparent; } .navbar-inverse .navbar-nav .open .dropdown-menu > li > a { color: #b2dbfb; } .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:focus { color: #ffffff; background-color: transparent; } .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a, .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:focus { color: #ffffff; background-color: #0c7cd5; } .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a, .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a:hover, .navbar-inverse .navbar-nav .open .dropdown-menu > .disabled > a:focus { color: #444444; background-color: transparent; } } .navbar-inverse .navbar-link { color: #b2dbfb; } .navbar-inverse .navbar-link:hover { color: #ffffff; } .navbar-inverse .btn-link { color: #b2dbfb; } .navbar-inverse .btn-link:hover, .navbar-inverse .btn-link:focus { color: #ffffff; } .navbar-inverse .btn-link[disabled]:hover, fieldset[disabled] .navbar-inverse .btn-link:hover, .navbar-inverse .btn-link[disabled]:focus, fieldset[disabled] .navbar-inverse .btn-link:focus { color: #444444; } .breadcrumb { padding: 8px 15px; margin-bottom: 23px; list-style: none; background-color: #f5f5f5; border-radius: 3px; } .breadcrumb > li { display: inline-block; } .breadcrumb > li + li:before { content: "/\00a0"; padding: 0 5px; color: #cccccc; } .breadcrumb > .active { color: #bbbbbb; } .pagination { display: inline-block; padding-left: 0; margin: 23px 0; border-radius: 3px; } .pagination > li { display: inline; } .pagination > li > a, .pagination > li > span { position: relative; float: left; padding: 6px 16px; line-height: 1.846; text-decoration: none; color: #2196f3; background-color: #ffffff; border: 1px solid #dddddd; margin-left: -1px; } .pagination > li:first-child > a, .pagination > li:first-child > span { margin-left: 0; border-bottom-left-radius: 3px; border-top-left-radius: 3px; } .pagination > li:last-child > a, .pagination > li:last-child > span { border-bottom-right-radius: 3px; border-top-right-radius: 3px; } .pagination > li > a:hover, .pagination > li > span:hover, .pagination > li > a:focus, .pagination > li > span:focus { z-index: 3; color: #0a6ebd; background-color: #eeeeee; border-color: #dddddd; } .pagination > .active > a, .pagination > .active > span, .pagination > .active > a:hover, .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus { z-index: 2; color: #ffffff; background-color: #2196f3; border-color: #2196f3; cursor: default; } .pagination > .disabled > span, .pagination > .disabled > span:hover, .pagination > .disabled > span:focus, .pagination > .disabled > a, .pagination > .disabled > a:hover, .pagination > .disabled > a:focus { color: #bbbbbb; background-color: #ffffff; border-color: #dddddd; cursor: not-allowed; } .pagination-lg > li > a, .pagination-lg > li > span { padding: 10px 16px; font-size: 17px; line-height: 1.3333333; } .pagination-lg > li:first-child > a, .pagination-lg > li:first-child > span { border-bottom-left-radius: 3px; border-top-left-radius: 3px; } .pagination-lg > li:last-child > a, .pagination-lg > li:last-child > span { border-bottom-right-radius: 3px; border-top-right-radius: 3px; } .pagination-sm > li > a, .pagination-sm > li > span { padding: 5px 10px; font-size: 12px; line-height: 1.5; } .pagination-sm > li:first-child > a, .pagination-sm > li:first-child > span { border-bottom-left-radius: 3px; border-top-left-radius: 3px; } .pagination-sm > li:last-child > a, .pagination-sm > li:last-child > span { border-bottom-right-radius: 3px; border-top-right-radius: 3px; } .pager { padding-left: 0; margin: 23px 0; list-style: none; text-align: center; } .pager li { display: inline; } .pager li > a, .pager li > span { display: inline-block; padding: 5px 14px; background-color: #ffffff; border: 1px solid #dddddd; border-radius: 15px; } .pager li > a:hover, .pager li > a:focus { text-decoration: none; background-color: #eeeeee; } .pager .next > a, .pager .next > span { float: right; } .pager .previous > a, .pager .previous > span { float: left; } .pager .disabled > a, .pager .disabled > a:hover, .pager .disabled > a:focus, .pager .disabled > span { color: #bbbbbb; background-color: #ffffff; cursor: not-allowed; } .label { display: inline; padding: .2em .6em .3em; font-size: 75%; font-weight: bold; line-height: 1; color: #ffffff; text-align: center; white-space: nowrap; vertical-align: baseline; border-radius: .25em; } a.label:hover, a.label:focus { color: #ffffff; text-decoration: none; cursor: pointer; } .label:empty { display: none; } .btn .label { position: relative; top: -1px; } .label-default { background-color: #bbbbbb; } .label-default[href]:hover, .label-default[href]:focus { background-color: #a2a2a2; } .label-primary { background-color: #2196f3; } .label-primary[href]:hover, .label-primary[href]:focus { background-color: #0c7cd5; } .label-success { background-color: #4caf50; } .label-success[href]:hover, .label-success[href]:focus { background-color: #3d8b40; } .label-info { background-color: #9c27b0; } .label-info[href]:hover, .label-info[href]:focus { background-color: #771e86; } .label-warning { background-color: #ff9800; } .label-warning[href]:hover, .label-warning[href]:focus { background-color: #cc7a00; } .label-danger { background-color: #e51c23; } .label-danger[href]:hover, .label-danger[href]:focus { background-color: #b9151b; } .badge { display: inline-block; min-width: 10px; padding: 3px 7px; font-size: 12px; font-weight: normal; color: #ffffff; line-height: 1; vertical-align: middle; white-space: nowrap; text-align: center; background-color: #bbbbbb; border-radius: 10px; } .badge:empty { display: none; } .btn .badge { position: relative; top: -1px; } .btn-xs .badge, .btn-group-xs > .btn .badge { top: 0; padding: 1px 5px; } a.badge:hover, a.badge:focus { color: #ffffff; text-decoration: none; cursor: pointer; } .list-group-item.active > .badge, .nav-pills > .active > a > .badge { color: #2196f3; background-color: #ffffff; } .list-group-item > .badge { float: right; } .list-group-item > .badge + .badge { margin-right: 5px; } .nav-pills > li > a > .badge { margin-left: 3px; } .jumbotron { padding-top: 30px; padding-bottom: 30px; margin-bottom: 30px; color: inherit; background-color: #f9f9f9; } .jumbotron h1, .jumbotron .h1 { color: #444444; } .jumbotron p { margin-bottom: 15px; font-size: 20px; font-weight: 200; } .jumbotron > hr { border-top-color: #e0e0e0; } .container .jumbotron, .container-fluid .jumbotron { border-radius: 3px; } .jumbotron .container { max-width: 100%; } @media screen and (min-width: 768px) { .jumbotron { padding-top: 48px; padding-bottom: 48px; } .container .jumbotron, .container-fluid .jumbotron { padding-left: 60px; padding-right: 60px; } .jumbotron h1, .jumbotron .h1 { font-size: 59px; } } .thumbnail { display: block; padding: 4px; margin-bottom: 23px; line-height: 1.846; background-color: #ffffff; border: 1px solid #dddddd; border-radius: 3px; -webkit-transition: border 0.2s ease-in-out; -o-transition: border 0.2s ease-in-out; transition: border 0.2s ease-in-out; } .thumbnail > img, .thumbnail a > img { margin-left: auto; margin-right: auto; } a.thumbnail:hover, a.thumbnail:focus, a.thumbnail.active { border-color: #2196f3; } .thumbnail .caption { padding: 9px; color: #666666; } .alert { padding: 15px; margin-bottom: 23px; border: 1px solid transparent; border-radius: 3px; } .alert h4 { margin-top: 0; color: inherit; } .alert .alert-link { font-weight: bold; } .alert > p, .alert > ul { margin-bottom: 0; } .alert > p + p { margin-top: 5px; } .alert-dismissable, .alert-dismissible { padding-right: 35px; } .alert-dismissable .close, .alert-dismissible .close { position: relative; top: -2px; right: -21px; color: inherit; } .alert-success { background-color: #dff0d8; border-color: #d6e9c6; color: #4caf50; } .alert-success hr { border-top-color: #c9e2b3; } .alert-success .alert-link { color: #3d8b40; } .alert-info { background-color: #e1bee7; border-color: #cba4dd; color: #9c27b0; } .alert-info hr { border-top-color: #c191d6; } .alert-info .alert-link { color: #771e86; } .alert-warning { background-color: #ffe0b2; border-color: #ffc599; color: #ff9800; } .alert-warning hr { border-top-color: #ffb67f; } .alert-warning .alert-link { color: #cc7a00; } .alert-danger { background-color: #f9bdbb; border-color: #f7a4af; color: #e51c23; } .alert-danger hr { border-top-color: #f58c9a; } .alert-danger .alert-link { color: #b9151b; } @-webkit-keyframes progress-bar-stripes { from { background-position: 40px 0; } to { background-position: 0 0; } } @-o-keyframes progress-bar-stripes { from { background-position: 40px 0; } to { background-position: 0 0; } } @keyframes progress-bar-stripes { from { background-position: 40px 0; } to { background-position: 0 0; } } .progress { overflow: hidden; height: 23px; margin-bottom: 23px; background-color: #f5f5f5; border-radius: 3px; -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); } .progress-bar { float: left; width: 0%; height: 100%; font-size: 12px; line-height: 23px; color: #ffffff; text-align: center; background-color: #2196f3; -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); -webkit-transition: width 0.6s ease; -o-transition: width 0.6s ease; transition: width 0.6s ease; } .progress-striped .progress-bar, .progress-bar-striped { background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); -webkit-background-size: 40px 40px; background-size: 40px 40px; } .progress.active .progress-bar, .progress-bar.active { -webkit-animation: progress-bar-stripes 2s linear infinite; -o-animation: progress-bar-stripes 2s linear infinite; animation: progress-bar-stripes 2s linear infinite; } .progress-bar-success { background-color: #4caf50; } .progress-striped .progress-bar-success { background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); } .progress-bar-info { background-color: #9c27b0; } .progress-striped .progress-bar-info { background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); } .progress-bar-warning { background-color: #ff9800; } .progress-striped .progress-bar-warning { background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); } .progress-bar-danger { background-color: #e51c23; } .progress-striped .progress-bar-danger { background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: -o-linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent); } .media { margin-top: 15px; } .media:first-child { margin-top: 0; } .media, .media-body { zoom: 1; overflow: hidden; } .media-body { width: 10000px; } .media-object { display: block; } .media-object.img-thumbnail { max-width: none; } .media-right, .media > .pull-right { padding-left: 10px; } .media-left, .media > .pull-left { padding-right: 10px; } .media-left, .media-right, .media-body { display: table-cell; vertical-align: top; } .media-middle { vertical-align: middle; } .media-bottom { vertical-align: bottom; } .media-heading { margin-top: 0; margin-bottom: 5px; } .media-list { padding-left: 0; list-style: none; } .list-group { margin-bottom: 20px; padding-left: 0; } .list-group-item { position: relative; display: block; padding: 10px 15px; margin-bottom: -1px; background-color: #ffffff; border: 1px solid #dddddd; } .list-group-item:first-child { border-top-right-radius: 3px; border-top-left-radius: 3px; } .list-group-item:last-child { margin-bottom: 0; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; } a.list-group-item, button.list-group-item { color: #555555; } a.list-group-item .list-group-item-heading, button.list-group-item .list-group-item-heading { color: #333333; } a.list-group-item:hover, button.list-group-item:hover, a.list-group-item:focus, button.list-group-item:focus { text-decoration: none; color: #555555; background-color: #f5f5f5; } button.list-group-item { width: 100%; text-align: left; } .list-group-item.disabled, .list-group-item.disabled:hover, .list-group-item.disabled:focus { background-color: #eeeeee; color: #bbbbbb; cursor: not-allowed; } .list-group-item.disabled .list-group-item-heading, .list-group-item.disabled:hover .list-group-item-heading, .list-group-item.disabled:focus .list-group-item-heading { color: inherit; } .list-group-item.disabled .list-group-item-text, .list-group-item.disabled:hover .list-group-item-text, .list-group-item.disabled:focus .list-group-item-text { color: #bbbbbb; } .list-group-item.active, .list-group-item.active:hover, .list-group-item.active:focus { z-index: 2; color: #ffffff; background-color: #2196f3; border-color: #2196f3; } .list-group-item.active .list-group-item-heading, .list-group-item.active:hover .list-group-item-heading, .list-group-item.active:focus .list-group-item-heading, .list-group-item.active .list-group-item-heading > small, .list-group-item.active:hover .list-group-item-heading > small, .list-group-item.active:focus .list-group-item-heading > small, .list-group-item.active .list-group-item-heading > .small, .list-group-item.active:hover .list-group-item-heading > .small, .list-group-item.active:focus .list-group-item-heading > .small { color: inherit; } .list-group-item.active .list-group-item-text, .list-group-item.active:hover .list-group-item-text, .list-group-item.active:focus .list-group-item-text { color: #e3f2fd; } .list-group-item-success { color: #4caf50; background-color: #dff0d8; } a.list-group-item-success, button.list-group-item-success { color: #4caf50; } a.list-group-item-success .list-group-item-heading, button.list-group-item-success .list-group-item-heading { color: inherit; } a.list-group-item-success:hover, button.list-group-item-success:hover, a.list-group-item-success:focus, button.list-group-item-success:focus { color: #4caf50; background-color: #d0e9c6; } a.list-group-item-success.active, button.list-group-item-success.active, a.list-group-item-success.active:hover, button.list-group-item-success.active:hover, a.list-group-item-success.active:focus, button.list-group-item-success.active:focus { color: #fff; background-color: #4caf50; border-color: #4caf50; } .list-group-item-info { color: #9c27b0; background-color: #e1bee7; } a.list-group-item-info, button.list-group-item-info { color: #9c27b0; } a.list-group-item-info .list-group-item-heading, button.list-group-item-info .list-group-item-heading { color: inherit; } a.list-group-item-info:hover, button.list-group-item-info:hover, a.list-group-item-info:focus, button.list-group-item-info:focus { color: #9c27b0; background-color: #d8abe0; } a.list-group-item-info.active, button.list-group-item-info.active, a.list-group-item-info.active:hover, button.list-group-item-info.active:hover, a.list-group-item-info.active:focus, button.list-group-item-info.active:focus { color: #fff; background-color: #9c27b0; border-color: #9c27b0; } .list-group-item-warning { color: #ff9800; background-color: #ffe0b2; } a.list-group-item-warning, button.list-group-item-warning { color: #ff9800; } a.list-group-item-warning .list-group-item-heading, button.list-group-item-warning .list-group-item-heading { color: inherit; } a.list-group-item-warning:hover, button.list-group-item-warning:hover, a.list-group-item-warning:focus, button.list-group-item-warning:focus { color: #ff9800; background-color: #ffd699; } a.list-group-item-warning.active, button.list-group-item-warning.active, a.list-group-item-warning.active:hover, button.list-group-item-warning.active:hover, a.list-group-item-warning.active:focus, button.list-group-item-warning.active:focus { color: #fff; background-color: #ff9800; border-color: #ff9800; } .list-group-item-danger { color: #e51c23; background-color: #f9bdbb; } a.list-group-item-danger, button.list-group-item-danger { color: #e51c23; } a.list-group-item-danger .list-group-item-heading, button.list-group-item-danger .list-group-item-heading { color: inherit; } a.list-group-item-danger:hover, button.list-group-item-danger:hover, a.list-group-item-danger:focus, button.list-group-item-danger:focus { color: #e51c23; background-color: #f7a6a4; } a.list-group-item-danger.active, button.list-group-item-danger.active, a.list-group-item-danger.active:hover, button.list-group-item-danger.active:hover, a.list-group-item-danger.active:focus, button.list-group-item-danger.active:focus { color: #fff; background-color: #e51c23; border-color: #e51c23; } .list-group-item-heading { margin-top: 0; margin-bottom: 5px; } .list-group-item-text { margin-bottom: 0; line-height: 1.3; } .panel { margin-bottom: 23px; background-color: #ffffff; border: 1px solid transparent; border-radius: 3px; -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05); } .panel-body { padding: 15px; } .panel-heading { padding: 10px 15px; border-bottom: 1px solid transparent; border-top-right-radius: 2px; border-top-left-radius: 2px; } .panel-heading > .dropdown .dropdown-toggle { color: inherit; } .panel-title { margin-top: 0; margin-bottom: 0; font-size: 15px; color: inherit; } .panel-title > a, .panel-title > small, .panel-title > .small, .panel-title > small > a, .panel-title > .small > a { color: inherit; } .panel-footer { padding: 10px 15px; background-color: #f5f5f5; border-top: 1px solid #dddddd; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; } .panel > .list-group, .panel > .panel-collapse > .list-group { margin-bottom: 0; } .panel > .list-group .list-group-item, .panel > .panel-collapse > .list-group .list-group-item { border-width: 1px 0; border-radius: 0; } .panel > .list-group:first-child .list-group-item:first-child, .panel > .panel-collapse > .list-group:first-child .list-group-item:first-child { border-top: 0; border-top-right-radius: 2px; border-top-left-radius: 2px; } .panel > .list-group:last-child .list-group-item:last-child, .panel > .panel-collapse > .list-group:last-child .list-group-item:last-child { border-bottom: 0; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; } .panel > .panel-heading + .panel-collapse > .list-group .list-group-item:first-child { border-top-right-radius: 0; border-top-left-radius: 0; } .panel-heading + .list-group .list-group-item:first-child { border-top-width: 0; } .list-group + .panel-footer { border-top-width: 0; } .panel > .table, .panel > .table-responsive > .table, .panel > .panel-collapse > .table { margin-bottom: 0; } .panel > .table caption, .panel > .table-responsive > .table caption, .panel > .panel-collapse > .table caption { padding-left: 15px; padding-right: 15px; } .panel > .table:first-child, .panel > .table-responsive:first-child > .table:first-child { border-top-right-radius: 2px; border-top-left-radius: 2px; } .panel > .table:first-child > thead:first-child > tr:first-child, .panel > .table-responsive:first-child > .table:first-child > thead:first-child > tr:first-child, .panel > .table:first-child > tbody:first-child > tr:first-child, .panel > .table-responsive:first-child > .table:first-child > tbody:first-child > tr:first-child { border-top-left-radius: 2px; border-top-right-radius: 2px; } .panel > .table:first-child > thead:first-child > tr:first-child td:first-child, .panel > .table-responsive:first-child > .table:first-child > thead:first-child > tr:first-child td:first-child, .panel > .table:first-child > tbody:first-child > tr:first-child td:first-child, .panel > .table-responsive:first-child > .table:first-child > tbody:first-child > tr:first-child td:first-child, .panel > .table:first-child > thead:first-child > tr:first-child th:first-child, .panel > .table-responsive:first-child > .table:first-child > thead:first-child > tr:first-child th:first-child, .panel > .table:first-child > tbody:first-child > tr:first-child th:first-child, .panel > .table-responsive:first-child > .table:first-child > tbody:first-child > tr:first-child th:first-child { border-top-left-radius: 2px; } .panel > .table:first-child > thead:first-child > tr:first-child td:last-child, .panel > .table-responsive:first-child > .table:first-child > thead:first-child > tr:first-child td:last-child, .panel > .table:first-child > tbody:first-child > tr:first-child td:last-child, .panel > .table-responsive:first-child > .table:first-child > tbody:first-child > tr:first-child td:last-child, .panel > .table:first-child > thead:first-child > tr:first-child th:last-child, .panel > .table-responsive:first-child > .table:first-child > thead:first-child > tr:first-child th:last-child, .panel > .table:first-child > tbody:first-child > tr:first-child th:last-child, .panel > .table-responsive:first-child > .table:first-child > tbody:first-child > tr:first-child th:last-child { border-top-right-radius: 2px; } .panel > .table:last-child, .panel > .table-responsive:last-child > .table:last-child { border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; } .panel > .table:last-child > tbody:last-child > tr:last-child, .panel > .table-responsive:last-child > .table:last-child > tbody:last-child > tr:last-child, .panel > .table:last-child > tfoot:last-child > tr:last-child, .panel > .table-responsive:last-child > .table:last-child > tfoot:last-child > tr:last-child { border-bottom-left-radius: 2px; border-bottom-right-radius: 2px; } .panel > .table:last-child > tbody:last-child > tr:last-child td:first-child, .panel > .table-responsive:last-child > .table:last-child > tbody:last-child > tr:last-child td:first-child, .panel > .table:last-child > tfoot:last-child > tr:last-child td:first-child, .panel > .table-responsive:last-child > .table:last-child > tfoot:last-child > tr:last-child td:first-child, .panel > .table:last-child > tbody:last-child > tr:last-child th:first-child, .panel > .table-responsive:last-child > .table:last-child > tbody:last-child > tr:last-child th:first-child, .panel > .table:last-child > tfoot:last-child > tr:last-child th:first-child, .panel > .table-responsive:last-child > .table:last-child > tfoot:last-child > tr:last-child th:first-child { border-bottom-left-radius: 2px; } .panel > .table:last-child > tbody:last-child > tr:last-child td:last-child, .panel > .table-responsive:last-child > .table:last-child > tbody:last-child > tr:last-child td:last-child, .panel > .table:last-child > tfoot:last-child > tr:last-child td:last-child, .panel > .table-responsive:last-child > .table:last-child > tfoot:last-child > tr:last-child td:last-child, .panel > .table:last-child > tbody:last-child > tr:last-child th:last-child, .panel > .table-responsive:last-child > .table:last-child > tbody:last-child > tr:last-child th:last-child, .panel > .table:last-child > tfoot:last-child > tr:last-child th:last-child, .panel > .table-responsive:last-child > .table:last-child > tfoot:last-child > tr:last-child th:last-child { border-bottom-right-radius: 2px; } .panel > .panel-body + .table, .panel > .panel-body + .table-responsive, .panel > .table + .panel-body, .panel > .table-responsive + .panel-body { border-top: 1px solid #dddddd; } .panel > .table > tbody:first-child > tr:first-child th, .panel > .table > tbody:first-child > tr:first-child td { border-top: 0; } .panel > .table-bordered, .panel > .table-responsive > .table-bordered { border: 0; } .panel > .table-bordered > thead > tr > th:first-child, .panel > .table-responsive > .table-bordered > thead > tr > th:first-child, .panel > .table-bordered > tbody > tr > th:first-child, .panel > .table-responsive > .table-bordered > tbody > tr > th:first-child, .panel > .table-bordered > tfoot > tr > th:first-child, .panel > .table-responsive > .table-bordered > tfoot > tr > th:first-child, .panel > .table-bordered > thead > tr > td:first-child, .panel > .table-responsive > .table-bordered > thead > tr > td:first-child, .panel > .table-bordered > tbody > tr > td:first-child, .panel > .table-responsive > .table-bordered > tbody > tr > td:first-child, .panel > .table-bordered > tfoot > tr > td:first-child, .panel > .table-responsive > .table-bordered > tfoot > tr > td:first-child { border-left: 0; } .panel > .table-bordered > thead > tr > th:last-child, .panel > .table-responsive > .table-bordered > thead > tr > th:last-child, .panel > .table-bordered > tbody > tr > th:last-child, .panel > .table-responsive > .table-bordered > tbody > tr > th:last-child, .panel > .table-bordered > tfoot > tr > th:last-child, .panel > .table-responsive > .table-bordered > tfoot > tr > th:last-child, .panel > .table-bordered > thead > tr > td:last-child, .panel > .table-responsive > .table-bordered > thead > tr > td:last-child, .panel > .table-bordered > tbody > tr > td:last-child, .panel > .table-responsive > .table-bordered > tbody > tr > td:last-child, .panel > .table-bordered > tfoot > tr > td:last-child, .panel > .table-responsive > .table-bordered > tfoot > tr > td:last-child { border-right: 0; } .panel > .table-bordered > thead > tr:first-child > td, .panel > .table-responsive > .table-bordered > thead > tr:first-child > td, .panel > .table-bordered > tbody > tr:first-child > td, .panel > .table-responsive > .table-bordered > tbody > tr:first-child > td, .panel > .table-bordered > thead > tr:first-child > th, .panel > .table-responsive > .table-bordered > thead > tr:first-child > th, .panel > .table-bordered > tbody > tr:first-child > th, .panel > .table-responsive > .table-bordered > tbody > tr:first-child > th { border-bottom: 0; } .panel > .table-bordered > tbody > tr:last-child > td, .panel > .table-responsive > .table-bordered > tbody > tr:last-child > td, .panel > .table-bordered > tfoot > tr:last-child > td, .panel > .table-responsive > .table-bordered > tfoot > tr:last-child > td, .panel > .table-bordered > tbody > tr:last-child > th, .panel > .table-responsive > .table-bordered > tbody > tr:last-child > th, .panel > .table-bordered > tfoot > tr:last-child > th, .panel > .table-responsive > .table-bordered > tfoot > tr:last-child > th { border-bottom: 0; } .panel > .table-responsive { border: 0; margin-bottom: 0; } .panel-group { margin-bottom: 23px; } .panel-group .panel { margin-bottom: 0; border-radius: 3px; } .panel-group .panel + .panel { margin-top: 5px; } .panel-group .panel-heading { border-bottom: 0; } .panel-group .panel-heading + .panel-collapse > .panel-body, .panel-group .panel-heading + .panel-collapse > .list-group { border-top: 1px solid #dddddd; } .panel-group .panel-footer { border-top: 0; } .panel-group .panel-footer + .panel-collapse .panel-body { border-bottom: 1px solid #dddddd; } .panel-default { border-color: #dddddd; } .panel-default > .panel-heading { color: #212121; background-color: #f5f5f5; border-color: #dddddd; } .panel-default > .panel-heading + .panel-collapse > .panel-body { border-top-color: #dddddd; } .panel-default > .panel-heading .badge { color: #f5f5f5; background-color: #212121; } .panel-default > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #dddddd; } .panel-primary { border-color: #2196f3; } .panel-primary > .panel-heading { color: #ffffff; background-color: #2196f3; border-color: #2196f3; } .panel-primary > .panel-heading + .panel-collapse > .panel-body { border-top-color: #2196f3; } .panel-primary > .panel-heading .badge { color: #2196f3; background-color: #ffffff; } .panel-primary > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #2196f3; } .panel-success { border-color: #d6e9c6; } .panel-success > .panel-heading { color: #ffffff; background-color: #4caf50; border-color: #d6e9c6; } .panel-success > .panel-heading + .panel-collapse > .panel-body { border-top-color: #d6e9c6; } .panel-success > .panel-heading .badge { color: #4caf50; background-color: #ffffff; } .panel-success > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #d6e9c6; } .panel-info { border-color: #cba4dd; } .panel-info > .panel-heading { color: #ffffff; background-color: #9c27b0; border-color: #cba4dd; } .panel-info > .panel-heading + .panel-collapse > .panel-body { border-top-color: #cba4dd; } .panel-info > .panel-heading .badge { color: #9c27b0; background-color: #ffffff; } .panel-info > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #cba4dd; } .panel-warning { border-color: #ffc599; } .panel-warning > .panel-heading { color: #ffffff; background-color: #ff9800; border-color: #ffc599; } .panel-warning > .panel-heading + .panel-collapse > .panel-body { border-top-color: #ffc599; } .panel-warning > .panel-heading .badge { color: #ff9800; background-color: #ffffff; } .panel-warning > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #ffc599; } .panel-danger { border-color: #f7a4af; } .panel-danger > .panel-heading { color: #ffffff; background-color: #e51c23; border-color: #f7a4af; } .panel-danger > .panel-heading + .panel-collapse > .panel-body { border-top-color: #f7a4af; } .panel-danger > .panel-heading .badge { color: #e51c23; background-color: #ffffff; } .panel-danger > .panel-footer + .panel-collapse > .panel-body { border-bottom-color: #f7a4af; } .embed-responsive { position: relative; display: block; height: 0; padding: 0; overflow: hidden; } .embed-responsive .embed-responsive-item, .embed-responsive iframe, .embed-responsive embed, .embed-responsive object, .embed-responsive video { position: absolute; top: 0; left: 0; bottom: 0; height: 100%; width: 100%; border: 0; } .embed-responsive-16by9 { padding-bottom: 56.25%; } .embed-responsive-4by3 { padding-bottom: 75%; } .well { min-height: 20px; padding: 19px; margin-bottom: 20px; background-color: #f9f9f9; border: 1px solid transparent; border-radius: 3px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); } .well blockquote { border-color: #ddd; border-color: rgba(0, 0, 0, 0.15); } .well-lg { padding: 24px; border-radius: 3px; } .well-sm { padding: 9px; border-radius: 3px; } .close { float: right; font-size: 19.5px; font-weight: normal; line-height: 1; color: #000000; text-shadow: none; opacity: 0.2; filter: alpha(opacity=20); } .close:hover, .close:focus { color: #000000; text-decoration: none; cursor: pointer; opacity: 0.5; filter: alpha(opacity=50); } button.close { padding: 0; cursor: pointer; background: transparent; border: 0; -webkit-appearance: none; } .modal-open { overflow: hidden; } .modal { display: none; overflow: hidden; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1050; -webkit-overflow-scrolling: touch; outline: 0; } .modal.fade .modal-dialog { -webkit-transform: translate(0, -25%); -ms-transform: translate(0, -25%); -o-transform: translate(0, -25%); transform: translate(0, -25%); -webkit-transition: -webkit-transform 0.3s ease-out; -o-transition: -o-transform 0.3s ease-out; transition: transform 0.3s ease-out; } .modal.in .modal-dialog { -webkit-transform: translate(0, 0); -ms-transform: translate(0, 0); -o-transform: translate(0, 0); transform: translate(0, 0); } .modal-open .modal { overflow-x: hidden; overflow-y: auto; } .modal-dialog { position: relative; width: auto; margin: 10px; } .modal-content { position: relative; background-color: #ffffff; border: 1px solid #999999; border: 1px solid transparent; border-radius: 3px; -webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5); box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5); -webkit-background-clip: padding-box; background-clip: padding-box; outline: 0; } .modal-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1040; background-color: #000000; } .modal-backdrop.fade { opacity: 0; filter: alpha(opacity=0); } .modal-backdrop.in { opacity: 0.5; filter: alpha(opacity=50); } .modal-header { padding: 15px; border-bottom: 1px solid transparent; min-height: 16.846px; } .modal-header .close { margin-top: -2px; } .modal-title { margin: 0; line-height: 1.846; } .modal-body { position: relative; padding: 15px; } .modal-footer { padding: 15px; text-align: right; border-top: 1px solid transparent; } .modal-footer .btn + .btn { margin-left: 5px; margin-bottom: 0; } .modal-footer .btn-group .btn + .btn { margin-left: -1px; } .modal-footer .btn-block + .btn-block { margin-left: 0; } .modal-scrollbar-measure { position: absolute; top: -9999px; width: 50px; height: 50px; overflow: scroll; } @media (min-width: 768px) { .modal-dialog { width: 600px; margin: 30px auto; } .modal-content { -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5); box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5); } .modal-sm { width: 300px; } } @media (min-width: 992px) { .modal-lg { width: 900px; } } .tooltip { position: absolute; z-index: 1070; display: block; font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-weight: normal; letter-spacing: normal; line-break: auto; line-height: 1.846; text-align: left; text-align: start; text-decoration: none; text-shadow: none; text-transform: none; white-space: normal; word-break: normal; word-spacing: normal; word-wrap: normal; font-size: 12px; opacity: 0; filter: alpha(opacity=0); } .tooltip.in { opacity: 0.9; filter: alpha(opacity=90); } .tooltip.top { margin-top: -3px; padding: 5px 0; } .tooltip.right { margin-left: 3px; padding: 0 5px; } .tooltip.bottom { margin-top: 3px; padding: 5px 0; } .tooltip.left { margin-left: -3px; padding: 0 5px; } .tooltip-inner { max-width: 200px; padding: 3px 8px; color: #ffffff; text-align: center; background-color: #727272; border-radius: 3px; } .tooltip-arrow { position: absolute; width: 0; height: 0; border-color: transparent; border-style: solid; } .tooltip.top .tooltip-arrow { bottom: 0; left: 50%; margin-left: -5px; border-width: 5px 5px 0; border-top-color: #727272; } .tooltip.top-left .tooltip-arrow { bottom: 0; right: 5px; margin-bottom: -5px; border-width: 5px 5px 0; border-top-color: #727272; } .tooltip.top-right .tooltip-arrow { bottom: 0; left: 5px; margin-bottom: -5px; border-width: 5px 5px 0; border-top-color: #727272; } .tooltip.right .tooltip-arrow { top: 50%; left: 0; margin-top: -5px; border-width: 5px 5px 5px 0; border-right-color: #727272; } .tooltip.left .tooltip-arrow { top: 50%; right: 0; margin-top: -5px; border-width: 5px 0 5px 5px; border-left-color: #727272; } .tooltip.bottom .tooltip-arrow { top: 0; left: 50%; margin-left: -5px; border-width: 0 5px 5px; border-bottom-color: #727272; } .tooltip.bottom-left .tooltip-arrow { top: 0; right: 5px; margin-top: -5px; border-width: 0 5px 5px; border-bottom-color: #727272; } .tooltip.bottom-right .tooltip-arrow { top: 0; left: 5px; margin-top: -5px; border-width: 0 5px 5px; border-bottom-color: #727272; } .popover { position: absolute; top: 0; left: 0; z-index: 1060; display: none; max-width: 276px; padding: 1px; font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; font-style: normal; font-weight: normal; letter-spacing: normal; line-break: auto; line-height: 1.846; text-align: left; text-align: start; text-decoration: none; text-shadow: none; text-transform: none; white-space: normal; word-break: normal; word-spacing: normal; word-wrap: normal; font-size: 13px; background-color: #ffffff; -webkit-background-clip: padding-box; background-clip: padding-box; border: 1px solid transparent; border-radius: 3px; -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); } .popover.top { margin-top: -10px; } .popover.right { margin-left: 10px; } .popover.bottom { margin-top: 10px; } .popover.left { margin-left: -10px; } .popover-title { margin: 0; padding: 8px 14px; font-size: 13px; background-color: #f7f7f7; border-bottom: 1px solid #ebebeb; border-radius: 2px 2px 0 0; } .popover-content { padding: 9px 14px; } .popover > .arrow, .popover > .arrow:after { position: absolute; display: block; width: 0; height: 0; border-color: transparent; border-style: solid; } .popover > .arrow { border-width: 11px; } .popover > .arrow:after { border-width: 10px; content: ""; } .popover.top > .arrow { left: 50%; margin-left: -11px; border-bottom-width: 0; border-top-color: rgba(0, 0, 0, 0); border-top-color: rgba(0, 0, 0, 0.075); bottom: -11px; } .popover.top > .arrow:after { content: " "; bottom: 1px; margin-left: -10px; border-bottom-width: 0; border-top-color: #ffffff; } .popover.right > .arrow { top: 50%; left: -11px; margin-top: -11px; border-left-width: 0; border-right-color: rgba(0, 0, 0, 0); border-right-color: rgba(0, 0, 0, 0.075); } .popover.right > .arrow:after { content: " "; left: 1px; bottom: -10px; border-left-width: 0; border-right-color: #ffffff; } .popover.bottom > .arrow { left: 50%; margin-left: -11px; border-top-width: 0; border-bottom-color: rgba(0, 0, 0, 0); border-bottom-color: rgba(0, 0, 0, 0.075); top: -11px; } .popover.bottom > .arrow:after { content: " "; top: 1px; margin-left: -10px; border-top-width: 0; border-bottom-color: #ffffff; } .popover.left > .arrow { top: 50%; right: -11px; margin-top: -11px; border-right-width: 0; border-left-color: rgba(0, 0, 0, 0); border-left-color: rgba(0, 0, 0, 0.075); } .popover.left > .arrow:after { content: " "; right: 1px; border-right-width: 0; border-left-color: #ffffff; bottom: -10px; } .carousel { position: relative; } .carousel-inner { position: relative; overflow: hidden; width: 100%; } .carousel-inner > .item { display: none; position: relative; -webkit-transition: 0.6s ease-in-out left; -o-transition: 0.6s ease-in-out left; transition: 0.6s ease-in-out left; } .carousel-inner > .item > img, .carousel-inner > .item > a > img { line-height: 1; } @media all and (transform-3d), (-webkit-transform-3d) { .carousel-inner > .item { -webkit-transition: -webkit-transform 0.6s ease-in-out; -o-transition: -o-transform 0.6s ease-in-out; transition: transform 0.6s ease-in-out; -webkit-backface-visibility: hidden; backface-visibility: hidden; -webkit-perspective: 1000px; perspective: 1000px; } .carousel-inner > .item.next, .carousel-inner > .item.active.right { -webkit-transform: translate3d(100%, 0, 0); transform: translate3d(100%, 0, 0); left: 0; } .carousel-inner > .item.prev, .carousel-inner > .item.active.left { -webkit-transform: translate3d(-100%, 0, 0); transform: translate3d(-100%, 0, 0); left: 0; } .carousel-inner > .item.next.left, .carousel-inner > .item.prev.right, .carousel-inner > .item.active { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); left: 0; } } .carousel-inner > .active, .carousel-inner > .next, .carousel-inner > .prev { display: block; } .carousel-inner > .active { left: 0; } .carousel-inner > .next, .carousel-inner > .prev { position: absolute; top: 0; width: 100%; } .carousel-inner > .next { left: 100%; } .carousel-inner > .prev { left: -100%; } .carousel-inner > .next.left, .carousel-inner > .prev.right { left: 0; } .carousel-inner > .active.left { left: -100%; } .carousel-inner > .active.right { left: 100%; } .carousel-control { position: absolute; top: 0; left: 0; bottom: 0; width: 15%; opacity: 0.5; filter: alpha(opacity=50); font-size: 20px; color: #ffffff; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); } .carousel-control.left { background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%); background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%); background-image: -webkit-gradient(linear, left top, right top, from(rgba(0, 0, 0, 0.5)), to(rgba(0, 0, 0, 0.0001))); background-image: linear-gradient(to right, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1); } .carousel-control.right { left: auto; right: 0; background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%); background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%); background-image: -webkit-gradient(linear, left top, right top, from(rgba(0, 0, 0, 0.0001)), to(rgba(0, 0, 0, 0.5))); background-image: linear-gradient(to right, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#80000000', GradientType=1); } .carousel-control:hover, .carousel-control:focus { outline: 0; color: #ffffff; text-decoration: none; opacity: 0.9; filter: alpha(opacity=90); } .carousel-control .icon-prev, .carousel-control .icon-next, .carousel-control .glyphicon-chevron-left, .carousel-control .glyphicon-chevron-right { position: absolute; top: 50%; margin-top: -10px; z-index: 5; display: inline-block; } .carousel-control .icon-prev, .carousel-control .glyphicon-chevron-left { left: 50%; margin-left: -10px; } .carousel-control .icon-next, .carousel-control .glyphicon-chevron-right { right: 50%; margin-right: -10px; } .carousel-control .icon-prev, .carousel-control .icon-next { width: 20px; height: 20px; line-height: 1; font-family: serif; } .carousel-control .icon-prev:before { content: '\2039'; } .carousel-control .icon-next:before { content: '\203a'; } .carousel-indicators { position: absolute; bottom: 10px; left: 50%; z-index: 15; width: 60%; margin-left: -30%; padding-left: 0; list-style: none; text-align: center; } .carousel-indicators li { display: inline-block; width: 10px; height: 10px; margin: 1px; text-indent: -999px; border: 1px solid #ffffff; border-radius: 10px; cursor: pointer; background-color: #000 \9; background-color: rgba(0, 0, 0, 0); } .carousel-indicators .active { margin: 0; width: 12px; height: 12px; background-color: #ffffff; } .carousel-caption { position: absolute; left: 15%; right: 15%; bottom: 20px; z-index: 10; padding-top: 20px; padding-bottom: 20px; color: #ffffff; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); } .carousel-caption .btn { text-shadow: none; } @media screen and (min-width: 768px) { .carousel-control .glyphicon-chevron-left, .carousel-control .glyphicon-chevron-right, .carousel-control .icon-prev, .carousel-control .icon-next { width: 30px; height: 30px; margin-top: -15px; font-size: 30px; } .carousel-control .glyphicon-chevron-left, .carousel-control .icon-prev { margin-left: -15px; } .carousel-control .glyphicon-chevron-right, .carousel-control .icon-next { margin-right: -15px; } .carousel-caption { left: 20%; right: 20%; padding-bottom: 30px; } .carousel-indicators { bottom: 20px; } } .clearfix:before, .clearfix:after, .dl-horizontal dd:before, .dl-horizontal dd:after, .container:before, .container:after, .container-fluid:before, .container-fluid:after, .row:before, .row:after, .form-horizontal .form-group:before, .form-horizontal .form-group:after, .btn-toolbar:before, .btn-toolbar:after, .btn-group-vertical > .btn-group:before, .btn-group-vertical > .btn-group:after, .nav:before, .nav:after, .navbar:before, .navbar:after, .navbar-header:before, .navbar-header:after, .navbar-collapse:before, .navbar-collapse:after, .pager:before, .pager:after, .panel-body:before, .panel-body:after, .modal-footer:before, .modal-footer:after { content: " "; display: table; } .clearfix:after, .dl-horizontal dd:after, .container:after, .container-fluid:after, .row:after, .form-horizontal .form-group:after, .btn-toolbar:after, .btn-group-vertical > .btn-group:after, .nav:after, .navbar:after, .navbar-header:after, .navbar-collapse:after, .pager:after, .panel-body:after, .modal-footer:after { clear: both; } .center-block { display: block; margin-left: auto; margin-right: auto; } .pull-right { float: right !important; } .pull-left { float: left !important; } .hide { display: none !important; } .show { display: block !important; } .invisible { visibility: hidden; } .text-hide { font: 0/0 a; color: transparent; text-shadow: none; background-color: transparent; border: 0; } .hidden { display: none !important; } .affix { position: fixed; } @-ms-viewport { width: device-width; } .visible-xs, .visible-sm, .visible-md, .visible-lg { display: none !important; } .visible-xs-block, .visible-xs-inline, .visible-xs-inline-block, .visible-sm-block, .visible-sm-inline, .visible-sm-inline-block, .visible-md-block, .visible-md-inline, .visible-md-inline-block, .visible-lg-block, .visible-lg-inline, .visible-lg-inline-block { display: none !important; } @media (max-width: 767px) { .visible-xs { display: block !important; } table.visible-xs { display: table !important; } tr.visible-xs { display: table-row !important; } th.visible-xs, td.visible-xs { display: table-cell !important; } } @media (max-width: 767px) { .visible-xs-block { display: block !important; } } @media (max-width: 767px) { .visible-xs-inline { display: inline !important; } } @media (max-width: 767px) { .visible-xs-inline-block { display: inline-block !important; } } @media (min-width: 768px) and (max-width: 991px) { .visible-sm { display: block !important; } table.visible-sm { display: table !important; } tr.visible-sm { display: table-row !important; } th.visible-sm, td.visible-sm { display: table-cell !important; } } @media (min-width: 768px) and (max-width: 991px) { .visible-sm-block { display: block !important; } } @media (min-width: 768px) and (max-width: 991px) { .visible-sm-inline { display: inline !important; } } @media (min-width: 768px) and (max-width: 991px) { .visible-sm-inline-block { display: inline-block !important; } } @media (min-width: 992px) and (max-width: 1199px) { .visible-md { display: block !important; } table.visible-md { display: table !important; } tr.visible-md { display: table-row !important; } th.visible-md, td.visible-md { display: table-cell !important; } } @media (min-width: 992px) and (max-width: 1199px) { .visible-md-block { display: block !important; } } @media (min-width: 992px) and (max-width: 1199px) { .visible-md-inline { display: inline !important; } } @media (min-width: 992px) and (max-width: 1199px) { .visible-md-inline-block { display: inline-block !important; } } @media (min-width: 1200px) { .visible-lg { display: block !important; } table.visible-lg { display: table !important; } tr.visible-lg { display: table-row !important; } th.visible-lg, td.visible-lg { display: table-cell !important; } } @media (min-width: 1200px) { .visible-lg-block { display: block !important; } } @media (min-width: 1200px) { .visible-lg-inline { display: inline !important; } } @media (min-width: 1200px) { .visible-lg-inline-block { display: inline-block !important; } } @media (max-width: 767px) { .hidden-xs { display: none !important; } } @media (min-width: 768px) and (max-width: 991px) { .hidden-sm { display: none !important; } } @media (min-width: 992px) and (max-width: 1199px) { .hidden-md { display: none !important; } } @media (min-width: 1200px) { .hidden-lg { display: none !important; } } .visible-print { display: none !important; } @media print { .visible-print { display: block !important; } table.visible-print { display: table !important; } tr.visible-print { display: table-row !important; } th.visible-print, td.visible-print { display: table-cell !important; } } .visible-print-block { display: none !important; } @media print { .visible-print-block { display: block !important; } } .visible-print-inline { display: none !important; } @media print { .visible-print-inline { display: inline !important; } } .visible-print-inline-block { display: none !important; } @media print { .visible-print-inline-block { display: inline-block !important; } } @media print { .hidden-print { display: none !important; } } .navbar { border: none; -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); } .navbar-brand { font-size: 24px; } .navbar-inverse .form-control { color: #fff; } .navbar-inverse .form-control::-moz-placeholder { color: #b2dbfb; opacity: 1; } .navbar-inverse .form-control:-ms-input-placeholder { color: #b2dbfb; } .navbar-inverse .form-control::-webkit-input-placeholder { color: #b2dbfb; } .navbar-inverse .form-control[type=text], .navbar-inverse .form-control[type=password] { -webkit-box-shadow: inset 0 -1px 0 #b2dbfb; box-shadow: inset 0 -1px 0 #b2dbfb; } .navbar-inverse .form-control[type=text]:focus, .navbar-inverse .form-control[type=password]:focus { -webkit-box-shadow: inset 0 -2px 0 #ffffff; box-shadow: inset 0 -2px 0 #ffffff; } .btn-default { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-default:hover, .btn-default:active:hover, .btn-default:focus { background-color: #f0f0f0; } .btn-default:active { background-color: #f0f0f0; background-image: -webkit-radial-gradient(circle, #f0f0f0 10%, #ffffff 11%); background-image: -o-radial-gradient(circle, #f0f0f0 10%, #ffffff 11%); background-image: radial-gradient(circle, #f0f0f0 10%, #ffffff 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn-primary { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-primary:hover, .btn-primary:active:hover, .btn-primary:focus { background-color: #0d87e9; } .btn-primary:active { background-color: #0d87e9; background-image: -webkit-radial-gradient(circle, #0d87e9 10%, #2196f3 11%); background-image: -o-radial-gradient(circle, #0d87e9 10%, #2196f3 11%); background-image: radial-gradient(circle, #0d87e9 10%, #2196f3 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn-success { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-success:hover, .btn-success:active:hover, .btn-success:focus { background-color: #439a46; } .btn-success:active { background-color: #439a46; background-image: -webkit-radial-gradient(circle, #439a46 10%, #4caf50 11%); background-image: -o-radial-gradient(circle, #439a46 10%, #4caf50 11%); background-image: radial-gradient(circle, #439a46 10%, #4caf50 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn-info { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-info:hover, .btn-info:active:hover, .btn-info:focus { background-color: #862197; } .btn-info:active { background-color: #862197; background-image: -webkit-radial-gradient(circle, #862197 10%, #9c27b0 11%); background-image: -o-radial-gradient(circle, #862197 10%, #9c27b0 11%); background-image: radial-gradient(circle, #862197 10%, #9c27b0 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn-warning { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-warning:hover, .btn-warning:active:hover, .btn-warning:focus { background-color: #e08600; } .btn-warning:active { background-color: #e08600; background-image: -webkit-radial-gradient(circle, #e08600 10%, #ff9800 11%); background-image: -o-radial-gradient(circle, #e08600 10%, #ff9800 11%); background-image: radial-gradient(circle, #e08600 10%, #ff9800 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn-danger { -webkit-background-size: 200% 200%; background-size: 200%; background-position: 50%; } .btn-danger:hover, .btn-danger:active:hover, .btn-danger:focus { background-color: #cb171e; } .btn-danger:active { background-color: #cb171e; background-image: -webkit-radial-gradient(circle, #cb171e 10%, #e51c23 11%); background-image: -o-radial-gradient(circle, #cb171e 10%, #e51c23 11%); background-image: radial-gradient(circle, #cb171e 10%, #e51c23 11%); background-repeat: no-repeat; -webkit-background-size: 1000% 1000%; background-size: 1000%; -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3); } .btn { text-transform: uppercase; border-right: none; border-bottom: none; -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3); box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3); -webkit-transition: all 0.2s; -o-transition: all 0.2s; transition: all 0.2s; } .btn-link { -webkit-box-shadow: none; box-shadow: none; } .btn-link:hover, .btn-link:focus { color: #2196f3; text-decoration: none; } .btn-default.disabled { border: 1px solid #eeeeee; } .btn-group .btn + .btn, .btn-group .btn + .btn-group, .btn-group .btn-group + .btn, .btn-group .btn-group + .btn-group { margin-left: 0; } .btn-group-vertical > .btn + .btn, .btn-group-vertical > .btn + .btn-group, .btn-group-vertical > .btn-group + .btn, .btn-group-vertical > .btn-group + .btn-group { margin-top: 0; } body { -webkit-font-smoothing: antialiased; letter-spacing: .1px; } p { margin: 0 0 1em; } input, button { -webkit-font-smoothing: antialiased; letter-spacing: .1px; } a { -webkit-transition: all 0.2s; -o-transition: all 0.2s; transition: all 0.2s; } .table-hover > tbody > tr, .table-hover > tbody > tr > th, .table-hover > tbody > tr > td { -webkit-transition: all 0.2s; -o-transition: all 0.2s; transition: all 0.2s; } label { font-weight: normal; } textarea, textarea.form-control, input.form-control, input[type=text], input[type=password], input[type=email], input[type=number], [type=text].form-control, [type=password].form-control, [type=email].form-control, [type=tel].form-control, [contenteditable].form-control { padding: 0; border: none; border-radius: 0; -webkit-appearance: none; -webkit-box-shadow: inset 0 -1px 0 #dddddd; box-shadow: inset 0 -1px 0 #dddddd; font-size: 16px; } textarea:focus, textarea.form-control:focus, input.form-control:focus, input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, input[type=number]:focus, [type=text].form-control:focus, [type=password].form-control:focus, [type=email].form-control:focus, [type=tel].form-control:focus, [contenteditable].form-control:focus { -webkit-box-shadow: inset 0 -2px 0 #2196f3; box-shadow: inset 0 -2px 0 #2196f3; } textarea[disabled], textarea.form-control[disabled], input.form-control[disabled], input[type=text][disabled], input[type=password][disabled], input[type=email][disabled], input[type=number][disabled], [type=text].form-control[disabled], [type=password].form-control[disabled], [type=email].form-control[disabled], [type=tel].form-control[disabled], [contenteditable].form-control[disabled], textarea[readonly], textarea.form-control[readonly], input.form-control[readonly], input[type=text][readonly], input[type=password][readonly], input[type=email][readonly], input[type=number][readonly], [type=text].form-control[readonly], [type=password].form-control[readonly], [type=email].form-control[readonly], [type=tel].form-control[readonly], [contenteditable].form-control[readonly] { -webkit-box-shadow: none; box-shadow: none; border-bottom: 1px dotted #ddd; } textarea.input-sm, textarea.form-control.input-sm, input.form-control.input-sm, input[type=text].input-sm, input[type=password].input-sm, input[type=email].input-sm, input[type=number].input-sm, [type=text].form-control.input-sm, [type=password].form-control.input-sm, [type=email].form-control.input-sm, [type=tel].form-control.input-sm, [contenteditable].form-control.input-sm { font-size: 12px; } textarea.input-lg, textarea.form-control.input-lg, input.form-control.input-lg, input[type=text].input-lg, input[type=password].input-lg, input[type=email].input-lg, input[type=number].input-lg, [type=text].form-control.input-lg, [type=password].form-control.input-lg, [type=email].form-control.input-lg, [type=tel].form-control.input-lg, [contenteditable].form-control.input-lg { font-size: 17px; } select, select.form-control { border: 0; border-radius: 0; -webkit-appearance: none; -moz-appearance: none; appearance: none; padding-left: 0; padding-right: 0\9; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAMAAACelLz8AAAAJ1BMVEVmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmaP/QSjAAAADHRSTlMAAgMJC0uWpKa6wMxMdjkoAAAANUlEQVR4AeXJyQEAERAAsNl7Hf3X6xt0QL6JpZWq30pdvdadme+0PMdzvHm8YThHcT1H7K0BtOMDniZhWOgAAAAASUVORK5CYII=); -webkit-background-size: 13px 13px; background-size: 13px; background-repeat: no-repeat; background-position: right center; -webkit-box-shadow: inset 0 -1px 0 #dddddd; box-shadow: inset 0 -1px 0 #dddddd; font-size: 16px; line-height: 1.5; } select::-ms-expand, select.form-control::-ms-expand { display: none; } select.input-sm, select.form-control.input-sm { font-size: 12px; } select.input-lg, select.form-control.input-lg { font-size: 17px; } select:focus, select.form-control:focus { -webkit-box-shadow: inset 0 -2px 0 #2196f3; box-shadow: inset 0 -2px 0 #2196f3; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAMAAACelLz8AAAAJ1BMVEUhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISF8S9ewAAAADHRSTlMAAgMJC0uWpKa6wMxMdjkoAAAANUlEQVR4AeXJyQEAERAAsNl7Hf3X6xt0QL6JpZWq30pdvdadme+0PMdzvHm8YThHcT1H7K0BtOMDniZhWOgAAAAASUVORK5CYII=); } select[multiple], select.form-control[multiple] { background: none; } .radio label, .radio-inline label, .checkbox label, .checkbox-inline label { padding-left: 25px; } .radio input[type="radio"], .radio-inline input[type="radio"], .checkbox input[type="radio"], .checkbox-inline input[type="radio"], .radio input[type="checkbox"], .radio-inline input[type="checkbox"], .checkbox input[type="checkbox"], .checkbox-inline input[type="checkbox"] { margin-left: -25px; } input[type="radio"], .radio input[type="radio"], .radio-inline input[type="radio"] { position: relative; margin-top: 5px; margin-right: 4px; vertical-align: -4px; border: none; background-color: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; } input[type="radio"]:focus, .radio input[type="radio"]:focus, .radio-inline input[type="radio"]:focus { outline: none; } input[type="radio"]:before, .radio input[type="radio"]:before, .radio-inline input[type="radio"]:before, input[type="radio"]:after, .radio input[type="radio"]:after, .radio-inline input[type="radio"]:after { content: ""; display: block; width: 18px; height: 18px; margin-top: -3px; border-radius: 50%; -webkit-transition: 240ms; -o-transition: 240ms; transition: 240ms; } input[type="radio"]:before, .radio input[type="radio"]:before, .radio-inline input[type="radio"]:before { position: absolute; left: 0; top: 0; background-color: #2196f3; -webkit-transform: scale(0); -ms-transform: scale(0); -o-transform: scale(0); transform: scale(0); } input[type="radio"]:after, .radio input[type="radio"]:after, .radio-inline input[type="radio"]:after { border: 2px solid #666666; } input[type="radio"]:checked:before, .radio input[type="radio"]:checked:before, .radio-inline input[type="radio"]:checked:before { -webkit-transform: scale(0.5); -ms-transform: scale(0.5); -o-transform: scale(0.5); transform: scale(0.5); } input[type="radio"]:disabled:checked:before, .radio input[type="radio"]:disabled:checked:before, .radio-inline input[type="radio"]:disabled:checked:before { background-color: #bbbbbb; } input[type="radio"]:checked:after, .radio input[type="radio"]:checked:after, .radio-inline input[type="radio"]:checked:after { border-color: #2196f3; } input[type="radio"]:disabled:after, .radio input[type="radio"]:disabled:after, .radio-inline input[type="radio"]:disabled:after, input[type="radio"]:disabled:checked:after, .radio input[type="radio"]:disabled:checked:after, .radio-inline input[type="radio"]:disabled:checked:after { border-color: #bbbbbb; } input[type="checkbox"], .checkbox input[type="checkbox"], .checkbox-inline input[type="checkbox"] { position: relative; vertical-align: -4px; border: none; -webkit-appearance: none; appearance: none; cursor: pointer; } input[type="checkbox"]:focus, .checkbox input[type="checkbox"]:focus, .checkbox-inline input[type="checkbox"]:focus { outline: none; } input[type="checkbox"]:after, .checkbox input[type="checkbox"]:after, .checkbox-inline input[type="checkbox"]:after { content: ""; display: block; width: 18px; height: 18px; margin-top: -2px; margin-right: 5px; border: 2px solid #666666; border-radius: 2px; -webkit-transition: 240ms; -o-transition: 240ms; transition: 240ms; } input[type="checkbox"]:checked:before, .checkbox input[type="checkbox"]:checked:before, .checkbox-inline input[type="checkbox"]:checked:before { content: ""; position: absolute; top: 0; left: 6px; display: table; width: 6px; height: 12px; border: 2px solid #fff; border-top-width: 0; border-left-width: 0; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } input[type="checkbox"]:checked:after, .checkbox input[type="checkbox"]:checked:after, .checkbox-inline input[type="checkbox"]:checked:after { background-color: #2196f3; border-color: #2196f3; } input[type="checkbox"]:disabled:after, .checkbox input[type="checkbox"]:disabled:after, .checkbox-inline input[type="checkbox"]:disabled:after { border-color: #bbbbbb; } input[type="checkbox"]:disabled:checked:after, .checkbox input[type="checkbox"]:disabled:checked:after, .checkbox-inline input[type="checkbox"]:disabled:checked:after { background-color: #bbbbbb; border-color: transparent; } .has-warning input:not([type=checkbox]), .has-warning .form-control, .has-warning input:not([type=checkbox]):focus, .has-warning .form-control:focus { -webkit-box-shadow: inset 0 -2px 0 #ff9800; box-shadow: inset 0 -2px 0 #ff9800; } .has-error input:not([type=checkbox]), .has-error .form-control, .has-error input:not([type=checkbox]):focus, .has-error .form-control:focus { -webkit-box-shadow: inset 0 -2px 0 #e51c23; box-shadow: inset 0 -2px 0 #e51c23; } .has-success input:not([type=checkbox]), .has-success .form-control, .has-success input:not([type=checkbox]):focus, .has-success .form-control:focus { -webkit-box-shadow: inset 0 -2px 0 #4caf50; box-shadow: inset 0 -2px 0 #4caf50; } .has-warning .input-group-addon, .has-error .input-group-addon, .has-success .input-group-addon { color: #666666; border-color: transparent; background-color: transparent; } .nav-tabs > li > a, .nav-tabs > li > a:focus { margin-right: 0; background-color: transparent; border: none; color: #666666; -webkit-box-shadow: inset 0 -1px 0 #dddddd; box-shadow: inset 0 -1px 0 #dddddd; -webkit-transition: all 0.2s; -o-transition: all 0.2s; transition: all 0.2s; } .nav-tabs > li > a:hover, .nav-tabs > li > a:focus:hover { background-color: transparent; -webkit-box-shadow: inset 0 -2px 0 #2196f3; box-shadow: inset 0 -2px 0 #2196f3; color: #2196f3; } .nav-tabs > li.active > a, .nav-tabs > li.active > a:focus { border: none; -webkit-box-shadow: inset 0 -2px 0 #2196f3; box-shadow: inset 0 -2px 0 #2196f3; color: #2196f3; } .nav-tabs > li.active > a:hover, .nav-tabs > li.active > a:focus:hover { border: none; color: #2196f3; } .nav-tabs > li.disabled > a { -webkit-box-shadow: inset 0 -1px 0 #dddddd; box-shadow: inset 0 -1px 0 #dddddd; } .nav-tabs.nav-justified > li > a, .nav-tabs.nav-justified > li > a:hover, .nav-tabs.nav-justified > li > a:focus, .nav-tabs.nav-justified > .active > a, .nav-tabs.nav-justified > .active > a:hover, .nav-tabs.nav-justified > .active > a:focus { border: none; } .nav-tabs .dropdown-menu { margin-top: 0; } .dropdown-menu { margin-top: 0; border: none; -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); } .alert { border: none; color: #fff; } .alert-success { background-color: #4caf50; } .alert-info { background-color: #9c27b0; } .alert-warning { background-color: #ff9800; } .alert-danger { background-color: #e51c23; } .alert a:not(.close), .alert .alert-link { color: #fff; font-weight: bold; } .alert .close { color: #fff; } .badge { padding: 3px 6px 5px; } .progress { position: relative; z-index: 1; height: 6px; border-radius: 0; -webkit-box-shadow: none; box-shadow: none; } .progress-bar { -webkit-box-shadow: none; box-shadow: none; } .progress-bar:last-child { border-radius: 0 3px 3px 0; } .progress-bar:last-child:before { display: block; content: ""; position: absolute; width: 100%; height: 100%; left: 0; right: 0; z-index: -1; background-color: #cae6fc; } .progress-bar-success:last-child.progress-bar:before { background-color: #c7e7c8; } .progress-bar-info:last-child.progress-bar:before { background-color: #edc9f3; } .progress-bar-warning:last-child.progress-bar:before { background-color: #ffe0b3; } .progress-bar-danger:last-child.progress-bar:before { background-color: #f28e92; } .close { font-size: 34px; font-weight: 300; line-height: 24px; opacity: 0.6; -webkit-transition: all 0.2s; -o-transition: all 0.2s; transition: all 0.2s; } .close:hover { opacity: 1; } .list-group-item { padding: 15px; } .list-group-item-text { color: #bbbbbb; } .well { border-radius: 0; -webkit-box-shadow: none; box-shadow: none; } .panel { border: none; border-radius: 2px; -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); } .panel-heading { border-bottom: none; } .panel-footer { border-top: none; } .popover { border: none; -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); } .carousel-caption h1, .carousel-caption h2, .carousel-caption h3, .carousel-caption h4, .carousel-caption h5, .carousel-caption h6 { color: inherit; } libinput-1.28.1/doc/api/style/customdoxygen.css000066400000000000000000000104561477265155700215620ustar00rootroot00000000000000h1, .h1, h2, .h2, h3, .h3{ font-weight: 200 !important; } #navrow1, #navrow2, #navrow3, #navrow4, #navrow5{ border-bottom: 1px solid #EEEEEE; } .adjust-right { margin-left: 30px !important; font-size: 1.15em !important; } .navbar{ border: 0px solid #222 !important; } /* Sticky footer styles -------------------------------------------------- */ html, body { height: 100%; /* The html and body elements cannot have any padding or margin. */ } /* Wrapper for page content to push down footer */ #wrap { min-height: 100%; height: auto; /* Negative indent footer by its height */ margin: 0 auto -60px; /* Pad bottom by footer height */ padding: 0 0 60px; } /* Set the fixed height of the footer here */ #footer { font-size: 0.9em; padding: 8px 0px; background-color: #f5f5f5; } .footer-row { line-height: 44px; } #footer > .container { padding-left: 15px; padding-right: 15px; } .footer-follow-icon { margin-left: 3px; text-decoration: none !important; } .footer-follow-icon img { width: 20px; } .footer-link { padding-top: 5px; display: inline-block; color: #999999; text-decoration: none; } .footer-copyright { text-align: center; } @media (min-width: 992px) { .footer-row { text-align: left; } .footer-icons { text-align: right; } } @media (max-width: 991px) { .footer-row { text-align: center; } .footer-icons { text-align: center; } } /* DOXYGEN Code Styles ----------------------------------- */ a.qindex { font-weight: bold; } a.qindexHL { font-weight: bold; background-color: #9CAFD4; color: #ffffff; border: 1px double #869DCA; } .contents a.qindexHL:visited { color: #ffffff; } a.code, a.code:visited, a.line, a.line:visited { color: #4665A2; } a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { color: #4665A2; } /* @end */ dl.el { margin-left: -1cm; } pre.fragment { border: 1px solid #C4CFE5; background-color: #FBFCFD; padding: 4px 6px; margin: 4px 8px 4px 2px; overflow: auto; word-wrap: break-word; font-size: 9pt; line-height: 125%; font-family: monospace, fixed; font-size: 105%; } div.fragment { padding: 4px 6px; margin: 4px 8px 4px 2px; border: 1px solid #C4CFE5; } div.line { font-family: monospace, fixed; font-size: 13px; min-height: 13px; line-height: 1.0; text-wrap: unrestricted; white-space: -moz-pre-wrap; /* Moz */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* IE 5.5+ */ text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; -webkit-transition-property: background-color, box-shadow; -webkit-transition-duration: 0.5s; -moz-transition-property: background-color, box-shadow; -moz-transition-duration: 0.5s; -ms-transition-property: background-color, box-shadow; -ms-transition-duration: 0.5s; -o-transition-property: background-color, box-shadow; -o-transition-duration: 0.5s; transition-property: background-color, box-shadow; transition-duration: 0.5s; } div.line.glow { background-color: cyan; box-shadow: 0 0 10px cyan; } span.lineno { padding-right: 4px; text-align: right; border-right: 2px solid #0F0; background-color: #E8E8E8; white-space: pre; } span.lineno a { background-color: #D8D8D8; } span.lineno a:hover { background-color: #C8C8C8; } div.groupHeader { margin-left: 16px; margin-top: 12px; font-weight: bold; } div.groupText { margin-left: 16px; font-style: italic; } /* @group Code Colorization */ span.keyword { color: #008000 } span.keywordtype { color: #604020 } span.keywordflow { color: #e08000 } span.comment { color: #800000 } span.preprocessor { color: #806020 } span.stringliteral { color: #002080 } span.charliteral { color: #008080 } span.vhdldigit { color: #ff00ff } span.vhdlchar { color: #000000 } span.vhdlkeyword { color: #700070 } span.vhdllogic { color: #ff0000 } blockquote { background-color: #F7F8FB; border-left: 2px solid #9CAFD4; margin: 0 24px 0 4px; padding: 0 12px 0 16px; } libinput-1.28.1/doc/api/style/footer.html000066400000000000000000000013561477265155700203230ustar00rootroot00000000000000 libinput-1.28.1/doc/api/style/header.html000066400000000000000000000036731477265155700202610ustar00rootroot00000000000000 $projectname: $title $title $treeview $search $mathjax $extrastylesheet
libinput-1.28.1/doc/api/style/libinputdoxygen.css000066400000000000000000000032121477265155700220660ustar00rootroot00000000000000@import url("https://fonts.googleapis.com/css?family=Roboto+Mono"); dd { margin-left: 30px; } .title { font-size: 200%; font-weight: bold; } .title .ingroups { font-size: 50%; } h1 { font-size: 150%; color: #354C7B; background: none; border-bottom: 1px solid #879ECB; font-size: 150%; font-weight: normal; padding-top: 8px; padding-bottom: 8px; padding-left: 0px; width: 100%; } h2 { font-size: 120%; color: #354C7B; background: none; border-bottom: 1px solid #879ECB; font-size: 150%; font-weight: normal; padding-top: 8px; padding-bottom: 8px; padding-left: 0px; width: 100%; } .sm-dox li { float:left; border-top: 0; padding-right: 20px; } .sm li, .sm a { position: relative; } .sm, .sm ul, .sm li { list-style: none; display: block; line-height: normal; direction: ltr; text-align: left; } .sm, .sm *, .sm *::before, .sm *::after { box-sizing: border-box; } #main-nav { padding: 30px; } /* Main menu sub-items like file-list, etc */ #main-menu li ul { display: none; } .paramname { padding-right: 10px; } .memtitle { background-image: none; background-color: #F0F0F0; } .memproto { background-color: #F0F0F0; } .headertitle { background-image: none; background-color: #F0F0F0; } div.header { border: none; } td.fieldname { font-family: 'Roboto Mono', monospace; } .fieldtable th { background-image: none; background-color: #F0F0F0; } body { letter-spacing: 0px; } .mdescLeft, .mdescRight, .memItemLeft, .memItemRight, .memTemplItemLeft, .memTemplItemRight, .memTemplParams { background-color: #F0F0F0; } a { color: #2873b0; } .navpath ul { background-image: none; background-color: #F0F0F0; } libinput-1.28.1/doc/button-debouncing-state-machine.svg000066400000000000000000003022271477265155700231160ustar00rootroot00000000000000

Entry states: IS_UP, IS_DOWN

Assumption: state is stored per-button, and OTHER BUTTON events are always processed before the actual button. Stored state per button is a single bit (up/down), a single state for the state machine across the device is sufficient.

Start the state machine with IS_UP or IS_DOWN based on the button's bit, any OTHER BUTTON event will reset it to that state anyway, so the state can be re-used for the new button.

Entry states: IS_UP, IS_DOWN...

Entry state: DISABLED

Only set on devices that have button debouncing disabled. This state is effectively a noop, it just forwards the events as they come in and returns back to the same state.
Entry state: DISABLED...
button
press
button...
button
release
button...
DISABLED
DISABLED
button
press
button...
notify
button
press
notify...
button
release
button...
notify
button
release
notify...
other
button
other...
IS_UP
IS_UP
button
press
button...
IS_DOWN_WAITING
IS_DOWN_WAITING
IS_UP_DELAYING
IS_UP_DELAYING
notify
button
release
notify...
notify
button
press
notify...
IS_UP
IS_UP
notify
button
release
notify...
IS_DOWN_DETECTING_SPURIOUS
IS_DOWN_DETECTING_SPURIOUS
spurious
enabled?
spurious...
no
no
yes
yes
set
timer
set...
notify
button
press
notify...
other
button
other...
enable
spurious
enable...
IS_DOWN
IS_DOWN
IS_DOWN
IS_DOWN
button
release
button...
set
timer
set...
set short
timer
set short...
other
button
other...
IS_UP_DELAYING_SPURIOUS
IS_UP_DELAYING_SPURIOUS
IS_UP_DETECTING_SPURIOUS
IS_UP_DETECTING_SPURIOUS
button
press
button...
timeout
short
timeout...
other
button
other...
timeout
timeout
button
release
button...
timeout
short
timeout...
other
button
other...
timeout
timeout
timeout
timeout
other
button
other...
timeout
timeout
other
button
other...
IS_DOWN_DELAYING
IS_DOWN_DELAYING
notify
button
press
notify...
timeout
timeout
button
press
button...
other
button
other...
notify
button
release
notify...
notify
button
release
notify...
timeout
short
timeout...
button
press
button...
other
button
other...
IS_UP_WAITING
IS_UP_WAITING
button
release
button...
timeout
timeout
other
button
other...
set
timer
set...
set
timer
set...
set
timer
set...
set
timer
set...
set
timer
set...
set short
timer
set short...
set
timer
set...
set short
timer
set short...
Viewer does not support full SVG 1.1
libinput-1.28.1/doc/button-debouncing-wave-diagram.txt000066400000000000000000000040501477265155700227510ustar00rootroot00000000000000# Source for the button debouncing wave diagram # Paste into http://wavedrom.com/editor.html {signal: [ {name:'current mode', wave: '3............', data: ['normal button press and release']}, {name:'physical button', wave: '01......0....'}, {name:'application ', wave: '01......0....'}, {}, ['bounce mode', {name:'current mode', wave: '4............', data: ['debounced button press']}, {name:'physical button', wave: '0101...0.....'}, {name: 'timeouts', wave: '01...0.1...0.'}, {name:'application ', wave: '01.....0.....'}, {}, {name:'current mode', wave: '4............', data: ['debounced button release']}, {name:'physical button', wave: '1...010......'}, {name: 'timeouts', wave: '0...1...0....'}, {name:'application ', wave: '1...0........'}, {}, {name:'current mode', wave: '5............', data: ['delayed button press']}, {name:'physical button', wave: '1...01.......'}, {name: 'timeouts', wave: '0...1...0....'}, {name:'application ', wave: '1...0...1....'}, {}, {name:'current mode', wave: '5............', data: ['delayed button release']}, {name:'physical button', wave: '0...10.......'}, {name: 'timeouts', wave: '0...1...0....'}, {name:'application ', wave: '0...1...0....'}, ], {}, ['spurious mode', {name:'current mode', wave: '3............', data: ['first spurious button release ']}, {name:'physical button', wave: '1.......01...'}, {name:'application ', wave: '1.......01...'}, {}, {name:'current mode', wave: '3............', data: ['later spurious button release ']}, {name:'physical button', wave: '1....01......'}, {name: 'timeouts', wave: '0....1..0....'}, {name:'application ', wave: '1............'}, {}, {name:'current mode', wave: '3............', data: ['delayed release in spurious mode ']}, {name:'physical button', wave: '1....0.......'}, {name: 'timeouts', wave: '0....1..0....'}, {name:'application ', wave: '1.......0....'} ], ], head:{ text:'Button Debouncing Scenarios', }, } libinput-1.28.1/doc/middle-button-emulation.svg000066400000000000000000003406621477265155700215170ustar00rootroot00000000000000
IDLE
[Not supported by viewer]
left button
press
[Not supported by viewer]
right button
press
[Not supported by viewer]
other button
press
[Not supported by viewer]
LEFT_DOWN
[Not supported by viewer]
RIGHT_DOWN
[Not supported by viewer]
PASSTHROUGH
[Not supported by viewer]
left button
release
[Not supported by viewer]
right button
press
[Not supported by viewer]
timeout
[Not supported by viewer]
BTN_LEFT
PRESS
[Not supported by viewer]
BTN_LEFT
RELEASE
[Not supported by viewer]
BTN_LEFT
PRESS
[Not supported by viewer]
MIDDLE
[Not supported by viewer]
BTN_MIDDLE
PRESS
[Not supported by viewer]
left button
release
[Not supported by viewer]
right button
release
[Not supported by viewer]
BTN_MIDDLE
RELEASE
[Not supported by viewer]
BTN_MIDDLE
RELEASE
[Not supported by viewer]
LUP_PENDING
[Not supported by viewer]
RUP_PENDING
[Not supported by viewer]
left button
release
[Not supported by viewer]
right button
release
[Not supported by viewer]
IDLE
[Not supported by viewer]
right button
press
[Not supported by viewer]
left button
press
[Not supported by viewer]
other button
press
[Not supported by viewer]
left button
press
[Not supported by viewer]
right button
release
[Not supported by viewer]
timeout
[Not supported by viewer]
other button
press
[Not supported by viewer]
BTN_RIGHT
PRESS
[Not supported by viewer]
BTN_RIGHT
PRESS
[Not supported by viewer]
BTN_RIGHT
RELEASE
[Not supported by viewer]
other button
press
[Not supported by viewer]
BTN_MIDDLE
RELEASE
[Not supported by viewer]
IGNORE_LR
[Not supported by viewer]
left button
release
[Not supported by viewer]
right button
release
[Not supported by viewer]
other button
event
[Not supported by viewer]
PASSTHROUGH
[Not supported by viewer]
IGNORE_R
[Not supported by viewer]
IGNORE_L
[Not supported by viewer]
left button
press
[Not supported by viewer]
BTN_LEFT
PRESS
[Not supported by viewer]
left button
release
[Not supported by viewer]
BTN_LEFT
RELEASE
[Not supported by viewer]
right button
release
[Not supported by viewer]
right button
release
[Not supported by viewer]
right button
press
[Not supported by viewer]
BTN_RIGHT
PRESS
[Not supported by viewer]
BTN_RIGHT
RELEASE
[Not supported by viewer]
left button
release
[Not supported by viewer]
other button
press
[Not supported by viewer]
other button
press
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
BTN_LEFT
PRESS
[Not supported by viewer]
BTN_RIGHT
PRESS
[Not supported by viewer]
any button
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
all buttons
up?
[Not supported by viewer]
no
[Not supported by viewer]
yes
[Not supported by viewer]
other button
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
other button
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
any button
event
[Not supported by viewer]
BTN*
event
[Not supported by viewer]
all buttons
up?
[Not supported by viewer]
no
[Not supported by viewer]
IDLE
[Not supported by viewer]
yes
[Not supported by viewer]
libinput-1.28.1/doc/touchpad-edge-scrolling-state-machine.svg000066400000000000000000000531221477265155700241700ustar00rootroot00000000000000 NONE on-entry: edge = none threshold = def EDGE_NEW on-entry: edge = get_edge() set_timer() AREA on-entry: edge = none set_pointer() release touch touch, edge &= get_edge() tp_edge_scroll_post_events() dirty? no yes current = buttons.state & 0x01 old = buttons.old_state & 0x01 button = 0 is_top = 0 notify_axis(last_axis, 0.0) last_axis = -1 edge == right yes axis = scroll_vertical delta = dy edge == none no edge == bottom yes no axis = scroll_horizontal delta = dx no get_delta() notify_axis(axis, delta) last_axis = axis emit(scroll_event_posted) delta < threshold yes no last_axis != -1 EDGE on-entry: threshold = 0.01 timeout || scroll_event_posted yes yes no yes no get_edge() edge no yes libinput-1.28.1/doc/touchpad-gestures-state-machine.svg000066400000000000000000004464631477265155700231510ustar00rootroot00000000000000
NONE
NONE
FINGER_DETECTED
FINGER_DETECTED
yes
yes
no
no
Gestures enabled?
Gestures enab...
UNKNOWN
UNKNOWN
  Start hold timer
  Start hold timer
Motion detected?
Motion detect...
yes
yes
no
no
Hold timeout
Hold timeout
HOLD_TIMEOUT
HOLD_TIMEOUT
HOLD
HOLD
HOLD_BEGIN
HOLD_BEGIN
yes
yes
no
no
Motion detected?
Motion detect...
HOLD_END
(CANCEL)
HOLD_END...
all
all
some (debounce)
some (debounce)
Finger up?
Finger up?
HOLD_END
HOLD_END
Number of fingers?
Number of fin...
2 fingers
2 fingers
3 or 4 fingers
3 or 4 fingers
1 finger
1 finger
(to NONE)
(to NONE)
5 or more
fingers
5 or more...
POINTER_MOTION
POINTER_MOTION
SCROLL
SCROLL
SWIPE
SWIPE
PINCH
PINCH
swipe
swipe
pinch
pinch
Gesture
type?
Gesture...
SWIPE
SWIPE
PINCH
PINCH
SWIPE_BEGIN
SWIPE_BEGIN
PINCH_BEGIN
PINCH_BEGIN
yes
yes
no
no
Motion
> hold threshold?
Motion...
no
no
yes
yes
1 finger?
1 finger?
Hold timeout
Hold timeout
yes
yes
no
no
Motion
< hold threshold?
Motion...
HOLD_AND_MOTION
HOLD_AND_MOTION
HOLD_BEGIN
HOLD_BEGIN
HOLD_TIMEOUT
HOLD_TIMEOUT
yes
yes
no
no
Gestures enabled?
Gestures enab...
SCROLL
SCROLL
POINTER_MOTION
POINTER_MOTION
yes
yes
no (to NONE)
no (to NONE)
Gestures enabled?
Gestures enab...
yes
yes
Finger up?
Finger up?
Finger count changed?
Finger count...
DEBOUNCE FINGER LOGIC
Start debounce timer
Start debounce timer
Debounce timeout
Debounce timeout
yes
yes
no
no
Number of fingers changed?
Number of fin...
CANCEL CURRENT GESTURE
CANCEL CURRENT GESTURE
Ignore this finger change and stay in the same state
Ignore this finger c...
(to NONE)
(to NONE)
all
all
some
some
no
no
Finger up?
Finger up?
(to NONE)
(to NONE)
SWIPE_END
SWIPE_END
some
some
all
all
no
no
Finger up?
Finger up?
(to NONE)
(to NONE)
PINCH_END
PINCH_END
yes (to NONE)
yes (to NONE)
no
no
Finger up?
Finger up?
SWIPE_UPDATE
SWIPE_UPDATE
PINCH_UPDATE
PINCH_UPDATE
POINTER_MOTION
POINTER_MOTION
no
no
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22(to%20NONE)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%222314.686274509804%22%20y%3D%221001.0588235294117%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22(to%20NONE)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%222314.686274509804%22%20y%3D%221001.0588235294117%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E(to NONE)
%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22(to%20NONE)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%222314.686274509804%22%20y%3D%221001.0588235294117%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22(to%20NONE)%22%20style%3D%22edgeLabel%3Bhtml%3D1%3Balign%3Dcenter%3BverticalAlign%3Dmiddle%3Bresizable%3D0%3Bpoints%3D%5B%5D%3B%22%20vertex%3D%221%22%20connectable%3D%220%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%222314.686274509804%22%20y%3D%221001.0588235294117%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3E(to NONE)
(to NONE)
(to NONE)
all
all
some (debounce)
some (debounce)
Finger up?
Finger up?
AXIS
AXIS
AXIS (0,0)
AXIS (0,0)
RESET
RESET
RESET
RESET
LEGEND
STATE
STATE
EVENT
EVENT
Conditional
Conditional
Time event
Time event
GESTURE
GESTURE
Condition
Condition
Hold
Hold
Hold and motion
Hold and motion
Pinch
Pinch
Swipe
Swipe
Pointer motion
Pointer motion
Scroll
Scroll
yes
yes
Was pinch?
Was pinch?

We may confuse a pinch for a scroll initially, allow to transform an ongoing scroll into a pinch

We may confuse a pinch for a s...
Text is not SVG - cannot display
libinput-1.28.1/doc/touchpad-softbutton-state-machine.svg000066400000000000000000001040051477265155700234760ustar00rootroot00000000000000 NONE on-entry: curr = none BOTTOM on-entry: curr = button AREA on-entry: curr =area set_pointer() finger in area or top finger up finger in bottom finger in area finger in bottom button != curr Check state of all touches tp_post_softbutton_buttons() !buttons.click_pend && current == old yes no current = buttons.state & 0x01 old = buttons.old_state & 0x01 button = 0 is_top = 0 All touches are in state none no yes buttons.click_pend = 1 (Some touches are in middle) || ((Some touches are in right) && (Some touches are in left)) yes button = BTN_MIDDLE current no yes Some touches are in right yes no button = BTN_RIGHT button = BTN_LEFT no buttons.active = button buttons.active_is_top = is_top state = BUTTON_PRESSED button = buttons.active is_top = buttons.active_is_top buttons.active = 0 buttons.active_is_top = 0 state = BUTTON_RELEASED buttons.click_pend = 0 button no yes tp_notify_softbutton( button, is_top, state) finger in top TOP_NEW on-entry: curr = button start enter timeout TOP phys button press enter timeout finger in top button != curr finger in area or bottom TOP_TO_IGNORE on-entry: start leave timeout finger in area or bottom finger in top button == curr IGNORE on-entry: curr =none leave timeout touches in top? yes is_top = 1 no libinput-1.28.1/doc/touchpad-tap-state-machine.svg000066400000000000000000005521461477265155700220700ustar00rootroot00000000000000
(this section exists for [n] = 1, [n] = 2, and [n] = 3)
(this section exists for [n] = 1, [n] = 2, and [n] = 3)
IDLETOUCHfirstfinger downfinger upbutton 1presstimeoutmove > thresholdsecondfinger downTOUCH_2secondfinger upbutton 2pressmove > thresholdtimeoutbutton 1releasebutton 2release[n]FGTAP_TAPPEDtimeoutfirstfinger down[n]FGTAP_DRAGGINGfirstfinger upbutton [n]releaseIDLEthirdfinger downTOUCH_3button 3pressbutton 3releasemove > thresholdIDLEtimeoutfirstfinger upIDLEfourthfinger down[n]FGTAP_DRAGGING_OR_DOUBLETAPtimeoutfirstfinger upbutton [n]releasesecondfinger downmove > thresholdHOLDfirstfinger upsecondfinger downTOUCH_2_HOLDsecondfinger upthirdfinger downTOUCH_3_HOLDfourthfinger downDEADany finger upfourthfinger upany finger upany finger upIDLEif fingercount == 0[n]FGTAP_DRAGGING_2secondfinger downthirdfinger downphysbuttonpressphysbuttonpressbutton [n]release[n]FGTAP_DRAGGING_WAITtimeoutfirstfinger downTOUCH_TOUCHTOUCH_IDLETOUCH_DEADTOUCH_DEADTOUCH_IDLETOUCH_TOUCHTOUCH_IDLETOUCH_IDLETOUCH_TOUCHthat fingerTOUCH_IDLETOUCH_DEADthat fingerTOUCH_IDLETOUCH_TOUCHTOUCH_IDLETOUCH_TOUCHTOUCH_DEADTOUCH_IDLETOUCH_TOUCHTOUCH_TOUCHTOUCH_IDLETOUCH_TOUCHthat fingerTOUCH_IDLETOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEADTOUCH_DEAD[n]FGTAP_DRAGGING_OR_TAPfirstfinger uptimeoutmove > thresholdTOUCH_IDLEdrag lockenabled?
no
no
yes
yes
thumbTOUCH_DEADTOUCH_2_RELEASEsecondfinger uptimeoutmove > thresholdfirstfinger downTOUCH_IDLEfirstfinger upsecondfinger downTOUCH_DEADTOUCH_DEADdragdisabled?
yes
yes
palmeither fingerpalmremaining fingerpalmany fingerpalmthat fingerTOUCH_DEADthat fingerTOUCH_DEADpalmany fingerpalmthat fingerTOUCH_DEADTOUCH_DEADpalmTOUCH_DEADany fingerpalmthat fingerTOUCH_DEADeither fingerpalmthat fingerTOUCH_DEADpalmTOUCH_DEADany fingerpalmthat fingerTOUCH_DEADTOUCH_DEADmove > thresholdmove > thresholdbutton 1press
[n] = 1
[n] = 1
[n] = 1
[n] = 1
no
no
button [n]releaseIDLEdragdisabled?
[n] = 2
[n] = 2
no
no
yes
yes
dragdisabled?
yes
yes
no
no
[n] = 3
[n] = 3
TOUCH_3_RELEASEtimeoutTOUCH_DEADTOUCH_DEADeither fingerpalmthat fingerTOUCH_DEADmove > thresholdthirdfinger downTOUCH_TOUCHTOUCH_3_RELEASE_2remainingfinger upthat fingerTOUCH_IDLEeither finger upthat fingerTOUCH_IDLEsecondfinger downremaining fingerpalmTOUCH_DEADtimeoutfirstfinger upbutton 3pressbutton 3releasebutton 3pressbutton 3releaseeither finger upthat fingerTOUCH_IDLEsecondfinger downbutton [n]releasebutton 3pressbutton 3releaseTOUCH_DEADbutton 3pressbutton 3releasebutton 3pressbutton 3release
Viewer does not support full SVG 1.1
libinput-1.28.1/doc/user/000077500000000000000000000000001477265155700151775ustar00rootroot00000000000000libinput-1.28.1/doc/user/404.rst000066400000000000000000000001771477265155700162450ustar00rootroot00000000000000:orphan: === 404 === This page has permanently moved, probably to `<@TARGET@>`_ This placeholder page will be removed soon. libinput-1.28.1/doc/user/absolute-axes.rst000066400000000000000000000131441477265155700205100ustar00rootroot00000000000000.. _absolute_axes: ============================================================================== Absolute axes ============================================================================== Devices with absolute axes are those that send positioning data for an axis in a device-specific coordinate range, defined by a minimum and a maximum value. Compare this to relative devices (e.g. a mouse) that can only detect directional data, not positional data. libinput supports three types of devices with absolute axes: - multi-touch screens - single-touch screens - :ref:`graphics tablets ` Touchpads are technically absolute devices but libinput converts the axis values to directional motion and posts events as relative events. Touchpads do not count as absolute devices in libinput. For all absolute devices in libinput, the default unit for x/y coordinates is in mm off the top left corner on the device, or more specifically off the device's sensor. If the device is physically rotated from its natural position and this rotation was communicated to libinput (e.g. by setting the device left-handed), the coordinate origin is the top left corner in the current rotation. .. _absolute_axes_handling: ------------------------------------------------------------------------------ Handling of absolute coordinates ------------------------------------------------------------------------------ In most use-cases, absolute input devices are mapped to a single screen. For direct input devices such as touchscreens the aspect ratio of the screen and the device match. Mapping the input device position to the output position is thus a simple mapping between two coordinates. libinput provides the API for this with - **libinput_event_pointer_get_absolute_x_transformed()** for pointer events - **libinput_event_touch_get_x_transformed()** for touch events libinput's API only provides the call to map into a single coordinate range. If the coordinate range has an offset, the compositor is responsible for applying that offset after the mapping. For example, if the device is mapped to the right of two outputs, add the output offset to the transformed coordinate. .. _absolute_axes_nores: ------------------------------------------------------------------------------ Devices without x/y resolution ------------------------------------------------------------------------------ An absolute device that does not provide a valid resolution is considered buggy and must be fixed in the kernel. Some touchpad devices do not provide resolution, those devices are correctly handled within libinput (touchpads are not absolute devices, as mentioned above). .. _calibration: ------------------------------------------------------------------------------ Calibration of absolute devices ------------------------------------------------------------------------------ Absolute devices may require calibration to map precisely into the output range required. This is done by setting a transformation matrix, see **libinput_device_config_calibration_set_matrix()** which is applied to each input coordinate. .. math:: \begin{pmatrix} cos\theta & -sin\theta & xoff \\ sin\theta & cos\theta & yoff \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix} :math:`\theta` is the rotation angle. The offsets :math:`xoff` and :math:`yoff` are specified in device dimensions, i.e. a value of 1 equals one device width or height. Note that rotation applies to the device's origin, rotation usually requires an offset to move the coordinates back into the original range. The most common matrices are: - 90 degree clockwise: .. math:: \begin{pmatrix} 0 & -1 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} - 180 degree clockwise: .. math:: \begin{pmatrix} -1 & 0 & 1 \\ 0 & -1 & 1 \\ 0 & 0 & 1 \end{pmatrix} - 270 degree clockwise: .. math:: \begin{pmatrix} 0 & 1 & 0 \\ -1 & 0 & 1 \\ 0 & 0 & 1 \end{pmatrix} - reflection along y axis: .. math:: \begin{pmatrix} -1 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} See Wikipedia's `Transformation Matrix article `_ for more information on the matrix maths. See **libinput_device_config_calibration_get_default_matrix()** for how these matrices must be supplied to libinput. Once applied, any x and y axis value has the calibration applied before it is made available to the caller. libinput does not provide access to the raw coordinates before the calibration is applied. .. _absolute_axes_nonorm: ------------------------------------------------------------------------------ Why x/y coordinates are not normalized ------------------------------------------------------------------------------ x/y are not given in :ref:`normalized coordinates ` ([0..1]) for one simple reason: the aspect ratio of virtually all current devices is something other than 1:1. A normalized axes thus is only useful to determine that the stylus is e.g. at 78% from the left, 34% from the top of the device. Without knowing the per-axis resolution, these numbers are meaningless. Worse, calculation based on previous coordinates is simply wrong: a movement from 0/0 to 50%/50% is not a 45-degree line. This could be alleviated by providing resolution and information about the aspect ratio to the caller. Which shifts processing and likely errors into the caller for little benefit. Providing the x/y axes in mm from the outset removes these errors. libinput-1.28.1/doc/user/absolute-coordinate-ranges.rst000066400000000000000000000137231477265155700231570ustar00rootroot00000000000000.. _absolute_coordinate_ranges: ============================================================================== Coordinate ranges for absolute axes ============================================================================== libinput requires that all touchpads provide a correct axis range and resolution. These are used to enable or disable certain features or adapt the interaction with the touchpad. For example, the software button area is narrower on small touchpads to avoid reducing the interactive surface too much. Likewise, palm detection works differently on small touchpads as palm interference is less likely to happen. Touchpads with incorrect axis ranges generate error messages in the form:
Axis 0x35 value 4000 is outside expected range [0, 3000]
This error message indicates that the ABS_MT_POSITION_X axis (i.e. the x axis) generated an event outside the expected range of 0-3000. In this case the value was 4000. This discrepancy between the coordinate range the kernels advertises vs. what the touchpad sends can be the source of a number of perceived bugs in libinput. .. _absolute_coordinate_ranges_fix: ------------------------------------------------------------------------------ Measuring and fixing touchpad ranges ------------------------------------------------------------------------------ To fix the touchpad you need to: #. measure the physical size of your touchpad in mm #. run the ``libinput measure touchpad-size`` tool #. verify the hwdb entry provided by this tool #. test locally #. send a patch to the `systemd project `_. Detailed explanations are below. .. note:: ``libinput measure touchpad-size`` was introduced in libinput 1.16. For earlier versions, use `libevdev `_'s ``touchpad-edge-detector`` tool. The ``libinput measure touchpad-size`` tool is an interactive tool. It must be called with the physical dimensions of the touchpad in mm. In the example below, we use 100mm wide and 55mm high. The tool will find the touchpad device automatically. :: $> sudo libinput measure touchpad-size 100x55 Using "Touchpad SynPS/2 Synaptics TouchPad": /dev/input/event4 Kernel specified touchpad size: 99.7x75.9mm User specified touchpad size: 100.0x55.0mm Kernel axis range: x [1024..5112], y [2024..4832] Detected axis range: x [ 0.. 0], y [ 0.. 0] Move one finger along all edges of the touchpad until the detected axis range stops changing. ... Move the finger around until the detected axis range matches the data sent by the device. ``Ctrl+C`` terminates the tool and prints a suggested hwdb entry. :: ... Kernel axis range: x [1024..5112], y [2024..4832] ^C Detected axis range: x [2072..4880], y [2159..4832] Resolutions calculated based on user-specified size: x 28, y 49 units/mm Suggested hwdb entry: Note: the dmi modalias match is a guess based on your machine's modalias: dmi:bvnLENOVO:bvrGJET72WW(2.22):bd02/21/2014:svnLENOVO:pn20ARS25701:pvrThinkPadT440s:rvnLENOVO:rn20ARS25701:rvrSDK0E50512STD:cvnLENOVO:ct10:cvrNotAvailable: Please verify that this is the most sensible match and adjust if necessary. -8<-------------------------- # Laptop model description (e.g. Lenovo X1 Carbon 5th) evdev:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*pvrThinkPadT440s* EVDEV_ABS_00=2072:4880:28 EVDEV_ABS_01=2159:4832:49 EVDEV_ABS_35=2072:4880:28 EVDEV_ABS_36=2159:4832:49 -8<-------------------------- Instructions on what to do with this snippet are in /usr/lib/udev/hwdb.d/60-evdev.hwdb If there are discrepancies between the coordinate range the kernels advertises and what what the touchpad sends, the hwdb entry should be added to the ``60-evdev.hwdb`` file provided by the `systemd project `_. An example commit can be found `here `_. The ``libinput measure touchpad-size`` tool attempts to provide the correct dmi match but it does require user verification. In most cases the dmi match can and should be trimmed to the system vendor (``svn``) and the product version (``pvr``) or product name (``pn``), with everything else replaced by a wildcard (``*``). In the above case, the match string is: :: evdev:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*pvrThinkPadT440s* As a general rule: for Lenovo devices use ``pvr`` and for all others use ``pn``. .. note:: hwdb match strings only allow for alphanumeric ascii characters. Use a wildcard (* or ?, whichever appropriate) for special characters. The actual axis overrides are in the form: :: # axis number=min:max:resolution EVDEV_ABS_00=2072:4880:28 or, if the range is correct but the resolution is wrong :: # axis number=::resolution EVDEV_ABS_00=::28 Note the leading single space. The axis numbers are in hex and can be found in ``linux/input-event-codes.h``. For touchpads ``ABS_X``, ``ABS_Y``, ``ABS_MT_POSITION_X`` and ``ABS_MT_POSITION_Y`` are required. .. note:: The touchpad's ranges and/or resolution should only be fixed when there is a significant discrepancy. A few units do not make a difference and a resolution that is off by 2 or less usually does not matter either. Once a match and override rule has been found, follow the instructions at the top of the `60-evdev.hwdb `_ file to save it locally and trigger the udev hwdb reload. Rebooting is always a good idea. If the match string is correct, the new properties will show up in the output of :: udevadm info /sys/class/input/event4 Adjust the command for the event node of your touchpad. A udev builtin will apply the new axis ranges automatically. When the axis override is confirmed to work, please submit it as a pull request to the `systemd project `_. libinput-1.28.1/doc/user/architecture.rst000066400000000000000000000220551477265155700204170ustar00rootroot00000000000000.. _architecture: ============================================================================== libinput's internal architecture ============================================================================== This page provides an outline of libinput's internal architecture. The goal here is to get the high-level picture across and point out the components and their interplay to new developers. The public facing API is in ``libinput.c``, this file is thus the entry point for almost all API calls. General device handling is in ``evdev.c`` with the device-type-specific implementations in ``evdev-.c``. It is not necessary to understand all of libinput to contribute a patch. :ref:`architecture-contexts` is the only user-visible implementation detail, everything else is purely internal implementation and may change when required. .. _architecture-contexts: ------------------------------------------------------------------------------ The udev and path contexts ------------------------------------------------------------------------------ The first building block is the "context" which can be one of two types, "path" and "udev". See **libinput_path_create_context()** and **libinput_udev_create_context()**. The path/udev specific bits are in ``path-seat.c`` and ``udev-seat.c``. This includes the functions that add new devices to a context. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] libudev [label="libudev 'add' event"] udev [label="**libinput_udev_create_context()**"]; udev_backend [label="udev-specific backend"]; context [label="libinput context"] udev -> udev_backend; libudev -> udev_backend; udev_backend -> context; } The udev context provides automatic device hotplugging as udev's "add" events are handled directly by libinput. The path context requires that the caller adds devices. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] path [label="**libinput_path_create_context()**"]; path_backend [label="path-specific backend"]; xdriver [label="**libinput_path_add_device()**"] context [label="libinput context"] path -> path_backend; xdriver -> path_backend; path_backend -> context; } As a general rule: all Wayland compositors use a udev context, the X.org stack uses a path context. Which context was initialized only matters for creating/destroying a context and adding devices. The device handling itself is the same for both types of context. .. _architecture-device: ------------------------------------------------------------------------------ Device initialization ------------------------------------------------------------------------------ libinput only supports evdev devices, all the device initialization is done in ``evdev.c``. Much of the libinput public API is also a thin wrapper around the matching implementation in the evdev device. There is a 1:1 mapping between libinput devices and ``/dev/input/eventX`` device nodes. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] devnode [label="/dev/input/event0"] libudev [label="libudev 'add' event"] xdriver [label="**libinput_path_add_device()**"] context [label="libinput context"] evdev [label="evdev_device_create()"] devnode -> xdriver; devnode -> libudev; xdriver -> context; libudev -> context; context->evdev; } Entry point for all devices is ``evdev_device_create()``, this function decides to create a ``struct evdev_device`` for the given device node. Based on the udev tags (e.g. ``ID_INPUT_TOUCHPAD``), a :ref:`architecture-dispatch` is initialized. All event handling is then in this dispatch. Rejection of devices and the application of quirks is generally handled in ``evdev.c`` as well. Common functionality shared across multiple device types (like button-scrolling) is also handled here. .. _architecture-dispatch: ------------------------------------------------------------------------------ Device-type specific event dispatch ------------------------------------------------------------------------------ Depending on the device type, ``evdev_configure_device`` creates the matching ``struct evdev_dispatch``. This dispatch interface contains the function pointers to handle events. Four such dispatch methods are currently implemented: touchpad, tablet, tablet pad, and the fallback dispatch which handles mice, keyboards and touchscreens. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] evdev [label="evdev_device_create()"] fallback [label="evdev-fallback.c"] touchpad [label="evdev-mt-touchpad.c"] tablet [label="evdev-tablet.c"] pad [label="evdev-tablet-pad.c"] evdev -> fallback; evdev -> touchpad; evdev -> tablet; evdev -> pad; } While ``evdev.c`` pulls the event out of libevdev, the actual handling of the events is performed within the dispatch method. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] evdev [label="evdev_device_dispatch()"] fallback [label="fallback_interface_process()"]; touchpad [label="tp_interface_process()"] tablet [label="tablet_process()"] pad [label="pad_process()"] evdev -> fallback; evdev -> touchpad; evdev -> tablet; evdev -> pad; } The dispatch methods then look at the ``struct input_event`` and proceed to update the state. Note: the serialized nature of the kernel evdev protocol requires that the device updates the state with each event but to delay processing until the ``SYN_REPORT`` event is received. .. _architecture-configuration: ------------------------------------------------------------------------------ Device configuration ------------------------------------------------------------------------------ All device-specific configuration is handled through ``struct libinput_device_config_FOO`` instances. These are set up during device init and provide the function pointers for the ``get``, ``set``, ``get_default`` triplet of configuration queries (or more, where applicable). For example, the ``struct tablet_dispatch`` for tablet devices has a ``struct libinput_device_config_accel``. This struct is set up with the required function pointers to change the profiles. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] tablet [label="struct tablet_dispatch"] config [label="struct libinput_device_config_accel"]; tablet_config [label="tablet_accel_config_set_profile()"]; tablet->config; config->tablet_config; } When the matching ``**libinput_device_config_set_FOO()**`` is called, this goes through to the config struct and invokes the function there. Thus, it is possible to have different configuration functions for a mouse vs a touchpad, even though the interface is the same. .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] libinput [label="**libinput_device_config_accel_set_profile()**"]; tablet_config [label="tablet_accel_config_set_profile()"]; libinput->tablet_config; } .. _architecture-filter: ------------------------------------------------------------------------------ Pointer acceleration filters ------------------------------------------------------------------------------ All pointer acceleration is handled in the ``filter.c`` file and its associated files. The ``struct motion_filter`` is initialized during device init, whenever deltas are available they are passed to ``filter_dispatch()``. This function returns a set of :ref:`normalized coordinates `. All actual acceleration is handled within the filter, the device itself has no further knowledge. Thus it is possible to have different acceleration filters for the same device types (e.g. the Lenovo X230 touchpad has a custom filter). .. graphviz:: digraph context { compound=true; rankdir="LR"; node [ shape="box"; ] fallback [label="fallback deltas"]; touchpad [label="touchpad deltas"]; tablet [label="tablet deltas"]; filter [label="filter_dispatch"]; fallback->filter; touchpad->filter; tablet->filter; flat [label="accelerator_interface_flat()"]; x230 [label="accelerator_filter_x230()"]; pen [label="tablet_accelerator_filter_flat_pen()"]; filter->flat; filter->x230; filter->pen; } Most filters convert the deltas (incl. timestamps) to a motion speed and then apply a so-called profile function. This function returns a factor that is then applied to the current delta, converting it into an accelerated delta. See :ref:`pointer-acceleration` for more details. the current libinput-1.28.1/doc/user/building.rst000066400000000000000000000250251477265155700175320ustar00rootroot00000000000000.. _building_libinput: ============================================================================== libinput build instructions ============================================================================== .. contents:: :local: :backlinks: entry Instructions on how to build libinput and its tools and how to build against libinput. The build instruction on this page detail how to overwrite your system-provided libinput with one from the git repository, see see :ref:`reverting_install` to revert to the previous state. .. _distribution_repos: ------------------------------------------------------------------------------ Distribution repositories for libinput from git ------------------------------------------------------------------------------ Some distributions provide package repositories for users that want to test the latest libinput without building it manually. .. note:: The list below is provided for convenience. The libinput community cannot provide any guarantees that the packages in those repositories are correct, up-to-date and/or unmodified from the git branch. Due dilligence is recommended. The following repositories provide an up-to-date package for libinput: - **Arch:** https://aur.archlinux.org/packages/libinput-git/ - **Fedora:** https://copr.fedorainfracloud.org/coprs/whot/libinput-git/ Please follow the respective repositories for instructions on how to enable the repository and install libinput. .. _building: ------------------------------------------------------------------------------ Building libinput ------------------------------------------------------------------------------ libinput uses `meson `_ and `ninja `_. A build is usually the three-step process below. A successful build requires the :ref:`building_dependencies` to be installed before running meson. :: $> git clone https://gitlab.freedesktop.org/libinput/libinput $> cd libinput $> meson setup --prefix=/usr builddir/ $> ninja -C builddir/ $> sudo ninja -C builddir/ install When running libinput versions 1.11.x or earlier, you must run :: $> sudo systemd-hwdb update Additional options may also be specified. For example: :: $> meson setup --prefix=/usr -Ddocumentation=false builddir/ We recommend that users disable the documentation, it's not usually required for testing and reduces the number of dependencies needed. The ``prefix`` or other options can be changed later with the ``meson configure`` command. For example: :: $> meson configure builddir/ -Dprefix=/some/other/prefix -Ddocumentation=true $> ninja -C builddir $> sudo ninja -C builddir/ install Running ``meson configure builddir/`` with no other arguments lists all configurable options meson provides. To rebuild from scratch, simply remove the build directory and run meson again: :: $> rm -r builddir/ $> meson setup --prefix=.... .. _verifying_install: .............................................................................. Verifying the install .............................................................................. To verify the install worked correctly, check that libinput.so.x.x.x is in the library path and that all symlinks point to the new library. :: $> ldconfig -p | grep libinput | awk '{print $NF}' | xargs ls -l lrwxrwxrwx 1 root root 14 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so -> libinput.so.10 lrwxrwxrwx 1 root root 19 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so.10 -> libinput.so.10.13.0 -rwxr-xr-x 1 root root 1064144 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so.10.13.0 .. _reverting_install: .............................................................................. Reverting to the system-provided libinput package .............................................................................. The recommended way to revert to the system install is to use the package manager to reinstall the libinput package. In some cases, this may leave files in the system (e.g. ``/usr/lib/libinput.la``) but these files are usually harmless. To definitely remove all files, run the following command from the libinput source directory: :: $> sudo ninja -C builddir/ uninstall # WARNING: Do not restart the computer/X/the Wayland compositor after # uninstall, reinstall the system package immediately! The following commands reinstall the current system package for libinput, overwriting manually installed files. - **Debian/Ubuntu** based distributions: ``sudo apt-get install --reinstall libinput`` - **Fedora 22** and later: ``sudo dnf reinstall libinput`` - **RHEL/CentOS/Fedora 21** and earlier: ``sudo yum reinstall libinput`` - **openSUSE**: ``sudo zypper install --force libinput10`` - **Arch**: ``sudo pacman -S libinput`` .. _building_selinux: .............................................................................. SELinux adjustments .............................................................................. .. note:: This section only applies to meson version < 0.42.0 On systems with SELinux, overwriting the distribution-provided package with a manually built libinput may cause SELinux denials. This usually manifests when gdm does not start because it is denied access to libinput. The journal shows a log message in the form of: :: May 25 15:28:42 localhost.localdomain audit[23268]: AVC avc: denied { execute } for pid=23268 comm="gnome-shell" path="/usr/lib64/libinput.so.10.12.2" dev="dm-0" ino=1709093 scontext=system_u:system_r:xdm_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0 May 25 15:28:42 localhost.localdomain org.gnome.Shell.desktop[23270]: /usr/bin/gnome-shell: error while loading shared libraries: libinput.so.10: failed to map segment from shared object The summary of this error message is that gdm's gnome-shell runs in the ``system_u:system_r:xdm_t`` context but libinput is installed with the context ``unconfined_u:object_r:user_home_t``. To avoid this issue, restore the SELinux context for any system files. :: $> sudo restorecon /usr/lib*/libinput.so.* This issue is tracked in https://github.com/mesonbuild/meson/issues/1967. .. _building_dependencies: ------------------------------------------------------------------------------ Build dependencies ------------------------------------------------------------------------------ libinput has a few build-time dependencies that must be installed prior to running meson. .. hint:: The build dependencies for some distributions can be found in the `GitLab Continuous Integration file `_. Search for **FEDORA_PACKAGES** in the **variables:** definition and check the list for an entry for your distribution. In most cases, it is sufficient to install the dependencies that your distribution uses to build the libinput package. These can be installed with one of the following commands: - **Debian/Ubuntu** based distributions: ``sudo apt-get build-dep libinput`` - **Fedora 22** and later: ``sudo dnf builddep libinput`` - **RHEL/CentOS/Fedora 21** and earlier: ``sudo yum-builddep libinput`` - **openSUSE**: :: $> sudo zypper modifyrepo --enable ``zypper repos | grep source | awk '{print $5}'`` $> sudo zypper source-install -d libinput10 $> sudo zypper install autoconf automake libtool $> sudo zypper modifyrepo --disable ``zypper repos | grep source | awk '{print $5}'`` - **Arch**: :: $> sudo pacman -S asp $> cd $(mktemp -d) $> asp export libinput $> cd libinput $> makepkg --syncdeps --nobuild --noextract If dependencies are missing, meson shows a message ``No package 'foo' found``. See `this blog post here `_ for instructions on how to fix it. .............................................................................. Build dependencies per distribution .............................................................................. .. include:: dependencies.rst .. _building_conditional: ------------------------------------------------------------------------------ Conditional builds ------------------------------------------------------------------------------ libinput supports several meson options to disable parts of the build. See the ``meson_options.txt`` file in the source tree for a full list of available options. The default build enables most options and thus requires more build dependencies. On systems where build dependencies are an issue, options may be disabled with this meson command: :: meson setup --prefix=/usr -Dsomefeature=false builddir Where ``-Dsomefeature=false`` may be one of: - ``-Ddocumentation=false`` Disables the documentation build (this website). Building the documentation is only needed on the maintainer machine. - ``-Dtests=false`` Disables the test suite. The test suite is only needed on developer systems. - ``-Ddebug-gui=false`` Disables the ``libinput debug-gui`` helper tool (see :ref:`tools`), dropping GTK and other build dependencies. The debug-gui is only required for troubleshooting. - ``-Dlibwacom=false`` libwacom is required by libinput's tablet code to gather additional information about tablets that is not available from the kernel device. It is not recommended to disable libwacom unless libinput is used in an environment where tablet support is not required. libinput provides tablet support even without libwacom, but some features may be missing or working differently. .. _building_against: ------------------------------------------------------------------------------ Building against libinput ------------------------------------------------------------------------------ libinput provides a `pkg-config `_ file. Software that uses autotools should use the ``PKG_CHECK_MODULES`` autoconf macro: :: PKG_CHECK_MODULES(LIBINPUT, "libinput") Software that uses meson should use the ``dependency()`` function: :: pkgconfig = import('pkgconfig') dep_libinput = dependency('libinput') Software that uses CMake should use: :: find_package(Libinput) target_link_libraries(myprogram PRIVATE Libinput::Libinput) Otherwise, the most rudimentary way to compile and link a program against libinput is: :: gcc -o myprogram myprogram.c ``pkg-config --cflags --libs libinput`` For further information on using pkgconfig see the pkg-config documentation. libinput-1.28.1/doc/user/button-debouncing.rst000066400000000000000000000054041477265155700213620ustar00rootroot00000000000000 .. _button_debouncing: ============================================================================== Button debouncing ============================================================================== Physical buttons experience wear-and-tear with usage. On some devices this can result in an effect called "contact bouncing" or "chatter". This effect can cause the button to send multiple events within a short time frame, even though the user only pressed or clicked the button once. This effect can be counteracted by "debouncing" the buttons, usually by ignoring erroneous events. libinput provides two methods of debouncing buttons, referred to as the "bounce" and "spurious" methods: - In the "bounce" method, libinput monitors hardware bouncing on button state changes, i.e. when a user clicks or releases a button. For example, if a user presses a button but the hardware generates a press-release-press sequence in quick succession, libinput ignores the release and second press event. This method is always enabled. - in the "spurious" method, libinput detects spurious releases of a button while the button is physically held down by the user. These releases are immediately followed by a press event. libinput monitors for these events and ignores the release and press event. This method is disabled by default and enables once libinput detects the first faulty event sequence. The "bounce" method guarantees that all press events are delivered immediately and most release events are delivered immediately. The "spurious" method requires that release events are delayed, libinput thus does not enable this method unless a faulty event sequence is detected. A message is printed to the log when spurious deboucing was detected. libinput's debouncing is supposed to correct hardware damage or substandard hardware. Debouncing also exists as an accessibility feature but the requirements are different. In the accessibility feature, multiple physical key presses, usually caused by involuntary muscle movement, must be filtered to only one key press. This feature must be implemented higher in the stack, libinput is limited to hardware debouncing. Below is an illustration of the button debouncing modes to show the relation of the physical button state and the application state. Where applicable, an extra line is added to show the timeouts used by libinput that affect the button state handling. The waveform's high and low states correspond to the buttons 'pressed' and 'released' states, respectively. .. figure:: button-debouncing-wave-diagram.svg :align: center Diagram illustrating button debouncing Some devices send events in bursts, erroneously triggering the button debouncing detection. Please :ref:`file a bug ` if that occurs for your device. libinput-1.28.1/doc/user/clickpad-softbuttons.rst000066400000000000000000000140341477265155700220750ustar00rootroot00000000000000.. _clickpad_softbuttons: ============================================================================== Clickpad software button behavior ============================================================================== "Clickpads" are touchpads without separate physical buttons. Instead, the whole touchpad acts as a button and left or right button clicks are distinguished by :ref:`the location of the fingers ` or the :ref:`number of fingers on the touchpad `. "ClickPad" is a trademark by `Synaptics Inc. `_ but for simplicity we refer to any touchpad with the above feature as Clickpad, regardless of the manufacturer. The kernel marks clickpads with the `INPUT_PROP_BUTTONPAD `_ property. Without this property, libinput would not know whether a touchpad is a clickpad or not. To perform a right-click on a Clickpad, libinput provides :ref:`software_buttons` and :ref:`clickfinger`. .. note:: The term "click" refers refer to a physical button press and/or release of the touchpad, the term "button event" refers to the events generated by libinput in response to a click. .. _software_buttons: ------------------------------------------------------------------------------ Software button areas ------------------------------------------------------------------------------ The bottom of the touchpad is split into three distinct areas generate left, middle or right button events on click. The height of the button area depends on the hardware but is usually around 10mm. .. figure :: software-buttons-visualized.svg :align: center The locations of the virtual button areas. Left, right and middle button events can be triggered as follows: - if a finger is in the main area or the left button area, a click generates left button events. - if a finger is in the right area, a click generates right button events. - if a finger is in the middle area, a click generates middle button events. .. figure:: software-buttons.svg :align: center Left, right and middle-button click with software button areas The middle button is always centered on the touchpad and smaller in size than the left or right button. The actual size is device-dependent. Many touchpads do not have visible markings so the exact location of the button is unfortunately not visibly obvious. .. note:: If :ref:`middle button emulation ` is enabled on a clickpad, only left and right button areas are available. If fingers are down in the main area in addition to fingers in the left or right button area, those fingers are are ignored. A release event always releases the buttons logically down, regardless of the current finger position .. figure:: software-buttons-thumbpress.svg :align: center Only the location of the thumb determines whether it is a left, right or middle click. The movement of a finger can alter the button area behavior: - if a finger starts in the main area and moves into the software button area, the software buttons do not apply to that finger - once a finger has moved out of the button area, it cannot move back in and trigger a right or middle button event - a finger moving within the software button area does not move the pointer - once a finger moves out out of the button area it will control the pointer (this only applies if there is no other finger down on the touchpad) .. figure:: software-buttons-conditions.svg :align: center **Left:** moving a finger into the right button area does not trigger a right-button click. **Right:** moving within the button areas does not generate pointer motion. On some touchpads, notably the 2015 Lenovo X1 Carbon 3rd series, the very bottom end of the touchpad is outside of the sensor range but it is possible to trigger a physical click there. To libinput, the click merely shows up as a left button click without any positional finger data and it is impossible to determine whether it is a left or a right click. libinput ignores such button clicks, this behavior is intentional. .. _clickfinger: ------------------------------------------------------------------------------ Clickfinger behavior ------------------------------------------------------------------------------ This is the default behavior on Apple touchpads. Here, a left, right, middle button event is generated when one, two, or three fingers are held down on the touchpad when a physical click is generated, given the default mapping. The location of the fingers does not matter and there are no software-defined button areas. It is possible to swap right and middle buttons, the same way as with :ref:`tapping `. .. figure:: clickfinger.svg :align: center One, two and three-finger click with Clickfinger behavior On some touchpads, libinput imposes a limit on how the fingers may be placed on the touchpad. In the most common use-case this allows for a user to trigger a click with the thumb while leaving the pointer-moving finger on the touchpad. .. figure:: clickfinger-distance.svg :align: center Illustration of the distance detection algorithm In the illustration above the red area marks the proximity area around the first finger. Since the thumb is outside of that area libinput considers the click a single-finger click rather than a two-finger click. .. _special_clickpads: ------------------------------------------------------------------------------ Special Clickpads ------------------------------------------------------------------------------ The Lenovo \*40 series laptops have a clickpad that provides two software button sections, one at the top and one at the bottom. See :ref:`Lenovo \*40 series touchpad support ` for details on the top software button. Some Clickpads, notably some Cypress ones, perform right button detection in firmware and appear to userspace as if the touchpad had physical buttons. While physically clickpads, these are not handled by the software and treated like traditional touchpads. libinput-1.28.1/doc/user/clickpad-with-right-button.rst000066400000000000000000000046511477265155700231060ustar00rootroot00000000000000.. _clickpads_with_right_buttons: ============================================================================== Clickpads with a fake right button ============================================================================== libinput relies on the kernel to label :ref:`Clickpads ` with the ``INPUT_PROP_BUTTONPAD`` property so it can enable the correct :ref:`clickpad_softbuttons`. Clickpads are not expected to have a right button since the whole surface can be depressed. A common bug encountered with :ref:`Clickpads ` is that the device advertises a physical right button where no such button exists. This is usually a bug in the firmware of the device and causes the following warning to be emitted by libinput:: " clickpad advertising right button" The user-visible effect of this is usually negligible since these devices cannot actually trigger a right click and libinput's default behaviors for clickpads work as expected. However, we should nonetheless correct the device to get rid of this warning and avoid potential issues with future features. The :ref:`device-quirks` provide a simple way to disable the fake right button on the device. The following quirk disables the right button on the MyModel laptop from the MyVendor OEM:: [MyVendor MyModel Touchpad] MatchName=Foo Bar Touchpad MatchUdevtype=touchpad MatchDMIModAlias=dmi:*svnMyVendor:pnMyModel:* AttrEventCode=-BTN_RIGHT The name of the device can be obtained using :ref:`libinput record `, the modalias match is a shell-style glob against the value of ``/sys/class/dmi/id/modalias``. In most cases, matching should be against ``svn`` (system vendor) and one of ``pn`` (product name) or ``pvr`` (product version), whichever provides a useful description of the individual laptop model. See the :ref:`device-quirks` documentation for details on testing local quirks. For reference, some example commits that add such a quirk are: - `bf61ab9bb0694d0ac3d60a7f815779abfe4886e6 `__ - `74fac6d040ac62048882dfb6f73da567ace6a6f5 `__ - `89cd0f990e3bee9906754d6ca8484ed5aa392249 `__ libinput-1.28.1/doc/user/conf.py.in000066400000000000000000000134111477265155700171030ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/stable/config # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # sys.path.insert(0, os.path.abspath('.')) import sys import os sys.path.insert(0, os.path.abspath('@BUILDDIR@')) # -- Project information ----------------------------------------------------- project = '@PROJECT_NAME@' copyright = '2019, the libinput authors' author = 'the libinput authors' # The short X.Y version version = '@PROJECT_VERSION@' # The full version, including alpha/beta/rc tags release = '@PROJECT_VERSION@' # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.mathjax', 'sphinx.ext.graphviz', 'sphinx.ext.extlinks', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path . exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' highlight_language = 'none' # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # html_theme_options = { 'collapse_navigation': False, 'navigation_depth': 3, } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # html_static_path = ['_static'] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # The default sidebars (for documents that don't match any pattern) are # defined by theme itself. Builtin themes are using these templates by # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', # 'searchbox.html']``. # # html_sidebars = {} # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. htmlhelp_basename = '@PROJECT_NAME@doc' # -- Options for LaTeX output ------------------------------------------------ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, '@PROJECT_NAME@.tex', '@PROJECT_NAME@ Documentation', 'Peter Hutterer', 'manual'), ] # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation', [author], 1) ] # -- Options for Texinfo output ---------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation', author, '@PROJECT_NAME@', 'One line description of project.', 'Miscellaneous'), ] # -- Extension configuration ------------------------------------------------- from recommonmark.parser import CommonMarkParser extlinks = { 'commit' : ('https://gitlab.freedesktop.org/libinput/libinput/commit/%s', 'git commit %s') } # -- git version hack ------------------------------------------------- # # meson doesn't take configuration_data() for vcs_tag, so we cannot replace # two substrings in the same file. # # sphinx cannot do ..include:: without linebreaks, so in-line replacements # are a no-go. # # Work around this by generating a mini python module in meson through # vcs_tag, then use that to generate the replacements in rst_prolog. import git_version rst_prolog = """ .. |git_version| replace:: :commit:`{}` .. |git_version_full| replace:: :commit:`{}` """.format(git_version.get_git_version(), git_version.get_git_version_full) libinput-1.28.1/doc/user/configuration.rst000066400000000000000000000240141477265155700206010ustar00rootroot00000000000000.. _config_options: ============================================================================== Configuration options ============================================================================== Below is a list of configurable options exposed to the users. .. hint:: Not all configuration options are available on all devices. Use :ref:`libinput list-devices ` to show the configuration options for local devices. libinput's configuration interface is available to the caller only, not directly to the user. Thus is is the responsibility of the caller to expose the various options and how these options are exposed. For example, the xf86-input-libinput driver exposes the options through X Input device properties and xorg.conf.d options. See the `libinput(4) `_ man page for more details. ------------------------------------------------------------------------------ Tap-to-click ------------------------------------------------------------------------------ See :ref:`tapping` for details on how this feature works. Configuration options exposed by libinput are: - how many tapping fingers are supported by this device - a toggle to enable/disable tapping - a toggle to enable/disable tap-and-drag, see :ref:`tapndrag`. - a toggle to enable/disable tap-and-drag drag lock, see :ref:`tapndrag` - The default order is 1, 2, 3 finger tap mapping to left, right, middle click, respectively. This order can be changed to left, middle, right click, respectively. Tapping is usually available on touchpads and the touchpad part of external graphics tablets. Tapping is usually **not** available on touch screens, for those devices it is expected to be implemented by the toolkit. ------------------------------------------------------------------------------ Three-finger drag ------------------------------------------------------------------------------ Three-finger drag allows emulates the mouse button down while three fingers are down on a touchpad without the need to press a physical button or use :ref:`tapndrag`. See :ref:`drag_3fg` for details on how this feature works. Three-finger drag is usually available on touchpads and the touchpad part of external graphics tablets. Three-finger drag is usually **not** available on touch screens, for those devices it is expected to be implemented by the toolkit. ------------------------------------------------------------------------------ Send Events Mode ------------------------------------------------------------------------------ The Send Events Mode is libinput's terminology for disabling a device. It is more precise in that the device only stops sending events but may not get fully disabled. For example, disabling the touchpad on a :ref:`Lenovo T440 and similar ` leaves the top software buttons enabled for the trackpoint. Available options are **enabled** (send events normally), **disabled** ( do not send events), **disabled on external mouse** (disable the device while an external mouse is plugged in). .. _config_pointer_acceleration: ------------------------------------------------------------------------------ Pointer acceleration ------------------------------------------------------------------------------ Pointer acceleration is a function to convert input deltas to output deltas, usually based on the movement speed of the device, see :ref:`pointer-acceleration` for details. Pointer acceleration is normalized into a [-1, 1] range, where -1 is "slowest" and 1 is "fastest". Most devices use a default speed of 0. The pointer acceleration profile defines **how** the input deltas are converted, see :ref:`ptraccel-profiles`. Most devices have their default profile (usually called "adaptive") and a "flat" profile. The flat profile does not apply any acceleration. ------------------------------------------------------------------------------ Scrolling ------------------------------------------------------------------------------ "Natural scrolling" is the terminology for moving the content in the direction of scrolling, i.e. moving the wheel or fingers down moves the page down. Traditional scrolling moves the content in the opposite direction. Natural scrolling can be turned on or off, it is usually off by default. The scroll method defines how to trigger scroll events. On touchpads libinput provides two-finger scrolling and edge scrolling. Two-finger scrolling converts a movement with two fingers to a series of scroll events. Edge scrolling converts a movement with one finger along the right or bottom edge of the touchpad into a series of scroll events. On other libinput provides button-scrolling - movement of the device while the designated scroll button is down is converted to scroll events. The button used for scrolling is configurable. The scroll method can be chosen or disabled altogether but most devices only support a subset of available scroll methods. libinput's default is two-finger scrolling for multi-touch touchpads, edge scrolling for single-touch touchpads. On tracksticks, button scrolling is enabled by default. See :ref:`scrolling` for more details on how the scroll methods work. ------------------------------------------------------------------------------ Left-handed Mode ------------------------------------------------------------------------------ Left-handed mode switches the device's functionality to be more accommodating for left-handed users. On mice this usually means swapping the left and right mouse button, on tablets this allows the tablet to be used upside-down to present the pad buttons for the non-dominant right hand. Not all devices have left-handed mode. Left-handed mode can be enabled or disabled and is disabled by default. ------------------------------------------------------------------------------ Middle Button Emulation ------------------------------------------------------------------------------ Middle button emulation converts a simultaneous left and right button click into a middle button. The emulation can be enabled or disabled. Middle button emulation is usually enabled when the device does not provide a middle button. ------------------------------------------------------------------------------ Click method ------------------------------------------------------------------------------ The click method defines how button events are triggered on a :ref:`clickpad `. When set to button areas, the bottom area of the touchpad is divided into a left, middle and right button area. When set to clickfinger, the number of fingers on the touchpad decide the button type. Clicking with 1, 2, 3 fingers triggers a left, right, or middle click, respectively. The default click method is software button areas. Click methods are usually only available on :ref:`clickpads `. ------------------------------------------------------------------------------ Disable while typing ------------------------------------------------------------------------------ DWT is the most generic form of palm detection on touchpad. While the user is typing on an internal keyboard the touchpad is disabled, the touchpad is enabled again after a timeout. See :ref:`disable-while-typing` for more info. Disable-while-typing can be enabled or disabled, it is enabled by default on most touchpads. ------------------------------------------------------------------------------ Disable while trackpointing ------------------------------------------------------------------------------ DWTP is a form of palm detecion for devices that have a trackpoint (like Thinkpads). While the user is using the trackpoint, the touchpad is disabled, being enabled again after a timeout. See :ref:`disable-while-trackpointing` for more info. Disable-while-trackpointing can be enabled or disabled, it is enabled by default. ------------------------------------------------------------------------------ Calibration ------------------------------------------------------------------------------ Calibration is available for some direct-input devices (touch screens, graphics tablets, etc.). The purpose of calibration is to ensure the input lines up with the output and the configuration data is a transformation matrix. It is thus not expected that the user sets this option. The desktop environment should provide an interface for this. ------------------------------------------------------------------------------ Rotation ------------------------------------------------------------------------------ The device rotation applies a corrective angle to relative input events, allowing the device to be used e.g. sideways or upside-down. For example, a trackball may be used in a 90° rotated position for accessibility reasons - such a rotated position allows triggering the buttons with the thumb or the non-dominant hand. Note that where a device rotation is higher than 160 but less than 200 degrees, the direction of wheels is also inverted. For all other angles, the wheel direction is left as-is. .. _config-tablet-pressure-range: ------------------------------------------------------------------------------ Tablet tool pressure range ------------------------------------------------------------------------------ The pressure range on a :ref:`Tablet tool ` can be reduced from the full available hardware range to a subset of that range. The effect of this is that the tablet will not register pressure below the given the given threshold is met, and will reach the maximum logical pressure before the maximum hardware-supported pressure is reached. See :ref:`tablet-pressure-range` for more info. ------------------------------------------------------------------------------ Area configuration ------------------------------------------------------------------------------ Area configuration is available for some indirect input devices such as graphics tablets. This configuration allows reducing the active area of such a device to a subset of the physically possible area. An example use-case for this is to match the aspect ratio of the device to that of the screen. See :ref:`tablet-area` for more info. libinput-1.28.1/doc/user/contributing.rst000066400000000000000000000426761477265155700204570ustar00rootroot00000000000000 .. _contributing: ============================================================================== Contributing to libinput ============================================================================== So you want to contribute to libinput? Great! We'd love to help you be a part of our community. Here is some important information to help you. .. contents:: :local: ------------------------------------------------------------------------------ Code of Conduct ------------------------------------------------------------------------------ As a freedesktop.org project, libinput follows the `freedesktop.org Contributor Covenant `_. Please conduct yourself in a respectful and civilised manner when interacting with community members on mailing lists, IRC, or bug trackers. The community represents the project as a whole, and abusive or bullying behaviour is not tolerated by the project. ------------------------------------------------------------------------------ Contact ------------------------------------------------------------------------------ Questions can be asked on ``#wayland`` on oftc or on the `wayland-devel@lists.freedesktop.org `_ mailing list. For IRC, ping user ``whot`` (Peter Hutterer, the libinput maintainer) though note that he lives on UTC+10 and thus the rest of the world is out of sync by default ;) For anything that appears to be device specific and/or related to a new feature, just file `an issue in our issue tracker `_. It's usually the most efficient way to get answers. ------------------------------------------------------------------------------ What to work on? ------------------------------------------------------------------------------ If you don't already know what you want to improve or fix with libinput, then a good way of finding something is to search for the ``help needed`` tag in our `issue tracker `_. These are issues that have been triaged to some degree and deemed to be a possible future feature to libinput. .. note:: Some of these issue may require specific hardware to reproduce. Another good place to help out with is the documentation. For anything you find in these pages that isn't clear enough please feel free to reword it and add what is missing. ------------------------------------------------------------------------------ Getting the code ------------------------------------------------------------------------------ The :ref:`building_libinput` have all the details but the short solution will be: :: $> git clone https://gitlab.freedesktop.org/libinput/libinput $> cd libinput $> meson setup --prefix=/usr builddir/ $> ninja -C builddir/ $> sudo ninja -C builddir/ install You can omit the last step if you only want to test locally. ------------------------------------------------------------------------------ Working on the code ------------------------------------------------------------------------------ If you are planning to send patches, it's a good idea to set up `pre-commit `_ with these commands:: $> pre-commit install $> pre-commit install --hook-type pre-push This will check a few things before you commit and/or push to your repos to reduce the turnaround time for some common mistakes. libinput has a roughly three-parts architecture: - the front-end code which handles the ``libinput_some_function()`` API calls in ``libinput.c`` - the generic evdev interface handling which maps those API calls to the backend calls (``evdev.c``). - there are device-specific backends which do most of the actual work - ``evdev-mt-touchpad.c`` is the one for touchpads for example. In general, things that only affect the internal workings of a device only get implemented in the device-specific backend. You only need to touch the API when you are adding configuration options. For more details, please read the :ref:`architecture` document. There's also a `blog post describing the building blocks `_ that may help to understand how it all fits together. Documentation is in ``/doc/api`` for the doxygen-generated API documentation. These are extracted from the libinput source code directly. The documentation you're reading right now is in ``/doc/user`` and generated with sphinx. Simply running ``ninja -C builddir`` will rebuild it and the final product ends up in ``builddir/Documentation``. ------------------------------------------------------------------------------ Testing the code ------------------------------------------------------------------------------ libinput provides a bunch of :ref:`tools` to debug any changes - without having to install libinput. The two most useful ones are :ref:`libinput debug-events ` and :ref:`libinput debug-gui `. Both tools can be run from the build directory directly and are great for quick test iterations:: $> sudo ./builddir/libinput-debug-events --verbose $> sudo ./builddir/libinput-debug-gui --verbose The former provides purely textual output and is useful for verifying event streams from buttons, etc. The latter is particularly useful when you are trying to debug pointer movement or placement. ``libinput debug-gui`` will also visualize the raw data from the device so you can compare pointer behavior with what comes from the kernel. These tools create a new libinput context and will not affect your session's behavior. Only once you've installed libinput and restarted your session will your changes affect the X server/Wayland compositor. Once everything seems to be correct, it's time to run the :ref:`test-suite`:: $> sudo ./builddir/libinput-test-suite This test suite can take test names etc. as arguments, have a look at :ref:`test-suite` for more info. There are a bunch of other tests that are run by the CI on merge requests, you can run those locally with :: $> sudo ninja -C builddir check So it always pays to run that before submitting. This will also run the code through valgrind and pick up any memory leaks. .. _contributing_submitting_code: ------------------------------------------------------------------------------ Submitting Code ------------------------------------------------------------------------------ Any patches should be sent via a Merge Request (see the `GitLab docs `_) in the `libinput GitLab instance hosted by freedesktop.org `_. .. note:: freedesktop.org's GitLab instance has restrictions to prevent Spam and you cannot fork libinput until you have successfully `applied for fork permissions `_. Below are the steps required to submit a merge request. They do not replace `learning git `__ but they should be sufficient to make some of the more confusing steps obvious. - `Register an account `_ in the freedesktop.org GitLab instance and `apply for fork permissions `_. - `Fork libinput `_ into your username's namespace. Select public visibility. - Get libinput's main repository. git will call this repository ``origin``. :: git clone https://gitlab.freedesktop.org/libinput/libinput.git - Add the forked git repository to your remotes (replace ``USERNAME`` with your username). git will call this repository ``gitlab``. :: cd /path/to/libinput.git git remote add gitlab git@gitlab.freedesktop.org:USERNAME/libinput.git git fetch gitlab - Create a new branch and commit your changes to that branch. :: git switch -C mynewbranch # edit files, make changes git add file1 file2 git commit -s # edit commit message in the editor Replace ``mynewbranch`` (here and in the commands below) with a meaningful name. See :ref:`contributing_commit_messages` for details on the commit message format. - Push your changes to your fork and submit a merge request :: git push gitlab mynewbranch This command will print the URL to file a merge request, you then only have to click through. Alternatively you can go to: https://gitlab.freedesktop.org/USERNAME/libinput/merge_requests Select your branch name to merge and ``libinput/libinput`` ``main`` as target branch. - Verify that the CI completes successfully by visiting the merge request page. A successful pipeline shows only green ticks, failure is indicated by a red cross or a yellow exclamation mark (see the `GitLab Docs `__). For details about the failures, click on the failed jobs in the pipelines and/or click the ``Expand`` button in the box for the test summaries. A merge request without a successful pipeline may never be looked at by a maintainer. - If changes are requested by the maintainers, please **amend** the commit(s) and **force-push** the updated branch. :: # edits in file foo.c git add foo.c git commit --amend git push -f gitlab mynewbranch A force-push will re-trigger the CI and notify the merge request that new changes are available. If the branch contains more than one commit, please look at `git interactive rebases `__ to learn how to change multiple commits, or squash new changes into older commits. ------------------------------------------------------------------------------ Commit History ------------------------------------------------------------------------------ libinput strives to have a `linear, 'recipe' style history `_ This means that every commit should be small, digestible, stand-alone, and functional. Rather than a purely chronological commit history like this: :: doc: final docs for view transforms fix tests when disabled, redo broken doc formatting better transformed-view iteration (thanks Hannah!) try to catch more cases in tests tests: add new spline test fix compilation on splines doc: notes on reticulating splines compositor: add spline reticulation for view transforms We aim to have a clean history which only reflects the final state, broken up into functional groupings: :: compositor: add spline reticulation for view transforms compositor: new iterator for view transforms tests: add view-transform correctness tests doc: fix Doxygen formatting for view transforms This ensures that the final patch series only contains the final state, without the changes and missteps taken along the development process. The first line of a commit message should contain a prefix indicating what part is affected by the patch followed by one sentence that describes the change. For example: :: touchpad: add software button behavior fallback: disable button debouncing on device foo If in doubt what prefix to use, look at other commits that change the same file(s) as the patch being sent. .. _contributing_commit_messages: ------------------------------------------------------------------------------ Commit Messages ------------------------------------------------------------------------------ When you re-send patches, revised or not, it would be very good to document the changes compared to the previous revision in the commit message and/or the merge request. If you have already received Reviewed-by or Acked-by tags, you should evaluate whether they still apply and include them in the respective commit messages. Otherwise the tags may be lost, reviewers miss the credit they deserve, and the patches may cause redundant review effort. If your commit solves a GitLab issue, add a ``Closes:`` tag followed by the issue number at the end of your commit message. For example: :: Closes: #974 If your commit fixes an issue introduced by another commit, use a ``Fixes`` tag followed by the first 12 characters of the SHA-1 ID and the commit one line summary at the end of your commit message. For example: :: Fixes: 123456789012 ("The commit that caused the issue") For further reading, please see `'on commit messages' `_ as a general guideline on what commit messages should contain. ------------------------------------------------------------------------------ Coding Style ------------------------------------------------------------------------------ Please see the `CODING_STYLE.md `_ document in the source tree. ------------------------------------------------------------------------------ Tracking patches and follow-ups ------------------------------------------------------------------------------ Once submitted to GitLab, your patches will be reviewed by the libinput development team on GitLab. Review may be entirely positive and result in your code landing instantly, in which case, great! You're done. However, we may ask you to make some revisions: fixing some bugs we've noticed, working to a slightly different design, or adding documentation and tests. If you do get asked to revise the patches, please bear in mind the notes above. You should use ``git rebase -i`` to make revisions, so that your patches follow the clear linear split documented above. Following that split makes it easier for reviewers to understand your work, and to verify that the code you're submitting is correct. A common request is to split single large patch into multiple patches. This can happen, for example, if when adding a new feature you notice a bug in libinput's core which you need to fix to progress. Separating these changes into separate commits will allow us to verify and land the bugfix quickly, pushing part of your work for the good of everyone, whilst revision and discussion continues on the larger feature part. It also allows us to direct you towards reviewers who best understand the different areas you are working on. When you have made any requested changes, please rebase the commits, verify that they still individually look good, then force-push your new branch to GitLab. This will update the merge request and notify everyone subscribed to your merge request, so they can review it again. There are also many GitLab CLI clients, if you prefer to avoid the web interface. It may be difficult to follow review comments without using the web interface though, so we do recommend using this to go through the review process, even if you use other clients to track the list of available patches. ------------------------------------------------------------------------------ Failed pipeline errors ------------------------------------------------------------------------------ After submitting your merge request to GitLab, you might receive an email informing you that your pipeline failed. Visit your merge request page and check the `pipeline mini graph `_ to know which step failed. Follow the appropriate section to fix the errors. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When your merge request modifies the CI templates, you might see this error mainly due two reasons: the wrong file was modified and/or ``ci-fairy generate-template`` wasn't run. ``.gitlab-ci.yaml`` is auto generated, changes should be made in: - ``.gitlab-ci/ci.template`` - ``.gitlab-ci/config.yaml`` Once the changes are ready, run `ci-fairy `_ to update ``.gitlab-ci.yaml``: :: ci-fairy generate-template Finally, force-push you changes. See :ref:`contributing_submitting_code` for more details. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Build errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Usually, checking the CI log is enough to catch this errors. However, your merge request is built using different configurations you might have not tested. In order to fix this kind of problems, you can compile libinput using the same flags used by the CI. For example, if an error is found in the ``build-no-libwacom`` step, open the log and search the build options: :: [...] + rm -rf 'build dir' + meson 'build dir' -Dlibwacom=false The Meson build system [...] Use the same flags to fix the issue and force-push you changes. See :ref:`contributing_submitting_code` for more details. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Test errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The test suite is run for your merge request to check for bugs, regressions and memory leaks among other issues. Open the CI error log and search for a message similar to: :: :: Failure: ../test/test-touchpad.c:465: touchpad_2fg_scroll_slow_distance(synaptics-t440) See :ref:`test-suite` to learn how to run the failing tests. Once the tests are fixed, force-push you changes. See :ref:`contributing_submitting_code` for more details. libinput-1.28.1/doc/user/dependencies.rst000066400000000000000000000005741477265155700203650ustar00rootroot00000000000000.. warning:: The package lists are autogenerated from the `CI `_. - Fedora: :: dnf install @FEDORA_PACKAGES@ - Ubuntu: :: apt install @UBUNTU_PACKAGES@ - Debian: :: apt install @DEBIAN_PACKAGES@ - Arch: :: pacman -S @ARCH_PACKAGES@ - Alpine: :: apk add @ALPINE_PACKAGES@ libinput-1.28.1/doc/user/development.rst000066400000000000000000000031531477265155700202550ustar00rootroot00000000000000.. _development: ============================================================================== Information for developers ============================================================================== Below is a list of topics of interest to developers, divided into information for those :ref:`using_libinput_as_library` in a Wayland compositor or other project. The :ref:`hacking_on_libinput` section applies to developers working on libinput itself. .. note:: If you use or work on libinput you should get in touch with the libinput developers on the wayland-devel@lists.freedesktop.org mailing lists .. _using_libinput_as_library: ------------------------------------------------------------------------------ Using libinput as library ------------------------------------------------------------------------------ See :ref:`building_against` for information on how to integrate libinput with your project's build system. .. note:: **libinput's API documentation is available here:** http://wayland.freedesktop.org/libinput/doc/latest/api/ Topics below explain some behaviors of libinput. .. toctree:: :maxdepth: 1 absolute-axes.rst absolute-coordinate-ranges.rst normalization-of-relative-motion.rst seats.rst timestamps.rst wheel-api.rst .. _hacking_on_libinput: ------------------------------------------------------------------------------ Hacking on libinput ------------------------------------------------------------------------------ .. toctree:: :maxdepth: 1 architecture test-suite.rst pointer-acceleration.rst device-configuration-via-udev.rst libinput-1.28.1/doc/user/device-configuration-via-udev.rst000066400000000000000000000240331477265155700235550ustar00rootroot00000000000000.. _udev_config: ============================================================================== Static device configuration via udev ============================================================================== libinput supports some static configuration through udev properties. These properties are read when the device is initially added to libinput's device list, i.e. before the **LIBINPUT_EVENT_DEVICE_ADDED** event is generated. The following udev properties are supported: LIBINPUT_CALIBRATION_MATRIX Sets the calibration matrix, see **libinput_device_config_calibration_get_default_matrix()**. If unset, defaults to the identity matrix. The udev property is parsed as 6 floating point numbers separated by a single space each (scanf(3) format ``"%f %f %f %f %f %f"``). The 6 values represent the first two rows of the calibration matrix as described in **libinput_device_config_calibration_set_matrix()**. Example values are: :: ENV{LIBINPUT_CALIBRATION_MATRIX}="1 0 0 0 1 0" # default ENV{LIBINPUT_CALIBRATION_MATRIX}="0 -1 1 1 0 0" # 90 degree clockwise ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 -1 1" # 180 degree clockwise ENV{LIBINPUT_CALIBRATION_MATRIX}="0 1 0 -1 0 1" # 270 degree clockwise ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 1 0" # reflect along y axis LIBINPUT_DEVICE_GROUP A string identifying the **libinput_device_group** for this device. Two devices with the same property value are grouped into the same device group, the value itself is irrelevant otherwise. LIBINPUT_IGNORE_DEVICE If set to anything other than "0", the device is ignored by libinput. See :ref:`ignoring_devices` for more details. ID_SEAT Assigns the physical :ref:`seat ` for this device. See **libinput_seat_get_physical_name()**. Defaults to "seat0". ID_INPUT If this property is set, the device is considered an input device. Any device with this property missing will be ignored, see :ref:`udev_device_type`. ID_INPUT_KEYBOARD, ID_INPUT_KEY, ID_INPUT_MOUSE, ID_INPUT_TOUCHPAD, ID_INPUT_TOUCHSCREEN, ID_INPUT_TABLET, ID_INPUT_JOYSTICK, ID_INPUT_ACCELEROMETER If any of the above is set, libinput initializes the device as the given type, see :ref:`udev_device_type`. Note that for historical reasons more than one of these may be set at any time, libinput will select only one of these to determine the device type. To ensure libinput selects the correct device type, only set one of them. WL_SEAT Assigns the logical :ref:`seat ` for this device. See **libinput_seat_get_logical_name()** context. Defaults to "default". MOUSE_DPI HW resolution and sampling frequency of a relative pointer device. See :ref:`motion_normalization` for details. MOUSE_WHEEL_CLICK_ANGLE The angle in degrees for each click on a mouse wheel. See **libinput_pointer_get_axis_source()** for details. Below is an example udev rule to assign "seat1" to a device from vendor ``0x012a`` with the model ID of ``0x034b``. :: $ cat /etc/udev/rules.d/99-my-device-is-on-seat1.rules ACTION!="remove", KERNEL=="event[0-9]*", \ ENV{ID_VENDOR_ID}=="012a", \ ENV{ID_MODEL_ID}=="034b", \ ENV{ID_SEAT}="seat1" .. _udev_device_type: ------------------------------------------------------------------------------ Device type assignment via udev ------------------------------------------------------------------------------ libinput requires the **ID_INPUT** property to be set on a device, otherwise the device will be ignored. In addition, one of **ID_INPUT_KEYBOARD, ID_INPUT_KEY, ID_INPUT_MOUSE, ID_INPUT_TOUCHPAD, ID_INPUT_TOUCHSCREEN, ID_INPUT_TABLET, ID_INPUT_JOYSTICK, ID_INPUT_ACCELEROMETER** must be set on the device to determine the device type. The usual error handling applies within libinput and a device type label does not guarantee that the device is initialized by libinput. If a device fails to meet the requirements for a device type (e.g. a keyboard labelled as touchpad) the device will not be available through libinput. Only one device type should be set per device at a type, though libinput can handle some combinations for historical reasons. Below is an example udev rule to remove an **ID_INPUT_TOUCHPAD** setting and change it into an **ID_INPUT_TABLET** setting. This rule would apply for a device with the vendor/model ID of ``012a``/``034b``. :: $ cat /etc/udev/rules.d/99-my-device-is-a-tablet.rules ACTION!="remove", KERNEL=="event[0-9]*", \ ENV{ID_VENDOR_ID}=="012a", \ ENV{ID_MODEL_ID}=="034b", \ ENV{ID_INPUT_TOUCHPAD}="", ENV{ID_INPUT_TABLET}="1" .. _model_specific_configuration: ------------------------------------------------------------------------------ Model-specific configuration ------------------------------------------------------------------------------ As of libinput 1.12, model-specific configuration is stored in the :ref:`device-quirks` and not in the hwdb anymore. Please see :ref:`device-quirks` for details. .. _model_specific_configuration_x220fw81: .............................................................................. Lenovo x220 with touchpad firmware v8.1 .............................................................................. The property **LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81** may be set by a user in a local hwdb file. This property designates the touchpad on a Lenovo x220 with a touchpad firmware version 8.1. When this firmware version is installed, the touchpad is imprecise. The touchpad device does not send continuous x/y axis position updates, a behavior also observed on its successor model, the Lenovo x230 which has the same firmware version. If the above property is set, libinput adjusts its behavior to better suit this particular model. The touchpad firmware version cannot be detected automatically by libinput, local configuration is required to set this property. Refer to the libinput model quirks hwdb for instructions. This property must not be used for any other purpose, no specific behavior is guaranteed. .. _hwdb: ------------------------------------------------------------------------------ Configuring the hwdb ------------------------------------------------------------------------------ This section outlines how to query the `udev hwdb `_ and reload properties so they are available to libinput. The hwdb contains a set of match rules that assign udev properties that are available to libinput when the device is connected and/or libinput is initialized. This section only describes the hwdb in relation to libinput, it is not a full documentation on how the hwdb works. libinput's use of the hwdb is limited to properties systemd and custom rules files (where available) provide. Hardware-specific quirks as used by libinput are in the :ref:`device-quirks` system. .. _hwdb_querying: .............................................................................. Querying the hwdb .............................................................................. libinput only uses device nodes in the form of ``/dev/input/eventX`` where X is the number of the specific device. Running ``libinput debug-events`` lists all devices currently available to libinput and their event node name: :: $> sudo libinput debug-events -event2 DEVICE_ADDED Power Button seat0 default group1 cap:k -event5 DEVICE_ADDED Video Bus seat0 default group2 cap:k -event0 DEVICE_ADDED Lid Switch seat0 default group3 cap:S ... Note the event node name for your device and translate it into a syspath in the form of ``/sys/class/input/eventX``. This path can be supplied to ``udevadm info`` :: $> udevadm info P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0/event0 N: input/event0 E: DEVNAME=/dev/input/event0 E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0/event0 E: ID_INPUT=1 E: ID_INPUT_SWITCH=1 E: MAJOR=13 E: MINOR=64 E: SUBSYSTEM=input E: TAGS=:power-switch: E: USEC_INITIALIZED=7167898 Lines starting with ``E:`` are udev properties available to libinput. For example, the above device's ``ID_INPUT_SWITCH`` property will cause libinput to treat this device as switch device. .. _hwdb_reloading: .............................................................................. Reloading the hwdb .............................................................................. The actual hwdb is stored in binary file on-disk and must be updated manually whenever a ``.hwdb`` file changes. This is required both when a user manually edits the ``.hwdb`` file but also when the git tree is updated (and that update causes a hwdb change). To update the binary file on-disk, run: :: sudo systemd-hwdb update Then, to trigger a reload of all properties on your device, run: :: sudo udevadm trigger /sys/class/input/eventX Then check with ``udevadm info`` whether the properties were updated, see :ref:`hwdb_querying`. If a new property does not appear on the device, use ``udevadm test`` to check for error messages by udev and the hwdb (e.g. syntax errors in the udev rules files). :: sudo udevadm test /sys/class/input/eventX .. warning:: ``udevadm test`` does not run commands specified in ``RUN`` directives. This affects the udev properties relying on e.g. the udev keyboard builtin such as the :ref:`touchpad_jitter` workarounds. .. _hwdb_modifying: .............................................................................. Modifying the hwdb .............................................................................. .. warning:: This section has been removed as it no longer applies in libinput 1.12 and later. libinput users should not need to modify the hwdb, any device-specific quirks must go in to the :ref:`device-quirks` system. For information about older libinput versions, please see the documentation for your version available in: https://wayland.freedesktop.org/libinput/doc/ libinput-1.28.1/doc/user/device-quirks.rst000066400000000000000000000273521477265155700205150ustar00rootroot00000000000000.. _device-quirks: ============================================================================== Device quirks ============================================================================== libinput requires extra information from devices that is not always readily available. For example, some touchpads are known to have jumping cursors under specific conditions. libinput ships a set of files containing the so-called model quirks to provide that information. Model quirks are usually installed under ``/usr/share/libinput/.quirks`` and are standard ``.ini`` files. A file may contain multiple section headers (``[some identifier]``) followed by one or more :ref:`MatchFoo=Bar ` directives, followed by at least one of ``ModelFoo=1`` or ``AttrFoo=bar`` directive. See the ``quirks/README.md`` file in the libinput source repository for more details on their contents. .. warning:: Model quirks are internal API and may change at any time. No backwards-compatibility is guaranteed. For example, a quirks file may have this content to label all keyboards on the serial bus (PS/2) as internal keyboards: :: [Serial Keyboards] MatchUdevType=keyboard MatchBus=serial AttrKeyboardIntegration=internal The model quirks are part of the source distribution and should never be modified locally. Updates to libinput may overwrite modifications or even stop parsing any property. For temporary local workarounds, see :ref:`device-quirks-local`. Device quirks are parsed on libinput initialization. A parsing error in the device quirks disables **all** device quirks and may negatively impact device behavior on the host. If the quirks cannot be loaded, an error message is posted to the log and users should use the information in :ref:`device-quirks-debugging` to verify their quirks files. .. _device-quirks-local: ------------------------------------------------------------------------------ Installing temporary local device quirks ------------------------------------------------------------------------------ The model quirks are part of the source distribution and should never be modified. For temporary local workarounds, libinput reads the ``/etc/libinput/local-overrides.quirks`` file. Users may add a sections to this file to add a device quirk for a local device but beware that **any modification must be upstreamed** or it may cease to work at any time. .. warning:: Model quirks are internal API and may change at any time. No backwards-compatibility is guaranteed. Local overrides should only be used until the distribution updates the libinput packages. The ``local-overrides.quirks`` file usually needs to be created by the user. Once the required section has been added, use the information from section :ref:`device-quirks-debugging` to validate and test the quirks. .. _device-quirks-debugging: ------------------------------------------------------------------------------ Debugging device quirks ------------------------------------------------------------------------------ libinput provides the ``libinput quirks`` tool to debug the quirks database. This tool takes an action as first argument, the most common invocation is ``libinput quirks list`` to list model quirks that apply to one or more local devices. :: $ libinput quirks list /dev/input/event19 $ libinput quirks list /dev/input/event0 AttrLidSwitchReliability=unreliable The device `event19` does not have any quirks assigned. When called with the ``--verbose`` argument, ``libinput quirks list`` prints information about all files and its attempts to match the device: :: $ libinput quirks list --verbose /dev/input/event0 quirks debug: /usr/share/share/libinput is data root quirks debug: /usr/share/share/libinput/10-generic-keyboard.quirks quirks debug: /usr/share/share/libinput/10-generic-lid.quirks [...] quirks debug: /usr/share/etc/libinput/local-overrides.quirks quirks debug: /dev/input/event0: fetching quirks quirks debug: [Serial Keyboards] (10-generic-keyboard.quirks) wants MatchBus but we don't have that quirks debug: [Lid Switch Ct9] (10-generic-lid.quirks) matches for MatchName quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) matches for MatchName quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) matches for MatchDMIModalias quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) is full match quirks debug: property added: AttrLidSwitchReliability from [Lid Switch Ct10] (10-generic-lid.quirks) quirks debug: [Aiptek No Tilt Tablet] (30-vendor-aiptek.quirks) wants MatchBus but we don't have that [...] quirks debug: [HUION PenTablet] (30-vendor-huion.quirks) wants MatchBus but we don't have that quirks debug: [Logitech Marble Mouse Trackball] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Logitech K400] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Logitech K400r] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Logitech K830] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Logitech K400Plus] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Logitech Wireless Touchpad] (30-vendor-logitech.quirks) wants MatchBus but we don't have that quirks debug: [Microsoft Surface 3 Lid Switch] (30-vendor-microsoft.quirks) matches for MatchName [...] AttrLidSwitchReliability Note that this is an example only, the output may change over time. The tool uses the same parser as libinput and any parsing errors will show up in the output. .. _device-quirks-list: ------------------------------------------------------------------------------ List of currently available device quirks ------------------------------------------------------------------------------ This list is a guide for developers to ease the process of submitting patches upstream. This section shows device quirks currently available in |git_version|. .. warning:: Quirks are internal API and may change at any time for any reason. No guarantee is given that any quirk below works on your version of libinput. In the documentation below, the letters N, M, O, P refer to arbitrary integer values. Quirks starting with **Model*** triggers implementation-defined behaviour for this device not needed for any other device. Only the more general-purpose **Model*** flags are listed here. ModelALPSTouchpad, ModelAppleTouchpad, ModelWacomTouchpad, ModelChromebook Reserved for touchpads made by the respective vendors ModelTouchpadVisibleMarker Indicates the touchpad has a drawn-on visible marker between the software buttons. ModelTabletModeNoSuspend Indicates that the device does not need to be suspended in :ref:`switches_tablet_mode`. ModelTabletModeSwitchUnreliable Indicates that this tablet mode switch's state cannot be relied upon. ModelTrackball Reserved for trackballs ModelBouncingKeys Indicates that the device may send fake bouncing key events and timestamps can not be relied upon. ModelSynapticsSerialTouchpad Reserved for touchpads made by Synaptics on the serial bus ModelPressurePad Unlike in traditional touchpads, whose pressure value equals contact size, on pressure pads pressure is a real physical axis. Indicates that the device is a pressure pad. ModelTouchpadPhantomClicks Some laptops are prone to registering touchpad clicks when the case is bent. Indicates that clicks should be ignored if no fingers are on the touchpad. AttrSizeHint=NxM, AttrResolutionHint=N Hints at the width x height of the device in mm, or the resolution of the x/y axis in units/mm. These may only be used where they apply to a large proportion of matching devices. They should not be used for any specific device, override ``EVDEV_ABS_*`` instead, see :ref:`absolute_coordinate_ranges_fix`. AttrTouchSizeRange=N:M, AttrPalmSizeThreshold=O Specifies the touch size required to trigger a press (N) and to trigger a release (M). O > N > M. See :ref:`touchpad_touch_size_hwdb` for more details. An AttrPalmSizeThreshold of zero unsets any threshold that has been inherited from another quirk. AttrPressureRange=N:M, AttrPalmPressureThreshold=O, AttrThumbPressureThreshold=P Specifies the touch pressure required to trigger a press (N) and to trigger a release (M), when a palm touch is triggered (O) and when a thumb touch is triggered (P). O > P > N > M. See :ref:`touchpad_pressure_hwdb` for more details. An AttrPalmPressureThreshold of zero unsets any threshold that has been inherited from another quirk. AttrLidSwitchReliability=reliable|unreliable|write_open Indicates the reliability of the lid switch. This is a string enum. Very few devices need this, if in doubt do not set. See :ref:`switches_lid` for details. libinput 1.21.0 changed the default from unreliable to reliable, which may be removed from local overrides. AttrKeyboardIntegration=internal|external Indicates the integration of the keyboard. This is a string enum. Generally only needed for USB keyboards. AttrTPKComboLayout=below Indicates the position of the touchpad on an external touchpad+keyboard combination device. This is a string enum. Don't specify it unless the touchpad is below. AttrEventCode=+EV_ABS;-BTN_STYLUS;+EV_KEY:0x123; Enables or disables the evdev event type/code tuples on the device. The prefix for each entry is either '+' (enable) or '-' (disable). Entries may be a named event type, or a named event code, or a named event type with a hexadecimal event code, separated by a single colon. AttrInputProp=+INPUT_PROP_BUTTONPAD;-INPUT_PROP_POINTER; Enables or disables the evdev input property on the device. The prefix for each entry is either '+' (enable) or '-' (disable). Entries may be a named input property or the hexadecimal value of that property. AttrPointingStickIntegration=internal|external Indicates the integration of the pointing stick. This is a string enum. Only needed for external pointing sticks. These are rare. AttrTabletSmoothing=1|0 Enables (1) or disables (0) input smoothing for tablet devices. Smoothing is enabled by default, except on AES devices. .. _device-quirks-matches: ------------------------------------------------------------------------------ List of currently available matches ------------------------------------------------------------------------------ ``Match*`` statements are how quirks are assigned to a device. Quirks with multiple match statements must match all of those to apply. .. warning:: Quirks are internal API and may change at any time for any reason. No guarantee is given that any ``Match`` statement below works on your version of libinput. MatchName, MatchUniq Match on the ``NAME`` or ``UNIQ`` udev property on this device. These properties are typically derived from the device's kernel name or uniq but may be overridden by a udev rule. These matches use ``fnmatch()`` globs. MatchBus A lower-case bus name. Currently supported are ``usb``, ``bluetooth``, ``ps2``, ``rmi``, ``i2c``, and ``spi``. MatchVendor, MatchProduct, MatchVersion The hexadecmial 4-digit vendor ID, product ID or driver version as exported, without a ``0x`` prefix. MatchDMIModalias, MatchDeviceTree An ``fnmatch()`` glob for the DMI modalias or the DeviceTree ``compatible`` string. See ``/sys/class/dmi/id/modalias`` and ``/sys/firmware/devicetree/base/compatible``. MatchUdevType One of ``touchpad``, ``mouse``, ``pointingstick``, ``keyboard``, ``joystick``, ``tablet``, ``tablet-pad``. Matches the corresponding ``ID_INPUT_*`` udev property. libinput-1.28.1/doc/user/dot/000077500000000000000000000000001477265155700157655ustar00rootroot00000000000000libinput-1.28.1/doc/user/dot/evemu.gv000066400000000000000000000003511477265155700174430ustar00rootroot00000000000000digraph stack { compound=true; rankdir="LR"; node [ shape="box"; ] kernel [label="Kernel"]; libinput; xserver [label="X Server"]; kernel -> libinput libinput -> xserver kernel -> evemu evemu -> stdout } libinput-1.28.1/doc/user/dot/libinput-record.gv000066400000000000000000000004201477265155700214210ustar00rootroot00000000000000digraph stack { compound=true; rankdir="LR"; node [ shape="box"; ] kernel [label="Kernel"]; libinput; xserver [label="X Server"]; record [label="libinput record"]; kernel -> libinput libinput -> xserver kernel -> record; record -> stdout } libinput-1.28.1/doc/user/dot/libinput-stack-gnome.gv000066400000000000000000000006521477265155700223620ustar00rootroot00000000000000digraph stack { compound=true; rankdir="LR"; node [ shape="box"; ] gcc -> gsettings xf86libinput -> libinput subgraph cluster0 { label="X.Org"; xf86libinput [label="xf86-input-libinput"]; xserver [label="X Server"]; xserver -> xf86libinput; } gcc [label="gnome-control-center"]; subgraph cluster3 { gsettings } gsd [label="mutter"]; gsd -> gsettings gsd -> xserver } libinput-1.28.1/doc/user/dot/libinput-stack-wayland.gv000066400000000000000000000006461477265155700227170ustar00rootroot00000000000000digraph stack { compound=true; rankdir="LR"; node [ shape="box"; ] subgraph cluster_2 { label="Kernel"; event0 [label="/dev/input/event0"] event1 [label="/dev/input/event1"] } subgraph cluster_0 { label="Compositor process"; libinput; } client [label="Wayland client"]; event0 -> libinput; event1 -> libinput; libinput -> client [ltail=cluster_0 label="Wayland protocol"]; } libinput-1.28.1/doc/user/dot/libinput-stack-xorg.gv000066400000000000000000000007441477265155700222360ustar00rootroot00000000000000digraph stack { compound=true; rankdir="LR"; node [ shape="box"; ] subgraph cluster_2 { label="Kernel"; event0 [label="/dev/input/event0"] event1 [label="/dev/input/event1"] } subgraph cluster_0 { label="X server process"; subgraph cluster_1 { label="xf86-input-libinput" libinput; } } libinput; client [label="X11 client"]; event0 -> libinput; event1 -> libinput; libinput -> client [ltail=cluster_0 label="X protocol"]; } libinput-1.28.1/doc/user/dot/seats-sketch-libinput.gv000066400000000000000000000010711477265155700225440ustar00rootroot00000000000000digraph seats_libinput { rankdir="BT"; node [ shape="box"; ] ctx1 [label="libinput context 1"; URL="\ref libinput"]; ctx2 [label="libinput context 2"; URL="\ref libinput"]; seat0 [ label="seat phys 0 logical A"]; seat1 [ label="seat phys 0 logical B"]; seat2 [ label="seat phys 1 logical C"]; dev1 [label="device 'Foo'"]; dev2 [label="device 'Bar'"]; dev3 [label="device 'Spam'"]; dev4 [label="device 'Egg'"]; ctx1 -> dev1 ctx1 -> dev2 ctx1 -> dev3 ctx2 -> dev4 dev1 -> seat0 dev2 -> seat0 dev3 -> seat1 dev4 -> seat2 } libinput-1.28.1/doc/user/dot/seats-sketch.gv000066400000000000000000000022401477265155700207170ustar00rootroot00000000000000digraph seats { rankdir="BT"; node [ shape="box"; ] kernel [label="Kernel"]; event0 [URL="\ref libinput_event"]; event1 [URL="\ref libinput_event"]; event2 [URL="\ref libinput_event"]; event3 [URL="\ref libinput_event"]; pseat0 [label="phys seat0"; URL="\ref libinput_seat_get_physical_name"]; pseat1 [label="phys seat1"; URL="\ref libinput_seat_get_physical_name"]; lseatA [label="logical seat A"; URL="\ref libinput_seat_get_logical_name"]; lseatB [label="logical seat B"; URL="\ref libinput_seat_get_logical_name"]; lseatC [label="logical seat C"; URL="\ref libinput_seat_get_logical_name"]; ctx1 [label="libinput context 1"; URL="\ref libinput"]; ctx2 [label="libinput context 2"; URL="\ref libinput"]; dev1 [label="device 'Foo'"]; dev2 [label="device 'Bar'"]; dev3 [label="device 'Spam'"]; dev4 [label="device 'Egg'"]; kernel -> event0 kernel -> event1 kernel -> event2 kernel -> event3 event0 -> pseat0 event1 -> pseat0 event2 -> pseat0 event3 -> pseat1 pseat0 -> ctx1 pseat1 -> ctx2 ctx1 -> lseatA ctx1 -> lseatB ctx2 -> lseatC lseatA -> dev1 lseatA -> dev2 lseatB -> dev3 lseatC -> dev4 } libinput-1.28.1/doc/user/drag-3fg.rst000066400000000000000000000036361477265155700173330ustar00rootroot00000000000000.. _drag_3fg: ============================================================================== Three-finger drag ============================================================================== Three-finger drag is a feature available on touchpads that emulates logical button presses if three fingers are moving on the touchpad. Three-finger drag is independent from :ref:`tapping` though some specific behaviors may change when both features are enabled. For example, with tapping *disabled* a three-finger gesture will virtually always be a three-finger drag. With tapping *enabled* a three finger gesture may be a three finger drag and a short delay is required to disambiguate between the two. The exact behavior of three-finger drag is implementation defined and may subtly change. As a general rule, the following constraints can be expected: - three fingers down and movement trigger a button down and subsequent motion events (i.e. a drag) - releasing one finger while keeping two fingers down will keep the drag and *not* switch to :ref:`twofinger_scrolling`. - releasing two fingers while keeping one finger down will end the drag (and thus release the button) and switch to normal pointer motion - releasing all three fingers and putting three fingers back on the touchpad immediately will keep the drag (i.e. behave as if the fingers were never lifted) - if tapping is enabled: a three finger tap immediately after a three-finger drag will *not* tap, the user needs to wait past the timeout to three-finger tap - releasing all three fingers and putting one or two fingers back on the touchpad will end the drag (and thus release the button) and proceed with pointer motion or two-finger scrolling, if applicable - if tapping is enabled: a one or two finger tap immediately after a three-finger drag will trigger a one or two finger tap. The user does not have to wait past the drag release timeout libinput-1.28.1/doc/user/faqs.rst000066400000000000000000000405701477265155700166710ustar00rootroot00000000000000.. _faq: ============================================================================== FAQs - Frequently Asked Questions ============================================================================== Frequently asked questions about libinput. .. contents:: :local: :backlinks: entry .. _faq_feature: ------------------------------------------------------------------------------ Why doesn't libinput support ...? ------------------------------------------------------------------------------ First, read :ref:`what_is_libinput` If you have a feature that you think libinput needs to support, please file a bug report. See :ref:`reporting_bugs` for more details. .. _faq_fast_mouse: ------------------------------------------------------------------------------ My mouse moves too fast, even at the slowest setting ------------------------------------------------------------------------------ This is a symptom of high-dpi mice (greater than 1000dpi). These devices need a udev hwdb entry to normalize their motion. See :ref:`motion_normalization` for a detailed explanation. .. _faq_fast_trackpoint: ------------------------------------------------------------------------------ My trackpoint moves too slow or too fast ------------------------------------------------------------------------------ This is a symptom of an invalid trackpoint multiplier. These devices need :ref:`device-quirks` to specify the range available so libinput can adjust the pointer acceleration accordingly. See :ref:`trackpoint_range` for a detailed explanation. .. _faq_pointer_acceleration: ------------------------------------------------------------------------------ Why is libinput's pointer acceleration worse than synaptics/evdev ------------------------------------------------------------------------------ This is a known problem affecting some devices and/or use-case but the exact cause is still unknown. It may be a device-specific issue, it may be a bug in libinput's acceleration code, it may be a disagreement about how pointer acceleration should feel. Unfortunately this is something that affected users need to investigate and analyze. .. _faq_enable_tapping: ------------------------------------------------------------------------------ Why isn't touchpad tap-to-click enabled by default ------------------------------------------------------------------------------ See :ref:`tapping_default` .. _faq_touchpad_pressure: ------------------------------------------------------------------------------ Why does my touchpad lose track of touches ------------------------------------------------------------------------------ The most common cause for this is an incorrect pressure threshold range. See :ref:`touchpad_pressure` for more info. .. _faq_kinetic_scrolling: ------------------------------------------------------------------------------ Kinetic scrolling does not work ------------------------------------------------------------------------------ The X.Org synaptics driver implemented kinetic scrolling in the driver. It measures the scroll speed and once the finger leaves the touchpad the driver keeps sending scroll events for a predetermined time. This effectively provides for kinetic scrolling without client support but triggers an unfixable `bug `_: the client cannot know that the events are from a kinetic scroll source. Scroll events in X are always sent to the current cursor position, a movement of the cursor after lifting the finger will send the kinetic scroll events to the new client, something the user does not usually expect. A key event during the kinetic scroll procedure causes side-effects such as triggering zoom. libinput does not implement kinetic scrolling for touchpads. Instead it provides the **libinput_event_pointer_get_axis_source()** function that enables callers to implement kinetic scrolling on a per-widget basis, see :ref:`scroll_sources`. .. _faq_gpl: ------------------------------------------------------------------------------ Is libinput GPL-licensed? ------------------------------------------------------------------------------ No, libinput is MIT licensed. The Linux kernel header file linux/input.h in libinput's tree is provided to ensure the same behavior regardless of which kernel version libinput is built on. It does not make libinput GPL-licensed. .. _faq_config_options: ------------------------------------------------------------------------------ Where is the configuration stored? ------------------------------------------------------------------------------ libinput does not store configuration options, it is up to the caller to manage these and decide which configuration option to apply to each device. This must be done at startup, after a resume and whenever a new device is detected. One commonly used way to configure libinput is to have the Wayland compositor expose a compositor-specific configuration option. For example, in a GNOME stack, the gnome-control-center modifies dconf entries. These changes are read by mutter and applied to libinput. Changing these entries via the gsettings commandline tool has the same effect. Another commonly used way to configure libinput is to have xorg.conf.d snippets. When libinput is used with the xf86-input-libinput driver in an X.Org stack, these options are read on startup and apply to each device. Changing properties at runtime with the xinput commandline tool has the same effect. In both cases, the selection of available options and how they are exposed depends on the libinput caller (e.g. mutter or xf86-input-libinput). .. graphviz:: libinput-stack-gnome.gv This has an effect on the availability of configuration options: if an option is not exposed by the intermediary, it cannot be configured by the client. Also some configuration options that are provided by the intermediary may not be libinput-specific configuration options. .. _faq_configure_wayland: ------------------------------------------------------------------------------ How do I configure my device on Wayland? ------------------------------------------------------------------------------ See :ref:`faq_config_options` Use the configuration tool provided by your desktop environment (e.g. gnome-control-center) or direct access to your desktop environment's configuration storage (e.g. gsettings). .. _faq_configure_xorg: ------------------------------------------------------------------------------ How do I configure my device on X? ------------------------------------------------------------------------------ See :ref:`faq_config_options` If your desktop environment does not provide a graphical configuration tool you can use an `xorg.conf.d snippet `_. Usually, such a snippet looks like this: :: $> cat /etc/X11/xorg.conf.d/99-libinput-custom-config.conf Section "InputClass" Identifier "something to identify this snippet" MatchDriver "libinput" MatchProduct "substring of the device name" Option "some option name" "the option value" EndSection The identifier is merely a human-readable string that shows up in the log file. The MatchProduct line should contain the device name or a substring of the device name that the snippet should apply to. For a full list of option names and permitted values, see the `libinput man page `_. xorg.conf.d snippets like the above apply to hotplugged devices but can be overwritten at runtime by desktop tools. Multiple snippets may be placed into the same file. For run-time configuration and testing, the `xinput `_ debugging tool can modify a devices' properties. See the `libinput man page `_ for supported property names and values. Usually, an invocation looks like this: :: $> xinput set-prop "the device name" "the property name" value [value2] [value3] .. note:: Changes performed by xinput do not persist across device hotplugs. xinput is considered a debugging and testing tool only and should not be used for permanent configurations. .. _faq_configuration: ------------------------------------------------------------------------------ Can you add a configuration option for $FEATURE? ------------------------------------------------------------------------------ No. At least that's going to be the initial answer. Read `Why libinput doesn't have a lot of configuration options `_ first. Configuration options for most features are a signal that we are incapable of handling it correctly. To get to that point, we want to be sure we're truly incapable of doing so. libinput has several features that are handled automatically (and correctly) that users wanted to have configuration options for initially. So the answer to this question will almost always be 'no'. A configuration option is, in most cases, a cop-out. .. _faq_synclient: ------------------------------------------------------------------------------ Why don't synclient and syndaemon work with libinput? ------------------------------------------------------------------------------ Synclient and syndaemon rely on X input device properties that are specific to the xf86-input-synaptics X.Org input driver. Both were written when the synaptics driver was the only common touchpad driver in existence. They assume that if the properties aren't available, no touchpad is available either. The xf86-input-libinput X.Org input driver does not export these driver-specific properties, synclient/syndaemon will thus not detect the touchpad and refuse to work. Other tools that rely on synclient/syndaemon or those same properties also do not work with xf86-input-libinput. Most of syndaemon's functionality is built into libinput, see :ref:`disable-while-typing`. synclient is merely a configuration tool, see :ref:`faq_configure_xorg` for similar functionality. See also the blog posts `The definitive guide to synclient `_ and `The future of xinput, xmodmap, setxkbmap, xsetwacom and other tools under Wayland `_ .. _faq_tablets: ------------------------------------------------------------------------------ Does libinput support non-Wacom tablets? ------------------------------------------------------------------------------ Yes, though unfortunately many non-Wacom tablets suffer from bad firmware and don't send the required events. But they should all work nonetheless. If you have a tablet that does not work with libinput, please :ref:`file a bug `. .. _faq_tablet_capabilities: ------------------------------------------------------------------------------ My tablet doesn't work ------------------------------------------------------------------------------ If you see the message :: libinput bug: device does not meet tablet criteria. Ignoring this device. or the message :: missing tablet capabilities [...] Ignoring this device. your tablet device does not have the required capabilities to be treated as a tablet. This is usually a problem with the device and the kernel driver. See :ref:`tablet-capabilities` for more details. .. _faq_hwdb_changes: ------------------------------------------------------------------------------ How to apply hwdb changes ------------------------------------------------------------------------------ Sometimes users are asked to test updates to the `udev hwdb `_ or patches that include a change to the hwdb. See :ref:`hwdb` for details on the hwdb and how to modify it locally. .. note:: As of libinput 1.12, libinput-specific properties are now stored in the :ref:`device-quirks` system. There are no libinput-specific hwdb entries anymore and any changes to the hwdb must be merged into the systemd repository. .. _faq_timer_offset: ------------------------------------------------------------------------------ What causes the "your system is too slow" warning? ------------------------------------------------------------------------------ libinput relies on the caller to call **libinput_dispatch()** whenever data is available. **libinput_dispatch()** will process the state of all devices, including some time-sensitive features (e.g. palm detection, tap-to-click, disable-while-typing, etc.). If the time between the event and the call to **libinput_dispatch()** is excessive, those features may not work correctly. For example, a delay in touch event processing may cause wrong or missing tap-to-click events or a palm may not be detected correctly. When this warning appears, it simply means that too much time has passed between the event occurring and the current time. In almost all cases this is an indication of the caller being overloaded and not handling events as speedily as required. The warning has no immediate effect on libinput's behavior but some of the functionality that relies on the timer may be impeded. This is not a bug in libinput. libinput does not control how quickly **libinput_dispatch()** is called. .. _faq_wayland: ------------------------------------------------------------------------------ Is libinput required for Wayland? ------------------------------------------------------------------------------ Technically - no. But for your use-case - probably. Wayland is a display server communication protocol. libinput is a low-level library to simplify handling input devices and their events. They have no direct connection. As a technical analogy, the question is similar to "is glibc required for HTTP", or (stretching the analogy a bit further) "Is a pen required to write English". No, it isn't. You can use libinput without a Wayland compositor, you can write a Wayland compositor without libinput. On most major distributions, libinput is the standard input stack used with the X.Org X server through the xf86-input-libinput driver. So why "for your use-case - probably"? All general-purpose Wayland compositors use libinput for their input stack. Wayland compositors that are more specialized (e.g. in-vehicle infotainment or IVI) can handle input devices directly but the compositor you want to use on your desktop needs an input stack that is more complex. And right now, libinput is the only input stack that exists for this use-case. .. _faq_separate_contexts: ------------------------------------------------------------------------------ Can I write a program to make libinput do $FOO ------------------------------------------------------------------------------ A common question is whether it's possible to write a program that can change libinput's behavior - specifically the libinput that is used inside the compositor. This indicates a misunderstanding of how libinput works: libinput is a library that converts kernel events into libinput events, much like ``sed`` reads data in, modifies it, and provides it to stdout. If ``sed`` is used by a shell-script, that script has full control over how ``sed`` processes data. In this analogy, ``sed`` is libinput and the shell script is the compositor. It is not possible to write a program to modify the behavior of the ``sed`` instance used inside that shell script Writing a program that uses libinput is akin to writing a new script that invoke ``sed``. It will not have any effect on the original ``sed`` instance. The only way to modify libinput's behavior is to use the configuration options exposed by the respective compositor. Those affect the libinput context inside the compositor and thus have an effect on the input device behavior. ------------------------------------------------------------------------------ Can I configure scroll speed? ------------------------------------------------------------------------------ No, or at least, not as a libinput option. When using a mouse, libinput notifies callers about physical scroll wheel movement. When using another device, libinput notifies scroll in scroll units. It is up to the caller to transform those events into a number of pixels to scroll and, if desired, provide a way to adjust scroll speed. This transformation cannot be done in libinput because it may depend on context only known by the caller. For example, a caller may want to scroll faster depending on how many pages a document has or depending on the widget that receives the scroll events. libinput-1.28.1/doc/user/features.rst000066400000000000000000000013701477265155700175500ustar00rootroot00000000000000.. _features: ============================================================================== libinput Features ============================================================================== Below is a list of features supported by libinput. The availability of features usually depends on the device type and a device's capabilities. Not all features are user-configurable, some rely on :ref:`device-quirks` to be useful. .. toctree:: :maxdepth: 1 button-debouncing.rst clickpad-softbuttons.rst gestures.rst middle-button-emulation.rst palm-detection.rst touchpad-thumb-detection.rst scrolling.rst t440-support.rst tapping.rst drag-3fg.rst tablet-support.rst switches.rst touchpad-pressure.rst trackpoints.rst libinput-1.28.1/doc/user/gestures.rst000066400000000000000000000425771477265155700176110ustar00rootroot00000000000000.. _gestures: ============================================================================== Gestures ============================================================================== libinput supports :ref:`gestures_pinch` and :ref:`gestures_swipe` on most modern touchpads and other indirect touch devices. Note that libinput **does not** support gestures on touchscreens, see :ref:`gestures_touchscreens`. .. _gestures_lifetime: ----------------------------------------------------------------------------- Lifetime of a gesture ----------------------------------------------------------------------------- A gesture starts when the finger position and/or finger motion is unambiguous as to what gesture to trigger and continues until the first finger belonging to this gesture is lifted. A single gesture cannot change the finger count. For example, if a user puts down a fourth finger during a three-finger swipe gesture, libinput will end (cancel) the three-finger gesture and, if applicable, start a four-finger swipe gesture. A caller may however decide that those gestures are semantically identical and continue the two gestures as one single gesture. .. _gestures_pinch: ------------------------------------------------------------------------------ Pinch gestures ------------------------------------------------------------------------------ Pinch gestures are executed when two or more fingers are located on the touchpad and are either changing the relative distance to each other (pinching) or are changing the relative angle (rotate). Pinch gestures may change both rotation and distance at the same time. For such gestures, libinput calculates a logical center for the gestures and provides the caller with the delta x/y coordinates of that center, the relative angle of the fingers compared to the previous event, and the absolute scale compared to the initial finger position. .. figure:: pinch-gestures.svg :align: center The pinch and rotate gestures The illustration above shows a basic pinch in the left image and a rotate in the right angle. Not shown is a movement of the logical center if the fingers move unevenly. Such a movement is supported by libinput, it is merely left out of the illustration. Note that while position and angle is relative to the previous event, the scale is always absolute and a multiplier of the initial finger position's scale. .. _gestures_swipe: ------------------------------------------------------------------------------ Swipe gestures ------------------------------------------------------------------------------ Swipe gestures are executed when three or more fingers are moved synchronously in the same direction. libinput provides x and y coordinates in the gesture and thus allows swipe gestures in any direction, including the tracing of complex paths. It is up to the caller to interpret the gesture into an action or limit a gesture to specific directions only. .. figure:: swipe-gestures.svg :align: center The swipe gestures The illustration above shows a vertical three-finger swipe. The coordinates provided during the gesture are the movements of the logical center. .. _gestures_hold: ------------------------------------------------------------------------------ Hold gestures ------------------------------------------------------------------------------ A hold gesture is one where the user places one or more fingers on the device without significant movement. The exact conditions when a hold gesture transitions to pointer motion, scrolling or other gestures are implementation-defined. The hold gesture is intended to allow for the implementation of two specific features: - where a two-finger scrolling starts kinetic scrolling in the caller, a subsequent hold gesture can be used to stop that kinetic scroll motion, and - hold-to-trigger interactions where the interaction could be a click, a context menu, or some other context-specific interaction. Hold gestures have three potential logical states: - **begin**: one or more fingers are placed on the device at the same time - **end**: all fingers are removed and the device enters a neutral logical state - **end(cancelled)**: all fingers are part of a known interaction and the currenthold gesture is no longer active. This may also occurs when switching between hold gestures with different finger counts. .. note:: By definition, a hold gesture does not move and thus no coordinate updates are available. For example, a user that puts one finger, then a second finger down and releases them later may trigger the following event sequence: ============= ============ ============ Action Event Finger count ============= ============ ============ Finger 1 down Finger 2 down **begin** 2 Finger 2 up **end** 2 Finger 1 up ============= ============ ============ A hold gesture may by be **cancelled**. This occurs when the hold gesture changes into some other interaction and should no longer be considered the current hold gesture. A **end(cancelled)** event applies to the whole gesture (all fingers). For example, a pointer motion on a touchpad may trigger this sequence: +-------------------+-----------------------+ | Action | Event | +===================+=======================+ | | Finger 1 down | | **hold begin** | +-------------------+-----------------------+ | | Finger 1 motion | | **hold cancel** | | | | | **pointer motion** | +-------------------+-----------------------+ | | Finger 1 motion | | **pointer motion** | +-------------------+-----------------------+ | | Finger 1 up | | *no event* | +-------------------+-----------------------+ .. note:: Many interactions with a touchpad will start with a hold gesture that is then cancelled as that gesture turns into e.g. pointer motion. A caller **must** handle hold gesture cancellations correctly. A two-finger scroll motion on a touchpad may trigger this sequence: +------------------------+---------------------+--------------+ | Action | Event | Finger count | +========================+=====================+==============+ | | Finger 1 down | | **hold begin** | | 1 | +------------------------+---------------------+--------------+ | | Finger 2 down | | **hold cancel** | | 1 | | | | | **hold begin** | | 2 | +------------------------+---------------------+--------------+ | | Finger 1+2 motion | | **hold cancel** | | 2 | | | | | **pointer axis** | | | +------------------------+---------------------+--------------+ | | Finger 1+2 motion | | **pointer axis** | | +------------------------+---------------------+--------------+ | | Finger 1 up | | **pointer axis** | | | | Finger 2 up | | (scroll stop) | | +------------------------+---------------------+--------------+ A three-finger-swipe on a touchpad may trigger this sequence: +---------------------+---------------------+--------------+ | Action | Event | Finger count | +=====================+=====================+==============+ | | Finger 1 down | | **hold begin** | | 1 | +---------------------+---------------------+--------------+ | | Finger 2 down | | **hold cancel** | | 1 | | | | | **hold begin** | | 2 | +---------------------+---------------------+--------------+ | | Finger 3 down | | **hold cancel** | | 2 | | | | | **hold begin** | | 3 | +---------------------+---------------------+--------------+ | | Finger motion | | **hold cancel** | | 3 | | | | | **swipe begin** | | 3 | +---------------------+---------------------+--------------+ | | Finger motion | | **swipe update** | | 3 | +---------------------+---------------------+--------------+ | | Finger 1 up | | **swipe end** | | 3 | | | Finger 2 up | | | | | | | Finger 3 up | | | | | +---------------------+---------------------+--------------+ Single-finger hold gestures ........................... libinput uses implementation-defined timeouts based on other interactions to determine whether a single-finger hold gestures should start. In other words, a caller **must not** rely on a hold gesture always being triggered as soon as a single finger is placed on the touchpad. This is true for any hold gesture but especially so for single-finger hold gestures. Hold gestures with a single finger are prone to being extremely short-lived. On many devices it is impossible to hold a finger still enough for there to be no pointer motion events, even if those deltas are miniscule. Changing movement thresholds to rely on hold gestures would reduce device responsiveness. It is thus the responsibility of the caller to determine where hold gestures transition in and out of other interactions. For example, a two-finger hold may produce a cancelled single-finger hold gesture first: +--------------------+----------------------+--------------+--------------+ | Action | Event | Finger count | Notes | +====================+======================+==============+==============+ | | Finger 1 down | | **hold begin** | | 1 | | +--------------------+----------------------+--------------+--------------+ | | Finger 1 motion | | **hold cancel** | | 1 | | tiny deltas| | | | | **pointer motion** | | | | | +--------------------+----------------------+--------------+--------------+ | | Finger 2 down | | **hold begin** | | 2 | | +--------------------+----------------------+--------------+--------------+ | | Finger 1 up | | **hold end** | | | | | | Finger 2 up | | | | | | +--------------------+----------------------+--------------+--------------+ Note how the second hold gesture started with a finger count of 2 - without the user ever lifting the first finger. Cancellation of hold gesture does not imply the user has lifted a finger. A hold gesture may start after a previous gesture completed. For example, a single finger move-and-hold may trigger different sequences for the same user interaction: +--------------------+---------------------+-------------------+--------------+ | Action | Device 1 | Device 2 | Notes | +====================+=====================+===================+==============+ | | Finger 1 down | | **hold begin** | | **hold begin** | | +--------------------+---------------------+-------------------+--------------+ | | Finger 1 motion | | **hold cancel** | | | tiny deltas| | | | **pointer motion**| | | | +--------------------+---------------------+-------------------+--------------+ | | | **hold begin** | | | +--------------------+---------------------+-------------------+--------------+ | | Finger 1 up | | **hold end** | | **hold end** | | +--------------------+---------------------+-------------------+--------------+ A caller that wants to use hold gestures must thus be able to infer the same interaction based on a stream of pointer motion events with small deltas. libinput may start a new hold begin gesture once the pointer stops moving. The time between the last pointer motion event and the hold begin event is implementation-defined. Hold gestures and thumb/palm detection ...................................... Thumb and palm detection effectively remove touches from being counted towards an interaction, see :ref:`thumb_detection` and :ref:`palm_detection` for details. In the context of hold gestures, thumbs and palms are treated by libinput as if the finger was removed from the device. Where other non-thumb/non-palm fingers remain on the device, an **hold update** event is sent. Otherwise, the hold gesture terminates with a **hold cancel** event. Notably, libinput's thumb and palm detection is not a simple boolean per touch but specific to the state of that touch in the overall context. For example, a touch may be a thumb for tapping but not for clickfinger interactions. A caller must not infer the number of physical fingers from the hold gesture. Likewise, libinput may classify a finger as thumb in the same hardware event as a new finger is placed on the touchpad. In that case, the hold gesture **may** continue as one-finger gesture despite there being two physical touch points. Information to determine whether a touch is a thumb or a palm may not be available until some time into an interaction. Thus very short brushes of the touchpad by a palm may trigger a **hold begin** followed by an immediate **hold end** as libinput lacks sufficient information to identify the touch as thumb/palm and send the corresponding **hold cancel** event. A caller must not assume that a hold gesture always represents a valid finger down. Hold gestures and tap-to-click .............................. :ref:`tapping` is the feature that enables short-lived touches to trigger button presses. .. warning:: Summary: do not use hold gestures to do your own tap-to-click implementation In the context of hold gestures, tap-to-click cancels current hold gestures and a finger dragging (see :ref:`tapndrag`) does not begin a hold gesture. Where tap-to-click is disabled a tap-like gesture may create **hold begin** followed by a **hold end** event. Callers **must not** use hold gestures for their own tap-to-click implementation as the data is not reliable enough. libinput may change internal timeouts and thresholds depending on whether tap-to-click is enabled and the hold gesture event may not match touch sequences that a user would expect to be a tap-to-click interaction. .. _gestures_touchscreens: ------------------------------------------------------------------------------ Touchscreen gestures ------------------------------------------------------------------------------ Touchscreen gestures are **not** interpreted by libinput. Rather, any touch point is passed to the caller and any interpretation of gestures is up to the caller or, eventually, the X or Wayland client. Interpreting gestures on a touchscreen requires context that libinput does not have, such as the location of windows and other virtual objects on the screen as well as the context of those virtual objects: .. figure:: touchscreen-gestures.svg :align: center Context-sensitivity of touchscreen gestures In the above example, the finger movements are identical but in the left case both fingers are located within the same window, thus suggesting an attempt to zoom. In the right case both fingers are located on a window border, thus suggesting a window movement. libinput has no knowledge of the window coordinates and thus cannot differentiate the two. .. _gestures_softbuttons: ------------------------------------------------------------------------------ Gestures with enabled software buttons ------------------------------------------------------------------------------ If the touchpad device is a :ref:`Clickpad `, it is recommended that a caller switches to :ref:`clickfinger`. Usually fingers placed in a :ref:`software button area ` are not considered for gestures, resulting in some gestures to be interpreted as pointer motion or two-finger scroll events. .. figure:: pinch-gestures-softbuttons.svg :align: center Interference of software buttons and pinch gestures In the example above, the software button area is highlighted in red. The user executes a three-finger pinch gesture, with the thumb remaining in the software button area. libinput ignores fingers within the software button areas, the movement of the remaining fingers is thus interpreted as a two-finger scroll motion. .. _gestures_twofinger_touchpads: ------------------------------------------------------------------------------ Gestures on two-finger touchpads ------------------------------------------------------------------------------ As of kernel 4.2, many :ref:`touchpads_touch_partial_mt` provide only two slots. This affects how gestures can be interpreted. Touchpads with only two slots can identify two touches by position but can usually tell that there is a third (or fourth) finger down on the touchpad - without providing positional information for that finger. Touchpoints are assigned in sequential order and only the first two touch points are trackable. For libinput this produces an ambiguity where it is impossible to detect whether a gesture is a pinch gesture or a swipe gesture whenever a user puts the index and middle finger down first. Since the third finger does not have positional information, it's location cannot be determined. .. figure:: gesture-2fg-ambiguity.svg :align: center Ambiguity of three-finger gestures on two-finger touchpads The image above illustrates this ambiguity. The index and middle finger are set down first, the data stream from both finger positions looks identical. In this case, libinput assumes the fingers are in a horizontal arrangement (the right image above) and use a swipe gesture. libinput-1.28.1/doc/user/git_version.py.in000066400000000000000000000001541477265155700205060ustar00rootroot00000000000000def get_git_version(): return "__GIT_VERSION__"[:7] def get_git_version_full(): return "__GIT_VERSION__" libinput-1.28.1/doc/user/ignoring-devices.rst000066400000000000000000000032211477265155700211630ustar00rootroot00000000000000.. _ignoring_devices: ============================================================================== Ignoring specific devices ============================================================================== If a device has the **LIBINPUT_IGNORE_DEVICE** udev property set to any value but "0", that device is not initialized by libinput. For a context created with **libinput_udev_create_context()**, the device is silently ignored and never shows up. If the device is added with **libinput_path_add_device()** to a context created with **libinput_path_create_context()**, adding the device will fail and return NULL (see that function's documentation for more information). If the property value is exactly "0", then the property is considered unset and libinput initializes the device normally. This property should be used for devices that are correctly detected as input devices (see :ref:`udev_device_type`) but that should not be used by libinput. It is recommended that devices that should not be handled as input devices at all unset the **ID_INPUT** and related properties instead. The **LIBINPUT_IGNORE_DEVICE** property signals that only libinput should ignore this property but other parts of the stack (if any) should continue treating this device normally. Below is an example udev rule to assign **LIBINPUT_IGNORE_DEVICE** to the device with the vendor/model ID of ``012a``/``034b``. :: $ cat /etc/udev/rules.d/99-ignore-my-device.rules ACTION!="remove", KERNEL=="event[0-9]*", \ ENV{ID_VENDOR_ID}=="012a", \ ENV{ID_MODEL_ID}=="034b", \ ENV{LIBINPUT_IGNORE_DEVICE}="1" See :ref:`udev_config` for more details on libinput's udev properties. libinput-1.28.1/doc/user/incorrectly-enabled-hires.rst000066400000000000000000000047371477265155700230010ustar00rootroot00000000000000.. _incorrectly_enabled_hires: ============================================================================== Incorrectly enabled high-resolution scroll ============================================================================== Some devices might announce support for high-resolution scroll wheel by enabling ``REL_WHEEL_HI_RES`` and/or ``REL_HWHEEL_HI_RES`` but never send a high-resolution scroll event. When the first low-resolution scroll event is received without any previous high-resolution event, libinput prints a bug warning with the text **"device supports high-resolution scroll but only low-resolution events have been received"** and a link to this page. .. note:: This warning will be printed only once In most cases this is a bug on the device firmware, the kernel driver or in a software used to create user-space devices through uinput. Once the bug is detected, libinput will start emulating high-resolution scroll events. ------------------------------------------------------------------------------ Detecting and fixing the issue ------------------------------------------------------------------------------ Events sent by a buggy device can be shown in the :ref:`libinput record ` output for the device. Notice that ``REL_WHEEL_HI_RES`` and ``REL_HWHEEL_HI_RES`` are set but only ``REL_WHEEL`` events are sent: :: # Supported Events: # Event type 0 (EV_SYN) # Event type 1 (EV_KEY) # Event code 272 (BTN_LEFT) # Event type 2 (EV_REL) # Event code 0 (REL_X) # Event code 1 (REL_Y) # Event code 6 (REL_HWHEEL) # Event code 8 (REL_WHEEL) # Event code 11 (REL_WHEEL_HI_RES) # Event code 12 (REL_HWHEEL_HI_RES) [...] quirks: events: - evdev: - [ 0, 0, 2, 8, 1] # EV_REL / REL_WHEEL 1 - [ 0, 0, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +0ms - evdev: - [ 0, 15126, 2, 8, 1] # EV_REL / REL_WHEEL 1 - [ 0, 15126, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +15ms - evdev: - [ 0, 30250, 2, 8, 1] # EV_REL / REL_WHEEL 1 - [ 0, 30250, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +15ms The issue can be fixed by adding a quirk to unset the ``REL_WHEEL_HI_RES`` and ``REL_HWHEEL_HI_RES`` event codes: :: AttrEventCode=-REL_WHEEL_HI_RES;-REL_HWHEEL_HI_RES; Please see :ref:`device-quirks` for details. libinput-1.28.1/doc/user/index.rst000066400000000000000000000041251477265155700170420ustar00rootroot00000000000000 .. toctree:: :maxdepth: 2 :hidden: what-is-libinput features configuration building faqs reporting-bugs troubleshooting contributing development API documentation <@HTTP_DOC_LINK@/api/> ++++++++++++++++++++++++++++++ libinput ++++++++++++++++++++++++++++++ libinput is a library that provides a full input stack for display servers and other applications that need to handle input devices provided by the kernel. libinput provides device detection, event handling and abstraction so minimize the amount of custom input code the user of libinput need to provide the common set of functionality that users expect. Input event processing includes scaling touch coordinates, generating relative pointer events from touchpads, pointer acceleration, etc. libinput is not used directly by applications. Think of it more as a device driver than an application library. See :ref:`what_is_libinput` for more details. -------------------- Users and Developers -------------------- Please use the side-bar to nagivate through the various documentation items. ----------------- API documentation ----------------- The API documentation is available here: https://wayland.freedesktop.org/libinput/doc/latest/api/ .. note:: This documentation is generally only needed by authors of Wayland compositors or other developers dealing with input events directly. ------- License ------- libinput is licensed under the MIT license .. code-block:: none Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: [...] See the `COPYING `_ file for the full license information. ..... About ..... Documentation generated from |git_version| libinput-1.28.1/doc/user/meson.build000066400000000000000000000161041477265155700173430ustar00rootroot00000000000000# Sphinx build sphinx = find_program('sphinx-build-3', 'sphinx-build', required : false) if not sphinx.found() error('Program "sphinx-build" not found or not executable. Try building with -Ddocumentation=false') endif yq = find_program('yq', required : false) if not yq.found() warning('Program "yq" not found or not executable. Dependency list will not be built.') endif sphinx_config = configuration_data() sphinx_config.set('PROJECT_NAME', meson.project_name()) sphinx_config.set('PROJECT_VERSION', meson.project_version()) sphinx_config.set('BUILDDIR', meson.current_build_dir()) sphinx_config.set('HTTP_DOC_LINK', doc_url) git_version_page = vcs_tag(command : ['git', 'log', '-1', '--format=%H'], fallback : 'unknown', input : 'git_version.py.in', output : 'git_version.py', replace_string: '__GIT_VERSION__') sphinx_conf_py = configure_file(input : 'conf.py.in', output : 'conf.py', configuration : sphinx_config) # 404 replacements for old URLs # The switch to sphinx caused a few pages to be renamed, sphinx uses # filename.html whereas doxygen used whatever the @page foo was. So old docs # *mostly* used underscores, now we're consistent with dashes. # We can't use htaccess on the server, so let's auto-generate a 404 list # with a basic page telling users that the link has moved. This can be # removed in a few months, towards the end of 2018. # # File list is: [current-sphinx-input-file, old-generated-page] # If they're the same they'll be ignored. src_404s = [ [ 'absolute-axes.rst', 'absolute_axes.html'], [ 'absolute-coordinate-ranges.rst', 'absolute_coordinate_ranges.html'], [ 'architecture.rst', 'architecture.html'], [ 'building.rst', 'building_libinput.html'], [ 'button-debouncing.rst', 'button_debouncing.html'], [ 'clickpad-softbuttons.rst', 'clickpad_softbuttons.html'], [ 'configuration.rst', 'config_options.html'], [ 'contributing.rst', 'contributing.html'], [ 'development.rst', 'development.html'], [ 'device-configuration-via-udev.rst', 'udev_config.html'], [ 'device-quirks.rst', 'device-quirks.html'], [ 'faqs.rst', 'faq.html'], [ 'features.rst', 'features.html'], [ 'gestures.rst', 'gestures.html'], [ 'incorrectly-enabled-hires.rst', 'incorrectly-enabled-hires.html'], [ 'middle-button-emulation.rst', 'middle_button_emulation.html'], [ 'normalization-of-relative-motion.rst', 'motion_normalization.html'], [ 'palm-detection.rst', 'palm_detection.html'], [ 'pointer-acceleration.rst', 'pointer-acceleration.html'], [ 'reporting-bugs.rst', 'reporting_bugs.html'], [ 'scrolling.rst', 'scrolling.html'], [ 'seats.rst', 'seats.html'], [ 'switches.rst', 'switches.html'], [ 't440-support.rst', 't440_support.html'], [ 'tablet-support.rst', 'tablet-support.html'], [ 'tapping.rst', 'tapping.html'], [ 'test-suite.rst', 'test-suite.html'], [ 'timestamps.rst', 'timestamps.html'], [ 'tools.rst', 'tools.html'], [ 'touchpad-jitter.rst', 'touchpad_jitter.html'], [ 'touchpad-jumping-cursors.rst', 'touchpad_jumping_cursor.html'], [ 'touchpad-pressure.rst', 'touchpad_pressure.html'], [ 'touchpads.rst', 'touchpads.html'], [ 'trackpoints.rst', 'trackpoints.html'], [ 'troubleshooting.rst', 'troubleshooting.html'], [ 'what-is-libinput.rst', 'what_is_libinput.html'], ] dst_404s = [] foreach s404 : src_404s target = s404[0] oldpage = s404[1] tname = target.split('.rst')[0] oname = oldpage.split('.html')[0] if tname != oname config_404 = configuration_data() config_404.set('TARGET', '@0@.html'.format(tname)) c = configure_file(input : '404.rst', output : '@0@.rst'.format(oname), configuration : config_404) dst_404s += [c] endif endforeach src_rst = files( # dot drawings 'dot/seats-sketch.gv', 'dot/seats-sketch-libinput.gv', 'dot/libinput-stack-wayland.gv', 'dot/libinput-stack-xorg.gv', 'dot/libinput-stack-gnome.gv', 'dot/evemu.gv', 'dot/libinput-record.gv', # svgs 'svg/button-debouncing-wave-diagram.svg', 'svg/button-scrolling.svg', 'svg/clickfinger.svg', 'svg/clickfinger-distance.svg', 'svg/edge-scrolling.svg', 'svg/gesture-2fg-ambiguity.svg', 'svg/palm-detection.svg', 'svg/pinch-gestures.svg', 'svg/pinch-gestures-softbuttons.svg', 'svg/ptraccel-custom.svg', 'svg/ptraccel-linear.svg', 'svg/ptraccel-low-dpi.svg', 'svg/ptraccel-touchpad.svg', 'svg/ptraccel-trackpoint.svg', 'svg/software-buttons.svg', 'svg/software-buttons-conditions.svg', 'svg/software-buttons-thumbpress.svg', 'svg/software-buttons-visualized.svg', 'svg/swipe-gestures.svg', 'svg/tablet-area.svg', 'svg/tablet-axes.svg', 'svg/tablet-cintiq24hd-modes.svg', 'svg/tablet-interfaces.svg', 'svg/tablet-intuos-modes.svg', 'svg/tablet-left-handed.svg', 'svg/tablet-out-of-bounds.svg', 'svg/tablet.svg', 'svg/tap-n-drag.svg', 'svg/thumb-detection.svg', 'svg/top-software-buttons.svg', 'svg/touchscreen-gestures.svg', 'svg/trackpoint-delta-illustration.svg', 'svg/twofinger-scrolling.svg', # rst files 'absolute-axes.rst', 'absolute-coordinate-ranges.rst', 'architecture.rst', 'building.rst', 'button-debouncing.rst', 'clickpad-softbuttons.rst', 'clickpad-with-right-button.rst', 'contributing.rst', 'device-configuration-via-udev.rst', 'device-quirks.rst', 'drag-3fg.rst', 'faqs.rst', 'gestures.rst', 'incorrectly-enabled-hires.rst', 'ignoring-devices.rst', 'middle-button-emulation.rst', 'normalization-of-relative-motion.rst', 'palm-detection.rst', 'pointer-acceleration.rst', 'reporting-bugs.rst', 'scrolling.rst', 'seats.rst', 'switches.rst', 't440-support.rst', 'tablet-support.rst', 'tapping.rst', 'test-suite.rst', 'timestamps.rst', 'tablet-debugging.rst', 'tools.rst', 'touchpad-jumping-cursors.rst', 'touchpad-pressure.rst', 'touchpad-pressure-debugging.rst', 'touchpad-jitter.rst', 'touchpad-thumb-detection.rst', 'touchpads.rst', 'trackpoints.rst', 'trackpoint-configuration.rst', 'what-is-libinput.rst', 'wheel-api.rst', 'features.rst', 'development.rst', 'troubleshooting.rst', 'configuration.rst', ) src_sphinx = [] foreach f : src_rst sf = configure_file(input: f, output: '@PLAINNAME@', copy : true) src_sphinx += [ sf ] endforeach configure_file(input: 'index.rst', output: 'index.rst', configuration: sphinx_config) dependencies_config = configuration_data() if yq.found() distributions = ['fedora', 'ubuntu', 'debian', 'arch', 'alpine'] foreach distro : distributions yq_filter = '.distributions[] | select(.name == "@0@") | .packages | join(" ")'.format(distro) deps = run_command(yq, '-r', yq_filter, dir_gitlab_ci / 'config.yml', check: true).stdout() dependencies_config.set('@0@_PACKAGES'.format(distro.to_upper()), deps) endforeach endif configure_file(input: 'dependencies.rst', output: 'dependencies.rst', configuration: dependencies_config) # do not use -j, it breaks on Ubuntu sphinx_output_dir = 'Documentation' custom_target('sphinx', input : [ sphinx_conf_py, git_version_page ] + src_sphinx + dst_404s, output : [ sphinx_output_dir ], command : [ sphinx, '-q', '-b', 'html', '-d', meson.current_build_dir() / 'doctrees', meson.current_build_dir(), sphinx_output_dir], build_by_default : true) libinput-1.28.1/doc/user/middle-button-emulation.rst000066400000000000000000000034541477265155700225010ustar00rootroot00000000000000.. _middle_button_emulation: ============================================================================== Middle button emulation ============================================================================== Middle button emulation provides users with the ability to generate a middle click even when the device does not have a physical middle button available. When middle button emulation is enabled, a simultaneous press of the left and right button generates a middle mouse button event. Releasing the buttons generates a middle mouse button release, the left and right button events are discarded otherwise. The middle button release event may be generated when either button is released, or when both buttons have been released. The exact behavior is device-dependent, libinput will implement the behavior that is most appropriate to the physical device. The middle button emulation behavior when combined with other device buttons, including a physical middle button is device-dependent. For example, :ref:`clickpad_softbuttons` provides a middle button area when middle button emulation is disabled. That middle button area disappears when middle button emulation is enabled - a middle click can then only be triggered by a simultaneous left + right click. Some devices provide middle mouse button emulation but do not allow enabling/disabling that emulation. Likewise, some devices may allow middle button emulation but have it disabled by default. This is the case for most mouse-like devices where a middle button is detected. libinput provides **libinput_device_config_middle_emulation_set_enabled()** to enable or disable middle button emulation. See :ref:`faq_configure_wayland` and :ref:`faq_configure_xorg` for info on how to enable or disable middle button emulation in the Wayland compositor or the X stack. libinput-1.28.1/doc/user/normalization-of-relative-motion.rst000066400000000000000000000101351477265155700243350ustar00rootroot00000000000000.. _motion_normalization: ============================================================================== Normalization of relative motion ============================================================================== Most relative input devices generate input in so-called "mickeys". A mickey is in device-specific units that depend on the resolution of the sensor. Most optical mice use sensors with 1000dpi resolution, but some devices range from 100dpi to well above 8000dpi. Without a physical reference point, a relative coordinate cannot be interpreted correctly. A delta of 10 mickeys may be a millimeter of physical movement or 10 millimeters, depending on the sensor. This affects pointer acceleration in libinput and interpretation of relative coordinates in callers. libinput does partial normalization of relative input. For devices with a resolution of 1000dpi and higher, motion events are normalized to a default of 1000dpi before pointer acceleration is applied. As a result, devices with 1000dpi and above feel the same. Devices below 1000dpi are not normalized (normalization of a 1-device unit movement on a 400dpi mouse would cause a 2.5 pixel movement). Instead, libinput applies a dpi-dependent acceleration function. At low speeds, a 1-device unit movement usually translates into a 1-pixel movements. As the movement speed increases, acceleration is applied - at high speeds a low-dpi device will roughly feel the same as a higher-dpi mouse. The reason for the normalization is convenience: a caller can assume that a delta of 1 should result in a movement of 1 pixel on a traditional (low-dpi) screen. On screens with high resolutions, the caller must scale according to the UI scale factors. This normalization only applies to accelerated coordinates, unaccelerated coordinates are left in device-units. It is up to the caller to interpret those coordinates correctly. .. _motion_normalization_touchpad: ------------------------------------------------------------------------------ Normalization of touchpad coordinates ------------------------------------------------------------------------------ Touchpads may have a different resolution for the horizontal and vertical axis. Interpreting coordinates from the touchpad without taking resolution into account results in uneven motion. libinput scales unaccelerated touchpad motion to the resolution of the touchpad's x axis, i.e. the unaccelerated value for the y axis is: ``y = (x / resolution_x) * resolution_y``. .. _motion_normalization_tablet: ------------------------------------------------------------------------------ Normalization of tablet coordinates ------------------------------------------------------------------------------ See :ref:`tablet-relative-motion` .. _motion_normalization_customization: ------------------------------------------------------------------------------ Setting custom DPI settings ------------------------------------------------------------------------------ Devices usually do not advertise their resolution and libinput relies on the udev property **MOUSE_DPI** for this information. This property is usually set via the `udev hwdb `_. The ``mouse-dpi-tool`` utility provided by `libevdev `_ should be used to measure a device's resolution. The format of the property for single-resolution mice is: :: MOUSE_DPI=resolution@frequency The resolution is in dots per inch, the frequency in Hz. The format of the property for multi-resolution mice may list multiple resolutions and frequencies: :: MOUSE_DPI=r1@f1 *r2@f2 r3@f3 The default frequency must be pre-fixed with an asterisk. For example, these two properties are valid: :: MOUSE_DPI=800@125 MOUSE_DPI=400@125 800@125 *1000@500 5500@500 The behavior for a malformed property is undefined. If the property is unset, libinput assumes the resolution is 1000dpi. Note that HW does not usually provide information about run-time resolution changes, libinput will thus not detect when a resolution changes to the non-default value. libinput-1.28.1/doc/user/palm-detection.rst000066400000000000000000000236461477265155700206510ustar00rootroot00000000000000.. _palm_detection: ============================================================================== Palm detection ============================================================================== Palm detection tries to identify accidental touches while typing, while using the trackpoint and/or during general use of the touchpad area. On most laptops typing on the keyboard generates accidental touches on the touchpad with the palm (usually the area below the thumb). This can lead to cursor jumps or accidental clicks. On large touchpads, the palm may also touch the bottom edges of the touchpad during normal interaction. Interference from a palm depends on the size of the touchpad and the position of the user's hand. Data from touchpads showed that almost all palm events during tying on a Lenovo T440 happened in the left-most and right-most 5% of the touchpad. The T440 series has one of the largest touchpads, other touchpads are less affected by palm touches. libinput has multiple ways of detecting a palm, each of which depends on hardware-specific capabilities. - :ref:`palm_tool` - :ref:`palm_pressure` - :ref:`palm_touch_size` - :ref:`palm_exclusion_zones` - :ref:`trackpoint-disabling` - :ref:`disable-while-typing` - :ref:`disable-while-trackpointing` - :ref:`stylus-touch-arbitration` Palm detection is always enabled, with the exception of disable-while-typing. .. _palm_tool: ------------------------------------------------------------------------------ Palm detection based on firmware labelling ------------------------------------------------------------------------------ Some devices provide palm detection in the firmware, forwarded by the kernel as the ``EV_ABS/ABS_MT_TOOL`` axis with a value of ``MT_TOOL_PALM`` (whenever a palm is detected). libinput honors that value and switches that touch to a palm. .. _palm_pressure: ------------------------------------------------------------------------------ Palm detection based on pressure ------------------------------------------------------------------------------ The simplest form of palm detection labels a touch as palm when the pressure value goes above a certain threshold. This threshold is usually high enough that it cannot be triggered by a finger movement. One a touch is labelled as palm based on pressure, it will remain so even if the pressure drops below the threshold again. This ensures that a palm remains a palm even when the pressure changes as the user is typing. For some information on how to detect pressure on a touch and debug the pressure ranges, see :ref:`touchpad_pressure`. .. _palm_touch_size: ------------------------------------------------------------------------------ Palm detection based on touch size ------------------------------------------------------------------------------ On touchpads that support the ``ABS_MT_TOUCH_MAJOR`` axes, libinput can perform palm detection based on the size of the touch ellipse. This works similar to the pressure-based palm detection in that a touch is labelled as palm when it exceeds the (device-specific) touch size threshold. For some information on how to detect the size of a touch and debug the touch size ranges, see :ref:`touchpad_pressure`. .. _palm_exclusion_zones: ------------------------------------------------------------------------------ Palm exclusion zones ------------------------------------------------------------------------------ libinput enables palm detection on the left, right and top edges of the touchpad. Two exclusion zones are defined on the left and right edge of the touchpad. If a touch starts in the exclusion zone, it is considered a palm and the touch point is ignored. However, for fast cursor movements across the screen, it is common for a finger to start inside an exclusion zone and move rapidly across the touchpad. libinput detects such movements and avoids palm detection on such touch sequences. Another exclusion zone is defined on the top edge of the touchpad. As with the edge zones, libinput detects vertical movements out of the edge zone and avoids palm detection on such touch sequences. A touch starting in the exclusion zone does not trigger a tap (see :ref:`tapping`). In the diagram below, the exclusion zones are painted red. Touch 'A' starts inside the exclusion zone and moves almost vertically. It is considered a palm and ignored for cursor movement, despite moving out of the exclusion zone. Touch 'B' starts inside the exclusion zone but moves horizontally out of the zone. It is considered a valid touch and controls the cursor. Touch 'C' occurs in the exclusion zone. Despite being a tapping motion, it does not generate an emulated button event. .. figure:: palm-detection.svg :align: center .. _trackpoint-disabling: ------------------------------------------------------------------------------ Palm detection during trackpoint use ------------------------------------------------------------------------------ If a device provides a `trackpoint `_, it is usually located above the touchpad. This increases the likelihood of accidental touches whenever the trackpoint is used. libinput disables the touchpad whenever it detects trackpoint activity for a certain timeout until after trackpoint activity stops. Touches generated during this timeout will not move the pointer, and touches started during this timeout will likewise not move the pointer (allowing for a user to rest the palm on the touchpad while using the trackstick). If the touchpad is disabled, the :ref:`top software buttons ` remain enabled. .. _disable-while-typing: ------------------------------------------------------------------------------ Disable-while-typing ------------------------------------------------------------------------------ libinput automatically disables the touchpad for a timeout after a key press, a feature traditionally referred to as "disable while typing" and previously available through the `syndaemon(1) `_ command. libinput does not require an external command and the feature is currently enabled for all touchpads but will be reduced in the future to only apply to touchpads where finger width or pressure data is unreliable. Notable behaviors of libinput's disable-while-typing feature: - Two different timeouts are used, after a single key press the timeout is short to ensure responsiveness. After multiple key events, the timeout is longer to avoid accidental pointer manipulation while typing. - Some keys do not trigger the timeout, specifically some modifier keys (Ctrl, Alt, Shift, and Fn). Actions such as Ctrl + click thus stay responsive. - Touches started while typing do not control the cursor even after typing has stopped, it is thus possible to rest the palm on the touchpad while typing. - Physical buttons work even while the touchpad is disabled. This includes :ref:`software-emulated buttons `. - libinput pairs touchpads and keyboards for the disable-while-typing feature. In the most common case, the internal touchpad is paired only with the internal keyboard. Typing on an external keyboard will thus not disable the touchpad. Some devices require a :ref:`quirk ` to be correctly paired. Disable-while-typing can be enabled and disabled by calling **libinput_device_config_dwt_set_enabled()**. .. _disable-while-trackpointing: ------------------------------------------------------------------------------ Disable-while-trackpointing ------------------------------------------------------------------------------ libinput automatically disables the touchpad for a timeout after the trackpoint is moved, a feature referred to as "disable while trackpointing". libinput does not require an external command and the feature is currently enabled for all touchpads. Disable-while-trackpointing can be enabled and disabled by calling **libinput_device_config_dwtp_set_enabled()**. .. _stylus-touch-arbitration: ------------------------------------------------------------------------------ Stylus-touch arbitration ------------------------------------------------------------------------------ A special case of palm detection is touch arbitration on devices that support styli. When interacting with a stylus on the screen, parts of the hand may touch the surface and trigger touches. As the user is currently interacting with the stylus, these touches would interfer with the correct working of the stylus. libinput employs a method similar to :ref:`disable-while-typing` to detect these touches and disables the touchpad accordingly. .. _thumb-detection: ------------------------------------------------------------------------------ Thumb detection ------------------------------------------------------------------------------ Many users rest their thumb on the touchpad while using the index finger to move the finger around. For clicks, often the thumb is used rather than the finger. The thumb should otherwise be ignored as a touch, i.e. it should not count towards :ref:`clickfinger` and it should not cause a single-finger movement to trigger :ref:`twofinger_scrolling`. libinput uses two triggers for thumb detection: pressure and location. A touch exceeding a pressure threshold is considered a thumb if it is within the thumb detection zone. .. note:: "Pressure" on touchpads is synonymous with "contact area." A large touch surface area has a higher pressure and thus hints at a thumb or palm touching the surface. Pressure readings are unreliable at the far bottom of the touchpad as a thumb hanging mostly off the touchpad will have a small surface area. libinput has a definitive thumb zone where any touch is considered a resting thumb. .. figure:: thumb-detection.svg :align: center The picture above shows the two detection areas. In the larger (light red) area, a touch is labelled as thumb when it exceeds a device-specific pressure threshold. In the lower (dark red) area, a touch is labelled as thumb if it remains in that area for a time without moving outside. libinput-1.28.1/doc/user/pointer-acceleration.rst000066400000000000000000000323631477265155700220470ustar00rootroot00000000000000.. _pointer-acceleration: ============================================================================== Pointer acceleration ============================================================================== libinput uses device-specific pointer acceleration methods, with the default being the :ref:`ptraccel-linear`. The methods share common properties, such as :ref:`ptraccel-velocity`. This page explains the high-level concepts used in the code. It aims to provide an overview for developers and is not necessarily useful for users. .. _ptraccel-profiles: ------------------------------------------------------------------------------ Pointer acceleration profiles ------------------------------------------------------------------------------ The profile decides the general method of pointer acceleration. libinput currently supports three profiles: **"adaptive"**, **"flat"** and **"custom"**. - The **adaptive** profile is the default profile for all devices and takes the current speed of the device into account when deciding on acceleration. - The **flat** profile is simply a constant factor applied to all device deltas, regardless of the speed of motion (see :ref:`ptraccel-profile-flat`). - The **custom** profile allows the user to define a custom acceleration function, giving full control over accelerations behavior at different speed (see :ref:`ptraccel-profile-custom`). Most of this document describes the adaptive pointer acceleration. .. _ptraccel-velocity: ------------------------------------------------------------------------------ Velocity calculation ------------------------------------------------------------------------------ The device's speed of movement is measured across multiple input events through so-called "trackers". Each event prepends a the tracker item, each subsequent tracker contains the delta of that item to the current position, the timestamp of the event that created it and the cardinal direction of the movement at the time. If a device moves into the same direction, the velocity is calculated across multiple trackers. For example, if a device moves steadily for 10 events to the left, the velocity is calculated across all 10 events. Whenever the movement changes direction or significantly changes speed, the velocity is calculated from the direction/speed change only. For example, if a device moves steadily for 8 events to the left and then 2 events to the right, the velocity is only that of the last 2 events. An extra time limit prevents events that are too old to factor into the velocity calculation. For example, if a device moves steadily for 5 events to the left, then pauses, then moves again for 5 events to the left, only the last 5 events are used for velocity calculation. The velocity is then used to calculate the acceleration factor .. _ptraccel-factor: ------------------------------------------------------------------------------ Acceleration factor ------------------------------------------------------------------------------ The acceleration factor is the final outcome of the pointer acceleration calculations. It is a unitless factor that is applied to the current delta, a factor of 2 doubles the delta (i.e. speeds up the movement), a factor of less than 1 reduces the delta (i.e. slows the movement). Any factor less than 1 requires the user to move the device further to move the visible pointer. This is called deceleration and enables high precision target selection through subpixel movements. libinput's current maximum deceleration factor is 0.3 (i.e. slow down to 30% of the pointer speed). A factor higher than 1 moves the pointer further than the physical device moves. This is acceleration and allows a user to cross the screen quickly but effectively skips pixels. libinput's current maximum acceleration factor is 3.5. .. _ptraccel-linear: ------------------------------------------------------------------------------ Linear pointer acceleration ------------------------------------------------------------------------------ The linear pointer acceleration method is the default for most pointer devices. It provides deceleration at very slow movements, a 1:1 mapping for regular movements and a linear increase to the maximum acceleration factor for fast movements. Linear pointer acceleration applies to devices with above 1000dpi resolution and after :ref:`motion_normalization` is applied. .. figure:: ptraccel-linear.svg :align: center Linear pointer acceleration The image above shows the linear pointer acceleration settings at various speeds. The line for 0.0 is the default acceleration curve, speed settings above 0.0 accelerate sooner, faster and to a higher maximum acceleration. Speed settings below 0 delay when acceleration kicks in, how soon the maximum acceleration is reached and the maximum acceleration factor. Extremely low speed settings provide no acceleration and additionally decelerate all movement by a constant factor. .. _ptraccel-low-dpi: ------------------------------------------------------------------------------ Pointer acceleration for low-dpi devices ------------------------------------------------------------------------------ Low-dpi devices are those with a physical resolution of less than 1000 dots per inch (dpi). The pointer acceleration is adjusted to provide roughly the same feel for all devices at normal to high speeds. At slow speeds, the pointer acceleration works on device-units rather than normalized coordinates (see :ref:`motion_normalization`). .. figure:: ptraccel-low-dpi.svg :align: center Pointer acceleration for low-dpi devices The image above shows the default pointer acceleration curve for a speed of 0.0 at different DPI settings. A device with low DPI has the acceleration applied sooner and with a stronger acceleration factor. .. _ptraccel-touchpad: ------------------------------------------------------------------------------ Pointer acceleration on touchpads ------------------------------------------------------------------------------ Touchpad pointer acceleration uses the same approach as the :ref:`ptraccel-linear` profile, with a constant deceleration factor applied. The user expectation of how much a pointer should move in response to finger movement is different to that of a mouse device, hence the constant deceleration factor. .. figure:: ptraccel-touchpad.svg :align: center Pointer acceleration curve for touchpads The image above shows the touchpad acceleration profile in comparison to the :ref:`ptraccel-linear`. The shape of the curve is identical but vertically squashed. .. _ptraccel-trackpoint: ------------------------------------------------------------------------------ Pointer acceleration on trackpoints ------------------------------------------------------------------------------ The main difference between trackpoint hardware and mice or touchpads is that trackpoint speed is a function of pressure rather than moving speed. But trackpoint hardware is quite varied in how it reacts to user pressure and unlike other devices it cannot easily be normalized for physical properties. Measuring pressure objectively across a variety of hardware is nontrivial. See :ref:`trackpoints` for more details. The deltas for trackpoints are converted units/ms but there is no common physical reference point for a unit. Thus, the same pressure on different trackpoints will generate different speeds and thus different acceleration behaviors. Additionally, some trackpoints provide the ability to adjust the sensitivity in hardware by modifying a sysfs file on the serio node. A higher sensitivity results in higher deltas, thus changing the definition of what is a unit again. libinput attempts to normalize unit data to the best of its abilities, see :ref:`trackpoint_multiplier`. Beyond this, it is not possible to have consistent behavior across different trackpoint devices. .. figure:: ptraccel-trackpoint.svg :align: center Pointer acceleration curves for trackpoints The image above shows the trackpoint acceleration profile for the speed in units/ms. .. _ptraccel-profile-flat: ------------------------------------------------------------------------------ The flat pointer acceleration profile ------------------------------------------------------------------------------ In a flat profile, the acceleration factor is constant regardless of the velocity of the pointer and each delta (dx, dy) results in an accelerated delta (dx * factor, dy * factor). This provides 1:1 movement between the device and the pointer on-screen. .. _ptraccel-tablet: ------------------------------------------------------------------------------ Pointer acceleration on tablets ------------------------------------------------------------------------------ Pointer acceleration for relative motion on tablet devices is a flat acceleration, with the speed setting slowing down or speeding up the pointer motion by a constant factor. Tablets do not allow for switchable profiles. .. _ptraccel-profile-custom: ------------------------------------------------------------------------------ The custom acceleration profile ------------------------------------------------------------------------------ libinput supports a user-defined custom acceleration profile, which can be adjusted for different movement types supported by a device. Movement types include pointer movement, scrolling, etc. but the set of supported movement types depends on the device. The custom pointer acceleration profile gives users full control over the acceleration behavior at different speeds. libinput exposes an acceleration function ``f(x)`` where the x axis is the device speed in device units per millisecond and the y axis is the pointer speed. By supplying the y axis values for this function, users can control the behavior of the device. The user should take into account the native device dpi and screen dpi in order to achieve the desired behavior/feel. The custom acceleration function is defined using ``n`` points which are spaced uniformly along the x axis, starting from 0 and continuing in constant steps. At least two points must be defined and there is an implementation-defined limit on how many points may be added. Thus the points defining the custom function are: ``(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])`` where ``f`` is a list of ``n`` values defining the output velocity for each input velocity. The acceleration factor is defined by the ratio of the output velocity to the input velocity. When a velocity value does not lie exactly on those points, a linear interpolation of the two closest points will be calculated. When a velocity value is greater than the max point defined, a linear extrapolation of the two biggest points will be calculated. the calculation made by libinput: :: input_delta = device delta units delta_time = time in ms since last input_delta input_speed = hypot(input_delta) / delta_time output_speed = user_custom_function(input_speed) acceleration_factor = output_speed / input_speed output_delta = input_delta * acceleration_factor An example is the curve of ``0.0, 1.0`` with a step of ``1.0``. This curve is the equivalent of the flat acceleration profile with any input speed ``N`` mapped to the same pointer speed ``N``. The curve ``1.0, 1.0`` neutralizes any input speed differences and results in a fixed pointer speed. Another example is the custom acceleration function ``x**2``, sampling the function at ``4`` points up to a maximum input speed of ``9`` will give us a custom function with a step of ``3`` and points ``[0.0, 9.0, 36.0, 81.0]``: .. figure:: ptraccel-custom.svg :align: center More sampled points can be added to improve the accuracy of the user custom function. Supported Movement types: +---------------+---------------------------------+----------------------+ | Movement type | Uses | supported by | +===============+=================================+======================+ | Fallback | Catch-all default movement type | All devices | +---------------+---------------------------------+----------------------+ | Motion | Used for pointer motion | All devices | +---------------+---------------------------------+----------------------+ | Scroll | Used for scroll movement | Mouse, Touchpad | +---------------+---------------------------------+----------------------+ If a user does not provide the fallback custom acceleration function, a flat acceleration function is used, i.e. no acceleration. The fallback acceleration may be used for different types of movements, it is strongly recommended that this acceleration function is a constant function. For example, a touchpad has multiple movement types: pointer movement, scroll movement, zoom movement (pinch), etc. As there is no separate movement type for zoom yet, zoom movement is accelerated using the Fallback acceleration function. Pointer movement is accelerated using the Motion acceleration function, and Scroll movement is accelerated using the Scroll acceleration function. If no Motion/Scroll acceleration function is set, the Fallback acceleration function is used. When using custom acceleration profile, any calls to set the speed have no effect on the behavior of the custom acceleration function, but any future calls to get the speed will reflect the requested speed setting. libinput-1.28.1/doc/user/reporting-bugs.rst000066400000000000000000000406401477265155700207040ustar00rootroot00000000000000.. _reporting_bugs: ============================================================================== Reporting bugs ============================================================================== A new bug can be filed here: https://gitlab.freedesktop.org/libinput/libinput/issues/new .. hint:: libinput has lots of users but very few developers. It is in your own interest to follow the steps here precisely to ensure your bug can be dealt with efficiently. When reporting bugs against libinput, you will need: - a reliable :ref:`reproducer ` for the bug - a :ref:`recording ` of the device while the bug is reproduced - device-specific information, see - :ref:`reporting_bugs_touchpad` - :ref:`reporting_bugs_mouse` - :ref:`reporting_bugs_keyboard` - :ref:`reporting_bugs_trackpoint` - :ref:`reporting_bugs_other` - the :ref:`libinput version ` you are on. - the :ref:`configuration options ` you have set - a `gitlab account `_ Stay technical, on-topic, and keep the description concise. .. _reporting_bugs_version: ------------------------------------------------------------------------------ Obtaining the libinput version ------------------------------------------------------------------------------ If your libinput version is older than the current stable branch, please try the latest version. If you run a distribution-provided libinput, use the package manager to get the **full** package name and version of libinput, e.g. - ``rpm -q libinput`` - ``dpkg -s libinput10`` If you run a self-compiled version of libinput provide the git commit you have built or the tarball name. As a last resort, use ``libinput --version`` .. _reporting_bugs_reproducer: ------------------------------------------------------------------------------ Reproducing bugs ------------------------------------------------------------------------------ Try to identify the bug by reproducing it reliably. Bugs without a reliable reproducer will have lowest priority. The more specific a bug description and reproducer is, the easier it is to fix. Try to replicate the series of events that lead to the bug being triggered. Narrow it down until you have a reliable sequence that can trigger the bug. For the vast majority of bugs you should not take longer than 5 seconds or three interactions (clicks, touches, taps, ...) with the device to reproduce. If it takes longer than that, you can narrow it down further. Once you can reproduce it, use the :ref:`libinput-debug-events` helper tool:: $> libinput debug-events --verbose The output is textual and can help identify whether the bug is in libinput at all. Note that any configuration options you have set must be specified on the commandline, see the :ref:`libinput-debug-events` man page. Use the ``--verbose`` flag to get more information about how libinput processes events. If the bug cannot be reproduced with the :ref:`libinput-debug-events` helper, even with the correct configuration options set, it is likely not a bug in libinput. .. _reporting_bugs_options: ------------------------------------------------------------------------------ libinput configuration settings ------------------------------------------------------------------------------ libinput has a number of device-specific default configuration settings that may differ from the ones your desktop environment picks by default. You may have changed some options in a settings panel or in an the xorg.conf snippet yourself. You must provide these options in the bug report, otherwise a developer reproducing the issue may not be able to do so. If you are on X11, the current settings can be can be obtained with ``xinput list-props "your device name"``. Use ``xinput list`` to obtain the device name. If you are on Wayland, provide a manual summary of the options you have changed from the default (e.g. "I enabled tap-to-click"). .. _reporting_bugs_touchpad: ------------------------------------------------------------------------------ Reporting touchpad bugs ------------------------------------------------------------------------------ When you file a bug, please attach the following information: - a virtual description of your input device, see :ref:`libinput-record`. This is the most important piece of information, do not forget it! - the output from udevadm info, see :ref:`udev_info`. - the vendor model number of your laptop (e.g. "Lenovo Thinkpad T440s") - and the content of ``/sys/class/dmi/id/modalias``. - run the ``touchpad-edge-detector`` tool (provided by libevdev) and verify that the ranges and sizes it prints match the touchpad (up to 5mm difference is ok) If you are reporting a bug related to button event generation: - does your touchpad have (separate) physical hardware buttons or is the whole touchpad clickable? - Are you using software buttons or clickfinger? See :ref:`clickpad_softbuttons`. - Do you have :ref:`tapping` enabled? .. _reporting_bugs_mouse: ------------------------------------------------------------------------------ Reporting mouse bugs ------------------------------------------------------------------------------ When you file a bug, please attach the following information: - a virtual description of your input device, see :ref:`libinput-record`. This is the most important piece of information, do not forget it! - the vendor model number of the device (e.g. "Logitech M325") - the output from udevadm info, see :ref:`udev_info`. If the bug is related to the :ref:`speed of the mouse `: - the resolution of the mouse as specified by the vendor (in DPI) - the output of the ``mouse-dpi-tool`` (provided by libevdev) .. _reporting_bugs_keyboard: ------------------------------------------------------------------------------ Reporting keyboard bugs ------------------------------------------------------------------------------ Is your bug related to a keyboard layout? libinput does not handle keyboard layouts and merely forwards the physical key events. File the bug with your desktop environment instead (e.g. GNOME, KDE, ...), that's most likely where the issue is. When you file a bug, please attach the following information: - a virtual description of your input device, see :ref:`libinput-record`. This is the most important piece of information, do not forget it! .. _reporting_bugs_trackpoint: ------------------------------------------------------------------------------ Reporting trackpoint bugs ------------------------------------------------------------------------------ When you file a bug, please attach the following information: - a virtual description of your input device, see :ref:`libinput-record`. This is the most important piece of information, do not forget it! - the vendor model number of the device (e.g. "Logitech M325") - the output from udevadm info, see :ref:`udev_info`. - the sensitivity of the trackpoint if it exists (adjust the event node number as needed): :: $ cat /sys/class/input/event17/device/device/sensitivity .. _reporting_bugs_other: ------------------------------------------------------------------------------ All other devices ------------------------------------------------------------------------------ When you file a bug, please attach the following information: - a virtual description of your input device, see :ref:`libinput-record`. This is the most important piece of information, do not forget it! - the vendor model number of the device (e.g. "Sony Plastation3 controller") .. _udev_info: ------------------------------------------------------------------------------ udev information for the device ------------------------------------------------------------------------------ In many cases, we require the udev properties assigned to the device to verify whether device-specific quirks were applied. This can be obtained with ``udevadm info /sys/class/input/eventX``, with the correct event node for your device. An example output is below: :: $ udevadm info /sys/class/input/event4 P: /devices/platform/i8042/serio1/input/input5/event4 N: input/event4 E: DEVNAME=/dev/input/event4 E: DEVPATH=/devices/platform/i8042/serio1/input/input5/event4 E: EVDEV_ABS_00=::41 E: EVDEV_ABS_01=::37 E: EVDEV_ABS_35=::41 E: EVDEV_ABS_36=::37 E: ID_INPUT=1 E: ID_INPUT_HEIGHT_MM=66 E: ID_INPUT_TOUCHPAD=1 E: ID_INPUT_WIDTH_MM=97 E: MAJOR=13 E: MINOR=68 E: SUBSYSTEM=input E: USEC_INITIALIZED=5463031 .. _evemu: ------------------------------------------------------------------------------ Recording devices with evemu ------------------------------------------------------------------------------ .. warning:: Where available, the :ref:`libinput-record` tools should be used instead of evemu `evemu-record `_ records the device capabilities together with the event stream from the kernel. On our side, this allows us to recreate a virtual device identical to your device and re-play the event sequence, hopefully triggering the same bug. evemu-record takes a ``/dev/input/eventX`` event node, but without arguments it will simply show the list of devices and let you select: :: $ sudo evemu-record > scroll.evemu Available devices: /dev/input/event0: Lid Switch /dev/input/event1: Sleep Button /dev/input/event2: Power Button /dev/input/event3: AT Translated Set 2 keyboard /dev/input/event4: SynPS/2 Synaptics TouchPad /dev/input/event5: Video Bus /dev/input/event6: ELAN Touchscreen /dev/input/event10: ThinkPad Extra Buttons /dev/input/event11: HDA Intel HDMI HDMI/DP,pcm=3 /dev/input/event12: HDA Intel HDMI HDMI/DP,pcm=7 /dev/input/event13: HDA Intel HDMI HDMI/DP,pcm=8 /dev/input/event14: HDA Intel PCH Dock Mic /dev/input/event15: HDA Intel PCH Mic /dev/input/event16: HDA Intel PCH Dock Headphone /dev/input/event17: HDA Intel PCH Headphone /dev/input/event18: Integrated Camera /dev/input/event19: TPPS/2 IBM TrackPoint Select the device event number [0-19]: Select the device that triggers the issue, then reproduce the bug and Ctrl+C the process. The resulting recording, ("scroll.evemu" in this example) will contain the sequence required to reproduce the bug. If the bug fails to reproduce during recording, simply Ctrl+C and restart evemu-record. Always start the recording from a neutral state, i.e. without any buttons or keys down, with the position of the device in the neutral position, without touching the screen/touchpad. .. note:: The longer the recording, the harder it is to identify the event sequence triggering the bug. Please keep the event sequence as short as possible. To verify that the recording contains the bug, you can replay it on your device. For example, to replay the sequence recorded in the example above: :: $ sudo evemu-play /dev/input/event4 < scroll.evemu If the bug is triggered by replaying on your device, attach the recording to the bug report. libinput does not affect the evemu recording. libinput and evemu talk directly to the kernel's device nodes. An evemu recording is not influenced by the libinput version or whether a libinput context is currently active. .. graphviz:: evemu.gv .. _fixed_bugs: ------------------------------------------------------------------------------ My bug was closed as fixed, what now? ------------------------------------------------------------------------------ libinput's policy on closing bugs is: once the fix for a given bug is on git master, the bug is considered fixed and the gitlab issue will be closed accordingly. Of course, unless you actually run git master, the bug will continue to affect you on your local machine. You are most likely running the distribution's package and you will need to wait until the distribution has updated its package accordingly. .. warning:: Do not re-open a bug just because it hasn't trickled down to your distribution's package version yet. Whether the bug fix ends up in your distribution depends on a number of things. Any given bug fix **may** be cherry-picked into the current stable branch, depending on its severity, impact, and likelihood to cause regressions. Once cherry-picked it will land in the next stable branch release. These are usually a few weeks apart. .. warning:: Do not re-open a bug because it wasn't picked into a stable branch release or because your distribution didn't update to the latest stable branch release. Stable branches are usually discontinued when the next release comes out. Your distribution may pick a patch up immediately and ship the fix even before the next stable branch update is released. For example, Fedora does this frequently. .. hint:: If a bug needs to be fixed urgently, file a bug in your distribution's bug tracker. Patches on git master will end up in the next libinput release. Once your distribution updates to that release, your local libinput version will contain the fix. .. warning:: Do not re-open a bug because your distribution didn't update to the release. You can always run libinput from git master (see :ref:`building_libinput`). Even while in development, libinput is very stable so this option isn't as scary as it may sounds. .. _reporting_bugs_reopen: .............................................................................. When is it ok to re-open a fixed bug? .............................................................................. Any time the bug was considered fixed but it turns out that the fix is insufficient and/or causes a regression. However, if the regression is in behavior unrelated to the fix itself it is usually better to file a new bug to reduce the noise. For example, if a fix to improve tapping breaks two-finger scrolling behavior, you should file a new bug but reference the original bug. .. _reporting_bugs_tags: ------------------------------------------------------------------------------ Gitlab issue tracker tags ------------------------------------------------------------------------------ The gitlab issue tracker allows developers to add tags to bugs to classify them. - **being worked on**: someone is currently working on this feature. This tag is used for features that will take a long time to implement fully and prevents others from having to duplicate the work. Do reach out and ask if help and/or further testing is needed. - **bug**: issue is confirmed to be a bug - **cantfix**: for technical reasons, this bug cannot be fixed, or at least it cannot be fixed in libinput. - **enhancement**: this issue describes a future feature, not a bug. - **help needed**: this issue requires someone outside the libinput core developer team to implement it. It is unlikely to be implemented without someone stepping up to do the work. If you do see this tag, do ask for guidance on how to implement it. - **hw issue**: an issue that affects a specific device and is a hardware bug, not a software bug. Often these needs to be worked around in libinput but there are cases where a hw issue ends up as *cantfix*. - **janitor**: a cleanup task that does not substantially affect how libinput works. These are usually good bugs for newcomers to start on. - **kernel**: this issue is a kernel bug, not a libinput bug. Often closed as *cantfix* of *wontfix* as we wait for the kernel to address the issue instead. - **needs triage**: bug has not yet been confirmed by a core developer. - **not our bug**: the issue is in some other component of the stack and needs to be addressed there. - **please test**: a fix is available but not yet merged and should be tested by the reporter or others affected by the issue. - **quirk**: this is issue needs :ref:`device-quirks` to be fixed - **regression**: the issue is a regression to previous versions of libinput. These issues get priorities. - **waiting on reporter**: some more information is required from the reporter and the issue cannot be fixed until the issue has been provided. Where a bug is left in this state for too long, the bug will be closed as *cantfix*. - **wontfix**: this issue will not get fixed. This tag is usually assigned to feature requests that are outside the scope of libinput or would put an unreasonable maintenance burdern on the maintainers. These tags are high-level categories only, always look for the comments in the issue to get further details. libinput-1.28.1/doc/user/scrolling.rst000066400000000000000000000172361477265155700177360ustar00rootroot00000000000000.. _scrolling: ============================================================================== Scrolling ============================================================================== libinput supports three different types of scrolling methods: :ref:`twofinger_scrolling`, :ref:`edge_scrolling` and :ref:`button_scrolling`. Some devices support multiple methods, though only one can be enabled at a time. As a general overview: - touchpad devices with physical buttons below the touchpad support edge and two-finger scrolling - touchpad devices without physical buttons (:ref:`ClickPads `) support two-finger scrolling only - pointing sticks provide on-button scrolling by default - mice and other pointing devices support on-button scrolling but it is not enabled by default A device may differ from the above based on its capabilities. See **libinput_device_config_scroll_set_method()** for documentation on how to switch methods and **libinput_device_config_scroll_get_methods()** for documentation on how to query a device for available scroll methods. .. _horizontal_scrolling: ------------------------------------------------------------------------------ Horizontal scrolling ------------------------------------------------------------------------------ Scroll movements provide vertical and horizontal directions, each scroll event contains both directions where applicable, see **libinput_event_pointer_get_axis_value()**. libinput does not provide separate toggles to enable or disable horizontal scrolling. Instead, horizontal scrolling is always enabled. This is intentional, libinput does not have enough context to know when horizontal scrolling is appropriate for a given widget. The task of filtering horizontal movements is up to the caller. .. _twofinger_scrolling: ------------------------------------------------------------------------------ Two-finger scrolling ------------------------------------------------------------------------------ The default on two-finger capable touchpads (almost all modern touchpads are capable of detecting two fingers). Scrolling is triggered by two fingers being placed on the surface of the touchpad, then moving those fingers vertically or horizontally. .. figure:: twofinger-scrolling.svg :align: center Vertical and horizontal two-finger scrolling For scrolling to trigger, a built-in distance threshold has to be met, but once engaged, any movement will scroll. In other words: to start scrolling, a sufficiently large movement is required; once scrolling, tiny amounts of movements will translate into tiny scroll movements. Scrolling in both directions at once is possible by meeting the required distance thresholds to enable each direction separately. When a scroll gesture remains close to perfectly straight, it will be held to exact 90-degree angles; but if the gesture moves diagonally, it is free to scroll in any direction. Two-finger scrolling requires the touchpad to track both touch points with reasonable precision. Unfortunately, some so-called "semi-mt" touchpads can only track the bounding box of the two fingers rather than the actual position of each finger. In addition, that bounding box usually suffers from a low resolution, causing jumpy movement during two-finger scrolling. libinput does not provide two-finger scrolling on those touchpads. .. _edge_scrolling: ------------------------------------------------------------------------------ Edge scrolling ------------------------------------------------------------------------------ On some touchpads, edge scrolling is available, triggered by moving a single finger along the right edge (vertical scroll) or bottom edge (horizontal scroll). .. figure:: edge-scrolling.svg :align: center Vertical and horizontal edge scrolling Due to the layout of the edges, diagonal scrolling is not possible. The behavior of edge scrolling using both edges at the same time is undefined. Edge scrolling overlaps with :ref:`clickpad_softbuttons`. A physical click on a clickpad ends scrolling. .. _button_scrolling: ------------------------------------------------------------------------------ On-Button scrolling ------------------------------------------------------------------------------ On-button scrolling converts the motion of a device into scroll events while a designated button is held down. For example, Lenovo devices provide a `pointing stick `_ that emulates scroll events when the trackstick's middle mouse button is held down. .. note:: On-button scrolling is enabled by default for pointing sticks. This prevents middle-button dragging; all motion events while the middle button is down are converted to scroll events. .. figure:: button-scrolling.svg :align: center Button scrolling The button may be changed with **libinput_device_config_scroll_set_button()** but must be on the same device as the motion events. Cross-device scrolling is not supported but for one exception: libinput's :ref:`t440_support` enables the use of the middle button for button scrolling (even when the touchpad is disabled). If the scroll button lock is enabled (see **libinput_device_config_scroll_set_button_lock()**), the button does not need to be held down. Pressing and releasing the button once enables the button lock, the button is now considered logically held down. Pressing and releasing the button a second time logically releases the button. While the button is logically held down, motion events are converted to scroll events. .. _scroll_sources: ------------------------------------------------------------------------------ Scroll sources ------------------------------------------------------------------------------ .. note:: Scroll sources are deprecated with libinput 1.19. The scroll source is now encoded in the event type. libinput provides a pointer axis *source* for each scroll event. The source can be obtained with the **libinput_event_pointer_get_axis_source()** function and is one of **wheel**, **finger**, or **continuous**. The source information lets a caller decide when to implement kinetic scrolling. Usually, a caller will process events of source wheel as they come in. For events of source finger a caller should calculate the velocity of the scroll motion and upon finger release start a kinetic scrolling motion (i.e. continue executing a scroll according to some friction factor). libinput expects the caller to be in charge of widget handling, the source information is thus enough to provide kinetic scrolling on a per-widget basis. A caller should cancel kinetic scrolling when the pointer leaves the current widget or when a key is pressed. See the **libinput_event_pointer_get_axis_source()** for details on the behavior of each scroll source. See also http://who-t.blogspot.com.au/2015/03/libinput-scroll-sources.html .. _natural_scrolling: ------------------------------------------------------------------------------ Natural scrolling vs. traditional scrolling ------------------------------------------------------------------------------ Natural scrolling is the term (probably) coined by Apple for matching the motion of the scroll device with the direction of the **content**. In traditional scrolling, moving the wheel down causes the scroll bar indicators to move down and the content to move up. In natural scrolling, moving the wheel down causes the content to move down and the scroll bar indicators to move up. This method of scrolling matches the interaction with content on touch screens where a movement down also moves the content down. libinput supports natural scrolling for all its scroll methods; it can be enabled with the **libinput_device_config_scroll_set_natural_scroll_enabled()** function. libinput-1.28.1/doc/user/seats.rst000066400000000000000000000072231477265155700170540ustar00rootroot00000000000000.. _seats: ============================================================================== Seats ============================================================================== Each device in libinput is assigned to one seat. A seat has two identifiers, the physical name and the logical name. The physical name is summarized as the list of devices a process on the same physical seat has access to. The logical seat name is the seat name for a logical group of devices. A compositor may use that to create additional seats as independent device sets. Alternatively, a compositor may limit itself to a single logical seat, leaving a second compositor to manage devices on the other logical seats. .. _seats_overview: ------------------------------------------------------------------------------ Overview ------------------------------------------------------------------------------ Below is an illustration of how physical seats and logical seats interact: .. graphviz:: seats-sketch.gv The devices "Foo", "Bar" and "Spam" share the same physical seat and are thus available in the same libinput context. Only "Foo" and "Bar" share the same logical seat. The device "Egg" is not available in the libinput context associated with the physical seat 0. The above graph is for illustration purposes only. In libinput, a struct **libinput_seat** comprises both physical seat and logical seat. From a caller's point-of-view the above device layout is presented as: .. graphviz:: seats-sketch-libinput.gv Thus, devices "Foo" and "Bar" both reference the same struct **libinput_seat**, all other devices reference their own respective seats. .. _seats_and_features: ------------------------------------------------------------------------------ The effect of seat assignment ------------------------------------------------------------------------------ A logical set is interpreted as a group of devices that usually belong to a single user that interacts with a computer. Thus, the devices are semantically related. This means for devices within the same logical seat: - if the same button is pressed on different devices, the button should only be considered logically pressed once. - if the same button is released on one device, the button should be considered logically down if still down on another device. - if two different buttons or keys are pressed on different devices, the logical state is that of both buttons/keys down. - if a button is pressed on one device and another device moves, this should count as dragging. - if two touches are down on different devices, the logical state is that of two touches down. libinput provides functions to aid with the above: **libinput_event_pointer_get_seat_button_count()**, **libinput_event_keyboard_get_seat_key_count()**, and **libinput_event_touch_get_seat_slot()**. Internally, libinput counts devices within the same logical seat as related. Cross-device features only activate if all required devices are in the same logical seat. For example, libinput will only activate the top software buttons (see :ref:`t440_support`) if both trackstick and touchpad are assigned to the same logical seat. .. _changing_seats: ------------------------------------------------------------------------------ Changing seats ------------------------------------------------------------------------------ A device may change the logical seat it is assigned to at runtime with **libinput_device_set_seat_logical_name()**. The physical seat is immutable and may not be changed. Changing the logical seat for a device is equivalent to unplugging the device and plugging it back in with the new logical seat. No device state carries over across a logical seat change. libinput-1.28.1/doc/user/svg/000077500000000000000000000000001477265155700157765ustar00rootroot00000000000000libinput-1.28.1/doc/user/svg/button-debouncing-wave-diagram.svg000066400000000000000000003225771477265155700245270ustar00rootroot00000000000000 Button Debouncing Scenarioscurrent modenormal button press and releasephysical buttonapplication current modedebounced button pressphysical buttontimeoutsapplication current modedebounced button releasephysical buttontimeoutsapplication current modedelayed button pressphysical buttontimeoutsapplication current modedelayed button releasephysical buttontimeoutsapplication current modefirst spurious button release physical buttonapplication current modelater spurious button release physical buttontimeoutsapplication current modedelayed release in spurious mode physical buttontimeoutsapplication bounce modespurious mode libinput-1.28.1/doc/user/svg/button-scrolling.svg000066400000000000000000000417641477265155700220400ustar00rootroot00000000000000 C V B N M J H G F libinput-1.28.1/doc/user/svg/clickfinger-distance.svg000066400000000000000000000136121477265155700225720ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/clickfinger.svg000066400000000000000000000371671477265155700210150ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/edge-scrolling.svg000066400000000000000000000160361477265155700214230ustar00rootroot00000000000000 libinput-1.28.1/doc/user/svg/gesture-2fg-ambiguity.svg000066400000000000000000000707671477265155700226620ustar00rootroot00000000000000 image/svg+xml Touch 1 Touch 2 libinput-1.28.1/doc/user/svg/palm-detection.svg000066400000000000000000000170551477265155700214340ustar00rootroot00000000000000 image/svg+xml A B C libinput-1.28.1/doc/user/svg/pinch-gestures-softbuttons.svg000066400000000000000000000407231477265155700240550ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/pinch-gestures.svg000066400000000000000000001046261477265155700214700ustar00rootroot00000000000000 image/svg+xml logicalcenter initial scale (1.0) current scale (> 1.0) logicalcenter deltaangle libinput-1.28.1/doc/user/svg/ptraccel-custom.svg000066400000000000000000000665561477265155700216460ustar00rootroot00000000000000 2023-08-16T19:10:50.848529 image/svg+xml Matplotlib v3.7.2, https://matplotlib.org/ libinput-1.28.1/doc/user/svg/ptraccel-linear.svg000066400000000000000000001317401477265155700215720ustar00rootroot00000000000000 Gnuplot Produced by GNUPLOT 5.0 patchlevel 6 0 0.5 1 1.5 2 2.5 3 0 50 100 150 200 250 300 350 400 accel factor speed in mm/s -1 -1 -0.75 -0.75 -0.5 -0.5 -0.25 -0.25 0 0 0.5 0.5 1 1 libinput-1.28.1/doc/user/svg/ptraccel-low-dpi.svg000066400000000000000000013611721477265155700217000ustar00rootroot00000000000000 Gnuplot Produced by GNUPLOT 5.0 patchlevel 0 0 1 2 3 4 5 0 0.0005 0.001 0.0015 0.002 0.0025 0.003 accel factor speed in units/us 200dpi 200dpi 400dpi 400dpi 800dpi 800dpi 1000dpi 1000dpi libinput-1.28.1/doc/user/svg/ptraccel-touchpad.svg000066400000000000000000001462641477265155700221360ustar00rootroot00000000000000 Gnuplot Produced by GNUPLOT 5.0 patchlevel 6 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0 50 100 150 200 250 300 350 400 accel factor speed in mm/s -1 -1 -0.75 -0.75 -0.5 -0.5 -0.25 -0.25 0 0 0.5 0.5 1 1 libinput-1.28.1/doc/user/svg/ptraccel-trackpoint.svg000066400000000000000000000343151477265155700224760ustar00rootroot00000000000000 Gnuplot Produced by GNUPLOT 5.0 patchlevel 6 0 1 2 3 4 5 0 0.2 0.4 0.6 0.8 1 accel factor delta (units/ms) -1 -1 -0.75 -0.75 -0.5 -0.5 -0.25 -0.25 0 0 0.5 0.5 1 1 libinput-1.28.1/doc/user/svg/software-buttons-conditions.svg000066400000000000000000000246431477265155700242250ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/software-buttons-thumbpress.svg000066400000000000000000000133651477265155700242470ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/software-buttons-visualized.svg000066400000000000000000000146641477265155700242350ustar00rootroot00000000000000 image/svg+xml main area right button left button middle libinput-1.28.1/doc/user/svg/software-buttons.svg000066400000000000000000000224331477265155700220510ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/swipe-gestures.svg000066400000000000000000000546701477265155700215210ustar00rootroot00000000000000 image/svg+xml logicalcenter libinput-1.28.1/doc/user/svg/tablet-area.svg000066400000000000000000000234461477265155700207110ustar00rootroot00000000000000 image/svg+xml 0/0 libinput-1.28.1/doc/user/svg/tablet-axes.svg000066400000000000000000000632271477265155700207420ustar00rootroot00000000000000 image/svg+xml Distance Pressure Tilt (angle) libinput-1.28.1/doc/user/svg/tablet-cintiq24hd-modes.svg000066400000000000000000000520611477265155700230520ustar00rootroot00000000000000 image/svg+xml mode indicators mode indicators mode toggle buttons mode toggle buttons libinput-1.28.1/doc/user/svg/tablet-interfaces.svg000066400000000000000000000365031477265155700221220ustar00rootroot00000000000000 image/svg+xml Pad buttons Pad buttons Pad buttons Pad ring Pad ring Tool buttons Tool tip libinput-1.28.1/doc/user/svg/tablet-intuos-modes.svg000066400000000000000000000355221477265155700224250ustar00rootroot00000000000000 image/svg+xml mode indicators mode indicators mode toggle button libinput-1.28.1/doc/user/svg/tablet-left-handed.svg000066400000000000000000000536541477265155700221600ustar00rootroot00000000000000 image/svg+xml origin origin zero zero libinput-1.28.1/doc/user/svg/tablet-out-of-bounds.svg000066400000000000000000000263041477265155700224760ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/tablet.svg000066400000000000000000000214441477265155700177770ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/tap-n-drag.svg000066400000000000000000001346131477265155700204610ustar00rootroot00000000000000 image/svg+xml a) Tap b) Hold down c) Move d) Reset finger, move (optional) f) Tap to end (optional) e) Release libinput-1.28.1/doc/user/svg/thumb-detection.svg000066400000000000000000000144201477265155700216130ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/top-software-buttons.svg000066400000000000000000000317241477265155700226540ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/touchscreen-gestures.svg000066400000000000000000000673061477265155700227140ustar00rootroot00000000000000 image/svg+xml libinput-1.28.1/doc/user/svg/trackpoint-delta-illustration.svg000066400000000000000000000216771477265155700245300ustar00rootroot00000000000000 Gnuplot Produced by GNUPLOT 5.0 patchlevel 6 minimum possible interval delta is 1 physical pressure time between events time between events (x, y) delta values (x, y) delta values libinput-1.28.1/doc/user/svg/twofinger-scrolling.svg000066400000000000000000000266351477265155700225310ustar00rootroot00000000000000 libinput-1.28.1/doc/user/switches.rst000066400000000000000000000055301477265155700175650ustar00rootroot00000000000000.. _switches: ============================================================================== Switches ============================================================================== libinput supports the lid and tablet-mode switches. Unlike button events that come in press and release pairs, switches are usually toggled once and left at the setting for an extended period of time. Only some switches are handled by libinput, see **libinput_switch** for a list of supported switches. Switch events are exposed to the caller, but libinput may handle some switch events internally and enable or disable specific features based on a switch state. The order of switch events is guaranteed to be correct, i.e., a switch will never send consecutive switch on, or switch off, events. .. _switches_lid: ------------------------------------------------------------------------------ Lid switch handling ------------------------------------------------------------------------------ Where available, libinput listens to devices providing a lid switch. The evdev event code ``EV_SW`` ``SW_LID`` is provided as **LIBINPUT_SWITCH_LID**. If devices with a lid switch have a touchpad device, the device is disabled while the lid is logically closed. This is to avoid ghost touches that can be caused by interference with touchpads and the closed lid. The touchpad is automatically re-enabled whenever the lid is opened. This handling of lid switches is transparent to the user, no notifications are sent and the device appears as enabled at all times. On some devices, the device's lid state does not always reflect the physical state and the lid state may report as closed even when the lid is physically open. libinput employs some heuristics to detect user input (specifically typing) to re-enable the touchpad on those devices. Where input is detected, libinput updates the lid status of the kernel device so other consumers of the kernel events also get the accurate state. .. _switches_tablet_mode: ------------------------------------------------------------------------------ Tablet mode switch handling ------------------------------------------------------------------------------ Where available, libinput listens to devices providing a tablet mode switch. This switch is usually triggered on devices that can switch between a normal laptop layout and a tablet-like layout. One example for such a device is the Lenovo Yoga. The event sent by the kernel is ``EV_SW`` ``SW_TABLET_MODE`` and is provided as **LIBINPUT_SWITCH_TABLET_MODE**. When the device switches to tablet mode, the touchpad and internal keyboard are disabled. If a trackpoint exists, it is disabled too. The input devices are automatically re-enabled whenever tablet mode is disengaged. This handling of tablet mode switches is transparent to the user, no notifications are sent and the device appears as enabled at all times. libinput-1.28.1/doc/user/t440-support.rst000066400000000000000000000112201477265155700201320ustar00rootroot00000000000000.. _t440_support: ============================================================================== Lenovo \*40 series touchpad support ============================================================================== The Lenovo \*40 series emulates trackstick buttons on the top part of the touchpads. .. _t440_support_overview: ------------------------------------------------------------------------------ Overview ------------------------------------------------------------------------------ The Lenovo \*40 series introduced a new type of touchpad. Previously, all laptops had a separate set of physical buttons for the `trackstick `_. This series removed these buttons, relying on a software emulation of the top section of the touchpad. This is visually marked on the trackpad itself, and clicks can be triggered by pressing the touchpad down with a finger in the respective area: .. figure:: top-software-buttons.svg :align: center Left, right and middle-button click with top software button areas This page only covers the top software buttons, the bottom button behavior is covered in :ref:`Clickpad software buttons `. Clickpads with a top button area are marked with the `INPUT_PROP_TOPBUTTONPAD `_ property. .. _t440_support_btn_size: ------------------------------------------------------------------------------ Size of the buttons ------------------------------------------------------------------------------ The size of the buttons matches the visual markings on this touchpad. The width of the left and right buttons is approximately 42% of the touchpad's width, the middle button is centered and assigned 16% of the touchpad width. The line of the buttons is 5mm from the top edge of the touchpad, measurements of button presses showed that the size of the buttons needs to be approximately 10mm high to work reliable (especially when using the thumb to press the button). .. _t440_support_btn_behavior: ------------------------------------------------------------------------------ Button behavior ------------------------------------------------------------------------------ Movement in the top button area does not generate pointer movement. These buttons are not replacement buttons for the bottom button area but have their own behavior. Semantically attached to the trackstick device, libinput re-routes events from these buttons to appear through the trackstick device. .. graphviz:: digraph top_button_routing { rankdir="LR"; node [shape="box";] trackstick [label="trackstick kernel device"]; touchpad [label="touchpad kernel device"]; subgraph cluster0 { bgcolor = floralwhite label = "libinput" libinput_ts [label="trackstick libinput_device" style=filled fillcolor=white]; libinput_tp [label="touchpad libinput_device" style=filled fillcolor=white]; libinput_tp -> libinput_ts [constraint=false color="red4"]; } trackstick -> libinput_ts [arrowhead="none"] touchpad -> libinput_tp [color="red4"] events_tp [label="other touchpad events"]; events_topbutton [label="top software button events"]; libinput_tp -> events_tp [arrowhead="none"] libinput_ts -> events_topbutton [color="red4"] } The top button areas work even if the touchpad is disabled but will be disabled when the trackstick device is disabled. If the finger starts inside the top area and moves outside the button area the finger is treated as dead and must be lifted to generate future buttons. Likewise, movement into the top button area does not trigger button events, a click has to start inside this area to take effect. .. _t440_support_identification: ------------------------------------------------------------------------------ Kernel support ------------------------------------------------------------------------------ The firmware on the first generation of touchpads providing top software buttons is buggy and announces wrong ranges. `Kernel patches `_ are required; these fixes are available in kernels 3.14.1, 3.15 and later but each touchpad needs a separate fix. The October 2014 refresh of these laptops do not have this firmware bug anymore and should work without per-device patches, though `this kernel commit `_ is required. For a complete list of supported touchpads check `the kernel source `_ (search for "topbuttonpad_pnp_ids"). libinput-1.28.1/doc/user/tablet-debugging.rst000066400000000000000000000035231477265155700211400ustar00rootroot00000000000000.. _tablet-debugging: ============================================================================== Debugging tablet issues ============================================================================== .. _tablet-capabilities: ------------------------------------------------------------------------------ Required tablet capabilities ------------------------------------------------------------------------------ To handle a tablet correctly, libinput requires a set of capabilities on the device. When these capabilities are missing, libinput ignores the device and prints an error to the log. This error messages reads :: missing tablet capabilities: xy pen btn-stylus resolution. Ignoring this device. or in older versions of libinput simply: :: libinput bug: device does not meet tablet criteria. Ignoring this device. When a tablet is rejected, it is usually possible to verify the issue with the ``libinput record`` tool. - **xy** indicates that the tablet is missing the ``ABS_X`` and/or ``ABS_Y`` axis. This indicates that the device is mislabelled and the udev tag ``ID_INPUT_TABLET`` is applied to a device that is not a tablet. A bug should be filed against `systemd `__. - **pen** or **btn-stylus** indicates that the tablet does not have the ``BTN_TOOL_PEN`` or ``BTN_STYLUS`` bit set. libinput requires either or both of them to be present. This indicates a bug in the kernel driver or the HID descriptors of the device. - **resolution** indicates that the device does not have a resolution set for the x and y axes. This can be fixed with a hwdb entry, locate and read the `60-evdev.hwdb `__ file on your machine and file a pull request with the fixes against `systemd `__. libinput-1.28.1/doc/user/tablet-support.rst000066400000000000000000000565061477265155700207320ustar00rootroot00000000000000.. _tablet-support: ============================================================================== Tablet support ============================================================================== This page provides details about the graphics tablet support in libinput. Note that the term "tablet" in libinput refers to graphics tablets only (e.g. Wacom Intuos), not to tablet devices like the Apple iPad. .. figure:: tablet.svg :align: center Illustration of a graphics tablet .. _tablet-tools: ------------------------------------------------------------------------------ Pad buttons vs. tablet tools ------------------------------------------------------------------------------ Most tablets provide two types of devices. The physical tablet often provides a number of buttons and a touch ring or strip. Interaction on the drawing surface of the tablet requires a tool, usually in the shape of a stylus. The libinput interface exposed by devices with the **LIBINPUT_DEVICE_CAP_TABLET_TOOL** capability applies only to events generated by tools. Buttons, rings or strips on the physical tablet hardware (the "pad") are exposed by devices with the **LIBINPUT_DEVICE_CAP_TABLET_PAD** capability. Pad events do not require a tool to be in proximity. Note that both capabilities may exist on the same device though usually they are split across multiple kernel devices. .. figure:: tablet-interfaces.svg :align: center Difference between Pad and Tool buttons Touch events on the tablet integrated into a screen itself are exposed through the **LIBINPUT_DEVICE_CAP_TOUCH** capability. Touch events on a standalone tablet are exposed through the **LIBINPUT_DEVICE_CAP_POINTER** capability. In both cases, the kernel usually provides a separate event node for the touch device, resulting in a separate libinput device. See **libinput_device_get_device_group()** for information on how to associate the touch part with other devices exposed by the same physical hardware. .. _tablet-tip: ------------------------------------------------------------------------------ Tool tip events vs. tool button events ------------------------------------------------------------------------------ The primary use of a tablet tool is to draw on the surface of the tablet. When the tool tip comes into contact with the surface, libinput sends an event of type **LIBINPUT_EVENT_TABLET_TOOL_TIP**, and again when the tip ceases contact with the surface. Tablet tools may send button events; these are exclusively for extra buttons unrelated to the tip. A button event is independent of the tip and can while the tip is down or up. Some tablet tools' pressure detection is too sensitive, causing phantom touches when the user only slightly brushes the surfaces. For example, some tools are capable of detecting 1 gram of pressure. libinput uses a device-specific pressure threshold to determine when the tip is considered logically down. As a result, libinput may send a nonzero pressure value while the tip is logically up. Most application can and should ignore pressure information until they receive the event of type **LIBINPUT_EVENT_TABLET_TOOL_TIP**. Applications that require extremely fine-grained pressure sensitivity should use the pressure data instead of the tip events to determine a logical tip down state and treat the tip events like axis events otherwise. Note that the pressure threshold to trigger a logical tip event may be zero on some devices. On tools without pressure sensitivity, determining when a tip is down is device-specific. .. _tablet-relative-motion: ------------------------------------------------------------------------------ Relative motion for tablet tools ------------------------------------------------------------------------------ libinput calculates the relative motion vector for each event and converts it to the same coordinate space that a normal mouse device would use. For the caller, this means that the delta coordinates returned by **libinput_event_tablet_tool_get_dx()** and **libinput_event_tablet_tool_get_dy()** can be used identical to the delta coordinates from any other pointer event. Any resolution differences between the x and y axes are accommodated for, a delta of N/N represents a 45 degree diagonal move on the tablet. The delta coordinates are available for all tablet events, it is up to the caller to decide when a tool should be used in relative mode. It is recommended that mouse and lens cursor tool default to relative mode and all pen-like tools to absolute mode. If a tool in relative mode must not use pointer acceleration, callers should use the absolute coordinates returned by **libinput_event_tablet_tool_get_x()** and libinput_event_tablet_tool_get_y() and calculate the delta themselves. Callers that require exact physical distance should also use these functions to calculate delta movements. .. _tablet-axes: ------------------------------------------------------------------------------ Special axes on tablet tools ------------------------------------------------------------------------------ A tablet tool usually provides additional information beyond x/y positional information and the tip state. A tool may provide the distance to the tablet surface and the pressure exerted on the tip when in contact. Some tablets additionally provide tilt information along the x and y axis. .. figure:: tablet-axes.svg :align: center Illustration of the distance, pressure and tilt axes The granularity and precision of the distance and pressure axes varies between tablet devices and cannot usually be mapped into a physical unit. libinput normalizes distance and pressure into the [0, 1] range. While the normalization range is identical for these axes, a caller should not interpret identical values as identical across axes, i.e. a value v1 on the distance axis has no relation to the same value v1 on the pressure axis. The tilt axes provide the angle in degrees between a vertical line out of the tablet and the top of the stylus. The angle is measured along the x and y axis, respectively, a positive tilt angle thus means that the stylus' top is tilted towards the logical right and/or bottom of the tablet. .. _tablet-fake-proximity: ------------------------------------------------------------------------------ Handling of proximity events ------------------------------------------------------------------------------ libinput's **LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY** events notify a caller when a tool comes into sensor range or leaves the sensor range. On some tools this range does not represent the physical range but a reduced tool-specific logical range. If the range is reduced, this is done transparent to the caller. For example, the Wacom mouse and lens cursor tools are usually used in relative mode, lying flat on the tablet. Movement typically follows the interaction normal mouse movements have, i.e. slightly lift the tool and place it in a separate location. The proximity detection on Wacom tablets however extends further than the user may lift the mouse, i.e. the tool may not be lifted out of physical proximity. For such tools, libinput provides software-emulated proximity. Events from the pad do not require proximity, they may be sent any time. .. _tablet-pressure-offset: ------------------------------------------------------------------------------ Pressure offset on worn-out tools ------------------------------------------------------------------------------ When a tool is used for an extended period it can wear down physically. A worn-down tool may never return a zero pressure value. Even when hovering above the surface, the pressure value returned by the tool is nonzero, creating a fake surface touch and making interaction with the tablet less predictable. libinput automatically detects pressure offsets and rescales the remaining pressure range into the available range, making pressure-offsets transparent to the caller. A tool with a pressure offset will thus send a 0 pressure value for the detected offset and nonzero pressure values for values higher than that offset. Some limitations apply to avoid misdetection of pressure offsets, specifically: - pressure offset is only detected on proximity in, and if a device is capable of detection distances, - pressure offset is only detected if the distance between the tool and the tablet is high enough, - pressure offset is only used if it is 50% or less of the pressure range available to the tool. A pressure offset higher than 50% indicates either a misdetection or a tool that should be replaced, and - if a pressure value less than the current pressure offset is seen, the offset resets to that value. Pressure offsets are not detected on **LIBINPUT_TABLET_TOOL_TYPE_MOUSE** and **LIBINPUT_TABLET_TOOL_TYPE_LENS** tools. .. _tablet-pressure-range: ------------------------------------------------------------------------------ Custom tablet tool pressure ranges ------------------------------------------------------------------------------ On tablets supporting pressure, libinput provides that hardware pressure as a logical range of ``0.0`` up to ``1.0`` for the maximum supported pressure. By default, the hardware range thus maps into the following logical range:: hw minimum hw maximum hw range: |------|-----------------------------------| logical range: |----|-----------------------------------| 0.0 | 1.0 Tip Note that libinput always has some built-in thresholds to filter out erroneous touches with near-zero pressure but otherwise the hardware range maps as-is into the logical range. The :ref:`tip event ` threshold is defined within this range. For some use-cases the full hardware range is not suitable, it may require either too light a pressure for the user to interact or it may require too hard a pressure before the logical maximum is reached. libinput provides the **libinput_tablet_tool_config_pressure_range_set()** function that allows reducing the usable range of the tablet:: hw minimum hw maximum hw range: |----------|-------------------------------| adjusted range: |------|---------------------| logical range: |----|---------------------| 0.0 | 1.0 Tip A reduced range as shown above will result in - all hw pressure below the new minimum to register as logical pressure ``0.0`` - all hw pressure above the new maximum to register as logical pressure ``1.0`` - the tip event threshold to be relative to the new minimum In other words, adjusting the pressure range of a tablet tool is equivalent to reducing the hardware range of said tool. Note that where a custom pressure range is set, detection of :ref:`tablet-pressure-offset` is disabled. .. _tablet-serial-numbers: ------------------------------------------------------------------------------ Tracking unique tools ------------------------------------------------------------------------------ Some tools provide hardware information that enables libinput to uniquely identify the physical device. For example, tools compatible with the Wacom Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely identifiable through a serial number. libinput does not specify how a tool can be identified uniquely, a caller should use **libinput_tablet_tool_is_unique()** to check if the tool is unique. libinput creates a struct libinput_tablet_tool on the first proximity in of this tool. By default, this struct is destroyed on proximity out and re-initialized on the next proximity in. If a caller keeps a reference to the tool by using **libinput_tablet_tool_ref()** libinput re-uses this struct whenever that same physical tool comes into proximity on any tablet recognized by libinput. It is possible to attach tool-specific virtual state to the tool. For example, a graphics program such as the GIMP may assign a specific color to each tool, allowing the artist to use the tools like physical pens of different color. In multi-tablet setups it is also possible to track the tool across devices. If the tool does not have a unique identifier, libinput creates a single struct libinput_tablet_tool per tool type on each tablet the tool is used on. .. _tablet-tool-types: ------------------------------------------------------------------------------ Vendor-specific tablet tool types ------------------------------------------------------------------------------ libinput supports a number of high-level tool types that describe the general interaction expected with the tool. For example, a user would expect a tool of type **LIBINPUT_TABLET_TOOL_TYPE_PEN** to interact with a graphics application taking pressure and tilt into account. The default virtual tool assigned should be a drawing tool, e.g. a virtual pen or brush. A tool of type **LIBINPUT_TABLET_TOOL_TYPE_ERASER** would normally be mapped to an eraser-like virtual tool. See **libinput_tablet_tool_type** for the list of all available tools. Vendors may provide more fine-grained information about the tool in use by adding a hardware-specific tool ID. libinput provides this ID to the caller with **libinput_tablet_tool_get_tool_id()** but makes no promises about the content or format of the ID. libinput currently supports Wacom-style tool IDs as provided on the Wacom Intuos 3, 4, 5, Wacon Cintiq and Wacom Intuos Pro series. The tool ID can be used to distinguish between e.g. a Wacom Classic Pen or a Wacom Pro Pen. It is the caller's responsibility to interpret the tool ID. .. _tablet-bounds: ------------------------------------------------------------------------------ Out-of-bounds motion events ------------------------------------------------------------------------------ Some tablets integrated into a screen (e.g. Wacom Cintiq 24HD, 27QHD and 13HD series, etc.) have a sensor larger than the display area. libinput uses the range advertised by the kernel as the valid range unless device-specific quirks are present. Events outside this range will produce coordinates that may be negative or larger than the tablet's width and/or height. It is up to the caller to ignore these events. .. figure:: tablet-out-of-bounds.svg :align: center Illustration of the out-of-bounds area on a tablet In the image above, the display area is shown in black. The red area around the display illustrates the sensor area that generates input events. Events within this area will have negative coordinate or coordinates larger than the width/height of the tablet. If events outside the logical bounds of the input area are scaled into a custom range with **libinput_event_tablet_tool_get_x_transformed()** and **libinput_event_tablet_tool_get_y_transformed()** the resulting value may be less than 0 or larger than the upper range provided. It is up to the caller to test for this and handle or ignore these events accordingly. .. _tablet-pad-buttons: ------------------------------------------------------------------------------ Tablet pad button numbers ------------------------------------------------------------------------------ Tablet Pad buttons are numbered sequentially, starting with button 0. Thus button numbers returned by **libinput_event_tablet_pad_get_button_number()** have no semantic meaning, a notable difference to the button codes returned by other libinput interfaces (e.g. **libinput_event_tablet_tool_get_button()**). The Linux kernel requires all input events to have semantic event codes, but generic buttons like those on a pad cannot easily be assigned semantic codes. The kernel supports generic codes in the form of BTN_0 through to BTN_9 and additional unnamed space up until code 0x10f. Additional generic buttons are available as BTN_A in the range dedicated for gamepads and joysticks. Thus, tablet with a large number of buttons have to map across two semantic ranges, have to use unnamed kernel button codes or risk leaking into an unrelated range. libinput transparently maps the kernel event codes into a sequential button range on the pad. Callers should use external sources like libwacom to associate button numbers to their position on the tablet. Some buttons may have expected default behaviors. For example, on Wacom Intuos Pro series tablets, the button inside the touch ring is expected to switch between modes, see :ref:`tablet-pad-modes`. Callers should use external sources like libwacom to identify which buttons have semantic behaviors. .. _tablet-left-handed: ------------------------------------------------------------------------------ Tablets in left-handed mode ------------------------------------------------------------------------------ Left-handed mode on tablet devices usually means rotating the physical tablet by 180 degrees to move the tablet pad button area to right side of the tablet. When left-handed mode is enabled on a tablet device (see **libinput_device_config_left_handed_set()**) the tablet tool and tablet pad behavior changes. In left-handed mode, the tools' axes are adjusted so that the origin of each axis remains the logical north-east of the physical tablet. For example, the x and y axes are inverted and the positive x/y coordinates are down/right of the top-left corner of the tablet in its current orientation. On a tablet pad, the ring and strip are similarly adjusted. The origin of the ring and strips remain the top-most point. .. figure:: tablet-left-handed.svg :align: center Tablet axes in right- and left-handed mode Pad buttons are not affected by left-handed mode; the number of each button remains the same even when the perceived physical location of the button changes. This is a conscious design decision: - Tablet pad buttons do not have intrinsic semantic meanings. Re-ordering the button numbers would not change any functionality. - Button numbers should not be exposed directly to the user but handled in the intermediate layers. Re-ordering button numbers thus has no user-visible effect. - Re-ordering button numbers may complicate the intermediate layers. Left-handed mode is only available on some tablets, some tablets are symmetric and thus do not support left-handed mode. libinput requires libwacom to determine if a tablet is capable of being switched to left-handed mode. .. _tablet-pad-modes: ------------------------------------------------------------------------------ Tablet pad modes ------------------------------------------------------------------------------ Tablet pad modes are virtual groupings of button, ring and strip functionality. A caller may assign different functionalities depending on the mode the tablet is in. For example, in mode 0 the touch ring may emulate scrolling, in mode 1 the touch ring may emulate zooming, etc. libinput handles the modes and mode switching but does not assign specific functionality to buttons, rings or strips based on the mode. It is up to the caller to decide whether the mode only applies to buttons, rings and strips or only to rings and strips (this is the case with the Wacom OS X and Windows driver). The availability of modes on a touchpad usually depends on visual feedback such as LEDs around the touch ring. If no visual feedback is available, only one mode may be available. Mode switching is controlled by libinput and usually toggled by one or more buttons on the device. For example, on the Wacom Intuos 4, 5, and Pro series tablets the mode button is the button centered in the touch ring and toggles the modes sequentially. On the Wacom Cintiq 24HD the three buttons next to each touch ring allow for directly changing the mode to the desired setting. Multiple modes may exist on the tablet, libinput uses the term "mode group" for such groupings of buttons that share a mode and mode toggle. For example, the Wacom Cintiq 24HD has two separate mode groups, one for the left set of buttons, strips, and touch rings and one for the right set. libinput handles the mode groups independently and returns the mode for each button as appropriate. The mode group is static for the lifetime of the device. .. figure:: tablet-intuos-modes.svg :align: center Modes on an Intuos Pro-like tablet In the image above, the Intuos Pro-like tablet provides 4 LEDs to indicate the currently active modes. The button inside the touch ring cycles through the modes in a clockwise fashion. The upper-right LED indicates that the currently active mode is 1, based on 0-indexed mode numbering. **libinput_event_tablet_pad_get_mode()** would thus return 1 for all button and ring events on this tablet. When the center button is pressed, the mode switches to mode 2, the LED changes to the bottom-right and **libinput_event_tablet_pad_get_mode()** returns 2 for the center button event and all subsequent events. .. figure:: tablet-cintiq24hd-modes.svg :align: center Modes on an Cintiq 24HD-like tablet In the image above, the Cintiq 24HD-like tablet provides 3 LEDs on each side of the tablet to indicate the currently active mode for that group of buttons and the respective ring. The buttons next to the touch ring select the mode directly. The two LEDs indicate that the mode for the left set of buttons is currently 0, the mode for the right set of buttons is currently 1, based on 0-indexed mode numbering. **libinput_event_tablet_pad_get_mode()** would thus return 0 for all button and ring events on the left and 1 for all button and ring events on the right. When one of the three mode toggle buttons on the right is pressed, the right mode switches to that button's mode but the left mode remains unchanged. .. _tablet-touch-arbitration: ------------------------------------------------------------------------------ Tablet touch arbitration ------------------------------------------------------------------------------ "Touch arbitration" is the terminology used when touch events are suppressed while the pen is in proximity. Since it is almost impossible to use a stylus or other tool without triggering touches with the hand holding the tool, touch arbitration serves to reduce the number of accidental inputs. The wacom kernel driver currently provides touch arbitration but for other devices arbitration has to be done in userspace. libinput uses the **libinput_device_group** to decide on touch arbitration and automatically discards touch events whenever a tool is in proximity. The exact behavior is device-dependent. .. _tablet-area: ------------------------------------------------------------------------------ Tablet area ------------------------------------------------------------------------------ External tablet devices such as e.g. the Wacom Intuos series can be configured to reduce the available logical input area. Typically the logical input area is equivalent to the physical input area but it can be reduced with the **libinput_device_config_area_set_rectangle()** call. Once reduced, input events outside the logical input area are ignored and the logical input area acts as if it represented the extents of the physical tablet. .. figure:: tablet-area.svg :align: center Tablet area configuration example In the image above, the area is set to the rectangle 0.25/0.25 to 0.5/0.75. Even though the tool is roughly at the physical position ``0.5 * width`` and ``0.75 * height``, the return values of **libinput_event_tablet_tool_get_x_transformed()** and **libinput_event_tablet_tool_get_y_transformed()** would be close to the maximum provided in this call. The size of the tablet reported by **libinput_device_get_size()** always reflects the physical area, not the logical area. libinput-1.28.1/doc/user/tapping.rst000066400000000000000000000122431477265155700173750ustar00rootroot00000000000000.. _tapping: ============================================================================== Tap-to-click behaviour ============================================================================== "Tapping" or "tap-to-click" is the name given to the behavior where a short finger touch down/up sequence maps into a button click. This is most commonly used on touchpads, but may be available on other devices. libinput implements tapping for one, two, and three fingers, where supported by the hardware, and maps those taps into a left, right, and middle button click, respectively. This mapping can be switched to left, middle and right through configuration. Not all devices support three fingers, libinput will support tapping up to whatever is supported by the hardware. libinput does not support four-finger taps or any tapping with more than four fingers, even though some hardware can distinguish between that many fingers. .. _tapping_default: ------------------------------------------------------------------------------ Tap-to-click default setting ------------------------------------------------------------------------------ Tapping is **disabled** by default on most devices, see :commit:`2219c12c3` because: - if you don't know that tapping is a thing (or enabled by default), you get spurious button events that make the desktop feel buggy. - if you do know what tapping is and you want it, you usually know where to enable it, or at least you can search for it. Tapping is **enabled** by default on devices where tapping is the only method to trigger button clicks. This includes devices without physical buttons such as touch-capable graphics tablets. .. note:: Unfortunately due to the current API design, devices that require tapping effectively prevent us from changing this default. For details see `this comment `_. Tapping can be enabled/disabled on a per-device basis. See **libinput_device_config_tap_set_enabled()** for details. .. _tapndrag: ------------------------------------------------------------------------------ Tap-and-drag ------------------------------------------------------------------------------ libinput also supports "tap-and-drag" where a tap immediately followed by a finger down and that finger being held down emulates a button press. Moving the finger around can thus drag the selected item on the screen. Tap-and-drag is optional and can be enabled or disabled with **libinput_device_config_tap_set_drag_enabled()**. Most devices have tap-and-drag enabled by default. .. note:: Dragging is always done with one finger. The number of fingers on the initial tap decide the type of button click. For example, to middle-click drag, tap with three fingers followed by a single-finger drag. Also optional is a feature called "drag lock". With drag lock disabled, lifting the finger will stop any drag process. When enabled, the drag process continues even after lifting a finger but can be ended with an additional tap. If timeout-based drag-locks are enabled the drag process will also automatically end once the finger has been lifted for an implementation-specific timeout. Drag lock can be enabled and disabled with **libinput_device_config_tap_set_drag_lock_enabled()**. Note that drag lock only applies if tap-and-drag is enabled. .. figure:: tap-n-drag.svg :align: center Tap-and-drag process The above diagram explains the process, a tap (a) followed by a finger held down (b) starts the drag process and logically holds the left mouse button down. A movement of the finger (c) will drag the selected item until the finger is released (e). If needed and drag lock is enabled, the finger's position can be reset by lifting and quickly setting it down again on the touchpad (d). This will be interpreted as continuing move and is especially useful on small touchpads or with slow pointer acceleration. If drag lock is enabled, the release of the mouse buttons after the finger release (e) is triggered by a timeout. To release the button immediately, simply tap again (f). If drag lock is enabled in sticky mode there is no timeout after releasing a finger and an extra tap is required to release the button. If two fingers are supported by the hardware, a second finger can be used to drag while the first is held in-place. .. _tap_constraints: ------------------------------------------------------------------------------ Constraints while tapping ------------------------------------------------------------------------------ A couple of constraints apply to the contact to be converted into a press, the most common ones are: - the touch down and touch up must happen within an implementation-defined timeout - if a finger moves more than an implementation-defined distance while in contact, it's not a tap - tapping within :ref:`clickpad software buttons ` may not trigger an event - a tap not meeting required pressure thresholds can be ignored as accidental touch - a tap exceeding certain pressure thresholds can be ignored (see :ref:`palm_detection`) - a tap on the edges of the touchpad can usually be ignored (see :ref:`palm_detection`) libinput-1.28.1/doc/user/test-suite.rst000066400000000000000000000206721477265155700200460ustar00rootroot00000000000000.. _test-suite: ============================================================================== libinput test suite ============================================================================== libinput's primary test suite can be invoked with :: $ sudo ./builddir/libinput-test-suite When developing libinput, the ``libinput-test-suite`` should always be run to check for behavior changes and/or regressions. For quick iteration, the number of tests to run can be filtered, see :ref:`test-filtering`. This allows for developers to verify a subset of tests (e.g. touchpad tap-to-click) while hacking on that specific feature and only run the full suite when development is done finished. .. note:: The test suite relies on udev and the kernel, specifically uinput. It creates virtual input devices and replays the events. This may interfere with your running session. The test suite is not suitable for running inside containers. In addition, libinput ships with a set of (primarily janitorial) tests that must pass for any merge request. These tests are invoked by calling ``meson test -C builddir`` (or ``ninja test``). The ``libinput-test-suite`` is part of that test set by default. The upstream CI runs all these tests and is run for every merge request. .. _test-job-control: ------------------------------------------------------------------------------ Job control in the test suite ------------------------------------------------------------------------------ The test suite runner has a make-like job control enabled by the ``-j`` or ``--jobs`` flag and will fork off as many parallel processes as given by this flag. The default if unspecified is 8. When debugging a specific test case failure it is recommended to employ test filtures (see :ref:`test-filtering`) and disable parallel tests. The test suite automatically disables parallel make when run in gdb. .. _test-config: ------------------------------------------------------------------------------ X.Org config to avoid interference ------------------------------------------------------------------------------ uinput devices created by the test suite are usually recognised by X as input devices. All events sent through these devices will generate X events and interfere with your desktop. Copy the file ``$srcdir/test/50-litest.conf`` into your ``/etc/X11/xorg.conf.d`` and restart X. This will ignore any litest devices and thus not interfere with your desktop. .. _test-root: ------------------------------------------------------------------------------ Permissions required to run tests ------------------------------------------------------------------------------ Most tests require the creation of uinput devices and access to the resulting ``/dev/input/eventX`` nodes. Some tests require temporary udev rules. **This usually requires the tests to be run as root**. If not run as root, the test suite runner will exit with status 77, an exit status interpreted as "skipped". .. _test-filtering: ------------------------------------------------------------------------------ Selective running of tests ------------------------------------------------------------------------------ litest's tests are grouped into test groups, test names and devices. A test group is e.g. "touchpad:tap" and incorporates all tapping-related tests for touchpads. Each test function is (usually) run with one or more specific devices. The ``--list`` commandline argument shows the list of suites and tests. This is useful when trying to figure out if a specific test is run for a device. :: $ ./builddir/libinput-test-suite --list ... pointer:left-handed: pointer_left_handed_during_click_multiple_buttons: trackpoint ms-surface-cover mouse-wheelclickcount mouse-wheelclickangle low-dpi-mouse mouse-roccat mouse-wheel-tilt mouse logitech-trackball cyborg-rat magicmouse pointer_left_handed_during_click: trackpoint ms-surface-cover mouse-wheelclickcount mouse-wheelclickangle low-dpi-mouse mouse-roccat mouse-wheel-tilt mouse logitech-trackball cyborg-rat litest-magicmouse-device pointer_left_handed: trackpoint ms-surface-cover mouse-wheelclickcount mouse-wheelclickangle low-dpi-mouse mouse-roccat mouse-wheel-tilt mouse ... In the above example, the "pointer:left-handed" suite contains multiple tests, e.g. "pointer_left_handed_during_click" (this is also the function name of the test, making it easy to grep for). This particular test is run for various devices including the trackpoint device and the magic mouse device. The "no device" entry signals that litest does not instantiate a uinput device for a specific test (though the test itself may instantiate one). The ``--filter-test`` argument enables selective running of tests through basic shell-style function name matching. For example: :: $ ./builddir/libinput-test-suite --filter-test="*1fg_tap*" The ``--filter-device`` argument enables selective running of tests through basic shell-style device name matching. The device names matched are the litest-specific shortnames, see the output of ``--list``. For example: :: $ ./builddir/libinput-test-suite --filter-device="synaptics*" The ``--filter-group`` argument enables selective running of test groups through basic shell-style test group matching. The test groups matched are litest-specific test groups, see the output of ``--list``. For example: :: $ ./builddir/libinput-test-suite --filter-group="touchpad:*hover*" The ``--filter-device`` and ``--filter-group`` arguments can be combined with ``--list`` to show which groups and devices will be affected. .. _test-verbosity: ------------------------------------------------------------------------------ Controlling test output ------------------------------------------------------------------------------ Each test supports the ``--verbose`` commandline option to enable debugging output, see **libinput_log_set_priority()** for details. The ``LITEST_VERBOSE`` environment variable, if set, also enables verbose mode. :: $ ./builddir/libinput-test-suite --verbose $ LITEST_VERBOSE=1 meson test -C builddir .. _test-installed: ------------------------------------------------------------------------------ Installing the test suite ------------------------------------------------------------------------------ If libinput is configured to install the tests, the test suite is available as the ``libinput test-suite`` command. When run as installed binary, the behavior of the test suite changes: - the ``libinput.so`` used is the one in the library lookup paths - no system-wide quirks are installed by the test suite, only those specific to the test devices - test device-specific quirks are installed in the system-wide quirks directory, usually ``/usr/share/libinput/``. It is not advisable to run ``libinput test-suite`` on a production machine. Data loss may occur. The primary use-case for the installed test suite is verification of distribution composes. .. note:: The ``prefix`` is still used by the test suite. For verification of a system package, the test suite must be configured with the same prefix. To configure libinput to install the tests, use the ``-Dinstall-tests=true`` meson option:: $ meson setup builddir -Dtests=true -Dinstall-tests=true .. _test-meson-suites: ------------------------------------------------------------------------------ Meson test suites ------------------------------------------------------------------------------ This section is primarily of interest to distributors that want to run test or developers working on libinput's CI. Tests invoked by ``meson test`` are grouped into test suites, the test suite names identify when the respective test can be run: - ``valgrind``: tests that can be run under valgrind (in addition to a normal run) - ``root``: tests that must be run as root - ``hardware``: tests that require a VM or physical machine - ``all``: all tests, only needed because of `meson bug 5340 `_ The suite names can be provided as filters to ``meson test --suite=`` or ``meson test --no-suite=``. For example, if running a container-based CI, you may specify the test suites as: :: $ meson test --no-suite=machine # only run container-friendly tests $ meson test --suite=valgrind --setup=valgrind # run all valgrind-compatible tests $ meson test --no-suite=root # run all tests not requiring root These suites are subject to change at any time. libinput-1.28.1/doc/user/timestamps.rst000066400000000000000000000032331477265155700201200ustar00rootroot00000000000000 .. _timestamps: ============================================================================== Timestamps ============================================================================== .. _event_timestamps: ------------------------------------------------------------------------------ Event timestamps ------------------------------------------------------------------------------ Most libinput events provide a timestamp in millisecond and/or microsecond resolution. These timestamp usually increase monotonically, but libinput does not guarantee that this always the case. In other words, it is possible to receive an event with a timestamp earlier than the previous event. For example, if a touchpad has :ref:`tapping` enabled, a button event may have a lower timestamp than an event from a different device. Tapping requires the use of timeouts to detect multi-finger taps and/or :ref:`tapndrag`. Consider the following event sequences from a touchpad and a mouse: :: Time Touchpad Mouse --------------------------------- t1 finger down t2 finger up t3 movement t4 tap timeout For this event sequence, the first event to be sent to a caller is in response to the mouse movement: an event of type **LIBINPUT_EVENT_POINTER_MOTION** with the timestamp t3. Once the timeout expires at t4, libinput generates an event of **LIBINPUT_EVENT_POINTER_BUTTON** (press) with a timestamp t1 and an event **LIBINPUT_EVENT_POINTER_BUTTON** (release) with a timestamp t2. Thus, the caller gets events with timestamps in the order t3, t1, t2, despite t3 > t2 > t1. libinput timestamps use **CLOCK_MONOTONIC**. libinput-1.28.1/doc/user/tools.rst000066400000000000000000000405631477265155700171010ustar00rootroot00000000000000.. _tools: ============================================================================== Helper tools ============================================================================== libinput provides a ``libinput`` tool to query state and events. This tool takes a subcommand as argument, similar to the **git** command. A full explanation of the various commands available in the libinput tool is available in the **libinput(1)** man page. The most common tools used are: - ``libinput list-devices``: to list locally available devices as seen by libinput, see :ref:`here ` - ``libinput list-kernel-devices``: to list locally available devices as seen by the kernel, see :ref:`here ` - ``libinput debug-events``: to monitor and debug events, see :ref:`here ` - ``libinput debug-gui``: to visualize events, see :ref:`here ` - ``libinput record``: to record an event sequence for replaying, see :ref:`here ` - ``libinput measure``: measure properties on a kernel device, see :ref:`here ` - ``libinput analyze``: analyse event recordings from a kernel device, see :ref:`here ` - ``libinput quirks``: show quirks assigned to a device, see :ref:`here ` Most of the tools must be run as root to have access to the kernel's ``/dev/input/event*`` device files. .. _libinput-list-devices: ------------------------------------------------------------------------------ libinput list-devices ------------------------------------------------------------------------------ The ``libinput list-devices`` command shows information about devices recognized by libinput and can help identifying why a device behaves different than expected. For example, if a device does not show up in the output, it is not a supported input device. .. note:: This tool does **not** show your desktop's configuration, just the libinput built-in defaults. :: $ sudo libinput list-devices [...] Device: SynPS/2 Synaptics TouchPad Kernel: /dev/input/event4 Group: 9 Seat: seat0, default Size: 97.33x66.86mm Capabilities: pointer Tap-to-click: disabled Tap drag lock: disabled Left-handed: disabled Nat.scrolling: disabled Middle emulation: n/a Calibration: n/a Scroll methods: *two-finger Click methods: *button-areas clickfinger [...] The above listing shows example output for a touchpad. The ``libinput list-devices`` command lists general information about the device (the kernel event node) but also the configuration options. If an option is ``n/a`` it does not exist on this device. Otherwise, the tool will show the default configuration for this device, for options that have more than a binary state all available options are listed, with the default one prefixed with an asterisk (``*``). In the example above, the default click method is button-areas but clickfinger is available. .. note:: This tool is intended for human-consumption and may change its output at any time. .. _libinput-list-kernel-devices: ------------------------------------------------------------------------------ libinput list-kernel-devices ------------------------------------------------------------------------------ The ``libinput list-kernel-devices`` command shows the devices known by **the kernel**. This command can help identify issues when a device is not handled by libinput. :: $ libinput list-kernel-devices /dev/input/event0: Sleep Button /dev/input/event1: Power Button /dev/input/event2: Power Button /dev/input/event3: Microsoft Microsoft® 2.4GHz Transceiver v9.0 /dev/input/event4: Microsoft Microsoft® 2.4GHz Transceiver v9.0 Mouse [...] In some cases, knowing about the HID devices behind the kernel's event nodes can be useful. To list HID devices, supply the ``--hid`` commandline flag: :: $ libinput list-kernel-devices --hid hid: - name: 'Logitech Gaming Mouse G303' id: '046d:c080' driver: 'hid-generic' hidraw: ['/dev/hidraw6'] evdev: ['/dev/input/event13'] - name: 'Logitech Gaming Mouse G303' id: '046d:c080' driver: 'hid-generic' hidraw: ['/dev/hidraw7'] evdev: ['/dev/input/event14'] - name: 'Microsoft Microsoft® 2.4GHz Transceiver v9.0' id: '045e:07a5' driver: 'hid-generic' hidraw: ['/dev/hidraw0'] evdev: ['/dev/input/event3'] .. note:: This tool is intended for human-consumption and may change its output at any time. .. _libinput-debug-events: ------------------------------------------------------------------------------ libinput debug-events ------------------------------------------------------------------------------ The ``libinput debug-events`` command prints events from devices and can help to identify why a device behaves different than expected. :: $ sudo libinput debug-events --enable-tapping --set-click-method=clickfinger All configuration options (enable/disable tapping, etc.) are available as commandline arguments. To reproduce the event sequence as your desktop session sees it, ensure that all options are turned on or off as required. See the **libinput-debug-events(1)** man page or the ``--help`` output for information about the available options. .. note:: When submitting a bug report, always use the ``--verbose`` flag to get additional information: ``libinput debug-events --verbose `` An example output from this tool may look like the snippet below. :: $ sudo libinput debug-events --enable-tapping --set-click-method=clickfinger -event2 DEVICE_ADDED Power Button seat0 default group1 cap:k -event5 DEVICE_ADDED Video Bus seat0 default group2 cap:k -event0 DEVICE_ADDED Lid Switch seat0 default group3 cap:S -event1 DEVICE_ADDED Sleep Button seat0 default group4 cap:k -event4 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=3 seat0 default group5 cap: -event11 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=7 seat0 default group6 cap: -event12 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=8 seat0 default group7 cap: -event13 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=9 seat0 default group8 cap: -event14 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=10 seat0 default group9 cap: -event19 DEVICE_ADDED Integrated Camera: Integrated C seat0 default group10 cap:k -event15 DEVICE_ADDED HDA Intel PCH Dock Mic seat0 default group11 cap: -event16 DEVICE_ADDED HDA Intel PCH Mic seat0 default group12 cap: -event17 DEVICE_ADDED HDA Intel PCH Dock Headphone seat0 default group13 cap: -event18 DEVICE_ADDED HDA Intel PCH Headphone seat0 default group14 cap: -event6 DEVICE_ADDED ELAN Touchscreen seat0 default group15 cap:t size 305x172mm ntouches 10 calib -event3 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group16 cap:k -event20 DEVICE_ADDED SynPS/2 Synaptics TouchPad seat0 default group17 cap:pg size 100x76mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on -event21 DEVICE_ADDED TPPS/2 IBM TrackPoint seat0 default group18 cap:p left scroll-nat scroll-button -event7 DEVICE_ADDED ThinkPad Extra Buttons seat0 default group19 cap:k -event20 POINTER_MOTION +3.62s 2.72/ -0.93 event20 POINTER_MOTION +3.63s 1.80/ -1.42 event20 POINTER_MOTION +3.65s 6.16/ -2.28 event20 POINTER_MOTION +3.66s 6.42/ -1.99 event20 POINTER_MOTION +3.67s 8.99/ -1.42 event20 POINTER_MOTION +3.68s 11.30/ 0.00 event20 POINTER_MOTION +3.69s 21.32/ 1.42 .. _libinput-debug-gui: ------------------------------------------------------------------------------ libinput debug-gui ------------------------------------------------------------------------------ A simple GTK-based graphical tool that shows the behavior and location of touch events, pointer motion, scroll axes and gestures. Since this tool gathers data directly from libinput, it is thus suitable for pointer-acceleration testing. .. note:: This tool does **not** use your desktop's configuration, just the libinput built-in defaults. :: $ sudo libinput debug-gui --enable-tapping As with :ref:`libinput-debug-events`, all options must be specified on the commandline to emulate the correct behavior. See the **libinput-debug-gui(1)** man page or the ``--help`` output for information about the available options. .. _libinput-record: ------------------------------------------------------------------------------ libinput record and libinput replay ------------------------------------------------------------------------------ .. note:: For libinput versions 1.10 and older, use :ref:`evemu`. The ``libinput record`` command records the **kernel** events from a specific device node. The recorded sequence can be replayed with the ``libinput replay`` command. This pair of tools is crucial to capturing bugs and reproducing them on a developer's machine. .. graphviz:: libinput-record.gv :align: center The recorded events are **kernel events** and independent of the libinput context. libinput does not need to be running, it does not matter whether a user is running X.Org or Wayland or even what version of libinput is currently running. The use of the tools is straightforward, just run without arguments, piping the output into a file: :: $ sudo libinput record > touchpad.yml Available devices: /dev/input/event0: Lid Switch /dev/input/event1: Sleep Button /dev/input/event2: Power Button /dev/input/event3: AT Translated Set 2 keyboard /dev/input/event4: ThinkPad Extra Buttons /dev/input/event5: ELAN Touchscreen /dev/input/event6: Video Bus /dev/input/event7: HDA Intel HDMI HDMI/DP,pcm=3 /dev/input/event8: HDA Intel HDMI HDMI/DP,pcm=7 /dev/input/event9: HDA Intel HDMI HDMI/DP,pcm=8 /dev/input/event10: HDA Intel HDMI HDMI/DP,pcm=9 /dev/input/event11: HDA Intel HDMI HDMI/DP,pcm=10 /dev/input/event12: HDA Intel PCH Dock Mic /dev/input/event13: HDA Intel PCH Mic /dev/input/event14: HDA Intel PCH Dock Headphone /dev/input/event15: HDA Intel PCH Headphone /dev/input/event16: Integrated Camera: Integrated C /dev/input/event17: SynPS/2 Synaptics TouchPad /dev/input/event18: TPPS/2 IBM TrackPoint Select the device event number: 17 /dev/input/event17 recording to stdout Without arguments, ``libinput record`` displays the available devices and lets the user select one. Supply the number (17 in this case for ``/dev/input/event17``) and the tool will print the device information and events to the file it is redirected to. More arguments are available, see the **libinput-record(1)** man page. .. note:: When reproducing a bug that crashes libinput, run inside ``screen`` or ``tmux``. Reproduce the bug, ctrl+c and attach the output file to a bug report. For data protection, ``libinput record`` obscures key codes by default, any alphanumeric key shows up as letter "a". .. warning:: The longer the recording, the harder it is to identify the event sequence triggering the bug. Please keep the event sequence as short as possible. The recording can be replayed with the ``libinput replay`` command: :: $ sudo libinput replay touchpad.yml SynPS/2 Synaptics TouchPad: /dev/input/event19 Hit enter to start replaying ``libinput replay`` creates a new virtual device based on the description in the log file. Hitting enter replays the event sequence once and the tool stops once all events have been replayed. Hitting enter again replays the sequence again, Ctrl+C stops it and removes the virtual device. Users are advised to always replay a recorded event sequence to ensure they have captured the bug. More arguments are available, see the **libinput-record(1)** and **libinput-replay(1)** man pages. .. _libinput-record-autorestart: .............................................................................. libinput record's autorestart feature .............................................................................. ``libinput record`` often collects thousands of events per minute. However, the output of ``libinput record`` usually needs to be visually inspected or replayed in realtime on a developer machine. It is thus imperative that the event log is kept as short as possible. For bugs that are difficult to reproduce use ``libinput record --autorestart=2 --output-file=recording.yml``. All events will be recorded to a file named ``recording.yml.`` and whenever the device does not send events for 2 seconds, a new file is created. This helps to keep individual recordings short. To use the ``--autorestart`` option correctly: - run ``libinput record --autorestart=2 --output-file=.yml``. You may provide a timeout other than 2 if needed. - use the device to reproduce the bug, pausing frequently for 2s and longer to rotate the logs - when the bug triggers, **immediately stop using the device** and wait several seconds for the log to rotate - Ctrl+C the ``libinput record`` process without using the device again. Attach the **last recording** to the bug report. If you have to use the recorded device to stop ``libinput record`` (e.g. to switch windows), remember that this will cause a new recording to be created. Thus, attach the **second-to-last recording** to the bug report because this one contains the bug trigger. .. _libinput-record-multiple: .............................................................................. Recording multiple devices at once .............................................................................. In some cases, an interaction between multiple devices is the cause for a specific bug. For example, a touchpad may not work in response to keyboard events. To accurately reproduce this sequence, the timing between multiple devices must be correct and we need to record the events in one go. ``libinput record`` has a ``--multiple`` argument to record multiple devices at once. Unlike the normal invocation, this one requires a number of arguments: :: $ sudo libinput record --multiple --output-file=touchpad-bug.yml /dev/input/event17 /dev/input/event3 recording to 'touchpad-bug.yml' As seen above, a user must specify ``--multiple`` and the ``--output-file``. Finally, all devices to be recorded must be specified on the commandline as well. Replaying events is the same as for a single recording: :: $ sudo libinput replay touchpad-bug.yml .. _libinput-measure: ------------------------------------------------------------------------------ Measuring device properties with libinput measure ------------------------------------------------------------------------------ The ``libinput measure`` tool is a multiplexer for various sub-tools that can measure specific properties on the device. These tools generally measure one thing and one thing only and their usage is highly specific to the tool. Please see the **libinput-measure(1)** man page for information about what tools are available and the man page for each respective tool. .. _libinput-analyze: ------------------------------------------------------------------------------ Analyzing device events with libinput analyze ------------------------------------------------------------------------------ The ``libinput analyze`` tool is a multiplexer for various sub-tools that can analyze input events previously recorded from a device. Please see the **libinput-analyze(1)** man page for information about what tools are available and the man page for each respective too. .. _libinput-quirks: ------------------------------------------------------------------------------ Listing quirks assigned to a device ------------------------------------------------------------------------------ The ``libinput quirks`` tool can show quirks applied for any given device. :: $ libinput quirks list /dev/input/event0 AttrLidSwitchReliability=unreliable If the tool's output is empty, no quirk is applied. See :ref:`device-quirks` for more information. libinput-1.28.1/doc/user/touchpad-jitter.rst000066400000000000000000000100521477265155700210350ustar00rootroot00000000000000.. _touchpad_jitter: ============================================================================== Touchpad jitter ============================================================================== Touchpad jitter describes random movement by a few pixels even when the user's finger is unmoving. libinput has a mechanism called a **hysteresis** to avoid that jitter. When active, movement with in the **hysteresis margin** is discarded. If the movement delta is larger than the margin, the movement is passed on as pointer movement. This is a simplified summary, developers should read the implementation of the hysteresis in ``src/evdev.c``. libinput uses the kernel ``fuzz`` value to determine the size of the hysteresis. Users should override this with a udev hwdb entry where the device itself does not provide the correct value. .. _touchpad_jitter_fuzz_override: ------------------------------------------------------------------------------ Overriding the hysteresis margins ------------------------------------------------------------------------------ libinput provides the debugging tool ``libinput measure fuzz`` to help edit or test a fuzz value. This tool is interactive and provides a udev hwdb entry that matches the device. To check if a fuzz is currently present, simply run without arguments or with the touchpad's device node: :: $ sudo libinput measure fuzz Using Synaptics TM2668-002: /dev/input/event17 Checking udev property... not set Checking axes... x=16 y=16 In the above output, the axis fuzz is set to 16. To set a specific fuzz, run with the ``--fuzz=`` argument. :: $ sudo libinput measure fuzz --fuzz=8 The tool will attempt to construct a hwdb file that matches your touchpad device. Follow the printed prompts. In the ideal case, the tool will provide you with a file that can be submitted to the systemd repo for inclusion. However, hwdb entry creation is difficult to automate and it's likely that the tools fails in doing so, especially if an existing entry is already present. Below is the outline of what a user needs to do to override a device's fuzz value in case the ``libinput measure fuzz`` tool fails. Check with ``udevadm info /sys/class/input/eventX`` (replace your device node number) whether an existing hwdb override exists. If the ``EVDEV_ABS_`` properties are present, the hwdb override exists. Find the file that contains that entry, most likely in ``/etc/udev/hwdb.d`` or ``/usr/lib/udev/hwdb.d``. The content of the property is a set of values in the format ``EVDEV_ABS_00=min:max:resolution:fuzz``. You need to set the ``fuzz`` part, leaving the remainder of the property as-is. Values may be empty, e.g. a property that only sets resolution and fuzz reads as ``EVDEV_ABS_00=::32:8``. If no properties exist, your hwdb.entry should look approximately like this: :: evdev:name:Synaptics TM2668-002:dmi:*:svnLENOVO*:pvrThinkPadT440s*: EVDEV_ABS_00=:::8 EVDEV_ABS_01=:::8 EVDEV_ABS_35=:::8 EVDEV_ABS_36=:::8 Substitute the ``name`` field with the device name (see the output of ``libinput measure fuzz`` and the DMI match content with your hardware. See :ref:`hwdb_modifying` for details. Once the hwdb entry has been modified, added, or created, :ref:`reload the hwdb `. Once reloaded, :ref:`libinput-record` "libinput record" should show the new fuzz value for the axes. Restart the host and libinput should pick up the revised fuzz values. .. _kernel_fuzz: ------------------------------------------------------------------------------ Kernel fuzz ------------------------------------------------------------------------------ A fuzz set on an absolute axis in the kernel causes the kernel to apply hysteresis-like behavior to the axis. Unfortunately, this behavior leads to inconsistent deltas. To avoid this, libinput sets the kernel fuzz on the device to 0 to disable this kernel behavior but remembers what the fuzz was on startup. The fuzz is stored in the ``LIBINPUT_FUZZ_XX`` udev property, on startup libinput will check that property as well as the axis itself. libinput-1.28.1/doc/user/touchpad-jumping-cursors.rst000066400000000000000000000107311477265155700227070ustar00rootroot00000000000000.. _touchpad_jumping_cursor: ============================================================================== Touchpad jumping cursor bugs ============================================================================== A common bug encountered on touchpads is a cursor jump when alternating between fingers on a multi-touch-capable touchpad. For example, after moving the cursor a user may use a second finger in the software button area to physically click the touchpad. Upon setting the finger down, the cursor exhibits a jump towards the bottom left or right, depending on the finger position. When libinput detects a cursor jump it prints a bug warning to the log with the text **"Touch jump detected and discarded."** and a link to this page. .. note:: This warning is ratelimited and will stop appearing after a few times, even if the touchpad jumps continue. In most cases, this is a bug in the firmware (or kernel driver) and to libinput it appears that the touch point moves from its previous position. The pointer jump can usually be seen in the :ref:`libinput record ` output for the device: :: E: 249.206319 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- E: 249.218008 0003 0035 3764 # EV_ABS / ABS_MT_POSITION_X 3764 E: 249.218008 0003 0036 2221 # EV_ABS / ABS_MT_POSITION_Y 2221 E: 249.218008 0003 003a 0065 # EV_ABS / ABS_MT_PRESSURE 65 E: 249.218008 0003 0000 3764 # EV_ABS / ABS_X 3764 E: 249.218008 0003 0001 2216 # EV_ABS / ABS_Y 2216 E: 249.218008 0003 0018 0065 # EV_ABS / ABS_PRESSURE 65 E: 249.218008 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- E: 249.230881 0003 0035 3752 # EV_ABS / ABS_MT_POSITION_X 3752 E: 249.230881 0003 003a 0046 # EV_ABS / ABS_MT_PRESSURE 46 E: 249.230881 0003 0000 3758 # EV_ABS / ABS_X 3758 E: 249.230881 0003 0018 0046 # EV_ABS / ABS_PRESSURE 46 E: 249.230881 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- E: 249.242648 0003 0035 1640 # EV_ABS / ABS_MT_POSITION_X 1640 E: 249.242648 0003 0036 4681 # EV_ABS / ABS_MT_POSITION_Y 4681 E: 249.242648 0003 003a 0025 # EV_ABS / ABS_MT_PRESSURE 25 E: 249.242648 0003 0000 1640 # EV_ABS / ABS_X 1640 E: 249.242648 0003 0001 4681 # EV_ABS / ABS_Y 4681 E: 249.242648 0003 0018 0025 # EV_ABS / ABS_PRESSURE 25 E: 249.242648 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- E: 249.254568 0003 0035 1648 # EV_ABS / ABS_MT_POSITION_X 1648 E: 249.254568 0003 003a 0027 # EV_ABS / ABS_MT_PRESSURE 27 E: 249.254568 0003 0000 1644 # EV_ABS / ABS_X 1644 E: 249.254568 0003 0018 0027 # EV_ABS / ABS_PRESSURE 27 In this recording, the pointer jumps from its position 3752/2216 to 1640/4681 within a single frame. On this particular touchpad, this would represent a physical move of almost 50mm. libinput detects some of these jumps and discards the movement but otherwise continues as usual. If your only encounter with these jumps is the warning printed to the log, libinput functions as intended. When you encounter the warning in the log, please generate a recording of your touchpad with :ref:`libinput record ` and file a bug. See :ref:`reporting_bugs` for more details. Note that it most cases, libinput cannot actually fix the issue. Filing a bug is useful to figure out if there are other factors at play or whether there are heuristics we can employ to reduce the impact. ------------------------------------------------------------------------------ AlpsPS/2 ALPS DualPoint TouchPad jumping to 4095/0 ------------------------------------------------------------------------------ A special case of pointer jumps happens on ``AlpsPS/2 ALPS DualPoint TouchPad`` devices found in the Lenovo ThinkPad E465 and E550 and likely others with the same touchpad hardware. On those devices, the touchpad occasionally sends an event for the second finger to move to position 4095/0 before moving back to the original position. libinput detects this movement and removes it but depending on the interaction this may cause a smaller jump later when the coordinates reset to the new position of the finger. Some more information is available in `Gitlab Issue #492 `__. libinput-1.28.1/doc/user/touchpad-pressure-debugging.rst000066400000000000000000000240571477265155700233470ustar00rootroot00000000000000============================================================================== Debugging touchpad pressure/size ranges ============================================================================== :ref:`Touchpad pressure/size ranges ` depend on :ref:`device-quirks` entry specific to each laptop model. To check if a pressure/size range is already defined for your device, use the :ref:`libinput quirks ` tool: :: $ libinput quirks list /dev/input/event19 If your device does not list any quirks, it probably needs a touch pressure/size range, a palm threshold and a thumb threshold. Start with :ref:`touchpad_pressure_hwdb`, then :ref:`touchpad_touch_size_hwdb`. The respective tools will exit if the required axis is not supported. .. _touchpad_pressure_hwdb: ------------------------------------------------------------------------------ Debugging touchpad pressure ranges ------------------------------------------------------------------------------ This section describes how to determine the touchpad pressure ranges required for a touchpad device and how to add the required :ref:`device-quirks` locally. Note that the quirk is **not public API** and **may change at any time**. Users are advised to :ref:`report a bug ` with the updated pressure ranges when testing has completed. .. note:: Most distributions ship ``libinput measure`` in a separate ``libinput-utils`` package. Use the ``libinput measure touchpad-pressure`` tool provided by libinput. This tool will search for your touchpad device and print some pressure statistics, including whether a touch is/was considered logically down. .. note:: This tool will only work on touchpads with pressure. Example output of the tool is below: :: $ sudo libinput measure touchpad-pressure Using Synaptics TM2668-002: /dev/input/event21 This is an interactive tool Place a single finger on the touchpad to measure pressure values. Check that: - touches subjectively perceived as down are tagged as down - touches with a thumb are tagged as thumb - touches with a palm are tagged as palm If the touch states do not match the interaction, re-run with --touch-thresholds=down:up using observed pressure values. See --help for more options. Press Ctrl+C to exit +-------------------------------------------------------------------------------+ | Thresh | 70 | 60 | 130 | 100 | | +-------------------------------------------------------------------------------+ | Touch | down | up | palm | thumb | min | max | p | avg | median | +-------------------------------------------------------------------------------+ | 178 | x | x | | | 75 | 75 | 0 | 75 | 75 | | 179 | x | x | | | 35 | 88 | 0 | 77 | 81 | | 180 | x | x | | x | 65 | 113 | 0 | 98 | 98 | | 181 | x | x | | x | 50 | 101 | 0 | 86 | 90 | | 182 | x | x | | | 40 | 80 | 0 | 66 | 70 | | 183 | x | | | | 43 | 78 | 78 | | ... The example output shows five completed touch sequences and one ongoing one. For each, the respective minimum and maximum pressure values are printed as well as some statistics. The ``down`` column show that each sequence was considered logically down at some point, two of the sequences were considered thumbs. This is an interactive tool and its output may change frequently. Refer to the **libinput-measure-touchpad-pressure(1)** man page for more details. By default, this tool uses the :ref:`device-quirks` for the pressure range. To narrow down on the best values for your device, specify the 'logically down' and 'logically up' pressure thresholds with the ``--touch-thresholds`` argument: :: $ sudo libinput measure touchpad-pressure --touch-thresholds=10:8 --palm-threshold=20 Interact with the touchpad and check if the output of this tool matches your expectations. .. note:: This is an interactive process. You will need to re-run the tool with varying thresholds until you find the right range for your touchpad. Attaching output logs to a bug will not help, only you with access to the hardware can figure out the correct ranges. Once the thresholds are decided on (e.g. 10 and 8), they can be enabled with :ref:`device-quirks` entry similar to this: :: $> cat /etc/libinput/local-overrides.quirks [Touchpad pressure override] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230* AttrPressureRange=10:8 AttrPalmPressureThreshold=150 AttrThumbPressureThreshold=100 The file name **must** be ``/etc/libinput/local-overrides.quirks``. The The first line is the section name and can be free-form. The ``Match`` directives limit the quirk to your touchpad, make sure the device name matches your device's name (see ``libinput record``'s output). The dmi modalias match should be based on the information in ``/sys/class/dmi/id/modalias``. This modalias should be shortened to the specific system's information, usually system vendor (svn) and product name (pn). Once in place, run the following command to verify the quirk is valid and works for your device: :: $ sudo libinput list-quirks /dev/input/event10 AttrPressureRange=10:8 Replace the event node with the one from your device. If the ``AttrPressureRange`` quirk does not show up, re-run with ``--verbose`` and check the output for any error messages. If the pressure range quirk shows up correctly, restart X or the Wayland compositor and libinput should now use the correct pressure thresholds. The :ref:`tools` can be used to verify the correct functionality first without the need for a restart. Once the pressure ranges are deemed correct, :ref:`report a bug ` to get the pressure ranges into the repository. .. _touchpad_touch_size_hwdb: ------------------------------------------------------------------------------ Debugging touch size ranges ------------------------------------------------------------------------------ This section describes how to determine the touchpad size ranges required for a touchpad device and how to add the required :ref:`device-quirks` locally. Note that the quirk is **not public API** and **may change at any time**. Users are advised to :ref:`report a bug ` with the updated pressure ranges when testing has completed. .. note:: Most distributions ship ``libinput measure`` in a separate ``libinput-utils`` package. Use the ``libinput measure touch-size`` tool provided by libinput. This tool will search for your touchpad device and print some touch size statistics, including whether a touch is/was considered logically down. .. note:: This tool will only work on touchpads with the ``ABS_MT_MAJOR`` axis. Example output of the tool is below: :: $ sudo libinput measure touch-size --touch-thresholds 10:8 --palm-threshold 14 Using ELAN Touchscreen: /dev/input/event5   Ready for recording data. Touch sizes used: 10:8 Palm size used: 14 Place a single finger on the device to measure touch size. Ctrl+C to exit   Sequence: major: [ 9.. 11] minor: [ 7.. 9] Sequence: major: [ 9.. 10] minor: [ 7.. 7] Sequence: major: [ 9.. 14] minor: [ 6.. 9] down Sequence: major: [ 11.. 11] minor: [ 9.. 9] down Sequence: major: [ 4.. 33] minor: [ 1.. 5] down palm The example output shows five completed touch sequences. For each, the respective minimum and maximum pressure values are printed as well as some statistics. The ``down`` and ``palm`` tags show that sequence was considered logically down or a palm at some point. This is an interactive tool and its output may change frequently. Refer to the **libinput-measure-touch-size(1)** man page for more details. By default, this tool uses the :ref:`device-quirks` for the touch size range. To narrow down on the best values for your device, specify the 'logically down' and 'logically up' pressure thresholds with the ``--touch-thresholds`` arguments as in the example above. Interact with the touchpad and check if the output of this tool matches your expectations. .. note:: This is an interactive process. You will need to re-run the tool with varying thresholds until you find the right range for your touchpad. Attaching output logs to a bug will not help, only you with access to the hardware can figure out the correct ranges. Once the thresholds are decided on (e.g. 10 and 8), they can be enabled with :ref:`device-quirks` entry similar to this: :: $> cat /etc/libinput/local-overrides.quirks [Touchpad touch size override] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230* AttrTouchSizeRange=10:8 The first line is the match line and should be adjusted for the device name (see :ref:`libinput record `'s output) and for the local system, based on the information in ``/sys/class/dmi/id/modalias``. The modalias should be shortened to the specific system's information, usually system vendor (svn) and product name (pn). Once in place, run the following command to verify the quirk is valid and works for your device: :: $ sudo libinput list-quirks /dev/input/event10 AttrTouchSizeRange=10:8 Replace the event node with the one from your device. If the ``AttrTouchSizeRange`` quirk does not show up, re-run with ``--verbose`` and check the output for any error messages. If the touch size range property shows up correctly, restart X or the Wayland compositor and libinput should now use the correct thresholds. The :ref:`tools` can be used to verify the correct functionality first without the need for a restart. Once the touch size ranges are deemed correct, :ref:`reporting_bugs` "report a bug" to get the thresholds into the repository. libinput-1.28.1/doc/user/touchpad-pressure.rst000066400000000000000000000062501477265155700214110ustar00rootroot00000000000000.. _touchpad_pressure: ============================================================================== Touchpad pressure-based touch detection ============================================================================== libinput uses the touchpad pressure values and/or touch size values to detect whether a finger has been placed on the touchpad. This is :ref:`kernel_pressure_information` and combines with a libinput-specific hardware database to adjust the thresholds on a per-device basis. libinput uses these thresholds primarily to filter out accidental light touches but the information is also used for some :ref:`palm_detection`. Most devices only support one of either touch pressure or touch size. libinput uses whichever is available but a preference is given to touch size as it provides more specific information. Since most devices only provide one type anyway, this internal preference does not usually matter. Pressure and touch size thresholds are **not** directly configurable by the user. Instead, libinput provides these thresholds for each device where necessary. See :ref:`touchpad_pressure_hwdb` for instructions on how to adjust the pressure ranges and :ref:`touchpad_touch_size_hwdb` for instructions on how to adjust the touch size ranges. .. _kernel_pressure_information: ------------------------------------------------------------------------------ Information provided by the kernel ------------------------------------------------------------------------------ The kernel sends multiple values to inform userspace about a finger touching the touchpad. The most basic is the ``EV_KEY/BTN_TOUCH`` boolean event that simply announces physical contact with the touchpad. The decision when this event is sent is usually made by the kernel driver and may depend on device-specific thresholds. These thresholds are transparent to userspace and cannot be modified. On touchpads where pressure or touch size is not available, libinput uses ``BTN_TOUCH`` to determine when a finger is logically down. Many contemporary touchpad devices provide an absolute pressure axis in addition to ``BTN_TOUCH``. This pressure generally increases as the pressure increases, however few touchpads are capable of detecting true pressure. The pressure value is usually related to the covered area - as the pressure increases a finger flattens and thus covers a larger area. The range provided by the kernel is not mapped to a specific physical range and often requires adjustment. Pressure is sent by the ``ABS_PRESSURE`` axis for single-touch touchpads or ``ABS_MT_PRESSURE`` on multi-touch capable touchpads. Some devices can detect multiple fingers but only provide ``ABS_PRESSURE``. Some devices provide additional touch size information through the ``ABS_MT_TOUCH_MAJOR/ABS_MT_TOUCH_MINOR`` axes and/or the ``ABS_MT_WIDTH_MAJOR/ABS_MT_WIDTH_MINOR`` axes. These axes specifcy the size of the touch ellipse. While the kernel documentation specifies how these axes are supposed to be mapped, few devices forward reliable information. libinput uses these values together with a device-specific :ref:`device-quirks` entry. In other words, touch size detection does not work unless a device quirk is present for the device. libinput-1.28.1/doc/user/touchpad-thumb-detection.rst000066400000000000000000000075611477265155700226420ustar00rootroot00000000000000.. _thumb_detection: ============================================================================== Thumb detection ============================================================================== Thumb detection tries to identify touches triggered by a thumb rather than a pointer-moving finger. This is necessary on :ref:`touchpads_buttons_clickpads` as a finger pressing a button always creates a new touch, causing misinterpretation of gestures. Click-and-drag with two fingers (one holding the button, one moving) would be interpreted as two-finger scrolling without working thumb detection. libinput has built-in thumb detection, partially dependent on hardware-specific capabilities. - :ref:`thumb_pressure` - :ref:`thumb_areas` - :ref:`thumb_speed` Thumb detection uses multiple approaches and the final decision on whether to ignore a thumb depends on the interaction at the time. .. _thumb_pressure: ------------------------------------------------------------------------------ Thumb detection based on pressure or size ------------------------------------------------------------------------------ The simplest form of thumb detection identifies a touch as thumb when the pressure value goes above a certain threshold. This threshold is usually high enough that it cannot be triggered by a finger movement. On touchpads that support the ``ABS_MT_TOUCH_MAJOR`` axes, libinput can perform thumb detection based on the size of the touch ellipse. This works similar to the pressure-based palm detection in that a touch is labelled as palm when it exceeds the (device-specific) touch size threshold. Pressure- and size-based thumb detection depends on the location of the thumb and usually only applies within the :ref:`thumb_areas`. For some information on how to detect pressure on a touch and debug the pressure ranges, see :ref:`touchpad_pressure`. Pressure- and size-based thumb detection require thresholds set in the :ref:`device-quirks`. .. _thumb_areas: ------------------------------------------------------------------------------ Thumb detection areas ------------------------------------------------------------------------------ Pressure and size readings are unreliable at the far bottom of the touchpad. A thumb hanging mostly off the touchpad will have a small surface area. libinput has a definitive thumb zone where any touch is considered a thumb. Immediately above that area is the area where libinput will label a thumb as such if the pressure or size thresholds are exceeded. .. figure:: thumb-detection.svg :align: center The picture above shows the two detection areas. In the larger (light red) area, a touch is labelled as thumb when it exceeds a device-specific pressure threshold. In the lower (dark red) area, a touch is always labelled as thumb. Moving outside the areas generally releases the thumb from being a thumb. .. _thumb_speed: ------------------------------------------------------------------------------ Thumb movement based on speed ------------------------------------------------------------------------------ Regular interactions with thumbs do not usually move the thumb. When fingers are moving across the touchpad and a thumb is dropped, this can cause erroneous scroll motion or similar issues. libinput observes the finger motion speed for all touches - where a finger has been moving a newly dropped finger is more likely to be labeled as thumb. ------------------------------------------------------------------------------ Thumb detection based on finger positions ------------------------------------------------------------------------------ The shape of the human hand and the interactions that usually involve a thumb imply that a thumb is situated in a specific position relative to other fingers (usually to the side and below). This is used by libinput to detect thumbs during some interactions that do not implicitly require a thumb (e.g. pinch-and-rotate). libinput-1.28.1/doc/user/touchpads.rst000066400000000000000000000233011477265155700177220ustar00rootroot00000000000000:orphan: .. _touchpads: ============================================================================== Touchpads ============================================================================== This page provides an outline of touchpad devices. Touchpads aren't simply categorised into a single type, instead they have a set of properties, a combination of number of physical buttons, multitouch support abilities and other properties. .. _touchpads_buttons: ------------------------------------------------------------------------------ Number of buttons ------------------------------------------------------------------------------ .. _touchapds_buttons_phys: .............................................................................. Physically separate buttons .............................................................................. Touchpads with physical buttons usually provide two buttons, left and right. A few touchpads with three buttons exist, and Apple used to have touchpads with a single physical buttons until ca 2008. Touchpads with only two buttons require the software stack to emulate a middle button. libinput does this when both buttons are pressed simultaneously. Note that many Lenovo laptops provide a pointing stick above the touchpad. This pointing stick has a set of physical buttons just above the touchpad. While many users use those as substitute touchpad buttons, they logically belong to the pointing stick. The \*40 and \*50 series are an exception here, the former had no physical buttons on the touchpad and required the top section of the pad to emulate pointing stick buttons, the \*50 series has physical buttons but they are wired to the touchpads. The kernel re-routes those buttons through the trackstick device. See :ref:`t440_support` for more information. .. _touchpads_buttons_clickpads: .............................................................................. Clickpads .............................................................................. Clickpads are the most common type of touchpads these days. A Clickpad has no separate physical buttons, instead the touchpad itself is clickable as a whole, i.e. a user presses down on the touch area and triggers a physical click. Clickpads thus only provide a single button, everything else needs to be software-emulated. See :ref:`clickpad_softbuttons` for more information. Clickpads are labelled by the kernel with the **INPUT_PROP_BUTTONPAD** input property. .. _touchpads_buttons_forcepads: .............................................................................. Forcepads .............................................................................. Forcepads are Clickpads without a physical button underneath the hardware. They provide pressure and may have a vibration element that is software-controlled. This element can simulate the feel of a physical click or be co-opted for other tasks. .. _touchpads_touch: ------------------------------------------------------------------------------ Touch capabilities ------------------------------------------------------------------------------ Virtually all touchpads available now can **detect** multiple fingers on the touchpad, i.e. provide information on how many fingers are on the touchpad. The touch capabilities described here specify how many fingers a device can **track**, i.e. provide reliable positional information for. In the kernel each finger is tracked in a so-called "slot", the number of slots thus equals the number of simultaneous touches a device can track. .. _touchapds_touch_st: .............................................................................. Single-touch touchpads .............................................................................. Single-finger touchpads can track a single touchpoint. Most single-touch touchpads can also detect three fingers on the touchpad, but no positional information is provided for those. In libinput, these touches are termed "fake touches". The kernel sends **BTN_TOOL_DOUBLETAP**, **BTN_TOOL_TRIPLETAP**, **BTN_TOOL_QUADTAP** and **BTN_TOOL_QUINTTAP** events when multiple fingers are detected. .. _touchpads_touch_mt: .............................................................................. Pure multi-touch touchpads .............................................................................. Pure multi-touch touchpads are those that can track, i.e. identify the location of all fingers on the touchpad. Apple's touchpads support 16 touches, others support 5 touches like the Synaptics touchpads when using SMBus. These touchpads usually also provide extra information. Apple touchpads provide an ellipse and the orientation of the ellipse for each touch point. Other touchpads provide a pressure value for each touch point (see :ref:`touchpads_pressure_handling`). Note that the kernel sends **BTN_TOOL_DOUBLETAP**, **BTN_TOOL_TRIPLETAP**, **BTN_TOOL_QUADTAP** and **BTN_TOOL_QUINTTAP** events for all touches for backwards compatibility. libinput ignores these events if the touchpad can track touches correctly. .. _touchpads_touch_partial_mt: .............................................................................. Partial multi-touch touchpads .............................................................................. The vast majority of touchpads fall into this category, the half-way point between single-touch and pure multi-touch. These devices can track N fingers, but detect more than N. For example, when using the serial protocol, Synaptics touchpads can track two fingers but may detect up to five. The number of slots may limit which features are available in libinput. Any device with two slots can support two-finger scrolling, but :ref:`thumb-detection` or :ref:`palm_detection` may be limited if only two slots are available. .. _touchpads_touch_semi_mt: .............................................................................. Semi-mt touchpads .............................................................................. A sub-class of partial multi-touch touchpads. These touchpads can technically detect two fingers but the location of both is limited to the bounding box, i.e. the first touch is always the top-left one and the second touch is the bottom-right one. Coordinates jump around as fingers move past each other. Many semi-mt touchpads also have a lower resolution for the second touch, or both touches. This may limit some features such as :ref:`gestures` or :ref:`scrolling`. Semi-mt are labelled by the kernel with the **INPUT_PROP_SEMI_MT** input property. .. _touchpads_mis: ------------------------------------------------------------------------------ Other touchpad properties ------------------------------------------------------------------------------ .. _touchpads_external: .............................................................................. External touchpads .............................................................................. External touchpads are USB or Bluetooth touchpads not in a laptop chassis, e.g. Apple Magic Trackpad or the Logitech T650. These are usually :ref:`touchpads_buttons_clickpads` the biggest difference is that they can be removed or added at runtime. One interaction method that is only possible on external touchpads is a thumb resting on the very edge/immediately next to the touchpad. On the far edge, touchpads don't always detect the finger location so clicking with a thumb barely touching the edge makes it hard or impossible to figure out which software button area the finger is on. These touchpads also don't need :ref:`palm_detection` - since they're not located underneath the keyboard, accidental palm touches are a non-issue. .. _touchpads_pressure_handling: .............................................................................. Touchpads pressure handling .............................................................................. Pressure is usually directly related to contact area. Human fingers flatten out as the pressure on the pad increases, resulting in a bigger contact area and the firmware then calculates that back into a pressure reading. libinput uses pressure to detect accidental palm contact and thumbs, though pressure data is often device-specific and unreliable. .. _touchpads_circular: .............................................................................. Circular touchpads .............................................................................. Only listed for completeness, circular touchpads have not been used in laptops for a number of years. These touchpad shaped in an ellipse or straight. .. _touchpads_tablets: .............................................................................. Graphics tablets .............................................................................. Touch-capable graphics tablets are effectively external touchpads, with two differentiators: they are larger than normal touchpads and they have no regular touchpad buttons. They either work like a :ref:`touchpads_buttons_forcepads` Forcepad, or rely on interaction methods that don't require buttons (like :ref:`tapping`). Since the physical device is shared with the pen input, some touch arbitration is required to avoid touch input interfering when the pen is in use. .. _touchpads_edge_zone: .............................................................................. Dedicated edge scroll area .............................................................................. Before :ref:`twofinger_scrolling` became the default scroll method, some touchpads provided a marking on the touch area that designates the edge to be used for scrolling. A finger movement in that edge zone should trigger vertical motions. Some touchpads had markers for a horizontal scroll area too at the bottom of the touchpad. libinput-1.28.1/doc/user/trackpoint-configuration.rst000066400000000000000000000133451477265155700227620ustar00rootroot00000000000000.. _trackpoint_configuration: ============================================================================== Trackpoint configuration ============================================================================== The sections below describe the trackpoint magic multiplier and how to apply it to your local device. See :ref:`trackpoint_range` for an explanation on why this multiplier is needed. .. note:: The magic trackpoint multiplier **is not user visible configuration**. It is part of the :ref:`device-quirks` system and provided once per device. User-specific preferences can be adjusted with the :ref:`config_pointer_acceleration` setting. .. _trackpoint_multiplier: ------------------------------------------------------------------------------ The magic trackpoint multiplier ------------------------------------------------------------------------------ To accommodate for the wildly different input data on trackpoint, libinput uses a multiplier that is applied to input deltas. Trackpoints that send comparatively high deltas can be "slowed down", trackpoints that send low deltas can be "sped up" to match the expected range. The actual acceleration profile is applied to these pre-multiplied deltas. Given a trackpoint delta ``(dx, dy)``, a multiplier ``M`` and a pointer acceleration function ``f(dx, dy) → (dx', dy')``, the algorithm is effectively: :: f(M * dx, M * dy) → (dx', dy') .. _trackpoint_multiplier_adjustment: .............................................................................. Adjusting the magic trackpoint multiplier .............................................................................. This section only applies if: - the trackpoint default speed (speed setting 0) is unusably slow or unusably fast, **and** - the lowest speed setting (-1) is still too fast **or** the highest speed setting is still too slow, **and** - the :ref:`device-quirks` for this device do not list a trackpoint multiplier (see :ref:`device-quirks-debugging`) If the only satisfactory speed settings are less than -0.75 or greater than 0.75, a multiplier *may* be required. A specific multiplier will apply to **all users with the same laptop model**, so proceed with caution. You must be capable/willing to adjust device quirks, build libinput from source and restart the session frequently to adjust the multiplier. If this does not apply, wait for someone else with the same hardware to do this. Finding the correct multiplier is difficult and requires some trial and error. The default multiplier is always 1.0. A value between 0.0 and 1.0 slows the trackpoint down, a value above 1.0 speeds the trackpoint up. Values below zero are invalid. .. warning:: The multiplier is not a configuration to adjust to personal preferences. The multiplier normalizes the input data into a range that can then be configured with the speed setting. To adjust the local multiplier, first :ref:`build libinput from git master `. It is not required to install libinput from git. The below assumes that all :ref:`building_dependencies` are already installed. :: $ cd path/to/libinput.git # Use an approximate multiplier in the quirks file $ cat > quirks/99-trackpoint-override.quirks <` with the contents of the file. Alternatively, file a merge request with the data added. .. _trackpoint_range_measure: ------------------------------------------------------------------------------ Measuring the trackpoint range ------------------------------------------------------------------------------ This section only applied to libinput version 1.9.x, 1.10.x, and 1.11.x and has been removed. See :ref:`trackpoint_multiplier` for versions 1.12.x and later. If using libinput version 1.11.x or earlier, please see `the 1.11.0 documentation `_ libinput-1.28.1/doc/user/trackpoints.rst000066400000000000000000000056261477265155700203030ustar00rootroot00000000000000.. _trackpoints: ============================================================================== Trackpoints and Pointing Sticks ============================================================================== This page provides an overview of trackpoint handling in libinput, also referred to as Pointing Stick or Trackstick. The device itself is usually a round plastic stick between the G, H and B keys with a set of buttons below the space bar. .. figure:: button-scrolling.svg :align: center A trackpoint libinput always treats the buttons below the space bar as the buttons that belong to the trackpoint even on the few laptops where the buttons are not physically wired to the trackpoint device anyway, see :ref:`t440_support`. .. _trackpoint_buttonscroll: ------------------------------------------------------------------------------ Button scrolling on trackpoints ------------------------------------------------------------------------------ Trackpoint devices have :ref:`button_scrolling` enabled by default. This may interfer with middle-button dragging, if middle-button dragging is required by a user then button scrolling must be disabled. .. _trackpoint_range: ------------------------------------------------------------------------------ Motion range on trackpoints ------------------------------------------------------------------------------ It is difficult to associate motion on a trackpoint with a physical reference. Unlike mice or touchpads where the motion can be measured in mm, the trackpoint only responds to pressure. Without special equipment it is impossible to measure identical pressure values across multiple laptops. The values provided by a trackpoint are motion deltas, usually corresponding to the pressure applied to the trackstick. For example, pressure towards the screen on a laptop provides negative y deltas. The reporting rate increases as the pressure increases and once events are reported at the maximum rate, the delta values increase. The figure below shows a rough illustration of this concept. As the pressure decreases, the delta decrease first, then the reporting rate until the trackpoint is in a neutral state and no events are reported. Trackpoint data is hard to generalize, see `Observations on trackpoint input data `_ for more details. .. figure:: trackpoint-delta-illustration.svg :align: center Illustration of the relationship between reporting rate and delta values on a trackpoint The delta range itself can vary greatly between laptops, some devices send a maximum delta value of 30, others can go beyond 100. However, the useful delta range is a fraction of the maximum range. It is uncomfortable to exert sufficient pressure to even get close to the maximum ranges. libinput provides a :ref:`Magic Trackpoint Multiplier ` to normalize the trackpoint input data. libinput-1.28.1/doc/user/troubleshooting.rst000066400000000000000000000007621477265155700211650ustar00rootroot00000000000000.. _troubleshooting: ============================================================================== Troubleshooting ============================================================================== .. toctree:: :maxdepth: 2 tools.rst device-quirks.rst touchpad-jumping-cursors.rst touchpad-jitter.rst touchpad-pressure-debugging.rst trackpoint-configuration.rst tablet-debugging.rst incorrectly-enabled-hires.rst clickpad-with-right-button.rst ignoring-devices.rst libinput-1.28.1/doc/user/what-is-libinput.rst000066400000000000000000000156031477265155700211360ustar00rootroot00000000000000 .. _what_is_libinput: ============================================================================== What is libinput? ============================================================================== This page describes what libinput is, but more importantly it also describes what libinput is **not**. .. _what_libinput_is: ------------------------------------------------------------------------------ What libinput is ------------------------------------------------------------------------------ libinput is an input stack for processes that need to provide events from commonly used input devices. That includes mice, keyboards, touchpads, touchscreens and graphics tablets. libinput handles device-specific quirks and provides an easy-to-use API to receive events from devices. libinput is designed to handle all input devices available on a system but it is possible to limit which devices libinput has access to. For example, the use of xf86-input-libinput depends on xorg.conf snippets for specific devices. But libinput works best if it handles all input devices as this allows for smarter handling of features that affect multiple devices. libinput restricts device-specific features to those devices that require those features. One example for this are the top software buttons on the touchpad in the Lenovo T440. While there may be use-cases for providing top software buttons on other devices, libinput does not do so. `This introductory blog post from 2015 `_ describes some of the motivations. .. _what_libinput_is_not: ------------------------------------------------------------------------------ What libinput is not ------------------------------------------------------------------------------ libinput is **not** a project to support experimental devices. Unless a device is commonly available off-the-shelf, libinput will not support this device. libinput can serve as a useful base for getting experimental devices enabled and reduce the amount of boilerplate required. But such support will not land in libinput master until the devices are commonly available. libinput is **not** a box of legos. It does not provide the pieces to assemble a selection of features. Many features can be disabled through configuration options, but some features are hardcoded and/or only available on some devices. There are plenty of use-cases to provide niche features, but libinput is not the place to support these. libinput is **not** a showcase for features. There are a lot of potential features that could be provided on input devices. But unless they have common usage, libinput is not the place to implement them. Every feature multiplies the maintenance effort, any feature that is provided but unused is a net drain on the already sparse developer resources libinput has available. libinput is boring. It does not intend to break new grounds on how devices are handled. Instead, it takes best practice and the common use-cases and provides it in an easy-to-consume package for compositors or other processes that need those interactions typically expected by users. .. _libinput-wayland: ------------------------------------------------------------------------------ libinput and Wayland ------------------------------------------------------------------------------ libinput is not used directly by Wayland applications, it is an input stack used by the compositor. The typical software stack for a system running Wayland is: .. graphviz:: libinput-stack-wayland.gv The Wayland compositor may be Weston, mutter, KWin, etc. Note that Wayland encourages the use of toolkits, so the Wayland client (your application) does not usually talk directly to the compositor but rather employs a toolkit (e.g. GTK) to do so. The Wayland client does not know whether libinput is in use. libinput is not a requirement for Wayland or even a Wayland compositor. There are some specialized compositors that do not need or want libinput. .. _libinput-xorg: ------------------------------------------------------------------------------ libinput and X.Org ------------------------------------------------------------------------------ libinput is not used directly by X applications but rather through the custom xf86-input-libinput driver. The simplified software stack for a system running X.Org is: .. graphviz:: libinput-stack-xorg.gv libinput is not employed directly by the X server but by the xf86-input-libinput driver instead. That driver is loaded by the server on demand, depending on the xorg.conf.d configuration snippets. The X client does not know whether libinput is in use. libinput and xf86-input-libinput are not a requirement, the driver will only handle those devices explicitly assigned through an xorg.conf.d snippets. It is possible to mix xf86-input-libinput with other X.Org drivers. ------------------------------------------------------------------------------ Device types ------------------------------------------------------------------------------ libinput handles all common devices used to interact with a desktop system. This includes mice, keyboards, touchscreens, touchpads and graphics tablets. libinput does not expose the device type to the caller, it solely provides capabilities and the attached features (see `this blog post `_). For example, a touchpad in libinput is a device that provides pointer events, gestures and has a number of :ref:`config_options` such as :ref:`tapping`. A caller may present the device as touchpad to the user, or simply as device with a config knob to enable or disable tapping. .............................................................................. Handled device types .............................................................................. - :ref:`Touchpads` - Touchscreens - Mice - Keyboards - Virtual absolute pointing devices such as those used by QEMU or VirtualBox - Switches (Lid Switch and Tablet Mode switch) - Graphics tablets - :ref:`Trackpoints` If a device falls into one of the above categories but does not work as expected, please :ref:`file a bug `. .............................................................................. Unhandled device types .............................................................................. libinput does not handle some devices. The primary reason is that these device have no clear interaction with a desktop environment. Joysticks: Joysticks have one or more axes and one or more buttons. Beyond that it is difficult to find common ground between joysticks and much of the interaction is application-specific, not system-specific. libinput does not provide support for joysticks for that reason, any abstraction libinput would provide for joysticks would be so generic that libinput would merely introduce complexity and processing delays for no real benefit. libinput-1.28.1/doc/user/wheel-api.rst000066400000000000000000000221661477265155700176130ustar00rootroot00000000000000.. _wheel_scrolling: ============================================================================== Wheel scrolling ============================================================================== libinput provides two events to handle wheel scrolling: - ``LIBINPUT_EVENT_POINTER_AXIS`` events are sent for regular wheel clicks, usually those representing one detent on the device. These wheel clicks usually require a rotation of 15 or 20 degrees. **This event is deprecated as of libinput 1.19.** - ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` events are sent for regular and/or high resolution wheel movements. High-resolution events are often 4 or 8 times more frequent than wheel clicks and require the device to be switched into high-resolution mode (Linux kernel 5.0 and later). Where high-resolution wheels are not provided by the kernel, libinput emulates these events for regular wheel clicks. **This event is available since libinput 1.19.** The events are separate for historical reasons. Both events are generated for the same device but are independent event streams. Callers must not assume any relation between the two, i.e. there is no guarantee that an axis event is sent before or after any specific high-resolution event and vice versa. Callers should not handle both events. .. warning:: do not handle both ``LIBINPUT_EVENT_POINTER_AXIS`` and ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``. Always use the latter where possible, otherwise only use the former. Both events have their own set of APIs to access the data within: - ``LIBINPUT_EVENT_POINTER_AXIS``: Deprecated as of libinput 1.19, where possible it is recommended to handle **only** ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``. * ``libinput_event_pointer_get_axis_value()`` returns the angle of movement in degrees. * ``libinput_event_pointer_get_axis_source()`` returns the source of the event: wheel, finger or continuous. * ``libinput_event_pointer_get_axis_value_discrete()`` returns the number of logical wheel clicks. - ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` available since libinput 1.19. * ``libinput_event_pointer_get_scroll_value_v120()`` returns a value normalized into the 0..120 range, see below. Any multiple of 120 should be treated as one full wheel click. .. note:: Where possible, the ``libinput_event_pointer_get_axis_value()``, ``libinput_event_pointer_get_axis_source()`` and ``libinput_event_pointer_get_axis_value_discrete()`` API should be avoided. ------------------------------------------------------------------------------ The v120 Wheel API ------------------------------------------------------------------------------ The ``v120`` value matches the Windows API for wheel scrolling. Wheel movements are normalized into multiples (or fractions) of 120 with each multiple of 120 representing one detent of movement. The ``v120`` API is the recommended API for callers that do not care about the exact physical motion and is the simplest API to handle high-resolution scrolling. Most wheels provide 24 detents per 360 degree rotation (click angle of 15), others provide 18 detents per 360 degree rotation (click angle 20). Mice falling outside these two are rare but do exist. Below is a table showing the various values for a single event, depending on the click angle of the wheel: +-------------+------------+---------------+------+ | Click angle | Axis value | Discrete value| v120 | +=============+============+===============+======+ | 15 | 15 | 1 | 120 | +-------------+------------+---------------+------+ | 20 | 20 | 1 | 120 | +-------------+------------+---------------+------+ Fast scrolling may trigger cover than one detent per event and thus each event may contain multiples of the value, discrete or v120 value: +-------------+------------+---------------+------+ | Click angle | Axis value | Discrete value| v120 | +=============+============+===============+======+ | 15 | 30 | 2 | 240 | +-------------+------------+---------------+------+ | 20 | 60 | 3 | 360 | +-------------+------------+---------------+------+ Scrolling on high-resolution wheels will produce fractions of 120, depending on the resolution of the wheel. The example below shows a mouse with click angle 15 and a resolution of 3 events per wheel click and a mouse with click angle 20 and a resolution of 2 events per wheel click. +-------------+------------+---------------+------+ | Click angle | Axis value | Discrete value| v120 | +=============+============+===============+======+ | 15 | 5 | 0 | 40 | +-------------+------------+---------------+------+ | 20 | 10 | 0 | 60 | +-------------+------------+---------------+------+ ------------------------------------------------------------------------------ Event sequences for high-resolution wheel mice ------------------------------------------------------------------------------ High-resolution scroll wheels provide multiple events for each detent is hit. For those mice, an event sequence covering two detents may look like this: +--------------+---------+------------+---------------+------+ | Event number | Type | Axis value | Discrete value| v120 | +==============+=========+============+===============+======+ | 1 | WHEEL | 5 | n/a | 40 | +--------------+---------+------------+---------------+------+ | 2 | WHEEL | 5 | n/a | 40 | +--------------+---------+------------+---------------+------+ | 3 | WHEEL | 5 | n/a | 40 | +--------------+---------+------------+---------------+------+ | 4 | AXIS | 15 | 1 | 120 | +--------------+---------+------------+---------------+------+ | 5 | WHEEL | 5 | n/a | 40 | +--------------+---------+------------+---------------+------+ | 6 | WHEEL | 5 | n/a | 40 | +--------------+---------+------------+---------------+------+ | 7 | AXIS | 15 | 1 | 120 | +--------------+---------+------------+---------------+------+ The above assumes a click angle of 15 for the physical detents. Note how the second set of high-resolution events do **not** add up to a multiple of 120 before the low-resolution event. A caller must not assume any relation between ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` and ``LIBINPUT_EVENT_POINTER_AXIS``. Fast-scrolling on a high-resolution mouse may trigger multiple fractions per hardware scanout cycle and result in an event sequence like this: +---------------+---------+------------+---------------+------+ | Event number | Type | Axis value | Discrete value| v120 | +===============+=========+============+===============+======+ | 1 | WHEEL | 5 | n/a | 40 | +---------------+---------+------------+---------------+------+ | 2 | WHEEL | 10 | n/a | 80 | +---------------+---------+------------+---------------+------+ | 3 | AXIS | 15 | 1 | 120 | +---------------+---------+------------+---------------+------+ | 4 | WHEEL | 10 | n/a | 80 | +---------------+---------+------------+---------------+------+ | 5 | WHEEL | 10 | n/a | 80 | +---------------+---------+------------+---------------+------+ | 6 | AXIS | 15 | 1 | 120 | +---------------+---------+------------+---------------+------+ | 7 | WHEEL | 5 | n/a | 40 | +---------------+---------+------------+---------------+------+ Note how the first low-resolution event is sent at an accumulated 15 degrees, the second at an accumulated 20 degrees. The libinput API does not specify the smallest fraction a wheel supports. ------------------------------------------------------------------------------ Event sequences for regular wheel mice ------------------------------------------------------------------------------ ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` for low-resolution mice are virtually identical to ``LIBINPUT_EVENT_POINTER_AXIS`` events. Note that the discrete value is always 0 for ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``. +--------------+---------+------------+---------------+------+ | Event number | Type | Axis value | Discrete value| v120 | +==============+=========+============+===============+======+ | 1 | AXIS | 15 | 1 | 120 | +--------------+---------+------------+---------------+------+ | 2 | WHEEL | 15 | n/a | 120 | +--------------+---------+------------+---------------+------+ | 3 | WHEEL | 15 | n/a | 120 | +--------------+---------+------------+---------------+------+ | 4 | AXIS | 15 | 1 | 120 | +--------------+---------+------------+---------------+------+ Note that the order of ``LIBINPUT_EVENT_POINTER_AXIS`` vs ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` events is not guaranteed, as shown in the example above. libinput-1.28.1/include/000077500000000000000000000000001477265155700150775ustar00rootroot00000000000000libinput-1.28.1/include/linux/000077500000000000000000000000001477265155700162365ustar00rootroot00000000000000libinput-1.28.1/include/linux/freebsd/000077500000000000000000000000001477265155700176505ustar00rootroot00000000000000libinput-1.28.1/include/linux/freebsd/input-event-codes.h000066400000000000000000000672351477265155700234070ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ /* * Input event codes * * *** IMPORTANT *** * This file is not only included from C-code but also from devicetree source * files. As such this file MUST only contain comments and defines. * * Copyright (c) 1999-2002 Vojtech Pavlik * Copyright (c) 2015 Hans de Goede * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */ #ifndef _UAPI_INPUT_EVENT_CODES_H #define _UAPI_INPUT_EVENT_CODES_H /* * Device properties and quirks */ #define INPUT_PROP_POINTER 0x00 /* needs a pointer */ #define INPUT_PROP_DIRECT 0x01 /* direct input devices */ #define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */ #define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */ #define INPUT_PROP_TOPBUTTONPAD 0x04 /* softbuttons at top of pad */ #define INPUT_PROP_POINTING_STICK 0x05 /* is a pointing stick */ #define INPUT_PROP_ACCELEROMETER 0x06 /* has accelerometer */ #define INPUT_PROP_MAX 0x1f #define INPUT_PROP_CNT (INPUT_PROP_MAX + 1) /* * Event types */ #define EV_SYN 0x00 #define EV_KEY 0x01 #define EV_REL 0x02 #define EV_ABS 0x03 #define EV_MSC 0x04 #define EV_SW 0x05 #define EV_LED 0x11 #define EV_SND 0x12 #define EV_REP 0x14 #define EV_FF 0x15 #define EV_PWR 0x16 #define EV_FF_STATUS 0x17 #define EV_MAX 0x1f #define EV_CNT (EV_MAX+1) /* * Synchronization events. */ #define SYN_REPORT 0 #define SYN_CONFIG 1 #define SYN_MT_REPORT 2 #define SYN_DROPPED 3 #define SYN_MAX 0xf #define SYN_CNT (SYN_MAX+1) /* * Keys and buttons * * Most of the keys/buttons are modeled after USB HUT 1.12 * (see http://www.usb.org/developers/hidpage). * Abbreviations in the comments: * AC - Application Control * AL - Application Launch Button * SC - System Control */ #define KEY_RESERVED 0 #define KEY_ESC 1 #define KEY_1 2 #define KEY_2 3 #define KEY_3 4 #define KEY_4 5 #define KEY_5 6 #define KEY_6 7 #define KEY_7 8 #define KEY_8 9 #define KEY_9 10 #define KEY_0 11 #define KEY_MINUS 12 #define KEY_EQUAL 13 #define KEY_BACKSPACE 14 #define KEY_TAB 15 #define KEY_Q 16 #define KEY_W 17 #define KEY_E 18 #define KEY_R 19 #define KEY_T 20 #define KEY_Y 21 #define KEY_U 22 #define KEY_I 23 #define KEY_O 24 #define KEY_P 25 #define KEY_LEFTBRACE 26 #define KEY_RIGHTBRACE 27 #define KEY_ENTER 28 #define KEY_LEFTCTRL 29 #define KEY_A 30 #define KEY_S 31 #define KEY_D 32 #define KEY_F 33 #define KEY_G 34 #define KEY_H 35 #define KEY_J 36 #define KEY_K 37 #define KEY_L 38 #define KEY_SEMICOLON 39 #define KEY_APOSTROPHE 40 #define KEY_GRAVE 41 #define KEY_LEFTSHIFT 42 #define KEY_BACKSLASH 43 #define KEY_Z 44 #define KEY_X 45 #define KEY_C 46 #define KEY_V 47 #define KEY_B 48 #define KEY_N 49 #define KEY_M 50 #define KEY_COMMA 51 #define KEY_DOT 52 #define KEY_SLASH 53 #define KEY_RIGHTSHIFT 54 #define KEY_KPASTERISK 55 #define KEY_LEFTALT 56 #define KEY_SPACE 57 #define KEY_CAPSLOCK 58 #define KEY_F1 59 #define KEY_F2 60 #define KEY_F3 61 #define KEY_F4 62 #define KEY_F5 63 #define KEY_F6 64 #define KEY_F7 65 #define KEY_F8 66 #define KEY_F9 67 #define KEY_F10 68 #define KEY_NUMLOCK 69 #define KEY_SCROLLLOCK 70 #define KEY_KP7 71 #define KEY_KP8 72 #define KEY_KP9 73 #define KEY_KPMINUS 74 #define KEY_KP4 75 #define KEY_KP5 76 #define KEY_KP6 77 #define KEY_KPPLUS 78 #define KEY_KP1 79 #define KEY_KP2 80 #define KEY_KP3 81 #define KEY_KP0 82 #define KEY_KPDOT 83 #define KEY_ZENKAKUHANKAKU 85 #define KEY_102ND 86 #define KEY_F11 87 #define KEY_F12 88 #define KEY_RO 89 #define KEY_KATAKANA 90 #define KEY_HIRAGANA 91 #define KEY_HENKAN 92 #define KEY_KATAKANAHIRAGANA 93 #define KEY_MUHENKAN 94 #define KEY_KPJPCOMMA 95 #define KEY_KPENTER 96 #define KEY_RIGHTCTRL 97 #define KEY_KPSLASH 98 #define KEY_SYSRQ 99 #define KEY_RIGHTALT 100 #define KEY_LINEFEED 101 #define KEY_HOME 102 #define KEY_UP 103 #define KEY_PAGEUP 104 #define KEY_LEFT 105 #define KEY_RIGHT 106 #define KEY_END 107 #define KEY_DOWN 108 #define KEY_PAGEDOWN 109 #define KEY_INSERT 110 #define KEY_DELETE 111 #define KEY_MACRO 112 #define KEY_MUTE 113 #define KEY_VOLUMEDOWN 114 #define KEY_VOLUMEUP 115 #define KEY_POWER 116 /* SC System Power Down */ #define KEY_KPEQUAL 117 #define KEY_KPPLUSMINUS 118 #define KEY_PAUSE 119 #define KEY_SCALE 120 /* AL Compiz Scale (Expose) */ #define KEY_KPCOMMA 121 #define KEY_HANGEUL 122 #define KEY_HANGUEL KEY_HANGEUL #define KEY_HANJA 123 #define KEY_YEN 124 #define KEY_LEFTMETA 125 #define KEY_RIGHTMETA 126 #define KEY_COMPOSE 127 #define KEY_STOP 128 /* AC Stop */ #define KEY_AGAIN 129 #define KEY_PROPS 130 /* AC Properties */ #define KEY_UNDO 131 /* AC Undo */ #define KEY_FRONT 132 #define KEY_COPY 133 /* AC Copy */ #define KEY_OPEN 134 /* AC Open */ #define KEY_PASTE 135 /* AC Paste */ #define KEY_FIND 136 /* AC Search */ #define KEY_CUT 137 /* AC Cut */ #define KEY_HELP 138 /* AL Integrated Help Center */ #define KEY_MENU 139 /* Menu (show menu) */ #define KEY_CALC 140 /* AL Calculator */ #define KEY_SETUP 141 #define KEY_SLEEP 142 /* SC System Sleep */ #define KEY_WAKEUP 143 /* System Wake Up */ #define KEY_FILE 144 /* AL Local Machine Browser */ #define KEY_SENDFILE 145 #define KEY_DELETEFILE 146 #define KEY_XFER 147 #define KEY_PROG1 148 #define KEY_PROG2 149 #define KEY_WWW 150 /* AL Internet Browser */ #define KEY_MSDOS 151 #define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */ #define KEY_SCREENLOCK KEY_COFFEE #define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */ #define KEY_DIRECTION KEY_ROTATE_DISPLAY #define KEY_CYCLEWINDOWS 154 #define KEY_MAIL 155 #define KEY_BOOKMARKS 156 /* AC Bookmarks */ #define KEY_COMPUTER 157 #define KEY_BACK 158 /* AC Back */ #define KEY_FORWARD 159 /* AC Forward */ #define KEY_CLOSECD 160 #define KEY_EJECTCD 161 #define KEY_EJECTCLOSECD 162 #define KEY_NEXTSONG 163 #define KEY_PLAYPAUSE 164 #define KEY_PREVIOUSSONG 165 #define KEY_STOPCD 166 #define KEY_RECORD 167 #define KEY_REWIND 168 #define KEY_PHONE 169 /* Media Select Telephone */ #define KEY_ISO 170 #define KEY_CONFIG 171 /* AL Consumer Control Configuration */ #define KEY_HOMEPAGE 172 /* AC Home */ #define KEY_REFRESH 173 /* AC Refresh */ #define KEY_EXIT 174 /* AC Exit */ #define KEY_MOVE 175 #define KEY_EDIT 176 #define KEY_SCROLLUP 177 #define KEY_SCROLLDOWN 178 #define KEY_KPLEFTPAREN 179 #define KEY_KPRIGHTPAREN 180 #define KEY_NEW 181 /* AC New */ #define KEY_REDO 182 /* AC Redo/Repeat */ #define KEY_F13 183 #define KEY_F14 184 #define KEY_F15 185 #define KEY_F16 186 #define KEY_F17 187 #define KEY_F18 188 #define KEY_F19 189 #define KEY_F20 190 #define KEY_F21 191 #define KEY_F22 192 #define KEY_F23 193 #define KEY_F24 194 #define KEY_PLAYCD 200 #define KEY_PAUSECD 201 #define KEY_PROG3 202 #define KEY_PROG4 203 #define KEY_DASHBOARD 204 /* AL Dashboard */ #define KEY_SUSPEND 205 #define KEY_CLOSE 206 /* AC Close */ #define KEY_PLAY 207 #define KEY_FASTFORWARD 208 #define KEY_BASSBOOST 209 #define KEY_PRINT 210 /* AC Print */ #define KEY_HP 211 #define KEY_CAMERA 212 #define KEY_SOUND 213 #define KEY_QUESTION 214 #define KEY_EMAIL 215 #define KEY_CHAT 216 #define KEY_SEARCH 217 #define KEY_CONNECT 218 #define KEY_FINANCE 219 /* AL Checkbook/Finance */ #define KEY_SPORT 220 #define KEY_SHOP 221 #define KEY_ALTERASE 222 #define KEY_CANCEL 223 /* AC Cancel */ #define KEY_BRIGHTNESSDOWN 224 #define KEY_BRIGHTNESSUP 225 #define KEY_MEDIA 226 #define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video outputs (Monitor/LCD/TV-out/etc) */ #define KEY_KBDILLUMTOGGLE 228 #define KEY_KBDILLUMDOWN 229 #define KEY_KBDILLUMUP 230 #define KEY_SEND 231 /* AC Send */ #define KEY_REPLY 232 /* AC Reply */ #define KEY_FORWARDMAIL 233 /* AC Forward Msg */ #define KEY_SAVE 234 /* AC Save */ #define KEY_DOCUMENTS 235 #define KEY_BATTERY 236 #define KEY_BLUETOOTH 237 #define KEY_WLAN 238 #define KEY_UWB 239 #define KEY_UNKNOWN 240 #define KEY_VIDEO_NEXT 241 /* drive next video source */ #define KEY_VIDEO_PREV 242 /* drive previous video source */ #define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */ #define KEY_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual brightness control is off, rely on ambient */ #define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO #define KEY_DISPLAY_OFF 245 /* display device to off state */ #define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */ #define KEY_WIMAX KEY_WWAN #define KEY_RFKILL 247 /* Key that controls all radios */ #define KEY_MICMUTE 248 /* Mute / unmute the microphone */ /* Code 255 is reserved for special needs of AT keyboard driver */ #define BTN_MISC 0x100 #define BTN_0 0x100 #define BTN_1 0x101 #define BTN_2 0x102 #define BTN_3 0x103 #define BTN_4 0x104 #define BTN_5 0x105 #define BTN_6 0x106 #define BTN_7 0x107 #define BTN_8 0x108 #define BTN_9 0x109 #define BTN_MOUSE 0x110 #define BTN_LEFT 0x110 #define BTN_RIGHT 0x111 #define BTN_MIDDLE 0x112 #define BTN_SIDE 0x113 #define BTN_EXTRA 0x114 #define BTN_FORWARD 0x115 #define BTN_BACK 0x116 #define BTN_TASK 0x117 #define BTN_JOYSTICK 0x120 #define BTN_TRIGGER 0x120 #define BTN_THUMB 0x121 #define BTN_THUMB2 0x122 #define BTN_TOP 0x123 #define BTN_TOP2 0x124 #define BTN_PINKIE 0x125 #define BTN_BASE 0x126 #define BTN_BASE2 0x127 #define BTN_BASE3 0x128 #define BTN_BASE4 0x129 #define BTN_BASE5 0x12a #define BTN_BASE6 0x12b #define BTN_DEAD 0x12f #define BTN_GAMEPAD 0x130 #define BTN_SOUTH 0x130 #define BTN_A BTN_SOUTH #define BTN_EAST 0x131 #define BTN_B BTN_EAST #define BTN_C 0x132 #define BTN_NORTH 0x133 #define BTN_X BTN_NORTH #define BTN_WEST 0x134 #define BTN_Y BTN_WEST #define BTN_Z 0x135 #define BTN_TL 0x136 #define BTN_TR 0x137 #define BTN_TL2 0x138 #define BTN_TR2 0x139 #define BTN_SELECT 0x13a #define BTN_START 0x13b #define BTN_MODE 0x13c #define BTN_THUMBL 0x13d #define BTN_THUMBR 0x13e #define BTN_DIGI 0x140 #define BTN_TOOL_PEN 0x140 #define BTN_TOOL_RUBBER 0x141 #define BTN_TOOL_BRUSH 0x142 #define BTN_TOOL_PENCIL 0x143 #define BTN_TOOL_AIRBRUSH 0x144 #define BTN_TOOL_FINGER 0x145 #define BTN_TOOL_MOUSE 0x146 #define BTN_TOOL_LENS 0x147 #define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */ #define BTN_STYLUS3 0x149 #define BTN_TOUCH 0x14a #define BTN_STYLUS 0x14b #define BTN_STYLUS2 0x14c #define BTN_TOOL_DOUBLETAP 0x14d #define BTN_TOOL_TRIPLETAP 0x14e #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ #define BTN_WHEEL 0x150 #define BTN_GEAR_DOWN 0x150 #define BTN_GEAR_UP 0x151 #define KEY_OK 0x160 #define KEY_SELECT 0x161 #define KEY_GOTO 0x162 #define KEY_CLEAR 0x163 #define KEY_POWER2 0x164 #define KEY_OPTION 0x165 #define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */ #define KEY_TIME 0x167 #define KEY_VENDOR 0x168 #define KEY_ARCHIVE 0x169 #define KEY_PROGRAM 0x16a /* Media Select Program Guide */ #define KEY_CHANNEL 0x16b #define KEY_FAVORITES 0x16c #define KEY_EPG 0x16d #define KEY_PVR 0x16e /* Media Select Home */ #define KEY_MHP 0x16f #define KEY_LANGUAGE 0x170 #define KEY_TITLE 0x171 #define KEY_SUBTITLE 0x172 #define KEY_ANGLE 0x173 #define KEY_FULL_SCREEN 0x174 /* AC View Toggle */ #define KEY_ZOOM KEY_FULL_SCREEN #define KEY_MODE 0x175 #define KEY_KEYBOARD 0x176 #define KEY_ASPECT_RATIO 0x177 /* HUTRR37: Aspect */ #define KEY_SCREEN KEY_ASPECT_RATIO #define KEY_PC 0x178 /* Media Select Computer */ #define KEY_TV 0x179 /* Media Select TV */ #define KEY_TV2 0x17a /* Media Select Cable */ #define KEY_VCR 0x17b /* Media Select VCR */ #define KEY_VCR2 0x17c /* VCR Plus */ #define KEY_SAT 0x17d /* Media Select Satellite */ #define KEY_SAT2 0x17e #define KEY_CD 0x17f /* Media Select CD */ #define KEY_TAPE 0x180 /* Media Select Tape */ #define KEY_RADIO 0x181 #define KEY_TUNER 0x182 /* Media Select Tuner */ #define KEY_PLAYER 0x183 #define KEY_TEXT 0x184 #define KEY_DVD 0x185 /* Media Select DVD */ #define KEY_AUX 0x186 #define KEY_MP3 0x187 #define KEY_AUDIO 0x188 /* AL Audio Browser */ #define KEY_VIDEO 0x189 /* AL Movie Browser */ #define KEY_DIRECTORY 0x18a #define KEY_LIST 0x18b #define KEY_MEMO 0x18c /* Media Select Messages */ #define KEY_CALENDAR 0x18d #define KEY_RED 0x18e #define KEY_GREEN 0x18f #define KEY_YELLOW 0x190 #define KEY_BLUE 0x191 #define KEY_CHANNELUP 0x192 /* Channel Increment */ #define KEY_CHANNELDOWN 0x193 /* Channel Decrement */ #define KEY_FIRST 0x194 #define KEY_LAST 0x195 /* Recall Last */ #define KEY_AB 0x196 #define KEY_NEXT 0x197 #define KEY_RESTART 0x198 #define KEY_SLOW 0x199 #define KEY_SHUFFLE 0x19a #define KEY_BREAK 0x19b #define KEY_PREVIOUS 0x19c #define KEY_DIGITS 0x19d #define KEY_TEEN 0x19e #define KEY_TWEN 0x19f #define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */ #define KEY_GAMES 0x1a1 /* Media Select Games */ #define KEY_ZOOMIN 0x1a2 /* AC Zoom In */ #define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */ #define KEY_ZOOMRESET 0x1a4 /* AC Zoom */ #define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */ #define KEY_EDITOR 0x1a6 /* AL Text Editor */ #define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */ #define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */ #define KEY_PRESENTATION 0x1a9 /* AL Presentation App */ #define KEY_DATABASE 0x1aa /* AL Database App */ #define KEY_NEWS 0x1ab /* AL Newsreader */ #define KEY_VOICEMAIL 0x1ac /* AL Voicemail */ #define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */ #define KEY_MESSENGER 0x1ae /* AL Instant Messaging */ #define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */ #define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE #define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */ #define KEY_LOGOFF 0x1b1 /* AL Logoff */ #define KEY_DOLLAR 0x1b2 #define KEY_EURO 0x1b3 #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ #define KEY_FRAMEFORWARD 0x1b5 #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ #define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */ #define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */ #define KEY_IMAGES 0x1ba /* AL Image Browser */ #define KEY_DEL_EOL 0x1c0 #define KEY_DEL_EOS 0x1c1 #define KEY_INS_LINE 0x1c2 #define KEY_DEL_LINE 0x1c3 #define KEY_FN 0x1d0 #define KEY_FN_ESC 0x1d1 #define KEY_FN_F1 0x1d2 #define KEY_FN_F2 0x1d3 #define KEY_FN_F3 0x1d4 #define KEY_FN_F4 0x1d5 #define KEY_FN_F5 0x1d6 #define KEY_FN_F6 0x1d7 #define KEY_FN_F7 0x1d8 #define KEY_FN_F8 0x1d9 #define KEY_FN_F9 0x1da #define KEY_FN_F10 0x1db #define KEY_FN_F11 0x1dc #define KEY_FN_F12 0x1dd #define KEY_FN_1 0x1de #define KEY_FN_2 0x1df #define KEY_FN_D 0x1e0 #define KEY_FN_E 0x1e1 #define KEY_FN_F 0x1e2 #define KEY_FN_S 0x1e3 #define KEY_FN_B 0x1e4 #define KEY_BRL_DOT1 0x1f1 #define KEY_BRL_DOT2 0x1f2 #define KEY_BRL_DOT3 0x1f3 #define KEY_BRL_DOT4 0x1f4 #define KEY_BRL_DOT5 0x1f5 #define KEY_BRL_DOT6 0x1f6 #define KEY_BRL_DOT7 0x1f7 #define KEY_BRL_DOT8 0x1f8 #define KEY_BRL_DOT9 0x1f9 #define KEY_BRL_DOT10 0x1fa #define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */ #define KEY_NUMERIC_1 0x201 /* and other keypads */ #define KEY_NUMERIC_2 0x202 #define KEY_NUMERIC_3 0x203 #define KEY_NUMERIC_4 0x204 #define KEY_NUMERIC_5 0x205 #define KEY_NUMERIC_6 0x206 #define KEY_NUMERIC_7 0x207 #define KEY_NUMERIC_8 0x208 #define KEY_NUMERIC_9 0x209 #define KEY_NUMERIC_STAR 0x20a #define KEY_NUMERIC_POUND 0x20b #define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */ #define KEY_NUMERIC_B 0x20d #define KEY_NUMERIC_C 0x20e #define KEY_NUMERIC_D 0x20f #define KEY_CAMERA_FOCUS 0x210 #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ #define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */ #define KEY_TOUCHPAD_ON 0x213 #define KEY_TOUCHPAD_OFF 0x214 #define KEY_CAMERA_ZOOMIN 0x215 #define KEY_CAMERA_ZOOMOUT 0x216 #define KEY_CAMERA_UP 0x217 #define KEY_CAMERA_DOWN 0x218 #define KEY_CAMERA_LEFT 0x219 #define KEY_CAMERA_RIGHT 0x21a #define KEY_ATTENDANT_ON 0x21b #define KEY_ATTENDANT_OFF 0x21c #define KEY_ATTENDANT_TOGGLE 0x21d /* Attendant call on or off */ #define KEY_LIGHTS_TOGGLE 0x21e /* Reading light on or off */ #define BTN_DPAD_UP 0x220 #define BTN_DPAD_DOWN 0x221 #define BTN_DPAD_LEFT 0x222 #define BTN_DPAD_RIGHT 0x223 #define KEY_ALS_TOGGLE 0x230 /* Ambient light sensor */ #define KEY_ROTATE_LOCK_TOGGLE 0x231 /* Display rotation lock */ #define KEY_BUTTONCONFIG 0x240 /* AL Button Configuration */ #define KEY_TASKMANAGER 0x241 /* AL Task/Project Manager */ #define KEY_JOURNAL 0x242 /* AL Log/Journal/Timecard */ #define KEY_CONTROLPANEL 0x243 /* AL Control Panel */ #define KEY_APPSELECT 0x244 /* AL Select Task/Application */ #define KEY_SCREENSAVER 0x245 /* AL Screen Saver */ #define KEY_VOICECOMMAND 0x246 /* Listening Voice Command */ #define KEY_ASSISTANT 0x247 /* AL Context-aware desktop assistant */ #define KEY_KBD_LAYOUT_NEXT 0x248 /* AC Next Keyboard Layout Select */ #define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */ #define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */ #define KEY_KBDINPUTASSIST_PREV 0x260 #define KEY_KBDINPUTASSIST_NEXT 0x261 #define KEY_KBDINPUTASSIST_PREVGROUP 0x262 #define KEY_KBDINPUTASSIST_NEXTGROUP 0x263 #define KEY_KBDINPUTASSIST_ACCEPT 0x264 #define KEY_KBDINPUTASSIST_CANCEL 0x265 /* Diagonal movement keys */ #define KEY_RIGHT_UP 0x266 #define KEY_RIGHT_DOWN 0x267 #define KEY_LEFT_UP 0x268 #define KEY_LEFT_DOWN 0x269 #define KEY_ROOT_MENU 0x26a /* Show Device's Root Menu */ /* Show Top Menu of the Media (e.g. DVD) */ #define KEY_MEDIA_TOP_MENU 0x26b #define KEY_NUMERIC_11 0x26c #define KEY_NUMERIC_12 0x26d /* * Toggle Audio Description: refers to an audio service that helps blind and * visually impaired consumers understand the action in a program. Note: in * some countries this is referred to as "Video Description". */ #define KEY_AUDIO_DESC 0x26e #define KEY_3D_MODE 0x26f #define KEY_NEXT_FAVORITE 0x270 #define KEY_STOP_RECORD 0x271 #define KEY_PAUSE_RECORD 0x272 #define KEY_VOD 0x273 /* Video on Demand */ #define KEY_UNMUTE 0x274 #define KEY_FASTREVERSE 0x275 #define KEY_SLOWREVERSE 0x276 /* * Control a data application associated with the currently viewed channel, * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.) */ #define KEY_DATA 0x277 #define KEY_ONSCREEN_KEYBOARD 0x278 /* Electronic privacy screen control */ #define KEY_PRIVACY_SCREEN_TOGGLE 0x279 /* Select an area of screen to be copied */ #define KEY_SELECTIVE_SCREENSHOT 0x27a /* * Some keyboards have keys which do not have a defined meaning, these keys * are intended to be programmed / bound to macros by the user. For most * keyboards with these macro-keys the key-sequence to inject, or action to * take, is all handled by software on the host side. So from the kernel's * point of view these are just normal keys. * * The KEY_MACRO# codes below are intended for such keys, which may be labeled * e.g. G1-G18, or S1 - S30. The KEY_MACRO# codes MUST NOT be used for keys * where the marking on the key does indicate a defined meaning / purpose. * * The KEY_MACRO# codes MUST also NOT be used as fallback for when no existing * KEY_FOO define matches the marking / purpose. In this case a new KEY_FOO * define MUST be added. */ #define KEY_MACRO1 0x290 #define KEY_MACRO2 0x291 #define KEY_MACRO3 0x292 #define KEY_MACRO4 0x293 #define KEY_MACRO5 0x294 #define KEY_MACRO6 0x295 #define KEY_MACRO7 0x296 #define KEY_MACRO8 0x297 #define KEY_MACRO9 0x298 #define KEY_MACRO10 0x299 #define KEY_MACRO11 0x29a #define KEY_MACRO12 0x29b #define KEY_MACRO13 0x29c #define KEY_MACRO14 0x29d #define KEY_MACRO15 0x29e #define KEY_MACRO16 0x29f #define KEY_MACRO17 0x2a0 #define KEY_MACRO18 0x2a1 #define KEY_MACRO19 0x2a2 #define KEY_MACRO20 0x2a3 #define KEY_MACRO21 0x2a4 #define KEY_MACRO22 0x2a5 #define KEY_MACRO23 0x2a6 #define KEY_MACRO24 0x2a7 #define KEY_MACRO25 0x2a8 #define KEY_MACRO26 0x2a9 #define KEY_MACRO27 0x2aa #define KEY_MACRO28 0x2ab #define KEY_MACRO29 0x2ac #define KEY_MACRO30 0x2ad /* * Some keyboards with the macro-keys described above have some extra keys * for controlling the host-side software responsible for the macro handling: * -A macro recording start/stop key. Note that not all keyboards which emit * KEY_MACRO_RECORD_START will also emit KEY_MACRO_RECORD_STOP if * KEY_MACRO_RECORD_STOP is not advertised, then KEY_MACRO_RECORD_START * should be interpreted as a recording start/stop toggle; * -Keys for switching between different macro (pre)sets, either a key for * cycling through the configured presets or keys to directly select a preset. */ #define KEY_MACRO_RECORD_START 0x2b0 #define KEY_MACRO_RECORD_STOP 0x2b1 #define KEY_MACRO_PRESET_CYCLE 0x2b2 #define KEY_MACRO_PRESET1 0x2b3 #define KEY_MACRO_PRESET2 0x2b4 #define KEY_MACRO_PRESET3 0x2b5 /* * Some keyboards have a buildin LCD panel where the contents are controlled * by the host. Often these have a number of keys directly below the LCD * intended for controlling a menu shown on the LCD. These keys often don't * have any labeling so we just name them KEY_KBD_LCD_MENU# */ #define KEY_KBD_LCD_MENU1 0x2b8 #define KEY_KBD_LCD_MENU2 0x2b9 #define KEY_KBD_LCD_MENU3 0x2ba #define KEY_KBD_LCD_MENU4 0x2bb #define KEY_KBD_LCD_MENU5 0x2bc #define BTN_TRIGGER_HAPPY 0x2c0 #define BTN_TRIGGER_HAPPY1 0x2c0 #define BTN_TRIGGER_HAPPY2 0x2c1 #define BTN_TRIGGER_HAPPY3 0x2c2 #define BTN_TRIGGER_HAPPY4 0x2c3 #define BTN_TRIGGER_HAPPY5 0x2c4 #define BTN_TRIGGER_HAPPY6 0x2c5 #define BTN_TRIGGER_HAPPY7 0x2c6 #define BTN_TRIGGER_HAPPY8 0x2c7 #define BTN_TRIGGER_HAPPY9 0x2c8 #define BTN_TRIGGER_HAPPY10 0x2c9 #define BTN_TRIGGER_HAPPY11 0x2ca #define BTN_TRIGGER_HAPPY12 0x2cb #define BTN_TRIGGER_HAPPY13 0x2cc #define BTN_TRIGGER_HAPPY14 0x2cd #define BTN_TRIGGER_HAPPY15 0x2ce #define BTN_TRIGGER_HAPPY16 0x2cf #define BTN_TRIGGER_HAPPY17 0x2d0 #define BTN_TRIGGER_HAPPY18 0x2d1 #define BTN_TRIGGER_HAPPY19 0x2d2 #define BTN_TRIGGER_HAPPY20 0x2d3 #define BTN_TRIGGER_HAPPY21 0x2d4 #define BTN_TRIGGER_HAPPY22 0x2d5 #define BTN_TRIGGER_HAPPY23 0x2d6 #define BTN_TRIGGER_HAPPY24 0x2d7 #define BTN_TRIGGER_HAPPY25 0x2d8 #define BTN_TRIGGER_HAPPY26 0x2d9 #define BTN_TRIGGER_HAPPY27 0x2da #define BTN_TRIGGER_HAPPY28 0x2db #define BTN_TRIGGER_HAPPY29 0x2dc #define BTN_TRIGGER_HAPPY30 0x2dd #define BTN_TRIGGER_HAPPY31 0x2de #define BTN_TRIGGER_HAPPY32 0x2df #define BTN_TRIGGER_HAPPY33 0x2e0 #define BTN_TRIGGER_HAPPY34 0x2e1 #define BTN_TRIGGER_HAPPY35 0x2e2 #define BTN_TRIGGER_HAPPY36 0x2e3 #define BTN_TRIGGER_HAPPY37 0x2e4 #define BTN_TRIGGER_HAPPY38 0x2e5 #define BTN_TRIGGER_HAPPY39 0x2e6 #define BTN_TRIGGER_HAPPY40 0x2e7 /* We avoid low common keys in module aliases so they don't get huge. */ #define KEY_MIN_INTERESTING KEY_MUTE #define KEY_MAX 0x2ff #define KEY_CNT (KEY_MAX+1) /* * Relative axes */ #define REL_X 0x00 #define REL_Y 0x01 #define REL_Z 0x02 #define REL_RX 0x03 #define REL_RY 0x04 #define REL_RZ 0x05 #define REL_HWHEEL 0x06 #define REL_DIAL 0x07 #define REL_WHEEL 0x08 #define REL_MISC 0x09 /* * 0x0a is reserved and should not be used in input drivers. * It was used by HID as REL_MISC+1 and userspace needs to detect if * the next REL_* event is correct or is just REL_MISC + n. * We define here REL_RESERVED so userspace can rely on it and detect * the situation described above. */ #define REL_RESERVED 0x0a #define REL_WHEEL_HI_RES 0x0b #define REL_HWHEEL_HI_RES 0x0c #define REL_MAX 0x0f #define REL_CNT (REL_MAX+1) /* * Absolute axes */ #define ABS_X 0x00 #define ABS_Y 0x01 #define ABS_Z 0x02 #define ABS_RX 0x03 #define ABS_RY 0x04 #define ABS_RZ 0x05 #define ABS_THROTTLE 0x06 #define ABS_RUDDER 0x07 #define ABS_WHEEL 0x08 #define ABS_GAS 0x09 #define ABS_BRAKE 0x0a #define ABS_HAT0X 0x10 #define ABS_HAT0Y 0x11 #define ABS_HAT1X 0x12 #define ABS_HAT1Y 0x13 #define ABS_HAT2X 0x14 #define ABS_HAT2Y 0x15 #define ABS_HAT3X 0x16 #define ABS_HAT3Y 0x17 #define ABS_PRESSURE 0x18 #define ABS_DISTANCE 0x19 #define ABS_TILT_X 0x1a #define ABS_TILT_Y 0x1b #define ABS_TOOL_WIDTH 0x1c #define ABS_VOLUME 0x20 #define ABS_MISC 0x28 /* * 0x2e is reserved and should not be used in input drivers. * It was used by HID as ABS_MISC+6 and userspace needs to detect if * the next ABS_* event is correct or is just ABS_MISC + n. * We define here ABS_RESERVED so userspace can rely on it and detect * the situation described above. */ #define ABS_RESERVED 0x2e #define ABS_MT_SLOT 0x2f /* MT slot being modified */ #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ #define ABS_MT_POSITION_X 0x35 /* Center X touch position */ #define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */ #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ #define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ #define ABS_MT_TOOL_X 0x3c /* Center X tool position */ #define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */ #define ABS_MAX 0x3f #define ABS_CNT (ABS_MAX+1) /* * Switch events */ #define SW_LID 0x00 /* set = lid shut */ #define SW_TABLET_MODE 0x01 /* set = tablet mode */ #define SW_HEADPHONE_INSERT 0x02 /* set = inserted */ #define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any" set = radio enabled */ #define SW_RADIO SW_RFKILL_ALL /* deprecated */ #define SW_MICROPHONE_INSERT 0x04 /* set = inserted */ #define SW_DOCK 0x05 /* set = plugged into dock */ #define SW_LINEOUT_INSERT 0x06 /* set = inserted */ #define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ #define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */ #define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */ #define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ #define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ #define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */ #define SW_LINEIN_INSERT 0x0d /* set = inserted */ #define SW_MUTE_DEVICE 0x0e /* set = device disabled */ #define SW_PEN_INSERTED 0x0f /* set = pen inserted */ #define SW_MACHINE_COVER 0x10 /* set = cover closed */ #define SW_MAX 0x10 #define SW_CNT (SW_MAX+1) /* * Misc events */ #define MSC_SERIAL 0x00 #define MSC_PULSELED 0x01 #define MSC_GESTURE 0x02 #define MSC_RAW 0x03 #define MSC_SCAN 0x04 #define MSC_TIMESTAMP 0x05 #define MSC_MAX 0x07 #define MSC_CNT (MSC_MAX+1) /* * LEDs */ #define LED_NUML 0x00 #define LED_CAPSL 0x01 #define LED_SCROLLL 0x02 #define LED_COMPOSE 0x03 #define LED_KANA 0x04 #define LED_SLEEP 0x05 #define LED_SUSPEND 0x06 #define LED_MUTE 0x07 #define LED_MISC 0x08 #define LED_MAIL 0x09 #define LED_CHARGING 0x0a #define LED_MAX 0x0f #define LED_CNT (LED_MAX+1) /* * Autorepeat values */ #define REP_DELAY 0x00 #define REP_PERIOD 0x01 #define REP_MAX 0x01 #define REP_CNT (REP_MAX+1) /* * Sounds */ #define SND_CLICK 0x00 #define SND_BELL 0x01 #define SND_TONE 0x02 #define SND_MAX 0x07 #define SND_CNT (SND_MAX+1) #endif libinput-1.28.1/include/linux/freebsd/input.h000066400000000000000000000372301477265155700211650ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * Copyright (c) 1999-2002 Vojtech Pavlik * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */ #ifndef _UAPI_INPUT_H #define _UAPI_INPUT_H #ifndef __KERNEL__ #include #include #include #endif #include "input-event-codes.h" /* * The event structure itself * Note that __USE_TIME_BITS64 is defined by libc based on * application's request to use 64 bit time_t. */ struct input_event { #if 1 /* (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL) */ struct timeval time; #define input_event_sec time.tv_sec #define input_event_usec time.tv_usec #else __kernel_ulong_t __sec; __kernel_ulong_t __usec; #define input_event_sec __sec #define input_event_usec __usec #endif uint16_t type; uint16_t code; int32_t value; }; /* * Protocol version. */ #define EV_VERSION 0x010001 /* * IOCTLs (0x00 - 0x7f) */ struct input_id { uint16_t bustype; uint16_t vendor; uint16_t product; uint16_t version; }; /** * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls * @value: latest reported value for the axis. * @minimum: specifies minimum value for the axis. * @maximum: specifies maximum value for the axis. * @fuzz: specifies fuzz value that is used to filter noise from * the event stream. * @flat: values that are within this value will be discarded by * joydev interface and reported as 0 instead. * @resolution: specifies resolution for the values reported for * the axis. * * Note that input core does not clamp reported values to the * [minimum, maximum] limits, such task is left to userspace. * * The default resolution for main axes (ABS_X, ABS_Y, ABS_Z) * is reported in units per millimeter (units/mm), resolution * for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported * in units per radian. * When INPUT_PROP_ACCELEROMETER is set the resolution changes. * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in * in units per g (units/g) and in units per degree per second * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ). */ struct input_absinfo { int32_t value; int32_t minimum; int32_t maximum; int32_t fuzz; int32_t flat; int32_t resolution; }; /** * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls * @scancode: scancode represented in machine-endian form. * @len: length of the scancode that resides in @scancode buffer. * @index: index in the keymap, may be used instead of scancode * @flags: allows to specify how kernel should handle the request. For * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel * should perform lookup in keymap by @index instead of @scancode * @keycode: key code assigned to this scancode * * The structure is used to retrieve and modify keymap data. Users have * option of performing lookup either by @scancode itself or by @index * in keymap entry. EVIOCGKEYCODE will also return scancode or index * (depending on which element was used to perform lookup). */ struct input_keymap_entry { #define INPUT_KEYMAP_BY_INDEX (1 << 0) uint8_t flags; uint8_t len; uint16_t index; uint32_t keycode; uint8_t scancode[32]; }; struct input_mask { uint32_t type; uint32_t codes_size; uint64_t codes_ptr; }; #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ #define EVIOCGKEYCODE _IOWR('E', 0x04, unsigned int[2]) /* get keycode */ #define EVIOCGKEYCODE_V2 _IOWR('E', 0x04, struct input_keymap_entry) #define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ #define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry) #define EVIOCGNAME(len) _IOC(IOC_OUT, 'E', 0x06, len) /* get device name */ #define EVIOCGPHYS(len) _IOC(IOC_OUT, 'E', 0x07, len) /* get physical location */ #define EVIOCGUNIQ(len) _IOC(IOC_OUT, 'E', 0x08, len) /* get unique identifier */ #define EVIOCGPROP(len) _IOC(IOC_OUT, 'E', 0x09, len) /* get device properties */ /** * EVIOCGMTSLOTS(len) - get MT slot values * @len: size of the data buffer in bytes * * The ioctl buffer argument should be binary equivalent to * * struct input_mt_request_layout { * uint32_t code; * int32_t values[num_slots]; * }; * * where num_slots is the (arbitrary) number of MT slots to extract. * * The ioctl size argument (len) is the size of the buffer, which * should satisfy len = (num_slots + 1) * sizeof(int32_t). If len is * too small to fit all available slots, the first num_slots are * returned. * * Before the call, code is set to the wanted ABS_MT event type. On * return, values[] is filled with the slot values for the specified * ABS_MT code. * * If the request code is not an ABS_MT value, -EINVAL is returned. */ #define EVIOCGMTSLOTS(len) _IOC(IOC_INOUT, 'E', 0x0a, len) #define EVIOCGKEY(len) _IOC(IOC_OUT, 'E', 0x18, len) /* get global key state */ #define EVIOCGLED(len) _IOC(IOC_OUT, 'E', 0x19, len) /* get all LEDs */ #define EVIOCGSND(len) _IOC(IOC_OUT, 'E', 0x1a, len) /* get all sounds status */ #define EVIOCGSW(len) _IOC(IOC_OUT, 'E', 0x1b, len) /* get all switch states */ #define EVIOCGBIT(ev,len) _IOC(IOC_OUT, 'E', 0x20 + (ev), len) /* get event bits */ #define EVIOCGABS(abs) _IOR('E', 0x40 + (abs), struct input_absinfo) /* get abs value/limits */ #define EVIOCSABS(abs) _IOW('E', 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */ #define EVIOCSFF _IOW('E', 0x80, struct ff_effect) /* send a force effect to a force feedback device */ #define EVIOCRMFF _IOWINT('E', 0x81) /* Erase a force effect */ #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */ #define EVIOCGRAB _IOWINT('E', 0x90) /* Grab/Release device */ #define EVIOCREVOKE _IOWINT('E', 0x91) /* Revoke device access */ /** * EVIOCGMASK - Retrieve current event mask * * This ioctl allows user to retrieve the current event mask for specific * event type. The argument must be of type "struct input_mask" and * specifies the event type to query, the address of the receive buffer and * the size of the receive buffer. * * The event mask is a per-client mask that specifies which events are * forwarded to the client. Each event code is represented by a single bit * in the event mask. If the bit is set, the event is passed to the client * normally. Otherwise, the event is filtered and will never be queued on * the client's receive buffer. * * Event masks do not affect global state of the input device. They only * affect the file descriptor they are applied to. * * The default event mask for a client has all bits set, i.e. all events * are forwarded to the client. If the kernel is queried for an unknown * event type or if the receive buffer is larger than the number of * event codes known to the kernel, the kernel returns all zeroes for those * codes. * * At maximum, codes_size bytes are copied. * * This ioctl may fail with ENODEV in case the file is revoked, EFAULT * if the receive-buffer points to invalid memory, or EINVAL if the kernel * does not implement the ioctl. */ #define EVIOCGMASK _IOW('E', 0x92, struct input_mask) /* Get event-masks */ /** * EVIOCSMASK - Set event mask * * This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the * current event mask, this changes the client's event mask for a specific * type. See EVIOCGMASK for a description of event-masks and the * argument-type. * * This ioctl provides full forward compatibility. If the passed event type * is unknown to the kernel, or if the number of event codes specified in * the mask is bigger than what is known to the kernel, the ioctl is still * accepted and applied. However, any unknown codes are left untouched and * stay cleared. That means, the kernel always filters unknown codes * regardless of what the client requests. If the new mask doesn't cover * all known event-codes, all remaining codes are automatically cleared and * thus filtered. * * This ioctl may fail with ENODEV in case the file is revoked. EFAULT is * returned if the receive-buffer points to invalid memory. EINVAL is returned * if the kernel does not implement the ioctl. */ #define EVIOCSMASK _IOW('E', 0x93, struct input_mask) /* Set event-masks */ #define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */ /* * IDs. */ #define ID_BUS 0 #define ID_VENDOR 1 #define ID_PRODUCT 2 #define ID_VERSION 3 #define BUS_PCI 0x01 #define BUS_ISAPNP 0x02 #define BUS_USB 0x03 #define BUS_HIL 0x04 #define BUS_BLUETOOTH 0x05 #define BUS_VIRTUAL 0x06 #define BUS_ISA 0x10 #define BUS_I8042 0x11 #define BUS_XTKBD 0x12 #define BUS_RS232 0x13 #define BUS_GAMEPORT 0x14 #define BUS_PARPORT 0x15 #define BUS_AMIGA 0x16 #define BUS_ADB 0x17 #define BUS_I2C 0x18 #define BUS_HOST 0x19 #define BUS_GSC 0x1A #define BUS_ATARI 0x1B #define BUS_SPI 0x1C #define BUS_RMI 0x1D #define BUS_CEC 0x1E #define BUS_INTEL_ISHTP 0x1F /* * MT_TOOL types */ #define MT_TOOL_FINGER 0x00 #define MT_TOOL_PEN 0x01 #define MT_TOOL_PALM 0x02 #define MT_TOOL_DIAL 0x0a #define MT_TOOL_MAX 0x0f /* * Values describing the status of a force-feedback effect */ #define FF_STATUS_STOPPED 0x00 #define FF_STATUS_PLAYING 0x01 #define FF_STATUS_MAX 0x01 /* * Structures used in ioctls to upload effects to a device * They are pieces of a bigger structure (called ff_effect) */ /* * All duration values are expressed in ms. Values above 32767 ms (0x7fff) * should not be used and have unspecified results. */ /** * struct ff_replay - defines scheduling of the force-feedback effect * @length: duration of the effect * @delay: delay before effect should start playing */ struct ff_replay { uint16_t length; uint16_t delay; }; /** * struct ff_trigger - defines what triggers the force-feedback effect * @button: number of the button triggering the effect * @interval: controls how soon the effect can be re-triggered */ struct ff_trigger { uint16_t button; uint16_t interval; }; /** * struct ff_envelope - generic force-feedback effect envelope * @attack_length: duration of the attack (ms) * @attack_level: level at the beginning of the attack * @fade_length: duration of fade (ms) * @fade_level: level at the end of fade * * The @attack_level and @fade_level are absolute values; when applying * envelope force-feedback core will convert to positive/negative * value based on polarity of the default level of the effect. * Valid range for the attack and fade levels is 0x0000 - 0x7fff */ struct ff_envelope { uint16_t attack_length; uint16_t attack_level; uint16_t fade_length; uint16_t fade_level; }; /** * struct ff_constant_effect - defines parameters of a constant force-feedback effect * @level: strength of the effect; may be negative * @envelope: envelope data */ struct ff_constant_effect { int16_t level; struct ff_envelope envelope; }; /** * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect * @start_level: beginning strength of the effect; may be negative * @end_level: final strength of the effect; may be negative * @envelope: envelope data */ struct ff_ramp_effect { int16_t start_level; int16_t end_level; struct ff_envelope envelope; }; /** * struct ff_condition_effect - defines a spring or friction force-feedback effect * @right_saturation: maximum level when joystick moved all way to the right * @left_saturation: same for the left side * @right_coeff: controls how fast the force grows when the joystick moves * to the right * @left_coeff: same for the left side * @deadband: size of the dead zone, where no force is produced * @center: position of the dead zone */ struct ff_condition_effect { uint16_t right_saturation; uint16_t left_saturation; int16_t right_coeff; int16_t left_coeff; uint16_t deadband; int16_t center; }; /** * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect * @waveform: kind of the effect (wave) * @period: period of the wave (ms) * @magnitude: peak value * @offset: mean value of the wave (roughly) * @phase: 'horizontal' shift * @envelope: envelope data * @custom_len: number of samples (FF_CUSTOM only) * @custom_data: buffer of samples (FF_CUSTOM only) * * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP, * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined * for the time being as no driver supports it yet. * * Note: the data pointed by custom_data is copied by the driver. * You can therefore dispose of the memory after the upload/update. */ struct ff_periodic_effect { uint16_t waveform; uint16_t period; int16_t magnitude; int16_t offset; uint16_t phase; struct ff_envelope envelope; uint32_t custom_len; int16_t *custom_data; }; /** * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect * @strong_magnitude: magnitude of the heavy motor * @weak_magnitude: magnitude of the light one * * Some rumble pads have two motors of different weight. Strong_magnitude * represents the magnitude of the vibration generated by the heavy one. */ struct ff_rumble_effect { uint16_t strong_magnitude; uint16_t weak_magnitude; }; /** * struct ff_effect - defines force feedback effect * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING, * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM) * @id: an unique id assigned to an effect * @direction: direction of the effect * @trigger: trigger conditions (struct ff_trigger) * @replay: scheduling of the effect (struct ff_replay) * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further * defining effect parameters * * This structure is sent through ioctl from the application to the driver. * To create a new effect application should set its @id to -1; the kernel * will return assigned @id which can later be used to update or delete * this effect. * * Direction of the effect is encoded as follows: * 0 deg -> 0x0000 (down) * 90 deg -> 0x4000 (left) * 180 deg -> 0x8000 (up) * 270 deg -> 0xC000 (right) */ struct ff_effect { uint16_t type; int16_t id; uint16_t direction; struct ff_trigger trigger; struct ff_replay replay; union { struct ff_constant_effect constant; struct ff_ramp_effect ramp; struct ff_periodic_effect periodic; struct ff_condition_effect condition[2]; /* One for each axis */ struct ff_rumble_effect rumble; } u; }; /* * Force feedback effect types */ #define FF_RUMBLE 0x50 #define FF_PERIODIC 0x51 #define FF_CONSTANT 0x52 #define FF_SPRING 0x53 #define FF_FRICTION 0x54 #define FF_DAMPER 0x55 #define FF_INERTIA 0x56 #define FF_RAMP 0x57 #define FF_EFFECT_MIN FF_RUMBLE #define FF_EFFECT_MAX FF_RAMP /* * Force feedback periodic effect types */ #define FF_SQUARE 0x58 #define FF_TRIANGLE 0x59 #define FF_SINE 0x5a #define FF_SAW_UP 0x5b #define FF_SAW_DOWN 0x5c #define FF_CUSTOM 0x5d #define FF_WAVEFORM_MIN FF_SQUARE #define FF_WAVEFORM_MAX FF_CUSTOM /* * Set ff device properties */ #define FF_GAIN 0x60 #define FF_AUTOCENTER 0x61 /* * ff->playback(effect_id = FF_GAIN) is the first effect_id to * cause a collision with another ff method, in this case ff->set_gain(). * Therefore the greatest safe value for effect_id is FF_GAIN - 1, * and thus the total number of effects should never exceed FF_GAIN. */ #define FF_MAX_EFFECTS FF_GAIN #define FF_MAX 0x7f #define FF_CNT (FF_MAX+1) #endif /* _UAPI_INPUT_H */ libinput-1.28.1/include/linux/input.h000066400000000000000000000001361477265155700175460ustar00rootroot00000000000000#ifdef __linux__ #include "linux/input.h" #elif __FreeBSD__ #include "freebsd/input.h" #endif libinput-1.28.1/include/linux/linux/000077500000000000000000000000001477265155700173755ustar00rootroot00000000000000libinput-1.28.1/include/linux/linux/input-event-codes.h000066400000000000000000000672351477265155700231340ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ /* * Input event codes * * *** IMPORTANT *** * This file is not only included from C-code but also from devicetree source * files. As such this file MUST only contain comments and defines. * * Copyright (c) 1999-2002 Vojtech Pavlik * Copyright (c) 2015 Hans de Goede * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */ #ifndef _UAPI_INPUT_EVENT_CODES_H #define _UAPI_INPUT_EVENT_CODES_H /* * Device properties and quirks */ #define INPUT_PROP_POINTER 0x00 /* needs a pointer */ #define INPUT_PROP_DIRECT 0x01 /* direct input devices */ #define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */ #define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */ #define INPUT_PROP_TOPBUTTONPAD 0x04 /* softbuttons at top of pad */ #define INPUT_PROP_POINTING_STICK 0x05 /* is a pointing stick */ #define INPUT_PROP_ACCELEROMETER 0x06 /* has accelerometer */ #define INPUT_PROP_MAX 0x1f #define INPUT_PROP_CNT (INPUT_PROP_MAX + 1) /* * Event types */ #define EV_SYN 0x00 #define EV_KEY 0x01 #define EV_REL 0x02 #define EV_ABS 0x03 #define EV_MSC 0x04 #define EV_SW 0x05 #define EV_LED 0x11 #define EV_SND 0x12 #define EV_REP 0x14 #define EV_FF 0x15 #define EV_PWR 0x16 #define EV_FF_STATUS 0x17 #define EV_MAX 0x1f #define EV_CNT (EV_MAX+1) /* * Synchronization events. */ #define SYN_REPORT 0 #define SYN_CONFIG 1 #define SYN_MT_REPORT 2 #define SYN_DROPPED 3 #define SYN_MAX 0xf #define SYN_CNT (SYN_MAX+1) /* * Keys and buttons * * Most of the keys/buttons are modeled after USB HUT 1.12 * (see http://www.usb.org/developers/hidpage). * Abbreviations in the comments: * AC - Application Control * AL - Application Launch Button * SC - System Control */ #define KEY_RESERVED 0 #define KEY_ESC 1 #define KEY_1 2 #define KEY_2 3 #define KEY_3 4 #define KEY_4 5 #define KEY_5 6 #define KEY_6 7 #define KEY_7 8 #define KEY_8 9 #define KEY_9 10 #define KEY_0 11 #define KEY_MINUS 12 #define KEY_EQUAL 13 #define KEY_BACKSPACE 14 #define KEY_TAB 15 #define KEY_Q 16 #define KEY_W 17 #define KEY_E 18 #define KEY_R 19 #define KEY_T 20 #define KEY_Y 21 #define KEY_U 22 #define KEY_I 23 #define KEY_O 24 #define KEY_P 25 #define KEY_LEFTBRACE 26 #define KEY_RIGHTBRACE 27 #define KEY_ENTER 28 #define KEY_LEFTCTRL 29 #define KEY_A 30 #define KEY_S 31 #define KEY_D 32 #define KEY_F 33 #define KEY_G 34 #define KEY_H 35 #define KEY_J 36 #define KEY_K 37 #define KEY_L 38 #define KEY_SEMICOLON 39 #define KEY_APOSTROPHE 40 #define KEY_GRAVE 41 #define KEY_LEFTSHIFT 42 #define KEY_BACKSLASH 43 #define KEY_Z 44 #define KEY_X 45 #define KEY_C 46 #define KEY_V 47 #define KEY_B 48 #define KEY_N 49 #define KEY_M 50 #define KEY_COMMA 51 #define KEY_DOT 52 #define KEY_SLASH 53 #define KEY_RIGHTSHIFT 54 #define KEY_KPASTERISK 55 #define KEY_LEFTALT 56 #define KEY_SPACE 57 #define KEY_CAPSLOCK 58 #define KEY_F1 59 #define KEY_F2 60 #define KEY_F3 61 #define KEY_F4 62 #define KEY_F5 63 #define KEY_F6 64 #define KEY_F7 65 #define KEY_F8 66 #define KEY_F9 67 #define KEY_F10 68 #define KEY_NUMLOCK 69 #define KEY_SCROLLLOCK 70 #define KEY_KP7 71 #define KEY_KP8 72 #define KEY_KP9 73 #define KEY_KPMINUS 74 #define KEY_KP4 75 #define KEY_KP5 76 #define KEY_KP6 77 #define KEY_KPPLUS 78 #define KEY_KP1 79 #define KEY_KP2 80 #define KEY_KP3 81 #define KEY_KP0 82 #define KEY_KPDOT 83 #define KEY_ZENKAKUHANKAKU 85 #define KEY_102ND 86 #define KEY_F11 87 #define KEY_F12 88 #define KEY_RO 89 #define KEY_KATAKANA 90 #define KEY_HIRAGANA 91 #define KEY_HENKAN 92 #define KEY_KATAKANAHIRAGANA 93 #define KEY_MUHENKAN 94 #define KEY_KPJPCOMMA 95 #define KEY_KPENTER 96 #define KEY_RIGHTCTRL 97 #define KEY_KPSLASH 98 #define KEY_SYSRQ 99 #define KEY_RIGHTALT 100 #define KEY_LINEFEED 101 #define KEY_HOME 102 #define KEY_UP 103 #define KEY_PAGEUP 104 #define KEY_LEFT 105 #define KEY_RIGHT 106 #define KEY_END 107 #define KEY_DOWN 108 #define KEY_PAGEDOWN 109 #define KEY_INSERT 110 #define KEY_DELETE 111 #define KEY_MACRO 112 #define KEY_MUTE 113 #define KEY_VOLUMEDOWN 114 #define KEY_VOLUMEUP 115 #define KEY_POWER 116 /* SC System Power Down */ #define KEY_KPEQUAL 117 #define KEY_KPPLUSMINUS 118 #define KEY_PAUSE 119 #define KEY_SCALE 120 /* AL Compiz Scale (Expose) */ #define KEY_KPCOMMA 121 #define KEY_HANGEUL 122 #define KEY_HANGUEL KEY_HANGEUL #define KEY_HANJA 123 #define KEY_YEN 124 #define KEY_LEFTMETA 125 #define KEY_RIGHTMETA 126 #define KEY_COMPOSE 127 #define KEY_STOP 128 /* AC Stop */ #define KEY_AGAIN 129 #define KEY_PROPS 130 /* AC Properties */ #define KEY_UNDO 131 /* AC Undo */ #define KEY_FRONT 132 #define KEY_COPY 133 /* AC Copy */ #define KEY_OPEN 134 /* AC Open */ #define KEY_PASTE 135 /* AC Paste */ #define KEY_FIND 136 /* AC Search */ #define KEY_CUT 137 /* AC Cut */ #define KEY_HELP 138 /* AL Integrated Help Center */ #define KEY_MENU 139 /* Menu (show menu) */ #define KEY_CALC 140 /* AL Calculator */ #define KEY_SETUP 141 #define KEY_SLEEP 142 /* SC System Sleep */ #define KEY_WAKEUP 143 /* System Wake Up */ #define KEY_FILE 144 /* AL Local Machine Browser */ #define KEY_SENDFILE 145 #define KEY_DELETEFILE 146 #define KEY_XFER 147 #define KEY_PROG1 148 #define KEY_PROG2 149 #define KEY_WWW 150 /* AL Internet Browser */ #define KEY_MSDOS 151 #define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */ #define KEY_SCREENLOCK KEY_COFFEE #define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */ #define KEY_DIRECTION KEY_ROTATE_DISPLAY #define KEY_CYCLEWINDOWS 154 #define KEY_MAIL 155 #define KEY_BOOKMARKS 156 /* AC Bookmarks */ #define KEY_COMPUTER 157 #define KEY_BACK 158 /* AC Back */ #define KEY_FORWARD 159 /* AC Forward */ #define KEY_CLOSECD 160 #define KEY_EJECTCD 161 #define KEY_EJECTCLOSECD 162 #define KEY_NEXTSONG 163 #define KEY_PLAYPAUSE 164 #define KEY_PREVIOUSSONG 165 #define KEY_STOPCD 166 #define KEY_RECORD 167 #define KEY_REWIND 168 #define KEY_PHONE 169 /* Media Select Telephone */ #define KEY_ISO 170 #define KEY_CONFIG 171 /* AL Consumer Control Configuration */ #define KEY_HOMEPAGE 172 /* AC Home */ #define KEY_REFRESH 173 /* AC Refresh */ #define KEY_EXIT 174 /* AC Exit */ #define KEY_MOVE 175 #define KEY_EDIT 176 #define KEY_SCROLLUP 177 #define KEY_SCROLLDOWN 178 #define KEY_KPLEFTPAREN 179 #define KEY_KPRIGHTPAREN 180 #define KEY_NEW 181 /* AC New */ #define KEY_REDO 182 /* AC Redo/Repeat */ #define KEY_F13 183 #define KEY_F14 184 #define KEY_F15 185 #define KEY_F16 186 #define KEY_F17 187 #define KEY_F18 188 #define KEY_F19 189 #define KEY_F20 190 #define KEY_F21 191 #define KEY_F22 192 #define KEY_F23 193 #define KEY_F24 194 #define KEY_PLAYCD 200 #define KEY_PAUSECD 201 #define KEY_PROG3 202 #define KEY_PROG4 203 #define KEY_DASHBOARD 204 /* AL Dashboard */ #define KEY_SUSPEND 205 #define KEY_CLOSE 206 /* AC Close */ #define KEY_PLAY 207 #define KEY_FASTFORWARD 208 #define KEY_BASSBOOST 209 #define KEY_PRINT 210 /* AC Print */ #define KEY_HP 211 #define KEY_CAMERA 212 #define KEY_SOUND 213 #define KEY_QUESTION 214 #define KEY_EMAIL 215 #define KEY_CHAT 216 #define KEY_SEARCH 217 #define KEY_CONNECT 218 #define KEY_FINANCE 219 /* AL Checkbook/Finance */ #define KEY_SPORT 220 #define KEY_SHOP 221 #define KEY_ALTERASE 222 #define KEY_CANCEL 223 /* AC Cancel */ #define KEY_BRIGHTNESSDOWN 224 #define KEY_BRIGHTNESSUP 225 #define KEY_MEDIA 226 #define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video outputs (Monitor/LCD/TV-out/etc) */ #define KEY_KBDILLUMTOGGLE 228 #define KEY_KBDILLUMDOWN 229 #define KEY_KBDILLUMUP 230 #define KEY_SEND 231 /* AC Send */ #define KEY_REPLY 232 /* AC Reply */ #define KEY_FORWARDMAIL 233 /* AC Forward Msg */ #define KEY_SAVE 234 /* AC Save */ #define KEY_DOCUMENTS 235 #define KEY_BATTERY 236 #define KEY_BLUETOOTH 237 #define KEY_WLAN 238 #define KEY_UWB 239 #define KEY_UNKNOWN 240 #define KEY_VIDEO_NEXT 241 /* drive next video source */ #define KEY_VIDEO_PREV 242 /* drive previous video source */ #define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */ #define KEY_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual brightness control is off, rely on ambient */ #define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO #define KEY_DISPLAY_OFF 245 /* display device to off state */ #define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */ #define KEY_WIMAX KEY_WWAN #define KEY_RFKILL 247 /* Key that controls all radios */ #define KEY_MICMUTE 248 /* Mute / unmute the microphone */ /* Code 255 is reserved for special needs of AT keyboard driver */ #define BTN_MISC 0x100 #define BTN_0 0x100 #define BTN_1 0x101 #define BTN_2 0x102 #define BTN_3 0x103 #define BTN_4 0x104 #define BTN_5 0x105 #define BTN_6 0x106 #define BTN_7 0x107 #define BTN_8 0x108 #define BTN_9 0x109 #define BTN_MOUSE 0x110 #define BTN_LEFT 0x110 #define BTN_RIGHT 0x111 #define BTN_MIDDLE 0x112 #define BTN_SIDE 0x113 #define BTN_EXTRA 0x114 #define BTN_FORWARD 0x115 #define BTN_BACK 0x116 #define BTN_TASK 0x117 #define BTN_JOYSTICK 0x120 #define BTN_TRIGGER 0x120 #define BTN_THUMB 0x121 #define BTN_THUMB2 0x122 #define BTN_TOP 0x123 #define BTN_TOP2 0x124 #define BTN_PINKIE 0x125 #define BTN_BASE 0x126 #define BTN_BASE2 0x127 #define BTN_BASE3 0x128 #define BTN_BASE4 0x129 #define BTN_BASE5 0x12a #define BTN_BASE6 0x12b #define BTN_DEAD 0x12f #define BTN_GAMEPAD 0x130 #define BTN_SOUTH 0x130 #define BTN_A BTN_SOUTH #define BTN_EAST 0x131 #define BTN_B BTN_EAST #define BTN_C 0x132 #define BTN_NORTH 0x133 #define BTN_X BTN_NORTH #define BTN_WEST 0x134 #define BTN_Y BTN_WEST #define BTN_Z 0x135 #define BTN_TL 0x136 #define BTN_TR 0x137 #define BTN_TL2 0x138 #define BTN_TR2 0x139 #define BTN_SELECT 0x13a #define BTN_START 0x13b #define BTN_MODE 0x13c #define BTN_THUMBL 0x13d #define BTN_THUMBR 0x13e #define BTN_DIGI 0x140 #define BTN_TOOL_PEN 0x140 #define BTN_TOOL_RUBBER 0x141 #define BTN_TOOL_BRUSH 0x142 #define BTN_TOOL_PENCIL 0x143 #define BTN_TOOL_AIRBRUSH 0x144 #define BTN_TOOL_FINGER 0x145 #define BTN_TOOL_MOUSE 0x146 #define BTN_TOOL_LENS 0x147 #define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */ #define BTN_STYLUS3 0x149 #define BTN_TOUCH 0x14a #define BTN_STYLUS 0x14b #define BTN_STYLUS2 0x14c #define BTN_TOOL_DOUBLETAP 0x14d #define BTN_TOOL_TRIPLETAP 0x14e #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ #define BTN_WHEEL 0x150 #define BTN_GEAR_DOWN 0x150 #define BTN_GEAR_UP 0x151 #define KEY_OK 0x160 #define KEY_SELECT 0x161 #define KEY_GOTO 0x162 #define KEY_CLEAR 0x163 #define KEY_POWER2 0x164 #define KEY_OPTION 0x165 #define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */ #define KEY_TIME 0x167 #define KEY_VENDOR 0x168 #define KEY_ARCHIVE 0x169 #define KEY_PROGRAM 0x16a /* Media Select Program Guide */ #define KEY_CHANNEL 0x16b #define KEY_FAVORITES 0x16c #define KEY_EPG 0x16d #define KEY_PVR 0x16e /* Media Select Home */ #define KEY_MHP 0x16f #define KEY_LANGUAGE 0x170 #define KEY_TITLE 0x171 #define KEY_SUBTITLE 0x172 #define KEY_ANGLE 0x173 #define KEY_FULL_SCREEN 0x174 /* AC View Toggle */ #define KEY_ZOOM KEY_FULL_SCREEN #define KEY_MODE 0x175 #define KEY_KEYBOARD 0x176 #define KEY_ASPECT_RATIO 0x177 /* HUTRR37: Aspect */ #define KEY_SCREEN KEY_ASPECT_RATIO #define KEY_PC 0x178 /* Media Select Computer */ #define KEY_TV 0x179 /* Media Select TV */ #define KEY_TV2 0x17a /* Media Select Cable */ #define KEY_VCR 0x17b /* Media Select VCR */ #define KEY_VCR2 0x17c /* VCR Plus */ #define KEY_SAT 0x17d /* Media Select Satellite */ #define KEY_SAT2 0x17e #define KEY_CD 0x17f /* Media Select CD */ #define KEY_TAPE 0x180 /* Media Select Tape */ #define KEY_RADIO 0x181 #define KEY_TUNER 0x182 /* Media Select Tuner */ #define KEY_PLAYER 0x183 #define KEY_TEXT 0x184 #define KEY_DVD 0x185 /* Media Select DVD */ #define KEY_AUX 0x186 #define KEY_MP3 0x187 #define KEY_AUDIO 0x188 /* AL Audio Browser */ #define KEY_VIDEO 0x189 /* AL Movie Browser */ #define KEY_DIRECTORY 0x18a #define KEY_LIST 0x18b #define KEY_MEMO 0x18c /* Media Select Messages */ #define KEY_CALENDAR 0x18d #define KEY_RED 0x18e #define KEY_GREEN 0x18f #define KEY_YELLOW 0x190 #define KEY_BLUE 0x191 #define KEY_CHANNELUP 0x192 /* Channel Increment */ #define KEY_CHANNELDOWN 0x193 /* Channel Decrement */ #define KEY_FIRST 0x194 #define KEY_LAST 0x195 /* Recall Last */ #define KEY_AB 0x196 #define KEY_NEXT 0x197 #define KEY_RESTART 0x198 #define KEY_SLOW 0x199 #define KEY_SHUFFLE 0x19a #define KEY_BREAK 0x19b #define KEY_PREVIOUS 0x19c #define KEY_DIGITS 0x19d #define KEY_TEEN 0x19e #define KEY_TWEN 0x19f #define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */ #define KEY_GAMES 0x1a1 /* Media Select Games */ #define KEY_ZOOMIN 0x1a2 /* AC Zoom In */ #define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */ #define KEY_ZOOMRESET 0x1a4 /* AC Zoom */ #define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */ #define KEY_EDITOR 0x1a6 /* AL Text Editor */ #define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */ #define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */ #define KEY_PRESENTATION 0x1a9 /* AL Presentation App */ #define KEY_DATABASE 0x1aa /* AL Database App */ #define KEY_NEWS 0x1ab /* AL Newsreader */ #define KEY_VOICEMAIL 0x1ac /* AL Voicemail */ #define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */ #define KEY_MESSENGER 0x1ae /* AL Instant Messaging */ #define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */ #define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE #define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */ #define KEY_LOGOFF 0x1b1 /* AL Logoff */ #define KEY_DOLLAR 0x1b2 #define KEY_EURO 0x1b3 #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ #define KEY_FRAMEFORWARD 0x1b5 #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ #define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */ #define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */ #define KEY_IMAGES 0x1ba /* AL Image Browser */ #define KEY_DEL_EOL 0x1c0 #define KEY_DEL_EOS 0x1c1 #define KEY_INS_LINE 0x1c2 #define KEY_DEL_LINE 0x1c3 #define KEY_FN 0x1d0 #define KEY_FN_ESC 0x1d1 #define KEY_FN_F1 0x1d2 #define KEY_FN_F2 0x1d3 #define KEY_FN_F3 0x1d4 #define KEY_FN_F4 0x1d5 #define KEY_FN_F5 0x1d6 #define KEY_FN_F6 0x1d7 #define KEY_FN_F7 0x1d8 #define KEY_FN_F8 0x1d9 #define KEY_FN_F9 0x1da #define KEY_FN_F10 0x1db #define KEY_FN_F11 0x1dc #define KEY_FN_F12 0x1dd #define KEY_FN_1 0x1de #define KEY_FN_2 0x1df #define KEY_FN_D 0x1e0 #define KEY_FN_E 0x1e1 #define KEY_FN_F 0x1e2 #define KEY_FN_S 0x1e3 #define KEY_FN_B 0x1e4 #define KEY_BRL_DOT1 0x1f1 #define KEY_BRL_DOT2 0x1f2 #define KEY_BRL_DOT3 0x1f3 #define KEY_BRL_DOT4 0x1f4 #define KEY_BRL_DOT5 0x1f5 #define KEY_BRL_DOT6 0x1f6 #define KEY_BRL_DOT7 0x1f7 #define KEY_BRL_DOT8 0x1f8 #define KEY_BRL_DOT9 0x1f9 #define KEY_BRL_DOT10 0x1fa #define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */ #define KEY_NUMERIC_1 0x201 /* and other keypads */ #define KEY_NUMERIC_2 0x202 #define KEY_NUMERIC_3 0x203 #define KEY_NUMERIC_4 0x204 #define KEY_NUMERIC_5 0x205 #define KEY_NUMERIC_6 0x206 #define KEY_NUMERIC_7 0x207 #define KEY_NUMERIC_8 0x208 #define KEY_NUMERIC_9 0x209 #define KEY_NUMERIC_STAR 0x20a #define KEY_NUMERIC_POUND 0x20b #define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */ #define KEY_NUMERIC_B 0x20d #define KEY_NUMERIC_C 0x20e #define KEY_NUMERIC_D 0x20f #define KEY_CAMERA_FOCUS 0x210 #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ #define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */ #define KEY_TOUCHPAD_ON 0x213 #define KEY_TOUCHPAD_OFF 0x214 #define KEY_CAMERA_ZOOMIN 0x215 #define KEY_CAMERA_ZOOMOUT 0x216 #define KEY_CAMERA_UP 0x217 #define KEY_CAMERA_DOWN 0x218 #define KEY_CAMERA_LEFT 0x219 #define KEY_CAMERA_RIGHT 0x21a #define KEY_ATTENDANT_ON 0x21b #define KEY_ATTENDANT_OFF 0x21c #define KEY_ATTENDANT_TOGGLE 0x21d /* Attendant call on or off */ #define KEY_LIGHTS_TOGGLE 0x21e /* Reading light on or off */ #define BTN_DPAD_UP 0x220 #define BTN_DPAD_DOWN 0x221 #define BTN_DPAD_LEFT 0x222 #define BTN_DPAD_RIGHT 0x223 #define KEY_ALS_TOGGLE 0x230 /* Ambient light sensor */ #define KEY_ROTATE_LOCK_TOGGLE 0x231 /* Display rotation lock */ #define KEY_BUTTONCONFIG 0x240 /* AL Button Configuration */ #define KEY_TASKMANAGER 0x241 /* AL Task/Project Manager */ #define KEY_JOURNAL 0x242 /* AL Log/Journal/Timecard */ #define KEY_CONTROLPANEL 0x243 /* AL Control Panel */ #define KEY_APPSELECT 0x244 /* AL Select Task/Application */ #define KEY_SCREENSAVER 0x245 /* AL Screen Saver */ #define KEY_VOICECOMMAND 0x246 /* Listening Voice Command */ #define KEY_ASSISTANT 0x247 /* AL Context-aware desktop assistant */ #define KEY_KBD_LAYOUT_NEXT 0x248 /* AC Next Keyboard Layout Select */ #define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */ #define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */ #define KEY_KBDINPUTASSIST_PREV 0x260 #define KEY_KBDINPUTASSIST_NEXT 0x261 #define KEY_KBDINPUTASSIST_PREVGROUP 0x262 #define KEY_KBDINPUTASSIST_NEXTGROUP 0x263 #define KEY_KBDINPUTASSIST_ACCEPT 0x264 #define KEY_KBDINPUTASSIST_CANCEL 0x265 /* Diagonal movement keys */ #define KEY_RIGHT_UP 0x266 #define KEY_RIGHT_DOWN 0x267 #define KEY_LEFT_UP 0x268 #define KEY_LEFT_DOWN 0x269 #define KEY_ROOT_MENU 0x26a /* Show Device's Root Menu */ /* Show Top Menu of the Media (e.g. DVD) */ #define KEY_MEDIA_TOP_MENU 0x26b #define KEY_NUMERIC_11 0x26c #define KEY_NUMERIC_12 0x26d /* * Toggle Audio Description: refers to an audio service that helps blind and * visually impaired consumers understand the action in a program. Note: in * some countries this is referred to as "Video Description". */ #define KEY_AUDIO_DESC 0x26e #define KEY_3D_MODE 0x26f #define KEY_NEXT_FAVORITE 0x270 #define KEY_STOP_RECORD 0x271 #define KEY_PAUSE_RECORD 0x272 #define KEY_VOD 0x273 /* Video on Demand */ #define KEY_UNMUTE 0x274 #define KEY_FASTREVERSE 0x275 #define KEY_SLOWREVERSE 0x276 /* * Control a data application associated with the currently viewed channel, * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.) */ #define KEY_DATA 0x277 #define KEY_ONSCREEN_KEYBOARD 0x278 /* Electronic privacy screen control */ #define KEY_PRIVACY_SCREEN_TOGGLE 0x279 /* Select an area of screen to be copied */ #define KEY_SELECTIVE_SCREENSHOT 0x27a /* * Some keyboards have keys which do not have a defined meaning, these keys * are intended to be programmed / bound to macros by the user. For most * keyboards with these macro-keys the key-sequence to inject, or action to * take, is all handled by software on the host side. So from the kernel's * point of view these are just normal keys. * * The KEY_MACRO# codes below are intended for such keys, which may be labeled * e.g. G1-G18, or S1 - S30. The KEY_MACRO# codes MUST NOT be used for keys * where the marking on the key does indicate a defined meaning / purpose. * * The KEY_MACRO# codes MUST also NOT be used as fallback for when no existing * KEY_FOO define matches the marking / purpose. In this case a new KEY_FOO * define MUST be added. */ #define KEY_MACRO1 0x290 #define KEY_MACRO2 0x291 #define KEY_MACRO3 0x292 #define KEY_MACRO4 0x293 #define KEY_MACRO5 0x294 #define KEY_MACRO6 0x295 #define KEY_MACRO7 0x296 #define KEY_MACRO8 0x297 #define KEY_MACRO9 0x298 #define KEY_MACRO10 0x299 #define KEY_MACRO11 0x29a #define KEY_MACRO12 0x29b #define KEY_MACRO13 0x29c #define KEY_MACRO14 0x29d #define KEY_MACRO15 0x29e #define KEY_MACRO16 0x29f #define KEY_MACRO17 0x2a0 #define KEY_MACRO18 0x2a1 #define KEY_MACRO19 0x2a2 #define KEY_MACRO20 0x2a3 #define KEY_MACRO21 0x2a4 #define KEY_MACRO22 0x2a5 #define KEY_MACRO23 0x2a6 #define KEY_MACRO24 0x2a7 #define KEY_MACRO25 0x2a8 #define KEY_MACRO26 0x2a9 #define KEY_MACRO27 0x2aa #define KEY_MACRO28 0x2ab #define KEY_MACRO29 0x2ac #define KEY_MACRO30 0x2ad /* * Some keyboards with the macro-keys described above have some extra keys * for controlling the host-side software responsible for the macro handling: * -A macro recording start/stop key. Note that not all keyboards which emit * KEY_MACRO_RECORD_START will also emit KEY_MACRO_RECORD_STOP if * KEY_MACRO_RECORD_STOP is not advertised, then KEY_MACRO_RECORD_START * should be interpreted as a recording start/stop toggle; * -Keys for switching between different macro (pre)sets, either a key for * cycling through the configured presets or keys to directly select a preset. */ #define KEY_MACRO_RECORD_START 0x2b0 #define KEY_MACRO_RECORD_STOP 0x2b1 #define KEY_MACRO_PRESET_CYCLE 0x2b2 #define KEY_MACRO_PRESET1 0x2b3 #define KEY_MACRO_PRESET2 0x2b4 #define KEY_MACRO_PRESET3 0x2b5 /* * Some keyboards have a buildin LCD panel where the contents are controlled * by the host. Often these have a number of keys directly below the LCD * intended for controlling a menu shown on the LCD. These keys often don't * have any labeling so we just name them KEY_KBD_LCD_MENU# */ #define KEY_KBD_LCD_MENU1 0x2b8 #define KEY_KBD_LCD_MENU2 0x2b9 #define KEY_KBD_LCD_MENU3 0x2ba #define KEY_KBD_LCD_MENU4 0x2bb #define KEY_KBD_LCD_MENU5 0x2bc #define BTN_TRIGGER_HAPPY 0x2c0 #define BTN_TRIGGER_HAPPY1 0x2c0 #define BTN_TRIGGER_HAPPY2 0x2c1 #define BTN_TRIGGER_HAPPY3 0x2c2 #define BTN_TRIGGER_HAPPY4 0x2c3 #define BTN_TRIGGER_HAPPY5 0x2c4 #define BTN_TRIGGER_HAPPY6 0x2c5 #define BTN_TRIGGER_HAPPY7 0x2c6 #define BTN_TRIGGER_HAPPY8 0x2c7 #define BTN_TRIGGER_HAPPY9 0x2c8 #define BTN_TRIGGER_HAPPY10 0x2c9 #define BTN_TRIGGER_HAPPY11 0x2ca #define BTN_TRIGGER_HAPPY12 0x2cb #define BTN_TRIGGER_HAPPY13 0x2cc #define BTN_TRIGGER_HAPPY14 0x2cd #define BTN_TRIGGER_HAPPY15 0x2ce #define BTN_TRIGGER_HAPPY16 0x2cf #define BTN_TRIGGER_HAPPY17 0x2d0 #define BTN_TRIGGER_HAPPY18 0x2d1 #define BTN_TRIGGER_HAPPY19 0x2d2 #define BTN_TRIGGER_HAPPY20 0x2d3 #define BTN_TRIGGER_HAPPY21 0x2d4 #define BTN_TRIGGER_HAPPY22 0x2d5 #define BTN_TRIGGER_HAPPY23 0x2d6 #define BTN_TRIGGER_HAPPY24 0x2d7 #define BTN_TRIGGER_HAPPY25 0x2d8 #define BTN_TRIGGER_HAPPY26 0x2d9 #define BTN_TRIGGER_HAPPY27 0x2da #define BTN_TRIGGER_HAPPY28 0x2db #define BTN_TRIGGER_HAPPY29 0x2dc #define BTN_TRIGGER_HAPPY30 0x2dd #define BTN_TRIGGER_HAPPY31 0x2de #define BTN_TRIGGER_HAPPY32 0x2df #define BTN_TRIGGER_HAPPY33 0x2e0 #define BTN_TRIGGER_HAPPY34 0x2e1 #define BTN_TRIGGER_HAPPY35 0x2e2 #define BTN_TRIGGER_HAPPY36 0x2e3 #define BTN_TRIGGER_HAPPY37 0x2e4 #define BTN_TRIGGER_HAPPY38 0x2e5 #define BTN_TRIGGER_HAPPY39 0x2e6 #define BTN_TRIGGER_HAPPY40 0x2e7 /* We avoid low common keys in module aliases so they don't get huge. */ #define KEY_MIN_INTERESTING KEY_MUTE #define KEY_MAX 0x2ff #define KEY_CNT (KEY_MAX+1) /* * Relative axes */ #define REL_X 0x00 #define REL_Y 0x01 #define REL_Z 0x02 #define REL_RX 0x03 #define REL_RY 0x04 #define REL_RZ 0x05 #define REL_HWHEEL 0x06 #define REL_DIAL 0x07 #define REL_WHEEL 0x08 #define REL_MISC 0x09 /* * 0x0a is reserved and should not be used in input drivers. * It was used by HID as REL_MISC+1 and userspace needs to detect if * the next REL_* event is correct or is just REL_MISC + n. * We define here REL_RESERVED so userspace can rely on it and detect * the situation described above. */ #define REL_RESERVED 0x0a #define REL_WHEEL_HI_RES 0x0b #define REL_HWHEEL_HI_RES 0x0c #define REL_MAX 0x0f #define REL_CNT (REL_MAX+1) /* * Absolute axes */ #define ABS_X 0x00 #define ABS_Y 0x01 #define ABS_Z 0x02 #define ABS_RX 0x03 #define ABS_RY 0x04 #define ABS_RZ 0x05 #define ABS_THROTTLE 0x06 #define ABS_RUDDER 0x07 #define ABS_WHEEL 0x08 #define ABS_GAS 0x09 #define ABS_BRAKE 0x0a #define ABS_HAT0X 0x10 #define ABS_HAT0Y 0x11 #define ABS_HAT1X 0x12 #define ABS_HAT1Y 0x13 #define ABS_HAT2X 0x14 #define ABS_HAT2Y 0x15 #define ABS_HAT3X 0x16 #define ABS_HAT3Y 0x17 #define ABS_PRESSURE 0x18 #define ABS_DISTANCE 0x19 #define ABS_TILT_X 0x1a #define ABS_TILT_Y 0x1b #define ABS_TOOL_WIDTH 0x1c #define ABS_VOLUME 0x20 #define ABS_MISC 0x28 /* * 0x2e is reserved and should not be used in input drivers. * It was used by HID as ABS_MISC+6 and userspace needs to detect if * the next ABS_* event is correct or is just ABS_MISC + n. * We define here ABS_RESERVED so userspace can rely on it and detect * the situation described above. */ #define ABS_RESERVED 0x2e #define ABS_MT_SLOT 0x2f /* MT slot being modified */ #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ #define ABS_MT_POSITION_X 0x35 /* Center X touch position */ #define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */ #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ #define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ #define ABS_MT_TOOL_X 0x3c /* Center X tool position */ #define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */ #define ABS_MAX 0x3f #define ABS_CNT (ABS_MAX+1) /* * Switch events */ #define SW_LID 0x00 /* set = lid shut */ #define SW_TABLET_MODE 0x01 /* set = tablet mode */ #define SW_HEADPHONE_INSERT 0x02 /* set = inserted */ #define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any" set = radio enabled */ #define SW_RADIO SW_RFKILL_ALL /* deprecated */ #define SW_MICROPHONE_INSERT 0x04 /* set = inserted */ #define SW_DOCK 0x05 /* set = plugged into dock */ #define SW_LINEOUT_INSERT 0x06 /* set = inserted */ #define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ #define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */ #define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */ #define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ #define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ #define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */ #define SW_LINEIN_INSERT 0x0d /* set = inserted */ #define SW_MUTE_DEVICE 0x0e /* set = device disabled */ #define SW_PEN_INSERTED 0x0f /* set = pen inserted */ #define SW_MACHINE_COVER 0x10 /* set = cover closed */ #define SW_MAX 0x10 #define SW_CNT (SW_MAX+1) /* * Misc events */ #define MSC_SERIAL 0x00 #define MSC_PULSELED 0x01 #define MSC_GESTURE 0x02 #define MSC_RAW 0x03 #define MSC_SCAN 0x04 #define MSC_TIMESTAMP 0x05 #define MSC_MAX 0x07 #define MSC_CNT (MSC_MAX+1) /* * LEDs */ #define LED_NUML 0x00 #define LED_CAPSL 0x01 #define LED_SCROLLL 0x02 #define LED_COMPOSE 0x03 #define LED_KANA 0x04 #define LED_SLEEP 0x05 #define LED_SUSPEND 0x06 #define LED_MUTE 0x07 #define LED_MISC 0x08 #define LED_MAIL 0x09 #define LED_CHARGING 0x0a #define LED_MAX 0x0f #define LED_CNT (LED_MAX+1) /* * Autorepeat values */ #define REP_DELAY 0x00 #define REP_PERIOD 0x01 #define REP_MAX 0x01 #define REP_CNT (REP_MAX+1) /* * Sounds */ #define SND_CLICK 0x00 #define SND_BELL 0x01 #define SND_TONE 0x02 #define SND_MAX 0x07 #define SND_CNT (SND_MAX+1) #endif libinput-1.28.1/include/linux/linux/input.h000066400000000000000000000370111477265155700207070ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * Copyright (c) 1999-2002 Vojtech Pavlik * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */ #ifndef _INPUT_H #define _INPUT_H #include #include #include #include #include "input-event-codes.h" /* * The event structure itself * Note that __USE_TIME_BITS64 is defined by libc based on * application's request to use 64 bit time_t. */ struct input_event { #if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL) struct timeval time; #define input_event_sec time.tv_sec #define input_event_usec time.tv_usec #else __kernel_ulong_t __sec; __kernel_ulong_t __usec; #define input_event_sec __sec #define input_event_usec __usec #endif __u16 type; __u16 code; __s32 value; }; /* * Protocol version. */ #define EV_VERSION 0x010001 /* * IOCTLs (0x00 - 0x7f) */ struct input_id { __u16 bustype; __u16 vendor; __u16 product; __u16 version; }; /** * struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls * @value: latest reported value for the axis. * @minimum: specifies minimum value for the axis. * @maximum: specifies maximum value for the axis. * @fuzz: specifies fuzz value that is used to filter noise from * the event stream. * @flat: values that are within this value will be discarded by * joydev interface and reported as 0 instead. * @resolution: specifies resolution for the values reported for * the axis. * * Note that input core does not clamp reported values to the * [minimum, maximum] limits, such task is left to userspace. * * The default resolution for main axes (ABS_X, ABS_Y, ABS_Z) * is reported in units per millimeter (units/mm), resolution * for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported * in units per radian. * When INPUT_PROP_ACCELEROMETER is set the resolution changes. * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in * in units per g (units/g) and in units per degree per second * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ). */ struct input_absinfo { __s32 value; __s32 minimum; __s32 maximum; __s32 fuzz; __s32 flat; __s32 resolution; }; /** * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls * @scancode: scancode represented in machine-endian form. * @len: length of the scancode that resides in @scancode buffer. * @index: index in the keymap, may be used instead of scancode * @flags: allows to specify how kernel should handle the request. For * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel * should perform lookup in keymap by @index instead of @scancode * @keycode: key code assigned to this scancode * * The structure is used to retrieve and modify keymap data. Users have * option of performing lookup either by @scancode itself or by @index * in keymap entry. EVIOCGKEYCODE will also return scancode or index * (depending on which element was used to perform lookup). */ struct input_keymap_entry { #define INPUT_KEYMAP_BY_INDEX (1 << 0) __u8 flags; __u8 len; __u16 index; __u32 keycode; __u8 scancode[32]; }; struct input_mask { __u32 type; __u32 codes_size; __u64 codes_ptr; }; #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ #define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */ #define EVIOCGKEYCODE_V2 _IOR('E', 0x04, struct input_keymap_entry) #define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ #define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry) #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ #define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */ #define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len) /* get device properties */ /** * EVIOCGMTSLOTS(len) - get MT slot values * @len: size of the data buffer in bytes * * The ioctl buffer argument should be binary equivalent to * * struct input_mt_request_layout { * __u32 code; * __s32 values[num_slots]; * }; * * where num_slots is the (arbitrary) number of MT slots to extract. * * The ioctl size argument (len) is the size of the buffer, which * should satisfy len = (num_slots + 1) * sizeof(__s32). If len is * too small to fit all available slots, the first num_slots are * returned. * * Before the call, code is set to the wanted ABS_MT event type. On * return, values[] is filled with the slot values for the specified * ABS_MT code. * * If the request code is not an ABS_MT value, -EINVAL is returned. */ #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) #define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */ #define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */ #define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */ #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + (ev), len) /* get event bits */ #define EVIOCGABS(abs) _IOR('E', 0x40 + (abs), struct input_absinfo) /* get abs value/limits */ #define EVIOCSABS(abs) _IOW('E', 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */ #define EVIOCSFF _IOW('E', 0x80, struct ff_effect) /* send a force effect to a force feedback device */ #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ #define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */ #define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */ #define EVIOCREVOKE _IOW('E', 0x91, int) /* Revoke device access */ /** * EVIOCGMASK - Retrieve current event mask * * This ioctl allows user to retrieve the current event mask for specific * event type. The argument must be of type "struct input_mask" and * specifies the event type to query, the address of the receive buffer and * the size of the receive buffer. * * The event mask is a per-client mask that specifies which events are * forwarded to the client. Each event code is represented by a single bit * in the event mask. If the bit is set, the event is passed to the client * normally. Otherwise, the event is filtered and will never be queued on * the client's receive buffer. * * Event masks do not affect global state of the input device. They only * affect the file descriptor they are applied to. * * The default event mask for a client has all bits set, i.e. all events * are forwarded to the client. If the kernel is queried for an unknown * event type or if the receive buffer is larger than the number of * event codes known to the kernel, the kernel returns all zeroes for those * codes. * * At maximum, codes_size bytes are copied. * * This ioctl may fail with ENODEV in case the file is revoked, EFAULT * if the receive-buffer points to invalid memory, or EINVAL if the kernel * does not implement the ioctl. */ #define EVIOCGMASK _IOR('E', 0x92, struct input_mask) /* Get event-masks */ /** * EVIOCSMASK - Set event mask * * This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the * current event mask, this changes the client's event mask for a specific * type. See EVIOCGMASK for a description of event-masks and the * argument-type. * * This ioctl provides full forward compatibility. If the passed event type * is unknown to the kernel, or if the number of event codes specified in * the mask is bigger than what is known to the kernel, the ioctl is still * accepted and applied. However, any unknown codes are left untouched and * stay cleared. That means, the kernel always filters unknown codes * regardless of what the client requests. If the new mask doesn't cover * all known event-codes, all remaining codes are automatically cleared and * thus filtered. * * This ioctl may fail with ENODEV in case the file is revoked. EFAULT is * returned if the receive-buffer points to invalid memory. EINVAL is returned * if the kernel does not implement the ioctl. */ #define EVIOCSMASK _IOW('E', 0x93, struct input_mask) /* Set event-masks */ #define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */ /* * IDs. */ #define ID_BUS 0 #define ID_VENDOR 1 #define ID_PRODUCT 2 #define ID_VERSION 3 #define BUS_PCI 0x01 #define BUS_ISAPNP 0x02 #define BUS_USB 0x03 #define BUS_HIL 0x04 #define BUS_BLUETOOTH 0x05 #define BUS_VIRTUAL 0x06 #define BUS_ISA 0x10 #define BUS_I8042 0x11 #define BUS_XTKBD 0x12 #define BUS_RS232 0x13 #define BUS_GAMEPORT 0x14 #define BUS_PARPORT 0x15 #define BUS_AMIGA 0x16 #define BUS_ADB 0x17 #define BUS_I2C 0x18 #define BUS_HOST 0x19 #define BUS_GSC 0x1A #define BUS_ATARI 0x1B #define BUS_SPI 0x1C #define BUS_RMI 0x1D #define BUS_CEC 0x1E #define BUS_INTEL_ISHTP 0x1F /* * MT_TOOL types */ #define MT_TOOL_FINGER 0x00 #define MT_TOOL_PEN 0x01 #define MT_TOOL_PALM 0x02 #define MT_TOOL_DIAL 0x0a #define MT_TOOL_MAX 0x0f /* * Values describing the status of a force-feedback effect */ #define FF_STATUS_STOPPED 0x00 #define FF_STATUS_PLAYING 0x01 #define FF_STATUS_MAX 0x01 /* * Structures used in ioctls to upload effects to a device * They are pieces of a bigger structure (called ff_effect) */ /* * All duration values are expressed in ms. Values above 32767 ms (0x7fff) * should not be used and have unspecified results. */ /** * struct ff_replay - defines scheduling of the force-feedback effect * @length: duration of the effect * @delay: delay before effect should start playing */ struct ff_replay { __u16 length; __u16 delay; }; /** * struct ff_trigger - defines what triggers the force-feedback effect * @button: number of the button triggering the effect * @interval: controls how soon the effect can be re-triggered */ struct ff_trigger { __u16 button; __u16 interval; }; /** * struct ff_envelope - generic force-feedback effect envelope * @attack_length: duration of the attack (ms) * @attack_level: level at the beginning of the attack * @fade_length: duration of fade (ms) * @fade_level: level at the end of fade * * The @attack_level and @fade_level are absolute values; when applying * envelope force-feedback core will convert to positive/negative * value based on polarity of the default level of the effect. * Valid range for the attack and fade levels is 0x0000 - 0x7fff */ struct ff_envelope { __u16 attack_length; __u16 attack_level; __u16 fade_length; __u16 fade_level; }; /** * struct ff_constant_effect - defines parameters of a constant force-feedback effect * @level: strength of the effect; may be negative * @envelope: envelope data */ struct ff_constant_effect { __s16 level; struct ff_envelope envelope; }; /** * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect * @start_level: beginning strength of the effect; may be negative * @end_level: final strength of the effect; may be negative * @envelope: envelope data */ struct ff_ramp_effect { __s16 start_level; __s16 end_level; struct ff_envelope envelope; }; /** * struct ff_condition_effect - defines a spring or friction force-feedback effect * @right_saturation: maximum level when joystick moved all way to the right * @left_saturation: same for the left side * @right_coeff: controls how fast the force grows when the joystick moves * to the right * @left_coeff: same for the left side * @deadband: size of the dead zone, where no force is produced * @center: position of the dead zone */ struct ff_condition_effect { __u16 right_saturation; __u16 left_saturation; __s16 right_coeff; __s16 left_coeff; __u16 deadband; __s16 center; }; /** * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect * @waveform: kind of the effect (wave) * @period: period of the wave (ms) * @magnitude: peak value * @offset: mean value of the wave (roughly) * @phase: 'horizontal' shift * @envelope: envelope data * @custom_len: number of samples (FF_CUSTOM only) * @custom_data: buffer of samples (FF_CUSTOM only) * * Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP, * FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined * for the time being as no driver supports it yet. * * Note: the data pointed by custom_data is copied by the driver. * You can therefore dispose of the memory after the upload/update. */ struct ff_periodic_effect { __u16 waveform; __u16 period; __s16 magnitude; __s16 offset; __u16 phase; struct ff_envelope envelope; __u32 custom_len; __s16 *custom_data; }; /** * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect * @strong_magnitude: magnitude of the heavy motor * @weak_magnitude: magnitude of the light one * * Some rumble pads have two motors of different weight. Strong_magnitude * represents the magnitude of the vibration generated by the heavy one. */ struct ff_rumble_effect { __u16 strong_magnitude; __u16 weak_magnitude; }; /** * struct ff_effect - defines force feedback effect * @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING, * FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM) * @id: an unique id assigned to an effect * @direction: direction of the effect * @trigger: trigger conditions (struct ff_trigger) * @replay: scheduling of the effect (struct ff_replay) * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further * defining effect parameters * * This structure is sent through ioctl from the application to the driver. * To create a new effect application should set its @id to -1; the kernel * will return assigned @id which can later be used to update or delete * this effect. * * Direction of the effect is encoded as follows: * 0 deg -> 0x0000 (down) * 90 deg -> 0x4000 (left) * 180 deg -> 0x8000 (up) * 270 deg -> 0xC000 (right) */ struct ff_effect { __u16 type; __s16 id; __u16 direction; struct ff_trigger trigger; struct ff_replay replay; union { struct ff_constant_effect constant; struct ff_ramp_effect ramp; struct ff_periodic_effect periodic; struct ff_condition_effect condition[2]; /* One for each axis */ struct ff_rumble_effect rumble; } u; }; /* * Force feedback effect types */ #define FF_RUMBLE 0x50 #define FF_PERIODIC 0x51 #define FF_CONSTANT 0x52 #define FF_SPRING 0x53 #define FF_FRICTION 0x54 #define FF_DAMPER 0x55 #define FF_INERTIA 0x56 #define FF_RAMP 0x57 #define FF_EFFECT_MIN FF_RUMBLE #define FF_EFFECT_MAX FF_RAMP /* * Force feedback periodic effect types */ #define FF_SQUARE 0x58 #define FF_TRIANGLE 0x59 #define FF_SINE 0x5a #define FF_SAW_UP 0x5b #define FF_SAW_DOWN 0x5c #define FF_CUSTOM 0x5d #define FF_WAVEFORM_MIN FF_SQUARE #define FF_WAVEFORM_MAX FF_CUSTOM /* * Set ff device properties */ #define FF_GAIN 0x60 #define FF_AUTOCENTER 0x61 /* * ff->playback(effect_id = FF_GAIN) is the first effect_id to * cause a collision with another ff method, in this case ff->set_gain(). * Therefore the greatest safe value for effect_id is FF_GAIN - 1, * and thus the total number of effects should never exceed FF_GAIN. */ #define FF_MAX_EFFECTS FF_GAIN #define FF_MAX 0x7f #define FF_CNT (FF_MAX+1) #endif /* _INPUT_H */ libinput-1.28.1/include/valgrind/000077500000000000000000000000001477265155700167055ustar00rootroot00000000000000libinput-1.28.1/include/valgrind/valgrind.h000066400000000000000000014721271477265155700207020ustar00rootroot00000000000000/* -*- c -*- ---------------------------------------------------------------- Notice that the following BSD-style license applies to this one file (valgrind.h) only. The rest of Valgrind is licensed under the terms of the GNU General Public License, version 2, unless otherwise indicated. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- This file is part of Valgrind, a dynamic binary instrumentation framework. Copyright (C) 2000-2017 Julian Seward. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------- Notice that the above BSD-style license applies to this one file (valgrind.h) only. The entire rest of Valgrind is licensed under the terms of the GNU General Public License, version 2. See the COPYING file in the source distribution for details. ---------------------------------------------------------------- */ /* This file is for inclusion into client (your!) code. You can use these macros to manipulate and query Valgrind's execution inside your own programs. The resulting executables will still run without Valgrind, just a little bit more slowly than they otherwise would, but otherwise unchanged. When not running on valgrind, each client request consumes very few (eg. 7) instructions, so the resulting performance loss is negligible unless you plan to execute client requests millions of times per second. Nevertheless, if that is still a problem, you can compile with the NVALGRIND symbol defined (gcc -DNVALGRIND) so that client requests are not even compiled in. */ #ifndef __VALGRIND_H #define __VALGRIND_H /* ------------------------------------------------------------------ */ /* VERSION NUMBER OF VALGRIND */ /* ------------------------------------------------------------------ */ /* Specify Valgrind's version number, so that user code can conditionally compile based on our version number. Note that these were introduced at version 3.6 and so do not exist in version 3.5 or earlier. The recommended way to use them to check for "version X.Y or later" is (eg) #if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \ && (__VALGRIND_MAJOR__ > 3 \ || (__VALGRIND_MAJOR__ == 3 && __VALGRIND_MINOR__ >= 6)) */ #define __VALGRIND_MAJOR__ 3 #define __VALGRIND_MINOR__ 18 #include /* Nb: this file might be included in a file compiled with -ansi. So we can't use C++ style "//" comments nor the "asm" keyword (instead use "__asm__"). */ /* Derive some tags indicating what the target platform is. Note that in this file we're using the compiler's CPP symbols for identifying architectures, which are different to the ones we use within the rest of Valgrind. Note, __powerpc__ is active for both 32 and 64-bit PPC, whereas __powerpc64__ is only active for the latter (on Linux, that is). Misc note: how to find out what's predefined in gcc by default: gcc -Wp,-dM somefile.c */ #undef PLAT_x86_darwin #undef PLAT_amd64_darwin #undef PLAT_x86_freebsd #undef PLAT_amd64_freebsd #undef PLAT_x86_win32 #undef PLAT_amd64_win64 #undef PLAT_x86_linux #undef PLAT_amd64_linux #undef PLAT_ppc32_linux #undef PLAT_ppc64be_linux #undef PLAT_ppc64le_linux #undef PLAT_arm_linux #undef PLAT_arm64_linux #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux #undef PLAT_nanomips_linux #undef PLAT_x86_solaris #undef PLAT_amd64_solaris #if defined(__APPLE__) && defined(__i386__) # define PLAT_x86_darwin 1 #elif defined(__APPLE__) && defined(__x86_64__) # define PLAT_amd64_darwin 1 #elif defined(__FreeBSD__) && defined(__i386__) # define PLAT_x86_freebsd 1 #elif defined(__FreeBSD__) && defined(__amd64__) # define PLAT_amd64_freebsd 1 #elif (defined(__MINGW32__) && defined(__i386__)) \ || defined(__CYGWIN32__) \ || (defined(_WIN32) && defined(_M_IX86)) # define PLAT_x86_win32 1 #elif (defined(__MINGW32__) && defined(__x86_64__)) \ || (defined(_WIN32) && defined(_M_X64)) /* __MINGW32__ and _WIN32 are defined in 64 bit mode as well. */ # define PLAT_amd64_win64 1 #elif defined(__linux__) && defined(__i386__) # define PLAT_x86_linux 1 #elif defined(__linux__) && defined(__x86_64__) && !defined(__ILP32__) # define PLAT_amd64_linux 1 #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__) # define PLAT_ppc32_linux 1 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF != 2 /* Big Endian uses ELF version 1 */ # define PLAT_ppc64be_linux 1 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF == 2 /* Little Endian uses ELF version 2 */ # define PLAT_ppc64le_linux 1 #elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__) # define PLAT_arm_linux 1 #elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__) # define PLAT_arm64_linux 1 #elif defined(__linux__) && defined(__s390__) && defined(__s390x__) # define PLAT_s390x_linux 1 #elif defined(__linux__) && defined(__mips__) && (__mips==64) # define PLAT_mips64_linux 1 #elif defined(__linux__) && defined(__mips__) && (__mips==32) # define PLAT_mips32_linux 1 #elif defined(__linux__) && defined(__nanomips__) # define PLAT_nanomips_linux 1 #elif defined(__sun) && defined(__i386__) # define PLAT_x86_solaris 1 #elif defined(__sun) && defined(__x86_64__) # define PLAT_amd64_solaris 1 #else /* If we're not compiling for our target platform, don't generate any inline asms. */ # if !defined(NVALGRIND) # define NVALGRIND 1 # endif #endif /* ------------------------------------------------------------------ */ /* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */ /* in here of use to end-users -- skip to the next section. */ /* ------------------------------------------------------------------ */ /* * VALGRIND_DO_CLIENT_REQUEST(): a statement that invokes a Valgrind client * request. Accepts both pointers and integers as arguments. * * VALGRIND_DO_CLIENT_REQUEST_STMT(): a statement that invokes a Valgrind * client request that does not return a value. * VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind * client request and whose value equals the client request result. Accepts * both pointers and integers as arguments. Note that such calls are not * necessarily pure functions -- they may have side effects. */ #define VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, \ _zzq_request, _zzq_arg1, _zzq_arg2, \ _zzq_arg3, _zzq_arg4, _zzq_arg5) \ do { (_zzq_rlval) = VALGRIND_DO_CLIENT_REQUEST_EXPR((_zzq_default), \ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0) #define VALGRIND_DO_CLIENT_REQUEST_STMT(_zzq_request, _zzq_arg1, \ _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0) #if defined(NVALGRIND) /* Define NVALGRIND to completely remove the Valgrind magic sequence from the compiled code (analogous to NDEBUG's effects on assert()) */ #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ (_zzq_default) #else /* ! NVALGRIND */ /* The following defines the magic code sequences which the JITter spots and handles magically. Don't look too closely at them as they will rot your brain. The assembly code sequences for all architectures is in this one file. This is because this file must be stand-alone, and we don't want to have multiple files. For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default value gets put in the return slot, so that everything works when this is executed not under Valgrind. Args are passed in a memory block, and so there's no intrinsic limit to the number that could be passed, but it's currently five. The macro args are: _zzq_rlval result lvalue _zzq_default default value (result returned when running on real CPU) _zzq_request request code _zzq_arg1..5 request params The other two macros are used to support function wrapping, and are a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the guest's NRADDR pseudo-register and whatever other information is needed to safely run the call original from the wrapper: on ppc64-linux, the R2 value at the divert point is also needed. This information is abstracted into a user-visible type, OrigFn. VALGRIND_CALL_NOREDIR_* behaves the same as the following on the guest, but guarantees that the branch instruction will not be redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64: branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a complete inline asm, since it needs to be combined with more magic inline asm stuff to be useful. */ /* ----------------- x86-{linux,darwin,solaris} ---------------- */ #if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \ || (defined(PLAT_x86_win32) && defined(__GNUC__)) \ || defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "roll $3, %%edi ; roll $13, %%edi\n\t" \ "roll $29, %%edi ; roll $19, %%edi\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %EDX = client_request ( %EAX ) */ \ "xchgl %%ebx,%%ebx" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), "0" (_zzq_default) \ : "cc", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %EAX = guest_NRADDR */ \ "xchgl %%ecx,%%ecx" \ : "=a" (__addr) \ : \ : "cc", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_EAX \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%EAX */ \ "xchgl %%edx,%%edx\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "xchgl %%edi,%%edi\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_x86_linux || PLAT_x86_darwin || (PLAT_x86_win32 && __GNUC__) || PLAT_x86_solaris */ /* ------------------------- x86-Win32 ------------------------- */ #if defined(PLAT_x86_win32) && !defined(__GNUC__) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #if defined(_MSC_VER) #define __SPECIAL_INSTRUCTION_PREAMBLE \ __asm rol edi, 3 __asm rol edi, 13 \ __asm rol edi, 29 __asm rol edi, 19 #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \ (uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \ (uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \ (uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5)) static __inline uintptr_t valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request, uintptr_t _zzq_arg1, uintptr_t _zzq_arg2, uintptr_t _zzq_arg3, uintptr_t _zzq_arg4, uintptr_t _zzq_arg5) { volatile uintptr_t _zzq_args[6]; volatile unsigned int _zzq_result; _zzq_args[0] = (uintptr_t)(_zzq_request); _zzq_args[1] = (uintptr_t)(_zzq_arg1); _zzq_args[2] = (uintptr_t)(_zzq_arg2); _zzq_args[3] = (uintptr_t)(_zzq_arg3); _zzq_args[4] = (uintptr_t)(_zzq_arg4); _zzq_args[5] = (uintptr_t)(_zzq_arg5); __asm { __asm lea eax, _zzq_args __asm mov edx, _zzq_default __SPECIAL_INSTRUCTION_PREAMBLE /* %EDX = client_request ( %EAX ) */ __asm xchg ebx,ebx __asm mov _zzq_result, edx } return _zzq_result; } #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \ /* %EAX = guest_NRADDR */ \ __asm xchg ecx,ecx \ __asm mov __addr, eax \ } \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_EAX ERROR #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \ __asm xchg edi,edi \ } \ } while (0) #else #error Unsupported compiler. #endif #endif /* PLAT_x86_win32 */ /* ----------------- amd64-{linux,darwin,solaris} --------------- */ #if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \ || defined(PLAT_amd64_solaris) \ || defined(PLAT_amd64_freebsd) \ || (defined(PLAT_amd64_win64) && defined(__GNUC__)) typedef struct { unsigned long int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \ "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned long int _zzq_args[6]; \ volatile unsigned long int _zzq_result; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RDX = client_request ( %RAX ) */ \ "xchgq %%rbx,%%rbx" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), "0" (_zzq_default) \ : "cc", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %RAX = guest_NRADDR */ \ "xchgq %%rcx,%%rcx" \ : "=a" (__addr) \ : \ : "cc", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_RAX \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%RAX */ \ "xchgq %%rdx,%%rdx\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "xchgq %%rdi,%%rdi\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */ /* ------------------------- amd64-Win64 ------------------------- */ #if defined(PLAT_amd64_win64) && !defined(__GNUC__) #error Unsupported compiler. #endif /* PLAT_amd64_win64 */ /* ------------------------ ppc32-linux ------------------------ */ #if defined(PLAT_ppc32_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \ "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({ unsigned int _zzq_args[6]; \ unsigned int _zzq_result; \ unsigned int* _zzq_ptr; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ _zzq_ptr = _zzq_args; \ __asm__ volatile("mr 3,%1\n\t" /*default*/ \ "mr 4,%2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = client_request ( %R4 ) */ \ "or 1,1,1\n\t" \ "mr %0,3" /*result*/ \ : "=b" (_zzq_result) \ : "b" (_zzq_default), "b" (_zzq_ptr) \ : "cc", "memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR */ \ "or 2,2,2\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R11 */ \ "or 3,3,3\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or 5,5,5\n\t" \ ); \ } while (0) #endif /* PLAT_ppc32_linux */ /* ------------------------ ppc64-linux ------------------------ */ #if defined(PLAT_ppc64be_linux) typedef struct { unsigned long int nraddr; /* where's the code? */ unsigned long int r2; /* what tocptr do we need? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \ "rotldi 0,0,61 ; rotldi 0,0,51\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({ unsigned long int _zzq_args[6]; \ unsigned long int _zzq_result; \ unsigned long int* _zzq_ptr; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ _zzq_ptr = _zzq_args; \ __asm__ volatile("mr 3,%1\n\t" /*default*/ \ "mr 4,%2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = client_request ( %R4 ) */ \ "or 1,1,1\n\t" \ "mr %0,3" /*result*/ \ : "=b" (_zzq_result) \ : "b" (_zzq_default), "b" (_zzq_ptr) \ : "cc", "memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR */ \ "or 2,2,2\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR_GPR2 */ \ "or 4,4,4\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->r2 = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R11 */ \ "or 3,3,3\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or 5,5,5\n\t" \ ); \ } while (0) #endif /* PLAT_ppc64be_linux */ #if defined(PLAT_ppc64le_linux) typedef struct { unsigned long int nraddr; /* where's the code? */ unsigned long int r2; /* what tocptr do we need? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \ "rotldi 0,0,61 ; rotldi 0,0,51\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({ unsigned long int _zzq_args[6]; \ unsigned long int _zzq_result; \ unsigned long int* _zzq_ptr; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ _zzq_ptr = _zzq_args; \ __asm__ volatile("mr 3,%1\n\t" /*default*/ \ "mr 4,%2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = client_request ( %R4 ) */ \ "or 1,1,1\n\t" \ "mr %0,3" /*result*/ \ : "=b" (_zzq_result) \ : "b" (_zzq_default), "b" (_zzq_ptr) \ : "cc", "memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR */ \ "or 2,2,2\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %R3 = guest_NRADDR_GPR2 */ \ "or 4,4,4\n\t" \ "mr %0,3" \ : "=b" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->r2 = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R12 */ \ "or 3,3,3\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or 5,5,5\n\t" \ ); \ } while (0) #endif /* PLAT_ppc64le_linux */ /* ------------------------- arm-linux ------------------------- */ #if defined(PLAT_arm_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \ "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile("mov r3, %1\n\t" /*default*/ \ "mov r4, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* R3 = client_request ( R4 ) */ \ "orr r10, r10, r10\n\t" \ "mov %0, r3" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "cc","memory", "r3", "r4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* R3 = guest_NRADDR */ \ "orr r11, r11, r11\n\t" \ "mov %0, r3" \ : "=r" (__addr) \ : \ : "cc", "memory", "r3" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir *%R4 */ \ "orr r12, r12, r12\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "orr r9, r9, r9\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_arm_linux */ /* ------------------------ arm64-linux ------------------------- */ #if defined(PLAT_arm64_linux) typedef struct { unsigned long int nraddr; /* where's the code? */ } OrigFn; #define __SPECIAL_INSTRUCTION_PREAMBLE \ "ror x12, x12, #3 ; ror x12, x12, #13 \n\t" \ "ror x12, x12, #51 ; ror x12, x12, #61 \n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ \ __extension__ \ ({volatile unsigned long int _zzq_args[6]; \ volatile unsigned long int _zzq_result; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ __asm__ volatile("mov x3, %1\n\t" /*default*/ \ "mov x4, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* X3 = client_request ( X4 ) */ \ "orr x10, x10, x10\n\t" \ "mov %0, x3" /*result*/ \ : "=r" (_zzq_result) \ : "r" ((unsigned long int)(_zzq_default)), \ "r" (&_zzq_args[0]) \ : "cc","memory", "x3", "x4"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* X3 = guest_NRADDR */ \ "orr x11, x11, x11\n\t" \ "mov %0, x3" \ : "=r" (__addr) \ : \ : "cc", "memory", "x3" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* branch-and-link-to-noredir X8 */ \ "orr x12, x12, x12\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "orr x9, x9, x9\n\t" \ : : : "cc", "memory" \ ); \ } while (0) #endif /* PLAT_arm64_linux */ /* ------------------------ s390x-linux ------------------------ */ #if defined(PLAT_s390x_linux) typedef struct { unsigned long int nraddr; /* where's the code? */ } OrigFn; /* __SPECIAL_INSTRUCTION_PREAMBLE will be used to identify Valgrind specific * code. This detection is implemented in platform specific toIR.c * (e.g. VEX/priv/guest_s390_decoder.c). */ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "lr 15,15\n\t" \ "lr 1,1\n\t" \ "lr 2,2\n\t" \ "lr 3,3\n\t" #define __CLIENT_REQUEST_CODE "lr 2,2\n\t" #define __GET_NR_CONTEXT_CODE "lr 3,3\n\t" #define __CALL_NO_REDIR_CODE "lr 4,4\n\t" #define __VEX_INJECT_IR_CODE "lr 5,5\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({volatile unsigned long int _zzq_args[6]; \ volatile unsigned long int _zzq_result; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ __asm__ volatile(/* r2 = args */ \ "lgr 2,%1\n\t" \ /* r3 = default */ \ "lgr 3,%2\n\t" \ __SPECIAL_INSTRUCTION_PREAMBLE \ __CLIENT_REQUEST_CODE \ /* results = r3 */ \ "lgr %0, 3\n\t" \ : "=d" (_zzq_result) \ : "a" (&_zzq_args[0]), \ "0" ((unsigned long int)_zzq_default) \ : "cc", "2", "3", "memory" \ ); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ __GET_NR_CONTEXT_CODE \ "lgr %0, 3\n\t" \ : "=a" (__addr) \ : \ : "cc", "3", "memory" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_R1 \ __SPECIAL_INSTRUCTION_PREAMBLE \ __CALL_NO_REDIR_CODE #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ __VEX_INJECT_IR_CODE); \ } while (0) #endif /* PLAT_s390x_linux */ /* ------------------------- mips32-linux ---------------- */ #if defined(PLAT_mips32_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; /* .word 0x342 * .word 0x742 * .word 0xC2 * .word 0x4C2*/ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "srl $0, $0, 13\n\t" \ "srl $0, $0, 29\n\t" \ "srl $0, $0, 3\n\t" \ "srl $0, $0, 19\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile("move $11, %1\n\t" /*default*/ \ "move $12, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* T3 = client_request ( T4 ) */ \ "or $13, $13, $13\n\t" \ "move %0, $11\n\t" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "$11", "$12", "memory"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* %t9 = guest_NRADDR */ \ "or $14, $14, $14\n\t" \ "move %0, $11" /*result*/ \ : "=r" (__addr) \ : \ : "$11" \ ); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_T9 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir *%t9 */ \ "or $15, $15, $15\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or $11, $11, $11\n\t" \ ); \ } while (0) #endif /* PLAT_mips32_linux */ /* ------------------------- mips64-linux ---------------- */ #if defined(PLAT_mips64_linux) typedef struct { unsigned long nraddr; /* where's the code? */ } OrigFn; /* dsll $0,$0, 3 * dsll $0,$0, 13 * dsll $0,$0, 29 * dsll $0,$0, 19*/ #define __SPECIAL_INSTRUCTION_PREAMBLE \ "dsll $0,$0, 3 ; dsll $0,$0,13\n\t" \ "dsll $0,$0,29 ; dsll $0,$0,19\n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned long int _zzq_args[6]; \ volatile unsigned long int _zzq_result; \ _zzq_args[0] = (unsigned long int)(_zzq_request); \ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \ __asm__ volatile("move $11, %1\n\t" /*default*/ \ "move $12, %2\n\t" /*ptr*/ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* $11 = client_request ( $12 ) */ \ "or $13, $13, $13\n\t" \ "move %0, $11\n\t" /*result*/ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "$11", "$12", "memory"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* $11 = guest_NRADDR */ \ "or $14, $14, $14\n\t" \ "move %0, $11" /*result*/ \ : "=r" (__addr) \ : \ : "$11"); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_T9 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir $25 */ \ "or $15, $15, $15\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or $11, $11, $11\n\t" \ ); \ } while (0) #endif /* PLAT_mips64_linux */ #if defined(PLAT_nanomips_linux) typedef struct { unsigned int nraddr; /* where's the code? */ } OrigFn; /* 8000 c04d srl zero, zero, 13 8000 c05d srl zero, zero, 29 8000 c043 srl zero, zero, 3 8000 c053 srl zero, zero, 19 */ #define __SPECIAL_INSTRUCTION_PREAMBLE "srl[32] $zero, $zero, 13 \n\t" \ "srl[32] $zero, $zero, 29 \n\t" \ "srl[32] $zero, $zero, 3 \n\t" \ "srl[32] $zero, $zero, 19 \n\t" #define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ _zzq_default, _zzq_request, \ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ __extension__ \ ({ volatile unsigned int _zzq_args[6]; \ volatile unsigned int _zzq_result; \ _zzq_args[0] = (unsigned int)(_zzq_request); \ _zzq_args[1] = (unsigned int)(_zzq_arg1); \ _zzq_args[2] = (unsigned int)(_zzq_arg2); \ _zzq_args[3] = (unsigned int)(_zzq_arg3); \ _zzq_args[4] = (unsigned int)(_zzq_arg4); \ _zzq_args[5] = (unsigned int)(_zzq_arg5); \ __asm__ volatile("move $a7, %1\n\t" /* default */ \ "move $t0, %2\n\t" /* ptr */ \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* $a7 = client_request( $t0 ) */ \ "or[32] $t0, $t0, $t0\n\t" \ "move %0, $a7\n\t" /* result */ \ : "=r" (_zzq_result) \ : "r" (_zzq_default), "r" (&_zzq_args[0]) \ : "$a7", "$t0", "memory"); \ _zzq_result; \ }) #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ volatile unsigned long int __addr; \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ /* $a7 = guest_NRADDR */ \ "or[32] $t1, $t1, $t1\n\t" \ "move %0, $a7" /*result*/ \ : "=r" (__addr) \ : \ : "$a7"); \ _zzq_orig->nraddr = __addr; \ } #define VALGRIND_CALL_NOREDIR_T9 \ __SPECIAL_INSTRUCTION_PREAMBLE \ /* call-noredir $25 */ \ "or[32] $t2, $t2, $t2\n\t" #define VALGRIND_VEX_INJECT_IR() \ do { \ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ "or[32] $t3, $t3, $t3\n\t" \ ); \ } while (0) #endif /* Insert assembly code for other platforms here... */ #endif /* NVALGRIND */ /* ------------------------------------------------------------------ */ /* PLATFORM SPECIFICS for FUNCTION WRAPPING. This is all very */ /* ugly. It's the least-worst tradeoff I can think of. */ /* ------------------------------------------------------------------ */ /* This section defines magic (a.k.a appalling-hack) macros for doing guaranteed-no-redirection macros, so as to get from function wrappers to the functions they are wrapping. The whole point is to construct standard call sequences, but to do the call itself with a special no-redirect call pseudo-instruction that the JIT understands and handles specially. This section is long and repetitious, and I can't see a way to make it shorter. The naming scheme is as follows: CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc} 'W' stands for "word" and 'v' for "void". Hence there are different macros for calling arity 0, 1, 2, 3, 4, etc, functions, and for each, the possibility of returning a word-typed result, or no result. */ /* Use these to write the name of your wrapper. NOTE: duplicates VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. NOTE also: inserts the default behaviour equivalance class tag "0000" into the name. See pub_tool_redir.h for details -- normally you don't need to think about this, though. */ /* Use an extra level of macroisation so as to ensure the soname/fnname args are fully macro-expanded before pasting them together. */ #define VG_CONCAT4(_aa,_bb,_cc,_dd) _aa##_bb##_cc##_dd #define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \ VG_CONCAT4(_vgw00000ZU_,soname,_,fnname) #define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \ VG_CONCAT4(_vgw00000ZZ_,soname,_,fnname) /* Use this macro from within a wrapper function to collect the context (address and possibly other info) of the original function. Once you have that you can then use it in one of the CALL_FN_ macros. The type of the argument _lval is OrigFn. */ #define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval) /* Also provide end-user facilities for function replacement, rather than wrapping. A replacement function differs from a wrapper in that it has no way to get hold of the original function being called, and hence no way to call onwards to it. In a replacement function, VALGRIND_GET_ORIG_FN always returns zero. */ #define I_REPLACE_SONAME_FNNAME_ZU(soname,fnname) \ VG_CONCAT4(_vgr00000ZU_,soname,_,fnname) #define I_REPLACE_SONAME_FNNAME_ZZ(soname,fnname) \ VG_CONCAT4(_vgr00000ZZ_,soname,_,fnname) /* Derivatives of the main macros below, for calling functions returning void. */ #define CALL_FN_v_v(fnptr) \ do { volatile unsigned long _junk; \ CALL_FN_W_v(_junk,fnptr); } while (0) #define CALL_FN_v_W(fnptr, arg1) \ do { volatile unsigned long _junk; \ CALL_FN_W_W(_junk,fnptr,arg1); } while (0) #define CALL_FN_v_WW(fnptr, arg1,arg2) \ do { volatile unsigned long _junk; \ CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0) #define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \ do { volatile unsigned long _junk; \ CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0) #define CALL_FN_v_WWWW(fnptr, arg1,arg2,arg3,arg4) \ do { volatile unsigned long _junk; \ CALL_FN_W_WWWW(_junk,fnptr,arg1,arg2,arg3,arg4); } while (0) #define CALL_FN_v_5W(fnptr, arg1,arg2,arg3,arg4,arg5) \ do { volatile unsigned long _junk; \ CALL_FN_W_5W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5); } while (0) #define CALL_FN_v_6W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6) \ do { volatile unsigned long _junk; \ CALL_FN_W_6W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6); } while (0) #define CALL_FN_v_7W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6,arg7) \ do { volatile unsigned long _junk; \ CALL_FN_W_7W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6,arg7); } while (0) /* ----------------- x86-{linux,darwin,solaris} ---------------- */ #if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \ || defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd) /* These regs are trashed by the hidden call. No need to mention eax as gcc can already see that, plus causes gcc to bomb. */ #define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "movl %%esp,%%edi\n\t" \ "andl $0xfffffff0,%%esp\n\t" #define VALGRIND_RESTORE_STACK \ "movl %%edi,%%esp\n\t" /* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $12, %%esp\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $8, %%esp\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "subl $4, %%esp\n\t" \ "pushl 44(%%eax)\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "pushl 48(%%eax)\n\t" \ "pushl 44(%%eax)\n\t" \ "pushl 40(%%eax)\n\t" \ "pushl 36(%%eax)\n\t" \ "pushl 32(%%eax)\n\t" \ "pushl 28(%%eax)\n\t" \ "pushl 24(%%eax)\n\t" \ "pushl 20(%%eax)\n\t" \ "pushl 16(%%eax)\n\t" \ "pushl 12(%%eax)\n\t" \ "pushl 8(%%eax)\n\t" \ "pushl 4(%%eax)\n\t" \ "movl (%%eax), %%eax\n\t" /* target->%eax */ \ VALGRIND_CALL_NOREDIR_EAX \ VALGRIND_RESTORE_STACK \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_x86_linux || PLAT_x86_darwin || PLAT_x86_solaris */ /* ---------------- amd64-{linux,darwin,solaris} --------------- */ #if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \ || defined(PLAT_amd64_solaris) || defined(PLAT_amd64_freebsd) /* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \ "rdi", "r8", "r9", "r10", "r11" /* This is all pretty complex. It's so as to make stack unwinding work reliably. See bug 243270. The basic problem is the sub and add of 128 of %rsp in all of the following macros. If gcc believes the CFA is in %rsp, then unwinding may fail, because what's at the CFA is not what gcc "expected" when it constructs the CFIs for the places where the macros are instantiated. But we can't just add a CFI annotation to increase the CFA offset by 128, to match the sub of 128 from %rsp, because we don't know whether gcc has chosen %rsp as the CFA at that point, or whether it has chosen some other register (eg, %rbp). In the latter case, adding a CFI annotation to change the CFA offset is simply wrong. So the solution is to get hold of the CFA using __builtin_dwarf_cfa(), put it in a known register, and add a CFI annotation to say what the register is. We choose %rbp for this (perhaps perversely), because: (1) %rbp is already subject to unwinding. If a new register was chosen then the unwinder would have to unwind it in all stack traces, which is expensive, and (2) %rbp is already subject to precise exception updates in the JIT. If a new register was chosen, we'd have to have precise exceptions for it too, which reduces performance of the generated code. However .. one extra complication. We can't just whack the result of __builtin_dwarf_cfa() into %rbp and then add %rbp to the list of trashed registers at the end of the inline assembly fragments; gcc won't allow %rbp to appear in that list. Hence instead we need to stash %rbp in %r15 for the duration of the asm, and say that %r15 is trashed instead. gcc seems happy to go with that. Oh .. and this all needs to be conditionalised so that it is unchanged from before this commit, when compiled with older gccs that don't support __builtin_dwarf_cfa. Furthermore, since this header file is freestanding, it has to be independent of config.h, and so the following conditionalisation cannot depend on configure time checks. Although it's not clear from 'defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)', this expression excludes Darwin. .cfi directives in Darwin assembly appear to be completely different and I haven't investigated how they work. For even more entertainment value, note we have to use the completely undocumented __builtin_dwarf_cfa(), which appears to really compute the CFA, whereas __builtin_frame_address(0) claims to but actually doesn't. See https://bugs.kde.org/show_bug.cgi?id=243270#c47 */ #if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM) # define __FRAME_POINTER \ ,"r"(__builtin_dwarf_cfa()) # define VALGRIND_CFI_PROLOGUE \ "movq %%rbp, %%r15\n\t" \ "movq %2, %%rbp\n\t" \ ".cfi_remember_state\n\t" \ ".cfi_def_cfa rbp, 0\n\t" # define VALGRIND_CFI_EPILOGUE \ "movq %%r15, %%rbp\n\t" \ ".cfi_restore_state\n\t" #else # define __FRAME_POINTER # define VALGRIND_CFI_PROLOGUE # define VALGRIND_CFI_EPILOGUE #endif /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "movq %%rsp,%%r14\n\t" \ "andq $0xfffffffffffffff0,%%rsp\n\t" #define VALGRIND_RESTORE_STACK \ "movq %%r14,%%rsp\n\t" /* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned long) == 8. */ /* NB 9 Sept 07. There is a nasty kludge here in all these CALL_FN_ macros. In order not to trash the stack redzone, we need to drop %rsp by 128 before the hidden call, and restore afterwards. The nastyness is that it is only by luck that the stack still appears to be unwindable during the hidden call - since then the behaviour of any routine using this macro does not match what the CFI data says. Sigh. Why is this important? Imagine that a wrapper has a stack allocated local, and passes to the hidden call, a pointer to it. Because gcc does not know about the hidden call, it may allocate that local in the redzone. Unfortunately the hidden call may then trash it before it comes to use it. So we must step clear of the redzone, for the duration of the hidden call, to make it safe. Probably the same problem afflicts the other redzone-style ABIs too (ppc64-linux); but for those, the stack is self describing (none of this CFI nonsense) so at least messing with the stack pointer doesn't give a danger of non-unwindable stack. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $136,%%rsp\n\t" \ "pushq 88(%%rax)\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ VALGRIND_ALIGN_STACK \ "subq $128,%%rsp\n\t" \ "pushq 96(%%rax)\n\t" \ "pushq 88(%%rax)\n\t" \ "pushq 80(%%rax)\n\t" \ "pushq 72(%%rax)\n\t" \ "pushq 64(%%rax)\n\t" \ "pushq 56(%%rax)\n\t" \ "movq 48(%%rax), %%r9\n\t" \ "movq 40(%%rax), %%r8\n\t" \ "movq 32(%%rax), %%rcx\n\t" \ "movq 24(%%rax), %%rdx\n\t" \ "movq 16(%%rax), %%rsi\n\t" \ "movq 8(%%rax), %%rdi\n\t" \ "movq (%%rax), %%rax\n\t" /* target->%rax */ \ VALGRIND_CALL_NOREDIR_RAX \ VALGRIND_RESTORE_STACK \ VALGRIND_CFI_EPILOGUE \ : /*out*/ "=a" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */ /* ------------------------ ppc32-linux ------------------------ */ #if defined(PLAT_ppc32_linux) /* This is useful for finding out about the on-stack stuff: extern int f9 ( int,int,int,int,int,int,int,int,int ); extern int f10 ( int,int,int,int,int,int,int,int,int,int ); extern int f11 ( int,int,int,int,int,int,int,int,int,int,int ); extern int f12 ( int,int,int,int,int,int,int,int,int,int,int,int ); int g9 ( void ) { return f9(11,22,33,44,55,66,77,88,99); } int g10 ( void ) { return f10(11,22,33,44,55,66,77,88,99,110); } int g11 ( void ) { return f11(11,22,33,44,55,66,77,88,99,110,121); } int g12 ( void ) { return f12(11,22,33,44,55,66,77,88,99,110,121,132); } */ /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "lr", "ctr", "xer", \ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \ "r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \ "r11", "r12", "r13" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "mr 28,1\n\t" \ "rlwinm 1,1,0,0,27\n\t" #define VALGRIND_RESTORE_STACK \ "mr 1,28\n\t" /* These CALL_FN_ macros assume that on ppc32-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-16\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-16\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-32\n\t" \ /* arg11 */ \ "lwz 3,44(11)\n\t" \ "stw 3,16(1)\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ _argvec[12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "addi 1,1,-32\n\t" \ /* arg12 */ \ "lwz 3,48(11)\n\t" \ "stw 3,20(1)\n\t" \ /* arg11 */ \ "lwz 3,44(11)\n\t" \ "stw 3,16(1)\n\t" \ /* arg10 */ \ "lwz 3,40(11)\n\t" \ "stw 3,12(1)\n\t" \ /* arg9 */ \ "lwz 3,36(11)\n\t" \ "stw 3,8(1)\n\t" \ /* args1-8 */ \ "lwz 3,4(11)\n\t" /* arg1->r3 */ \ "lwz 4,8(11)\n\t" \ "lwz 5,12(11)\n\t" \ "lwz 6,16(11)\n\t" /* arg4->r6 */ \ "lwz 7,20(11)\n\t" \ "lwz 8,24(11)\n\t" \ "lwz 9,28(11)\n\t" \ "lwz 10,32(11)\n\t" /* arg8->r10 */ \ "lwz 11,0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ VALGRIND_RESTORE_STACK \ "mr %0,3" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_ppc32_linux */ /* ------------------------ ppc64-linux ------------------------ */ #if defined(PLAT_ppc64be_linux) /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "lr", "ctr", "xer", \ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \ "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \ "r11", "r12", "r13" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "mr 28,1\n\t" \ "rldicr 1,1,0,59\n\t" #define VALGRIND_RESTORE_STACK \ "mr 1,28\n\t" /* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned long) == 8. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+0]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+1]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+2]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+3]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+4]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+5]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+6]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+7]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+8]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+9]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+10]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+11]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg11 */ \ "ld 3,88(11)\n\t" \ "std 3,128(1)\n\t" \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+12]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ _argvec[2+12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 11,%1\n\t" \ "std 2,-16(11)\n\t" /* save tocptr */ \ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg12 */ \ "ld 3,96(11)\n\t" \ "std 3,136(1)\n\t" \ /* arg11 */ \ "ld 3,88(11)\n\t" \ "std 3,128(1)\n\t" \ /* arg10 */ \ "ld 3,80(11)\n\t" \ "std 3,120(1)\n\t" \ /* arg9 */ \ "ld 3,72(11)\n\t" \ "std 3,112(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(11)\n\t" /* arg1->r3 */ \ "ld 4, 16(11)\n\t" /* arg2->r4 */ \ "ld 5, 24(11)\n\t" /* arg3->r5 */ \ "ld 6, 32(11)\n\t" /* arg4->r6 */ \ "ld 7, 40(11)\n\t" /* arg5->r7 */ \ "ld 8, 48(11)\n\t" /* arg6->r8 */ \ "ld 9, 56(11)\n\t" /* arg7->r9 */ \ "ld 10, 64(11)\n\t" /* arg8->r10 */ \ "ld 11, 0(11)\n\t" /* target->r11 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ "mr 11,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(11)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_ppc64be_linux */ /* ------------------------- ppc64le-linux ----------------------- */ #if defined(PLAT_ppc64le_linux) /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "lr", "ctr", "xer", \ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \ "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \ "r11", "r12", "r13" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ #define VALGRIND_ALIGN_STACK \ "mr 28,1\n\t" \ "rldicr 1,1,0,59\n\t" #define VALGRIND_RESTORE_STACK \ "mr 1,28\n\t" /* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned long) == 8. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+0]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+1]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+2]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+3]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+4]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+5]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+6]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+7]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+8]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 10, 64(12)\n\t" /* arg8->r10 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+9]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg9 */ \ "ld 3,72(12)\n\t" \ "std 3,96(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 10, 64(12)\n\t" /* arg8->r10 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+10]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-128\n\t" /* expand stack frame */ \ /* arg10 */ \ "ld 3,80(12)\n\t" \ "std 3,104(1)\n\t" \ /* arg9 */ \ "ld 3,72(12)\n\t" \ "std 3,96(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 10, 64(12)\n\t" /* arg8->r10 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+11]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg11 */ \ "ld 3,88(12)\n\t" \ "std 3,112(1)\n\t" \ /* arg10 */ \ "ld 3,80(12)\n\t" \ "std 3,104(1)\n\t" \ /* arg9 */ \ "ld 3,72(12)\n\t" \ "std 3,96(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 10, 64(12)\n\t" /* arg8->r10 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3+12]; \ volatile unsigned long _res; \ /* _argvec[0] holds current r2 across the call */ \ _argvec[1] = (unsigned long)_orig.r2; \ _argvec[2] = (unsigned long)_orig.nraddr; \ _argvec[2+1] = (unsigned long)arg1; \ _argvec[2+2] = (unsigned long)arg2; \ _argvec[2+3] = (unsigned long)arg3; \ _argvec[2+4] = (unsigned long)arg4; \ _argvec[2+5] = (unsigned long)arg5; \ _argvec[2+6] = (unsigned long)arg6; \ _argvec[2+7] = (unsigned long)arg7; \ _argvec[2+8] = (unsigned long)arg8; \ _argvec[2+9] = (unsigned long)arg9; \ _argvec[2+10] = (unsigned long)arg10; \ _argvec[2+11] = (unsigned long)arg11; \ _argvec[2+12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "mr 12,%1\n\t" \ "std 2,-16(12)\n\t" /* save tocptr */ \ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \ "addi 1,1,-144\n\t" /* expand stack frame */ \ /* arg12 */ \ "ld 3,96(12)\n\t" \ "std 3,120(1)\n\t" \ /* arg11 */ \ "ld 3,88(12)\n\t" \ "std 3,112(1)\n\t" \ /* arg10 */ \ "ld 3,80(12)\n\t" \ "std 3,104(1)\n\t" \ /* arg9 */ \ "ld 3,72(12)\n\t" \ "std 3,96(1)\n\t" \ /* args1-8 */ \ "ld 3, 8(12)\n\t" /* arg1->r3 */ \ "ld 4, 16(12)\n\t" /* arg2->r4 */ \ "ld 5, 24(12)\n\t" /* arg3->r5 */ \ "ld 6, 32(12)\n\t" /* arg4->r6 */ \ "ld 7, 40(12)\n\t" /* arg5->r7 */ \ "ld 8, 48(12)\n\t" /* arg6->r8 */ \ "ld 9, 56(12)\n\t" /* arg7->r9 */ \ "ld 10, 64(12)\n\t" /* arg8->r10 */ \ "ld 12, 0(12)\n\t" /* target->r12 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \ "mr 12,%1\n\t" \ "mr %0,3\n\t" \ "ld 2,-16(12)\n\t" /* restore tocptr */ \ VALGRIND_RESTORE_STACK \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[2]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_ppc64le_linux */ /* ------------------------- arm-linux ------------------------- */ #if defined(PLAT_arm_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "r0", "r1", "r2", "r3","r4", "r12", "r14" /* Macros to save and align the stack before making a function call and restore it afterwards as gcc may not keep the stack pointer aligned if it doesn't realise calls are being made to other functions. */ /* This is a bit tricky. We store the original stack pointer in r10 as it is callee-saves. gcc doesn't allow the use of r11 for some reason. Also, we can't directly "bic" the stack pointer in thumb mode since r13 isn't an allowed register number in that context. So use r4 as a temporary, since that is about to get trashed anyway, just after each use of this macro. Side effect is we need to be very careful about any future changes, since VALGRIND_ALIGN_STACK simply assumes r4 is usable. */ #define VALGRIND_ALIGN_STACK \ "mov r10, sp\n\t" \ "mov r4, sp\n\t" \ "bic r4, r4, #7\n\t" \ "mov sp, r4\n\t" #define VALGRIND_RESTORE_STACK \ "mov sp, r10\n\t" /* These CALL_FN_ macros assume that on arm-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "push {r0} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "push {r0, r1} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "push {r0, r1, r2} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "push {r0, r1, r2, r3} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #40] \n\t" \ "push {r0} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #4 \n\t" \ "ldr r0, [%1, #40] \n\t" \ "ldr r1, [%1, #44] \n\t" \ "push {r0, r1} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr r0, [%1, #40] \n\t" \ "ldr r1, [%1, #44] \n\t" \ "ldr r2, [%1, #48] \n\t" \ "push {r0, r1, r2} \n\t" \ "ldr r0, [%1, #20] \n\t" \ "ldr r1, [%1, #24] \n\t" \ "ldr r2, [%1, #28] \n\t" \ "ldr r3, [%1, #32] \n\t" \ "ldr r4, [%1, #36] \n\t" \ "push {r0, r1, r2, r3, r4} \n\t" \ "ldr r0, [%1, #4] \n\t" \ "ldr r1, [%1, #8] \n\t" \ "ldr r2, [%1, #12] \n\t" \ "ldr r3, [%1, #16] \n\t" \ "ldr r4, [%1] \n\t" /* target->r4 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \ VALGRIND_RESTORE_STACK \ "mov %0, r0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_arm_linux */ /* ------------------------ arm64-linux ------------------------ */ #if defined(PLAT_arm64_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS \ "x0", "x1", "x2", "x3","x4", "x5", "x6", "x7", "x8", "x9", \ "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", \ "x18", "x19", "x20", "x30", \ "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \ "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", \ "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", \ "v26", "v27", "v28", "v29", "v30", "v31" /* x21 is callee-saved, so we can use it to save and restore SP around the hidden call. */ #define VALGRIND_ALIGN_STACK \ "mov x21, sp\n\t" \ "bic sp, x21, #15\n\t" #define VALGRIND_RESTORE_STACK \ "mov sp, x21\n\t" /* These CALL_FN_ macros assume that on arm64-linux, sizeof(unsigned long) == 8. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x7, [%1, #64] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #0x20 \n\t" \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x7, [%1, #64] \n\t" \ "ldr x8, [%1, #72] \n\t" \ "str x8, [sp, #0] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #0x20 \n\t" \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x7, [%1, #64] \n\t" \ "ldr x8, [%1, #72] \n\t" \ "str x8, [sp, #0] \n\t" \ "ldr x8, [%1, #80] \n\t" \ "str x8, [sp, #8] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #0x30 \n\t" \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x7, [%1, #64] \n\t" \ "ldr x8, [%1, #72] \n\t" \ "str x8, [sp, #0] \n\t" \ "ldr x8, [%1, #80] \n\t" \ "str x8, [sp, #8] \n\t" \ "ldr x8, [%1, #88] \n\t" \ "str x8, [sp, #16] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10,arg11, \ arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ VALGRIND_ALIGN_STACK \ "sub sp, sp, #0x30 \n\t" \ "ldr x0, [%1, #8] \n\t" \ "ldr x1, [%1, #16] \n\t" \ "ldr x2, [%1, #24] \n\t" \ "ldr x3, [%1, #32] \n\t" \ "ldr x4, [%1, #40] \n\t" \ "ldr x5, [%1, #48] \n\t" \ "ldr x6, [%1, #56] \n\t" \ "ldr x7, [%1, #64] \n\t" \ "ldr x8, [%1, #72] \n\t" \ "str x8, [sp, #0] \n\t" \ "ldr x8, [%1, #80] \n\t" \ "str x8, [sp, #8] \n\t" \ "ldr x8, [%1, #88] \n\t" \ "str x8, [sp, #16] \n\t" \ "ldr x8, [%1, #96] \n\t" \ "str x8, [sp, #24] \n\t" \ "ldr x8, [%1] \n\t" /* target->x8 */ \ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \ VALGRIND_RESTORE_STACK \ "mov %0, x0" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_arm64_linux */ /* ------------------------- s390x-linux ------------------------- */ #if defined(PLAT_s390x_linux) /* Similar workaround as amd64 (see above), but we use r11 as frame pointer and save the old r11 in r7. r11 might be used for argvec, therefore we copy argvec in r1 since r1 is clobbered after the call anyway. */ #if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM) # define __FRAME_POINTER \ ,"d"(__builtin_dwarf_cfa()) # define VALGRIND_CFI_PROLOGUE \ ".cfi_remember_state\n\t" \ "lgr 1,%1\n\t" /* copy the argvec pointer in r1 */ \ "lgr 7,11\n\t" \ "lgr 11,%2\n\t" \ ".cfi_def_cfa r11, 0\n\t" # define VALGRIND_CFI_EPILOGUE \ "lgr 11, 7\n\t" \ ".cfi_restore_state\n\t" #else # define __FRAME_POINTER # define VALGRIND_CFI_PROLOGUE \ "lgr 1,%1\n\t" # define VALGRIND_CFI_EPILOGUE #endif /* Nb: On s390 the stack pointer is properly aligned *at all times* according to the s390 GCC maintainer. (The ABI specification is not precise in this regard.) Therefore, VALGRIND_ALIGN_STACK and VALGRIND_RESTORE_STACK are not defined here. */ /* These regs are trashed by the hidden call. Note that we overwrite r14 in s390_irgen_noredir (VEX/priv/guest_s390_irgen.c) to give the function a proper return address. All others are ABI defined call clobbers. */ #if defined(__VX__) || defined(__S390_VX__) #define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \ "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", \ "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", \ "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", \ "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31" #else #define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \ "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7" #endif /* Nb: Although r11 is modified in the asm snippets below (inside VALGRIND_CFI_PROLOGUE) it is not listed in the clobber section, for two reasons: (1) r11 is restored in VALGRIND_CFI_EPILOGUE, so effectively it is not modified (2) GCC will complain that r11 cannot appear inside a clobber section, when compiled with -O -fno-omit-frame-pointer */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 1, 0(1)\n\t" /* target->r1 */ \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "d" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) /* The call abi has the arguments in r2-r6 and stack */ #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1, arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1, arg2, arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1, arg2, arg3, arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1, arg2, arg3, arg4, arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-160\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,160\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-168\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,168\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-176\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,176\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-184\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,184\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-192\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,192\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-200\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,200\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10, arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-208\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "mvc 200(8,15), 88(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,208\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1, arg2, arg3, arg4, arg5, \ arg6, arg7 ,arg8, arg9, arg10, arg11, arg12)\ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)arg1; \ _argvec[2] = (unsigned long)arg2; \ _argvec[3] = (unsigned long)arg3; \ _argvec[4] = (unsigned long)arg4; \ _argvec[5] = (unsigned long)arg5; \ _argvec[6] = (unsigned long)arg6; \ _argvec[7] = (unsigned long)arg7; \ _argvec[8] = (unsigned long)arg8; \ _argvec[9] = (unsigned long)arg9; \ _argvec[10] = (unsigned long)arg10; \ _argvec[11] = (unsigned long)arg11; \ _argvec[12] = (unsigned long)arg12; \ __asm__ volatile( \ VALGRIND_CFI_PROLOGUE \ "aghi 15,-216\n\t" \ "lg 2, 8(1)\n\t" \ "lg 3,16(1)\n\t" \ "lg 4,24(1)\n\t" \ "lg 5,32(1)\n\t" \ "lg 6,40(1)\n\t" \ "mvc 160(8,15), 48(1)\n\t" \ "mvc 168(8,15), 56(1)\n\t" \ "mvc 176(8,15), 64(1)\n\t" \ "mvc 184(8,15), 72(1)\n\t" \ "mvc 192(8,15), 80(1)\n\t" \ "mvc 200(8,15), 88(1)\n\t" \ "mvc 208(8,15), 96(1)\n\t" \ "lg 1, 0(1)\n\t" \ VALGRIND_CALL_NOREDIR_R1 \ "aghi 15,216\n\t" \ VALGRIND_CFI_EPILOGUE \ "lgr %0, 2\n\t" \ : /*out*/ "=d" (_res) \ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_s390x_linux */ /* ------------------------- mips32-linux ----------------------- */ #if defined(PLAT_mips32_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \ "$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \ "$25", "$31" /* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16\n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" /* arg1*/ \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "subu $29, $29, 16 \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 16 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 24\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 24 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 32\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "nop\n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 32 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 32\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 32 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 40\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 40 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 40\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 40 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 48\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 48 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 48\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 44(%1) \n\t" \ "sw $4, 40($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 48 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ "subu $29, $29, 8 \n\t" \ "sw $28, 0($29) \n\t" \ "sw $31, 4($29) \n\t" \ "lw $4, 20(%1) \n\t" \ "subu $29, $29, 56\n\t" \ "sw $4, 16($29) \n\t" \ "lw $4, 24(%1) \n\t" \ "sw $4, 20($29) \n\t" \ "lw $4, 28(%1) \n\t" \ "sw $4, 24($29) \n\t" \ "lw $4, 32(%1) \n\t" \ "sw $4, 28($29) \n\t" \ "lw $4, 36(%1) \n\t" \ "sw $4, 32($29) \n\t" \ "lw $4, 40(%1) \n\t" \ "sw $4, 36($29) \n\t" \ "lw $4, 44(%1) \n\t" \ "sw $4, 40($29) \n\t" \ "lw $4, 48(%1) \n\t" \ "sw $4, 44($29) \n\t" \ "lw $4, 4(%1) \n\t" \ "lw $5, 8(%1) \n\t" \ "lw $6, 12(%1) \n\t" \ "lw $7, 16(%1) \n\t" \ "lw $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "addu $29, $29, 56 \n\t" \ "lw $28, 0($29) \n\t" \ "lw $31, 4($29) \n\t" \ "addu $29, $29, 8 \n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_mips32_linux */ /* ------------------------- nanomips-linux -------------------- */ #if defined(PLAT_nanomips_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "$t4", "$t5", "$a0", "$a1", "$a2", \ "$a3", "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", \ "$t8","$t9", "$at" /* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned long) == 4. */ #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[1]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[2]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[3]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[4]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[5]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ "lw $a3,16(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[6]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ "lw $a3,16(%1)\n\t" \ "lw $a4,20(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[7]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ "lw $a3,16(%1)\n\t" \ "lw $a4,20(%1)\n\t" \ "lw $a5,24(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[8]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ "lw $a3,16(%1)\n\t" \ "lw $a4,20(%1)\n\t" \ "lw $a5,24(%1)\n\t" \ "lw $a6,28(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[9]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ __asm__ volatile( \ "lw $t9, 0(%1)\n\t" \ "lw $a0, 4(%1)\n\t" \ "lw $a1, 8(%1)\n\t" \ "lw $a2,12(%1)\n\t" \ "lw $a3,16(%1)\n\t" \ "lw $a4,20(%1)\n\t" \ "lw $a5,24(%1)\n\t" \ "lw $a6,28(%1)\n\t" \ "lw $a7,32(%1)\n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[10]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ __asm__ volatile( \ "addiu $sp, $sp, -16 \n\t" \ "lw $t9,36(%1) \n\t" \ "sw $t9, 0($sp) \n\t" \ "lw $t9, 0(%1) \n\t" \ "lw $a0, 4(%1) \n\t" \ "lw $a1, 8(%1) \n\t" \ "lw $a2,12(%1) \n\t" \ "lw $a3,16(%1) \n\t" \ "lw $a4,20(%1) \n\t" \ "lw $a5,24(%1) \n\t" \ "lw $a6,28(%1) \n\t" \ "lw $a7,32(%1) \n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0 \n\t" \ "addiu $sp, $sp, 16 \n\t" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[11]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ __asm__ volatile( \ "addiu $sp, $sp, -16 \n\t" \ "lw $t9,36(%1) \n\t" \ "sw $t9, 0($sp) \n\t" \ "lw $t9,40(%1) \n\t" \ "sw $t9, 4($sp) \n\t" \ "lw $t9, 0(%1) \n\t" \ "lw $a0, 4(%1) \n\t" \ "lw $a1, 8(%1) \n\t" \ "lw $a2,12(%1) \n\t" \ "lw $a3,16(%1) \n\t" \ "lw $a4,20(%1) \n\t" \ "lw $a5,24(%1) \n\t" \ "lw $a6,28(%1) \n\t" \ "lw $a7,32(%1) \n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0 \n\t" \ "addiu $sp, $sp, 16 \n\t" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[12]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ __asm__ volatile( \ "addiu $sp, $sp, -16 \n\t" \ "lw $t9,36(%1) \n\t" \ "sw $t9, 0($sp) \n\t" \ "lw $t9,40(%1) \n\t" \ "sw $t9, 4($sp) \n\t" \ "lw $t9,44(%1) \n\t" \ "sw $t9, 8($sp) \n\t" \ "lw $t9, 0(%1) \n\t" \ "lw $a0, 4(%1) \n\t" \ "lw $a1, 8(%1) \n\t" \ "lw $a2,12(%1) \n\t" \ "lw $a3,16(%1) \n\t" \ "lw $a4,20(%1) \n\t" \ "lw $a5,24(%1) \n\t" \ "lw $a6,28(%1) \n\t" \ "lw $a7,32(%1) \n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0 \n\t" \ "addiu $sp, $sp, 16 \n\t" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long _argvec[13]; \ volatile unsigned long _res; \ _argvec[0] = (unsigned long)_orig.nraddr; \ _argvec[1] = (unsigned long)(arg1); \ _argvec[2] = (unsigned long)(arg2); \ _argvec[3] = (unsigned long)(arg3); \ _argvec[4] = (unsigned long)(arg4); \ _argvec[5] = (unsigned long)(arg5); \ _argvec[6] = (unsigned long)(arg6); \ _argvec[7] = (unsigned long)(arg7); \ _argvec[8] = (unsigned long)(arg8); \ _argvec[9] = (unsigned long)(arg9); \ _argvec[10] = (unsigned long)(arg10); \ _argvec[11] = (unsigned long)(arg11); \ _argvec[12] = (unsigned long)(arg12); \ __asm__ volatile( \ "addiu $sp, $sp, -16 \n\t" \ "lw $t9,36(%1) \n\t" \ "sw $t9, 0($sp) \n\t" \ "lw $t9,40(%1) \n\t" \ "sw $t9, 4($sp) \n\t" \ "lw $t9,44(%1) \n\t" \ "sw $t9, 8($sp) \n\t" \ "lw $t9,48(%1) \n\t" \ "sw $t9,12($sp) \n\t" \ "lw $t9, 0(%1) \n\t" \ "lw $a0, 4(%1) \n\t" \ "lw $a1, 8(%1) \n\t" \ "lw $a2,12(%1) \n\t" \ "lw $a3,16(%1) \n\t" \ "lw $a4,20(%1) \n\t" \ "lw $a5,24(%1) \n\t" \ "lw $a6,28(%1) \n\t" \ "lw $a7,32(%1) \n\t" \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $a0 \n\t" \ "addiu $sp, $sp, 16 \n\t" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) _res; \ } while (0) #endif /* PLAT_nanomips_linux */ /* ------------------------- mips64-linux ------------------------- */ #if defined(PLAT_mips64_linux) /* These regs are trashed by the hidden call. */ #define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \ "$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \ "$25", "$31" /* These CALL_FN_ macros assume that on mips64-linux, sizeof(long long) == 8. */ #define MIPS64_LONG2REG_CAST(x) ((long long)(long)x) #define CALL_FN_W_v(lval, orig) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[1]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ __asm__ volatile( \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "0" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_W(lval, orig, arg1) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[2]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" /* arg1*/ \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[3]; \ volatile unsigned long long _res; \ _argvec[0] = _orig.nraddr; \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[4]; \ volatile unsigned long long _res; \ _argvec[0] = _orig.nraddr; \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[5]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[6]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[7]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[8]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[9]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \ __asm__ volatile( \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1) \n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[10]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \ __asm__ volatile( \ "dsubu $29, $29, 8\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 8\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ arg7,arg8,arg9,arg10) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[11]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \ __asm__ volatile( \ "dsubu $29, $29, 16\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 16\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[12]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \ _argvec[11] = MIPS64_LONG2REG_CAST(arg11); \ __asm__ volatile( \ "dsubu $29, $29, 24\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 88(%1)\n\t" \ "sd $4, 16($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 24\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ arg6,arg7,arg8,arg9,arg10, \ arg11,arg12) \ do { \ volatile OrigFn _orig = (orig); \ volatile unsigned long long _argvec[13]; \ volatile unsigned long long _res; \ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \ _argvec[11] = MIPS64_LONG2REG_CAST(arg11); \ _argvec[12] = MIPS64_LONG2REG_CAST(arg12); \ __asm__ volatile( \ "dsubu $29, $29, 32\n\t" \ "ld $4, 72(%1)\n\t" \ "sd $4, 0($29)\n\t" \ "ld $4, 80(%1)\n\t" \ "sd $4, 8($29)\n\t" \ "ld $4, 88(%1)\n\t" \ "sd $4, 16($29)\n\t" \ "ld $4, 96(%1)\n\t" \ "sd $4, 24($29)\n\t" \ "ld $4, 8(%1)\n\t" \ "ld $5, 16(%1)\n\t" \ "ld $6, 24(%1)\n\t" \ "ld $7, 32(%1)\n\t" \ "ld $8, 40(%1)\n\t" \ "ld $9, 48(%1)\n\t" \ "ld $10, 56(%1)\n\t" \ "ld $11, 64(%1)\n\t" \ "ld $25, 0(%1)\n\t" /* target->t9 */ \ VALGRIND_CALL_NOREDIR_T9 \ "daddu $29, $29, 32\n\t" \ "move %0, $2\n" \ : /*out*/ "=r" (_res) \ : /*in*/ "r" (&_argvec[0]) \ : /*trash*/ "memory", __CALLER_SAVED_REGS \ ); \ lval = (__typeof__(lval)) (long)_res; \ } while (0) #endif /* PLAT_mips64_linux */ /* ------------------------------------------------------------------ */ /* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */ /* */ /* ------------------------------------------------------------------ */ /* Some request codes. There are many more of these, but most are not exposed to end-user view. These are the public ones, all of the form 0x1000 + small_number. Core ones are in the range 0x00000000--0x0000ffff. The non-public ones start at 0x2000. */ /* These macros are used by tools -- they must be public, but don't embed them into other programs. */ #define VG_USERREQ_TOOL_BASE(a,b) \ ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16)) #define VG_IS_TOOL_USERREQ(a, b, v) \ (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000)) /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! This enum comprises an ABI exported by Valgrind to programs which use client requests. DO NOT CHANGE THE NUMERIC VALUES OF THESE ENTRIES, NOR DELETE ANY -- add new ones at the end of the most relevant group. */ typedef enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001, VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002, /* These allow any function to be called from the simulated CPU but run on the real CPU. Nb: the first arg passed to the function is always the ThreadId of the running thread! So CLIENT_CALL0 actually requires a 1 arg function, etc. */ VG_USERREQ__CLIENT_CALL0 = 0x1101, VG_USERREQ__CLIENT_CALL1 = 0x1102, VG_USERREQ__CLIENT_CALL2 = 0x1103, VG_USERREQ__CLIENT_CALL3 = 0x1104, /* Can be useful in regression testing suites -- eg. can send Valgrind's output to /dev/null and still count errors. */ VG_USERREQ__COUNT_ERRORS = 0x1201, /* Allows the client program and/or gdbserver to execute a monitor command. */ VG_USERREQ__GDB_MONITOR_COMMAND = 0x1202, /* Allows the client program to change a dynamic command line option. */ VG_USERREQ__CLO_CHANGE = 0x1203, /* These are useful and can be interpreted by any tool that tracks malloc() et al, by using vg_replace_malloc.c. */ VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301, VG_USERREQ__RESIZEINPLACE_BLOCK = 0x130b, VG_USERREQ__FREELIKE_BLOCK = 0x1302, /* Memory pool support. */ VG_USERREQ__CREATE_MEMPOOL = 0x1303, VG_USERREQ__DESTROY_MEMPOOL = 0x1304, VG_USERREQ__MEMPOOL_ALLOC = 0x1305, VG_USERREQ__MEMPOOL_FREE = 0x1306, VG_USERREQ__MEMPOOL_TRIM = 0x1307, VG_USERREQ__MOVE_MEMPOOL = 0x1308, VG_USERREQ__MEMPOOL_CHANGE = 0x1309, VG_USERREQ__MEMPOOL_EXISTS = 0x130a, /* Allow printfs to valgrind log. */ /* The first two pass the va_list argument by value, which assumes it is the same size as or smaller than a UWord, which generally isn't the case. Hence are deprecated. The second two pass the vargs by reference and so are immune to this problem. */ /* both :: char* fmt, va_list vargs (DEPRECATED) */ VG_USERREQ__PRINTF = 0x1401, VG_USERREQ__PRINTF_BACKTRACE = 0x1402, /* both :: char* fmt, va_list* vargs */ VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404, /* Stack support. */ VG_USERREQ__STACK_REGISTER = 0x1501, VG_USERREQ__STACK_DEREGISTER = 0x1502, VG_USERREQ__STACK_CHANGE = 0x1503, /* Wine support */ VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601, /* Querying of debug info. */ VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701, /* Disable/enable error reporting level. Takes a single Word arg which is the delta to this thread's error disablement indicator. Hence 1 disables or further disables errors, and -1 moves back towards enablement. Other values are not allowed. */ VG_USERREQ__CHANGE_ERR_DISABLEMENT = 0x1801, /* Some requests used for Valgrind internal, such as self-test or self-hosting. */ /* Initialise IR injection */ VG_USERREQ__VEX_INIT_FOR_IRI = 0x1901, /* Used by Inner Valgrind to inform Outer Valgrind where to find the list of inner guest threads */ VG_USERREQ__INNER_THREADS = 0x1902 } Vg_ClientRequest; #if !defined(__GNUC__) # define __extension__ /* */ #endif /* Returns the number of Valgrinds this code is running under. That is, 0 if running natively, 1 if running under Valgrind, 2 if running under Valgrind which is running under another Valgrind, etc. */ #define RUNNING_ON_VALGRIND \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */, \ VG_USERREQ__RUNNING_ON_VALGRIND, \ 0, 0, 0, 0, 0) \ /* Discard translation of code in the range [_qzz_addr .. _qzz_addr + _qzz_len - 1]. Useful if you are debugging a JITter or some such, since it provides a way to make sure valgrind will retranslate the invalidated area. Returns no value. */ #define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DISCARD_TRANSLATIONS, \ _qzz_addr, _qzz_len, 0, 0, 0) #define VALGRIND_INNER_THREADS(_qzz_addr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__INNER_THREADS, \ _qzz_addr, 0, 0, 0, 0) /* These requests are for getting Valgrind itself to print something. Possibly with a backtrace. This is a really ugly hack. The return value is the number of characters printed, excluding the "**** " part at the start and the backtrace (if present). */ #if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER) /* Modern GCC will optimize the static routine out if unused, and unused attribute will shut down warnings about it. */ static int VALGRIND_PRINTF(const char *format, ...) __attribute__((format(__printf__, 1, 2), __unused__)); #endif static int #if defined(_MSC_VER) __inline #endif VALGRIND_PRINTF(const char *format, ...) { #if defined(NVALGRIND) (void)format; return 0; #else /* NVALGRIND */ #if defined(_MSC_VER) || defined(__MINGW64__) uintptr_t _qzz_res; #else unsigned long _qzz_res; #endif va_list vargs; va_start(vargs, format); #if defined(_MSC_VER) || defined(__MINGW64__) _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_VALIST_BY_REF, (uintptr_t)format, (uintptr_t)&vargs, 0, 0, 0); #else _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_VALIST_BY_REF, (unsigned long)format, (unsigned long)&vargs, 0, 0, 0); #endif va_end(vargs); return (int)_qzz_res; #endif /* NVALGRIND */ } #if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER) static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...) __attribute__((format(__printf__, 1, 2), __unused__)); #endif static int #if defined(_MSC_VER) __inline #endif VALGRIND_PRINTF_BACKTRACE(const char *format, ...) { #if defined(NVALGRIND) (void)format; return 0; #else /* NVALGRIND */ #if defined(_MSC_VER) || defined(__MINGW64__) uintptr_t _qzz_res; #else unsigned long _qzz_res; #endif va_list vargs; va_start(vargs, format); #if defined(_MSC_VER) || defined(__MINGW64__) _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF, (uintptr_t)format, (uintptr_t)&vargs, 0, 0, 0); #else _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF, (unsigned long)format, (unsigned long)&vargs, 0, 0, 0); #endif va_end(vargs); return (int)_qzz_res; #endif /* NVALGRIND */ } /* These requests allow control to move from the simulated CPU to the real CPU, calling an arbitrary function. Note that the current ThreadId is inserted as the first argument. So this call: VALGRIND_NON_SIMD_CALL2(f, arg1, arg2) requires f to have this signature: Word f(Word tid, Word arg1, Word arg2) where "Word" is a word-sized type. Note that these client requests are not entirely reliable. For example, if you call a function with them that subsequently calls printf(), there's a high chance Valgrind will crash. Generally, your prospects of these working are made higher if the called function does not refer to any global variables, and does not refer to any libc or other functions (printf et al). Any kind of entanglement with libc or dynamic linking is likely to have a bad outcome, for tricky reasons which we've grappled with a lot in the past. */ #define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL0, \ _qyy_fn, \ 0, 0, 0, 0) #define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL1, \ _qyy_fn, \ _qyy_arg1, 0, 0, 0) #define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL2, \ _qyy_fn, \ _qyy_arg1, _qyy_arg2, 0, 0) #define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \ VG_USERREQ__CLIENT_CALL3, \ _qyy_fn, \ _qyy_arg1, _qyy_arg2, \ _qyy_arg3, 0) /* Counts the number of errors that have been recorded by a tool. Nb: the tool must record the errors with VG_(maybe_record_error)() or VG_(unique_error)() for them to be counted. */ #define VALGRIND_COUNT_ERRORS \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR( \ 0 /* default return */, \ VG_USERREQ__COUNT_ERRORS, \ 0, 0, 0, 0, 0) /* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing when heap blocks are allocated in order to give accurate results. This happens automatically for the standard allocator functions such as malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete, delete[], etc. But if your program uses a custom allocator, this doesn't automatically happen, and Valgrind will not do as well. For example, if you allocate superblocks with mmap() and then allocates chunks of the superblocks, all Valgrind's observations will be at the mmap() level and it won't know that the chunks should be considered separate entities. In Memcheck's case, that means you probably won't get heap block overrun detection (because there won't be redzones marked as unaddressable) and you definitely won't get any leak detection. The following client requests allow a custom allocator to be annotated so that it can be handled accurately by Valgrind. VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated by a malloc()-like function. For Memcheck (an illustrative case), this does two things: - It records that the block has been allocated. This means any addresses within the block mentioned in error messages will be identified as belonging to the block. It also means that if the block isn't freed it will be detected by the leak checker. - It marks the block as being addressable and undefined (if 'is_zeroed' is not set), or addressable and defined (if 'is_zeroed' is set). This controls how accesses to the block by the program are handled. 'addr' is the start of the usable block (ie. after any redzone), 'sizeB' is its size. 'rzB' is the redzone size if the allocator can apply redzones -- these are blocks of padding at the start and end of each block. Adding redzones is recommended as it makes it much more likely Valgrind will spot block overruns. `is_zeroed' indicates if the memory is zeroed (or filled with another predictable value), as is the case for calloc(). VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a heap block -- that will be used by the client program -- is allocated. It's best to put it at the outermost level of the allocator if possible; for example, if you have a function my_alloc() which calls internal_alloc(), and the client request is put inside internal_alloc(), stack traces relating to the heap block will contain entries for both my_alloc() and internal_alloc(), which is probably not what you want. For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out custom blocks from within a heap block, B, that has been allocated with malloc/calloc/new/etc, then block B will be *ignored* during leak-checking -- the custom blocks will take precedence. VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For Memcheck, it does two things: - It records that the block has been deallocated. This assumes that the block was annotated as having been allocated via VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued. - It marks the block as being unaddressable. VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a heap block is deallocated. VALGRIND_RESIZEINPLACE_BLOCK informs a tool about reallocation. For Memcheck, it does four things: - It records that the size of a block has been changed. This assumes that the block was annotated as having been allocated via VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued. - If the block shrunk, it marks the freed memory as being unaddressable. - If the block grew, it marks the new area as undefined and defines a red zone past the end of the new block. - The V-bits of the overlap between the old and the new block are preserved. VALGRIND_RESIZEINPLACE_BLOCK should be put after allocation of the new block and before deallocation of the old block. In many cases, these three client requests will not be enough to get your allocator working well with Memcheck. More specifically, if your allocator writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call will be necessary to mark the memory as addressable just before the zeroing occurs, otherwise you'll get a lot of invalid write errors. For example, you'll need to do this if your allocator recycles freed blocks, but it zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK). Alternatively, if your allocator reuses freed blocks for allocator-internal data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary. Really, what's happening is a blurring of the lines between the client program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the memory should be considered unaddressable to the client program, but the allocator knows more than the rest of the client program and so may be able to safely access it. Extra client requests are necessary for Valgrind to understand the distinction between the allocator and the rest of the program. Ignored if addr == 0. */ #define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK, \ addr, sizeB, rzB, is_zeroed, 0) /* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details. Ignored if addr == 0. */ #define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__RESIZEINPLACE_BLOCK, \ addr, oldSizeB, newSizeB, rzB, 0) /* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details. Ignored if addr == 0. */ #define VALGRIND_FREELIKE_BLOCK(addr, rzB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__FREELIKE_BLOCK, \ addr, rzB, 0, 0, 0) /* Create a memory pool. */ #define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \ pool, rzB, is_zeroed, 0, 0) /* Create a memory pool with some flags specifying extended behaviour. When flags is zero, the behaviour is identical to VALGRIND_CREATE_MEMPOOL. The flag VALGRIND_MEMPOOL_METAPOOL specifies that the pieces of memory associated with the pool using VALGRIND_MEMPOOL_ALLOC will be used by the application as superblocks to dole out MALLOC_LIKE blocks using VALGRIND_MALLOCLIKE_BLOCK. In other words, a meta pool is a "2 levels" pool : first level is the blocks described by VALGRIND_MEMPOOL_ALLOC. The second level blocks are described using VALGRIND_MALLOCLIKE_BLOCK. Note that the association between the pool and the second level blocks is implicit : second level blocks will be located inside first level blocks. It is necessary to use the VALGRIND_MEMPOOL_METAPOOL flag for such 2 levels pools, as otherwise valgrind will detect overlapping memory blocks, and will abort execution (e.g. during leak search). Such a meta pool can also be marked as an 'auto free' pool using the flag VALGRIND_MEMPOOL_AUTO_FREE, which must be OR-ed together with the VALGRIND_MEMPOOL_METAPOOL. For an 'auto free' pool, VALGRIND_MEMPOOL_FREE will automatically free the second level blocks that are contained inside the first level block freed with VALGRIND_MEMPOOL_FREE. In other words, calling VALGRIND_MEMPOOL_FREE will cause implicit calls to VALGRIND_FREELIKE_BLOCK for all the second level blocks included in the first level block. Note: it is an error to use the VALGRIND_MEMPOOL_AUTO_FREE flag without the VALGRIND_MEMPOOL_METAPOOL flag. */ #define VALGRIND_MEMPOOL_AUTO_FREE 1 #define VALGRIND_MEMPOOL_METAPOOL 2 #define VALGRIND_CREATE_MEMPOOL_EXT(pool, rzB, is_zeroed, flags) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \ pool, rzB, is_zeroed, flags, 0) /* Destroy a memory pool. */ #define VALGRIND_DESTROY_MEMPOOL(pool) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \ pool, 0, 0, 0, 0) /* Associate a piece of memory with a memory pool. */ #define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_ALLOC, \ pool, addr, size, 0, 0) /* Disassociate a piece of memory from a memory pool. */ #define VALGRIND_MEMPOOL_FREE(pool, addr) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_FREE, \ pool, addr, 0, 0, 0) /* Disassociate any pieces outside a particular range. */ #define VALGRIND_MEMPOOL_TRIM(pool, addr, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_TRIM, \ pool, addr, size, 0, 0) /* Resize and/or move a piece associated with a memory pool. */ #define VALGRIND_MOVE_MEMPOOL(poolA, poolB) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MOVE_MEMPOOL, \ poolA, poolB, 0, 0, 0) /* Resize and/or move a piece associated with a memory pool. */ #define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_CHANGE, \ pool, addrA, addrB, size, 0) /* Return 1 if a mempool exists, else 0. */ #define VALGRIND_MEMPOOL_EXISTS(pool) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__MEMPOOL_EXISTS, \ pool, 0, 0, 0, 0) /* Mark a piece of memory as being a stack. Returns a stack id. start is the lowest addressable stack byte, end is the highest addressable stack byte. */ #define VALGRIND_STACK_REGISTER(start, end) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__STACK_REGISTER, \ start, end, 0, 0, 0) /* Unmark the piece of memory associated with a stack id as being a stack. */ #define VALGRIND_STACK_DEREGISTER(id) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_DEREGISTER, \ id, 0, 0, 0, 0) /* Change the start and end address of the stack id. start is the new lowest addressable stack byte, end is the new highest addressable stack byte. */ #define VALGRIND_STACK_CHANGE(id, start, end) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_CHANGE, \ id, start, end, 0, 0) /* Load PDB debug info for Wine PE image_map. */ #define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LOAD_PDB_DEBUGINFO, \ fd, ptr, total_size, delta, 0) /* Map a code address to a source file name and line number. buf64 must point to a 64-byte buffer in the caller's address space. The result will be dumped in there and is guaranteed to be zero terminated. If no info is found, the first byte is set to zero. */ #define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64) \ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \ VG_USERREQ__MAP_IP_TO_SRCLOC, \ addr, buf64, 0, 0, 0) /* Disable error reporting for this thread. Behaves in a stack like way, so you can safely call this multiple times provided that VALGRIND_ENABLE_ERROR_REPORTING is called the same number of times to re-enable reporting. The first call of this macro disables reporting. Subsequent calls have no effect except to increase the number of VALGRIND_ENABLE_ERROR_REPORTING calls needed to re-enable reporting. Child threads do not inherit this setting from their parents -- they are always created with reporting enabled. */ #define VALGRIND_DISABLE_ERROR_REPORTING \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \ 1, 0, 0, 0, 0) /* Re-enable error reporting, as per comments on VALGRIND_DISABLE_ERROR_REPORTING. */ #define VALGRIND_ENABLE_ERROR_REPORTING \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \ -1, 0, 0, 0, 0) /* Execute a monitor command from the client program. If a connection is opened with GDB, the output will be sent according to the output mode set for vgdb. If no connection is opened, output will go to the log output. Returns 1 if command not recognised, 0 otherwise. */ #define VALGRIND_MONITOR_COMMAND(command) \ VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__GDB_MONITOR_COMMAND, \ command, 0, 0, 0, 0) /* Change the value of a dynamic command line option. Note that unknown or not dynamically changeable options will cause a warning message to be output. */ #define VALGRIND_CLO_CHANGE(option) \ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CLO_CHANGE, \ option, 0, 0, 0, 0) #undef PLAT_x86_darwin #undef PLAT_amd64_darwin #undef PLAT_x86_win32 #undef PLAT_amd64_win64 #undef PLAT_x86_linux #undef PLAT_amd64_linux #undef PLAT_ppc32_linux #undef PLAT_ppc64be_linux #undef PLAT_ppc64le_linux #undef PLAT_arm_linux #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux #undef PLAT_nanomips_linux #undef PLAT_x86_solaris #undef PLAT_amd64_solaris #endif /* __VALGRIND_H */ libinput-1.28.1/meson.build000066400000000000000000001067541477265155700156330ustar00rootroot00000000000000project('libinput', 'c', version : '1.28.1', license : 'MIT/Expat', default_options : [ 'c_std=gnu99', 'warning_level=2' ], meson_version : '>= 0.56.0') libinput_version = meson.project_version().split('.') dir_data = get_option('prefix') / get_option('datadir') / 'libinput' dir_etc = get_option('prefix') / get_option('sysconfdir') dir_overrides = get_option('prefix') / get_option('sysconfdir') / 'libinput' dir_libexec = get_option('prefix') / get_option('libexecdir') / 'libinput' dir_lib = get_option('prefix') / get_option('libdir') dir_man1 = get_option('prefix') / get_option('mandir') / 'man1' dir_system_udev = get_option('prefix') / 'lib' / 'udev' dir_src_quirks = meson.current_source_dir() / 'quirks' dir_src_test = meson.current_source_dir() / 'test' dir_src = meson.current_source_dir() / 'src' dir_gitlab_ci = meson.current_source_dir() / '.gitlab-ci' dir_udev = get_option('udev-dir') if dir_udev == '' dir_udev = dir_system_udev endif dir_udev_callouts = dir_udev dir_udev_rules = dir_udev / 'rules.d' # Collection of man pages, we'll append to that src_man = files() # We use libtool-version numbers because it's easier to understand. # Before making a release, the libinput_so_* # numbers should be modified. The components are of the form C:R:A. # a) If binary compatibility has been broken (eg removed or changed interfaces) # change to C+1:0:0. # b) If interfaces have been changed or added, but binary compatibility has # been preserved, change to C+1:0:A+1 # c) If the interface is the same as the previous version, change to C:R+1:A libinput_lt_c=23 libinput_lt_r=0 libinput_lt_a=13 # convert to soname libinput_so_version = '@0@.@1@.@2@'.format((libinput_lt_c - libinput_lt_a), libinput_lt_a, libinput_lt_r) # Compiler setup cc = meson.get_compiler('c') cflags = [ '-Wno-unused-parameter', '-Wmissing-prototypes', '-Wstrict-prototypes', '-Wundef', '-Wlogical-op', '-Wpointer-arith', '-Wuninitialized', '-Winit-self', '-Wstrict-prototypes', '-Wimplicit-fallthrough', '-Wredundant-decls', '-Wincompatible-pointer-types', '-Wformat=2', '-Wno-missing-field-initializers', '-Wmissing-declarations', '-fvisibility=hidden', ] add_project_arguments(cc.get_supported_arguments(cflags), language : 'c') # config.h config_h = configuration_data() doc_url_base = 'https://wayland.freedesktop.org/libinput/doc' if libinput_version[2].to_int() >= 90 doc_url = '@0@/latest'.format(doc_url_base) else doc_url = '@0@/@1@'.format(doc_url_base, meson.project_version()) endif config_h.set_quoted('HTTP_DOC_LINK', doc_url) config_h.set('_GNU_SOURCE', '1') if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized' config_h.set_quoted('MESON_BUILD_ROOT', meson.current_build_dir()) else config_h.set_quoted('MESON_BUILD_ROOT', '') endif prefix = '''#define _GNU_SOURCE 1 #include ''' if cc.get_define('static_assert', prefix : prefix) == '' config_h.set('static_assert(...)', '/* */') endif # Coverity breaks because it doesn't define _Float128 correctly, you'll end # up with a bunch of messages in the form: # "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is # undefined # extern _Float128 strtof128 (const char *__restrict __nptr, # ^ # We don't use float128 ourselves, it gets pulled in from math.h or # something, so let's just define it as uint128 and move on. # Unfortunately we can't detect the coverity build at meson configure # time, we only know it fails at runtime. So make this an option instead, to # be removed when coverity fixes this again. if get_option('coverity') config_h.set('_Float128', '__uint128_t') config_h.set('_Float32', 'int') config_h.set('_Float32x', 'int') config_h.set('_Float64', 'long') config_h.set('_Float64x', 'long') endif if cc.has_header_symbol('dirent.h', 'versionsort', prefix : prefix) config_h.set('HAVE_VERSIONSORT', '1') endif if cc.get_define('SYS_pidfd_open', prefix: '#include ') != '' config_h.set('HAVE_PIDFD_OPEN', '1') endif if cc.has_function('sigabbrev_np', prefix: '#define _GNU_SOURCE 1\n#include ') config_h.set('HAVE_SIGABBREV_NP', '1') endif if not cc.has_header_symbol('errno.h', 'program_invocation_short_name', prefix : prefix) if cc.has_header_symbol('stdlib.h', 'getprogname') config_h.set('program_invocation_short_name', 'getprogname()') endif endif if cc.has_header('xlocale.h') config_h.set('HAVE_XLOCALE_H', '1') endif code = ''' #include void main(void) { newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); } ''' if cc.links(code, name : 'locale.h') config_h.set('HAVE_LOCALE_H', '1') endif if not cc.has_header_symbol('sys/ptrace.h', 'PTRACE_ATTACH', prefix : prefix) config_h.set('PTRACE_ATTACH', 'PT_ATTACH') config_h.set('PTRACE_CONT', 'PT_CONTINUE') config_h.set('PTRACE_DETACH', 'PT_DETACH') endif config_h.set10('HAVE_INSTALLED_TESTS', get_option('install-tests')) # Dependencies pkgconfig = import('pkgconfig') dep_udev = dependency('libudev') dep_mtdev = dependency('mtdev', version : '>= 1.1.0') dep_libevdev = dependency('libevdev') config_h.set10('HAVE_LIBEVDEV_DISABLE_PROPERTY', dep_libevdev.version().version_compare('>= 1.9.902')) dep_lm = cc.find_library('m', required : false) dep_rt = cc.find_library('rt', required : false) # Include directories includes_include = include_directories('include') includes_src = include_directories('src') ############ libwacom configuration ############ have_libwacom = get_option('libwacom') config_h.set10('HAVE_LIBWACOM', have_libwacom) if have_libwacom dep_libwacom = dependency('libwacom', version : '>= 0.27') if cc.has_header_symbol('libwacom/libwacom.h', 'WACOM_BUTTON_DIAL_MODESWITCH', dependencies : dep_libwacom) config_h.set('HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH', '1') endif if cc.has_function('libwacom_get_button_modeswitch_mode', dependencies: dep_libwacom) config_h.set('HAVE_LIBWACOM_BUTTON_MODESWITCH_MODE', '1') endif else dep_libwacom = declare_dependency() endif ############ udev bits ############ executable('libinput-device-group', 'udev/libinput-device-group.c', dependencies : [dep_udev, dep_libwacom], include_directories : [includes_src, includes_include], install : true, install_dir : dir_udev_callouts) executable('libinput-fuzz-extract', 'udev/libinput-fuzz-extract.c', 'src/util-strings.c', 'src/util-prop-parsers.c', dependencies : [dep_udev, dep_libevdev, dep_lm], include_directories : [includes_src, includes_include], install : true, install_dir : dir_udev_callouts) executable('libinput-fuzz-to-zero', 'udev/libinput-fuzz-to-zero.c', dependencies : [dep_udev, dep_libevdev], include_directories : [includes_src, includes_include], install : true, install_dir : dir_udev_callouts) udev_rules_config = configuration_data() udev_rules_config.set('UDEV_TEST_PATH', '') configure_file(input : 'udev/80-libinput-device-groups.rules.in', output : '80-libinput-device-groups.rules', install_dir : dir_udev_rules, configuration : udev_rules_config) configure_file(input : 'udev/90-libinput-fuzz-override.rules.in', output : '90-libinput-fuzz-override.rules', install_dir : dir_udev_rules, configuration : udev_rules_config) litest_udev_rules_config = configuration_data() litest_udev_rules_config.set('UDEV_TEST_PATH', meson.current_build_dir() + '/') litest_groups_rules_file = configure_file(input : 'udev/80-libinput-device-groups.rules.in', output : '80-libinput-device-groups-litest.rules', configuration : litest_udev_rules_config) litest_fuzz_override_file = configure_file(input : 'udev/90-libinput-fuzz-override.rules.in', output : '90-libinput-fuzz-override-litest.rules', configuration : litest_udev_rules_config) ############ Check for leftover udev rules ######## # This test should be defined first so we don't waste time testing anything # else if we're about to fail anyway. ninja test will execute tests in the # order of them defined in meson.build if get_option('tests') test('leftover-rules', find_program('test/check-leftover-udev-rules.sh'), is_parallel : false, suite : ['all']) endif ############ libepoll-shim (BSD) ############ if cc.has_header_symbol('sys/epoll.h', 'epoll_create1', prefix : prefix) # epoll is built-in (Linux, illumos) dep_libepoll = declare_dependency() else # epoll is implemented in userspace by libepoll-shim (FreeBSD) dir_libepoll = get_option('epoll-dir') if dir_libepoll == '' dir_libepoll = get_option('prefix') endif includes_epoll = include_directories(dir_libepoll / 'include' / 'libepoll-shim') dep_libepoll = cc.find_library('epoll-shim', dirs : dir_libepoll / 'lib') code = ''' #include int main(void) { epoll_create1(0); } ''' if not cc.links(code, name : 'libepoll-shim check', dependencies : [dep_libepoll, dep_rt], include_directories : includes_epoll) # note: wants an include_directories object error('No built-in epoll or libepoll-shim found.') endif dep_libepoll = declare_dependency( include_directories : includes_epoll, dependencies : [dep_libepoll, dep_rt]) endif ############ libinput-util.a ############ # Basic compilation test to make sure the headers include and define all the # necessary bits. util_headers = [ 'util-backtrace.h', 'util-bits.h', 'util-input-event.h', 'util-list.h', 'util-files.h', 'util-macros.h', 'util-matrix.h', 'util-prop-parsers.h', 'util-ratelimit.h', 'util-stringbuf.h', 'util-strings.h', 'util-time.h', ] foreach h: util_headers c = configuration_data() c.set_quoted('FILE', h) testfile = configure_file(input : 'test/test-util-includes.c', output : 'test-util-includes-@0@.c'.format(h), configuration : c) executable('test-build-@0@'.format(h), testfile, include_directories : [includes_src, includes_include], install : false) endforeach src_libinput_util = [ 'src/util-list.c', 'src/util-ratelimit.c', 'src/util-strings.c', 'src/util-prop-parsers.c', ] libinput_util = static_library('libinput-util', src_libinput_util, dependencies : [dep_udev, dep_libevdev, dep_libwacom], include_directories : includes_include) dep_libinput_util = declare_dependency(link_with : libinput_util) ############ libfilter.a ############ src_libfilter = [ 'src/filter.c', 'src/filter-custom.c', 'src/filter-flat.c', 'src/filter-low-dpi.c', 'src/filter-mouse.c', 'src/filter-touchpad.c', 'src/filter-touchpad-flat.c', 'src/filter-touchpad-x230.c', 'src/filter-tablet.c', 'src/filter-trackpoint.c', 'src/filter-trackpoint-flat.c', ] libfilter = static_library('filter', src_libfilter, dependencies : [dep_udev, dep_libwacom], include_directories : includes_include) dep_libfilter = declare_dependency(link_with : libfilter) ############ libquirks.a ############# libinput_data_path = dir_data libinput_data_override_path = dir_overrides / 'local-overrides.quirks' config_h.set_quoted('LIBINPUT_QUIRKS_DIR', dir_data) config_h.set_quoted('LIBINPUT_QUIRKS_OVERRIDE_FILE', libinput_data_override_path) config_h.set_quoted('LIBINPUT_QUIRKS_SRCDIR', dir_src_quirks) install_subdir('quirks', exclude_files: ['README.md'], install_dir : dir_data, strip_directory : true) src_libquirks = [ 'src/quirks.c', ] deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util] libquirks = static_library('quirks', src_libquirks, dependencies : deps_libquirks, include_directories : includes_include) dep_libquirks = declare_dependency(link_with : libquirks) # Create /etc/libinput if meson.version().version_compare('>= 0.60') install_emptydir(dir_etc / 'libinput') else install_subdir('libinput', install_dir : dir_etc) endif ############ libinput.so ############ config_h.set10('EVENT_DEBUGGING', get_option('internal-event-debugging')) install_headers('src/libinput.h') src_libinput = src_libfilter + [ 'src/libinput.c', 'src/libinput-private-config.c', 'src/evdev.c', 'src/evdev-debounce.c', 'src/evdev-fallback.c', 'src/evdev-totem.c', 'src/evdev-middle-button.c', 'src/evdev-mt-touchpad.c', 'src/evdev-mt-touchpad-tap.c', 'src/evdev-mt-touchpad-thumb.c', 'src/evdev-mt-touchpad-buttons.c', 'src/evdev-mt-touchpad-edge-scroll.c', 'src/evdev-mt-touchpad-gestures.c', 'src/evdev-tablet.c', 'src/evdev-tablet-pad.c', 'src/evdev-tablet-pad-leds.c', 'src/evdev-wheel.c', 'src/path-seat.c', 'src/udev-seat.c', 'src/timer.c', 'src/util-libinput.c', ] deps_libinput = [ dep_mtdev, dep_udev, dep_libevdev, dep_libepoll, dep_lm, dep_rt, dep_libwacom, dep_libinput_util, dep_libquirks ] libinput_version_h_config = configuration_data() libinput_version_h_config.set('LIBINPUT_VERSION_MAJOR', libinput_version[0]) libinput_version_h_config.set('LIBINPUT_VERSION_MINOR', libinput_version[1]) libinput_version_h_config.set('LIBINPUT_VERSION_MICRO', libinput_version[2]) libinput_version_h_config.set('LIBINPUT_VERSION', meson.project_version()) libinput_version_h = configure_file( input : 'src/libinput-version.h.in', output : 'libinput-version.h', configuration : libinput_version_h_config, ) mapfile = dir_src / 'libinput.sym' version_flag = '-Wl,--version-script,@0@'.format(mapfile) lib_libinput = shared_library('input', src_libinput, include_directories : [include_directories('.'), includes_include], dependencies : deps_libinput, version : libinput_so_version, link_args : version_flag, link_depends : mapfile, install : true ) dep_libinput = declare_dependency( link_with : lib_libinput, dependencies : deps_libinput) if meson.version().version_compare('>= 0.54.0') meson.override_dependency('libinput', dep_libinput) endif pkgconfig.generate( filebase : 'libinput', name : 'Libinput', description : 'Input device library', version : meson.project_version(), libraries : lib_libinput ) git_version_h = vcs_tag(command : ['git', 'describe'], fallback : 'unknown', input : 'src/libinput-git-version.h.in', output :'libinput-git-version.h') ############ documentation ############ if get_option('documentation') subdir('doc/api') subdir('doc/user') endif ############ shell completion ######### subdir('completion/zsh') ############ libinput-util-libinput.a ############ # This one needs libinput itself src_libinput_util_libinput = [ 'src/util-libinput.c' ] libinput_util_libinput = static_library('libinput-util-libinput', src_libinput_util_libinput, dependencies : [dep_libevdev, dep_libinput_util, dep_libinput], include_directories : includes_include) dep_libinput_util_libinput = declare_dependency(link_with : libinput_util_libinput) ############ tools ############ libinput_tool_path = dir_libexec config_h.set_quoted('LIBINPUT_TOOL_PATH', libinput_tool_path) tools_shared_sources = [ 'tools/shared.c' ] deps_tools_shared = [ dep_libinput, dep_libevdev, dep_libinput_util_libinput ] lib_tools_shared = static_library('tools_shared', tools_shared_sources, include_directories : [includes_src, includes_include], dependencies : deps_tools_shared) dep_tools_shared = declare_dependency(link_with : lib_tools_shared, dependencies : deps_tools_shared) deps_tools = [ dep_tools_shared, dep_libinput ] libinput_debug_events_sources = [ 'tools/libinput-debug-events.c', libinput_version_h, ] executable('libinput-debug-events', libinput_debug_events_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true ) libinput_debug_tablet_sources = [ 'tools/libinput-debug-tablet.c' ] executable('libinput-debug-tablet', libinput_debug_tablet_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true) libinput_quirks_sources = [ 'tools/libinput-quirks.c' ] libinput_quirks = executable('libinput-quirks', libinput_quirks_sources, dependencies : [dep_libquirks, dep_tools_shared, dep_libinput], include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true ) test('validate-quirks', libinput_quirks, args: ['validate', '--data-dir=@0@'.format(dir_src_quirks)], suite : ['all'] ) quirks_file_tester = find_program('test/test_quirks_files.py') test('validate-quirks-files', quirks_file_tester, suite : ['all'], env: ['MESON_SOURCE_ROOT=@0@'.format(meson.project_source_root())], ) libinput_list_devices_sources = [ 'tools/libinput-list-devices.c' ] libinput_list_devices = executable('libinput-list-devices', libinput_list_devices_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, ) test('list-devices', libinput_list_devices, suite : ['all', 'root', 'hardware']) libinput_measure_sources = [ 'tools/libinput-measure.c' ] executable('libinput-measure', libinput_measure_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, ) libinput_analyze_sources = [ 'tools/libinput-analyze.c' ] executable('libinput-analyze', libinput_analyze_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, ) src_python_tools = files( 'tools/libinput-analyze-buttons.py', 'tools/libinput-analyze-per-slot-delta.py', 'tools/libinput-analyze-recording.py', 'tools/libinput-analyze-touch-down-state.py', 'tools/libinput-list-kernel-devices.py', 'tools/libinput-measure-fuzz.py', 'tools/libinput-measure-touchpad-size.py', 'tools/libinput-measure-touchpad-tap.py', 'tools/libinput-measure-touchpad-pressure.py', 'tools/libinput-measure-touch-size.py', 'tools/libinput-replay.py' ) foreach t : src_python_tools configure_file(input: t, output: '@BASENAME@', copy: true, install_dir : libinput_tool_path ) endforeach libinput_record_sources = [ 'tools/libinput-record.c', git_version_h ] executable('libinput-record', libinput_record_sources, dependencies : deps_tools + [dep_udev], include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, ) config_h.set10('HAVE_DEBUG_GUI', get_option('debug-gui')) if get_option('debug-gui') dep_gtk = dependency('gtk4', version : '>= 4.0', required : false) config_h.set10('HAVE_GTK4', dep_gtk.found()) if not dep_gtk.found() dep_gtk = dependency('gtk+-3.0', version : '>= 3.20') config_h.set10('HAVE_GTK3', dep_gtk.found()) endif if meson.version().version_compare('>= 0.58') gtk_targets = dep_gtk.get_variable('targets') else gtk_targets = dep_gtk.get_pkgconfig_variable('targets') endif have_gtk_wayland = gtk_targets.contains('wayland') have_gtk_x11 = gtk_targets.contains('x11') dep_cairo = dependency('cairo') dep_glib = dependency('glib-2.0') dep_x11 = dependency('x11', required : false) dep_wayland_client = dependency('wayland-client', required : false) dep_wayland_protocols = dependency('wayland-protocols', required : false) config_h.set10('HAVE_GTK_X11', have_gtk_x11 and dep_x11.found()) config_h.set10('HAVE_GTK_WAYLAND', false) debug_gui_sources = [ 'tools/libinput-debug-gui.c' ] if have_gtk_wayland and dep_wayland_client.found() and dep_wayland_protocols.found() wayland_scanner = find_program('wayland-scanner') if meson.version().version_compare('>= 0.58') wlproto_dir = dep_wayland_protocols.get_variable('pkgdatadir') else wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir') endif proto_name = 'pointer-constraints-unstable-v1' input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name)) wayland_headers = custom_target('@0@ client header'.format(proto_name), input: input, output: '@0@-client-protocol.h'.format(proto_name), command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'], ) wayland_sources = custom_target('@0@ source'.format(proto_name), input: input, output: '@0@-protocol.c'.format(proto_name), command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'], ) debug_gui_sources += [ wayland_headers, wayland_sources ] config_h.set10('HAVE_GTK_WAYLAND', true) endif deps_debug_gui = [ dep_gtk, dep_cairo, dep_glib, dep_wayland_client, dep_wayland_protocols, dep_x11, ] + deps_tools executable('libinput-debug-gui', debug_gui_sources, dependencies : deps_debug_gui, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true ) src_man += files('tools/libinput-debug-gui.man') endif libinput_sources = [ 'tools/libinput-tool.c' ] libinput_tool = executable('libinput', libinput_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install : true ) ptraccel_debug_sources = [ 'tools/ptraccel-debug.c' ] executable('ptraccel-debug', ptraccel_debug_sources, dependencies : [ dep_libfilter, dep_libinput ], include_directories : [includes_src, includes_include], install : false ) # Don't run the test during a release build because we rely on the magic # subtool lookup if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized' config_tool_option_test = configuration_data() config_tool_option_test.set('DISABLE_WARNING', 'yes') config_tool_option_test.set('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui')) config_tool_option_test.set('MESON_BUILD_ROOT', meson.current_build_dir()) config_tool_option_test.set('TOOL_PATH', libinput_tool.full_path()) tool_option_test = configure_file(input: 'tools/test_tool_option_parsing.py', output: '@PLAINNAME@', configuration : config_tool_option_test) test('tool-option-parsing', tool_option_test, args : [tool_option_test], suite : ['all', 'root'], timeout : 240) endif # the libinput tools check whether we execute from the builddir, this is # the test to verify that lookup. We test twice, once as normal test # run from the builddir, once after copying to /tmp test_builddir_lookup = executable('test-builddir-lookup', 'test/test-builddir-lookup.c', dependencies : [ dep_tools_shared], include_directories : [includes_src, includes_include], install : false) test('tools-builddir-lookup', test_builddir_lookup, args : ['--builddir-is-set'], suite : ['all']) test('tools-builddir-lookup-installed', find_program('test/helper-copy-and-exec-from-tmp.sh'), args : [test_builddir_lookup.full_path(), '--builddir-is-null'], env : ['LD_LIBRARY_PATH=@0@'.format(meson.current_build_dir())], suite : ['all'], workdir : '/tmp') ############ tests ############ test('symbols-leak-test', find_program('test/symbols-leak-test'), args : [ dir_src / 'libinput.sym', dir_src], suite : ['all']) # build-test only executable('test-build-pedantic', 'test/build-pedantic.c', dependencies : [dep_udev], include_directories : [includes_src, includes_include], c_args : ['-std=c99', '-pedantic', '-Werror'], install : false) # build-test only executable('test-build-std-gnuc90', 'test/build-pedantic.c', dependencies : [dep_udev], include_directories : [includes_src, includes_include], c_args : ['-std=gnu89', '-Werror'], install : false) # test for linking with the minimal linker flags executable('test-build-linker', 'test/build-pedantic.c', include_directories : [includes_src, includes_include], dependencies : [ dep_libinput, dep_libinput_util ], install : false) # test including from C++ (in case CPP compiler is available) if add_languages('cpp', native: false, required: false) executable('test-build-cxx', 'test/build-cxx.cc', dependencies : [dep_udev], include_directories : [includes_src, includes_include], install : false) endif libinput_test_sources = [ 'tools/libinput-test.c' ] executable('libinput-test', libinput_test_sources, dependencies : deps_tools, include_directories : [includes_src, includes_include], install_dir : libinput_tool_path, install : true, ) # This is the test suite runner, we allow disabling that one because of # dependencies if get_option('tests') dep_check = dependency('check', version : '>= 0.9.10', required: false) gstack = find_program('gstack', required : false) config_h.set10('HAVE_GSTACK', gstack.found()) # for inhibit support during test run dep_libsystemd = dependency('libsystemd', version : '>= 221', required : false) config_h.set10('HAVE_LIBSYSTEMD', dep_libsystemd.found()) litest_sources = [ 'src/libinput-private-config.c', 'test/litest-device-absinfo-override.c', 'test/litest-device-acer-hawaii-keyboard.c', 'test/litest-device-acer-hawaii-touchpad.c', 'test/litest-device-aiptek-tablet.c', 'test/litest-device-alps-3fg.c', 'test/litest-device-alps-semi-mt.c', 'test/litest-device-alps-dualpoint.c', 'test/litest-device-anker-mouse-kbd.c', 'test/litest-device-apple-appletouch.c', 'test/litest-device-apple-internal-keyboard.c', 'test/litest-device-apple-magicmouse.c', 'test/litest-device-asus-rog-gladius.c', 'test/litest-device-atmel-hover.c', 'test/litest-device-bcm5974.c', 'test/litest-device-calibrated-touchscreen.c', 'test/litest-device-cyborg-rat-5.c', 'test/litest-device-dell-canvas-totem.c', 'test/litest-device-dell-canvas-totem-touch.c', 'test/litest-device-elantech-touchpad.c', 'test/litest-device-elan-tablet.c', 'test/litest-device-format-string.c', 'test/litest-device-generic-pressurepad.c', 'test/litest-device-generic-singletouch.c', 'test/litest-device-gpio-keys.c', 'test/litest-device-huion-pentablet.c', 'test/litest-device-huion-q620m-dial.c', 'test/litest-device-hp-wmi-hotkeys.c', 'test/litest-device-ignored-mouse.c', 'test/litest-device-keyboard.c', 'test/litest-device-keyboard-all-codes.c', 'test/litest-device-keyboard-quirked.c', 'test/litest-device-keyboard-razer-blackwidow.c', 'test/litest-device-keyboard-razer-blade-stealth.c', 'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c', 'test/litest-device-lenovo-scrollpoint.c', 'test/litest-device-lid-switch.c', 'test/litest-device-lid-switch-surface3.c', 'test/litest-device-logitech-media-keyboard-elite.c', 'test/litest-device-logitech-trackball.c', 'test/litest-device-nexus4-touch-screen.c', 'test/litest-device-magic-trackpad.c', 'test/litest-device-mouse.c', 'test/litest-device-mouse-wheel-tilt.c', 'test/litest-device-mouse-roccat.c', 'test/litest-device-mouse-low-dpi.c', 'test/litest-device-mouse-wheel-click-angle.c', 'test/litest-device-mouse-wheel-click-count.c', 'test/litest-device-ms-nano-transceiver-mouse.c', 'test/litest-device-ms-surface-cover.c', 'test/litest-device-protocol-a-touch-screen.c', 'test/litest-device-qemu-usb-tablet.c', 'test/litest-device-sony-vaio-keys.c', 'test/litest-device-synaptics-x220.c', 'test/litest-device-synaptics-hover.c', 'test/litest-device-synaptics-i2c.c', 'test/litest-device-synaptics-pressurepad.c', 'test/litest-device-synaptics-rmi4.c', 'test/litest-device-synaptics-st.c', 'test/litest-device-synaptics-t440.c', 'test/litest-device-synaptics-x1-carbon-3rd.c', 'test/litest-device-synaptics-phantomclicks.c', 'test/litest-device-tablet-doubledial.c', 'test/litest-device-tablet-mode-switch.c', 'test/litest-device-tablet-rel-dial.c', 'test/litest-device-thinkpad-extrabuttons.c', 'test/litest-device-trackpoint.c', 'test/litest-device-touch-screen.c', 'test/litest-device-touchpad-palm-threshold-zero.c', 'test/litest-device-touchscreen-invalid-range.c', 'test/litest-device-touchscreen-fuzz.c', 'test/litest-device-touchscreen-mt-tool.c', 'test/litest-device-uclogic-tablet.c', 'test/litest-device-wacom-bamboo-2fg-finger.c', 'test/litest-device-wacom-bamboo-2fg-pad.c', 'test/litest-device-wacom-bamboo-2fg-pen.c', 'test/litest-device-wacom-bamboo-16fg-pen.c', 'test/litest-device-wacom-calibrated-tablet.c', 'test/litest-device-wacom-cintiq-12wx-pen.c', 'test/litest-device-wacom-cintiq-13hdt-finger.c', 'test/litest-device-wacom-cintiq-13hdt-pad.c', 'test/litest-device-wacom-cintiq-13hdt-pen.c', 'test/litest-device-wacom-cintiq-24hd-pen.c', 'test/litest-device-wacom-cintiq-24hdt-pad.c', 'test/litest-device-wacom-cintiq-pro-16-finger.c', 'test/litest-device-wacom-cintiq-pro-16-pad.c', 'test/litest-device-wacom-cintiq-pro-16-pen.c', 'test/litest-device-wacom-ekr.c', 'test/litest-device-wacom-hid4800-pen.c', 'test/litest-device-wacom-intuos3-pad.c', 'test/litest-device-wacom-intuos5-finger.c', 'test/litest-device-wacom-intuos5-pad.c', 'test/litest-device-wacom-intuos5-pen.c', 'test/litest-device-wacom-isdv4-4200-pen.c', 'test/litest-device-wacom-isdv4-524c-pen.c', 'test/litest-device-wacom-isdv4-e6-pen.c', 'test/litest-device-wacom-isdv4-e6-finger.c', 'test/litest-device-wacom-mobilestudio-pro-pad.c', 'test/litest-device-waltop-tablet.c', 'test/litest-device-wheel-only.c', 'test/litest-device-xen-virtual-pointer.c', 'test/litest-device-vmware-virtual-usb-mouse.c', 'test/litest-device-yubikey.c', 'test/litest-runner.c', 'test/litest.c', ] dep_dl = cc.find_library('dl') deps_litest = [ dep_libinput, dep_udev, dep_libevdev, dep_dl, dep_lm, dep_libsystemd, dep_libquirks, dep_libinput_util_libinput, ] litest_config_h = configuration_data() litest_config_h.set_quoted('LIBINPUT_DEVICE_GROUPS_RULES_FILE', meson.current_build_dir() / '80-libinput-device-groups-litest.rules') litest_config_h.set_quoted('LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE', meson.current_build_dir() / '90-libinput-fuzz-override-litest.rules') def_no_main = '-DLITEST_NO_MAIN' if dep_check.found() def_disable_backtrace = '-DLITEST_DISABLE_BACKTRACE_LOGGING' defs_litest_selftest = [ def_no_main, def_disable_backtrace, '-Wno-unused', ] test_litest_selftest_sources = [ 'test/litest-selftest.c', 'test/litest-runner.c', 'test/litest.c', ] test_litest_selftest = executable('test-litest-selftest', test_litest_selftest_sources, include_directories : [includes_src, includes_include], dependencies : [deps_litest, dep_check], c_args : defs_litest_selftest, install : false) test('test-litest-selftest', test_litest_selftest, suite : ['all'], timeout : 100) endif def_LT_VERSION = '-DLIBINPUT_LT_VERSION="@0@:@1@:@2@"'.format(libinput_lt_c, libinput_lt_r, libinput_lt_a) test_library_version = executable('test-library-version', ['test/test-library-version.c'], c_args : [ def_LT_VERSION ], install : false) test('test-library-version', test_library_version, suite : ['all']) test_utils_sources = [ 'test/test-utils.c', 'test/litest-runner.c', 'test/litest.c', ] test_utils = executable('libinput-test-utils', test_utils_sources, include_directories : [includes_src, includes_include], c_args : [def_no_main], dependencies : deps_litest, install_dir : libinput_tool_path, install : get_option('install-tests')) test('test-utils', test_utils, suite : ['all']) tests_sources = [ 'test/test-udev.c', 'test/test-path.c', 'test/test-pointer.c', 'test/test-touch.c', 'test/test-log.c', 'test/test-tablet.c', 'test/test-totem.c', 'test/test-pad.c', 'test/test-touchpad.c', 'test/test-touchpad-tap.c', 'test/test-touchpad-buttons.c', 'test/test-trackpoint.c', 'test/test-trackball.c', 'test/test-misc.c', 'test/test-keyboard.c', 'test/test-device.c', 'test/test-gestures.c', 'test/test-switch.c', 'test/test-quirks.c', ] libinput_test_runner_sources = litest_sources + tests_sources libinput_test_runner = executable('libinput-test-suite', libinput_test_runner_sources, include_directories : [includes_src, includes_include], dependencies : deps_litest, install_dir : libinput_tool_path, install : get_option('install-tests')) src_man += 'test/libinput-test-suite.man' # When adding new TEST_COLLECTION() macros, add to this list and the CI # $ git grep TEST_COLLECTION test/test-* | sed -e "s|.*TEST_COLLECTION(\(.*\))|\t\t'\1',|" | sort collections = [ 'device', 'gestures', 'keyboard', 'log', 'misc', 'pad', 'path', 'pointer', 'quirks', 'switch', 'tablet', 'tablet_left_handed', 'totem', 'touch', 'touchpad', 'touchpad_buttons', 'touchpad_dwt', 'touchpad_palm', 'touchpad_tap', 'touchpad_tap_drag', 'touchpad_tap_palm', 'trackball', 'trackpoint', 'udev', ] foreach group : collections test('libinput-test-suite-@0@'.format(group), libinput_test_runner, suite : ['all', 'valgrind', 'root', 'hardware'], args : ['--filter-group=@0@'.format(group)], is_parallel : false, timeout : 1200) endforeach test('libinput-test-deviceless', libinput_test_runner, suite : ['all', 'valgrind'], args: ['--filter-deviceless']) valgrind = find_program('valgrind', required : false) if valgrind.found() valgrind_env = environment() valgrind_suppressions_file = dir_src_test / 'valgrind.suppressions' add_test_setup('valgrind', exe_wrapper : [ valgrind, '--log-file=valgrind.%p.log', '--leak-check=full', '--gen-suppressions=all', '--error-exitcode=3', '--suppressions=' + valgrind_suppressions_file ], env : valgrind_env, timeout_multiplier : 100) else message('valgrind not found, disabling valgrind test suite') endif configure_file(output : 'litest-config.h', configuration : litest_config_h) endif ############ man pages ############ man_config = configuration_data() man_config.set('LIBINPUT_VERSION', meson.project_version()) man_config.set('LIBINPUT_DATA_DIR', dir_data) if get_option('install-tests') man_config.set('HAVE_INSTALLED_TESTS', '.\"') else man_config.set('HAVE_INSTALLED_TESTS', '') endif if get_option('debug-gui') man_config.set('HAVE_DEBUG_GUI', '') else man_config.set('HAVE_DEBUG_GUI', '.\"') endif src_man += files( 'tools/libinput.man', 'tools/libinput-analyze.man', 'tools/libinput-analyze-buttons.man', 'tools/libinput-analyze-per-slot-delta.man', 'tools/libinput-analyze-recording.man', 'tools/libinput-analyze-touch-down-state.man', 'tools/libinput-debug-events.man', 'tools/libinput-debug-tablet.man', 'tools/libinput-list-devices.man', 'tools/libinput-list-kernel-devices.man', 'tools/libinput-measure.man', 'tools/libinput-measure-fuzz.man', 'tools/libinput-measure-touchpad-size.man', 'tools/libinput-measure-touchpad-tap.man', 'tools/libinput-measure-touchpad-pressure.man', 'tools/libinput-measure-touch-size.man', 'tools/libinput-quirks.man', 'tools/libinput-record.man', 'tools/libinput-replay.man', 'tools/libinput-test.man', ) foreach m : src_man configure_file(input : m, output : '@BASENAME@.1', configuration : man_config, install_dir : dir_man1) endforeach # Same man page for the subtools to stay consistent with the other tools configure_file(input : 'tools/libinput-quirks.man', output : 'libinput-quirks-list.1', configuration : man_config, install_dir : dir_man1, ) configure_file(input : 'tools/libinput-quirks.man', output : 'libinput-quirks-validate.1', configuration : man_config, install_dir : dir_man1, ) ############ output files ############ configure_file(output : 'config.h', configuration : config_h) libinput-1.28.1/meson_options.txt000066400000000000000000000027201477265155700171120ustar00rootroot00000000000000option('udev-dir', type: 'string', value: '', description: 'udev base directory [default=$prefix/lib/udev]') option('epoll-dir', type: 'string', value: '', description: 'libepoll-shim base directory (for non-Linux OS) [default=$prefix]') option('libwacom', type: 'boolean', value: true, description: 'Use libwacom for tablet identification (default=true)') option('debug-gui', type: 'boolean', value: true, description: 'Enable the "debug-gui" feature in the libinput tool [default=true]') option('tests', type: 'boolean', value: true, description: 'Build the tests [default=true]') option('install-tests', type: 'boolean', value: false, description: 'Install the libinput test command [default=false]') option('documentation', type: 'boolean', value: false, description: 'Build the documentation [default=false]') option('coverity', type: 'boolean', value: false, description: 'Enable coverity build fixes, see meson.build for details [default=false]') option('zshcompletiondir', type: 'string', value: '', description: 'Directory for zsh completion scripts ["no" disables]') option('internal-event-debugging', type: 'boolean', value: false, description: 'Enable additional internal event debug tracing. This will print key values to the logs and thus must never be enabled in a release build') libinput-1.28.1/quirks/000077500000000000000000000000001477265155700147725ustar00rootroot00000000000000libinput-1.28.1/quirks/10-generic-keyboard.quirks000066400000000000000000000003651477265155700216660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Serial Keyboards] MatchUdevType=keyboard MatchBus=ps2 AttrKeyboardIntegration=internal [Bluetooth Keyboards] MatchUdevType=keyboard MatchBus=bluetooth AttrKeyboardIntegration=external libinput-1.28.1/quirks/10-generic-mouse.quirks000066400000000000000000000003051477265155700212100ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # https://gitlab.freedesktop.org/libinput/libinput/-/issues/656 [Emulated Mouse] MatchName=ImPS/2 Generic Wheel Mouse ModelBouncingKeys=1 libinput-1.28.1/quirks/10-generic-trackball.quirks000066400000000000000000000001561477265155700220230ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Trackball] MatchName=*Trackball* ModelTrackball=1 libinput-1.28.1/quirks/30-vendor-a4tech.quirks000066400000000000000000000001441477265155700211140ustar00rootroot00000000000000[A4TECH USB X-710BK] MatchVendor=0x09DA MatchProduct=0x9090 MatchUdevType=mouse ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-aiptek.quirks000066400000000000000000000004631477265155700212250ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Aiptek No Tilt Tablet] MatchUdevType=tablet MatchBus=usb MatchVendor=0x08CA AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y; [Aiptek 8000U pressure threshold] MatchUdevType=tablet MatchBus=usb MatchVendor=0x08CA MatchProduct=0x0010 AttrPressureRange=70:50 libinput-1.28.1/quirks/30-vendor-alps.quirks000066400000000000000000000015761477265155700207150ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # ALPS firmware versions: # V1 = 0x100 # V2 = 0x200 # V3 = 0x300 # V3_RUSHMORE = 0x310 # V4 = 0x400 # V5 = 0x500 # V6 = 0x600 # V7 = 0x700 /* t3btl t4s */ # V8 = 0x800 /* SS4btl SS4s */ # V9 = 0x900 /* ss3btl */ [ALPS Serial Touchpads] MatchUdevType=touchpad MatchBus=ps2 MatchVendor=0x0002 MatchProduct=0x0008 ModelALPSSerialTouchpad=1 [ALPS i2c Touchpads] MatchUdevType=touchpad MatchBus=i2c MatchVendor=0x0488 AttrPalmPressureThreshold=180 [ALPS v8 Touchpads] MatchUdevType=touchpad MatchBus=ps2 MatchVendor=0x0002 MatchProduct=0x0008 MatchVersion=0x0800 AttrSizeHint=100x55 [ALPS v8 Trackpoint] MatchUdevType=pointingstick MatchBus=ps2 MatchVendor=0x0002 MatchProduct=0x0008 MatchVersion=0x0800 AttrTrackpointMultiplier=0.125 libinput-1.28.1/quirks/30-vendor-contour.quirks000066400000000000000000000010771477265155700214430ustar00rootroot00000000000000[Contour Design RollerMouse Free 2] MatchVendor=0x0B33 MatchProduct=0x0401 MatchUdevType=mouse ModelBouncingKeys=1 [Contour Design RollerMouse Free 3] MatchVendor=0x0B33 MatchProduct=0x0404 MatchUdevType=mouse ModelBouncingKeys=1 [Contour Design RollerMouse Re:d] MatchVendor=0x0B33 MatchProduct=0x1000 MatchUdevType=mouse ModelBouncingKeys=1 [Contour Design RollerMouse Red v3] MatchVendor=0x0B33 MatchProduct=0x1004 MatchUdevType=mouse ModelBouncingKeys=1 [Contour Design RollerMouse Pro3] MatchVendor=0x0B33 MatchProduct=0x0703 MatchUdevType=mouse ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-cypress.quirks000066400000000000000000000004201477265155700214310ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Cyapa Touchpads] MatchName=*Cypress APA Trackpad ?cyapa? AttrPressureRange=10:8 [Cypress Touchpads] MatchUdevType=touchpad MatchName=*CyPS/2 Cypress Trackpad AttrPressureRange=10:8 AttrPalmPressureThreshold=254 libinput-1.28.1/quirks/30-vendor-elantech.quirks000066400000000000000000000003721477265155700215320ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Elantech Touchpads] MatchName=*Elantech Touchpad* AttrResolutionHint=31x31 AttrPressureRange=10:8 [Elan Touchpads] MatchName=*Elan Touchpad* AttrResolutionHint=31x31 AttrPressureRange=10:8 libinput-1.28.1/quirks/30-vendor-glorious.quirks000066400000000000000000000001571477265155700216130ustar00rootroot00000000000000[Glorious Model O] MatchUdevType=mouse MatchBus=usb MatchVendor=0x258A MatchProduct=0x0036 ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-huion.quirks000066400000000000000000000003151477265155700210660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # This will match several vendors that all # re-use the same vendor ID 256C. [Huion/Gaomon Tablets] MatchVendor=0x256C AttrResolutionHint=205x328 libinput-1.28.1/quirks/30-vendor-ibm.quirks000066400000000000000000000021131477265155700205110ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # IBM/Lenovo Scrollpoint mouse. Instead of a scroll wheel these mice # feature trackpoint-like sticks which generate a huge amount of scroll # events that need to be handled differently than scroll wheel events [IBM ScrollPoint Mouse 3100] MatchUdevType=mouse MatchVendor=0x04B3 MatchProduct=0x3100 ModelLenovoScrollPoint=1 [IBM ScrollPoint Mouse 3103] MatchUdevType=mouse MatchVendor=0x04B3 MatchProduct=0x3103 ModelLenovoScrollPoint=1 [IBM ScrollPoint Mouse 3105] MatchUdevType=mouse MatchVendor=0x04B3 MatchProduct=0x3105 ModelLenovoScrollPoint=1 [IBM ScrollPoint Mouse 3108] MatchUdevType=mouse MatchVendor=0x04B3 MatchProduct=0x3108 ModelLenovoScrollPoint=1 [IBM ScrollPoint Mouse 3109] MatchUdevType=mouse MatchVendor=0x04B3 MatchProduct=0x3109 ModelLenovoScrollPoint=1 [IBM ScrollPoint Mouse 6049] MatchUdevType=mouse MatchVendor=0x17EF MatchProduct=0x6049 ModelLenovoScrollPoint=1 [IBM USB Travel Keyboard with Ultra Nav Mouse] MatchUdevType=pointingstick MatchVendor=0x04B3 MatchProduct=0x301E AttrTrackpointMultiplier=1.50 libinput-1.28.1/quirks/30-vendor-ite.quirks000066400000000000000000000003461477265155700205310ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # Tested on PCSpecialist Recoil 17 [ITE Device(8176) Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0x5000 AttrKeyboardIntegration=internal libinput-1.28.1/quirks/30-vendor-kensington.quirks000066400000000000000000000002731477265155700221260ustar00rootroot00000000000000# Kensington Orbit claims to have a middle button, same for [Kensington Orbit Scroll Wheel] MatchBus=usb MatchVendor=0x047D MatchProduct=0x2048 ModelTrackball=1 AttrEventCode=-BTN_MIDDLE libinput-1.28.1/quirks/30-vendor-logitech.quirks000066400000000000000000000047271477265155700215550ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Logitech M570] MatchName=*Logitech M570* ModelTrackball=1 # This will also work for the newer 'S' version — Logitech ERGO M575S [Logitech ERGO M575] MatchName=*Logitech*M575* ModelTrackball=1 # Logitech Marble Mouse claims to have a middle button [Logitech Marble Mouse Trackball] MatchUdevType=mouse MatchBus=usb MatchVendor=0x046D MatchProduct=0xC408 AttrEventCode=-BTN_MIDDLE [Logitech K400] MatchUdevType=mouse MatchBus=usb MatchVendor=0x046D MatchProduct=0x4024 ModelBouncingKeys=1 [Logitech K400r] MatchUdevType=mouse MatchBus=usb MatchVendor=0x046D MatchProduct=0x404B ModelBouncingKeys=1 [Logitech K830] MatchUdevType=mouse MatchBus=usb MatchVendor=0x046D MatchProduct=0x404C ModelBouncingKeys=1 [Logitech K400Plus] MatchUdevType=mouse MatchBus=usb MatchVendor=0x046D MatchProduct=0x404D ModelBouncingKeys=1 [Logitech Wireless Touchpad] MatchBus=usb MatchVendor=0x046D MatchProduct=0x4011 AttrPalmPressureThreshold=400 [Logitech MX Master (4041)] MatchVendor=0x046D MatchProduct=0x4041 ModelInvertHorizontalScrolling=1 [Logitech MX Master (4060)] MatchVendor=0x046D MatchProduct=0x4060 ModelInvertHorizontalScrolling=1 [Logitech MX Master (4071)] MatchVendor=0x046D MatchProduct=0x4071 ModelInvertHorizontalScrolling=1 # MX Master has a different PID on bluetooth [Logitech MX Master (Bluetooth B012)] MatchVendor=0x046D MatchProduct=0xB012 ModelInvertHorizontalScrolling=1 [Logitech MX Master (Bluetooth B017)] MatchVendor=0x046D MatchProduct=0xB017 ModelInvertHorizontalScrolling=1 [Logitech MX Master (Bluetooth B01E)] MatchVendor=0x046D MatchProduct=0xB01E ModelInvertHorizontalScrolling=1 [Logitech MX Master 2S USB] MatchVendor=0x046D MatchProduct=0x4069 ModelInvertHorizontalScrolling=1 # MX Master 2S has a different PID on bluetooth [Logitech MX Master 2S Bluetooth] MatchVendor=0x046D MatchProduct=0xB019 ModelInvertHorizontalScrolling=1 [Logitech MX Master 3 USB] MatchVendor=0x046D MatchProduct=0x4082 ModelInvertHorizontalScrolling=1 # MX Master 3 has a different PID on bluetooth [Logitech MX Master 3 Bluetooth] MatchVendor=0x046D MatchProduct=0xB023 ModelInvertHorizontalScrolling=1 [Logitech MX Master 3S] MatchVendor=0x046D MatchProduct=0xB034 ModelInvertHorizontalScrolling=1 [Logitech MX Master 3B] MatchVendor=0x046D MatchProduct=0xB028 ModelInvertHorizontalScrolling=1 # Don't add quirks for the Logitech Bolt Receiver: # MatchVendor=0x046D # MatchProduct=0xC548 # This receiver can be used with multiple mice. libinput-1.28.1/quirks/30-vendor-madcatz.quirks000066400000000000000000000036401477265155700213730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # The Madcatz RAT3 has a mode button that cycles through event codes. # On press, we get a release for the current mode and a press for the # next mode: # -event21 DEVICE_ADDED Madcatz Mad Catz R.A.T.3 Mouse seat0 default group1 cap:p left scroll-nat scroll-button # event21 POINTER_BUTTON +2.35s BTN_BACK (278) pressed, seat count: 1 # event21 POINTER_BUTTON +3.08s BTN_BACK (278) released, seat count: 0 # event21 POINTER_BUTTON +3.08s BTN_TASK (279) pressed, seat count: 1 # event21 POINTER_BUTTON +6.69s BTN_FORWARD (277) pressed, seat count: 1 # event21 POINTER_BUTTON +6.69s BTN_TASK (279) released, seat count: 0 # event21 POINTER_BUTTON +7.32s BTN_FORWARD (277) released, seat count: 0 # event21 POINTER_BUTTON +7.32s BTN_BACK (278) pressed, seat count: 1 # event21 POINTER_BUTTON +7.84s BTN_BACK (278) released, seat count: 0 # event21 POINTER_BUTTON +7.84s BTN_TASK (279) pressed, seat count: 1 # # Disable the event codes to avoid stuck buttons. [Madcatz RAT3] MatchUdevType=mouse MatchBus=usb MatchVendor=0x0738 MatchProduct=0x1703 # EV_KEY 0x115, 0x116, 0x117 AttrEventCode=-EV_KEY:0x115;-EV_KEY:0x116;-EV_KEY:0x117 # Like the Madcatz RAT3, but with different codes: # event8 POINTER_BUTTON +0.488s ??? (280) pressed, seat count: 1 # event8 POINTER_BUTTON +1.275s ??? (280) released, seat count: 0 # event8 POINTER_BUTTON +1.275s ??? (281) pressed, seat count: 1 # event8 POINTER_BUTTON +3.585s ??? (281) released, seat count: 0 # event8 POINTER_BUTTON +3.585s ??? (282) pressed, seat count: 1 # event8 POINTER_BUTTON +4.184s ??? (280) pressed, seat count: 1 # event8 POINTER_BUTTON +4.184s ??? (282) released, seat count: 0 [Madcatz RAT7] MatchUdevType=mouse MatchBus=usb MatchVendor=0x0738 MatchProduct=0x1708 # EV_KEY 0x118, 0x119, 0x11A AttrEventCode=-EV_KEY:0x118;-EV_KEY:0x119;-EV_KEY:0x11A libinput-1.28.1/quirks/30-vendor-microsoft.quirks000066400000000000000000000022671477265155700217610ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Microsoft Surface 3 Lid Switch] MatchName=*Lid Switch* MatchDMIModalias=dmi:*svnMicrosoftCorporation:pnSurface3:* AttrLidSwitchReliability=write_open # Matches both Surface Laptop keyboards as well as type covers. # i.e. # - Surface 3: Microsoft Surface 3 Type Cover Keyboard # - Surface Laptop 3: Microsoft Surface 045E:09AE Keyboard # - Surface Book 2: Microsoft Surface Keyboard [Microsoft Surface Keyboard] MatchName=*Microsoft Surface *Keyboard* MatchDMIModalias=dmi:*svnMicrosoftCorporation:* AttrKeyboardIntegration=internal [Microsoft Surface Cover] MatchName=*Microsoft Surface *Cover* MatchDMIModalias=dmi:*svnMicrosoftCorporation:* AttrKeyboardIntegration=internal [Microsoft Surface Laptop Studio Touchpad] MatchVendor=0x045E MatchProduct=0x09AF MatchUdevType=touchpad AttrPressureRange=25:10 AttrPalmPressureThreshold=500 [Microsoft Surface Laptop Studio Built-In Peripherals] MatchName=*Microsoft Surface* MatchDMIModalias=dmi:*svnMicrosoftCorporation:*pnSurfaceLaptopStudio ModelTabletModeNoSuspend=1 [Microsoft Nano Transceiver v2.0] MatchUdevType=mouse MatchBus=usb MatchVendor=0x045E MatchProduct=0x0800 ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-oracle.quirks000066400000000000000000000001341477265155700212100ustar00rootroot00000000000000[VirtualBox mouse integration] MatchName=*VirtualBox mouse integration* ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-qemu.quirks000066400000000000000000000001221477265155700207070ustar00rootroot00000000000000[QEMU/KVM mouse integration] MatchName=*spice vdagent tablet* ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-razer.quirks000066400000000000000000000141431477265155700210730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Razer Blade Lid Switch] MatchName=*Lid Switch* MatchDMIModalias=dmi:*svnRazer:pnBlade* AttrLidSwitchReliability=write_open # Manually added entries must go above this line. # Entries below this line are autogenerated # AUTOGENERATED [RazerBladeStealth Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0205 AttrKeyboardIntegration=internal [RazerBladeQHD Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x020F AttrKeyboardIntegration=internal [RazerBladeProLate2016 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0210 AttrKeyboardIntegration=internal [RazerBladeStealthLate2016 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0220 AttrKeyboardIntegration=internal [RazerBladeLate2016 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0224 AttrKeyboardIntegration=internal [RazerBladePro2017 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0225 AttrKeyboardIntegration=internal [RazerBladeStealthMid2017 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x022D AttrKeyboardIntegration=internal [RazerBladePro2017FullHD Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x022F AttrKeyboardIntegration=internal [RazerBladeStealthLate2017 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0232 AttrKeyboardIntegration=internal [RazerBlade2018 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0233 AttrKeyboardIntegration=internal [RazerBladePro2019 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0234 AttrKeyboardIntegration=internal [RazerBladeStealth2019 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0239 AttrKeyboardIntegration=internal [RazerBlade2019Adv Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x023A AttrKeyboardIntegration=internal [RazerBlade2018Base Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x023B AttrKeyboardIntegration=internal [RazerBlade2018Mercury Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0240 AttrKeyboardIntegration=internal [RazerBladeMid2019Mercury Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0245 AttrKeyboardIntegration=internal [RazerBlade2019Base Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0246 AttrKeyboardIntegration=internal [RazerBladeStealthLate2019 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x024A AttrKeyboardIntegration=internal [RazerBladeAdvancedLate2019 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x024B AttrKeyboardIntegration=internal [RazerBladeProLate2019 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x024C AttrKeyboardIntegration=internal [RazerBlade2019StudioEdition Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x024D AttrKeyboardIntegration=internal [RazerBladeStealthEarly2020 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0252 AttrKeyboardIntegration=internal [RazerBlade15Advanced2020 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0253 AttrKeyboardIntegration=internal [RazerBladeEarly2020Base Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0255 AttrKeyboardIntegration=internal [RazerBladeProEarly2020 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0256 AttrKeyboardIntegration=internal [RazerBladeStealthLate2020 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0259 AttrKeyboardIntegration=internal [RazerBlade15AdvancedEarly2021 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x026D AttrKeyboardIntegration=internal [RazerBlade17ProEarly2021 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x026E AttrKeyboardIntegration=internal [RazerBladeEarly2021Base Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x026F AttrKeyboardIntegration=internal [RazerBlade142021 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0270 AttrKeyboardIntegration=internal [RazerBlade15Advanced2021 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0276 AttrKeyboardIntegration=internal [RazerBlade17Pro2021 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x0279 AttrKeyboardIntegration=internal [RazerBladeEarly2022Base Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x027A AttrKeyboardIntegration=internal [RazerBlade15AdvancedEarly2022 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x028A AttrKeyboardIntegration=internal [RazerBlade172022 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x028B AttrKeyboardIntegration=internal [RazerBlade142022 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x028C AttrKeyboardIntegration=internal [RazerBlade142023 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x029D AttrKeyboardIntegration=internal [RazerBlade152023 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x029E AttrKeyboardIntegration=internal [RazerBlade162023 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x029F AttrKeyboardIntegration=internal [RazerBlade182023 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x02A0 AttrKeyboardIntegration=internal [RazerBlade142024 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x02B6 AttrKeyboardIntegration=internal [RazerBlade182024 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x1532 MatchProduct=0x02B8 AttrKeyboardIntegration=internal libinput-1.28.1/quirks/30-vendor-synaptics.quirks000066400000000000000000000007761477265155700217740ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Synaptics Serial Touchpads] MatchUdevType=touchpad MatchBus=ps2 MatchVendor=0x0002 MatchProduct=0x0007 ModelSynapticsSerialTouchpad=1 # SYNA3602:00 0911:5288 touchpad, clickpad pretending it has a right button. # Integrated into several systems, including # Purism Librem 14v1 # Prestigio Smartbook 141 C2 # StarLite Mk II # Iota IOTA2320 [Synaptics 0911:5288 Touchpad] MatchUdevType=touchpad MatchName=* 0911:5288 Touchpad AttrEventCode=-BTN_RIGHT libinput-1.28.1/quirks/30-vendor-trust.quirks000066400000000000000000000001701477265155700211240ustar00rootroot00000000000000[Trust GXT 25 Gaming Mouse] MatchUdevType=mouse MatchBus=usb MatchVendor=0x1D57 MatchProduct=0xAD03 ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-uniwill.quirks000066400000000000000000000003251477265155700214300ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # Tested on PCSpecialist Recoil 17 [Uniwill Touchpad] MatchUdevType=touchpad MatchBus=i2c MatchVendor=0x093A MatchProduct=0x0274 AttrEventCode=-BTN_RIGHT libinput-1.28.1/quirks/30-vendor-vmware.quirks000066400000000000000000000003651477265155700212520ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [VMWare Virtual PS/2 Mouse] MatchName=*VirtualPS/2 VMware VMMouse* ModelBouncingKeys=1 [VMware VMware Virtual USB Mouse] MatchName=*VMware VMware Virtual USB Mouse* ModelBouncingKeys=1 libinput-1.28.1/quirks/30-vendor-wacom.quirks000066400000000000000000000014511477265155700210540ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Wacom Touchpads] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x056A ModelWacomTouchpad=1 [Wacom Bamboo Fun Pen] MatchUdevType=tablet MatchBus=usb MatchVendor=0x056A MatchProduct=0x0018 AttrEventCode=-ABS_DISTANCE [Wacom Bamboo 2FG 6x8] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x056A MatchProduct=0x00D3 AttrInputProp=+INPUT_PROP_SEMI_MT [Wacom Intuos Pro PTH660] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x056A MatchProduct=0x0357 AttrPalmSizeThreshold=5 [Wacom ISDV4 4200 Pen] MatchUdevType=tablet MatchBus=usb MatchVendor=0x056A MatchProduct=0x4200 AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y; [Wacom ISDV4 524c Pen] MatchUdevType=tablet MatchBus=usb MatchVendor=0x2D1F MatchProduct=0x524C AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y; libinput-1.28.1/quirks/50-system-acer.quirks000066400000000000000000000004121477265155700207050ustar00rootroot00000000000000[Acer Switch Alpha 12] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnAcer:pnSwitchSA5-271:* ModelTabletModeNoSuspend=1 [Acer Spin 5] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnAcer:pnSpinSP513-52N:* ModelTabletModeNoSuspend=1 libinput-1.28.1/quirks/50-system-apple.quirks000066400000000000000000000071651477265155700211100ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Apple Touchpads USB] MatchVendor=0x05AC MatchBus=usb MatchUdevType=touchpad ModelAppleTouchpad=1 AttrSizeHint=104x75 AttrTouchSizeRange=150:130 AttrPalmSizeThreshold=1600 [Apple Touchpads Bluetooth] MatchVendor=0x05AC MatchBus=bluetooth MatchUdevType=touchpad ModelAppleTouchpad=1 AttrTouchSizeRange=150:130 [Apple Touchpads Bluetooth (new vendor ID)] MatchVendor=0x004C MatchBus=bluetooth MatchUdevType=touchpad ModelAppleTouchpad=1 AttrTouchSizeRange=150:130 [Apple Internal Keyboard] MatchName=*Apple Inc. Apple Internal Keyboard* AttrKeyboardIntegration=internal [Apple Internal Keyboard (SPI)] MatchUdevType=keyboard MatchBus=spi MatchVendor=0x05AC AttrKeyboardIntegration=internal # The Apple MagicMouse has a touchpad built-in but the kernel still # emulates a full 2/3 button mouse for us. Ignore anything from the # ABS interface [Apple MagicMouse] MatchUdevType=mouse MatchBus=bluetooth MatchVendor=0x05AC MatchProduct=0x030D AttrEventCode=-EV_ABS # The External Apple "Magic" trackpads, both the 1st and 2nd generations, have # pretty good built-in spurious touch filtering in the device firmware. Using # low enough values such as 20:10 effectively disables libinput's filtering. [Apple Magic Trackpad v1 (2010, clickpad)] MatchUdevType=touchpad MatchBus=bluetooth MatchVendor=0x05AC MatchProduct=0x030E AttrSizeHint=130x110 AttrTouchSizeRange=20:10 AttrPalmSizeThreshold=900 AttrThumbSizeThreshold=700 # 2nd generation trackpad can be connected over Bluetooth as well as USB. [Apple Magic Trackpad v2 (2015)] MatchVendor=0x05AC MatchProduct=0x0265 AttrSizeHint=162x115 AttrTouchSizeRange=20:10 AttrPalmSizeThreshold=900 AttrThumbSizeThreshold=800 AttrPalmPressureThreshold=190 [Apple Magic Trackpad v2 (new vendor ID)] MatchVendor=0x004C MatchProduct=0x0265 AttrSizeHint=162x115 AttrTouchSizeRange=20:10 AttrPalmSizeThreshold=900 AttrThumbSizeThreshold=800 AttrPalmPressureThreshold=190 [Apple Magic Trackpad v2 Bluetooth (2024)] MatchVendor=0x004C MatchProduct=0x0324 AttrSizeHint=162x115 AttrTouchSizeRange=20:10 AttrPressureRange=3:0 AttrPalmSizeThreshold=900 AttrThumbSizeThreshold=700 [Apple Magic Trackpad v2 USB-C (2024)] MatchBus=usb MatchVendor=0x05AC MatchProduct=0x0324 AttrTouchSizeRange=20:10 AttrPressureRange=3:0 AttrPalmSizeThreshold=900 AttrThumbSizeThreshold=700 [Apple Touchpad OneButton] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x05AC MatchProduct=0x021A ModelAppleTouchpadOneButton=1 [Apple Touchpad OneButton A1181] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x05AC MatchProduct=0x022A ModelAppleTouchpadOneButton=1 [Apple Touchpad MacbookPro5,5] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x05AC MatchProduct=0x0237 AttrPalmSizeThreshold=1000 [Apple Laptop Touchpad (MacBookPro11,2 among others)] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x05AC MatchProduct=0x0262 AttrPalmSizeThreshold=1600 [Apple Laptop Touchpad (SPI)] MatchUdevType=touchpad MatchBus=spi MatchVendor=0x05AC ModelAppleTouchpad=1 AttrSizeHint=104x75 AttrTouchSizeRange=150:130 AttrPalmSizeThreshold=1600 [Apple Laptop Touchpad (MTP)] MatchUdevType=touchpad MatchName=Apple*MTP* MatchVendor=0x05AC ModelAppleTouchpad=1 AttrSizeHint=104x75 AttrTouchSizeRange=150:130 AttrPalmSizeThreshold=1600 [Apple Laptop Keyboard (MTP)] MatchUdevType=keyboard MatchName=Apple*MTP* MatchVendor=0x05AC AttrKeyboardIntegration=internal # The Linux applespi driver currently uses the Synaptics vendor for some reason [Apple Laptop Touchpad (SPI) applespi driver] MatchUdevType=touchpad MatchBus=spi MatchVendor=0x06CB ModelAppleTouchpad=1 AttrSizeHint=104x75 AttrTouchSizeRange=150:130 AttrPalmSizeThreshold=1600 libinput-1.28.1/quirks/50-system-asus.quirks000066400000000000000000000027771477265155700207660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Asus X555LAB] MatchName=*ETPS/2 Elantech Touchpad* MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnX555LAB:* ModelTouchpadVisibleMarker=1 [Asus UX21E] MatchName=*ETPS/2 Elantech Touchpad* MatchDMIModalias=dmi:*svnASUSTeKComputerInc.:pnUX21E:* AttrPressureRange=24:10 # Asus UX302LA touchpad doesn't update the pressure values once two # fingers are down. So let's just pretend it doesn't have pressure # at all. https://gitlab.freedesktop.org/libinput/libinput/issues/145 [Asus UX302LA] MatchName=*ETPS/2 Elantech Touchpad* MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnUX302LA:* AttrEventCode=-ABS_MT_PRESSURE;-ABS_PRESSURE; # Asus VivoBook Flip 14 TP412UA tablet switch seems misbehaving, always # indicating tablet position [Asus TP412UA Tablet Mode Switch] MatchName=*Intel Virtual Button* MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnVivoBookFlip14_ASUSFlipTP412UA:* ModelTabletModeSwitchUnreliable=1 # keyboard has a different vid/pid to the touchpad # so libinput won't pair the two together and dwt isn't active. # see: https://gitlab.freedesktop.org/libinput/libinput/-/issues/615 [Asus ROG Zephyrus G15 2021 keyboard] MatchVendor=0x0B05 MatchProduct=0x19B6 MatchUdevType=keyboard AttrKeyboardIntegration=internal # keyboard has a different vid/pid to the touchpad # so libinput won't pair the two together and dwt isn't active. [Asus ROG Strix G15 2021 keyboard] MatchVendor=0x0B05 MatchProduct=0x1866 MatchUdevType=keyboard AttrKeyboardIntegration=internal libinput-1.28.1/quirks/50-system-chicony.quirks000066400000000000000000000006511477265155700214340ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # Acer Hawaii Keyboard, uses Chicony VID [Acer Hawaii Keyboard] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x04F2 MatchProduct=0x1558 AttrTPKComboLayout=below # Lenovo MIIX 720 comes with a detachable touchpad-keyboard combo [Chicony Lenovo MIIX 720 Touchpad] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x17EF MatchProduct=0x60A6 AttrTPKComboLayout=below libinput-1.28.1/quirks/50-system-chuwi.quirks000066400000000000000000000003321477265155700211130ustar00rootroot00000000000000[Chuwi Gemibook] MatchName=HTIX5288:00 093A:1336 Touchpad MatchUdevType=touchpad AttrEventCode=-BTN_RIGHT [Chuwi AeroBook Plus] MatchName=SYNA3602:01 093A:1336 Touchpad MatchUdevType=touchpad AttrEventCode=-BTN_RIGHT libinput-1.28.1/quirks/50-system-cyborg.quirks000066400000000000000000000027621477265155700212720ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # The Cyborg RAT has a mode button that cycles through event codes. # On press, we get a release for the current mode and a press for the # next mode: # E: 0.000001 0004 0004 589833 # EV_MSC / MSC_SCAN 589833 # E: 0.000001 0001 0118 0000 # EV_KEY / (null) 0 # E: 0.000001 0004 0004 589834 # EV_MSC / MSC_SCAN 589834 # E: 0.000001 0001 0119 0001 # EV_KEY / (null) 1 # E: 0.000001 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +0ms # E: 0.705000 0004 0004 589834 # EV_MSC / MSC_SCAN 589834 # E: 0.705000 0001 0119 0000 # EV_KEY / (null) 0 # E: 0.705000 0004 0004 589835 # EV_MSC / MSC_SCAN 589835 # E: 0.705000 0001 011a 0001 # EV_KEY / (null) 1 # E: 0.705000 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +705ms # E: 1.496995 0004 0004 589833 # EV_MSC / MSC_SCAN 589833 # E: 1.496995 0001 0118 0001 # EV_KEY / (null) 1 # E: 1.496995 0004 0004 589835 # EV_MSC / MSC_SCAN 589835 # E: 1.496995 0001 011a 0000 # EV_KEY / (null) 0 # E: 1.496995 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +791ms # # https://bugs.freedesktop.org/show_bug.cgi?id=92127 # # Disable the event codes to avoid stuck buttons. [Saitek Cyborg RAT5] MatchUdevType=mouse MatchBus=usb MatchVendor=0x06A3 MatchProduct=0x0CD5 # EV_KEY 0x118, 0x119, 0x11a AttrEventCode=-EV_KEY:0x118;-EV_KEY:0x119;-EV_KEY:0x11a libinput-1.28.1/quirks/50-system-dell.quirks000066400000000000000000000100271477265155700207160ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Dell Touchpads] MatchName=* Touchpad MatchDMIModalias=dmi:*svnDellInc.:* ModelTouchpadVisibleMarker=1 [Dell i2c Touchpads] MatchBus=i2c MatchUdevType=touchpad MatchDMIModalias=dmi:*svnDellInc.:* AttrMscTimestamp=watch [Dell Inspiron 15R N5110 Touchpad] MatchUdevType=touchpad MatchName=*AlpsPS/2 ALPS GlidePoint MatchVersion=0x0300 MatchDMIModalias=dmi:*svnDellInc.:*pnInspironN5110* AttrPressureRange=100:95 [Dell Latitude E5510 Touchpad] MatchUdevType=touchpad MatchName=*AlpsPS/2 ALPS GlidePoint MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE5510:* AttrPressureRange=100:90 [Dell Latitude E6220 Touchpad] MatchName=*AlpsPS/2 ALPS GlidePoint MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6220:* AttrPressureRange=100:90 [Dell XPS L322X Touchpad] MatchName=*CyPS/2 Cypress Trackpad MatchDMIModalias=dmi:*svnDell*:*XPSL322X* AttrPressureRange=30:20 AttrPalmPressureThreshold=254 [Dell XPS13 9333 Touchpad] MatchName=*Synaptics s3203 MatchDMIModalias=dmi:*svnDellInc.:*pnXPS139333* AttrPressureRange=15:10 AttrPalmPressureThreshold=150 [Dell XPS 15 9500 Touchpad] MatchName=* Touchpad MatchDMIModalias=dmi:*svnDellInc.:pnXPS159500:* ModelTouchpadVisibleMarker=0 ModelTouchpadPhantomClicks=1 [Dell Latitude D620 Trackpoint] MatchName=*DualPoint Stick MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeD620* AttrTrackpointMultiplier=0.5 [Latitude E5480 Trackpoint] MatchName=*DualPoint Stick MatchUdevType=pointingstick MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude5480* AttrTrackpointMultiplier=0.5 [Latitude 5580 Trackpoint] MatchName=*DualPoint Stick MatchUdevType=pointingstick MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude5580* AttrTrackpointMultiplier=0.5 [Latitude E5570 Trackpoint] MatchName=*DualPoint Stick MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE5570* AttrTrackpointMultiplier=0.1 [Latitude E6320 Trackpoint] MatchName=*DualPoint Stick MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6320* AttrTrackpointMultiplier=2.0 [Latitude E6400 Trackpoint] MatchName=*DualPoint Stick MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6400* AttrTrackpointMultiplier=1.5 [Latitude E7470 Trackpoint] MatchName=*DualPoint Stick MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE7470* AttrTrackpointMultiplier=0.125 [Latitude 7275] MatchName=*AT Translated Set 2 keyboard* MatchDMIModalias=dmi:*:svnDellInc.:pnLatitude7275:* ModelTabletModeNoSuspend=1 [Latitude 7480 Touchpad] MatchName=DLL07A0* MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude7480* AttrPressureRange=35:34 [Latitude 7490 Trackpoint] MatchName=*Mouse MatchUdevType=pointingstick MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude7490* AttrTrackpointMultiplier=0.3 [Precision 7x50 Touchpad] MatchBus=i2c MatchUdevType=touchpad MatchDMIModalias=dmi:*svnDellInc.:pnPrecision7?50* AttrInputProp=-INPUT_PROP_BUTTONPAD # The touch device has the same vid/pid as the totem, the MatchName # directive is required here [Canvas Totem] MatchName=*System Multi Axis MatchBus=usb MatchVendor=0x2575 MatchProduct=0x0204 ModelDellCanvasTotem=1 [Dell 2-in-1 Models] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*:svnDellInc.:pn*2-in-1:* ModelTabletModeNoSuspend=1 # This is a true pressurepad so disable pressure for contact size # https://gitlab.freedesktop.org/libinput/libinput/-/issues/849 [Dell Precision5680 Touchpad] MatchBus=i2c MatchVendor=0x27C6 MatchProduct=0x0F60 ModelPressurePad=1 [Dell Mayabay Touchpad] MatchBus=i2c MatchVendor=0x06CB MatchProduct=0xCFA0 ModelPressurePad=1 [Dell Precision 5480] MatchBus=i2c MatchVendor=0x0488 MatchProduct=0x1063 MatchUdevType=touchpad MatchDMIModalias=dmi:*svnDellInc.:pnPrecision5480* ModelTouchpadVisibleMarker=0 [Dell laptop 14 Synaptics touchpad] MatchBus=i2c MatchVendor=0x06CB MatchProduct=0xCFF8 ModelPressurePad=1 [Dell laptop 16 Synaptics touchpad] MatchBus=i2c MatchVendor=0x06CB MatchProduct=0xCFF9 ModelPressurePad=1 [Dell laptop 14 Goodix touchpad] MatchBus=i2c MatchVendor=0x27C6 MatchProduct=0x0F61 ModelPressurePad=1 [Dell laptop 16 Goodix touchpad] MatchBus=i2c MatchVendor=0x27C6 MatchProduct=0x0F62 ModelPressurePad=1 libinput-1.28.1/quirks/50-system-framework.quirks000066400000000000000000000005371477265155700220000ustar00rootroot00000000000000[Framework Laptop Touchpad] MatchName=PIXA3854:00 093A:0274 Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnFramework:pnLaptop* AttrEventCode=-BTN_RIGHT [Framework Laptop 16 Keyboard Module] MatchName=Framework Laptop 16 Keyboard Module* MatchUdevType=keyboard MatchDMIModalias=dmi:*svnFramework:pnLaptop16* AttrKeyboardIntegration=internal libinput-1.28.1/quirks/50-system-gigabyte.quirks000066400000000000000000000002371477265155700215730ustar00rootroot00000000000000[Gigabyte Aero 15 touchpad] MatchUdevType=touchpad MatchName=ETPS/2 Elantech Touchpad MatchDMIModalias=dmi:*svnGIGABYTE:pnAERO15-XA* AttrPalmSizeThreshold=800 libinput-1.28.1/quirks/50-system-google.quirks000066400000000000000000000101761477265155700212570ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Generic Google ARM device with Touchpad] MatchName=*Elan Touchpad* MatchDeviceTree=*google* ModelChromebook=1 [Google Chromebook R13 CB5-312T] MatchName=*Elan Touchpad* MatchDeviceTree=*Chromebook R13 CB5-312T* AttrPressureRange=6:4 [Google Chromebook CB5-312T] MatchName=*Elan Touchpad* MatchDeviceTree=*CB5-312T* AttrPressureRange=6:4 [Google Chromebook Elm] MatchName=*Elan Touchpad* MatchDeviceTree=*Elm* AttrPressureRange=6:4 [Google Chromebook Falco] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*pn*Falco* ModelChromebook=1 [Google Chromebook Mario] MatchUdevType=touchpad MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*pn*Mario* ModelChromebook=1 [Google Chromebook Butterfly] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*pn*Butterfly* ModelChromebook=1 [Google Chromebook Peppy] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*pn*Peppy* ModelChromebook=1 [Google Chromebook ZGB] MatchUdevType=touchpad MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*pn*ZGB* ModelChromebook=1 [Google Chromebook Parrot] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*pn*Parrot* ModelChromebook=1 [Google Chromebook Leon] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*bvn*coreboot*:pn*Leon* ModelChromebook=1 [Google Chromebook Wolf] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*bvn*coreboot*:pn*Wolf* ModelChromebook=1 [Google Chromebook Link] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*svn*GOOGLE*:pn*Link* ModelChromebook=1 [Google Chromebook Alex] MatchUdevType=touchpad MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*pn*Alex* ModelChromebook=1 [Google Chromebook Lumpy] MatchUdevType=touchpad MatchName=Cypress APA Trackpad ?cyapa? MatchDMIModalias=dmi:*svn*SAMSUNG*:pn*Lumpy* ModelChromebook=1 [Google Chromebook Samus] MatchUdevType=touchpad MatchName=Atmel maXTouch Touchpad MatchDMIModalias=dmi:*svn*GOOGLE*:pn*Samus* ModelChromebook=1 [Google Chromebook Eve] MatchUdevType=touchpad MatchName=ACPI0C50:00 18D1:5028* MatchDMIModalias=dmi:*svnGoogle:pnEve* ModelChromebook=1 AttrPressureRange=6:4 AttrThumbPressureThreshold=45 [Google Chromebook Atlas] MatchUdevType=touchpad MatchName=ACPI0C50:01 04F3:30C5 Touchpad MatchDMIModalias=dmi:*svnGoogle:*pnAtlas* ModelChromebook=1 AttrPressureRange=6:4 [Google Chromebook Lazor Keyboard] MatchName=*cros_ec* MatchDeviceTree=*lazor* AttrKeyboardIntegration=internal [Google Chromebook Redrix] MatchUdevType=touchpad MatchName=ELAN2703:00 04F3:323B Touchpad MatchDMIModalias=dmi:*pn*Redrix* ModelChromebook=1 AttrPressureRange=-0:-2 AttrThumbPressureThreshold=45 AttrPalmPressureThreshold=0 [Google Chromebook Drobit] MatchUdevType=touchpad MatchName=ELAN2701:00 04F3:31C6 Touchpad MatchDMIModalias=dmi:*svnGoogle:*pnDrobit* ModelChromebook=1 AttrPressureRange=6:4 [HP Dragonfly Pro Chromebook] MatchName=*ELAN2703* MatchDMIModalias=dmi:*pn*Vell* ModelChromebook=1 AttrPressureRange=1:0 AttrThumbPressureThreshold=25 AttrPalmPressureThreshold=0 [Google Chromebook Krane] MatchUdevType=touchpad MatchName=Google Inc. Hammer MatchBus=usb MatchVendor=0x18D1 MatchDeviceTree=*krane* ModelChromebook=1 AttrPressureRange=20:10 [Google Chromebook Wormdingler] MatchUdevType=touchpad MatchName=Google Inc. Hammer MatchBus=usb MatchVendor=0x18D1 MatchDeviceTree=*wormdingler* ModelChromebook=1 AttrPressureRange=20:10 [Google Chromebook Coachz] MatchUdevType=touchpad MatchName=Google Inc. Hammer MatchBus=usb MatchVendor=0x18D1 MatchDeviceTree=*coachz* ModelChromebook=1 AttrPressureRange=20:10 [Google Chromebook Cret] MatchUdevType=touchpad MatchName=GDIX0000:00 27C6:0D55 Touchpad MatchDMIModalias=dmi:*svnGoogle:*pnCret* ModelChromebook=1 AttrPressureRange=6:4 [Google Chromebook Banshee] MatchUdevType=touchpad MatchName=PNP0C50:00 093A:0274 Touchpad MatchDMIModalias=dmi:*svnGoogle:*pnBanshee* ModelChromebook=1 AttrPressureRange=0:-2 AttrThumbPressureThreshold=45 AttrPalmPressureThreshold=0 libinput-1.28.1/quirks/50-system-gpd.quirks000066400000000000000000000002361477265155700205510ustar00rootroot00000000000000[GPD Win Max - All versions] MatchName=HTIX5288:00 093A:0255 Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnGPD:*pnG1619-* AttrEventCode=-BTN_RIGHT libinput-1.28.1/quirks/50-system-graviton.quirks000066400000000000000000000007721477265155700216350ustar00rootroot00000000000000# Touchpad is not a clickpad but INPUT_PROP_BUTTONPAD is set [Synaptics ALPS0001:00 0911:5288 Touchpad] MatchUdevType=touchpad MatchName=ALPS0001:00 0911:5288 Touchpad MatchDMIModalias=dmi:*svn3LogicGroup:*:pnGravitonN15i-K2*:* AttrInputProp=-INPUT_PROP_BUTTONPAD AttrEventCode=+BTN_RIGHT [PCTel PCT2342:00 0911:5288 Touchpad] MatchUdevType=touchpad MatchName=PCT2342:00 0911:5288 Touchpad MatchDMIModalias=dmi:*svn3LogicGroup:pnGravitonN15i:* AttrInputProp=-INPUT_PROP_BUTTONPAD AttrEventCode=+BTN_RIGHT libinput-1.28.1/quirks/50-system-honor.quirks000066400000000000000000000003361477265155700211250ustar00rootroot00000000000000# Clickpad that announces BTN_RIGHT # requires ModelPressurePad=1 [HONOR MagicBook Art 14] MatchName=*TOPS0102* MatchDMIModalias=dmi:*svnHONOR:*pnMRA-XXX* MatchUdevType=touchpad AttrEventCode=-BTN_RIGHT ModelPressurePad=1 libinput-1.28.1/quirks/50-system-hp.quirks000066400000000000000000000066271477265155700204200ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # # Claims to have double/tripletap but doesn't actually send it # https://bugs.freedesktop.org/show_bug.cgi?id=98538 [HP Compaq 6910p] MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPCompaq6910p* AttrEventCode=-BTN_TOOL_DOUBLETAP;-BTN_TOOL_TRIPLETAP; # Claims to have double/tripletap but doesn't actually send it # https://bugzilla.redhat.com/show_bug.cgi?id=1351285 and [HP Compaq 8510w] MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPCompaq8510w* AttrEventCode=-BTN_TOOL_DOUBLETAP;-BTN_TOOL_TRIPLETAP; [HP Pavilion dmi4] MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPPaviliondm4NotebookPC* ModelHPPavilionDM4Touchpad=1 # Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see # https://bugs.freedesktop.org/show_bug.cgi?id=97147 [HP Stream 11] MatchName=SYN1EDE:00 06CB:7442* MatchDMIModalias=dmi:*svnHewlett-Packard:pnHPStreamNotebookPC11* AttrInputProp=+INPUT_PROP_BUTTONPAD # The HP stream x360's embedded-controller filters out events form its builtin # keyboard when in tablet-mode itself; and it has a capacitive home-button # (windows logo) underneath its display which also sends PS/2 key-events. # Do not suspend the keyboard when in tablet-mode so that the home button # keeps working when in tablet-mode. [HP Stream x360 11] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*:svnHewlett-Packard:pnHPStreamx360ConvertiblePC11:* ModelTabletModeNoSuspend=1 [HP Spectre x360 Convertible 15-bl000] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*:svnHP:pnHPSpectrex360Convertible15-bl0XX:* ModelTabletModeNoSuspend=1 [HP ZBook Studio G3] MatchName=AlpsPS/2 ALPS GlidePoint MatchDMIModalias=dmi:*svnHP:pnHPZBookStudioG3:* ModelHPZBookStudioG3=1 [HP Chromebook 14] MatchName=*Cypress APA Trackpad *cyapa* MatchDMIModalias=dmi:*svnHewlett-Packard*:pnFalco* AttrPressureRange=12:8 [HP Spectre x360 Convertible 15-bl1xx] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-bl1XX:* AttrPressureRange=55:40 AttrThumbPressureThreshold=90 AttrPalmPressureThreshold=100 [HP Spectre x360 Convertible 15-ch0xx] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-ch0xx:* AttrThumbPressureThreshold=90 AttrPalmPressureThreshold=100 # The HP stream x360's embedded-controller filters out events form its builtin # keyboard when in tablet-mode itself; and it has a volume up/down on the side. # Do not suspend the keyboard when in tablet-mode so that the volume up/down # button keeps working when in tablet-mode. [HP Spectre x360 Convertible 15-ch0xx Tablet Mode Switch] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-ch0xx:* ModelTabletModeNoSuspend=1 [HP Elite x2 1013 G3 Tablet Mode Switch] MatchName=*Intel Virtual Button* MatchDMIModalias=dmi:*svnHP:pnHPElitex21013G3:* ModelTabletModeSwitchUnreliable=1 [HP Elite x2 1013 G3 Touchpad] MatchUdevType=touchpad MatchBus=usb MatchVendor=0x044E MatchProduct=0x1221 AttrTPKComboLayout=below [HP Elite x2 1013 G3 Keyboard] MatchUdevType=keyboard MatchBus=ps2 MatchDMIModalias=dmi:*svnHP:pnHPElitex21013G3:* AttrKeyboardIntegration=external [HP Haptics Touchpad CFD2] MatchBus=i2c MatchVendor=0x06CB MatchProduct=0xCFD2 ModelPressurePad=1 libinput-1.28.1/quirks/50-system-huawei.quirks000066400000000000000000000012221477265155700212550ustar00rootroot00000000000000# Clickpad that announces BTN_RIGHT # https://bugzilla.redhat.com/show_bug.cgi?id=1972370 [Huawei MateBook 2020 Touchpad] MatchName=ELAN2604:00 04F3:3114 Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnHUAWEI:*pvrM1010* AttrEventCode=-BTN_RIGHT [Huawei MateBook X Pro 2022 Touchpad] MatchName=GXTP7863:00 27C6:01E0 Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnHUAWEI:*pnMRGF-XX* AttrEventCode=-BTN_RIGHT # 2024 model requires ModelPressurePad=1 [Huawei MateBook X Pro 2024 Touchpad] MatchName=GXTP7863:00 27C6:01E0 Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnHUAWEI:*pnVGHH-XX* AttrEventCode=-BTN_RIGHT ModelPressurePad=1 libinput-1.28.1/quirks/50-system-icl.quirks000066400000000000000000000004241477265155700205450ustar00rootroot00000000000000# Touchpad is not a clickpad but INPUT_PROP_BUTTONPAD is set [Synaptics ALPS0001:00 0911:5288 Touchpad] MatchUdevType=touchpad MatchName=ALPS0001:00 0911:5288 Touchpad MatchDMIModalias=dmi:*svnICL:*:rvnICL:rnSi16:* AttrInputProp=-INPUT_PROP_BUTTONPAD AttrEventCode=+BTN_RIGHT libinput-1.28.1/quirks/50-system-lenovo.quirks000066400000000000000000000302621477265155700213030ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Lenovo Thinkpad Touchpad] MatchName=*Synaptics* MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad*:* AttrThumbPressureThreshold=100 [Lenovo x230 Touchpad] MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230* ModelLenovoX230=1 [Lenovo T440p Touchpad PS/2] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT440p* ModelLenovoT450Touchpad=1 [Lenovo T440p Touchpad RMI4] MatchName=Synaptics tm2964-001 MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT440p* ModelLenovoT450Touchpad=1 [Lenovo T470 Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT470:* AttrTrackpointMultiplier=0.75 [Lenovo T480 Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480:* AttrTrackpointMultiplier=0.75 [Lenovo A485 Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadA485:* AttrTrackpointMultiplier=0.75 # Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see # https://gitlab.freedesktop.org/libinput/libinput/issues/177 [Lenovo T480s Touchpad] MatchName=Elan Touchpad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480s* AttrInputProp=+INPUT_PROP_BUTTONPAD # Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see # https://gitlab.freedesktop.org/libinput/libinput/issues/177 [Lenovo T490s Touchpad] MatchName=Elan Touchpad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s* AttrInputProp=+INPUT_PROP_BUTTONPAD [Lenovo T490s Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s:* AttrTrackpointMultiplier=0.4 [Lenovo P14s Gen 1 AMD Trackpoint] MatchUdevType=pointingstick MatchName=*TPPS/2 Elan TrackPoint* MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadP14sGen1* AttrTrackpointMultiplier=0.4 # Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see # https://gitlab.freedesktop.org/libinput/libinput/issues/234 [Lenovo L380 Touchpad] MatchName=Elan Touchpad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadL380* AttrInputProp=+INPUT_PROP_BUTTONPAD [Lenovo X200/201 Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20?:* AttrTrackpointMultiplier=0.25 [Lenovo X200s/201s Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20??:* AttrTrackpointMultiplier=0.25 [Lenovo X230 Trackpoint] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX230:* AttrTrackpointMultiplier=0.25 [Lenovo X280 Trackpoint] MatchName=*TPPS/2 Elan TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX280:* AttrTrackpointMultiplier=0.5 [Lenovo X280 Touchpad] MatchName=Synaptics TM3381-002 MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX280* AttrPalmSizeThreshold=6 [Lenovo P50 Touchpad] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadP50*: ModelLenovoT450Touchpad=1 AttrPalmPressureThreshold=150 [Lenovo *50 Touchpad] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad??50*: ModelLenovoT450Touchpad=1 AttrPalmPressureThreshold=150 [Lenovo *60 Touchpad] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad??60*: ModelLenovoT450Touchpad=1 AttrPalmPressureThreshold=150 [Lenovo X1 Carbon 3rd Touchpad] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon3rd:* ModelLenovoT450Touchpad=1 AttrPalmPressureThreshold=150 [Lenovo X1 Carbon 4th Trackpoint] MatchUdevType=pointingstick MatchName=*TPPS/2 IBM TrackPoint* MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon4th* AttrTrackpointMultiplier=0.5 [Lenovo X1 Carbon 6th Trackpoint] MatchUdevType=pointingstick MatchName=*TPPS/2 Elan TrackPoint* MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon6th* AttrTrackpointMultiplier=0.4 [Lenovo ThinkPad Compact USB Keyboard with TrackPoint (keyboard)] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x17EF MatchProduct=0x6047 AttrKeyboardIntegration=external [Lenovo ThinkPad Compact USB Keyboard with TrackPoint (trackpoint)] MatchUdevType=pointingstick MatchBus=usb MatchVendor=0x17EF MatchProduct=0x6047 AttrPointingStickIntegration=external # Lenovo Thinkpad Yoga (not the consumer versions) disables the keyboard # mechanically. We must not disable the keyboard because some keys are # still accessible on the screen and volume rocker. # Initially #103749 and extended by #106799 comment 7 [Lenovo Thinkpad Yoga] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPad*Yoga*:* ModelTabletModeNoSuspend=1 [Lenovo X1 Yoga Trackpoint 1st gen] MatchName=*TPPS/2 IBM TrackPoint MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Yoga1st:* AttrTrackpointMultiplier=1.25 # A true pressurepad so let's not use pressure for contact size # https://gitlab.freedesktop.org/libinput/libinput/-/issues/562 [Lenovo Yoga 9i Pressurepad] MatchBus=i2c MatchVendor=0x06CB MatchProduct=0xCE37 ModelPressurePad=1 [Lenovo Yoga C930 Tablet] MatchBus=i2c MatchVendor=0x056A MatchProduct=0x5196 AttrTabletSmoothing=1 # Lenovo Carbon X1 6th gen (RMI4 only, PS/2 is broken on this device, # sends bogus ABS_MT_TOOL_TYPE events for MT_TOOL_PALM [Lenovo Carbon X1 6th gen] MatchName=Synaptics TM3288-011 MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX1Carbon6th:* AttrEventCode=-ABS_MT_TOOL_TYPE ModelLenovoX1Gen6Touchpad=1 [Lenovo X41 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnIBM:*pvrThinkPadX41Tablet:* ModelTabletModeNoSuspend=1 [Lenovo X60 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX60Tablet:* ModelTabletModeNoSuspend=1 [Lenovo X61 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX61Tablet:* ModelTabletModeNoSuspend=1 # Lenovo X220 Tablet special bezel buttons are associated to the # keyboard and would therefore mistakenly be deactivated as well. # See https://gitlab.freedesktop.org/libinput/libinput/issues/154 [Lenovo X220 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX220Tablet:* ModelTabletModeNoSuspend=1 # Special bezel button deactivation with # keyboard also applies to X230 Tablet [Lenovo X230 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX230Tablet:* ModelTabletModeNoSuspend=1 # Special bezel button deactivation with # keyboard also applies to X200 Tablet [Lenovo X200 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX200Tablet:* ModelTabletModeNoSuspend=1 [Lenovo X201 Tablet] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX201Tablet:* ModelTabletModeNoSuspend=1 # Lenovo MIIX 720 comes with a detachable keyboard. We must not disable # the keyboard because some keys are still accessible on the screen and # volume rocker. See # https://gitlab.freedesktop.org/libinput/libinput/issues/115 [Lenovo MIIX 720] MatchName=AT Raw Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrLenovoMIIX720-12IKB:* ModelTabletModeNoSuspend=1 # Lenovo ThinkPad X1 Tablet (1st Gen) also comes with a detachable keyboard. # We must not disable the keyboard because some keys are still accessible on # volume rocker. [Lenovo ThinkPad X1 Tablet (1st Gen)] MatchName=AT Raw Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX1Tablet:* ModelTabletModeNoSuspend=1 # Misidentified as an external keyboard by libinput # Tested on Legion 5 15AR05H [Lenovo Legion 5 Keyboard (C100)] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC100 AttrKeyboardIntegration=internal # Tested on Legion 5 15ARH7H, should also work for Legion 5 Pro 16ARH7H # 048d:c102 Integrated Technology Express, Inc. ITE Device(8910) [Lenovo Legion 5 Keyboard (C102)] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC102 AttrKeyboardIntegration=internal # Tested on Legion Pro 5 16IRX8 # 048d:c103 Integrated Technology Express, Inc. ITE Device(8910) [Lenovo Legion 5 Keyboard (C103)] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC103 AttrKeyboardIntegration=internal [Lenovo Legion 5 Keyboard (C955)] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC955 AttrKeyboardIntegration=internal # Tested on Lenovo Legion 5 Pro 16ACH6H [Lenovo Legion 5 Pro Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC101 AttrKeyboardIntegration=internal [Lenovo Legion 5i Keyboard] MatchName=ITE Tech. Inc. ITE Device(8910) Keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrLegion515IAH7H:* AttrKeyboardIntegration=internal [Lenovo Legion 7 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC968 AttrKeyboardIntegration=internal [Lenovo Legion Y740 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC936 AttrKeyboardIntegration=internal [Lenovo Legion Slim 7] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC967 AttrKeyboardIntegration=internal [Lenovo Legion Slim 7 Gen 8] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC987 AttrKeyboardIntegration=internal # https://gitlab.freedesktop.org/libinput/libinput/-/issues/604 [Lenovo Yoga Slim 9 14ITL5 Pressurepad] MatchBus=i2c MatchVendor=0x27C6 MatchProduct=0x01E8 ModelPressurePad=1 # Duet 7i tablet switch activated by folding keyboard cover, or removing it. # We must not disable volume rocker 'keyboard'. [Lenovo Duet 7i] MatchName=AT Raw Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrYogaDuet713IML05:* ModelTabletModeNoSuspend=1 # Lenovo IdeaPad Duet 3 also comes with a detachable keyboard. [Lenovo IdeaPad Duet 3] MatchName=AT Raw Set 2 keyboard MatchDMIModalias=dmi:*svnLENOVO:*pvrIdeaPadDuet3*:* ModelTabletModeNoSuspend=1 # Modifies pressure range to avoid random jumps. # https://gitlab.freedesktop.org/libinput/libinput/-/issues/407 [Lenovo Yoga 2 Pro touchpad] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnLENOVO:*:pvrLenovoYoga2Pro* AttrPressureRange=50:45 [Lenovo Legion 7i 4090 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchDMIModalias=dmi:*svnLENOVO:*:pvrLegionY9000PIRX8H* AttrKeyboardIntegration=internal [Lenovo LOQ 15IRH8 Keyboard] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC986 AttrKeyboardIntegration=internal [Lenovo ThinkPad E14 v2] MatchUdevType=touchpad MatchName=*Elan Touchpad MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadE14Gen2* AttrPalmPressureThreshold=300 AttrPressureRange=10:8 # White Backlit Keyboard [Lenovo Ideapad Gaming 3] MatchUdevType=keyboard MatchBus=usb MatchVendor=0x048D MatchProduct=0xC966 AttrKeyboardIntegration=internal [Lenovo Thinkpad Yoga X390] MatchUdevType=pointingstick MatchName=*TPPS/2 Elan TrackPoint* MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX390Yoga*:* AttrTrackpointMultiplier=0.4 # This should cover all keyboards that are misidentified as external. # Tested on Lenovo Legion 5 Pro (2023) [Lenovo 16ARX8 keyboard] MatchName=ITE Tech. Inc. ITE Device(8910) Keyboard MatchUdevType=keyboard MatchDMIModalias=dmi:*svnLENOVO:* AttrKeyboardIntegration=internal # Some ThinkBook 14 G7+ ASP models come with pressure pads that were not # correctly declared as such. [Lenovo ThinkBook 14 G7+ ASP touchpad] MatchName=*GXTP5100* MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G7+ASP*:* MatchUdevType=touchpad ModelPressurePad=1 # The ThinkBook 14 G6+ IMH also has a similar issue as the G7+ mentioned above. [Lenovo ThinkBook 14 G6+ IMH] MatchName=*GXTP5100* MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G6+IMH*:* MatchUdevType=touchpad ModelPressurePad=1 # Lenovo Yoga Slim 7i Carbon sends bogus ABS_MT_TOOL_TYPE MT_TOOL_PALM events [Lenovo Yoga Slim 7i Carbon] MatchName=* Touchpad MatchDMIModalias=dmi:*:svnLENOVO:*pvrYogaSlim7Carbon13IAP7:* AttrEventCode=-ABS_MT_TOOL_TYPE # The ThinkPad X9 15 Gen 1 Forcepad touchpad is not # detected as a pressure pad [Lenovo ThinkPad X9 15 Gen 1] MatchName=*GXTP5100* MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX9-15Gen1*:* MatchUdevType=touchpad ModelPressurePad=1 # The ThinkBook 14 G7+ IAH also has a similar issue as the ASP mentioned above. [Lenovo ThinkBook 14 G7+ IAH touchpad] MatchName=*GXTP5100* MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G7+IAH*:* MatchUdevType=touchpad ModelPressurePad=1 libinput-1.28.1/quirks/50-system-lg.quirks000066400000000000000000000003021477265155700203730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [LG gram 14 2023 Touchpad] MatchName=* Touchpad MatchDMIModalias=dmi:*svnLGElectronics:pn14Z90R-G.AA79G:* ModelTouchpadPhantomClicks=1 libinput-1.28.1/quirks/50-system-minisforum.quirks000066400000000000000000000005511477265155700221670ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Minisforum V3 volume keys] MatchName=AT Translated Set 2 keyboard MatchDMIModalias=dmi:*svnMicroComputer(HK)TechLimited:pnV3:* ModelTabletModeNoSuspend=1 [Minisforum V3 touchpad dwt] MatchName=USB Keyboard MatchDMIModalias=dmi:*svnMicroComputer(HK)TechLimited:pnV3:* AttrKeyboardIntegration=internal libinput-1.28.1/quirks/50-system-pine64.quirks000066400000000000000000000002041477265155700210770ustar00rootroot00000000000000[PineBook Pro Keyboard] MatchVendor=0x258A MatchProduct=0x001E MatchUdevType=keyboard MatchBus=usb AttrKeyboardIntegration=internal libinput-1.28.1/quirks/50-system-sony.quirks000066400000000000000000000003661477265155700207730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [Sony Vaio VPCEG Series Touchpad Pressure Override] MatchUdevType=touchpad MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnSonyCorporation:pnVPCEG* AttrPressureRange=45:40 libinput-1.28.1/quirks/50-system-starlabs.quirks000066400000000000000000000002411477265155700216060ustar00rootroot00000000000000[Star Labs Touchpad] MatchName=*Touchpad MatchUdevType=touchpad MatchDMIModalias=dmi:*svnStarLabs:* AttrEventCode=-BTN_RIGHT AttrInputProp=+INPUT_PROP_BUTTONPAD libinput-1.28.1/quirks/50-system-system76.quirks000066400000000000000000000010771477265155700215040ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update [System76 Bonobo Professional] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnSystem76*pvrbonp5* ModelSystem76Bonobo=1 [System76 Clevo] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*pnW740SU*rnW740SU* ModelClevoW740SU=1 [System76 Galago Ultra Pro] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnSystem76*pvrgalu1* ModelSystem76Galago=1 [System76 Kudu Professional] MatchName=SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnSystem76*pvrkudp1* ModelSystem76Kudu=1 libinput-1.28.1/quirks/50-system-toshiba.quirks000066400000000000000000000002261477265155700214270ustar00rootroot00000000000000[Toshiba Satellite L855-14E Touchpad] MatchName=*SynPS/2 Synaptics TouchPad MatchDMIModalias=dmi:*svnTOSHIBA:pnSATELLITEL855* AttrPressureRange=45:44 libinput-1.28.1/quirks/50-system-vaio.quirks000066400000000000000000000002551477265155700207360ustar00rootroot00000000000000[Positivo-Vaio Touchpad] MatchName=SYNA3602:00 0911:5288 Touchpad MatchDMIModalias=dmi:*svnPositivoBahia-VAIO:pnVJ[FP][EWX]* MatchUdevType=touchpad AttrEventCode=+BTN_RIGHT libinput-1.28.1/quirks/README.md000066400000000000000000000055061477265155700162570ustar00rootroot00000000000000libinput quirks file format =========================== This directory contains hardware quirks used by libinput to work around bugs in the hardware, device behavior and to supply information not obtained through the kernel device. **THIS IS NOT STABLE API** The data format may change at any time. If your quirks file is not part of the libinput git tree, do not expect it to work after an update. Absolutely no guarantees are made for backwards-compatibility. **THIS IS NOT A CONFIGURATION API** Use the `libinput_device_config_foo()` functions for device configuration. Quirks here are hardware quirks only. Data file naming ---------------- Data files are read in versionsort order, read order determines how values override each other. Values read later override previously read values. The current structure is: - `10-generic-foo.quirks` for generic settings, - `30-vendor-foo.quirks` for vendor-specific settings, and - `50-system-foo.quirks` for system vendors. This is not a fixed naming scheme and may change at any time. It's an approximation only because some vendors are also system vendors, e.g. Microsoft makes devices and laptops. Laptop-specific quirks should always go into the laptop vendor's file even where they apply to a component of a different vendor. For example, a quirk for a Synaptics touchpad specific to a Dell laptop should go into the Dell quirks file. Sections, matches and values ---------------------------- A data file must contain at least one section, each section must have at least one `Match` tag and at least one of either `Attr` or `Model`. Section names are free-form and may contain spaces. ``` # This is a comment [Some touchpad] MatchBus=usb # No quotes around strings MatchName=*Synaptics Touchpad* AttrSizeHint=50x50 ModelSynapticsTouchpad=1 [Apple touchpad] MatchVendor=0x5AC MatchProduct=0x123 ModelAppleTouchpad=1 ``` Comments are lines starting with `#`. All `Model` tags take a value of either `1` or `0`. All `Attr` tag values are specific to that attribute. Parser errors ------------- The following requirements must be met: * No whitespace is allowed at the beginning of the line * A Section must have at least one `Match*` entry * A Section must not repeat `Match*` entry * A Section must have at least one of `Model*` or `Attr*` entries * A `Model` tag may only have the value `1` or `0` * String properties must not be enclosed in quotes * Hex numbers must use uppercase letters (e.g. `0x12AB`) Failure to meet these requirements will cause a parser error and the quirks files will not be used. Debugging --------- When modifying a data file, use the `libinput list-quirks` tool to verify the changes. The tool can be pointed at the data directory to analyse, use `--verbose` to get more info. For example: ``` libinput list-quirks --data-dir /path/to/git/repo/quirks/ --verbose /dev/input/event0 ``` libinput-1.28.1/src/000077500000000000000000000000001477265155700142435ustar00rootroot00000000000000libinput-1.28.1/src/builddir.h000066400000000000000000000037621477265155700162220ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #pragma once #include #include "util-strings.h" /** * Try to figure out the directory we're executing from and if it matches * the builddir, return that directory. Otherwise, return NULL. */ static inline char * builddir_lookup(void) { char execdir[PATH_MAX]; char *pathsep; ssize_t nread; /* In the case of release builds, the builddir is the empty string */ if (streq(MESON_BUILD_ROOT, "")) return NULL; nread = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1); if (nread <= 0 || nread == sizeof(execdir) - 1) return NULL; /* readlink doesn't terminate the string and readlink says anything past sz is undefined */ execdir[nread] = '\0'; pathsep = strrchr(execdir, '/'); if (!pathsep) return NULL; *pathsep = '\0'; if (!streq(execdir, MESON_BUILD_ROOT)) return NULL; return safe_strdup(execdir); } libinput-1.28.1/src/evdev-debounce.c000066400000000000000000000432051477265155700173060ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev-fallback.h" /* Debounce cases to handle P ... button press R ... button release ---| timeout duration 'normal' .... event sent when it happens 'filtered' .. event is not sent (but may be sent later) 'delayed' ... event is sent with wall-clock delay 1) P---| R P normal, R normal 2) R---| P R normal, P normal 3) P---R--| P P normal, R filtered, delayed, P normal 4) R---P--| R R normal, P filtered, delayed, R normal 4.1) P---| R--P--| P normal, R filtered 5) P--R-P-| R P normal, R filtered, P filtered, R normal 6) R--P-R-| P R normal, P filtered, R filtered, P normal 7) P--R--| ---P-| P normal, R filtered, P filtered 8) R--P--| ---R-| R normal, P filtered, R filtered 1, 2 are the normal click cases without debouncing taking effect 3, 4 are fast clicks where the second event is delivered with a delay 5, 6 are contact bounces, fast 7, 8 are contact bounces, slow 4.1 is a special case with the same event sequence as 4 but we want to filter the *release* event out, it's a button losing contact while being held down. 7 and 8 are cases where the first event happens within the first timeout but the second event is outside that timeout (but within the timeout of the second event). These cases are handled by restarting the timer on every event that could be part of a bouncing sequence, which makes these cases indistinguishable from 5 and 6. */ enum debounce_event { DEBOUNCE_EVENT_PRESS = 50, DEBOUNCE_EVENT_RELEASE, DEBOUNCE_EVENT_TIMEOUT, DEBOUNCE_EVENT_TIMEOUT_SHORT, DEBOUNCE_EVENT_OTHERBUTTON, }; static inline const char * debounce_state_to_str(enum debounce_state state) { switch(state) { CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_WAITING); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DELAYING); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_WAITING); CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_DELAYING); CASE_RETURN_STRING(DEBOUNCE_STATE_DISABLED); } return NULL; } static inline const char* debounce_event_to_str(enum debounce_event event) { switch(event) { CASE_RETURN_STRING(DEBOUNCE_EVENT_PRESS); CASE_RETURN_STRING(DEBOUNCE_EVENT_RELEASE); CASE_RETURN_STRING(DEBOUNCE_EVENT_TIMEOUT); CASE_RETURN_STRING(DEBOUNCE_EVENT_TIMEOUT_SHORT); CASE_RETURN_STRING(DEBOUNCE_EVENT_OTHERBUTTON); } return NULL; } static inline void log_debounce_bug(struct fallback_dispatch *fallback, enum debounce_event event) { evdev_log_bug_libinput(fallback->device, "invalid debounce event %s in state %s\n", debounce_event_to_str(event), debounce_state_to_str(fallback->debounce.state)); } static inline void debounce_set_state(struct fallback_dispatch *fallback, enum debounce_state new_state) { assert(new_state >= DEBOUNCE_STATE_IS_UP && new_state <= DEBOUNCE_STATE_IS_DOWN_DELAYING); fallback->debounce.state = new_state; } static inline void debounce_set_timer(struct fallback_dispatch *fallback, uint64_t time) { const int DEBOUNCE_TIMEOUT_BOUNCE = ms2us(25); libinput_timer_set(&fallback->debounce.timer, time + DEBOUNCE_TIMEOUT_BOUNCE); } static inline void debounce_set_timer_short(struct fallback_dispatch *fallback, uint64_t time) { const int DEBOUNCE_TIMEOUT_SPURIOUS = ms2us(12); libinput_timer_set(&fallback->debounce.timer_short, time + DEBOUNCE_TIMEOUT_SPURIOUS); } static inline void debounce_cancel_timer(struct fallback_dispatch *fallback) { libinput_timer_cancel(&fallback->debounce.timer); } static inline void debounce_cancel_timer_short(struct fallback_dispatch *fallback) { libinput_timer_cancel(&fallback->debounce.timer_short); } static inline void debounce_enable_spurious(struct fallback_dispatch *fallback) { if (fallback->debounce.spurious_enabled) evdev_log_bug_libinput(fallback->device, "tried to enable spurious debouncing twice\n"); fallback->debounce.spurious_enabled = true; evdev_log_info(fallback->device, "Enabling spurious button debouncing, " "see %s/button-debouncing.html for details\n", HTTP_DOC_LINK); } static void debounce_notify_button(struct fallback_dispatch *fallback, enum libinput_button_state state) { struct evdev_device *device = fallback->device; unsigned int code = fallback->debounce.button_code; uint64_t time = fallback->debounce.button_time; code = evdev_to_left_handed(device, code); fallback_notify_physical_button(fallback, device, time, code, state); } static void debounce_is_up_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: fallback->debounce.button_time = time; debounce_set_timer(fallback, time); debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_WAITING); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_PRESSED); break; case DEBOUNCE_EVENT_RELEASE: case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_OTHERBUTTON: break; } } static void debounce_is_down_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_RELEASE: fallback->debounce.button_time = time; debounce_set_timer(fallback, time); debounce_set_timer_short(fallback, time); if (fallback->debounce.spurious_enabled) { debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS); } else { debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_RELEASED); } break; case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_OTHERBUTTON: break; } } static void debounce_is_down_waiting_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_RELEASE: debounce_set_timer(fallback, time); debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DELAYING); /* Note: In the debouncing RPR case, we use the last * release's time stamp */ fallback->debounce.button_time = time; break; case DEBOUNCE_EVENT_TIMEOUT: debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); break; } } static void debounce_is_up_delaying_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: debounce_set_timer(fallback, time); debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_WAITING); break; case DEBOUNCE_EVENT_RELEASE: case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_RELEASED); break; } } static void debounce_is_up_delaying_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); debounce_cancel_timer(fallback); debounce_cancel_timer_short(fallback); break; case DEBOUNCE_EVENT_RELEASE: case DEBOUNCE_EVENT_TIMEOUT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_RELEASED); break; case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_RELEASED); break; } } static void debounce_is_up_detecting_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: debounce_set_timer(fallback, time); debounce_set_timer_short(fallback, time); /* Note: in a bouncing PRP case, we use the last press * event time */ fallback->debounce.button_time = time; debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS); break; case DEBOUNCE_EVENT_RELEASE: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_TIMEOUT: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING); break; case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP); break; } } static void debounce_is_down_detecting_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_RELEASE: debounce_set_timer(fallback, time); debounce_set_timer_short(fallback, time); debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: debounce_cancel_timer(fallback); debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); debounce_enable_spurious(fallback); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_PRESSED); break; case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_PRESSED); break; } } static void debounce_is_up_waiting_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: debounce_set_timer(fallback, time); /* Note: in a debouncing PRP case, we use the last press' * time */ fallback->debounce.button_time = time; debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_DELAYING); break; case DEBOUNCE_EVENT_RELEASE: case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP); break; } } static void debounce_is_down_delaying_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_RELEASE: debounce_set_timer(fallback, time); debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_TIMEOUT: case DEBOUNCE_EVENT_OTHERBUTTON: debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN); debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_PRESSED); break; } } static void debounce_disabled_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { switch (event) { case DEBOUNCE_EVENT_PRESS: fallback->debounce.button_time = time; debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_PRESSED); break; case DEBOUNCE_EVENT_RELEASE: fallback->debounce.button_time = time; debounce_notify_button(fallback, LIBINPUT_BUTTON_STATE_RELEASED); break; case DEBOUNCE_EVENT_TIMEOUT_SHORT: case DEBOUNCE_EVENT_TIMEOUT: log_debounce_bug(fallback, event); break; case DEBOUNCE_EVENT_OTHERBUTTON: break; } } static void debounce_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time) { enum debounce_state current = fallback->debounce.state; if (event == DEBOUNCE_EVENT_OTHERBUTTON) { debounce_cancel_timer(fallback); debounce_cancel_timer_short(fallback); } switch(current) { case DEBOUNCE_STATE_IS_UP: debounce_is_up_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_DOWN: debounce_is_down_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_DOWN_WAITING: debounce_is_down_waiting_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_UP_DELAYING: debounce_is_up_delaying_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS: debounce_is_up_delaying_spurious_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS: debounce_is_up_detecting_spurious_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS: debounce_is_down_detecting_spurious_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_UP_WAITING: debounce_is_up_waiting_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_IS_DOWN_DELAYING: debounce_is_down_delaying_handle_event(fallback, event, time); break; case DEBOUNCE_STATE_DISABLED: debounce_disabled_handle_event(fallback, event, time); break; } evdev_log_debug(fallback->device, "debounce state: %s → %s → %s\n", debounce_state_to_str(current), debounce_event_to_str(event), debounce_state_to_str(fallback->debounce.state)); } void fallback_debounce_handle_state(struct fallback_dispatch *dispatch, uint64_t time) { unsigned int changed[16] = {0}; /* event codes of changed buttons */ size_t nchanged = 0; bool flushed = false; for (unsigned int code = 0; code <= KEY_MAX; code++) { if (get_key_type(code) != KEY_TYPE_BUTTON) continue; if (hw_key_has_changed(dispatch, code)) changed[nchanged++] = code; /* If you manage to press more than 16 buttons in the same * frame, we just quietly ignore the rest of them */ if (nchanged == ARRAY_LENGTH(changed)) break; } /* If we have more than one button this frame or a different button, * flush the state machine with otherbutton */ if (nchanged > 1 || changed[0] != dispatch->debounce.button_code) { debounce_handle_event(dispatch, DEBOUNCE_EVENT_OTHERBUTTON, time); flushed = true; } /* The state machine has some pre-conditions: * - the IS_DOWN and IS_UP states are neutral entry states without * any timeouts * - a OTHERBUTTON event always flushes the state to IS_DOWN or * IS_UP */ for (size_t i = 0; i < nchanged; i++) { bool is_down = hw_is_key_down(dispatch, changed[i]); if (flushed && dispatch->debounce.state != DEBOUNCE_STATE_DISABLED) { debounce_set_state(dispatch, !is_down ? DEBOUNCE_STATE_IS_DOWN : DEBOUNCE_STATE_IS_UP); flushed = false; } dispatch->debounce.button_code = changed[i]; debounce_handle_event(dispatch, is_down ? DEBOUNCE_EVENT_PRESS : DEBOUNCE_EVENT_RELEASE, time); /* if we have more than one event, we flush the state * machine immediately after the event itself */ if (nchanged > 1) { debounce_handle_event(dispatch, DEBOUNCE_EVENT_OTHERBUTTON, time); flushed = true; } } } static void debounce_timeout(uint64_t now, void *data) { struct evdev_device *device = data; struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); debounce_handle_event(dispatch, DEBOUNCE_EVENT_TIMEOUT, now); } static void debounce_timeout_short(uint64_t now, void *data) { struct evdev_device *device = data; struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); debounce_handle_event(dispatch, DEBOUNCE_EVENT_TIMEOUT_SHORT, now); } void fallback_init_debounce(struct fallback_dispatch *dispatch) { struct evdev_device *device = dispatch->device; char timer_name[64]; if (evdev_device_has_model_quirk(device, QUIRK_MODEL_BOUNCING_KEYS)) { dispatch->debounce.state = DEBOUNCE_STATE_DISABLED; return; } dispatch->debounce.state = DEBOUNCE_STATE_IS_UP; snprintf(timer_name, sizeof(timer_name), "%s debounce short", evdev_device_get_sysname(device)); libinput_timer_init(&dispatch->debounce.timer_short, evdev_libinput_context(device), timer_name, debounce_timeout_short, device); snprintf(timer_name, sizeof(timer_name), "%s debounce", evdev_device_get_sysname(device)); libinput_timer_init(&dispatch->debounce.timer, evdev_libinput_context(device), timer_name, debounce_timeout, device); } libinput-1.28.1/src/evdev-fallback.c000066400000000000000000001302221477265155700172550ustar00rootroot00000000000000/* * Copyright © 2010 Intel Corporation * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2017 Red Hat, Inc. * Copyright © 2017 James Ye * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "evdev-fallback.h" #include "util-input-event.h" static void fallback_keyboard_notify_key(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time, int key, enum libinput_key_state state) { int down_count; down_count = evdev_update_key_down_count(device, key, state); if ((state == LIBINPUT_KEY_STATE_PRESSED && down_count == 1) || (state == LIBINPUT_KEY_STATE_RELEASED && down_count == 0)) keyboard_notify_key(&device->base, time, key, state); } static void fallback_lid_notify_toggle(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { if (dispatch->lid.is_closed ^ dispatch->lid.is_closed_client_state) { switch_notify_toggle(&device->base, time, LIBINPUT_SWITCH_LID, dispatch->lid.is_closed); dispatch->lid.is_closed_client_state = dispatch->lid.is_closed; } } void fallback_notify_physical_button(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state) { evdev_pointer_notify_physical_button(device, time, button, state); } static enum libinput_switch_state fallback_interface_get_switch_state(struct evdev_dispatch *evdev_dispatch, enum libinput_switch sw) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); switch (sw) { case LIBINPUT_SWITCH_TABLET_MODE: break; default: /* Internal function only, so we can abort here */ abort(); } return dispatch->tablet_mode.sw.state ? LIBINPUT_SWITCH_STATE_ON : LIBINPUT_SWITCH_STATE_OFF; } static inline bool post_button_scroll(struct evdev_device *device, struct device_float_coords raw, uint64_t time) { if (device->scroll.method != LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) return false; switch(device->scroll.button_scroll_state) { case BUTTONSCROLL_IDLE: return false; case BUTTONSCROLL_BUTTON_DOWN: /* if the button is down but scroll is not active, we're within the timeout where we swallow motion events but don't post scroll buttons */ evdev_log_debug(device, "btnscroll: discarding\n"); return true; case BUTTONSCROLL_READY: device->scroll.button_scroll_state = BUTTONSCROLL_SCROLLING; _fallthrough_; case BUTTONSCROLL_SCROLLING: { const struct normalized_coords normalized = filter_dispatch_scroll(device->pointer.filter, &raw, device, time); evdev_post_scroll(device, time, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, &normalized); } return true; } assert(!"invalid scroll button state"); } static inline bool fallback_filter_defuzz_touch(struct fallback_dispatch *dispatch, struct evdev_device *device, struct mt_slot *slot) { struct device_coords point; if (!dispatch->mt.want_hysteresis) return false; point = evdev_hysteresis(&slot->point, &slot->hysteresis_center, &dispatch->mt.hysteresis_margin); slot->point = point; if (point.x == slot->hysteresis_center.x && point.y == slot->hysteresis_center.y) return true; slot->hysteresis_center = point; return false; } static inline struct device_float_coords fallback_rotate_relative(struct fallback_dispatch *dispatch, struct evdev_device *device) { struct device_float_coords rel = { dispatch->rel.x, dispatch->rel.y }; if (!device->base.config.rotation) return rel; matrix_mult_vec_double(&dispatch->rotation.matrix, &rel.x, &rel.y); return rel; } static void fallback_flush_relative_motion(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct normalized_coords accel; if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) return; struct device_float_coords raw = fallback_rotate_relative(dispatch, device); dispatch->rel.x = 0; dispatch->rel.y = 0; /* Use unaccelerated deltas for pointing stick scroll */ if (post_button_scroll(device, raw, time)) return; if (device->pointer.filter) { /* Apply pointer acceleration. */ accel = filter_dispatch(device->pointer.filter, &raw, device, time); } else { evdev_log_bug_libinput(device, "accel filter missing\n"); accel.x = accel.y = 0; } if (normalized_is_zero(accel)) return; pointer_notify_motion(base, time, &accel, &raw); } static void fallback_flush_absolute_motion(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct device_coords point; if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) return; point = dispatch->abs.point; evdev_transform_absolute(device, &point); pointer_notify_motion_absolute(base, time, &point); } static bool fallback_flush_mt_down(struct fallback_dispatch *dispatch, struct evdev_device *device, int slot_idx, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; struct device_coords point; struct mt_slot *slot; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; slot = &dispatch->mt.slots[slot_idx]; if (slot->seat_slot != -1) { evdev_log_bug_kernel(device, "driver sent multiple touch down for the same slot"); return false; } seat_slot = ffs(~seat->slot_map) - 1; slot->seat_slot = seat_slot; if (seat_slot == -1) return false; seat->slot_map |= bit(seat_slot); point = slot->point; slot->hysteresis_center = point; evdev_transform_absolute(device, &point); touch_notify_touch_down(base, time, slot_idx, seat_slot, &point); return true; } static bool fallback_flush_mt_motion(struct fallback_dispatch *dispatch, struct evdev_device *device, int slot_idx, uint64_t time) { struct libinput_device *base = &device->base; struct device_coords point; struct mt_slot *slot; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; slot = &dispatch->mt.slots[slot_idx]; seat_slot = slot->seat_slot; point = slot->point; if (seat_slot == -1) return false; if (fallback_filter_defuzz_touch(dispatch, device, slot)) return false; evdev_transform_absolute(device, &point); touch_notify_touch_motion(base, time, slot_idx, seat_slot, &point); return true; } static bool fallback_flush_mt_up(struct fallback_dispatch *dispatch, struct evdev_device *device, int slot_idx, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; struct mt_slot *slot; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; slot = &dispatch->mt.slots[slot_idx]; seat_slot = slot->seat_slot; slot->seat_slot = -1; if (seat_slot == -1) return false; seat->slot_map &= ~bit(seat_slot); touch_notify_touch_up(base, time, slot_idx, seat_slot); return true; } static bool fallback_flush_mt_cancel(struct fallback_dispatch *dispatch, struct evdev_device *device, int slot_idx, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; struct mt_slot *slot; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; slot = &dispatch->mt.slots[slot_idx]; seat_slot = slot->seat_slot; slot->seat_slot = -1; if (seat_slot == -1) return false; seat->slot_map &= ~bit(seat_slot); touch_notify_touch_cancel(base, time, slot_idx, seat_slot); return true; } static bool fallback_flush_st_down(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; struct device_coords point; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; if (dispatch->abs.seat_slot != -1) { evdev_log_bug_kernel(device, "driver sent multiple touch down for the same slot"); return false; } seat_slot = ffs(~seat->slot_map) - 1; dispatch->abs.seat_slot = seat_slot; if (seat_slot == -1) return false; seat->slot_map |= bit(seat_slot); point = dispatch->abs.point; evdev_transform_absolute(device, &point); touch_notify_touch_down(base, time, -1, seat_slot, &point); return true; } static bool fallback_flush_st_motion(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct device_coords point; int seat_slot; point = dispatch->abs.point; evdev_transform_absolute(device, &point); seat_slot = dispatch->abs.seat_slot; if (seat_slot == -1) return false; touch_notify_touch_motion(base, time, -1, seat_slot, &point); return true; } static bool fallback_flush_st_up(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; seat_slot = dispatch->abs.seat_slot; dispatch->abs.seat_slot = -1; if (seat_slot == -1) return false; seat->slot_map &= ~bit(seat_slot); touch_notify_touch_up(base, time, -1, seat_slot); return true; } static bool fallback_flush_st_cancel(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_seat *seat = base->seat; int seat_slot; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; seat_slot = dispatch->abs.seat_slot; dispatch->abs.seat_slot = -1; if (seat_slot == -1) return false; seat->slot_map &= ~bit(seat_slot); touch_notify_touch_cancel(base, time, -1, seat_slot); return true; } static void fallback_process_touch_button(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time, int value) { dispatch->pending_event |= (value) ? EVDEV_ABSOLUTE_TOUCH_DOWN : EVDEV_ABSOLUTE_TOUCH_UP; } static inline void fallback_process_key(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { enum key_type type; /* ignore kernel key repeat */ if (e->value == 2) return; if (e->code == BTN_TOUCH) { if (!device->is_mt) fallback_process_touch_button(dispatch, device, time, e->value); return; } type = get_key_type(e->code); /* Ignore key release events from the kernel for keys that libinput * never got a pressed event for or key presses for keys that we * think are still down */ switch (type) { case KEY_TYPE_NONE: break; case KEY_TYPE_KEY: case KEY_TYPE_BUTTON: if ((e->value && hw_is_key_down(dispatch, e->code)) || (e->value == 0 && !hw_is_key_down(dispatch, e->code))) return; dispatch->pending_event |= EVDEV_KEY; break; } hw_set_key_down(dispatch, e->code, e->value); switch (type) { case KEY_TYPE_NONE: break; case KEY_TYPE_KEY: fallback_keyboard_notify_key( dispatch, device, time, e->code, e->value ? LIBINPUT_KEY_STATE_PRESSED : LIBINPUT_KEY_STATE_RELEASED); break; case KEY_TYPE_BUTTON: break; } } static void fallback_process_touch(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { struct mt_slot *slot = &dispatch->mt.slots[dispatch->mt.slot]; if (e->code == ABS_MT_SLOT) { if ((size_t)e->value >= dispatch->mt.slots_len) { evdev_log_bug_libinput(device, "exceeded slot count (%d of max %zd)\n", e->value, dispatch->mt.slots_len); e->value = dispatch->mt.slots_len - 1; } dispatch->mt.slot = e->value; return; } switch (e->code) { case ABS_MT_TRACKING_ID: if (e->value >= 0) { dispatch->pending_event |= EVDEV_ABSOLUTE_MT; slot->state = SLOT_STATE_BEGIN; if (dispatch->mt.has_palm) { int v; v = libevdev_get_slot_value(device->evdev, dispatch->mt.slot, ABS_MT_TOOL_TYPE); switch (v) { case MT_TOOL_PALM: /* new touch, no cancel needed */ slot->palm_state = PALM_WAS_PALM; break; default: slot->palm_state = PALM_NONE; break; } } else { slot->palm_state = PALM_NONE; } } else { dispatch->pending_event |= EVDEV_ABSOLUTE_MT; slot->state = SLOT_STATE_END; } slot->dirty = true; break; case ABS_MT_POSITION_X: evdev_device_check_abs_axis_range(device, e->code, e->value); dispatch->mt.slots[dispatch->mt.slot].point.x = e->value; dispatch->pending_event |= EVDEV_ABSOLUTE_MT; slot->dirty = true; break; case ABS_MT_POSITION_Y: evdev_device_check_abs_axis_range(device, e->code, e->value); dispatch->mt.slots[dispatch->mt.slot].point.y = e->value; dispatch->pending_event |= EVDEV_ABSOLUTE_MT; slot->dirty = true; break; case ABS_MT_TOOL_TYPE: /* The transitions matter - we (may) need to send a touch * cancel event if we just switched to a palm touch. And the * kernel may switch back to finger but we keep the touch as * palm - but then we need to reset correctly on a new touch * sequence. */ switch (e->value) { case MT_TOOL_PALM: if (slot->palm_state == PALM_NONE) slot->palm_state = PALM_NEW; break; default: if (slot->palm_state == PALM_IS_PALM) slot->palm_state = PALM_WAS_PALM; break; } dispatch->pending_event |= EVDEV_ABSOLUTE_MT; slot->dirty = true; break; } } static inline void fallback_process_absolute_motion(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e) { switch (e->code) { case ABS_X: evdev_device_check_abs_axis_range(device, e->code, e->value); dispatch->abs.point.x = e->value; dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION; break; case ABS_Y: evdev_device_check_abs_axis_range(device, e->code, e->value); dispatch->abs.point.y = e->value; dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION; break; } } static void fallback_lid_keyboard_event(uint64_t time, struct libinput_event *event, void *data) { struct fallback_dispatch *dispatch = fallback_dispatch(data); if (!dispatch->lid.is_closed) return; if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY) return; if (dispatch->lid.reliability == RELIABILITY_WRITE_OPEN) { int fd = libevdev_get_fd(dispatch->device->evdev); int rc; struct input_event ev[2]; ev[0] = input_event_init(0, EV_SW, SW_LID, 0); ev[1] = input_event_init(0, EV_SYN, SYN_REPORT, 0); rc = write(fd, ev, sizeof(ev)); if (rc < 0) evdev_log_error(dispatch->device, "failed to write SW_LID state (%s)", strerror(errno)); /* In case write() fails, we sync the lid state manually * regardless. */ } /* Posting the event here means we preempt the keyboard events that * caused us to wake up, so the lid event is always passed on before * the key event. */ dispatch->lid.is_closed = false; fallback_lid_notify_toggle(dispatch, dispatch->device, time); } static void fallback_lid_toggle_keyboard_listener(struct fallback_dispatch *dispatch, struct evdev_paired_keyboard *kbd, bool is_closed) { assert(kbd->device); libinput_device_remove_event_listener(&kbd->listener); if (is_closed) { libinput_device_add_event_listener( &kbd->device->base, &kbd->listener, fallback_lid_keyboard_event, dispatch); } else { libinput_device_init_event_listener(&kbd->listener); } } static void fallback_lid_toggle_keyboard_listeners(struct fallback_dispatch *dispatch, bool is_closed) { struct evdev_paired_keyboard *kbd; list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) { if (!kbd->device) continue; fallback_lid_toggle_keyboard_listener(dispatch, kbd, is_closed); } } static inline void fallback_process_switch(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { enum libinput_switch_state state; bool is_closed; /* TODO: this should to move to handle_state */ switch (e->code) { case SW_LID: is_closed = !!e->value; fallback_lid_toggle_keyboard_listeners(dispatch, is_closed); if (dispatch->lid.is_closed == is_closed) return; dispatch->lid.is_closed = is_closed; fallback_lid_notify_toggle(dispatch, device, time); break; case SW_TABLET_MODE: if (dispatch->tablet_mode.sw.state == e->value) return; dispatch->tablet_mode.sw.state = e->value; if (e->value) state = LIBINPUT_SWITCH_STATE_ON; else state = LIBINPUT_SWITCH_STATE_OFF; switch_notify_toggle(&device->base, time, LIBINPUT_SWITCH_TABLET_MODE, state); break; } } static inline bool fallback_reject_relative(struct evdev_device *device, const struct input_event *e, uint64_t time) { if ((e->code == REL_X || e->code == REL_Y) && (device->seat_caps & EVDEV_DEVICE_POINTER) == 0) { evdev_log_bug_libinput_ratelimit(device, &device->nonpointer_rel_limit, "REL_X/Y from a non-pointer device\n"); return true; } return false; } static inline void fallback_process_relative(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { if (fallback_reject_relative(device, e, time)) return; switch (e->code) { case REL_X: dispatch->rel.x += e->value; dispatch->pending_event |= EVDEV_RELATIVE_MOTION; break; case REL_Y: dispatch->rel.y += e->value; dispatch->pending_event |= EVDEV_RELATIVE_MOTION; break; } fallback_wheel_process_relative(dispatch, device, e, time); } static inline void fallback_process_absolute(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { if (device->is_mt) { fallback_process_touch(dispatch, device, e, time); } else { fallback_process_absolute_motion(dispatch, device, e); } } static inline bool fallback_any_button_down(struct fallback_dispatch *dispatch, struct evdev_device *device) { unsigned int button; for (button = BTN_LEFT; button < BTN_JOYSTICK; button++) { if (libevdev_has_event_code(device->evdev, EV_KEY, button) && hw_is_key_down(dispatch, button)) return true; } return false; } static inline bool fallback_arbitrate_touch(struct fallback_dispatch *dispatch, struct mt_slot *slot) { bool discard = false; struct device_coords point = slot->point; evdev_transform_absolute(dispatch->device, &point); if (dispatch->arbitration.state == ARBITRATION_IGNORE_RECT && point_in_rect(&point, &dispatch->arbitration.rect)) { slot->palm_state = PALM_IS_PALM; discard = true; } return discard; } static inline bool fallback_flush_mt_events(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { bool sent = false; for (size_t i = 0; i < dispatch->mt.slots_len; i++) { struct mt_slot *slot = &dispatch->mt.slots[i]; if (!slot->dirty) continue; slot->dirty = false; /* Any palm state other than PALM_NEW means we've either * already cancelled the touch or the touch was never * a finger anyway and we didn't send the begin. */ if (slot->palm_state == PALM_NEW) { if (slot->state != SLOT_STATE_BEGIN) sent = fallback_flush_mt_cancel(dispatch, device, i, time); slot->palm_state = PALM_IS_PALM; } else if (slot->palm_state == PALM_NONE) { switch (slot->state) { case SLOT_STATE_BEGIN: if (!fallback_arbitrate_touch(dispatch, slot)) { sent = fallback_flush_mt_down(dispatch, device, i, time); } break; case SLOT_STATE_UPDATE: sent = fallback_flush_mt_motion(dispatch, device, i, time); break; case SLOT_STATE_END: sent = fallback_flush_mt_up(dispatch, device, i, time); break; case SLOT_STATE_NONE: break; } } /* State machine continues independent of the palm state */ switch (slot->state) { case SLOT_STATE_BEGIN: slot->state = SLOT_STATE_UPDATE; break; case SLOT_STATE_UPDATE: break; case SLOT_STATE_END: slot->state = SLOT_STATE_NONE; break; case SLOT_STATE_NONE: /* touch arbitration may swallow the begin, * so we may get updates for a touch still * in NONE state */ break; } } return sent; } static void fallback_handle_state(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { bool need_touch_frame = false; /* Relative motion */ if (dispatch->pending_event & EVDEV_RELATIVE_MOTION) fallback_flush_relative_motion(dispatch, device, time); /* Single touch or absolute pointer devices */ if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_DOWN) { if (fallback_flush_st_down(dispatch, device, time)) need_touch_frame = true; } else if (dispatch->pending_event & EVDEV_ABSOLUTE_MOTION) { if (device->seat_caps & EVDEV_DEVICE_TOUCH) { if (fallback_flush_st_motion(dispatch, device, time)) need_touch_frame = true; } else if (device->seat_caps & EVDEV_DEVICE_POINTER) { fallback_flush_absolute_motion(dispatch, device, time); } } if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_UP) { if (fallback_flush_st_up(dispatch, device, time)) need_touch_frame = true; } /* Multitouch devices */ if (dispatch->pending_event & EVDEV_ABSOLUTE_MT) need_touch_frame = fallback_flush_mt_events(dispatch, device, time); if (need_touch_frame) touch_notify_frame(&device->base, time); fallback_wheel_handle_state(dispatch, device, time); /* Buttons and keys */ if (dispatch->pending_event & EVDEV_KEY) { bool want_debounce = false; for (unsigned int code = 0; code <= KEY_MAX; code++) { if (!hw_key_has_changed(dispatch, code)) continue; if (get_key_type(code) == KEY_TYPE_BUTTON) { want_debounce = true; break; } } if (want_debounce) fallback_debounce_handle_state(dispatch, time); hw_key_update_last_state(dispatch); } dispatch->pending_event = EVDEV_NONE; } static void fallback_interface_process(struct evdev_dispatch *evdev_dispatch, struct evdev_device *device, struct input_event *event, uint64_t time) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); static bool warned = false; if (dispatch->arbitration.in_arbitration) { if (!warned) { evdev_log_debug(device, "dropping events due to touch arbitration\n"); warned = true; } return; } warned = false; switch (event->type) { case EV_REL: fallback_process_relative(dispatch, device, event, time); break; case EV_ABS: fallback_process_absolute(dispatch, device, event, time); break; case EV_KEY: fallback_process_key(dispatch, device, event, time); break; case EV_SW: fallback_process_switch(dispatch, device, event, time); break; case EV_SYN: fallback_handle_state(dispatch, device, time); break; } } static void cancel_touches(struct fallback_dispatch *dispatch, struct evdev_device *device, const struct device_coord_rect *rect, uint64_t time) { unsigned int idx; bool need_frame = false; struct device_coords point; point = dispatch->abs.point; evdev_transform_absolute(device, &point); if (!rect || point_in_rect(&point, rect)) need_frame = fallback_flush_st_cancel(dispatch, device, time); for (idx = 0; idx < dispatch->mt.slots_len; idx++) { struct mt_slot *slot = &dispatch->mt.slots[idx]; point = slot->point; evdev_transform_absolute(device, &point); if (slot->seat_slot == -1) continue; if ((!rect || point_in_rect(&point, rect)) && fallback_flush_mt_cancel(dispatch, device, idx, time)) need_frame = true; } if (need_frame) touch_notify_frame(&device->base, time); } static void release_pressed_keys(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { int code; for (code = 0; code < KEY_CNT; code++) { int count = get_key_down_count(device, code); if (count == 0) continue; if (count > 1) { evdev_log_bug_libinput(device, "key %d is down %d times.\n", code, count); } switch (get_key_type(code)) { case KEY_TYPE_NONE: break; case KEY_TYPE_KEY: fallback_keyboard_notify_key( dispatch, device, time, code, LIBINPUT_KEY_STATE_RELEASED); break; case KEY_TYPE_BUTTON: /* Note: the left-handed configuration is nonzero for * the mapped button (not the physical button), in * get_key_down_count(). We must not map this to left-handed * again, see #881. */ evdev_pointer_notify_button( device, time, code, LIBINPUT_BUTTON_STATE_RELEASED); break; } count = get_key_down_count(device, code); if (count != 0) { evdev_log_bug_libinput(device, "releasing key %d failed.\n", code); break; } } } static void fallback_return_to_neutral_state(struct fallback_dispatch *dispatch, struct evdev_device *device) { struct libinput *libinput = evdev_libinput_context(device); uint64_t time; if ((time = libinput_now(libinput)) == 0) return; cancel_touches(dispatch, device, NULL, time); release_pressed_keys(dispatch, device, time); memset(dispatch->hw_key_mask, 0, sizeof(dispatch->hw_key_mask)); memset(dispatch->hw_key_mask, 0, sizeof(dispatch->last_hw_key_mask)); } static void fallback_interface_suspend(struct evdev_dispatch *evdev_dispatch, struct evdev_device *device) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); fallback_return_to_neutral_state(dispatch, device); } static void fallback_interface_remove(struct evdev_dispatch *evdev_dispatch) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); struct evdev_paired_keyboard *kbd; libinput_timer_cancel(&dispatch->wheel.scroll_timer); libinput_timer_cancel(&dispatch->debounce.timer); libinput_timer_cancel(&dispatch->debounce.timer_short); libinput_timer_cancel(&dispatch->arbitration.arbitration_timer); libinput_device_remove_event_listener(&dispatch->tablet_mode.other.listener); list_for_each_safe(kbd, &dispatch->lid.paired_keyboard_list, link) { evdev_paired_keyboard_destroy(kbd); } } static void fallback_interface_sync_initial_state(struct evdev_device *device, struct evdev_dispatch *evdev_dispatch) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); uint64_t time = libinput_now(evdev_libinput_context(device)); if (device->tags & EVDEV_TAG_LID_SWITCH) { struct libevdev *evdev = device->evdev; dispatch->lid.is_closed = libevdev_get_event_value(evdev, EV_SW, SW_LID); dispatch->lid.is_closed_client_state = false; /* For the initial state sync, we depend on whether the lid switch * is reliable. If we know it's reliable, we sync as expected. * If we're not sure, we ignore the initial state and only sync on * the first future lid close event. Laptops with a broken switch * that always have the switch in 'on' state thus don't mess up our * touchpad. */ if (dispatch->lid.is_closed && dispatch->lid.reliability == RELIABILITY_RELIABLE) { fallback_lid_notify_toggle(dispatch, device, time); } } if (dispatch->tablet_mode.sw.state) { switch_notify_toggle(&device->base, time, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); } } static void fallback_interface_update_rect(struct evdev_dispatch *evdev_dispatch, struct evdev_device *device, const struct phys_rect *phys_rect, uint64_t time) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); struct device_coord_rect rect; assert(phys_rect); /* Existing touches do not change, we just update the rect and only * new touches in these areas will be ignored. If you want to paint * over your finger, be my guest. */ rect = evdev_phys_rect_to_units(device, phys_rect); dispatch->arbitration.rect = rect; } static void fallback_interface_toggle_touch(struct evdev_dispatch *evdev_dispatch, struct evdev_device *device, enum evdev_arbitration_state which, const struct phys_rect *phys_rect, uint64_t time) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); struct device_coord_rect rect = {0}; const char *state = NULL; if (which == dispatch->arbitration.state) return; switch (which) { case ARBITRATION_NOT_ACTIVE: /* if in-kernel arbitration is in use and there is a touch * and a pen in proximity, lifting the pen out of proximity * causes a touch begin for the touch. On a hand-lift the * proximity out precedes the touch up by a few ms, so we * get what looks like a tap. Fix this by delaying * arbitration by just a little bit so that any touch in * event is caught as palm touch. */ libinput_timer_set(&dispatch->arbitration.arbitration_timer, time + ms2us(90)); state = "not-active"; break; case ARBITRATION_IGNORE_RECT: assert(phys_rect); rect = evdev_phys_rect_to_units(device, phys_rect); cancel_touches(dispatch, device, &rect, time); dispatch->arbitration.rect = rect; state = "ignore-rect"; break; case ARBITRATION_IGNORE_ALL: libinput_timer_cancel(&dispatch->arbitration.arbitration_timer); fallback_return_to_neutral_state(dispatch, device); dispatch->arbitration.in_arbitration = true; state = "ignore-all"; break; } evdev_log_debug(device, "Touch arbitration state now %s\n", state); dispatch->arbitration.state = which; } static void fallback_interface_destroy(struct evdev_dispatch *evdev_dispatch) { struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch); libinput_timer_destroy(&dispatch->wheel.scroll_timer); libinput_timer_destroy(&dispatch->arbitration.arbitration_timer); libinput_timer_destroy(&dispatch->debounce.timer); libinput_timer_destroy(&dispatch->debounce.timer_short); free(dispatch->mt.slots); free(dispatch); } static void fallback_lid_pair_keyboard(struct evdev_device *lid_switch, struct evdev_device *keyboard) { struct fallback_dispatch *dispatch = fallback_dispatch(lid_switch->dispatch); struct evdev_paired_keyboard *kbd; size_t count = 0; if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0 || (lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0) return; if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0) return; list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) { count++; if (count > 3) { evdev_log_info(lid_switch, "lid: too many internal keyboards\n"); break; } } kbd = zalloc(sizeof(*kbd)); kbd->device = keyboard; libinput_device_init_event_listener(&kbd->listener); list_insert(&dispatch->lid.paired_keyboard_list, &kbd->link); evdev_log_debug(lid_switch, "lid: keyboard paired with %s<->%s\n", lid_switch->devname, keyboard->devname); /* We need to init the event listener now only if the * reported state is closed. */ if (dispatch->lid.is_closed) fallback_lid_toggle_keyboard_listener(dispatch, kbd, dispatch->lid.is_closed); } static void fallback_resume(struct fallback_dispatch *dispatch, struct evdev_device *device) { if (dispatch->base.sendevents.current_mode == LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) return; evdev_device_resume(device); } static void fallback_suspend(struct fallback_dispatch *dispatch, struct evdev_device *device) { evdev_device_suspend(device); } static void fallback_tablet_mode_switch_event(uint64_t time, struct libinput_event *event, void *data) { struct fallback_dispatch *dispatch = data; struct evdev_device *device = dispatch->device; struct libinput_event_switch *swev; if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) return; swev = libinput_event_get_switch_event(event); if (libinput_event_switch_get_switch(swev) != LIBINPUT_SWITCH_TABLET_MODE) return; switch (libinput_event_switch_get_switch_state(swev)) { case LIBINPUT_SWITCH_STATE_OFF: fallback_resume(dispatch, device); evdev_log_debug(device, "tablet-mode: resuming device\n"); break; case LIBINPUT_SWITCH_STATE_ON: fallback_suspend(dispatch, device); evdev_log_debug(device, "tablet-mode: suspending device\n"); break; } } static void fallback_pair_tablet_mode(struct evdev_device *keyboard, struct evdev_device *tablet_mode_switch) { struct fallback_dispatch *dispatch = fallback_dispatch(keyboard->dispatch); if ((keyboard->tags & EVDEV_TAG_EXTERNAL_KEYBOARD)) return; if ((keyboard->tags & EVDEV_TAG_TRACKPOINT)) { if (keyboard->tags & EVDEV_TAG_EXTERNAL_MOUSE) return; /* This filters out all internal keyboard-like devices (Video * Switch) */ } else if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0) { return; } if (evdev_device_has_model_quirk(keyboard, QUIRK_MODEL_TABLET_MODE_NO_SUSPEND)) return; if ((tablet_mode_switch->tags & EVDEV_TAG_TABLET_MODE_SWITCH) == 0) return; if (dispatch->tablet_mode.other.sw_device) return; evdev_log_debug(keyboard, "tablet-mode: paired %s<->%s\n", keyboard->devname, tablet_mode_switch->devname); libinput_device_add_event_listener(&tablet_mode_switch->base, &dispatch->tablet_mode.other.listener, fallback_tablet_mode_switch_event, dispatch); dispatch->tablet_mode.other.sw_device = tablet_mode_switch; if (evdev_device_switch_get_state(tablet_mode_switch, LIBINPUT_SWITCH_TABLET_MODE) == LIBINPUT_SWITCH_STATE_ON) { evdev_log_debug(keyboard, "tablet-mode: suspending device\n"); fallback_suspend(dispatch, keyboard); } } static void fallback_interface_device_added(struct evdev_device *device, struct evdev_device *added_device) { fallback_lid_pair_keyboard(device, added_device); fallback_pair_tablet_mode(device, added_device); } static void fallback_interface_device_removed(struct evdev_device *device, struct evdev_device *removed_device) { struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); struct evdev_paired_keyboard *kbd; list_for_each_safe(kbd, &dispatch->lid.paired_keyboard_list, link) { if (!kbd->device) continue; if (kbd->device != removed_device) continue; evdev_paired_keyboard_destroy(kbd); } if (removed_device == dispatch->tablet_mode.other.sw_device) { libinput_device_remove_event_listener( &dispatch->tablet_mode.other.listener); libinput_device_init_event_listener( &dispatch->tablet_mode.other.listener); dispatch->tablet_mode.other.sw_device = NULL; } } static struct evdev_dispatch_interface fallback_interface = { .process = fallback_interface_process, .suspend = fallback_interface_suspend, .remove = fallback_interface_remove, .destroy = fallback_interface_destroy, .device_added = fallback_interface_device_added, .device_removed = fallback_interface_device_removed, .device_suspended = fallback_interface_device_removed, /* treat as remove */ .device_resumed = fallback_interface_device_added, /* treat as add */ .post_added = fallback_interface_sync_initial_state, .touch_arbitration_toggle = fallback_interface_toggle_touch, .touch_arbitration_update_rect = fallback_interface_update_rect, .get_switch_state = fallback_interface_get_switch_state, }; static void fallback_change_to_left_handed(struct evdev_device *device) { struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); if (device->left_handed.want_enabled == device->left_handed.enabled) return; if (fallback_any_button_down(dispatch, device)) return; device->left_handed.enabled = device->left_handed.want_enabled; } static void fallback_change_scroll_method(struct evdev_device *device) { struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); if (device->scroll.want_method == device->scroll.method && device->scroll.want_button == device->scroll.button && device->scroll.want_lock_enabled == device->scroll.lock_enabled) return; if (fallback_any_button_down(dispatch, device)) return; device->scroll.method = device->scroll.want_method; device->scroll.button = device->scroll.want_button; device->scroll.lock_enabled = device->scroll.want_lock_enabled; evdev_set_button_scroll_lock_enabled(device, device->scroll.lock_enabled); } static int fallback_rotation_config_is_available(struct libinput_device *device) { /* This function only gets called when we support rotation */ return 1; } static enum libinput_config_status fallback_rotation_config_set_angle(struct libinput_device *libinput_device, unsigned int degrees_cw) { struct evdev_device *device = evdev_device(libinput_device); struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); dispatch->rotation.angle = degrees_cw; matrix_init_rotate(&dispatch->rotation.matrix, degrees_cw); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static unsigned int fallback_rotation_config_get_angle(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); return dispatch->rotation.angle; } static unsigned int fallback_rotation_config_get_default_angle(struct libinput_device *device) { return 0; } static void fallback_init_rotation(struct fallback_dispatch *dispatch, struct evdev_device *device) { if (device->tags & EVDEV_TAG_TRACKPOINT) return; dispatch->rotation.config.is_available = fallback_rotation_config_is_available; dispatch->rotation.config.set_angle = fallback_rotation_config_set_angle; dispatch->rotation.config.get_angle = fallback_rotation_config_get_angle; dispatch->rotation.config.get_default_angle = fallback_rotation_config_get_default_angle; matrix_init_identity(&dispatch->rotation.matrix); device->base.config.rotation = &dispatch->rotation.config; } static inline int fallback_dispatch_init_slots(struct fallback_dispatch *dispatch, struct evdev_device *device) { struct libevdev *evdev = device->evdev; struct mt_slot *slots; int num_slots; int active_slot; int slot; if (evdev_is_fake_mt_device(device) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) return 0; /* We only handle the slotted Protocol B in libinput. Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT require mtdev for conversion. */ if (evdev_need_mtdev(device)) { device->mtdev = mtdev_new_open(device->fd); if (!device->mtdev) return -1; /* pick 10 slots as default for type A devices. */ num_slots = 10; active_slot = device->mtdev->caps.slot.value; } else { num_slots = libevdev_get_num_slots(device->evdev); active_slot = libevdev_get_current_slot(evdev); } slots = zalloc(num_slots * sizeof(struct mt_slot)); for (slot = 0; slot < num_slots; ++slot) { slots[slot].seat_slot = -1; if (evdev_need_mtdev(device)) continue; slots[slot].point.x = libevdev_get_slot_value(evdev, slot, ABS_MT_POSITION_X); slots[slot].point.y = libevdev_get_slot_value(evdev, slot, ABS_MT_POSITION_Y); } dispatch->mt.slots = slots; dispatch->mt.slots_len = num_slots; dispatch->mt.slot = active_slot; dispatch->mt.has_palm = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOOL_TYPE); if (device->abs.absinfo_x->fuzz || device->abs.absinfo_y->fuzz) { dispatch->mt.want_hysteresis = true; dispatch->mt.hysteresis_margin.x = device->abs.absinfo_x->fuzz/2; dispatch->mt.hysteresis_margin.y = device->abs.absinfo_y->fuzz/2; } return 0; } static inline void fallback_dispatch_init_rel(struct fallback_dispatch *dispatch, struct evdev_device *device) { dispatch->rel.x = 0; dispatch->rel.y = 0; } static inline void fallback_dispatch_init_abs(struct fallback_dispatch *dispatch, struct evdev_device *device) { if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X)) return; dispatch->abs.point.x = device->abs.absinfo_x->value; dispatch->abs.point.y = device->abs.absinfo_y->value; dispatch->abs.seat_slot = -1; evdev_device_init_abs_range_warnings(device); } static inline void fallback_dispatch_init_switch(struct fallback_dispatch *dispatch, struct evdev_device *device) { int val; list_init(&dispatch->lid.paired_keyboard_list); if (device->tags & EVDEV_TAG_LID_SWITCH) { dispatch->lid.reliability = evdev_read_switch_reliability_prop(device); dispatch->lid.is_closed = false; } if (device->tags & EVDEV_TAG_TABLET_MODE_SWITCH) { val = libevdev_get_event_value(device->evdev, EV_SW, SW_TABLET_MODE); dispatch->tablet_mode.sw.state = val; } libinput_device_init_event_listener(&dispatch->tablet_mode.other.listener); } static void fallback_arbitration_timeout(uint64_t now, void *data) { struct fallback_dispatch *dispatch = data; if (dispatch->arbitration.in_arbitration) dispatch->arbitration.in_arbitration = false; evdev_log_debug(dispatch->device, "touch arbitration timeout\n"); } static void fallback_init_arbitration(struct fallback_dispatch *dispatch, struct evdev_device *device) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s arbitration", evdev_device_get_sysname(device)); libinput_timer_init(&dispatch->arbitration.arbitration_timer, evdev_libinput_context(device), timer_name, fallback_arbitration_timeout, dispatch); dispatch->arbitration.in_arbitration = false; } struct evdev_dispatch * fallback_dispatch_create(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); struct fallback_dispatch *dispatch; dispatch = zalloc(sizeof *dispatch); dispatch->device = evdev_device(libinput_device); dispatch->base.dispatch_type = DISPATCH_FALLBACK; dispatch->base.interface = &fallback_interface; dispatch->pending_event = EVDEV_NONE; list_init(&dispatch->lid.paired_keyboard_list); fallback_dispatch_init_rel(dispatch, device); fallback_dispatch_init_abs(dispatch, device); if (fallback_dispatch_init_slots(dispatch, device) == -1) { free(dispatch); return NULL; } fallback_dispatch_init_switch(dispatch, device); if (device->left_handed.want_enabled) evdev_init_left_handed(device, fallback_change_to_left_handed); if (device->scroll.want_button) evdev_init_button_scroll(device, fallback_change_scroll_method); if (device->scroll.natural_scrolling_enabled) evdev_init_natural_scroll(device); evdev_init_calibration(device, &dispatch->calibration); evdev_init_sendevents(device, &dispatch->base); fallback_init_rotation(dispatch, device); /* BTN_MIDDLE is set on mice even when it's not present. So * we can only use the absence of BTN_MIDDLE to mean something, i.e. * we enable it by default on anything that only has L&R. * If we have L&R and no middle, we don't expose it as config * option */ if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) && libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { bool has_middle = libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE); bool want_config = has_middle; bool enable_by_default = !has_middle; evdev_init_middlebutton(device, enable_by_default, want_config); } fallback_init_wheel(dispatch, device); fallback_init_debounce(dispatch); fallback_init_arbitration(dispatch, device); return &dispatch->base; } libinput-1.28.1/src/evdev-fallback.h000066400000000000000000000162171477265155700172710ustar00rootroot00000000000000/* * Copyright © 2010 Intel Corporation * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2017 Red Hat, Inc. * Copyright © 2017 James Ye * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #ifndef EVDEV_FALLBACK_H #define EVDEV_FALLBACK_H #include "evdev.h" enum debounce_state { DEBOUNCE_STATE_IS_UP = 100, DEBOUNCE_STATE_IS_DOWN, DEBOUNCE_STATE_IS_DOWN_WAITING, DEBOUNCE_STATE_IS_UP_DELAYING, DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS, DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS, DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS, DEBOUNCE_STATE_IS_UP_WAITING, DEBOUNCE_STATE_IS_DOWN_DELAYING, DEBOUNCE_STATE_DISABLED = 999, }; enum mt_slot_state { SLOT_STATE_NONE, SLOT_STATE_BEGIN, SLOT_STATE_UPDATE, SLOT_STATE_END, }; enum palm_state { PALM_NONE, PALM_NEW, PALM_IS_PALM, PALM_WAS_PALM, /* this touch sequence was a palm but isn't now */ }; enum wheel_state { WHEEL_STATE_NONE, WHEEL_STATE_ACCUMULATING_SCROLL, WHEEL_STATE_SCROLLING, }; enum wheel_direction { WHEEL_DIR_UNKNOW, WHEEL_DIR_VPOS, WHEEL_DIR_VNEG, WHEEL_DIR_HPOS, WHEEL_DIR_HNEG, }; struct mt_slot { bool dirty; enum mt_slot_state state; int32_t seat_slot; struct device_coords point; struct device_coords hysteresis_center; enum palm_state palm_state; }; struct fallback_dispatch { struct evdev_dispatch base; struct evdev_device *device; struct libinput_device_config_calibration calibration; struct { int angle; struct matrix matrix; struct libinput_device_config_rotation config; } rotation; struct { struct device_coords point; int32_t seat_slot; } abs; struct { int slot; struct mt_slot *slots; size_t slots_len; bool want_hysteresis; struct device_coords hysteresis_margin; bool has_palm; } mt; struct device_coords rel; struct { enum wheel_state state; struct device_coords lo_res; struct device_coords hi_res; bool emulate_hi_res_wheel; bool hi_res_event_received; struct libinput_timer scroll_timer; enum wheel_direction dir; } wheel; struct { /* The struct for the tablet mode switch device itself */ struct { int state; } sw; /* The struct for other devices listening to the tablet mode switch */ struct { struct evdev_device *sw_device; struct libinput_event_listener listener; } other; } tablet_mode; /* Bitmask of pressed keys used to ignore initial release events from * the kernel. */ unsigned long hw_key_mask[NLONGS(KEY_CNT)]; unsigned long last_hw_key_mask[NLONGS(KEY_CNT)]; enum evdev_event_type pending_event; struct { unsigned int button_code; uint64_t button_time; struct libinput_timer timer; struct libinput_timer timer_short; enum debounce_state state; bool spurious_enabled; } debounce; struct { enum switch_reliability reliability; bool is_closed; bool is_closed_client_state; /* We allow multiple paired keyboards for the lid switch * listener. Only one keyboard should exist, but that can * have more than one event node. And it's a list because * otherwise the test suite run fails too often. */ struct list paired_keyboard_list; } lid; /* pen/touch arbitration has a delayed state, * in_arbitration is what decides when to filter. */ struct { enum evdev_arbitration_state state; bool in_arbitration; struct device_coord_rect rect; struct libinput_timer arbitration_timer; } arbitration; }; static inline struct fallback_dispatch* fallback_dispatch(struct evdev_dispatch *dispatch) { evdev_verify_dispatch_type(dispatch, DISPATCH_FALLBACK); return container_of(dispatch, struct fallback_dispatch, base); } enum key_type { KEY_TYPE_NONE, KEY_TYPE_KEY, KEY_TYPE_BUTTON, }; static inline enum key_type get_key_type(uint16_t code) { switch (code) { case BTN_TOOL_PEN: case BTN_TOOL_RUBBER: case BTN_TOOL_BRUSH: case BTN_TOOL_PENCIL: case BTN_TOOL_AIRBRUSH: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: case BTN_TOOL_QUINTTAP: case BTN_TOOL_DOUBLETAP: case BTN_TOOL_TRIPLETAP: case BTN_TOOL_QUADTAP: case BTN_TOOL_FINGER: case BTN_TOUCH: return KEY_TYPE_NONE; } if (code >= KEY_ESC && code <= KEY_MICMUTE) return KEY_TYPE_KEY; if (code >= BTN_MISC && code <= BTN_GEAR_UP) return KEY_TYPE_BUTTON; if (code >= KEY_OK && code <= KEY_LIGHTS_TOGGLE) return KEY_TYPE_KEY; if (code >= BTN_DPAD_UP && code <= BTN_DPAD_RIGHT) return KEY_TYPE_BUTTON; if (code >= KEY_ALS_TOGGLE && code < BTN_TRIGGER_HAPPY) return KEY_TYPE_KEY; if (code >= BTN_TRIGGER_HAPPY && code <= BTN_TRIGGER_HAPPY40) return KEY_TYPE_BUTTON; return KEY_TYPE_NONE; } static inline void hw_set_key_down(struct fallback_dispatch *dispatch, int code, int pressed) { long_set_bit_state(dispatch->hw_key_mask, code, pressed); } static inline bool hw_key_has_changed(struct fallback_dispatch *dispatch, int code) { return long_bit_is_set(dispatch->hw_key_mask, code) != long_bit_is_set(dispatch->last_hw_key_mask, code); } static inline void hw_key_update_last_state(struct fallback_dispatch *dispatch) { static_assert(sizeof(dispatch->hw_key_mask) == sizeof(dispatch->last_hw_key_mask), "Mismatching key mask size"); memcpy(dispatch->last_hw_key_mask, dispatch->hw_key_mask, sizeof(dispatch->hw_key_mask)); } static inline bool hw_is_key_down(struct fallback_dispatch *dispatch, int code) { return long_bit_is_set(dispatch->hw_key_mask, code); } static inline int get_key_down_count(struct evdev_device *device, int code) { return device->key_count[code]; } void fallback_init_debounce(struct fallback_dispatch *dispatch); void fallback_debounce_handle_state(struct fallback_dispatch *dispatch, uint64_t time); void fallback_notify_physical_button(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state); void fallback_init_wheel(struct fallback_dispatch *dispatch, struct evdev_device *device); void fallback_wheel_process_relative(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time); void fallback_wheel_handle_state(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time); #endif libinput-1.28.1/src/evdev-middle-button.c000066400000000000000000000456411477265155700202770ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "evdev.h" #define MIDDLEBUTTON_TIMEOUT ms2us(50) /***************************************** * BEFORE YOU EDIT THIS FILE, look at the state diagram in * doc/middle-button-emulation-state-machine.svg (generated with * https://www.diagrams.net). * * Any changes in this file must be represented in the diagram. * * Note in regards to the state machine: it only handles left, right and * emulated middle button clicks, all other button events are passed * through. When in the PASSTHROUGH state, all events are passed through * as-is. */ static inline const char* middlebutton_state_to_str(enum evdev_middlebutton_state state) { switch (state) { CASE_RETURN_STRING(MIDDLEBUTTON_IDLE); CASE_RETURN_STRING(MIDDLEBUTTON_LEFT_DOWN); CASE_RETURN_STRING(MIDDLEBUTTON_RIGHT_DOWN); CASE_RETURN_STRING(MIDDLEBUTTON_MIDDLE); CASE_RETURN_STRING(MIDDLEBUTTON_LEFT_UP_PENDING); CASE_RETURN_STRING(MIDDLEBUTTON_RIGHT_UP_PENDING); CASE_RETURN_STRING(MIDDLEBUTTON_PASSTHROUGH); CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_LR); CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_L); CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_R); } return NULL; } static inline const char* middlebutton_event_to_str(enum evdev_middlebutton_event event) { switch (event) { CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_L_DOWN); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_R_DOWN); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_OTHER); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_L_UP); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_R_UP); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_TIMEOUT); CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_ALL_UP); } return NULL; } static void middlebutton_state_error(struct evdev_device *device, enum evdev_middlebutton_event event) { evdev_log_bug_libinput(device, "Invalid event %s in middle btn state %s\n", middlebutton_event_to_str(event), middlebutton_state_to_str(device->middlebutton.state)); } static void middlebutton_timer_set(struct evdev_device *device, uint64_t now) { libinput_timer_set(&device->middlebutton.timer, now + MIDDLEBUTTON_TIMEOUT); } static void middlebutton_timer_cancel(struct evdev_device *device) { libinput_timer_cancel(&device->middlebutton.timer); } static inline void middlebutton_set_state(struct evdev_device *device, enum evdev_middlebutton_state state, uint64_t now) { switch (state) { case MIDDLEBUTTON_LEFT_DOWN: case MIDDLEBUTTON_RIGHT_DOWN: middlebutton_timer_set(device, now); device->middlebutton.first_event_time = now; break; case MIDDLEBUTTON_IDLE: case MIDDLEBUTTON_MIDDLE: case MIDDLEBUTTON_LEFT_UP_PENDING: case MIDDLEBUTTON_RIGHT_UP_PENDING: case MIDDLEBUTTON_PASSTHROUGH: case MIDDLEBUTTON_IGNORE_LR: case MIDDLEBUTTON_IGNORE_L: case MIDDLEBUTTON_IGNORE_R: middlebutton_timer_cancel(device); break; } device->middlebutton.state = state; } static void middlebutton_post_event(struct evdev_device *device, uint64_t now, int button, enum libinput_button_state state) { evdev_pointer_notify_button(device, now, button, state); } static int evdev_middlebutton_idle_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_set_state(device, MIDDLEBUTTON_LEFT_DOWN, time); break; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_set_state(device, MIDDLEBUTTON_RIGHT_DOWN, time); break; case MIDDLEBUTTON_EVENT_OTHER: return 0; case MIDDLEBUTTON_EVENT_R_UP: case MIDDLEBUTTON_EVENT_L_UP: case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: break; } return 1; } static int evdev_middlebutton_ldown_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time); break; case MIDDLEBUTTON_EVENT_OTHER: middlebutton_post_event(device, time, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_post_event(device, device->middlebutton.first_event_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_post_event(device, time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_post_event(device, device->middlebutton.first_event_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_rdown_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time); break; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_OTHER: middlebutton_post_event(device, device->middlebutton.first_event_time, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_post_event(device, device->middlebutton.first_event_time, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_post_event(device, time, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_post_event(device, device->middlebutton.first_event_time, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_middle_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_OTHER: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_LR, time); return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); middlebutton_set_state(device, MIDDLEBUTTON_LEFT_UP_PENDING, time); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); middlebutton_set_state(device, MIDDLEBUTTON_RIGHT_UP_PENDING, time); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_lup_pending_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time); break; case MIDDLEBUTTON_EVENT_OTHER: middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_L, time); return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_rup_pending_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_post_event(device, time, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time); break; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_OTHER: middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_R, time); return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_passthrough_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: case MIDDLEBUTTON_EVENT_R_DOWN: case MIDDLEBUTTON_EVENT_OTHER: case MIDDLEBUTTON_EVENT_R_UP: case MIDDLEBUTTON_EVENT_L_UP: return 0; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time); break; } return 1; } static int evdev_middlebutton_ignore_lr_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_OTHER: return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_L, time); break; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_R, time); break; case MIDDLEBUTTON_EVENT_TIMEOUT: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_ignore_l_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_R_DOWN: return 0; case MIDDLEBUTTON_EVENT_OTHER: case MIDDLEBUTTON_EVENT_R_UP: return 0; case MIDDLEBUTTON_EVENT_L_UP: middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); break; case MIDDLEBUTTON_EVENT_TIMEOUT: case MIDDLEBUTTON_EVENT_ALL_UP: middlebutton_state_error(device, event); break; } return 1; } static int evdev_middlebutton_ignore_r_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { switch (event) { case MIDDLEBUTTON_EVENT_L_DOWN: return 0; case MIDDLEBUTTON_EVENT_R_DOWN: middlebutton_state_error(device, event); break; case MIDDLEBUTTON_EVENT_OTHER: return 0; case MIDDLEBUTTON_EVENT_R_UP: middlebutton_set_state(device, MIDDLEBUTTON_PASSTHROUGH, time); break; case MIDDLEBUTTON_EVENT_L_UP: return 0; case MIDDLEBUTTON_EVENT_TIMEOUT: case MIDDLEBUTTON_EVENT_ALL_UP: break; } return 1; } static int evdev_middlebutton_handle_event(struct evdev_device *device, uint64_t time, enum evdev_middlebutton_event event) { int rc = 0; enum evdev_middlebutton_state current; current = device->middlebutton.state; switch (current) { case MIDDLEBUTTON_IDLE: rc = evdev_middlebutton_idle_handle_event(device, time, event); break; case MIDDLEBUTTON_LEFT_DOWN: rc = evdev_middlebutton_ldown_handle_event(device, time, event); break; case MIDDLEBUTTON_RIGHT_DOWN: rc = evdev_middlebutton_rdown_handle_event(device, time, event); break; case MIDDLEBUTTON_MIDDLE: rc = evdev_middlebutton_middle_handle_event(device, time, event); break; case MIDDLEBUTTON_LEFT_UP_PENDING: rc = evdev_middlebutton_lup_pending_handle_event(device, time, event); break; case MIDDLEBUTTON_RIGHT_UP_PENDING: rc = evdev_middlebutton_rup_pending_handle_event(device, time, event); break; case MIDDLEBUTTON_PASSTHROUGH: rc = evdev_middlebutton_passthrough_handle_event(device, time, event); break; case MIDDLEBUTTON_IGNORE_LR: rc = evdev_middlebutton_ignore_lr_handle_event(device, time, event); break; case MIDDLEBUTTON_IGNORE_L: rc = evdev_middlebutton_ignore_l_handle_event(device, time, event); break; case MIDDLEBUTTON_IGNORE_R: rc = evdev_middlebutton_ignore_r_handle_event(device, time, event); break; default: evdev_log_bug_libinput(device, "Invalid middle button state %d\n", current); break; } evdev_log_debug(device, "middlebutton state: %s → %s → %s, rc %d\n", middlebutton_state_to_str(current), middlebutton_event_to_str(event), middlebutton_state_to_str(device->middlebutton.state), rc); return rc; } static inline void evdev_middlebutton_apply_config(struct evdev_device *device) { if (device->middlebutton.want_enabled == device->middlebutton.enabled) return; if (device->middlebutton.button_mask != 0) return; device->middlebutton.enabled = device->middlebutton.want_enabled; } bool evdev_middlebutton_filter_button(struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state) { enum evdev_middlebutton_event event; bool is_press = state == LIBINPUT_BUTTON_STATE_PRESSED; int rc; unsigned int btnbit = (button - BTN_LEFT); uint32_t old_mask = 0; if (!device->middlebutton.enabled) return false; switch (button) { case BTN_LEFT: if (is_press) event = MIDDLEBUTTON_EVENT_L_DOWN; else event = MIDDLEBUTTON_EVENT_L_UP; break; case BTN_RIGHT: if (is_press) event = MIDDLEBUTTON_EVENT_R_DOWN; else event = MIDDLEBUTTON_EVENT_R_UP; break; /* BTN_MIDDLE counts as "other" and resets middle button * emulation */ case BTN_MIDDLE: default: event = MIDDLEBUTTON_EVENT_OTHER; break; } if (button < BTN_LEFT || btnbit >= sizeof(device->middlebutton.button_mask) * 8) { evdev_log_bug_libinput(device, "Button mask too small for %s\n", libevdev_event_code_get_name(EV_KEY, button)); return true; } rc = evdev_middlebutton_handle_event(device, time, event); old_mask = device->middlebutton.button_mask; if (is_press) device->middlebutton.button_mask |= bit(btnbit); else device->middlebutton.button_mask &= ~bit(btnbit); if (old_mask != device->middlebutton.button_mask && device->middlebutton.button_mask == 0) { evdev_middlebutton_handle_event(device, time, MIDDLEBUTTON_EVENT_ALL_UP); evdev_middlebutton_apply_config(device); } return rc; } static void evdev_middlebutton_handle_timeout(uint64_t now, void *data) { struct evdev_device *device = evdev_device(data); evdev_middlebutton_handle_event(device, now, MIDDLEBUTTON_EVENT_TIMEOUT); } int evdev_middlebutton_is_available(struct libinput_device *device) { return 1; } static enum libinput_config_status evdev_middlebutton_set(struct libinput_device *device, enum libinput_config_middle_emulation_state enable) { struct evdev_device *evdev = evdev_device(device); switch (enable) { case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED: evdev->middlebutton.want_enabled = true; break; case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED: evdev->middlebutton.want_enabled = false; break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } evdev_middlebutton_apply_config(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } enum libinput_config_middle_emulation_state evdev_middlebutton_get(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); return evdev->middlebutton.want_enabled ? LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED : LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; } enum libinput_config_middle_emulation_state evdev_middlebutton_get_default(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); return evdev->middlebutton.enabled_default ? LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED : LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; } void evdev_init_middlebutton(struct evdev_device *device, bool enable, bool want_config) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s middlebutton", evdev_device_get_sysname(device)); libinput_timer_init(&device->middlebutton.timer, evdev_libinput_context(device), timer_name, evdev_middlebutton_handle_timeout, device); device->middlebutton.enabled_default = enable; device->middlebutton.want_enabled = enable; device->middlebutton.enabled = enable; if (!want_config) return; device->middlebutton.config.available = evdev_middlebutton_is_available; device->middlebutton.config.set = evdev_middlebutton_set; device->middlebutton.config.get = evdev_middlebutton_get; device->middlebutton.config.get_default = evdev_middlebutton_get_default; device->base.config.middle_emulation = &device->middlebutton.config; } libinput-1.28.1/src/evdev-mt-touchpad-buttons.c000066400000000000000000001116501477265155700214430ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "linux/input.h" #include "util-input-event.h" #include "evdev-mt-touchpad.h" #define DEFAULT_BUTTON_ENTER_TIMEOUT ms2us(100) #define DEFAULT_BUTTON_LEAVE_TIMEOUT ms2us(300) /***************************************** * BEFORE YOU EDIT THIS FILE, look at the state diagram in * doc/touchpad-softbutton-state-machine.svg (generated with * https://www.diagrams.net). * Any changes in this file must be represented in the diagram. * * The state machine only affects the soft button area code. */ static inline const char* button_state_to_str(enum button_state state) { switch(state) { CASE_RETURN_STRING(BUTTON_STATE_NONE); CASE_RETURN_STRING(BUTTON_STATE_AREA); CASE_RETURN_STRING(BUTTON_STATE_BOTTOM); CASE_RETURN_STRING(BUTTON_STATE_TOP); CASE_RETURN_STRING(BUTTON_STATE_TOP_NEW); CASE_RETURN_STRING(BUTTON_STATE_TOP_TO_IGNORE); CASE_RETURN_STRING(BUTTON_STATE_IGNORE); } return NULL; } static inline const char* button_event_to_str(enum button_event event) { switch(event) { CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_R); CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_M); CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_L); CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_R); CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_M); CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_L); CASE_RETURN_STRING(BUTTON_EVENT_IN_AREA); CASE_RETURN_STRING(BUTTON_EVENT_UP); CASE_RETURN_STRING(BUTTON_EVENT_PRESS); CASE_RETURN_STRING(BUTTON_EVENT_RELEASE); CASE_RETURN_STRING(BUTTON_EVENT_TIMEOUT); } return NULL; } static inline bool is_inside_bottom_button_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->point.y >= tp->buttons.bottom_area.top_edge; } static inline bool is_inside_bottom_right_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return is_inside_bottom_button_area(tp, t) && t->point.x > tp->buttons.bottom_area.rightbutton_left_edge; } static inline bool is_inside_bottom_middle_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return is_inside_bottom_button_area(tp, t) && !is_inside_bottom_right_area(tp, t) && t->point.x > tp->buttons.bottom_area.middlebutton_left_edge; } static inline bool is_inside_top_button_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->point.y <= tp->buttons.top_area.bottom_edge; } static inline bool is_inside_top_right_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return is_inside_top_button_area(tp, t) && t->point.x > tp->buttons.top_area.rightbutton_left_edge; } static inline bool is_inside_top_middle_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return is_inside_top_button_area(tp, t) && t->point.x >= tp->buttons.top_area.leftbutton_right_edge && t->point.x <= tp->buttons.top_area.rightbutton_left_edge; } static void tp_button_set_enter_timer(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { libinput_timer_set(&t->button.timer, time + DEFAULT_BUTTON_ENTER_TIMEOUT); } static void tp_button_set_leave_timer(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { libinput_timer_set(&t->button.timer, time + DEFAULT_BUTTON_LEAVE_TIMEOUT); } /* * tp_button_set_state, change state and implement on-entry behavior * as described in the state machine diagram. */ static void tp_button_set_state(struct tp_dispatch *tp, struct tp_touch *t, enum button_state new_state, enum button_event event, uint64_t time) { libinput_timer_cancel(&t->button.timer); t->button.state = new_state; switch (t->button.state) { case BUTTON_STATE_NONE: t->button.current = 0; break; case BUTTON_STATE_AREA: t->button.current = BUTTON_EVENT_IN_AREA; break; case BUTTON_STATE_BOTTOM: t->button.current = event; break; case BUTTON_STATE_TOP: break; case BUTTON_STATE_TOP_NEW: t->button.current = event; tp_button_set_enter_timer(tp, t, time); break; case BUTTON_STATE_TOP_TO_IGNORE: tp_button_set_leave_timer(tp, t, time); break; case BUTTON_STATE_IGNORE: t->button.current = 0; break; } } static void tp_button_none_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch (event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: tp_button_set_state(tp, t, BUTTON_STATE_BOTTOM, event, time); break; case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: tp_button_set_state(tp, t, BUTTON_STATE_TOP_NEW, event, time); break; case BUTTON_EVENT_IN_AREA: tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time); break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: case BUTTON_EVENT_RELEASE: case BUTTON_EVENT_TIMEOUT: break; } } static void tp_button_area_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch (event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: case BUTTON_EVENT_IN_AREA: break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: case BUTTON_EVENT_RELEASE: case BUTTON_EVENT_TIMEOUT: break; } } /** * Release any button in the bottom area, provided it started within a * threshold around start_time (i.e. simultaneously with the other touch * that triggered this call). */ static inline void tp_button_release_other_bottom_touches(struct tp_dispatch *tp, uint64_t other_start_time) { struct tp_touch *t; tp_for_each_touch(tp, t) { uint64_t tdelta; if (t->button.state != BUTTON_STATE_BOTTOM || t->button.has_moved) continue; if (other_start_time > t->button.initial_time) tdelta = other_start_time - t->button.initial_time; else tdelta = t->button.initial_time - other_start_time; if (tdelta > ms2us(80)) continue; t->button.has_moved = true; } } static void tp_button_bottom_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch (event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: if (event != t->button.current) tp_button_set_state(tp, t, BUTTON_STATE_BOTTOM, event, time); break; case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: case BUTTON_EVENT_IN_AREA: tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time); /* We just transitioned one finger from BOTTOM to AREA, * if there are other fingers in BOTTOM that started * simultaneously with this finger, release those fingers * because they're part of a gesture. */ tp_button_release_other_bottom_touches(tp, t->button.initial_time); break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: case BUTTON_EVENT_RELEASE: case BUTTON_EVENT_TIMEOUT: break; } } static void tp_button_top_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch (event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: tp_button_set_state(tp, t, BUTTON_STATE_TOP_TO_IGNORE, event, time); break; case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: if (event != t->button.current) tp_button_set_state(tp, t, BUTTON_STATE_TOP_NEW, event, time); break; case BUTTON_EVENT_IN_AREA: tp_button_set_state(tp, t, BUTTON_STATE_TOP_TO_IGNORE, event, time); break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: case BUTTON_EVENT_RELEASE: case BUTTON_EVENT_TIMEOUT: break; } } static void tp_button_top_new_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch(event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time); break; case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: if (event != t->button.current) tp_button_set_state(tp, t, BUTTON_STATE_TOP_NEW, event, time); break; case BUTTON_EVENT_IN_AREA: tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time); break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: tp_button_set_state(tp, t, BUTTON_STATE_TOP, event, time); break; case BUTTON_EVENT_RELEASE: break; case BUTTON_EVENT_TIMEOUT: tp_button_set_state(tp, t, BUTTON_STATE_TOP, event, time); break; } } static void tp_button_top_to_ignore_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch(event) { case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: if (event == t->button.current) tp_button_set_state(tp, t, BUTTON_STATE_TOP, event, time); else tp_button_set_state(tp, t, BUTTON_STATE_TOP_NEW, event, time); break; case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: case BUTTON_EVENT_IN_AREA: break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: case BUTTON_EVENT_RELEASE: break; case BUTTON_EVENT_TIMEOUT: tp_button_set_state(tp, t, BUTTON_STATE_IGNORE, event, time); break; } } static void tp_button_ignore_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { switch (event) { case BUTTON_EVENT_IN_BOTTOM_R: case BUTTON_EVENT_IN_BOTTOM_M: case BUTTON_EVENT_IN_BOTTOM_L: case BUTTON_EVENT_IN_TOP_R: case BUTTON_EVENT_IN_TOP_M: case BUTTON_EVENT_IN_TOP_L: case BUTTON_EVENT_IN_AREA: break; case BUTTON_EVENT_UP: tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time); break; case BUTTON_EVENT_PRESS: t->button.current = BUTTON_EVENT_IN_AREA; break; case BUTTON_EVENT_RELEASE: break; case BUTTON_EVENT_TIMEOUT: break; } } static void tp_button_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum button_event event, uint64_t time) { enum button_state current = t->button.state; switch(t->button.state) { case BUTTON_STATE_NONE: tp_button_none_handle_event(tp, t, event, time); break; case BUTTON_STATE_AREA: tp_button_area_handle_event(tp, t, event, time); break; case BUTTON_STATE_BOTTOM: tp_button_bottom_handle_event(tp, t, event, time); break; case BUTTON_STATE_TOP: tp_button_top_handle_event(tp, t, event, time); break; case BUTTON_STATE_TOP_NEW: tp_button_top_new_handle_event(tp, t, event, time); break; case BUTTON_STATE_TOP_TO_IGNORE: tp_button_top_to_ignore_handle_event(tp, t, event, time); break; case BUTTON_STATE_IGNORE: tp_button_ignore_handle_event(tp, t, event, time); break; } if (current != t->button.state) evdev_log_debug(tp->device, "button state: touch %d from %-20s event %-24s to %-20s\n", t->index, button_state_to_str(current), button_event_to_str(event), button_state_to_str(t->button.state)); } static inline void tp_button_check_for_movement(struct tp_dispatch *tp, struct tp_touch *t) { struct device_coords delta; struct phys_coords mm; double vector_length; if (t->button.has_moved) return; switch (t->button.state) { case BUTTON_STATE_NONE: case BUTTON_STATE_AREA: case BUTTON_STATE_TOP: case BUTTON_STATE_TOP_NEW: case BUTTON_STATE_TOP_TO_IGNORE: case BUTTON_STATE_IGNORE: /* No point calculating if we're not going to use it */ return; case BUTTON_STATE_BOTTOM: break; } delta.x = t->point.x - t->button.initial.x; delta.y = t->point.y - t->button.initial.y; mm = evdev_device_unit_delta_to_mm(tp->device, &delta); vector_length = hypot(mm.x, mm.y); if (vector_length > 5.0 /* mm */) { t->button.has_moved = true; tp_button_release_other_bottom_touches(tp, t->button.initial_time); } } void tp_button_handle_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE || t->state == TOUCH_HOVERING) continue; if (t->state == TOUCH_BEGIN) { t->button.initial = t->point; t->button.initial_time = time; t->button.has_moved = false; } if (t->state == TOUCH_END) { tp_button_handle_event(tp, t, BUTTON_EVENT_UP, time); } else if (t->dirty) { enum button_event event; if (is_inside_bottom_button_area(tp, t)) { if (is_inside_bottom_right_area(tp, t)) event = BUTTON_EVENT_IN_BOTTOM_R; else if (is_inside_bottom_middle_area(tp, t)) event = BUTTON_EVENT_IN_BOTTOM_M; else event = BUTTON_EVENT_IN_BOTTOM_L; /* In the bottom area we check for movement * within the area. Top area - meh */ tp_button_check_for_movement(tp, t); } else if (is_inside_top_button_area(tp, t)) { if (is_inside_top_right_area(tp, t)) event = BUTTON_EVENT_IN_TOP_R; else if (is_inside_top_middle_area(tp, t)) event = BUTTON_EVENT_IN_TOP_M; else event = BUTTON_EVENT_IN_TOP_L; } else { event = BUTTON_EVENT_IN_AREA; } tp_button_handle_event(tp, t, event, time); } if (tp->queued & TOUCHPAD_EVENT_BUTTON_RELEASE) tp_button_handle_event(tp, t, BUTTON_EVENT_RELEASE, time); if (tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) tp_button_handle_event(tp, t, BUTTON_EVENT_PRESS, time); } } static void tp_button_handle_timeout(uint64_t now, void *data) { struct tp_touch *t = data; tp_button_handle_event(t->tp, t, BUTTON_EVENT_TIMEOUT, now); } void tp_process_button(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { uint32_t mask = bit(e->code - BTN_LEFT); /* Ignore other buttons on clickpads */ if (tp->buttons.is_clickpad && e->code != BTN_LEFT) { evdev_log_bug_kernel(tp->device, "received %s button event on a clickpad\n", libevdev_event_code_get_name(EV_KEY, e->code)); return; } if (e->value) { tp->buttons.state |= mask; tp->queued |= TOUCHPAD_EVENT_BUTTON_PRESS; } else { tp->buttons.state &= ~mask; tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE; } } void tp_release_all_buttons(struct tp_dispatch *tp, uint64_t time) { if (tp->buttons.state) { tp->buttons.state = 0; tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE; } } static void tp_init_softbuttons(struct tp_dispatch *tp, struct evdev_device *device) { double width, height; struct device_coords edges; int mb_le, mb_re; /* middle button left/right edge */ struct phys_coords mm = { 0.0, 0.0 }; evdev_device_get_size(device, &width, &height); /* button height: 10mm or 15% or the touchpad height, whichever is smaller */ if (height * 0.15 > 10) mm.y = height - 10; else mm.y = height * 0.85; mm.x = width * 0.5; edges = evdev_device_mm_to_units(device, &mm); tp->buttons.bottom_area.top_edge = edges.y; tp->buttons.bottom_area.rightbutton_left_edge = edges.x; tp->buttons.bottom_area.middlebutton_left_edge = INT_MAX; /* if middlebutton emulation is enabled, don't init a software area */ if (device->middlebutton.want_enabled) return; /* The middle button is 25% of the touchpad and centered. Many * touchpads don't have markings for the middle button at all so we * need to make it big enough to reliably hit it but not too big so * it takes away all the space. * * On touchpads with visible markings we reduce the size of the * middle button since users have a visual guide. */ if (evdev_device_has_model_quirk(device, QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER)) { mm.x = width/2 - 5; /* 10mm wide */ edges = evdev_device_mm_to_units(device, &mm); mb_le = edges.x; mm.x = width/2 + 5; /* 10mm wide */ edges = evdev_device_mm_to_units(device, &mm); mb_re = edges.x; } else { mm.x = width * 0.375; edges = evdev_device_mm_to_units(device, &mm); mb_le = edges.x; mm.x = width * 0.625; edges = evdev_device_mm_to_units(device, &mm); mb_re = edges.x; } tp->buttons.bottom_area.middlebutton_left_edge = mb_le; tp->buttons.bottom_area.rightbutton_left_edge = mb_re; } void tp_init_top_softbuttons(struct tp_dispatch *tp, struct evdev_device *device, double topbutton_size_mult) { struct device_coords edges; if (tp->buttons.has_topbuttons) { /* T440s has the top button line 5mm from the top, event analysis has shown events to start down to ~10mm from the top - which maps to 15%. We allow the caller to enlarge the area using a multiplier for the touchpad disabled case. */ double topsize_mm = 10 * topbutton_size_mult; struct phys_coords mm; double width, height; evdev_device_get_size(device, &width, &height); mm.x = width * 0.60; mm.y = topsize_mm; edges = evdev_device_mm_to_units(device, &mm); tp->buttons.top_area.bottom_edge = edges.y; tp->buttons.top_area.rightbutton_left_edge = edges.x; mm.x = width * 0.40; edges = evdev_device_mm_to_units(device, &mm); tp->buttons.top_area.leftbutton_right_edge = edges.x; } else { tp->buttons.top_area.bottom_edge = INT_MIN; } } static inline uint32_t tp_button_config_click_get_methods(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; uint32_t methods = LIBINPUT_CONFIG_CLICK_METHOD_NONE; if (tp->buttons.is_clickpad) { methods |= LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; if (tp->has_mt) methods |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; } if (evdev->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) methods |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; return methods; } static void tp_switch_click_method(struct tp_dispatch *tp) { /* * All we need to do when switching click methods is to change the * bottom_area.top_edge so that when in clickfinger mode the bottom * touchpad area is not dead wrt finger movement starting there. * * We do not need to take any state into account, fingers which are * already down will simply keep the state / area they have assigned * until they are released, and the post_button_events path is state * agnostic. */ switch (tp->buttons.click_method) { case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS: tp_init_softbuttons(tp, tp->device); break; case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER: case LIBINPUT_CONFIG_CLICK_METHOD_NONE: tp->buttons.bottom_area.top_edge = INT_MAX; break; } } static enum libinput_config_status tp_button_config_click_set_method(struct libinput_device *device, enum libinput_config_click_method method) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; tp->buttons.click_method = method; tp_switch_click_method(tp); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_click_method tp_button_config_click_get_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp->buttons.click_method; } static enum libinput_config_click_method tp_click_get_default_method(struct tp_dispatch *tp) { struct evdev_device *device = tp->device; if (evdev_device_has_model_quirk(device, QUIRK_MODEL_CHROMEBOOK) || evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_BONOBO) || evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_GALAGO) || evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_KUDU) || evdev_device_has_model_quirk(device, QUIRK_MODEL_CLEVO_W740SU) || evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON)) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; if (!tp->buttons.is_clickpad) return LIBINPUT_CONFIG_CLICK_METHOD_NONE; if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD)) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; } static enum libinput_config_click_method tp_button_config_click_get_default_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp_click_get_default_method(tp); } void tp_clickpad_middlebutton_apply_config(struct evdev_device *device) { struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch; if (!tp->buttons.is_clickpad || tp->buttons.state != 0) return; if (device->middlebutton.want_enabled == device->middlebutton.enabled) return; device->middlebutton.enabled = device->middlebutton.want_enabled; if (tp->buttons.click_method == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) tp_init_softbuttons(tp, device); } static int tp_clickpad_middlebutton_is_available(struct libinput_device *device) { return evdev_middlebutton_is_available(device); } static enum libinput_config_status tp_clickpad_middlebutton_set(struct libinput_device *device, enum libinput_config_middle_emulation_state enable) { struct evdev_device *evdev = evdev_device(device); switch (enable) { case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED: evdev->middlebutton.want_enabled = true; break; case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED: evdev->middlebutton.want_enabled = false; break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } tp_clickpad_middlebutton_apply_config(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_middle_emulation_state tp_clickpad_middlebutton_get(struct libinput_device *device) { return evdev_middlebutton_get(device); } static enum libinput_config_middle_emulation_state tp_clickpad_middlebutton_get_default(struct libinput_device *device) { return evdev_middlebutton_get_default(device); } static inline void tp_init_clickpad_middlebutton_emulation(struct tp_dispatch *tp, struct evdev_device *device) { device->middlebutton.enabled_default = false; device->middlebutton.want_enabled = false; device->middlebutton.enabled = false; device->middlebutton.config.available = tp_clickpad_middlebutton_is_available; device->middlebutton.config.set = tp_clickpad_middlebutton_set; device->middlebutton.config.get = tp_clickpad_middlebutton_get; device->middlebutton.config.get_default = tp_clickpad_middlebutton_get_default; device->base.config.middle_emulation = &device->middlebutton.config; } static inline void tp_init_middlebutton_emulation(struct tp_dispatch *tp, struct evdev_device *device) { bool enable_by_default, want_config_option; /* On clickpads we provide the config option but disable by default. When enabled, the middle software button disappears */ if (tp->buttons.is_clickpad) { tp_init_clickpad_middlebutton_emulation(tp, device); return; } /* init middle button emulation on non-clickpads, but only if we * don't have a middle button. Exception: ALPS touchpads don't know * if they have a middle button, so we always want the option there * and enabled by default. */ if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE)) { enable_by_default = true; want_config_option = false; } else if (evdev_device_has_model_quirk(device, QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD)) { enable_by_default = true; want_config_option = true; } else return; evdev_init_middlebutton(tp->device, enable_by_default, want_config_option); } static bool tp_guess_clickpad(const struct tp_dispatch *tp, struct evdev_device *device) { bool is_clickpad; bool has_left = libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT), has_middle = libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE), has_right = libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT); is_clickpad = libevdev_has_property(device->evdev, INPUT_PROP_BUTTONPAD); /* A non-clickpad without a right button is a clickpad, assume the * kernel is wrong. * Exceptions here: * - The one-button Apple touchpad (discontinued in 2008) has a * single physical button * - Wacom touch devices have neither left nor right buttons */ if (!is_clickpad && has_left && !has_right && (tp->device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) == 0) { evdev_log_bug_kernel(device, "missing right button, assuming it is a clickpad.\n"); is_clickpad = true; } if (has_middle || has_right) { if (is_clickpad) evdev_log_bug_kernel(device, "clickpad advertising right button. " "See %s/clickpad-with-right-button.html for details\n", HTTP_DOC_LINK); } else if (has_left && !is_clickpad && libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) { evdev_log_bug_kernel(device, "non clickpad without right button?\n"); } return is_clickpad; } static inline void tp_button_update_clickfinger_map(struct tp_dispatch *tp) { if (tp->buttons.state != BUTTON_STATE_NONE) return; if (tp->buttons.map != tp->buttons.want_map) tp->buttons.map = tp->buttons.want_map; } void tp_button_post_process_state(struct tp_dispatch *tp) { tp_button_update_clickfinger_map(tp); } static enum libinput_config_status tp_button_config_set_clickfinger_map(struct libinput_device *device, enum libinput_config_clickfinger_button_map map) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); tp->buttons.want_map = map; tp_button_update_clickfinger_map(tp); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_clickfinger_button_map tp_button_config_get_clickfinger_map(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->buttons.want_map; } static enum libinput_config_clickfinger_button_map tp_button_config_get_default_clickfinger_map(struct libinput_device *device) { return LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; } void tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device) { struct tp_touch *t; const struct input_absinfo *absinfo_x, *absinfo_y; int i; tp->buttons.is_clickpad = tp_guess_clickpad(tp, device); tp->buttons.has_topbuttons = libevdev_has_property(device->evdev, INPUT_PROP_TOPBUTTONPAD); absinfo_x = device->abs.absinfo_x; absinfo_y = device->abs.absinfo_y; /* pinned-finger motion threshold, see tp_unpin_finger. */ tp->buttons.motion_dist.x_scale_coeff = 1.0/absinfo_x->resolution; tp->buttons.motion_dist.y_scale_coeff = 1.0/absinfo_y->resolution; tp->buttons.config_method.get_methods = tp_button_config_click_get_methods; tp->buttons.config_method.set_method = tp_button_config_click_set_method; tp->buttons.config_method.get_method = tp_button_config_click_get_method; tp->buttons.config_method.get_default_method = tp_button_config_click_get_default_method; tp->buttons.config_method.set_clickfinger_map = tp_button_config_set_clickfinger_map; tp->buttons.config_method.get_clickfinger_map = tp_button_config_get_clickfinger_map; tp->buttons.config_method.get_default_clickfinger_map = tp_button_config_get_default_clickfinger_map; tp->device->base.config.click_method = &tp->buttons.config_method; tp->buttons.map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; tp->buttons.want_map = tp->buttons.map; tp->buttons.click_method = tp_click_get_default_method(tp); tp_switch_click_method(tp); tp_init_top_softbuttons(tp, device, 1.0); tp_init_middlebutton_emulation(tp, device); i = 0; tp_for_each_touch(tp, t) { char timer_name[64]; i++; snprintf(timer_name, sizeof(timer_name), "%s (%d) button", evdev_device_get_sysname(device), i); t->button.state = BUTTON_STATE_NONE; libinput_timer_init(&t->button.timer, tp_libinput_context(tp), timer_name, tp_button_handle_timeout, t); } } void tp_remove_buttons(struct tp_dispatch *tp) { struct tp_touch *t; tp_for_each_touch(tp, t) { libinput_timer_cancel(&t->button.timer); libinput_timer_destroy(&t->button.timer); } } static int tp_post_physical_buttons(struct tp_dispatch *tp, uint64_t time) { uint32_t current, old, button; current = tp->buttons.state; old = tp->buttons.old_state; button = BTN_LEFT; while (current || old) { enum libinput_button_state state; if ((current & 0x1) ^ (old & 0x1)) { uint32_t b; if (!!(current & 0x1)) state = LIBINPUT_BUTTON_STATE_PRESSED; else state = LIBINPUT_BUTTON_STATE_RELEASED; b = evdev_to_left_handed(tp->device, button); evdev_pointer_notify_physical_button(tp->device, time, b, state); } button++; current >>= 1; old >>= 1; } return 0; } static inline bool tp_clickfinger_within_distance(struct tp_dispatch *tp, struct tp_touch *t1, struct tp_touch *t2) { double x, y; bool within_distance = false; int xres, yres; int bottom_threshold; if (!t1 || !t2) return 0; if (tp_thumb_ignored(tp, t1) || tp_thumb_ignored(tp, t2)) return 0; x = abs(t1->point.x - t2->point.x); y = abs(t1->point.y - t2->point.y); xres = tp->device->abs.absinfo_x->resolution; yres = tp->device->abs.absinfo_y->resolution; x /= xres; y /= yres; /* maximum horiz spread is 40mm horiz, 30mm vert, anything wider * than that is probably a gesture. */ if (x > 40 || y > 30) goto out; within_distance = true; /* if y spread is <= 20mm, they're definitely together. */ if (y <= 20) goto out; /* if they're vertically spread between 20-40mm, they're not * together if: * - the touchpad's vertical size is >50mm, anything smaller is * unlikely to have a thumb resting on it * - and one of the touches is in the bottom 20mm of the touchpad * and the other one isn't */ if (tp->device->abs.dimensions.y/yres < 50) goto out; bottom_threshold = tp->device->abs.absinfo_y->maximum - 20 * yres; if ((t1->point.y > bottom_threshold) != (t2->point.y > bottom_threshold)) within_distance = 0; out: return within_distance; } static uint32_t tp_clickfinger_set_button(struct tp_dispatch *tp) { uint32_t button; unsigned int nfingers = 0; struct tp_touch *t; struct tp_touch *first = NULL, *second = NULL; int32_t button_map[2][3] = { { BTN_LEFT, BTN_RIGHT, BTN_MIDDLE }, { BTN_LEFT, BTN_MIDDLE, BTN_RIGHT }, }; tp_for_each_touch(tp, t) { if (t->state != TOUCH_BEGIN && t->state != TOUCH_UPDATE) continue; if (tp_thumb_ignored(tp, t)) continue; if (t->palm.state != PALM_NONE) continue; nfingers++; if (!first) first = t; else if (!second) second = t; } /* Only check for finger distance when there are 2 fingers on the * touchpad */ if (nfingers != 2) goto out; if (tp_clickfinger_within_distance(tp, first, second)) nfingers = 2; else nfingers = 1; out: nfingers = max(1, nfingers); switch (nfingers) { case 1: case 2: case 3: button = button_map[tp->buttons.map][nfingers-1]; break; default: button = 0; break; } return button; } static int tp_notify_clickpadbutton(struct tp_dispatch *tp, uint64_t time, uint32_t button, uint32_t is_topbutton, enum libinput_button_state state) { /* If we've a trackpoint, send top buttons through the trackpoint */ if (tp->buttons.trackpoint) { if (is_topbutton) { struct evdev_dispatch *dispatch = tp->buttons.trackpoint->dispatch; struct input_event event, syn_report; int value; value = (state == LIBINPUT_BUTTON_STATE_PRESSED) ? 1 : 0; event = input_event_init(time, EV_KEY, button, value); syn_report = input_event_init(time, EV_SYN, SYN_REPORT, 0); dispatch->interface->process(dispatch, tp->buttons.trackpoint, &event, time); dispatch->interface->process(dispatch, tp->buttons.trackpoint, &syn_report, time); return 1; } /* Ignore button events not for the trackpoint while suspended */ if (tp->device->is_suspended) return 0; } /* A button click always terminates edge scrolling, even if we * don't end up sending a button event. */ tp_edge_scroll_stop_events(tp, time); /* * If the user has requested clickfinger replace the button chosen * by the softbutton code with one based on the number of fingers. */ if (tp->buttons.click_method == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER && state == LIBINPUT_BUTTON_STATE_PRESSED) { button = tp_clickfinger_set_button(tp); tp->buttons.active = button; if (!button) return 0; } evdev_pointer_notify_button(tp->device, time, button, state); return 1; } static int tp_post_clickpadbutton_buttons(struct tp_dispatch *tp, uint64_t time) { uint32_t current, old, button, is_top; enum libinput_button_state state; enum { AREA = 0x01, LEFT = 0x02, MIDDLE = 0x04, RIGHT = 0x08 }; bool want_left_handed = true; current = tp->buttons.state; old = tp->buttons.old_state; is_top = 0; if (!tp->buttons.click_pending && current == old) return 0; if (current) { struct tp_touch *t; uint32_t area = 0; if (evdev_device_has_model_quirk(tp->device, QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS) && tp->nactive_slots == 0) { /* Some touchpads, notably those on the Dell XPS 15 9500, * are prone to registering touchpad clicks when the * case is sufficiently flexed. Ignore these by * disregarding any clicks that are registered without * touchpad touch. */ tp->buttons.click_pending = true; return 0; } tp_for_each_touch(tp, t) { switch (t->button.current) { case BUTTON_EVENT_IN_AREA: area |= AREA; break; case BUTTON_EVENT_IN_TOP_L: is_top = 1; _fallthrough_; case BUTTON_EVENT_IN_BOTTOM_L: area |= LEFT; break; case BUTTON_EVENT_IN_TOP_M: is_top = 1; _fallthrough_; case BUTTON_EVENT_IN_BOTTOM_M: area |= MIDDLE; break; case BUTTON_EVENT_IN_TOP_R: is_top = 1; _fallthrough_; case BUTTON_EVENT_IN_BOTTOM_R: area |= RIGHT; break; default: break; } } if (area == 0 && tp->buttons.click_method != LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) { /* No touches, wait for a touch before processing */ tp->buttons.click_pending = true; return 0; } if ((tp->device->middlebutton.enabled || is_top) && (area & LEFT) && (area & RIGHT)) { button = BTN_MIDDLE; } else if (area & MIDDLE) { button = BTN_MIDDLE; } else if (area & RIGHT) { button = BTN_RIGHT; } else if (area & LEFT) { button = BTN_LEFT; } else { /* main or no area (for clickfinger) is always BTN_LEFT */ button = BTN_LEFT; want_left_handed = false; } if (is_top) want_left_handed = false; if (want_left_handed) button = evdev_to_left_handed(tp->device, button); tp->buttons.active = button; tp->buttons.active_is_topbutton = is_top; state = LIBINPUT_BUTTON_STATE_PRESSED; } else { button = tp->buttons.active; is_top = tp->buttons.active_is_topbutton; tp->buttons.active = 0; tp->buttons.active_is_topbutton = 0; state = LIBINPUT_BUTTON_STATE_RELEASED; } tp->buttons.click_pending = false; if (button) return tp_notify_clickpadbutton(tp, time, button, is_top, state); return 0; } int tp_post_button_events(struct tp_dispatch *tp, uint64_t time) { if (tp->buttons.is_clickpad || tp->device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) return tp_post_clickpadbutton_buttons(tp, time); return tp_post_physical_buttons(tp, time); } bool tp_button_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->button.state == BUTTON_STATE_AREA || t->button.has_moved; } bool tp_button_is_inside_softbutton_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return is_inside_top_button_area(tp, t) || is_inside_bottom_button_area(tp, t); } libinput-1.28.1/src/evdev-mt-touchpad-edge-scroll.c000066400000000000000000000320641477265155700221460ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "evdev-mt-touchpad.h" /* Use a reasonably large threshold until locked into scrolling mode, to avoid accidentally locking in scrolling mode when trying to use the entire touchpad to move the pointer. The user can wait for the timeout to trigger to do a small scroll. */ #define DEFAULT_SCROLL_THRESHOLD TP_MM_TO_DPI_NORMALIZED(3) enum scroll_event { SCROLL_EVENT_TOUCH, SCROLL_EVENT_MOTION, SCROLL_EVENT_RELEASE, SCROLL_EVENT_TIMEOUT, SCROLL_EVENT_POSTED, }; static inline const char* edge_state_to_str(enum tp_edge_scroll_touch_state state) { switch (state) { CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_NONE); CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_EDGE_NEW); CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_EDGE); CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_AREA); } return NULL; } static inline const char* edge_event_to_str(enum scroll_event event) { switch (event) { CASE_RETURN_STRING(SCROLL_EVENT_TOUCH); CASE_RETURN_STRING(SCROLL_EVENT_MOTION); CASE_RETURN_STRING(SCROLL_EVENT_RELEASE); CASE_RETURN_STRING(SCROLL_EVENT_TIMEOUT); CASE_RETURN_STRING(SCROLL_EVENT_POSTED); } return NULL; } uint32_t tp_touch_get_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { uint32_t edge = EDGE_NONE; if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE) return EDGE_NONE; if (t->point.x > tp->scroll.right_edge) edge |= EDGE_RIGHT; if (t->point.y > tp->scroll.bottom_edge) edge |= EDGE_BOTTOM; return edge; } static inline void tp_edge_scroll_set_timer(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { const int DEFAULT_SCROLL_LOCK_TIMEOUT = ms2us(300); /* if we use software buttons, we disable timeout-based * edge scrolling. A finger resting on the button areas is * likely there to trigger a button event. */ if (tp->buttons.click_method == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) return; libinput_timer_set(&t->scroll.timer, time + DEFAULT_SCROLL_LOCK_TIMEOUT); } static void tp_edge_scroll_set_state(struct tp_dispatch *tp, struct tp_touch *t, enum tp_edge_scroll_touch_state state, uint64_t time) { libinput_timer_cancel(&t->scroll.timer); t->scroll.edge_state = state; switch (state) { case EDGE_SCROLL_TOUCH_STATE_NONE: t->scroll.edge = EDGE_NONE; break; case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW: t->scroll.edge = tp_touch_get_edge(tp, t); t->scroll.initial = t->point; tp_edge_scroll_set_timer(tp, t, time); break; case EDGE_SCROLL_TOUCH_STATE_EDGE: break; case EDGE_SCROLL_TOUCH_STATE_AREA: t->scroll.edge = EDGE_NONE; break; } } static void tp_edge_scroll_handle_none(struct tp_dispatch *tp, struct tp_touch *t, enum scroll_event event, uint64_t time) { switch (event) { case SCROLL_EVENT_TOUCH: if (tp_touch_get_edge(tp, t)) { tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_EDGE_NEW, time); } else { tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_AREA, time); } break; case SCROLL_EVENT_MOTION: case SCROLL_EVENT_RELEASE: case SCROLL_EVENT_TIMEOUT: case SCROLL_EVENT_POSTED: evdev_log_bug_libinput(tp->device, "edge-scroll: touch %d: unexpected scroll event %d in none state\n", t->index, event); break; } } static void tp_edge_scroll_handle_edge_new(struct tp_dispatch *tp, struct tp_touch *t, enum scroll_event event, uint64_t time) { switch (event) { case SCROLL_EVENT_TOUCH: evdev_log_bug_libinput(tp->device, "edge-scroll: touch %d: unexpected scroll event %d in edge new state\n", t->index, event); break; case SCROLL_EVENT_MOTION: t->scroll.edge &= tp_touch_get_edge(tp, t); if (!t->scroll.edge) tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_AREA, time); break; case SCROLL_EVENT_RELEASE: tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_NONE, time); break; case SCROLL_EVENT_TIMEOUT: case SCROLL_EVENT_POSTED: tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_EDGE, time); break; } } static void tp_edge_scroll_handle_edge(struct tp_dispatch *tp, struct tp_touch *t, enum scroll_event event, uint64_t time) { switch (event) { case SCROLL_EVENT_TOUCH: case SCROLL_EVENT_TIMEOUT: evdev_log_bug_libinput(tp->device, "edge-scroll: touch %d: unexpected scroll event %d in edge state\n", t->index, event); break; case SCROLL_EVENT_MOTION: /* If started at the bottom right, decide in which dir to scroll */ if (t->scroll.edge == (EDGE_RIGHT | EDGE_BOTTOM)) { t->scroll.edge &= tp_touch_get_edge(tp, t); if (!t->scroll.edge) tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_AREA, time); } break; case SCROLL_EVENT_RELEASE: tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_NONE, time); break; case SCROLL_EVENT_POSTED: break; } } static void tp_edge_scroll_handle_area(struct tp_dispatch *tp, struct tp_touch *t, enum scroll_event event, uint64_t time) { switch (event) { case SCROLL_EVENT_TOUCH: case SCROLL_EVENT_TIMEOUT: case SCROLL_EVENT_POSTED: evdev_log_bug_libinput(tp->device, "unexpected scroll event %d in area state\n", event); break; case SCROLL_EVENT_MOTION: break; case SCROLL_EVENT_RELEASE: tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_NONE, time); break; } } static void tp_edge_scroll_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum scroll_event event, uint64_t time) { enum tp_edge_scroll_touch_state current = t->scroll.edge_state; switch (current) { case EDGE_SCROLL_TOUCH_STATE_NONE: tp_edge_scroll_handle_none(tp, t, event, time); break; case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW: tp_edge_scroll_handle_edge_new(tp, t, event, time); break; case EDGE_SCROLL_TOUCH_STATE_EDGE: tp_edge_scroll_handle_edge(tp, t, event, time); break; case EDGE_SCROLL_TOUCH_STATE_AREA: tp_edge_scroll_handle_area(tp, t, event, time); break; } if (current != t->scroll.edge_state) evdev_log_debug(tp->device, "edge-scroll: touch %d state %s → %s → %s\n", t->index, edge_state_to_str(current), edge_event_to_str(event), edge_state_to_str(t->scroll.edge_state)); } static void tp_edge_scroll_handle_timeout(uint64_t now, void *data) { struct tp_touch *t = data; tp_edge_scroll_handle_event(t->tp, t, SCROLL_EVENT_TIMEOUT, now); } void tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device) { struct tp_touch *t; double width, height; bool want_horiz_scroll = true; struct device_coords edges; struct phys_coords mm = { 0.0, 0.0 }; int i; evdev_device_get_size(device, &width, &height); /* Touchpads smaller than 40mm are not tall enough to have a horizontal scroll area, it takes too much space away. But clickpads have enough space here anyway because of the software button area (and all these tiny clickpads were built when software buttons were a thing, e.g. Lenovo *20 series) */ if (!tp->buttons.is_clickpad) want_horiz_scroll = (height >= 40); /* 7mm edge size */ mm.x = width - 7; mm.y = height - 7; edges = evdev_device_mm_to_units(device, &mm); tp->scroll.right_edge = edges.x; if (want_horiz_scroll) tp->scroll.bottom_edge = edges.y; else tp->scroll.bottom_edge = INT_MAX; i = 0; tp_for_each_touch(tp, t) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s (%d) edgescroll", evdev_device_get_sysname(device), i); t->scroll.direction = -1; libinput_timer_init(&t->scroll.timer, tp_libinput_context(tp), timer_name, tp_edge_scroll_handle_timeout, t); } } void tp_remove_edge_scroll(struct tp_dispatch *tp) { struct tp_touch *t; tp_for_each_touch(tp, t) { libinput_timer_cancel(&t->scroll.timer); libinput_timer_destroy(&t->scroll.timer); } } void tp_edge_scroll_handle_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE) { tp_for_each_touch(tp, t) { if (t->state == TOUCH_BEGIN) t->scroll.edge_state = EDGE_SCROLL_TOUCH_STATE_AREA; else if (t->state == TOUCH_END) t->scroll.edge_state = EDGE_SCROLL_TOUCH_STATE_NONE; } return; } tp_for_each_touch(tp, t) { if (!t->dirty) continue; switch (t->state) { case TOUCH_NONE: case TOUCH_HOVERING: break; case TOUCH_BEGIN: tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_TOUCH, time); break; case TOUCH_UPDATE: tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_MOTION, time); break; case TOUCH_MAYBE_END: /* This shouldn't happen we transfer to TOUCH_END * before processing state */ evdev_log_debug(tp->device, "touch %d: unexpected state %d\n", t->index, t->state); _fallthrough_; case TOUCH_END: tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_RELEASE, time); break; } } } int tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time) { struct evdev_device *device = tp->device; struct tp_touch *t; enum libinput_pointer_axis axis; double *delta; struct device_coords raw; struct device_float_coords fraw; struct normalized_coords normalized, tmp; const struct normalized_coords zero = { 0.0, 0.0 }; tp_for_each_touch(tp, t) { if (!t->dirty) continue; if (t->palm.state != PALM_NONE || tp_thumb_ignored(tp, t)) continue; /* only scroll with the finger in the previous edge */ if (t->scroll.edge && (tp_touch_get_edge(tp, t) & t->scroll.edge) == 0) continue; switch (t->scroll.edge) { case EDGE_NONE: if (t->scroll.direction != -1) { /* Send stop scroll event */ evdev_notify_axis_finger(device, time, bit(t->scroll.direction), &zero); t->scroll.direction = -1; } continue; case EDGE_RIGHT: axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; delta = &normalized.y; break; case EDGE_BOTTOM: axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; delta = &normalized.x; break; default: /* EDGE_RIGHT | EDGE_BOTTOM */ continue; /* Don't know direction yet, skip */ } raw = tp_get_delta(t); fraw.x = raw.x; fraw.y = raw.y; /* scroll is not accelerated */ normalized = tp_filter_motion_unaccelerated(tp, &fraw, time); switch (t->scroll.edge_state) { case EDGE_SCROLL_TOUCH_STATE_NONE: case EDGE_SCROLL_TOUCH_STATE_AREA: evdev_log_bug_libinput(device, "unexpected scroll state %d\n", t->scroll.edge_state); break; case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW: tmp = normalized; normalized = tp_normalize_delta(tp, device_delta(t->point, t->scroll.initial)); if (fabs(*delta) < DEFAULT_SCROLL_THRESHOLD) normalized = zero; else normalized = tmp; break; case EDGE_SCROLL_TOUCH_STATE_EDGE: break; } if (*delta == 0.0) continue; evdev_notify_axis_finger(device, time, bit(axis), &normalized); t->scroll.direction = axis; tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED, time); } return 0; /* Edge touches are suppressed by edge_scroll_touch_active */ } void tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time) { struct evdev_device *device = tp->device; struct tp_touch *t; const struct normalized_coords zero = { 0.0, 0.0 }; tp_for_each_touch(tp, t) { if (t->scroll.direction != -1) { evdev_notify_axis_finger(device, time, bit(t->scroll.direction), &zero); t->scroll.direction = -1; /* reset touch to area state, avoids loading the * state machine with special case handling */ t->scroll.edge = EDGE_NONE; t->scroll.edge_state = EDGE_SCROLL_TOUCH_STATE_AREA; } } } int tp_edge_scroll_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->scroll.edge_state == EDGE_SCROLL_TOUCH_STATE_AREA; } libinput-1.28.1/src/evdev-mt-touchpad-gestures.c000066400000000000000000002004731477265155700216100ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include "evdev-mt-touchpad.h" enum gesture_cancelled { END_GESTURE = 0, CANCEL_GESTURE = 1, }; #define QUICK_GESTURE_HOLD_TIMEOUT ms2us(40) #define DEFAULT_GESTURE_HOLD_TIMEOUT ms2us(180) #define DEFAULT_GESTURE_SWITCH_TIMEOUT ms2us(100) #define DEFAULT_GESTURE_SWIPE_TIMEOUT ms2us(150) #define DEFAULT_GESTURE_PINCH_TIMEOUT ms2us(300) #define HOLD_AND_MOTION_THRESHOLD 0.5 /* mm */ #define PINCH_DISAMBIGUATION_MOVE_THRESHOLD 1.5 /* mm */ enum gesture_event { GESTURE_EVENT_RESET, GESTURE_EVENT_END, GESTURE_EVENT_CANCEL, GESTURE_EVENT_FINGER_DETECTED, GESTURE_EVENT_FINGER_SWITCH_TIMEOUT, GESTURE_EVENT_TAP_TIMEOUT, GESTURE_EVENT_HOLD_TIMEOUT, GESTURE_EVENT_HOLD_AND_MOTION_START, GESTURE_EVENT_POINTER_MOTION_START, GESTURE_EVENT_SCROLL_START, GESTURE_EVENT_SWIPE_START, GESTURE_EVENT_PINCH_START, GESTURE_EVENT_3FG_DRAG_START, GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT, }; /***************************************** * DO NOT EDIT THIS FILE! * * Look at the state diagram in doc/touchpad-gestures-state-machine.svg * (generated with https://www.diagrams.net) * * Any changes in this file must be represented in the diagram. */ static inline const char* gesture_state_to_str(enum tp_gesture_state state) { switch (state) { CASE_RETURN_STRING(GESTURE_STATE_NONE); CASE_RETURN_STRING(GESTURE_STATE_UNKNOWN); CASE_RETURN_STRING(GESTURE_STATE_HOLD); CASE_RETURN_STRING(GESTURE_STATE_HOLD_AND_MOTION); CASE_RETURN_STRING(GESTURE_STATE_POINTER_MOTION); CASE_RETURN_STRING(GESTURE_STATE_SCROLL_START); CASE_RETURN_STRING(GESTURE_STATE_SCROLL); CASE_RETURN_STRING(GESTURE_STATE_PINCH_START); CASE_RETURN_STRING(GESTURE_STATE_PINCH); CASE_RETURN_STRING(GESTURE_STATE_SWIPE_START); CASE_RETURN_STRING(GESTURE_STATE_SWIPE); CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG_START); CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG); CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG_RELEASED); } return NULL; } static inline const char* gesture_event_to_str(enum gesture_event event) { switch(event) { CASE_RETURN_STRING(GESTURE_EVENT_RESET); CASE_RETURN_STRING(GESTURE_EVENT_END); CASE_RETURN_STRING(GESTURE_EVENT_CANCEL); CASE_RETURN_STRING(GESTURE_EVENT_FINGER_DETECTED); CASE_RETURN_STRING(GESTURE_EVENT_FINGER_SWITCH_TIMEOUT); CASE_RETURN_STRING(GESTURE_EVENT_TAP_TIMEOUT); CASE_RETURN_STRING(GESTURE_EVENT_HOLD_TIMEOUT); CASE_RETURN_STRING(GESTURE_EVENT_HOLD_AND_MOTION_START); CASE_RETURN_STRING(GESTURE_EVENT_POINTER_MOTION_START); CASE_RETURN_STRING(GESTURE_EVENT_SCROLL_START); CASE_RETURN_STRING(GESTURE_EVENT_SWIPE_START); CASE_RETURN_STRING(GESTURE_EVENT_PINCH_START); CASE_RETURN_STRING(GESTURE_EVENT_3FG_DRAG_START); CASE_RETURN_STRING(GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT); } return NULL; } static struct device_float_coords tp_get_touches_delta(struct tp_dispatch *tp, bool average) { struct tp_touch *t; unsigned int i, nactive = 0; struct device_float_coords delta = {0.0, 0.0}; for (i = 0; i < tp->num_slots; i++) { t = &tp->touches[i]; if (!tp_touch_active_for_gesture(tp, t)) continue; nactive++; if (t->dirty) { struct device_coords d; d = tp_get_delta(t); delta.x += d.x; delta.y += d.y; } } if (!average || nactive == 0) return delta; delta.x /= nactive; delta.y /= nactive; return delta; } static void tp_gesture_init_scroll(struct tp_dispatch *tp) { struct phys_coords zero = {0.0, 0.0}; tp->scroll.active.h = false; tp->scroll.active.v = false; tp->scroll.duration.h = 0; tp->scroll.duration.v = 0; tp->scroll.vector = zero; tp->scroll.time_prev = 0; } static inline struct device_float_coords tp_get_combined_touches_delta(struct tp_dispatch *tp) { return tp_get_touches_delta(tp, false); } static inline struct device_float_coords tp_get_average_touches_delta(struct tp_dispatch *tp) { return tp_get_touches_delta(tp, true); } static struct device_float_coords tp_get_raw_pointer_motion(struct tp_dispatch *tp) { struct device_float_coords raw; /* When a clickpad is clicked, combine motion of all active touches */ if (tp->buttons.is_clickpad && tp->buttons.state) raw = tp_get_combined_touches_delta(tp); else raw = tp_get_average_touches_delta(tp); return raw; } static bool tp_has_pending_pointer_motion(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; if (!(tp->queued & TOUCHPAD_EVENT_MOTION)) return false; /* Checking for raw pointer motion is enough in this case. * Calling tp_filter_motion is intentionally omitted to avoid calling * it twice (here and in tp_gesture_post_pointer_motion) with the same * event. */ raw = tp_get_raw_pointer_motion(tp); return !device_float_is_zero(raw); } static void tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; struct normalized_coords delta; raw = tp_get_raw_pointer_motion(tp); delta = tp_filter_motion(tp, &raw, time); if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { struct device_float_coords unaccel; unaccel = tp_scale_to_xaxis(tp, raw); pointer_notify_motion(&tp->device->base, time, &delta, &unaccel); } } static unsigned int tp_gesture_get_active_touches(const struct tp_dispatch *tp, struct tp_touch **touches, unsigned int count) { unsigned int n = 0; struct tp_touch *t; memset(touches, 0, count * sizeof(struct tp_touch *)); tp_for_each_touch(tp, t) { if (tp_touch_active_for_gesture(tp, t)) { touches[n++] = t; if (n == count) return count; } } /* * This can happen when the user does .e.g: * 1) Put down 1st finger in center (so active) * 2) Put down 2nd finger in a button area (so inactive) * 3) Put down 3th finger somewhere, gets reported as a fake finger, * so gets same coordinates as 1st -> active * * We could avoid this by looking at all touches, be we really only * want to look at real touches. */ return n; } static inline int tp_gesture_same_directions(int dir1, int dir2) { /* * In some cases (semi-mt touchpads) we may seen one finger move * e.g. N/NE and the other W/NW so we not only check for overlapping * directions, but also for neighboring bits being set. * The ((dira & 0x80) && (dirb & 0x01)) checks are to check for bit 0 * and 7 being set as they also represent neighboring directions. */ return ((dir1 | (dir1 >> 1)) & dir2) || ((dir2 | (dir2 >> 1)) & dir1) || ((dir1 & 0x80) && (dir2 & 0x01)) || ((dir2 & 0x80) && (dir1 & 0x01)); } static struct phys_coords tp_gesture_mm_moved(struct tp_dispatch *tp, struct tp_touch *t) { struct device_coords delta; delta.x = abs(t->point.x - t->gesture.initial.x); delta.y = abs(t->point.y - t->gesture.initial.y); return evdev_device_unit_delta_to_mm(tp->device, &delta); } static uint32_t tp_gesture_get_direction(struct tp_dispatch *tp, struct tp_touch *touch) { struct phys_coords mm; struct device_float_coords delta; delta = device_delta(touch->point, touch->gesture.initial); mm = tp_phys_delta(tp, delta); return phys_get_direction(mm); } static void tp_gesture_get_pinch_info(struct tp_dispatch *tp, double *distance, double *angle, struct device_float_coords *center) { struct normalized_coords normalized; struct device_float_coords delta; struct tp_touch *first = tp->gesture.touches[0], *second = tp->gesture.touches[1]; delta = device_delta(first->point, second->point); normalized = tp_normalize_delta(tp, delta); *distance = normalized_length(normalized); *angle = rad2deg(atan2(normalized.y, normalized.x)); *center = device_average(first->point, second->point); } static inline void tp_gesture_init_pinch(struct tp_dispatch *tp) { tp_gesture_get_pinch_info(tp, &tp->gesture.initial_distance, &tp->gesture.angle, &tp->gesture.center); tp->gesture.prev_scale = 1.0; } static inline void tp_gesture_init_3fg_drag(struct tp_dispatch *tp, uint64_t time) { } static inline void tp_gesture_stop_3fg_drag(struct tp_dispatch *tp, uint64_t time) { } static void tp_gesture_set_scroll_buildup(struct tp_dispatch *tp) { struct device_float_coords d0, d1; struct device_float_coords average; struct tp_touch *first = tp->gesture.touches[0], *second = tp->gesture.touches[1]; d0 = device_delta(first->point, first->gesture.initial); d1 = device_delta(second->point, second->gesture.initial); average = device_float_average(d0, d1); tp->device->scroll.buildup = tp_normalize_delta(tp, average); } static void tp_gesture_apply_scroll_constraints(struct tp_dispatch *tp, struct device_float_coords *raw, struct normalized_coords *delta, uint64_t time) { uint64_t tdelta = 0; struct phys_coords delta_mm, vector; double vector_decay, vector_length, slope; const uint64_t ACTIVE_THRESHOLD = ms2us(100), INACTIVE_THRESHOLD = ms2us(50), EVENT_TIMEOUT = ms2us(100); /* Both axes active == true means free scrolling is enabled */ if (tp->scroll.active.h && tp->scroll.active.v) return; /* Determine time delta since last movement event */ if (tp->scroll.time_prev != 0) tdelta = time - tp->scroll.time_prev; if (tdelta > EVENT_TIMEOUT) tdelta = 0; tp->scroll.time_prev = time; /* Delta since last movement event in mm */ delta_mm = tp_phys_delta(tp, *raw); /* Old vector data "fades" over time. This is a two-part linear * approximation of an exponential function - for example, for * EVENT_TIMEOUT of 100, vector_decay = (0.97)^tdelta. This linear * approximation allows easier tweaking of EVENT_TIMEOUT and is faster. */ if (tdelta > 0) { double recent, later; recent = ((EVENT_TIMEOUT / 2.0) - tdelta) / (EVENT_TIMEOUT / 2.0); later = (EVENT_TIMEOUT - tdelta) / (EVENT_TIMEOUT * 2.0); vector_decay = tdelta <= (0.33 * EVENT_TIMEOUT) ? recent : later; } else { vector_decay = 0.0; } /* Calculate windowed vector from delta + weighted historic data */ vector.x = (tp->scroll.vector.x * vector_decay) + delta_mm.x; vector.y = (tp->scroll.vector.y * vector_decay) + delta_mm.y; vector_length = hypot(vector.x, vector.y); tp->scroll.vector = vector; /* We care somewhat about distance and speed, but more about * consistency of direction over time. Keep track of the time spent * primarily along each axis. If one axis is active, time spent NOT * moving much in the other axis is subtracted, allowing a switch of * axes in a single scroll + ability to "break out" and go diagonal. * * Slope to degree conversions (infinity = 90°, 0 = 0°): */ const double DEGREE_75 = 3.73; const double DEGREE_60 = 1.73; const double DEGREE_30 = 0.57; const double DEGREE_15 = 0.27; slope = (vector.x != 0) ? fabs(vector.y / vector.x) : INFINITY; /* Ensure vector is big enough (in mm per EVENT_TIMEOUT) to be confident * of direction. Larger = harder to enable diagonal/free scrolling. */ const double MIN_VECTOR = 0.15; if (slope >= DEGREE_30 && vector_length > MIN_VECTOR) { tp->scroll.duration.v += tdelta; if (tp->scroll.duration.v > ACTIVE_THRESHOLD) tp->scroll.duration.v = ACTIVE_THRESHOLD; if (slope >= DEGREE_75) { if (tp->scroll.duration.h > tdelta) tp->scroll.duration.h -= tdelta; else tp->scroll.duration.h = 0; } } if (slope < DEGREE_60 && vector_length > MIN_VECTOR) { tp->scroll.duration.h += tdelta; if (tp->scroll.duration.h > ACTIVE_THRESHOLD) tp->scroll.duration.h = ACTIVE_THRESHOLD; if (slope < DEGREE_15) { if (tp->scroll.duration.v > tdelta) tp->scroll.duration.v -= tdelta; else tp->scroll.duration.v = 0; } } if (tp->scroll.duration.h == ACTIVE_THRESHOLD) { tp->scroll.active.h = true; if (tp->scroll.duration.v < INACTIVE_THRESHOLD) tp->scroll.active.v = false; } if (tp->scroll.duration.v == ACTIVE_THRESHOLD) { tp->scroll.active.v = true; if (tp->scroll.duration.h < INACTIVE_THRESHOLD) tp->scroll.active.h = false; } /* If vector is big enough in a diagonal direction, always unlock * both axes regardless of thresholds */ if (vector_length > 5.0 && slope < 1.73 && slope >= 0.57) { tp->scroll.active.v = true; tp->scroll.active.h = true; } /* If only one axis is active, constrain motion accordingly. If both * are set, we've detected deliberate diagonal movement; enable free * scrolling for the life of the gesture. */ if (!tp->scroll.active.h && tp->scroll.active.v) delta->x = 0.0; if (tp->scroll.active.h && !tp->scroll.active.v) delta->y = 0.0; /* If we haven't determined an axis, use the slope in the meantime */ if (!tp->scroll.active.h && !tp->scroll.active.v) { delta->x = (slope >= DEGREE_60) ? 0.0 : delta->x; delta->y = (slope < DEGREE_30) ? 0.0 : delta->y; } } static inline void log_gesture_bug(struct tp_dispatch *tp, enum gesture_event event) { evdev_log_bug_libinput(tp->device, "invalid gesture event %s in state %s\n", gesture_event_to_str(event), gesture_state_to_str(tp->gesture.state)); } static bool tp_gesture_is_quick_hold(struct tp_dispatch *tp) { /* When 1 or 2 fingers are used to hold, always use a "quick" hold to * make the hold to stop kinetic scrolling user interaction feel more * natural. */ return (tp->gesture.finger_count == 1) || (tp->gesture.finger_count == 2); } static bool tp_gesture_use_hold_timer(struct tp_dispatch *tp) { /* When tap is not enabled, always use the timer */ if (!tp->tap.enabled) return true; /* Always use the timer if it is a quick hold */ if (tp_gesture_is_quick_hold(tp)) return true; /* If the number of fingers on the touchpad exceeds the number of * allowed fingers to tap, use the timer. */ if (tp->gesture.finger_count > 3) return true; /* If the tap state machine is already in a hold status, for example * when holding with 3 fingers and then holding with 2, use the timer. */ if (tp->tap.state == TAP_STATE_HOLD || tp->tap.state == TAP_STATE_TOUCH_2_HOLD || tp->tap.state == TAP_STATE_TOUCH_3_HOLD) return true; /* If the tap state machine is in dead status, use the timer. This * happens when the user holds after cancelling a gesture/scroll. */ if (tp->tap.state == TAP_STATE_DEAD) return true; /* Otherwise, sync the hold notification with the tap state machine */ return false; } static void tp_gesture_set_hold_timer(struct tp_dispatch *tp, uint64_t time) { uint64_t timeout; if (!tp->gesture.hold_enabled) return; if (tp_gesture_use_hold_timer(tp)) { timeout = tp_gesture_is_quick_hold(tp) ? QUICK_GESTURE_HOLD_TIMEOUT : DEFAULT_GESTURE_HOLD_TIMEOUT; libinput_timer_set(&tp->gesture.hold_timer, time + timeout); } } static void tp_gesture_handle_event_on_state_none(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); break; case GESTURE_EVENT_FINGER_DETECTED: /* Note: this makes 3fg drag more responsive but disables * 3fg pinch/hold. Those are niche enough to not worry about * for now. */ if (!tp->tap.enabled && tp->drag_3fg.nfingers == tp->gesture.finger_count) { tp->gesture.state = GESTURE_STATE_3FG_DRAG_START; } else { tp_gesture_set_hold_timer(tp, time); tp->gesture.state = GESTURE_STATE_UNKNOWN; } break; case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: break; case GESTURE_EVENT_POINTER_MOTION_START: tp->gesture.state = GESTURE_STATE_POINTER_MOTION; break; case GESTURE_EVENT_SCROLL_START: tp->gesture.state = GESTURE_STATE_SCROLL_START; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_unknown(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: break; case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: tp->gesture.state = GESTURE_STATE_HOLD; gesture_notify_hold_begin(&tp->device->base, time, tp->gesture.finger_count); break; case GESTURE_EVENT_POINTER_MOTION_START: /* Don't cancel the hold timer. This pointer motion can end up * being recognised as hold and motion. */ tp->gesture.state = GESTURE_STATE_POINTER_MOTION; break; case GESTURE_EVENT_SCROLL_START: libinput_timer_cancel(&tp->gesture.hold_timer); tp_gesture_set_scroll_buildup(tp); tp->gesture.state = GESTURE_STATE_SCROLL_START; break; case GESTURE_EVENT_SWIPE_START: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_SWIPE_START; break; case GESTURE_EVENT_PINCH_START: libinput_timer_cancel(&tp->gesture.hold_timer); tp_gesture_init_pinch(tp); tp->gesture.state = GESTURE_STATE_PINCH_START; break; case GESTURE_EVENT_3FG_DRAG_START: libinput_timer_cancel(&tp->gesture.hold_timer); tp_gesture_init_3fg_drag(tp, time); tp->gesture.state = GESTURE_STATE_3FG_DRAG_START; break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_hold(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: { bool cancelled = event == GESTURE_EVENT_CANCEL; gesture_notify_hold_end(&tp->device->base, time, tp->gesture.finger_count, cancelled); libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; } case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: tp_gesture_cancel(tp, time); break; case GESTURE_EVENT_HOLD_AND_MOTION_START: tp->gesture.state = GESTURE_STATE_HOLD_AND_MOTION; break; case GESTURE_EVENT_POINTER_MOTION_START: tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_POINTER_MOTION; break; case GESTURE_EVENT_SCROLL_START: tp_gesture_set_scroll_buildup(tp); tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_SCROLL_START; break; case GESTURE_EVENT_SWIPE_START: tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_SWIPE_START; break; case GESTURE_EVENT_PINCH_START: tp_gesture_cancel(tp, time); tp_gesture_init_pinch(tp); tp->gesture.state = GESTURE_STATE_PINCH_START; break; case GESTURE_EVENT_3FG_DRAG_START: tp_gesture_cancel(tp, time); tp_gesture_init_3fg_drag(tp, time); tp->gesture.state = GESTURE_STATE_3FG_DRAG_START; break; case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_hold_and_motion(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: { bool cancelled = event == GESTURE_EVENT_CANCEL; gesture_notify_hold_end(&tp->device->base, time, tp->gesture.finger_count, cancelled); libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; } case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: tp_gesture_cancel(tp, time); break; case GESTURE_EVENT_POINTER_MOTION_START: tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_POINTER_MOTION; break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_pointer_motion(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { struct tp_touch *first; struct phys_coords first_moved; double first_mm; switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: if (tp->gesture.finger_count != 1) break; first = tp->gesture.touches[0]; first_moved = tp_gesture_mm_moved(tp, first); first_mm = hypot(first_moved.x, first_moved.y); if (first_mm < HOLD_AND_MOTION_THRESHOLD) { tp->gesture.state = GESTURE_STATE_HOLD_AND_MOTION; gesture_notify_hold_begin(&tp->device->base, time, tp->gesture.finger_count); } break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_scroll_start(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: break; case GESTURE_EVENT_PINCH_START: tp_gesture_init_pinch(tp); tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_PINCH_START; break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_scroll(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: tp_gesture_stop_twofinger_scroll(tp, time); libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: tp_gesture_cancel(tp, time); break; case GESTURE_EVENT_PINCH_START: tp_gesture_init_pinch(tp); tp_gesture_cancel(tp, time); tp->gesture.state = GESTURE_STATE_PINCH_START; break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_pinch_start(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_pinch(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: { bool cancelled = event == GESTURE_EVENT_CANCEL; gesture_notify_pinch_end(&tp->device->base, time, tp->gesture.finger_count, tp->gesture.prev_scale, cancelled); libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; } case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: tp_gesture_cancel(tp, time); break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_swipe_start(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_swipe(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: { bool cancelled = event == GESTURE_EVENT_CANCEL; gesture_notify_swipe_end(&tp->device->base, time, tp->gesture.finger_count, cancelled); libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; } case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: tp_gesture_cancel(tp, time); break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_3fg_drag_start(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: libinput_timer_cancel(&tp->gesture.hold_timer); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_TAP_TIMEOUT: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_set_3fg_drag_timer(struct tp_dispatch *tp, uint64_t time) { tp->gesture.drag_3fg_release_time = time; libinput_timer_set(&tp->gesture.drag_3fg_timer, time + ms2us(700)); } static void tp_gesture_handle_event_on_state_3fg_drag(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_CANCEL: /* If the gesture is cancelled we release the button immediately */ evdev_pointer_notify_button(tp->device, tp->gesture.drag_3fg_release_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_END: /* If the gesture ends we start the timer so we * can keep dragging */ tp_gesture_set_3fg_drag_timer(tp, time); tp->gesture.state = GESTURE_STATE_3FG_DRAG_RELEASED; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: if (tp->gesture.finger_count_pending < 2) { evdev_pointer_notify_button(tp->device, tp->gesture.drag_3fg_release_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); tp->gesture.state = GESTURE_STATE_NONE; } break; case GESTURE_EVENT_TAP_TIMEOUT: break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_FINGER_DETECTED: case GESTURE_EVENT_HOLD_TIMEOUT: case GESTURE_EVENT_POINTER_MOTION_START: case GESTURE_EVENT_SCROLL_START: case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: log_gesture_bug(tp, event); break; } } static void tp_gesture_handle_event_on_state_3fg_drag_released(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { switch(event) { case GESTURE_EVENT_RESET: log_gesture_bug(tp, event); break; case GESTURE_EVENT_END: case GESTURE_EVENT_CANCEL: case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT: tp_gesture_stop_3fg_drag(tp, time); libinput_timer_cancel(&tp->gesture.drag_3fg_timer); libinput_timer_cancel(&tp->gesture.finger_count_switch_timer); evdev_pointer_notify_button(tp->device, tp->gesture.drag_3fg_release_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); tp->gesture.state = GESTURE_STATE_NONE; break; case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT: case GESTURE_EVENT_TAP_TIMEOUT: if (tp->gesture.finger_count_pending == tp->drag_3fg.nfingers) { libinput_timer_cancel(&tp->gesture.drag_3fg_timer); tp->gesture.state = GESTURE_STATE_3FG_DRAG; } break; case GESTURE_EVENT_FINGER_DETECTED: break; case GESTURE_EVENT_POINTER_MOTION_START: tp_gesture_stop_3fg_drag(tp, time); libinput_timer_cancel(&tp->gesture.drag_3fg_timer); evdev_pointer_notify_button(tp->device, tp->gesture.drag_3fg_release_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); tp->gesture.state = GESTURE_STATE_POINTER_MOTION; break; case GESTURE_EVENT_HOLD_AND_MOTION_START: case GESTURE_EVENT_HOLD_TIMEOUT: log_gesture_bug(tp, event); break; /* Anything that's detected as gesture in this state * will be continue the current 3fg drag gesture */ case GESTURE_EVENT_SCROLL_START: libinput_timer_cancel(&tp->gesture.drag_3fg_timer); evdev_pointer_notify_button(tp->device, tp->gesture.drag_3fg_release_time, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); tp->gesture.state = GESTURE_STATE_SCROLL_START; break; case GESTURE_EVENT_SWIPE_START: case GESTURE_EVENT_PINCH_START: case GESTURE_EVENT_3FG_DRAG_START: libinput_timer_cancel(&tp->gesture.drag_3fg_timer); tp->gesture.state = GESTURE_STATE_3FG_DRAG; break; } } static void tp_gesture_handle_event(struct tp_dispatch *tp, enum gesture_event event, uint64_t time) { enum tp_gesture_state oldstate; oldstate = tp->gesture.state; switch(tp->gesture.state) { case GESTURE_STATE_NONE: tp_gesture_handle_event_on_state_none(tp, event, time); break; case GESTURE_STATE_UNKNOWN: tp_gesture_handle_event_on_state_unknown(tp, event, time); break; case GESTURE_STATE_HOLD: tp_gesture_handle_event_on_state_hold(tp, event, time); break; case GESTURE_STATE_HOLD_AND_MOTION: tp_gesture_handle_event_on_state_hold_and_motion(tp, event, time); break; case GESTURE_STATE_POINTER_MOTION: tp_gesture_handle_event_on_state_pointer_motion(tp, event, time); break; case GESTURE_STATE_SCROLL_START: tp_gesture_handle_event_on_state_scroll_start(tp, event, time); break; case GESTURE_STATE_SCROLL: tp_gesture_handle_event_on_state_scroll(tp, event, time); break; case GESTURE_STATE_PINCH_START: tp_gesture_handle_event_on_state_pinch_start(tp, event, time); break; case GESTURE_STATE_PINCH: tp_gesture_handle_event_on_state_pinch(tp, event, time); break; case GESTURE_STATE_SWIPE_START: tp_gesture_handle_event_on_state_swipe_start(tp, event, time); break; case GESTURE_STATE_SWIPE: tp_gesture_handle_event_on_state_swipe(tp, event, time); break; case GESTURE_STATE_3FG_DRAG_START: tp_gesture_handle_event_on_state_3fg_drag_start(tp, event, time); break; case GESTURE_STATE_3FG_DRAG: tp_gesture_handle_event_on_state_3fg_drag(tp, event, time); break; case GESTURE_STATE_3FG_DRAG_RELEASED: tp_gesture_handle_event_on_state_3fg_drag_released(tp, event, time); break; } if (oldstate != tp->gesture.state) { evdev_log_debug(tp->device, "gesture: [%dfg] event %s → %s → %s\n", tp->gesture.finger_count, gesture_state_to_str(oldstate), gesture_event_to_str(event), gesture_state_to_str(tp->gesture.state)); } } static void tp_gesture_hold_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; if (tp_tap_dragging_or_double_tapping(tp) || tp_tap_dragging(tp)) return; tp_gesture_handle_event(tp, GESTURE_EVENT_HOLD_TIMEOUT, now); } void tp_gesture_tap_timeout(struct tp_dispatch *tp, uint64_t time) { if (!tp->gesture.hold_enabled) return; if (!tp_gesture_is_quick_hold(tp)) tp_gesture_handle_event(tp, GESTURE_EVENT_TAP_TIMEOUT, time); } static void tp_gesture_3fg_drag_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT, now); } static void tp_gesture_detect_motion_gestures(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *first = tp->gesture.touches[0], *second = tp->gesture.touches[1], *thumb; uint32_t dir1, dir2; struct device_coords delta; struct phys_coords first_moved, second_moved, distance_mm; double first_mm, second_mm; /* movement since gesture start in mm */ double min_move = 1.5; /* min movement threshold in mm - count this touch */ double max_move = 4.0; /* max movement threshold in mm - ignore other touch */ bool is_hold_and_motion; first_moved = tp_gesture_mm_moved(tp, first); first_mm = hypot(first_moved.x, first_moved.y); if (tp->gesture.finger_count == 1) { if (!tp_has_pending_pointer_motion(tp, time)) return; is_hold_and_motion = (first_mm < HOLD_AND_MOTION_THRESHOLD); if (tp->gesture.state == GESTURE_STATE_HOLD && is_hold_and_motion) { tp_gesture_handle_event(tp, GESTURE_EVENT_HOLD_AND_MOTION_START, time); return; } if (tp->gesture.state == GESTURE_STATE_HOLD_AND_MOTION && is_hold_and_motion) return; tp_gesture_handle_event(tp, GESTURE_EVENT_POINTER_MOTION_START, time); return; } /* If we have more fingers than slots, we don't know where the * fingers are. Default to swipe/3fg drag */ if (tp->gesture.enabled && tp->gesture.finger_count > 2 && tp->gesture.finger_count > tp->num_slots) { if (tp->drag_3fg.nfingers == tp->gesture.finger_count) tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time); else tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time); return; } /* Need more margin for error when there are more fingers */ max_move += 2.0 * (tp->gesture.finger_count - 2); min_move += 0.5 * (tp->gesture.finger_count - 2); second_moved = tp_gesture_mm_moved(tp, second); second_mm = hypot(second_moved.x, second_moved.y); delta.x = abs(first->point.x - second->point.x); delta.y = abs(first->point.y - second->point.y); distance_mm = evdev_device_unit_delta_to_mm(tp->device, &delta); /* If both touches moved less than a mm, we cannot decide yet */ if (first_mm < 1 && second_mm < 1) return; /* If both touches are within 7mm vertically and 40mm horizontally * past the timeout, assume scroll/swipe */ if ((!tp->gesture.enabled || (distance_mm.x < 40.0 && distance_mm.y < 7.0)) && time > (tp->gesture.initial_time + DEFAULT_GESTURE_SWIPE_TIMEOUT)) { if (tp->gesture.finger_count == 2) tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time); else if (tp->drag_3fg.nfingers == tp->gesture.finger_count) tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time); else tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time); return; } /* If 3fg dragging touches are within a 60x10mm box, start * dragging immediately */ if (tp->gesture.finger_count == tp->drag_3fg.nfingers && distance_mm.x < 60.0 && distance_mm.y < 10.0) { tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time); return; } /* If one touch exceeds the max_move threshold while the other has not * yet passed the min_move threshold, there is either a resting thumb, * or the user is doing "one-finger-scroll," where one touch stays in * place while the other moves. */ if (first_mm >= max_move || second_mm >= max_move) { double thumb_mm, finger_mm; /* Pick the thumb as the lowest point on the touchpad */ if (first->point.y > second->point.y) { thumb = first; thumb_mm = first_mm; finger_mm = second_mm; } else { thumb = second; thumb_mm = second_mm; finger_mm = first_mm; } /* If thumb detection is enabled, and thumb is still while * finger moves, cancel gestures and mark lower as thumb. * This applies to all gestures (2, 3, 4+ fingers), but allows * more thumb motion on >2 finger gestures during detection. */ if (tp->thumb.detect_thumbs && thumb_mm < min_move) { tp_thumb_suppress(tp, thumb); tp_gesture_cancel(tp, time); return; } /* If gestures detection is disabled, or if finger is still * while thumb moves, assume this is "one-finger scrolling." * This applies only to 2-finger gestures. */ if ((!tp->gesture.enabled || finger_mm < min_move) && tp->gesture.finger_count == 2) { tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time); return; } /* If more than 2 fingers are involved, and the thumb moves * while the fingers stay still, assume a pinch if eligible. */ if (finger_mm < min_move && tp->gesture.finger_count > 2 && tp->gesture.enabled && tp->thumb.pinch_eligible) { tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time); return; } } /* If either touch is still below the min_move threshold, we can't * tell what kind of gesture this is. */ if ((first_mm < min_move) || (second_mm < min_move)) return; /* Both touches have exceeded the min_move threshold, so we have a * valid gesture. Update gesture initial time and get directions so * we know if it's a pinch or swipe/scroll. */ dir1 = tp_gesture_get_direction(tp, first); dir2 = tp_gesture_get_direction(tp, second); /* If we can't accurately detect pinches, or if the touches are moving * the same way, this is a scroll or swipe. */ if (tp->gesture.finger_count > tp->num_slots || tp_gesture_same_directions(dir1, dir2)) { if (tp->gesture.finger_count == 2) { tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time); return; } if (tp->drag_3fg.nfingers == tp->gesture.finger_count) { tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time); return; } if (tp->gesture.enabled) { tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time); return; } } /* If the touches are moving away from each other, this is a pinch */ tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time); } static bool tp_gesture_is_pinch(struct tp_dispatch *tp) { struct tp_touch *first = tp->gesture.touches[0], *second = tp->gesture.touches[1]; uint32_t dir1, dir2; struct phys_coords first_moved, second_moved; double first_mm, second_mm; dir1 = tp_gesture_get_direction(tp, first); dir2 = tp_gesture_get_direction(tp, second); if (tp_gesture_same_directions(dir1, dir2)) return false; first_moved = tp_gesture_mm_moved(tp, first); first_mm = hypot(first_moved.x, first_moved.y); if (first_mm < PINCH_DISAMBIGUATION_MOVE_THRESHOLD) return false; second_moved = tp_gesture_mm_moved(tp, second); second_mm = hypot(second_moved.x, second_moved.y); if (second_mm < PINCH_DISAMBIGUATION_MOVE_THRESHOLD) return false; return true; } static void tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *first, *second; struct tp_touch *touches[4]; unsigned int ntouches; unsigned int i; ntouches = tp_gesture_get_active_touches(tp, touches, 4); first = touches[0]; second = touches[1]; if (ntouches == 0) return; if (ntouches == 1) { first->gesture.initial = first->point; tp->gesture.touches[0] = first; tp_gesture_handle_event(tp, GESTURE_EVENT_FINGER_DETECTED, time); return; } if (!tp->gesture.enabled && !tp->tap.enabled && ntouches == 2) { tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time); return; } /* For 3+ finger gestures, we only really need to track two touches. * The human hand's finger arrangement means that for a pinch, the * bottom-most touch will always be the thumb, and the top-most touch * will always be one of the fingers. * * For 3+ finger swipes, the fingers will likely (but not necessarily) * be in a horizontal line. They all move together, regardless, so it * doesn't really matter which two of those touches we track. * * Tracking top and bottom is a change from previous versions, where * we tracked leftmost and rightmost. This change enables: * * - More accurate pinch detection if thumb is near the center * - Better resting-thumb detection while two-finger scrolling * - On capable hardware, allow 3- or 4-finger swipes with resting * thumb or held-down clickpad */ if (ntouches > 2) { second = touches[0]; for (i = 1; i < ntouches && i < tp->num_slots; i++) { if (touches[i]->point.y < first->point.y) first = touches[i]; else if (touches[i]->point.y >= second->point.y) second = touches[i]; } if (first == second) return; } tp->gesture.initial_time = time; first->gesture.initial = first->point; second->gesture.initial = second->point; tp->gesture.touches[0] = first; tp->gesture.touches[1] = second; tp_gesture_handle_event(tp, GESTURE_EVENT_FINGER_DETECTED, time); } static void tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time, bool ignore_motion) { if (!ignore_motion) tp_gesture_detect_motion_gestures(tp, time); } static void tp_gesture_handle_state_hold(struct tp_dispatch *tp, uint64_t time, bool ignore_motion) { if (!ignore_motion) tp_gesture_detect_motion_gestures(tp, time); } static void tp_gesture_handle_state_hold_and_pointer_motion(struct tp_dispatch *tp, uint64_t time) { if (tp->queued & TOUCHPAD_EVENT_MOTION) tp_gesture_post_pointer_motion(tp, time); tp_gesture_detect_motion_gestures(tp, time); } static void tp_gesture_handle_state_pointer_motion(struct tp_dispatch *tp, uint64_t time) { if (tp->queued & TOUCHPAD_EVENT_MOTION) tp_gesture_post_pointer_motion(tp, time); } static void tp_gesture_handle_state_scroll_start(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; struct normalized_coords delta; if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG) return; /* We may confuse a pinch for a scroll initially, * allow ourselves to correct our guess. */ if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) && tp_gesture_is_pinch(tp)) { tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time); return; } raw = tp_get_average_touches_delta(tp); /* scroll is not accelerated by default */ delta = tp_filter_scroll(tp, &raw, time); if (normalized_is_zero(delta)) return; tp_gesture_init_scroll(tp); tp->gesture.state = GESTURE_STATE_SCROLL; } static void tp_gesture_handle_state_scroll(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; struct normalized_coords delta; if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG) return; /* We may confuse a pinch for a scroll initially, * allow ourselves to correct our guess. */ if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) && tp_gesture_is_pinch(tp)) { tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time); return; } raw = tp_get_average_touches_delta(tp); /* scroll is not accelerated by default */ delta = tp_filter_scroll(tp, &raw, time); if (normalized_is_zero(delta)) return; tp_gesture_apply_scroll_constraints(tp, &raw, &delta, time); evdev_post_scroll(tp->device, time, LIBINPUT_POINTER_AXIS_SOURCE_FINGER, &delta); } static void tp_gesture_handle_state_swipe_start(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; struct normalized_coords delta; raw = tp_get_average_touches_delta(tp); delta = tp_filter_motion(tp, &raw, time); if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { const struct normalized_coords zero = { 0.0, 0.0 }; gesture_notify_swipe(&tp->device->base, time, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, tp->gesture.finger_count, &zero, &zero); tp->gesture.state = GESTURE_STATE_SWIPE; } } static void tp_gesture_handle_state_swipe(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; struct normalized_coords delta, unaccel; raw = tp_get_average_touches_delta(tp); delta = tp_filter_motion(tp, &raw, time); if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { unaccel = tp_filter_motion_unaccelerated(tp, &raw, time); gesture_notify_swipe(&tp->device->base, time, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, tp->gesture.finger_count, &delta, &unaccel); } } static void tp_gesture_handle_state_pinch_start(struct tp_dispatch *tp, uint64_t time) { const struct normalized_coords zero = { 0.0, 0.0 }; double angle, angle_delta, distance, scale; struct device_float_coords center, fdelta; struct normalized_coords delta; tp_gesture_get_pinch_info(tp, &distance, &angle, ¢er); scale = distance / tp->gesture.initial_distance; angle_delta = angle - tp->gesture.angle; tp->gesture.angle = angle; if (angle_delta > 180.0) angle_delta -= 360.0; else if (angle_delta < -180.0) angle_delta += 360.0; fdelta = device_float_delta(center, tp->gesture.center); tp->gesture.center = center; delta = tp_filter_motion(tp, &fdelta, time); if (normalized_is_zero(delta) && device_float_is_zero(fdelta) && scale == tp->gesture.prev_scale && angle_delta == 0.0) return; gesture_notify_pinch(&tp->device->base, time, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, tp->gesture.finger_count, &zero, &zero, 1.0, 0.0); tp->gesture.prev_scale = scale; tp->gesture.state = GESTURE_STATE_PINCH; } static void tp_gesture_handle_state_pinch(struct tp_dispatch *tp, uint64_t time) { double angle, angle_delta, distance, scale; struct device_float_coords center, fdelta; struct normalized_coords delta, unaccel; tp_gesture_get_pinch_info(tp, &distance, &angle, ¢er); scale = distance / tp->gesture.initial_distance; angle_delta = angle - tp->gesture.angle; tp->gesture.angle = angle; if (angle_delta > 180.0) angle_delta -= 360.0; else if (angle_delta < -180.0) angle_delta += 360.0; fdelta = device_float_delta(center, tp->gesture.center); tp->gesture.center = center; delta = tp_filter_motion(tp, &fdelta, time); if (normalized_is_zero(delta) && device_float_is_zero(fdelta) && scale == tp->gesture.prev_scale && angle_delta == 0.0) return; unaccel = tp_filter_motion_unaccelerated(tp, &fdelta, time); gesture_notify_pinch(&tp->device->base, time, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, tp->gesture.finger_count, &delta, &unaccel, scale, angle_delta); tp->gesture.prev_scale = scale; } static void tp_gesture_handle_state_3fg_drag_start(struct tp_dispatch *tp, uint64_t time) { evdev_pointer_notify_button(tp->device, time, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); /* FIXME: immediately send a motion event? */ tp->gesture.state = GESTURE_STATE_3FG_DRAG; } static void tp_gesture_handle_state_3fg_drag(struct tp_dispatch *tp, uint64_t time) { if (!(tp->queued & TOUCHPAD_EVENT_MOTION)) return; struct device_float_coords raw = tp_get_average_touches_delta(tp); struct normalized_coords delta = tp_filter_motion(tp, &raw, time); if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { if (tp->queued & TOUCHPAD_EVENT_MOTION) tp_gesture_post_pointer_motion(tp, time); } } static void tp_gesture_handle_state_3fg_drag_released(struct tp_dispatch *tp, uint64_t time, bool ignore_motion) { tp_gesture_detect_motion_gestures(tp, time); } static void tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time, bool ignore_motion) { enum tp_gesture_state oldstate = tp->gesture.state; enum tp_gesture_state transitions[16] = {0}; enum tp_gesture_state *transition_state = transitions; #define REMEMBER_TRANSITION(_ts, _state) { \ if (*(_ts) != (_state)) { \ ++(_ts); \ assert((_ts) < transitions + ARRAY_LENGTH(transitions)); \ *(_ts) = _state; \ } \ } *transition_state = tp->gesture.state; if (tp->gesture.state == GESTURE_STATE_NONE) { tp_gesture_handle_state_none(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_UNKNOWN) { tp_gesture_handle_state_unknown(tp, time, ignore_motion); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_HOLD) { tp_gesture_handle_state_hold(tp, time, ignore_motion); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_POINTER_MOTION) { tp_gesture_handle_state_pointer_motion(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_HOLD_AND_MOTION) { tp_gesture_handle_state_hold_and_pointer_motion(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_SCROLL) { tp_gesture_handle_state_scroll(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_SCROLL_START) { tp_gesture_handle_state_scroll_start(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_SWIPE) { tp_gesture_handle_state_swipe(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_SWIPE_START) { tp_gesture_handle_state_swipe_start(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_PINCH) { tp_gesture_handle_state_pinch(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_PINCH_START) { tp_gesture_handle_state_pinch_start(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_3FG_DRAG) { tp_gesture_handle_state_3fg_drag(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_3FG_DRAG_START) { tp_gesture_handle_state_3fg_drag_start(tp, time); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } if (tp->gesture.state == GESTURE_STATE_3FG_DRAG_RELEASED) { tp_gesture_handle_state_3fg_drag_released(tp, time, ignore_motion); REMEMBER_TRANSITION(transition_state, tp->gesture.state); } #undef REMEMBER_TRANSITION if (oldstate != tp->gesture.state) { char buf[1024] = {0}; size_t remaining = sizeof(buf); size_t slen = 0; for (enum tp_gesture_state *s = transitions + 1; s < transition_state; s++) { int n = snprintf(&buf[slen], remaining, " → %s", gesture_state_to_str(*s)); slen += n; remaining -= n; } evdev_log_debug(tp->device, "gesture: [%dfg] state %s%s → %s\n", tp->gesture.finger_count, gesture_state_to_str(oldstate), buf, gesture_state_to_str(tp->gesture.state)); } } static bool tp_gesture_thumb_moved(struct tp_dispatch *tp) { struct tp_touch *thumb; struct phys_coords thumb_moved; double thumb_mm; thumb = tp_thumb_get_touch(tp); if (!thumb) return false; if (!tp_touch_active_for_gesture(tp, thumb)) return false; thumb_moved = tp_gesture_mm_moved(tp, thumb); thumb_mm = hypot(thumb_moved.x, thumb_moved.y); return thumb_mm >= PINCH_DISAMBIGUATION_MOVE_THRESHOLD; } void tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time, bool ignore_motion) { if (tp->gesture.finger_count == 0) return; /* When tap-and-dragging, force 1fg mode. On clickpads, if the * physical button is down, don't allow gestures unless the button * is held down by a *thumb*, specifically. */ if (tp_tap_dragging(tp) || (tp->buttons.is_clickpad && tp->buttons.state && tp->thumb.state == THUMB_STATE_FINGER)) { if (tp->gesture.state != GESTURE_STATE_POINTER_MOTION) { tp_gesture_cancel(tp, time); tp_gesture_handle_event(tp, GESTURE_EVENT_POINTER_MOTION_START, time); } tp->gesture.finger_count = 1; tp->gesture.finger_count_pending = 0; } /* Don't send events when we're unsure in which mode we are */ if (tp->gesture.finger_count_pending) return; /* When pinching, the thumb tends to move slower than the finger, * so we may suppress it too early. Give it some time to move. */ if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) && tp_gesture_thumb_moved(tp)) tp_thumb_reset(tp); if (tp->gesture.finger_count <= 4) tp_gesture_handle_state(tp, time, ignore_motion); } void tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time) { if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG) return; evdev_stop_scroll(tp->device, time, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); } static void tp_gesture_end(struct tp_dispatch *tp, uint64_t time, enum gesture_cancelled cancelled) { switch (tp->gesture.state) { case GESTURE_STATE_NONE: case GESTURE_STATE_UNKNOWN: case GESTURE_STATE_SCROLL_START: case GESTURE_STATE_PINCH_START: case GESTURE_STATE_SWIPE_START: case GESTURE_STATE_3FG_DRAG_START: tp_gesture_handle_event(tp, GESTURE_EVENT_RESET, time); break; case GESTURE_STATE_HOLD: case GESTURE_STATE_HOLD_AND_MOTION: case GESTURE_STATE_POINTER_MOTION: case GESTURE_STATE_SCROLL: case GESTURE_STATE_PINCH: case GESTURE_STATE_SWIPE: case GESTURE_STATE_3FG_DRAG: case GESTURE_STATE_3FG_DRAG_RELEASED: switch (cancelled) { case CANCEL_GESTURE: tp_gesture_handle_event(tp, GESTURE_EVENT_CANCEL, time); break; case END_GESTURE: tp_gesture_handle_event(tp, GESTURE_EVENT_END, time); break; } break; } } void tp_gesture_cancel(struct tp_dispatch *tp, uint64_t time) { tp_gesture_end(tp, time, CANCEL_GESTURE); } void tp_gesture_cancel_motion_gestures(struct tp_dispatch *tp, uint64_t time) { switch (tp->gesture.state) { case GESTURE_STATE_NONE: case GESTURE_STATE_UNKNOWN: case GESTURE_STATE_SCROLL_START: case GESTURE_STATE_PINCH_START: case GESTURE_STATE_SWIPE_START: case GESTURE_STATE_3FG_DRAG_START: break; case GESTURE_STATE_HOLD: break; case GESTURE_STATE_HOLD_AND_MOTION: case GESTURE_STATE_POINTER_MOTION: case GESTURE_STATE_SCROLL: case GESTURE_STATE_PINCH: case GESTURE_STATE_SWIPE: evdev_log_debug(tp->device, "Cancelling motion gestures\n"); tp_gesture_cancel(tp, time); break; case GESTURE_STATE_3FG_DRAG: break; case GESTURE_STATE_3FG_DRAG_RELEASED: break; } } void tp_gesture_stop(struct tp_dispatch *tp, uint64_t time) { tp_gesture_end(tp, time, END_GESTURE); } static void tp_gesture_finger_count_switch_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; if (!tp->gesture.finger_count_pending) return; tp_gesture_handle_event(tp, GESTURE_EVENT_FINGER_SWITCH_TIMEOUT, now); tp->gesture.finger_count = tp->gesture.finger_count_pending; tp->gesture.finger_count_pending = 0; } static bool tp_gesture_debounce_finger_changes(struct tp_dispatch *tp) { switch (tp->gesture.state) { case GESTURE_STATE_NONE: case GESTURE_STATE_UNKNOWN: case GESTURE_STATE_SCROLL_START: case GESTURE_STATE_PINCH_START: case GESTURE_STATE_SWIPE_START: case GESTURE_STATE_POINTER_MOTION: return false; case GESTURE_STATE_HOLD: case GESTURE_STATE_HOLD_AND_MOTION: case GESTURE_STATE_SCROLL: case GESTURE_STATE_PINCH: case GESTURE_STATE_SWIPE: case GESTURE_STATE_3FG_DRAG_START: case GESTURE_STATE_3FG_DRAG_RELEASED: case GESTURE_STATE_3FG_DRAG: return true; } abort(); } void tp_gesture_update_finger_state(struct tp_dispatch *tp, uint64_t time) { unsigned int active_touches = 0; struct tp_touch *t; tp_for_each_touch(tp, t) { if (tp_touch_active_for_gesture(tp, t)) active_touches++; } if (active_touches != tp->gesture.finger_count) { /* If all fingers are lifted immediately end the gesture */ if (active_touches == 0) { tp_gesture_stop(tp, time); tp->gesture.finger_count = 0; tp->gesture.finger_count_pending = 0; /* Immediately switch to new mode to avoid initial latency */ } else if (!tp_gesture_debounce_finger_changes(tp)) { tp->gesture.finger_count = active_touches; tp->gesture.finger_count_pending = 0; /* If in UNKNOWN or POINTER_MOTION state, go back to * NONE to re-evaluate leftmost and rightmost touches */ if (tp->gesture.state == GESTURE_STATE_UNKNOWN || tp->gesture.state == GESTURE_STATE_POINTER_MOTION) { tp_gesture_handle_event(tp, GESTURE_EVENT_RESET, time); } /* Else debounce finger changes */ } else if (active_touches != tp->gesture.finger_count_pending) { tp->gesture.finger_count_pending = active_touches; libinput_timer_set(&tp->gesture.finger_count_switch_timer, time + DEFAULT_GESTURE_SWITCH_TIMEOUT); } } else { tp->gesture.finger_count_pending = 0; } } static bool tp_gesture_are_gestures_enabled(struct tp_dispatch *tp) { return (!tp->semi_mt && tp->num_slots > 1); } static enum libinput_config_status tp_gesture_set_hold_enabled(struct libinput_device *device, enum libinput_config_hold_state enabled) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); if (!tp_gesture_are_gestures_enabled(tp)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; tp->gesture.hold_enabled = (enabled == LIBINPUT_CONFIG_HOLD_ENABLED); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_hold_state tp_gesture_is_hold_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->gesture.hold_enabled ? LIBINPUT_CONFIG_HOLD_ENABLED : LIBINPUT_CONFIG_HOLD_DISABLED; } static enum libinput_config_hold_state tp_gesture_get_hold_default(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp_gesture_are_gestures_enabled(tp) ? LIBINPUT_CONFIG_HOLD_ENABLED : LIBINPUT_CONFIG_HOLD_DISABLED; } static int tp_3fg_drag_count(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); /* If we can't to gestures we can't do 3fg drag */ if (!tp_gesture_are_gestures_enabled(tp)) return 0; /* For now return the number of MT slots until we need to figure out * if we can implement this on a 2-finger BTN_TOOL_TRIPLETAP device */ return tp->num_slots; } static enum libinput_config_status tp_3fg_drag_set_enabled(struct libinput_device *device, enum libinput_config_3fg_drag_state enabled) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); if (tp_3fg_drag_count(device) < 3) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; switch (enabled) { case LIBINPUT_CONFIG_3FG_DRAG_DISABLED: tp->drag_3fg.want_nfingers = 0; break; case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG: tp->drag_3fg.want_nfingers = 3; break; case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG: tp->drag_3fg.want_nfingers = 4; break; } tp_3fg_drag_apply_config(evdev_device(device)); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_3fg_drag_state tp_3fg_drag_get_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); switch (tp->drag_3fg.want_nfingers) { case 3: return LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG; case 4: return LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG; } return LIBINPUT_CONFIG_3FG_DRAG_DISABLED; } static enum libinput_config_3fg_drag_state tp_3fg_drag_default(struct tp_dispatch *tp) { return LIBINPUT_CONFIG_3FG_DRAG_DISABLED; } static enum libinput_config_3fg_drag_state tp_3fg_drag_get_default_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp_3fg_drag_default(tp); } void tp_3fg_drag_apply_config(struct evdev_device *device) { struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch; if (tp->drag_3fg.want_nfingers == tp->drag_3fg.nfingers) return; if (tp->nfingers_down) return; tp->drag_3fg.nfingers = tp->drag_3fg.want_nfingers; evdev_log_debug(device, "touchpad-3fg-drag: drag is now for %zd fingers\n", tp->drag_3fg.nfingers); } void tp_init_gesture(struct tp_dispatch *tp) { char timer_name[64]; tp->gesture.config.set_hold_enabled = tp_gesture_set_hold_enabled; tp->gesture.config.get_hold_enabled = tp_gesture_is_hold_enabled; tp->gesture.config.get_hold_default = tp_gesture_get_hold_default; tp->device->base.config.gesture = &tp->gesture.config; tp->drag_3fg.config.count = tp_3fg_drag_count; tp->drag_3fg.config.set_enabled = tp_3fg_drag_set_enabled; tp->drag_3fg.config.get_enabled = tp_3fg_drag_get_enabled; tp->drag_3fg.config.get_default = tp_3fg_drag_get_default_enabled; tp->device->base.config.drag_3fg = &tp->drag_3fg.config; switch (tp_3fg_drag_default(tp)) { case LIBINPUT_CONFIG_3FG_DRAG_DISABLED: tp->drag_3fg.nfingers = 0; break; case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG: tp->drag_3fg.nfingers = 3; break; case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG: tp->drag_3fg.nfingers = 4; break; } tp->drag_3fg.want_nfingers = tp->drag_3fg.nfingers; /* two-finger scrolling is always enabled, this flag just * decides whether we detect pinch. semi-mt devices are too * unreliable to do pinch gestures. */ tp->gesture.enabled = tp_gesture_are_gestures_enabled(tp); tp->gesture.state = GESTURE_STATE_NONE; tp->gesture.hold_enabled = tp_gesture_are_gestures_enabled(tp); snprintf(timer_name, sizeof(timer_name), "%s gestures", evdev_device_get_sysname(tp->device)); libinput_timer_init(&tp->gesture.finger_count_switch_timer, tp_libinput_context(tp), timer_name, tp_gesture_finger_count_switch_timeout, tp); snprintf(timer_name, sizeof(timer_name), "%s hold", evdev_device_get_sysname(tp->device)); libinput_timer_init(&tp->gesture.hold_timer, tp_libinput_context(tp), timer_name, tp_gesture_hold_timeout, tp); snprintf(timer_name, sizeof(timer_name), "%s drag_3fg", evdev_device_get_sysname(tp->device)); libinput_timer_init(&tp->gesture.drag_3fg_timer, tp_libinput_context(tp), timer_name, tp_gesture_3fg_drag_timeout, tp); } void tp_remove_gesture(struct tp_dispatch *tp) { libinput_timer_cancel(&tp->gesture.finger_count_switch_timer); libinput_timer_cancel(&tp->gesture.hold_timer); libinput_timer_cancel(&tp->gesture.drag_3fg_timer); } libinput-1.28.1/src/evdev-mt-touchpad-tap.c000066400000000000000000001237161477265155700205370ustar00rootroot00000000000000/* * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "evdev-mt-touchpad.h" #define DEFAULT_TAP_TIMEOUT_PERIOD ms2us(180) #define DEFAULT_DRAG_TIMEOUT_PERIOD_BASE ms2us(160) #define DEFAULT_DRAG_TIMEOUT_PERIOD_PERFINGER ms2us(20) #define DEFAULT_DRAGLOCK_TIMEOUT_PERIOD ms2us(300) #define DEFAULT_TAP_MOVE_THRESHOLD 1.3 /* mm */ enum tap_event { TAP_EVENT_TOUCH = 12, TAP_EVENT_MOTION, TAP_EVENT_RELEASE, TAP_EVENT_BUTTON, TAP_EVENT_TIMEOUT, TAP_EVENT_THUMB, TAP_EVENT_PALM, TAP_EVENT_PALM_UP, }; /***************************************** * DO NOT EDIT THIS FILE! * * Look at the state diagram in doc/touchpad-tap-state-machine.svg * (generated with https://www.diagrams.net) * * Any changes in this file must be represented in the diagram. */ static inline const char* tap_state_to_str(enum tp_tap_state state) { switch(state) { CASE_RETURN_STRING(TAP_STATE_IDLE); CASE_RETURN_STRING(TAP_STATE_HOLD); CASE_RETURN_STRING(TAP_STATE_TOUCH); CASE_RETURN_STRING(TAP_STATE_1FGTAP_TAPPED); CASE_RETURN_STRING(TAP_STATE_2FGTAP_TAPPED); CASE_RETURN_STRING(TAP_STATE_3FGTAP_TAPPED); CASE_RETURN_STRING(TAP_STATE_TOUCH_2); CASE_RETURN_STRING(TAP_STATE_TOUCH_2_HOLD); CASE_RETURN_STRING(TAP_STATE_TOUCH_2_RELEASE); CASE_RETURN_STRING(TAP_STATE_TOUCH_3); CASE_RETURN_STRING(TAP_STATE_TOUCH_3_HOLD); CASE_RETURN_STRING(TAP_STATE_TOUCH_3_RELEASE); CASE_RETURN_STRING(TAP_STATE_TOUCH_3_RELEASE_2); CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING); CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING); CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING); CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_WAIT); CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_WAIT); CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_WAIT); CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP); CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP); CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP); CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_TAP); CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_TAP); CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_TAP); CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_2); CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_2); CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_2); CASE_RETURN_STRING(TAP_STATE_DEAD); } return NULL; } static inline const char* tap_event_to_str(enum tap_event event) { switch(event) { CASE_RETURN_STRING(TAP_EVENT_TOUCH); CASE_RETURN_STRING(TAP_EVENT_MOTION); CASE_RETURN_STRING(TAP_EVENT_RELEASE); CASE_RETURN_STRING(TAP_EVENT_TIMEOUT); CASE_RETURN_STRING(TAP_EVENT_BUTTON); CASE_RETURN_STRING(TAP_EVENT_THUMB); CASE_RETURN_STRING(TAP_EVENT_PALM); CASE_RETURN_STRING(TAP_EVENT_PALM_UP); } return NULL; } static inline void log_tap_bug(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event) { evdev_log_bug_libinput(tp->device, "%d: invalid tap event %s in state %s\n", t->index, tap_event_to_str(event), tap_state_to_str(tp->tap.state)); } static void tp_tap_notify(struct tp_dispatch *tp, uint64_t time, int nfingers, enum libinput_button_state state) { int32_t button; int32_t button_map[2][3] = { { BTN_LEFT, BTN_RIGHT, BTN_MIDDLE }, { BTN_LEFT, BTN_MIDDLE, BTN_RIGHT }, }; assert(tp->tap.map < ARRAY_LENGTH(button_map)); if (nfingers < 1 || nfingers > 3) return; tp_gesture_cancel(tp, time); button = button_map[tp->tap.map][nfingers - 1]; if (state == LIBINPUT_BUTTON_STATE_PRESSED) tp->tap.buttons_pressed |= bit(nfingers); else tp->tap.buttons_pressed &= ~bit(nfingers); evdev_pointer_notify_button(tp->device, time, button, state); } static void tp_tap_set_timer(struct tp_dispatch *tp, uint64_t time) { libinput_timer_set(&tp->tap.timer, time + DEFAULT_TAP_TIMEOUT_PERIOD); } static void tp_tap_set_drag_timer(struct tp_dispatch *tp, uint64_t time, int nfingers_tapped) { libinput_timer_set(&tp->tap.timer, time + DEFAULT_DRAG_TIMEOUT_PERIOD_BASE + (nfingers_tapped * DEFAULT_DRAG_TIMEOUT_PERIOD_PERFINGER)); } static void tp_tap_set_draglock_timer(struct tp_dispatch *tp, uint64_t time) { libinput_timer_set(&tp->tap.timer, time + DEFAULT_DRAGLOCK_TIMEOUT_PERIOD); } static void tp_tap_clear_timer(struct tp_dispatch *tp) { libinput_timer_cancel(&tp->tap.timer); } static void tp_tap_move_to_dead(struct tp_dispatch *tp, struct tp_touch *t) { tp->tap.state = TAP_STATE_DEAD; t->tap.state = TAP_TOUCH_STATE_DEAD; tp_tap_clear_timer(tp); } static void tp_tap_idle_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: break; case TAP_EVENT_MOTION: log_tap_bug(tp, t, event); break; case TAP_EVENT_TIMEOUT: break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: log_tap_bug(tp, t, event); break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_IDLE; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH_2; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp_tap_notify(tp, tp->tap.saved_press_time, 1, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { tp->tap.state = TAP_STATE_1FGTAP_TAPPED; tp->tap.saved_release_time = time; tp_tap_set_drag_timer(tp, time, 1); } else { tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_HOLD; tp_tap_clear_timer(tp); tp_gesture_tap_timeout(tp, time); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: tp->tap.state = TAP_STATE_IDLE; t->tap.is_thumb = true; tp->tap.nfingers_down--; t->tap.state = TAP_TOUCH_STATE_DEAD; tp_tap_clear_timer(tp); break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_IDLE; tp_tap_clear_timer(tp); break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_hold_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH_2; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_IDLE; break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: tp->tap.state = TAP_STATE_IDLE; t->tap.is_thumb = true; tp->tap.nfingers_down--; t->tap.state = TAP_TOUCH_STATE_DEAD; break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_IDLE; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_tapped_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_MOTION: case TAP_EVENT_RELEASE: log_tap_bug(tp, t, event); break; case TAP_EVENT_TOUCH: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP, TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP, TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; } case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_IDLE; tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: log_tap_bug(tp, t, event); break; case TAP_EVENT_PALM: log_tap_bug(tp, t, event); break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch2_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH_3; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_TOUCH_2_RELEASE; tp->tap.saved_release_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_TOUCH_2_HOLD; tp_gesture_tap_timeout(tp, time); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_TOUCH; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch2_hold_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH_3; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_HOLD; break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_TOUCH_2_HOLD; break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_HOLD; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch2_release_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_TOUCH_2_HOLD; t->tap.state = TAP_TOUCH_STATE_DEAD; tp_tap_clear_timer(tp); break; case TAP_EVENT_RELEASE: tp_tap_notify(tp, tp->tap.saved_press_time, 2, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { tp->tap.state = TAP_STATE_2FGTAP_TAPPED; tp_tap_set_drag_timer(tp, time, 2); } else { tp_tap_notify(tp, tp->tap.saved_release_time, 2, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_HOLD; break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: /* There's only one saved press time and it's overwritten by * the last touch down. So in the case of finger down, palm * down, finger up, palm detected, we use the * palm touch's press time here instead of the finger's press * time. Let's wait and see if that's an issue. */ tp_tap_notify(tp, tp->tap.saved_press_time, 1, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { /* For a single-finger tap the timer delay is the same * as for the release of the finger that became a palm, * no reset necessary */ tp->tap.state = TAP_STATE_1FGTAP_TAPPED; } else { tp_tap_notify(tp, tp->tap.saved_release_time, 1, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch3_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_DEAD; tp_tap_clear_timer(tp); break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_TOUCH_3_HOLD; tp_tap_clear_timer(tp); tp_gesture_tap_timeout(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_TOUCH_3_RELEASE; tp->tap.saved_release_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_TOUCH_2; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch3_hold_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_DEAD; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_TOUCH_2_HOLD; break; case TAP_EVENT_MOTION: tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_TOUCH_2_HOLD; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch3_release_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_TOUCH_3; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_TOUCH_3_RELEASE_2; tp_tap_set_timer(tp, time); break; case TAP_EVENT_MOTION: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_TOUCH_2_HOLD; break; case TAP_EVENT_BUTTON: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp->tap.state = TAP_STATE_TOUCH_2_RELEASE; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_touch3_release2_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_TOUCH: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_TOUCH_2; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_RELEASE: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { tp->tap.state = TAP_STATE_3FGTAP_TAPPED; tp_tap_set_drag_timer(tp, time, 3); } else { tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_MOTION: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp_tap_move_to_dead(tp, t); break; case TAP_EVENT_TIMEOUT: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_HOLD; break; case TAP_EVENT_BUTTON: tp_tap_notify(tp, tp->tap.saved_press_time, 3, LIBINPUT_BUTTON_STATE_PRESSED); tp_tap_notify(tp, tp->tap.saved_release_time, 3, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_DEAD; break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp_tap_notify(tp, tp->tap.saved_press_time, 2, LIBINPUT_BUTTON_STATE_PRESSED); if (tp->tap.drag_enabled) { /* Resetting the timer to the appropriate delay * for a two-finger tap would be ideal, but the * timestamp of the last real finger release is lost, * so the in-progress similar delay for release * of the finger which became a palm instead * will have to do */ tp->tap.state = TAP_STATE_2FGTAP_TAPPED; } else { tp_tap_notify(tp, tp->tap.saved_release_time, 2, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_TOUCH: { tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_TOUCH_2; tp->tap.saved_press_time = time; tp_tap_set_timer(tp, time); break; } case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_1FGTAP_TAPPED; tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); tp_tap_notify(tp, tp->tap.saved_press_time, 1, LIBINPUT_BUTTON_STATE_PRESSED); tp->tap.saved_release_time = time; tp_tap_set_timer(tp, time); break; case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING, TAP_STATE_2FGTAP_DRAGGING, TAP_STATE_3FGTAP_DRAGGING, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_TAPPED, TAP_STATE_2FGTAP_TAPPED, TAP_STATE_3FGTAP_TAPPED, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dragging_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_TOUCH: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING_2, TAP_STATE_2FGTAP_DRAGGING_2, TAP_STATE_3FGTAP_DRAGGING_2, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_RELEASE: if (tp->tap.drag_lock != LIBINPUT_CONFIG_DRAG_LOCK_DISABLED) { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING_WAIT, TAP_STATE_2FGTAP_DRAGGING_WAIT, TAP_STATE_3FGTAP_DRAGGING_WAIT, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; if (tp->tap.drag_lock == LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT) tp_tap_set_draglock_timer(tp, time); } else { tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; } break; case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: /* noop */ break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: tp_tap_notify(tp, tp->tap.saved_release_time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); tp->tap.state = TAP_STATE_IDLE; break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dragging_wait_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_TOUCH: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING_OR_TAP, TAP_STATE_2FGTAP_DRAGGING_OR_TAP, TAP_STATE_3FGTAP_DRAGGING_OR_TAP, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; tp_tap_set_timer(tp, time); break; } case TAP_EVENT_RELEASE: case TAP_EVENT_MOTION: log_tap_bug(tp, t, event); break; case TAP_EVENT_TIMEOUT: tp->tap.state = TAP_STATE_IDLE; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: case TAP_EVENT_PALM: log_tap_bug(tp, t, event); break; case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dragging_tap_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_TOUCH: { tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); tp_tap_clear_timer(tp); tp_tap_move_to_dead(tp, t); break; } case TAP_EVENT_RELEASE: tp->tap.state = TAP_STATE_IDLE; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING, TAP_STATE_2FGTAP_DRAGGING, TAP_STATE_3FGTAP_DRAGGING, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING_WAIT, TAP_STATE_2FGTAP_DRAGGING_WAIT, TAP_STATE_3FGTAP_DRAGGING_WAIT, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dragging2_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time, int nfingers_tapped) { switch (event) { case TAP_EVENT_RELEASE: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING, TAP_STATE_2FGTAP_DRAGGING, TAP_STATE_3FGTAP_DRAGGING, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_TOUCH: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: /* noop */ break; case TAP_EVENT_BUTTON: tp->tap.state = TAP_STATE_DEAD; tp_tap_notify(tp, time, nfingers_tapped, LIBINPUT_BUTTON_STATE_RELEASED); break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: { enum tp_tap_state dest[3] = { TAP_STATE_1FGTAP_DRAGGING, TAP_STATE_2FGTAP_DRAGGING, TAP_STATE_3FGTAP_DRAGGING, }; assert(nfingers_tapped >= 1 && nfingers_tapped <= 3); tp->tap.state = dest[nfingers_tapped - 1]; break; } case TAP_EVENT_PALM_UP: break; } } static void tp_tap_dead_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { switch (event) { case TAP_EVENT_RELEASE: if (tp->tap.nfingers_down == 0) tp->tap.state = TAP_STATE_IDLE; break; case TAP_EVENT_TOUCH: case TAP_EVENT_MOTION: case TAP_EVENT_TIMEOUT: case TAP_EVENT_BUTTON: break; case TAP_EVENT_THUMB: break; case TAP_EVENT_PALM: case TAP_EVENT_PALM_UP: if (tp->tap.nfingers_down == 0) tp->tap.state = TAP_STATE_IDLE; break; } } static void tp_tap_handle_event(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event, uint64_t time) { enum tp_tap_state current; current = tp->tap.state; switch(tp->tap.state) { case TAP_STATE_IDLE: tp_tap_idle_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH: tp_tap_touch_handle_event(tp, t, event, time); break; case TAP_STATE_HOLD: tp_tap_hold_handle_event(tp, t, event, time); break; case TAP_STATE_1FGTAP_TAPPED: tp_tap_tapped_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_TAPPED: tp_tap_tapped_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_TAPPED: tp_tap_tapped_handle_event(tp, t, event, time, 3); break; case TAP_STATE_TOUCH_2: tp_tap_touch2_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_2_HOLD: tp_tap_touch2_hold_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_2_RELEASE: tp_tap_touch2_release_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_3: tp_tap_touch3_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_3_HOLD: tp_tap_touch3_hold_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_3_RELEASE: tp_tap_touch3_release_handle_event(tp, t, event, time); break; case TAP_STATE_TOUCH_3_RELEASE_2: tp_tap_touch3_release2_handle_event(tp, t, event, time); break; case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP: tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP: tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP: tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time, 3); break; case TAP_STATE_1FGTAP_DRAGGING: tp_tap_dragging_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_DRAGGING: tp_tap_dragging_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_DRAGGING: tp_tap_dragging_handle_event(tp, t, event, time, 3); break; case TAP_STATE_1FGTAP_DRAGGING_WAIT: tp_tap_dragging_wait_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_DRAGGING_WAIT: tp_tap_dragging_wait_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_DRAGGING_WAIT: tp_tap_dragging_wait_handle_event(tp, t, event, time, 3); break; case TAP_STATE_1FGTAP_DRAGGING_OR_TAP: tp_tap_dragging_tap_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_DRAGGING_OR_TAP: tp_tap_dragging_tap_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_DRAGGING_OR_TAP: tp_tap_dragging_tap_handle_event(tp, t, event, time, 3); break; case TAP_STATE_1FGTAP_DRAGGING_2: tp_tap_dragging2_handle_event(tp, t, event, time, 1); break; case TAP_STATE_2FGTAP_DRAGGING_2: tp_tap_dragging2_handle_event(tp, t, event, time, 2); break; case TAP_STATE_3FGTAP_DRAGGING_2: tp_tap_dragging2_handle_event(tp, t, event, time, 3); break; case TAP_STATE_DEAD: tp_tap_dead_handle_event(tp, t, event, time); break; } if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD) tp_tap_clear_timer(tp); if (current != tp->tap.state) evdev_log_debug(tp->device, "tap: touch %d (%s), tap state %s → %s → %s\n", t ? (int)t->index : -1, t ? touch_state_to_str(t->state) : "", tap_state_to_str(current), tap_event_to_str(event), tap_state_to_str(tp->tap.state)); } static bool tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp, struct tp_touch *t) { struct phys_coords mm = tp_phys_delta(tp, device_delta(t->point, t->tap.initial)); /* if we have more fingers down than slots, we know that synaptics * touchpads are likely to give us pointer jumps. * This triggers the movement threshold, making three-finger taps * less reliable (#101435) * * This uses the real nfingers_down, not the one for taps. */ if (tp->device->model_flags & EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD && (tp->nfingers_down > 2 || tp->old_nfingers_down > 2) && (tp->nfingers_down > tp->num_slots || tp->old_nfingers_down > tp->num_slots)) { return false; } /* Semi-mt devices will give us large movements on finger release, * depending which touch is released. Make sure we ignore any * movement in the same frame as a finger change. */ if (tp->semi_mt && tp->nfingers_down != tp->old_nfingers_down) return false; return length_in_mm(mm) > DEFAULT_TAP_MOVE_THRESHOLD; } static bool tp_tap_enabled(struct tp_dispatch *tp) { return tp->tap.enabled && !tp->tap.suspended; } int tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; int filter_motion = 0; if (!tp_tap_enabled(tp)) return 0; /* Handle queued button pressed events from clickpads. For touchpads * with separate physical buttons, ignore button pressed events so they * don't interfere with tapping. */ if (tp->buttons.is_clickpad && tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) tp_tap_handle_event(tp, NULL, TAP_EVENT_BUTTON, time); tp_for_each_touch(tp, t) { if (!t->dirty || t->state == TOUCH_NONE) continue; if (tp->buttons.is_clickpad && tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) t->tap.state = TAP_TOUCH_STATE_DEAD; /* If a touch was considered thumb for tapping once, we * ignore it for the rest of lifetime */ if (t->tap.is_thumb) continue; /* A palm tap needs to be properly released because we might * be who-knows-where in the state machine. Otherwise, we * ignore any event from it. */ if (t->tap.is_palm) { if (t->state == TOUCH_END) tp_tap_handle_event(tp, t, TAP_EVENT_PALM_UP, time); continue; } if (t->state == TOUCH_HOVERING) continue; if (t->palm.state != PALM_NONE) { assert(!t->tap.is_palm); t->tap.is_palm = true; t->tap.state = TAP_TOUCH_STATE_DEAD; if (t->state != TOUCH_BEGIN) { tp_tap_handle_event(tp, t, TAP_EVENT_PALM, time); assert(tp->tap.nfingers_down > 0); tp->tap.nfingers_down--; } } else if (t->state == TOUCH_BEGIN) { /* The simple version: if a touch is a thumb on * begin we ignore it. All other thumb touches * follow the normal tap state for now */ if (tp_thumb_ignored_for_tap(tp, t)) { t->tap.is_thumb = true; continue; } t->tap.state = TAP_TOUCH_STATE_TOUCH; t->tap.initial = t->point; tp->tap.nfingers_down++; tp_tap_handle_event(tp, t, TAP_EVENT_TOUCH, time); } else if (t->state == TOUCH_END) { if (t->was_down) { assert(tp->tap.nfingers_down >= 1); tp->tap.nfingers_down--; tp_tap_handle_event(tp, t, TAP_EVENT_RELEASE, time); } t->tap.state = TAP_TOUCH_STATE_IDLE; } else if (tp->tap.state != TAP_STATE_IDLE && tp_thumb_ignored(tp, t)) { tp_tap_handle_event(tp, t, TAP_EVENT_THUMB, time); } else if (tp->tap.state != TAP_STATE_IDLE && tp_tap_exceeds_motion_threshold(tp, t)) { struct tp_touch *tmp; /* Any touch exceeding the threshold turns all * touches into DEAD */ tp_for_each_touch(tp, tmp) { if (tmp->tap.state == TAP_TOUCH_STATE_TOUCH) tmp->tap.state = TAP_TOUCH_STATE_DEAD; } tp_tap_handle_event(tp, t, TAP_EVENT_MOTION, time); } } /** * In any state where motion exceeding the move threshold would * move to the next state, filter that motion until we actually * exceed it. This prevents small motion events while we're waiting * on a decision if a tap is a tap. */ switch (tp->tap.state) { case TAP_STATE_TOUCH: case TAP_STATE_1FGTAP_TAPPED: case TAP_STATE_2FGTAP_TAPPED: case TAP_STATE_3FGTAP_TAPPED: case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP: case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP: case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP: case TAP_STATE_1FGTAP_DRAGGING_OR_TAP: case TAP_STATE_2FGTAP_DRAGGING_OR_TAP: case TAP_STATE_3FGTAP_DRAGGING_OR_TAP: case TAP_STATE_TOUCH_2: case TAP_STATE_TOUCH_3: filter_motion = 1; break; default: break; } assert(tp->tap.nfingers_down <= tp->nfingers_down); if (tp->nfingers_down == 0) assert(tp->tap.nfingers_down == 0); return filter_motion; } static inline void tp_tap_update_map(struct tp_dispatch *tp) { if (tp->tap.state != TAP_STATE_IDLE) return; if (tp->tap.map != tp->tap.want_map) tp->tap.map = tp->tap.want_map; } void tp_tap_post_process_state(struct tp_dispatch *tp) { tp_tap_update_map(tp); } static void tp_tap_handle_timeout(uint64_t time, void *data) { struct tp_dispatch *tp = data; struct tp_touch *t; tp_tap_handle_event(tp, NULL, TAP_EVENT_TIMEOUT, time); tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE || t->tap.state == TAP_TOUCH_STATE_IDLE) continue; t->tap.state = TAP_TOUCH_STATE_DEAD; } } static void tp_tap_enabled_update(struct tp_dispatch *tp, bool suspended, bool enabled, uint64_t time) { bool was_enabled = tp_tap_enabled(tp); tp->tap.suspended = suspended; tp->tap.enabled = enabled; if (tp_tap_enabled(tp) == was_enabled) return; if (tp_tap_enabled(tp)) { struct tp_touch *t; /* On resume, all touches are considered palms */ tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE) continue; t->tap.is_palm = true; t->tap.state = TAP_TOUCH_STATE_DEAD; } tp->tap.state = TAP_STATE_IDLE; tp->tap.nfingers_down = 0; } else { tp_release_all_taps(tp, time); } } static int tp_tap_config_count(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return min(tp->ntouches, 3U); /* we only do up to 3 finger tap */ } static enum libinput_config_status tp_tap_config_set_enabled(struct libinput_device *device, enum libinput_config_tap_state enabled) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); tp_tap_enabled_update(tp, tp->tap.suspended, (enabled == LIBINPUT_CONFIG_TAP_ENABLED), libinput_now(device->seat->libinput)); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_tap_state tp_tap_config_is_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->tap.enabled ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED; } static enum libinput_config_tap_state tp_tap_default(struct evdev_device *evdev) { /** * If we don't have a left button we must have tapping enabled by * default. */ if (!libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_LEFT)) return LIBINPUT_CONFIG_TAP_ENABLED; /** * Tapping is disabled by default for two reasons: * * if you don't know that tapping is a thing (or enabled by * default), you get spurious mouse events that make the desktop * feel buggy. * * if you do know what tapping is and you want it, you * usually know where to enable it, or at least you can search for * it. */ return LIBINPUT_CONFIG_TAP_DISABLED; } static enum libinput_config_tap_state tp_tap_config_get_default(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); return tp_tap_default(evdev); } static enum libinput_config_status tp_tap_config_set_map(struct libinput_device *device, enum libinput_config_tap_button_map map) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); tp->tap.want_map = map; tp_tap_update_map(tp); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_tap_button_map tp_tap_config_get_map(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->tap.want_map; } static enum libinput_config_tap_button_map tp_tap_config_get_default_map(struct libinput_device *device) { return LIBINPUT_CONFIG_TAP_MAP_LRM; } static enum libinput_config_status tp_tap_config_set_drag_enabled(struct libinput_device *device, enum libinput_config_drag_state enabled) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); tp->tap.drag_enabled = enabled; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_drag_state tp_tap_config_get_drag_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->tap.drag_enabled; } static inline enum libinput_config_drag_state tp_drag_default(struct evdev_device *device) { return LIBINPUT_CONFIG_DRAG_ENABLED; } static enum libinput_config_drag_state tp_tap_config_get_default_drag_enabled(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); return tp_drag_default(evdev); } static enum libinput_config_status tp_tap_config_set_draglock_enabled(struct libinput_device *device, enum libinput_config_drag_lock_state enabled) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); tp->tap.drag_lock = enabled; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_drag_lock_state tp_tap_config_get_draglock_enabled(struct libinput_device *device) { struct evdev_dispatch *dispatch = evdev_device(device)->dispatch; struct tp_dispatch *tp = tp_dispatch(dispatch); return tp->tap.drag_lock; } static inline enum libinput_config_drag_lock_state tp_drag_lock_default(struct evdev_device *device) { return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; } static enum libinput_config_drag_lock_state tp_tap_config_get_default_draglock_enabled(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); return tp_drag_lock_default(evdev); } void tp_init_tap(struct tp_dispatch *tp) { char timer_name[64]; tp->tap.config.count = tp_tap_config_count; tp->tap.config.set_enabled = tp_tap_config_set_enabled; tp->tap.config.get_enabled = tp_tap_config_is_enabled; tp->tap.config.get_default = tp_tap_config_get_default; tp->tap.config.set_map = tp_tap_config_set_map; tp->tap.config.get_map = tp_tap_config_get_map; tp->tap.config.get_default_map = tp_tap_config_get_default_map; tp->tap.config.set_drag_enabled = tp_tap_config_set_drag_enabled; tp->tap.config.get_drag_enabled = tp_tap_config_get_drag_enabled; tp->tap.config.get_default_drag_enabled = tp_tap_config_get_default_drag_enabled; tp->tap.config.set_draglock_enabled = tp_tap_config_set_draglock_enabled; tp->tap.config.get_draglock_enabled = tp_tap_config_get_draglock_enabled; tp->tap.config.get_default_draglock_enabled = tp_tap_config_get_default_draglock_enabled; tp->device->base.config.tap = &tp->tap.config; tp->tap.state = TAP_STATE_IDLE; tp->tap.enabled = tp_tap_default(tp->device); tp->tap.map = LIBINPUT_CONFIG_TAP_MAP_LRM; tp->tap.want_map = tp->tap.map; tp->tap.drag_enabled = tp_drag_default(tp->device); tp->tap.drag_lock = tp_drag_lock_default(tp->device); snprintf(timer_name, sizeof(timer_name), "%s tap", evdev_device_get_sysname(tp->device)); libinput_timer_init(&tp->tap.timer, tp_libinput_context(tp), timer_name, tp_tap_handle_timeout, tp); } void tp_remove_tap(struct tp_dispatch *tp) { libinput_timer_cancel(&tp->tap.timer); } void tp_release_all_taps(struct tp_dispatch *tp, uint64_t now) { struct tp_touch *t; int i; for (i = 1; i <= 3; i++) { if (tp->tap.buttons_pressed & bit(i)) tp_tap_notify(tp, now, i, LIBINPUT_BUTTON_STATE_RELEASED); } /* To neutralize all current touches, we make them all palms */ tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE) continue; if (t->tap.is_palm) continue; t->tap.is_palm = true; t->tap.state = TAP_TOUCH_STATE_DEAD; } tp->tap.state = TAP_STATE_IDLE; tp->tap.nfingers_down = 0; } void tp_tap_suspend(struct tp_dispatch *tp, uint64_t time) { tp_tap_enabled_update(tp, true, tp->tap.enabled, time); } void tp_tap_resume(struct tp_dispatch *tp, uint64_t time) { tp_tap_enabled_update(tp, false, tp->tap.enabled, time); } bool tp_tap_dragging(const struct tp_dispatch *tp) { switch (tp->tap.state) { case TAP_STATE_1FGTAP_DRAGGING: case TAP_STATE_2FGTAP_DRAGGING: case TAP_STATE_3FGTAP_DRAGGING: case TAP_STATE_1FGTAP_DRAGGING_2: case TAP_STATE_2FGTAP_DRAGGING_2: case TAP_STATE_3FGTAP_DRAGGING_2: case TAP_STATE_1FGTAP_DRAGGING_WAIT: case TAP_STATE_2FGTAP_DRAGGING_WAIT: case TAP_STATE_3FGTAP_DRAGGING_WAIT: case TAP_STATE_1FGTAP_DRAGGING_OR_TAP: case TAP_STATE_2FGTAP_DRAGGING_OR_TAP: case TAP_STATE_3FGTAP_DRAGGING_OR_TAP: return true; default: return false; } } bool tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp) { switch (tp->tap.state) { case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP: case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP: case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP: return true; default: return false; } } libinput-1.28.1/src/evdev-mt-touchpad-thumb.c000066400000000000000000000304101477265155700210560ustar00rootroot00000000000000/* * Copyright © 2019 Matt Mayfield * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev-mt-touchpad.h" /* distance between fingers to assume it is not a scroll */ #define SCROLL_MM_X 35 #define SCROLL_MM_Y 25 #define THUMB_TIMEOUT ms2us(100) static inline const char* thumb_state_to_str(enum tp_thumb_state state) { switch(state){ CASE_RETURN_STRING(THUMB_STATE_FINGER); CASE_RETURN_STRING(THUMB_STATE_JAILED); CASE_RETURN_STRING(THUMB_STATE_PINCH); CASE_RETURN_STRING(THUMB_STATE_SUPPRESSED); CASE_RETURN_STRING(THUMB_STATE_REVIVED); CASE_RETURN_STRING(THUMB_STATE_REVIVED_JAILED); CASE_RETURN_STRING(THUMB_STATE_DEAD); } return NULL; } static void tp_thumb_set_state(struct tp_dispatch *tp, struct tp_touch *t, enum tp_thumb_state state) { unsigned int index = t ? t->index : UINT_MAX; if (tp->thumb.state == state && tp->thumb.index == index) return; evdev_log_debug(tp->device, "thumb: touch %d, %s → %s\n", (int)index, thumb_state_to_str(tp->thumb.state), thumb_state_to_str(state)); tp->thumb.state = state; tp->thumb.index = index; } void tp_thumb_reset(struct tp_dispatch *tp) { tp->thumb.state = THUMB_STATE_FINGER; tp->thumb.index = UINT_MAX; tp->thumb.pinch_eligible = true; } static void tp_thumb_lift(struct tp_dispatch *tp) { tp->thumb.state = THUMB_STATE_FINGER; tp->thumb.index = UINT_MAX; } static bool tp_thumb_in_exclusion_area(const struct tp_dispatch *tp, const struct tp_touch *t) { return (t->point.y > tp->thumb.lower_thumb_line && tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE); } static bool tp_thumb_detect_pressure_size(const struct tp_dispatch *tp, const struct tp_touch *t) { bool is_thumb = false; if (tp->thumb.use_pressure && t->pressure > tp->thumb.pressure_threshold && tp_thumb_in_exclusion_area(tp, t)) { is_thumb = true; } if (tp->thumb.use_size && (t->major > tp->thumb.size_threshold) && (t->minor < (tp->thumb.size_threshold * 0.6))) { is_thumb = true; } return is_thumb; } static bool tp_thumb_needs_jail(const struct tp_dispatch *tp, const struct tp_touch *t) { if (t->point.y < tp->thumb.upper_thumb_line || tp->scroll.method == LIBINPUT_CONFIG_SCROLL_EDGE) return false; if (!tp_thumb_in_exclusion_area(tp, t) && (tp->thumb.use_size || tp->thumb.use_pressure) && !tp_thumb_detect_pressure_size(tp, t)) return false; if (t->speed.exceeded_count >= 10) return false; return true; } bool tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t) { return (tp->thumb.detect_thumbs && tp->thumb.index == t->index && (tp->thumb.state == THUMB_STATE_JAILED || tp->thumb.state == THUMB_STATE_PINCH || tp->thumb.state == THUMB_STATE_SUPPRESSED || tp->thumb.state == THUMB_STATE_REVIVED_JAILED || tp->thumb.state == THUMB_STATE_DEAD)); } bool tp_thumb_ignored_for_tap(const struct tp_dispatch *tp, const struct tp_touch *t) { return (tp->thumb.detect_thumbs && tp->thumb.index == t->index && (tp->thumb.state == THUMB_STATE_PINCH || tp->thumb.state == THUMB_STATE_SUPPRESSED || tp->thumb.state == THUMB_STATE_DEAD)); } bool tp_thumb_ignored_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t) { return (tp->thumb.detect_thumbs && tp->thumb.index == t->index && (tp->thumb.state == THUMB_STATE_JAILED || tp->thumb.state == THUMB_STATE_SUPPRESSED || tp->thumb.state == THUMB_STATE_REVIVED_JAILED || tp->thumb.state == THUMB_STATE_DEAD)); } void tp_thumb_suppress(struct tp_dispatch *tp, struct tp_touch *t) { if(tp->thumb.state == THUMB_STATE_FINGER || tp->thumb.state == THUMB_STATE_JAILED || tp->thumb.state == THUMB_STATE_PINCH || tp->thumb.index != t->index) { tp_thumb_set_state(tp, t, THUMB_STATE_SUPPRESSED); return; } tp_thumb_set_state(tp, t, THUMB_STATE_DEAD); } static void tp_thumb_pinch(struct tp_dispatch *tp, struct tp_touch *t) { if(tp->thumb.state == THUMB_STATE_FINGER || tp->thumb.state == THUMB_STATE_JAILED || tp->thumb.index != t->index) tp_thumb_set_state(tp, t, THUMB_STATE_PINCH); else if (tp->thumb.state != THUMB_STATE_PINCH) tp_thumb_suppress(tp, t); } static void tp_thumb_revive(struct tp_dispatch *tp, struct tp_touch *t) { if((tp->thumb.state != THUMB_STATE_SUPPRESSED && tp->thumb.state != THUMB_STATE_PINCH) || (tp->thumb.index != t->index)) return; if(tp_thumb_needs_jail(tp, t)) tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED_JAILED); else tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED); } void tp_thumb_update_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (!tp->thumb.detect_thumbs) return; /* Once any active touch exceeds the speed threshold, don't * try to detect pinches until all touches lift. */ if (t->speed.exceeded_count >= 10 && tp->thumb.pinch_eligible && tp->gesture.state == GESTURE_STATE_NONE) { tp->thumb.pinch_eligible = false; if(tp->thumb.state == THUMB_STATE_PINCH) { struct tp_touch *thumb; tp_for_each_touch(tp, thumb) { if (thumb->index != tp->thumb.index) continue; tp_thumb_set_state(tp, thumb, THUMB_STATE_SUPPRESSED); break; } } } /* Handle the thumb lifting off the touchpad */ if (t->state == TOUCH_END && t->index == tp->thumb.index) { tp_thumb_lift(tp); return; } /* If this touch is not the only one, thumb updates happen by context * instead of here */ if (tp->nfingers_down > 1) return; /* If we arrived here by other fingers lifting off, revive current touch * if appropriate */ tp_thumb_revive(tp, t); /* First new touch below the lower_thumb_line, or below the upper_thumb_ * line if hardware can't verify it's a finger, starts as JAILED. */ if (t->state == TOUCH_BEGIN && tp_thumb_needs_jail(tp, t)) { tp_thumb_set_state(tp, t, THUMB_STATE_JAILED); return; } /* If a touch breaks the speed threshold, or leaves the thumb area * (upper or lower, depending on HW detection), it "escapes" jail. */ if (tp->thumb.state == THUMB_STATE_JAILED && !(tp_thumb_needs_jail(tp, t))) tp_thumb_set_state(tp, t, THUMB_STATE_FINGER); if (tp->thumb.state == THUMB_STATE_REVIVED_JAILED && !(tp_thumb_needs_jail(tp, t))) tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED); } void tp_thumb_update_multifinger(struct tp_dispatch *tp) { struct tp_touch *t; struct tp_touch *first = NULL, *second = NULL, *newest = NULL, *oldest = NULL; struct device_coords distance; struct phys_coords mm; unsigned int speed_exceeded_count = 0; /* Get the first and second bottom-most touches, the max speed exceeded * count overall, and the newest and oldest touches. */ tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE || t->state == TOUCH_HOVERING) continue; if (t->state == TOUCH_BEGIN) newest = t; speed_exceeded_count = max(speed_exceeded_count, t->speed.exceeded_count); if (!oldest || t->initial_time < oldest->initial_time) { oldest = t; } if (!first) { first = t; continue; } if (t->point.y > first->point.y) { second = first; first = t; continue; } if (!second || t->point.y > second->point.y ) { second = t; } } if (!first || !second) return; distance.x = abs(first->point.x - second->point.x); distance.y = abs(first->point.y - second->point.y); mm = evdev_device_unit_delta_to_mm(tp->device, &distance); /* Speed-based thumb detection: if an existing finger is moving, and * a new touch arrives, mark it as a thumb if it doesn't qualify as a * 2-finger scroll. Also account for a thumb dropping onto the touchpad * while scrolling or swiping. */ if (newest && tp->thumb.state == THUMB_STATE_FINGER && tp->nfingers_down >= 2 && speed_exceeded_count > 5 && (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG || (mm.x > SCROLL_MM_X || mm.y > SCROLL_MM_Y))) { evdev_log_debug(tp->device, "touch %d is speed-based thumb\n", newest->index); tp_thumb_suppress(tp, newest); return; } /* Contextual thumb detection: When a new touch arrives, check the * timing and position of the two lowest touches. * * If both touches are very close, regardless of timing, and no matter * their absolute position on the touchpad, count them both as live * to support responsive two-finger scrolling. */ if (mm.x < SCROLL_MM_X && mm.y < SCROLL_MM_Y) { tp_thumb_lift(tp); return; } /* If all the touches arrived within a very short time, and all of them * are above the lower_thumb_line, assume the touches are all live to * enable double, triple, and quadruple taps, clicks, and gestures. (If * there is an actual resting thumb, it will be detected later based on * the behavior of the other touches.) */ if (newest && (newest->initial_time - oldest->initial_time) < THUMB_TIMEOUT && first->point.y < tp->thumb.lower_thumb_line) { tp_thumb_lift(tp); return; } /* If we're past the THUMB_TIMEOUT, and the touches are relatively far * apart, then the new touch is unlikely to be a tap or clickfinger. * Proceed with pre-1.14.901 thumb detection. */ if (mm.y > SCROLL_MM_Y) { if (tp->thumb.pinch_eligible) tp_thumb_pinch(tp, first); else tp_thumb_suppress(tp, first); } else { tp_thumb_lift(tp); } } void tp_init_thumb(struct tp_dispatch *tp) { struct evdev_device *device = tp->device; double w = 0.0, h = 0.0; struct device_coords edges; struct phys_coords mm = { 0.0, 0.0 }; uint32_t threshold; struct quirks_context *quirks; struct quirks *q; tp->thumb.detect_thumbs = false; if (!tp->buttons.is_clickpad) return; /* if the touchpad is less than 50mm high, skip thumb detection. * it's too small to meaningfully interact with a thumb on the * touchpad */ evdev_device_get_size(device, &w, &h); if (h < 50) return; tp->thumb.detect_thumbs = true; tp->thumb.use_pressure = false; tp->thumb.pressure_threshold = INT_MAX; tp->thumb.size_threshold = INT_MAX; /* detect thumbs by pressure in the bottom 15mm, detect thumbs by * lingering in the bottom 8mm */ mm.y = h * 0.85; edges = evdev_device_mm_to_units(device, &mm); tp->thumb.upper_thumb_line = edges.y; mm.y = h * 0.92; edges = evdev_device_mm_to_units(device, &mm); tp->thumb.lower_thumb_line = edges.y; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) { if (quirks_get_uint32(q, QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD, &threshold)) { tp->thumb.use_pressure = true; tp->thumb.pressure_threshold = threshold; } } if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_TOUCH_MAJOR)) { if (quirks_get_uint32(q, QUIRK_ATTR_THUMB_SIZE_THRESHOLD, &threshold)) { tp->thumb.use_size = true; tp->thumb.size_threshold = threshold; } } tp_thumb_reset(tp); quirks_unref(q); evdev_log_debug(device, "thumb: enabled thumb detection (area%s%s)\n", tp->thumb.use_pressure ? ", pressure" : "", tp->thumb.use_size ? ", size" : ""); } struct tp_touch* tp_thumb_get_touch(struct tp_dispatch *tp) { struct tp_touch *thumb; if (tp->thumb.index == UINT_MAX) return NULL; tp_for_each_touch(tp, thumb) { if (thumb->index == tp->thumb.index) return thumb; } return NULL; } libinput-1.28.1/src/evdev-mt-touchpad.c000066400000000000000000003143071477265155700177530ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #if HAVE_LIBWACOM #include #endif #include "quirks.h" #include "evdev-mt-touchpad.h" #include "util-input-event.h" #define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT ms2us(300) #define DEFAULT_TRACKPOINT_EVENT_TIMEOUT ms2us(40) #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1 ms2us(200) #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2 ms2us(500) #define FAKE_FINGER_OVERFLOW bit(7) #define THUMB_IGNORE_SPEED_THRESHOLD 20 /* mm/s */ enum notify { DONT_NOTIFY, DO_NOTIFY, }; static inline struct tp_history_point* tp_motion_history_offset(struct tp_touch *t, int offset) { int offset_index = (t->history.index - offset + TOUCHPAD_HISTORY_LENGTH) % TOUCHPAD_HISTORY_LENGTH; return &t->history.samples[offset_index]; } struct normalized_coords tp_filter_motion(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time) { struct device_float_coords raw; const struct normalized_coords zero = { 0.0, 0.0 }; if (device_float_is_zero(*unaccelerated)) return zero; /* Convert to device units with x/y in the same resolution */ raw = tp_scale_to_xaxis(tp, *unaccelerated); return filter_dispatch(tp->device->pointer.filter, &raw, tp, time); } struct normalized_coords tp_filter_motion_unaccelerated(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time) { struct device_float_coords raw; const struct normalized_coords zero = { 0.0, 0.0 }; if (device_float_is_zero(*unaccelerated)) return zero; /* Convert to device units with x/y in the same resolution */ raw = tp_scale_to_xaxis(tp, *unaccelerated); return filter_dispatch_constant(tp->device->pointer.filter, &raw, tp, time); } struct normalized_coords tp_filter_scroll(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time) { struct device_float_coords raw; const struct normalized_coords zero = { 0.0, 0.0 }; if (device_float_is_zero(*unaccelerated)) return zero; /* Convert to device units with x/y in the same resolution */ raw = tp_scale_to_xaxis(tp, *unaccelerated); return filter_dispatch_scroll(tp->device->pointer.filter, &raw, tp, time); } static inline void tp_calculate_motion_speed(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { const struct tp_history_point *last; struct device_coords delta; struct phys_coords mm; double distance; double speed; /* Don't do this on single-touch or semi-mt devices */ if (!tp->has_mt || tp->semi_mt) return; if (t->state != TOUCH_UPDATE) return; /* This doesn't kick in until we have at least 4 events in the * motion history. As a side-effect, this automatically handles the * 2fg scroll where a finger is down and moving fast before the * other finger comes down for the scroll. * * We do *not* reset the speed to 0 here though. The motion history * is reset whenever a new finger is down, so we'd be resetting the * speed and failing. */ if (t->history.count < 4) return; /* TODO: we probably need a speed history here so we can average * across a few events */ last = tp_motion_history_offset(t, 1); delta.x = abs(t->point.x - last->point.x); delta.y = abs(t->point.y - last->point.y); mm = evdev_device_unit_delta_to_mm(tp->device, &delta); distance = length_in_mm(mm); speed = distance/(time - last->time); /* mm/us */ speed *= 1000000; /* mm/s */ t->speed.last_speed = speed; } static inline void tp_motion_history_push(struct tp_touch *t, uint64_t time) { int motion_index = (t->history.index + 1) % TOUCHPAD_HISTORY_LENGTH; if (t->history.count < TOUCHPAD_HISTORY_LENGTH) t->history.count++; t->history.samples[motion_index].point = t->point; t->history.samples[motion_index].time = time; t->history.index = motion_index; } /* Idea: if we got a tuple of *very* quick moves like {Left, Right, * Left}, or {Right, Left, Right}, it means touchpad jitters since no * human can move like that within thresholds. * * We encode left moves as zeroes, and right as ones. We also drop * the array to all zeroes when constraints are not satisfied. Then we * search for the pattern {1,0,1}. It can't match {Left, Right, Left}, * but it does match {Left, Right, Left, Right}, so it's okay. * * This only looks at x changes, y changes are ignored. */ static inline void tp_detect_wobbling(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { int dx, dy; uint64_t dtime; const struct device_coords* prev_point; if (tp->nfingers_down != 1 || tp->nfingers_down != tp->old_nfingers_down) return; if (tp->hysteresis.enabled || t->history.count == 0) return; if (!(tp->queued & TOUCHPAD_EVENT_MOTION)) { t->hysteresis.x_motion_history = 0; return; } prev_point = &tp_motion_history_offset(t, 0)->point; dx = prev_point->x - t->point.x; dy = prev_point->y - t->point.y; dtime = time - tp->hysteresis.last_motion_time; tp->hysteresis.last_motion_time = time; if ((dx == 0 && dy != 0) || dtime > ms2us(40)) { t->hysteresis.x_motion_history = 0; return; } t->hysteresis.x_motion_history >>= 1; if (dx > 0) { /* right move */ static const char r_l_r = 0x5; /* {Right, Left, Right} */ t->hysteresis.x_motion_history |= bit(2); if (t->hysteresis.x_motion_history == r_l_r) { tp->hysteresis.enabled = true; evdev_log_debug(tp->device, "hysteresis enabled. " "See %s/touchpad-jitter.html for details\n", HTTP_DOC_LINK); } } } static inline void tp_motion_hysteresis(struct tp_dispatch *tp, struct tp_touch *t) { if (!tp->hysteresis.enabled) return; if (t->history.count > 0) t->point = evdev_hysteresis(&t->point, &t->hysteresis.center, &tp->hysteresis.margin); t->hysteresis.center = t->point; } static inline void tp_motion_history_reset(struct tp_touch *t) { t->history.count = 0; } static inline struct tp_touch * tp_current_touch(struct tp_dispatch *tp) { return &tp->touches[min(tp->slot, tp->ntouches - 1)]; } static inline struct tp_touch * tp_get_touch(struct tp_dispatch *tp, unsigned int slot) { assert(slot < tp->ntouches); return &tp->touches[slot]; } static inline unsigned int tp_fake_finger_count(struct tp_dispatch *tp) { unsigned int fake_touches = tp->fake_touches & ~(FAKE_FINGER_OVERFLOW|0x1); /* Only one of BTN_TOOL_DOUBLETAP/TRIPLETAP/... may be set at any * time */ if (fake_touches & (fake_touches - 1)) evdev_log_bug_kernel(tp->device, "Invalid fake finger state %#x\n", tp->fake_touches); if (tp->fake_touches & FAKE_FINGER_OVERFLOW) return FAKE_FINGER_OVERFLOW; /* don't count BTN_TOUCH */ return ffs(tp->fake_touches >> 1); } static inline bool tp_fake_finger_is_touching(struct tp_dispatch *tp) { return tp->fake_touches & 0x1; } static inline void tp_fake_finger_set(struct tp_dispatch *tp, unsigned int code, bool is_press) { unsigned int shift; switch (code) { case BTN_TOUCH: if (!is_press) tp->fake_touches &= ~FAKE_FINGER_OVERFLOW; shift = 0; break; case BTN_TOOL_FINGER: shift = 1; break; case BTN_TOOL_DOUBLETAP: case BTN_TOOL_TRIPLETAP: case BTN_TOOL_QUADTAP: shift = code - BTN_TOOL_DOUBLETAP + 2; break; /* when QUINTTAP is released we're either switching to 6 fingers (flag stays in place until BTN_TOUCH is released) or one of DOUBLE/TRIPLE/QUADTAP (will clear the flag on press) */ case BTN_TOOL_QUINTTAP: if (is_press) tp->fake_touches |= FAKE_FINGER_OVERFLOW; return; default: return; } if (is_press) { tp->fake_touches &= ~FAKE_FINGER_OVERFLOW; tp->fake_touches |= bit(shift); } else { tp->fake_touches &= ~bit(shift); } } static inline void tp_new_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE || t->state == TOUCH_HOVERING) return; /* Bug #161: touch ends in the same event frame where it restarts again. That's a kernel bug, so let's complain. */ if (t->state == TOUCH_MAYBE_END) { evdev_log_bug_kernel(tp->device, "touch %d ended and began in in same frame.\n", t->index); tp->nfingers_down++; t->state = TOUCH_UPDATE; t->has_ended = false; return; } /* we begin the touch as hovering because until BTN_TOUCH happens we * don't know if it's a touch down or not. And BTN_TOUCH may happen * after ABS_MT_TRACKING_ID */ tp_motion_history_reset(t); t->dirty = true; t->has_ended = false; t->was_down = false; t->palm.state = PALM_NONE; t->state = TOUCH_HOVERING; t->pinned.is_pinned = false; t->speed.last_speed = 0; t->speed.exceeded_count = 0; t->hysteresis.x_motion_history = 0; tp->queued |= TOUCHPAD_EVENT_MOTION; } static inline void tp_begin_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { t->dirty = true; t->state = TOUCH_BEGIN; t->initial_time = time; t->was_down = true; tp->nfingers_down++; t->palm.time = time; t->tap.is_thumb = false; t->tap.is_palm = false; t->speed.exceeded_count = 0; assert(tp->nfingers_down >= 1); tp->hysteresis.last_motion_time = time; } /** * Schedule a touch to be ended, based on either the events or some * attributes of the touch (size, pressure). In some cases we need to * resurrect a touch that has ended, so this doesn't actually end the touch * yet. All the TOUCH_MAYBE_END touches get properly ended once the device * state has been processed once and we know how many zombie touches we * need. */ static inline void tp_maybe_end_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { switch (t->state) { case TOUCH_NONE: case TOUCH_MAYBE_END: return; case TOUCH_END: evdev_log_bug_libinput(tp->device, "touch %d: already in TOUCH_END\n", t->index); return; case TOUCH_HOVERING: case TOUCH_BEGIN: case TOUCH_UPDATE: break; } if (t->state != TOUCH_HOVERING) { assert(tp->nfingers_down >= 1); tp->nfingers_down--; t->state = TOUCH_MAYBE_END; } else { t->state = TOUCH_NONE; } t->dirty = true; } /** * Inverse to tp_maybe_end_touch(), restores a touch back to its previous * state. */ static inline void tp_recover_ended_touch(struct tp_dispatch *tp, struct tp_touch *t) { t->dirty = true; t->state = TOUCH_UPDATE; tp->nfingers_down++; } /** * End a touch, even if the touch sequence is still active. * Use tp_maybe_end_touch() instead. */ static inline void tp_end_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (t->state != TOUCH_MAYBE_END) { evdev_log_bug_libinput(tp->device, "touch %d should be MAYBE_END, is %d\n", t->index, t->state); return; } t->dirty = true; t->palm.state = PALM_NONE; t->state = TOUCH_END; t->pinned.is_pinned = false; t->palm.time = 0; t->speed.exceeded_count = 0; tp->queued |= TOUCHPAD_EVENT_MOTION; } /** * End the touch sequence on ABS_MT_TRACKING_ID -1 or when the BTN_TOOL_* 0 is received. */ static inline void tp_end_sequence(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { t->has_ended = true; tp_maybe_end_touch(tp, t, time); } static void tp_stop_actions(struct tp_dispatch *tp, uint64_t time) { tp_edge_scroll_stop_events(tp, time); tp_gesture_cancel(tp, time); tp_tap_suspend(tp, time); } struct device_coords tp_get_delta(struct tp_touch *t) { struct device_coords delta; const struct device_coords zero = { 0.0, 0.0 }; if (t->history.count <= 1) return zero; delta.x = tp_motion_history_offset(t, 0)->point.x - tp_motion_history_offset(t, 1)->point.x; delta.y = tp_motion_history_offset(t, 0)->point.y - tp_motion_history_offset(t, 1)->point.y; return delta; } static inline int32_t rotated(struct tp_dispatch *tp, unsigned int code, int value) { const struct input_absinfo *absinfo; if (!tp->left_handed.rotate) return value; switch (code) { case ABS_X: case ABS_MT_POSITION_X: absinfo = tp->device->abs.absinfo_x; break; case ABS_Y: case ABS_MT_POSITION_Y: absinfo = tp->device->abs.absinfo_y; break; default: abort(); } return absinfo->maximum - (value - absinfo->minimum); } static void tp_process_absolute(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { struct tp_touch *t = tp_current_touch(tp); switch(e->code) { case ABS_MT_POSITION_X: evdev_device_check_abs_axis_range(tp->device, e->code, e->value); t->point.x = rotated(tp, e->code, e->value); t->dirty = true; tp->queued |= TOUCHPAD_EVENT_MOTION; break; case ABS_MT_POSITION_Y: evdev_device_check_abs_axis_range(tp->device, e->code, e->value); t->point.y = rotated(tp, e->code, e->value); t->dirty = true; tp->queued |= TOUCHPAD_EVENT_MOTION; break; case ABS_MT_SLOT: tp->slot = e->value; break; case ABS_MT_TRACKING_ID: if (e->value != -1) { tp->nactive_slots += 1; tp_new_touch(tp, t, time); } else if (tp->nactive_slots >= 1) { tp->nactive_slots -= 1; tp_end_sequence(tp, t, time); } break; case ABS_MT_PRESSURE: t->pressure = e->value; t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; case ABS_MT_TOOL_TYPE: t->is_tool_palm = e->value == MT_TOOL_PALM; t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; case ABS_MT_TOUCH_MAJOR: t->major = e->value; t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; case ABS_MT_TOUCH_MINOR: t->minor = e->value; t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; } } static void tp_process_absolute_st(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { struct tp_touch *t = tp_current_touch(tp); switch(e->code) { case ABS_X: evdev_device_check_abs_axis_range(tp->device, e->code, e->value); t->point.x = rotated(tp, e->code, e->value); t->dirty = true; tp->queued |= TOUCHPAD_EVENT_MOTION; break; case ABS_Y: evdev_device_check_abs_axis_range(tp->device, e->code, e->value); t->point.y = rotated(tp, e->code, e->value); t->dirty = true; tp->queued |= TOUCHPAD_EVENT_MOTION; break; case ABS_PRESSURE: t->pressure = e->value; t->dirty = true; tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; break; } } static inline void tp_restore_synaptics_touches(struct tp_dispatch *tp, uint64_t time) { unsigned int i; unsigned int nfake_touches; nfake_touches = tp_fake_finger_count(tp); if (nfake_touches < 3) return; if (tp->nfingers_down >= nfake_touches || (tp->nfingers_down == tp->num_slots && nfake_touches == tp->num_slots)) return; /* Synaptics devices may end touch 2 on transition to/from * BTN_TOOL_TRIPLETAP and start it again on the next frame with * different coordinates (bz#91352, gitlab#434). We search the * touches we have, if there is one that has just ended despite us * being on tripletap, we move it back to update. * * Note: we only handle the transition from 2 to 3 touches, not the * other way round (see gitlab#434) */ for (i = 0; i < tp->num_slots; i++) { struct tp_touch *t = tp_get_touch(tp, i); if (t->state != TOUCH_MAYBE_END) continue; /* new touch, move it through begin to update immediately */ tp_recover_ended_touch(tp, t); } } static void tp_process_fake_touches(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; unsigned int nfake_touches; unsigned int i, start; nfake_touches = tp_fake_finger_count(tp); if (nfake_touches == FAKE_FINGER_OVERFLOW) return; if (tp->device->model_flags & EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD) tp_restore_synaptics_touches(tp, time); /* ALPS serial touchpads always set 3 slots in the kernel, even * where they support less than that. So we get BTN_TOOL_TRIPLETAP * but never slot 2 because our slot count is wrong. * This also means that the third touch falls through the cracks and * is ignored. * * See https://gitlab.freedesktop.org/libinput/libinput/issues/408 * * All touchpad devices have at least one slot so we only do this * for 2 touches or higher. * * There's an bug in libevdev < 1.9.0 affecting slots after a * SYN_DROPPED. Where a user release one or more touches during * SYN_DROPPED and places new ones on the touchpad, we may end up * with fake touches but no active slots. * So let's check for nactive_slots > 0 to make sure we don't lose * all fingers. That's a workaround only, this must be fixed in * libevdev. * * For a long explanation of what happens, see * https://gitlab.freedesktop.org/libevdev/libevdev/merge_requests/19 */ if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD && nfake_touches > 1 && tp->has_mt && tp->nactive_slots > 0 && nfake_touches > tp->nactive_slots && tp->nactive_slots < tp->num_slots) { evdev_log_bug_kernel(tp->device, "Wrong slot count (%d), reducing to %d\n", tp->num_slots, tp->nactive_slots); /* This should be safe since we fill the slots from the * first one so hiding the excessive slots shouldn't matter. * There are sequences where we could accidentally lose an * actual touch point but that requires specially crafted * sequences and let's deal with that when it happens. */ tp->num_slots = tp->nactive_slots; } start = tp->has_mt ? tp->num_slots : 0; for (i = start; i < tp->ntouches; i++) { t = tp_get_touch(tp, i); if (i < nfake_touches) tp_new_touch(tp, t, time); else tp_end_sequence(tp, t, time); } } static void tp_process_trackpoint_button(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { struct evdev_dispatch *dispatch; struct input_event event; struct input_event syn_report = { .input_event_sec = 0, .input_event_usec = 0, .type = EV_SYN, .code = SYN_REPORT, .value = 0 }; if (!tp->buttons.trackpoint) return; dispatch = tp->buttons.trackpoint->dispatch; event = *e; syn_report.input_event_sec = e->input_event_sec; syn_report.input_event_usec = e->input_event_usec; switch (event.code) { case BTN_0: event.code = BTN_LEFT; break; case BTN_1: event.code = BTN_RIGHT; break; case BTN_2: event.code = BTN_MIDDLE; break; default: return; } dispatch->interface->process(dispatch, tp->buttons.trackpoint, &event, time); dispatch->interface->process(dispatch, tp->buttons.trackpoint, &syn_report, time); } static void tp_process_key(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { /* ignore kernel key repeat */ if (e->value == 2) return; switch (e->code) { case BTN_LEFT: case BTN_MIDDLE: case BTN_RIGHT: tp_process_button(tp, e, time); break; case BTN_TOUCH: case BTN_TOOL_FINGER: case BTN_TOOL_DOUBLETAP: case BTN_TOOL_TRIPLETAP: case BTN_TOOL_QUADTAP: case BTN_TOOL_QUINTTAP: tp_fake_finger_set(tp, e->code, !!e->value); break; case BTN_0: case BTN_1: case BTN_2: tp_process_trackpoint_button(tp, e, time); break; } } static void tp_process_msc(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { if (e->code != MSC_TIMESTAMP) return; tp->quirks.msc_timestamp.now = e->value; tp->queued |= TOUCHPAD_EVENT_TIMESTAMP; } static void tp_unpin_finger(const struct tp_dispatch *tp, struct tp_touch *t) { struct phys_coords mm; struct device_coords delta; if (!t->pinned.is_pinned) return; delta.x = abs(t->point.x - t->pinned.center.x); delta.y = abs(t->point.y - t->pinned.center.y); mm = evdev_device_unit_delta_to_mm(tp->device, &delta); /* 1.5mm movement -> unpin */ if (hypot(mm.x, mm.y) >= 1.5) { t->pinned.is_pinned = false; return; } } static void tp_pin_fingers(struct tp_dispatch *tp) { struct tp_touch *t; tp_for_each_touch(tp, t) { t->pinned.is_pinned = true; t->pinned.center = t->point; } } bool tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t) { return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) && t->palm.state == PALM_NONE && !t->pinned.is_pinned && !tp_thumb_ignored(tp, t) && tp_button_touch_active(tp, t) && tp_edge_scroll_touch_active(tp, t); } bool tp_touch_active_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t) { return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) && t->palm.state == PALM_NONE && !t->pinned.is_pinned && !tp_thumb_ignored_for_gesture(tp, t) && tp_button_touch_active(tp, t) && tp_edge_scroll_touch_active(tp, t); } static inline bool tp_palm_was_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->palm.first.x < tp->palm.left_edge || t->palm.first.x > tp->palm.right_edge; } static inline bool tp_palm_was_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->palm.first.y < tp->palm.upper_edge; } static inline bool tp_palm_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->point.x < tp->palm.left_edge || t->point.x > tp->palm.right_edge; } static inline bool tp_palm_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { return t->point.y < tp->palm.upper_edge; } static inline bool tp_palm_in_edge(const struct tp_dispatch *tp, const struct tp_touch *t) { return tp_palm_in_side_edge(tp, t) || tp_palm_in_top_edge(tp, t); } static bool tp_palm_detect_dwt_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (tp->dwt.dwt_enabled && tp->dwt.keyboard_active && t->state == TOUCH_BEGIN) { t->palm.state = PALM_TYPING; t->palm.first = t->point; return true; } if (!tp->dwt.keyboard_active && t->state == TOUCH_UPDATE && t->palm.state == PALM_TYPING) { /* If a touch has started before the first or after the last key press, release it on timeout. Benefit: a palm rested while typing on the touchpad will be ignored, but a touch started once we stop typing will be able to control the pointer (alas not tap, etc.). */ if (t->palm.time == 0 || t->palm.time > tp->dwt.keyboard_last_press_time) { t->palm.state = PALM_NONE; evdev_log_debug(tp->device, "palm: touch %d released, timeout after typing\n", t->index); } } return false; } static bool tp_palm_detect_trackpoint_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (!tp->palm.monitor_trackpoint) return false; if (t->palm.state == PALM_NONE && t->state == TOUCH_BEGIN && tp->palm.trackpoint_active) { t->palm.state = PALM_TRACKPOINT; return true; } if (t->palm.state == PALM_TRACKPOINT && t->state == TOUCH_UPDATE && !tp->palm.trackpoint_active) { if (t->palm.time == 0 || t->palm.time > tp->palm.trackpoint_last_event_time) { t->palm.state = PALM_NONE; evdev_log_debug(tp->device, "palm: touch %d released, timeout after trackpoint\n", t->index); } } return false; } static bool tp_palm_detect_tool_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (!tp->palm.use_mt_tool) return false; if (t->palm.state != PALM_NONE && t->palm.state != PALM_TOOL_PALM) return false; if (t->palm.state == PALM_NONE && t->is_tool_palm) t->palm.state = PALM_TOOL_PALM; else if (t->palm.state == PALM_TOOL_PALM && !t->is_tool_palm) t->palm.state = PALM_NONE; return t->palm.state == PALM_TOOL_PALM; } static inline bool tp_palm_detect_move_out_of_edge(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { const int PALM_TIMEOUT = ms2us(200); int directions = 0; struct device_float_coords delta; int dirs; if (time < t->palm.time + PALM_TIMEOUT && !tp_palm_in_edge(tp, t)) { if (tp_palm_was_in_side_edge(tp, t)) directions = NE|E|SE|SW|W|NW; else if (tp_palm_was_in_top_edge(tp, t)) directions = S|SE|SW; if (directions) { delta = device_delta(t->point, t->palm.first); dirs = phys_get_direction(tp_phys_delta(tp, delta)); if ((dirs & directions) && !(dirs & ~directions)) return true; } } return false; } static inline bool tp_palm_detect_multifinger(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { struct tp_touch *other; if (tp->nfingers_down < 2) return false; /* If we have at least one other active non-palm touch make this * touch non-palm too. This avoids palm detection during two-finger * scrolling. * * Note: if both touches start in the palm zone within the same * frame the second touch will still be PALM_NONE and thus detected * here as non-palm touch. This is too niche to worry about for now. */ tp_for_each_touch(tp, other) { if (other == t) continue; if (tp_touch_active(tp, other) && other->palm.state == PALM_NONE) { return true; } } return false; } static inline bool tp_palm_detect_touch_size_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (!tp->palm.use_size) return false; /* If a finger size is large enough for palm, we stick with that and * force the user to release and reset the finger */ if (t->palm.state != PALM_NONE && t->palm.state != PALM_TOUCH_SIZE) return false; if (t->major > tp->palm.size_threshold || t->minor > tp->palm.size_threshold) { if (t->palm.state != PALM_TOUCH_SIZE) evdev_log_debug(tp->device, "palm: touch %d size exceeded\n", t->index); t->palm.state = PALM_TOUCH_SIZE; return true; } return false; } static inline bool tp_palm_detect_edge(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (t->palm.state == PALM_EDGE) { if (tp_palm_detect_multifinger(tp, t, time)) { t->palm.state = PALM_NONE; evdev_log_debug(tp->device, "palm: touch %d released, multiple fingers\n", t->index); /* If labelled a touch as palm, we unlabel as palm when we move out of the palm edge zone within the timeout, provided the direction is within 45 degrees of the horizontal. */ } else if (tp_palm_detect_move_out_of_edge(tp, t, time)) { t->palm.state = PALM_NONE; evdev_log_debug(tp->device, "palm: touch %d released, out of edge zone\n", t->index); } return false; } if (tp_palm_detect_multifinger(tp, t, time)) { return false; } /* palm must start in exclusion zone, it's ok to move into the zone without being a palm */ if (t->state != TOUCH_BEGIN || !tp_palm_in_edge(tp, t)) return false; if (tp_touch_get_edge(tp, t) & EDGE_RIGHT) return false; t->palm.state = PALM_EDGE; t->palm.time = time; t->palm.first = t->point; return true; } static bool tp_palm_detect_pressure_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (!tp->palm.use_pressure) return false; if (t->palm.state != PALM_NONE && t->palm.state != PALM_PRESSURE) return false; if (t->pressure > tp->palm.pressure_threshold) t->palm.state = PALM_PRESSURE; return t->palm.state == PALM_PRESSURE; } static bool tp_palm_detect_arbitration_triggered(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { if (tp->arbitration.state == ARBITRATION_NOT_ACTIVE) return false; t->palm.state = PALM_ARBITRATION; return true; } static void tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { const char *palm_state; enum touch_palm_state oldstate = t->palm.state; if (tp_palm_detect_pressure_triggered(tp, t, time)) goto out; if (tp_palm_detect_arbitration_triggered(tp, t, time)) goto out; if (tp_palm_detect_dwt_triggered(tp, t, time)) goto out; if (tp_palm_detect_trackpoint_triggered(tp, t, time)) goto out; if (tp_palm_detect_tool_triggered(tp, t, time)) goto out; if (tp_palm_detect_touch_size_triggered(tp, t, time)) goto out; if (tp_palm_detect_edge(tp, t, time)) goto out; /* Pressure is highest priority because it cannot be released and * overrides all other checks. So we check once before anything else * in case pressure triggers on a non-palm touch. And again after * everything in case one of the others released but we have a * pressure trigger now. */ if (tp_palm_detect_pressure_triggered(tp, t, time)) goto out; return; out: if (oldstate == t->palm.state) return; switch (t->palm.state) { case PALM_EDGE: palm_state = "edge"; break; case PALM_TYPING: palm_state = "typing"; break; case PALM_TRACKPOINT: palm_state = "trackpoint"; break; case PALM_TOOL_PALM: palm_state = "tool-palm"; break; case PALM_PRESSURE: palm_state = "pressure"; break; case PALM_TOUCH_SIZE: palm_state = "touch size"; break; case PALM_ARBITRATION: palm_state = "arbitration"; break; case PALM_NONE: default: abort(); break; } evdev_log_debug(tp->device, "palm: touch %d (%s), palm detected (%s)\n", t->index, touch_state_to_str(t->state), palm_state); } static void tp_unhover_pressure(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; int i; unsigned int nfake_touches; unsigned int real_fingers_down = 0; nfake_touches = tp_fake_finger_count(tp); if (nfake_touches == FAKE_FINGER_OVERFLOW) nfake_touches = 0; for (i = 0; i < (int)tp->num_slots; i++) { t = tp_get_touch(tp, i); if (t->state == TOUCH_NONE) continue; if (t->dirty) { if (t->state == TOUCH_HOVERING) { if (t->pressure >= tp->pressure.high) { evdev_log_debug(tp->device, "pressure: begin touch %d\n", t->index); /* avoid jumps when landing a finger */ tp_motion_history_reset(t); tp_begin_touch(tp, t, time); } /* don't unhover for pressure if we have too many * fake fingers down, see comment below. Except * for single-finger touches where the real touch * decides for the rest. */ } else if (nfake_touches <= tp->num_slots || tp->num_slots == 1) { if (t->pressure < tp->pressure.low) { evdev_log_debug(tp->device, "pressure: end touch %d\n", t->index); tp_maybe_end_touch(tp, t, time); } } } if (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) real_fingers_down++; } if (nfake_touches <= tp->num_slots || tp->nfingers_down == 0) return; /* if we have more fake fingers down than slots, we assume * _all_ fingers have enough pressure, even if some of the slotted * ones don't. Anything else gets insane quickly. */ if (real_fingers_down > 0) { tp_for_each_touch(tp, t) { if (t->state == TOUCH_HOVERING) { /* avoid jumps when landing a finger */ tp_motion_history_reset(t); tp_begin_touch(tp, t, time); if (tp->nfingers_down >= nfake_touches) break; } } } if (tp->nfingers_down > nfake_touches || real_fingers_down == 0) { for (i = tp->ntouches - 1; i >= 0; i--) { t = tp_get_touch(tp, i); if (t->state == TOUCH_HOVERING || t->state == TOUCH_NONE || t->state == TOUCH_MAYBE_END) continue; tp_maybe_end_touch(tp, t, time); if (real_fingers_down > 0 && tp->nfingers_down == nfake_touches) break; } } } static void tp_unhover_size(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; int low = tp->touch_size.low, high = tp->touch_size.high; int i; /* We require 5 slots for size handling, so we don't need to care * about fake touches here */ for (i = 0; i < (int)tp->num_slots; i++) { t = tp_get_touch(tp, i); if (t->state == TOUCH_NONE) continue; if (!t->dirty) continue; if (t->state == TOUCH_HOVERING) { if ((t->major > high && t->minor > low) || (t->major > low && t->minor > high)) { evdev_log_debug(tp->device, "touch-size: begin touch %d\n", t->index); /* avoid jumps when landing a finger */ tp_motion_history_reset(t); tp_begin_touch(tp, t, time); } } else { if (t->major < low || t->minor < low) { evdev_log_debug(tp->device, "touch-size: end touch %d\n", t->index); tp_maybe_end_touch(tp, t, time); } } } } static void tp_unhover_fake_touches(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; unsigned int nfake_touches; int i; if (!tp->fake_touches && !tp->nfingers_down) return; nfake_touches = tp_fake_finger_count(tp); if (nfake_touches == FAKE_FINGER_OVERFLOW) return; if (tp->nfingers_down == nfake_touches && ((tp->nfingers_down == 0 && !tp_fake_finger_is_touching(tp)) || (tp->nfingers_down > 0 && tp_fake_finger_is_touching(tp)))) return; /* if BTN_TOUCH is set and we have less fingers down than fake * touches, switch each hovering touch to BEGIN * until nfingers_down matches nfake_touches */ if (tp_fake_finger_is_touching(tp) && tp->nfingers_down < nfake_touches) { tp_for_each_touch(tp, t) { if (t->state == TOUCH_HOVERING) { tp_begin_touch(tp, t, time); if (tp->nfingers_down >= nfake_touches) break; } } } /* if BTN_TOUCH is unset end all touches, we're hovering now. If we * have too many touches also end some of them. This is done in * reverse order. */ if (tp->nfingers_down > nfake_touches || !tp_fake_finger_is_touching(tp)) { for (i = tp->ntouches - 1; i >= 0; i--) { t = tp_get_touch(tp, i); if (t->state == TOUCH_HOVERING || t->state == TOUCH_NONE) continue; tp_maybe_end_touch(tp, t, time); if (tp_fake_finger_is_touching(tp) && tp->nfingers_down == nfake_touches) break; } } } static void tp_unhover_touches(struct tp_dispatch *tp, uint64_t time) { if (tp->pressure.use_pressure) tp_unhover_pressure(tp, time); else if (tp->touch_size.use_touch_size) tp_unhover_size(tp, time); else tp_unhover_fake_touches(tp, time); } static inline void tp_position_fake_touches(struct tp_dispatch *tp) { struct tp_touch *t; struct tp_touch *topmost = NULL; unsigned int start, i; if (tp_fake_finger_count(tp) <= tp->num_slots || tp->nfingers_down == 0) return; /* We have at least one fake touch down. Find the top-most real * touch and copy its coordinates over to to all fake touches. * This is more reliable than just taking the first touch. */ for (i = 0; i < tp->num_slots; i++) { t = tp_get_touch(tp, i); if (t->state == TOUCH_END || t->state == TOUCH_NONE) continue; if (topmost == NULL || t->point.y < topmost->point.y) topmost = t; } if (!topmost) { evdev_log_bug_libinput(tp->device, "Unable to find topmost touch\n"); return; } start = tp->has_mt ? tp->num_slots : 1; for (i = start; i < tp->ntouches; i++) { t = tp_get_touch(tp, i); if (t->state == TOUCH_NONE) continue; t->point = topmost->point; t->pressure = topmost->pressure; if (!t->dirty) t->dirty = topmost->dirty; } } static inline bool tp_need_motion_history_reset(struct tp_dispatch *tp) { bool rc = false; /* Changing the numbers of fingers can cause a jump in the * coordinates, always reset the motion history for all touches when * that happens. */ if (tp->nfingers_down != tp->old_nfingers_down) return true; /* Quirk: if we had multiple events without x/y axis information, the next x/y event is going to be a jump. So we reset that touch to non-dirty effectively swallowing that event and restarting with the next event again. */ if (tp->device->model_flags & EVDEV_MODEL_LENOVO_T450_TOUCHPAD) { if (tp->queued & TOUCHPAD_EVENT_MOTION) { if (tp->quirks.nonmotion_event_count > 10) { tp->queued &= ~TOUCHPAD_EVENT_MOTION; rc = true; } tp->quirks.nonmotion_event_count = 0; } if ((tp->queued & (TOUCHPAD_EVENT_OTHERAXIS|TOUCHPAD_EVENT_MOTION)) == TOUCHPAD_EVENT_OTHERAXIS) tp->quirks.nonmotion_event_count++; } return rc; } static bool tp_detect_jumps(const struct tp_dispatch *tp, struct tp_touch *t, uint64_t time) { struct device_coords delta; struct phys_coords mm; struct tp_history_point *last; double abs_distance, rel_distance; bool is_jump = false; uint64_t tdelta; /* Reference interval from the touchpad the various thresholds * were measured from */ unsigned int reference_interval = ms2us(12); /* On some touchpads the firmware does funky stuff and we cannot * have our own jump detection, e.g. Lenovo Carbon X1 Gen 6 (see * issue #506) */ if (tp->jump.detection_disabled) return false; /* We haven't seen pointer jumps on Wacom tablets yet, so exclude * those. */ if (tp->device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD) return false; if (t->history.count == 0) { t->jumps.last_delta_mm = 0.0; return false; } /* called before tp_motion_history_push, so offset 0 is the most * recent coordinate */ last = tp_motion_history_offset(t, 0); tdelta = time - last->time; /* For test devices we always force the time delta to 12, at least until the test suite actually does proper intervals. */ if (tp->device->model_flags & EVDEV_MODEL_TEST_DEVICE) reference_interval = tdelta; /* If the last frame is more than 30ms ago, we have irregular * frames, who knows what's a pointer jump here and what's * legitimate movement.... */ if (tdelta > 2.5 * reference_interval || tdelta == 0) return false; /* We historically expected ~12ms frame intervals, so the numbers below are normalized to that (and that's also where the measured data came from) */ delta.x = abs(t->point.x - last->point.x); delta.y = abs(t->point.y - last->point.y); mm = evdev_device_unit_delta_to_mm(tp->device, &delta); abs_distance = hypot(mm.x, mm.y) * reference_interval/tdelta; rel_distance = abs_distance - t->jumps.last_delta_mm; /* Special case for the ALPS devices in the Lenovo ThinkPad E465, * E550. These devices send occasional 4095/0 events on two fingers * before snapping back to the correct position. * https://gitlab.freedesktop.org/libinput/libinput/-/issues/492 * The specific values are hardcoded here, if this ever happens on * any other device we can make it absmax/absmin instead. */ if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD && t->point.x == 4095 && t->point.y == 0) { t->point = last->point; return true; } /* Cursor jump if: * - current single-event delta is >20mm, or * - we increased the delta by over 7mm within a 12ms frame. * (12ms simply because that's what I measured) */ is_jump = abs_distance > 20.0 || rel_distance > 7; t->jumps.last_delta_mm = abs_distance; return is_jump; } /** * Rewrite the motion history so that previous points' timestamps are the * current point's timestamp minus whatever MSC_TIMESTAMP gives us. * * This must be called before tp_motion_history_push() * * @param t The touch point * @param jumping_interval The large time interval in µs * @param normal_interval Normal hw interval in µs * @param time Current time in µs */ static inline void tp_motion_history_fix_last(struct tp_dispatch *tp, struct tp_touch *t, unsigned int jumping_interval, unsigned int normal_interval, uint64_t time) { if (t->state != TOUCH_UPDATE) return; /* We know the coordinates are correct because the touchpad should * get that bit right. But the timestamps we got from the kernel are * messed up, so we go back in the history and fix them. * * This way the next delta is huge but it's over a large time, so * the pointer accel code should do the right thing. */ for (int i = 0; i < (int)t->history.count; i++) { struct tp_history_point *p; p = tp_motion_history_offset(t, i); p->time = time - jumping_interval - normal_interval * i; } } static void tp_process_msc_timestamp(struct tp_dispatch *tp, uint64_t time) { struct msc_timestamp *m = &tp->quirks.msc_timestamp; /* Pointer jump detection based on MSC_TIMESTAMP. MSC_TIMESTAMP gets reset after a kernel timeout (1s) and on some devices (Dell XPS) the i2c controller sleeps after a timeout. On wakeup, some events are swallowed, triggering a cursor jump. The event sequence after a sleep is always: initial finger down: ABS_X/Y x/y MSC_TIMESTAMP 0 SYN_REPORT +2500ms second event: ABS_X/Y x+n/y+n # normal movement MSC_TIMESTAMP 7300 # the hw interval SYN_REPORT +2ms third event: ABS_X/Y x+lots/y+lots # pointer jump! MSC_TIMESTAMP 123456 # well above the hw interval SYN_REPORT +2ms fourth event: ABS_X/Y x+lots+n/y+lots+n # all normal again MSC_TIMESTAMP 123456 + 7300 SYN_REPORT +8ms Our approach is to detect the 0 timestamp, check the interval on the next event and then calculate the movement for one fictitious event instead, swallowing all other movements. So if the time delta is equivalent to 10 events and the movement is x, we instead pretend there was movement of x/10. */ if (m->now == 0) { m->state = JUMP_STATE_EXPECT_FIRST; m->interval = 0; return; } switch(m->state) { case JUMP_STATE_EXPECT_FIRST: if (m->now > ms2us(20)) { m->state = JUMP_STATE_IGNORE; } else { m->state = JUMP_STATE_EXPECT_DELAY; m->interval = m->now; } break; case JUMP_STATE_EXPECT_DELAY: if (m->now > m->interval * 2) { uint32_t tdelta; /* µs */ struct tp_touch *t; /* The current time is > 2 times the interval so we * have a jump. Fix the motion history */ tdelta = m->now - m->interval; tp_for_each_touch(tp, t) { tp_motion_history_fix_last(tp, t, tdelta, m->interval, time); } m->state = JUMP_STATE_IGNORE; /* We need to restart the acceleration filter to forget its history. * The current point becomes the first point in the history there * (including timestamp) and that accelerates correctly. * This has a potential to be incorrect but since we only ever see * those jumps over the first three events it doesn't matter. */ filter_restart(tp->device->pointer.filter, tp, time - tdelta); } break; case JUMP_STATE_IGNORE: break; } } static void tp_pre_process_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; if (tp->queued & TOUCHPAD_EVENT_TIMESTAMP) tp_process_msc_timestamp(tp, time); tp_process_fake_touches(tp, time); tp_unhover_touches(tp, time); tp_for_each_touch(tp, t) { if (t->state == TOUCH_MAYBE_END) tp_end_touch(tp, t, time); /* Ignore motion when pressure/touch size fell below the * threshold, thus ending the touch */ if (t->state == TOUCH_END && t->history.count > 0) t->point = tp_motion_history_offset(t, 0)->point; } } static void tp_process_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; bool restart_filter = false; bool want_motion_reset; bool have_new_touch = false; unsigned int speed_exceeded_count = 0; tp_position_fake_touches(tp); want_motion_reset = tp_need_motion_history_reset(tp); tp_for_each_touch(tp, t) { if (t->state == TOUCH_NONE) continue; if (want_motion_reset) { tp_motion_history_reset(t); t->quirks.reset_motion_history = true; } else if (t->quirks.reset_motion_history) { tp_motion_history_reset(t); t->quirks.reset_motion_history = false; } if (!t->dirty) { /* A non-dirty touch must be below the speed limit */ if (t->speed.exceeded_count > 0) t->speed.exceeded_count--; speed_exceeded_count = max(speed_exceeded_count, t->speed.exceeded_count); /* A touch that hasn't moved must be in the same * position, so let's add this to the motion * history. */ tp_motion_history_push(t, time); continue; } if (tp_detect_jumps(tp, t, time)) { if (!tp->semi_mt) evdev_log_bug_kernel_ratelimit(tp->device, &tp->jump.warning, "Touch jump detected and discarded.\n" "See %s/touchpad-jumping-cursors.html for details\n", HTTP_DOC_LINK); tp_motion_history_reset(t); } tp_thumb_update_touch(tp, t, time); tp_palm_detect(tp, t, time); tp_detect_wobbling(tp, t, time); tp_motion_hysteresis(tp, t); tp_motion_history_push(t, time); /* Touch speed handling: if we'are above the threshold, * count each event that we're over the threshold up to 10 * events. Count down when we are below the speed. * * Take the touch with the highest speed excess, if it is * above a certain threshold (5, see below), assume a * dropped finger is a thumb. * * Yes, this relies on the touchpad to keep sending us * events even if the finger doesn't move, otherwise we * never count down. Let's see how far we get with that. */ if (t->speed.last_speed > THUMB_IGNORE_SPEED_THRESHOLD) { if (t->speed.exceeded_count < 15) t->speed.exceeded_count++; } else if (t->speed.exceeded_count > 0) { t->speed.exceeded_count--; } speed_exceeded_count = max(speed_exceeded_count, t->speed.exceeded_count); tp_calculate_motion_speed(tp, t, time); tp_unpin_finger(tp, t); if (t->state == TOUCH_BEGIN) { have_new_touch = true; restart_filter = true; } } if (tp->thumb.detect_thumbs && have_new_touch && tp->nfingers_down >= 2) tp_thumb_update_multifinger(tp); if (restart_filter) filter_restart(tp->device->pointer.filter, tp, time); tp_button_handle_state(tp, time); tp_edge_scroll_handle_state(tp, time); /* * We have a physical button down event on a clickpad. To avoid * spurious pointer moves by the clicking finger we pin all fingers. * We unpin fingers when they move more then a certain threshold to * to allow drag and drop. */ if ((tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) && tp->buttons.is_clickpad) tp_pin_fingers(tp); tp_gesture_update_finger_state(tp, time); } static void tp_post_process_state(struct tp_dispatch *tp, uint64_t time) { struct tp_touch *t; tp_for_each_touch(tp, t) { if (!t->dirty) continue; if (t->state == TOUCH_END) { if (t->has_ended) t->state = TOUCH_NONE; else t->state = TOUCH_HOVERING; } else if (t->state == TOUCH_BEGIN) { t->state = TOUCH_UPDATE; } t->dirty = false; } tp->old_nfingers_down = tp->nfingers_down; tp->buttons.old_state = tp->buttons.state; tp->queued = TOUCHPAD_EVENT_NONE; if (tp->nfingers_down == 0) tp_thumb_reset(tp); tp_tap_post_process_state(tp); tp_button_post_process_state(tp); } static void tp_post_events(struct tp_dispatch *tp, uint64_t time) { bool ignore_motion = false; /* Only post (top) button events while suspended */ if (tp->device->is_suspended) { tp_post_button_events(tp, time); return; } ignore_motion |= tp_tap_handle_state(tp, time); ignore_motion |= tp_post_button_events(tp, time); if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) { tp_edge_scroll_stop_events(tp, time); tp_gesture_cancel(tp, time); return; } if (ignore_motion) { tp_edge_scroll_stop_events(tp, time); tp_gesture_cancel_motion_gestures(tp, time); tp_gesture_post_events(tp, time, true); return; } if (tp_edge_scroll_post_events(tp, time) != 0) return; tp_gesture_post_events(tp, time, false); } static void tp_apply_rotation(struct evdev_device *device) { struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch; if (tp->left_handed.want_rotate == tp->left_handed.rotate) return; if (tp->nfingers_down) return; tp->left_handed.rotate = tp->left_handed.want_rotate; evdev_log_debug(device, "touchpad-rotation: rotation is %s\n", tp->left_handed.rotate ? "on" : "off"); } static void tp_handle_state(struct tp_dispatch *tp, uint64_t time) { tp_pre_process_state(tp, time); tp_process_state(tp, time); tp_post_events(tp, time); tp_post_process_state(tp, time); tp_clickpad_middlebutton_apply_config(tp->device); tp_apply_rotation(tp->device); tp_3fg_drag_apply_config(tp->device); } LIBINPUT_UNUSED static inline void tp_debug_touch_state(struct tp_dispatch *tp, struct evdev_device *device) { char buf[1024] = {0}; struct tp_touch *t; size_t i = 0; tp_for_each_touch(tp, t) { if (i >= tp->nfingers_down) break; sprintf(&buf[strlen(buf)], "slot %zd: %04d/%04d p%03d %s |", i++, t->point.x, t->point.y, t->pressure, tp_touch_active(tp, t) ? "" : "inactive"); } if (buf[0] != '\0') evdev_log_debug(device, "touch state: %s\n", buf); } static void tp_interface_process(struct evdev_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { struct tp_dispatch *tp = tp_dispatch(dispatch); switch (e->type) { case EV_ABS: if (tp->has_mt) tp_process_absolute(tp, e, time); else tp_process_absolute_st(tp, e, time); break; case EV_KEY: tp_process_key(tp, e, time); break; case EV_MSC: tp_process_msc(tp, e, time); break; case EV_SYN: tp_handle_state(tp, time); #if 0 tp_debug_touch_state(tp, device); #endif break; } } static void tp_remove_sendevents(struct tp_dispatch *tp) { struct evdev_paired_keyboard *kbd; libinput_timer_cancel(&tp->palm.trackpoint_timer); libinput_timer_cancel(&tp->dwt.keyboard_timer); if (tp->buttons.trackpoint && tp->palm.monitor_trackpoint) libinput_device_remove_event_listener( &tp->palm.trackpoint_listener); list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) { libinput_device_remove_event_listener(&kbd->listener); } if (tp->lid_switch.lid_switch) libinput_device_remove_event_listener( &tp->lid_switch.listener); if (tp->tablet_mode_switch.tablet_mode_switch) libinput_device_remove_event_listener( &tp->tablet_mode_switch.listener); } static void tp_interface_remove(struct evdev_dispatch *dispatch) { struct tp_dispatch *tp = tp_dispatch(dispatch); struct evdev_paired_keyboard *kbd; libinput_timer_cancel(&tp->arbitration.arbitration_timer); list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) { evdev_paired_keyboard_destroy(kbd); } tp->dwt.keyboard_active = false; tp_remove_tap(tp); tp_remove_buttons(tp); tp_remove_sendevents(tp); tp_remove_edge_scroll(tp); tp_remove_gesture(tp); } static void tp_interface_destroy(struct evdev_dispatch *dispatch) { struct tp_dispatch *tp = tp_dispatch(dispatch); libinput_timer_destroy(&tp->arbitration.arbitration_timer); libinput_timer_destroy(&tp->palm.trackpoint_timer); libinput_timer_destroy(&tp->dwt.keyboard_timer); libinput_timer_destroy(&tp->tap.timer); libinput_timer_destroy(&tp->gesture.finger_count_switch_timer); libinput_timer_destroy(&tp->gesture.hold_timer); libinput_timer_destroy(&tp->gesture.drag_3fg_timer); free(tp->touches); free(tp); } static void tp_release_fake_touches(struct tp_dispatch *tp) { tp->fake_touches = 0; } static void tp_clear_state(struct tp_dispatch *tp) { uint64_t now = libinput_now(tp_libinput_context(tp)); struct tp_touch *t; /* Unroll the touchpad state. * Release buttons first. If tp is a clickpad, the button event * must come before the touch up. If it isn't, the order doesn't * matter anyway * * Then cancel all timeouts on the taps, triggering the last set * of events. * * Then lift all touches so the touchpad is in a neutral state. * * Then reset thumb state. * */ tp_release_all_buttons(tp, now); tp_release_all_taps(tp, now); tp_for_each_touch(tp, t) { tp_end_sequence(tp, t, now); } tp_release_fake_touches(tp); tp_thumb_reset(tp); tp_handle_state(tp, now); } static void tp_suspend(struct tp_dispatch *tp, struct evdev_device *device, enum suspend_trigger trigger) { if (tp->suspend_reason & trigger) return; if (tp->suspend_reason != 0) goto out; tp_clear_state(tp); /* On devices with top softwarebuttons we don't actually suspend the * device, to keep the "trackpoint" buttons working. tp_post_events() * will only send events for the trackpoint while suspended. */ if (tp->buttons.has_topbuttons) { evdev_notify_suspended_device(device); /* Enlarge topbutton area while suspended */ tp_init_top_softbuttons(tp, device, 3.0); } else { evdev_device_suspend(device); } out: tp->suspend_reason |= trigger; } static void tp_interface_suspend(struct evdev_dispatch *dispatch, struct evdev_device *device) { struct tp_dispatch *tp = tp_dispatch(dispatch); tp_clear_state(tp); } static inline void tp_sync_touch(struct tp_dispatch *tp, struct evdev_device *device, struct tp_touch *t, int slot) { struct libevdev *evdev = device->evdev; int tracking_id; if (!libevdev_fetch_slot_value(evdev, slot, ABS_MT_POSITION_X, &t->point.x)) t->point.x = libevdev_get_event_value(evdev, EV_ABS, ABS_X); if (!libevdev_fetch_slot_value(evdev, slot, ABS_MT_POSITION_Y, &t->point.y)) t->point.y = libevdev_get_event_value(evdev, EV_ABS, ABS_Y); if (!libevdev_fetch_slot_value(evdev, slot, ABS_MT_PRESSURE, &t->pressure)) t->pressure = libevdev_get_event_value(evdev, EV_ABS, ABS_PRESSURE); libevdev_fetch_slot_value(evdev, slot, ABS_MT_TOUCH_MAJOR, &t->major); libevdev_fetch_slot_value(evdev, slot, ABS_MT_TOUCH_MINOR, &t->minor); if (libevdev_fetch_slot_value(evdev, slot, ABS_MT_TRACKING_ID, &tracking_id) && tracking_id != -1) tp->nactive_slots++; } static void tp_sync_slots(struct tp_dispatch *tp, struct evdev_device *device) { /* Always sync the first touch so we get ABS_X/Y synced on * single-touch touchpads */ tp_sync_touch(tp, device, &tp->touches[0], 0); for (unsigned int i = 1; i < tp->num_slots; i++) tp_sync_touch(tp, device, &tp->touches[i], i); } static void tp_resume(struct tp_dispatch *tp, struct evdev_device *device, enum suspend_trigger trigger) { tp->suspend_reason &= ~trigger; if (tp->suspend_reason != 0) return; if (tp->buttons.has_topbuttons) { /* tap state-machine is offline while suspended, reset state */ tp_clear_state(tp); /* restore original topbutton area size */ tp_init_top_softbuttons(tp, device, 1.0); evdev_notify_resumed_device(device); } else { evdev_device_resume(device); } tp_sync_slots(tp, device); } static void tp_trackpoint_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; if (tp->palm.trackpoint_active) { tp_tap_resume(tp, now); tp->palm.trackpoint_active = false; } tp->palm.trackpoint_event_count = 0; } static void tp_trackpoint_event(uint64_t time, struct libinput_event *event, void *data) { struct tp_dispatch *tp = data; if (!tp->palm.dwtp_enabled) return; /* Buttons do not count as trackpad activity, as people may use the trackpoint buttons in combination with the touchpad. */ if (event->type == LIBINPUT_EVENT_POINTER_BUTTON) return; tp->palm.trackpoint_last_event_time = time; tp->palm.trackpoint_event_count++; /* Require at least three events before enabling palm detection */ if (tp->palm.trackpoint_event_count < 3) { libinput_timer_set(&tp->palm.trackpoint_timer, time + DEFAULT_TRACKPOINT_EVENT_TIMEOUT); return; } if (!tp->palm.trackpoint_active) { tp_stop_actions(tp, time); tp->palm.trackpoint_active = true; } libinput_timer_set(&tp->palm.trackpoint_timer, time + DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT); } static void tp_keyboard_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; if (tp->dwt.dwt_enabled && long_any_bit_set(tp->dwt.key_mask, ARRAY_LENGTH(tp->dwt.key_mask))) { libinput_timer_set(&tp->dwt.keyboard_timer, now + DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2); tp->dwt.keyboard_last_press_time = now; evdev_log_debug(tp->device, "palm: keyboard timeout refresh\n"); return; } tp_tap_resume(tp, now); tp->dwt.keyboard_active = false; evdev_log_debug(tp->device, "palm: keyboard timeout\n"); } static inline bool tp_key_is_shift(unsigned int keycode) { return keycode == KEY_LEFTSHIFT || keycode == KEY_RIGHTSHIFT; } static inline bool tp_key_is_modifier(unsigned int keycode) { switch (keycode) { /* Ignore modifiers to be responsive to ctrl-click, alt-tab, etc. */ case KEY_LEFTCTRL: case KEY_RIGHTCTRL: case KEY_LEFTALT: case KEY_RIGHTALT: case KEY_LEFTSHIFT: case KEY_RIGHTSHIFT: case KEY_FN: case KEY_CAPSLOCK: case KEY_TAB: case KEY_COMPOSE: case KEY_RIGHTMETA: case KEY_LEFTMETA: return true; default: return false; } } static inline bool tp_key_ignore_for_dwt(unsigned int keycode) { /* Ignore keys not part of the "typewriter set", i.e. F-keys, * multimedia keys, numpad, etc. */ if (tp_key_is_modifier(keycode)) return false; switch (keycode) { case KEY_ESC: case KEY_KPASTERISK: return true; default: return keycode >= KEY_F1; } } static void tp_keyboard_event(uint64_t time, struct libinput_event *event, void *data) { struct tp_dispatch *tp = data; struct libinput_event_keyboard *kbdev; unsigned int timeout; unsigned int key; bool is_modifier; if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY) return; kbdev = libinput_event_get_keyboard_event(event); key = libinput_event_keyboard_get_key(kbdev); /* Only trigger the timer on key down. */ if (libinput_event_keyboard_get_key_state(kbdev) != LIBINPUT_KEY_STATE_PRESSED) { long_clear_bit(tp->dwt.key_mask, key); long_clear_bit(tp->dwt.mod_mask, key); return; } if (!tp->dwt.dwt_enabled) return; if (tp_key_ignore_for_dwt(key)) return; /* modifier keys don't trigger disable-while-typing so things like * ctrl+zoom or ctrl+click are possible. * The exception is shift which we don't trigger DWT for on its own * but we do trigger DWT for once we type some other key. */ is_modifier = tp_key_is_modifier(key); if (is_modifier) { if (!tp_key_is_shift(key)) long_set_bit(tp->dwt.mod_mask, key); return; } if (!tp->dwt.keyboard_active) { /* This is the first non-modifier key press. Check if the * modifier mask is set. If any modifier is down we don't * trigger dwt because it's likely to be combination like * Ctrl+S or similar */ if (long_any_bit_set(tp->dwt.mod_mask, ARRAY_LENGTH(tp->dwt.mod_mask))) return; tp_stop_actions(tp, time); tp->dwt.keyboard_active = true; timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1; } else { timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2; } tp->dwt.keyboard_last_press_time = time; long_set_bit(tp->dwt.key_mask, key); libinput_timer_set(&tp->dwt.keyboard_timer, time + timeout); } static bool tp_want_dwt(struct evdev_device *touchpad, struct evdev_device *keyboard) { unsigned int vendor_tp = evdev_device_get_id_vendor(touchpad); unsigned int vendor_kbd = evdev_device_get_id_vendor(keyboard); unsigned int product_tp = evdev_device_get_id_product(touchpad); unsigned int product_kbd = evdev_device_get_id_product(keyboard); /* External touchpads with the same vid/pid as the keyboard are considered a happy couple */ if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD) return vendor_tp == vendor_kbd && product_tp == product_kbd; if (keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) return true; /* keyboard is not tagged as internal keyboard and it's not part of * a combo */ return false; } static void tp_dwt_pair_keyboard(struct evdev_device *touchpad, struct evdev_device *keyboard) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; struct evdev_paired_keyboard *kbd; size_t count = 0; if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0) return; if (!tp_want_dwt(touchpad, keyboard)) return; list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) { count++; if (count > 3) { evdev_log_info(touchpad, "too many internal keyboards for dwt\n"); break; } } kbd = zalloc(sizeof(*kbd)); kbd->device = keyboard; libinput_device_add_event_listener(&keyboard->base, &kbd->listener, tp_keyboard_event, tp); list_insert(&tp->dwt.paired_keyboard_list, &kbd->link); evdev_log_debug(touchpad, "palm: dwt activated with %s<->%s\n", touchpad->devname, keyboard->devname); } static void tp_pair_trackpoint(struct evdev_device *touchpad, struct evdev_device *trackpoint) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; unsigned int bus_trp = libevdev_get_id_bustype(trackpoint->evdev); bool tp_is_internal, trp_is_internal; if ((trackpoint->tags & EVDEV_TAG_TRACKPOINT) == 0) return; tp_is_internal = !!(touchpad->tags & EVDEV_TAG_INTERNAL_TOUCHPAD); trp_is_internal = bus_trp != BUS_USB && bus_trp != BUS_BLUETOOTH; if (tp->buttons.trackpoint == NULL && tp_is_internal && trp_is_internal) { /* Don't send any pending releases to the new trackpoint */ tp->buttons.active_is_topbutton = false; tp->buttons.trackpoint = trackpoint; if (tp->palm.monitor_trackpoint) libinput_device_add_event_listener(&trackpoint->base, &tp->palm.trackpoint_listener, tp_trackpoint_event, tp); } } static void tp_lid_switch_event(uint64_t time, struct libinput_event *event, void *data) { struct tp_dispatch *tp = data; struct libinput_event_switch *swev; if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) return; swev = libinput_event_get_switch_event(event); if (libinput_event_switch_get_switch(swev) != LIBINPUT_SWITCH_LID) return; switch (libinput_event_switch_get_switch_state(swev)) { case LIBINPUT_SWITCH_STATE_OFF: tp_resume(tp, tp->device, SUSPEND_LID); evdev_log_debug(tp->device, "lid: resume touchpad\n"); break; case LIBINPUT_SWITCH_STATE_ON: tp_suspend(tp, tp->device, SUSPEND_LID); evdev_log_debug(tp->device, "lid: suspending touchpad\n"); break; } } static void tp_tablet_mode_switch_event(uint64_t time, struct libinput_event *event, void *data) { struct tp_dispatch *tp = data; struct libinput_event_switch *swev; if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) return; swev = libinput_event_get_switch_event(event); if (libinput_event_switch_get_switch(swev) != LIBINPUT_SWITCH_TABLET_MODE) return; switch (libinput_event_switch_get_switch_state(swev)) { case LIBINPUT_SWITCH_STATE_OFF: tp_resume(tp, tp->device, SUSPEND_TABLET_MODE); evdev_log_debug(tp->device, "tablet-mode: resume touchpad\n"); break; case LIBINPUT_SWITCH_STATE_ON: tp_suspend(tp, tp->device, SUSPEND_TABLET_MODE); evdev_log_debug(tp->device, "tablet-mode: suspending touchpad\n"); break; } } static void tp_pair_lid_switch(struct evdev_device *touchpad, struct evdev_device *lid_switch) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; if ((lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0) return; if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD) return; if (tp->lid_switch.lid_switch == NULL) { evdev_log_debug(touchpad, "lid: activated for %s<->%s\n", touchpad->devname, lid_switch->devname); libinput_device_add_event_listener(&lid_switch->base, &tp->lid_switch.listener, tp_lid_switch_event, tp); tp->lid_switch.lid_switch = lid_switch; } } static void tp_pair_tablet_mode_switch(struct evdev_device *touchpad, struct evdev_device *tablet_mode_switch) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; if ((tablet_mode_switch->tags & EVDEV_TAG_TABLET_MODE_SWITCH) == 0) return; if (tp->tablet_mode_switch.tablet_mode_switch) return; if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD) return; if (evdev_device_has_model_quirk(touchpad, QUIRK_MODEL_TABLET_MODE_NO_SUSPEND)) return; evdev_log_debug(touchpad, "tablet-mode: activated for %s<->%s\n", touchpad->devname, tablet_mode_switch->devname); libinput_device_add_event_listener(&tablet_mode_switch->base, &tp->tablet_mode_switch.listener, tp_tablet_mode_switch_event, tp); tp->tablet_mode_switch.tablet_mode_switch = tablet_mode_switch; if (evdev_device_switch_get_state(tablet_mode_switch, LIBINPUT_SWITCH_TABLET_MODE) == LIBINPUT_SWITCH_STATE_ON) { tp_suspend(tp, touchpad, SUSPEND_TABLET_MODE); } } static void tp_change_rotation(struct evdev_device *device, enum notify notify) { struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch; struct evdev_device *tablet_device = tp->left_handed.tablet_device; bool tablet_is_left, touchpad_is_left; if (!tp->left_handed.must_rotate) return; touchpad_is_left = device->left_handed.enabled; tablet_is_left = tp->left_handed.tablet_left_handed_state; tp->left_handed.want_rotate = touchpad_is_left || tablet_is_left; tp_apply_rotation(device); if (notify == DO_NOTIFY && tablet_device) { struct evdev_dispatch *dispatch = tablet_device->dispatch; if (dispatch->interface->left_handed_toggle) dispatch->interface->left_handed_toggle(dispatch, tablet_device, tp->left_handed.want_rotate); } } static void tp_pair_tablet(struct evdev_device *touchpad, struct evdev_device *tablet) { struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch; if (!tp->left_handed.must_rotate) return; if ((tablet->seat_caps & EVDEV_DEVICE_TABLET) == 0) return; if (libinput_device_get_device_group(&touchpad->base) != libinput_device_get_device_group(&tablet->base)) return; tp->left_handed.tablet_device = tablet; evdev_log_debug(touchpad, "touchpad-rotation: %s will rotate %s\n", touchpad->devname, tablet->devname); if (libinput_device_config_left_handed_get(&tablet->base)) { tp->left_handed.want_rotate = true; tp->left_handed.tablet_left_handed_state = true; tp_change_rotation(touchpad, DONT_NOTIFY); } } static void tp_interface_device_added(struct evdev_device *device, struct evdev_device *added_device) { struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch; tp_pair_trackpoint(device, added_device); tp_dwt_pair_keyboard(device, added_device); tp_pair_lid_switch(device, added_device); tp_pair_tablet_mode_switch(device, added_device); tp_pair_tablet(device, added_device); if (tp->sendevents.current_mode != LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) return; if (added_device->tags & EVDEV_TAG_EXTERNAL_MOUSE) tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE); } static void tp_interface_device_removed(struct evdev_device *device, struct evdev_device *removed_device) { struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch; struct evdev_paired_keyboard *kbd; if (removed_device == tp->buttons.trackpoint) { /* Clear any pending releases for the trackpoint */ if (tp->buttons.active && tp->buttons.active_is_topbutton) { tp->buttons.active = 0; tp->buttons.active_is_topbutton = false; } if (tp->palm.monitor_trackpoint) libinput_device_remove_event_listener( &tp->palm.trackpoint_listener); tp->buttons.trackpoint = NULL; } list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) { if (kbd->device == removed_device) { evdev_paired_keyboard_destroy(kbd); tp->dwt.keyboard_active = false; } } if (removed_device == tp->lid_switch.lid_switch) { libinput_device_remove_event_listener( &tp->lid_switch.listener); tp->lid_switch.lid_switch = NULL; tp_resume(tp, device, SUSPEND_LID); } if (removed_device == tp->tablet_mode_switch.tablet_mode_switch) { libinput_device_remove_event_listener( &tp->tablet_mode_switch.listener); tp->tablet_mode_switch.tablet_mode_switch = NULL; tp_resume(tp, device, SUSPEND_TABLET_MODE); } if (tp->sendevents.current_mode == LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) { struct libinput_device *dev; bool found = false; list_for_each(dev, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(dev); if (d != removed_device && (d->tags & EVDEV_TAG_EXTERNAL_MOUSE)) { found = true; break; } } if (!found) tp_resume(tp, device, SUSPEND_EXTERNAL_MOUSE); } if (removed_device == tp->left_handed.tablet_device) { tp->left_handed.tablet_device = NULL; tp->left_handed.tablet_left_handed_state = false; /* Slight awkwardness: removing the tablet causes the * touchpad to rotate back to normal if only the tablet was * set to left-handed. Niche case, nothing to worry about */ tp_change_rotation(device, DO_NOTIFY); } } static inline void evdev_tag_touchpad_internal(struct evdev_device *device) { device->tags |= EVDEV_TAG_INTERNAL_TOUCHPAD; device->tags &= ~EVDEV_TAG_EXTERNAL_TOUCHPAD; } static inline void evdev_tag_touchpad_external(struct evdev_device *device) { device->tags |= EVDEV_TAG_EXTERNAL_TOUCHPAD; device->tags &= ~EVDEV_TAG_INTERNAL_TOUCHPAD; } static void evdev_tag_touchpad(struct evdev_device *device, struct udev_device *udev_device) { int bustype, vendor; const char *prop; prop = udev_device_get_property_value(udev_device, "ID_INPUT_TOUCHPAD_INTEGRATION"); if (prop) { if (streq(prop, "internal")) { evdev_tag_touchpad_internal(device); return; } if (streq(prop, "external")) { evdev_tag_touchpad_external(device); return; } evdev_log_info(device, "tagged with unknown value %s\n", prop); } /* The hwdb is the authority on integration, these heuristics are * the fallback only (they precede the hwdb too). * * Simple approach: * Bluetooth touchpads are considered external, anything else is * internal. Except the ones from some vendors that only make external * touchpads. */ bustype = libevdev_get_id_bustype(device->evdev); vendor = libevdev_get_id_vendor(device->evdev); switch (bustype) { case BUS_BLUETOOTH: evdev_tag_touchpad_external(device); break; default: evdev_tag_touchpad_internal(device); break; } switch (vendor) { /* Logitech does not have internal touchpads */ case VENDOR_ID_LOGITECH: evdev_tag_touchpad_external(device); break; } /* Wacom makes touchpads, but not internal ones */ if (device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD) evdev_tag_touchpad_external(device); if ((device->tags & (EVDEV_TAG_EXTERNAL_TOUCHPAD|EVDEV_TAG_INTERNAL_TOUCHPAD)) == 0) { evdev_log_bug_libinput(device, "Internal or external? Please file a bug.\n"); evdev_tag_touchpad_external(device); } } static void tp_arbitration_timeout(uint64_t now, void *data) { struct tp_dispatch *tp = data; if (tp->arbitration.state != ARBITRATION_NOT_ACTIVE) tp->arbitration.state = ARBITRATION_NOT_ACTIVE; } static void tp_interface_toggle_touch(struct evdev_dispatch *dispatch, struct evdev_device *device, enum evdev_arbitration_state which, const struct phys_rect *rect, uint64_t time) { struct tp_dispatch *tp = tp_dispatch(dispatch); if (which == tp->arbitration.state) return; switch (which) { case ARBITRATION_IGNORE_ALL: case ARBITRATION_IGNORE_RECT: libinput_timer_cancel(&tp->arbitration.arbitration_timer); tp_clear_state(tp); tp->arbitration.state = which; break; case ARBITRATION_NOT_ACTIVE: /* if in-kernel arbitration is in use and there is a touch * and a pen in proximity, lifting the pen out of proximity * causes a touch begin for the touch. On a hand-lift the * proximity out precedes the touch up by a few ms, so we * get what looks like a tap. Fix this by delaying * arbitration by just a little bit so that any touch in * event is caught as palm touch. */ libinput_timer_set(&tp->arbitration.arbitration_timer, time + ms2us(90)); break; } } /* Called when the tablet toggles to left-handed */ static void touchpad_left_handed_toggled(struct evdev_dispatch *dispatch, struct evdev_device *device, bool left_handed_enabled) { struct tp_dispatch *tp = tp_dispatch(dispatch); if (!tp->left_handed.tablet_device) return; evdev_log_debug(device, "touchpad-rotation: tablet is %s\n", left_handed_enabled ? "left-handed" : "right-handed"); /* Our left-handed config is independent even though rotation is * locked. So we rotate when either device is left-handed. But it * can only be actually changed when the device is in a neutral * state, hence the want_rotate. */ tp->left_handed.tablet_left_handed_state = left_handed_enabled; tp_change_rotation(device, DONT_NOTIFY); } static struct evdev_dispatch_interface tp_interface = { .process = tp_interface_process, .suspend = tp_interface_suspend, .remove = tp_interface_remove, .destroy = tp_interface_destroy, .device_added = tp_interface_device_added, .device_removed = tp_interface_device_removed, .device_suspended = tp_interface_device_removed, /* treat as remove */ .device_resumed = tp_interface_device_added, /* treat as add */ .post_added = NULL, .touch_arbitration_toggle = tp_interface_toggle_touch, .touch_arbitration_update_rect = NULL, .get_switch_state = NULL, .left_handed_toggle = touchpad_left_handed_toggled, }; static void tp_init_touch(struct tp_dispatch *tp, struct tp_touch *t, unsigned int index) { t->tp = tp; t->has_ended = true; t->index = index; } static inline void tp_disable_abs_mt(struct evdev_device *device) { struct libevdev *evdev = device->evdev; unsigned int code; for (code = ABS_MT_SLOT; code <= ABS_MAX; code++) libevdev_disable_event_code(evdev, EV_ABS, code); } static bool tp_init_slots(struct tp_dispatch *tp, struct evdev_device *device) { const struct input_absinfo *absinfo; struct map { unsigned int code; int ntouches; } max_touches[] = { { BTN_TOOL_QUINTTAP, 5 }, { BTN_TOOL_QUADTAP, 4 }, { BTN_TOOL_TRIPLETAP, 3 }, { BTN_TOOL_DOUBLETAP, 2 }, }; unsigned int i, n_btn_tool_touches = 1; absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_SLOT); if (absinfo) { tp->num_slots = absinfo->maximum + 1; tp->slot = absinfo->value; tp->has_mt = true; } else { tp->num_slots = 1; tp->slot = 0; tp->has_mt = false; } tp->semi_mt = libevdev_has_property(device->evdev, INPUT_PROP_SEMI_MT); /* Semi-mt devices are not reliable for true multitouch data, so we * simply pretend they're single touch touchpads with BTN_TOOL bits. * Synaptics: * Terrible resolution when two fingers are down, * causing scroll jumps. The single-touch emulation ABS_X/Y is * accurate but the ABS_MT_POSITION touchpoints report the bounding * box and that causes jumps. See https://bugzilla.redhat.com/1235175 * Elantech: * On three-finger taps/clicks, one slot doesn't get a coordinate * assigned. See https://bugs.freedesktop.org/show_bug.cgi?id=93583 * Alps: * If three fingers are set down in the same frame, one slot has the * coordinates 0/0 and may not get updated for several frames. * See https://bugzilla.redhat.com/show_bug.cgi?id=1295073 * * The HP Pavilion DM4 touchpad has random jumps in slots, including * for single-finger movement. See fdo bug 91135 */ if (tp->semi_mt || evdev_device_has_model_quirk(tp->device, QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD)) { tp->num_slots = 1; tp->slot = 0; tp->has_mt = false; } if (!tp->has_mt) tp_disable_abs_mt(device); ARRAY_FOR_EACH(max_touches, m) { if (libevdev_has_event_code(device->evdev, EV_KEY, m->code)) { n_btn_tool_touches = m->ntouches; break; } } tp->ntouches = max(tp->num_slots, n_btn_tool_touches); tp->touches = zalloc(tp->ntouches * sizeof(struct tp_touch)); for (i = 0; i < tp->ntouches; i++) tp_init_touch(tp, &tp->touches[i], i); tp_sync_slots(tp, device); /* Some touchpads don't reset BTN_TOOL_FINGER on touch up and only * change to/from it when BTN_TOOL_DOUBLETAP is set. This causes us * to ignore the first touches events until a two-finger gesture is * performed. */ if (libevdev_get_event_value(device->evdev, EV_KEY, BTN_TOOL_FINGER)) tp_fake_finger_set(tp, BTN_TOOL_FINGER, 1); return true; } static enum libinput_config_status tp_accel_config_set_profile(struct libinput_device *libinput_device, enum libinput_config_accel_profile profile); static bool tp_init_accel(struct tp_dispatch *tp, enum libinput_config_accel_profile which) { struct evdev_device *device = tp->device; int res_x, res_y; struct motion_filter *filter; int dpi = device->dpi; bool use_v_avg = device->use_velocity_averaging; res_x = tp->device->abs.absinfo_x->resolution; res_y = tp->device->abs.absinfo_y->resolution; /* * Not all touchpads report the same amount of units/mm (resolution). * Normalize motion events to the default mouse DPI as base * (unaccelerated) speed. This also evens out any differences in x * and y resolution, so that a circle on the * touchpad does not turn into an ellipse on the screen. */ tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x; tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y; tp->accel.xy_scale_coeff = 1.0 * res_x/res_y; if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) { filter = create_pointer_accelerator_filter_touchpad_flat(dpi); } else if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) { filter = create_custom_accelerator_filter(); } else if (evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_X230) || tp->device->model_flags & EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81) { filter = create_pointer_accelerator_filter_lenovo_x230(dpi, use_v_avg); } else { uint64_t eds_threshold = 0; uint64_t eds_value = 0; if (libevdev_get_id_bustype(device->evdev) == BUS_BLUETOOTH) { eds_threshold = ms2us(50); eds_value = ms2us(10); } filter = create_pointer_accelerator_filter_touchpad(dpi, eds_threshold, eds_value, use_v_avg); } if (!filter) return false; evdev_device_init_pointer_acceleration(tp->device, filter); device->pointer.config.set_profile = tp_accel_config_set_profile; return true; } static enum libinput_config_status tp_accel_config_set_speed(struct libinput_device *device, double speed) { struct evdev_device *dev = evdev_device(device); if (!filter_set_speed(dev->pointer.filter, speed)) return LIBINPUT_CONFIG_STATUS_INVALID; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_status tp_accel_config_set_profile(struct libinput_device *libinput_device, enum libinput_config_accel_profile profile) { struct evdev_device *device = evdev_device(libinput_device); struct tp_dispatch *tp = tp_dispatch(device->dispatch); struct motion_filter *filter; double speed; filter = device->pointer.filter; if (filter_get_type(filter) == profile) return LIBINPUT_CONFIG_STATUS_SUCCESS; speed = filter_get_speed(filter); device->pointer.filter = NULL; if (tp_init_accel(tp, profile)) { tp_accel_config_set_speed(libinput_device, speed); filter_destroy(filter); } else { device->pointer.filter = filter; return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } return LIBINPUT_CONFIG_STATUS_SUCCESS; } static uint32_t tp_scroll_get_methods(struct tp_dispatch *tp) { uint32_t methods = LIBINPUT_CONFIG_SCROLL_EDGE; /* Any movement with more than one finger has random cursor * jumps. Don't allow for 2fg scrolling on this device, see * fdo bug 91135 */ if (evdev_device_has_model_quirk(tp->device, QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD)) return LIBINPUT_CONFIG_SCROLL_EDGE; if (tp->ntouches >= 2) methods |= LIBINPUT_CONFIG_SCROLL_2FG; return methods; } static uint32_t tp_scroll_config_scroll_method_get_methods(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp_scroll_get_methods(tp); } static enum libinput_config_status tp_scroll_config_scroll_method_set_method(struct libinput_device *device, enum libinput_config_scroll_method method) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; uint64_t time = libinput_now(tp_libinput_context(tp)); if (method == tp->scroll.method) return LIBINPUT_CONFIG_STATUS_SUCCESS; tp_edge_scroll_stop_events(tp, time); tp_gesture_stop_twofinger_scroll(tp, time); tp->scroll.method = method; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_scroll_method tp_scroll_config_scroll_method_get_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp->scroll.method; } static enum libinput_config_scroll_method tp_scroll_get_default_method(struct tp_dispatch *tp) { uint32_t methods; enum libinput_config_scroll_method method; methods = tp_scroll_get_methods(tp); if (methods & LIBINPUT_CONFIG_SCROLL_2FG) method = LIBINPUT_CONFIG_SCROLL_2FG; else method = LIBINPUT_CONFIG_SCROLL_EDGE; if ((methods & method) == 0) evdev_log_bug_libinput(tp->device, "invalid default scroll method %d\n", method); return method; } static enum libinput_config_scroll_method tp_scroll_config_scroll_method_get_default_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp_scroll_get_default_method(tp); } static int tp_scroll_config_natural_get_default(struct libinput_device *device) { struct evdev_device *dev = evdev_device(device); return (evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD) || evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON)); } static void tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device) { tp_edge_scroll_init(tp, device); evdev_init_natural_scroll(device); /* Override natural scroll config for Apple touchpads */ device->scroll.config_natural.get_default_enabled = tp_scroll_config_natural_get_default; device->scroll.natural_scrolling_enabled = tp_scroll_config_natural_get_default(&device->base); tp->scroll.config_method.get_methods = tp_scroll_config_scroll_method_get_methods; tp->scroll.config_method.set_method = tp_scroll_config_scroll_method_set_method; tp->scroll.config_method.get_method = tp_scroll_config_scroll_method_get_method; tp->scroll.config_method.get_default_method = tp_scroll_config_scroll_method_get_default_method; tp->scroll.method = tp_scroll_get_default_method(tp); tp->device->base.config.scroll_method = &tp->scroll.config_method; /* In mm for touchpads with valid resolution, see tp_init_accel() */ tp->device->scroll.threshold = 0.0; tp->device->scroll.direction_lock_threshold = 5.0; } static int tp_dwt_config_is_available(struct libinput_device *device) { return 1; } static enum libinput_config_status tp_dwt_config_set(struct libinput_device *device, enum libinput_config_dwt_state enable) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; switch(enable) { case LIBINPUT_CONFIG_DWT_ENABLED: case LIBINPUT_CONFIG_DWT_DISABLED: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } tp->dwt.dwt_enabled = (enable == LIBINPUT_CONFIG_DWT_ENABLED); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_dwt_state tp_dwt_config_get(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp->dwt.dwt_enabled ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED; } static bool tp_dwt_default_enabled(struct tp_dispatch *tp) { return true; } static enum libinput_config_dwt_state tp_dwt_config_get_default(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp_dwt_default_enabled(tp) ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED; } static int tp_dwtp_config_is_available(struct libinput_device *device) { return 1; } static enum libinput_config_status tp_dwtp_config_set(struct libinput_device *device, enum libinput_config_dwtp_state enable) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; switch(enable) { case LIBINPUT_CONFIG_DWTP_ENABLED: case LIBINPUT_CONFIG_DWTP_DISABLED: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } tp->palm.dwtp_enabled = (enable == LIBINPUT_CONFIG_DWTP_ENABLED); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_dwtp_state tp_dwtp_config_get(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp->palm.dwtp_enabled ? LIBINPUT_CONFIG_DWTP_ENABLED : LIBINPUT_CONFIG_DWTP_DISABLED; } static bool tp_dwtp_default_enabled(struct tp_dispatch *tp) { return true; } static enum libinput_config_dwtp_state tp_dwtp_config_get_default(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; return tp_dwtp_default_enabled(tp) ? LIBINPUT_CONFIG_DWTP_ENABLED : LIBINPUT_CONFIG_DWTP_DISABLED; } static inline bool tp_is_tpkb_combo_below(struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; char *prop; enum tpkbcombo_layout layout = TPKBCOMBO_LAYOUT_UNKNOWN; int rc = false; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q) return false; if (quirks_get_string(q, QUIRK_ATTR_TPKBCOMBO_LAYOUT, &prop)) { rc = parse_tpkbcombo_layout_poperty(prop, &layout) && layout == TPKBCOMBO_LAYOUT_BELOW; } quirks_unref(q); return rc; } static inline bool tp_is_tablet(struct evdev_device *device) { return device->tags & EVDEV_TAG_TABLET_TOUCHPAD; } static void tp_init_dwt(struct tp_dispatch *tp, struct evdev_device *device) { if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD && !tp_is_tpkb_combo_below(device)) return; tp->dwt.config.is_available = tp_dwt_config_is_available; tp->dwt.config.set_enabled = tp_dwt_config_set; tp->dwt.config.get_enabled = tp_dwt_config_get; tp->dwt.config.get_default_enabled = tp_dwt_config_get_default; tp->dwt.dwt_enabled = tp_dwt_default_enabled(tp); device->base.config.dwt = &tp->dwt.config; } static void tp_init_dwtp(struct tp_dispatch *tp, struct evdev_device *device) { tp->palm.dwtp_enabled = tp_dwtp_default_enabled(tp); if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD) return; tp->palm.config.is_available = tp_dwtp_config_is_available; tp->palm.config.set_enabled = tp_dwtp_config_set; tp->palm.config.get_enabled = tp_dwtp_config_get; tp->palm.config.get_default_enabled = tp_dwtp_config_get_default; device->base.config.dwtp = &tp->palm.config; } static inline void tp_init_palmdetect_edge(struct tp_dispatch *tp, struct evdev_device *device) { double width, height; struct phys_coords mm = { 0.0, 0.0 }; struct device_coords edges; if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD && !tp_is_tpkb_combo_below(device)) return; /* Edge palm detection hurts more than it helps on Apple touchpads. */ if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD)) return; evdev_device_get_size(device, &width, &height); /* Enable edge palm detection on touchpads >= 70 mm. Anything smaller probably won't need it, until we find out it does */ if (width < 70.0) return; /* palm edges are 8% of the width on each side */ mm.x = min(8, width * 0.08); edges = evdev_device_mm_to_units(device, &mm); tp->palm.left_edge = edges.x; mm.x = width - min(8, width * 0.08); edges = evdev_device_mm_to_units(device, &mm); tp->palm.right_edge = edges.x; if (!tp->buttons.has_topbuttons && height > 55) { /* top edge is 5% of the height */ mm.y = height * 0.05; edges = evdev_device_mm_to_units(device, &mm); tp->palm.upper_edge = edges.y; } } static int tp_read_palm_pressure_prop(struct tp_dispatch *tp, const struct evdev_device *device) { const int default_palm_threshold = 130; uint32_t threshold = default_palm_threshold; struct quirks_context *quirks; struct quirks *q; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q) return threshold; quirks_get_uint32(q, QUIRK_ATTR_PALM_PRESSURE_THRESHOLD, &threshold); quirks_unref(q); return threshold; } static inline void tp_init_palmdetect_pressure(struct tp_dispatch *tp, struct evdev_device *device) { if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) { tp->palm.use_pressure = false; return; } tp->palm.pressure_threshold = tp_read_palm_pressure_prop(tp, device); if (tp->palm.pressure_threshold != 0) { tp->palm.use_pressure = true; evdev_log_debug(device, "palm: pressure threshold is %d\n", tp->palm.pressure_threshold); } } static inline void tp_init_palmdetect_size(struct tp_dispatch *tp, struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; uint32_t threshold; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q) return; if (quirks_get_uint32(q, QUIRK_ATTR_PALM_SIZE_THRESHOLD, &threshold)) { if (threshold != 0) { tp->palm.use_size = true; tp->palm.size_threshold = threshold; } } quirks_unref(q); } static inline void tp_init_palmdetect_arbitration(struct tp_dispatch *tp, struct evdev_device *device) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s arbitration", evdev_device_get_sysname(device)); libinput_timer_init(&tp->arbitration.arbitration_timer, tp_libinput_context(tp), timer_name, tp_arbitration_timeout, tp); tp->arbitration.state = ARBITRATION_NOT_ACTIVE; } static void tp_init_palmdetect(struct tp_dispatch *tp, struct evdev_device *device) { tp->palm.right_edge = INT_MAX; tp->palm.left_edge = INT_MIN; tp->palm.upper_edge = INT_MIN; tp_init_palmdetect_arbitration(tp, device); if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD && !tp_is_tpkb_combo_below(device) && !tp_is_tablet(device)) return; if (!tp_is_tablet(device)) tp->palm.monitor_trackpoint = true; if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_TOOL_TYPE)) tp->palm.use_mt_tool = true; if (!tp_is_tablet(device)) tp_init_palmdetect_edge(tp, device); tp_init_palmdetect_pressure(tp, device); tp_init_palmdetect_size(tp, device); } static void tp_init_sendevents(struct tp_dispatch *tp, struct evdev_device *device) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s trackpoint", evdev_device_get_sysname(device)); libinput_timer_init(&tp->palm.trackpoint_timer, tp_libinput_context(tp), timer_name, tp_trackpoint_timeout, tp); snprintf(timer_name, sizeof(timer_name), "%s keyboard", evdev_device_get_sysname(device)); libinput_timer_init(&tp->dwt.keyboard_timer, tp_libinput_context(tp), timer_name, tp_keyboard_timeout, tp); } static bool tp_pass_sanity_check(struct tp_dispatch *tp, struct evdev_device *device) { struct libevdev *evdev = device->evdev; if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X)) goto error; if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH)) goto error; if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER)) goto error; return true; error: evdev_log_bug_kernel(device, "device failed touchpad sanity checks\n"); return false; } static void tp_init_default_resolution(struct tp_dispatch *tp, struct evdev_device *device) { const int touchpad_width_mm = 69, /* 1 under palm detection */ touchpad_height_mm = 50; int xres, yres; if (!device->abs.is_fake_resolution) return; /* we only get here if * - the touchpad provides no resolution * - the udev hwdb didn't override the resolution * - no ATTR_SIZE_HINT is set * * The majority of touchpads that triggers all these conditions * are old ones, so let's assume a small touchpad size and assume * that. */ evdev_log_info(device, "no resolution or size hints, assuming a size of %dx%dmm\n", touchpad_width_mm, touchpad_height_mm); xres = device->abs.dimensions.x/touchpad_width_mm; yres = device->abs.dimensions.y/touchpad_height_mm; libevdev_set_abs_resolution(device->evdev, ABS_X, xres); libevdev_set_abs_resolution(device->evdev, ABS_Y, yres); libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_X, xres); libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_Y, yres); device->abs.is_fake_resolution = false; } static inline void tp_init_hysteresis(struct tp_dispatch *tp) { int xmargin, ymargin; const struct input_absinfo *ax = tp->device->abs.absinfo_x, *ay = tp->device->abs.absinfo_y; if (ax->fuzz) xmargin = ax->fuzz; else xmargin = ax->resolution/4; if (ay->fuzz) ymargin = ay->fuzz; else ymargin = ay->resolution/4; tp->hysteresis.margin.x = xmargin; tp->hysteresis.margin.y = ymargin; tp->hysteresis.enabled = (ax->fuzz || ay->fuzz); if (tp->hysteresis.enabled) evdev_log_debug(tp->device, "hysteresis enabled. " "See %s/touchpad-jitter.html for details\n", HTTP_DOC_LINK); } static void tp_init_pressure(struct tp_dispatch *tp, struct evdev_device *device) { const struct input_absinfo *abs; unsigned int code; struct quirks_context *quirks; struct quirks *q; struct quirk_range r; int hi, lo; code = tp->has_mt ? ABS_MT_PRESSURE : ABS_PRESSURE; if (!libevdev_has_event_code(device->evdev, EV_ABS, code)) { tp->pressure.use_pressure = false; return; } abs = libevdev_get_abs_info(device->evdev, code); assert(abs); quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) { hi = r.upper; lo = r.lower; if (hi == 0 && lo == 0) { evdev_log_info(device, "pressure-based touch detection disabled\n"); goto out; } } else { double range = absinfo_range(abs); /* Approximately the synaptics defaults */ hi = abs->minimum + 0.12 * range; lo = abs->minimum + 0.10 * range; } if (hi > abs->maximum || hi < abs->minimum || lo > abs->maximum || lo < abs->minimum) { evdev_log_bug_libinput(device, "discarding out-of-bounds pressure range %d:%d\n", hi, lo); goto out; } tp->pressure.use_pressure = true; tp->pressure.high = hi; tp->pressure.low = lo; evdev_log_debug(device, "using pressure-based touch detection (%d:%d)\n", lo, hi); out: quirks_unref(q); } static bool tp_init_touch_size(struct tp_dispatch *tp, struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; struct quirk_range r; int lo, hi; int rc = false; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_TOUCH_MAJOR)) { return false; } quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q && quirks_get_range(q, QUIRK_ATTR_TOUCH_SIZE_RANGE, &r)) { hi = r.upper; lo = r.lower; } else { goto out; } if (libevdev_get_num_slots(device->evdev) < 5) { evdev_log_bug_libinput(device, "Expected 5+ slots for touch size detection\n"); goto out; } if (hi == 0 && lo == 0) { evdev_log_info(device, "touch size based touch detection disabled\n"); goto out; } /* Thresholds apply for both major or minor */ tp->touch_size.low = lo; tp->touch_size.high = hi; tp->touch_size.use_touch_size = true; evdev_log_debug(device, "using size-based touch detection (%d:%d)\n", hi, lo); rc = true; out: quirks_unref(q); return rc; } static void tp_init_pressurepad(struct tp_dispatch *tp, struct evdev_device *device) { /* On traditional touchpads, the pressure value equals contact * size. On PressurePads, pressure is a real physical axis for the * force down. So we disable it here because we don't do anything * with it anyway and using it for touch size messes things up. * * The kernel/udev set the resolution to non-zero on those devices * to indicate that the value is in a known axis space. * * See also #562 */ if (libevdev_get_abs_resolution(device->evdev, ABS_MT_PRESSURE) != 0 || evdev_device_has_model_quirk(device, QUIRK_MODEL_PRESSURE_PAD)) { libevdev_disable_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE); libevdev_disable_event_code(device->evdev, EV_ABS, ABS_PRESSURE); } } static int tp_init(struct tp_dispatch *tp, struct evdev_device *device) { bool use_touch_size = false; tp->base.dispatch_type = DISPATCH_TOUCHPAD; tp->base.interface = &tp_interface; tp->device = device; list_init(&tp->dwt.paired_keyboard_list); if (!tp_pass_sanity_check(tp, device)) return false; tp_init_default_resolution(tp, device); tp_init_pressurepad(tp, device); if (!tp_init_slots(tp, device)) return false; evdev_device_init_abs_range_warnings(device); use_touch_size = tp_init_touch_size(tp, device); if (!use_touch_size) tp_init_pressure(tp, device); /* 5 warnings per 24 hours should be enough */ ratelimit_init(&tp->jump.warning, h2us(24), 5); /* Set the dpi to that of the x axis, because that's what we normalize to when needed*/ device->dpi = device->abs.absinfo_x->resolution * 25.4; tp_init_hysteresis(tp); if (!tp_init_accel(tp, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) return false; tp_init_tap(tp); tp_init_buttons(tp, device); tp_init_dwt(tp, device); tp_init_dwtp(tp, device); tp_init_palmdetect(tp, device); tp_init_sendevents(tp, device); tp_init_scroll(tp, device); tp_init_gesture(tp); tp_init_thumb(tp); /* Lenovo X1 Gen6 buffers the events in a weird way, making jump * detection impossible. See * https://gitlab.freedesktop.org/libinput/libinput/-/issues/506 */ if (evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD)) tp->jump.detection_disabled = true; device->seat_caps |= EVDEV_DEVICE_POINTER; if (tp->gesture.enabled) device->seat_caps |= EVDEV_DEVICE_GESTURE; return true; } static uint32_t tp_sendevents_get_modes(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); uint32_t modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; if (evdev->tags & EVDEV_TAG_INTERNAL_TOUCHPAD) modes |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; return modes; } static void tp_suspend_conditional(struct tp_dispatch *tp, struct evdev_device *device) { struct libinput_device *dev; list_for_each(dev, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(dev); if (d->tags & EVDEV_TAG_EXTERNAL_MOUSE) { tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE); break; } } } static enum libinput_config_status tp_sendevents_set_mode(struct libinput_device *device, enum libinput_config_send_events_mode mode) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch; /* DISABLED overrides any DISABLED_ON_ */ if ((mode & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) && (mode & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE)) mode &= ~LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; if (mode == tp->sendevents.current_mode) return LIBINPUT_CONFIG_STATUS_SUCCESS; switch(mode) { case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: tp_resume(tp, evdev, SUSPEND_SENDEVENTS); tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE); break; case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: tp_suspend(tp, evdev, SUSPEND_SENDEVENTS); tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE); break; case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: tp_suspend_conditional(tp, evdev); tp_resume(tp, evdev, SUSPEND_SENDEVENTS); break; default: return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } tp->sendevents.current_mode = mode; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_send_events_mode tp_sendevents_get_mode(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tp_dispatch *dispatch = (struct tp_dispatch*)evdev->dispatch; return dispatch->sendevents.current_mode; } static enum libinput_config_send_events_mode tp_sendevents_get_default_mode(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } static void tp_change_to_left_handed(struct evdev_device *device) { struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch; if (device->left_handed.want_enabled == device->left_handed.enabled) return; if (tp->buttons.state & 0x3) /* BTN_LEFT|BTN_RIGHT */ return; /* tapping and clickfinger aren't affected by left-handed config, * so checking physical buttons is enough */ device->left_handed.enabled = device->left_handed.want_enabled; tp_change_rotation(device, DO_NOTIFY); } static bool tp_requires_rotation(struct tp_dispatch *tp, struct evdev_device *device) { bool rotate = false; #if HAVE_LIBWACOM struct libinput *li = tp_libinput_context(tp); WacomDeviceDatabase *db = NULL; WacomDevice **devices = NULL, **d; WacomDevice *dev; uint32_t vid = evdev_device_get_id_vendor(device), pid = evdev_device_get_id_product(device); if ((device->tags & EVDEV_TAG_TABLET_TOUCHPAD) == 0) goto out; db = libinput_libwacom_ref(li); if (!db) goto out; /* Check if we have a device with the same vid/pid. If not, we need to loop through all devices and check their paired device. */ dev = libwacom_new_from_usbid(db, vid, pid, NULL); if (dev) { rotate = libwacom_is_reversible(dev); libwacom_destroy(dev); goto out; } devices = libwacom_list_devices_from_database(db, NULL); if (!devices) goto out; d = devices; while(*d) { const WacomMatch *paired; paired = libwacom_get_paired_device(*d); if (paired && libwacom_match_get_vendor_id(paired) == vid && libwacom_match_get_product_id(paired) == pid) { rotate = libwacom_is_reversible(dev); break; } d++; } free(devices); out: /* We don't need to keep it around for the touchpad, we're done with * it until the device dies. */ if (db) libinput_libwacom_unref(li); #endif return rotate; } static void tp_init_left_handed(struct tp_dispatch *tp, struct evdev_device *device) { bool want_left_handed = true; tp->left_handed.must_rotate = tp_requires_rotation(tp, device); if (device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) want_left_handed = false; if (want_left_handed) evdev_init_left_handed(device, tp_change_to_left_handed); } struct evdev_dispatch * evdev_mt_touchpad_create(struct evdev_device *device) { struct tp_dispatch *tp; evdev_tag_touchpad(device, device->udev_device); tp = zalloc(sizeof *tp); if (!tp_init(tp, device)) { tp_interface_destroy(&tp->base); return NULL; } device->base.config.sendevents = &tp->sendevents.config; tp->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; tp->sendevents.config.get_modes = tp_sendevents_get_modes; tp->sendevents.config.set_mode = tp_sendevents_set_mode; tp->sendevents.config.get_mode = tp_sendevents_get_mode; tp->sendevents.config.get_default_mode = tp_sendevents_get_default_mode; tp_init_left_handed(tp, device); return &tp->base; } libinput-1.28.1/src/evdev-mt-touchpad.h000066400000000000000000000457661477265155700177720ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef EVDEV_MT_TOUCHPAD_H #define EVDEV_MT_TOUCHPAD_H #include #include "evdev.h" #include "timer.h" #define TOUCHPAD_HISTORY_LENGTH 4 #define TOUCHPAD_MIN_SAMPLES 4 /* Convert mm to a distance normalized to DEFAULT_MOUSE_DPI */ #define TP_MM_TO_DPI_NORMALIZED(mm) (DEFAULT_MOUSE_DPI/25.4 * mm) enum touchpad_event { TOUCHPAD_EVENT_NONE = 0, TOUCHPAD_EVENT_MOTION = bit(0), TOUCHPAD_EVENT_BUTTON_PRESS = bit(1), TOUCHPAD_EVENT_BUTTON_RELEASE = bit(2), TOUCHPAD_EVENT_OTHERAXIS = bit(3), TOUCHPAD_EVENT_TIMESTAMP = bit(4), }; enum touch_state { TOUCH_NONE = 0, TOUCH_HOVERING = 1, TOUCH_BEGIN = 2, TOUCH_UPDATE = 3, TOUCH_MAYBE_END = 4, TOUCH_END = 5, }; static inline const char * touch_state_to_str(enum touch_state state) { switch(state) { CASE_RETURN_STRING(TOUCH_NONE); CASE_RETURN_STRING(TOUCH_HOVERING); CASE_RETURN_STRING(TOUCH_BEGIN); CASE_RETURN_STRING(TOUCH_UPDATE); CASE_RETURN_STRING(TOUCH_MAYBE_END); CASE_RETURN_STRING(TOUCH_END); } return NULL; } enum touch_palm_state { PALM_NONE = 0, PALM_EDGE, PALM_TYPING, PALM_TRACKPOINT, PALM_TOOL_PALM, PALM_PRESSURE, PALM_TOUCH_SIZE, PALM_ARBITRATION, }; enum button_event { BUTTON_EVENT_IN_BOTTOM_R = 30, BUTTON_EVENT_IN_BOTTOM_M, BUTTON_EVENT_IN_BOTTOM_L, BUTTON_EVENT_IN_TOP_R, BUTTON_EVENT_IN_TOP_M, BUTTON_EVENT_IN_TOP_L, BUTTON_EVENT_IN_AREA, BUTTON_EVENT_UP, BUTTON_EVENT_PRESS, BUTTON_EVENT_RELEASE, BUTTON_EVENT_TIMEOUT, }; enum button_state { BUTTON_STATE_NONE, BUTTON_STATE_AREA, BUTTON_STATE_BOTTOM, BUTTON_STATE_TOP, BUTTON_STATE_TOP_NEW, BUTTON_STATE_TOP_TO_IGNORE, BUTTON_STATE_IGNORE, }; enum tp_tap_state { TAP_STATE_IDLE = 4, TAP_STATE_TOUCH, TAP_STATE_HOLD, TAP_STATE_1FGTAP_TAPPED, TAP_STATE_2FGTAP_TAPPED, TAP_STATE_3FGTAP_TAPPED, TAP_STATE_TOUCH_2, TAP_STATE_TOUCH_2_HOLD, TAP_STATE_TOUCH_2_RELEASE, TAP_STATE_TOUCH_3, TAP_STATE_TOUCH_3_HOLD, TAP_STATE_TOUCH_3_RELEASE, TAP_STATE_TOUCH_3_RELEASE_2, TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP, TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP, TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP, TAP_STATE_1FGTAP_DRAGGING_OR_TAP, TAP_STATE_2FGTAP_DRAGGING_OR_TAP, TAP_STATE_3FGTAP_DRAGGING_OR_TAP, TAP_STATE_1FGTAP_DRAGGING, TAP_STATE_2FGTAP_DRAGGING, TAP_STATE_3FGTAP_DRAGGING, TAP_STATE_1FGTAP_DRAGGING_WAIT, TAP_STATE_2FGTAP_DRAGGING_WAIT, TAP_STATE_3FGTAP_DRAGGING_WAIT, TAP_STATE_1FGTAP_DRAGGING_2, TAP_STATE_2FGTAP_DRAGGING_2, TAP_STATE_3FGTAP_DRAGGING_2, TAP_STATE_DEAD, /**< finger count exceeded */ }; enum tp_tap_touch_state { TAP_TOUCH_STATE_IDLE = 16, /**< not in touch */ TAP_TOUCH_STATE_TOUCH, /**< touching, may tap */ TAP_TOUCH_STATE_DEAD, /**< exceeded motion/timeout */ }; /* For edge scrolling, so we only care about right and bottom */ enum tp_edge { EDGE_NONE = 0, EDGE_RIGHT = bit(0), EDGE_BOTTOM = bit(1), }; enum tp_edge_scroll_touch_state { EDGE_SCROLL_TOUCH_STATE_NONE, EDGE_SCROLL_TOUCH_STATE_EDGE_NEW, EDGE_SCROLL_TOUCH_STATE_EDGE, EDGE_SCROLL_TOUCH_STATE_AREA, }; enum tp_gesture_state { GESTURE_STATE_NONE, GESTURE_STATE_UNKNOWN, GESTURE_STATE_HOLD, GESTURE_STATE_HOLD_AND_MOTION, GESTURE_STATE_POINTER_MOTION, GESTURE_STATE_SCROLL_START, GESTURE_STATE_SCROLL, GESTURE_STATE_PINCH_START, GESTURE_STATE_PINCH, GESTURE_STATE_SWIPE_START, GESTURE_STATE_SWIPE, GESTURE_STATE_3FG_DRAG_START, GESTURE_STATE_3FG_DRAG, GESTURE_STATE_3FG_DRAG_RELEASED, }; enum tp_thumb_state { THUMB_STATE_FINGER, THUMB_STATE_JAILED, THUMB_STATE_PINCH, THUMB_STATE_SUPPRESSED, THUMB_STATE_REVIVED, THUMB_STATE_REVIVED_JAILED, THUMB_STATE_DEAD, }; enum tp_jump_state { JUMP_STATE_IGNORE = 0, JUMP_STATE_EXPECT_FIRST, JUMP_STATE_EXPECT_DELAY, }; struct tp_touch { struct tp_dispatch *tp; unsigned int index; enum touch_state state; bool has_ended; /* TRACKING_ID == -1 */ bool dirty; struct device_coords point; uint64_t initial_time; int pressure; bool is_tool_palm; /* MT_TOOL_PALM */ int major, minor; bool was_down; /* if distance == 0, false for pure hovering touches */ struct { /* A quirk mostly used on Synaptics touchpads. In a transition to/from fake touches > num_slots, the current event data is likely garbage and the subsequent event is likely too. This marker tells us to reset the motion history again -> this effectively swallows any motion */ bool reset_motion_history; } quirks; struct { struct tp_history_point { uint64_t time; struct device_coords point; } samples[TOUCHPAD_HISTORY_LENGTH]; unsigned int index; unsigned int count; } history; struct { double last_delta_mm; } jumps; struct { struct device_coords center; uint8_t x_motion_history; } hysteresis; /* A pinned touchpoint is the one that pressed the physical button * on a clickpad. After the release, it won't move until the center * moves more than a threshold away from the original coordinates */ struct { bool is_pinned; struct device_coords center; } pinned; /* Software-button state and timeout if applicable */ struct { enum button_state state; /* We use button_event here so we can use == on events */ enum button_event current; struct libinput_timer timer; struct device_coords initial; bool has_moved; /* has moved more than threshold */ uint64_t initial_time; } button; struct { enum tp_tap_touch_state state; struct device_coords initial; bool is_thumb; bool is_palm; } tap; struct { enum tp_edge_scroll_touch_state edge_state; uint32_t edge; int direction; struct libinput_timer timer; struct device_coords initial; } scroll; struct { enum touch_palm_state state; struct device_coords first; /* first coordinates if is_palm == true */ uint64_t time; /* first timestamp if is_palm == true */ } palm; struct { struct device_coords initial; } gesture; struct { double last_speed; /* speed in mm/s at last sample */ unsigned int exceeded_count; } speed; }; enum suspend_trigger { SUSPEND_NO_FLAG = 0x0, SUSPEND_EXTERNAL_MOUSE = 0x1, SUSPEND_SENDEVENTS = 0x2, SUSPEND_LID = 0x4, SUSPEND_TABLET_MODE = 0x8, }; struct tp_dispatch { struct evdev_dispatch base; struct evdev_device *device; unsigned int nfingers_down; /* number of fingers down */ unsigned int old_nfingers_down; /* previous no fingers down */ unsigned int slot; /* current slot */ bool has_mt; bool semi_mt; uint32_t suspend_reason; /* pen/touch arbitration */ struct { enum evdev_arbitration_state state; struct libinput_timer arbitration_timer; } arbitration; unsigned int nactive_slots; /* number of active slots */ unsigned int num_slots; /* number of slots */ unsigned int ntouches; /* no slots inc. fakes */ struct tp_touch *touches; /* len == ntouches */ /* bit 0: BTN_TOUCH * bit 1: BTN_TOOL_FINGER * bit 2: BTN_TOOL_DOUBLETAP * ... */ unsigned int fake_touches; struct { bool detection_disabled; struct ratelimit warning; } jump; /* if pressure goes above high -> touch down, if pressure then goes below low -> touch up */ struct { bool use_pressure; int high; int low; } pressure; /* If touch size (either axis) goes above high -> touch down, if touch size (either axis) goes below low -> touch up */ struct { bool use_touch_size; int high; int low; /* convert device units to angle */ double orientation_to_angle; } touch_size; struct { bool enabled; struct device_coords margin; unsigned int other_event_count; uint64_t last_motion_time; } hysteresis; struct { double x_scale_coeff; double y_scale_coeff; double xy_scale_coeff; } accel; struct { struct libinput_device_config_gesture config; bool enabled; unsigned int finger_count; unsigned int finger_count_pending; struct libinput_timer finger_count_switch_timer; enum tp_gesture_state state; struct tp_touch *touches[2]; uint64_t initial_time; double initial_distance; double prev_scale; double angle; struct device_float_coords center; struct libinput_timer hold_timer; bool hold_enabled; struct libinput_timer drag_3fg_timer; uint64_t drag_3fg_release_time; } gesture; struct { bool is_clickpad; /* true for clickpads */ bool has_topbuttons; bool use_clickfinger; /* number of fingers decides button number */ bool click_pending; uint32_t state; uint32_t old_state; struct { double x_scale_coeff; double y_scale_coeff; } motion_dist; /* for pinned touches */ unsigned int active; /* currently active button, for release event */ bool active_is_topbutton; /* is active a top button? */ /* Only used for clickpads. The software button areas are * always 2 horizontal stripes across the touchpad. * The buttons are split according to the edge settings. */ struct { int32_t top_edge; /* in device coordinates */ int32_t rightbutton_left_edge; /* in device coordinates */ int32_t middlebutton_left_edge; /* in device coordinates */ } bottom_area; struct { int32_t bottom_edge; /* in device coordinates */ int32_t rightbutton_left_edge; /* in device coordinates */ int32_t leftbutton_right_edge; /* in device coordinates */ } top_area; struct evdev_device *trackpoint; enum libinput_config_click_method click_method; struct libinput_device_config_click_method config_method; enum libinput_config_clickfinger_button_map map; enum libinput_config_clickfinger_button_map want_map; } buttons; struct { struct libinput_device_config_scroll_method config_method; enum libinput_config_scroll_method method; int32_t right_edge; /* in device coordinates */ int32_t bottom_edge; /* in device coordinates */ struct { bool h, v; } active; struct phys_coords vector; uint64_t time_prev; struct { uint64_t h, v; } duration; } scroll; enum touchpad_event queued; struct { struct libinput_device_config_tap config; bool enabled; bool suspended; struct libinput_timer timer; enum tp_tap_state state; uint32_t buttons_pressed; uint64_t saved_press_time, saved_release_time; enum libinput_config_tap_button_map map; enum libinput_config_tap_button_map want_map; bool drag_enabled; enum libinput_config_drag_lock_state drag_lock; unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */ } tap; struct { struct libinput_device_config_3fg_drag config; size_t nfingers; size_t want_nfingers; } drag_3fg; struct { struct libinput_device_config_dwtp config; bool dwtp_enabled; int32_t right_edge; /* in device coordinates */ int32_t left_edge; /* in device coordinates */ int32_t upper_edge; /* in device coordinates */ bool trackpoint_active; struct libinput_event_listener trackpoint_listener; struct libinput_timer trackpoint_timer; uint64_t trackpoint_last_event_time; uint32_t trackpoint_event_count; bool monitor_trackpoint; bool use_mt_tool; bool use_pressure; int pressure_threshold; bool use_size; int size_threshold; } palm; struct { struct libinput_device_config_send_events config; enum libinput_config_send_events_mode current_mode; } sendevents; struct { struct libinput_device_config_dwt config; bool dwt_enabled; /* We have to allow for more than one device node to be the * internal dwt keyboard (Razer Blade). But they're the same * physical device, so we don't care about per-keyboard * key/modifier masks. */ struct list paired_keyboard_list; unsigned long key_mask[NLONGS(KEY_CNT)]; unsigned long mod_mask[NLONGS(KEY_CNT)]; bool keyboard_active; struct libinput_timer keyboard_timer; uint64_t keyboard_last_press_time; } dwt; struct { bool detect_thumbs; int upper_thumb_line; int lower_thumb_line; bool use_pressure; int pressure_threshold; bool use_size; int size_threshold; enum tp_thumb_state state; unsigned int index; bool pinch_eligible; } thumb; struct { /* A quirk used on the T450 series Synaptics hardware. * Slowly moving the finger causes multiple events with only * ABS_MT_PRESSURE but no x/y information. When the x/y * event comes, it will be a jump of ~20 units. We use the * below to count non-motion events to discard that first * event with the jump. */ unsigned int nonmotion_event_count; struct msc_timestamp { enum tp_jump_state state; uint32_t interval; uint32_t now; } msc_timestamp; } quirks; struct { struct libinput_event_listener listener; struct evdev_device *lid_switch; } lid_switch; struct { struct libinput_event_listener listener; struct evdev_device *tablet_mode_switch; } tablet_mode_switch; struct { bool rotate; bool want_rotate; bool must_rotate; /* true if we should rotate when applicable */ struct evdev_device *tablet_device; bool tablet_left_handed_state; } left_handed; }; static inline struct tp_dispatch* tp_dispatch(struct evdev_dispatch *dispatch) { evdev_verify_dispatch_type(dispatch, DISPATCH_TOUCHPAD); return container_of(dispatch, struct tp_dispatch, base); } #define tp_for_each_touch(_tp, _t) \ for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++) static inline struct libinput* tp_libinput_context(const struct tp_dispatch *tp) { return evdev_libinput_context(tp->device); } static inline struct normalized_coords tp_normalize_delta(const struct tp_dispatch *tp, struct device_float_coords delta) { struct normalized_coords normalized; normalized.x = delta.x * tp->accel.x_scale_coeff; normalized.y = delta.y * tp->accel.y_scale_coeff; return normalized; } static inline struct phys_coords tp_phys_delta(const struct tp_dispatch *tp, struct device_float_coords delta) { struct phys_coords mm; mm.x = delta.x / tp->device->abs.absinfo_x->resolution; mm.y = delta.y / tp->device->abs.absinfo_y->resolution; return mm; } /** * Takes a set of device coordinates, returns that set of coordinates in the * x-axis' resolution. */ static inline struct device_float_coords tp_scale_to_xaxis(const struct tp_dispatch *tp, struct device_float_coords delta) { struct device_float_coords raw; raw.x = delta.x; raw.y = delta.y * tp->accel.xy_scale_coeff; return raw; } struct device_coords tp_get_delta(struct tp_touch *t); struct normalized_coords tp_filter_motion(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time); struct normalized_coords tp_filter_motion_unaccelerated(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time); struct normalized_coords tp_filter_scroll(struct tp_dispatch *tp, const struct device_float_coords *unaccelerated, uint64_t time); bool tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t); bool tp_touch_active_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t); int tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time); void tp_tap_post_process_state(struct tp_dispatch *tp); void tp_button_post_process_state(struct tp_dispatch *tp); void tp_init_tap(struct tp_dispatch *tp); void tp_remove_tap(struct tp_dispatch *tp); void tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device); void tp_init_top_softbuttons(struct tp_dispatch *tp, struct evdev_device *device, double topbutton_size_mult); void tp_remove_buttons(struct tp_dispatch *tp); void tp_process_button(struct tp_dispatch *tp, const struct input_event *e, uint64_t time); void tp_release_all_buttons(struct tp_dispatch *tp, uint64_t time); int tp_post_button_events(struct tp_dispatch *tp, uint64_t time); void tp_button_handle_state(struct tp_dispatch *tp, uint64_t time); bool tp_button_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t); bool tp_button_is_inside_softbutton_area(const struct tp_dispatch *tp, const struct tp_touch *t); void tp_release_all_taps(struct tp_dispatch *tp, uint64_t now); void tp_tap_suspend(struct tp_dispatch *tp, uint64_t time); void tp_tap_resume(struct tp_dispatch *tp, uint64_t time); bool tp_tap_dragging(const struct tp_dispatch *tp); bool tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp); void tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device); void tp_remove_edge_scroll(struct tp_dispatch *tp); void tp_edge_scroll_handle_state(struct tp_dispatch *tp, uint64_t time); int tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time); void tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time); int tp_edge_scroll_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t); uint32_t tp_touch_get_edge(const struct tp_dispatch *tp, const struct tp_touch *t); void tp_init_gesture(struct tp_dispatch *tp); void tp_remove_gesture(struct tp_dispatch *tp); void tp_gesture_stop(struct tp_dispatch *tp, uint64_t time); void tp_gesture_cancel(struct tp_dispatch *tp, uint64_t time); void tp_gesture_cancel_motion_gestures(struct tp_dispatch *tp, uint64_t time); void tp_gesture_update_finger_state(struct tp_dispatch *tp, uint64_t time); void tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time, bool ignore_motion); void tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time); void tp_gesture_tap_timeout(struct tp_dispatch *tp, uint64_t time); void tp_clickpad_middlebutton_apply_config(struct evdev_device *device); bool tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t); void tp_thumb_reset(struct tp_dispatch *tp); bool tp_thumb_ignored_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t); bool tp_thumb_ignored_for_tap(const struct tp_dispatch *tp, const struct tp_touch *t); void tp_thumb_suppress(struct tp_dispatch *tp, struct tp_touch *t); void tp_thumb_update_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time); void tp_detect_thumb_while_moving(struct tp_dispatch *tp); void tp_thumb_update_multifinger(struct tp_dispatch *tp); void tp_init_thumb(struct tp_dispatch *tp); struct tp_touch* tp_thumb_get_touch(struct tp_dispatch *tp); void tp_3fg_drag_apply_config(struct evdev_device *device); #endif libinput-1.28.1/src/evdev-tablet-pad-leds.c000066400000000000000000000417341477265155700204710ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include "evdev-tablet-pad.h" #if HAVE_LIBWACOM #include #endif /* We only have 4 modes on current devices but * anything other than MODE_NEXT is used as * numeric value anyway so it doesn't matter if a value is * missing here * * Once libwacom 2.15 is commonplace we can use the * libwacom enum directly. */ enum pad_toggle_button_target_mode { MODE_NEXT = -1, MODE_0, MODE_1, MODE_2, MODE_3, }; struct pad_led_group { struct libinput_tablet_pad_mode_group base; struct list led_list; struct list toggle_button_list; }; struct pad_mode_toggle_button { struct list link; unsigned int button_index; enum pad_toggle_button_target_mode target_mode; }; struct pad_mode_led { struct list link; /* /sys/devices/..../input1235/input1235::wacom-led_0.1/brightness */ int brightness_fd; int mode_idx; }; static inline void pad_mode_toggle_button_destroy(struct pad_mode_toggle_button* button) { list_remove(&button->link); free(button); } static inline int pad_led_group_get_mode(struct pad_led_group *group) { char buf[4] = {0}; int rc; unsigned int brightness; struct pad_mode_led *led; list_for_each(led, &group->led_list, link) { rc = lseek(led->brightness_fd, 0, SEEK_SET); if (rc == -1) return -errno; rc = read(led->brightness_fd, buf, sizeof(buf) - 1); if (rc == -1) return -errno; rc = sscanf(buf, "%u\n", &brightness); if (rc != 1) return -EINVAL; /* Assumption: only one LED lit up at any time */ if (brightness != 0) return led->mode_idx; } /* Wacom PTH-660 doesn't light up any LEDs * until the button is pressed, so let's assume mode 0 */ return 0; } static inline void pad_led_destroy(struct libinput *libinput, struct pad_mode_led *led) { list_remove(&led->link); if (led->brightness_fd != -1) close_restricted(libinput, led->brightness_fd); free(led); } #if HAVE_LIBWACOM static inline struct pad_mode_led * pad_led_new(struct libinput *libinput, const char *prefix, int group, int mode) { struct pad_mode_led *led; char path[PATH_MAX]; int rc, fd, save_errno; led = zalloc(sizeof *led); led->brightness_fd = -1; led->mode_idx = mode; list_init(&led->link); /* /sys/devices/..../input1235/input1235::wacom-0.1/brightness, * where 0 and 1 are group and mode index. */ rc = snprintf(path, sizeof(path), "%s%d.%d/brightness", prefix, group, mode); if (rc == -1) goto error; fd = open_restricted(libinput, path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); if (fd < 0) { errno = -fd; goto error; } led->brightness_fd = fd; return led; error: save_errno = errno; pad_led_destroy(libinput, led); errno = save_errno; return NULL; } #endif /* HAVE_LIBWACOM */ static void pad_led_group_destroy(struct libinput_tablet_pad_mode_group *g) { struct pad_led_group *group = (struct pad_led_group *)g; struct pad_mode_toggle_button *button; struct pad_mode_led *led; list_for_each_safe(button, &group->toggle_button_list, link) pad_mode_toggle_button_destroy(button); list_for_each_safe(led, &group->led_list, link) pad_led_destroy(g->device->seat->libinput, led); free(group); } static struct pad_led_group * pad_group_new(struct pad_dispatch *pad, unsigned int group_index, int num_modes) { struct pad_led_group *group; group = zalloc(sizeof *group); group->base.device = &pad->device->base; group->base.refcount = 1; group->base.index = group_index; group->base.current_mode = 0; group->base.num_modes = num_modes; group->base.destroy = pad_led_group_destroy; list_init(&group->toggle_button_list); list_init(&group->led_list); return group; } static inline struct libinput_tablet_pad_mode_group * pad_get_mode_group(struct pad_dispatch *pad, unsigned int index) { struct libinput_tablet_pad_mode_group *group; list_for_each(group, &pad->modes.mode_group_list, link) { if (group->index == index) return group; } return NULL; } #if HAVE_LIBWACOM static inline bool is_litest_device(struct evdev_device *device) { return !!udev_device_get_property_value(device->udev_device, "LIBINPUT_TEST_DEVICE"); } static inline struct pad_mode_toggle_button * pad_mode_toggle_button_new(unsigned int button_index) { struct pad_mode_toggle_button *button; button = zalloc(sizeof *button); button->button_index = button_index; button->target_mode = MODE_NEXT; return button; } static int pad_led_group_add_toggle_button(struct pad_led_group *group, int button_index, enum pad_toggle_button_target_mode mode) { struct pad_mode_toggle_button *button; button = pad_mode_toggle_button_new(button_index); if (!button) return -ENOMEM; button->target_mode = mode; list_append(&group->toggle_button_list, &button->link); group->base.toggle_button_mask |= bit(button_index); group->base.button_mask |= bit(button_index); return 0; } static inline bool pad_led_get_sysfs_base_path(struct evdev_device *device, char *path_out, size_t path_out_sz) { struct udev_device *parent, *udev_device; const char *test_path; int rc; udev_device = device->udev_device; /* For testing purposes only allow for a base path set through a * udev rule. We still expect the normal directory hierarchy inside */ test_path = udev_device_get_property_value(udev_device, "LIBINPUT_TEST_TABLET_PAD_SYSFS_PATH"); if (test_path) { rc = snprintf(path_out, path_out_sz, "%s", test_path); return rc != -1; } parent = udev_device_get_parent_with_subsystem_devtype(udev_device, "input", NULL); if (!parent) return false; rc = snprintf(path_out, path_out_sz, "%s/%s::wacom-", udev_device_get_syspath(parent), udev_device_get_sysname(parent)); return rc != -1; } static int pad_add_mode_group(struct pad_dispatch *pad, struct evdev_device *device, unsigned int group_index, int nmodes, int button_index, enum pad_toggle_button_target_mode mode, uint32_t ring_mask, uint32_t strip_mask, uint32_t dial_mask, bool create_leds) { struct libinput *li = pad_libinput_context(pad); struct pad_led_group *group = NULL; int rc = -ENOMEM; char syspath[PATH_MAX]; /* syspath is /sys/class/leds/input1234/input12345::wacom-" and only needs the group + mode appended */ if (!pad_led_get_sysfs_base_path(device, syspath, sizeof(syspath))) return -ENOMEM; group = pad_group_new(pad, group_index, nmodes); if (!group) goto out; group->base.ring_mask = ring_mask; group->base.strip_mask = strip_mask; group->base.dial_mask = dial_mask; group->base.button_mask |= bit(button_index); rc = pad_led_group_add_toggle_button(group, button_index, mode); if (rc < 0) goto out; for (int mode = 0; create_leds && mode < nmodes; mode++) { struct pad_mode_led *led; led = pad_led_new(li, syspath, group_index, mode); if (!led) { rc = -errno; goto out; } list_append(&group->led_list, &led->link); } if (create_leds) { rc = pad_led_group_get_mode(group); if (rc < 0) { goto out; } } list_insert(&pad->modes.mode_group_list, &group->base.link); rc = 0; out: if (rc) pad_led_group_destroy(&group->base); return rc; } static int pad_fetch_group_index(struct pad_dispatch *pad, WacomDevice *wacom, int button_index) { char btn = 'A' + button_index; WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn); int led_group = libwacom_get_button_led_group(wacom, btn); if ((flags & WACOM_BUTTON_MODESWITCH) == 0) { evdev_log_bug_libinput(pad->device, "Cannot fetch group index for non-mode toggle button %c\n", btn); return -1; } if (led_group >= 0) return led_group; /* Note on group_index: libwacom gives us the led_group * but this is really just the index of the entry in * the StatusLEDs line. This is effectively always * 0 for the first ring or strip and 1 for the second * ring or strip. The few devices that matter * have either a pair of rings or strips, not mixed. * * Which means for devices where we don't have StatusLEDs * we can hardcode this behavior, if we ever get a ring+strip * devcice we need to update libwacom for that anyway. */ int group_index = -1; switch (flags & WACOM_BUTTON_MODESWITCH) { case WACOM_BUTTON_RING_MODESWITCH: group_index = 0; break; case WACOM_BUTTON_RING2_MODESWITCH: group_index = 1; break; case WACOM_BUTTON_TOUCHSTRIP_MODESWITCH: group_index = 0; break; case WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH: group_index = 1; break; #ifdef HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH case WACOM_BUTTON_DIAL_MODESWITCH: group_index = 0; break; case WACOM_BUTTON_DIAL2_MODESWITCH: group_index = 1; break; #endif } return group_index; } static inline int pad_find_button_group(struct pad_dispatch *pad, WacomDevice *wacom, int button_index, WacomButtonFlags button_flags) { int i; WacomButtonFlags flags; for (i = 0; i < libwacom_get_num_buttons(wacom); i++) { if (i == button_index) continue; flags = libwacom_get_button_flag(wacom, 'A' + i); if ((flags & WACOM_BUTTON_MODESWITCH) == 0) continue; if ((flags & WACOM_BUTTON_DIRECTION) == (button_flags & WACOM_BUTTON_DIRECTION)) return pad_fetch_group_index(pad, wacom, i); } return -1; } static enum pad_toggle_button_target_mode pad_button_target_mode(WacomDevice *wacom, char button) { #ifdef HAVE_LIBWACOM_BUTTON_MODESWITCH_MODE switch (libwacom_get_button_modeswitch_mode(wacom, button)) { case WACOM_MODE_SWITCH_NEXT: return MODE_NEXT; case WACOM_MODE_SWITCH_0: return MODE_0; case WACOM_MODE_SWITCH_1: return MODE_1; case WACOM_MODE_SWITCH_2: return MODE_2; case WACOM_MODE_SWITCH_3: return MODE_3; } #endif return MODE_NEXT; } static int pad_init_leds_from_libwacom(struct pad_dispatch *pad, struct evdev_device *device, WacomDevice *wacom) { int rc = -EINVAL; if (!wacom) return -ENOENT; for (int b = 0; b < libwacom_get_num_buttons(wacom); b++) { char btn = 'A' + b; WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn); int nmodes = 0; uint32_t ring_mask = 0; uint32_t strip_mask = 0; uint32_t dial_mask = 0; bool have_status_led = false; if ((flags & WACOM_BUTTON_MODESWITCH) == 0) continue; enum pad_toggle_button_target_mode target_mode = pad_button_target_mode(wacom, btn); int group_index = pad_fetch_group_index(pad, wacom, b); switch (flags & WACOM_BUTTON_MODESWITCH) { case WACOM_BUTTON_RING_MODESWITCH: nmodes = libwacom_get_ring_num_modes(wacom); ring_mask = 0x1; break; case WACOM_BUTTON_RING2_MODESWITCH: nmodes = libwacom_get_ring2_num_modes(wacom); ring_mask = 0x2; break; case WACOM_BUTTON_TOUCHSTRIP_MODESWITCH: nmodes = libwacom_get_strips_num_modes(wacom); strip_mask = 0x1; break; case WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH: /* there is no get_strips2_... */ nmodes = libwacom_get_strips_num_modes(wacom); strip_mask = 0x2; break; #ifdef HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH case WACOM_BUTTON_DIAL_MODESWITCH: nmodes = libwacom_get_dial_num_modes(wacom); dial_mask = 0x1; break; case WACOM_BUTTON_DIAL2_MODESWITCH: nmodes = libwacom_get_dial2_num_modes(wacom); dial_mask = 0x2; break; #endif default: evdev_log_error(pad->device, "unable to init pad mode group: button %c has multiple modeswitch flags 0x%x\n", btn, flags); goto out; } have_status_led = libwacom_get_button_led_group(wacom, btn) >= 0; if (nmodes > 1) { struct libinput_tablet_pad_mode_group *group = pad_get_mode_group(pad, group_index); if (!group) { rc = pad_add_mode_group(pad, device, group_index, nmodes, b, target_mode, ring_mask, strip_mask, dial_mask, have_status_led); } else { struct pad_led_group *led_group = (struct pad_led_group *)group; /* Multiple toggle buttons (Wacom MobileStudio Pro 16) */ rc = pad_led_group_add_toggle_button(led_group, b, target_mode); if (rc < 0) goto out; } } } if (list_empty(&pad->modes.mode_group_list)) { rc = 1; goto out; } /* Now loop again to match the other buttons with the existing * mode groups */ for (int b = 0; b < libwacom_get_num_buttons(wacom); b++) { char btn = 'A' + b; WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn); if ((flags & WACOM_BUTTON_MODESWITCH)) continue; int group_index = pad_find_button_group(pad, wacom, b, flags); if (group_index == -1) { evdev_log_bug_libinput(pad->device, "unhandled position for button %i\n", b); rc = -EINVAL; goto out; } struct libinput_tablet_pad_mode_group *group = pad_get_mode_group(pad, group_index); if (!group) { evdev_log_bug_libinput(pad->device, "Failed to find group %d for button %i\n", group_index, b); rc = -EINVAL; goto out; } group->button_mask |= bit(b); } rc = 0; out: if (rc != 0) { if (rc == -ENOENT && is_litest_device(pad->device)) { evdev_log_error(pad->device, "unable to init pad mode group: %s\n", strerror(-rc)); } pad_destroy_leds(pad); } return rc; } #endif /* HAVE_LIBWACOM */ static int pad_init_fallback_group(struct pad_dispatch *pad) { struct pad_led_group *group; group = pad_group_new(pad, 0, 1); if (!group) return 1; /* If we only have one group, all buttons/strips/rings are part of * that group. We rely on the other layers to filter out invalid * indices */ group->base.button_mask = -1; group->base.strip_mask = -1; group->base.ring_mask = -1; group->base.dial_mask = -1; group->base.toggle_button_mask = 0; list_insert(&pad->modes.mode_group_list, &group->base.link); return 0; } int pad_init_leds(struct pad_dispatch *pad, struct evdev_device *device, WacomDevice *wacom) { int rc = 1; list_init(&pad->modes.mode_group_list); if (pad->nbuttons > 32) { evdev_log_bug_libinput(pad->device, "Too many pad buttons for modes %d\n", pad->nbuttons); return rc; } /* If libwacom fails, we init one fallback group anyway */ #if HAVE_LIBWACOM rc = pad_init_leds_from_libwacom(pad, device, wacom); #endif if (rc != 0) rc = pad_init_fallback_group(pad); return rc; } void pad_destroy_leds(struct pad_dispatch *pad) { struct libinput_tablet_pad_mode_group *group; list_for_each_safe(group, &pad->modes.mode_group_list, link) libinput_tablet_pad_mode_group_unref(group); } void pad_button_update_mode(struct libinput_tablet_pad_mode_group *g, unsigned int button_index, enum libinput_button_state state) { struct pad_led_group *group = (struct pad_led_group*)g; int rc = -ENODEV; if (state != LIBINPUT_BUTTON_STATE_PRESSED) return; if (!libinput_tablet_pad_mode_group_button_is_toggle(g, button_index)) return; if (list_empty(&group->led_list)) { struct pad_mode_toggle_button *button; list_for_each(button, &group->toggle_button_list, link) { if (button->button_index == button_index) { if (button->target_mode == MODE_NEXT) { unsigned int nmodes = group->base.num_modes; rc = (group->base.current_mode + 1) % nmodes; } else { rc = button->target_mode; } break; } } } else { rc = pad_led_group_get_mode(group); } if (rc >= 0) group->base.current_mode = rc; } int evdev_device_tablet_pad_get_num_mode_groups(struct evdev_device *device) { struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch; struct libinput_tablet_pad_mode_group *group; int num_groups = 0; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; list_for_each(group, &pad->modes.mode_group_list, link) num_groups++; return num_groups; } struct libinput_tablet_pad_mode_group * evdev_device_tablet_pad_get_mode_group(struct evdev_device *device, unsigned int index) { struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return NULL; if (index >= (unsigned int)evdev_device_tablet_pad_get_num_mode_groups(device)) return NULL; return pad_get_mode_group(pad, index); } libinput-1.28.1/src/evdev-tablet-pad.c000066400000000000000000000576461477265155700175550ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev-tablet-pad.h" #include "util-input-event.h" #include #include #include #if HAVE_LIBWACOM #include #endif #define pad_set_status(pad_,s_) (pad_)->status |= (s_) #define pad_unset_status(pad_,s_) (pad_)->status &= ~(s_) #define pad_has_status(pad_,s_) (!!((pad_)->status & (s_))) static void pad_get_buttons_pressed(struct pad_dispatch *pad, struct button_state *buttons) { struct button_state *state = &pad->button_state; struct button_state *prev_state = &pad->prev_button_state; unsigned int i; for (i = 0; i < sizeof(buttons->bits); i++) buttons->bits[i] = state->bits[i] & ~(prev_state->bits[i]); } static void pad_get_buttons_released(struct pad_dispatch *pad, struct button_state *buttons) { struct button_state *state = &pad->button_state; struct button_state *prev_state = &pad->prev_button_state; unsigned int i; for (i = 0; i < sizeof(buttons->bits); i++) buttons->bits[i] = prev_state->bits[i] & ~(state->bits[i]); } static inline bool pad_button_is_down(const struct pad_dispatch *pad, uint32_t button) { return bit_is_set(pad->button_state.bits, button); } static inline bool pad_any_button_down(const struct pad_dispatch *pad) { const struct button_state *state = &pad->button_state; unsigned int i; for (i = 0; i < sizeof(state->bits); i++) if (state->bits[i] != 0) return true; return false; } static inline void pad_button_set_down(struct pad_dispatch *pad, uint32_t button, bool is_down) { struct button_state *state = &pad->button_state; if (is_down) { set_bit(state->bits, button); pad_set_status(pad, PAD_BUTTONS_PRESSED); } else { clear_bit(state->bits, button); pad_set_status(pad, PAD_BUTTONS_RELEASED); } } static void pad_process_relative(struct pad_dispatch *pad, struct evdev_device *device, struct input_event *e, uint64_t time) { switch (e->code) { case REL_DIAL: pad->dials.dial1 = e->value * 120; pad->changed_axes |= PAD_AXIS_DIAL1; pad_set_status(pad, PAD_AXES_UPDATED); break; case REL_WHEEL: if (!pad->dials.has_hires_dial) { pad->dials.dial1 = -1 * e->value * 120; pad->changed_axes |= PAD_AXIS_DIAL1; pad_set_status(pad, PAD_AXES_UPDATED); } break; case REL_HWHEEL: if (!pad->dials.has_hires_dial) { pad->dials.dial2 = e->value * 120; pad->changed_axes |= PAD_AXIS_DIAL2; pad_set_status(pad, PAD_AXES_UPDATED); } break; case REL_WHEEL_HI_RES: pad->dials.dial1 = -1 * e->value; pad->changed_axes |= PAD_AXIS_DIAL1; pad_set_status(pad, PAD_AXES_UPDATED); break; case REL_HWHEEL_HI_RES: pad->dials.dial2 = e->value; pad->changed_axes |= PAD_AXIS_DIAL2; pad_set_status(pad, PAD_AXES_UPDATED); break; default: evdev_log_info(device, "Unhandled EV_REL event code %#x\n", e->code); break; } } static void pad_update_changed_axis(struct pad_dispatch *pad, enum pad_axes axis, const struct input_event *e) { if (pad->changed_axes & axis) { evdev_log_bug_kernel_ratelimit(pad->device, &pad->duplicate_abs_limit, "Multiple EV_ABS %s events in the same SYN_REPORT\n", libevdev_event_code_get_name(EV_ABS, e->code)); /* Special heuristics probably good enough: * if we get multiple EV_ABS in the same SYN_REPORT * and one of them is zero, assume they're all * zero and unchanged. That's not perfectly * correct but probably covers all cases */ if (e->value == 0) { pad->changed_axes &= ~axis; if (pad->changed_axes == 0) pad_unset_status(pad, PAD_AXES_UPDATED); return; } } pad->changed_axes |= axis; pad_set_status(pad, PAD_AXES_UPDATED); } static void pad_process_absolute(struct pad_dispatch *pad, struct evdev_device *device, struct input_event *e, uint64_t time) { enum pad_axes axis = PAD_AXIS_NONE; switch (e->code) { case ABS_WHEEL: axis = PAD_AXIS_RING1; break; case ABS_THROTTLE: axis = PAD_AXIS_RING2; break; case ABS_RX: axis = PAD_AXIS_STRIP1; break; case ABS_RY: axis = PAD_AXIS_STRIP2; break; case ABS_MISC: /* The wacom driver always sends a 0 axis event on finger up, but we also get an ABS_MISC 15 on touch down and ABS_MISC 0 on touch up, on top of the actual event. This is kernel behavior for xf86-input-wacom backwards compatibility after the 3.17 wacom HID move. We use that event to tell when we truly went a full rotation around the wheel vs. a finger release. FIXME: On the Intuos5 and later the kernel merges all states into that event, so if any finger is down on any button, the wheel release won't trigger the ABS_MISC 0 but still send a 0 event. We can't currently detect this. */ pad->have_abs_misc_terminator = true; break; default: evdev_log_info(device, "Unhandled EV_ABS event code %#x\n", e->code); break; } if (axis != PAD_AXIS_NONE) { pad_update_changed_axis(pad, axis, e); } } static inline double normalize_wacom_ring(const struct input_absinfo *absinfo) { /* libinput has 0 as the ring's northernmost point in the device's current logical rotation, increasing clockwise to 1. Wacom has 0 on the left-most wheel position. */ double range = absinfo_range(absinfo); double value = (absinfo->value - absinfo->minimum) / range - 0.25; if (value < 0.0) value += 1.0; return value; } static inline double normalize_wacom_strip(const struct input_absinfo *absinfo) { /* strip axes don't use a proper value, they just shift the bit left * for each position. 0 isn't a real value either, it's only sent on * finger release */ double min = 0, max = log2(absinfo->maximum); double range = max - min; double value = (log2(absinfo->value) - min) / range; return value; } static inline double normalize_strip(const struct input_absinfo *absinfo) { return absinfo_normalize_value(absinfo, absinfo->value); } static inline double pad_handle_ring(struct pad_dispatch *pad, struct evdev_device *device, unsigned int code) { const struct input_absinfo *absinfo; double degrees; absinfo = libevdev_get_abs_info(device->evdev, code); assert(absinfo); degrees = normalize_wacom_ring(absinfo) * 360; if (device->left_handed.enabled) degrees = fmod(degrees + 180, 360); return degrees; } static inline double pad_handle_strip(struct pad_dispatch *pad, struct evdev_device *device, unsigned int code) { const struct input_absinfo *absinfo; double pos; absinfo = libevdev_get_abs_info(device->evdev, code); assert(absinfo); if (absinfo->value == 0) return 0.0; if (evdev_device_get_id_vendor(device) == VENDOR_ID_WACOM) pos = normalize_wacom_strip(absinfo); else pos = normalize_strip(absinfo); if (device->left_handed.enabled) pos = 1.0 - pos; return pos; } static inline struct libinput_tablet_pad_mode_group * pad_dial_get_mode_group(struct pad_dispatch *pad, unsigned int dial) { struct libinput_tablet_pad_mode_group *group; list_for_each(group, &pad->modes.mode_group_list, link) { if (libinput_tablet_pad_mode_group_has_dial(group, dial)) return group; } assert(!"Unable to find dial mode group"); return NULL; } static inline struct libinput_tablet_pad_mode_group * pad_ring_get_mode_group(struct pad_dispatch *pad, unsigned int ring) { struct libinput_tablet_pad_mode_group *group; list_for_each(group, &pad->modes.mode_group_list, link) { if (libinput_tablet_pad_mode_group_has_ring(group, ring)) return group; } assert(!"Unable to find ring mode group"); return NULL; } static inline struct libinput_tablet_pad_mode_group * pad_strip_get_mode_group(struct pad_dispatch *pad, unsigned int strip) { struct libinput_tablet_pad_mode_group *group; list_for_each(group, &pad->modes.mode_group_list, link) { if (libinput_tablet_pad_mode_group_has_strip(group, strip)) return group; } assert(!"Unable to find strip mode group"); return NULL; } static void pad_check_notify_axes(struct pad_dispatch *pad, struct evdev_device *device, uint64_t time) { struct libinput_device *base = &device->base; struct libinput_tablet_pad_mode_group *group; double value; bool send_finger_up = false; /* Suppress the reset to 0 on finger up. See the comment in pad_process_absolute */ if (pad->have_abs_misc_terminator && libevdev_get_event_value(device->evdev, EV_ABS, ABS_MISC) == 0) send_finger_up = true; /* Unlike the ring axis we don't get an event when we release * so we can't set a source */ if (pad->changed_axes & PAD_AXIS_DIAL1) { group = pad_dial_get_mode_group(pad, 0); tablet_pad_notify_dial(base, time, 0, pad->dials.dial1, group); } if (pad->changed_axes & PAD_AXIS_DIAL2) { group = pad_dial_get_mode_group(pad, 1); tablet_pad_notify_dial(base, time, 1, pad->dials.dial2, group); } if (pad->changed_axes & PAD_AXIS_RING1) { value = pad_handle_ring(pad, device, ABS_WHEEL); if (send_finger_up) value = -1.0; group = pad_ring_get_mode_group(pad, 0); tablet_pad_notify_ring(base, time, 0, value, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER, group); } if (pad->changed_axes & PAD_AXIS_RING2) { value = pad_handle_ring(pad, device, ABS_THROTTLE); if (send_finger_up) value = -1.0; group = pad_ring_get_mode_group(pad, 1); tablet_pad_notify_ring(base, time, 1, value, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER, group); } if (pad->changed_axes & PAD_AXIS_STRIP1) { value = pad_handle_strip(pad, device, ABS_RX); if (send_finger_up) value = -1.0; group = pad_strip_get_mode_group(pad, 0); tablet_pad_notify_strip(base, time, 0, value, LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, group); } if (pad->changed_axes & PAD_AXIS_STRIP2) { value = pad_handle_strip(pad, device, ABS_RY); if (send_finger_up) value = -1.0; group = pad_strip_get_mode_group(pad, 1); tablet_pad_notify_strip(base, time, 1, value, LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, group); } pad->changed_axes = PAD_AXIS_NONE; pad->have_abs_misc_terminator = false; } static void pad_process_key(struct pad_dispatch *pad, struct evdev_device *device, struct input_event *e, uint64_t time) { uint32_t button = e->code; uint32_t is_press = e->value != 0; /* ignore kernel key repeat */ if (e->value == 2) return; pad_button_set_down(pad, button, is_press); } static inline struct libinput_tablet_pad_mode_group * pad_button_get_mode_group(struct pad_dispatch *pad, unsigned int button) { struct libinput_tablet_pad_mode_group *group; list_for_each(group, &pad->modes.mode_group_list, link) { if (libinput_tablet_pad_mode_group_has_button(group, button)) return group; } assert(!"Unable to find button mode group\n"); return NULL; } static void pad_notify_button_mask(struct pad_dispatch *pad, struct evdev_device *device, uint64_t time, const struct button_state *buttons, enum libinput_button_state state) { struct libinput_device *base = &device->base; struct libinput_tablet_pad_mode_group *group; int32_t code; unsigned int i; for (i = 0; i < sizeof(buttons->bits); i++) { unsigned char buttons_slice = buttons->bits[i]; code = i * 8; while (buttons_slice) { int enabled; key_or_button_map_t map; code++; enabled = (buttons_slice & 1); buttons_slice >>= 1; if (!enabled) continue; map = pad->button_map[code - 1]; if (map_is_unmapped(map)) continue; if (map_is_button(map)) { int32_t button = map_value(map); group = pad_button_get_mode_group(pad, button); pad_button_update_mode(group, button, state); tablet_pad_notify_button(base, time, button, state, group); } else if (map_is_key(map)) { uint32_t key = map_value(map); tablet_pad_notify_key(base, time, key, (enum libinput_key_state)state); } else { abort(); } } } } static void pad_notify_buttons(struct pad_dispatch *pad, struct evdev_device *device, uint64_t time, enum libinput_button_state state) { struct button_state buttons; if (state == LIBINPUT_BUTTON_STATE_PRESSED) pad_get_buttons_pressed(pad, &buttons); else pad_get_buttons_released(pad, &buttons); pad_notify_button_mask(pad, device, time, &buttons, state); } static void pad_change_to_left_handed(struct evdev_device *device) { struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch; if (device->left_handed.enabled == device->left_handed.want_enabled) return; if (pad_any_button_down(pad)) return; device->left_handed.enabled = device->left_handed.want_enabled; } static void pad_flush(struct pad_dispatch *pad, struct evdev_device *device, uint64_t time) { if (pad_has_status(pad, PAD_AXES_UPDATED)) { pad_check_notify_axes(pad, device, time); pad_unset_status(pad, PAD_AXES_UPDATED); } if (pad_has_status(pad, PAD_BUTTONS_RELEASED)) { pad_notify_buttons(pad, device, time, LIBINPUT_BUTTON_STATE_RELEASED); pad_unset_status(pad, PAD_BUTTONS_RELEASED); pad_change_to_left_handed(device); } if (pad_has_status(pad, PAD_BUTTONS_PRESSED)) { pad_notify_buttons(pad, device, time, LIBINPUT_BUTTON_STATE_PRESSED); pad_unset_status(pad, PAD_BUTTONS_PRESSED); } /* Update state */ memcpy(&pad->prev_button_state, &pad->button_state, sizeof(pad->button_state)); pad->dials.dial1 = 0; pad->dials.dial2 = 0; } static void pad_process(struct evdev_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { struct pad_dispatch *pad = pad_dispatch(dispatch); switch (e->type) { case EV_REL: pad_process_relative(pad, device, e, time); break; case EV_ABS: pad_process_absolute(pad, device, e, time); break; case EV_KEY: pad_process_key(pad, device, e, time); break; case EV_SYN: pad_flush(pad, device, time); break; case EV_MSC: /* The EKR sends the serial as MSC_SERIAL, ignore this for * now */ break; default: evdev_log_error(device, "Unexpected event type %s (%#x)\n", libevdev_event_type_get_name(e->type), e->type); break; } } static void pad_suspend(struct evdev_dispatch *dispatch, struct evdev_device *device) { struct pad_dispatch *pad = pad_dispatch(dispatch); struct libinput *libinput = pad_libinput_context(pad); unsigned int code; for (code = KEY_ESC; code < KEY_CNT; code++) { if (pad_button_is_down(pad, code)) pad_button_set_down(pad, code, false); } pad_flush(pad, device, libinput_now(libinput)); } static void pad_destroy(struct evdev_dispatch *dispatch) { struct pad_dispatch *pad = pad_dispatch(dispatch); pad_destroy_leds(pad); free(pad); } static struct evdev_dispatch_interface pad_interface = { .process = pad_process, .suspend = pad_suspend, .remove = NULL, .destroy = pad_destroy, .device_added = NULL, .device_removed = NULL, .device_suspended = NULL, .device_resumed = NULL, .post_added = NULL, .touch_arbitration_toggle = NULL, .touch_arbitration_update_rect = NULL, .get_switch_state = NULL, }; static bool pad_init_buttons_from_libwacom(struct pad_dispatch *pad, struct evdev_device *device, WacomDevice *tablet) { bool rc = false; #if HAVE_LIBWACOM if (tablet) { int num_buttons = libwacom_get_num_buttons(tablet); int map = 0; for (int i = 0; i < num_buttons; i++) { unsigned int code; code = libwacom_get_button_evdev_code(tablet, 'A' + i); if (code == 0) continue; map_set_button_map(pad->button_map[code], map++); } pad->nbuttons = map; rc = true; } #endif return rc; } static void pad_init_buttons_from_kernel(struct pad_dispatch *pad, struct evdev_device *device) { unsigned int code; int map = 0; /* we match wacom_report_numbered_buttons() from the kernel */ for (code = BTN_0; code < BTN_0 + 10; code++) { if (libevdev_has_event_code(device->evdev, EV_KEY, code)) map_set_button_map(pad->button_map[code], map++); } for (code = BTN_BASE; code < BTN_BASE + 2; code++) { if (libevdev_has_event_code(device->evdev, EV_KEY, code)) map_set_button_map(pad->button_map[code], map++); } for (code = BTN_A; code < BTN_A + 6; code++) { if (libevdev_has_event_code(device->evdev, EV_KEY, code)) map_set_button_map(pad->button_map[code], map++); } for (code = BTN_LEFT; code < BTN_LEFT + 7; code++) { if (libevdev_has_event_code(device->evdev, EV_KEY, code)) map_set_button_map(pad->button_map[code], map++); } pad->nbuttons = map; } static void pad_init_keys(struct pad_dispatch *pad, struct evdev_device *device) { unsigned int codes[] = { KEY_BUTTONCONFIG, KEY_ONSCREEN_KEYBOARD, KEY_CONTROLPANEL, }; /* Wacom's keys are the only ones we know anything about */ if (libevdev_get_id_vendor(device->evdev) != VENDOR_ID_WACOM) return; ARRAY_FOR_EACH(codes, code) { if (libevdev_has_event_code(device->evdev, EV_KEY, *code)) map_set_key_map(pad->button_map[*code], *code); } } static void pad_init_buttons(struct pad_dispatch *pad, struct evdev_device *device, WacomDevice *wacom) { size_t i; for (i = 0; i < ARRAY_LENGTH(pad->button_map); i++) map_init(pad->button_map[i]); if (!pad_init_buttons_from_libwacom(pad, device, wacom)) pad_init_buttons_from_kernel(pad, device); pad_init_keys(pad, device); } static void pad_init_left_handed(struct evdev_device *device, WacomDevice *wacom) { bool has_left_handed = true; #if HAVE_LIBWACOM has_left_handed = !wacom || libwacom_is_reversible(wacom); #endif if (has_left_handed) evdev_init_left_handed(device, pad_change_to_left_handed); } static int pad_init(struct pad_dispatch *pad, struct evdev_device *device) { int rc = 1; struct libinput *li = evdev_libinput_context(device); WacomDevice *wacom = NULL; #if HAVE_LIBWACOM WacomDeviceDatabase *db = libinput_libwacom_ref(li); if (db) { char event_path[64]; snprintf(event_path, sizeof(event_path), "/dev/input/%s", evdev_device_get_sysname(device)); wacom = libwacom_new_from_path(db, event_path, WFALLBACK_NONE, NULL); if (!wacom) { wacom = libwacom_new_from_usbid(db, evdev_device_get_id_vendor(device), evdev_device_get_id_product(device), NULL); } if (!wacom) { evdev_log_info(device, "device \"%s\" (%04x:%04x) is not known to libwacom\n", evdev_device_get_name(device), evdev_device_get_id_vendor(device), evdev_device_get_id_product(device)); } } #endif pad->base.dispatch_type = DISPATCH_TABLET_PAD; pad->base.interface = &pad_interface; pad->device = device; pad->status = PAD_NONE; pad->changed_axes = PAD_AXIS_NONE; /* We expect the kernel to either give us both axes as hires or neither. * Getting one is a kernel bug we don't need to care about */ pad->dials.has_hires_dial = libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL_HI_RES) || libevdev_has_event_code(device->evdev, EV_REL, REL_HWHEEL_HI_RES); if (libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL) && libevdev_has_event_code(device->evdev, EV_REL, REL_DIAL)) { log_bug_libinput(li, "Unsupported combination REL_DIAL and REL_WHEEL\n"); } pad_init_buttons(pad, device, wacom); pad_init_left_handed(device, wacom); rc = pad_init_leds(pad, device, wacom); /* at most 5 "Multiple EV_ABS events" log messages per hour */ ratelimit_init(&pad->duplicate_abs_limit, s2us(60 * 60), 5); #if HAVE_LIBWACOM if (wacom) libwacom_destroy(wacom); if (db) libinput_libwacom_unref(li); #endif return rc; } static uint32_t pad_sendevents_get_modes(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; } static enum libinput_config_status pad_sendevents_set_mode(struct libinput_device *device, enum libinput_config_send_events_mode mode) { struct evdev_device *evdev = evdev_device(device); struct pad_dispatch *pad = (struct pad_dispatch*)evdev->dispatch; if (mode == pad->sendevents.current_mode) return LIBINPUT_CONFIG_STATUS_SUCCESS; switch(mode) { case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: break; case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: pad_suspend(evdev->dispatch, evdev); break; default: return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } pad->sendevents.current_mode = mode; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_send_events_mode pad_sendevents_get_mode(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct pad_dispatch *dispatch = (struct pad_dispatch*)evdev->dispatch; return dispatch->sendevents.current_mode; } static enum libinput_config_send_events_mode pad_sendevents_get_default_mode(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } struct evdev_dispatch * evdev_tablet_pad_create(struct evdev_device *device) { struct pad_dispatch *pad; pad = zalloc(sizeof *pad); if (pad_init(pad, device) != 0) { pad_destroy(&pad->base); return NULL; } device->base.config.sendevents = &pad->sendevents.config; pad->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; pad->sendevents.config.get_modes = pad_sendevents_get_modes; pad->sendevents.config.set_mode = pad_sendevents_set_mode; pad->sendevents.config.get_mode = pad_sendevents_get_mode; pad->sendevents.config.get_default_mode = pad_sendevents_get_default_mode; return &pad->base; } int evdev_device_tablet_pad_has_key(struct evdev_device *device, uint32_t code) { if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; return libevdev_has_event_code(device->evdev, EV_KEY, code); } int evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device) { struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; return pad->nbuttons; } int evdev_device_tablet_pad_get_num_dials(struct evdev_device *device) { int ndials = 0; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; if (libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL) || libevdev_has_event_code(device->evdev, EV_REL, REL_DIAL)) { ndials++; if (libevdev_has_event_code(device->evdev, EV_REL, REL_HWHEEL)) ndials++; } return ndials; } int evdev_device_tablet_pad_get_num_rings(struct evdev_device *device) { int nrings = 0; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL)) { nrings++; if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_THROTTLE)) nrings++; } return nrings; } int evdev_device_tablet_pad_get_num_strips(struct evdev_device *device) { int nstrips = 0; if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD)) return -1; if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_RX)) { nstrips++; if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_RY)) nstrips++; } return nstrips; } libinput-1.28.1/src/evdev-tablet-pad.h000066400000000000000000000066061477265155700175500ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef EVDEV_TABLET_PAD_H #define EVDEV_TABLET_PAD_H #include "evdev.h" #if !HAVE_LIBWACOM typedef void * WacomDevice; #endif #define LIBINPUT_BUTTONSET_AXIS_NONE 0 enum pad_status { PAD_NONE = 0, PAD_AXES_UPDATED = bit(0), PAD_BUTTONS_PRESSED = bit(1), PAD_BUTTONS_RELEASED = bit(2), }; enum pad_axes { PAD_AXIS_NONE = 0, PAD_AXIS_RING1 = bit(0), PAD_AXIS_RING2 = bit(1), PAD_AXIS_STRIP1 = bit(2), PAD_AXIS_STRIP2 = bit(3), PAD_AXIS_DIAL1 = bit(4), PAD_AXIS_DIAL2 = bit(5), }; struct button_state { unsigned char bits[NCHARS(KEY_CNT)]; }; typedef struct { uint32_t value; } key_or_button_map_t; #define map_init(x_) ((x_).value = (uint32_t)-1) #define map_is_unmapped(x_) ((x_).value == (uint32_t)-1) #define map_is_button(x_) (((x_).value & 0xFF000000) == 0) #define map_is_key(x_) (((x_).value & 0xFF000000) != 0) #define map_set_button_map(field_, value_) ((field_).value = value_) #define map_set_key_map(field_, value_) ((field_).value = value_ | 0xFF000000) #define map_value(x_) ((x_).value & 0x00FFFFFF) struct pad_dispatch { struct evdev_dispatch base; struct evdev_device *device; unsigned char status; uint32_t changed_axes; struct button_state button_state; struct button_state prev_button_state; key_or_button_map_t button_map[KEY_CNT]; unsigned int nbuttons; bool have_abs_misc_terminator; struct { bool has_hires_dial; double dial1; double dial2; } dials; struct { struct libinput_device_config_send_events config; enum libinput_config_send_events_mode current_mode; } sendevents; struct { struct list mode_group_list; } modes; struct ratelimit duplicate_abs_limit; }; static inline struct pad_dispatch* pad_dispatch(struct evdev_dispatch *dispatch) { evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET_PAD); return container_of(dispatch, struct pad_dispatch, base); } static inline struct libinput * pad_libinput_context(const struct pad_dispatch *pad) { return evdev_libinput_context(pad->device); } int pad_init_leds(struct pad_dispatch *pad, struct evdev_device *device, WacomDevice *wacom); void pad_destroy_leds(struct pad_dispatch *pad); void pad_button_update_mode(struct libinput_tablet_pad_mode_group *g, unsigned int button_index, enum libinput_button_state state); #endif libinput-1.28.1/src/evdev-tablet.c000066400000000000000000002575651477265155700170150ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * Copyright © 2014 Lyude Paul * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev-tablet.h" #include "util-input-event.h" #include #include #include #if HAVE_LIBWACOM #include #endif enum notify { DONT_NOTIFY, DO_NOTIFY, }; /* The tablet sends events every ~2ms , 50ms should be plenty enough to detect out-of-range. This value is higher during test suite runs */ static int FORCED_PROXOUT_TIMEOUT = 50 * 1000; /* µs */ #define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_) #define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_) #define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_))) static inline void tablet_get_pressed_buttons(struct tablet_dispatch *tablet, struct button_state *buttons) { size_t i; const struct button_state *state = &tablet->button_state, *prev_state = &tablet->prev_button_state; for (i = 0; i < sizeof(buttons->bits); i++) buttons->bits[i] = state->bits[i] & ~(prev_state->bits[i]); } static inline void tablet_get_released_buttons(struct tablet_dispatch *tablet, struct button_state *buttons) { size_t i; const struct button_state *state = &tablet->button_state, *prev_state = &tablet->prev_button_state; for (i = 0; i < sizeof(buttons->bits); i++) buttons->bits[i] = prev_state->bits[i] & ~(state->bits[i]); } static struct libinput_tablet_tool_pressure_threshold* tablet_tool_get_threshold(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) { if (threshold->tablet_id == tablet->tablet_id) { return threshold; } } /* If we ever get here, we failed detecting the proximity for this tablet * (or we have too many tablets). Return the first one which will * make things work incorrectly but we don't need to NULL-check * everything for an extremely unlikely situtation */ evdev_log_bug_libinput(tablet->device, "Failed to find tablet_id %d for pressure offsets\n", tablet->tablet_id); return &tool->pressure.thresholds[0]; } /* Merge the previous state with the current one so all buttons look like * they just got pressed in this frame */ static inline void tablet_force_button_presses(struct tablet_dispatch *tablet) { struct button_state *state = &tablet->button_state, *prev_state = &tablet->prev_button_state; size_t i; for (i = 0; i < sizeof(state->bits); i++) { state->bits[i] = state->bits[i] | prev_state->bits[i]; prev_state->bits[i] = 0; } } static inline size_t tablet_history_size(const struct tablet_dispatch *tablet) { return tablet->history.size; } static inline void tablet_history_reset(struct tablet_dispatch *tablet) { tablet->history.count = 0; } static inline void tablet_history_push(struct tablet_dispatch *tablet, const struct tablet_axes *axes) { unsigned int index = (tablet->history.index + 1) % tablet_history_size(tablet); tablet->history.samples[index] = *axes; tablet->history.index = index; tablet->history.count = min(tablet->history.count + 1, tablet_history_size(tablet)); if (tablet->history.count < tablet_history_size(tablet)) tablet_history_push(tablet, axes); } /** * Return a previous axis state, where index of 0 means "most recent", 1 is * "one before most recent", etc. */ static inline const struct tablet_axes* tablet_history_get(const struct tablet_dispatch *tablet, unsigned int index) { size_t sz = tablet_history_size(tablet); assert(index < sz); assert(index < tablet->history.count); index = (tablet->history.index + sz - index) % sz; return &tablet->history.samples[index]; } static inline void tablet_reset_changed_axes(struct tablet_dispatch *tablet) { memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); } static bool tablet_device_has_axis(struct tablet_dispatch *tablet, enum libinput_tablet_tool_axis axis) { struct libevdev *evdev = tablet->device->evdev; bool has_axis = false; unsigned int code; if (axis == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z) { has_axis = (libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_MOUSE) && libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X) && libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_Y)); code = axis_to_evcode(axis); has_axis |= libevdev_has_event_code(evdev, EV_ABS, code); } else if (axis == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { has_axis = libevdev_has_event_code(evdev, EV_REL, REL_WHEEL); } else { code = axis_to_evcode(axis); has_axis = libevdev_has_event_code(evdev, EV_ABS, code); } return has_axis; } static inline bool tablet_filter_axis_fuzz(const struct tablet_dispatch *tablet, const struct evdev_device *device, const struct input_event *e, enum libinput_tablet_tool_axis axis) { int delta, fuzz; int current, previous; previous = tablet->prev_value[axis]; current = e->value; delta = previous - current; fuzz = libevdev_get_abs_fuzz(device->evdev, e->code); /* ABS_DISTANCE doesn't have have fuzz set and causes continuous * updates for the cursor/lens tools. Add a minimum fuzz of 2, same * as the xf86-input-wacom driver */ switch (e->code) { case ABS_DISTANCE: fuzz = max(2, fuzz); break; default: break; } return abs(delta) <= fuzz; } static void tablet_process_absolute(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, uint64_t time) { enum libinput_tablet_tool_axis axis; switch (e->code) { case ABS_X: case ABS_Y: case ABS_Z: case ABS_PRESSURE: case ABS_TILT_X: case ABS_TILT_Y: case ABS_DISTANCE: case ABS_WHEEL: axis = evcode_to_axis(e->code); if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) { evdev_log_bug_libinput(device, "Invalid ABS event code %#x\n", e->code); break; } tablet->prev_value[axis] = tablet->current_value[axis]; if (tablet_filter_axis_fuzz(tablet, device, e, axis)) break; tablet->current_value[axis] = e->value; set_bit(tablet->changed_axes, axis); tablet_set_status(tablet, TABLET_AXES_UPDATED); break; /* tool_id is the identifier for the tool we can use in libwacom * to identify it (if we have one anyway) */ case ABS_MISC: tablet->current_tool.id = e->value; break; /* Intuos 3 strip data. Should only happen on the Pad device, not on the Pen device. */ case ABS_RX: case ABS_RY: /* Only on the 4D mouse (Intuos2), obsolete */ case ABS_RZ: /* Only on the 4D mouse (Intuos2), obsolete. The 24HD sends ABS_THROTTLE on the Pad device for the second wheel but we shouldn't get here on kernel >= 3.17. */ case ABS_THROTTLE: default: evdev_log_info(device, "Unhandled ABS event code %#x\n", e->code); break; } } static inline int axis_range_percentage(const struct input_absinfo *a, double percent) { return (a->maximum - a->minimum) * percent/100.0 + a->minimum; } static void tablet_change_area(struct evdev_device *device) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); if (memcmp(&tablet->area.rect, &tablet->area.want_rect, sizeof(tablet->area.rect)) == 0) return; if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) return; tablet->area.rect = tablet->area.want_rect; evdev_log_debug(device, "tablet-area: area is %.2f/%.2f - %.2f/%.2f\n", tablet->area.rect.x1, tablet->area.rect.y1, tablet->area.rect.x2, tablet->area.rect.y2); const struct input_absinfo *absx = device->abs.absinfo_x; const struct input_absinfo *absy = device->abs.absinfo_y; tablet->area.x.minimum = axis_range_percentage(absx, tablet->area.rect.x1 * 100); tablet->area.x.maximum = axis_range_percentage(absx, tablet->area.rect.x2 * 100); tablet->area.y.minimum = axis_range_percentage(absy, tablet->area.rect.y1 * 100); tablet->area.y.maximum = axis_range_percentage(absy, tablet->area.rect.y2 * 100); } static void tablet_apply_rotation(struct evdev_device *device) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); if (tablet->rotation.rotate == tablet->rotation.want_rotate) return; if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) return; tablet->rotation.rotate = tablet->rotation.want_rotate; evdev_log_debug(device, "tablet-rotation: rotation is %s\n", tablet->rotation.rotate ? "on" : "off"); } static void tablet_change_rotation(struct evdev_device *device, enum notify notify) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); struct evdev_device *touch_device = tablet->touch_device; struct evdev_dispatch *dispatch; bool tablet_is_left, touchpad_is_left; tablet_is_left = tablet->device->left_handed.enabled; touchpad_is_left = tablet->rotation.touch_device_left_handed_state; tablet->rotation.want_rotate = tablet_is_left || touchpad_is_left; tablet_apply_rotation(device); if (notify == DO_NOTIFY && touch_device) { bool enable = device->left_handed.want_enabled; dispatch = touch_device->dispatch; if (dispatch->interface->left_handed_toggle) dispatch->interface->left_handed_toggle(dispatch, touch_device, enable); } } static void tablet_change_to_left_handed(struct evdev_device *device) { if (device->left_handed.enabled == device->left_handed.want_enabled) return; device->left_handed.enabled = device->left_handed.want_enabled; tablet_change_rotation(device, DO_NOTIFY); } static void tablet_update_tool(struct tablet_dispatch *tablet, struct evdev_device *device, enum libinput_tablet_tool_type tool, bool enabled) { assert(tool != LIBINPUT_TOOL_NONE); if (enabled) { tablet->current_tool.type = tool; tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) { tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } } static inline double normalize_slider(const struct input_absinfo *absinfo) { return absinfo_normalize(absinfo) * 2 - 1; } static inline double normalize_distance(const struct input_absinfo *absinfo) { return absinfo_normalize(absinfo); } static inline double normalize_pressure(struct libinput_tablet_tool_pressure_threshold *threshold, int abs_value) { /** * Note: the upper threshold takes the offset into account so that * |- 4% -| * min |------X------X-------------------------| max * | | * | + upper threshold / tip trigger * +- offset and lower threshold * * The axis is scaled into the range [lower, max] so that the lower * threshold is 0 pressure. */ struct input_absinfo abs = threshold->abs_pressure; abs.minimum = threshold->threshold.lower; return absinfo_normalize_value(&abs, abs_value); } static inline double adjust_tilt(const struct input_absinfo *absinfo) { double value = absinfo_normalize(absinfo); const int WACOM_MAX_DEGREES = 64; /* If resolution is nonzero, it's in units/radian. But require * a min/max less/greater than zero so we can assume 0 is the * center */ if (absinfo->resolution != 0 && absinfo->maximum > 0 && absinfo->minimum < 0) { value = rad2deg((double)absinfo->value/absinfo->resolution); } else { /* Wacom supports physical [-64, 64] degrees, so map to that by * default. If other tablets have a different physical range or * nonzero physical offsets, they need extra treatment * here. */ /* Map to the (-1, 1) range */ value = (value * 2) - 1; value *= WACOM_MAX_DEGREES; } return value; } static inline int32_t invert_axis(const struct input_absinfo *absinfo) { return absinfo->maximum - (absinfo->value - absinfo->minimum); } static void convert_tilt_to_rotation(struct tablet_dispatch *tablet) { const int offset = 5; double x, y; double angle = 0.0; /* Wacom Intuos 4, 5, Pro mouse calculates rotation from the x/y tilt values. The device has a 175 degree CCW hardware offset but since we use atan2 the effective offset is just 5 degrees. */ x = tablet->axes.tilt.x; y = tablet->axes.tilt.y; /* atan2 is CCW, we want CW -> negate x */ if (x || y) angle = rad2deg(atan2(-x, y)); angle = fmod(360 + angle - offset, 360); tablet->axes.rotation = angle; set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } static double convert_to_degrees(const struct input_absinfo *absinfo, double offset) { /* range is [0, 360[, i.e. range + 1 */ double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo); return fmod(value * 360.0 + offset, 360.0); } static inline double normalize_wheel(struct tablet_dispatch *tablet, int value) { struct evdev_device *device = tablet->device; return value * device->scroll.wheel_click_angle.x; } static bool is_inside_area(struct tablet_dispatch *tablet, const struct device_coords *point, double normalized_margin) { if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 && tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0) return true; assert(normalized_margin > 0.0); assert(normalized_margin <= 1.0); int xmargin = (tablet->area.x.maximum - tablet->area.x.minimum) * normalized_margin; int ymargin = (tablet->area.y.maximum - tablet->area.y.minimum) * normalized_margin; return (point->x >= tablet->area.x.minimum - xmargin && point->x <= tablet->area.x.maximum + xmargin && point->y >= tablet->area.y.minimum - ymargin && point->y <= tablet->area.y.maximum + ymargin); } static void apply_tablet_area(struct tablet_dispatch *tablet, struct evdev_device *device, struct device_coords *point) { if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 && tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0) return; /* The point is somewhere on the tablet in device coordinates, * but we need it relative to the x/y offset. * So clip it first, then offset it to our area min/max. * * Right now we're just clipping, we don't completely * ignore events. What we should do is ignore events outside * altogether and generate prox in/out events when we actually * enter the area. */ point->x = min(point->x, tablet->area.x.maximum); point->y = min(point->y, tablet->area.y.maximum); point->x = max(point->x, tablet->area.x.minimum); point->y = max(point->y, tablet->area.y.minimum); } static inline void tablet_update_xy(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; int value; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X) || !libevdev_has_event_code(device->evdev, EV_ABS, ABS_Y)) return; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) { absinfo = device->abs.absinfo_x; if (tablet->rotation.rotate) value = invert_axis(absinfo); else value = absinfo->value; tablet->axes.point.x = value; absinfo = device->abs.absinfo_y; if (tablet->rotation.rotate) value = invert_axis(absinfo); else value = absinfo->value; tablet->axes.point.y = value; /* calibration and area are currently mutually exclusive so * one of those is a noop */ evdev_transform_absolute(device, &tablet->axes.point); apply_tablet_area(tablet, device, &tablet->axes.point); } } static inline struct normalized_coords tablet_tool_process_delta(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, const struct evdev_device *device, struct tablet_axes *axes, uint64_t time) { const struct normalized_coords zero = { 0.0, 0.0 }; struct device_coords delta = { 0, 0 }; struct device_float_coords accel; /* When tool contact changes, we probably got a cursor jump. Don't try to calculate a delta for that event */ if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY) && !tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) && !tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) && (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y))) { delta.x = axes->point.x - tablet->last_smooth_point.x; delta.y = axes->point.y - tablet->last_smooth_point.y; } if (axes->point.x != tablet->last_smooth_point.x) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X); if (axes->point.y != tablet->last_smooth_point.y) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y); tablet->last_smooth_point = axes->point; accel.x = 1.0 * delta.x; accel.y = 1.0 * delta.y; if (device_float_is_zero(accel)) return zero; return filter_dispatch(device->pointer.filter, &accel, tool, time); } static inline void tablet_update_pressure(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool) { const struct input_absinfo *abs = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); if (!abs) return; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { struct libinput_tablet_tool_pressure_threshold *threshold = tablet_tool_get_threshold(tablet, tool); tablet->axes.pressure = normalize_pressure(threshold, abs->value); } } static inline void tablet_update_distance(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_DISTANCE)) return; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); tablet->axes.distance = normalize_distance(absinfo); } } static inline void tablet_update_slider(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL)) return; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL); tablet->axes.slider = normalize_slider(absinfo); } } static inline void tablet_update_tilt(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_X) || !libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_Y)) return; /* mouse rotation resets tilt to 0 so always fetch both axes if * either has changed */ if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); tablet->axes.tilt.x = adjust_tilt(absinfo); absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); tablet->axes.tilt.y = adjust_tilt(absinfo); if (device->left_handed.enabled) { tablet->axes.tilt.x *= -1; tablet->axes.tilt.y *= -1; } } } static inline void tablet_update_artpen_rotation(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Z)) return; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_Z); /* artpen has 0 with buttons pointing east */ tablet->axes.rotation = convert_to_degrees(absinfo, 90); } } static inline void tablet_update_mouse_rotation(struct tablet_dispatch *tablet, struct evdev_device *device) { if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { convert_tilt_to_rotation(tablet); } } static inline void tablet_update_rotation(struct tablet_dispatch *tablet, struct evdev_device *device) { /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are * already normalized and set if we have the mouse/lens tool */ if (tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) { tablet_update_mouse_rotation(tablet, device); clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); tablet->axes.tilt.x = 0; tablet->axes.tilt.y = 0; /* tilt is already converted to left-handed, so mouse * rotation is converted to left-handed automatically */ } else { tablet_update_artpen_rotation(tablet, device); if (device->left_handed.enabled) { double r = tablet->axes.rotation; tablet->axes.rotation = fmod(180 + r, 360); } } } static inline void tablet_update_wheel(struct tablet_dispatch *tablet, struct evdev_device *device) { int a; a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { /* tablet->axes.wheel_discrete is already set */ tablet->axes.wheel = normalize_wheel(tablet, tablet->axes.wheel_discrete); } else { tablet->axes.wheel = 0; tablet->axes.wheel_discrete = 0; } } static void tablet_smoothen_axes(const struct tablet_dispatch *tablet, struct tablet_axes *axes) { size_t i; size_t count = tablet_history_size(tablet); struct tablet_axes smooth = { 0 }; for (i = 0; i < count; i++) { const struct tablet_axes *a = tablet_history_get(tablet, i); smooth.point.x += a->point.x; smooth.point.y += a->point.y; smooth.tilt.x += a->tilt.x; smooth.tilt.y += a->tilt.y; } axes->point.x = smooth.point.x/count; axes->point.y = smooth.point.y/count; axes->tilt.x = smooth.tilt.x/count; axes->tilt.y = smooth.tilt.y/count; } static bool tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool, struct tablet_axes *axes_out, uint64_t time) { struct tablet_axes axes = {0}; const char tmp[sizeof(tablet->changed_axes)] = {0}; bool rc = false; if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) { axes = tablet->axes; goto out; } tablet_update_xy(tablet, device); tablet_update_pressure(tablet, device, tool); tablet_update_distance(tablet, device); tablet_update_slider(tablet, device); tablet_update_tilt(tablet, device); tablet_update_wheel(tablet, device); /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are * already normalized and set if we have the mouse/lens tool */ tablet_update_rotation(tablet, device); axes.point = tablet->axes.point; axes.pressure = tablet->axes.pressure; axes.distance = tablet->axes.distance; axes.slider = tablet->axes.slider; axes.tilt = tablet->axes.tilt; axes.wheel = tablet->axes.wheel; axes.wheel_discrete = tablet->axes.wheel_discrete; axes.rotation = tablet->axes.rotation; rc = true; out: /* The tool position often jumps to a different spot when contact changes. * If tool contact changes, clear the history to prevent axis smoothing * from trying to average over the spatial discontinuity. */ if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) || tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) { tablet_history_reset(tablet); } tablet_history_push(tablet, &tablet->axes); tablet_smoothen_axes(tablet, &axes); /* The delta relies on the last *smooth* point, so we do it last */ axes.delta = tablet_tool_process_delta(tablet, tool, device, &axes, time); *axes_out = axes; return rc; } static void tablet_update_button(struct tablet_dispatch *tablet, uint32_t evcode, uint32_t enable) { switch (evcode) { case BTN_LEFT: case BTN_RIGHT: case BTN_MIDDLE: case BTN_SIDE: case BTN_EXTRA: case BTN_FORWARD: case BTN_BACK: case BTN_TASK: case BTN_STYLUS: case BTN_STYLUS2: case BTN_STYLUS3: break; default: evdev_log_info(tablet->device, "Unhandled button %s (%#x)\n", libevdev_event_code_get_name(EV_KEY, evcode), evcode); return; } if (enable) { set_bit(tablet->button_state.bits, evcode); tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); } else { clear_bit(tablet->button_state.bits, evcode); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } } static inline enum libinput_tablet_tool_type tablet_evcode_to_tool(int code) { enum libinput_tablet_tool_type type; switch (code) { case BTN_TOOL_PEN: type = LIBINPUT_TABLET_TOOL_TYPE_PEN; break; case BTN_TOOL_RUBBER: type = LIBINPUT_TABLET_TOOL_TYPE_ERASER; break; case BTN_TOOL_BRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_BRUSH; break; case BTN_TOOL_PENCIL: type = LIBINPUT_TABLET_TOOL_TYPE_PENCIL; break; case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH; break; case BTN_TOOL_MOUSE: type = LIBINPUT_TABLET_TOOL_TYPE_MOUSE; break; case BTN_TOOL_LENS: type = LIBINPUT_TABLET_TOOL_TYPE_LENS; break; default: abort(); } return type; } static void tablet_process_key(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, uint64_t time) { enum libinput_tablet_tool_type type; /* ignore kernel key repeat */ if (e->value == 2) return; switch (e->code) { case BTN_TOOL_FINGER: evdev_log_bug_libinput(device, "Invalid tool 'finger' on tablet interface\n"); break; case BTN_TOOL_PEN: case BTN_TOOL_RUBBER: case BTN_TOOL_BRUSH: case BTN_TOOL_PENCIL: case BTN_TOOL_AIRBRUSH: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: type = tablet_evcode_to_tool(e->code); tablet_set_status(tablet, TABLET_TOOL_UPDATED); if (e->value) tablet->tool_state |= bit(type); else tablet->tool_state &= ~bit(type); break; case BTN_TOUCH: if (!bit_is_set(tablet->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { if (e->value) tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT); else tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); } break; default: tablet_update_button(tablet, e->code, e->value); break; } } static void tablet_process_relative(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, uint64_t time) { enum libinput_tablet_tool_axis axis; switch (e->code) { case REL_WHEEL: axis = rel_evcode_to_axis(e->code); if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) { evdev_log_bug_libinput(device, "Invalid ABS event code %#x\n", e->code); break; } set_bit(tablet->changed_axes, axis); tablet->axes.wheel_discrete = -1 * e->value; tablet_set_status(tablet, TABLET_AXES_UPDATED); break; default: evdev_log_info(device, "Unhandled relative axis %s (%#x)\n", libevdev_event_code_get_name(EV_REL, e->code), e->code); return; } } static void tablet_process_misc(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, uint64_t time) { switch (e->code) { case MSC_SERIAL: if (e->value != -1) tablet->current_tool.serial = e->value; break; case MSC_SCAN: break; default: evdev_log_info(device, "Unhandled MSC event code %s (%#x)\n", libevdev_event_code_get_name(EV_MSC, e->code), e->code); break; } } static inline void copy_axis_cap(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_axis axis) { if (bit_is_set(tablet->axis_caps, axis)) set_bit(tool->axis_caps, axis); } static inline void copy_button_cap(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, uint32_t button) { struct libevdev *evdev = tablet->device->evdev; if (libevdev_has_event_code(evdev, EV_KEY, button)) set_bit(tool->buttons, button); } static inline bool tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { bool rc = false; #if HAVE_LIBWACOM WacomDeviceDatabase *db; const WacomStylus *s = NULL; int code; WacomStylusType type; WacomAxisTypeFlags axes; db = tablet_libinput_context(tablet)->libwacom.db; if (!db) return rc; s = libwacom_stylus_get_for_id(db, tool->tool_id); if (!s) return rc; type = libwacom_stylus_get_type(s); if (type == WSTYLUS_PUCK) { for (code = BTN_LEFT; code < BTN_LEFT + libwacom_stylus_get_num_buttons(s); code++) copy_button_cap(tablet, tool, code); } else { if (libwacom_stylus_get_num_buttons(s) >= 3) copy_button_cap(tablet, tool, BTN_STYLUS3); if (libwacom_stylus_get_num_buttons(s) >= 2) copy_button_cap(tablet, tool, BTN_STYLUS2); if (libwacom_stylus_get_num_buttons(s) >= 1) copy_button_cap(tablet, tool, BTN_STYLUS); } if (libwacom_stylus_has_wheel(s)) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); axes = libwacom_stylus_get_axes(s); if (axes & WACOM_AXIS_TYPE_TILT) { /* tilt on the puck is converted to rotation */ if (type == WSTYLUS_PUCK) { set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } else { copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); } } if (axes & WACOM_AXIS_TYPE_ROTATION_Z) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); if (axes & WACOM_AXIS_TYPE_DISTANCE) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); if (axes & WACOM_AXIS_TYPE_SLIDER) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); if (axes & WACOM_AXIS_TYPE_PRESSURE) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); rc = true; #endif return rc; } static void tool_set_bits(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { enum libinput_tablet_tool_type type = tool->type; copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_X); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_Y); if (tool_set_bits_from_libwacom(tablet, tool)) return; /* If we don't have libwacom, we simply copy any axis we have on the tablet onto the tool. Except we know that mice only have rotation anyway. */ switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: case LIBINPUT_TABLET_TOOL_TYPE_ERASER: case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); /* Rotation is special, it can be either ABS_Z or * BTN_TOOL_MOUSE+ABS_TILT_X/Y. Aiptek tablets have * mouse+tilt (and thus rotation), but they do not have * ABS_Z. So let's not copy the axis bit if we don't have * ABS_Z, otherwise we try to get the value from it later on * proximity in and go boom because the absinfo isn't there. */ if (libevdev_has_event_code(tablet->device->evdev, EV_ABS, ABS_Z)) copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: case LIBINPUT_TABLET_TOOL_TYPE_LENS: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); break; default: break; } /* If we don't have libwacom, copy all pen-related buttons from the tablet vs all mouse-related buttons */ switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: case LIBINPUT_TABLET_TOOL_TYPE_ERASER: copy_button_cap(tablet, tool, BTN_STYLUS); copy_button_cap(tablet, tool, BTN_STYLUS2); copy_button_cap(tablet, tool, BTN_STYLUS3); break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: case LIBINPUT_TABLET_TOOL_TYPE_LENS: copy_button_cap(tablet, tool, BTN_LEFT); copy_button_cap(tablet, tool, BTN_MIDDLE); copy_button_cap(tablet, tool, BTN_RIGHT); copy_button_cap(tablet, tool, BTN_SIDE); copy_button_cap(tablet, tool, BTN_EXTRA); break; default: break; } } static bool tablet_get_quirked_pressure_thresholds(struct tablet_dispatch *tablet, int *hi, int *lo) { struct evdev_device *device = tablet->device; struct quirks_context *quirks = evdev_libinput_context(device)->quirks; struct quirks *q = quirks_fetch_for_device(quirks, device->udev_device); struct quirk_range r; bool status = false; /* Note: the quirk term "range" refers to the hi/lo settings, not the * full available range for the pressure axis */ if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) { if (r.lower < r.upper) { *hi = r.lower; *lo = r.upper; status = true; } else { evdev_log_info(device, "Invalid pressure range, using defaults\n"); } } quirks_unref(q); return status; } static void apply_pressure_range_configuration(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, bool force_update) { struct evdev_device *device = tablet->device; if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_PRESSURE) || (!force_update && tool->pressure.range.min == tool->pressure.wanted_range.min && tool->pressure.range.max == tool->pressure.wanted_range.max)) return; double min = tool->pressure.wanted_range.min; double max = tool->pressure.wanted_range.max; struct input_absinfo abs = *libevdev_get_abs_info(device->evdev, ABS_PRESSURE); int minimum = axis_range_percentage(&abs, min * 100.0); int maximum = axis_range_percentage(&abs, max * 100.0); abs.minimum = minimum; abs.maximum = maximum; /* Only use the quirk pressure range if we don't have a custom range */ int hi, lo; if (tool->pressure.wanted_range.min != 0.0 || tool->pressure.wanted_range.max != 1.0 || !tablet_get_quirked_pressure_thresholds(tablet, &hi, &lo)) { /* 5 and 1% of the pressure range */ hi = axis_range_percentage(&abs, 5); lo = axis_range_percentage(&abs, 1); } struct libinput_tablet_tool_pressure_threshold *threshold = tablet_tool_get_threshold(tablet, tool); threshold->abs_pressure = abs; threshold->threshold.upper = hi; threshold->threshold.lower = lo; tool->pressure.range.min = tool->pressure.wanted_range.min; tool->pressure.range.max = tool->pressure.wanted_range.max; /* Disable any heuristics */ if (tool->pressure.has_configured_range) { threshold->has_offset = true; threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE; } } static inline void tool_init_pressure_thresholds(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct libinput_tablet_tool_pressure_threshold *threshold) { struct evdev_device *device = tablet->device; const struct input_absinfo *pressure, *distance; threshold->tablet_id = tablet->tablet_id; threshold->offset = 0; threshold->has_offset = false; threshold->threshold.upper = 1; threshold->threshold.lower = 0; pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); if (!pressure) return; threshold->abs_pressure = *pressure; distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); if (distance) { threshold->offset = pressure->minimum; threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE; } else { threshold->offset = pressure->maximum; threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_PROXIN1; } apply_pressure_range_configuration(tablet, tool, true); } static int pressure_range_is_available(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); } static enum libinput_config_status pressure_range_set(struct libinput_tablet_tool *tool, double min, double max) { if (min < 0.0 || min >= 1.0 || max <= 0.0 || max > 1.0 || max <= min) return LIBINPUT_CONFIG_STATUS_INVALID; tool->pressure.wanted_range.min = min; tool->pressure.wanted_range.max = max; tool->pressure.has_configured_range = true; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static void pressure_range_get(struct libinput_tablet_tool *tool, double *min, double *max) { *min = tool->pressure.wanted_range.min; *max = tool->pressure.wanted_range.max; } static void pressure_range_get_default(struct libinput_tablet_tool *tool, double *min, double *max) { *min = 0.0; *max = 1.0; } static struct libinput_tablet_tool * tablet_new_tool(struct tablet_dispatch *tablet, enum libinput_tablet_tool_type type, uint32_t tool_id, uint32_t serial) { struct libinput_tablet_tool *tool = zalloc(sizeof *tool); *tool = (struct libinput_tablet_tool) { .type = type, .serial = serial, .tool_id = tool_id, .refcount = 1, .pressure.range.min = 0.0, .pressure.range.max = 0.0, /* to trigger configuration */ .pressure.wanted_range.min = 0.0, .pressure.wanted_range.max = 1.0, .config.pressure_range.is_available = pressure_range_is_available, .config.pressure_range.set = pressure_range_set, .config.pressure_range.get = pressure_range_get, .config.pressure_range.get_default = pressure_range_get_default, }; tool_init_pressure_thresholds(tablet, tool, &tool->pressure.thresholds[0]); tool_set_bits(tablet, tool); return tool; } static struct libinput_tablet_tool * tablet_get_tool(struct tablet_dispatch *tablet, enum libinput_tablet_tool_type type, uint32_t tool_id, uint32_t serial) { struct libinput *libinput = tablet_libinput_context(tablet); struct libinput_tablet_tool *tool = NULL, *t; struct list *tool_list; if (serial) { tool_list = &libinput->tool_list; /* Check if we already have the tool in our list of tools */ list_for_each(t, tool_list, link) { if (type == t->type && serial == t->serial) { tool = t; break; } } } /* If we get a tool with a delayed serial number, we already created * a 0-serial number tool for it earlier. Re-use that, even though * it means we can't distinguish this tool from others. * https://bugs.freedesktop.org/show_bug.cgi?id=97526 */ if (!tool) { tool_list = &tablet->tool_list; /* We can't guarantee that tools without serial numbers are * unique, so we keep them local to the tablet that they come * into proximity of instead of storing them in the global tool * list * Same as above, but don't bother checking the serial number */ list_for_each(t, tool_list, link) { if (type == t->type) { tool = t; break; } } /* Didn't find the tool but we have a serial. Switch * tool_list back so we create in the correct list */ if (!tool && serial) tool_list = &libinput->tool_list; } /* If we didn't already have the new_tool in our list of tools, * add it */ if (!tool) { tool = tablet_new_tool(tablet, type, tool_id, serial); list_insert(tool_list, &tool->link); } else { ARRAY_FOR_EACH(tool->pressure.thresholds, t) { if (t->tablet_id == tablet->tablet_id) break; if (t->tablet_id == 0) { tool_init_pressure_thresholds(tablet, tool, t); break; } } } return tool; } static void tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time, struct libinput_tablet_tool *tool, const struct button_state *buttons, enum libinput_button_state state) { struct libinput_device *base = &device->base; size_t i; size_t nbits = 8 * sizeof(buttons->bits); enum libinput_tablet_tool_tip_state tip_state; if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; else tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; for (i = 0; i < nbits; i++) { if (!bit_is_set(buttons->bits, i)) continue; tablet_notify_button(base, time, tool, tip_state, &tablet->axes, i, state, &tablet->area.x, &tablet->area.y); } } static void tablet_notify_buttons(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_button_state state) { struct button_state buttons; if (state == LIBINPUT_BUTTON_STATE_PRESSED) tablet_get_pressed_buttons(tablet, &buttons); else tablet_get_released_buttons(tablet, &buttons); tablet_notify_button_mask(tablet, device, time, tool, &buttons, state); } static void sanitize_pressure_distance(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { bool tool_in_contact; const struct input_absinfo *distance, *pressure; distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE); /* Note: for pressure/distance sanitization we use the real pressure axis, not our configured one */ pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); if (!pressure || !distance) return; bool pressure_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); bool distance_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); if (!pressure_changed && !distance_changed) return; /* Note: this is an arbitrary "in contact" decision rather than "tip * down". We use the lower threshold as minimum pressure value, * anything less than that gets filtered away */ struct libinput_tablet_tool_pressure_threshold* threshold = tablet_tool_get_threshold(tablet, tool); tool_in_contact = (pressure->value > threshold->threshold.lower); /* Keep distance and pressure mutually exclusive */ if (distance && distance->value > distance->minimum && pressure->value > pressure->minimum) { if (tool_in_contact) { clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); tablet->axes.distance = 0; } else { clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); tablet->axes.pressure = 0; } } else if (pressure_changed && !tool_in_contact) { /* Make sure that the last axis value sent to the caller is a 0 */ if (tablet->axes.pressure == 0) clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); else tablet->axes.pressure = 0; } } static inline void sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet) { /* If we have a mouse/lens cursor and the tilt changed, the rotation changed. Mark this, calculate the angle later */ if ((tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) && (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y))) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } static void sanitize_tablet_axes(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { sanitize_pressure_distance(tablet, tool); sanitize_mouse_lens_rotation(tablet); } static void set_pressure_offset(struct libinput_tablet_tool_pressure_threshold *threshold, int offset) { threshold->offset = offset; threshold->has_offset = true; /* Adjust the tresholds accordingly - we use the same gap (4% in * device coordinates) between upper and lower as before which isn't * technically correct (our range shrunk) but it's easy to calculate. */ int gap = threshold->threshold.upper - threshold->threshold.lower; threshold->threshold.lower = offset; threshold->threshold.upper = offset + gap; } static void update_pressure_offset(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool) { const struct input_absinfo *pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); if (!pressure || tool->pressure.has_configured_range || !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) return; /* If we have an event that falls below the current offset, adjust * the offset downwards. A fast contact can start with a * higher-than-needed pressure offset and then we'd be tied into a * high pressure offset for the rest of the session. * * If we are still pending the offset decision, only update the observed * offset value, don't actually set it to have an offset. */ int offset = pressure->value; struct libinput_tablet_tool_pressure_threshold *threshold = tablet_tool_get_threshold(tablet, tool); if (threshold->has_offset) { if (offset < threshold->offset) set_pressure_offset(threshold, offset); } else if (threshold->heuristic_state != PRESSURE_HEURISTIC_STATE_DONE) { threshold->offset = min(offset, threshold->offset); } } static void detect_pressure_offset(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool) { const struct input_absinfo *pressure, *distance; int offset; if (tool->pressure.has_configured_range || !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) return; struct libinput_tablet_tool_pressure_threshold *threshold = tablet_tool_get_threshold(tablet, tool); if (threshold->has_offset) return; pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); if (!pressure) return; offset = pressure->value; if (offset <= pressure->minimum) return; if (distance) { /* If we're closer than 50% of the distance axis, skip pressure * offset detection, too likely to be wrong */ if (distance->value < axis_range_percentage(distance, 50)) return; } else { /* A device without distance will always have some pressure on * contact. Offset detection is delayed for a few proximity ins * in the hope we'll find the minimum value until then. That * offset is updated during motion events so by the time the * deciding prox-in arrives we should know the minimum offset. */ if (offset > pressure->minimum) threshold->offset = min(offset, threshold->offset); switch (threshold->heuristic_state) { case PRESSURE_HEURISTIC_STATE_PROXIN1: case PRESSURE_HEURISTIC_STATE_PROXIN2: threshold->heuristic_state++; return; case PRESSURE_HEURISTIC_STATE_DECIDE: threshold->heuristic_state++; offset = threshold->offset; break; case PRESSURE_HEURISTIC_STATE_DONE: return; } } if (offset <= pressure->minimum) return; if (offset > axis_range_percentage(pressure, 50)) { evdev_log_error(device, "Ignoring pressure offset greater than 50%% detected on tool %s (serial %#x). " "See %s/tablet-support.html\n", tablet_tool_type_to_string(tool->type), tool->serial, HTTP_DOC_LINK); return; } evdev_log_info(device, "Pressure offset detected on tool %s (serial %#x). " "See %s/tablet-support.html\n", tablet_tool_type_to_string(tool->type), tool->serial, HTTP_DOC_LINK); set_pressure_offset(threshold, offset); } static void detect_tool_contact(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool) { const struct input_absinfo *p; int pressure; if (!bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) return; /* if we have pressure, always use that for contact, not BTN_TOUCH */ if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) evdev_log_bug_libinput(device, "Invalid status: entering contact\n"); if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) && !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) evdev_log_bug_libinput(device, "Invalid status: leaving contact\n"); p = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); if (!p) { evdev_log_bug_libinput(device, "Missing pressure axis\n"); return; } pressure = p->value; struct libinput_tablet_tool_pressure_threshold *threshold = tablet_tool_get_threshold(tablet, tool); if (pressure <= threshold->threshold.lower && tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); } else if (pressure >= threshold->threshold.upper && !tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT); } } static void tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { static_assert(sizeof(tablet->changed_axes) == sizeof(tool->axis_caps), "Mismatching array sizes"); memcpy(tablet->changed_axes, tool->axis_caps, sizeof(tablet->changed_axes)); } static void tablet_update_proximity_state(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool) { const struct input_absinfo *distance; int dist_max = tablet->cursor_proximity_threshold; int dist; distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE); if (!distance) return; dist = distance->value; if (dist == 0) return; /* Tool got into permitted range */ if (dist < dist_max && (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) || tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))) { tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_RANGE); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_mark_all_axes_changed(tablet, tool); tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); tablet_force_button_presses(tablet); return; } if (dist < dist_max) return; /* Still out of range/proximity */ if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) || tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) return; /* Tool entered prox but is outside of permitted range */ if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { tablet_set_status(tablet, TABLET_TOOL_OUT_OF_RANGE); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); return; } /* Tool was in prox and is now outside of range. Set leaving * proximity, on the next event it will be OUT_OF_PROXIMITY and thus * caught by the above conditions */ tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } static struct phys_rect tablet_calculate_arbitration_rect(struct tablet_dispatch *tablet) { struct evdev_device *device = tablet->device; struct phys_rect r = {0}; struct phys_coords mm; mm = evdev_device_units_to_mm(device, &tablet->axes.point); /* The rect we disable is 20mm left of the tip, 100mm north of the * tip, and 200x250mm large. * If the stylus is tilted left (tip further right than the eraser * end) assume left-handed mode. * * Obviously if we'd run out of the boundaries, we clip the rect * accordingly. */ if (tablet->axes.tilt.x > 0) { r.x = mm.x - 20; r.w = 200; } else { r.x = mm.x + 20; r.w = 200; r.x -= r.w; } if (r.x < 0) { r.w += r.x; r.x = 0; } r.y = mm.y - 100; r.h = 250; if (r.y < 0) { r.h += r.y; r.y = 0; } return r; } static inline void tablet_update_touch_device_rect(struct tablet_dispatch *tablet, const struct tablet_axes *axes, uint64_t time) { struct evdev_dispatch *dispatch; struct phys_rect rect = {0}; if (tablet->touch_device == NULL || tablet->arbitration != ARBITRATION_IGNORE_RECT) return; rect = tablet_calculate_arbitration_rect(tablet); dispatch = tablet->touch_device->dispatch; if (dispatch->interface->touch_arbitration_update_rect) dispatch->interface->touch_arbitration_update_rect(dispatch, tablet->touch_device, &rect, time); } static inline bool tablet_send_proximity_in(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, struct tablet_axes *axes, uint64_t time) { if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) return false; tablet_notify_proximity(&device->base, time, tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, tablet->changed_axes, axes, &tablet->area.x, &tablet->area.y); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_reset_changed_axes(tablet); axes->delta.x = 0; axes->delta.y = 0; return true; } static inline void tablet_send_proximity_out(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, struct tablet_axes *axes, uint64_t time) { if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY) && !tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) { tablet_notify_proximity(&device->base, time, tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, tablet->changed_axes, axes, &tablet->area.x, &tablet->area.y); } } static inline bool tablet_send_tip(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, struct tablet_axes *axes, uint64_t time) { if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) { tablet_notify_tip(&device->base, time, tool, LIBINPUT_TABLET_TOOL_TIP_DOWN, tablet->changed_axes, axes, &tablet->area.x, &tablet->area.y); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); tablet_reset_changed_axes(tablet); axes->delta.x = 0; axes->delta.y = 0; return true; } if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) { tablet_notify_tip(&device->base, time, tool, LIBINPUT_TABLET_TOOL_TIP_UP, tablet->changed_axes, axes, &tablet->area.x, &tablet->area.y); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); tablet_reset_changed_axes(tablet); axes->delta.x = 0; axes->delta.y = 0; return true; } return false; } static inline void tablet_send_axes(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, struct tablet_axes *axes, uint64_t time) { enum libinput_tablet_tool_tip_state tip_state; if (!tablet_has_status(tablet, TABLET_AXES_UPDATED)) return; if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; else tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; tablet_notify_axis(&device->base, time, tool, tip_state, tablet->changed_axes, axes, &tablet->area.x, &tablet->area.y); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_reset_changed_axes(tablet); axes->delta.x = 0; axes->delta.y = 0; } static inline void tablet_send_buttons(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, uint64_t time) { if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { tablet_notify_buttons(tablet, device, time, tool, LIBINPUT_BUTTON_STATE_RELEASED); tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED); } if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) { tablet_notify_buttons(tablet, device, time, tool, LIBINPUT_BUTTON_STATE_PRESSED); tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } } static void tablet_send_events(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, struct evdev_device *device, uint64_t time) { struct tablet_axes axes = {0}; if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { /* Tool is leaving proximity, we can't rely on the last axis * information (it'll be mostly 0), so we just get the * current state and skip over updating the axes. */ axes = tablet->axes; /* Don't send an axis event, but we may have a tip event * update */ tablet_unset_status(tablet, TABLET_AXES_UPDATED); } else { if (tablet_check_notify_axes(tablet, device, tool, &axes, time)) tablet_update_touch_device_rect(tablet, &axes, time); } assert(tablet->axes.delta.x == 0); assert(tablet->axes.delta.y == 0); tablet_send_proximity_in(tablet, tool, device, &axes, time); if (!tablet_send_tip(tablet, tool, device, &axes, time)) tablet_send_axes(tablet, tool, device, &axes, time); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); tablet_reset_changed_axes(tablet); tablet_send_buttons(tablet, tool, device, time); tablet_send_proximity_out(tablet, tool, device, &axes, time); } /** * Handling for the proximity out workaround. Some tablets only send * BTN_TOOL_PEN on the very first event, then leave it set even when the pen * leaves the detectable range. To libinput this looks like we always have * the pen in proximity. * * To avoid this, we set a timer on BTN_TOOL_PEN in. We expect the tablet to * continuously send events, and while it's doing so we keep updating the * timer. Once we go Xms without an event we assume proximity out and inject * a BTN_TOOL_PEN event into the sequence through the timer func. * * We need to remember that we did that, on the first event after the * timeout we need to emulate a BTN_TOOL_PEN event again to force proximity * in. * * Other tools never send the BTN_TOOL_PEN event. For those tools, we * piggyback along with the proximity out quirks by injecting * the event during the first event frame. */ static inline void tablet_proximity_out_quirk_set_timer(struct tablet_dispatch *tablet, uint64_t time) { if (tablet->quirks.need_to_force_prox_out) libinput_timer_set(&tablet->quirks.prox_out_timer, time + FORCED_PROXOUT_TIMEOUT); } static bool tablet_update_tool_state(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time) { enum libinput_tablet_tool_type type; uint32_t changed; int state; uint32_t doubled_up_new_tool_bit = 0; /* we were already out of proximity but now got a tool update but * our tool state is zero - i.e. we got a valid prox out from the * device. */ if (tablet->quirks.proximity_out_forced && tablet_has_status(tablet, TABLET_TOOL_UPDATED) && !tablet->tool_state) { tablet->quirks.need_to_force_prox_out = false; tablet->quirks.proximity_out_forced = false; } /* We need to emulate a BTN_TOOL_PEN if we get an axis event (i.e. * stylus is def. in proximity) and: * - we forced a proximity out before, or * - on the very first event after init, because if we didn't get a * BTN_TOOL_PEN and the state for the tool was 0, this device will * never send the event. * We don't do this for pure button events because we discard those. * * But: on some devices the proximity out is delayed by the kernel, * so we get it after our forced prox-out has triggered. In that * case we need to just ignore the change. */ if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { if (tablet->quirks.proximity_out_forced) { if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) && !tablet->tool_state) tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN); tablet->quirks.proximity_out_forced = false; } else if (tablet->tool_state == 0 && tablet->current_tool.type == LIBINPUT_TOOL_NONE) { tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN); tablet->quirks.proximity_out_forced = false; } } if (tablet->tool_state == tablet->prev_tool_state) return false; /* Kernel tools are supposed to be mutually exclusive, but we may have * two bits set due to firmware/kernel bugs. * Two cases that have been seen in the wild: * - BTN_TOOL_PEN on proximity in, followed by * BTN_TOOL_RUBBER later, see #259 * -> We force a prox-out of the pen, trigger prox-in for eraser * - BTN_TOOL_RUBBER on proximity in, but BTN_TOOL_PEN when * the tip is down, see #702. * -> We ignore BTN_TOOL_PEN * In both cases the eraser is what we want, so we bias * towards that. */ if (tablet->tool_state & (tablet->tool_state - 1)) { doubled_up_new_tool_bit = tablet->tool_state ^ tablet->prev_tool_state; /* The new tool is the pen. Ignore it */ if (doubled_up_new_tool_bit == bit(LIBINPUT_TABLET_TOOL_TYPE_PEN)) { tablet->tool_state &= ~bit(LIBINPUT_TABLET_TOOL_TYPE_PEN); return false; } /* The new tool is some tool other than pen (usually eraser). * We set the current tool state to zero, thus setting * everything up for a prox out on the tool. Once that is set * up, we change the tool state to be the new one we just got. * When we re-process this function we now get the new tool * as prox in. Importantly, we basically rely on nothing else * happening in the meantime. */ tablet->tool_state = 0; } changed = tablet->tool_state ^ tablet->prev_tool_state; type = ffs(changed) - 1; state = !!(tablet->tool_state & bit(type)); tablet_update_tool(tablet, device, type, state); /* The proximity timeout is only needed for BTN_TOOL_PEN, devices * that require it don't do erasers */ if (type == LIBINPUT_TABLET_TOOL_TYPE_PEN) { if (state) { tablet_proximity_out_quirk_set_timer(tablet, time); } else { /* If we get a BTN_TOOL_PEN 0 when *not* injecting * events it means the tablet will give us the right * events after all and we can disable our * timer-based proximity out. */ if (!tablet->quirks.proximity_out_in_progress) tablet->quirks.need_to_force_prox_out = false; libinput_timer_cancel(&tablet->quirks.prox_out_timer); } } tablet->prev_tool_state = tablet->tool_state; if (doubled_up_new_tool_bit) { tablet->tool_state = doubled_up_new_tool_bit; return true; /* need to re-process */ } return false; } static struct libinput_tablet_tool * tablet_get_current_tool(struct tablet_dispatch *tablet) { if (tablet->current_tool.type == LIBINPUT_TOOL_NONE) return NULL; return tablet_get_tool(tablet, tablet->current_tool.type, tablet->current_tool.id, tablet->current_tool.serial); } static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time) { struct libinput_tablet_tool *tool; bool process_tool_twice; reprocess: process_tool_twice = tablet_update_tool_state(tablet, device, time); tool = tablet_get_current_tool(tablet); if (!tool) return; /* OOM */ if (tool->type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || tool->type == LIBINPUT_TABLET_TOOL_TYPE_LENS) tablet_update_proximity_state(tablet, device, tool); if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) || tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE)) return; if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { /* Release all stylus buttons */ memset(tablet->button_state.bits, 0, sizeof(tablet->button_state.bits)); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); apply_pressure_range_configuration(tablet, tool, false); } else if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) { if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { /* If we get into proximity outside the tablet area, we ignore * that whole sequence of events even if we later move into * the allowed area. This may be bad UX but it's complicated to * implement so let's wait for someone to actually complain * about it. * * We allow a margin of 3% (6mm on a 200mm tablet) to be "within" * the area - there we clip to the area but do not ignore the * sequence. */ const struct device_coords point = { device->abs.absinfo_x->value, device->abs.absinfo_y->value, }; const double margin = 0.03; if (is_inside_area(tablet, &point, margin)) { tablet_mark_all_axes_changed(tablet, tool); update_pressure_offset(tablet, device, tool); detect_pressure_offset(tablet, device, tool); detect_tool_contact(tablet, device, tool); sanitize_tablet_axes(tablet, tool); } else { tablet_set_status(tablet, TABLET_TOOL_OUTSIDE_AREA); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); } } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { update_pressure_offset(tablet, device, tool); detect_tool_contact(tablet, device, tool); sanitize_tablet_axes(tablet, tool); } } if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) tablet_send_events(tablet, tool, device, time); if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_OUTSIDE_AREA); tablet_reset_changed_axes(tablet); tablet_change_to_left_handed(device); tablet_apply_rotation(device); tablet_change_area(device); tablet_history_reset(tablet); } if (process_tool_twice) goto reprocess; } static inline void tablet_set_touch_device_enabled(struct tablet_dispatch *tablet, enum evdev_arbitration_state which, const struct phys_rect *rect, uint64_t time) { struct evdev_device *touch_device = tablet->touch_device; struct evdev_dispatch *dispatch; if (touch_device == NULL) return; tablet->arbitration = which; dispatch = touch_device->dispatch; if (dispatch->interface->touch_arbitration_toggle) dispatch->interface->touch_arbitration_toggle(dispatch, touch_device, which, rect, time); } static inline void tablet_toggle_touch_device(struct tablet_dispatch *tablet, struct evdev_device *tablet_device, uint64_t time) { enum evdev_arbitration_state which; struct phys_rect r = {0}; struct phys_rect *rect = NULL; if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) || tablet_has_status(tablet, TABLET_NONE) || tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY) || tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) { which = ARBITRATION_NOT_ACTIVE; } else if (tablet->axes.tilt.x == 0) { which = ARBITRATION_IGNORE_ALL; } else if (tablet->arbitration != ARBITRATION_IGNORE_RECT) { /* This enables rect-based arbitration, updates are sent * elsewhere */ r = tablet_calculate_arbitration_rect(tablet); rect = &r; which = ARBITRATION_IGNORE_RECT; } else { return; } tablet_set_touch_device_enabled(tablet, which, rect, time); } static inline void tablet_reset_state(struct tablet_dispatch *tablet) { struct button_state zero = {0}; /* Update state */ memcpy(&tablet->prev_button_state, &tablet->button_state, sizeof(tablet->button_state)); tablet_unset_status(tablet, TABLET_TOOL_UPDATED); if (memcmp(&tablet->button_state, &zero, sizeof(zero)) == 0) tablet_unset_status(tablet, TABLET_BUTTONS_DOWN); else tablet_set_status(tablet, TABLET_BUTTONS_DOWN); } static void tablet_proximity_out_quirk_timer_func(uint64_t now, void *data) { struct tablet_dispatch *tablet = data; struct timeval tv = us2tv(now); struct input_event events[2] = { { .input_event_sec = tv.tv_sec, .input_event_usec = tv.tv_usec, .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 }, { .input_event_sec = tv.tv_sec, .input_event_usec = tv.tv_usec, .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, }; if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) || tablet_has_status(tablet, TABLET_BUTTONS_DOWN)) { tablet_proximity_out_quirk_set_timer(tablet, now); return; } if (tablet->quirks.last_event_time > now - FORCED_PROXOUT_TIMEOUT) { tablet_proximity_out_quirk_set_timer(tablet, tablet->quirks.last_event_time); return; } evdev_log_debug(tablet->device, "tablet: forcing proximity after timeout\n"); tablet->quirks.proximity_out_in_progress = true; ARRAY_FOR_EACH(events, e) { tablet->base.interface->process(&tablet->base, tablet->device, e, now); } tablet->quirks.proximity_out_in_progress = false; tablet->quirks.proximity_out_forced = true; } static void tablet_process(struct evdev_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { struct tablet_dispatch *tablet = tablet_dispatch(dispatch); switch (e->type) { case EV_ABS: tablet_process_absolute(tablet, device, e, time); break; case EV_REL: tablet_process_relative(tablet, device, e, time); break; case EV_KEY: tablet_process_key(tablet, device, e, time); break; case EV_MSC: tablet_process_misc(tablet, device, e, time); break; case EV_SYN: tablet_flush(tablet, device, time); tablet_toggle_touch_device(tablet, device, time); tablet_reset_state(tablet); tablet->quirks.last_event_time = time; break; default: evdev_log_error(device, "Unexpected event type %s (%#x)\n", libevdev_event_type_get_name(e->type), e->type); break; } } static void tablet_suspend(struct evdev_dispatch *dispatch, struct evdev_device *device) { struct tablet_dispatch *tablet = tablet_dispatch(dispatch); struct libinput *li = tablet_libinput_context(tablet); uint64_t now = libinput_now(li); tablet_set_touch_device_enabled(tablet, ARBITRATION_NOT_ACTIVE, NULL, now); if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) { tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); tablet_flush(tablet, device, libinput_now(li)); } } static void tablet_destroy(struct evdev_dispatch *dispatch) { struct tablet_dispatch *tablet = tablet_dispatch(dispatch); struct libinput_tablet_tool *tool; struct libinput *li = tablet_libinput_context(tablet); libinput_timer_cancel(&tablet->quirks.prox_out_timer); libinput_timer_destroy(&tablet->quirks.prox_out_timer); list_for_each(tool, &li->tool_list, link) { ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) { if (threshold->tablet_id == tablet->tablet_id) { threshold->tablet_id = 0; break; } } } list_for_each_safe(tool, &tablet->tool_list, link) { libinput_tablet_tool_unref(tool); } libinput_libwacom_unref(li); free(tablet); } static void tablet_setup_touch_arbitration(struct evdev_device *device, struct evdev_device *new_device) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); /* We enable touch arbitration with the first touch screen/external * touchpad we see. This may be wrong in some cases, so we have some * heuristics in case we find a "better" device. */ if (tablet->touch_device != NULL) { struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base); struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base); /* same phsical device? -> better, otherwise keep the one we have */ if (group1 != group2) return; /* We found a better device, let's swap it out */ struct libinput *li = tablet_libinput_context(tablet); tablet_set_touch_device_enabled(tablet, ARBITRATION_NOT_ACTIVE, NULL, libinput_now(li)); evdev_log_debug(device, "touch-arbitration: removing pairing for %s<->%s\n", device->devname, tablet->touch_device->devname); } evdev_log_debug(device, "touch-arbitration: activated for %s<->%s\n", device->devname, new_device->devname); tablet->touch_device = new_device; } static void tablet_setup_rotation(struct evdev_device *device, struct evdev_device *new_device) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base); struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base); if (tablet->rotation.touch_device == NULL && (group1 == group2)) { evdev_log_debug(device, "tablet-rotation: %s will rotate %s\n", device->devname, new_device->devname); tablet->rotation.touch_device = new_device; if (libinput_device_config_left_handed_get(&new_device->base)) { tablet->rotation.touch_device_left_handed_state = true; tablet_change_rotation(device, DO_NOTIFY); } } } static void tablet_device_added(struct evdev_device *device, struct evdev_device *added_device) { bool is_touchscreen, is_ext_touchpad; is_touchscreen = evdev_device_has_capability(added_device, LIBINPUT_DEVICE_CAP_TOUCH); is_ext_touchpad = evdev_device_has_capability(added_device, LIBINPUT_DEVICE_CAP_POINTER) && (added_device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD); if (is_touchscreen || is_ext_touchpad) tablet_setup_touch_arbitration(device, added_device); if (is_ext_touchpad) tablet_setup_rotation(device, added_device); } static void tablet_device_removed(struct evdev_device *device, struct evdev_device *removed_device) { struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); if (tablet->touch_device == removed_device) tablet->touch_device = NULL; if (tablet->rotation.touch_device == removed_device) { tablet->rotation.touch_device = NULL; tablet->rotation.touch_device_left_handed_state = false; tablet_change_rotation(device, DO_NOTIFY); } } static void tablet_check_initial_proximity(struct evdev_device *device, struct evdev_dispatch *dispatch) { struct tablet_dispatch *tablet = tablet_dispatch(dispatch); struct libinput *li = tablet_libinput_context(tablet); int code, state; enum libinput_tablet_tool_type tool; for (tool = LIBINPUT_TABLET_TOOL_TYPE_PEN; tool <= LIBINPUT_TABLET_TOOL_TYPE_MAX; tool++) { code = tablet_tool_to_evcode(tool); /* we only expect one tool to be in proximity at a time */ if (libevdev_fetch_event_value(device->evdev, EV_KEY, code, &state) && state) { tablet->tool_state = bit(tool); tablet->prev_tool_state = bit(tool); break; } } if (!tablet->tool_state) return; tablet_update_tool(tablet, device, tool, state); if (tablet->quirks.need_to_force_prox_out) tablet_proximity_out_quirk_set_timer(tablet, libinput_now(li)); tablet->current_tool.id = libevdev_get_event_value(device->evdev, EV_ABS, ABS_MISC); /* we can't fetch MSC_SERIAL from the kernel, so we set the serial * to 0 for now. On the first real event from the device we get the * serial (if any) and that event will be converted into a proximity * event */ tablet->current_tool.serial = 0; } /* Called when the touchpad toggles to left-handed */ static void tablet_left_handed_toggled(struct evdev_dispatch *dispatch, struct evdev_device *device, bool left_handed_enabled) { struct tablet_dispatch *tablet = tablet_dispatch(dispatch); if (!tablet->rotation.touch_device) return; evdev_log_debug(device, "tablet-rotation: touchpad is %s\n", left_handed_enabled ? "left-handed" : "right-handed"); /* Our left-handed config is independent even though rotation is * locked. So we rotate when either device is left-handed. But it * can only be actually changed when the device is in a neutral * state, hence the want_rotate. */ tablet->rotation.touch_device_left_handed_state = left_handed_enabled; tablet_change_rotation(device, DONT_NOTIFY); } static struct evdev_dispatch_interface tablet_interface = { .process = tablet_process, .suspend = tablet_suspend, .remove = NULL, .destroy = tablet_destroy, .device_added = tablet_device_added, .device_removed = tablet_device_removed, .device_suspended = NULL, .device_resumed = NULL, .post_added = tablet_check_initial_proximity, .touch_arbitration_toggle = NULL, .touch_arbitration_update_rect = NULL, .get_switch_state = NULL, .left_handed_toggle = tablet_left_handed_toggled, }; static void tablet_init_calibration(struct tablet_dispatch *tablet, struct evdev_device *device, bool is_display_tablet) { if (is_display_tablet || libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) evdev_init_calibration(device, &tablet->calibration); } static int tablet_area_has_rectangle(struct libinput_device *device) { return 1; } static enum libinput_config_status tablet_area_set_rectangle(struct libinput_device *device, const struct libinput_config_area_rectangle *rectangle) { struct evdev_device *evdev = evdev_device(device); struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch); if (rectangle->x1 >= rectangle->x2 || rectangle->y1 >= rectangle->y2) return LIBINPUT_CONFIG_STATUS_INVALID; if (rectangle->x1 < 0.0 || rectangle->x2 > 1.0 || rectangle->y1 < 0.0 || rectangle->y2 > 1.0) return LIBINPUT_CONFIG_STATUS_INVALID; tablet->area.want_rect = *rectangle; tablet_change_area(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static struct libinput_config_area_rectangle tablet_area_get_rectangle(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch); return tablet->area.rect; } static struct libinput_config_area_rectangle tablet_area_get_default_rectangle(struct libinput_device *device) { struct libinput_config_area_rectangle rect = { 0.0, 0.0, 1.0, 1.0, }; return rect; } static void tablet_init_area(struct tablet_dispatch *tablet, struct evdev_device *device) { tablet->area.rect = (struct libinput_config_area_rectangle) { 0.0, 0.0, 1.0, 1.0, }; tablet->area.want_rect = tablet->area.rect; tablet->area.x = *device->abs.absinfo_x; tablet->area.y = *device->abs.absinfo_y; if (!libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) { device->base.config.area = &tablet->area.config; tablet->area.config.has_rectangle = tablet_area_has_rectangle; tablet->area.config.set_rectangle = tablet_area_set_rectangle; tablet->area.config.get_rectangle = tablet_area_get_rectangle; tablet->area.config.get_default_rectangle = tablet_area_get_default_rectangle; } } static void tablet_init_proximity_threshold(struct tablet_dispatch *tablet, struct evdev_device *device) { /* This rules out most of the bamboos and other devices, we're * pretty much down to */ if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_MOUSE) && !libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_LENS)) return; /* 42 is the default proximity threshold the xf86-input-wacom driver * uses for Intuos/Cintiq models. Graphire models have a threshold * of 10 but since they haven't been manufactured in ages and the * intersection of users having a graphire, running libinput and * wanting to use the mouse/lens cursor tool is small enough to not * worry about it for now. If we need to, we can introduce a udev * property later. * * Value is in device coordinates. */ tablet->cursor_proximity_threshold = 42; } static uint32_t tablet_accel_config_get_profiles(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static enum libinput_config_status tablet_accel_config_set_profile(struct libinput_device *libinput_device, enum libinput_config_accel_profile profile) { return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } static enum libinput_config_accel_profile tablet_accel_config_get_profile(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static enum libinput_config_accel_profile tablet_accel_config_get_default_profile(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static int tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *x, *y; struct motion_filter *filter; x = device->abs.absinfo_x; y = device->abs.absinfo_y; filter = create_pointer_accelerator_filter_tablet(x->resolution, y->resolution); if (!filter) return -1; evdev_device_init_pointer_acceleration(device, filter); /* we override the profile hooks for accel configuration with hooks * that don't allow selection of profiles */ device->pointer.config.get_profiles = tablet_accel_config_get_profiles; device->pointer.config.set_profile = tablet_accel_config_set_profile; device->pointer.config.get_profile = tablet_accel_config_get_profile; device->pointer.config.get_default_profile = tablet_accel_config_get_default_profile; return 0; } static void tablet_init_left_handed(struct evdev_device *device, WacomDevice *wacom) { bool has_left_handed = true; #if HAVE_LIBWACOM has_left_handed = !wacom || libwacom_is_reversible(wacom); #endif if (has_left_handed) evdev_init_left_handed(device, tablet_change_to_left_handed); } static inline bool tablet_is_display_tablet(WacomDevice *wacom) { #if HAVE_LIBWACOM return !wacom || (libwacom_get_integration_flags(wacom) & (WACOM_DEVICE_INTEGRATED_SYSTEM|WACOM_DEVICE_INTEGRATED_DISPLAY)); #else return true; #endif } static inline bool tablet_is_aes(struct evdev_device *device, WacomDevice *wacom) { #if HAVE_LIBWACOM int vid = evdev_device_get_id_vendor(device); /* Wacom-specific check for whether smoothing is required: * libwacom keeps all the AES pens in a single group, so any device * that supports AES pens will list all AES pens. 0x11 is one of the * lenovo pens so we use that as the flag of whether the tablet * is an AES tablet */ if (wacom && vid == VENDOR_ID_WACOM) { int nstyli; const int *stylus_ids = libwacom_get_supported_styli(wacom, &nstyli); for (int i = 0; i < nstyli; i++) { if (stylus_ids[i] == 0x11) { return true; } } } #endif return false; } static void tablet_init_smoothing(struct evdev_device *device, struct tablet_dispatch *tablet, bool is_aes) { size_t history_size = ARRAY_LENGTH(tablet->history.samples); struct quirks_context *quirks = NULL; struct quirks *q = NULL; bool use_smoothing = true; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); /* By default, always enable smoothing except on AES devices. * AttrTabletSmoothing can override this, if necessary. */ if (!q || !quirks_get_bool(q, QUIRK_ATTR_TABLET_SMOOTHING, &use_smoothing)) use_smoothing = !is_aes; /* Setting the history size to 1 means we never do any actual smoothing. */ if (!use_smoothing) history_size = 1; quirks_unref(q); tablet->history.size = history_size; } static bool tablet_reject_device(struct evdev_device *device) { struct libevdev *evdev = device->evdev; double w, h; bool has_xy, has_pen, has_btn_stylus, has_size; has_xy = libevdev_has_event_code(evdev, EV_ABS, ABS_X) && libevdev_has_event_code(evdev, EV_ABS, ABS_Y); has_pen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN); has_btn_stylus = libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS); has_size = evdev_device_get_size(device, &w, &h) == 0; if (has_xy && (has_pen || has_btn_stylus) && has_size) return false; evdev_log_bug_libinput(device, "missing tablet capabilities:%s%s%s%s. " "Ignoring this device.\n", has_xy ? "" : " xy", has_pen ? "" : " pen", has_btn_stylus ? "" : " btn-stylus", has_size ? "" : " resolution"); return true; } static void tablet_fix_tilt(struct tablet_dispatch *tablet, struct evdev_device *device) { struct libevdev *evdev = device->evdev; if (libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X) != libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_Y)) { libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_X); libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_Y); return; } if (!libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X)) return; /* Wacom has three types of devices: * - symmetrical: [-90, 90], like the ISDv4 524c * - asymmetrical: [-64, 63], like the Cintiq l3HDT * - zero-based: [0, 127], like the Cintiq 12WX * * Note how the latter two cases have an even range and thus do * not have a logical center value. But this is tilt and at * least in the asymmetrical case we assume that hardware zero * means vertical. So we cheat and adjust the range depending * on whether it's odd, then use the center value. * * Since it's always the max that's one too low let's go with that and * fix it if we run into a device where that isn't the case. */ for (unsigned int axis = ABS_TILT_X; axis <= ABS_TILT_Y; axis++) { struct input_absinfo abs = *libevdev_get_abs_info(evdev, axis); /* Don't touch axes reporting radians */ if (abs.resolution != 0) continue; if ((int)absinfo_range(&abs) % 2 == 1) continue; abs.maximum += 1; libevdev_set_abs_info(evdev, axis, &abs); evdev_log_debug(device, "Adjusting %s range to [%d, %d]\n", libevdev_event_code_get_name(EV_ABS, axis), abs.minimum, abs.maximum); } } static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) { static unsigned int tablet_ids = 0; struct libinput *li = evdev_libinput_context(device); struct libevdev *evdev = device->evdev; enum libinput_tablet_tool_axis axis; int rc = -1; WacomDevice *wacom = NULL; #if HAVE_LIBWACOM WacomDeviceDatabase *db = libinput_libwacom_ref(li); if (db) { char event_path[64]; snprintf(event_path, sizeof(event_path), "/dev/input/%s", evdev_device_get_sysname(device)); wacom = libwacom_new_from_path(db, event_path, WFALLBACK_NONE, NULL); if (!wacom) { wacom = libwacom_new_from_usbid(db, evdev_device_get_id_vendor(device), evdev_device_get_id_product(device), NULL); } if (!wacom) { evdev_log_info(device, "device \"%s\" (%04x:%04x) is not known to libwacom\n", evdev_device_get_name(device), evdev_device_get_id_vendor(device), evdev_device_get_id_product(device)); } } #endif tablet->tablet_id = ++tablet_ids; tablet->base.dispatch_type = DISPATCH_TABLET; tablet->base.interface = &tablet_interface; tablet->device = device; tablet->status = TABLET_NONE; tablet->current_tool.type = LIBINPUT_TOOL_NONE; list_init(&tablet->tool_list); if (tablet_reject_device(device)) goto out; bool is_aes = tablet_is_aes(device, wacom); bool is_display_tablet = tablet_is_display_tablet(wacom); if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN)) { libevdev_enable_event_code(evdev, EV_KEY, BTN_TOOL_PEN, NULL); tablet->quirks.proximity_out_forced = true; } /* Our rotation code only works with Wacoms, let's wait until * someone shouts */ if (evdev_device_get_id_vendor(device) != VENDOR_ID_WACOM) { libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_MOUSE); libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_LENS); } tablet_fix_tilt(tablet, device); tablet_init_calibration(tablet, device, is_display_tablet); tablet_init_area(tablet, device); tablet_init_proximity_threshold(tablet, device); rc = tablet_init_accel(tablet, device); if (rc != 0) goto out; evdev_init_sendevents(device, &tablet->base); tablet_init_left_handed(device, wacom); tablet_init_smoothing(device, tablet, is_aes); for (axis = LIBINPUT_TABLET_TOOL_AXIS_X; axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX; axis++) { if (tablet_device_has_axis(tablet, axis)) set_bit(tablet->axis_caps, axis); } tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); /* We always enable the proximity out quirk, but disable it once a device gives us the right event sequence */ tablet->quirks.need_to_force_prox_out = true; libinput_timer_init(&tablet->quirks.prox_out_timer, li, "proxout", tablet_proximity_out_quirk_timer_func, tablet); rc = 0; out: #if HAVE_LIBWACOM if (wacom) libwacom_destroy(wacom); if (db) libinput_libwacom_unref(li); #endif return rc; } struct evdev_dispatch * evdev_tablet_create(struct evdev_device *device) { struct tablet_dispatch *tablet; struct libinput *li = evdev_libinput_context(device); libinput_libwacom_ref(li); /* Stop false positives caused by the forced proximity code */ if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) FORCED_PROXOUT_TIMEOUT = 150 * 1000; /* µs */ tablet = zalloc(sizeof *tablet); if (tablet_init(tablet, device) != 0) { tablet_destroy(&tablet->base); return NULL; } return &tablet->base; } libinput-1.28.1/src/evdev-tablet.h000066400000000000000000000165711477265155700170100ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * Copyright © 2014 Lyude Paul * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef EVDEV_TABLET_H #define EVDEV_TABLET_H #include "evdev.h" #if !HAVE_LIBWACOM typedef void * WacomDevice; #endif #define LIBINPUT_TABLET_TOOL_AXIS_NONE 0 #define LIBINPUT_TOOL_NONE 0 #define LIBINPUT_TABLET_TOOL_TYPE_MAX LIBINPUT_TABLET_TOOL_TYPE_LENS #define TABLET_HISTORY_LENGTH 4 enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = bit(0), TABLET_BUTTONS_PRESSED = bit(1), TABLET_BUTTONS_DOWN = bit(2), TABLET_BUTTONS_RELEASED = bit(3), TABLET_TOOL_UPDATED = bit(4), TABLET_TOOL_IN_CONTACT = bit(5), TABLET_TOOL_LEAVING_PROXIMITY = bit(6), TABLET_TOOL_OUT_OF_PROXIMITY = bit(7), TABLET_TOOL_ENTERING_PROXIMITY = bit(8), TABLET_TOOL_ENTERING_CONTACT = bit(9), TABLET_TOOL_LEAVING_CONTACT = bit(10), TABLET_TOOL_OUT_OF_RANGE = bit(11), TABLET_TOOL_OUTSIDE_AREA = bit(12), }; struct button_state { unsigned char bits[NCHARS(KEY_CNT)]; }; struct tablet_dispatch { struct evdev_dispatch base; struct evdev_device *device; unsigned int tablet_id; /* incremental ID */ unsigned int status; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct tablet_axes axes; /* for assembling the current state */ struct device_coords last_smooth_point; struct { unsigned int index; unsigned int count; struct tablet_axes samples[TABLET_HISTORY_LENGTH]; size_t size; } history; unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; int current_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; int prev_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; /* Only used for tablets that don't report serial numbers */ struct list tool_list; struct button_state button_state; struct button_state prev_button_state; uint32_t tool_state; uint32_t prev_tool_state; struct { enum libinput_tablet_tool_type type; uint32_t id; uint32_t serial; } current_tool; uint32_t cursor_proximity_threshold; struct libinput_device_config_calibration calibration; struct { struct libinput_device_config_area config; struct libinput_config_area_rectangle rect; struct libinput_config_area_rectangle want_rect; struct input_absinfo x; struct input_absinfo y; } area; /* The paired touch device on devices with both pen & touch */ struct evdev_device *touch_device; enum evdev_arbitration_state arbitration; struct { /* The device locked for rotation */ struct evdev_device *touch_device; /* Last known left-handed state of the touchpad */ bool touch_device_left_handed_state; bool rotate; bool want_rotate; } rotation; struct { bool need_to_force_prox_out; struct libinput_timer prox_out_timer; bool proximity_out_forced; uint64_t last_event_time; /* true while injecting BTN_TOOL_PEN events */ bool proximity_out_in_progress; } quirks; }; static inline struct tablet_dispatch* tablet_dispatch(struct evdev_dispatch *dispatch) { evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET); return container_of(dispatch, struct tablet_dispatch, base); } static inline enum libinput_tablet_tool_axis evcode_to_axis(const uint32_t evcode) { enum libinput_tablet_tool_axis axis; switch (evcode) { case ABS_X: axis = LIBINPUT_TABLET_TOOL_AXIS_X; break; case ABS_Y: axis = LIBINPUT_TABLET_TOOL_AXIS_Y; break; case ABS_Z: axis = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; break; case ABS_DISTANCE: axis = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; break; case ABS_PRESSURE: axis = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; break; case ABS_TILT_X: axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; break; case ABS_TILT_Y: axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; break; case ABS_WHEEL: axis = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; break; default: axis = LIBINPUT_TABLET_TOOL_AXIS_NONE; break; } return axis; } static inline enum libinput_tablet_tool_axis rel_evcode_to_axis(const uint32_t evcode) { enum libinput_tablet_tool_axis axis; switch (evcode) { case REL_WHEEL: axis = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; break; default: axis = LIBINPUT_TABLET_TOOL_AXIS_NONE; break; } return axis; } static inline uint32_t axis_to_evcode(const enum libinput_tablet_tool_axis axis) { uint32_t evcode; switch (axis) { case LIBINPUT_TABLET_TOOL_AXIS_X: evcode = ABS_X; break; case LIBINPUT_TABLET_TOOL_AXIS_Y: evcode = ABS_Y; break; case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: evcode = ABS_DISTANCE; break; case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: evcode = ABS_PRESSURE; break; case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: evcode = ABS_TILT_X; break; case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: evcode = ABS_TILT_Y; break; case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: evcode = ABS_Z; break; case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: evcode = ABS_WHEEL; break; case LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR: evcode = ABS_MT_TOUCH_MAJOR; break; case LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR: evcode = ABS_MT_TOUCH_MINOR; break; default: abort(); } return evcode; } static inline int tablet_tool_to_evcode(enum libinput_tablet_tool_type type) { int code; switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break; case LIBINPUT_TABLET_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; default: abort(); } return code; } static inline const char * tablet_tool_type_to_string(enum libinput_tablet_tool_type type) { const char *str; switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: str = "pen"; break; case LIBINPUT_TABLET_TOOL_TYPE_ERASER: str = "eraser"; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: str = "brush"; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: str = "pencil"; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: str = "airbrush"; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: str = "mouse"; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: str = "lens"; break; default: abort(); } return str; } static inline struct libinput * tablet_libinput_context(const struct tablet_dispatch *tablet) { return evdev_libinput_context(tablet->device); } #endif libinput-1.28.1/src/evdev-totem.c000066400000000000000000000556431477265155700166630ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev.h" enum totem_slot_state { SLOT_STATE_NONE, SLOT_STATE_BEGIN, SLOT_STATE_UPDATE, SLOT_STATE_END, }; struct totem_slot { bool dirty; unsigned int index; enum totem_slot_state state; struct libinput_tablet_tool *tool; struct tablet_axes axes; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct device_coords last_point; }; struct totem_dispatch { struct evdev_dispatch base; struct evdev_device *device; int slot; /* current slot */ struct totem_slot *slots; size_t nslots; struct evdev_device *touch_device; /* We only have one button */ bool button_state_now; bool button_state_previous; enum evdev_arbitration_state arbitration_state; }; static inline struct totem_dispatch* totem_dispatch(struct evdev_dispatch *totem) { evdev_verify_dispatch_type(totem, DISPATCH_TOTEM); return container_of(totem, struct totem_dispatch, base); } static inline struct libinput * totem_libinput_context(const struct totem_dispatch *totem) { return evdev_libinput_context(totem->device); } static struct libinput_tablet_tool * totem_new_tool(struct totem_dispatch *totem) { struct libinput *libinput = totem_libinput_context(totem); struct libinput_tablet_tool *tool; tool = zalloc(sizeof *tool); *tool = (struct libinput_tablet_tool) { .type = LIBINPUT_TABLET_TOOL_TYPE_TOTEM, .serial = 0, .tool_id = 0, .refcount = 1, }; ARRAY_FOR_EACH(tool->pressure.thresholds, t) { t->tablet_id = 0; t->offset = 0; t->has_offset = false; t->threshold.lower = 0; t->threshold.upper = 1; } set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_X); set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_Y); set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR); set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR); set_bit(tool->buttons, BTN_0); list_insert(&libinput->tool_list, &tool->link); return tool; } static inline void totem_set_touch_device_enabled(struct totem_dispatch *totem, bool enable_touch_device, uint64_t time) { struct evdev_device *touch_device = totem->touch_device; struct evdev_dispatch *dispatch; struct phys_rect r, *rect = NULL; enum evdev_arbitration_state state = ARBITRATION_NOT_ACTIVE; if (touch_device == NULL) return; /* We just pick the coordinates of the first touch we find. The * totem only does one tool right now despite being nominally an MT * device, so let's not go too hard on ourselves*/ for (size_t i = 0; !enable_touch_device && i < totem->nslots; i++) { struct totem_slot *slot = &totem->slots[i]; struct phys_coords mm; if (slot->state == SLOT_STATE_NONE) continue; /* Totem size is ~70mm. We could calculate the real size but until we need that, hardcoding it is enough */ mm = evdev_device_units_to_mm(totem->device, &slot->axes.point); r.x = mm.x - 30; r.y = mm.y - 30; r.w = 100; r.h = 100; rect = &r; state = ARBITRATION_IGNORE_RECT; break; } dispatch = touch_device->dispatch; if (enable_touch_device) { if (dispatch->interface->touch_arbitration_toggle) dispatch->interface->touch_arbitration_toggle(dispatch, touch_device, state, rect, time); } else { switch (totem->arbitration_state) { case ARBITRATION_IGNORE_ALL: abort(); case ARBITRATION_NOT_ACTIVE: if (dispatch->interface->touch_arbitration_toggle) dispatch->interface->touch_arbitration_toggle(dispatch, touch_device, state, rect, time); break; case ARBITRATION_IGNORE_RECT: if (dispatch->interface->touch_arbitration_update_rect) dispatch->interface->touch_arbitration_update_rect(dispatch, touch_device, rect, time); break; } } totem->arbitration_state = state; } static void totem_process_key(struct totem_dispatch *totem, struct evdev_device *device, struct input_event *e, uint64_t time) { /* ignore kernel key repeat */ if (e->value == 2) return; switch(e->code) { case BTN_0: totem->button_state_now = !!e->value; break; default: evdev_log_info(device, "Unhandled KEY event code %#x\n", e->code); break; } } static void totem_process_abs(struct totem_dispatch *totem, struct evdev_device *device, struct input_event *e, uint64_t time) { struct totem_slot *slot = &totem->slots[totem->slot]; switch(e->code) { case ABS_MT_SLOT: if ((size_t)e->value >= totem->nslots) { evdev_log_bug_libinput(device, "exceeded slot count (%d of max %zd)\n", e->value, totem->nslots); e->value = totem->nslots - 1; } totem->slot = e->value; return; case ABS_MT_TRACKING_ID: /* If the totem is already down on init, we currently ignore it */ if (e->value >= 0) slot->state = SLOT_STATE_BEGIN; else if (slot->state != SLOT_STATE_NONE) slot->state = SLOT_STATE_END; break; case ABS_MT_POSITION_X: set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X); break; case ABS_MT_POSITION_Y: set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y); break; case ABS_MT_TOUCH_MAJOR: set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR); break; case ABS_MT_TOUCH_MINOR: set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR); break; case ABS_MT_ORIENTATION: set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); break; case ABS_MT_TOOL_TYPE: if (e->value != MT_TOOL_DIAL) { evdev_log_info(device, "Unexpected tool type %#x, changing to dial\n", e->code); } break; default: evdev_log_info(device, "Unhandled ABS event code %#x\n", e->code); break; } } static bool totem_slot_fetch_axes(struct totem_dispatch *totem, struct totem_slot *slot, struct libinput_tablet_tool *tool, struct tablet_axes *axes_out, uint64_t time) { struct evdev_device *device = totem->device; const char tmp[sizeof(slot->changed_axes)] = {0}; struct tablet_axes axes = {0}; struct device_float_coords delta; bool rc = false; if (memcmp(tmp, slot->changed_axes, sizeof(tmp)) == 0) { axes = slot->axes; goto out; } if (bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) || bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) { slot->axes.point.x = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_POSITION_X); slot->axes.point.y = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_POSITION_Y); } if (bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { int angle = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_ORIENTATION); /* The kernel gives us ±90 degrees off neutral */ slot->axes.rotation = (360 - angle) % 360; } if (bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR) || bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR)) { int major, minor; unsigned int rmajor, rminor; major = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_TOUCH_MAJOR); minor = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_TOUCH_MINOR); rmajor = libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MAJOR); rminor = libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MINOR); slot->axes.size.major = (double)major/rmajor; slot->axes.size.minor = (double)minor/rminor; } axes.point = slot->axes.point; axes.rotation = slot->axes.rotation; axes.size = slot->axes.size; delta.x = slot->axes.point.x - slot->last_point.x; delta.y = slot->axes.point.y - slot->last_point.y; axes.delta = filter_dispatch(device->pointer.filter, &delta, tool, time); rc = true; out: *axes_out = axes; return rc; } static void totem_slot_mark_all_axes_changed(struct totem_dispatch *totem, struct totem_slot *slot, struct libinput_tablet_tool *tool) { static_assert(sizeof(slot->changed_axes) == sizeof(tool->axis_caps), "Mismatching array sizes"); memcpy(slot->changed_axes, tool->axis_caps, sizeof(slot->changed_axes)); } static inline void totem_slot_reset_changed_axes(struct totem_dispatch *totem, struct totem_slot *slot) { memset(slot->changed_axes, 0, sizeof(slot->changed_axes)); } static inline void slot_axes_initialize(struct totem_dispatch *totem, struct totem_slot *slot) { struct evdev_device *device = totem->device; slot->axes.point.x = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_POSITION_X); slot->axes.point.y = libevdev_get_slot_value(device->evdev, slot->index, ABS_MT_POSITION_Y); slot->last_point.x = slot->axes.point.x; slot->last_point.y = slot->axes.point.y; } static enum totem_slot_state totem_handle_slot_state(struct totem_dispatch *totem, struct totem_slot *slot, uint64_t time) { struct evdev_device *device = totem->device; struct tablet_axes axes; enum libinput_tablet_tool_tip_state tip_state; bool updated; switch (slot->state) { case SLOT_STATE_BEGIN: if (!slot->tool) slot->tool = totem_new_tool(totem); slot_axes_initialize(totem, slot); totem_slot_mark_all_axes_changed(totem, slot, slot->tool); break; case SLOT_STATE_UPDATE: case SLOT_STATE_END: assert(slot->tool); break; case SLOT_STATE_NONE: return SLOT_STATE_NONE; } tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; updated = totem_slot_fetch_axes(totem, slot, slot->tool, &axes, time); switch (slot->state) { case SLOT_STATE_BEGIN: tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; tablet_notify_proximity(&device->base, time, slot->tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); totem_slot_reset_changed_axes(totem, slot); tablet_notify_tip(&device->base, time, slot->tool, tip_state, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); slot->state = SLOT_STATE_UPDATE; break; case SLOT_STATE_UPDATE: tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; if (updated) { tablet_notify_axis(&device->base, time, slot->tool, tip_state, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); } break; case SLOT_STATE_END: /* prox out is handled after button events */ break; case SLOT_STATE_NONE: abort(); break; } /* We only have one button but possibly multiple totems. It's not * clear how the firmware will work, so for now we just handle the * button state in the first slot. * * Due to the design of the totem we're also less fancy about * button handling than the tablet code. Worst case, you might get * tip up before button up but meh. */ if (totem->button_state_now != totem->button_state_previous) { enum libinput_button_state btn_state; if (totem->button_state_now) btn_state = LIBINPUT_BUTTON_STATE_PRESSED; else btn_state = LIBINPUT_BUTTON_STATE_RELEASED; tablet_notify_button(&device->base, time, slot->tool, tip_state, &axes, BTN_0, btn_state, device->abs.absinfo_x, device->abs.absinfo_y); totem->button_state_previous = totem->button_state_now; } switch(slot->state) { case SLOT_STATE_BEGIN: case SLOT_STATE_UPDATE: break; case SLOT_STATE_END: tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; tablet_notify_tip(&device->base, time, slot->tool, tip_state, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); totem_slot_reset_changed_axes(totem, slot); tablet_notify_proximity(&device->base, time, slot->tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); slot->state = SLOT_STATE_NONE; break; case SLOT_STATE_NONE: abort(); break; } slot->last_point = slot->axes.point; totem_slot_reset_changed_axes(totem, slot); return slot->state; } static enum totem_slot_state totem_handle_state(struct totem_dispatch *totem, uint64_t time) { enum totem_slot_state global_state = SLOT_STATE_NONE; for (size_t i = 0; i < totem->nslots; i++) { enum totem_slot_state s; s = totem_handle_slot_state(totem, &totem->slots[i], time); /* If one slot is active, the totem is active */ if (s != SLOT_STATE_NONE) global_state = SLOT_STATE_UPDATE; } return global_state; } static void totem_interface_process(struct evdev_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { struct totem_dispatch *totem = totem_dispatch(dispatch); enum totem_slot_state global_state; bool enable_touch; switch(e->type) { case EV_ABS: totem_process_abs(totem, device, e, time); break; case EV_KEY: totem_process_key(totem, device, e, time); break; case EV_MSC: /* timestamp, ignore */ break; case EV_SYN: global_state = totem_handle_state(totem, time); enable_touch = (global_state == SLOT_STATE_NONE); totem_set_touch_device_enabled(totem, enable_touch, time); break; default: evdev_log_error(device, "Unexpected event type %s (%#x)\n", libevdev_event_type_get_name(e->type), e->type); break; } } static void totem_interface_suspend(struct evdev_dispatch *dispatch, struct evdev_device *device) { struct totem_dispatch *totem = totem_dispatch(dispatch); uint64_t now = libinput_now(evdev_libinput_context(device)); for (size_t i = 0; i < totem->nslots; i++) { struct totem_slot *slot = &totem->slots[i]; struct tablet_axes axes; enum libinput_tablet_tool_tip_state tip_state; /* If we never initialized a tool, we can skip everything */ if (!slot->tool) continue; totem_slot_fetch_axes(totem, slot, slot->tool, &axes, now); totem_slot_reset_changed_axes(totem, slot); if (slot->state == SLOT_STATE_NONE) tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; else tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; if (totem->button_state_now) { tablet_notify_button(&device->base, now, slot->tool, tip_state, &axes, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED, device->abs.absinfo_x, device->abs.absinfo_y); totem->button_state_now = false; totem->button_state_previous = false; } if (slot->state != SLOT_STATE_NONE) { tablet_notify_tip(&device->base, now, slot->tool, LIBINPUT_TABLET_TOOL_TIP_UP, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); } tablet_notify_proximity(&device->base, now, slot->tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); } totem_set_touch_device_enabled(totem, true, now); } static void totem_interface_destroy(struct evdev_dispatch *dispatch) { struct totem_dispatch *totem = totem_dispatch(dispatch); free(totem->slots); free(totem); } static void totem_interface_device_added(struct evdev_device *device, struct evdev_device *added_device) { struct totem_dispatch *totem = totem_dispatch(device->dispatch); struct libinput_device_group *g1, *g2; if ((evdev_device_get_id_vendor(added_device) != evdev_device_get_id_vendor(device)) || (evdev_device_get_id_product(added_device) != evdev_device_get_id_product(device))) return; /* virtual devices don't have device groups, so check for that libinput replay */ g1 = libinput_device_get_device_group(&device->base); g2 = libinput_device_get_device_group(&added_device->base); if (g1 && g2 && g1->identifier != g2->identifier) return; if (totem->touch_device != NULL) { evdev_log_bug_libinput(device, "already has a paired touch device, ignoring (%s)\n", added_device->devname); return; } totem->touch_device = added_device; evdev_log_info(device, "%s: is the totem touch device\n", added_device->devname); } static void totem_interface_device_removed(struct evdev_device *device, struct evdev_device *removed_device) { struct totem_dispatch *totem = totem_dispatch(device->dispatch); if (totem->touch_device != removed_device) return; totem_set_touch_device_enabled(totem, true, libinput_now(evdev_libinput_context(device))); totem->touch_device = NULL; } static void totem_interface_initial_proximity(struct evdev_device *device, struct evdev_dispatch *dispatch) { struct totem_dispatch *totem = totem_dispatch(dispatch); uint64_t now = libinput_now(evdev_libinput_context(device)); bool enable_touch = true; for (size_t i = 0; i < totem->nslots; i++) { struct totem_slot *slot = &totem->slots[i]; struct tablet_axes axes; int tracking_id; tracking_id = libevdev_get_slot_value(device->evdev, i, ABS_MT_TRACKING_ID); if (tracking_id == -1) continue; slot->tool = totem_new_tool(totem); slot_axes_initialize(totem, slot); totem_slot_mark_all_axes_changed(totem, slot, slot->tool); totem_slot_fetch_axes(totem, slot, slot->tool, &axes, now); tablet_notify_proximity(&device->base, now, slot->tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); totem_slot_reset_changed_axes(totem, slot); tablet_notify_tip(&device->base, now, slot->tool, LIBINPUT_TABLET_TOOL_TIP_DOWN, slot->changed_axes, &axes, device->abs.absinfo_x, device->abs.absinfo_y); slot->state = SLOT_STATE_UPDATE; enable_touch = false; } totem_set_touch_device_enabled(totem, enable_touch, now); } static struct evdev_dispatch_interface totem_interface = { .process = totem_interface_process, .suspend = totem_interface_suspend, .remove = NULL, .destroy = totem_interface_destroy, .device_added = totem_interface_device_added, .device_removed = totem_interface_device_removed, .device_suspended = totem_interface_device_removed, /* treat as remove */ .device_resumed = totem_interface_device_added, /* treat as add */ .post_added = totem_interface_initial_proximity, .touch_arbitration_toggle = NULL, .touch_arbitration_update_rect = NULL, .get_switch_state = NULL, }; static bool totem_reject_device(struct evdev_device *device) { struct libevdev *evdev = device->evdev; bool has_xy, has_slot, has_tool_dial, has_size, has_touch_size; double w, h; has_xy = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) && libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y); has_slot = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT); has_tool_dial = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOOL_TYPE) && libevdev_get_abs_maximum(evdev, ABS_MT_TOOL_TYPE) >= MT_TOOL_DIAL; has_size = evdev_device_get_size(device, &w, &h) == 0; has_touch_size = libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MAJOR) > 0 || libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MINOR) > 0; if (has_xy && has_slot && has_tool_dial && has_size && has_touch_size) return false; evdev_log_bug_libinput(device, "missing totem capabilities:%s%s%s%s%s. " "Ignoring this device.\n", has_xy ? "" : " xy", has_slot ? "" : " slot", has_tool_dial ? "" : " dial", has_size ? "" : " resolutions", has_touch_size ? "" : " touch-size"); return true; } static uint32_t totem_accel_config_get_profiles(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static enum libinput_config_status totem_accel_config_set_profile(struct libinput_device *libinput_device, enum libinput_config_accel_profile profile) { return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } static enum libinput_config_accel_profile totem_accel_config_get_profile(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static enum libinput_config_accel_profile totem_accel_config_get_default_profile(struct libinput_device *libinput_device) { return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; } static int totem_init_accel(struct totem_dispatch *totem, struct evdev_device *device) { const struct input_absinfo *x, *y; struct motion_filter *filter; x = device->abs.absinfo_x; y = device->abs.absinfo_y; /* same filter as the tablet */ filter = create_pointer_accelerator_filter_tablet(x->resolution, y->resolution); if (!filter) return -1; evdev_device_init_pointer_acceleration(device, filter); /* we override the profile hooks for accel configuration with hooks * that don't allow selection of profiles */ device->pointer.config.get_profiles = totem_accel_config_get_profiles; device->pointer.config.set_profile = totem_accel_config_set_profile; device->pointer.config.get_profile = totem_accel_config_get_profile; device->pointer.config.get_default_profile = totem_accel_config_get_default_profile; return 0; } struct evdev_dispatch * evdev_totem_create(struct evdev_device *device) { struct totem_dispatch *totem; struct totem_slot *slots; int num_slots; if (totem_reject_device(device)) return NULL; totem = zalloc(sizeof *totem); totem->device = device; totem->base.dispatch_type = DISPATCH_TOTEM; totem->base.interface = &totem_interface; num_slots = libevdev_get_num_slots(device->evdev); if (num_slots <= 0) goto error; totem->slot = libevdev_get_current_slot(device->evdev); slots = zalloc(num_slots * sizeof(*totem->slots)); for (int slot = 0; slot < num_slots; ++slot) { slots[slot].index = slot; } totem->slots = slots; totem->nslots = num_slots; evdev_init_sendevents(device, &totem->base); totem_init_accel(totem, device); return &totem->base; error: totem_interface_destroy(&totem->base); return NULL; } libinput-1.28.1/src/evdev-wheel.c000066400000000000000000000312241477265155700166240ustar00rootroot00000000000000/* * Copyright © 2010 Intel Corporation * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2017 Red Hat, Inc. * Copyright © 2017 James Ye * Copyright © 2021 José Expósito * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "evdev-fallback.h" #include "util-input-event.h" #define ACC_V120_THRESHOLD 60 #define WHEEL_SCROLL_TIMEOUT ms2us(500) enum wheel_event { WHEEL_EVENT_SCROLL_ACCUMULATED, WHEEL_EVENT_SCROLL, WHEEL_EVENT_SCROLL_TIMEOUT, WHEEL_EVENT_SCROLL_DIR_CHANGED, }; static inline const char * wheel_state_to_str(enum wheel_state state) { switch(state) { CASE_RETURN_STRING(WHEEL_STATE_NONE); CASE_RETURN_STRING(WHEEL_STATE_ACCUMULATING_SCROLL); CASE_RETURN_STRING(WHEEL_STATE_SCROLLING); } return NULL; } static inline const char* wheel_event_to_str(enum wheel_event event) { switch(event) { CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_ACCUMULATED); CASE_RETURN_STRING(WHEEL_EVENT_SCROLL); CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_TIMEOUT); CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_DIR_CHANGED); } return NULL; } static inline void log_wheel_bug(struct fallback_dispatch *dispatch, enum wheel_event event) { evdev_log_bug_libinput(dispatch->device, "invalid wheel event %s in state %s\n", wheel_event_to_str(event), wheel_state_to_str(dispatch->wheel.state)); } static inline void wheel_set_scroll_timer(struct fallback_dispatch *dispatch, uint64_t time) { libinput_timer_set(&dispatch->wheel.scroll_timer, time + WHEEL_SCROLL_TIMEOUT); } static inline void wheel_cancel_scroll_timer(struct fallback_dispatch *dispatch) { libinput_timer_cancel(&dispatch->wheel.scroll_timer); } static void wheel_handle_event_on_state_none(struct fallback_dispatch *dispatch, enum wheel_event event, uint64_t time) { switch (event) { case WHEEL_EVENT_SCROLL: dispatch->wheel.state = WHEEL_STATE_ACCUMULATING_SCROLL; break; case WHEEL_EVENT_SCROLL_DIR_CHANGED: break; case WHEEL_EVENT_SCROLL_ACCUMULATED: case WHEEL_EVENT_SCROLL_TIMEOUT: log_wheel_bug(dispatch, event); break; } } static void wheel_handle_event_on_state_accumulating_scroll(struct fallback_dispatch *dispatch, enum wheel_event event, uint64_t time) { switch (event) { case WHEEL_EVENT_SCROLL_ACCUMULATED: dispatch->wheel.state = WHEEL_STATE_SCROLLING; wheel_set_scroll_timer(dispatch, time); break; case WHEEL_EVENT_SCROLL: /* Ignore scroll while accumulating deltas */ break; case WHEEL_EVENT_SCROLL_DIR_CHANGED: dispatch->wheel.state = WHEEL_STATE_NONE; break; case WHEEL_EVENT_SCROLL_TIMEOUT: log_wheel_bug(dispatch, event); break; } } static void wheel_handle_event_on_state_scrolling(struct fallback_dispatch *dispatch, enum wheel_event event, uint64_t time) { switch (event) { case WHEEL_EVENT_SCROLL: wheel_cancel_scroll_timer(dispatch); wheel_set_scroll_timer(dispatch, time); break; case WHEEL_EVENT_SCROLL_TIMEOUT: dispatch->wheel.state = WHEEL_STATE_NONE; break; case WHEEL_EVENT_SCROLL_DIR_CHANGED: wheel_cancel_scroll_timer(dispatch); dispatch->wheel.state = WHEEL_STATE_NONE; break; case WHEEL_EVENT_SCROLL_ACCUMULATED: log_wheel_bug(dispatch, event); break; } } static void wheel_handle_event(struct fallback_dispatch *dispatch, enum wheel_event event, uint64_t time) { enum wheel_state oldstate = dispatch->wheel.state; switch (oldstate) { case WHEEL_STATE_NONE: wheel_handle_event_on_state_none(dispatch, event, time); break; case WHEEL_STATE_ACCUMULATING_SCROLL: wheel_handle_event_on_state_accumulating_scroll(dispatch, event, time); break; case WHEEL_STATE_SCROLLING: wheel_handle_event_on_state_scrolling(dispatch, event, time); break; } if (oldstate != dispatch->wheel.state) { evdev_log_debug(dispatch->device, "wheel state %s → %s → %s\n", wheel_state_to_str(oldstate), wheel_event_to_str(event), wheel_state_to_str(dispatch->wheel.state)); } } static void wheel_flush_scroll(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { struct normalized_coords wheel_degrees = { 0.0, 0.0 }; struct discrete_coords discrete = { 0.0, 0.0 }; struct wheel_v120 v120 = { 0.0, 0.0 }; /* This mouse has a trackstick instead of a mouse wheel and sends * trackstick data via REL_WHEEL. Normalize it like normal x/y coordinates. */ if (device->model_flags & EVDEV_MODEL_LENOVO_SCROLLPOINT) { const struct device_float_coords raw = { .x = dispatch->wheel.lo_res.x, .y = dispatch->wheel.lo_res.y * -1, }; const struct normalized_coords normalized = filter_dispatch_scroll(device->pointer.filter, &raw, device, time); evdev_post_scroll(device, time, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, &normalized); dispatch->wheel.hi_res.x = 0; dispatch->wheel.hi_res.y = 0; dispatch->wheel.lo_res.x = 0; dispatch->wheel.lo_res.y = 0; return; } if (dispatch->wheel.hi_res.y != 0) { int value = dispatch->wheel.hi_res.y; v120.y = -1 * value; wheel_degrees.y = -1 * value/120.0 * device->scroll.wheel_click_angle.y; evdev_notify_axis_wheel( device, time, bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), &wheel_degrees, &v120); dispatch->wheel.hi_res.y = 0; } if (dispatch->wheel.lo_res.y != 0) { int value = dispatch->wheel.lo_res.y; wheel_degrees.y = -1 * value * device->scroll.wheel_click_angle.y; discrete.y = -1 * value; evdev_notify_axis_legacy_wheel( device, time, bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), &wheel_degrees, &discrete); dispatch->wheel.lo_res.y = 0; } if (dispatch->wheel.hi_res.x != 0) { int value = dispatch->wheel.hi_res.x; v120.x = value; wheel_degrees.x = value/120.0 * device->scroll.wheel_click_angle.x; evdev_notify_axis_wheel( device, time, bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL), &wheel_degrees, &v120); dispatch->wheel.hi_res.x = 0; } if (dispatch->wheel.lo_res.x != 0) { int value = dispatch->wheel.lo_res.x; wheel_degrees.x = value * device->scroll.wheel_click_angle.x; discrete.x = value; evdev_notify_axis_legacy_wheel( device, time, bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL), &wheel_degrees, &discrete); dispatch->wheel.lo_res.x = 0; } } static void wheel_handle_state_none(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { } static void wheel_handle_state_accumulating_scroll(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { if (abs(dispatch->wheel.hi_res.x) >= ACC_V120_THRESHOLD || abs(dispatch->wheel.hi_res.y) >= ACC_V120_THRESHOLD) { wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL_ACCUMULATED, time); wheel_flush_scroll(dispatch, device, time); } } static void wheel_handle_state_scrolling(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { wheel_flush_scroll(dispatch, device, time); } static void wheel_handle_direction_change(struct fallback_dispatch *dispatch, struct input_event *e, uint64_t time) { enum wheel_direction new_dir = WHEEL_DIR_UNKNOW; switch (e->code) { case REL_WHEEL_HI_RES: new_dir = (e->value > 0) ? WHEEL_DIR_VPOS : WHEEL_DIR_VNEG; break; case REL_HWHEEL_HI_RES: new_dir = (e->value > 0) ? WHEEL_DIR_HPOS : WHEEL_DIR_HNEG; break; } if (new_dir != WHEEL_DIR_UNKNOW && new_dir != dispatch->wheel.dir) { dispatch->wheel.dir = new_dir; wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL_DIR_CHANGED, time); } } static void fallback_rotate_wheel(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e) { /* Special case: if we're upside down (-ish), * swap the direction of the wheels so that user-down * means scroll down. This isn't done for any other angle * since it's not clear what the heuristics should be.*/ if (dispatch->rotation.angle >= 160.0 && dispatch->rotation.angle <= 220.0) { e->value *= -1; } } void fallback_wheel_process_relative(struct fallback_dispatch *dispatch, struct evdev_device *device, struct input_event *e, uint64_t time) { switch (e->code) { case REL_WHEEL: fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.lo_res.y += e->value; if (dispatch->wheel.emulate_hi_res_wheel) dispatch->wheel.hi_res.y += e->value * 120; dispatch->pending_event |= EVDEV_WHEEL; wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_HWHEEL: fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.lo_res.x += e->value; if (dispatch->wheel.emulate_hi_res_wheel) dispatch->wheel.hi_res.x += e->value * 120; dispatch->pending_event |= EVDEV_WHEEL; wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_WHEEL_HI_RES: fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.hi_res.y += e->value; dispatch->wheel.hi_res_event_received = true; dispatch->pending_event |= EVDEV_WHEEL; wheel_handle_direction_change(dispatch, e, time); wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_HWHEEL_HI_RES: fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.hi_res.x += e->value; dispatch->wheel.hi_res_event_received = true; dispatch->pending_event |= EVDEV_WHEEL; wheel_handle_direction_change(dispatch, e, time); wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; } } void fallback_wheel_handle_state(struct fallback_dispatch *dispatch, struct evdev_device *device, uint64_t time) { if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) return; if (!dispatch->wheel.emulate_hi_res_wheel && !dispatch->wheel.hi_res_event_received && (dispatch->wheel.lo_res.x != 0 || dispatch->wheel.lo_res.y != 0)) { evdev_log_bug_kernel(device, "device supports high-resolution scroll but only low-resolution events have been received.\n" "See %s/incorrectly-enabled-hires.html for details\n", HTTP_DOC_LINK); dispatch->wheel.emulate_hi_res_wheel = true; dispatch->wheel.hi_res.x = dispatch->wheel.lo_res.x * 120; dispatch->wheel.hi_res.y = dispatch->wheel.lo_res.y * 120; } switch (dispatch->wheel.state) { case WHEEL_STATE_NONE: wheel_handle_state_none(dispatch, device, time); break; case WHEEL_STATE_ACCUMULATING_SCROLL: wheel_handle_state_accumulating_scroll(dispatch, device, time); break; case WHEEL_STATE_SCROLLING: wheel_handle_state_scrolling(dispatch, device, time); break; } } static void wheel_init_scroll_timer(uint64_t now, void *data) { struct evdev_device *device = data; struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch); wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL_TIMEOUT, now); } void fallback_init_wheel(struct fallback_dispatch *dispatch, struct evdev_device *device) { char timer_name[64]; dispatch->wheel.state = WHEEL_STATE_NONE; dispatch->wheel.dir = WHEEL_DIR_UNKNOW; /* On kernel < 5.0 we need to emulate high-resolution wheel scroll events */ if ((libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL) && !libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL_HI_RES)) || (libevdev_has_event_code(device->evdev, EV_REL, REL_HWHEEL) && !libevdev_has_event_code(device->evdev, EV_REL, REL_HWHEEL_HI_RES))) dispatch->wheel.emulate_hi_res_wheel = true; snprintf(timer_name, sizeof(timer_name), "%s wheel scroll", evdev_device_get_sysname(device)); libinput_timer_init(&dispatch->wheel.scroll_timer, evdev_libinput_context(device), timer_name, wheel_init_scroll_timer, device); } libinput-1.28.1/src/evdev.c000066400000000000000000002504001477265155700155210ustar00rootroot00000000000000/* * Copyright © 2010 Intel Corporation * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2017 Red Hat, Inc. * Copyright © 2017 James Ye * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include "linux/input.h" #include #include #include #include #include #include "libinput.h" #include "evdev.h" #include "filter.h" #include "libinput-private.h" #include "quirks.h" #include "util-input-event.h" #if HAVE_LIBWACOM #include #endif #define DEFAULT_WHEEL_CLICK_ANGLE 15 #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200) enum evdev_device_udev_tags { EVDEV_UDEV_TAG_INPUT = bit(0), EVDEV_UDEV_TAG_KEYBOARD = bit(1), EVDEV_UDEV_TAG_MOUSE = bit(2), EVDEV_UDEV_TAG_TOUCHPAD = bit(3), EVDEV_UDEV_TAG_TOUCHSCREEN = bit(4), EVDEV_UDEV_TAG_TABLET = bit(5), EVDEV_UDEV_TAG_JOYSTICK = bit(6), EVDEV_UDEV_TAG_ACCELEROMETER = bit(7), EVDEV_UDEV_TAG_TABLET_PAD = bit(8), EVDEV_UDEV_TAG_POINTINGSTICK = bit(9), EVDEV_UDEV_TAG_TRACKBALL = bit(10), EVDEV_UDEV_TAG_SWITCH = bit(11), }; struct evdev_udev_tag_match { const char *name; enum evdev_device_udev_tags tag; }; static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = { {"ID_INPUT", EVDEV_UDEV_TAG_INPUT}, {"ID_INPUT_KEYBOARD", EVDEV_UDEV_TAG_KEYBOARD}, {"ID_INPUT_KEY", EVDEV_UDEV_TAG_KEYBOARD}, {"ID_INPUT_MOUSE", EVDEV_UDEV_TAG_MOUSE}, {"ID_INPUT_TOUCHPAD", EVDEV_UDEV_TAG_TOUCHPAD}, {"ID_INPUT_TOUCHSCREEN", EVDEV_UDEV_TAG_TOUCHSCREEN}, {"ID_INPUT_TABLET", EVDEV_UDEV_TAG_TABLET}, {"ID_INPUT_TABLET_PAD", EVDEV_UDEV_TAG_TABLET_PAD}, {"ID_INPUT_JOYSTICK", EVDEV_UDEV_TAG_JOYSTICK}, {"ID_INPUT_ACCELEROMETER", EVDEV_UDEV_TAG_ACCELEROMETER}, {"ID_INPUT_POINTINGSTICK", EVDEV_UDEV_TAG_POINTINGSTICK}, {"ID_INPUT_TRACKBALL", EVDEV_UDEV_TAG_TRACKBALL}, {"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH}, }; static const unsigned int well_known_keyboard_keys[] = { KEY_LEFTCTRL, KEY_CAPSLOCK, KEY_NUMLOCK, KEY_INSERT, KEY_MUTE, KEY_CALC, KEY_FILE, KEY_MAIL, KEY_PLAYPAUSE, KEY_BRIGHTNESSDOWN, }; static inline bool parse_udev_flag(struct evdev_device *device, struct udev_device *udev_device, const char *property) { const char *val; bool b; val = udev_device_get_property_value(udev_device, property); if (!val) return false; if (!parse_boolean_property(val, &b)) { evdev_log_error(device, "property %s has invalid value '%s'\n", property, val); return false; } return b; } int evdev_update_key_down_count(struct evdev_device *device, int code, int pressed) { int key_count = 0; assert(code >= 0 && code < KEY_CNT); if (pressed) { key_count = ++device->key_count[code]; } else { if (device->key_count[code] > 0) { key_count = --device->key_count[code]; } else { evdev_log_bug_libinput(device, "releasing key %s with count %d\n", libevdev_event_code_get_name(EV_KEY, code), device->key_count[code]); } } if (key_count > 32) { evdev_log_bug_libinput(device, "key count for %s reached abnormal values\n", libevdev_event_code_get_name(EV_KEY, code)); } return key_count; } enum libinput_switch_state evdev_device_switch_get_state(struct evdev_device *device, enum libinput_switch sw) { struct evdev_dispatch *dispatch = device->dispatch; assert(dispatch->interface->get_switch_state); return dispatch->interface->get_switch_state(dispatch, sw); } void evdev_pointer_notify_physical_button(struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state) { if (evdev_middlebutton_filter_button(device, time, button, state)) return; evdev_pointer_notify_button(device, time, (unsigned int)button, state); } static void evdev_pointer_post_button(struct evdev_device *device, uint64_t time, unsigned int button, enum libinput_button_state state) { int down_count; down_count = evdev_update_key_down_count(device, button, state); if ((state == LIBINPUT_BUTTON_STATE_PRESSED && down_count == 1) || (state == LIBINPUT_BUTTON_STATE_RELEASED && down_count == 0)) { pointer_notify_button(&device->base, time, button, state); if (state == LIBINPUT_BUTTON_STATE_RELEASED) { if (device->left_handed.change_to_enabled) device->left_handed.change_to_enabled(device); if (device->scroll.change_scroll_method) device->scroll.change_scroll_method(device); } } } static void evdev_button_scroll_timeout(uint64_t time, void *data) { struct evdev_device *device = data; device->scroll.button_scroll_state = BUTTONSCROLL_READY; } static void evdev_button_scroll_button(struct evdev_device *device, uint64_t time, int is_press) { /* Where the button lock is enabled, we wrap the buttons into their own little state machine and filter out the events. */ switch (device->scroll.lock_state) { case BUTTONSCROLL_LOCK_DISABLED: break; case BUTTONSCROLL_LOCK_IDLE: assert(is_press); device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTDOWN; evdev_log_debug(device, "scroll lock: first down\n"); break; /* handle event */ case BUTTONSCROLL_LOCK_FIRSTDOWN: assert(!is_press); device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTUP; evdev_log_debug(device, "scroll lock: first up\n"); return; /* filter release event */ case BUTTONSCROLL_LOCK_FIRSTUP: assert(is_press); device->scroll.lock_state = BUTTONSCROLL_LOCK_SECONDDOWN; evdev_log_debug(device, "scroll lock: second down\n"); return; /* filter press event */ case BUTTONSCROLL_LOCK_SECONDDOWN: assert(!is_press); device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE; evdev_log_debug(device, "scroll lock: idle\n"); break; /* handle event */ } if (is_press) { if (device->scroll.button < BTN_MOUSE + 5) { /* For mouse buttons 1-5 (0x110 to 0x114) we apply a timeout before scrolling * since the button could also be used for regular clicking. */ enum timer_flags flags = TIMER_FLAG_NONE; device->scroll.button_scroll_state = BUTTONSCROLL_BUTTON_DOWN; /* Special case: if middle button emulation is enabled and * our scroll button is the left or right button, we only * get here *after* the middle button timeout has expired * for that button press. The time passed is the button-down * time though (which is in the past), so we have to allow * for a negative timer to be set. */ if (device->middlebutton.enabled && (device->scroll.button == BTN_LEFT || device->scroll.button == BTN_RIGHT)) { flags = TIMER_FLAG_ALLOW_NEGATIVE; } libinput_timer_set_flags(&device->scroll.timer, time + DEFAULT_BUTTON_SCROLL_TIMEOUT, flags); } else { /* For extra mouse buttons numbered 6 or more (0x115+) we assume it is * dedicated exclusively to scrolling, so we don't apply the timeout * in order to provide immediate scrolling responsiveness. */ device->scroll.button_scroll_state = BUTTONSCROLL_READY; } device->scroll.button_down_time = time; evdev_log_debug(device, "btnscroll: down\n"); } else { libinput_timer_cancel(&device->scroll.timer); switch(device->scroll.button_scroll_state) { case BUTTONSCROLL_IDLE: evdev_log_bug_libinput(device, "invalid state IDLE for button up\n"); break; case BUTTONSCROLL_BUTTON_DOWN: case BUTTONSCROLL_READY: evdev_log_debug(device, "btnscroll: cancel\n"); /* If the button is released quickly enough or * without scroll events, emit the * button press/release events. */ evdev_pointer_post_button(device, device->scroll.button_down_time, device->scroll.button, LIBINPUT_BUTTON_STATE_PRESSED); evdev_pointer_post_button(device, time, device->scroll.button, LIBINPUT_BUTTON_STATE_RELEASED); break; case BUTTONSCROLL_SCROLLING: evdev_log_debug(device, "btnscroll: up\n"); evdev_stop_scroll(device, time, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); break; } device->scroll.button_scroll_state = BUTTONSCROLL_IDLE; } } void evdev_pointer_notify_button(struct evdev_device *device, uint64_t time, unsigned int button, enum libinput_button_state state) { if (device->scroll.method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN && button == device->scroll.button) { evdev_button_scroll_button(device, time, state); return; } evdev_pointer_post_button(device, time, button, state); } void evdev_device_led_update(struct evdev_device *device, enum libinput_led leds) { static const struct { enum libinput_led libinput; int evdev; } map[] = { { LIBINPUT_LED_NUM_LOCK, LED_NUML }, { LIBINPUT_LED_CAPS_LOCK, LED_CAPSL }, { LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL }, { LIBINPUT_LED_COMPOSE, LED_COMPOSE }, { LIBINPUT_LED_KANA, LED_KANA }, }; struct input_event ev[ARRAY_LENGTH(map) + 1]; unsigned int i; if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD)) return; memset(ev, 0, sizeof(ev)); for (i = 0; i < ARRAY_LENGTH(map); i++) { ev[i].type = EV_LED; ev[i].code = map[i].evdev; ev[i].value = !!(leds & map[i].libinput); } ev[i].type = EV_SYN; ev[i].code = SYN_REPORT; i = write(device->fd, ev, sizeof ev); (void)i; /* no, we really don't care about the return value */ } void evdev_transform_absolute(struct evdev_device *device, struct device_coords *point) { if (!device->abs.apply_calibration) return; matrix_mult_vec(&device->abs.calibration, &point->x, &point->y); } void evdev_transform_relative(struct evdev_device *device, struct device_coords *point) { struct matrix rel_matrix; if (!device->abs.apply_calibration) return; matrix_to_relative(&rel_matrix, &device->abs.calibration); matrix_mult_vec(&rel_matrix, &point->x, &point->y); } double evdev_device_transform_x(struct evdev_device *device, double x, uint32_t width) { return absinfo_scale_axis(device->abs.absinfo_x, x, width); } double evdev_device_transform_y(struct evdev_device *device, double y, uint32_t height) { return absinfo_scale_axis(device->abs.absinfo_y, y, height); } void evdev_notify_axis_legacy_wheel(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in, const struct discrete_coords *discrete_in) { struct normalized_coords delta = *delta_in; struct discrete_coords discrete = *discrete_in; if (device->scroll.invert_horizontal_scrolling) { delta.x *= -1; discrete.x *= -1; } if (device->scroll.natural_scrolling_enabled) { delta.x *= -1; delta.y *= -1; discrete.x *= -1; discrete.y *= -1; } pointer_notify_axis_legacy_wheel(&device->base, time, axes, &delta, &discrete); } void evdev_notify_axis_wheel(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in, const struct wheel_v120 *v120_in) { struct normalized_coords delta = *delta_in; struct wheel_v120 v120 = *v120_in; if (device->scroll.invert_horizontal_scrolling) { delta.x *= -1; v120.x *= -1; } if (device->scroll.natural_scrolling_enabled) { delta.x *= -1; delta.y *= -1; v120.x *= -1; v120.y *= -1; } pointer_notify_axis_wheel(&device->base, time, axes, &delta, &v120); } void evdev_notify_axis_finger(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in) { struct normalized_coords delta = *delta_in; if (device->scroll.natural_scrolling_enabled) { delta.x *= -1; delta.y *= -1; } pointer_notify_axis_finger(&device->base, time, axes, &delta); } void evdev_notify_axis_continous(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in) { struct normalized_coords delta = *delta_in; if (device->scroll.natural_scrolling_enabled) { delta.x *= -1; delta.y *= -1; } pointer_notify_axis_continuous(&device->base, time, axes, &delta); } static void evdev_tag_external_mouse(struct evdev_device *device, struct udev_device *udev_device) { int bustype; bustype = libevdev_get_id_bustype(device->evdev); if (bustype == BUS_USB || bustype == BUS_BLUETOOTH) device->tags |= EVDEV_TAG_EXTERNAL_MOUSE; } static void evdev_tag_trackpoint(struct evdev_device *device, struct udev_device *udev_device) { struct quirks_context *quirks; struct quirks *q; char *prop; if (!libevdev_has_property(device->evdev, INPUT_PROP_POINTING_STICK) && !parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK")) return; device->tags |= EVDEV_TAG_TRACKPOINT; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q && quirks_get_string(q, QUIRK_ATTR_TRACKPOINT_INTEGRATION, &prop)) { if (streq(prop, "internal")) { /* noop, this is the default anyway */ } else if (streq(prop, "external")) { device->tags |= EVDEV_TAG_EXTERNAL_MOUSE; evdev_log_info(device, "is an external pointing stick\n"); } else { evdev_log_info(device, "tagged with unknown value %s\n", prop); } } quirks_unref(q); } static inline void evdev_tag_keyboard_internal(struct evdev_device *device) { device->tags |= EVDEV_TAG_INTERNAL_KEYBOARD; device->tags &= ~EVDEV_TAG_EXTERNAL_KEYBOARD; } static inline void evdev_tag_keyboard_external(struct evdev_device *device) { device->tags |= EVDEV_TAG_EXTERNAL_KEYBOARD; device->tags &= ~EVDEV_TAG_INTERNAL_KEYBOARD; } static void evdev_tag_keyboard(struct evdev_device *device, struct udev_device *udev_device) { struct quirks_context *quirks; struct quirks *q; char *prop; int code; if (!libevdev_has_event_type(device->evdev, EV_KEY)) return; for (code = KEY_Q; code <= KEY_P; code++) { if (!libevdev_has_event_code(device->evdev, EV_KEY, code)) return; } quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q && quirks_get_string(q, QUIRK_ATTR_KEYBOARD_INTEGRATION, &prop)) { if (streq(prop, "internal")) { evdev_tag_keyboard_internal(device); } else if (streq(prop, "external")) { evdev_tag_keyboard_external(device); } else { evdev_log_info(device, "tagged with unknown value %s\n", prop); } } quirks_unref(q); device->tags |= EVDEV_TAG_KEYBOARD; } static void evdev_tag_tablet_touchpad(struct evdev_device *device) { device->tags |= EVDEV_TAG_TABLET_TOUCHPAD; } static int evdev_calibration_has_matrix(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); return device->abs.absinfo_x && device->abs.absinfo_y; } static enum libinput_config_status evdev_calibration_set_matrix(struct libinput_device *libinput_device, const float matrix[6]) { struct evdev_device *device = evdev_device(libinput_device); evdev_device_calibrate(device, matrix); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static int evdev_calibration_get_matrix(struct libinput_device *libinput_device, float matrix[6]) { struct evdev_device *device = evdev_device(libinput_device); matrix_to_farray6(&device->abs.usermatrix, matrix); return !matrix_is_identity(&device->abs.usermatrix); } static int evdev_calibration_get_default_matrix(struct libinput_device *libinput_device, float matrix[6]) { struct evdev_device *device = evdev_device(libinput_device); matrix_to_farray6(&device->abs.default_calibration, matrix); return !matrix_is_identity(&device->abs.default_calibration); } static uint32_t evdev_sendevents_get_modes(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; } static enum libinput_config_status evdev_sendevents_set_mode(struct libinput_device *device, enum libinput_config_send_events_mode mode) { struct evdev_device *evdev = evdev_device(device); struct evdev_dispatch *dispatch = evdev->dispatch; if (mode == dispatch->sendevents.current_mode) return LIBINPUT_CONFIG_STATUS_SUCCESS; switch(mode) { case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: evdev_device_resume(evdev); break; case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: evdev_device_suspend(evdev); break; default: /* no support for combined modes yet */ return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } dispatch->sendevents.current_mode = mode; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_send_events_mode evdev_sendevents_get_mode(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); struct evdev_dispatch *dispatch = evdev->dispatch; return dispatch->sendevents.current_mode; } static enum libinput_config_send_events_mode evdev_sendevents_get_default_mode(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } static int evdev_left_handed_has(struct libinput_device *device) { /* This is only hooked up when we have left-handed configuration, so we * can hardcode 1 here */ return 1; } static enum libinput_config_status evdev_left_handed_set(struct libinput_device *device, int left_handed) { struct evdev_device *evdev = evdev_device(device); evdev->left_handed.want_enabled = left_handed ? true : false; evdev->left_handed.change_to_enabled(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static int evdev_left_handed_get(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); /* return the wanted configuration, even if it hasn't taken * effect yet! */ return evdev->left_handed.want_enabled; } static int evdev_left_handed_get_default(struct libinput_device *device) { return 0; } void evdev_init_left_handed(struct evdev_device *device, void (*change_to_left_handed)(struct evdev_device *)) { device->left_handed.config.has = evdev_left_handed_has; device->left_handed.config.set = evdev_left_handed_set; device->left_handed.config.get = evdev_left_handed_get; device->left_handed.config.get_default = evdev_left_handed_get_default; device->base.config.left_handed = &device->left_handed.config; device->left_handed.enabled = false; device->left_handed.want_enabled = false; device->left_handed.change_to_enabled = change_to_left_handed; } static uint32_t evdev_scroll_get_methods(struct libinput_device *device) { return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } static enum libinput_config_status evdev_scroll_set_method(struct libinput_device *device, enum libinput_config_scroll_method method) { struct evdev_device *evdev = evdev_device(device); evdev->scroll.want_method = method; evdev->scroll.change_scroll_method(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_scroll_method evdev_scroll_get_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); /* return the wanted configuration, even if it hasn't taken * effect yet! */ return evdev->scroll.want_method; } static enum libinput_config_scroll_method evdev_scroll_get_default_method(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); if (evdev->tags & EVDEV_TAG_TRACKPOINT) return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; /* Mice without a scroll wheel but with middle button have on-button * scrolling by default */ if (!libevdev_has_event_code(evdev->evdev, EV_REL, REL_WHEEL) && !libevdev_has_event_code(evdev->evdev, EV_REL, REL_HWHEEL) && libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE)) return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } static enum libinput_config_status evdev_scroll_set_button(struct libinput_device *device, uint32_t button) { struct evdev_device *evdev = evdev_device(device); evdev->scroll.want_button = button; evdev->scroll.change_scroll_method(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static uint32_t evdev_scroll_get_button(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); /* return the wanted configuration, even if it hasn't taken * effect yet! */ return evdev->scroll.want_button; } static uint32_t evdev_scroll_get_default_button(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); unsigned int code; if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE)) return BTN_MIDDLE; for (code = BTN_SIDE; code <= BTN_TASK; code++) { if (libevdev_has_event_code(evdev->evdev, EV_KEY, code)) return code; } if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_RIGHT)) return BTN_RIGHT; return 0; } static enum libinput_config_status evdev_scroll_set_button_lock(struct libinput_device *device, enum libinput_config_scroll_button_lock_state state) { struct evdev_device *evdev = evdev_device(device); switch (state) { case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED: evdev->scroll.want_lock_enabled = false; break; case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED: evdev->scroll.want_lock_enabled = true; break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } evdev->scroll.change_scroll_method(evdev); return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_scroll_button_lock_state evdev_scroll_get_button_lock(struct libinput_device *device) { struct evdev_device *evdev = evdev_device(device); if (evdev->scroll.lock_state == BUTTONSCROLL_LOCK_DISABLED) return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED; } static enum libinput_config_scroll_button_lock_state evdev_scroll_get_default_button_lock(struct libinput_device *device) { return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; } void evdev_set_button_scroll_lock_enabled(struct evdev_device *device, bool enabled) { if (enabled) device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE; else device->scroll.lock_state = BUTTONSCROLL_LOCK_DISABLED; } void evdev_init_button_scroll(struct evdev_device *device, void (*change_scroll_method)(struct evdev_device *)) { char timer_name[64]; snprintf(timer_name, sizeof(timer_name), "%s btnscroll", evdev_device_get_sysname(device)); libinput_timer_init(&device->scroll.timer, evdev_libinput_context(device), timer_name, evdev_button_scroll_timeout, device); device->scroll.config.get_methods = evdev_scroll_get_methods; device->scroll.config.set_method = evdev_scroll_set_method; device->scroll.config.get_method = evdev_scroll_get_method; device->scroll.config.get_default_method = evdev_scroll_get_default_method; device->scroll.config.set_button = evdev_scroll_set_button; device->scroll.config.get_button = evdev_scroll_get_button; device->scroll.config.get_default_button = evdev_scroll_get_default_button; device->scroll.config.set_button_lock = evdev_scroll_set_button_lock; device->scroll.config.get_button_lock = evdev_scroll_get_button_lock; device->scroll.config.get_default_button_lock = evdev_scroll_get_default_button_lock; device->base.config.scroll_method = &device->scroll.config; device->scroll.method = evdev_scroll_get_default_method((struct libinput_device *)device); device->scroll.want_method = device->scroll.method; device->scroll.button = evdev_scroll_get_default_button((struct libinput_device *)device); device->scroll.want_button = device->scroll.button; device->scroll.change_scroll_method = change_scroll_method; } void evdev_init_calibration(struct evdev_device *device, struct libinput_device_config_calibration *calibration) { device->base.config.calibration = calibration; calibration->has_matrix = evdev_calibration_has_matrix; calibration->set_matrix = evdev_calibration_set_matrix; calibration->get_matrix = evdev_calibration_get_matrix; calibration->get_default_matrix = evdev_calibration_get_default_matrix; } void evdev_init_sendevents(struct evdev_device *device, struct evdev_dispatch *dispatch) { device->base.config.sendevents = &dispatch->sendevents.config; dispatch->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; dispatch->sendevents.config.get_modes = evdev_sendevents_get_modes; dispatch->sendevents.config.set_mode = evdev_sendevents_set_mode; dispatch->sendevents.config.get_mode = evdev_sendevents_get_mode; dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode; } static int evdev_scroll_config_natural_has(struct libinput_device *device) { return 1; } static enum libinput_config_status evdev_scroll_config_natural_set(struct libinput_device *device, int enabled) { struct evdev_device *dev = evdev_device(device); dev->scroll.natural_scrolling_enabled = enabled ? true : false; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static int evdev_scroll_config_natural_get(struct libinput_device *device) { struct evdev_device *dev = evdev_device(device); return dev->scroll.natural_scrolling_enabled ? 1 : 0; } static int evdev_scroll_config_natural_get_default(struct libinput_device *device) { /* Overridden in evdev-mt-touchpad.c for Apple touchpads. */ return 0; } void evdev_init_natural_scroll(struct evdev_device *device) { device->scroll.config_natural.has = evdev_scroll_config_natural_has; device->scroll.config_natural.set_enabled = evdev_scroll_config_natural_set; device->scroll.config_natural.get_enabled = evdev_scroll_config_natural_get; device->scroll.config_natural.get_default_enabled = evdev_scroll_config_natural_get_default; device->scroll.natural_scrolling_enabled = false; device->base.config.natural_scroll = &device->scroll.config_natural; } int evdev_need_mtdev(struct evdev_device *device) { struct libevdev *evdev = device->evdev; return (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) && libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y) && !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT)); } /* Fake MT devices have the ABS_MT_SLOT bit set because of the limited ABS_* range - they aren't MT devices, they just have too many ABS_ axes */ bool evdev_is_fake_mt_device(struct evdev_device *device) { struct libevdev *evdev = device->evdev; return libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT) && libevdev_get_num_slots(evdev) == -1; } enum switch_reliability evdev_read_switch_reliability_prop(struct evdev_device *device) { enum switch_reliability r; struct quirks_context *quirks; struct quirks *q; char *prop; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q || !quirks_get_string(q, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) { r = RELIABILITY_RELIABLE; } else if (!parse_switch_reliability_property(prop, &r)) { evdev_log_error(device, "%s: switch reliability set to unknown value '%s'\n", device->devname, prop); r = RELIABILITY_RELIABLE; } else if (r == RELIABILITY_WRITE_OPEN) { evdev_log_info(device, "will write switch open events\n"); } quirks_unref(q); return r; } LIBINPUT_UNUSED static inline void evdev_print_event(struct evdev_device *device, const struct input_event *e) { static uint32_t offset = 0; static uint32_t last_time = 0; uint32_t time = us2ms(input_event_time(e)); if (offset == 0) { offset = time; last_time = time - offset; } time -= offset; if (libevdev_event_is_code(e, EV_SYN, SYN_REPORT)) { evdev_log_debug(device, "%u.%03u ----------------- EV_SYN ----------------- +%ums\n", time / 1000, time % 1000, time - last_time); last_time = time; } else { evdev_log_debug(device, "%u.%03u %-16s %-20s %4d\n", time / 1000, time % 1000, libevdev_event_type_get_name(e->type), libevdev_event_code_get_name(e->type, e->code), e->value); } } static inline void evdev_process_event(struct evdev_device *device, struct input_event *e) { struct evdev_dispatch *dispatch = device->dispatch; uint64_t time = input_event_time(e); #if EVENT_DEBUGGING evdev_print_event(device, e); #endif libinput_timer_flush(evdev_libinput_context(device), time); dispatch->interface->process(dispatch, device, e, time); } static inline void evdev_device_dispatch_one(struct evdev_device *device, struct input_event *ev) { if (!device->mtdev) { evdev_process_event(device, ev); } else { mtdev_put_event(device->mtdev, ev); if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) { while (!mtdev_empty(device->mtdev)) { struct input_event e; mtdev_get_event(device->mtdev, &e); evdev_process_event(device, &e); } } } } static int evdev_sync_device(struct evdev_device *device) { struct input_event ev; int rc; do { rc = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_SYNC, &ev); if (rc < 0) break; evdev_device_dispatch_one(device, &ev); } while (rc == LIBEVDEV_READ_STATUS_SYNC); return rc == -EAGAIN ? 0 : rc; } static inline void evdev_note_time_delay(struct evdev_device *device, const struct input_event *ev) { struct libinput *libinput = evdev_libinput_context(device); uint32_t tdelta; uint64_t eventtime = input_event_time(ev); /* if we have a current libinput_dispatch() snapshot, compare our * event time with the one from the snapshot. If we have more than * 10ms delay, complain about it. This catches delays in processing * where there is no steady event flow and thus SYN_DROPPED may not * get hit by the kernel despite us being too slow. */ if (libinput->dispatch_time == 0 || eventtime > libinput->dispatch_time) return; tdelta = us2ms(libinput->dispatch_time - eventtime); if (tdelta > 20) { evdev_log_bug_client_ratelimit(device, &device->delay_warning_limit, "event processing lagging behind by %dms, your system is too slow\n", tdelta); } } static void evdev_device_dispatch(void *data) { struct evdev_device *device = data; struct libinput *libinput = evdev_libinput_context(device); struct input_event ev; int rc; bool once = false; /* If the compositor is repainting, this function is called only once * per frame and we have to process all the events available on the * fd, otherwise there will be input lag. */ do { rc = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (rc == LIBEVDEV_READ_STATUS_SYNC) { evdev_log_info_ratelimit(device, &device->syn_drop_limit, "SYN_DROPPED event - some input events have been lost.\n"); /* send one more sync event so we handle all currently pending events before we sync up to the current state */ ev.code = SYN_REPORT; evdev_device_dispatch_one(device, &ev); rc = evdev_sync_device(device); if (rc == 0) rc = LIBEVDEV_READ_STATUS_SUCCESS; } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) { if (!once) { evdev_note_time_delay(device, &ev); once = true; } evdev_device_dispatch_one(device, &ev); } else if (rc == -ENODEV) { evdev_device_remove(device); return; } } while (rc == LIBEVDEV_READ_STATUS_SUCCESS); if (rc != -EAGAIN && rc != -EINTR) { libinput_remove_source(libinput, device->source); device->source = NULL; } } static inline bool evdev_init_accel(struct evdev_device *device, enum libinput_config_accel_profile which) { struct motion_filter *filter = NULL; if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) filter = create_custom_accelerator_filter(); else if (device->tags & EVDEV_TAG_TRACKPOINT) { if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) filter = create_pointer_accelerator_filter_trackpoint_flat(device->trackpoint_multiplier); else filter = create_pointer_accelerator_filter_trackpoint(device->trackpoint_multiplier, device->use_velocity_averaging); } else { if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) filter = create_pointer_accelerator_filter_flat(device->dpi); else if (device->dpi < DEFAULT_MOUSE_DPI) filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi, device->use_velocity_averaging); } if (!filter) filter = create_pointer_accelerator_filter_linear(device->dpi, device->use_velocity_averaging); if (!filter) return false; evdev_device_init_pointer_acceleration(device, filter); return true; } static int evdev_accel_config_available(struct libinput_device *device) { /* this function is only called if we set up ptraccel, so we can reply with a resounding "Yes" */ return 1; } static enum libinput_config_status evdev_accel_config_set_speed(struct libinput_device *device, double speed) { struct evdev_device *dev = evdev_device(device); if (!filter_set_speed(dev->pointer.filter, speed)) return LIBINPUT_CONFIG_STATUS_INVALID; return LIBINPUT_CONFIG_STATUS_SUCCESS; } static double evdev_accel_config_get_speed(struct libinput_device *device) { struct evdev_device *dev = evdev_device(device); return filter_get_speed(dev->pointer.filter); } static double evdev_accel_config_get_default_speed(struct libinput_device *device) { return 0.0; } static uint32_t evdev_accel_config_get_profiles(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); if (!device->pointer.filter) return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE | LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT | LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM; } static enum libinput_config_status evdev_accel_config_set_profile(struct libinput_device *libinput_device, enum libinput_config_accel_profile profile) { struct evdev_device *device = evdev_device(libinput_device); struct motion_filter *filter; double speed; filter = device->pointer.filter; if (filter_get_type(filter) == profile) return LIBINPUT_CONFIG_STATUS_SUCCESS; speed = filter_get_speed(filter); device->pointer.filter = NULL; if (evdev_init_accel(device, profile)) { evdev_accel_config_set_speed(libinput_device, speed); filter_destroy(filter); } else { device->pointer.filter = filter; return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; } return LIBINPUT_CONFIG_STATUS_SUCCESS; } static enum libinput_config_accel_profile evdev_accel_config_get_profile(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); return filter_get_type(device->pointer.filter); } static enum libinput_config_accel_profile evdev_accel_config_get_default_profile(struct libinput_device *libinput_device) { struct evdev_device *device = evdev_device(libinput_device); if (!device->pointer.filter) return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; /* No device has a flat profile as default */ return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; } static enum libinput_config_status evdev_set_accel_config(struct libinput_device *libinput_device, struct libinput_config_accel *accel_config) { assert(evdev_accel_config_get_profile(libinput_device) == accel_config->profile); struct evdev_device *dev = evdev_device(libinput_device); if (!filter_set_accel_config(dev->pointer.filter, accel_config)) return LIBINPUT_CONFIG_STATUS_INVALID; return LIBINPUT_CONFIG_STATUS_SUCCESS; } void evdev_device_init_pointer_acceleration(struct evdev_device *device, struct motion_filter *filter) { device->pointer.filter = filter; if (device->base.config.accel == NULL) { double default_speed; device->pointer.config.available = evdev_accel_config_available; device->pointer.config.set_speed = evdev_accel_config_set_speed; device->pointer.config.get_speed = evdev_accel_config_get_speed; device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed; device->pointer.config.get_profiles = evdev_accel_config_get_profiles; device->pointer.config.set_profile = evdev_accel_config_set_profile; device->pointer.config.get_profile = evdev_accel_config_get_profile; device->pointer.config.get_default_profile = evdev_accel_config_get_default_profile; device->pointer.config.set_accel_config = evdev_set_accel_config; device->base.config.accel = &device->pointer.config; default_speed = evdev_accel_config_get_default_speed(&device->base); evdev_accel_config_set_speed(&device->base, default_speed); } } static inline bool evdev_read_wheel_click_prop(struct evdev_device *device, const char *prop, double *angle) { int val; *angle = DEFAULT_WHEEL_CLICK_ANGLE; prop = udev_device_get_property_value(device->udev_device, prop); if (!prop) return false; val = parse_mouse_wheel_click_angle_property(prop); if (val) { *angle = val; return true; } evdev_log_error(device, "mouse wheel click angle is present but invalid, " "using %d degrees instead\n", DEFAULT_WHEEL_CLICK_ANGLE); return false; } static inline bool evdev_read_wheel_click_count_prop(struct evdev_device *device, const char *prop, double *angle) { int val; prop = udev_device_get_property_value(device->udev_device, prop); if (!prop) return false; val = parse_mouse_wheel_click_angle_property(prop); if (val) { *angle = 360.0/val; return true; } evdev_log_error(device, "mouse wheel click count is present but invalid, " "using %d degrees for angle instead instead\n", DEFAULT_WHEEL_CLICK_ANGLE); *angle = DEFAULT_WHEEL_CLICK_ANGLE; return false; } static inline struct wheel_angle evdev_read_wheel_click_props(struct evdev_device *device) { struct wheel_angle angles; const char *wheel_count = "MOUSE_WHEEL_CLICK_COUNT"; const char *wheel_angle = "MOUSE_WHEEL_CLICK_ANGLE"; const char *hwheel_count = "MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL"; const char *hwheel_angle = "MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL"; /* CLICK_COUNT overrides CLICK_ANGLE */ if (evdev_read_wheel_click_count_prop(device, wheel_count, &angles.y) || evdev_read_wheel_click_prop(device, wheel_angle, &angles.y)) { evdev_log_debug(device, "wheel: vert click angle: %.2f\n", angles.y); } if (evdev_read_wheel_click_count_prop(device, hwheel_count, &angles.x) || evdev_read_wheel_click_prop(device, hwheel_angle, &angles.x)) { evdev_log_debug(device, "wheel: horizontal click angle: %.2f\n", angles.x); } else { angles.x = angles.y; } return angles; } static inline double evdev_get_trackpoint_multiplier(struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; double multiplier = 1.0; if (!(device->tags & EVDEV_TAG_TRACKPOINT)) return 1.0; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q) { quirks_get_double(q, QUIRK_ATTR_TRACKPOINT_MULTIPLIER, &multiplier); quirks_unref(q); } if (multiplier <= 0.0) { evdev_log_bug_libinput(device, "trackpoint multiplier %.2f is invalid\n", multiplier); multiplier = 1.0; } if (multiplier != 1.0) evdev_log_info(device, "trackpoint multiplier is %.2f\n", multiplier); return multiplier; } static inline bool evdev_need_velocity_averaging(struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; bool use_velocity_averaging = false; /* default off unless we have quirk */ quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (q) { quirks_get_bool(q, QUIRK_ATTR_USE_VELOCITY_AVERAGING, &use_velocity_averaging); quirks_unref(q); } if (use_velocity_averaging) evdev_log_info(device, "velocity averaging is turned on\n"); return use_velocity_averaging; } static inline int evdev_read_dpi_prop(struct evdev_device *device) { const char *mouse_dpi; int dpi = DEFAULT_MOUSE_DPI; if (device->tags & EVDEV_TAG_TRACKPOINT) return DEFAULT_MOUSE_DPI; mouse_dpi = udev_device_get_property_value(device->udev_device, "MOUSE_DPI"); if (mouse_dpi) { dpi = parse_mouse_dpi_property(mouse_dpi); if (!dpi) { evdev_log_error(device, "mouse DPI property is present but invalid, " "using %d DPI instead\n", DEFAULT_MOUSE_DPI); dpi = DEFAULT_MOUSE_DPI; } evdev_log_info(device, "device set to %d DPI\n", dpi); } return dpi; } static inline uint32_t evdev_read_model_flags(struct evdev_device *device) { const struct model_map { enum quirk quirk; enum evdev_device_model model; } model_map[] = { #define MODEL(name) { QUIRK_MODEL_##name, EVDEV_MODEL_##name } MODEL(WACOM_TOUCHPAD), MODEL(SYNAPTICS_SERIAL_TOUCHPAD), MODEL(ALPS_SERIAL_TOUCHPAD), MODEL(LENOVO_T450_TOUCHPAD), MODEL(TRACKBALL), MODEL(APPLE_TOUCHPAD_ONEBUTTON), MODEL(LENOVO_SCROLLPOINT), #undef MODEL { 0, 0 }, }; const struct model_map *m = model_map; uint32_t model_flags = 0; uint32_t all_model_flags = 0; struct quirks_context *quirks; struct quirks *q; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); while (q && m->quirk) { bool is_set; /* Check for flag re-use */ assert((all_model_flags & m->model) == 0); all_model_flags |= m->model; if (quirks_get_bool(q, m->quirk, &is_set)) { if (is_set) { evdev_log_debug(device, "tagged as %s\n", quirk_get_name(m->quirk)); model_flags |= m->model; } else { evdev_log_debug(device, "untagged as %s\n", quirk_get_name(m->quirk)); model_flags &= ~m->model; } } m++; } quirks_unref(q); if (parse_udev_flag(device, device->udev_device, "ID_INPUT_TRACKBALL")) { evdev_log_debug(device, "tagged as trackball\n"); model_flags |= EVDEV_MODEL_TRACKBALL; } /** * Device is 6 years old at the time of writing this and this was * one of the few udev properties that wasn't reserved for private * usage, so we need to keep this for backwards compat. */ if (parse_udev_flag(device, device->udev_device, "LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81")) { evdev_log_debug(device, "tagged as trackball\n"); model_flags |= EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81; } if (parse_udev_flag(device, device->udev_device, "LIBINPUT_TEST_DEVICE")) { evdev_log_debug(device, "is a test device\n"); model_flags |= EVDEV_MODEL_TEST_DEVICE; } return model_flags; } static inline bool evdev_read_attr_res_prop(struct evdev_device *device, size_t *xres, size_t *yres) { struct quirks_context *quirks; struct quirks *q; struct quirk_dimensions dim; bool rc = false; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q) return false; rc = quirks_get_dimensions(q, QUIRK_ATTR_RESOLUTION_HINT, &dim); if (rc) { *xres = dim.x; *yres = dim.y; } quirks_unref(q); return rc; } static inline bool evdev_read_attr_size_prop(struct evdev_device *device, size_t *size_x, size_t *size_y) { struct quirks_context *quirks; struct quirks *q; struct quirk_dimensions dim; bool rc = false; quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q) return false; rc = quirks_get_dimensions(q, QUIRK_ATTR_SIZE_HINT, &dim); if (rc) { *size_x = dim.x; *size_y = dim.y; } quirks_unref(q); return rc; } /* Return 1 if the device is set to the fake resolution or 0 otherwise */ static inline int evdev_fix_abs_resolution(struct evdev_device *device, unsigned int xcode, unsigned int ycode) { struct libevdev *evdev = device->evdev; const struct input_absinfo *absx, *absy; size_t widthmm = 0, heightmm = 0; size_t xres = EVDEV_FAKE_RESOLUTION, yres = EVDEV_FAKE_RESOLUTION; if (!(xcode == ABS_X && ycode == ABS_Y) && !(xcode == ABS_MT_POSITION_X && ycode == ABS_MT_POSITION_Y)) { evdev_log_bug_libinput(device, "invalid x/y code combination %d/%d\n", xcode, ycode); return 0; } absx = libevdev_get_abs_info(evdev, xcode); absy = libevdev_get_abs_info(evdev, ycode); if (absx->resolution != 0 || absy->resolution != 0) return 0; /* Note: we *do not* override resolutions if provided by the kernel. * If a device needs this, add it to 60-evdev.hwdb. The libinput * property is only for general size hints where we can make * educated guesses but don't know better. */ if (!evdev_read_attr_res_prop(device, &xres, &yres) && evdev_read_attr_size_prop(device, &widthmm, &heightmm)) { xres = absinfo_range(absx)/widthmm; yres = absinfo_range(absy)/heightmm; } /* libevdev_set_abs_resolution() changes the absinfo we already have a pointer to, no need to fetch it again */ libevdev_set_abs_resolution(evdev, xcode, xres); libevdev_set_abs_resolution(evdev, ycode, yres); return xres == EVDEV_FAKE_RESOLUTION; } static enum evdev_device_udev_tags evdev_device_get_udev_tags(struct evdev_device *device, struct udev_device *udev_device) { enum evdev_device_udev_tags tags = 0; int i; for (i = 0; i < 2 && udev_device; i++) { unsigned j; for (j = 0; j < ARRAY_LENGTH(evdev_udev_tag_matches); j++) { const struct evdev_udev_tag_match match = evdev_udev_tag_matches[j]; if (parse_udev_flag(device, udev_device, match.name)) tags |= match.tag; } udev_device = udev_device_get_parent(udev_device); } return tags; } static inline void evdev_fix_android_mt(struct evdev_device *device) { struct libevdev *evdev = device->evdev; if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) || libevdev_has_event_code(evdev, EV_ABS, ABS_Y)) return; if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y) || evdev_is_fake_mt_device(device)) return; libevdev_enable_event_code(evdev, EV_ABS, ABS_X, libevdev_get_abs_info(evdev, ABS_MT_POSITION_X)); libevdev_enable_event_code(evdev, EV_ABS, ABS_Y, libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y)); } static inline bool evdev_check_min_max(struct evdev_device *device, unsigned int code) { struct libevdev *evdev = device->evdev; const struct input_absinfo *absinfo; if (!libevdev_has_event_code(evdev, EV_ABS, code)) return true; absinfo = libevdev_get_abs_info(evdev, code); if (absinfo->minimum == absinfo->maximum) { /* Some devices have a sort-of legitimate min/max of 0 for * ABS_MISC and above (e.g. Roccat Kone XTD). Don't ignore * them, simply disable the axes so we won't get events, * we don't know what to do with them anyway. */ if (absinfo->minimum == 0 && code >= ABS_MISC && code < ABS_MT_SLOT) { evdev_log_info(device, "disabling EV_ABS %#x on device (min == max == 0)\n", code); libevdev_disable_event_code(device->evdev, EV_ABS, code); } else { evdev_log_bug_kernel(device, "device has min == max on %s\n", libevdev_event_code_get_name(EV_ABS, code)); return false; } } return true; } static bool evdev_reject_device(struct evdev_device *device) { struct libevdev *evdev = device->evdev; unsigned int code; const struct input_absinfo *absx, *absy; if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) ^ libevdev_has_event_code(evdev, EV_ABS, ABS_Y)) return true; if (libevdev_has_event_code(evdev, EV_REL, REL_X) ^ libevdev_has_event_code(evdev, EV_REL, REL_Y)) return true; if (!evdev_is_fake_mt_device(device) && libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ^ libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) return true; if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) { absx = libevdev_get_abs_info(evdev, ABS_X); absy = libevdev_get_abs_info(evdev, ABS_Y); if ((absx->resolution == 0 && absy->resolution != 0) || (absx->resolution != 0 && absy->resolution == 0)) { evdev_log_bug_kernel(device, "kernel has only x or y resolution, not both.\n"); return true; } } if (!evdev_is_fake_mt_device(device) && libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X)) { absx = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X); absy = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y); if ((absx->resolution == 0 && absy->resolution != 0) || (absx->resolution != 0 && absy->resolution == 0)) { evdev_log_bug_kernel(device, "kernel has only x or y MT resolution, not both.\n"); return true; } } for (code = 0; code < ABS_CNT; code++) { switch (code) { case ABS_MISC: case ABS_MT_SLOT: case ABS_MT_TOOL_TYPE: break; default: if (!evdev_check_min_max(device, code)) return true; } } return false; } static void evdev_extract_abs_axes(struct evdev_device *device, enum evdev_device_udev_tags udev_tags) { struct libevdev *evdev = device->evdev; int fuzz; if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X) || !libevdev_has_event_code(evdev, EV_ABS, ABS_Y)) return; if (evdev_fix_abs_resolution(device, ABS_X, ABS_Y)) device->abs.is_fake_resolution = true; if (udev_tags & (EVDEV_UDEV_TAG_TOUCHPAD|EVDEV_UDEV_TAG_TOUCHSCREEN)) { fuzz = evdev_read_fuzz_prop(device, ABS_X); libevdev_set_abs_fuzz(evdev, ABS_X, fuzz); fuzz = evdev_read_fuzz_prop(device, ABS_Y); libevdev_set_abs_fuzz(evdev, ABS_Y, fuzz); } device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X); device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y); device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x)); device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y)); if (evdev_is_fake_mt_device(device) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) || !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) return; if (evdev_fix_abs_resolution(device, ABS_MT_POSITION_X, ABS_MT_POSITION_Y)) device->abs.is_fake_resolution = true; if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_X))) libevdev_set_abs_fuzz(evdev, ABS_MT_POSITION_X, fuzz); if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_Y))) libevdev_set_abs_fuzz(evdev, ABS_MT_POSITION_Y, fuzz); device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X); device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y); device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x)); device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y)); device->is_mt = 1; } static void evdev_disable_accelerometer_axes(struct evdev_device *device) { struct libevdev *evdev = device->evdev; libevdev_disable_event_code(evdev, EV_ABS, ABS_X); libevdev_disable_event_code(evdev, EV_ABS, ABS_Y); libevdev_disable_event_code(evdev, EV_ABS, ABS_Z); libevdev_disable_event_code(evdev, EV_ABS, REL_X); libevdev_disable_event_code(evdev, EV_ABS, REL_Y); libevdev_disable_event_code(evdev, EV_ABS, REL_Z); } static bool evdev_device_is_joystick_or_gamepad(struct evdev_device *device) { enum evdev_device_udev_tags udev_tags; bool has_joystick_tags; struct libevdev *evdev = device->evdev; unsigned int code; /* The EVDEV_UDEV_TAG_JOYSTICK is set when a joystick or gamepad button * is found. However, it can not be used to identify joysticks or * gamepads because there are keyboards that also have it. Even worse, * many joysticks also map KEY_* and thus are tagged as keyboards. * * In order to be able to detect joysticks and gamepads and * differentiate them from keyboards, apply the following rules: * * 1. The device is tagged as joystick but not as tablet * 2. The device doesn't have 4 well-known keyboard keys * 3. It has at least 2 joystick buttons * 4. It doesn't have 10 keyboard keys */ udev_tags = evdev_device_get_udev_tags(device, device->udev_device); has_joystick_tags = (udev_tags & EVDEV_UDEV_TAG_JOYSTICK) && !(udev_tags & EVDEV_UDEV_TAG_TABLET) && !(udev_tags & EVDEV_UDEV_TAG_TABLET_PAD); if (!has_joystick_tags) return false; unsigned int num_well_known_keys = 0; for (size_t i = 0; i < ARRAY_LENGTH(well_known_keyboard_keys); i++) { code = well_known_keyboard_keys[i]; if (libevdev_has_event_code(evdev, EV_KEY, code)) num_well_known_keys++; } if (num_well_known_keys >= 4) /* should not have 4 well-known keys */ return false; unsigned int num_joystick_btns = 0; for (code = BTN_JOYSTICK; code < BTN_DIGI; code++) { if (libevdev_has_event_code(evdev, EV_KEY, code)) num_joystick_btns++; } for (code = BTN_TRIGGER_HAPPY; code <= BTN_TRIGGER_HAPPY40; code++) { if (libevdev_has_event_code(evdev, EV_KEY, code)) num_joystick_btns++; } if (num_joystick_btns < 2) /* require at least 2 joystick buttons */ return false; unsigned int num_keys = 0; for (code = KEY_ESC; code <= KEY_MICMUTE; code++) { if (libevdev_has_event_code(evdev, EV_KEY, code) ) num_keys++; } for (code = KEY_OK; code <= KEY_LIGHTS_TOGGLE; code++) { if (libevdev_has_event_code(evdev, EV_KEY, code) ) num_keys++; } for (code = KEY_ALS_TOGGLE; code < BTN_TRIGGER_HAPPY; code++) { if (libevdev_has_event_code(evdev, EV_KEY, code) ) num_keys++; } if (num_keys >= 10) /* should not have 10 keyboard keys */ return false; return true; } static struct evdev_dispatch * evdev_configure_device(struct evdev_device *device) { struct libevdev *evdev = device->evdev; enum evdev_device_udev_tags udev_tags; unsigned int tablet_tags; struct evdev_dispatch *dispatch; udev_tags = evdev_device_get_udev_tags(device, device->udev_device); if ((udev_tags & EVDEV_UDEV_TAG_INPUT) == 0 || (udev_tags & ~EVDEV_UDEV_TAG_INPUT) == 0) { evdev_log_info(device, "not tagged as supported input device\n"); return NULL; } evdev_log_info(device, "is tagged by udev as:%s%s%s%s%s%s%s%s%s%s%s\n", udev_tags & EVDEV_UDEV_TAG_KEYBOARD ? " Keyboard" : "", udev_tags & EVDEV_UDEV_TAG_MOUSE ? " Mouse" : "", udev_tags & EVDEV_UDEV_TAG_TOUCHPAD ? " Touchpad" : "", udev_tags & EVDEV_UDEV_TAG_TOUCHSCREEN ? " Touchscreen" : "", udev_tags & EVDEV_UDEV_TAG_TABLET ? " Tablet" : "", udev_tags & EVDEV_UDEV_TAG_POINTINGSTICK ? " Pointingstick" : "", udev_tags & EVDEV_UDEV_TAG_JOYSTICK ? " Joystick" : "", udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER ? " Accelerometer" : "", udev_tags & EVDEV_UDEV_TAG_TABLET_PAD ? " TabletPad" : "", udev_tags & EVDEV_UDEV_TAG_TRACKBALL ? " Trackball" : "", udev_tags & EVDEV_UDEV_TAG_SWITCH ? " Switch" : ""); /* Ignore pure accelerometers, but accept devices that are * accelerometers with other axes */ if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_ACCELEROMETER)) { evdev_log_info(device, "device is an accelerometer, ignoring\n"); return NULL; } if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) { evdev_disable_accelerometer_axes(device); } if (evdev_device_is_joystick_or_gamepad(device)) { evdev_log_info(device, "device is a joystick or a gamepad, ignoring\n"); return NULL; } if (evdev_reject_device(device)) { evdev_log_info(device, "was rejected\n"); return NULL; } if (!evdev_is_fake_mt_device(device)) evdev_fix_android_mt(device); if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) { evdev_extract_abs_axes(device, udev_tags); if (evdev_is_fake_mt_device(device)) udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN; } if (evdev_device_has_model_quirk(device, QUIRK_MODEL_DELL_CANVAS_TOTEM)) { dispatch = evdev_totem_create(device); device->seat_caps |= EVDEV_DEVICE_TABLET; evdev_log_info(device, "device is a totem\n"); return dispatch; } /* libwacom assigns touchpad (or touchscreen) _and_ tablet to the tablet touch bits, so make sure we don't initialize the tablet interface for the touch device */ tablet_tags = EVDEV_UDEV_TAG_TABLET | EVDEV_UDEV_TAG_TOUCHPAD | EVDEV_UDEV_TAG_TOUCHSCREEN; /* libwacom assigns tablet _and_ tablet_pad to the pad devices */ if (udev_tags & EVDEV_UDEV_TAG_TABLET_PAD) { dispatch = evdev_tablet_pad_create(device); device->seat_caps |= EVDEV_DEVICE_TABLET_PAD; evdev_log_info(device, "device is a tablet pad\n"); return dispatch; } if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) { dispatch = evdev_tablet_create(device); device->seat_caps |= EVDEV_DEVICE_TABLET; evdev_log_info(device, "device is a tablet\n"); return dispatch; } if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) { if (udev_tags & EVDEV_UDEV_TAG_TABLET) evdev_tag_tablet_touchpad(device); /* whether velocity should be averaged, false by default */ device->use_velocity_averaging = evdev_need_velocity_averaging(device); dispatch = evdev_mt_touchpad_create(device); evdev_log_info(device, "device is a touchpad\n"); return dispatch; } if (udev_tags & EVDEV_UDEV_TAG_MOUSE || udev_tags & EVDEV_UDEV_TAG_POINTINGSTICK) { evdev_tag_external_mouse(device, device->udev_device); evdev_tag_trackpoint(device, device->udev_device); if (device->tags & EVDEV_TAG_TRACKPOINT) device->trackpoint_multiplier = evdev_get_trackpoint_multiplier(device); else device->dpi = evdev_read_dpi_prop(device); /* whether velocity should be averaged, false by default */ device->use_velocity_averaging = evdev_need_velocity_averaging(device); device->seat_caps |= EVDEV_DEVICE_POINTER; evdev_log_info(device, "device is a pointer\n"); /* want left-handed config option */ device->left_handed.want_enabled = true; /* want natural-scroll config option */ device->scroll.natural_scrolling_enabled = true; /* want button scrolling config option */ if (libevdev_has_event_code(evdev, EV_REL, REL_X) || libevdev_has_event_code(evdev, EV_REL, REL_Y)) device->scroll.want_button = 1; } if (udev_tags & EVDEV_UDEV_TAG_KEYBOARD) { device->seat_caps |= EVDEV_DEVICE_KEYBOARD; evdev_log_info(device, "device is a keyboard\n"); /* want natural-scroll config option */ if (libevdev_has_event_code(evdev, EV_REL, REL_WHEEL) || libevdev_has_event_code(evdev, EV_REL, REL_HWHEEL)) { device->scroll.natural_scrolling_enabled = true; device->seat_caps |= EVDEV_DEVICE_POINTER; } evdev_tag_keyboard(device, device->udev_device); } if (udev_tags & EVDEV_UDEV_TAG_TOUCHSCREEN) { device->seat_caps |= EVDEV_DEVICE_TOUCH; evdev_log_info(device, "device is a touch device\n"); } if (udev_tags & EVDEV_UDEV_TAG_SWITCH) { if (libevdev_has_event_code(evdev, EV_SW, SW_LID)) { device->seat_caps |= EVDEV_DEVICE_SWITCH; device->tags |= EVDEV_TAG_LID_SWITCH; } if (libevdev_has_event_code(evdev, EV_SW, SW_TABLET_MODE)) { if (evdev_device_has_model_quirk(device, QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE)) { evdev_log_info(device, "device is an unreliable tablet mode switch, filtering events.\n"); libevdev_disable_event_code(device->evdev, EV_SW, SW_TABLET_MODE); } else { device->tags |= EVDEV_TAG_TABLET_MODE_SWITCH; device->seat_caps |= EVDEV_DEVICE_SWITCH; } } if (device->seat_caps & EVDEV_DEVICE_SWITCH) evdev_log_info(device, "device is a switch device\n"); } if (device->seat_caps & EVDEV_DEVICE_POINTER && libevdev_has_event_code(evdev, EV_REL, REL_X) && libevdev_has_event_code(evdev, EV_REL, REL_Y) && !evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) { evdev_log_error(device, "failed to initialize pointer acceleration\n"); return NULL; } if (evdev_device_has_model_quirk(device, QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING)) { device->scroll.invert_horizontal_scrolling = true; } return fallback_dispatch_create(&device->base); } static void evdev_notify_added_device(struct evdev_device *device) { struct libinput_device *dev; list_for_each(dev, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(dev); if (dev == &device->base) continue; /* Notify existing device d about addition of device */ if (d->dispatch->interface->device_added) d->dispatch->interface->device_added(d, device); /* Notify new device about existing device d */ if (device->dispatch->interface->device_added) device->dispatch->interface->device_added(device, d); /* Notify new device if existing device d is suspended */ if (d->is_suspended && device->dispatch->interface->device_suspended) device->dispatch->interface->device_suspended(device, d); } notify_added_device(&device->base); if (device->dispatch->interface->post_added) device->dispatch->interface->post_added(device, device->dispatch); } static bool evdev_device_have_same_syspath(struct udev_device *udev_device, int fd) { struct udev *udev = udev_device_get_udev(udev_device); struct udev_device *udev_device_new = NULL; struct stat st; bool rc = false; if (fstat(fd, &st) < 0) goto out; udev_device_new = udev_device_new_from_devnum(udev, 'c', st.st_rdev); if (!udev_device_new) goto out; rc = streq(udev_device_get_syspath(udev_device_new), udev_device_get_syspath(udev_device)); out: if (udev_device_new) udev_device_unref(udev_device_new); return rc; } static bool evdev_set_device_group(struct evdev_device *device, struct udev_device *udev_device) { struct libinput *libinput = evdev_libinput_context(device); struct libinput_device_group *group = NULL; const char *udev_group; udev_group = udev_device_get_property_value(udev_device, "LIBINPUT_DEVICE_GROUP"); if (udev_group) group = libinput_device_group_find_group(libinput, udev_group); if (!group) { group = libinput_device_group_create(libinput, udev_group); if (!group) return false; libinput_device_set_device_group(&device->base, group); libinput_device_group_unref(group); } else { libinput_device_set_device_group(&device->base, group); } return true; } static inline void evdev_drain_fd(int fd) { struct input_event ev[24]; size_t sz = sizeof ev; while (read(fd, &ev, sz) == (int)sz) { /* discard all pending events */ } } static inline void evdev_pre_configure_model_quirks(struct evdev_device *device) { struct quirks_context *quirks; struct quirks *q; const struct quirk_tuples *t; char *prop; /* Touchpad claims to have 4 slots but only ever sends 2 * https://bugs.freedesktop.org/show_bug.cgi?id=98100 */ if (evdev_device_has_model_quirk(device, QUIRK_MODEL_HP_ZBOOK_STUDIO_G3)) libevdev_set_abs_maximum(device->evdev, ABS_MT_SLOT, 1); /* Generally we don't care about MSC_TIMESTAMP and it can cause * unnecessary wakeups but on some devices we need to watch it for * pointer jumps */ quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); if (!q || !quirks_get_string(q, QUIRK_ATTR_MSC_TIMESTAMP, &prop) || !streq(prop, "watch")) { libevdev_disable_event_code(device->evdev, EV_MSC, MSC_TIMESTAMP); } if (quirks_get_tuples(q, QUIRK_ATTR_EVENT_CODE, &t)) { for (size_t i = 0; i < t->ntuples; i++) { const struct input_absinfo absinfo = { .minimum = 0, .maximum = 1, }; int type = t->tuples[i].first; int code = t->tuples[i].second; bool enable = t->tuples[i].third; if (code == EVENT_CODE_UNDEFINED) { if (enable) libevdev_enable_event_type(device->evdev, type); else libevdev_disable_event_type(device->evdev, type); } else { if (enable) libevdev_enable_event_code(device->evdev, type, code, type == EV_ABS ? &absinfo : NULL); else libevdev_disable_event_code(device->evdev, type, code); } evdev_log_debug(device, "quirks: %s %s %s (%#x %#x)\n", enable ? "enabling" : "disabling", libevdev_event_type_get_name(type), libevdev_event_code_get_name(type, code), type, code); } } if (quirks_get_tuples(q, QUIRK_ATTR_INPUT_PROP, &t)) { for (size_t idx = 0; idx < t->ntuples; idx++) { unsigned int p = t->tuples[idx].first; bool enable = t->tuples[idx].second; if (enable) { libevdev_enable_property(device->evdev, p); } else { #if HAVE_LIBEVDEV_DISABLE_PROPERTY libevdev_disable_property(device->evdev, p); #else evdev_log_error(device, "quirks: a quirk for this device requires newer libevdev than installed\n"); #endif } evdev_log_debug(device, "quirks: %s %s (%#x)\n", enable ? "enabling" : "disabling", libevdev_property_get_name(p), p); } } quirks_unref(q); } static void libevdev_log_func(const struct libevdev *evdev, enum libevdev_log_priority priority, void *data, const char *file, int line, const char *func, const char *format, va_list args) { struct libinput *libinput = data; enum libinput_log_priority pri = LIBINPUT_LOG_PRIORITY_ERROR; const char prefix[] = "libevdev: "; char fmt[strlen(format) + strlen(prefix) + 1]; switch (priority) { case LIBEVDEV_LOG_ERROR: pri = LIBINPUT_LOG_PRIORITY_ERROR; break; case LIBEVDEV_LOG_INFO: pri = LIBINPUT_LOG_PRIORITY_INFO; break; case LIBEVDEV_LOG_DEBUG: pri = LIBINPUT_LOG_PRIORITY_DEBUG; break; } snprintf(fmt, sizeof(fmt), "%s%s", prefix, format); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" log_msg_va(libinput, pri, fmt, args); #pragma GCC diagnostic pop } static bool udev_device_should_be_ignored(struct udev_device *udev_device) { const char *value; value = udev_device_get_property_value(udev_device, "LIBINPUT_IGNORE_DEVICE"); return value && !streq(value, "0"); } struct evdev_device * evdev_device_create(struct libinput_seat *seat, struct udev_device *udev_device) { struct libinput *libinput = seat->libinput; struct evdev_device *device = NULL; int rc; int fd = -1; int unhandled_device = 0; const char *devnode = udev_device_get_devnode(udev_device); char *sysname = str_sanitize(udev_device_get_sysname(udev_device)); if (!devnode) { log_info(libinput, "%s: no device node associated\n", sysname); goto err; } if (udev_device_should_be_ignored(udev_device)) { log_debug(libinput, "%s: device is ignored\n", sysname); goto err; } /* Use non-blocking mode so that we can loop on read on * evdev_device_data() until all events on the fd are * read. mtdev_get() also expects this. */ fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK | O_CLOEXEC); if (fd < 0) { log_info(libinput, "%s: opening input device '%s' failed (%s).\n", sysname, devnode, strerror(-fd)); goto err; } if (!evdev_device_have_same_syspath(udev_device, fd)) goto err; device = zalloc(sizeof *device); device->sysname = sysname; sysname = NULL; libinput_device_init(&device->base, seat); libinput_seat_ref(seat); evdev_drain_fd(fd); rc = libevdev_new_from_fd(fd, &device->evdev); if (rc != 0) goto err; libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC); libevdev_set_device_log_function(device->evdev, libevdev_log_func, LIBEVDEV_LOG_ERROR, libinput); device->seat_caps = 0; device->is_mt = 0; device->mtdev = NULL; device->udev_device = udev_device_ref(udev_device); device->dispatch = NULL; device->fd = fd; device->devname = libevdev_get_name(device->evdev); /* the log_prefix_name is used as part of a printf format string and * must not contain % directives, see evdev_log_msg */ device->log_prefix_name = str_sanitize(device->devname); device->scroll.threshold = 5.0; /* Default may be overridden */ device->scroll.direction_lock_threshold = 5.0; /* Default may be overridden */ device->scroll.direction = 0; device->scroll.wheel_click_angle = evdev_read_wheel_click_props(device); device->model_flags = evdev_read_model_flags(device); device->dpi = DEFAULT_MOUSE_DPI; /* at most 5 SYN_DROPPED log-messages per 30s */ ratelimit_init(&device->syn_drop_limit, s2us(30), 5); /* at most 5 "delayed processing" log messages per hour */ ratelimit_init(&device->delay_warning_limit, s2us(60 * 60), 5); /* at most 5 log-messages per 5s */ ratelimit_init(&device->nonpointer_rel_limit, s2us(5), 5); matrix_init_identity(&device->abs.calibration); matrix_init_identity(&device->abs.usermatrix); matrix_init_identity(&device->abs.default_calibration); evdev_pre_configure_model_quirks(device); device->dispatch = evdev_configure_device(device); if (device->dispatch == NULL || device->seat_caps == 0) goto err; device->source = libinput_add_fd(libinput, fd, evdev_device_dispatch, device); if (!device->source) goto err; if (!evdev_set_device_group(device, udev_device)) goto err; list_insert(seat->devices_list.prev, &device->base.link); evdev_notify_added_device(device); return device; err: if (fd >= 0) { close_restricted(libinput, fd); if (device) { unhandled_device = device->seat_caps == 0; evdev_device_destroy(device); } } free(sysname); return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL; } const char * evdev_device_get_output(struct evdev_device *device) { return device->output_name; } const char * evdev_device_get_sysname(struct evdev_device *device) { return device->sysname; } const char * evdev_device_get_name(struct evdev_device *device) { return device->devname; } unsigned int evdev_device_get_id_bustype(struct evdev_device *device) { return libevdev_get_id_bustype(device->evdev); } unsigned int evdev_device_get_id_product(struct evdev_device *device) { return libevdev_get_id_product(device->evdev); } unsigned int evdev_device_get_id_vendor(struct evdev_device *device) { return libevdev_get_id_vendor(device->evdev); } struct udev_device * evdev_device_get_udev_device(struct evdev_device *device) { return udev_device_ref(device->udev_device); } void evdev_device_set_default_calibration(struct evdev_device *device, const float calibration[6]) { matrix_from_farray6(&device->abs.default_calibration, calibration); evdev_device_calibrate(device, calibration); } void evdev_device_calibrate(struct evdev_device *device, const float calibration[6]) { struct matrix scale, translate, transform; double sx, sy; matrix_from_farray6(&transform, calibration); device->abs.apply_calibration = !matrix_is_identity(&transform); /* back up the user matrix so we can return it on request */ matrix_from_farray6(&device->abs.usermatrix, calibration); if (!device->abs.apply_calibration) { matrix_init_identity(&device->abs.calibration); return; } sx = absinfo_range(device->abs.absinfo_x); sy = absinfo_range(device->abs.absinfo_y); /* The transformation matrix is in the form: * [ a b c ] * [ d e f ] * [ 0 0 1 ] * Where a, e are the scale components, a, b, d, e are the rotation * component (combined with scale) and c and f are the translation * component. The translation component in the input matrix must be * normalized to multiples of the device width and height, * respectively. e.g. c == 1 shifts one device-width to the right. * * We pre-calculate a single matrix to apply to event coordinates: * M = Un-Normalize * Calibration * Normalize * * Normalize: scales the device coordinates to [0,1] * Calibration: user-supplied matrix * Un-Normalize: scales back up to device coordinates * Matrix maths requires the normalize/un-normalize in reverse * order. */ /* Un-Normalize */ matrix_init_translate(&translate, device->abs.absinfo_x->minimum, device->abs.absinfo_y->minimum); matrix_init_scale(&scale, sx, sy); matrix_mult(&scale, &translate, &scale); /* Calibration */ matrix_mult(&transform, &scale, &transform); /* Normalize */ matrix_init_translate(&translate, -device->abs.absinfo_x->minimum/sx, -device->abs.absinfo_y->minimum/sy); matrix_init_scale(&scale, 1.0/sx, 1.0/sy); matrix_mult(&scale, &translate, &scale); /* store final matrix in device */ matrix_mult(&device->abs.calibration, &transform, &scale); } void evdev_read_calibration_prop(struct evdev_device *device) { const char *prop; float calibration[6]; prop = udev_device_get_property_value(device->udev_device, "LIBINPUT_CALIBRATION_MATRIX"); if (prop == NULL) return; if (!device->abs.absinfo_x || !device->abs.absinfo_y) return; if (!parse_calibration_property(prop, calibration)) return; evdev_device_set_default_calibration(device, calibration); evdev_log_info(device, "applying calibration: %f %f %f %f %f %f\n", calibration[0], calibration[1], calibration[2], calibration[3], calibration[4], calibration[5]); } int evdev_read_fuzz_prop(struct evdev_device *device, unsigned int code) { const char *prop; char name[32]; int rc; int fuzz = 0; const struct input_absinfo *abs; rc = snprintf(name, sizeof(name), "LIBINPUT_FUZZ_%02x", code); if (rc == -1) return 0; prop = udev_device_get_property_value(device->udev_device, name); if (prop && (safe_atoi(prop, &fuzz) == false || fuzz < 0)) { evdev_log_bug_libinput(device, "invalid LIBINPUT_FUZZ property value: %s\n", prop); return 0; } /* The udev callout should have set the kernel fuzz to zero. * If the kernel fuzz is nonzero, something has gone wrong there, so * let's complain but still use a fuzz of zero for our view of the * device. Otherwise, the kernel will use the nonzero fuzz, we then * use the same fuzz on top of the pre-fuzzed data and that leads to * unresponsive behaviur. */ abs = libevdev_get_abs_info(device->evdev, code); if (!abs || abs->fuzz == 0) return fuzz; if (prop) { evdev_log_bug_libinput(device, "kernel fuzz of %d even with LIBINPUT_FUZZ_%02x present\n", abs->fuzz, code); } else { evdev_log_bug_libinput(device, "kernel fuzz of %d but LIBINPUT_FUZZ_%02x is missing\n", abs->fuzz, code); } return 0; } bool evdev_device_has_capability(struct evdev_device *device, enum libinput_device_capability capability) { switch (capability) { case LIBINPUT_DEVICE_CAP_POINTER: return !!(device->seat_caps & EVDEV_DEVICE_POINTER); case LIBINPUT_DEVICE_CAP_KEYBOARD: return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD); case LIBINPUT_DEVICE_CAP_TOUCH: return !!(device->seat_caps & EVDEV_DEVICE_TOUCH); case LIBINPUT_DEVICE_CAP_GESTURE: return !!(device->seat_caps & EVDEV_DEVICE_GESTURE); case LIBINPUT_DEVICE_CAP_TABLET_TOOL: return !!(device->seat_caps & EVDEV_DEVICE_TABLET); case LIBINPUT_DEVICE_CAP_TABLET_PAD: return !!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD); case LIBINPUT_DEVICE_CAP_SWITCH: return !!(device->seat_caps & EVDEV_DEVICE_SWITCH); default: return false; } } int evdev_device_get_size(const struct evdev_device *device, double *width, double *height) { const struct input_absinfo *x, *y; x = libevdev_get_abs_info(device->evdev, ABS_X); y = libevdev_get_abs_info(device->evdev, ABS_Y); if ((x && x->minimum == 0 && x->maximum == 1) || (y && y->minimum == 0 && y->maximum == 1)) return -1; if (!x || !y || device->abs.is_fake_resolution || !x->resolution || !y->resolution) return -1; *width = absinfo_convert_to_mm(x, x->maximum); *height = absinfo_convert_to_mm(y, y->maximum); return 0; } int evdev_device_has_button(struct evdev_device *device, uint32_t code) { if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) return -1; return libevdev_has_event_code(device->evdev, EV_KEY, code); } int evdev_device_has_key(struct evdev_device *device, uint32_t code) { if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD)) return -1; return libevdev_has_event_code(device->evdev, EV_KEY, code); } int evdev_device_get_touch_count(struct evdev_device *device) { int ntouches; if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return -1; ntouches = libevdev_get_num_slots(device->evdev); if (ntouches == -1) { /* mtdev devices have multitouch but we don't know * how many. Otherwise, any touch device with num_slots of * -1 is a single-touch device */ if (device->mtdev) ntouches = 0; else ntouches = 1; } return ntouches; } int evdev_device_has_switch(struct evdev_device *device, enum libinput_switch sw) { unsigned int code; if (!(device->seat_caps & EVDEV_DEVICE_SWITCH)) return -1; switch (sw) { case LIBINPUT_SWITCH_LID: code = SW_LID; break; case LIBINPUT_SWITCH_TABLET_MODE: code = SW_TABLET_MODE; break; default: return -1; } return libevdev_has_event_code(device->evdev, EV_SW, code); } static inline bool evdev_is_scrolling(const struct evdev_device *device, enum libinput_pointer_axis axis) { assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL || axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); return (device->scroll.direction & bit(axis)) != 0; } static inline void evdev_start_scrolling(struct evdev_device *device, enum libinput_pointer_axis axis) { assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL || axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); device->scroll.direction |= bit(axis); } void evdev_post_scroll(struct evdev_device *device, uint64_t time, enum libinput_pointer_axis_source source, const struct normalized_coords *delta) { const struct normalized_coords *trigger; struct normalized_coords event; if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) device->scroll.buildup.y += delta->y; if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) device->scroll.buildup.x += delta->x; trigger = &device->scroll.buildup; /* If we're not scrolling yet, use a distance trigger: moving past a certain distance starts scrolling */ if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) && !evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { if (fabs(trigger->y) >= device->scroll.threshold) evdev_start_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); if (fabs(trigger->x) >= device->scroll.threshold) evdev_start_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); /* We're already scrolling in one direction. Require some trigger speed to start scrolling in the other direction */ } else if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { if (fabs(delta->y) >= device->scroll.direction_lock_threshold) evdev_start_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); } else if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { if (fabs(delta->x) >= device->scroll.direction_lock_threshold) evdev_start_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); } event = *delta; /* We use the trigger to enable, but the delta from this event for * the actual scroll movement. Otherwise we get a jump once * scrolling engages */ if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) event.y = 0.0; if (!evdev_is_scrolling(device, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) event.x = 0.0; if (!normalized_is_zero(event)) { uint32_t axes = device->scroll.direction; if (event.y == 0.0) axes &= ~bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); if (event.x == 0.0) axes &= ~bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); switch (source) { case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: evdev_notify_axis_finger(device, time, axes, &event); break; case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: evdev_notify_axis_continous(device, time, axes, &event); break; default: evdev_log_bug_libinput(device, "Posting invalid scroll source %d\n", source); break; } } } void evdev_stop_scroll(struct evdev_device *device, uint64_t time, enum libinput_pointer_axis_source source) { const struct normalized_coords zero = { 0.0, 0.0 }; /* terminate scrolling with a zero scroll event */ if (device->scroll.direction != 0) { switch (source) { case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: pointer_notify_axis_finger(&device->base, time, device->scroll.direction, &zero); break; case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: pointer_notify_axis_continuous(&device->base, time, device->scroll.direction, &zero); break; default: evdev_log_bug_libinput(device, "Stopping invalid scroll source %d\n", source); break; } } device->scroll.buildup.x = 0; device->scroll.buildup.y = 0; device->scroll.direction = 0; } void evdev_notify_suspended_device(struct evdev_device *device) { struct libinput_device *it; if (device->is_suspended) return; list_for_each(it, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(it); if (it == &device->base) continue; if (d->dispatch->interface->device_suspended) d->dispatch->interface->device_suspended(d, device); } device->is_suspended = true; } void evdev_notify_resumed_device(struct evdev_device *device) { struct libinput_device *it; if (!device->is_suspended) return; list_for_each(it, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(it); if (it == &device->base) continue; if (d->dispatch->interface->device_resumed) d->dispatch->interface->device_resumed(d, device); } device->is_suspended = false; } void evdev_device_suspend(struct evdev_device *device) { struct libinput *libinput = evdev_libinput_context(device); evdev_notify_suspended_device(device); if (device->dispatch->interface->suspend) device->dispatch->interface->suspend(device->dispatch, device); if (device->source) { libinput_remove_source(libinput, device->source); device->source = NULL; } if (device->mtdev) { mtdev_close_delete(device->mtdev); device->mtdev = NULL; } if (device->fd != -1) { close_restricted(libinput, device->fd); device->fd = -1; } } int evdev_device_resume(struct evdev_device *device) { struct libinput *libinput = evdev_libinput_context(device); int fd; const char *devnode; struct input_event ev; enum libevdev_read_status status; if (device->fd != -1) return 0; if (device->was_removed) return -ENODEV; devnode = udev_device_get_devnode(device->udev_device); if (!devnode) return -ENODEV; fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK | O_CLOEXEC); if (fd < 0) return -errno; if (!evdev_device_have_same_syspath(device->udev_device, fd)) { close_restricted(libinput, fd); return -ENODEV; } evdev_drain_fd(fd); device->fd = fd; if (evdev_need_mtdev(device)) { device->mtdev = mtdev_new_open(device->fd); if (!device->mtdev) return -ENODEV; } libevdev_change_fd(device->evdev, fd); libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC); /* re-sync libevdev's view of the device, but discard the actual events. Our device is in a neutral state already */ libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); do { status = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_SYNC, &ev); } while (status == LIBEVDEV_READ_STATUS_SYNC); device->source = libinput_add_fd(libinput, fd, evdev_device_dispatch, device); if (!device->source) { mtdev_close_delete(device->mtdev); return -ENOMEM; } evdev_notify_resumed_device(device); return 0; } void evdev_device_remove(struct evdev_device *device) { struct libinput_device *dev; evdev_log_info(device, "device removed\n"); libinput_timer_cancel(&device->scroll.timer); libinput_timer_cancel(&device->middlebutton.timer); list_for_each(dev, &device->base.seat->devices_list, link) { struct evdev_device *d = evdev_device(dev); if (dev == &device->base) continue; if (d->dispatch->interface->device_removed) d->dispatch->interface->device_removed(d, device); } evdev_device_suspend(device); if (device->dispatch->interface->remove) device->dispatch->interface->remove(device->dispatch); /* A device may be removed while suspended, mark it to * skip re-opening a different device with the same node */ device->was_removed = true; list_remove(&device->base.link); notify_removed_device(&device->base); libinput_device_unref(&device->base); } void evdev_device_destroy(struct evdev_device *device) { struct evdev_dispatch *dispatch; dispatch = device->dispatch; if (dispatch) dispatch->interface->destroy(dispatch); if (device->base.group) libinput_device_group_unref(device->base.group); free(device->log_prefix_name); free(device->sysname); free(device->output_name); filter_destroy(device->pointer.filter); libinput_timer_destroy(&device->scroll.timer); libinput_timer_destroy(&device->middlebutton.timer); libinput_seat_unref(device->base.seat); libevdev_free(device->evdev); udev_device_unref(device->udev_device); free(device); } libinput-1.28.1/src/evdev.h000066400000000000000000000723261477265155700155370ustar00rootroot00000000000000/* * Copyright © 2011, 2012 Intel Corporation * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef EVDEV_H #define EVDEV_H #include "config.h" #include #include #include "linux/input.h" #include #include "libinput-private.h" #include "timer.h" #include "filter.h" #include "quirks.h" #include "util-input-event.h" /* The fake resolution value for abs devices without resolution */ #define EVDEV_FAKE_RESOLUTION 1 enum evdev_event_type { EVDEV_NONE, EVDEV_ABSOLUTE_TOUCH_DOWN = bit(0), EVDEV_ABSOLUTE_MOTION = bit(1), EVDEV_ABSOLUTE_TOUCH_UP = bit(2), EVDEV_ABSOLUTE_MT = bit(3), EVDEV_WHEEL = bit(4), EVDEV_KEY = bit(5), EVDEV_RELATIVE_MOTION = bit(6), EVDEV_BUTTON = bit(7), }; enum evdev_device_seat_capability { EVDEV_DEVICE_POINTER = bit(0), EVDEV_DEVICE_KEYBOARD = bit(1), EVDEV_DEVICE_TOUCH = bit(2), EVDEV_DEVICE_TABLET = bit(3), EVDEV_DEVICE_TABLET_PAD = bit(4), EVDEV_DEVICE_GESTURE = bit(5), EVDEV_DEVICE_SWITCH = bit(6), }; enum evdev_device_tags { EVDEV_TAG_EXTERNAL_MOUSE = bit(0), EVDEV_TAG_INTERNAL_TOUCHPAD = bit(1), EVDEV_TAG_EXTERNAL_TOUCHPAD = bit(2), EVDEV_TAG_TRACKPOINT = bit(3), EVDEV_TAG_KEYBOARD = bit(4), EVDEV_TAG_LID_SWITCH = bit(5), EVDEV_TAG_INTERNAL_KEYBOARD = bit(6), EVDEV_TAG_EXTERNAL_KEYBOARD = bit(7), EVDEV_TAG_TABLET_MODE_SWITCH = bit(8), EVDEV_TAG_TABLET_TOUCHPAD = bit(9), }; enum evdev_middlebutton_state { MIDDLEBUTTON_IDLE, MIDDLEBUTTON_LEFT_DOWN, MIDDLEBUTTON_RIGHT_DOWN, MIDDLEBUTTON_MIDDLE, MIDDLEBUTTON_LEFT_UP_PENDING, MIDDLEBUTTON_RIGHT_UP_PENDING, MIDDLEBUTTON_IGNORE_LR, MIDDLEBUTTON_IGNORE_L, MIDDLEBUTTON_IGNORE_R, MIDDLEBUTTON_PASSTHROUGH, }; enum evdev_middlebutton_event { MIDDLEBUTTON_EVENT_L_DOWN, MIDDLEBUTTON_EVENT_R_DOWN, MIDDLEBUTTON_EVENT_OTHER, MIDDLEBUTTON_EVENT_L_UP, MIDDLEBUTTON_EVENT_R_UP, MIDDLEBUTTON_EVENT_TIMEOUT, MIDDLEBUTTON_EVENT_ALL_UP, }; /** * model flags are used as shortcut for quirks that need to be checked * multiple times in timing-sensitive paths. For quirks that need to be * checked only once, use the quirk directly. */ enum evdev_device_model { EVDEV_MODEL_DEFAULT = 0, EVDEV_MODEL_WACOM_TOUCHPAD = bit(1), EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD = bit(2), EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD = bit(3), EVDEV_MODEL_LENOVO_T450_TOUCHPAD = bit(4), EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON = bit(5), EVDEV_MODEL_LENOVO_SCROLLPOINT = bit(6), /* udev tags, not true quirks */ EVDEV_MODEL_TEST_DEVICE = bit(20), EVDEV_MODEL_TRACKBALL = bit(21), EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81 = bit(22), }; enum evdev_button_scroll_state { BUTTONSCROLL_IDLE, BUTTONSCROLL_BUTTON_DOWN, /* button is down */ BUTTONSCROLL_READY, /* ready for scroll events */ BUTTONSCROLL_SCROLLING, /* have sent scroll events */ }; enum evdev_button_scroll_lock_state { BUTTONSCROLL_LOCK_DISABLED, BUTTONSCROLL_LOCK_IDLE, BUTTONSCROLL_LOCK_FIRSTDOWN, BUTTONSCROLL_LOCK_FIRSTUP, BUTTONSCROLL_LOCK_SECONDDOWN, }; enum evdev_debounce_state { /** * Initial state, no debounce but monitoring events */ DEBOUNCE_INIT, /** * Bounce detected, future events need debouncing */ DEBOUNCE_NEEDED, /** * Debounce is enabled, but no event is currently being filtered */ DEBOUNCE_ON, /** * Debounce is enabled and we are currently filtering an event */ DEBOUNCE_ACTIVE, }; enum evdev_arbitration_state { ARBITRATION_NOT_ACTIVE, ARBITRATION_IGNORE_ALL, ARBITRATION_IGNORE_RECT, }; struct evdev_device { struct libinput_device base; struct libinput_source *source; struct evdev_dispatch *dispatch; struct libevdev *evdev; struct udev_device *udev_device; char *output_name; const char *devname; char *log_prefix_name; char *sysname; bool was_removed; int fd; enum evdev_device_seat_capability seat_caps; enum evdev_device_tags tags; bool is_mt; bool is_suspended; int dpi; /* HW resolution */ double trackpoint_multiplier; /* trackpoint constant multiplier */ bool use_velocity_averaging; /* whether averaging should be applied on velocity calculation */ struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */ struct ratelimit delay_warning_limit; /* ratelimit for delayd processing logging */ struct ratelimit nonpointer_rel_limit; /* ratelimit for REL_* events from non-pointer devices */ uint32_t model_flags; struct mtdev *mtdev; struct { const struct input_absinfo *absinfo_x, *absinfo_y; bool is_fake_resolution; int apply_calibration; struct matrix calibration; struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */ struct matrix usermatrix; /* as supplied by the caller */ struct device_coords dimensions; struct { struct device_coords min, max; struct ratelimit range_warn_limit; } warning_range; } abs; struct { struct libinput_timer timer; struct libinput_device_config_scroll_method config; /* Currently enabled method, button */ enum libinput_config_scroll_method method; uint32_t button; uint64_t button_down_time; /* set during device init, used at runtime to delay changes * until all buttons are up */ enum libinput_config_scroll_method want_method; uint32_t want_button; /* Checks if buttons are down and commits the setting */ void (*change_scroll_method)(struct evdev_device *device); enum evdev_button_scroll_state button_scroll_state; double threshold; double direction_lock_threshold; uint32_t direction; struct normalized_coords buildup; struct libinput_device_config_natural_scroll config_natural; /* set during device init if we want natural scrolling, * used at runtime to enable/disable the feature */ bool natural_scrolling_enabled; /* set during device init to invert direction of * horizontal scrolling */ bool invert_horizontal_scrolling; /* angle per REL_WHEEL click in degrees */ struct wheel_angle wheel_click_angle; enum evdev_button_scroll_lock_state lock_state; bool want_lock_enabled; bool lock_enabled; } scroll; struct { struct libinput_device_config_accel config; struct motion_filter *filter; } pointer; /* Key counter used for multiplexing button events internally in * libinput. */ uint8_t key_count[KEY_CNT]; struct { struct libinput_device_config_left_handed config; /* left-handed currently enabled */ bool enabled; /* set during device init if we want left_handed config, * used at runtime to delay the effect until buttons are up */ bool want_enabled; /* Checks if buttons are down and commits the setting */ void (*change_to_enabled)(struct evdev_device *device); } left_handed; struct { struct libinput_device_config_middle_emulation config; /* middle-button emulation enabled */ bool enabled; bool enabled_default; bool want_enabled; enum evdev_middlebutton_state state; struct libinput_timer timer; uint32_t button_mask; uint64_t first_event_time; } middlebutton; }; static inline struct evdev_device * evdev_device(struct libinput_device *device) { return container_of(device, struct evdev_device, base); } #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1) struct evdev_dispatch; struct evdev_dispatch_interface { /* Process an evdev input event. */ void (*process)(struct evdev_dispatch *dispatch, struct evdev_device *device, struct input_event *event, uint64_t time); /* Device is being suspended */ void (*suspend)(struct evdev_dispatch *dispatch, struct evdev_device *device); /* Device is being removed (may be NULL) */ void (*remove)(struct evdev_dispatch *dispatch); /* Destroy an event dispatch handler and free all its resources. */ void (*destroy)(struct evdev_dispatch *dispatch); /* A new device was added */ void (*device_added)(struct evdev_device *device, struct evdev_device *added_device); /* A device was removed */ void (*device_removed)(struct evdev_device *device, struct evdev_device *removed_device); /* A device was suspended */ void (*device_suspended)(struct evdev_device *device, struct evdev_device *suspended_device); /* A device was resumed */ void (*device_resumed)(struct evdev_device *device, struct evdev_device *resumed_device); /* Called immediately after the LIBINPUT_EVENT_DEVICE_ADDED event * was sent */ void (*post_added)(struct evdev_device *device, struct evdev_dispatch *dispatch); /* For touch arbitration, called on the device that should * enable/disable touch capabilities. */ void (*touch_arbitration_toggle)(struct evdev_dispatch *dispatch, struct evdev_device *device, enum evdev_arbitration_state which, const struct phys_rect *rect, /* may be NULL */ uint64_t now); /* Called when touch arbitration is on, updates the area where touch * arbitration should apply. */ void (*touch_arbitration_update_rect)(struct evdev_dispatch *dispatch, struct evdev_device *device, const struct phys_rect *rect, uint64_t now); /* Return the state of the given switch */ enum libinput_switch_state (*get_switch_state)(struct evdev_dispatch *dispatch, enum libinput_switch which); void (*left_handed_toggle)(struct evdev_dispatch *dispatch, struct evdev_device *device, bool left_handed_enabled); }; enum evdev_dispatch_type { DISPATCH_FALLBACK, DISPATCH_TOUCHPAD, DISPATCH_TABLET, DISPATCH_TABLET_PAD, DISPATCH_TOTEM, }; struct evdev_dispatch { enum evdev_dispatch_type dispatch_type; struct evdev_dispatch_interface *interface; struct { struct libinput_device_config_send_events config; enum libinput_config_send_events_mode current_mode; } sendevents; }; static inline void evdev_verify_dispatch_type(struct evdev_dispatch *dispatch, enum evdev_dispatch_type type) { if (dispatch->dispatch_type != type) abort(); } struct evdev_device * evdev_device_create(struct libinput_seat *seat, struct udev_device *device); static inline struct libinput * evdev_libinput_context(const struct evdev_device *device) { return device->base.seat->libinput; } static inline bool evdev_device_has_model_quirk(struct evdev_device *device, enum quirk model_quirk) { struct quirks_context *quirks; struct quirks *q; bool result = false; assert(quirk_get_name(model_quirk) != NULL); quirks = evdev_libinput_context(device)->quirks; q = quirks_fetch_for_device(quirks, device->udev_device); quirks_get_bool(q, model_quirk, &result); quirks_unref(q); return result; } void evdev_transform_absolute(struct evdev_device *device, struct device_coords *point); void evdev_transform_relative(struct evdev_device *device, struct device_coords *point); void evdev_init_calibration(struct evdev_device *device, struct libinput_device_config_calibration *calibration); void evdev_read_calibration_prop(struct evdev_device *device); int evdev_read_fuzz_prop(struct evdev_device *device, unsigned int code); enum switch_reliability evdev_read_switch_reliability_prop(struct evdev_device *device); void evdev_init_sendevents(struct evdev_device *device, struct evdev_dispatch *dispatch); void evdev_device_init_pointer_acceleration(struct evdev_device *device, struct motion_filter *filter); struct evdev_dispatch * evdev_touchpad_create(struct evdev_device *device); struct evdev_dispatch * evdev_mt_touchpad_create(struct evdev_device *device); struct evdev_dispatch * evdev_tablet_create(struct evdev_device *device); struct evdev_dispatch * evdev_tablet_pad_create(struct evdev_device *device); struct evdev_dispatch * evdev_lid_switch_dispatch_create(struct evdev_device *device); struct evdev_dispatch * fallback_dispatch_create(struct libinput_device *libinput_device); struct evdev_dispatch * evdev_totem_create(struct evdev_device *device); bool evdev_is_fake_mt_device(struct evdev_device *device); int evdev_need_mtdev(struct evdev_device *device); void evdev_device_led_update(struct evdev_device *device, enum libinput_led leds); int evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size); const char * evdev_device_get_output(struct evdev_device *device); const char * evdev_device_get_sysname(struct evdev_device *device); const char * evdev_device_get_name(struct evdev_device *device); unsigned int evdev_device_get_id_bustype(struct evdev_device *device); unsigned int evdev_device_get_id_product(struct evdev_device *device); unsigned int evdev_device_get_id_vendor(struct evdev_device *device); struct udev_device * evdev_device_get_udev_device(struct evdev_device *device); void evdev_device_set_default_calibration(struct evdev_device *device, const float calibration[6]); void evdev_device_calibrate(struct evdev_device *device, const float calibration[6]); bool evdev_device_has_capability(struct evdev_device *device, enum libinput_device_capability capability); int evdev_device_get_size(const struct evdev_device *device, double *w, double *h); int evdev_device_has_button(struct evdev_device *device, uint32_t code); int evdev_device_has_key(struct evdev_device *device, uint32_t code); int evdev_device_get_touch_count(struct evdev_device *device); int evdev_device_has_switch(struct evdev_device *device, enum libinput_switch sw); int evdev_device_tablet_pad_has_key(struct evdev_device *device, uint32_t code); int evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device); int evdev_device_tablet_pad_get_num_dials(struct evdev_device *device); int evdev_device_tablet_pad_get_num_rings(struct evdev_device *device); int evdev_device_tablet_pad_get_num_strips(struct evdev_device *device); int evdev_device_tablet_pad_get_num_mode_groups(struct evdev_device *device); struct libinput_tablet_pad_mode_group * evdev_device_tablet_pad_get_mode_group(struct evdev_device *device, unsigned int index); enum libinput_switch_state evdev_device_switch_get_state(struct evdev_device *device, enum libinput_switch sw); double evdev_device_transform_x(struct evdev_device *device, double x, uint32_t width); double evdev_device_transform_y(struct evdev_device *device, double y, uint32_t height); void evdev_device_suspend(struct evdev_device *device); int evdev_device_resume(struct evdev_device *device); void evdev_notify_suspended_device(struct evdev_device *device); void evdev_notify_resumed_device(struct evdev_device *device); void evdev_pointer_notify_button(struct evdev_device *device, uint64_t time, unsigned int button, enum libinput_button_state state); void evdev_pointer_notify_physical_button(struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state); void evdev_init_natural_scroll(struct evdev_device *device); void evdev_init_button_scroll(struct evdev_device *device, void (*change_scroll_method)(struct evdev_device *)); void evdev_set_button_scroll_lock_enabled(struct evdev_device *device, bool enabled); int evdev_update_key_down_count(struct evdev_device *device, int code, int pressed); void evdev_notify_axis_legacy_wheel(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in, const struct discrete_coords *discrete_in); void evdev_notify_axis_wheel(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in, const struct wheel_v120 *v120_in); void evdev_notify_axis_finger(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in); void evdev_notify_axis_continous(struct evdev_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta_in); void evdev_post_scroll(struct evdev_device *device, uint64_t time, enum libinput_pointer_axis_source source, const struct normalized_coords *delta); void evdev_stop_scroll(struct evdev_device *device, uint64_t time, enum libinput_pointer_axis_source source); void evdev_device_remove(struct evdev_device *device); void evdev_device_destroy(struct evdev_device *device); bool evdev_middlebutton_filter_button(struct evdev_device *device, uint64_t time, int button, enum libinput_button_state state); void evdev_init_middlebutton(struct evdev_device *device, bool enabled, bool want_config); enum libinput_config_middle_emulation_state evdev_middlebutton_get(struct libinput_device *device); int evdev_middlebutton_is_available(struct libinput_device *device); enum libinput_config_middle_emulation_state evdev_middlebutton_get_default(struct libinput_device *device); static inline struct phys_coords evdev_convert_xy_to_mm(const struct evdev_device *device, int x, int y) { struct phys_coords mm; mm.x = absinfo_convert_to_mm(device->abs.absinfo_x, x); mm.y = absinfo_convert_to_mm(device->abs.absinfo_y, y); return mm; } void evdev_init_left_handed(struct evdev_device *device, void (*change_to_left_handed)(struct evdev_device *)); static inline uint32_t evdev_to_left_handed(struct evdev_device *device, uint32_t button) { if (device->left_handed.enabled) { if (button == BTN_LEFT) return BTN_RIGHT; else if (button == BTN_RIGHT) return BTN_LEFT; } return button; } /** * Apply a hysteresis filtering to the coordinate in, based on the current * hysteresis center and the margin. If 'in' is within 'margin' of center, * return the center (and thus filter the motion). If 'in' is outside, * return a point on the edge of the new margin (which is an ellipse, usually * a circle). So for a point x in the space outside c + margin we return r: * ,---. ,---. * | c | x → | r x * `---' `---' * * The effect of this is that initial small motions are filtered. Once we * move into one direction we lag the real coordinates by 'margin' but any * movement that continues into that direction will always be just outside * margin - we get responsive movement. Once we move back into the other * direction, the first movements are filtered again. * * Returning the edge rather than the point avoids cursor jumps, as the * first reachable coordinate is the point next to the center (center + 1). * Otherwise, the center has a dead zone of size margin around it and the * first reachable point is the margin edge. * * @param in The input coordinate * @param center Current center of the hysteresis * @param margin Hysteresis width (on each side) * * @return The new center of the hysteresis */ static inline struct device_coords evdev_hysteresis(const struct device_coords *in, const struct device_coords *center, const struct device_coords *margin) { int dx = in->x - center->x; int dy = in->y - center->y; int dx2 = dx * dx; int dy2 = dy * dy; int a = margin->x; int b = margin->y; double normalized_finger_distance, finger_distance, margin_distance; double lag_x, lag_y; struct device_coords result; if (!a || !b) return *in; /* * Basic equation for an ellipse of radii a,b: * x²/a² + y²/b² = 1 * But we start by making a scaled ellipse passing through the * relative finger location (dx,dy). So the scale of this ellipse is * the ratio of finger_distance to margin_distance: * dx²/a² + dy²/b² = normalized_finger_distance² */ normalized_finger_distance = sqrt((double)dx2 / (a * a) + (double)dy2 / (b * b)); /* Which means anything less than 1 is within the elliptical margin */ if (normalized_finger_distance < 1.0) return *center; finger_distance = sqrt(dx2 + dy2); margin_distance = finger_distance / normalized_finger_distance; /* * Now calculate the x,y coordinates on the edge of the margin ellipse * where it intersects the finger vector. Shortcut: We achieve this by * finding the point with the same gradient as dy/dx. */ if (dx) { double gradient = (double)dy / dx; lag_x = margin_distance / sqrt(gradient * gradient + 1); lag_y = sqrt((margin_distance + lag_x) * (margin_distance - lag_x)); } else { /* Infinite gradient */ lag_x = 0.0; lag_y = margin_distance; } /* * 'result' is the centre of an ellipse (radii a,b) which has been * dragged by the finger moving inside it to 'in'. The finger is now * touching the margin ellipse at some point: (±lag_x,±lag_y) */ result.x = (dx >= 0) ? in->x - lag_x : in->x + lag_x; result.y = (dy >= 0) ? in->y - lag_y : in->y + lag_y; return result; } LIBINPUT_ATTRIBUTE_PRINTF(3, 4) static inline void evdev_log_msg(struct evdev_device *device, enum libinput_log_priority priority, const char *format, ...) { va_list args; char buf[1024]; if (!is_logged(evdev_libinput_context(device), priority)) return; /* Anything info and above is user-visible, use the device name */ snprintf(buf, sizeof(buf), "%-7s - %s%s%s", evdev_device_get_sysname(device), (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "", (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "", format); va_start(args, format); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" log_msg_va(evdev_libinput_context(device), priority, buf, args); #pragma GCC diagnostic pop va_end(args); } LIBINPUT_ATTRIBUTE_PRINTF(4, 5) static inline void evdev_log_msg_ratelimit(struct evdev_device *device, struct ratelimit *ratelimit, enum libinput_log_priority priority, const char *format, ...) { va_list args; char buf[1024]; enum ratelimit_state state; if (!is_logged(evdev_libinput_context(device), priority)) return; state = ratelimit_test(ratelimit); if (state == RATELIMIT_EXCEEDED) return; /* Anything info and above is user-visible, use the device name */ snprintf(buf, sizeof(buf), "%-7s - %s%s%s", evdev_device_get_sysname(device), (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "", (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "", format); va_start(args, format); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" log_msg_va(evdev_libinput_context(device), priority, buf, args); #pragma GCC diagnostic pop va_end(args); if (state == RATELIMIT_THRESHOLD) { struct human_time ht = to_human_time(ratelimit->interval); evdev_log_msg(device, priority, "WARNING: log rate limit exceeded (%d msgs per %d%s). " "Discarding future messages.\n", ratelimit->burst, ht.value, ht.unit); } } #define evdev_log_debug(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) #define evdev_log_info(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) #define evdev_log_error(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) #define evdev_log_bug_kernel(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) #define evdev_log_bug_libinput(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) #define evdev_log_bug_client(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) #define evdev_log_debug_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) #define evdev_log_info_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) #define evdev_log_error_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) #define evdev_log_bug_kernel_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) #define evdev_log_bug_libinput_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) #define evdev_log_bug_client_ratelimit(d_, r_, ...) \ evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) /** * Convert the pair of delta coordinates in device space to mm. */ static inline struct phys_coords evdev_device_unit_delta_to_mm(const struct evdev_device* device, const struct device_coords *units) { struct phys_coords mm = { 0, 0 }; const struct input_absinfo *absx, *absy; if (device->abs.absinfo_x == NULL || device->abs.absinfo_y == NULL) { log_bug_libinput(evdev_libinput_context(device), "%s: is not an abs device\n", device->devname); return mm; } absx = device->abs.absinfo_x; absy = device->abs.absinfo_y; mm.x = 1.0 * units->x/absx->resolution; mm.y = 1.0 * units->y/absy->resolution; return mm; } /** * Convert the pair of coordinates in device space to mm. This takes the * axis min into account, i.e. a unit of min is equivalent to 0 mm. */ static inline struct phys_coords evdev_device_units_to_mm(const struct evdev_device* device, const struct device_coords *units) { struct phys_coords mm = { 0, 0 }; const struct input_absinfo *absx, *absy; if (device->abs.absinfo_x == NULL || device->abs.absinfo_y == NULL) { log_bug_libinput(evdev_libinput_context(device), "%s: is not an abs device\n", device->devname); return mm; } absx = device->abs.absinfo_x; absy = device->abs.absinfo_y; mm.x = (units->x - absx->minimum)/absx->resolution; mm.y = (units->y - absy->minimum)/absy->resolution; return mm; } /** * Convert the pair of coordinates in mm to device units. This takes the * axis min into account, i.e. 0 mm is equivalent to the min. */ static inline struct device_coords evdev_device_mm_to_units(const struct evdev_device *device, const struct phys_coords *mm) { struct device_coords units = { 0, 0 }; const struct input_absinfo *absx, *absy; if (device->abs.absinfo_x == NULL || device->abs.absinfo_y == NULL) { log_bug_libinput(evdev_libinput_context(device), "%s: is not an abs device\n", device->devname); return units; } absx = device->abs.absinfo_x; absy = device->abs.absinfo_y; units.x = mm->x * absx->resolution + absx->minimum; units.y = mm->y * absy->resolution + absy->minimum; return units; } static inline struct device_coord_rect evdev_phys_rect_to_units(const struct evdev_device *device, const struct phys_rect *mm) { struct device_coord_rect units = {0}; const struct input_absinfo *absx, *absy; if (device->abs.absinfo_x == NULL || device->abs.absinfo_y == NULL) { log_bug_libinput(evdev_libinput_context(device), "%s: is not an abs device\n", device->devname); return units; } absx = device->abs.absinfo_x; absy = device->abs.absinfo_y; units.x = mm->x * absx->resolution + absx->minimum; units.y = mm->y * absy->resolution + absy->minimum; units.w = mm->w * absx->resolution; units.h = mm->h * absy->resolution; return units; } static inline void evdev_device_init_abs_range_warnings(struct evdev_device *device) { const struct input_absinfo *x, *y; int width, height; x = device->abs.absinfo_x; y = device->abs.absinfo_y; width = device->abs.dimensions.x; height = device->abs.dimensions.y; device->abs.warning_range.min.x = x->minimum - 0.05 * width; device->abs.warning_range.min.y = y->minimum - 0.05 * height; device->abs.warning_range.max.x = x->maximum + 0.05 * width; device->abs.warning_range.max.y = y->maximum + 0.05 * height; /* One warning every 5 min is enough */ ratelimit_init(&device->abs.warning_range.range_warn_limit, s2us(3000), 1); } static inline void evdev_device_check_abs_axis_range(struct evdev_device *device, unsigned int code, int value) { int min, max; switch(code) { case ABS_X: case ABS_MT_POSITION_X: min = device->abs.warning_range.min.x; max = device->abs.warning_range.max.x; break; case ABS_Y: case ABS_MT_POSITION_Y: min = device->abs.warning_range.min.y; max = device->abs.warning_range.max.y; break; default: return; } if (value < min || value > max) { log_info_ratelimit(evdev_libinput_context(device), &device->abs.warning_range.range_warn_limit, "Axis %#x value %d is outside expected range [%d, %d]\n" "See %s/absolute_coordinate_ranges.html for details\n", code, value, min, max, HTTP_DOC_LINK); } } struct evdev_paired_keyboard { struct list link; struct evdev_device *device; struct libinput_event_listener listener; }; static inline void evdev_paired_keyboard_destroy(struct evdev_paired_keyboard *kbd) { kbd->device = NULL; libinput_device_remove_event_listener(&kbd->listener); list_remove(&kbd->link); free(kbd); } #endif /* EVDEV_H */ libinput-1.28.1/src/filter-custom.c000066400000000000000000000314051477265155700172070ustar00rootroot00000000000000/* * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "filter-private.h" #define MOTION_TIMEOUT ms2us(1000) #define FIRST_MOTION_TIME_INTERVAL ms2us(7) /* random but good enough interval for very first event */ struct custom_accel_function { uint64_t last_time; double step; size_t npoints; double points[]; }; static struct custom_accel_function * create_custom_accel_function(double step, const double *points, size_t npoints) { if (npoints < LIBINPUT_ACCEL_NPOINTS_MIN || npoints > LIBINPUT_ACCEL_NPOINTS_MAX) return NULL; if (step <= 0 || step > LIBINPUT_ACCEL_STEP_MAX) return NULL; for (size_t idx = 0; idx < npoints; idx++) { if (points[idx] < LIBINPUT_ACCEL_POINT_MIN_VALUE || points[idx] > LIBINPUT_ACCEL_POINT_MAX_VALUE) return NULL; } struct custom_accel_function *cf = zalloc(sizeof(*cf) + npoints * sizeof(*points)); cf->last_time = 0; cf->step = step; cf->npoints = npoints; memcpy(cf->points, points, sizeof(*points) * npoints); return cf; } static void custom_accel_function_destroy(struct custom_accel_function *cf) { if (cf == NULL) return; free(cf); } static double custom_accel_function_calculate_speed(struct custom_accel_function *cf, const struct device_float_coords *unaccelerated, uint64_t time) { /* Although most devices have a constant polling rate, and for fast * movements these distances do represent the actual speed, * for slow movements it is not the case. * * Since all devices have a finite resolution, real world events * for a slow smooth movement could look like: * Event 1 - (0, 1) - time 0 * Event 2 - (0, 0) - time 7 - filtered (zero event) * Event 3 - (1, 0) - time 14 * Event 4 - (0, 0) - time 21 - filtered (zero event) * Event 5 - (0, 0) - time 28 - filtered (zero event) * Event 6 - (0, 1) - time 35 * * Not taking the time into account would mean interpreting those events as: * Move 1 unit over 7 ms * Pause for 7 ms * Move 1 unit over 7 ms * Pause for 14 ms * Move 1 unit over 7ms * * Where in reality this was one smooth movement without pauses, * so after normalizing for time we get: * Move 1 unit over 7 ms * Move 1 unit over 14 ms * Move 1 unit over 21ms * * which should give us better speed estimation. */ /* calculate speed based on time passed since last event */ double distance = hypot(unaccelerated->x, unaccelerated->y); /* handle first event in a motion */ if (time - cf->last_time > MOTION_TIMEOUT) cf->last_time = time - FIRST_MOTION_TIME_INTERVAL; double dt = us2ms_f(time - cf->last_time); double speed = distance / dt; /* speed is in device-units per ms */ cf->last_time = time; return speed; } static double custom_accel_function_profile(struct custom_accel_function *cf, double speed_in) { size_t npoints = cf->npoints; double step = cf->step; double *points = cf->points; /* calculate the index of the first point used for interpolation */ size_t i = speed_in / step; /* if speed is greater than custom curve's max speed, use last 2 points for linear extrapolation (same calculation as linear interpolation) */ i = min(i, npoints - 2); /* the 2 points used for linear interpolation */ double x0 = step * i; double x1 = step * (i + 1); double y0 = points[i]; double y1 = points[i + 1]; /* linear interpolation */ double speed_out = (y0 * (x1 - speed_in) + y1 * (speed_in - x0)) / step; /* We moved (dx, dy) device units within the last N ms. This gives us a * given speed S in units/ms, that's our accel input. Our curve says map * that speed S to some other speed S'. * * Our device delta is represented by the vector, that vector needs to * be modified to represent our intended speed. * * Example: we moved a delta of 7 over the last 7ms. Our speed is * thus 1 u/ms, our out speed is 2 u/ms because we want to double our * speed (points: [0.0, 2.0]). Our delta must thus be 14 - factor of 2, * or out-speed/in-speed. * * Example: we moved a delta of 1 over the last 7ms. Our input speed is * 1/7 u/ms, our out speed is 1/7ms because we set up a flat accel * curve (points: [0.0, 1.0]). Our delta must thus be 1 - factor of 1, * or out-speed/in-speed. * * Example: we moved a delta of 1 over the last 21ms. Our input speed is * 1/21 u/ms, our out speed is 1u/ms because we set up a fixed-speed * curve (points: [1.0, 1.0]). Our delta must thus be 21 - factor of 21, * or out-speed/in-speed. * * Example: we moved a delta of 21 over the last 7ms. Our input speed is * 3 u/ms, our out speed is 1u/ms because we set up a fixed-speed * curve (points: [1.0, 1.0]). Our delta must thus be 7 - factor of 1/3, * or out-speed/in-speed. */ /* calculate the acceleration factor based on the user desired speed out */ double accel_factor = speed_out / speed_in; return accel_factor; } static struct normalized_coords custom_accel_function_filter(struct custom_accel_function *cf, const struct device_float_coords *unaccelerated, uint64_t time) { double speed = custom_accel_function_calculate_speed(cf, unaccelerated, time); double accel_factor = custom_accel_function_profile(cf, speed); struct normalized_coords accelerated = { .x = unaccelerated->x * accel_factor, .y = unaccelerated->y * accel_factor, }; return accelerated; } struct custom_accelerator { struct motion_filter base; struct { struct custom_accel_function *fallback; struct custom_accel_function *motion; struct custom_accel_function *scroll; } funcs; }; static struct custom_accel_function * custom_accelerator_get_custom_function(struct custom_accelerator *f, enum libinput_config_accel_type accel_type) { switch (accel_type) { case LIBINPUT_ACCEL_TYPE_FALLBACK: return f->funcs.fallback; case LIBINPUT_ACCEL_TYPE_MOTION: return f->funcs.motion ? f->funcs.motion : f->funcs.fallback; case LIBINPUT_ACCEL_TYPE_SCROLL: return f->funcs.scroll ? f->funcs.scroll : f->funcs.fallback; } return f->funcs.fallback; } static double custom_accelerator_profile(enum libinput_config_accel_type accel_type, struct motion_filter *filter, double speed_in) { struct custom_accelerator *f = (struct custom_accelerator *)filter; struct custom_accel_function *cf; cf = custom_accelerator_get_custom_function(f, accel_type); return custom_accel_function_profile(cf, speed_in); } static struct normalized_coords custom_accelerator_filter(enum libinput_config_accel_type accel_type, struct motion_filter *filter, const struct device_float_coords *unaccelerated, uint64_t time) { struct custom_accelerator *f = (struct custom_accelerator *)filter; struct custom_accel_function *cf; cf = custom_accelerator_get_custom_function(f, accel_type); return custom_accel_function_filter(cf, unaccelerated, time); } static void custom_accelerator_restart(struct motion_filter *filter, void *data, uint64_t time) { /* noop, this function has no effect in the custom interface */ } static void custom_accelerator_destroy(struct motion_filter *filter) { struct custom_accelerator *f = (struct custom_accelerator *)filter; /* destroy all custom movement functions */ custom_accel_function_destroy(f->funcs.fallback); custom_accel_function_destroy(f->funcs.motion); custom_accel_function_destroy(f->funcs.scroll); free(f); } static bool custom_accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); /* noop, this function has no effect in the custom interface */ return true; } static bool custom_accelerator_set_accel_config(struct motion_filter *filter, struct libinput_config_accel *config) { struct custom_accelerator *f = (struct custom_accelerator *)filter; struct custom_accel_function *fallback = NULL, *motion = NULL, *scroll = NULL; if (config->custom.fallback) { fallback = create_custom_accel_function(config->custom.fallback->step, config->custom.fallback->points, config->custom.fallback->npoints); if (!fallback) goto out; } if (config->custom.motion) { motion = create_custom_accel_function(config->custom.motion->step, config->custom.motion->points, config->custom.motion->npoints); if (!motion) goto out; } if (config->custom.scroll) { scroll = create_custom_accel_function(config->custom.scroll->step, config->custom.scroll->points, config->custom.scroll->npoints); if (!scroll) goto out; } custom_accel_function_destroy(f->funcs.fallback); custom_accel_function_destroy(f->funcs.motion); custom_accel_function_destroy(f->funcs.scroll); f->funcs.fallback = fallback; f->funcs.motion = motion; f->funcs.scroll = scroll; return true; out: custom_accel_function_destroy(fallback); custom_accel_function_destroy(motion); custom_accel_function_destroy(scroll); return false; } /* custom profiles and filters for the different accel types: */ double custom_accel_profile_fallback(struct motion_filter *filter, void *data, double speed_in, uint64_t time) { return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_FALLBACK, filter, speed_in); } static struct normalized_coords custom_accelerator_filter_fallback(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_FALLBACK, filter, unaccelerated, time); } double custom_accel_profile_motion(struct motion_filter *filter, void *data, double speed_in, uint64_t time) { return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_MOTION, filter, speed_in); } static struct normalized_coords custom_accelerator_filter_motion(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_MOTION, filter, unaccelerated, time); } double custom_accel_profile_scroll(struct motion_filter *filter, void *data, double speed_in, uint64_t time) { return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_SCROLL, filter, speed_in); } static struct normalized_coords custom_accelerator_filter_scroll(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_SCROLL, filter, unaccelerated, time); } static struct motion_filter_interface custom_accelerator_interface = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM, .filter = custom_accelerator_filter_motion, .filter_constant = custom_accelerator_filter_fallback, .filter_scroll = custom_accelerator_filter_scroll, .restart = custom_accelerator_restart, .destroy = custom_accelerator_destroy, .set_speed = custom_accelerator_set_speed, .set_accel_config = custom_accelerator_set_accel_config, }; struct motion_filter * create_custom_accelerator_filter(void) { struct custom_accelerator *f = zalloc(sizeof(*f)); /* the unit function by default, speed in = speed out, i.e. no acceleration */ const double default_step = 1.0; const double default_points[2] = {0.0, 1.0}; /* initialize default acceleration, used as fallback */ f->funcs.fallback = create_custom_accel_function(default_step, default_points, ARRAY_LENGTH(default_points)); /* Don't initialize other acceleration functions. Those will be initialized if the user sets their points, otherwise the fallback acceleration function is used */ f->base.interface = &custom_accelerator_interface; return &f->base; } libinput-1.28.1/src/filter-flat.c000066400000000000000000000101401477265155700166140ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" struct pointer_accelerator_flat { struct motion_filter base; double factor; int dpi; }; static struct normalized_coords accelerator_filter_flat(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator_flat *accel_filter = (struct pointer_accelerator_flat *)filter; double factor; /* unitless factor */ struct normalized_coords accelerated; /* You want flat acceleration, you get flat acceleration for the * device */ factor = accel_filter->factor; accelerated.x = factor * unaccelerated->x; accelerated.y = factor * unaccelerated->y; return accelerated; } static struct normalized_coords accelerator_filter_noop_flat(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { /* We map the unaccelerated flat filter to have the same behavior as * the "accelerated" flat filter. * The filter by definition is flat, i.e. it does not actually * apply any acceleration (merely a constant factor) and we can assume * that a user wants all mouse movement to have the same speed, mapped * 1:1 to the input speed. * * Thus we apply the same factor to our non-accelerated motion - this way * things like button scrolling end up having the same movement as * pointer motion. */ return accelerator_filter_flat(filter, unaccelerated, data, time); } static bool accelerator_set_speed_flat(struct motion_filter *filter, double speed_adjustment) { struct pointer_accelerator_flat *accel_filter = (struct pointer_accelerator_flat *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); /* Speed range is 0-200% of the nominal speed, with 0 mapping to the * nominal speed. Anything above 200 is pointless, we're already * skipping over ever second pixel at 200% speed. */ accel_filter->factor = max(0.005, 1 + speed_adjustment); filter->speed_adjustment = speed_adjustment; return true; } static void accelerator_destroy_flat(struct motion_filter *filter) { struct pointer_accelerator_flat *accel = (struct pointer_accelerator_flat *) filter; free(accel); } static const struct motion_filter_interface accelerator_interface_flat = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, .filter = accelerator_filter_flat, .filter_constant = accelerator_filter_noop_flat, .filter_scroll = accelerator_filter_noop_flat, .restart = NULL, .destroy = accelerator_destroy_flat, .set_speed = accelerator_set_speed_flat, }; struct motion_filter * create_pointer_accelerator_filter_flat(int dpi) { struct pointer_accelerator_flat *filter; filter = zalloc(sizeof *filter); filter->base.interface = &accelerator_interface_flat; filter->dpi = dpi; return &filter->base; } libinput-1.28.1/src/filter-low-dpi.c000066400000000000000000000166311477265155700172540ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" /* * Default parameters for pointer acceleration profiles. */ #define DEFAULT_THRESHOLD v_ms2us(0.4) /* in units/us */ #define MINIMUM_THRESHOLD v_ms2us(0.2) /* in units/us */ #define DEFAULT_ACCELERATION 2.0 /* unitless factor */ #define DEFAULT_INCLINE 1.1 /* unitless factor */ struct pointer_accelerator_low_dpi { struct motion_filter base; accel_profile_func_t profile; double velocity; /* units/us */ double last_velocity; /* units/us */ struct pointer_trackers trackers; double threshold; /* units/us */ double accel; /* unitless factor */ double incline; /* incline of the function */ int dpi; }; /** * Custom acceleration function for mice < 1000dpi. * At slow motion, a single device unit causes a one-pixel movement. * The threshold/max accel depends on the DPI, the smaller the DPI the * earlier we accelerate and the higher the maximum acceleration is. Result: * at low speeds we get pixel-precision, at high speeds we get approx. the * same movement as a high-dpi mouse. * * Note: data fed to this function is in device units, not normalized. */ double pointer_accel_profile_linear_low_dpi(struct motion_filter *filter, void *data, double speed_in, /* in device units (units/us) */ uint64_t time) { struct pointer_accelerator_low_dpi *accel_filter = (struct pointer_accelerator_low_dpi *)filter; double max_accel = accel_filter->accel; /* unitless factor */ double threshold = accel_filter->threshold; /* units/us */ const double incline = accel_filter->incline; double dpi_factor = accel_filter->dpi/(double)DEFAULT_MOUSE_DPI; double factor; /* unitless */ /* dpi_factor is always < 1.0, increase max_accel, reduce the threshold so it kicks in earlier */ max_accel /= dpi_factor; threshold *= dpi_factor; /* see pointer_accel_profile_linear for a long description */ if (v_us2ms(speed_in) < 0.07) factor = 10 * v_us2ms(speed_in) + 0.3; else if (speed_in < threshold) factor = 1; else factor = incline * v_us2ms(speed_in - threshold) + 1; factor = min(max_accel, factor); return factor; } static inline double calculate_acceleration_factor(struct pointer_accelerator_low_dpi *accel, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { double velocity; /* units/us in device-native dpi*/ double accel_factor; trackers_feed(&accel->trackers, unaccelerated, time); velocity = trackers_velocity(&accel->trackers, time); accel_factor = calculate_acceleration_simpsons(&accel->base, accel->profile, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; return accel_factor; } static struct normalized_coords accelerator_filter_low_dpi(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator_low_dpi *accel = (struct pointer_accelerator_low_dpi *) filter; /* Accelerate for device units and return device units */ double accel_factor = calculate_acceleration_factor(accel, unaccelerated, data, time); const struct normalized_coords normalized = { .x = accel_factor * unaccelerated->x, .y = accel_factor * unaccelerated->y, }; return normalized; } static struct normalized_coords accelerator_filter_noop(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { const struct normalized_coords normalized = { .x = unaccelerated->x, .y = unaccelerated->y, }; return normalized; } static void accelerator_restart(struct motion_filter *filter, void *data, uint64_t time) { struct pointer_accelerator_low_dpi *accel = (struct pointer_accelerator_low_dpi *) filter; trackers_reset(&accel->trackers, time); } static void accelerator_destroy(struct motion_filter *filter) { struct pointer_accelerator_low_dpi *accel = (struct pointer_accelerator_low_dpi *) filter; trackers_free(&accel->trackers); free(accel); } static bool accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { struct pointer_accelerator_low_dpi *accel_filter = (struct pointer_accelerator_low_dpi *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); /* Note: the numbers below are nothing but trial-and-error magic, don't read more into them other than "they mostly worked ok" */ /* delay when accel kicks in */ accel_filter->threshold = DEFAULT_THRESHOLD - v_ms2us(0.25) * speed_adjustment; if (accel_filter->threshold < MINIMUM_THRESHOLD) accel_filter->threshold = MINIMUM_THRESHOLD; /* adjust max accel factor */ accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5; /* higher speed -> faster to reach max */ accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75; filter->speed_adjustment = speed_adjustment; return true; } static const struct motion_filter_interface accelerator_interface_low_dpi = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, .filter = accelerator_filter_low_dpi, .filter_constant = accelerator_filter_noop, .filter_scroll = accelerator_filter_noop, .restart = accelerator_restart, .destroy = accelerator_destroy, .set_speed = accelerator_set_speed, }; static struct pointer_accelerator_low_dpi * create_default_filter(int dpi, bool use_velocity_averaging) { struct pointer_accelerator_low_dpi *filter; filter = zalloc(sizeof *filter); filter->last_velocity = 0.0; trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2); filter->threshold = DEFAULT_THRESHOLD; filter->accel = DEFAULT_ACCELERATION; filter->incline = DEFAULT_INCLINE; filter->dpi = dpi; return filter; } struct motion_filter * create_pointer_accelerator_filter_linear_low_dpi(int dpi, bool use_velocity_averaging) { struct pointer_accelerator_low_dpi *filter; filter = create_default_filter(dpi, use_velocity_averaging); if (!filter) return NULL; filter->base.interface = &accelerator_interface_low_dpi; filter->profile = pointer_accel_profile_linear_low_dpi; return &filter->base; } libinput-1.28.1/src/filter-mouse.c000066400000000000000000000215311477265155700170240ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" /* * Default parameters for pointer acceleration profiles. */ #define DEFAULT_THRESHOLD v_ms2us(0.4) /* in 1000dpi units/us */ #define MINIMUM_THRESHOLD v_ms2us(0.2) /* in 1000dpi units/us */ #define DEFAULT_ACCELERATION 2.0 /* unitless factor */ #define DEFAULT_INCLINE 1.1 /* unitless factor */ struct pointer_accelerator { struct motion_filter base; accel_profile_func_t profile; double velocity; /* units/us */ double last_velocity; /* units/us */ struct pointer_trackers trackers; double threshold; /* 1000dpi units/us */ double accel; /* unitless factor */ double incline; /* incline of the function */ int dpi; }; /** * Calculate the acceleration factor for the given delta with the timestamp. * * @param accel The acceleration filter * @param unaccelerated The raw delta in the device's dpi * @param data Caller-specific data * @param time Current time in µs * * @return A unitless acceleration factor, to be applied to the delta */ static inline double calculate_acceleration_factor(struct pointer_accelerator *accel, const struct normalized_coords *unaccelerated, void *data, uint64_t time) { double velocity; /* units/us in normalized 1000dpi units*/ double accel_factor; /* The trackers API need device_float_coords, but note that we have * normalized coordinates */ const struct device_float_coords unaccel = { .x = unaccelerated->x, .y = unaccelerated->y, }; trackers_feed(&accel->trackers, &unaccel, time); velocity = trackers_velocity(&accel->trackers, time); /* This will call into our pointer_accel_profile_linear() profile func */ accel_factor = calculate_acceleration_simpsons(&accel->base, accel->profile, data, velocity, /* normalized coords */ accel->last_velocity, /* normalized coords */ time); accel->last_velocity = velocity; return accel_factor; } static struct normalized_coords accelerator_filter_linear(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; /* Accelerate for normalized units and return normalized units */ const struct normalized_coords normalized = normalize_for_dpi(unaccelerated, accel->dpi); double accel_factor = calculate_acceleration_factor(accel, &normalized, data, time); struct normalized_coords accelerated = { .x = normalized.x * accel_factor, .y = normalized.y * accel_factor, }; return accelerated; } /** * Generic filter that does nothing beyond converting from the device's * native dpi into normalized coordinates. * * @param filter The acceleration filter * @param unaccelerated The raw delta in the device's dpi * @param data Caller-specific data * @param time Current time in µs * * @return An accelerated tuple of coordinates representing normalized * motion */ static struct normalized_coords accelerator_filter_noop(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; return normalize_for_dpi(unaccelerated, accel->dpi); } static void accelerator_restart(struct motion_filter *filter, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; trackers_reset(&accel->trackers, time); } static void accelerator_destroy(struct motion_filter *filter) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; trackers_free(&accel->trackers); free(accel); } static bool accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { struct pointer_accelerator *accel_filter = (struct pointer_accelerator *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); /* Note: the numbers below are nothing but trial-and-error magic, don't read more into them other than "they mostly worked ok" */ /* delay when accel kicks in */ accel_filter->threshold = DEFAULT_THRESHOLD - v_ms2us(0.25) * speed_adjustment; if (accel_filter->threshold < MINIMUM_THRESHOLD) accel_filter->threshold = MINIMUM_THRESHOLD; /* adjust max accel factor */ accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5; /* higher speed -> faster to reach max */ accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75; filter->speed_adjustment = speed_adjustment; return true; } double pointer_accel_profile_linear(struct motion_filter *filter, void *data, double speed_in, /* in normalized units */ uint64_t time) { struct pointer_accelerator *accel_filter = (struct pointer_accelerator *)filter; const double max_accel = accel_filter->accel; /* unitless factor */ const double threshold = accel_filter->threshold; /* 1000dpi units/us */ const double incline = accel_filter->incline; double factor; /* unitless */ /* Our acceleration function calculates a factor to accelerate input deltas with. The function is a double incline with a plateau, with a rough shape like this: accel factor ^ | / | _____/ | / |/ +-------------> speed in The two inclines are linear functions in the form y = ax + b where y is speed_out x is speed_in a is the incline of acceleration b is minimum acceleration factor for speeds up to 0.07 u/ms, we decelerate, down to 30% of input speed. hence 1 = a * 0.07 + 0.3 0.7 = a * 0.07 => a := 10 deceleration function is thus: y = 10x + 0.3 Note: * 0.07u/ms as threshold is a result of trial-and-error and has no other intrinsic meaning. * 0.3 is chosen simply because it is above the Nyquist frequency for subpixel motion within a pixel. */ if (v_us2ms(speed_in) < 0.07) { factor = 10 * v_us2ms(speed_in) + 0.3; /* up to the threshold, we keep factor 1, i.e. 1:1 movement */ } else if (speed_in < threshold) { factor = 1; } else { /* Acceleration function above the threshold: y = ax' + b where T is threshold x is speed_in x' is speed and y(T) == 1 hence 1 = ax' + 1 => x' := (x - T) */ factor = incline * v_us2ms(speed_in - threshold) + 1; } /* Cap at the maximum acceleration factor */ factor = min(max_accel, factor); return factor; } static const struct motion_filter_interface accelerator_interface = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, .filter = accelerator_filter_linear, .filter_constant = accelerator_filter_noop, .filter_scroll = accelerator_filter_noop, .restart = accelerator_restart, .destroy = accelerator_destroy, .set_speed = accelerator_set_speed, }; static struct pointer_accelerator * create_default_filter(int dpi, bool use_velocity_averaging) { struct pointer_accelerator *filter; filter = zalloc(sizeof *filter); filter->last_velocity = 0.0; trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2); filter->threshold = DEFAULT_THRESHOLD; filter->accel = DEFAULT_ACCELERATION; filter->incline = DEFAULT_INCLINE; filter->dpi = dpi; return filter; } struct motion_filter * create_pointer_accelerator_filter_linear(int dpi, bool use_velocity_averaging) { struct pointer_accelerator *filter; filter = create_default_filter(dpi, use_velocity_averaging); if (!filter) return NULL; filter->base.interface = &accelerator_interface; filter->profile = pointer_accel_profile_linear; return &filter->base; } libinput-1.28.1/src/filter-private.h000066400000000000000000000105641477265155700173570ustar00rootroot00000000000000/* * Copyright © 2012 Jonas Ådahl * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef FILTER_PRIVATE_H #define FILTER_PRIVATE_H #include "config.h" #include "filter.h" struct motion_filter_interface { enum libinput_config_accel_profile type; struct normalized_coords (*filter)( struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); struct normalized_coords (*filter_constant)( struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); struct normalized_coords (*filter_scroll)( struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); void (*restart)(struct motion_filter *filter, void *data, uint64_t time); void (*destroy)(struct motion_filter *filter); bool (*set_speed)(struct motion_filter *filter, double speed_adjustment); bool (*set_accel_config)(struct motion_filter *filter, struct libinput_config_accel *accel_config); }; struct motion_filter { double speed_adjustment; /* normalized [-1, 1] */ const struct motion_filter_interface *interface; }; struct pointer_tracker { struct device_float_coords delta; /* delta to most recent event */ uint64_t time; /* us */ uint32_t dir; }; /* For smoothing timestamps from devices with unreliable timing */ struct pointer_delta_smoothener { uint64_t threshold; uint64_t value; }; static inline struct pointer_delta_smoothener * pointer_delta_smoothener_create(uint64_t event_delta_smooth_threshold, uint64_t event_delta_smooth_value) { struct pointer_delta_smoothener *s = zalloc(sizeof(*s)); s->threshold = event_delta_smooth_threshold; s->value = event_delta_smooth_value; return s; } static inline void pointer_delta_smoothener_destroy(struct pointer_delta_smoothener *smoothener) { free(smoothener); } struct pointer_trackers { struct pointer_tracker *trackers; size_t ntrackers; unsigned int cur_tracker; struct pointer_delta_smoothener *smoothener; }; void trackers_init(struct pointer_trackers *trackers, int ntrackers); void trackers_free(struct pointer_trackers *trackers); void trackers_reset(struct pointer_trackers *trackers, uint64_t time); void trackers_feed(struct pointer_trackers *trackers, const struct device_float_coords *delta, uint64_t time); struct pointer_tracker * trackers_by_offset(struct pointer_trackers *trackers, unsigned int offset); double trackers_velocity(struct pointer_trackers *trackers, uint64_t time); double calculate_acceleration_simpsons(struct motion_filter *filter, accel_profile_func_t profile, void *data, double velocity, double last_velocity, uint64_t time); /* Convert speed/velocity from units/us to units/ms */ static inline double v_us2ms(double units_per_us) { return units_per_us * 1000.0; } static inline double v_us2s(double units_per_us) { return units_per_us * 1000000.0; } /* Convert speed/velocity from units/ms to units/us */ static inline double v_ms2us(double units_per_ms) { return units_per_ms/1000.0; } static inline struct normalized_coords normalize_for_dpi(const struct device_float_coords *coords, int dpi) { struct normalized_coords norm; norm.x = coords->x * DEFAULT_MOUSE_DPI/dpi; norm.y = coords->y * DEFAULT_MOUSE_DPI/dpi; return norm; } #endif libinput-1.28.1/src/filter-tablet.c000066400000000000000000000125301477265155700171460ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" struct tablet_accelerator_flat { struct motion_filter base; double factor; int xres, yres; double xres_scale, /* 1000dpi : tablet res */ yres_scale; /* 1000dpi : tablet res */ }; static inline struct normalized_coords tablet_accelerator_filter_flat_mouse(struct tablet_accelerator_flat *filter, const struct device_float_coords *units) { struct normalized_coords accelerated; /* Tablets are high res (Intuos 4 is 5080 dpi) and unmodified deltas are way too high. Slow it down to the equivalent of a 1000dpi mouse. The ratio of that is: ratio = 1000/(resolution_per_mm * 25.4) i.e. on the Intuos4 it's a ratio of ~1/5. */ accelerated.x = units->x * filter->xres_scale; accelerated.y = units->y * filter->yres_scale; accelerated.x *= filter->factor; accelerated.y *= filter->factor; return accelerated; } static struct normalized_coords tablet_accelerator_filter_flat_pen(struct tablet_accelerator_flat *filter, const struct device_float_coords *units) { struct normalized_coords accelerated; /* Tablet input is in device units, output is supposed to be in * logical pixels roughly equivalent to a mouse/touchpad. * * This is a magical constant found by trial and error. On a 96dpi * screen 0.4mm of movement correspond to 1px logical pixel which * is almost identical to the tablet mapped to screen in absolute * mode. Tested on a Intuos5, other tablets may vary. */ const double DPI_CONVERSION = 96.0/25.4 * 2.5; /* unitless factor */ struct normalized_coords mm; mm.x = 1.0 * units->x/filter->xres; mm.y = 1.0 * units->y/filter->yres; accelerated.x = mm.x * filter->factor * DPI_CONVERSION; accelerated.y = mm.y * filter->factor * DPI_CONVERSION; return accelerated; } static struct normalized_coords tablet_accelerator_filter_flat(struct motion_filter *filter, const struct device_float_coords *units, void *data, uint64_t time) { struct tablet_accelerator_flat *accel_filter = (struct tablet_accelerator_flat *)filter; struct libinput_tablet_tool *tool = (struct libinput_tablet_tool*)data; enum libinput_tablet_tool_type type; struct normalized_coords accel; type = libinput_tablet_tool_get_type(tool); switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: case LIBINPUT_TABLET_TOOL_TYPE_LENS: accel = tablet_accelerator_filter_flat_mouse(accel_filter, units); break; default: accel = tablet_accelerator_filter_flat_pen(accel_filter, units); break; } return accel; } static bool tablet_accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { struct tablet_accelerator_flat *accel_filter = (struct tablet_accelerator_flat *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); accel_filter->factor = speed_adjustment + 1.0; return true; } static void tablet_accelerator_destroy(struct motion_filter *filter) { struct tablet_accelerator_flat *accel_filter = (struct tablet_accelerator_flat *)filter; free(accel_filter); } static const struct motion_filter_interface accelerator_interface_tablet = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, .filter = tablet_accelerator_filter_flat, .filter_constant = NULL, .filter_scroll = NULL, .restart = NULL, .destroy = tablet_accelerator_destroy, .set_speed = tablet_accelerator_set_speed, }; static struct tablet_accelerator_flat * create_tablet_filter_flat(int xres, int yres) { struct tablet_accelerator_flat *filter; filter = zalloc(sizeof *filter); filter->factor = 1.0; filter->xres = xres; filter->yres = yres; filter->xres_scale = DEFAULT_MOUSE_DPI/(25.4 * xres); filter->yres_scale = DEFAULT_MOUSE_DPI/(25.4 * yres); return filter; } struct motion_filter * create_pointer_accelerator_filter_tablet(int xres, int yres) { struct tablet_accelerator_flat *filter; filter = create_tablet_filter_flat(xres, yres); if (!filter) return NULL; filter->base.interface = &accelerator_interface_tablet; return &filter->base; } libinput-1.28.1/src/filter-touchpad-flat.c000066400000000000000000000102311477265155700204220ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" #define TP_MAGIC_SLOWDOWN_FLAT 0.2968 struct touchpad_accelerator_flat { struct motion_filter base; double factor; int dpi; }; static struct normalized_coords accelerator_filter_touchpad_flat(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct touchpad_accelerator_flat *accel = (struct touchpad_accelerator_flat *)filter; double factor; /* unitless factor */ struct normalized_coords normalized; /* You want flat acceleration, you get flat acceleration for the * device */ factor = accel->factor; normalized = normalize_for_dpi(unaccelerated, accel->dpi); normalized.x = TP_MAGIC_SLOWDOWN_FLAT * factor * normalized.x; normalized.y = TP_MAGIC_SLOWDOWN_FLAT * factor * normalized.y; return normalized; } static struct normalized_coords accelerator_filter_noop_touchpad_flat(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { /* We map the unaccelerated flat filter to have the same behavior as * the "accelerated" flat filter. * The filter by definition is flat, i.e. it does not actually * apply any acceleration (merely a constant factor) and we can assume * that a user wants all mouse movement to have the same speed, mapped * 1:1 to the input speed. * * Thus we apply the same factor to our non-accelerated motion - this way * things like gestures end up having the same movement as * pointer motion. */ return accelerator_filter_touchpad_flat(filter, unaccelerated, data, time); } static bool accelerator_set_speed_touchpad_flat(struct motion_filter *filter, double speed_adjustment) { struct touchpad_accelerator_flat *accel_filter = (struct touchpad_accelerator_flat *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); accel_filter->factor = max(0.005, 1 + speed_adjustment); filter->speed_adjustment = speed_adjustment; return true; } static void accelerator_destroy_touchpad_flat(struct motion_filter *filter) { struct touchpad_accelerator_flat *accel = (struct touchpad_accelerator_flat *) filter; free(accel); } static const struct motion_filter_interface accelerator_interface_touchpad_flat = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, .filter = accelerator_filter_touchpad_flat, .filter_constant = accelerator_filter_noop_touchpad_flat, .filter_scroll = accelerator_filter_noop_touchpad_flat, .restart = NULL, .destroy = accelerator_destroy_touchpad_flat, .set_speed = accelerator_set_speed_touchpad_flat, }; struct motion_filter * create_pointer_accelerator_filter_touchpad_flat(int dpi) { struct touchpad_accelerator_flat *filter; filter = zalloc(sizeof *filter); filter->base.interface = &accelerator_interface_touchpad_flat; filter->dpi = dpi; return &filter->base; } libinput-1.28.1/src/filter-touchpad-x230.c000066400000000000000000000244421477265155700202010ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" /* Trackpoint acceleration for the Lenovo x230. DO NOT TOUCH. * This code is only invoked on the X230 and is quite flimsy, * custom-designed to make this touchpad less terrible than the * out-of-the-box experience. The x230 was released in 2013, it's * not worth trying to optimize the code or de-duplicate the various * copy-pastes. */ /* * Default parameters for pointer acceleration profiles. */ #define DEFAULT_THRESHOLD v_ms2us(0.4) /* in units/us */ #define MINIMUM_THRESHOLD v_ms2us(0.2) /* in units/us */ #define DEFAULT_ACCELERATION 2.0 /* unitless factor */ #define DEFAULT_INCLINE 1.1 /* unitless factor */ /* for the Lenovo x230 custom accel. do not touch */ #define X230_THRESHOLD v_ms2us(0.4) /* in units/us */ #define X230_ACCELERATION 2.0 /* unitless factor */ #define X230_INCLINE 1.1 /* unitless factor */ #define X230_MAGIC_SLOWDOWN 0.4 /* unitless */ #define X230_TP_MAGIC_LOW_RES_FACTOR 4.0 /* unitless */ struct pointer_accelerator_x230 { struct motion_filter base; accel_profile_func_t profile; double velocity; /* units/us */ double last_velocity; /* units/us */ struct pointer_trackers trackers; double threshold; /* units/us */ double accel; /* unitless factor */ double incline; /* incline of the function */ int dpi; }; /** * Apply the acceleration profile to the given velocity. * * @param accel The acceleration filter * @param data Caller-specific data * @param velocity Velocity in device-units per µs * @param time Current time in µs * * @return A unitless acceleration factor, to be applied to the delta */ static double acceleration_profile(struct pointer_accelerator_x230 *accel, void *data, double velocity, uint64_t time) { return accel->profile(&accel->base, data, velocity, time); } /** * Calculate the acceleration factor for our current velocity, averaging * between our current and the most recent velocity to smoothen out changes. * * @param accel The acceleration filter * @param data Caller-specific data * @param velocity Velocity in device-units per µs * @param last_velocity Previous velocity in device-units per µs * @param time Current time in µs * * @return A unitless acceleration factor, to be applied to the delta */ static double calculate_acceleration(struct pointer_accelerator_x230 *accel, void *data, double velocity, double last_velocity, uint64_t time) { double factor; /* Use Simpson's rule to calculate the average acceleration between * the previous motion and the most recent. */ factor = acceleration_profile(accel, data, velocity, time); factor += acceleration_profile(accel, data, last_velocity, time); factor += 4.0 * acceleration_profile(accel, data, (last_velocity + velocity) / 2, time); factor = factor / 6.0; return factor; /* unitless factor */ } static struct normalized_coords accelerator_filter_x230(struct motion_filter *filter, const struct device_float_coords *raw, void *data, uint64_t time) { struct pointer_accelerator_x230 *accel = (struct pointer_accelerator_x230 *) filter; double accel_factor; /* unitless factor */ struct normalized_coords accelerated; struct device_float_coords delta_normalized; struct normalized_coords unaccelerated; double velocity; /* units/us */ /* This filter is a "do not touch me" filter. So the hack here is * just to replicate the old behavior before filters switched to * device-native dpi: * 1) convert from device-native to 1000dpi normalized * 2) run all calculation on 1000dpi-normalized data * 3) apply accel factor no normalized data */ unaccelerated = normalize_for_dpi(raw, accel->dpi); delta_normalized.x = unaccelerated.x; delta_normalized.y = unaccelerated.y; trackers_feed(&accel->trackers, &delta_normalized, time); velocity = trackers_velocity(&accel->trackers, time); accel_factor = calculate_acceleration(accel, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; accelerated.x = accel_factor * delta_normalized.x; accelerated.y = accel_factor * delta_normalized.y; return accelerated; } static struct normalized_coords accelerator_filter_constant_x230(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator_x230 *accel = (struct pointer_accelerator_x230 *) filter; struct normalized_coords normalized; const double factor = X230_MAGIC_SLOWDOWN/X230_TP_MAGIC_LOW_RES_FACTOR; normalized = normalize_for_dpi(unaccelerated, accel->dpi); normalized.x = factor * normalized.x; normalized.y = factor * normalized.y; return normalized; } static void accelerator_restart_x230(struct motion_filter *filter, void *data, uint64_t time) { struct pointer_accelerator_x230 *accel = (struct pointer_accelerator_x230 *) filter; unsigned int offset; struct pointer_tracker *tracker; for (offset = 1; offset < accel->trackers.ntrackers; offset++) { tracker = trackers_by_offset(&accel->trackers, offset); tracker->time = 0; tracker->dir = 0; tracker->delta.x = 0; tracker->delta.y = 0; } tracker = trackers_by_offset(&accel->trackers, 0); tracker->time = time; tracker->dir = UNDEFINED_DIRECTION; } static void accelerator_destroy_x230(struct motion_filter *filter) { struct pointer_accelerator_x230 *accel = (struct pointer_accelerator_x230 *) filter; free(accel->trackers.trackers); free(accel); } static bool accelerator_set_speed_x230(struct motion_filter *filter, double speed_adjustment) { struct pointer_accelerator_x230 *accel_filter = (struct pointer_accelerator_x230 *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); /* Note: the numbers below are nothing but trial-and-error magic, don't read more into them other than "they mostly worked ok" */ /* delay when accel kicks in */ accel_filter->threshold = DEFAULT_THRESHOLD - v_ms2us(0.25) * speed_adjustment; if (accel_filter->threshold < MINIMUM_THRESHOLD) accel_filter->threshold = MINIMUM_THRESHOLD; /* adjust max accel factor */ accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5; /* higher speed -> faster to reach max */ accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75; filter->speed_adjustment = speed_adjustment; return true; } double touchpad_lenovo_x230_accel_profile(struct motion_filter *filter, void *data, double speed_in, /* 1000dpi-units/µs */ uint64_t time) { /* Those touchpads presents an actual lower resolution that what is * advertised. We see some jumps from the cursor due to the big steps * in X and Y when we are receiving data. * Apply a factor to minimize those jumps at low speed, and try * keeping the same feeling as regular touchpads at high speed. * It still feels slower but it is usable at least */ double factor; /* unitless */ struct pointer_accelerator_x230 *accel_filter = (struct pointer_accelerator_x230 *)filter; double f1, f2; /* unitless */ const double max_accel = accel_filter->accel * X230_TP_MAGIC_LOW_RES_FACTOR; /* unitless factor */ const double threshold = accel_filter->threshold / X230_TP_MAGIC_LOW_RES_FACTOR; /* units/us */ const double incline = accel_filter->incline * X230_TP_MAGIC_LOW_RES_FACTOR; /* Note: the magic values in this function are obtained by * trial-and-error. No other meaning should be interpreted. * The calculation is a compressed form of * pointer_accel_profile_linear(), look at the git history of that * function for an explanation of what the min/max/etc. does. */ speed_in *= X230_MAGIC_SLOWDOWN / X230_TP_MAGIC_LOW_RES_FACTOR; f1 = min(1, v_us2ms(speed_in) * 5); f2 = 1 + (v_us2ms(speed_in) - v_us2ms(threshold)) * incline; factor = min(max_accel, f2 > 1 ? f2 : f1); return factor * X230_MAGIC_SLOWDOWN / X230_TP_MAGIC_LOW_RES_FACTOR; } static const struct motion_filter_interface accelerator_interface_x230 = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, .filter = accelerator_filter_x230, .filter_constant = accelerator_filter_constant_x230, .filter_scroll = accelerator_filter_constant_x230, .restart = accelerator_restart_x230, .destroy = accelerator_destroy_x230, .set_speed = accelerator_set_speed_x230, }; /* The Lenovo x230 has a bad touchpad. This accel method has been * trial-and-error'd, any changes to it will require re-testing everything. * Don't touch this. */ struct motion_filter * create_pointer_accelerator_filter_lenovo_x230(int dpi, bool use_velocity_averaging) { struct pointer_accelerator_x230 *filter; filter = zalloc(sizeof *filter); filter->base.interface = &accelerator_interface_x230; filter->profile = touchpad_lenovo_x230_accel_profile; filter->last_velocity = 0.0; trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2); filter->threshold = X230_THRESHOLD; filter->accel = X230_ACCELERATION; /* unitless factor */ filter->incline = X230_INCLINE; /* incline of the acceleration function */ filter->dpi = dpi; return &filter->base; } libinput-1.28.1/src/filter-touchpad.c000066400000000000000000000224121477265155700175020ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" /* Once normalized, touchpads see the same acceleration as mice. that is * technically correct but subjectively wrong, we expect a touchpad to be a * lot slower than a mouse. Apply a magic factor to slow down all movements */ #define TP_MAGIC_SLOWDOWN 0.2968 /* unitless factor */ struct touchpad_accelerator { struct motion_filter base; accel_profile_func_t profile; double velocity; /* units/us */ double last_velocity; /* units/us */ struct pointer_trackers trackers; double threshold; /* mm/s */ double accel; /* unitless factor */ int dpi; double speed_factor; /* factor based on speed setting */ }; /** * Calculate the acceleration factor for the given delta with the timestamp. * * @param accel The acceleration filter * @param unaccelerated The raw delta in the device's dpi * @param data Caller-specific data * @param time Current time in µs * * @return A unitless acceleration factor, to be applied to the delta */ static inline double calculate_acceleration_factor(struct touchpad_accelerator *accel, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { double velocity; /* units/us in device-native dpi*/ double accel_factor; trackers_feed(&accel->trackers, unaccelerated, time); velocity = trackers_velocity(&accel->trackers, time); accel_factor = calculate_acceleration_simpsons(&accel->base, accel->profile, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; return accel_factor; } static struct normalized_coords accelerator_filter_touchpad(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct touchpad_accelerator *accel = (struct touchpad_accelerator *) filter; /* Accelerate for device units, normalize afterwards */ double accel_factor = calculate_acceleration_factor(accel, unaccelerated, data, time); const struct device_float_coords accelerated = { .x = unaccelerated->x * accel_factor, .y = unaccelerated->y * accel_factor, }; return normalize_for_dpi(&accelerated, accel->dpi); } /* Maps the [-1, 1] speed setting into a constant acceleration * range. This isn't a linear scale, we keep 0 as the 'optimized' * mid-point and scale down to 0.05 for setting -1 and up to 5 for * setting 1. On the premise that if you want a faster cursor, it * doesn't matter as much whether you have 0.56789 or 0.56790, * but for lower settings it does because you may lose movements. * *shrug*. */ static inline double speed_factor(double s) { return pow(s + 1, 2.38) * 0.95 + 0.05; } static bool touchpad_accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { struct touchpad_accelerator *accel_filter = (struct touchpad_accelerator *)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); filter->speed_adjustment = speed_adjustment; accel_filter->speed_factor = speed_factor(speed_adjustment); return true; } static struct normalized_coords touchpad_constant_filter(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct touchpad_accelerator *accel = (struct touchpad_accelerator *)filter; struct normalized_coords normalized; /* We need to use the same baseline here as the accelerated code, * otherwise our unaccelerated speed is different to the accelerated * speed on the plateau. * * This is a hack, the baseline should be incorporated into the * TP_MAGIC_SLOWDOWN so we only have one number here but meanwhile * this will do. */ const double baseline = 0.9; normalized = normalize_for_dpi(unaccelerated, accel->dpi); normalized.x = baseline * TP_MAGIC_SLOWDOWN * normalized.x; normalized.y = baseline * TP_MAGIC_SLOWDOWN * normalized.y; return normalized; } static void touchpad_accelerator_restart(struct motion_filter *filter, void *data, uint64_t time) { struct touchpad_accelerator *accel = (struct touchpad_accelerator *) filter; trackers_reset(&accel->trackers, time); } static void touchpad_accelerator_destroy(struct motion_filter *filter) { struct touchpad_accelerator *accel = (struct touchpad_accelerator *) filter; trackers_free(&accel->trackers); free(accel); } double touchpad_accel_profile_linear(struct motion_filter *filter, void *data, double speed_in, /* in device units/µs */ uint64_t time) { struct touchpad_accelerator *accel_filter = (struct touchpad_accelerator *)filter; const double threshold = accel_filter->threshold; /* mm/s */ const double baseline = 0.9; double factor; /* unitless */ /* Convert to mm/s because that's something one can understand */ speed_in = v_us2s(speed_in) * 25.4/accel_filter->dpi; /* Our acceleration function calculates a factor to accelerate input deltas with. The function is a double incline with a plateau, with a rough shape like this: accel factor ^ ______ | ) | _____) | / |/ +-------------> speed in Except the second incline is a curve, but well, asciiart. The first incline is a linear function in the form y = ax + b where y is speed_out x is speed_in a is the incline of acceleration b is minimum acceleration factor for speeds up to the lower threshold, we decelerate, down to 30% of input speed. hence 1 = a * 7 + 0.3 0.7 = a * 7 => a := 0.1 deceleration function is thus: y = 0.1x + 0.3 The first plateau is the baseline. The second incline is a curve up, based on magic numbers obtained by trial-and-error. Above the second incline we have another plateau because by then you're moving so fast that extra acceleration doesn't help. Note: * The minimum threshold is a result of trial-and-error and has no other special meaning. * 0.3 is chosen simply because it is above the Nyquist frequency for subpixel motion within a pixel. */ if (speed_in < 7.0) { factor = min(baseline, 0.1 * speed_in + 0.3); /* up to the threshold, we keep factor 1, i.e. 1:1 movement */ } else if (speed_in < threshold) { factor = baseline; } else { /* Acceleration function above the threshold is a curve up to four times the threshold, because why not. Don't assume anything about the specific numbers though, this was all just trial and error by tweaking numbers here and there, then the formula was optimized doing basic maths. You could replace this with some other random formula that gives the same numbers and it would be just as correct. */ const double upper_threshold = threshold * 4.0; speed_in = min(speed_in, upper_threshold); factor = 0.0025 * (speed_in/threshold) * (speed_in - threshold) + baseline; } factor *= accel_filter->speed_factor; return factor * TP_MAGIC_SLOWDOWN; } static const struct motion_filter_interface accelerator_interface_touchpad = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, .filter = accelerator_filter_touchpad, .filter_constant = touchpad_constant_filter, .filter_scroll = touchpad_constant_filter, .restart = touchpad_accelerator_restart, .destroy = touchpad_accelerator_destroy, .set_speed = touchpad_accelerator_set_speed, }; struct motion_filter * create_pointer_accelerator_filter_touchpad(int dpi, uint64_t event_delta_smooth_threshold, uint64_t event_delta_smooth_value, bool use_velocity_averaging) { struct touchpad_accelerator *filter; filter = zalloc(sizeof *filter); filter->last_velocity = 0.0; trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2); filter->threshold = 130; filter->dpi = dpi; filter->base.interface = &accelerator_interface_touchpad; filter->profile = touchpad_accel_profile_linear; filter->trackers.smoothener = pointer_delta_smoothener_create(event_delta_smooth_threshold, event_delta_smooth_value); return &filter->base; } libinput-1.28.1/src/filter-trackpoint-flat.c000066400000000000000000000113211477265155700207720ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" struct trackpoint_flat_accelerator { struct motion_filter base; double speed_factor; double multiplier; }; static struct normalized_coords trackpoint_flat_filter(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct trackpoint_flat_accelerator *accel_filter = (struct trackpoint_flat_accelerator *) filter; struct normalized_coords accelerated; double factor = accel_filter->speed_factor; double multiplier = accel_filter->multiplier; accelerated.x = factor * multiplier * unaccelerated->x; accelerated.y = factor * multiplier * unaccelerated->y; return accelerated; } static struct normalized_coords trackpoint_flat_filter_noop(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { /* We map the unaccelerated flat filter to have the same behavior as * the "accelerated" flat filter. * The filter by definition is flat, i.e. it does not actually * apply any acceleration (merely a constant factor) and we can assume * that a user wants all mouse movement to have the same speed, mapped * 1:1 to the input speed. * * Thus we apply the same factor to our non-accelerated motion - this way * things like button scrolling end up having the same movement as * pointer motion. */ return trackpoint_flat_filter(filter, unaccelerated, data, time); } /* Maps the [-1, 1] speed setting into a constant acceleration * range. This isn't a linear scale, we keep 0 as the 'optimized' * mid-point and scale down to 0 for setting -1 and up to 5 for * setting 1. On the premise that if you want a faster cursor, it * doesn't matter as much whether you have 0.56789 or 0.56790, * but for lower settings it does because you may lose movements. * *shrug*. * * Magic numbers calculated by MyCurveFit.com, data points were * 0.0 0.0 * 0.1 0.1 (because we need 4 points) * 1 1 * 2 5 * * This curve fits nicely into the range necessary. */ static inline double speed_factor(double s) { s += 1; /* map to [0, 2] */ return 435837.2 + (0.04762636 - 435837.2)/(1 + pow(s/240.4549, 2.377168)); } static bool trackpoint_flat_set_speed(struct motion_filter *filter, double speed_adjustment) { struct trackpoint_flat_accelerator *accel_filter = (struct trackpoint_flat_accelerator *) filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); filter->speed_adjustment = speed_adjustment; accel_filter->speed_factor = speed_factor(speed_adjustment); return true; } static void trackpoint_flat_destroy(struct motion_filter *filter) { struct trackpoint_flat_accelerator *accel_filter = (struct trackpoint_flat_accelerator *) filter; free(accel_filter); } static struct motion_filter_interface accelerator_interface_flat = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, .filter = trackpoint_flat_filter, .filter_constant = trackpoint_flat_filter_noop, .filter_scroll = trackpoint_flat_filter_noop, .restart = NULL, .destroy = trackpoint_flat_destroy, .set_speed = trackpoint_flat_set_speed, }; struct motion_filter * create_pointer_accelerator_filter_trackpoint_flat(double multiplier) { struct trackpoint_flat_accelerator *filter; filter = zalloc(sizeof *filter); filter->base.interface = &accelerator_interface_flat; filter->multiplier = multiplier; return &filter->base; } libinput-1.28.1/src/filter-trackpoint.c000066400000000000000000000144251477265155700200560ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" struct trackpoint_accelerator { struct motion_filter base; struct pointer_trackers trackers; double speed_factor; double multiplier; }; double trackpoint_accel_profile(struct motion_filter *filter, void *data, double velocity, uint64_t time) { struct trackpoint_accelerator *accel_filter = (struct trackpoint_accelerator *)filter; double factor; velocity = v_us2ms(velocity); /* make it units/ms */ /* Just a nice-enough curve that provides fluid factor conversion * from the minimum speed up to the real maximum. Generated by * https://www.mycurvefit.com/ with input data * 0 0.3 * 0.1 1 * 0.4 3 * 0.6 4 */ factor = 10.06254 + (0.3 - 10.06254)/(1 + pow(velocity/0.9205459, 1.15363)); factor *= accel_filter->speed_factor; return factor; } static struct normalized_coords trackpoint_accelerator_filter(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct trackpoint_accelerator *accel_filter = (struct trackpoint_accelerator *)filter; struct device_float_coords multiplied; struct normalized_coords coords; double f; double velocity; multiplied.x = unaccelerated->x * accel_filter->multiplier; multiplied.y = unaccelerated->y * accel_filter->multiplier; trackers_feed(&accel_filter->trackers, &multiplied, time); velocity = trackers_velocity(&accel_filter->trackers, time); f = trackpoint_accel_profile(filter, data, velocity, time); coords.x = multiplied.x * f; coords.y = multiplied.y * f; return coords; } static struct normalized_coords trackpoint_accelerator_filter_noop(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { struct trackpoint_accelerator *accel_filter = (struct trackpoint_accelerator *)filter; struct normalized_coords coords; coords.x = unaccelerated->x * accel_filter->multiplier; coords.y = unaccelerated->y * accel_filter->multiplier; return coords; } /* Maps the [-1, 1] speed setting into a constant acceleration * range. This isn't a linear scale, we keep 0 as the 'optimized' * mid-point and scale down to 0 for setting -1 and up to 5 for * setting 1. On the premise that if you want a faster cursor, it * doesn't matter as much whether you have 0.56789 or 0.56790, * but for lower settings it does because you may lose movements. * *shrug*. * * Magic numbers calculated by MyCurveFit.com, data points were * 0.0 0.0 * 0.1 0.1 (because we need 4 points) * 1 1 * 2 5 * * This curve fits nicely into the range necessary. */ static inline double speed_factor(double s) { s += 1; /* map to [0, 2] */ return 435837.2 + (0.04762636 - 435837.2)/(1 + pow(s/240.4549, 2.377168)); } static bool trackpoint_accelerator_set_speed(struct motion_filter *filter, double speed_adjustment) { struct trackpoint_accelerator *accel_filter = (struct trackpoint_accelerator*)filter; assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); filter->speed_adjustment = speed_adjustment; accel_filter->speed_factor = speed_factor(speed_adjustment); return true; } static void trackpoint_accelerator_restart(struct motion_filter *filter, void *data, uint64_t time) { struct trackpoint_accelerator *accel = (struct trackpoint_accelerator *) filter; trackers_reset(&accel->trackers, time); } static void trackpoint_accelerator_destroy(struct motion_filter *filter) { struct trackpoint_accelerator *accel_filter = (struct trackpoint_accelerator *)filter; trackers_free(&accel_filter->trackers); free(accel_filter); } static const struct motion_filter_interface accelerator_interface_trackpoint = { .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, .filter = trackpoint_accelerator_filter, .filter_constant = trackpoint_accelerator_filter_noop, .filter_scroll = trackpoint_accelerator_filter_noop, .restart = trackpoint_accelerator_restart, .destroy = trackpoint_accelerator_destroy, .set_speed = trackpoint_accelerator_set_speed, }; struct motion_filter * create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocity_averaging) { struct trackpoint_accelerator *filter; assert(multiplier > 0.0); /* Trackpoints are special. They don't have a movement speed like a * mouse or a finger, instead they send a stream of events based on * the pressure applied. * * Physical ranges on a trackpoint are the max values for relative * deltas, but these are highly device-specific and unreliable to * measure. * * Instead, we just have a constant multiplier we have in the quirks * system. */ filter = zalloc(sizeof *filter); if (!filter) return NULL; filter->multiplier = multiplier; trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2); filter->base.interface = &accelerator_interface_trackpoint; filter->trackers.smoothener = pointer_delta_smoothener_create(ms2us(10), ms2us(10)); return &filter->base; } libinput-1.28.1/src/filter.c000066400000000000000000000214421477265155700156770ustar00rootroot00000000000000/* * Copyright © 2006-2009 Simon Thum * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include "filter.h" #include "libinput-util.h" #include "filter-private.h" #define MOTION_TIMEOUT ms2us(1000) struct normalized_coords filter_dispatch(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return filter->interface->filter(filter, unaccelerated, data, time); } struct normalized_coords filter_dispatch_constant(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return filter->interface->filter_constant(filter, unaccelerated, data, time); } struct normalized_coords filter_dispatch_scroll(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time) { return filter->interface->filter_scroll(filter, unaccelerated, data, time); } void filter_restart(struct motion_filter *filter, void *data, uint64_t time) { if (filter->interface->restart) filter->interface->restart(filter, data, time); } void filter_destroy(struct motion_filter *filter) { if (!filter || !filter->interface->destroy) return; filter->interface->destroy(filter); } bool filter_set_speed(struct motion_filter *filter, double speed_adjustment) { return filter->interface->set_speed(filter, speed_adjustment); } double filter_get_speed(struct motion_filter *filter) { return filter->speed_adjustment; } enum libinput_config_accel_profile filter_get_type(struct motion_filter *filter) { return filter->interface->type; } bool filter_set_accel_config(struct motion_filter *filter, struct libinput_config_accel *accel_config) { assert(filter_get_type(filter) == accel_config->profile); if (!filter->interface->set_accel_config) return false; return filter->interface->set_accel_config(filter, accel_config); } void trackers_init(struct pointer_trackers *trackers, int ntrackers) { trackers->trackers = zalloc(ntrackers * sizeof(*trackers->trackers)); trackers->ntrackers = ntrackers; trackers->cur_tracker = 0; trackers->smoothener = NULL; } void trackers_free(struct pointer_trackers *trackers) { free(trackers->trackers); pointer_delta_smoothener_destroy(trackers->smoothener); } void trackers_reset(struct pointer_trackers *trackers, uint64_t time) { unsigned int offset; struct pointer_tracker *tracker; for (offset = 1; offset < trackers->ntrackers; offset++) { tracker = trackers_by_offset(trackers, offset); tracker->time = 0; tracker->dir = 0; tracker->delta.x = 0; tracker->delta.y = 0; } tracker = trackers_by_offset(trackers, 0); tracker->time = time; tracker->dir = UNDEFINED_DIRECTION; } void trackers_feed(struct pointer_trackers *trackers, const struct device_float_coords *delta, uint64_t time) { unsigned int i, current; struct pointer_tracker *ts = trackers->trackers; assert(trackers->ntrackers); for (i = 0; i < trackers->ntrackers; i++) { ts[i].delta.x += delta->x; ts[i].delta.y += delta->y; } current = (trackers->cur_tracker + 1) % trackers->ntrackers; trackers->cur_tracker = current; ts[current].delta.x = 0.0; ts[current].delta.y = 0.0; ts[current].time = time; ts[current].dir = device_float_get_direction(*delta); } struct pointer_tracker * trackers_by_offset(struct pointer_trackers *trackers, unsigned int offset) { unsigned int index = (trackers->cur_tracker + trackers->ntrackers - offset) % trackers->ntrackers; return &trackers->trackers[index]; } static double calculate_trackers_velocity(const struct pointer_tracker *tracker, uint64_t time, struct pointer_delta_smoothener *smoothener) { uint64_t tdelta = time - tracker->time + 1; if (smoothener && tdelta < smoothener->threshold) tdelta = smoothener->value; return hypot(tracker->delta.x, tracker->delta.y) / (double)tdelta; /* units/us */ } static double trackers_velocity_after_timeout(const struct pointer_tracker *tracker, struct pointer_delta_smoothener *smoothener) { /* First movement after timeout needs special handling. * * When we trigger the timeout, the last event is too far in the * past to use it for velocity calculation across multiple tracker * values. * * Use the motion timeout itself to calculate the speed rather than * the last tracker time. This errs on the side of being too fast * for really slow movements but provides much more useful initial * movement in normal use-cases (pause, move, pause, move) */ return calculate_trackers_velocity(tracker, tracker->time + MOTION_TIMEOUT, smoothener); } /** * Calculate the velocity based on the tracker data. Velocity is averaged * across multiple historical values, provided those values aren't "too * different" to our current one. That includes either being too far in the * past, moving into a different direction or having too much of a velocity * change between events. */ double trackers_velocity(struct pointer_trackers *trackers, uint64_t time) { const double MAX_VELOCITY_DIFF = v_ms2us(1); /* units/us */ double result = 0.0; double initial_velocity = 0.0; unsigned int dir = trackers_by_offset(trackers, 0)->dir; /* Find least recent vector within a timelimit, maximum velocity diff * and direction threshold. */ for (unsigned int offset = 1; offset < trackers->ntrackers; offset++) { const struct pointer_tracker *tracker = trackers_by_offset(trackers, offset); /* Bug: time running backwards */ if (tracker->time > time) break; /* Stop if too far away in time */ if (time - tracker->time > MOTION_TIMEOUT) { if (offset == 1) result = trackers_velocity_after_timeout( tracker, trackers->smoothener); break; } double velocity = calculate_trackers_velocity(tracker, time, trackers->smoothener); /* Stop if direction changed */ dir &= tracker->dir; if (dir == 0) { /* First movement after dirchange - velocity is that * of the last movement */ if (offset == 1) result = velocity; break; } /* Always average the first two events. On some touchpads * where the first event is jumpy, this somewhat reduces * pointer jumps on slow motions. */ if (initial_velocity == 0.0 || offset <= 2) { result = initial_velocity = velocity; } else { /* Stop if velocity differs too much from initial */ double velocity_diff = fabs(initial_velocity - velocity); if (velocity_diff > MAX_VELOCITY_DIFF) break; result = velocity; } } return result; /* units/us */ } /** * Calculate the acceleration factor for our current velocity, averaging * between our current and the most recent velocity to smoothen out changes. * * @param accel The acceleration filter * @param data Caller-specific data * @param velocity Velocity - depending on the caller this may be in * device-units per µs or normalized per µs * @param last_velocity Previous velocity in device-units per µs * @param time Current time in µs * * @return A unitless acceleration factor, to be applied to the delta */ double calculate_acceleration_simpsons(struct motion_filter *filter, accel_profile_func_t profile, void *data, double velocity, double last_velocity, uint64_t time) { double factor; /* Use Simpson's rule to calculate the average acceleration between * the previous motion and the most recent. */ factor = profile(filter, data, velocity, time); factor += profile(filter, data, last_velocity, time); factor += 4.0 * profile(filter, data, (last_velocity + velocity) / 2, time); factor = factor / 6.0; return factor; /* unitless factor */ } libinput-1.28.1/src/filter.h000066400000000000000000000151151477265155700157040ustar00rootroot00000000000000/* * Copyright © 2012 Jonas Ådahl * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef FILTER_H #define FILTER_H #include "config.h" #include #include #include "libinput-private.h" struct motion_filter; /** * Accelerate the given coordinates. * Takes a set of unaccelerated deltas and accelerates them based on the * current and previous motion. * * This is a superset of filter_dispatch_constant() * * @param filter The device's motion filter * @param unaccelerated The unaccelerated delta in the device's dpi * resolution as specified during filter creation. If a device has uneven * resolution for x and y, one axis needs to be scaled to match the * originally provided resolution. * @param data Custom data * @param time The time of the delta * * @return A set of normalized coordinates that can be used for pixel * movement. The normalized coordinates are scaled to the default dpi range, * i.e. regardless of the resolution of the underlying device, the returned * values always reflect a 1000dpi mouse. * * @see filter_dispatch_constant */ struct normalized_coords filter_dispatch(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); /** * Apply constant motion filters, but no acceleration. * * Takes a set of unaccelerated deltas and applies any constant filters to * it but does not accelerate the delta in the conventional sense. * * @param filter The device's motion filter * @param unaccelerated The unaccelerated delta in the device's dpi * resolution as specified during filter creation. If a device has uneven * resolution for x and y, one axis needs to be scaled to match the * originally provided resolution. * @param data Custom data * @param time The time of the delta * * @see filter_dispatch */ struct normalized_coords filter_dispatch_constant(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); /** * Apply a scroll filter. * Depending on the device, and the acceleration profile, * this filter allows the user to accelerate the scroll movement. * * Takes a set of unaccelerated deltas and applies the scroll filter to it. * * @param filter The device's motion filter * @param unaccelerated The unaccelerated delta in the device's dpi * resolution as specified during filter creation. If a device has uneven * resolution for x and y, one axis needs to be scaled to match the * originally provided resolution. * @param data Custom data * @param time The time of the delta * * @see filter_dispatch */ struct normalized_coords filter_dispatch_scroll(struct motion_filter *filter, const struct device_float_coords *unaccelerated, void *data, uint64_t time); void filter_restart(struct motion_filter *filter, void *data, uint64_t time); void filter_destroy(struct motion_filter *filter); bool filter_set_speed(struct motion_filter *filter, double speed); double filter_get_speed(struct motion_filter *filter); enum libinput_config_accel_profile filter_get_type(struct motion_filter *filter); typedef double (*accel_profile_func_t)(struct motion_filter *filter, void *data, double velocity, uint64_t time); bool filter_set_accel_config(struct motion_filter *filter, struct libinput_config_accel *accel_config); /* Pointer acceleration types */ struct motion_filter * create_pointer_accelerator_filter_flat(int dpi); struct motion_filter * create_pointer_accelerator_filter_linear(int dpi, bool use_velocity_averaging); struct motion_filter * create_pointer_accelerator_filter_linear_low_dpi(int dpi, bool use_velocity_averaging); struct motion_filter * create_pointer_accelerator_filter_touchpad(int dpi, uint64_t event_delta_smooth_threshold, uint64_t event_delta_smooth_value, bool use_velocity_averaging); struct motion_filter * create_pointer_accelerator_filter_touchpad_flat(int dpi); struct motion_filter * create_pointer_accelerator_filter_lenovo_x230(int dpi, bool use_velocity_averaging); struct motion_filter * create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocity_averaging); struct motion_filter * create_pointer_accelerator_filter_trackpoint_flat(double multiplier); struct motion_filter * create_pointer_accelerator_filter_tablet(int xres, int yres); struct motion_filter * create_custom_accelerator_filter(void); /* * Pointer acceleration profiles. */ double pointer_accel_profile_linear_low_dpi(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double pointer_accel_profile_linear(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double touchpad_accel_profile_linear(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double touchpad_lenovo_x230_accel_profile(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double trackpoint_accel_profile(struct motion_filter *filter, void *data, double velocity, uint64_t time); double custom_accel_profile_fallback(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double custom_accel_profile_motion(struct motion_filter *filter, void *data, double speed_in, uint64_t time); double custom_accel_profile_scroll(struct motion_filter *filter, void *data, double speed_in, uint64_t time); #endif /* FILTER_H */ libinput-1.28.1/src/libinput-git-version.h.in000066400000000000000000000000671477265155700211160ustar00rootroot00000000000000#pragma once #define LIBINPUT_GIT_VERSION "@VCS_TAG@" libinput-1.28.1/src/libinput-private-config.c000066400000000000000000000051121477265155700211470ustar00rootroot00000000000000/* * Copyright © 2021 Red Hat, Inc. * Copyright © 2021 José Expósito * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "libinput-private-config.h" #include "libinput-private.h" int libinput_device_config_gesture_hold_is_available(struct libinput_device *device) { if (!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) return 0; if (!device->config.gesture->get_hold_default(device)) return 0; return 1; } enum libinput_config_status libinput_device_config_gesture_set_hold_enabled(struct libinput_device *device, enum libinput_config_hold_state enable) { if (enable != LIBINPUT_CONFIG_HOLD_ENABLED && enable != LIBINPUT_CONFIG_HOLD_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (!libinput_device_config_gesture_hold_is_available(device)) { return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; } return device->config.gesture->set_hold_enabled(device, enable); } enum libinput_config_hold_state libinput_device_config_gesture_get_hold_enabled(struct libinput_device *device) { if (!libinput_device_config_gesture_hold_is_available(device)) return LIBINPUT_CONFIG_HOLD_DISABLED; return device->config.gesture->get_hold_enabled(device); } enum libinput_config_hold_state libinput_device_config_gesture_get_hold_default_enabled(struct libinput_device *device) { if (!libinput_device_config_gesture_hold_is_available(device)) return LIBINPUT_CONFIG_HOLD_DISABLED; return device->config.gesture->get_hold_default(device); } libinput-1.28.1/src/libinput-private-config.h000066400000000000000000000077601477265155700211670ustar00rootroot00000000000000/* * Copyright © 2021 Red Hat, Inc. * Copyright © 2021 José Expósito * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef LIBINPUT_PRIVATE_CONFIG_H #define LIBINPUT_PRIVATE_CONFIG_H #include "config.h" #include "libinput.h" enum libinput_config_hold_state { /** Hold gestures are to be disabled, or are currently disabled */ LIBINPUT_CONFIG_HOLD_DISABLED, /** Hold gestures are to be enabled, or are currently disabled */ LIBINPUT_CONFIG_HOLD_ENABLED, }; /** * @ingroup config * * Check whether a device can perform hold gestures. * * @param device The device to configure * @return Non-zero if a device can perform hold gestures, zero otherwise. * * @see libinput_device_config_gesture_set_hold_enabled * @see libinput_device_config_gesture_get_hold_enabled * @see libinput_device_config_gesture_get_hold_default_enabled */ int libinput_device_config_gesture_hold_is_available(struct libinput_device *device); /** * @ingroup config * * Enable or disable hold gestures on this device. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_HOLD_ENABLED to enable hold gestures or * @ref LIBINPUT_CONFIG_HOLD_DISABLED to disable them * * @return A config status code. Disabling hold gestures on a device that does * not support them always succeeds. * * @see libinput_device_config_gesture_hold_is_available * @see libinput_device_config_gesture_get_hold_enabled * @see libinput_device_config_gesture_get_hold_default_enabled */ enum libinput_config_status libinput_device_config_gesture_set_hold_enabled(struct libinput_device *device, enum libinput_config_hold_state enable); /** * @ingroup config * * Check if hold gestures are enabled on this device. If the device does not * support hold gestures, this function always returns @ref * LIBINPUT_CONFIG_HOLD_DISABLED. * * @param device The device to configure * * @retval LIBINPUT_CONFIG_HOLD_ENABLED If hold gestures are currently enabled * @retval LIBINPUT_CONFIG_HOLD_DISABLED If hold gestures are currently disabled * * @see libinput_device_config_gesture_hold_is_available * @see libinput_device_config_gesture_set_hold_enabled * @see libinput_device_config_gesture_get_hold_default_enabled */ enum libinput_config_hold_state libinput_device_config_gesture_get_hold_enabled(struct libinput_device *device); /** * @ingroup config * * Return the default setting for whether hold gestures are enabled on this * device. * * @param device The device to configure * @retval LIBINPUT_CONFIG_HOLD_ENABLED If hold gestures are enabled by default * @retval LIBINPUT_CONFIG_HOLD_DISABLED If hold gestures are disabled by * default * * @see libinput_device_config_gesture_hold_is_available * @see libinput_device_config_gesture_set_hold_enabled * @see libinput_device_config_gesture_get_hold_enabled */ enum libinput_config_hold_state libinput_device_config_gesture_get_hold_default_enabled(struct libinput_device *device); #endif /* LIBINPUT_PRIVATE_CONFIG_H */ libinput-1.28.1/src/libinput-private.h000066400000000000000000000746541477265155700177320ustar00rootroot00000000000000/* * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef LIBINPUT_PRIVATE_H #define LIBINPUT_PRIVATE_H #include "config.h" #include #include #include #if HAVE_LIBWACOM #include #endif #include "linux/input.h" #include "libinput.h" #include "libinput-private-config.h" #include "libinput-util.h" #include "libinput-version.h" struct libinput_source; /* A coordinate pair in device coordinates */ struct device_coords { int x, y; }; /* * A coordinate pair in device coordinates, capable of holding non discrete * values, this is necessary e.g. when device coordinates get averaged. */ struct device_float_coords { double x, y; }; /* A dpi-normalized coordinate pair */ struct normalized_coords { double x, y; }; /* A discrete step pair (mouse wheels) */ struct discrete_coords { int x, y; }; /* A pair of coordinates normalized to a [0,1] or [-1, 1] range */ struct normalized_range_coords { double x, y; }; /* A [0.0, 1.0] normalized range */ struct normalized_range { double min, max; }; /* A pair of angles in degrees */ struct wheel_angle { double x, y; }; /* A pair of wheel click data for the 120-normalized range */ struct wheel_v120 { int x, y; }; /* A pair of angles in degrees */ struct tilt_degrees { double x, y; }; /* A threshold with an upper and lower limit */ struct threshold { int upper; int lower; }; /* A pair of coordinates in mm */ struct phys_coords { double x; double y; }; /* A rectangle in mm, x/y is the top-left corner */ struct phys_rect { double x, y; double w, h; }; /* A rectangle in device coordinates, x/y is the top-left corner */ struct device_coord_rect { int x, y; int w, h; }; /* A pair of major/minor in mm */ struct phys_ellipsis { double major; double minor; }; struct libinput_interface_backend { int (*resume)(struct libinput *libinput); void (*suspend)(struct libinput *libinput); void (*destroy)(struct libinput *libinput); int (*device_change_seat)(struct libinput_device *device, const char *seat_name); }; struct libinput { int epoll_fd; struct list source_destroy_list; struct list seat_list; struct { struct list list; struct libinput_source *source; int fd; uint64_t next_expiry; struct ratelimit expiry_in_past_limit; } timer; struct libinput_event **events; size_t events_count; size_t events_len; size_t events_in; size_t events_out; struct list tool_list; const struct libinput_interface *interface; const struct libinput_interface_backend *interface_backend; libinput_log_handler log_handler; enum libinput_log_priority log_priority; void *user_data; int refcount; struct list device_group_list; uint64_t last_event_time; uint64_t dispatch_time; bool quirks_initialized; struct quirks_context *quirks; #if HAVE_LIBWACOM struct { WacomDeviceDatabase *db; size_t refcount; } libwacom; #endif }; typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat); struct libinput_seat { struct libinput *libinput; struct list link; struct list devices_list; void *user_data; int refcount; libinput_seat_destroy_func destroy; char *physical_name; char *logical_name; uint32_t slot_map; uint32_t button_count[KEY_CNT]; }; struct libinput_device_config_tap { int (*count)(struct libinput_device *device); enum libinput_config_status (*set_enabled)(struct libinput_device *device, enum libinput_config_tap_state enable); enum libinput_config_tap_state (*get_enabled)(struct libinput_device *device); enum libinput_config_tap_state (*get_default)(struct libinput_device *device); enum libinput_config_status (*set_map)(struct libinput_device *device, enum libinput_config_tap_button_map map); enum libinput_config_tap_button_map (*get_map)(struct libinput_device *device); enum libinput_config_tap_button_map (*get_default_map)(struct libinput_device *device); enum libinput_config_status (*set_drag_enabled)(struct libinput_device *device, enum libinput_config_drag_state); enum libinput_config_drag_state (*get_drag_enabled)(struct libinput_device *device); enum libinput_config_drag_state (*get_default_drag_enabled)(struct libinput_device *device); enum libinput_config_status (*set_draglock_enabled)(struct libinput_device *device, enum libinput_config_drag_lock_state); enum libinput_config_drag_lock_state (*get_draglock_enabled)(struct libinput_device *device); enum libinput_config_drag_lock_state (*get_default_draglock_enabled)(struct libinput_device *device); }; struct libinput_device_config_3fg_drag { int (*count)(struct libinput_device *device); enum libinput_config_status (*set_enabled)(struct libinput_device *device, enum libinput_config_3fg_drag_state enable); enum libinput_config_3fg_drag_state (*get_enabled)(struct libinput_device *device); enum libinput_config_3fg_drag_state (*get_default)(struct libinput_device *device); }; struct libinput_device_config_calibration { int (*has_matrix)(struct libinput_device *device); enum libinput_config_status (*set_matrix)(struct libinput_device *device, const float matrix[6]); int (*get_matrix)(struct libinput_device *device, float matrix[6]); int (*get_default_matrix)(struct libinput_device *device, float matrix[6]); }; struct libinput_device_config_area { int (*has_rectangle)(struct libinput_device *device); enum libinput_config_status (*set_rectangle)(struct libinput_device *device, const struct libinput_config_area_rectangle *rectangle); struct libinput_config_area_rectangle (*get_rectangle)(struct libinput_device *device); struct libinput_config_area_rectangle (*get_default_rectangle)(struct libinput_device *device); }; struct libinput_device_config_send_events { uint32_t (*get_modes)(struct libinput_device *device); enum libinput_config_status (*set_mode)(struct libinput_device *device, enum libinput_config_send_events_mode mode); enum libinput_config_send_events_mode (*get_mode)(struct libinput_device *device); enum libinput_config_send_events_mode (*get_default_mode)(struct libinput_device *device); }; /** * Custom acceleration function min number of points * At least 2 points are required for linear interpolation */ #define LIBINPUT_ACCEL_NPOINTS_MIN 2 /** * Custom acceleration function max number of points * an arbitrary limit of sample points * it should be more than enough for everyone */ #define LIBINPUT_ACCEL_NPOINTS_MAX 64 /** * Custom acceleration function min point value */ #define LIBINPUT_ACCEL_POINT_MIN_VALUE 0 /** * Custom acceleration function max point value */ #define LIBINPUT_ACCEL_POINT_MAX_VALUE 10000 /** * Custom acceleration function max step size */ #define LIBINPUT_ACCEL_STEP_MAX 10000 struct libinput_config_accel_custom_func { double step; size_t npoints; double points[LIBINPUT_ACCEL_NPOINTS_MAX]; }; struct libinput_config_accel { enum libinput_config_accel_profile profile; struct { struct libinput_config_accel_custom_func *fallback; struct libinput_config_accel_custom_func *motion; struct libinput_config_accel_custom_func *scroll; } custom; }; struct libinput_device_config_accel { int (*available)(struct libinput_device *device); enum libinput_config_status (*set_speed)(struct libinput_device *device, double speed); double (*get_speed)(struct libinput_device *device); double (*get_default_speed)(struct libinput_device *device); uint32_t (*get_profiles)(struct libinput_device *device); enum libinput_config_status (*set_profile)(struct libinput_device *device, enum libinput_config_accel_profile); enum libinput_config_accel_profile (*get_profile)(struct libinput_device *device); enum libinput_config_accel_profile (*get_default_profile)(struct libinput_device *device); enum libinput_config_status (*set_accel_config)(struct libinput_device *device, struct libinput_config_accel *accel_config); }; struct libinput_device_config_natural_scroll { int (*has)(struct libinput_device *device); enum libinput_config_status (*set_enabled)(struct libinput_device *device, int enabled); int (*get_enabled)(struct libinput_device *device); int (*get_default_enabled)(struct libinput_device *device); }; struct libinput_device_config_left_handed { int (*has)(struct libinput_device *device); enum libinput_config_status (*set)(struct libinput_device *device, int left_handed); int (*get)(struct libinput_device *device); int (*get_default)(struct libinput_device *device); }; struct libinput_device_config_scroll_method { uint32_t (*get_methods)(struct libinput_device *device); enum libinput_config_status (*set_method)(struct libinput_device *device, enum libinput_config_scroll_method method); enum libinput_config_scroll_method (*get_method)(struct libinput_device *device); enum libinput_config_scroll_method (*get_default_method)(struct libinput_device *device); enum libinput_config_status (*set_button)(struct libinput_device *device, uint32_t button); uint32_t (*get_button)(struct libinput_device *device); uint32_t (*get_default_button)(struct libinput_device *device); enum libinput_config_status (*set_button_lock)(struct libinput_device *device, enum libinput_config_scroll_button_lock_state); enum libinput_config_scroll_button_lock_state (*get_button_lock)(struct libinput_device *device); enum libinput_config_scroll_button_lock_state (*get_default_button_lock)(struct libinput_device *device); }; struct libinput_device_config_click_method { uint32_t (*get_methods)(struct libinput_device *device); enum libinput_config_status (*set_method)(struct libinput_device *device, enum libinput_config_click_method method); enum libinput_config_click_method (*get_method)(struct libinput_device *device); enum libinput_config_click_method (*get_default_method)(struct libinput_device *device); enum libinput_config_status (*set_clickfinger_map)(struct libinput_device *device, enum libinput_config_clickfinger_button_map map); enum libinput_config_clickfinger_button_map (*get_clickfinger_map)(struct libinput_device *device); enum libinput_config_clickfinger_button_map (*get_default_clickfinger_map)(struct libinput_device *device); }; struct libinput_device_config_middle_emulation { int (*available)(struct libinput_device *device); enum libinput_config_status (*set)( struct libinput_device *device, enum libinput_config_middle_emulation_state); enum libinput_config_middle_emulation_state (*get)( struct libinput_device *device); enum libinput_config_middle_emulation_state (*get_default)( struct libinput_device *device); }; struct libinput_device_config_dwt { int (*is_available)(struct libinput_device *device); enum libinput_config_status (*set_enabled)( struct libinput_device *device, enum libinput_config_dwt_state enable); enum libinput_config_dwt_state (*get_enabled)( struct libinput_device *device); enum libinput_config_dwt_state (*get_default_enabled)( struct libinput_device *device); }; struct libinput_device_config_dwtp { int (*is_available)(struct libinput_device *device); enum libinput_config_status (*set_enabled)( struct libinput_device *device, enum libinput_config_dwtp_state enable); enum libinput_config_dwtp_state (*get_enabled)( struct libinput_device *device); enum libinput_config_dwtp_state (*get_default_enabled)( struct libinput_device *device); }; struct libinput_device_config_rotation { int (*is_available)(struct libinput_device *device); enum libinput_config_status (*set_angle)( struct libinput_device *device, unsigned int degrees_cw); unsigned int (*get_angle)(struct libinput_device *device); unsigned int (*get_default_angle)(struct libinput_device *device); }; struct libinput_device_config_gesture { enum libinput_config_status (*set_hold_enabled)(struct libinput_device *device, enum libinput_config_hold_state enabled); enum libinput_config_hold_state (*get_hold_enabled)(struct libinput_device *device); enum libinput_config_hold_state (*get_hold_default)(struct libinput_device *device); }; struct libinput_device_config { struct libinput_device_config_tap *tap; struct libinput_device_config_calibration *calibration; struct libinput_device_config_area *area; struct libinput_device_config_send_events *sendevents; struct libinput_device_config_accel *accel; struct libinput_device_config_natural_scroll *natural_scroll; struct libinput_device_config_left_handed *left_handed; struct libinput_device_config_scroll_method *scroll_method; struct libinput_device_config_click_method *click_method; struct libinput_device_config_middle_emulation *middle_emulation; struct libinput_device_config_dwt *dwt; struct libinput_device_config_dwtp *dwtp; struct libinput_device_config_rotation *rotation; struct libinput_device_config_gesture *gesture; struct libinput_device_config_3fg_drag *drag_3fg; }; struct libinput_device_group { int refcount; void *user_data; char *identifier; /* unique identifier or NULL for singletons */ struct list link; }; struct libinput_device { struct libinput_seat *seat; struct libinput_device_group *group; struct list link; struct list event_listeners; void *user_data; int refcount; struct libinput_device_config config; }; enum libinput_tablet_tool_axis { LIBINPUT_TABLET_TOOL_AXIS_X = 1, LIBINPUT_TABLET_TOOL_AXIS_Y = 2, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE = 3, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE = 4, LIBINPUT_TABLET_TOOL_AXIS_TILT_X = 5, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y = 6, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z = 7, LIBINPUT_TABLET_TOOL_AXIS_SLIDER = 8, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL = 9, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR = 10, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR = 11, }; #define LIBINPUT_TABLET_TOOL_AXIS_MAX LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR struct tablet_axes { struct device_coords point; struct normalized_coords delta; double distance; double pressure; struct tilt_degrees tilt; double rotation; double slider; double wheel; int wheel_discrete; struct phys_ellipsis size; }; enum pressure_heuristic_state { PRESSURE_HEURISTIC_STATE_PROXIN1, /** First proximity in event */ PRESSURE_HEURISTIC_STATE_PROXIN2, /** Second proximity in event */ PRESSURE_HEURISTIC_STATE_DECIDE, /** Decide on offset now */ PRESSURE_HEURISTIC_STATE_DONE, /** Decision's been made, live with it */ }; struct libinput_tablet_tool_config_pressure_range { int (*is_available)(struct libinput_tablet_tool *tool); enum libinput_config_status (*set)(struct libinput_tablet_tool *tool, double min, double max); void (*get)(struct libinput_tablet_tool *tool, double *min, double *max); void (*get_default)(struct libinput_tablet_tool *tool, double *min, double *max); }; struct libinput_tablet_tool_pressure_threshold { unsigned int tablet_id; /* The configured axis we actually work with */ struct input_absinfo abs_pressure; struct threshold threshold; /* in device coordinates */ int offset; /* in device coordinates */ bool has_offset; /* This gives us per-tablet heuristic state which is arguably * wrong but >99% of users have one tablet and it's easier to * implement it this way */ enum pressure_heuristic_state heuristic_state; }; struct libinput_tablet_tool { struct list link; uint32_t serial; uint32_t tool_id; enum libinput_tablet_tool_type type; unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; unsigned char buttons[NCHARS(KEY_MAX) + 1]; int refcount; void *user_data; struct { /* We're assuming that the *configured* pressure range is per * tool, not per tablet. The *adjusted* thresholds are then * per-tablet. */ struct normalized_range range; struct normalized_range wanted_range; bool has_configured_range; /* Hard-coded because I doubt we have users with more * than 4 tablets at the same time */ struct libinput_tablet_tool_pressure_threshold thresholds[4]; } pressure; struct { struct libinput_tablet_tool_config_pressure_range pressure_range; } config; }; struct libinput_tablet_pad_mode_group { struct libinput_device *device; struct list link; int refcount; void *user_data; unsigned int index; unsigned int num_modes; unsigned int current_mode; uint32_t button_mask; uint32_t ring_mask; uint32_t strip_mask; uint32_t dial_mask; uint32_t toggle_button_mask; void (*destroy)(struct libinput_tablet_pad_mode_group *group); }; struct libinput_event { enum libinput_event_type type; struct libinput_device *device; }; struct libinput_event_listener { struct list link; void (*notify_func)(uint64_t time, struct libinput_event *ev, void *notify_func_data); void *notify_func_data; }; typedef void (*libinput_source_dispatch_t)(void *data); #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) #define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) #define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) #define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) #define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) #define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) #define log_debug_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) #define log_info_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) #define log_error_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) #define log_bug_kernel_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) #define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__) #define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__) static inline bool is_logged(const struct libinput *libinput, enum libinput_log_priority priority) { return libinput->log_handler && libinput->log_priority <= priority; } void log_msg_ratelimit(struct libinput *libinput, struct ratelimit *ratelimit, enum libinput_log_priority priority, const char *format, ...) LIBINPUT_ATTRIBUTE_PRINTF(4, 5); void log_msg(struct libinput *libinput, enum libinput_log_priority priority, const char *format, ...) LIBINPUT_ATTRIBUTE_PRINTF(3, 4); void log_msg_va(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) LIBINPUT_ATTRIBUTE_PRINTF(3, 0); int libinput_init(struct libinput *libinput, const struct libinput_interface *interface, const struct libinput_interface_backend *interface_backend, void *user_data); void libinput_init_quirks(struct libinput *libinput); struct libinput_source * libinput_add_fd(struct libinput *libinput, int fd, libinput_source_dispatch_t dispatch, void *data); void libinput_remove_source(struct libinput *libinput, struct libinput_source *source); int open_restricted(struct libinput *libinput, const char *path, int flags); void close_restricted(struct libinput *libinput, int fd); bool ignore_litest_test_suite_device(struct udev_device *device); void libinput_seat_init(struct libinput_seat *seat, struct libinput *libinput, const char *physical_name, const char *logical_name, libinput_seat_destroy_func destroy); void libinput_device_init(struct libinput_device *device, struct libinput_seat *seat); struct libinput_device_group * libinput_device_group_create(struct libinput *libinput, const char *identifier); struct libinput_device_group * libinput_device_group_find_group(struct libinput *libinput, const char *identifier); void libinput_device_set_device_group(struct libinput_device *device, struct libinput_device_group *group); void libinput_device_init_event_listener(struct libinput_event_listener *listener); void libinput_device_add_event_listener(struct libinput_device *device, struct libinput_event_listener *listener, void (*notify_func)( uint64_t time, struct libinput_event *event, void *notify_func_data), void *notify_func_data); void libinput_device_remove_event_listener(struct libinput_event_listener *listener); void notify_added_device(struct libinput_device *device); void notify_removed_device(struct libinput_device *device); void keyboard_notify_key(struct libinput_device *device, uint64_t time, uint32_t key, enum libinput_key_state state); void pointer_notify_motion(struct libinput_device *device, uint64_t time, const struct normalized_coords *delta, const struct device_float_coords *raw); void pointer_notify_motion_absolute(struct libinput_device *device, uint64_t time, const struct device_coords *point); void pointer_notify_button(struct libinput_device *device, uint64_t time, int32_t button, enum libinput_button_state state); void pointer_notify_axis_finger(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta); void pointer_notify_axis_continuous(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta); void pointer_notify_axis_legacy_wheel(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta, const struct discrete_coords *discrete); void pointer_notify_axis_wheel(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta, const struct wheel_v120 *v120); void touch_notify_touch_down(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot, const struct device_coords *point); void touch_notify_touch_motion(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot, const struct device_coords *point); void touch_notify_touch_up(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot); void touch_notify_touch_cancel(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot); void touch_notify_frame(struct libinput_device *device, uint64_t time); void gesture_notify_swipe(struct libinput_device *device, uint64_t time, enum libinput_event_type type, int finger_count, const struct normalized_coords *delta, const struct normalized_coords *unaccel); void gesture_notify_swipe_end(struct libinput_device *device, uint64_t time, int finger_count, bool cancelled); void gesture_notify_pinch(struct libinput_device *device, uint64_t time, enum libinput_event_type type, int finger_count, const struct normalized_coords *delta, const struct normalized_coords *unaccel, double scale, double angle); void gesture_notify_pinch_end(struct libinput_device *device, uint64_t time, int finger_count, double scale, bool cancelled); void gesture_notify_hold_begin(struct libinput_device *device, uint64_t time, int finger_count); void gesture_notify_hold_end(struct libinput_device *device, uint64_t time, int finger_count, bool cancelled); void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y); void tablet_notify_proximity(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_proximity_state state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y); void tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y); void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, const struct tablet_axes *axes, int32_t button, enum libinput_button_state state, const struct input_absinfo *x, const struct input_absinfo *y); void tablet_pad_notify_button(struct libinput_device *device, uint64_t time, int32_t button, enum libinput_button_state state, struct libinput_tablet_pad_mode_group *group); void tablet_pad_notify_dial(struct libinput_device *device, uint64_t time, unsigned int number, double value, struct libinput_tablet_pad_mode_group *group); void tablet_pad_notify_ring(struct libinput_device *device, uint64_t time, unsigned int number, double value, enum libinput_tablet_pad_ring_axis_source source, struct libinput_tablet_pad_mode_group *group); void tablet_pad_notify_strip(struct libinput_device *device, uint64_t time, unsigned int number, double value, enum libinput_tablet_pad_strip_axis_source source, struct libinput_tablet_pad_mode_group *group); void tablet_pad_notify_key(struct libinput_device *device, uint64_t time, int32_t key, enum libinput_key_state state); void switch_notify_toggle(struct libinput_device *device, uint64_t time, enum libinput_switch sw, enum libinput_switch_state state); static inline uint64_t libinput_now(struct libinput *libinput) { uint64_t now; int rc = now_in_us(&now); if (rc < 0) { log_error(libinput, "clock_gettime failed: %s\n", strerror(-rc)); return 0; } return now; } static inline struct device_float_coords device_delta(const struct device_coords a, const struct device_coords b) { struct device_float_coords delta; delta.x = a.x - b.x; delta.y = a.y - b.y; return delta; } static inline struct device_float_coords device_average(const struct device_coords a, const struct device_coords b) { struct device_float_coords average; average.x = (a.x + b.x) / 2.0; average.y = (a.y + b.y) / 2.0; return average; } static inline struct device_float_coords device_float_delta(const struct device_float_coords a, const struct device_float_coords b) { struct device_float_coords delta; delta.x = a.x - b.x; delta.y = a.y - b.y; return delta; } static inline struct device_float_coords device_float_average(const struct device_float_coords a, const struct device_float_coords b) { struct device_float_coords average; average.x = (a.x + b.x) / 2.0; average.y = (a.y + b.y) / 2.0; return average; } static inline bool device_float_is_zero(const struct device_float_coords coords) { return coords.x == 0.0 && coords.y == 0.0; } static inline double normalized_length(const struct normalized_coords norm) { return hypot(norm.x, norm.y); } static inline bool normalized_is_zero(const struct normalized_coords norm) { return norm.x == 0.0 && norm.y == 0.0; } static inline double length_in_mm(const struct phys_coords mm) { return hypot(mm.x, mm.y); } enum directions { N = bit(0), NE = bit(1), E = bit(2), SE = bit(3), S = bit(4), SW = bit(5), W = bit(6), NW = bit(7), UNDEFINED_DIRECTION = 0xff }; static inline uint32_t xy_get_direction(double x, double y) { uint32_t dir = UNDEFINED_DIRECTION; int d1, d2; double r; if (fabs(x) < 2.0 && fabs(y) < 2.0) { if (x > 0.0 && y > 0.0) dir = S | SE | E; else if (x > 0.0 && y < 0.0) dir = N | NE | E; else if (x < 0.0 && y > 0.0) dir = S | SW | W; else if (x < 0.0 && y < 0.0) dir = N | NW | W; else if (x > 0.0) dir = NE | E | SE; else if (x < 0.0) dir = NW | W | SW; else if (y > 0.0) dir = SE | S | SW; else if (y < 0.0) dir = NE | N | NW; } else { /* Calculate r within the interval [0 to 8) * * r = [0 .. 2π] where 0 is North * d_f = r / 2π ([0 .. 1)) * d_8 = 8 * d_f */ r = atan2(y, x); r = fmod(r + 2.5*M_PI, 2*M_PI); r *= 4*M_1_PI; /* Mark one or two close enough octants */ d1 = (int)(r + 0.9) % 8; d2 = (int)(r + 0.1) % 8; dir = bit(d1) | bit(d2); } return dir; } static inline uint32_t phys_get_direction(const struct phys_coords mm) { return xy_get_direction(mm.x, mm.y); } /** * Get the direction for the given set of coordinates. * assumption: coordinates are normalized to one axis resolution. */ static inline uint32_t device_float_get_direction(const struct device_float_coords coords) { return xy_get_direction(coords.x, coords.y); } /** * Returns true if the point is within the given rectangle, including the * left edge but excluding the right edge. */ static inline bool point_in_rect(const struct device_coords *point, const struct device_coord_rect *rect) { return (point->x >= rect->x && point->x < rect->x + rect->w && point->y >= rect->y && point->y < rect->y + rect->h); } #if HAVE_LIBWACOM WacomDeviceDatabase * libinput_libwacom_ref(struct libinput *li); void libinput_libwacom_unref(struct libinput *li); #else static inline void *libinput_libwacom_ref(struct libinput *li) { return NULL; } static inline void libinput_libwacom_unref(struct libinput *li) {} #endif #endif /* LIBINPUT_PRIVATE_H */ libinput-1.28.1/src/libinput-restore-selinux-context.sh000066400000000000000000000004021477265155700232510ustar00rootroot00000000000000#!/bin/sh # # $1: abs path to libdir # $2: abs path to .so file libdir="$1" sofile=$(basename "$2") if command -v restorecon >/dev/null; then echo "Restoring SELinux context on ${DESTDIR}${libdir}/${sofile}" restorecon "${DESTDIR}${libdir}/${sofile}" fi libinput-1.28.1/src/libinput-uninstalled.pc.in000066400000000000000000000003651477265155700213460ustar00rootroot00000000000000libdir=@abs_builddir@/.libs includedir=@abs_srcdir@ Name: Libinput Description: Input device library (not installed) Version: @LIBINPUT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -linput Libs.private: -lm -lrt Requires.private: libudev libinput-1.28.1/src/libinput-util.h000066400000000000000000000050341477265155700172170ustar00rootroot00000000000000/* * Copyright © 2008 Kristian Høgsberg * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef LIBINPUT_UTIL_H #define LIBINPUT_UTIL_H #include "config.h" #ifdef NDEBUG #warning "libinput relies on assert(). #defining NDEBUG is not recommended" #endif #include "libinput.h" #include "util-bits.h" #include "util-macros.h" #include "util-list.h" #include "util-matrix.h" #include "util-multivalue.h" #include "util-strings.h" #include "util-ratelimit.h" #include "util-range.h" #include "util-prop-parsers.h" #include "util-time.h" #define VENDOR_ID_APPLE 0x5ac #define VENDOR_ID_CHICONY 0x4f2 #define VENDOR_ID_LOGITECH 0x46d #define VENDOR_ID_WACOM 0x56a #define VENDOR_ID_SYNAPTICS_SERIAL 0x002 #define PRODUCT_ID_APPLE_KBD_TOUCHPAD 0x273 #define PRODUCT_ID_APPLE_APPLETOUCH 0x21a #define PRODUCT_ID_SYNAPTICS_SERIAL 0x007 #define PRODUCT_ID_WACOM_EKR 0x0331 /* The HW DPI rate we normalize to before calculating pointer acceleration */ #define DEFAULT_MOUSE_DPI 1000 #define DEFAULT_TRACKPOINT_SENSITIVITY 128 #define _trace(file, ...) \ do { \ char buf_[1024]; \ snprintf(buf_, sizeof(buf_), __VA_ARGS__); \ fprintf(file, ANSI_BLUE "%30s():%4d - " ANSI_RED "%s" ANSI_NORMAL "\n", __func__, __LINE__, buf_); \ } while (0) #define trace(...) _trace(stdout, __VA_ARGS__) #define etrace(...) _trace(stderr, __VA_ARGS__) #define LIBINPUT_EXPORT __attribute__ ((visibility("default"))) #define LIBINPUT_UNUSED __attribute__ ((unused)) #endif /* LIBINPUT_UTIL_H */ libinput-1.28.1/src/libinput-version.h.in000066400000000000000000000026251477265155700203370ustar00rootroot00000000000000/* * Copyright © 2013 Jonas Ådahl * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef LIBINPUT_VERSION_H #define LIBINPUT_VERSION_H #define LIBINPUT_VERSION_MAJOR @LIBINPUT_VERSION_MAJOR@ #define LIBINPUT_VERSION_MINOR @LIBINPUT_VERSION_MINOR@ #define LIBINPUT_VERSION_MICRO @LIBINPUT_VERSION_MICRO@ #define LIBINPUT_VERSION "@LIBINPUT_VERSION@" #endif libinput-1.28.1/src/libinput-versionsort.h000066400000000000000000000050361477265155700206410ustar00rootroot00000000000000#pragma once /* Copyright © 2005-2014 Rich Felker, et al. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #if !defined(HAVE_VERSIONSORT) || defined(TEST_VERSIONSORT) static inline int libinput_strverscmp(const char *l0, const char *r0) { const unsigned char *l = (const void *)l0; const unsigned char *r = (const void *)r0; size_t i, dp, j; int z = 1; /* Find maximal matching prefix and track its maximal digit * suffix and whether those digits are all zeros. */ for (dp=i=0; l[i]==r[i]; i++) { int c = l[i]; if (!c) return 0; if (!isdigit(c)) dp=i+1, z=1; else if (c!='0') z=0; } if (l[dp]!='0' && r[dp]!='0') { /* If we're not looking at a digit sequence that began * with a zero, longest digit string is greater. */ for (j=i; isdigit(l[j]); j++) if (!isdigit(r[j])) return 1; if (isdigit(r[j])) return -1; } else if (z && dpd_name, (*b)->d_name); } #endif libinput-1.28.1/src/libinput.c000066400000000000000000004077201477265155700162470ustar00rootroot00000000000000/* * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include "libinput.h" #include "libinput-private.h" #include "util-input-event.h" #include "util-libinput.h" #include "evdev.h" #include "timer.h" #include "quirks.h" #define require_event_type(li_, type_, retval_, ...) \ if (type_ == LIBINPUT_EVENT_NONE) abort(); \ if (!check_event_type(li_, __func__, type_, __VA_ARGS__, -1)) \ return retval_; \ #define ASSERT_INT_SIZE(type_) \ static_assert(sizeof(type_) == sizeof(unsigned int), \ "sizeof(" #type_ ") must be sizeof(uint)") ASSERT_INT_SIZE(enum libinput_log_priority); ASSERT_INT_SIZE(enum libinput_device_capability); ASSERT_INT_SIZE(enum libinput_key_state); ASSERT_INT_SIZE(enum libinput_led); ASSERT_INT_SIZE(enum libinput_button_state); ASSERT_INT_SIZE(enum libinput_pointer_axis); ASSERT_INT_SIZE(enum libinput_pointer_axis_source); ASSERT_INT_SIZE(enum libinput_tablet_pad_ring_axis_source); ASSERT_INT_SIZE(enum libinput_tablet_pad_strip_axis_source); ASSERT_INT_SIZE(enum libinput_tablet_tool_type); ASSERT_INT_SIZE(enum libinput_tablet_tool_proximity_state); ASSERT_INT_SIZE(enum libinput_tablet_tool_tip_state); ASSERT_INT_SIZE(enum libinput_switch_state); ASSERT_INT_SIZE(enum libinput_switch); ASSERT_INT_SIZE(enum libinput_event_type); ASSERT_INT_SIZE(enum libinput_config_status); ASSERT_INT_SIZE(enum libinput_config_tap_state); ASSERT_INT_SIZE(enum libinput_config_tap_button_map); ASSERT_INT_SIZE(enum libinput_config_drag_state); ASSERT_INT_SIZE(enum libinput_config_drag_lock_state); ASSERT_INT_SIZE(enum libinput_config_send_events_mode); ASSERT_INT_SIZE(enum libinput_config_accel_profile); ASSERT_INT_SIZE(enum libinput_config_click_method); ASSERT_INT_SIZE(enum libinput_config_clickfinger_button_map); ASSERT_INT_SIZE(enum libinput_config_middle_emulation_state); ASSERT_INT_SIZE(enum libinput_config_scroll_method); ASSERT_INT_SIZE(enum libinput_config_dwt_state); ASSERT_INT_SIZE(enum libinput_config_dwtp_state); static inline const char * event_type_to_str(enum libinput_event_type type) { switch(type) { CASE_RETURN_STRING(LIBINPUT_EVENT_DEVICE_ADDED); CASE_RETURN_STRING(LIBINPUT_EVENT_DEVICE_REMOVED); CASE_RETURN_STRING(LIBINPUT_EVENT_KEYBOARD_KEY); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_BUTTON); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_AXIS); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_SCROLL_WHEEL); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_SCROLL_FINGER); CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_DOWN); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_UP); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_MOTION); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_CANCEL); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_FRAME); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_AXIS); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_TIP); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_BUTTON); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_BUTTON); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_RING); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_STRIP); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_KEY); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_DIAL); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_END); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_BEGIN); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_UPDATE); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_END); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_HOLD_BEGIN); CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_HOLD_END); CASE_RETURN_STRING(LIBINPUT_EVENT_SWITCH_TOGGLE); case LIBINPUT_EVENT_NONE: abort(); } return NULL; } static inline bool check_event_type(struct libinput *libinput, const char *function_name, unsigned int type_in, ...) { bool rc = false; va_list args; unsigned int type_permitted; va_start(args, type_in); type_permitted = va_arg(args, unsigned int); while (type_permitted != (unsigned int)-1) { if (type_permitted == type_in) { rc = true; break; } type_permitted = va_arg(args, unsigned int); } va_end(args); if (!rc) { const char *name = event_type_to_str(type_in); log_bug_client(libinput, "Invalid event type %s (%d) passed to %s()\n", name, type_in, function_name); } return rc; } struct libinput_source { libinput_source_dispatch_t dispatch; void *user_data; int fd; struct list link; }; struct libinput_event_device_notify { struct libinput_event base; }; struct libinput_event_keyboard { struct libinput_event base; uint64_t time; uint32_t key; uint32_t seat_key_count; enum libinput_key_state state; }; struct libinput_event_pointer { struct libinput_event base; uint64_t time; struct normalized_coords delta; struct device_float_coords delta_raw; struct device_coords absolute; struct discrete_coords discrete; struct wheel_v120 v120; uint32_t button; uint32_t seat_button_count; enum libinput_button_state state; enum libinput_pointer_axis_source source; uint32_t axes; }; struct libinput_event_touch { struct libinput_event base; uint64_t time; int32_t slot; int32_t seat_slot; struct device_coords point; }; struct libinput_event_gesture { struct libinput_event base; uint64_t time; int finger_count; int cancelled; struct normalized_coords delta; struct normalized_coords delta_unaccel; double scale; double angle; }; struct libinput_event_tablet_tool { struct libinput_event base; uint32_t button; enum libinput_button_state state; uint32_t seat_button_count; uint64_t time; struct tablet_axes axes; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; enum libinput_tablet_tool_proximity_state proximity_state; enum libinput_tablet_tool_tip_state tip_state; struct { struct input_absinfo x; struct input_absinfo y; } abs; }; struct libinput_event_tablet_pad { struct libinput_event base; unsigned int mode; struct libinput_tablet_pad_mode_group *mode_group; uint64_t time; struct { uint32_t number; enum libinput_button_state state; } button; struct { uint32_t code; enum libinput_key_state state; } key; struct { double v120; int number; } dial; struct { enum libinput_tablet_pad_ring_axis_source source; double position; int number; } ring; struct { enum libinput_tablet_pad_strip_axis_source source; double position; int number; } strip; }; struct libinput_event_switch { struct libinput_event base; uint64_t time; enum libinput_switch sw; enum libinput_switch_state state; }; LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void libinput_default_log_func(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { const char *prefix; switch(priority) { case LIBINPUT_LOG_PRIORITY_DEBUG: prefix = "debug"; break; case LIBINPUT_LOG_PRIORITY_INFO: prefix = "info"; break; case LIBINPUT_LOG_PRIORITY_ERROR: prefix = "error"; break; default: prefix=""; break; } fprintf(stderr, "libinput %s: ", prefix); vfprintf(stderr, format, args); } void log_msg_va(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { if (is_logged(libinput, priority)) libinput->log_handler(libinput, priority, format, args); } void log_msg(struct libinput *libinput, enum libinput_log_priority priority, const char *format, ...) { va_list args; va_start(args, format); log_msg_va(libinput, priority, format, args); va_end(args); } void log_msg_ratelimit(struct libinput *libinput, struct ratelimit *ratelimit, enum libinput_log_priority priority, const char *format, ...) { va_list args; enum ratelimit_state state; state = ratelimit_test(ratelimit); if (state == RATELIMIT_EXCEEDED) return; va_start(args, format); log_msg_va(libinput, priority, format, args); va_end(args); if (state == RATELIMIT_THRESHOLD) log_msg(libinput, priority, "WARNING: log rate limit exceeded (%d msgs per %dms). Discarding future messages.\n", ratelimit->burst, us2ms(ratelimit->interval)); } LIBINPUT_EXPORT void libinput_log_set_priority(struct libinput *libinput, enum libinput_log_priority priority) { libinput->log_priority = priority; } LIBINPUT_EXPORT enum libinput_log_priority libinput_log_get_priority(const struct libinput *libinput) { return libinput->log_priority; } LIBINPUT_EXPORT void libinput_log_set_handler(struct libinput *libinput, libinput_log_handler log_handler) { libinput->log_handler = log_handler; } static void libinput_device_group_destroy(struct libinput_device_group *group); static void libinput_post_event(struct libinput *libinput, struct libinput_event *event); LIBINPUT_EXPORT enum libinput_event_type libinput_event_get_type(struct libinput_event *event) { return event->type; } LIBINPUT_EXPORT struct libinput * libinput_event_get_context(struct libinput_event *event) { return event->device->seat->libinput; } LIBINPUT_EXPORT struct libinput_device * libinput_event_get_device(struct libinput_event *event) { return event->device; } LIBINPUT_EXPORT struct libinput_event_pointer * libinput_event_get_pointer_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_POINTER_MOTION, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, LIBINPUT_EVENT_POINTER_BUTTON, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_POINTER_AXIS); return (struct libinput_event_pointer *) event; } LIBINPUT_EXPORT struct libinput_event_keyboard * libinput_event_get_keyboard_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_KEYBOARD_KEY); return (struct libinput_event_keyboard *) event; } LIBINPUT_EXPORT struct libinput_event_touch * libinput_event_get_touch_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL, LIBINPUT_EVENT_TOUCH_FRAME); return (struct libinput_event_touch *) event; } LIBINPUT_EXPORT struct libinput_event_gesture * libinput_event_get_gesture_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); return (struct libinput_event_gesture *) event; } LIBINPUT_EXPORT struct libinput_event_tablet_tool * libinput_event_get_tablet_tool_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return (struct libinput_event_tablet_tool *) event; } LIBINPUT_EXPORT struct libinput_event_tablet_pad * libinput_event_get_tablet_pad_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON, LIBINPUT_EVENT_TABLET_PAD_KEY); return (struct libinput_event_tablet_pad *) event; } LIBINPUT_EXPORT struct libinput_event_device_notify * libinput_event_get_device_notify_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_DEVICE_ADDED, LIBINPUT_EVENT_DEVICE_REMOVED); return (struct libinput_event_device_notify *) event; } LIBINPUT_EXPORT struct libinput_event_switch * libinput_event_get_switch_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, NULL, LIBINPUT_EVENT_SWITCH_TOGGLE); return (struct libinput_event_switch *) event; } LIBINPUT_EXPORT uint32_t libinput_event_keyboard_get_time(struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_KEYBOARD_KEY); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_keyboard_get_time_usec(struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_KEYBOARD_KEY); return event->time; } LIBINPUT_EXPORT uint32_t libinput_event_keyboard_get_key(struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_KEYBOARD_KEY); return event->key; } LIBINPUT_EXPORT enum libinput_key_state libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_KEYBOARD_KEY); return event->state; } LIBINPUT_EXPORT uint32_t libinput_event_keyboard_get_seat_key_count( struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_KEYBOARD_KEY); return event->seat_key_count; } LIBINPUT_EXPORT uint32_t libinput_event_pointer_get_time(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, LIBINPUT_EVENT_POINTER_BUTTON, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_POINTER_AXIS); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_pointer_get_time_usec(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, LIBINPUT_EVENT_POINTER_BUTTON, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_POINTER_AXIS); return event->time; } LIBINPUT_EXPORT double libinput_event_pointer_get_dx(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION); return event->delta.x; } LIBINPUT_EXPORT double libinput_event_pointer_get_dy(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION); return event->delta.y; } LIBINPUT_EXPORT double libinput_event_pointer_get_dx_unaccelerated( struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION); return event->delta_raw.x; } LIBINPUT_EXPORT double libinput_event_pointer_get_dy_unaccelerated( struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION); return event->delta_raw.y; } LIBINPUT_EXPORT double libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); return absinfo_convert_to_mm(device->abs.absinfo_x, event->absolute.x); } LIBINPUT_EXPORT double libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); return absinfo_convert_to_mm(device->abs.absinfo_y, event->absolute.y); } LIBINPUT_EXPORT double libinput_event_pointer_get_absolute_x_transformed( struct libinput_event_pointer *event, uint32_t width) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); return evdev_device_transform_x(device, event->absolute.x, width); } LIBINPUT_EXPORT double libinput_event_pointer_get_absolute_y_transformed( struct libinput_event_pointer *event, uint32_t height) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); return evdev_device_transform_y(device, event->absolute.y, height); } LIBINPUT_EXPORT uint32_t libinput_event_pointer_get_button(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_BUTTON); return event->button; } LIBINPUT_EXPORT enum libinput_button_state libinput_event_pointer_get_button_state(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_BUTTON); return event->state; } LIBINPUT_EXPORT uint32_t libinput_event_pointer_get_seat_button_count( struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_BUTTON); return event->seat_button_count; } LIBINPUT_EXPORT int libinput_event_pointer_has_axis(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_POINTER_AXIS); switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: return !!(event->axes & bit(axis)); } return 0; } LIBINPUT_EXPORT double libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { struct libinput *libinput = event->base.device->seat->libinput; double value = 0; require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_POINTER_AXIS); if (!libinput_event_pointer_has_axis(event, axis)) { log_bug_client(libinput, "value requested for unset axis\n"); } else { switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: value = event->delta.x; break; case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: value = event->delta.y; break; } } return value; } LIBINPUT_EXPORT double libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { struct libinput *libinput = event->base.device->seat->libinput; double value = 0; require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_POINTER_AXIS); if (!libinput_event_pointer_has_axis(event, axis)) { log_bug_client(libinput, "value requested for unset axis\n"); } else { switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: value = event->discrete.x; break; case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: value = event->discrete.y; break; } } return value; } LIBINPUT_EXPORT double libinput_event_pointer_get_scroll_value(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { struct libinput *libinput = event->base.device->seat->libinput; double value = 0; require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); if (!libinput_event_pointer_has_axis(event, axis)) { log_bug_client(libinput, "value requested for unset axis\n"); } else { switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: value = event->delta.x; break; case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: value = event->delta.y; break; } } return value; } LIBINPUT_EXPORT double libinput_event_pointer_get_scroll_value_v120(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { struct libinput *libinput = event->base.device->seat->libinput; double value = 0; require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL); if (!libinput_event_pointer_has_axis(event, axis)) { log_bug_client(libinput, "value requested for unset axis\n"); } else { switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: value = event->v120.x; break; case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: value = event->v120.y; break; } } return value; } LIBINPUT_EXPORT enum libinput_pointer_axis_source libinput_event_pointer_get_axis_source(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_POINTER_AXIS); return event->source; } LIBINPUT_EXPORT uint32_t libinput_event_touch_get_time(struct libinput_event_touch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL, LIBINPUT_EVENT_TOUCH_FRAME); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_touch_get_time_usec(struct libinput_event_touch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL, LIBINPUT_EVENT_TOUCH_FRAME); return event->time; } LIBINPUT_EXPORT int32_t libinput_event_touch_get_slot(struct libinput_event_touch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL); return event->slot; } LIBINPUT_EXPORT int32_t libinput_event_touch_get_seat_slot(struct libinput_event_touch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL); return event->seat_slot; } LIBINPUT_EXPORT double libinput_event_touch_get_x(struct libinput_event_touch *event) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_MOTION); return absinfo_convert_to_mm(device->abs.absinfo_x, event->point.x); } LIBINPUT_EXPORT double libinput_event_touch_get_x_transformed(struct libinput_event_touch *event, uint32_t width) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_MOTION); return evdev_device_transform_x(device, event->point.x, width); } LIBINPUT_EXPORT double libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_MOTION); return evdev_device_transform_y(device, event->point.y, height); } LIBINPUT_EXPORT double libinput_event_touch_get_y(struct libinput_event_touch *event) { struct evdev_device *device = evdev_device(event->base.device); require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_MOTION); return absinfo_convert_to_mm(device->abs.absinfo_y, event->point.y); } LIBINPUT_EXPORT uint32_t libinput_event_gesture_get_time(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_gesture_get_time_usec(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); return event->time; } LIBINPUT_EXPORT int libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); return event->finger_count; } LIBINPUT_EXPORT int libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_HOLD_END); return event->cancelled; } LIBINPUT_EXPORT double libinput_event_gesture_get_dx(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END); return event->delta.x; } LIBINPUT_EXPORT double libinput_event_gesture_get_dy(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END); return event->delta.y; } LIBINPUT_EXPORT double libinput_event_gesture_get_dx_unaccelerated( struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END); return event->delta_unaccel.x; } LIBINPUT_EXPORT double libinput_event_gesture_get_dy_unaccelerated( struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END); return event->delta_unaccel.y; } LIBINPUT_EXPORT double libinput_event_gesture_get_scale(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END); return event->scale; } LIBINPUT_EXPORT double libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END); return event->angle; } LIBINPUT_EXPORT int libinput_event_tablet_tool_x_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X); } LIBINPUT_EXPORT int libinput_event_tablet_tool_y_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y); } LIBINPUT_EXPORT int libinput_event_tablet_tool_pressure_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); } LIBINPUT_EXPORT int libinput_event_tablet_tool_distance_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); } LIBINPUT_EXPORT int libinput_event_tablet_tool_tilt_x_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); } LIBINPUT_EXPORT int libinput_event_tablet_tool_tilt_y_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); } LIBINPUT_EXPORT int libinput_event_tablet_tool_rotation_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } LIBINPUT_EXPORT int libinput_event_tablet_tool_slider_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); } LIBINPUT_EXPORT int libinput_event_tablet_tool_size_major_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR); } LIBINPUT_EXPORT int libinput_event_tablet_tool_size_minor_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR); } LIBINPUT_EXPORT int libinput_event_tablet_tool_wheel_has_changed( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return absinfo_convert_to_mm(&event->abs.x, event->axes.point.x); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return absinfo_convert_to_mm(&event->abs.y, event->axes.point.y); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_dx(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.delta.x; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_dy(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.delta.y; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.pressure; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.distance; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.tilt.x; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.tilt.y; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.rotation; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.slider; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_size_major(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.size.major; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_size_minor(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.size.minor; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.wheel; } LIBINPUT_EXPORT int libinput_event_tablet_tool_get_wheel_delta_discrete( struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->axes.wheel_discrete; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event, uint32_t width) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return absinfo_scale_axis(&event->abs.x, event->axes.point.x, width); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event, uint32_t height) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return absinfo_scale_axis(&event->abs.y, event->axes.point.y, height); } LIBINPUT_EXPORT struct libinput_tablet_tool * libinput_event_tablet_tool_get_tool(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->tool; } LIBINPUT_EXPORT enum libinput_tablet_tool_proximity_state libinput_event_tablet_tool_get_proximity_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->proximity_state; } LIBINPUT_EXPORT enum libinput_tablet_tool_tip_state libinput_event_tablet_tool_get_tip_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->tip_state; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_tool_get_time(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->time; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_tool_get_button(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->button; } LIBINPUT_EXPORT enum libinput_button_state libinput_event_tablet_tool_get_button_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->state; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_tool_get_seat_button_count(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->seat_button_count; } LIBINPUT_EXPORT enum libinput_tablet_tool_type libinput_tablet_tool_get_type(struct libinput_tablet_tool *tool) { return tool->type; } LIBINPUT_EXPORT uint64_t libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool) { return tool->tool_id; } LIBINPUT_EXPORT int libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool) { return tool->serial != 0; } LIBINPUT_EXPORT uint64_t libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool) { return tool->serial; } LIBINPUT_EXPORT int libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); } LIBINPUT_EXPORT int libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); } LIBINPUT_EXPORT int libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); } LIBINPUT_EXPORT int libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } LIBINPUT_EXPORT int libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); } LIBINPUT_EXPORT int libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } LIBINPUT_EXPORT int libinput_tablet_tool_has_size(struct libinput_tablet_tool *tool) { return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR); } LIBINPUT_EXPORT int libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, uint32_t code) { if (NCHARS(code) > sizeof(tool->buttons)) return 0; return bit_is_set(tool->buttons, code); } LIBINPUT_EXPORT void libinput_tablet_tool_set_user_data(struct libinput_tablet_tool *tool, void *user_data) { tool->user_data = user_data; } LIBINPUT_EXPORT void * libinput_tablet_tool_get_user_data(struct libinput_tablet_tool *tool) { return tool->user_data; } LIBINPUT_EXPORT struct libinput_tablet_tool * libinput_tablet_tool_ref(struct libinput_tablet_tool *tool) { tool->refcount++; return tool; } LIBINPUT_EXPORT struct libinput_tablet_tool * libinput_tablet_tool_unref(struct libinput_tablet_tool *tool) { assert(tool->refcount > 0); tool->refcount--; if (tool->refcount > 0) return tool; list_remove(&tool->link); free(tool); return NULL; } LIBINPUT_EXPORT struct libinput_event * libinput_event_switch_get_base_event(struct libinput_event_switch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_SWITCH_TOGGLE); return &event->base; } LIBINPUT_EXPORT enum libinput_switch libinput_event_switch_get_switch(struct libinput_event_switch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_SWITCH_TOGGLE); return event->sw; } LIBINPUT_EXPORT enum libinput_switch_state libinput_event_switch_get_switch_state(struct libinput_event_switch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_SWITCH_TOGGLE); return event->state; } LIBINPUT_EXPORT uint32_t libinput_event_switch_get_time(struct libinput_event_switch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_SWITCH_TOGGLE); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_switch_get_time_usec(struct libinput_event_switch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_SWITCH_TOGGLE); return event->time; } struct libinput_source * libinput_add_fd(struct libinput *libinput, int fd, libinput_source_dispatch_t dispatch, void *user_data) { struct libinput_source *source; struct epoll_event ep; source = zalloc(sizeof *source); source->dispatch = dispatch; source->user_data = user_data; source->fd = fd; memset(&ep, 0, sizeof ep); ep.events = EPOLLIN; ep.data.ptr = source; if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) { free(source); return NULL; } return source; } void libinput_remove_source(struct libinput *libinput, struct libinput_source *source) { epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL); source->fd = -1; list_insert(&libinput->source_destroy_list, &source->link); } int libinput_init(struct libinput *libinput, const struct libinput_interface *interface, const struct libinput_interface_backend *interface_backend, void *user_data) { assert(interface->open_restricted != NULL); assert(interface->close_restricted != NULL); libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (libinput->epoll_fd < 0) return -1; libinput->events_len = 4; libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events)); libinput->log_handler = libinput_default_log_func; libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR; libinput->interface = interface; libinput->interface_backend = interface_backend; libinput->user_data = user_data; libinput->refcount = 1; list_init(&libinput->source_destroy_list); list_init(&libinput->seat_list); list_init(&libinput->device_group_list); list_init(&libinput->tool_list); if (libinput_timer_subsys_init(libinput) != 0) { free(libinput->events); close(libinput->epoll_fd); return -1; } return 0; } void libinput_init_quirks(struct libinput *libinput) { const char *data_path, *override_file = NULL; struct quirks_context *quirks; if (libinput->quirks_initialized) return; /* If we fail, we'll fail next time too */ libinput->quirks_initialized = true; data_path = getenv("LIBINPUT_QUIRKS_DIR"); if (!data_path) { data_path = LIBINPUT_QUIRKS_DIR; override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE; } quirks = quirks_init_subsystem(data_path, override_file, log_msg_va, libinput, QLOG_LIBINPUT_LOGGING); if (!quirks) { log_error(libinput, "Failed to load the device quirks from %s%s%s. " "This will negatively affect device behavior. " "See %s/device-quirks.html for details.\n", data_path, override_file ? " and " : "", override_file ? override_file : "", HTTP_DOC_LINK ); return; } libinput->quirks = quirks; } static void libinput_device_destroy(struct libinput_device *device); static void libinput_seat_destroy(struct libinput_seat *seat); static void libinput_drop_destroyed_sources(struct libinput *libinput) { struct libinput_source *source; list_for_each_safe(source, &libinput->source_destroy_list, link) free(source); list_init(&libinput->source_destroy_list); } LIBINPUT_EXPORT struct libinput * libinput_ref(struct libinput *libinput) { libinput->refcount++; return libinput; } LIBINPUT_EXPORT struct libinput * libinput_unref(struct libinput *libinput) { struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat; struct libinput_tablet_tool *tool; struct libinput_device_group *group; if (libinput == NULL) return NULL; assert(libinput->refcount > 0); libinput->refcount--; if (libinput->refcount > 0) return libinput; libinput_suspend(libinput); libinput->interface_backend->destroy(libinput); while ((event = libinput_get_event(libinput))) libinput_event_destroy(event); free(libinput->events); list_for_each_safe(seat, &libinput->seat_list, link) { list_for_each_safe(device, &seat->devices_list, link) libinput_device_destroy(device); libinput_seat_destroy(seat); } list_for_each_safe(group, &libinput->device_group_list, link) { libinput_device_group_destroy(group); } list_for_each_safe(tool, &libinput->tool_list, link) { libinput_tablet_tool_unref(tool); } libinput_timer_subsys_destroy(libinput); libinput_drop_destroyed_sources(libinput); quirks_context_unref(libinput->quirks); close(libinput->epoll_fd); free(libinput); return NULL; } static void libinput_event_tablet_tool_destroy(struct libinput_event_tablet_tool *event) { libinput_tablet_tool_unref(event->tool); } static void libinput_event_tablet_pad_destroy(struct libinput_event_tablet_pad *event) { if (event->base.type != LIBINPUT_EVENT_TABLET_PAD_KEY) libinput_tablet_pad_mode_group_unref(event->mode_group); } LIBINPUT_EXPORT void libinput_event_destroy(struct libinput_event *event) { if (event == NULL) return; switch(event->type) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: case LIBINPUT_EVENT_TABLET_TOOL_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_TIP: case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: libinput_event_tablet_tool_destroy( libinput_event_get_tablet_tool_event(event)); break; case LIBINPUT_EVENT_TABLET_PAD_RING: case LIBINPUT_EVENT_TABLET_PAD_DIAL: case LIBINPUT_EVENT_TABLET_PAD_STRIP: case LIBINPUT_EVENT_TABLET_PAD_BUTTON: case LIBINPUT_EVENT_TABLET_PAD_KEY: libinput_event_tablet_pad_destroy( libinput_event_get_tablet_pad_event(event)); break; default: break; } if (event->device) libinput_device_unref(event->device); free(event); } int open_restricted(struct libinput *libinput, const char *path, int flags) { return libinput->interface->open_restricted(path, flags, libinput->user_data); } void close_restricted(struct libinput *libinput, int fd) { libinput->interface->close_restricted(fd, libinput->user_data); } bool ignore_litest_test_suite_device(struct udev_device *device) { if (!getenv("LIBINPUT_RUNNING_TEST_SUITE") && udev_device_get_property_value(device, "LIBINPUT_TEST_DEVICE")) return true; return false; } void libinput_seat_init(struct libinput_seat *seat, struct libinput *libinput, const char *physical_name, const char *logical_name, libinput_seat_destroy_func destroy) { seat->refcount = 1; seat->libinput = libinput; seat->physical_name = safe_strdup(physical_name); seat->logical_name = safe_strdup(logical_name); seat->destroy = destroy; list_init(&seat->devices_list); list_insert(&libinput->seat_list, &seat->link); } LIBINPUT_EXPORT struct libinput_seat * libinput_seat_ref(struct libinput_seat *seat) { seat->refcount++; return seat; } static void libinput_seat_destroy(struct libinput_seat *seat) { list_remove(&seat->link); free(seat->logical_name); free(seat->physical_name); seat->destroy(seat); } LIBINPUT_EXPORT struct libinput_seat * libinput_seat_unref(struct libinput_seat *seat) { assert(seat->refcount > 0); seat->refcount--; if (seat->refcount == 0) { libinput_seat_destroy(seat); return NULL; } return seat; } LIBINPUT_EXPORT void libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data) { seat->user_data = user_data; } LIBINPUT_EXPORT void * libinput_seat_get_user_data(struct libinput_seat *seat) { return seat->user_data; } LIBINPUT_EXPORT struct libinput * libinput_seat_get_context(struct libinput_seat *seat) { return seat->libinput; } LIBINPUT_EXPORT const char * libinput_seat_get_physical_name(struct libinput_seat *seat) { return seat->physical_name; } LIBINPUT_EXPORT const char * libinput_seat_get_logical_name(struct libinput_seat *seat) { return seat->logical_name; } void libinput_device_init(struct libinput_device *device, struct libinput_seat *seat) { device->seat = seat; device->refcount = 1; list_init(&device->event_listeners); } LIBINPUT_EXPORT struct libinput_device * libinput_device_ref(struct libinput_device *device) { device->refcount++; return device; } static void libinput_device_destroy(struct libinput_device *device) { assert(list_empty(&device->event_listeners)); evdev_device_destroy(evdev_device(device)); } LIBINPUT_EXPORT struct libinput_device * libinput_device_unref(struct libinput_device *device) { assert(device->refcount > 0); device->refcount--; if (device->refcount == 0) { libinput_device_destroy(device); return NULL; } return device; } LIBINPUT_EXPORT int libinput_get_fd(struct libinput *libinput) { return libinput->epoll_fd; } LIBINPUT_EXPORT int libinput_dispatch(struct libinput *libinput) { static uint8_t take_time_snapshot; struct libinput_source *source; struct epoll_event ep[32]; int i, count; /* Every 10 calls to libinput_dispatch() we take the current time so * we can check the delay between our current time and the event * timestamps */ if ((++take_time_snapshot % 10) == 0) libinput->dispatch_time = libinput_now(libinput); else if (libinput->dispatch_time) libinput->dispatch_time = 0; count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0); if (count < 0) return -errno; for (i = 0; i < count; ++i) { source = ep[i].data.ptr; if (source->fd == -1) continue; source->dispatch(source->user_data); } libinput_drop_destroyed_sources(libinput); return 0; } void libinput_device_init_event_listener(struct libinput_event_listener *listener) { list_init(&listener->link); } void libinput_device_add_event_listener(struct libinput_device *device, struct libinput_event_listener *listener, void (*notify_func)( uint64_t time, struct libinput_event *event, void *notify_func_data), void *notify_func_data) { listener->notify_func = notify_func; listener->notify_func_data = notify_func_data; list_insert(&device->event_listeners, &listener->link); } void libinput_device_remove_event_listener(struct libinput_event_listener *listener) { list_remove(&listener->link); } static uint32_t update_seat_key_count(struct libinput_seat *seat, int32_t key, enum libinput_key_state state) { assert(key >= 0 && key <= KEY_MAX); switch (state) { case LIBINPUT_KEY_STATE_PRESSED: return ++seat->button_count[key]; case LIBINPUT_KEY_STATE_RELEASED: /* We might not have received the first PRESSED event. */ if (seat->button_count[key] == 0) return 0; return --seat->button_count[key]; } return 0; } static uint32_t update_seat_button_count(struct libinput_seat *seat, int32_t button, enum libinput_button_state state) { assert(button >= 0 && button <= KEY_MAX); switch (state) { case LIBINPUT_BUTTON_STATE_PRESSED: return ++seat->button_count[button]; case LIBINPUT_BUTTON_STATE_RELEASED: /* We might not have received the first PRESSED event. */ if (seat->button_count[button] == 0) return 0; return --seat->button_count[button]; } return 0; } static void init_event_base(struct libinput_event *event, struct libinput_device *device, enum libinput_event_type type) { event->type = type; event->device = device; } static void post_base_event(struct libinput_device *device, enum libinput_event_type type, struct libinput_event *event) { struct libinput *libinput = device->seat->libinput; init_event_base(event, device, type); libinput_post_event(libinput, event); } static void post_device_event(struct libinput_device *device, uint64_t time, enum libinput_event_type type, struct libinput_event *event) { struct libinput_event_listener *listener; #if 0 struct libinput *libinput = device->seat->libinput; if (libinput->last_event_time > time) { log_bug_libinput(device->seat->libinput, "out-of-order timestamps for %s time %" PRIu64 "\n", event_type_to_str(type), time); } libinput->last_event_time = time; #endif init_event_base(event, device, type); list_for_each_safe(listener, &device->event_listeners, link) listener->notify_func(time, event, listener->notify_func_data); libinput_post_event(device->seat->libinput, event); } void notify_added_device(struct libinput_device *device) { struct libinput_event_device_notify *added_device_event; added_device_event = zalloc(sizeof *added_device_event); post_base_event(device, LIBINPUT_EVENT_DEVICE_ADDED, &added_device_event->base); #ifdef __clang_analyzer__ /* clang doesn't realize we're not leaking the event here, so * pretend to free it */ free(added_device_event); #endif } void notify_removed_device(struct libinput_device *device) { struct libinput_event_device_notify *removed_device_event; removed_device_event = zalloc(sizeof *removed_device_event); post_base_event(device, LIBINPUT_EVENT_DEVICE_REMOVED, &removed_device_event->base); #ifdef __clang_analyzer__ /* clang doesn't realize we're not leaking the event here, so * pretend to free it */ free(removed_device_event); #endif } static inline bool device_has_cap(struct libinput_device *device, enum libinput_device_capability cap) { const char *capability; if (libinput_device_has_capability(device, cap)) return true; switch (cap) { case LIBINPUT_DEVICE_CAP_POINTER: capability = "CAP_POINTER"; break; case LIBINPUT_DEVICE_CAP_KEYBOARD: capability = "CAP_KEYBOARD"; break; case LIBINPUT_DEVICE_CAP_TOUCH: capability = "CAP_TOUCH"; break; case LIBINPUT_DEVICE_CAP_GESTURE: capability = "CAP_GESTURE"; break; case LIBINPUT_DEVICE_CAP_TABLET_TOOL: capability = "CAP_TABLET_TOOL"; break; case LIBINPUT_DEVICE_CAP_TABLET_PAD: capability = "CAP_TABLET_PAD"; break; case LIBINPUT_DEVICE_CAP_SWITCH: capability = "CAP_SWITCH"; break; } log_bug_libinput(device->seat->libinput, "Event for missing capability %s on device \"%s\"\n", capability, libinput_device_get_name(device)); return false; } void keyboard_notify_key(struct libinput_device *device, uint64_t time, uint32_t key, enum libinput_key_state state) { struct libinput_event_keyboard *key_event; uint32_t seat_key_count; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) return; key_event = zalloc(sizeof *key_event); seat_key_count = update_seat_key_count(device->seat, key, state); *key_event = (struct libinput_event_keyboard) { .time = time, .key = key, .state = state, .seat_key_count = seat_key_count, }; post_device_event(device, time, LIBINPUT_EVENT_KEYBOARD_KEY, &key_event->base); } void pointer_notify_motion(struct libinput_device *device, uint64_t time, const struct normalized_coords *delta, const struct device_float_coords *raw) { struct libinput_event_pointer *motion_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; motion_event = zalloc(sizeof *motion_event); *motion_event = (struct libinput_event_pointer) { .time = time, .delta = *delta, .delta_raw = *raw, }; post_device_event(device, time, LIBINPUT_EVENT_POINTER_MOTION, &motion_event->base); } void pointer_notify_motion_absolute(struct libinput_device *device, uint64_t time, const struct device_coords *point) { struct libinput_event_pointer *motion_absolute_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; motion_absolute_event = zalloc(sizeof *motion_absolute_event); *motion_absolute_event = (struct libinput_event_pointer) { .time = time, .absolute = *point, }; post_device_event(device, time, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, &motion_absolute_event->base); } void pointer_notify_button(struct libinput_device *device, uint64_t time, int32_t button, enum libinput_button_state state) { struct libinput_event_pointer *button_event; int32_t seat_button_count; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; button_event = zalloc(sizeof *button_event); seat_button_count = update_seat_button_count(device->seat, button, state); *button_event = (struct libinput_event_pointer) { .time = time, .button = button, .state = state, .seat_button_count = seat_button_count, }; post_device_event(device, time, LIBINPUT_EVENT_POINTER_BUTTON, &button_event->base); } void pointer_notify_axis_finger(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta) { struct libinput_event_pointer *axis_event, *axis_event_legacy; const struct discrete_coords zero_discrete = {0}; const struct wheel_v120 zero_v120 = {0}; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; axis_event = zalloc(sizeof *axis_event); axis_event_legacy = zalloc(sizeof *axis_event_legacy); *axis_event = (struct libinput_event_pointer) { .time = time, .delta = *delta, .source = LIBINPUT_POINTER_AXIS_SOURCE_FINGER, .axes = axes, .discrete = zero_discrete, .v120 = zero_v120, }; *axis_event_legacy = *axis_event; post_device_event(device, time, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, &axis_event->base); post_device_event(device, time, LIBINPUT_EVENT_POINTER_AXIS, &axis_event_legacy->base); } void pointer_notify_axis_continuous(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta) { struct libinput_event_pointer *axis_event, *axis_event_legacy; const struct discrete_coords zero_discrete = {0}; const struct wheel_v120 zero_v120 = {0}; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; axis_event = zalloc(sizeof *axis_event); axis_event_legacy = zalloc(sizeof *axis_event_legacy); *axis_event = (struct libinput_event_pointer) { .time = time, .delta = *delta, .source = LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, .axes = axes, .discrete = zero_discrete, .v120 = zero_v120, }; *axis_event_legacy = *axis_event; post_device_event(device, time, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, &axis_event->base); post_device_event(device, time, LIBINPUT_EVENT_POINTER_AXIS, &axis_event_legacy->base); } void pointer_notify_axis_legacy_wheel(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta, const struct discrete_coords *discrete) { struct libinput_event_pointer *axis_event; const struct wheel_v120 zero_v120 = {0}; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; axis_event = zalloc(sizeof *axis_event); *axis_event = (struct libinput_event_pointer) { .time = time, .delta = *delta, .source = LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, .axes = axes, .discrete = *discrete, .v120 = zero_v120, }; post_device_event(device, time, LIBINPUT_EVENT_POINTER_AXIS, &axis_event->base); } void pointer_notify_axis_wheel(struct libinput_device *device, uint64_t time, uint32_t axes, const struct normalized_coords *delta, const struct wheel_v120 *v120) { struct libinput_event_pointer *axis_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_POINTER)) return; axis_event = zalloc(sizeof *axis_event); *axis_event = (struct libinput_event_pointer) { .time = time, .delta = *delta, .source = LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, .axes = axes, .discrete.x = 0, .discrete.y = 0, .v120 = *v120, }; post_device_event(device, time, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, &axis_event->base); /* legacy wheel events are sent separately */ } void touch_notify_touch_down(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot, const struct device_coords *point) { struct libinput_event_touch *touch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) return; touch_event = zalloc(sizeof *touch_event); *touch_event = (struct libinput_event_touch) { .time = time, .slot = slot, .seat_slot = seat_slot, .point = *point, }; post_device_event(device, time, LIBINPUT_EVENT_TOUCH_DOWN, &touch_event->base); } void touch_notify_touch_motion(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot, const struct device_coords *point) { struct libinput_event_touch *touch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) return; touch_event = zalloc(sizeof *touch_event); *touch_event = (struct libinput_event_touch) { .time = time, .slot = slot, .seat_slot = seat_slot, .point = *point, }; post_device_event(device, time, LIBINPUT_EVENT_TOUCH_MOTION, &touch_event->base); } void touch_notify_touch_up(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot) { struct libinput_event_touch *touch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) return; touch_event = zalloc(sizeof *touch_event); *touch_event = (struct libinput_event_touch) { .time = time, .slot = slot, .seat_slot = seat_slot, }; post_device_event(device, time, LIBINPUT_EVENT_TOUCH_UP, &touch_event->base); } void touch_notify_touch_cancel(struct libinput_device *device, uint64_t time, int32_t slot, int32_t seat_slot) { struct libinput_event_touch *touch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) return; touch_event = zalloc(sizeof *touch_event); *touch_event = (struct libinput_event_touch) { .time = time, .slot = slot, .seat_slot = seat_slot, }; post_device_event(device, time, LIBINPUT_EVENT_TOUCH_CANCEL, &touch_event->base); } void touch_notify_frame(struct libinput_device *device, uint64_t time) { struct libinput_event_touch *touch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_TOUCH)) return; touch_event = zalloc(sizeof *touch_event); *touch_event = (struct libinput_event_touch) { .time = time, }; post_device_event(device, time, LIBINPUT_EVENT_TOUCH_FRAME, &touch_event->base); } void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y) { struct libinput_event_tablet_tool *axis_event; axis_event = zalloc(sizeof *axis_event); *axis_event = (struct libinput_event_tablet_tool) { .time = time, .tool = libinput_tablet_tool_ref(tool), .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, .axes = *axes, .abs.x = *x, .abs.y = *y, }; memcpy(axis_event->changed_axes, changed_axes, sizeof(axis_event->changed_axes)); post_device_event(device, time, LIBINPUT_EVENT_TABLET_TOOL_AXIS, &axis_event->base); } void tablet_notify_proximity(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_proximity_state proximity_state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y) { struct libinput_event_tablet_tool *proximity_event; proximity_event = zalloc(sizeof *proximity_event); *proximity_event = (struct libinput_event_tablet_tool) { .time = time, .tool = libinput_tablet_tool_ref(tool), .tip_state = LIBINPUT_TABLET_TOOL_TIP_UP, .proximity_state = proximity_state, .axes = *axes, .abs.x = *x, .abs.y = *y, }; memcpy(proximity_event->changed_axes, changed_axes, sizeof(proximity_event->changed_axes)); post_device_event(device, time, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, &proximity_event->base); } void tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, const struct tablet_axes *axes, const struct input_absinfo *x, const struct input_absinfo *y) { struct libinput_event_tablet_tool *tip_event; tip_event = zalloc(sizeof *tip_event); *tip_event = (struct libinput_event_tablet_tool) { .time = time, .tool = libinput_tablet_tool_ref(tool), .tip_state = tip_state, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .axes = *axes, .abs.x = *x, .abs.y = *y, }; memcpy(tip_event->changed_axes, changed_axes, sizeof(tip_event->changed_axes)); post_device_event(device, time, LIBINPUT_EVENT_TABLET_TOOL_TIP, &tip_event->base); } void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, const struct tablet_axes *axes, int32_t button, enum libinput_button_state state, const struct input_absinfo *x, const struct input_absinfo *y) { struct libinput_event_tablet_tool *button_event; int32_t seat_button_count; button_event = zalloc(sizeof *button_event); seat_button_count = update_seat_button_count(device->seat, button, state); *button_event = (struct libinput_event_tablet_tool) { .time = time, .tool = libinput_tablet_tool_ref(tool), .button = button, .state = state, .seat_button_count = seat_button_count, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, .axes = *axes, .abs.x = *x, .abs.y = *y, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_TOOL_BUTTON, &button_event->base); } void tablet_pad_notify_button(struct libinput_device *device, uint64_t time, int32_t button, enum libinput_button_state state, struct libinput_tablet_pad_mode_group *group) { struct libinput_event_tablet_pad *button_event; unsigned int mode; button_event = zalloc(sizeof *button_event); mode = libinput_tablet_pad_mode_group_get_mode(group); *button_event = (struct libinput_event_tablet_pad) { .time = time, .button.number = button, .button.state = state, .mode_group = libinput_tablet_pad_mode_group_ref(group), .mode = mode, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_PAD_BUTTON, &button_event->base); } void tablet_pad_notify_dial(struct libinput_device *device, uint64_t time, unsigned int number, double value, struct libinput_tablet_pad_mode_group *group) { struct libinput_event_tablet_pad *dial_event; unsigned int mode; dial_event = zalloc(sizeof *dial_event); mode = libinput_tablet_pad_mode_group_get_mode(group); *dial_event = (struct libinput_event_tablet_pad) { .time = time, .dial.number = number, .dial.v120 = value, .mode_group = libinput_tablet_pad_mode_group_ref(group), .mode = mode, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_PAD_DIAL, &dial_event->base); } void tablet_pad_notify_ring(struct libinput_device *device, uint64_t time, unsigned int number, double value, enum libinput_tablet_pad_ring_axis_source source, struct libinput_tablet_pad_mode_group *group) { struct libinput_event_tablet_pad *ring_event; unsigned int mode; ring_event = zalloc(sizeof *ring_event); mode = libinput_tablet_pad_mode_group_get_mode(group); *ring_event = (struct libinput_event_tablet_pad) { .time = time, .ring.number = number, .ring.position = value, .ring.source = source, .mode_group = libinput_tablet_pad_mode_group_ref(group), .mode = mode, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_PAD_RING, &ring_event->base); } void tablet_pad_notify_strip(struct libinput_device *device, uint64_t time, unsigned int number, double value, enum libinput_tablet_pad_strip_axis_source source, struct libinput_tablet_pad_mode_group *group) { struct libinput_event_tablet_pad *strip_event; unsigned int mode; strip_event = zalloc(sizeof *strip_event); mode = libinput_tablet_pad_mode_group_get_mode(group); *strip_event = (struct libinput_event_tablet_pad) { .time = time, .strip.number = number, .strip.position = value, .strip.source = source, .mode_group = libinput_tablet_pad_mode_group_ref(group), .mode = mode, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_PAD_STRIP, &strip_event->base); } void tablet_pad_notify_key(struct libinput_device *device, uint64_t time, int32_t key, enum libinput_key_state state) { struct libinput_event_tablet_pad *key_event; key_event = zalloc(sizeof *key_event); *key_event = (struct libinput_event_tablet_pad) { .time = time, .key.code = key, .key.state = state, }; post_device_event(device, time, LIBINPUT_EVENT_TABLET_PAD_KEY, &key_event->base); } static void gesture_notify(struct libinput_device *device, uint64_t time, enum libinput_event_type type, int finger_count, bool cancelled, const struct normalized_coords *delta, const struct normalized_coords *unaccel, double scale, double angle) { struct libinput_event_gesture *gesture_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_GESTURE)) return; gesture_event = zalloc(sizeof *gesture_event); *gesture_event = (struct libinput_event_gesture) { .time = time, .finger_count = finger_count, .cancelled = cancelled, .delta = *delta, .delta_unaccel = *unaccel, .scale = scale, .angle = angle, }; post_device_event(device, time, type, &gesture_event->base); } void gesture_notify_swipe(struct libinput_device *device, uint64_t time, enum libinput_event_type type, int finger_count, const struct normalized_coords *delta, const struct normalized_coords *unaccel) { gesture_notify(device, time, type, finger_count, 0, delta, unaccel, 0.0, 0.0); } void gesture_notify_swipe_end(struct libinput_device *device, uint64_t time, int finger_count, bool cancelled) { const struct normalized_coords zero = { 0.0, 0.0 }; gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_SWIPE_END, finger_count, cancelled, &zero, &zero, 0.0, 0.0); } void gesture_notify_pinch(struct libinput_device *device, uint64_t time, enum libinput_event_type type, int finger_count, const struct normalized_coords *delta, const struct normalized_coords *unaccel, double scale, double angle) { gesture_notify(device, time, type, finger_count, 0, delta, unaccel, scale, angle); } void gesture_notify_pinch_end(struct libinput_device *device, uint64_t time, int finger_count, double scale, bool cancelled) { const struct normalized_coords zero = { 0.0, 0.0 }; gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_PINCH_END, finger_count, cancelled, &zero, &zero, scale, 0.0); } void gesture_notify_hold_begin(struct libinput_device *device, uint64_t time, int finger_count) { const struct normalized_coords zero = { 0.0, 0.0 }; gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, finger_count, 0, &zero, &zero, 0.0, 0.0); } void gesture_notify_hold_end(struct libinput_device *device, uint64_t time, int finger_count, bool cancelled) { const struct normalized_coords zero = { 0.0, 0.0 }; gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_HOLD_END, finger_count, cancelled, &zero, &zero, 0, 0.0); } void switch_notify_toggle(struct libinput_device *device, uint64_t time, enum libinput_switch sw, enum libinput_switch_state state) { struct libinput_event_switch *switch_event; if (!device_has_cap(device, LIBINPUT_DEVICE_CAP_SWITCH)) return; switch_event = zalloc(sizeof *switch_event); *switch_event = (struct libinput_event_switch) { .time = time, .sw = sw, .state = state, }; post_device_event(device, time, LIBINPUT_EVENT_SWITCH_TOGGLE, &switch_event->base); #ifdef __clang_analyzer__ /* clang doesn't realize we're not leaking the event here, so * pretend to free it */ free(switch_event); #endif } LIBINPUT_UNUSED static inline void libinput_print_queued_event(struct libinput_event *event) { struct libinput *libinput = libinput_event_get_context(event); char *event_str = libinput_event_to_str(event, 0, NULL); log_debug(libinput, "Queuing %s\n", event_str); free(event_str); } static void libinput_post_event(struct libinput *libinput, struct libinput_event *event) { struct libinput_event **events = libinput->events; size_t events_len = libinput->events_len; size_t events_count = libinput->events_count; size_t move_len; size_t new_out; #if EVENT_DEBUGGING libinput_print_queued_event(event); #endif events_count++; if (events_count > events_len) { void *tmp; events_len *= 2; tmp = realloc(events, events_len * sizeof *events); if (!tmp) { log_error(libinput, "Failed to reallocate event ring buffer. " "Events may be discarded\n"); return; } events = tmp; if (libinput->events_count > 0 && libinput->events_in == 0) { libinput->events_in = libinput->events_len; } else if (libinput->events_count > 0 && libinput->events_out >= libinput->events_in) { move_len = libinput->events_len - libinput->events_out; new_out = events_len - move_len; memmove(events + new_out, events + libinput->events_out, move_len * sizeof *events); libinput->events_out = new_out; } libinput->events = events; libinput->events_len = events_len; } if (event->device) libinput_device_ref(event->device); libinput->events_count = events_count; events[libinput->events_in] = event; libinput->events_in = (libinput->events_in + 1) % libinput->events_len; } LIBINPUT_EXPORT struct libinput_event * libinput_get_event(struct libinput *libinput) { struct libinput_event *event; if (libinput->events_count == 0) return NULL; event = libinput->events[libinput->events_out]; libinput->events_out = (libinput->events_out + 1) % libinput->events_len; libinput->events_count--; return event; } LIBINPUT_EXPORT enum libinput_event_type libinput_next_event_type(struct libinput *libinput) { struct libinput_event *event; if (libinput->events_count == 0) return LIBINPUT_EVENT_NONE; event = libinput->events[libinput->events_out]; return event->type; } LIBINPUT_EXPORT void libinput_set_user_data(struct libinput *libinput, void *user_data) { libinput->user_data = user_data; } LIBINPUT_EXPORT void * libinput_get_user_data(struct libinput *libinput) { return libinput->user_data; } LIBINPUT_EXPORT int libinput_resume(struct libinput *libinput) { return libinput->interface_backend->resume(libinput); } LIBINPUT_EXPORT void libinput_suspend(struct libinput *libinput) { libinput->interface_backend->suspend(libinput); } LIBINPUT_EXPORT void libinput_device_set_user_data(struct libinput_device *device, void *user_data) { device->user_data = user_data; } LIBINPUT_EXPORT void * libinput_device_get_user_data(struct libinput_device *device) { return device->user_data; } LIBINPUT_EXPORT struct libinput * libinput_device_get_context(struct libinput_device *device) { return libinput_seat_get_context(device->seat); } LIBINPUT_EXPORT struct libinput_device_group * libinput_device_get_device_group(struct libinput_device *device) { return device->group; } LIBINPUT_EXPORT const char * libinput_device_get_sysname(struct libinput_device *device) { return evdev_device_get_sysname((struct evdev_device *) device); } LIBINPUT_EXPORT const char * libinput_device_get_name(struct libinput_device *device) { return evdev_device_get_name((struct evdev_device *) device); } LIBINPUT_EXPORT unsigned int libinput_device_get_id_bustype(struct libinput_device *device) { return evdev_device_get_id_bustype((struct evdev_device *) device); } LIBINPUT_EXPORT unsigned int libinput_device_get_id_product(struct libinput_device *device) { return evdev_device_get_id_product((struct evdev_device *) device); } LIBINPUT_EXPORT unsigned int libinput_device_get_id_vendor(struct libinput_device *device) { return evdev_device_get_id_vendor((struct evdev_device *) device); } LIBINPUT_EXPORT const char * libinput_device_get_output_name(struct libinput_device *device) { return evdev_device_get_output((struct evdev_device *) device); } LIBINPUT_EXPORT struct libinput_seat * libinput_device_get_seat(struct libinput_device *device) { return device->seat; } LIBINPUT_EXPORT int libinput_device_set_seat_logical_name(struct libinput_device *device, const char *name) { struct libinput *libinput = device->seat->libinput; if (name == NULL) return -1; return libinput->interface_backend->device_change_seat(device, name); } LIBINPUT_EXPORT struct udev_device * libinput_device_get_udev_device(struct libinput_device *device) { return evdev_device_get_udev_device((struct evdev_device *)device); } LIBINPUT_EXPORT void libinput_device_led_update(struct libinput_device *device, enum libinput_led leds) { evdev_device_led_update((struct evdev_device *) device, leds); } LIBINPUT_EXPORT int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability) { return evdev_device_has_capability((struct evdev_device *) device, capability); } LIBINPUT_EXPORT int libinput_device_get_size(struct libinput_device *device, double *width, double *height) { return evdev_device_get_size((struct evdev_device *)device, width, height); } LIBINPUT_EXPORT int libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code) { return evdev_device_has_button((struct evdev_device *)device, code); } LIBINPUT_EXPORT int libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code) { return evdev_device_has_key((struct evdev_device *)device, code); } LIBINPUT_EXPORT int libinput_device_touch_get_touch_count(struct libinput_device *device) { return evdev_device_get_touch_count((struct evdev_device *)device); } LIBINPUT_EXPORT int libinput_device_switch_has_switch(struct libinput_device *device, enum libinput_switch sw) { return evdev_device_has_switch((struct evdev_device *)device, sw); } LIBINPUT_EXPORT int libinput_device_tablet_pad_has_key(struct libinput_device *device, uint32_t code) { return evdev_device_tablet_pad_has_key((struct evdev_device *)device, code); } LIBINPUT_EXPORT int libinput_device_tablet_pad_get_num_buttons(struct libinput_device *device) { return evdev_device_tablet_pad_get_num_buttons((struct evdev_device *)device); } LIBINPUT_EXPORT int libinput_device_tablet_pad_get_num_dials(struct libinput_device *device) { return evdev_device_tablet_pad_get_num_dials((struct evdev_device *)device); } LIBINPUT_EXPORT int libinput_device_tablet_pad_get_num_rings(struct libinput_device *device) { return evdev_device_tablet_pad_get_num_rings((struct evdev_device *)device); } LIBINPUT_EXPORT int libinput_device_tablet_pad_get_num_strips(struct libinput_device *device) { return evdev_device_tablet_pad_get_num_strips((struct evdev_device *)device); } LIBINPUT_EXPORT int libinput_device_tablet_pad_get_num_mode_groups(struct libinput_device *device) { return evdev_device_tablet_pad_get_num_mode_groups((struct evdev_device *)device); } LIBINPUT_EXPORT struct libinput_tablet_pad_mode_group* libinput_device_tablet_pad_get_mode_group(struct libinput_device *device, unsigned int index) { return evdev_device_tablet_pad_get_mode_group((struct evdev_device *)device, index); } LIBINPUT_EXPORT unsigned int libinput_tablet_pad_mode_group_get_num_modes( struct libinput_tablet_pad_mode_group *group) { return group->num_modes; } LIBINPUT_EXPORT unsigned int libinput_tablet_pad_mode_group_get_mode(struct libinput_tablet_pad_mode_group *group) { return group->current_mode; } LIBINPUT_EXPORT unsigned int libinput_tablet_pad_mode_group_get_index(struct libinput_tablet_pad_mode_group *group) { return group->index; } LIBINPUT_EXPORT int libinput_tablet_pad_mode_group_has_button(struct libinput_tablet_pad_mode_group *group, unsigned int button) { if ((int)button >= libinput_device_tablet_pad_get_num_buttons(group->device)) return 0; return !!(group->button_mask & bit(button)); } LIBINPUT_EXPORT int libinput_tablet_pad_mode_group_has_dial(struct libinput_tablet_pad_mode_group *group, unsigned int dial) { if ((int)dial >= libinput_device_tablet_pad_get_num_dials(group->device)) return 0; return !!(group->dial_mask & bit(dial)); } LIBINPUT_EXPORT int libinput_tablet_pad_mode_group_has_ring(struct libinput_tablet_pad_mode_group *group, unsigned int ring) { if ((int)ring >= libinput_device_tablet_pad_get_num_rings(group->device)) return 0; return !!(group->ring_mask & bit(ring)); } LIBINPUT_EXPORT int libinput_tablet_pad_mode_group_has_strip(struct libinput_tablet_pad_mode_group *group, unsigned int strip) { if ((int)strip >= libinput_device_tablet_pad_get_num_strips(group->device)) return 0; return !!(group->strip_mask & bit(strip)); } LIBINPUT_EXPORT int libinput_tablet_pad_mode_group_button_is_toggle(struct libinput_tablet_pad_mode_group *group, unsigned int button) { if ((int)button >= libinput_device_tablet_pad_get_num_buttons(group->device)) return 0; return !!(group->toggle_button_mask & bit(button)); } LIBINPUT_EXPORT struct libinput_tablet_pad_mode_group * libinput_tablet_pad_mode_group_ref( struct libinput_tablet_pad_mode_group *group) { group->refcount++; return group; } LIBINPUT_EXPORT struct libinput_tablet_pad_mode_group * libinput_tablet_pad_mode_group_unref( struct libinput_tablet_pad_mode_group *group) { assert(group->refcount > 0); group->refcount--; if (group->refcount > 0) return group; list_remove(&group->link); group->destroy(group); return NULL; } LIBINPUT_EXPORT void libinput_tablet_pad_mode_group_set_user_data( struct libinput_tablet_pad_mode_group *group, void *user_data) { group->user_data = user_data; } LIBINPUT_EXPORT void * libinput_tablet_pad_mode_group_get_user_data( struct libinput_tablet_pad_mode_group *group) { return group->user_data; } LIBINPUT_EXPORT struct libinput_event * libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_DEVICE_ADDED, LIBINPUT_EVENT_DEVICE_REMOVED); return &event->base; } LIBINPUT_EXPORT struct libinput_event * libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_KEYBOARD_KEY); return &event->base; } LIBINPUT_EXPORT struct libinput_event * libinput_event_pointer_get_base_event(struct libinput_event_pointer *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_POINTER_MOTION, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, LIBINPUT_EVENT_POINTER_BUTTON, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_POINTER_AXIS); return &event->base; } LIBINPUT_EXPORT struct libinput_event * libinput_event_touch_get_base_event(struct libinput_event_touch *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_TOUCH_DOWN, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL, LIBINPUT_EVENT_TOUCH_FRAME); return &event->base; } LIBINPUT_EXPORT struct libinput_event * libinput_event_gesture_get_base_event(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); return &event->base; } LIBINPUT_EXPORT struct libinput_event * libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return &event->base; } LIBINPUT_EXPORT double libinput_event_tablet_pad_get_dial_delta_v120(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_TABLET_PAD_DIAL); return event->dial.v120; } LIBINPUT_EXPORT unsigned int libinput_event_tablet_pad_get_dial_number(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_DIAL); return event->dial.number; } LIBINPUT_EXPORT double libinput_event_tablet_pad_get_ring_position(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_TABLET_PAD_RING); return event->ring.position; } LIBINPUT_EXPORT unsigned int libinput_event_tablet_pad_get_ring_number(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_RING); return event->ring.number; } LIBINPUT_EXPORT enum libinput_tablet_pad_ring_axis_source libinput_event_tablet_pad_get_ring_source(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN, LIBINPUT_EVENT_TABLET_PAD_RING); return event->ring.source; } LIBINPUT_EXPORT double libinput_event_tablet_pad_get_strip_position(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0.0, LIBINPUT_EVENT_TABLET_PAD_STRIP); return event->strip.position; } LIBINPUT_EXPORT unsigned int libinput_event_tablet_pad_get_strip_number(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_STRIP); return event->strip.number; } LIBINPUT_EXPORT enum libinput_tablet_pad_strip_axis_source libinput_event_tablet_pad_get_strip_source(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN, LIBINPUT_EVENT_TABLET_PAD_STRIP); return event->strip.source; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_pad_get_button_number(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_BUTTON); return event->button.number; } LIBINPUT_EXPORT enum libinput_button_state libinput_event_tablet_pad_get_button_state(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, LIBINPUT_BUTTON_STATE_RELEASED, LIBINPUT_EVENT_TABLET_PAD_BUTTON); return event->button.state; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_pad_get_key(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_KEY); return event->key.code; } LIBINPUT_EXPORT enum libinput_key_state libinput_event_tablet_pad_get_key_state(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, LIBINPUT_KEY_STATE_RELEASED, LIBINPUT_EVENT_TABLET_PAD_KEY); return event->key.state; } LIBINPUT_EXPORT unsigned int libinput_event_tablet_pad_get_mode(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON); return event->mode; } LIBINPUT_EXPORT struct libinput_tablet_pad_mode_group * libinput_event_tablet_pad_get_mode_group(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON); return event->mode_group; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_pad_get_time(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON, LIBINPUT_EVENT_TABLET_PAD_KEY); return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_tablet_pad_get_time_usec(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON, LIBINPUT_EVENT_TABLET_PAD_KEY); return event->time; } LIBINPUT_EXPORT struct libinput_event * libinput_event_tablet_pad_get_base_event(struct libinput_event_tablet_pad *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, NULL, LIBINPUT_EVENT_TABLET_PAD_RING, LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_TABLET_PAD_STRIP, LIBINPUT_EVENT_TABLET_PAD_BUTTON, LIBINPUT_EVENT_TABLET_PAD_KEY); return &event->base; } LIBINPUT_EXPORT struct libinput_device_group * libinput_device_group_ref(struct libinput_device_group *group) { group->refcount++; return group; } struct libinput_device_group * libinput_device_group_create(struct libinput *libinput, const char *identifier) { struct libinput_device_group *group; group = zalloc(sizeof *group); group->refcount = 1; group->identifier = safe_strdup(identifier); list_init(&group->link); list_insert(&libinput->device_group_list, &group->link); return group; } struct libinput_device_group * libinput_device_group_find_group(struct libinput *libinput, const char *identifier) { struct libinput_device_group *g = NULL; list_for_each(g, &libinput->device_group_list, link) { if (identifier && g->identifier && streq(g->identifier, identifier)) { return g; } } return NULL; } void libinput_device_set_device_group(struct libinput_device *device, struct libinput_device_group *group) { device->group = group; libinput_device_group_ref(group); } static void libinput_device_group_destroy(struct libinput_device_group *group) { list_remove(&group->link); free(group->identifier); free(group); } LIBINPUT_EXPORT struct libinput_device_group * libinput_device_group_unref(struct libinput_device_group *group) { assert(group->refcount > 0); group->refcount--; if (group->refcount == 0) { libinput_device_group_destroy(group); return NULL; } return group; } LIBINPUT_EXPORT void libinput_device_group_set_user_data(struct libinput_device_group *group, void *user_data) { group->user_data = user_data; } LIBINPUT_EXPORT void * libinput_device_group_get_user_data(struct libinput_device_group *group) { return group->user_data; } LIBINPUT_EXPORT const char * libinput_config_status_to_str(enum libinput_config_status status) { const char *str = NULL; switch(status) { case LIBINPUT_CONFIG_STATUS_SUCCESS: str = "Success"; break; case LIBINPUT_CONFIG_STATUS_UNSUPPORTED: str = "Unsupported configuration option"; break; case LIBINPUT_CONFIG_STATUS_INVALID: str = "Invalid argument range"; break; } return str; } LIBINPUT_EXPORT int libinput_device_config_tap_get_finger_count(struct libinput_device *device) { return device->config.tap ? device->config.tap->count(device) : 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_tap_set_enabled(struct libinput_device *device, enum libinput_config_tap_state enable) { if (enable != LIBINPUT_CONFIG_TAP_ENABLED && enable != LIBINPUT_CONFIG_TAP_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (libinput_device_config_tap_get_finger_count(device) == 0) return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; return device->config.tap->set_enabled(device, enable); } LIBINPUT_EXPORT enum libinput_config_tap_state libinput_device_config_tap_get_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_TAP_DISABLED; return device->config.tap->get_enabled(device); } LIBINPUT_EXPORT enum libinput_config_tap_state libinput_device_config_tap_get_default_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_TAP_DISABLED; return device->config.tap->get_default(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_tap_set_button_map(struct libinput_device *device, enum libinput_config_tap_button_map map) { switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: case LIBINPUT_CONFIG_TAP_MAP_LMR: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.tap->set_map(device, map); } LIBINPUT_EXPORT enum libinput_config_tap_button_map libinput_device_config_tap_get_button_map(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_TAP_MAP_LRM; return device->config.tap->get_map(device); } LIBINPUT_EXPORT enum libinput_config_tap_button_map libinput_device_config_tap_get_default_button_map(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_TAP_MAP_LRM; return device->config.tap->get_default_map(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_tap_set_drag_enabled(struct libinput_device *device, enum libinput_config_drag_state enable) { if (enable != LIBINPUT_CONFIG_DRAG_ENABLED && enable != LIBINPUT_CONFIG_DRAG_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (libinput_device_config_tap_get_finger_count(device) == 0) return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; return device->config.tap->set_drag_enabled(device, enable); } LIBINPUT_EXPORT enum libinput_config_drag_state libinput_device_config_tap_get_drag_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_DRAG_DISABLED; return device->config.tap->get_drag_enabled(device); } LIBINPUT_EXPORT enum libinput_config_drag_state libinput_device_config_tap_get_default_drag_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_DRAG_DISABLED; return device->config.tap->get_default_drag_enabled(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_tap_set_drag_lock_enabled(struct libinput_device *device, enum libinput_config_drag_lock_state enable) { if (enable != LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY && enable != LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT && enable != LIBINPUT_CONFIG_DRAG_LOCK_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (libinput_device_config_tap_get_finger_count(device) == 0) return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; return device->config.tap->set_draglock_enabled(device, enable); } LIBINPUT_EXPORT enum libinput_config_drag_lock_state libinput_device_config_tap_get_drag_lock_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; return device->config.tap->get_draglock_enabled(device); } LIBINPUT_EXPORT enum libinput_config_drag_lock_state libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device *device) { if (libinput_device_config_tap_get_finger_count(device) == 0) return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; return device->config.tap->get_default_draglock_enabled(device); } LIBINPUT_EXPORT int libinput_device_config_3fg_drag_get_finger_count(struct libinput_device *device) { return device->config.drag_3fg ? device->config.drag_3fg->count(device) : 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_3fg_drag_set_enabled(struct libinput_device *device, enum libinput_config_3fg_drag_state enable) { if (libinput_device_config_3fg_drag_get_finger_count(device) < 3) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; switch (enable) { case LIBINPUT_CONFIG_3FG_DRAG_DISABLED: case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG: case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG: return device->config.drag_3fg->set_enabled(device, enable); break; } return LIBINPUT_CONFIG_STATUS_INVALID; } LIBINPUT_EXPORT enum libinput_config_3fg_drag_state libinput_device_config_3fg_drag_get_enabled(struct libinput_device *device) { if (libinput_device_config_3fg_drag_get_finger_count(device) < 3) return LIBINPUT_CONFIG_3FG_DRAG_DISABLED; return device->config.drag_3fg->get_enabled(device); } LIBINPUT_EXPORT enum libinput_config_3fg_drag_state libinput_device_config_3fg_drag_get_default_enabled(struct libinput_device *device) { if (libinput_device_config_3fg_drag_get_finger_count(device) < 3) return LIBINPUT_CONFIG_3FG_DRAG_DISABLED; return device->config.drag_3fg->get_default(device); } LIBINPUT_EXPORT int libinput_device_config_calibration_has_matrix(struct libinput_device *device) { return device->config.calibration ? device->config.calibration->has_matrix(device) : 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_calibration_set_matrix(struct libinput_device *device, const float matrix[6]) { if (!libinput_device_config_calibration_has_matrix(device)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.calibration->set_matrix(device, matrix); } LIBINPUT_EXPORT int libinput_device_config_calibration_get_matrix(struct libinput_device *device, float matrix[6]) { if (!libinput_device_config_calibration_has_matrix(device)) return 0; return device->config.calibration->get_matrix(device, matrix); } LIBINPUT_EXPORT int libinput_device_config_calibration_get_default_matrix(struct libinput_device *device, float matrix[6]) { if (!libinput_device_config_calibration_has_matrix(device)) return 0; return device->config.calibration->get_default_matrix(device, matrix); } LIBINPUT_EXPORT int libinput_device_config_area_has_rectangle(struct libinput_device *device) { return device->config.area ? device->config.area->has_rectangle(device) : 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_area_set_rectangle(struct libinput_device *device, const struct libinput_config_area_rectangle *rectangle) { if (!libinput_device_config_area_has_rectangle(device)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (rectangle->x1 >= rectangle->x2 || rectangle->y1 >= rectangle->y2) return LIBINPUT_CONFIG_STATUS_INVALID; if (rectangle->x1 < 0.0 || rectangle->x2 > 1.0 || rectangle->y1 < 0.0 || rectangle->y2 > 1.0) return LIBINPUT_CONFIG_STATUS_INVALID; return device->config.area->set_rectangle(device, rectangle); } LIBINPUT_EXPORT struct libinput_config_area_rectangle libinput_device_config_area_get_rectangle(struct libinput_device *device) { struct libinput_config_area_rectangle rect = { 0.0, 0.0, 1.0, 1.0 }; if (!libinput_device_config_area_has_rectangle(device)) return rect; return device->config.area->get_rectangle(device); } LIBINPUT_EXPORT struct libinput_config_area_rectangle libinput_device_config_area_get_default_rectangle(struct libinput_device *device) { struct libinput_config_area_rectangle rect = { 0.0, 0.0, 1.0, 1.0 }; if (!libinput_device_config_area_has_rectangle(device)) return rect; return device->config.area->get_default_rectangle(device); } LIBINPUT_EXPORT uint32_t libinput_device_config_send_events_get_modes(struct libinput_device *device) { uint32_t modes = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; if (device->config.sendevents) modes |= device->config.sendevents->get_modes(device); return modes; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_send_events_set_mode(struct libinput_device *device, uint32_t mode) { if ((libinput_device_config_send_events_get_modes(device) & mode) != mode) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (device->config.sendevents) return device->config.sendevents->set_mode(device, mode); /* mode must be _ENABLED to get here */ return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT uint32_t libinput_device_config_send_events_get_mode(struct libinput_device *device) { if (device->config.sendevents) return device->config.sendevents->get_mode(device); return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } LIBINPUT_EXPORT uint32_t libinput_device_config_send_events_get_default_mode(struct libinput_device *device) { return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } LIBINPUT_EXPORT int libinput_device_config_accel_is_available(struct libinput_device *device) { return device->config.accel ? device->config.accel->available(device) : 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_accel_set_speed(struct libinput_device *device, double speed) { /* Need the negation in case speed is NaN */ if (!(speed >= -1.0 && speed <= 1.0)) return LIBINPUT_CONFIG_STATUS_INVALID; if (!libinput_device_config_accel_is_available(device)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.accel->set_speed(device, speed); } LIBINPUT_EXPORT double libinput_device_config_accel_get_speed(struct libinput_device *device) { if (!libinput_device_config_accel_is_available(device)) return 0; return device->config.accel->get_speed(device); } LIBINPUT_EXPORT double libinput_device_config_accel_get_default_speed(struct libinput_device *device) { if (!libinput_device_config_accel_is_available(device)) return 0; return device->config.accel->get_default_speed(device); } LIBINPUT_EXPORT uint32_t libinput_device_config_accel_get_profiles(struct libinput_device *device) { if (!libinput_device_config_accel_is_available(device)) return 0; return device->config.accel->get_profiles(device); } LIBINPUT_EXPORT enum libinput_config_accel_profile libinput_device_config_accel_get_profile(struct libinput_device *device) { if (!libinput_device_config_accel_is_available(device)) return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; return device->config.accel->get_profile(device); } LIBINPUT_EXPORT enum libinput_config_accel_profile libinput_device_config_accel_get_default_profile(struct libinput_device *device) { if (!libinput_device_config_accel_is_available(device)) return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; return device->config.accel->get_default_profile(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_accel_set_profile(struct libinput_device *device, enum libinput_config_accel_profile profile) { switch (profile) { case LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT: case LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE: case LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if (!libinput_device_config_accel_is_available(device) || (libinput_device_config_accel_get_profiles(device) & profile) == 0) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.accel->set_profile(device, profile); } static inline struct libinput_config_accel_custom_func * libinput_config_accel_custom_func_create(void) { struct libinput_config_accel_custom_func *func = zalloc(sizeof(*func)); func->step = 1.0; func->npoints = 2; func->points[0] = 0.0; /* default to a flat unaccelerated function */ func->points[1] = 1.0; return func; } static inline void libinput_config_accel_custom_func_destroy(struct libinput_config_accel_custom_func * func) { free(func); } LIBINPUT_EXPORT struct libinput_config_accel * libinput_config_accel_create(enum libinput_config_accel_profile profile) { struct libinput_config_accel *config = zalloc(sizeof(*config)); config->profile = profile; switch (profile) { case LIBINPUT_CONFIG_ACCEL_PROFILE_NONE: break; case LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT: case LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE: return config; case LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM: config->custom.fallback = libinput_config_accel_custom_func_create(); return config; } free(config); return NULL; } LIBINPUT_EXPORT void libinput_config_accel_destroy(struct libinput_config_accel *accel_config) { libinput_config_accel_custom_func_destroy(accel_config->custom.fallback); libinput_config_accel_custom_func_destroy(accel_config->custom.motion); libinput_config_accel_custom_func_destroy(accel_config->custom.scroll); free(accel_config); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_accel_apply(struct libinput_device *device, struct libinput_config_accel *accel_config) { enum libinput_config_status status; status = libinput_device_config_accel_set_profile(device, accel_config->profile); if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) return status; switch (accel_config->profile) { case LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT: case LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE: { double speed = libinput_device_config_accel_get_default_speed(device); return libinput_device_config_accel_set_speed(device, speed); } case LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM: return device->config.accel->set_accel_config(device, accel_config); default: return LIBINPUT_CONFIG_STATUS_INVALID; } } LIBINPUT_EXPORT enum libinput_config_status libinput_config_accel_set_points(struct libinput_config_accel *config, enum libinput_config_accel_type accel_type, double step, size_t npoints, double *points) { if (config->profile != LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) return LIBINPUT_CONFIG_STATUS_INVALID; switch (accel_type) { case LIBINPUT_ACCEL_TYPE_FALLBACK: case LIBINPUT_ACCEL_TYPE_MOTION: case LIBINPUT_ACCEL_TYPE_SCROLL: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if (step <= 0 || step > LIBINPUT_ACCEL_STEP_MAX) return LIBINPUT_CONFIG_STATUS_INVALID; if (npoints < LIBINPUT_ACCEL_NPOINTS_MIN || npoints > LIBINPUT_ACCEL_NPOINTS_MAX) return LIBINPUT_CONFIG_STATUS_INVALID; for (size_t idx = 0; idx < npoints; idx++) { if (points[idx] < LIBINPUT_ACCEL_POINT_MIN_VALUE || points[idx] > LIBINPUT_ACCEL_POINT_MAX_VALUE) return LIBINPUT_CONFIG_STATUS_INVALID; } struct libinput_config_accel_custom_func *func = libinput_config_accel_custom_func_create(); func->step = step; func->npoints = npoints; memcpy(func->points, points, sizeof(*points) * npoints); switch (accel_type) { case LIBINPUT_ACCEL_TYPE_FALLBACK: libinput_config_accel_custom_func_destroy(config->custom.fallback); config->custom.fallback = func; break; case LIBINPUT_ACCEL_TYPE_MOTION: libinput_config_accel_custom_func_destroy(config->custom.motion); config->custom.motion = func; break; case LIBINPUT_ACCEL_TYPE_SCROLL: libinput_config_accel_custom_func_destroy(config->custom.scroll); config->custom.scroll = func; break; } return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT int libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device) { if (!device->config.natural_scroll) return 0; return device->config.natural_scroll->has(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, int enabled) { if (!libinput_device_config_scroll_has_natural_scroll(device)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.natural_scroll->set_enabled(device, enabled); } LIBINPUT_EXPORT int libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device) { if (!device->config.natural_scroll) return 0; return device->config.natural_scroll->get_enabled(device); } LIBINPUT_EXPORT int libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device) { if (!device->config.natural_scroll) return 0; return device->config.natural_scroll->get_default_enabled(device); } LIBINPUT_EXPORT int libinput_device_config_left_handed_is_available(struct libinput_device *device) { if (!device->config.left_handed) return 0; return device->config.left_handed->has(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_left_handed_set(struct libinput_device *device, int left_handed) { if (!libinput_device_config_left_handed_is_available(device)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.left_handed->set(device, left_handed); } LIBINPUT_EXPORT int libinput_device_config_left_handed_get(struct libinput_device *device) { if (!libinput_device_config_left_handed_is_available(device)) return 0; return device->config.left_handed->get(device); } LIBINPUT_EXPORT int libinput_device_config_left_handed_get_default(struct libinput_device *device) { if (!libinput_device_config_left_handed_is_available(device)) return 0; return device->config.left_handed->get_default(device); } LIBINPUT_EXPORT uint32_t libinput_device_config_click_get_methods(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_methods(device); return 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_click_set_method(struct libinput_device *device, enum libinput_config_click_method method) { /* Check method is a single valid method */ switch (method) { case LIBINPUT_CONFIG_CLICK_METHOD_NONE: case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS: case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if ((libinput_device_config_click_get_methods(device) & method) != method) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (device->config.click_method) return device->config.click_method->set_method(device, method); /* method must be _NONE to get here */ return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT enum libinput_config_click_method libinput_device_config_click_get_method(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_method(device); return LIBINPUT_CONFIG_CLICK_METHOD_NONE; } LIBINPUT_EXPORT enum libinput_config_click_method libinput_device_config_click_get_default_method(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_default_method(device); return LIBINPUT_CONFIG_CLICK_METHOD_NONE; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_click_set_clickfinger_button_map(struct libinput_device *device, enum libinput_config_clickfinger_button_map map) { switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if ((libinput_device_config_click_get_methods(device) & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) != LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; return device->config.click_method->set_clickfinger_map(device, map); } LIBINPUT_EXPORT enum libinput_config_clickfinger_button_map libinput_device_config_click_get_clickfinger_button_map(struct libinput_device *device) { if ((libinput_device_config_click_get_methods(device) & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) != LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) return LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; return device->config.click_method->get_clickfinger_map(device); } LIBINPUT_EXPORT enum libinput_config_clickfinger_button_map libinput_device_config_click_get_default_clickfinger_button_map(struct libinput_device *device) { if ((libinput_device_config_click_get_methods(device) & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) != LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) return LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; return device->config.click_method->get_default_clickfinger_map(device); } LIBINPUT_EXPORT int libinput_device_config_middle_emulation_is_available( struct libinput_device *device) { if (device->config.middle_emulation) return device->config.middle_emulation->available(device); return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_middle_emulation_set_enabled( struct libinput_device *device, enum libinput_config_middle_emulation_state enable) { int available = libinput_device_config_middle_emulation_is_available(device); switch (enable) { case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED: if (!available) return LIBINPUT_CONFIG_STATUS_SUCCESS; break; case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED: if (!available) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } return device->config.middle_emulation->set(device, enable); } LIBINPUT_EXPORT enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_enabled( struct libinput_device *device) { if (!libinput_device_config_middle_emulation_is_available(device)) return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; return device->config.middle_emulation->get(device); } LIBINPUT_EXPORT enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_default_enabled( struct libinput_device *device) { if (!libinput_device_config_middle_emulation_is_available(device)) return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; return device->config.middle_emulation->get_default(device); } LIBINPUT_EXPORT uint32_t libinput_device_config_scroll_get_methods(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_methods(device); return 0; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_scroll_set_method(struct libinput_device *device, enum libinput_config_scroll_method method) { /* Check method is a single valid method */ switch (method) { case LIBINPUT_CONFIG_SCROLL_NO_SCROLL: case LIBINPUT_CONFIG_SCROLL_2FG: case LIBINPUT_CONFIG_SCROLL_EDGE: case LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } if ((libinput_device_config_scroll_get_methods(device) & method) != method) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (device->config.scroll_method) return device->config.scroll_method->set_method(device, method); /* method must be _NO_SCROLL to get here */ return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT enum libinput_config_scroll_method libinput_device_config_scroll_get_method(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_method(device); return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } LIBINPUT_EXPORT enum libinput_config_scroll_method libinput_device_config_scroll_get_default_method(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_default_method(device); return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_scroll_set_button(struct libinput_device *device, uint32_t button) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (button && !libinput_device_pointer_has_button(device, button)) return LIBINPUT_CONFIG_STATUS_INVALID; return device->config.scroll_method->set_button(device, button); } LIBINPUT_EXPORT uint32_t libinput_device_config_scroll_get_button(struct libinput_device *device) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return 0; return device->config.scroll_method->get_button(device); } LIBINPUT_EXPORT uint32_t libinput_device_config_scroll_get_default_button(struct libinput_device *device) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return 0; return device->config.scroll_method->get_default_button(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_scroll_set_button_lock(struct libinput_device *device, enum libinput_config_scroll_button_lock_state state) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; switch (state) { case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED: case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED: break; default: return LIBINPUT_CONFIG_STATUS_INVALID; } return device->config.scroll_method->set_button_lock(device, state); } LIBINPUT_EXPORT enum libinput_config_scroll_button_lock_state libinput_device_config_scroll_get_button_lock(struct libinput_device *device) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; return device->config.scroll_method->get_button_lock(device); } LIBINPUT_EXPORT enum libinput_config_scroll_button_lock_state libinput_device_config_scroll_get_default_button_lock(struct libinput_device *device) { if ((libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) == 0) return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; return device->config.scroll_method->get_default_button_lock(device); } LIBINPUT_EXPORT int libinput_device_config_dwt_is_available(struct libinput_device *device) { if (!device->config.dwt) return 0; return device->config.dwt->is_available(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_dwt_set_enabled(struct libinput_device *device, enum libinput_config_dwt_state enable) { if (enable != LIBINPUT_CONFIG_DWT_ENABLED && enable != LIBINPUT_CONFIG_DWT_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (!libinput_device_config_dwt_is_available(device)) return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; return device->config.dwt->set_enabled(device, enable); } LIBINPUT_EXPORT enum libinput_config_dwt_state libinput_device_config_dwt_get_enabled(struct libinput_device *device) { if (!libinput_device_config_dwt_is_available(device)) return LIBINPUT_CONFIG_DWT_DISABLED; return device->config.dwt->get_enabled(device); } LIBINPUT_EXPORT enum libinput_config_dwt_state libinput_device_config_dwt_get_default_enabled(struct libinput_device *device) { if (!libinput_device_config_dwt_is_available(device)) return LIBINPUT_CONFIG_DWT_DISABLED; return device->config.dwt->get_default_enabled(device); } LIBINPUT_EXPORT int libinput_device_config_dwtp_is_available(struct libinput_device *device) { if (!device->config.dwtp) return 0; return device->config.dwtp->is_available(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_dwtp_set_enabled(struct libinput_device *device, enum libinput_config_dwtp_state enable) { if (enable != LIBINPUT_CONFIG_DWTP_ENABLED && enable != LIBINPUT_CONFIG_DWTP_DISABLED) return LIBINPUT_CONFIG_STATUS_INVALID; if (!libinput_device_config_dwtp_is_available(device)) return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; return device->config.dwtp->set_enabled(device, enable); } LIBINPUT_EXPORT enum libinput_config_dwtp_state libinput_device_config_dwtp_get_enabled(struct libinput_device *device) { if (!libinput_device_config_dwtp_is_available(device)) return LIBINPUT_CONFIG_DWTP_DISABLED; return device->config.dwtp->get_enabled(device); } LIBINPUT_EXPORT enum libinput_config_dwtp_state libinput_device_config_dwtp_get_default_enabled(struct libinput_device *device) { if (!libinput_device_config_dwtp_is_available(device)) return LIBINPUT_CONFIG_DWTP_DISABLED; return device->config.dwtp->get_default_enabled(device); } LIBINPUT_EXPORT int libinput_device_config_rotation_is_available(struct libinput_device *device) { if (!device->config.rotation) return 0; return device->config.rotation->is_available(device); } LIBINPUT_EXPORT enum libinput_config_status libinput_device_config_rotation_set_angle(struct libinput_device *device, unsigned int degrees_cw) { if (!libinput_device_config_rotation_is_available(device)) return degrees_cw ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : LIBINPUT_CONFIG_STATUS_SUCCESS; if (degrees_cw >= 360) return LIBINPUT_CONFIG_STATUS_INVALID; return device->config.rotation->set_angle(device, degrees_cw); } LIBINPUT_EXPORT unsigned int libinput_device_config_rotation_get_angle(struct libinput_device *device) { if (!libinput_device_config_rotation_is_available(device)) return 0; return device->config.rotation->get_angle(device); } LIBINPUT_EXPORT unsigned int libinput_device_config_rotation_get_default_angle(struct libinput_device *device) { if (!libinput_device_config_rotation_is_available(device)) return 0; return device->config.rotation->get_default_angle(device); } LIBINPUT_EXPORT int libinput_tablet_tool_config_pressure_range_is_available(struct libinput_tablet_tool *tool) { if (!tool->config.pressure_range.is_available) return 0; return tool->config.pressure_range.is_available(tool); } LIBINPUT_EXPORT enum libinput_config_status libinput_tablet_tool_config_pressure_range_set(struct libinput_tablet_tool *tool, double minimum, double maximum) { if (!libinput_tablet_tool_config_pressure_range_is_available(tool)) return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; if (minimum < 0.0 || minimum >= 1.0 || maximum <= 0.0 || maximum > 1.0 || maximum <= minimum) return LIBINPUT_CONFIG_STATUS_INVALID; return tool->config.pressure_range.set(tool, minimum, maximum); } LIBINPUT_EXPORT double libinput_tablet_tool_config_pressure_range_get_minimum(struct libinput_tablet_tool *tool) { double min = 0.0, max = 1.0; if (libinput_tablet_tool_config_pressure_range_is_available(tool)) tool->config.pressure_range.get(tool, &min, &max); return min; } LIBINPUT_EXPORT double libinput_tablet_tool_config_pressure_range_get_maximum(struct libinput_tablet_tool *tool) { double min = 0.0, max = 1.0; if (libinput_tablet_tool_config_pressure_range_is_available(tool)) tool->config.pressure_range.get(tool, &min, &max); return max; } LIBINPUT_EXPORT double libinput_tablet_tool_config_pressure_range_get_default_minimum(struct libinput_tablet_tool *tool) { double min = 0.0, max = 1.0; if (libinput_tablet_tool_config_pressure_range_is_available(tool)) tool->config.pressure_range.get_default(tool, &min, &max); return min; } LIBINPUT_EXPORT double libinput_tablet_tool_config_pressure_range_get_default_maximum(struct libinput_tablet_tool *tool) { double min = 0.0, max = 1.0; if (libinput_tablet_tool_config_pressure_range_is_available(tool)) tool->config.pressure_range.get_default(tool, &min, &max); return max; } #if HAVE_LIBWACOM WacomDeviceDatabase * libinput_libwacom_ref(struct libinput *li) { WacomDeviceDatabase *db = NULL; if (!li->libwacom.db) { db = libwacom_database_new(); if (!db) { log_error(li, "Failed to initialize libwacom context\n"); return NULL; } li->libwacom.db = db; li->libwacom.refcount = 0; } li->libwacom.refcount++; db = li->libwacom.db; return db; } void libinput_libwacom_unref(struct libinput *li) { if (!li->libwacom.db) return; assert(li->libwacom.refcount >= 1); if (--li->libwacom.refcount == 0) { libwacom_database_destroy(li->libwacom.db); li->libwacom.db = NULL; } } #endif libinput-1.28.1/src/libinput.h000066400000000000000000006765751477265155700162740ustar00rootroot00000000000000/* * Copyright © 2013 Jonas Ådahl * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef LIBINPUT_H #define LIBINPUT_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include #define LIBINPUT_ATTRIBUTE_PRINTF(_format, _args) \ __attribute__ ((format (printf, _format, _args))) #define LIBINPUT_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated)) /** * @ingroup base * @struct libinput * * A handle for accessing libinput. This struct is refcounted, use * libinput_ref() and libinput_unref(). */ struct libinput; /** * @ingroup device * @struct libinput_device * * A base handle for accessing libinput devices. This struct is * refcounted, use libinput_device_ref() and libinput_device_unref(). */ struct libinput_device; /** * @ingroup device * @struct libinput_device_group * * A base handle for accessing libinput device groups. This struct is * refcounted, use libinput_device_group_ref() and * libinput_device_group_unref(). */ struct libinput_device_group; /** * @ingroup seat * @struct libinput_seat * * The base handle for accessing libinput seats. This struct is * refcounted, use libinput_seat_ref() and libinput_seat_unref(). */ struct libinput_seat; /** * @ingroup device * @struct libinput_tablet_tool * * An object representing a tool being used by a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * Tablet events generated by such a device are bound to a specific tool * rather than coming from the device directly. Depending on the hardware it * is possible to track the same physical tool across multiple * struct libinput_device devices. * See libinput_tablet_tool_get_serial() for more details. * * This struct is refcounted, use libinput_tablet_tool_ref() and * libinput_tablet_tool_unref(). * * @since 1.2 */ struct libinput_tablet_tool; /** * @ingroup event * @struct libinput_event * * The base event type. Use libinput_event_get_pointer_event() or similar to * get the actual event type. * * @warning Unlike other structs events are considered transient and * not refcounted. */ struct libinput_event; /** * @ingroup event * @struct libinput_event_device_notify * * An event notifying the caller of a device being added or removed. */ struct libinput_event_device_notify; /** * @ingroup event_keyboard * @struct libinput_event_keyboard * * A keyboard event representing a key press/release. */ struct libinput_event_keyboard; /** * @ingroup event_pointer * @struct libinput_event_pointer * * A pointer event representing relative or absolute pointer movement, * a button press/release or scroll axis events. */ struct libinput_event_pointer; /** * @ingroup event_touch * @struct libinput_event_touch * * Touch event representing a touch down, move or up, as well as a touch * cancel and touch frame events. Valid event types for this event are @ref * LIBINPUT_EVENT_TOUCH_DOWN, @ref LIBINPUT_EVENT_TOUCH_MOTION, @ref * LIBINPUT_EVENT_TOUCH_UP, @ref LIBINPUT_EVENT_TOUCH_CANCEL and @ref * LIBINPUT_EVENT_TOUCH_FRAME. */ struct libinput_event_touch; /** * @ingroup event_tablet * @struct libinput_event_tablet_tool * * Tablet tool event representing an axis update, button press, or tool * update. Valid event types for this event are @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, and @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @since 1.2 */ struct libinput_event_tablet_tool; /** * @ingroup event_tablet_pad * @struct libinput_event_tablet_pad * * Tablet pad event representing a button press, or ring/strip update on * the tablet pad itself. Valid event types for this event are @ref * LIBINPUT_EVENT_TABLET_PAD_BUTTON, @ref LIBINPUT_EVENT_TABLET_PAD_RING, * @ref LIBINPUT_EVENT_TABLET_PAD_STRIP, @ref LIBINPUT_EVENT_TABLET_PAD_KEY * and @ref LIBINPUT_EVENT_TABLET_PAD_DIAL. * * @since 1.3 */ struct libinput_event_tablet_pad; /** * @ingroup base * * Log priority for internal logging messages. */ enum libinput_log_priority { LIBINPUT_LOG_PRIORITY_DEBUG = 10, LIBINPUT_LOG_PRIORITY_INFO = 20, LIBINPUT_LOG_PRIORITY_ERROR = 30, }; /** * @ingroup device * * Capabilities on a device. A device may have one or more capabilities * at a time, capabilities remain static for the lifetime of the device. */ enum libinput_device_capability { LIBINPUT_DEVICE_CAP_KEYBOARD = 0, LIBINPUT_DEVICE_CAP_POINTER = 1, LIBINPUT_DEVICE_CAP_TOUCH = 2, LIBINPUT_DEVICE_CAP_TABLET_TOOL = 3, LIBINPUT_DEVICE_CAP_TABLET_PAD = 4, LIBINPUT_DEVICE_CAP_GESTURE = 5, LIBINPUT_DEVICE_CAP_SWITCH = 6, }; /** * @ingroup device * * Logical state of a key. Note that the logical state may not represent * the physical state of the key. */ enum libinput_key_state { LIBINPUT_KEY_STATE_RELEASED = 0, LIBINPUT_KEY_STATE_PRESSED = 1 }; /** * @ingroup device * * Mask reflecting LEDs on a device. */ enum libinput_led { LIBINPUT_LED_NUM_LOCK = (1 << 0), LIBINPUT_LED_CAPS_LOCK = (1 << 1), LIBINPUT_LED_SCROLL_LOCK = (1 << 2), LIBINPUT_LED_COMPOSE = (1 << 3), LIBINPUT_LED_KANA = (1 << 4) }; /** * @ingroup device * * Logical state of a physical button. Note that the logical state may not * represent the physical state of the button. */ enum libinput_button_state { LIBINPUT_BUTTON_STATE_RELEASED = 0, LIBINPUT_BUTTON_STATE_PRESSED = 1 }; /** * @ingroup device * * Axes on a device with the capability @ref LIBINPUT_DEVICE_CAP_POINTER * that are not x or y coordinates. * * The two scroll axes @ref LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL and * @ref LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL are engaged separately, * depending on the device. libinput provides some scroll direction locking * but it is up to the caller to determine which axis is needed and * appropriate in the current interaction */ enum libinput_pointer_axis { LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL = 0, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL = 1, }; /** * @ingroup device * * The source for a libinput_pointer_axis event. See * libinput_event_pointer_get_axis_source() for details. * * @note Pointer axis sources are deprecated, the source is now encoded in * the event types * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. */ enum libinput_pointer_axis_source { /** * The event is caused by the rotation of a wheel. */ LIBINPUT_POINTER_AXIS_SOURCE_WHEEL = 1, /** * The event is caused by the movement of one or more fingers on a * device. */ LIBINPUT_POINTER_AXIS_SOURCE_FINGER, /** * The event is caused by the motion of some device. */ LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, /** * The event is caused by the tilting of a mouse wheel rather than * its rotation. This method is commonly used on mice without * separate horizontal scroll wheels. * * @deprecated This axis source is deprecated as of libinput 1.16. * It was never used by any device before libinput 1.16. All wheel * tilt devices use @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL instead. */ LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT, }; /** * @ingroup event_tablet_pad * * The source for a @ref LIBINPUT_EVENT_TABLET_PAD_RING event. See * libinput_event_tablet_pad_get_ring_source() for details. * * @since 1.3 */ enum libinput_tablet_pad_ring_axis_source { LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN = 1, /** * The event is caused by the movement of one or more fingers on * the ring. */ LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER, }; /** * @ingroup event_tablet_pad * * The source for a @ref LIBINPUT_EVENT_TABLET_PAD_STRIP event. See * libinput_event_tablet_pad_get_strip_source() for details. * * @since 1.3 */ enum libinput_tablet_pad_strip_axis_source { LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN = 1, /** * The event is caused by the movement of one or more fingers on * the strip. */ LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, }; /** * @ingroup device * * Available tool types for a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. The tool type defines the default * usage of the tool as advertised by the manufacturer. Multiple different * physical tools may share the same tool type, e.g. a Wacom Classic Pen, * Wacom Pro Pen and a Wacom Grip Pen are all of type @ref * LIBINPUT_TABLET_TOOL_TYPE_PEN. * Use libinput_tablet_tool_get_tool_id() to get a specific model where applicable. * * Note that on some device, the eraser tool is on the tail end of a pen * device. On other devices, e.g. MS Surface 3, the eraser is the pen tip * while a button is held down. * * @note The @ref libinput_tablet_tool_type can only describe the default physical * type of the device. For devices with adjustable physical properties * the tool type remains the same, i.e. putting a Wacom stroke nib into a * classic pen leaves the tool type as @ref LIBINPUT_TABLET_TOOL_TYPE_PEN. * * @since 1.2 */ enum libinput_tablet_tool_type { LIBINPUT_TABLET_TOOL_TYPE_PEN = 1, /**< A generic pen */ LIBINPUT_TABLET_TOOL_TYPE_ERASER, /**< Eraser */ LIBINPUT_TABLET_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ LIBINPUT_TABLET_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. Wacom Inking Pen */ LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ LIBINPUT_TABLET_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ LIBINPUT_TABLET_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ LIBINPUT_TABLET_TOOL_TYPE_TOTEM, /**< A rotary device with positional and rotation data */ }; /** * @ingroup device * * The state of proximity for a tool on a device. The device must have the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * The proximity of a tool is a binary state signalling whether the tool is * within a detectable distance of the tablet device. A tool that is out of * proximity cannot generate events. * * On some hardware a tool goes out of proximity when it ceases to touch the * surface. On other hardware, the tool is still detectable within a short * distance (a few cm) off the surface. * * @since 1.2 */ enum libinput_tablet_tool_proximity_state { LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT = 0, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN = 1, }; /** * @ingroup device * * The tip contact state for a tool on a device. The device must have * the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * The tip contact state of a tool is a binary state signalling whether the tool is * touching the surface of the tablet device. * * @since 1.2 */ enum libinput_tablet_tool_tip_state { LIBINPUT_TABLET_TOOL_TIP_UP = 0, LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, }; /** * @defgroup tablet_pad_modes Tablet pad modes * * Handling the virtual mode groups of buttons, strips and rings on tablet * pad devices. See the libinput documentation for more details. */ /** * @ingroup tablet_pad_modes * @struct libinput_tablet_pad_mode_group * * A mode on a tablet pad is a virtual grouping of functionality, usually * based on some visual feedback like LEDs on the pad. The set of buttons, * rings and strips that share the same mode are a "mode group". Whenever * the mode changes, all buttons, rings and strips within this mode group * are affected. * * Most tablets only have a single mode group, some tablets provide multiple * mode groups through independent banks of LEDs (e.g. the Wacom Cintiq * 24HD). libinput guarantees that at least one mode group is always * available. * * This struct is refcounted, use libinput_tablet_pad_mode_group_ref() and * libinput_tablet_pad_mode_group_unref(). * * @since 1.4 */ struct libinput_tablet_pad_mode_group; /** * @ingroup tablet_pad_modes * * Most devices only provide a single mode group, however devices such as * the Wacom Cintiq 22HD provide two mode groups. If multiple mode groups * are available, a caller should use * libinput_tablet_pad_mode_group_has_button(), * libinput_tablet_pad_mode_group_has_ring(), * libinput_tablet_pad_mode_group_has_dial() and * libinput_tablet_pad_mode_group_has_strip() to associate each button, * ring and strip with the correct mode group. * * @return the number of mode groups available on this device * * @since 1.4 */ int libinput_device_tablet_pad_get_num_mode_groups(struct libinput_device *device); /** * @ingroup tablet_pad_modes * * The returned mode group is not refcounted and may become invalid after * the next call to libinput. Use libinput_tablet_pad_mode_group_ref() and * libinput_tablet_pad_mode_group_unref() to continue using the handle * outside of the immediate scope. * * While at least one reference is kept by the caller, the returned mode * group will be identical for each subsequent call of this function with * the same index and that same struct is returned from * libinput_event_tablet_pad_get_mode_group(), provided the event was * generated by this mode group. * * @param device A device with the @ref LIBINPUT_DEVICE_CAP_TABLET_PAD * capability * @param index A mode group index * @return the mode group with the given index or NULL if an invalid index * is given. * * @since 1.4 */ struct libinput_tablet_pad_mode_group* libinput_device_tablet_pad_get_mode_group(struct libinput_device *device, unsigned int index); /** * @ingroup tablet_pad_modes * * The returned number is the same index as passed to * libinput_device_tablet_pad_get_mode_group(). For tablets with only one * mode this number is always 0. * * @param group A previously obtained mode group * @return the numeric index this mode group represents, starting at 0 * * @since 1.4 */ unsigned int libinput_tablet_pad_mode_group_get_index(struct libinput_tablet_pad_mode_group *group); /** * @ingroup tablet_pad_modes * * Query the mode group for the number of available modes. The number of * modes is usually decided by the number of physical LEDs available on the * device. Different mode groups may have a different number of modes. Use * libinput_tablet_pad_mode_group_get_mode() to get the currently active * mode. * * libinput guarantees that at least one mode is available. A device without * mode switching capability has a single mode group and a single mode. * * @param group A previously obtained mode group * @return the number of modes available in this mode group * * @since 1.4 */ unsigned int libinput_tablet_pad_mode_group_get_num_modes(struct libinput_tablet_pad_mode_group *group); /** * @ingroup tablet_pad_modes * * Return the current mode this mode group is in. Note that the returned * mode is the mode valid as of completing the last libinput_dispatch(). * The returned mode may thus be different than the mode returned by * libinput_event_tablet_pad_get_mode(). * * For example, if the mode was toggled three times between the call to * libinput_dispatch(), this function returns the third mode but the events * in the event queue will return the modes 1, 2 and 3, respectively. * * @param group A previously obtained mode group * @return the numeric index of the current mode in this group, starting at 0 * * @see libinput_event_tablet_pad_get_mode * * @since 1.4 */ unsigned int libinput_tablet_pad_mode_group_get_mode(struct libinput_tablet_pad_mode_group *group); /** * @ingroup tablet_pad_modes * * Devices without mode switching capabilities return true for every button. * * @param group A previously obtained mode group * @param button A button index, starting at 0 * @return true if the given button index is part of this mode group or * false otherwise * * @since 1.4 */ int libinput_tablet_pad_mode_group_has_button(struct libinput_tablet_pad_mode_group *group, unsigned int button); /** * @ingroup tablet_pad_modes * * Devices without mode switching capabilities return true for every dial. * * @param group A previously obtained mode group * @param dial A dial index, starting at 0 * @return true if the given dial index is part of this mode group or * false otherwise * * @since 1.26 */ int libinput_tablet_pad_mode_group_has_dial(struct libinput_tablet_pad_mode_group *group, unsigned int dial); /** * @ingroup tablet_pad_modes * * Devices without mode switching capabilities return true for every ring. * * @param group A previously obtained mode group * @param ring A ring index, starting at 0 * @return true if the given ring index is part of this mode group or * false otherwise * * @since 1.4 */ int libinput_tablet_pad_mode_group_has_ring(struct libinput_tablet_pad_mode_group *group, unsigned int ring); /** * @ingroup tablet_pad_modes * * Devices without mode switching capabilities return true for every strip. * * @param group A previously obtained mode group * @param strip A strip index, starting at 0 * @return true if the given strip index is part of this mode group or * false otherwise * * @since 1.4 */ int libinput_tablet_pad_mode_group_has_strip(struct libinput_tablet_pad_mode_group *group, unsigned int strip); /** * @ingroup tablet_pad_modes * * The toggle button in a mode group is the button assigned to cycle to or * directly assign a new mode when pressed. Not all devices have a toggle * button and some devices may have more than one toggle button. For * example, the Wacom Cintiq 24HD has six toggle buttons in two groups, each * directly selecting one of the three modes per group. * * Devices without mode switching capabilities return false for every button. * * @param group A previously obtained mode group * @param button A button index, starting at 0 * @retval non-zero if the button is a mode toggle button for this group, or * zero otherwise * * @since 1.4 */ int libinput_tablet_pad_mode_group_button_is_toggle(struct libinput_tablet_pad_mode_group *group, unsigned int button); /** * @ingroup tablet_pad_modes * * Increase the refcount of the mode group. A mode group will be * freed whenever the refcount reaches 0. * * @param group A previously obtained mode group * @return The passed mode group * * @since 1.4 */ struct libinput_tablet_pad_mode_group * libinput_tablet_pad_mode_group_ref( struct libinput_tablet_pad_mode_group *group); /** * @ingroup tablet_pad_modes * * Decrease the refcount of the mode group. A mode group will be * freed whenever the refcount reaches 0. * * @param group A previously obtained mode group * @return NULL if the group was destroyed, otherwise the passed mode group * * @since 1.4 */ struct libinput_tablet_pad_mode_group * libinput_tablet_pad_mode_group_unref( struct libinput_tablet_pad_mode_group *group); /** * @ingroup tablet_pad_modes * * Set caller-specific data associated with this mode group. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param group A previously obtained mode group * @param user_data Caller-specific data pointer * @see libinput_tablet_pad_mode_group_get_user_data * * @since 1.4 */ void libinput_tablet_pad_mode_group_set_user_data( struct libinput_tablet_pad_mode_group *group, void *user_data); /** * @ingroup tablet_pad_modes * * Get the caller-specific data associated with this mode group, if any. * * @param group A previously obtained mode group * @return Caller-specific data pointer or NULL if none was set * @see libinput_tablet_pad_mode_group_set_user_data * * @since 1.4 */ void * libinput_tablet_pad_mode_group_get_user_data( struct libinput_tablet_pad_mode_group *group); /** * @ingroup device * * The state of a switch. The default state of a switch is @ref * LIBINPUT_SWITCH_STATE_OFF and no event is sent to confirm a switch in the * off position. If a switch is logically on during initialization, libinput * sends an event of type @ref LIBINPUT_EVENT_SWITCH_TOGGLE with a state * @ref LIBINPUT_SWITCH_STATE_ON. * * @since 1.7 */ enum libinput_switch_state { LIBINPUT_SWITCH_STATE_OFF = 0, LIBINPUT_SWITCH_STATE_ON = 1, }; /** * @ingroup device * * The type of a switch. * * @since 1.7 */ enum libinput_switch { /** * The laptop lid was closed when the switch state is @ref * LIBINPUT_SWITCH_STATE_ON, or was opened when it is @ref * LIBINPUT_SWITCH_STATE_OFF. */ LIBINPUT_SWITCH_LID = 1, /** * This switch indicates whether the device is in normal laptop mode * or behaves like a tablet-like device where the primary * interaction is usually a touch screen. When in tablet mode, the * keyboard and touchpad are usually inaccessible. * * If the switch is in state @ref LIBINPUT_SWITCH_STATE_OFF, the * device is in laptop mode. If the switch is in state @ref * LIBINPUT_SWITCH_STATE_ON, the device is in tablet mode and the * keyboard or touchpad may not be accessible. * * It is up to the caller to identify which devices are inaccessible * in tablet mode. */ LIBINPUT_SWITCH_TABLET_MODE, }; /** * @ingroup event_switch * @struct libinput_event_switch * * A switch event representing a changed state in a switch. * * @since 1.7 */ struct libinput_event_switch; /** * @ingroup base * * Event type for events returned by libinput_get_event(). */ enum libinput_event_type { /** * This is not a real event type, and is only used to tell the user that * no new event is available in the queue. See * libinput_next_event_type(). */ LIBINPUT_EVENT_NONE = 0, /** * Signals that a device has been added to the context. The device will * not be read until the next time the user calls libinput_dispatch() * and data is available. * * This allows setting up initial device configuration before any events * are created. */ LIBINPUT_EVENT_DEVICE_ADDED, /** * Signals that a device has been removed. No more events from the * associated device will be in the queue or be queued after this event. */ LIBINPUT_EVENT_DEVICE_REMOVED, LIBINPUT_EVENT_KEYBOARD_KEY = 300, LIBINPUT_EVENT_POINTER_MOTION = 400, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, LIBINPUT_EVENT_POINTER_BUTTON, /** * A scroll event from various sources. * * This event is deprecated as of libinput 1.19. Use * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS instead. * * Use libinput_event_pointer_get_axis_source() to determine the * source of a scroll event. For libinput versions 1.19 and later, * the source is encoded in the event type. * * This event is sent **in addition** to events of type * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. * Do not mix and match, either use the old event or the new events. * libinput makes no guarantee about the relation between * @ref LIBINPUT_EVENT_POINTER_AXIS and the new event types * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. You may receive * multiple zero, one or more new events per legacy event. * * @warning Ignore this event if you are processing * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. */ LIBINPUT_EVENT_POINTER_AXIS, /** * A scroll event from a wheel. This event is sent is sent **in * addition** to the @ref LIBINPUT_EVENT_POINTER_AXIS * event for all events with a * libinput_event_pointer_get_axis_source() of @ref * LIBINPUT_POINTER_AXIS_SOURCE_WHEEL. Ignore @ref * LIBINPUT_EVENT_POINTER_AXIS if you are processing this event. * * See the libinput documentation for details. * * @since 1.19 */ LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, /** * A scroll event caused by the movement of one or more fingers on a * device. This event is sent is sent **in addition** to the @ref * LIBINPUT_EVENT_POINTER_AXIS event for all events with a * libinput_event_pointer_get_axis_source() of @ref * LIBINPUT_POINTER_AXIS_SOURCE_FINGER. Ignore @ref * LIBINPUT_EVENT_POINTER_AXIS if you are processing this event. * * See the libinput documentation for details. * * @since 1.19 */ LIBINPUT_EVENT_POINTER_SCROLL_FINGER, /** * A scroll event from a continuous scroll source, e.g. button * scrolling. This event is sent is sent **in * addition** to the @ref LIBINPUT_EVENT_POINTER_AXIS * event for all events with a * libinput_event_pointer_get_axis_source() of @ref * LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS. Ignore @ref * LIBINPUT_EVENT_POINTER_AXIS if you are processing this event. * * See the libinput documentation for details. * * @since 1.19 */ LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_EVENT_TOUCH_DOWN = 500, LIBINPUT_EVENT_TOUCH_UP, LIBINPUT_EVENT_TOUCH_MOTION, LIBINPUT_EVENT_TOUCH_CANCEL, /** * Signals the end of a set of touchpoints at one device sample * time. This event has no coordinate information attached. */ LIBINPUT_EVENT_TOUCH_FRAME, /** * One or more axes have changed state on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. This event is only sent * when the tool is in proximity, see @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY for details. * * The proximity event contains the initial state of the axis as the * tool comes into proximity. An event of type @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS is only sent when an axis value * changes from this initial state. It is possible for a tool to * enter and leave proximity without sending an event of type @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS. * * An event of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS is sent * when the tip state does not change. See the documentation for * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP for more details. * * @since 1.2 */ LIBINPUT_EVENT_TABLET_TOOL_AXIS = 600, /** * Signals that a tool has come in or out of proximity of a device with * the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * Proximity events contain each of the current values for each axis, * and these values may be extracted from them in the same way they are * with @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS events. * * Some tools may always be in proximity. For these tools, events of * type @ref LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN are sent only once after @ref * LIBINPUT_EVENT_DEVICE_ADDED, and events of type @ref * LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT are sent only once before @ref * LIBINPUT_EVENT_DEVICE_REMOVED. * * If the tool that comes into proximity supports x/y coordinates, * libinput guarantees that both x and y are set in the proximity * event. * * When a tool goes out of proximity, the value of every axis should be * assumed to have an undefined state and any buttons that are currently held * down on the stylus are marked as released. Button release events for * each button that was held down on the stylus are sent before the * proximity out event. * * @since 1.2 */ LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, /** * Signals that a tool has come in contact with the surface of a * device with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * On devices without distance proximity detection, the @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP is sent immediately after @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY for the tip down event, and * immediately before for the tip up event. * * The decision when a tip touches the surface is device-dependent * and may be derived from pressure data or other means. If the tip * state is changed by axes changing state, the * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP event includes the changed * axes and no additional axis event is sent for this state change. * In other words, a caller must look at both @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP events to know the current state * of the axes. * * If a button state change occurs at the same time as a tip state * change, the order of events is device-dependent. * * @since 1.2 */ LIBINPUT_EVENT_TABLET_TOOL_TIP, /** * Signals that a tool has changed a logical button state on a * device with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * Button state changes occur on their own and do not include axis * state changes. If button and axis state changes occur within the * same logical hardware event, the order of the @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON and @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS event is device-specific. * * This event is not to be confused with the button events emitted * by the tablet pad. See @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON. * * @see LIBINPUT_EVENT_TABLET_PAD_BUTTON * * @since 1.2 */ LIBINPUT_EVENT_TABLET_TOOL_BUTTON, /** * A button pressed on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * * A button differs from @ref LIBINPUT_EVENT_TABLET_PAD_KEY in that * buttons are sequentially indexed from 0 and do not carry any * other information. Keys have a specific functionality assigned * to them. The key code thus carries a semantic meaning, a button * number does not. * * This event is not to be confused with the button events emitted * by tools on a tablet (@ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON). * * @since 1.3 */ LIBINPUT_EVENT_TABLET_PAD_BUTTON = 700, /** * A status change on a tablet ring with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * * @since 1.3 */ LIBINPUT_EVENT_TABLET_PAD_RING, /** * A status change on a strip on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * * @since 1.3 */ LIBINPUT_EVENT_TABLET_PAD_STRIP, /** * A key pressed on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * * A key differs from @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON in that * keys have a specific functionality assigned to them (buttons are * sequentially ordered). The key code thus carries a semantic * meaning, a button number does not. * * @since 1.15 */ LIBINPUT_EVENT_TABLET_PAD_KEY, /** * A status change on a tablet dial with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * * @since 1.26 */ LIBINPUT_EVENT_TABLET_PAD_DIAL, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, LIBINPUT_EVENT_GESTURE_SWIPE_END, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, LIBINPUT_EVENT_GESTURE_PINCH_END, /** * @since 1.19 */ LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END, /** * @since 1.7 */ LIBINPUT_EVENT_SWITCH_TOGGLE = 900, }; /** * @defgroup event Accessing and destruction of events */ /** * @ingroup event * * Destroy the event, freeing all associated resources. Resources obtained * from this event must be considered invalid after this call. * * @warning Unlike other structs events are considered transient and * not refcounted. Calling libinput_event_destroy() will * destroy the event. * * @param event An event retrieved by libinput_get_event(). */ void libinput_event_destroy(struct libinput_event *event); /** * @ingroup event * * Get the type of the event. * * @param event An event retrieved by libinput_get_event(). */ enum libinput_event_type libinput_event_get_type(struct libinput_event *event); /** * @ingroup event * * Get the libinput context from the event. * * @param event The libinput event * @return The libinput context for this event. */ struct libinput * libinput_event_get_context(struct libinput_event *event); /** * @ingroup event * * Return the device associated with this event. For device added/removed * events this is the device added or removed. For all other device events, * this is the device that generated the event. * * This device is not refcounted and its lifetime is that of the event. Use * libinput_device_ref() before using the device outside of this scope. * * @return The device associated with this event */ struct libinput_device * libinput_event_get_device(struct libinput_event *event); /** * @ingroup event * * Return the pointer event that is this input event. If the event type does * not match the pointer event types, this function returns NULL. * * The inverse of this function is libinput_event_pointer_get_base_event(). * * @return A pointer event, or NULL for other events */ struct libinput_event_pointer * libinput_event_get_pointer_event(struct libinput_event *event); /** * @ingroup event * * Return the keyboard event that is this input event. If the event type does * not match the keyboard event types, this function returns NULL. * * The inverse of this function is libinput_event_keyboard_get_base_event(). * * @return A keyboard event, or NULL for other events */ struct libinput_event_keyboard * libinput_event_get_keyboard_event(struct libinput_event *event); /** * @ingroup event * * Return the touch event that is this input event. If the event type does * not match the touch event types, this function returns NULL. * * The inverse of this function is libinput_event_touch_get_base_event(). * * @return A touch event, or NULL for other events */ struct libinput_event_touch * libinput_event_get_touch_event(struct libinput_event *event); /** * @ingroup event * * Return the gesture event that is this input event. If the event type does * not match the gesture event types, this function returns NULL. * * A gesture's lifetime has three distinct stages: begin, update and end, each * with their own event types. Begin is sent when the fingers are first set * down or libinput decides that the gesture begins. For @ref * LIBINPUT_EVENT_GESTURE_PINCH_BEGIN this sets the initial scale. Any * events changing properties of the gesture are sent as update events. On * termination of the gesture, an end event is sent. * * The inverse of this function is libinput_event_gesture_get_base_event(). * * @return A gesture event, or NULL for other events */ struct libinput_event_gesture * libinput_event_get_gesture_event(struct libinput_event *event); /** * @ingroup event * * Return the tablet tool event that is this input event. If the event type * does not match the tablet tool event types, this function returns NULL. * * The inverse of this function is libinput_event_tablet_tool_get_base_event(). * * @return A tablet tool event, or NULL for other events * * @since 1.2 */ struct libinput_event_tablet_tool * libinput_event_get_tablet_tool_event(struct libinput_event *event); /** * @ingroup event * * Return the tablet pad event that is this input event. If the event type does not * match the tablet pad event types, this function returns NULL. * * The inverse of this function is libinput_event_tablet_pad_get_base_event(). * * @return A tablet pad event, or NULL for other events */ struct libinput_event_tablet_pad * libinput_event_get_tablet_pad_event(struct libinput_event *event); /** * @ingroup event * * Return the switch event that is this input event. If the event type does * not match the switch event types, this function returns NULL. * * The inverse of this function is libinput_event_switch_get_base_event(). * * @return A switch event, or NULL for other events * * @since 1.7 */ struct libinput_event_switch * libinput_event_get_switch_event(struct libinput_event *event); /** * @ingroup event * * Return the device event that is this input event. If the event type does * not match the device event types, this function returns NULL. * * The inverse of this function is * libinput_event_device_notify_get_base_event(). * * @return A device event, or NULL for other events */ struct libinput_event_device_notify * libinput_event_get_device_notify_event(struct libinput_event *event); /** * @ingroup event * * @return The generic libinput_event of this event */ struct libinput_event * libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event); /** * @defgroup event_keyboard Keyboard events * * Key events are generated when a key changes its logical state, usually by * being pressed or released. */ /** * @ingroup event_keyboard * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event */ uint32_t libinput_event_keyboard_get_time(struct libinput_event_keyboard *event); /** * @ingroup event_keyboard * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event in microseconds */ uint64_t libinput_event_keyboard_get_time_usec(struct libinput_event_keyboard *event); /** * @ingroup event_keyboard * * @return The keycode that triggered this key event */ uint32_t libinput_event_keyboard_get_key(struct libinput_event_keyboard *event); /** * @ingroup event_keyboard * * @return The state change of the key */ enum libinput_key_state libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event); /** * @ingroup event_keyboard * * @return The generic libinput_event of this event */ struct libinput_event * libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event); /** * @ingroup event_keyboard * * For the key of a @ref LIBINPUT_EVENT_KEYBOARD_KEY event, return the total number * of keys pressed on all devices on the associated seat after the event was * triggered. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_KEYBOARD_KEY. For other events, this function returns 0. * * @return The seat wide pressed key count for the key of this event */ uint32_t libinput_event_keyboard_get_seat_key_count( struct libinput_event_keyboard *event); /** * @defgroup event_pointer Pointer events * * Pointer events reflect motion, button and scroll events, as well as * events from other axes. */ /** * @ingroup event_pointer * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event */ uint32_t libinput_event_pointer_get_time(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event in microseconds */ uint64_t libinput_event_pointer_get_time_usec(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the delta between the last event and the current event. For pointer * events that are not of type @ref LIBINPUT_EVENT_POINTER_MOTION, this * function returns 0. * * If a device employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * Relative motion deltas are to be interpreted as pixel movement of a * standardized mouse. See the libinput documentation for more details. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION. * * @return The relative x movement since the last event */ double libinput_event_pointer_get_dx(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the delta between the last event and the current event. For pointer * events that are not of type @ref LIBINPUT_EVENT_POINTER_MOTION, this * function returns 0. * * If a device employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * Relative motion deltas are to be interpreted as pixel movement of a * standardized mouse. See the libinput documentation for more details. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION. * * @return The relative y movement since the last event */ double libinput_event_pointer_get_dy(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the relative delta of the unaccelerated motion vector of the * current event. For pointer events that are not of type @ref * LIBINPUT_EVENT_POINTER_MOTION, this function returns 0. * * Relative unaccelerated motion deltas are raw device coordinates. * Note that these coordinates are subject to the device's native * resolution. Touchpad coordinates represent raw device coordinates in the * X resolution of the touchpad. See the libinput documentation for more * details. * * Any rotation applied to the device also applies to unaccelerated motion * (see libinput_device_config_rotation_set_angle()). * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION. * * @return The unaccelerated relative x movement since the last event */ double libinput_event_pointer_get_dx_unaccelerated( struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the relative delta of the unaccelerated motion vector of the * current event. For pointer events that are not of type @ref * LIBINPUT_EVENT_POINTER_MOTION, this function returns 0. * * Relative unaccelerated motion deltas are raw device coordinates. * Note that these coordinates are subject to the device's native * resolution. Touchpad coordinates represent raw device coordinates in the * X resolution of the touchpad. See the libinput documentation for more * details. * * Any rotation applied to the device also applies to unaccelerated motion * (see libinput_device_config_rotation_set_angle()). * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION. * * @return The unaccelerated relative y movement since the last event */ double libinput_event_pointer_get_dy_unaccelerated( struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the current absolute x coordinate of the pointer event, in mm from * the top left corner of the device. To get the corresponding output screen * coordinate, use libinput_event_pointer_get_absolute_x_transformed(). * * For pointer events that are not of type * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE. * * @return The current absolute x coordinate */ double libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the current absolute y coordinate of the pointer event, in mm from * the top left corner of the device. To get the corresponding output screen * coordinate, use libinput_event_pointer_get_absolute_y_transformed(). * * For pointer events that are not of type * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE. * * @return The current absolute y coordinate */ double libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the current absolute x coordinate of the pointer event, transformed to * screen coordinates. * * For pointer events that are not of type * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, the return value of this * function is undefined. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE. * * @param event The libinput pointer event * @param width The current output screen width * @return The current absolute x coordinate transformed to a screen coordinate */ double libinput_event_pointer_get_absolute_x_transformed( struct libinput_event_pointer *event, uint32_t width); /** * @ingroup event_pointer * * Return the current absolute y coordinate of the pointer event, transformed to * screen coordinates. * * For pointer events that are not of type * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, the return value of this function is * undefined. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE. * * @param event The libinput pointer event * @param height The current output screen height * @return The current absolute y coordinate transformed to a screen coordinate */ double libinput_event_pointer_get_absolute_y_transformed( struct libinput_event_pointer *event, uint32_t height); /** * @ingroup event_pointer * * Return the button that triggered this event. * For pointer events that are not of type @ref * LIBINPUT_EVENT_POINTER_BUTTON, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_BUTTON. * * @return The button triggering this event */ uint32_t libinput_event_pointer_get_button(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the button state that triggered this event. * For pointer events that are not of type @ref * LIBINPUT_EVENT_POINTER_BUTTON, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_BUTTON. * * @return The button state triggering this event */ enum libinput_button_state libinput_event_pointer_get_button_state(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * For the button of a @ref LIBINPUT_EVENT_POINTER_BUTTON event, return the * total number of buttons pressed on all devices on the associated seat * after the event was triggered. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_BUTTON. For other events, this function * returns 0. * * @return The seat wide pressed button count for the key of this event */ uint32_t libinput_event_pointer_get_seat_button_count( struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Check if the event has a valid value for the given axis. * * If this function returns non-zero for an axis and * libinput_event_pointer_get_axis_value() returns a value of 0, the event * is a scroll stop event. * * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_AXIS, * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, @ref * LIBINPUT_EVENT_POINTER_SCROLL_FINGER, or @ref * LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_AXIS, * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, or * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. * * @return Non-zero if this event contains a value for this axis */ int libinput_event_pointer_has_axis(struct libinput_event_pointer *event, enum libinput_pointer_axis axis); /** * @ingroup event_pointer * * Return the axis value of the given axis. The interpretation of the value * depends on the axis. For the two scrolling axes * @ref LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL and * @ref LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, the value of the event is in * relative scroll units, with the positive direction being down or right, * respectively. For the interpretation of the value, see * libinput_event_pointer_get_axis_source(). * * If libinput_event_pointer_has_axis() returns 0 for an axis, this function * returns 0 for that axis. * * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_AXIS, * this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_AXIS. * * @return The axis value of this event * * @see libinput_event_pointer_get_axis_value_discrete */ double libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event, enum libinput_pointer_axis axis); /** * @ingroup event_pointer * * Return the source for a given axis event. Axis events (scroll events) can * be caused by a hardware item such as a scroll wheel or emulated from * other input sources, such as two-finger or edge scrolling on a * touchpad. * * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_FINGER, libinput * guarantees that a scroll sequence is terminated with a scroll value of 0. * A caller may use this information to decide on whether kinetic scrolling * should be triggered on this scroll sequence. * The coordinate system is identical to the cursor movement, i.e. a * scroll value of 1 represents the equivalent relative motion of 1. * * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, no terminating * event is guaranteed (though it may happen). * Scrolling is in discrete steps, the value is the angle the wheel moved * in degrees. The default is 15 degrees per wheel click, but some mice may * have differently grained wheels. It is up to the caller how to interpret * such different step sizes. Callers should use * libinput_event_pointer_get_scroll_value_v120() for a simpler API of * handling scroll wheel events of different step sizes. * * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, libinput * guarantees that a scroll sequence is terminated with a scroll value of 0. * The coordinate system is identical to the cursor movement, i.e. a * scroll value of 1 represents the equivalent relative motion of 1. * * @deprecated The source @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT is * deprecated as of libinput 1.16. No device has ever sent this source. * * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_AXIS, * this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_AXIS. * * @note This function is superfluous as of libinput 1.19. The event * codes for @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, @ref * LIBINPUT_EVENT_POINTER_SCROLL_FINGER and @ref * LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS have the axis source encoded in * the event type. * * @return The source for this axis event */ enum libinput_pointer_axis_source libinput_event_pointer_get_axis_source(struct libinput_event_pointer *event); /** * @ingroup event_pointer * * Return the axis value in discrete steps for a given axis event. How a * value translates into a discrete step depends on the source. * * @note This function does not support high-resolution mouse wheels and * should be considered deprecated as of libinput 1.19. Callers should use * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL and * libinput_event_pointer_get_scroll_value_v120() instead. * * If the event is not of type @ref LIBINPUT_EVENT_POINTER_AXIS, this * function returns 0. * * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, the discrete * value correspond to the number of physical mouse wheel clicks. * * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS or @ref * LIBINPUT_POINTER_AXIS_SOURCE_FINGER, the discrete value is always 0. * * @return The discrete value for the given event. * * @see libinput_event_pointer_get_axis_value * @see libinput_event_pointer_get_scroll_value_v120 */ double libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event, enum libinput_pointer_axis axis); /** * @ingroup event_pointer * * Return the axis value of the given axis. The interpretation of the value * depends on the axis. For the two scrolling axes * @ref LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL and * @ref LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, the value of the event is in * relative scroll units, with the positive direction being down or right, * respectively. If libinput_event_pointer_has_axis() returns 0 for an axis, * this function returns 0 for that axis. * * If the event is @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, libinput * guarantees that a scroll sequence is terminated with a scroll value of 0. * A caller may use this information to decide on whether kinetic scrolling * should be triggered on this scroll sequence. * The coordinate system is identical to the cursor movement, i.e. a * scroll value of 1 represents the equivalent relative motion of 1. * * If the event is @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, no terminating * event is guaranteed (though it may happen). * Scrolling is in discrete steps, the value is the angle the wheel moved * in degrees. The default is 15 degrees per wheel click, but some mice may * have differently grained wheels. It is up to the caller how to interpret * such different step sizes. Callers should use * libinput_event_pointer_get_scroll_value_v120() for a simpler API of * handling scroll wheel events of different step sizes. * * If the event is @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, libinput * guarantees that a scroll sequence is terminated with a scroll value of 0. * The coordinate system is identical to the cursor movement, i.e. a * scroll value of 1 represents the equivalent relative motion of 1. * * For pointer events that are not of type * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, or * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, this function returns zero. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, * @ref LIBINPUT_EVENT_POINTER_SCROLL_FINGER, or * @ref LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. * * @return The axis value of this event * * @see libinput_event_pointer_get_scroll_value_v120 * * @since 1.19 */ double libinput_event_pointer_get_scroll_value(struct libinput_event_pointer *event, enum libinput_pointer_axis axis); /** * @ingroup event_pointer * * For events of type @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL * the v120-normalized value represents the movement in logical mouse wheel * clicks, normalized to the -120..+120 range. * * A value that is a fraction of ±120 indicates a wheel movement less than * one logical click, a caller should either scroll by the respective * fraction of the normal scroll distance or accumulate that value until a * multiple of 120 is reached. * * For most callers, this is the preferred way of handling high-resolution * scroll events. * * The normalized v120 value does not take device-specific physical angles * or distances into account, i.e. a wheel with a click angle of 20 degrees * produces only 18 logical clicks per 360 degree rotation, a wheel with a * click angle of 15 degrees produces 24 logical clicks per 360 degree * rotation. Where the physical angle matters, use * libinput_event_pointer_get_axis_value() instead. * * The magic number 120 originates from the * Windows Vista Mouse Wheel design document. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_POINTER_SCROLL_WHEEL. * * @return A value normalized to the 0-±120 range * * @see libinput_event_pointer_get_axis_value * @see libinput_event_pointer_get_axis_value_discrete * * @since 1.19 */ double libinput_event_pointer_get_scroll_value_v120(struct libinput_event_pointer *event, enum libinput_pointer_axis axis); /** * @ingroup event_pointer * * @return The generic libinput_event of this event */ struct libinput_event * libinput_event_pointer_get_base_event(struct libinput_event_pointer *event); /** * @defgroup event_touch Touch events * * Events from absolute touch devices. */ /** * @ingroup event_touch * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event */ uint32_t libinput_event_touch_get_time(struct libinput_event_touch *event); /** * @ingroup event_touch * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event in microseconds */ uint64_t libinput_event_touch_get_time_usec(struct libinput_event_touch *event); /** * @ingroup event_touch * * Get the slot of this touch event. See the kernel's multitouch * protocol B documentation for more information. * * If the touch event has no assigned slot, for example if it is from a * single touch device, this function returns -1. * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_UP, @ref LIBINPUT_EVENT_TOUCH_MOTION or @ref * LIBINPUT_EVENT_TOUCH_CANCEL, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref LIBINPUT_EVENT_TOUCH_UP, * @ref LIBINPUT_EVENT_TOUCH_MOTION or @ref LIBINPUT_EVENT_TOUCH_CANCEL. * * @return The slot of this touch event */ int32_t libinput_event_touch_get_slot(struct libinput_event_touch *event); /** * @ingroup event_touch * * Get the seat slot of the touch event. A seat slot is a non-negative seat * wide unique identifier of an active touch point. * * Events from single touch devices will be represented as one individual * touch point per device. * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_UP, @ref LIBINPUT_EVENT_TOUCH_MOTION or @ref * LIBINPUT_EVENT_TOUCH_CANCEL, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref LIBINPUT_EVENT_TOUCH_UP, * @ref LIBINPUT_EVENT_TOUCH_MOTION or @ref LIBINPUT_EVENT_TOUCH_CANCEL. * * @return The seat slot of the touch event */ int32_t libinput_event_touch_get_seat_slot(struct libinput_event_touch *event); /** * @ingroup event_touch * * Return the current absolute x coordinate of the touch event, in mm from * the top left corner of the device. To get the corresponding output screen * coordinate, use libinput_event_touch_get_x_transformed(). * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref * LIBINPUT_EVENT_TOUCH_MOTION. * * @param event The libinput touch event * @return The current absolute x coordinate */ double libinput_event_touch_get_x(struct libinput_event_touch *event); /** * @ingroup event_touch * * Return the current absolute y coordinate of the touch event, in mm from * the top left corner of the device. To get the corresponding output screen * coordinate, use libinput_event_touch_get_y_transformed(). * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref * LIBINPUT_EVENT_TOUCH_MOTION. * * @param event The libinput touch event * @return The current absolute y coordinate */ double libinput_event_touch_get_y(struct libinput_event_touch *event); /** * @ingroup event_touch * * Return the current absolute x coordinate of the touch event, transformed to * screen coordinates. * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref * LIBINPUT_EVENT_TOUCH_MOTION. * * @param event The libinput touch event * @param width The current output screen width * @return The current absolute x coordinate transformed to a screen coordinate */ double libinput_event_touch_get_x_transformed(struct libinput_event_touch *event, uint32_t width); /** * @ingroup event_touch * * Return the current absolute y coordinate of the touch event, transformed to * screen coordinates. * * For events not of type @ref LIBINPUT_EVENT_TOUCH_DOWN, @ref * LIBINPUT_EVENT_TOUCH_MOTION, this function returns 0. * * @note It is an application bug to call this function for events of type * other than @ref LIBINPUT_EVENT_TOUCH_DOWN or @ref * LIBINPUT_EVENT_TOUCH_MOTION. * * @param event The libinput touch event * @param height The current output screen height * @return The current absolute y coordinate transformed to a screen coordinate */ double libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height); /** * @ingroup event_touch * * @return The generic libinput_event of this event */ struct libinput_event * libinput_event_touch_get_base_event(struct libinput_event_touch *event); /** * @defgroup event_gesture Gesture events * * Gesture events are generated when a gesture is recognized on a touchpad. * * Gesture sequences always start with a LIBINPUT_EVENT_GESTURE_FOO_START * event. All following gesture events will be of the * LIBINPUT_EVENT_GESTURE_FOO_UPDATE type until a * LIBINPUT_EVENT_GESTURE_FOO_END is generated which signals the end of the * gesture. * * See the libinput documentation for details on gesture handling. */ /** * @ingroup event_gesture * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event */ uint32_t libinput_event_gesture_get_time(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @return The event time for this event in microseconds */ uint64_t libinput_event_gesture_get_time_usec(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * @return The generic libinput_event of this event */ struct libinput_event * libinput_event_gesture_get_base_event(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the number of fingers used for a gesture. This can be used e.g. * to differentiate between 3 or 4 finger swipes. * * This function can be called on all gesture events and the returned finger * count value remains the same for the lifetime of a gesture. Thus, if a * user puts down a fourth finger during a three-finger swipe gesture, * libinput will end the three-finger gesture and, if applicable, start a * four-finger swipe gesture. A caller may decide that those gestures are * semantically identical and continue the two gestures as one single gesture. * * @return the number of fingers used for a gesture */ int libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return if the gesture ended normally, or if it was cancelled. * For gesture events that are not of type * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or * @ref LIBINPUT_EVENT_GESTURE_PINCH_END, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or * @ref LIBINPUT_EVENT_GESTURE_PINCH_END. * * @return 0 or 1, with 1 indicating that the gesture was cancelled. */ int libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the delta between the last event and the current event. For gesture * events that are not of type @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0. * * If a device employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * Relative motion deltas are normalized to represent those of a device with * 1000dpi resolution. See the libinput documentation for more details. * * @return the relative x movement since the last event */ double libinput_event_gesture_get_dx(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the delta between the last event and the current event. For gesture * events that are not of type @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0. * * If a device employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * Relative motion deltas are normalized to represent those of a device with * 1000dpi resolution. See the libinput documentation for more details. * * @return the relative y movement since the last event */ double libinput_event_gesture_get_dy(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the relative delta of the unaccelerated motion vector of the * current event. For gesture events that are not of type * @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0. * * Relative unaccelerated motion deltas are normalized to represent those of a * device with 1000dpi resolution. See the libinput documentation for more * details. Note that unaccelerated events are not equivalent to 'raw' events * as read from the device. * * Any rotation applied to the device also applies to gesture motion * (see libinput_device_config_rotation_set_angle()). * * @return the unaccelerated relative x movement since the last event */ double libinput_event_gesture_get_dx_unaccelerated( struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the relative delta of the unaccelerated motion vector of the * current event. For gesture events that are not of type * @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0. * * Relative unaccelerated motion deltas are normalized to represent those of a * device with 1000dpi resolution. See the libinput documentation for more * details. Note that unaccelerated events are not equivalent to 'raw' events * as read from the device. * * Any rotation applied to the device also applies to gesture motion * (see libinput_device_config_rotation_set_angle()). * * @return the unaccelerated relative y movement since the last event */ double libinput_event_gesture_get_dy_unaccelerated( struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the absolute scale of a pinch gesture, the scale is the division * of the current distance between the fingers and the distance at the start * of the gesture. The scale begins at 1.0, and if e.g. the fingers moved * together by 50% then the scale will become 0.5, if they move twice as far * apart as initially the scale becomes 2.0, etc. * * For gesture events that are of type @ref * LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, this function returns 1.0. * * For gesture events that are of type @ref * LIBINPUT_EVENT_GESTURE_PINCH_END, this function returns the scale value * of the most recent @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE event (if * any) or 1.0 otherwise. * * For all other events this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, @ref * LIBINPUT_EVENT_GESTURE_PINCH_END or * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE. * * @return the absolute scale of a pinch gesture */ double libinput_event_gesture_get_scale(struct libinput_event_gesture *event); /** * @ingroup event_gesture * * Return the angle delta in degrees between the last and the current @ref * LIBINPUT_EVENT_GESTURE_PINCH_UPDATE event. For gesture events that * are not of type @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this * function returns 0. * * The angle delta is defined as the change in angle of the line formed by * the 2 fingers of a pinch gesture. Clockwise rotation is represented * by a positive delta, counter-clockwise by a negative delta. If e.g. the * fingers are on the 12 and 6 location of a clock face plate and they move * to the 1 resp. 7 location in a single event then the angle delta is * 30 degrees. * * If more than two fingers are present, the angle represents the rotation * around the center of gravity. The calculation of the center of gravity is * implementation-dependent. * * @return the angle delta since the last event */ double libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); /** * @defgroup event_tablet Tablet events * * Events that come from tools on tablet devices. For events from the pad, * see @ref event_tablet_pad. * * Events from tablet devices are exposed by two interfaces, tools and pads. * Tool events originate (usually) from a stylus-like device, pad events * reflect any events originating from the physical tablet itself. * * Note that many tablets support touch events. These are exposed through * the @ref LIBINPUT_DEVICE_CAP_POINTER interface (for external touchpad-like * devices such as the Wacom Intuos series) or @ref * LIBINPUT_DEVICE_CAP_TOUCH interface (for built-in touchscreen-like * devices such as the Wacom Cintiq series). */ /** * @ingroup event_tablet * * @return The generic libinput_event of this event * * @since 1.2 */ struct libinput_event * libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the x axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_x_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the y axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_y_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the pressure axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_pressure_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the distance axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * For tablet tool events of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, * this function always returns 1. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_distance_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the tilt x axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_tilt_x_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the tilt y axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_tilt_y_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the z-rotation axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_rotation_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the slider axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_slider_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the size major axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise */ int libinput_event_tablet_tool_size_major_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the size minor axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise */ int libinput_event_tablet_tool_size_minor_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Check if the wheel axis was updated in this event. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return 1 if the axis was updated or 0 otherwise * * @since 1.2 */ int libinput_event_tablet_tool_wheel_has_changed( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the X coordinate of the tablet tool, in mm from the top left * corner of the tablet in its current logical orientation. Use * libinput_event_tablet_tool_get_x_transformed() for transforming the axis * value into a different coordinate space. * * If an area is defined for this device, the coordinate is in mm from * the top left corner of the area. See * libinput_device_config_area_set_rectangle() for details. * * @note On some devices, returned value may be negative or larger than the * width of the device. See the libinput documentation for more details. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the Y coordinate of the tablet tool, in mm from the top left * corner of the tablet in its current logical orientation. Use * libinput_event_tablet_tool_get_y_transformed() for transforming the axis * value into a different coordinate space. * * If an area is defined for this device, the coordinate is in mm from * the top left corner of the area. See * libinput_device_config_area_set_rectangle() for details. * * @note On some devices, returned value may be negative or larger than the * width of the device. See the libinput documentation for more details. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the delta between the last event and the current event. * If the tool employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * This value is in screen coordinate space, the delta is to be interpreted * like the return value of libinput_event_pointer_get_dx(). * See the libinput documentation for more details. * * @param event The libinput tablet event * @return The relative x movement since the last event * * @since 1.2 */ double libinput_event_tablet_tool_get_dx(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the delta between the last event and the current event. * If the tool employs pointer acceleration, the delta returned by this * function is the accelerated delta. * * This value is in screen coordinate space, the delta is to be interpreted * like the return value of libinput_event_pointer_get_dx(). * See the libinput documentation for more details. * * @param event The libinput tablet event * @return The relative y movement since the last event * * @since 1.2 */ double libinput_event_tablet_tool_get_dy(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current pressure being applied on the tool in use, normalized * to the range [0, 1]. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current distance from the tablet's sensor, normalized to the * range [0, 1]. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current tilt along the X axis of the tablet's current logical * orientation, in degrees off the tablet's z axis. That is, if the tool is * perfectly orthogonal to the tablet, the tilt angle is 0. When the top * tilts towards the logical top/left of the tablet, the x/y tilt angles are * negative, if the top tilts towards the logical bottom/right of the * tablet, the x/y tilt angles are positive. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the axis in degrees * * @since 1.2 */ double libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current tilt along the Y axis of the tablet's current logical * orientation, in degrees off the tablet's z axis. That is, if the tool is * perfectly orthogonal to the tablet, the tilt angle is 0. When the top * tilts towards the logical top/left of the tablet, the x/y tilt angles are * negative, if the top tilts towards the logical bottom/right of the * tablet, the x/y tilt angles are positive. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the the axis in degrees * * @since 1.2 */ double libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current z rotation of the tool in degrees, clockwise from the * tool's logical neutral position. * * For tools of type @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref * LIBINPUT_TABLET_TOOL_TYPE_LENS the logical neutral position is * pointing to the current logical north of the tablet. For tools of type @ref * LIBINPUT_TABLET_TOOL_TYPE_BRUSH, the logical neutral position is with the * buttons pointing up. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current position of the slider on the tool, normalized to the * range [-1, 1]. The logical zero is the neutral position of the slider, or * the logical center of the axis. This axis is available on e.g. the Wacom * Airbrush. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the the axis * * @since 1.2 */ double libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current size in mm along the major axis of the touching * ellipse. This axis is not necessarily aligned with either x or y, the * rotation must be taken into account. * * Where no rotation is available on a tool, or where rotation is zero, the * major axis aligns with the y axis and the minor axis with the x axis. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the axis major in mm */ double libinput_event_tablet_tool_get_size_major(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the current size in mm along the minor axis of the touching * ellipse. This axis is not necessarily aligned with either x or y, the * rotation must be taken into account. * * Where no rotation is available on a tool, or where rotation is zero, the * minor axis aligns with the y axis and the minor axis with the x axis. * * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet tool event * @return The current value of the axis minor in mm */ double libinput_event_tablet_tool_get_size_minor(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the delta for the wheel in degrees. * * @param event The libinput tablet tool event * @return The delta of the wheel, in degrees, compared to the last event * * @see libinput_event_tablet_tool_get_wheel_delta_discrete */ double libinput_event_tablet_tool_get_wheel_delta( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the delta for the wheel in discrete steps (e.g. wheel clicks). * @param event The libinput tablet tool event * @return The delta of the wheel, in discrete steps, compared to the last event * * @see libinput_event_tablet_tool_get_wheel_delta_discrete * * @since 1.2 */ int libinput_event_tablet_tool_get_wheel_delta_discrete( struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the current absolute x coordinate of the tablet tool event, * transformed to screen coordinates. * * @note This function may be called for a specific axis even if * libinput_event_tablet_tool_*_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @note On some devices, returned value may be negative or larger than the * width of the device. See the libinput documentation for more details. * * @param event The libinput tablet tool event * @param width The current output screen width * @return the current absolute x coordinate transformed to a screen coordinate * * @since 1.2 */ double libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event, uint32_t width); /** * @ingroup event_tablet * * Return the current absolute y coordinate of the tablet tool event, * transformed to screen coordinates. * * @note This function may be called for a specific axis even if * libinput_event_tablet_tool_*_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @note On some devices, returned value may be negative or larger than the * width of the device. See the libinput documentation for more details. * * @param event The libinput tablet tool event * @param height The current output screen height * @return the current absolute y coordinate transformed to a screen coordinate * * @since 1.2 */ double libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event, uint32_t height); /** * @ingroup event_tablet * * Returns the tool that was in use during this event. * * The returned tablet tool is not refcounted and may become invalid after * the next call to libinput. Use libinput_tablet_tool_ref() and * libinput_tablet_tool_unref() to continue using the handle outside of the * immediate scope. * * If the caller holds at least one reference, this struct is used * whenever the tools enters proximity again. * * @note Physical tool tracking requires hardware support. If unavailable, * libinput creates one tool per type per tablet. See * libinput_tablet_tool_get_serial() for more details. * * @param event The libinput tablet tool event * @return The new tool triggering this event * * @since 1.2 */ struct libinput_tablet_tool * libinput_event_tablet_tool_get_tool(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the new proximity state of a tool from a proximity event. * Used to check whether or not a tool came in or out of proximity during an * event of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * The proximity state represents the logical proximity state which does not * necessarily match when a tool comes into sensor range or leaves the * sensor range. On some tools this range does not represent the physical * range but a reduced tool-specific logical range. If the range is reduced, * this is done transparent to the caller. * * For example, the Wacom mouse and lens cursor tools are usually * used in relative mode, lying flat on the tablet. Movement typically follows * the interaction normal mouse movements have, i.e. slightly lift the tool and * place it in a separate location. The proximity detection on Wacom * tablets however extends further than the user may lift the mouse, i.e. the * tool may not be lifted out of physical proximity. For such tools, libinput * provides software-emulated proximity. * * @param event The libinput tablet tool event * @return The new proximity state of the tool from the event. * * @since 1.2 */ enum libinput_tablet_tool_proximity_state libinput_event_tablet_tool_get_proximity_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Returns the new tip state of a tool from a tip event. * Used to check whether or not a tool came in contact with the tablet * surface or left contact with the tablet surface during an * event of type @ref LIBINPUT_EVENT_TABLET_TOOL_TIP. * * @param event The libinput tablet tool event * @return The new tip state of the tool from the event. * * @since 1.2 */ enum libinput_tablet_tool_tip_state libinput_event_tablet_tool_get_tip_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the button that triggered this event. For events that are not of * type @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return the button triggering this event * * @since 1.2 */ uint32_t libinput_event_tablet_tool_get_button(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the button state of the event. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet tool event * @return the button state triggering this event * * @since 1.2 */ enum libinput_button_state libinput_event_tablet_tool_get_button_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * For the button of a @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON event, return the total * number of buttons pressed on all devices on the associated seat after the * the event was triggered. * " @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. For other events, this function returns 0. * * @param event The libinput tablet tool event * @return the seat wide pressed button count for the key of this event * * @since 1.2 */ uint32_t libinput_event_tablet_tool_get_seat_button_count(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput tablet tool event * @return The event time for this event * * @since 1.2 */ uint32_t libinput_event_tablet_tool_get_time(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput tablet tool event * @return The event time for this event in microseconds * * @since 1.2 */ uint64_t libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * * Return the high-level tool type for a tool object. * * The high level tool describes general interaction expected with the tool. * For example, a user would expect a tool of type @ref * LIBINPUT_TABLET_TOOL_TYPE_PEN to interact with a graphics application * taking pressure and tilt into account. The default virtual tool assigned * should be a drawing tool, e.g. a virtual pen or brush. * A tool of type @ref LIBINPUT_TABLET_TOOL_TYPE_ERASER would normally be * mapped to an eraser-like virtual tool. * * If supported by the hardware, a more specific tool id is always * available, see libinput_tablet_tool_get_tool_id(). * * @param tool The libinput tool * @return The tool type for this tool object * * @see libinput_tablet_tool_get_tool_id * * @since 1.2 */ enum libinput_tablet_tool_type libinput_tablet_tool_get_type(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return the tool ID for a tool object. If nonzero, this number identifies * the specific type of the tool with more precision than the type returned in * libinput_tablet_tool_get_type(). Not all tablets support a tool ID. * * Tablets known to support tool IDs include the Wacom Intuos 3, 4, 5, Wacom * Cintiq and Wacom Intuos Pro series. The tool ID can be used to * distinguish between e.g. a Wacom Classic Pen or a Wacom Pro Pen. It is * the caller's responsibility to interpret the tool ID. * * @param tool The libinput tool * @return The tool ID for this tool object or 0 if none is provided * * @see libinput_tablet_tool_get_type * * @since 1.2 */ uint64_t libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Increment the reference count of the tool by one. A tool is destroyed * whenever the reference count reaches 0. See libinput_tablet_tool_unref(). * * @param tool The tool to increment the ref count of * @return The passed tool * * @see libinput_tablet_tool_unref * * @since 1.2 */ struct libinput_tablet_tool * libinput_tablet_tool_ref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Decrement the reference count of the tool by one. When the reference * count of the tool reaches 0, the memory allocated for the tool will be * freed. * * @param tool The tool to decrement the ref count of * @return NULL if the tool was destroyed otherwise the passed tool * * @see libinput_tablet_tool_ref * * @since 1.2 */ struct libinput_tablet_tool * libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool supports pressure. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool supports distance. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool supports tilt. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool supports z-rotation. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool has a slider axis. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool has a ellipsis major and minor. * Where the underlying hardware only supports one of either major or minor, * libinput emulates the other axis as a circular contact, i.e. major == * minor for all values of major. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. */ int libinput_tablet_tool_has_size(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return whether the tablet tool has a relative wheel. * * @param tool The tool to check the axis capabilities of * @return Nonzero if the axis is available, zero otherwise. * * @since 1.2 */ int libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Check if a tablet tool has a button with the * passed-in code (see linux/input.h). * * @param tool A tablet tool * @param code button code to check for * * @return 1 if the tool supports this button code, 0 if it does not * * @since 1.2 */ int libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, uint32_t code); /** * @ingroup event_tablet * * Return nonzero if the physical tool can be uniquely identified by * libinput, or nonzero otherwise. If a tool can be uniquely identified, * keeping a reference to the tool allows tracking the tool across * proximity out sequences and across compatible tablets. * See libinput_tablet_tool_get_serial() for more details. * * @param tool A tablet tool * @return 1 if the tool can be uniquely identified, 0 otherwise. * * @see libinput_tablet_tool_get_serial * * @since 1.2 */ int libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return the serial number of a tool. If the tool does not report a serial * number, this function returns zero. * * Some tools provide hardware information that enables libinput to uniquely * identify the physical device. For example, tools compatible with the * Wacom Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely * identifiable through a serial number. libinput does not specify how a * tool can be identified uniquely, a caller should use * libinput_tablet_tool_is_unique() to check if the tool is unique. * * libinput creates a struct @ref libinput_tablet_tool on the first * proximity in of this tool. By default, this struct is destroyed on * proximity out and re-initialized on the next proximity in. If a caller * keeps a reference to the tool by using libinput_tablet_tool_ref() * libinput re-uses this struct whenever that same physical tool comes into * proximity on any tablet * recognized by libinput. It is possible to attach tool-specific virtual * state to the tool. For example, a graphics program such as the GIMP may * assign a specific color to each tool, allowing the artist to use the * tools like physical pens of different color. In multi-tablet setups it is * also possible to track the tool across devices. * * If the tool does not have a unique identifier, libinput creates a single * struct @ref libinput_tablet_tool per tool type on each tablet the tool is * used on. * * @param tool The libinput tool * @return The tool serial number * * @see libinput_tablet_tool_is_unique * * @since 1.2 */ uint64_t libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Return the user data associated with a tool object. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param tool The libinput tool * @return The user data associated with the tool object * * @since 1.2 */ void * libinput_tablet_tool_get_user_data(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * * Set the user data associated with a tool object, if any. * * @param tool The libinput tool * @param user_data The user data to associate with the tool object * * @since 1.2 */ void libinput_tablet_tool_set_user_data(struct libinput_tablet_tool *tool, void *user_data); /** * @defgroup event_tablet_pad Tablet pad events * * Events that come from the pad of tablet devices. For events from the * tablet tools, see @ref event_tablet. * * @since 1.3 */ /** * @ingroup event_tablet_pad * * @return The generic libinput_event of this event * * @since 1.3 */ struct libinput_event * libinput_event_tablet_pad_get_base_event(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the current position of the ring, in degrees clockwise * from the northern-most point of the ring in the tablet's current logical * orientation. * * If the source is @ref LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER, * libinput sends a terminating event with a ring value of -1 when the * finger is lifted from the ring. A caller may use this information to e.g. * determine if kinetic scrolling should be triggered. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_RING. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The current value of the the axis * @retval -1 The finger was lifted * * @since 1.3 */ double libinput_event_tablet_pad_get_ring_position(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the number of the ring that has changed state, with 0 being the * first ring. On tablets with only one ring, this function always returns * 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_RING. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The index of the ring that changed state * * @since 1.3 */ unsigned int libinput_event_tablet_pad_get_ring_number(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the source of the interaction with the ring. If the source is * @ref LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER, libinput sends a ring * position value of -1 to terminate the current interaction. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_RING. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The source of the ring interaction * * @since 1.3 */ enum libinput_tablet_pad_ring_axis_source libinput_event_tablet_pad_get_ring_source(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the current position of the strip, normalized to the range * [0, 1], with 0 being the top/left-most point in the tablet's current * logical orientation. * * If the source is @ref LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, * libinput sends a terminating event with a ring value of -1 when the * finger is lifted from the ring. A caller may use this information to e.g. * determine if kinetic scrolling should be triggered. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_STRIP. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The current value of the the axis * @retval -1 The finger was lifted * * @since 1.3 */ double libinput_event_tablet_pad_get_strip_position(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the number of the strip that has changed state, with 0 being the * first strip. On tablets with only one strip, this function always returns * 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_STRIP. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The index of the strip that changed state * * @since 1.3 */ unsigned int libinput_event_tablet_pad_get_strip_number(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the source of the interaction with the strip. If the source is * @ref LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER, libinput sends a strip * position value of -1 to terminate the current interaction. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_STRIP. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The source of the strip interaction * * @since 1.3 */ enum libinput_tablet_pad_strip_axis_source libinput_event_tablet_pad_get_strip_source(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Return the button number that triggered this event, starting at 0. * For events that are not of type @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON, * this function returns 0. * * Note that the number returned is a generic sequential button number and * not a semantic button code as defined in linux/input.h. * See the libinput documentation for more details. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return the button triggering this event * * @since 1.3 */ uint32_t libinput_event_tablet_pad_get_button_number(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Return the button state of the event. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return the button state triggering this event * * @since 1.3 */ enum libinput_button_state libinput_event_tablet_pad_get_button_state(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Return the key code that triggered this event, e.g. KEY_CONTROLPANEL. The * list of key codes is defined in linux/input-event-codes.h. * * For events that are not of type @ref LIBINPUT_EVENT_TABLET_PAD_KEY, * this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_KEY. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return the key code triggering this event * * @since 1.15 */ uint32_t libinput_event_tablet_pad_get_key(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Return the key state of the event. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_KEY. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return the key state triggering this event * * @since 1.15 */ enum libinput_key_state libinput_event_tablet_pad_get_key_state(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the delta change of the dial, in multiples or fractions of 120, with * each multiple of 120 indicating one logical wheel event. * See libinput_event_pointer_get_scroll_value_v120() for more details. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_DIAL. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The delta of the the axis * * @since 1.26 */ double libinput_event_tablet_pad_get_dial_delta_v120(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the number of the dial that has changed state, with 0 being the * first dial. On tablets with only one dial, this function always returns * 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_PAD_DIAL. For other events, this function * returns 0. * * @param event The libinput tablet pad event * @return The index of the dial that changed state * * @since 1.26 */ unsigned int libinput_event_tablet_pad_get_dial_number(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the mode the button, ring, or strip that triggered this event is * in, at the time of the event. * * The mode is a virtual grouping of functionality, usually based on some * visual feedback like LEDs on the pad. Mode indices start at 0, a device * that does not support modes always returns 0. * * @note Pad keys are not part of a mode group. It is an application bug to * call this function for @ref LIBINPUT_EVENT_TABLET_PAD_KEY. * * Mode switching is controlled by libinput and more than one mode may exist * on the tablet. This function returns the mode that this event's button, * ring or strip is logically in. If the button is a mode toggle button * and the button event caused a new mode to be toggled, the mode returned * is the new mode the button is in. * * Note that the returned mode is the mode valid as of the time of the * event. The returned mode may thus be different to the mode returned by * libinput_tablet_pad_mode_group_get_mode(). See * libinput_tablet_pad_mode_group_get_mode() for details. * * @param event The libinput tablet pad event * @return the 0-indexed mode of this button, ring or strip at the time of * the event * * @see libinput_tablet_pad_mode_group_get_mode * * @since 1.4 */ unsigned int libinput_event_tablet_pad_get_mode(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * Returns the mode group that the button, ring, or strip that triggered * this event is considered in. The mode is a virtual grouping of * functionality, usually based on some visual feedback like LEDs on the * pad. * * @note Pad keys are not part of a mode group. It is an application bug to * call this function for @ref LIBINPUT_EVENT_TABLET_PAD_KEY. * * The returned mode group is not refcounted and may become invalid after * the next call to libinput. Use libinput_tablet_pad_mode_group_ref() and * libinput_tablet_pad_mode_group_unref() to continue using the handle * outside of the immediate scope. * * @param event The libinput tablet pad event * @return the mode group of the button, ring or strip that caused this event * * @see libinput_device_tablet_pad_get_mode_group * * @since 1.4 */ struct libinput_tablet_pad_mode_group * libinput_event_tablet_pad_get_mode_group(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput tablet pad event * @return The event time for this event * * @since 1.3 */ uint32_t libinput_event_tablet_pad_get_time(struct libinput_event_tablet_pad *event); /** * @ingroup event_tablet_pad * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput tablet pad event * @return The event time for this event in microseconds * * @since 1.3 */ uint64_t libinput_event_tablet_pad_get_time_usec(struct libinput_event_tablet_pad *event); /** * @defgroup event_switch Switch events * * Events that come from switch devices. */ /** * @ingroup event_switch * * Return the switch that triggered this event. * For pointer events that are not of type @ref * LIBINPUT_EVENT_SWITCH_TOGGLE, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_SWITCH_TOGGLE. * * @param event The libinput switch event * @return The switch triggering this event * * @since 1.7 */ enum libinput_switch libinput_event_switch_get_switch(struct libinput_event_switch *event); /** * @ingroup event_switch * * Return the switch state that triggered this event. * For switch events that are not of type @ref * LIBINPUT_EVENT_SWITCH_TOGGLE, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_SWITCH_TOGGLE. * * @param event The libinput switch event * @return The switch state triggering this event * * @since 1.7 */ enum libinput_switch_state libinput_event_switch_get_switch_state(struct libinput_event_switch *event); /** * @ingroup event_switch * * @return The generic libinput_event of this event * * @since 1.7 */ struct libinput_event * libinput_event_switch_get_base_event(struct libinput_event_switch *event); /** * @ingroup event_switch * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput switch event * @return The event time for this event * * @since 1.7 */ uint32_t libinput_event_switch_get_time(struct libinput_event_switch *event); /** * @ingroup event_switch * * @note Timestamps may not always increase. See the libinput documentation * for more details. * * @param event The libinput switch event * @return The event time for this event in microseconds * * @since 1.7 */ uint64_t libinput_event_switch_get_time_usec(struct libinput_event_switch *event); /** * @defgroup base Initialization and manipulation of libinput contexts */ /** * @ingroup base * @struct libinput_interface * * libinput does not open file descriptors to devices directly, instead * open_restricted() and close_restricted() are called for each path that * must be opened. * * @see libinput_udev_create_context * @see libinput_path_create_context */ struct libinput_interface { /** * Open the device at the given path with the flags provided and * return the fd. * * @param path The device path to open * @param flags Flags as defined by open(2) * @param user_data The user_data provided in * libinput_udev_create_context() * * @return The file descriptor, or a negative errno on failure. */ int (*open_restricted)(const char *path, int flags, void *user_data); /** * Close the file descriptor. * * @param fd The file descriptor to close * @param user_data The user_data provided in * libinput_udev_create_context() */ void (*close_restricted)(int fd, void *user_data); }; /** * @ingroup base * * Create a new libinput context from udev. This context is inactive until * assigned a seat ID with libinput_udev_assign_seat(). * * @param interface The callback interface * @param user_data Caller-specific data passed to the various callback * interfaces. * @param udev An already initialized udev context * * @return An initialized, but inactive libinput context or NULL on error */ struct libinput * libinput_udev_create_context(const struct libinput_interface *interface, void *user_data, struct udev *udev); /** * @ingroup base * * Assign a seat to this libinput context. New devices or the removal of * existing devices will appear as events during libinput_dispatch(). * * libinput_udev_assign_seat() succeeds even if no input devices are currently * available on this seat, or if devices are available but fail to open in * @ref libinput_interface::open_restricted. 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 * ignored until the next call to libinput_resume(). * * This function may only be called once per context. * * @param libinput A libinput context initialized with * libinput_udev_create_context() * @param seat_id A seat identifier. This string must not be NULL. * * @return 0 on success or -1 on failure. */ int libinput_udev_assign_seat(struct libinput *libinput, const char *seat_id); /** * @ingroup base * * Create a new libinput context that requires the caller to manually add or * remove devices with libinput_path_add_device() and * libinput_path_remove_device(). * * The context is fully initialized but will not generate events until at * least one device has been added. * * The reference count of the context is initialized to 1. See @ref * libinput_unref. * * @param interface The callback interface * @param user_data Caller-specific data passed to the various callback * interfaces. * * @return An initialized, empty libinput context. */ struct libinput * libinput_path_create_context(const struct libinput_interface *interface, void *user_data); /** * @ingroup base * * Add a device to a libinput context initialized with * libinput_path_create_context(). If successful, the device will be * added to the internal list and re-opened on libinput_resume(). The device * can be removed with libinput_path_remove_device(). * * If the device was successfully initialized, it is returned in the device * argument. The lifetime of the returned device pointer is limited until * the next libinput_dispatch(), use libinput_device_ref() to keep a permanent * reference. * * @param libinput A previously initialized libinput context * @param path Path to an input device * @return The newly initiated device on success, or NULL on failure. * * @note It is an application bug to call this function on a libinput * context initialized with libinput_udev_create_context(). */ struct libinput_device * libinput_path_add_device(struct libinput *libinput, const char *path); /** * @ingroup base * * Remove a device from a libinput context initialized with * libinput_path_create_context() or added to such a context with * libinput_path_add_device(). * * Events already processed from this input device are kept in the queue, * the @ref LIBINPUT_EVENT_DEVICE_REMOVED event marks the end of events for * this device. * * If no matching device exists, this function does nothing. * * @param device A libinput device * * @note It is an application bug to call this function on a libinput * context initialized with libinput_udev_create_context(). */ void libinput_path_remove_device(struct libinput_device *device); /** * @ingroup base * * libinput keeps a single file descriptor for all events. Call into * libinput_dispatch() if any events become available on this fd. * * @return The file descriptor used to notify of pending events. */ int libinput_get_fd(struct libinput *libinput); /** * @ingroup base * * Main event dispatchment function. Reads events of the file descriptors * and processes them internally. Use libinput_get_event() to retrieve the * events. * * Dispatching does not necessarily queue libinput events. This function * should be called immediately once data is available on the file * descriptor returned by libinput_get_fd(). libinput has a number of * timing-sensitive features (e.g. tap-to-click), any delay in calling * libinput_dispatch() may prevent these features from working correctly. * * @param libinput A previously initialized libinput context * * @return 0 on success, or a negative errno on failure */ int libinput_dispatch(struct libinput *libinput); /** * @ingroup base * * Retrieve the next event from libinput's internal event queue. * * After handling the retrieved event, the caller must destroy it using * libinput_event_destroy(). * * @param libinput A previously initialized libinput context * @return The next available event, or NULL if no event is available. */ struct libinput_event * libinput_get_event(struct libinput *libinput); /** * @ingroup base * * Return the type of the next event in the internal queue. This function * does not pop the event off the queue and the next call to * libinput_get_event() returns that event. * * @param libinput A previously initialized libinput context * @return The event type of the next available event or @ref * LIBINPUT_EVENT_NONE if no event is available. */ enum libinput_event_type libinput_next_event_type(struct libinput *libinput); /** * @ingroup base * * Set caller-specific data associated with this context. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param libinput A previously initialized libinput context * @param user_data Caller-specific data passed to the various callback * interfaces. */ void libinput_set_user_data(struct libinput *libinput, void *user_data); /** * @ingroup base * * Get the caller-specific data associated with this context, if any. * * @param libinput A previously initialized libinput context * @return The caller-specific data previously assigned in * libinput_set_user_data(), libinput_path_create_context() or * libinput_udev_create_context(). */ void * libinput_get_user_data(struct libinput *libinput); /** * @ingroup base * * Resume a suspended libinput context. This re-enables device * monitoring and adds existing devices. * * @param libinput A previously initialized libinput context * @see libinput_suspend * * @return 0 on success or -1 on failure */ int libinput_resume(struct libinput *libinput); /** * @ingroup base * * Suspend monitoring for new devices and close existing devices. * This all but terminates libinput but does keep the context * valid to be resumed with libinput_resume(). * * @param libinput A previously initialized libinput context */ void libinput_suspend(struct libinput *libinput); /** * @ingroup base * * Add a reference to the context. A context is destroyed whenever the * reference count reaches 0. See @ref libinput_unref. * * @param libinput A previously initialized valid libinput context * @return The passed libinput context */ struct libinput * libinput_ref(struct libinput *libinput); /** * @ingroup base * * Dereference the libinput context. After this, the context may have been * destroyed, if the last reference was dereferenced. If so, the context is * invalid and may not be interacted with. * * @bug When the refcount reaches zero, libinput_unref() releases resources * even if a caller still holds refcounted references to related resources * (e.g. a libinput_device). When libinput_unref() returns * NULL, the caller must consider any resources related to that context * invalid. See https://bugs.freedesktop.org/show_bug.cgi?id=91872. * * Example code: * @code * li = libinput_path_create_context(&interface, NULL); * device = libinput_path_add_device(li, "/dev/input/event0"); * // get extra reference to device * libinput_device_ref(device); * * // refcount reaches 0, so *all* resources are cleaned up, * // including device * libinput_unref(li); * * // INCORRECT: device has been cleaned up and must not be used * // li = libinput_device_get_context(device); * @endcode * * @param libinput A previously initialized libinput context * @return NULL if context was destroyed otherwise the passed context */ struct libinput * libinput_unref(struct libinput *libinput); /** * @ingroup base * * Set the log priority for the libinput context. Messages with priorities * equal to or higher than the argument will be printed to the context's * log handler. * * The default log priority is @ref LIBINPUT_LOG_PRIORITY_ERROR. * * @param libinput A previously initialized libinput context * @param priority The minimum priority of log messages to print. * * @see libinput_log_set_handler * @see libinput_log_get_priority */ void libinput_log_set_priority(struct libinput *libinput, enum libinput_log_priority priority); /** * @ingroup base * * Get the context's log priority. Messages with priorities equal to or * higher than the argument will be printed to the current log handler. * * The default log priority is @ref LIBINPUT_LOG_PRIORITY_ERROR. * * @param libinput A previously initialized libinput context * @return The minimum priority of log messages to print. * * @see libinput_log_set_handler * @see libinput_log_set_priority */ enum libinput_log_priority libinput_log_get_priority(const struct libinput *libinput); /** * @ingroup base * * Log handler type for custom logging. * * @param libinput The libinput context * @param priority The priority of the current message * @param format Message format in printf-style * @param args Message arguments * * @see libinput_log_set_priority * @see libinput_log_get_priority * @see libinput_log_set_handler */ typedef void (*libinput_log_handler)(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) LIBINPUT_ATTRIBUTE_PRINTF(3, 0); /** * @ingroup base * * Set the context's log handler. Messages with priorities equal to or * higher than the context's log priority will be passed to the given * log handler. * * The default log handler prints to stderr. * * @param libinput A previously initialized libinput context * @param log_handler The log handler for library messages. * * @see libinput_log_set_priority * @see libinput_log_get_priority */ void libinput_log_set_handler(struct libinput *libinput, libinput_log_handler log_handler); /** * @defgroup seat Initialization and manipulation of seats * * A seat has two identifiers, the physical name and the logical name. A * device is always assigned to exactly one seat. It may change to a * different logical seat but it cannot change physical seats. * * See the libinput documentation for more information on seats. */ /** * @ingroup seat * * Increase the refcount of the seat. A seat will be freed whenever the * refcount reaches 0. This may happen during libinput_dispatch() if the * seat was removed from the system. A caller must ensure to reference * the seat correctly to avoid dangling pointers. * * @param seat A previously obtained seat * @return The passed seat */ struct libinput_seat * libinput_seat_ref(struct libinput_seat *seat); /** * @ingroup seat * * Decrease the refcount of the seat. A seat will be freed whenever the * refcount reaches 0. This may happen during libinput_dispatch() if the * seat was removed from the system. A caller must ensure to reference * the seat correctly to avoid dangling pointers. * * @param seat A previously obtained seat * @return NULL if seat was destroyed, otherwise the passed seat */ struct libinput_seat * libinput_seat_unref(struct libinput_seat *seat); /** * @ingroup seat * * Set caller-specific data associated with this seat. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param seat A previously obtained seat * @param user_data Caller-specific data pointer * @see libinput_seat_get_user_data */ void libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data); /** * @ingroup seat * * Get the caller-specific data associated with this seat, if any. * * @param seat A previously obtained seat * @return Caller-specific data pointer or NULL if none was set * @see libinput_seat_set_user_data */ void * libinput_seat_get_user_data(struct libinput_seat *seat); /** * @ingroup seat * * Get the libinput context from the seat. * * @param seat A previously obtained seat * @return The libinput context for this seat. */ struct libinput * libinput_seat_get_context(struct libinput_seat *seat); /** * @ingroup seat * * Return the physical name of the seat. For libinput contexts created from * udev, this is always the same value as passed into * libinput_udev_assign_seat() and all seats from that context will have * the same physical name. * * The physical name of the seat is one that is usually set by the system or * lower levels of the stack. In most cases, this is the base filter for * devices - devices assigned to seats outside the current seat will not * be available to the caller. * * @param seat A previously obtained seat * @return The physical name of this seat */ const char * libinput_seat_get_physical_name(struct libinput_seat *seat); /** * @ingroup seat * * Return the logical name of the seat. This is an identifier to group sets * of devices within the compositor. * * @param seat A previously obtained seat * @return The logical name of this seat */ const char * libinput_seat_get_logical_name(struct libinput_seat *seat); /** * @defgroup device Initialization and manipulation of input devices */ /** * @ingroup device * * Increase the refcount of the input device. An input device will be freed * whenever the refcount reaches 0. This may happen during * libinput_dispatch() if the device was removed from the system. A caller * must ensure to reference the device correctly to avoid dangling pointers. * * @param device A previously obtained device * @return The passed device */ struct libinput_device * libinput_device_ref(struct libinput_device *device); /** * @ingroup device * * Decrease the refcount of the input device. An input device will be freed * whenever the refcount reaches 0. This may happen during libinput_dispatch * if the device was removed from the system. A caller must ensure to * reference the device correctly to avoid dangling pointers. * * @param device A previously obtained device * @return NULL if the device was destroyed, otherwise the passed device */ struct libinput_device * libinput_device_unref(struct libinput_device *device); /** * @ingroup device * * Set caller-specific data associated with this input device. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param device A previously obtained device * @param user_data Caller-specific data pointer * @see libinput_device_get_user_data */ void libinput_device_set_user_data(struct libinput_device *device, void *user_data); /** * @ingroup device * * Get the caller-specific data associated with this input device, if any. * * @param device A previously obtained device * @return Caller-specific data pointer or NULL if none was set * @see libinput_device_set_user_data */ void * libinput_device_get_user_data(struct libinput_device *device); /** * @ingroup device * * Get the libinput context from the device. * * @param device A previously obtained device * @return The libinput context for this device. */ struct libinput * libinput_device_get_context(struct libinput_device *device); /** * @ingroup device * * Get the device group this device is assigned to. Some physical * devices like graphics tablets are represented by multiple kernel * devices and thus by multiple struct @ref libinput_device. * * libinput assigns these devices to the same @ref libinput_device_group * allowing the caller to identify such devices and adjust configuration * settings accordingly. For example, setting a tablet to left-handed often * means turning it upside down. A touch device on the same tablet would * need to be turned upside down too to work correctly. * * All devices are part of a device group though for most devices the group * will be a singleton. A device is assigned to a device group on @ref * LIBINPUT_EVENT_DEVICE_ADDED and removed from that group on @ref * LIBINPUT_EVENT_DEVICE_REMOVED. It is up to the caller to track how many * devices are in each device group. * * @dot * digraph groups_libinput { * rankdir="TB"; * node [ * shape="box"; * ] * * mouse [ label="mouse"; URL="\ref libinput_device"]; * kbd [ label="keyboard"; URL="\ref libinput_device"]; * * pen [ label="tablet pen"; URL="\ref libinput_device"]; * touch [ label="tablet touch"; URL="\ref libinput_device"]; * pad [ label="tablet pad"; URL="\ref libinput_device"]; * * group1 [ label="group 1"; URL="\ref libinput_device_group"]; * group2 [ label="group 2"; URL="\ref libinput_device_group"]; * group3 [ label="group 3"; URL="\ref libinput_device_group"]; * * mouse -> group1 * kbd -> group2 * * pen -> group3; * touch -> group3; * pad -> group3; * } * @enddot * * Device groups do not get re-used once the last device in the group was * removed, i.e. unplugging and re-plugging a physical device with grouped * devices will return a different device group after every unplug. * * The returned device group is not refcounted and may become invalid after * the next call to libinput. Use libinput_device_group_ref() and * libinput_device_group_unref() to continue using the handle outside of the * immediate scope. * * Device groups are assigned based on the LIBINPUT_DEVICE_GROUP udev * property, see the libinput documentation for more details. * * @return The device group this device belongs to */ struct libinput_device_group * libinput_device_get_device_group(struct libinput_device *device); /** * @ingroup device * * Get the system name of the device. * * To get the descriptive device name, use libinput_device_get_name(). * * @param device A previously obtained device * @return System name of the device * */ const char * libinput_device_get_sysname(struct libinput_device *device); /** * @ingroup device * * The descriptive device name as advertised by the kernel and/or the * hardware itself. To get the sysname for this device, use * libinput_device_get_sysname(). * * The lifetime of the returned string is tied to the struct * libinput_device. The string may be the empty string but is never NULL. * * @param device A previously obtained device * @return The device name */ const char * libinput_device_get_name(struct libinput_device *device); /** * @ingroup device * * Get the bus type ID for this device. * * @param device A previously obtained device * @return The bus type ID of this device (see BUS_* in linux/input.h) * * @since 1.26 */ unsigned int libinput_device_get_id_bustype(struct libinput_device *device); /** * @ingroup device * * Get the product ID for this device. * * @param device A previously obtained device * @return The product ID of this device */ unsigned int libinput_device_get_id_product(struct libinput_device *device); /** * @ingroup device * * Get the vendor ID for this device. * * @param device A previously obtained device * @return The vendor ID of this device */ unsigned int libinput_device_get_id_vendor(struct libinput_device *device); /** * @ingroup device * * A device may be mapped to a single output, or all available outputs. If a * device is mapped to a single output only, a relative device may not move * beyond the boundaries of this output. An absolute device has its input * coordinates mapped to the extents of this output. * * @note Use of this function is discouraged. Its return value is not * precisely defined and may not be understood by the caller or may be * insufficient to map the device. Instead, the system configuration could * set a udev property the caller understands and interprets correctly. The * caller could then obtain device with libinput_device_get_udev_device() * and query it for this property. For more complex cases, the caller * must implement monitor-to-device association heuristics. * * @return The name of the output this device is mapped to, or NULL if no * output is set */ const char * libinput_device_get_output_name(struct libinput_device *device); /** * @ingroup device * * Get the seat associated with this input device. * * A seat can be uniquely identified by the physical and logical seat name. * There will ever be only one seat instance with a given physical and logical * seat name pair at any given time, but if no external reference is kept, it * may be destroyed if no device belonging to it is left. * * The returned seat is not refcounted and may become invalid after * the next call to libinput. Use libinput_seat_ref() and * libinput_seat_unref() to continue using the handle outside of the * immediate scope. * * See the libinput documentation for more information on seats. * * @param device A previously obtained device * @return The seat this input device belongs to */ struct libinput_seat * libinput_device_get_seat(struct libinput_device *device); /** * @ingroup device * * Change the logical seat associated with this device by removing the * device and adding it to the new seat. * * This command is identical to physically unplugging the device, then * re-plugging it as a member of the new seat. libinput will generate a * @ref LIBINPUT_EVENT_DEVICE_REMOVED event and this @ref libinput_device is * considered removed from the context; it will not generate further events * and will be freed when the refcount reaches zero. * A @ref LIBINPUT_EVENT_DEVICE_ADDED event is generated with a new @ref * libinput_device handle. It is the caller's responsibility to update * references to the new device accordingly. * * If the logical seat name already exists in the device's physical seat, * the device is added to this seat. Otherwise, a new seat is created. * * @note This change applies to this device until removal or @ref * libinput_suspend(), whichever happens earlier. * * @param device A previously obtained device * @param name The new logical seat name * @return 0 on success, non-zero on error */ int libinput_device_set_seat_logical_name(struct libinput_device *device, const char *name); /** * @ingroup device * * Return a udev handle to the device that is this libinput device, if any. * The returned handle has a refcount of at least 1, the caller must call * udev_device_unref() once to release the associated resources. * See the [libudev documentation] * (http://www.freedesktop.org/software/systemd/libudev/) for details. * * Some devices may not have a udev device, or the udev device may be * unobtainable. This function returns NULL if no udev device was available. * * Calling this function multiple times for the same device may not * return the same udev handle each time. * * @param device A previously obtained device * @return A udev handle to the device with a refcount of >= 1 or NULL. * @retval NULL This device is not represented by a udev device */ struct udev_device * libinput_device_get_udev_device(struct libinput_device *device); /** * @ingroup device * * Update the LEDs on the device, if any. If the device does not have * LEDs, or does not have one or more of the LEDs given in the mask, this * function does nothing. * * @param device A previously obtained device * @param leds A mask of the LEDs to set, or unset. */ void libinput_device_led_update(struct libinput_device *device, enum libinput_led leds); /** * @ingroup device * * Check if the given device has the specified capability * * @return Non-zero if the given device has the capability or zero otherwise */ int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability); /** * @ingroup device * * Get the physical size of a device in mm, where meaningful. This function * only succeeds on devices with the required data, i.e. tablets, touchpads * and touchscreens. * * If this function returns nonzero, width and height are unmodified. * * @param device The device * @param width Set to the width of the device * @param height Set to the height of the device * @return 0 on success, or nonzero otherwise */ int libinput_device_get_size(struct libinput_device *device, double *width, double *height); /** * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_POINTER device has a button with the * given code (see linux/input-event-codes.h). * * @param device A current input device * @param code Button code to check for, e.g. BTN_LEFT * * @return 1 if the device supports this button code, 0 if it does not, -1 * on error. */ int libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code); /** * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_KEYBOARD device has a key with the * given code (see linux/input-event-codes.h). * * @param device A current input device * @param code Key code to check for, e.g. KEY_ESC * * @return 1 if the device supports this key code, 0 if it does not, -1 * on error. */ int libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code); /** * @ingroup device * * Check how many touches a @ref LIBINPUT_DEVICE_CAP_TOUCH device supports * simultaneously. * * @param device A current input device * * @return The number of simultaneous touches or 0 if unknown, -1 * on error. * * @since 1.11 */ int libinput_device_touch_get_touch_count(struct libinput_device *device); /** * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_SWITCH device has a switch of the * given type. * * @param device A current input device * @param sw Switch to check for * * @return 1 if the device supports this switch, 0 if it does not, -1 * on error. * * @since 1.9 */ int libinput_device_switch_has_switch(struct libinput_device *device, enum libinput_switch sw); /** * @ingroup device * * Return the number of buttons on a device with the * @ref LIBINPUT_DEVICE_CAP_TABLET_PAD capability. * Buttons on a pad device are numbered sequentially, see the * libinput documentation for details. * * @param device A current input device * * @return The number of buttons supported by the device. -1 on error. * * @since 1.3 */ int libinput_device_tablet_pad_get_num_buttons(struct libinput_device *device); /** * @ingroup device * * Return the number of dials a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability provides. * * @param device A current input device * * @return The number of dials or 0 if the device has no dials. -1 on error. * * @see libinput_event_tablet_pad_get_dial_number * * @since 1.26 */ int libinput_device_tablet_pad_get_num_dials(struct libinput_device *device); /** * @ingroup device * * Return the number of rings a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability provides. * * @param device A current input device * * @return The number of rings or 0 if the device has no rings. -1 on error. * * @see libinput_event_tablet_pad_get_ring_number * * @since 1.3 */ int libinput_device_tablet_pad_get_num_rings(struct libinput_device *device); /** * @ingroup device * * Return the number of strips a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_PAD capability provides. * * @param device A current input device * * @return The number of strips or 0 if the device has no strips. -1 on error. * * @see libinput_event_tablet_pad_get_strip_number * * @since 1.3 */ int libinput_device_tablet_pad_get_num_strips(struct libinput_device *device); /** * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_TABLET_PAD device has a key with the * given code (see linux/input-event-codes.h). * * @param device A current input device * @param code Key code to check for, e.g. KEY_ESC * * @return 1 if the device supports this key code, 0 if it does not, -1 * on error. * * @since 1.15 */ int libinput_device_tablet_pad_has_key(struct libinput_device *device, uint32_t code); /** * @ingroup device * * Increase the refcount of the device group. A device group will be freed * whenever the refcount reaches 0. This may happen during * libinput_dispatch() if all devices of this group were removed from the * system. A caller must ensure to reference the device group correctly to * avoid dangling pointers. * * @param group A previously obtained device group * @return The passed device group */ struct libinput_device_group * libinput_device_group_ref(struct libinput_device_group *group); /** * @ingroup device * * Decrease the refcount of the device group. A device group will be freed * whenever the refcount reaches 0. This may happen during * libinput_dispatch() if all devices of this group were removed from the * system. A caller must ensure to reference the device group correctly to * avoid dangling pointers. * * @param group A previously obtained device group * @return NULL if the device group was destroyed, otherwise the passed * device group */ struct libinput_device_group * libinput_device_group_unref(struct libinput_device_group *group); /** * @ingroup device * * Set caller-specific data associated with this device group. libinput does * not manage, look at, or modify this data. The caller must ensure the * data is valid. * * @param group A previously obtained device group * @param user_data Caller-specific data pointer * @see libinput_device_group_get_user_data */ void libinput_device_group_set_user_data(struct libinput_device_group *group, void *user_data); /** * @ingroup device * * Get the caller-specific data associated with this input device group, if * any. * * @param group A previously obtained group * @return Caller-specific data pointer or NULL if none was set * @see libinput_device_group_set_user_data */ void * libinput_device_group_get_user_data(struct libinput_device_group *group); /** * @defgroup config Device configuration * * Enable, disable, change and/or check for device-specific features. For * all features, libinput assigns a default based on the hardware * configuration. This default can be obtained with the respective * get_default call. * * Configuration options are device dependent and not all options are * supported on all devices. For all configuration options, libinput * provides a call to check if a configuration option is available on a * device (e.g. libinput_device_config_calibration_has_matrix()) * * Some configuration option may be dependent on or mutually exclusive with * with other options. The behavior in those cases is * implementation-dependent, the caller must ensure that the options are set * in the right order. * * Below is a general grouping of configuration options according to device * type. Note that this is a guide only and not indicative of any specific * device. * - Touchpad: * - libinput_device_config_tap_set_enabled() * - libinput_device_config_tap_set_drag_enabled() * - libinput_device_config_tap_set_drag_lock_enabled() * - libinput_device_config_click_set_method() * - libinput_device_config_click_set_clickfinger_button_map() * - libinput_device_config_scroll_set_method() * - libinput_device_config_dwt_set_enabled() * - Touchscreens: * - libinput_device_config_calibration_set_matrix() * - Tablets: * - libinput_device_config_calibration_set_matrix() * - libinput_tablet_tool_config_pressure_range_set() * - libinput_device_config_left_handed_set() * - Pointer devices (mice, trackballs, touchpads): * - libinput_device_config_accel_set_speed() * - libinput_device_config_accel_set_profile() * - libinput_device_config_scroll_set_natural_scroll_enabled() * - libinput_device_config_left_handed_set() * - libinput_device_config_middle_emulation_set_enabled() * - libinput_device_config_rotation_set_angle() * - All devices: * - libinput_device_config_send_events_set_mode() */ /** * @ingroup config * * Status codes returned when applying configuration settings. */ enum libinput_config_status { LIBINPUT_CONFIG_STATUS_SUCCESS = 0, /**< Config applied successfully */ LIBINPUT_CONFIG_STATUS_UNSUPPORTED, /**< Configuration not available on this device */ LIBINPUT_CONFIG_STATUS_INVALID, /**< Invalid parameter range */ }; /** * @ingroup config * * Return a string describing the error. * * @param status The status to translate to a string * @return A human-readable string representing the error or NULL for an * invalid status. */ const char * libinput_config_status_to_str(enum libinput_config_status status); /** * @ingroup config */ enum libinput_config_tap_state { LIBINPUT_CONFIG_TAP_DISABLED, /**< Tapping is to be disabled, or is currently disabled */ LIBINPUT_CONFIG_TAP_ENABLED, /**< Tapping is to be enabled, or is currently enabled */ }; /** * @ingroup config * * Check if the device supports tap-to-click and how many fingers can be * used for tapping. See * libinput_device_config_tap_set_enabled() for more information. * * @param device The device to configure * @return The number of fingers that can generate a tap event, or 0 if the * device does not support tapping. * * @see libinput_device_config_tap_set_enabled * @see libinput_device_config_tap_get_enabled * @see libinput_device_config_tap_get_default_enabled */ int libinput_device_config_tap_get_finger_count(struct libinput_device *device); /** * @ingroup config * * Enable or disable tap-to-click on this device, with a default mapping of * 1, 2, 3 finger tap mapping to left, right, middle click, respectively. * Tapping is limited by the number of simultaneous touches * supported by the device, see * libinput_device_config_tap_get_finger_count(). * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_TAP_ENABLED to enable tapping or @ref * LIBINPUT_CONFIG_TAP_DISABLED to disable tapping * * @return A config status code. Disabling tapping on a device that does not * support tapping always succeeds. * * @see libinput_device_config_tap_get_finger_count * @see libinput_device_config_tap_get_enabled * @see libinput_device_config_tap_get_default_enabled */ enum libinput_config_status libinput_device_config_tap_set_enabled(struct libinput_device *device, enum libinput_config_tap_state enable); /** * @ingroup config * * Check if tap-to-click is enabled on this device. If the device does not * support tapping, this function always returns @ref * LIBINPUT_CONFIG_TAP_DISABLED. * * @param device The device to configure * * @retval LIBINPUT_CONFIG_TAP_ENABLED If tapping is currently enabled * @retval LIBINPUT_CONFIG_TAP_DISABLED If tapping is currently disabled * * @see libinput_device_config_tap_get_finger_count * @see libinput_device_config_tap_set_enabled * @see libinput_device_config_tap_get_default_enabled */ enum libinput_config_tap_state libinput_device_config_tap_get_enabled(struct libinput_device *device); /** * @ingroup config * * Return the default setting for whether tap-to-click is enabled on this * device. * * @param device The device to configure * @retval LIBINPUT_CONFIG_TAP_ENABLED If tapping is enabled by default * @retval LIBINPUT_CONFIG_TAP_DISABLED If tapping Is disabled by default * * @see libinput_device_config_tap_get_finger_count * @see libinput_device_config_tap_set_enabled * @see libinput_device_config_tap_get_enabled */ enum libinput_config_tap_state libinput_device_config_tap_get_default_enabled(struct libinput_device *device); /** * @ingroup config * * @since 1.5 */ enum libinput_config_tap_button_map { /** 1/2/3 finger tap maps to left/right/middle */ LIBINPUT_CONFIG_TAP_MAP_LRM, /** 1/2/3 finger tap maps to left/middle/right*/ LIBINPUT_CONFIG_TAP_MAP_LMR, }; /** * @ingroup config */ enum libinput_config_clickfinger_button_map { /** 1/2/3 finger click maps to left/right/middle */ LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM, /** 1/2/3 finger click maps to left/middle/right*/ LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR, }; /** * @ingroup config * * Set the finger number to button number mapping for tap-to-click. The * default mapping on most devices is to have a 1, 2 and 3 finger tap to map * to the left, right and middle button, respectively. * A device may permit changing the button mapping but disallow specific * maps. In this case @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED is returned, * the caller is expected to handle this case correctly. * * Changing the button mapping may not take effect immediately, * the device may wait until it is in a neutral state before applying any * changes. * * The mapping may be changed when tap-to-click is disabled. The new mapping * takes effect when tap-to-click is enabled in the future. * * @note It is an application bug to call this function for devices where * libinput_device_config_tap_get_finger_count() returns 0. * * @param device The device to configure * @param map The new finger-to-button number mapping * @return A config status code. Changing the order on a device that does not * support tapping always fails with @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED. * * @see libinput_device_config_tap_get_button_map * @see libinput_device_config_tap_get_default_button_map * * @since 1.5 */ enum libinput_config_status libinput_device_config_tap_set_button_map(struct libinput_device *device, enum libinput_config_tap_button_map map); /** * @ingroup config * * Get the finger number to button number mapping for tap-to-click. * * The return value for a device that does not support tapping is always * @ref LIBINPUT_CONFIG_TAP_MAP_LRM. * * @note It is an application bug to call this function for devices where * libinput_device_config_tap_get_finger_count() returns 0. * * @param device The device to configure * @return The current finger-to-button number mapping * * @see libinput_device_config_tap_set_button_map * @see libinput_device_config_tap_get_default_button_map * * @since 1.5 */ enum libinput_config_tap_button_map libinput_device_config_tap_get_button_map(struct libinput_device *device); /** * @ingroup config * * Get the default finger number to button number mapping for tap-to-click. * * The return value for a device that does not support tapping is always * @ref LIBINPUT_CONFIG_TAP_MAP_LRM. * * @note It is an application bug to call this function for devices where * libinput_device_config_tap_get_finger_count() returns 0. * * @param device The device to configure * @return The current finger-to-button number mapping * * @see libinput_device_config_tap_set_button_map * @see libinput_device_config_tap_get_default_button_map * * @since 1.5 */ enum libinput_config_tap_button_map libinput_device_config_tap_get_default_button_map(struct libinput_device *device); /** * @ingroup config * * A config status to distinguish or set dragging on a device. Currently * implemented for tap-and-drag only, see * libinput_device_config_tap_set_drag_enabled() * * @since 1.2 */ enum libinput_config_drag_state { /** * Drag is to be disabled, or is * currently disabled. */ LIBINPUT_CONFIG_DRAG_DISABLED, /** * Drag is to be enabled, or is * currently enabled */ LIBINPUT_CONFIG_DRAG_ENABLED, }; /** * @ingroup config * * Enable or disable tap-and-drag on this device. When enabled, a * tap immediately followed by a finger down results in a button down event, * subsequent finger motion thus triggers a drag. The button is released * on finger up. See the libinput documentation for more details. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_DRAG_ENABLED to enable, @ref * LIBINPUT_CONFIG_DRAG_DISABLED to disable tap-and-drag * * @see libinput_device_config_tap_get_drag_enabled * @see libinput_device_config_tap_get_default_drag_enabled * * @since 1.2 */ enum libinput_config_status libinput_device_config_tap_set_drag_enabled(struct libinput_device *device, enum libinput_config_drag_state enable); /** * @ingroup config * * Return whether tap-and-drag is enabled or disabled on this device. * * @param device The device to check * @retval LIBINPUT_CONFIG_DRAG_ENABLED if tap-and-drag is enabled * @retval LIBINPUT_CONFIG_DRAG_DISABLED if tap-and-drag is * disabled * * @see libinput_device_config_tap_set_drag_enabled * @see libinput_device_config_tap_get_default_default_enabled * * @since 1.2 */ enum libinput_config_drag_state libinput_device_config_tap_get_drag_enabled(struct libinput_device *device); /** * @ingroup config * * Return whether tap-and-drag is enabled or disabled by default on this * device. * * @param device The device to check * @retval LIBINPUT_CONFIG_DRAG_ENABLED if tap-and-drag is enabled by * default * @retval LIBINPUT_CONFIG_DRAG_DISABLED if tap-and-drag is * disabled by default * * @see libinput_device_config_tap_set_drag_enabled * @see libinput_device_config_tap_get_drag_enabled * * @since 1.2 */ enum libinput_config_drag_state libinput_device_config_tap_get_default_drag_enabled(struct libinput_device *device); /** * @ingroup config */ enum libinput_config_drag_lock_state { /** Drag lock is to be disabled, or is currently disabled */ LIBINPUT_CONFIG_DRAG_LOCK_DISABLED, /** Drag lock is to be enabled in timeout mode, * or is currently enabled in timeout mode */ LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT, /** legacy spelling for LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT */ LIBINPUT_CONFIG_DRAG_LOCK_ENABLED = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT, /** Drag lock is to be enabled in sticky mode, * or is currently enabled in sticky mode */ LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY, }; /** * @ingroup config * * Enable or disable drag-lock during tapping on this device. When enabled, * a finger may be lifted and put back on the touchpad and the drag process * continues. A timeout for lifting the finger is optional. When disabled, * lifting the finger during a tap-and-drag will immediately stop the drag. * See the libinput documentation for more details. * * Enabling drag lock on a device that has tapping or tap-and-drag disabled is * permitted, but has no effect until tapping and tap-and-drag are enabled. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY to enable drag * lock in sticky mode, * @ref LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT to enable drag lock in timeout * mode, * or @ref LIBINPUT_CONFIG_DRAG_LOCK_DISABLED to disable drag lock * * @return A config status code. Disabling drag lock on a device that does not * support tapping always succeeds. * * @see libinput_device_config_tap_get_drag_lock_enabled * @see libinput_device_config_tap_get_default_drag_lock_enabled */ enum libinput_config_status libinput_device_config_tap_set_drag_lock_enabled(struct libinput_device *device, enum libinput_config_drag_lock_state enable); /** * @ingroup config * * Check if drag-lock during tapping is enabled on this device. If the * device does not support tapping, this function always returns * @ref LIBINPUT_CONFIG_DRAG_LOCK_DISABLED. * * Drag lock may be enabled even when tapping or tap-and-drag is disabled. * * @param device The device to configure * * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY If drag lock is currently * enabled in sticky mode * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT If drag lock is currently * enabled in timeout mode * @retval LIBINPUT_CONFIG_DRAG_LOCK_DISABLED If drag lock is currently disabled * * @see libinput_device_config_tap_set_drag_lock_enabled * @see libinput_device_config_tap_get_default_drag_lock_enabled */ enum libinput_config_drag_lock_state libinput_device_config_tap_get_drag_lock_enabled(struct libinput_device *device); /** * @ingroup config * * Check if drag-lock during tapping is enabled by default on this device. * If the device does not support tapping, this function always returns * @ref LIBINPUT_CONFIG_DRAG_LOCK_DISABLED. * * Drag lock may be enabled by default even when tapping or tap-and-drag is * disabled by default. * * @param device The device to configure * * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY If drag lock is enabled in * sticky mode by default * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT If drag lock is enabled in * timeout mode by default * @retval LIBINPUT_CONFIG_DRAG_LOCK_DISABLED If drag lock is disabled by * default * * @see libinput_device_config_tap_set_drag_lock_enabled * @see libinput_device_config_tap_get_drag_lock_enabled */ enum libinput_config_drag_lock_state libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device *device); /** * @ingroup config * * A config status to distinguish or set 3-finger dragging on a device. * * @since 1.27 */ enum libinput_config_3fg_drag_state { /** * Drag is to be disabled, or is * currently disabled. */ LIBINPUT_CONFIG_3FG_DRAG_DISABLED, /** * Drag is to be enabled for 3 fingers, or is * currently enabled */ LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG, /** * Drag is to be enabled for 4 fingers, or is * currently enabled */ LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG, }; /** * @ingroup config * * Returns the maximum number of fingers available for 3-finger dragging. * * @param device The device to check * * @see libinput_device_config_3fg_drag_set_enabled * @see libinput_device_config_3fg_drag_get_enabled * @see libinput_device_config_3fg_drag_get_default_enabled * * @since 1.27 */ int libinput_device_config_3fg_drag_get_finger_count(struct libinput_device *device); /** * @ingroup config * * Enable or disable 3-finger drag on this device. When enabled, three fingers * down will result in a button down event, subsequent finger motion triggers * a drag. The button is released shortly after all fingers are logically up. * See the libinput documentation for more details. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_DRAG_ENABLED to enable, @ref * LIBINPUT_CONFIG_DRAG_DISABLED to disable 3-finger drag * * @see libinput_device_config_3fg_drag_is_available * @see libinput_device_config_3fg_drag_get_enabled * @see libinput_device_config_3fg_drag_get_default_enabled * * @since 1.27 */ enum libinput_config_status libinput_device_config_3fg_drag_set_enabled(struct libinput_device *device, enum libinput_config_3fg_drag_state enable); /** * @ingroup config * * Return whether 3-finger drag is enabled or disabled on this device. * * @param device The device to check * @retval LIBINPUT_CONFIG_DRAG_ENABLED if 3-finger drag is enabled * @retval LIBINPUT_CONFIG_DRAG_DISABLED if 3-finger drag is * disabled * * @see libinput_device_config_3fg_drag_is_available * @see libinput_device_config_3fg_drag_set_enabled * @see libinput_device_config_3fg_drag_get_default_enabled * * @since 1.27 */ enum libinput_config_3fg_drag_state libinput_device_config_3fg_drag_get_enabled(struct libinput_device *device); /** * @ingroup config * * Return whether 3-finger drag is enabled or disabled by default on this device. * * @param device The device to check * @retval LIBINPUT_CONFIG_DRAG_ENABLED if 3-finger drag is enabled * @retval LIBINPUT_CONFIG_DRAG_DISABLED if 3-finger drag is * disabled * * @see libinput_device_config_3fg_drag_is_available * @see libinput_device_config_3fg_drag_set_enabled * @see libinput_device_config_3fg_drag_get_enabled * * @since 1.27 */ enum libinput_config_3fg_drag_state libinput_device_config_3fg_drag_get_default_enabled(struct libinput_device *device); /** * @ingroup config * * Check if the device can be calibrated via a calibration matrix. * * @param device The device to check * @return Non-zero if the device can be calibrated, zero otherwise. * * @see libinput_device_config_calibration_set_matrix * @see libinput_device_config_calibration_get_matrix * @see libinput_device_config_calibration_get_default_matrix */ int libinput_device_config_calibration_has_matrix(struct libinput_device *device); /** * @ingroup config * * Apply the 3x3 transformation matrix to absolute device coordinates. This * matrix has no effect on relative events. * * Given a 6-element array [a, b, c, d, e, f], the matrix is applied as * @code * [ a b c ] [ x ] * [ d e f ] * [ y ] * [ 0 0 1 ] [ 1 ] * @endcode * * The translation component (c, f) is expected to be normalized to the * device coordinate range. For example, the matrix * @code * [ 1 0 1 ] * [ 0 1 -1 ] * [ 0 0 1 ] * @endcode * moves all coordinates by 1 device-width to the right and 1 device-height * up. * * The rotation matrix for rotation around the origin is defined as * @code * [ cos(a) -sin(a) 0 ] * [ sin(a) cos(a) 0 ] * [ 0 0 1 ] * @endcode * Note that any rotation requires an additional translation component to * translate the rotated coordinates back into the original device space. * The rotation matrixes for 90, 180 and 270 degrees clockwise are: * @code * 90 deg cw: 180 deg cw: 270 deg cw: * [ 0 -1 1] [ -1 0 1] [ 0 1 0 ] * [ 1 0 0] [ 0 -1 1] [ -1 0 1 ] * [ 0 0 1] [ 0 0 1] [ 0 0 1 ] * @endcode * * @param device The device to configure * @param matrix An array representing the first two rows of a 3x3 matrix as * described above. * * @return A config status code. * * @see libinput_device_config_calibration_has_matrix * @see libinput_device_config_calibration_get_matrix * @see libinput_device_config_calibration_get_default_matrix */ enum libinput_config_status libinput_device_config_calibration_set_matrix(struct libinput_device *device, const float matrix[6]); /** * @ingroup config * * Return the current calibration matrix for this device. * * @param device The device to configure * @param matrix Set to the array representing the first two rows of a 3x3 matrix as * described in libinput_device_config_calibration_set_matrix(). * * @return 0 if no calibration is set and the returned matrix is the * identity matrix, 1 otherwise * * @see libinput_device_config_calibration_has_matrix * @see libinput_device_config_calibration_set_matrix * @see libinput_device_config_calibration_get_default_matrix */ int libinput_device_config_calibration_get_matrix(struct libinput_device *device, float matrix[6]); /** * @ingroup config * * Return the default calibration matrix for this device. On most devices, * this is the identity matrix. If the udev property * LIBINPUT_CALIBRATION_MATRIX is set on the respective udev device, * that property's value becomes the default matrix, see the libinput * documentation for more details. * * @param device The device to configure * @param matrix Set to the array representing the first two rows of a 3x3 matrix as * described in libinput_device_config_calibration_set_matrix(). * * @return 0 if no calibration is set and the returned matrix is the * identity matrix, 1 otherwise * * @see libinput_device_config_calibration_has_matrix * @see libinput_device_config_calibration_set_matrix * @see libinput_device_config_calibration_get_matrix */ int libinput_device_config_calibration_get_default_matrix(struct libinput_device *device, float matrix[6]); /** * @ingroup config * * Describes a rectangle to configure a device's area, see * libinput_device_config_area_set_rectangle(). * * This struct describes a rectangle via the upper left points (x1, y1) * and the lower right point (x2, y2). * * All arguments are normalized to the range [0.0, 1.0] to represent the * corresponding proportion of the device's width and height, respectively. * A rectangle covering the whole device thus comprises of the points * (0.0, 0.0) and (1.0, 1.0). * * The conditions x1 < x2 and y1 < y2 must be true. */ struct libinput_config_area_rectangle { double x1; double y1; double x2; double y2; }; /** * @ingroup config * * Check if the device can change its logical input area via a rectangle. * * @param device The device to check * @return Non-zero if the device can be calibrated, zero otherwise. * * @see libinput_device_config_area_set_rectangle * @see libinput_device_config_area_get_rectangle * @see libinput_device_config_area_get_default_rectangle */ int libinput_device_config_area_has_rectangle(struct libinput_device *device); /** * @ingroup config * * Set the given rectangle as the logical input area of this device. * Future interactions by a tablet tool on this devices are scaled * to only consider events within this logical input area - as if the * logical input area were the available physical area. * * The coordinates of the rectangle represent the proportion of the * available maximum physical area, normalized to the range [0.0, 1.0]. * For example, a rectangle with the two points 0.25, 0.5, 0.75, 1.0 * adds a 25% dead zone to the left and right and a 50% dead zone on * the top: * * @code * +----------------------------------+ * | | * | 50% | * | | * | +-----------------+ | * | | | | * | 25% | | 25% | * | | | | * +--------+-----------------+-------+ * @endcode * * The area applies in the tablet's current logical rotation, i.e. the above * example is always at the bottom of the tablet. * * Once applied, the logical area's top-left coordinate (in the current logical * rotation) becomes the new offset (0/0) and the return values of * libinput_event_tablet_tool_get_x() and libinput_event_tablet_tool_get_y() * are in relation to this new offset. * * Likewise, libinput_event_tablet_tool_get_x_transformed() and * libinput_event_tablet_tool_get_y_transformed() represent the value scaled * into the configured logical area. * * The return value of libinput_device_get_size() is not affected by the * configured area. * * Changing the area may not take effect immediately, the device may wait until * it is in a neutral state before applying any changes. * * @param device The device to check * @param rect The intended rectangle * @return A config status code. Setting the area on a device that does not * support area rectangles always fails with @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED. * * @see libinput_device_config_area_has_rectangle * @see libinput_device_config_area_get_rectangle * @see libinput_device_config_area_get_default_rectangle */ enum libinput_config_status libinput_device_config_area_set_rectangle(struct libinput_device *device, const struct libinput_config_area_rectangle *rect); /** * @ingroup config * * Return the current area rectangle for this device. * * The return value for a device that does not support area rectangles is a * rectangle with the points 0/0 and 1/1. * * @note It is an application bug to call this function for devices where * libinput_device_config_area_has_rectangle() returns 0. * * @param device The device to check * @return The current area rectangle * * @see libinput_device_config_area_has_rectangle * @see libinput_device_config_area_set_rectangle * @see libinput_device_config_area_get_default_rectangle */ struct libinput_config_area_rectangle libinput_device_config_area_get_rectangle(struct libinput_device *device); /** * @ingroup config * * Return the default area rectangle for this device. * * The return value for a device that does not support area rectangles is a * rectangle with the points 0/0 and 1/1. * * @note It is an application bug to call this function for devices where * libinput_device_config_area_has_rectangle() returns 0. * * @param device The device to check * @return The default area rectangle * * @see libinput_device_config_area_has_rectangle * @see libinput_device_config_area_set_rectangle * @see libinput_device_config_area_get_rectangle */ struct libinput_config_area_rectangle libinput_device_config_area_get_default_rectangle(struct libinput_device *device); /** * @ingroup config * * The send-event mode of a device defines when a device may generate events * and pass those events to the caller. */ enum libinput_config_send_events_mode { /** * Send events from this device normally. This is a placeholder * mode only, any device detected by libinput can be enabled. Do not * test for this value as bitmask. */ LIBINPUT_CONFIG_SEND_EVENTS_ENABLED = 0, /** * Do not send events through this device. Depending on the device, * this may close all file descriptors on the device or it may leave * the file descriptors open and route events through a different * device. * * If this bit field is set, other disable modes may be * ignored. For example, if both @ref * LIBINPUT_CONFIG_SEND_EVENTS_DISABLED and @ref * LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE are set, * the device remains disabled when all external pointer devices are * unplugged. */ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED = (1 << 0), /** * If an external pointer device is plugged in, do not send events * from this device. This option may be available on built-in * touchpads. */ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE = (1 << 1), }; /** * @ingroup config * * Return the possible send-event modes for this device. These modes define * when a device may process and send events. * * @param device The device to configure * * @return A bitmask of possible modes. * * @see libinput_device_config_send_events_set_mode * @see libinput_device_config_send_events_get_mode * @see libinput_device_config_send_events_get_default_mode */ uint32_t libinput_device_config_send_events_get_modes(struct libinput_device *device); /** * @ingroup config * * Set the send-event mode for this device. The mode defines when the device * processes and sends events to the caller. * * The selected mode may not take effect immediately. Events already * received and processed from this device are unaffected and will be passed * to the caller on the next call to libinput_get_event(). * * If the mode is a bitmask of @ref libinput_config_send_events_mode, * the device may wait for or generate events until it is in a neutral * state. For example, this may include waiting for or generating button * release events. * * If the device is already suspended, this function does nothing and * returns success. Changing the send-event mode on a device that has been * removed is permitted. * * @param device The device to configure * @param mode A bitmask of send-events modes * * @return A config status code. * * @see libinput_device_config_send_events_get_modes * @see libinput_device_config_send_events_get_mode * @see libinput_device_config_send_events_get_default_mode */ enum libinput_config_status libinput_device_config_send_events_set_mode(struct libinput_device *device, uint32_t mode); /** * @ingroup config * * Get the send-event mode for this device. The mode defines when the device * processes and sends events to the caller. * * If a caller enables the bits for multiple modes, some of which are * subsets of another mode libinput may drop the bits that are subsets. In * other words, don't expect libinput_device_config_send_events_get_mode() * to always return exactly the same bitmask as passed into * libinput_device_config_send_events_set_mode(). * * @param device The device to configure * @return The current bitmask of the send-event mode for this device. * * @see libinput_device_config_send_events_get_modes * @see libinput_device_config_send_events_set_mode * @see libinput_device_config_send_events_get_default_mode */ uint32_t libinput_device_config_send_events_get_mode(struct libinput_device *device); /** * @ingroup config * * Get the default send-event mode for this device. The mode defines when * the device processes and sends events to the caller. * * @param device The device to configure * @return The bitmask of the send-event mode for this device. * * @see libinput_device_config_send_events_get_modes * @see libinput_device_config_send_events_set_mode * @see libinput_device_config_send_events_get_mode */ uint32_t libinput_device_config_send_events_get_default_mode(struct libinput_device *device); /** * @ingroup config * * Check if a device uses libinput-internal pointer-acceleration. * * @param device The device to configure * * @return 0 if the device is not accelerated, nonzero if it is accelerated * * @see libinput_device_config_accel_set_speed * @see libinput_device_config_accel_get_speed * @see libinput_device_config_accel_get_default_speed */ int libinput_device_config_accel_is_available(struct libinput_device *device); /** * @ingroup config * * Set the pointer acceleration speed of this pointer device within a range * of [-1, 1], where 0 is the default acceleration for this device, -1 is * the slowest acceleration and 1 is the maximum acceleration available on * this device. The actual pointer acceleration mechanism is * implementation-dependent, as is the number of steps available within the * range. libinput picks the semantically closest acceleration step if the * requested value does not match a discrete setting. * * @param device The device to configure * @param speed The normalized speed, in a range of [-1, 1] * * @return A config status code * * @see libinput_device_config_accel_is_available * @see libinput_device_config_accel_get_speed * @see libinput_device_config_accel_get_default_speed */ enum libinput_config_status libinput_device_config_accel_set_speed(struct libinput_device *device, double speed); /** * @ingroup config * * Get the current pointer acceleration setting for this pointer device. The * returned value is normalized to a range of [-1, 1]. * See libinput_device_config_accel_set_speed() for details. * * If the current acceleration profile is @ref * LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM, the behavior of the * device will not change but future calls to * libinput_device_config_accel_get_speed() will reflect the updated speed * setting. * * @param device The device to configure * * @return The current speed, range -1 to 1 * * @see libinput_device_config_accel_is_available * @see libinput_device_config_accel_set_speed * @see libinput_device_config_accel_get_default_speed */ double libinput_device_config_accel_get_speed(struct libinput_device *device); /** * @ingroup config * * Return the default speed setting for this device, normalized to a range * of [-1, 1]. * See libinput_device_config_accel_set_speed() for details. * * @param device The device to configure * @return The default speed setting for this device. * * @see libinput_device_config_accel_is_available * @see libinput_device_config_accel_set_speed * @see libinput_device_config_accel_get_speed */ double libinput_device_config_accel_get_default_speed(struct libinput_device *device); /** * @ingroup config * * @since 1.1 */ enum libinput_config_accel_profile { /** * Placeholder for devices that don't have a configurable pointer * acceleration profile. */ LIBINPUT_CONFIG_ACCEL_PROFILE_NONE = 0, /** * A flat acceleration profile. Pointer motion is accelerated by a * constant (device-specific) factor, depending on the current * speed. * * @see libinput_device_config_accel_set_speed */ LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT = (1 << 0), /** * An adaptive acceleration profile. Pointer acceleration depends * on the input speed. This is the default profile for most devices. */ LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE = (1 << 1), /** * A custom acceleration profile. Device movement acceleration depends * on user defined custom acceleration functions for each movement * type. * * @see libinput_config_accel_set_points */ LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM = (1 << 2), }; /** * @ingroup config * * A handle for configuration pointer acceleration. * * @warning Unlike other structs pointer acceleration configuration is * considered transient and not refcounted. Calling * libinput_config_accel_destroy() will destroy the configuration. * * To configure pointer acceleration, first create a config of a desired * acceleration profile with libinput_config_accel_create(), then * configure the profile-specific acceleration properties. * * In this version of libinput, this pointer acceleration configuration * only provides configuration for @ref LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM. * * For @ref LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM use * @ref libinput_config_accel_set_points. * * Once set up, apply the configuration to a device using * libinput_device_config_accel_apply(). Once applied, * destroy it with libinput_config_accel_destroy(). * * @since 1.23 */ struct libinput_config_accel; /** * @ingroup config * * Create an acceleration configuration of a given profile. * * Note that in this version of libinput, only the * @ref LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM profile provides configuration * options. All other acceleration profiles, when applied, will merely switch * the profile and reset any profile-specific options to the default values. * * @param profile The profile of the newly created acceleration configuration. * * @return The newly created acceleration configuration or NULL on error. * * @warning Unlike other structs pointer acceleration configuration is * considered transient and not refcounted. Calling * libinput_config_accel_destroy() will destroy the configuration. * * @see libinput_config_accel * @since 1.23 */ struct libinput_config_accel * libinput_config_accel_create(enum libinput_config_accel_profile profile); /** * @ingroup config * * Destroy an acceleration configuration. * * @warning Unlike other structs pointer acceleration configuration is * considered transient and not refcounted. Calling * libinput_config_accel_destroy() will destroy the configuration. * * @param accel_config The acceleration configuration to destroy. * * @see libinput_config_accel * @since 1.23 */ void libinput_config_accel_destroy(struct libinput_config_accel *accel_config); /** * @ingroup config * * Apply this pointer acceleration configuration to the device. This changes the * device's pointer acceleration method to the method given in * libinput_config_accel_create() and applies all other configuration settings. * * Once applied, call libinput_config_accel_destroy() to destroy the * configuration struct. * * @param device The device to configure. * @param accel_config The acceleration configuration. * * @return A config status code. * * @see libinput_config_accel * @since 1.23 */ enum libinput_config_status libinput_device_config_accel_apply(struct libinput_device *device, struct libinput_config_accel *accel_config); /** * @ingroup config * * Acceleration types are categories of movement by a device that may have * specific acceleration functions applied. A device always supports the * @ref LIBINPUT_ACCEL_TYPE_MOTION type (for regular pointer motion). Other * types (e.g. scrolling) may be added in the future. * * The special type @ref LIBINPUT_ACCEL_TYPE_FALLBACK specifies the acceleration * function to be moved for any movement produced by the device that does not * have a specific acceleration type defined. * * Use to specify the acceleration function type in * @ref libinput_config_accel_set_points * * Each device implements a subset of those types, see a list of supported * devices for each movement type definition. * * @see LIBINPUT_ACCEL_ARG_TYPE * @since 1.23 */ enum libinput_config_accel_type { /** * The default acceleration type used as a fallback when other * acceleration types are not provided. */ LIBINPUT_ACCEL_TYPE_FALLBACK = 0, /** * Acceleration type for regular pointer movement. This * type is always supported. */ LIBINPUT_ACCEL_TYPE_MOTION, /** * Acceleration type for scroll movement. * This type is supported by mouse and touchpad. */ LIBINPUT_ACCEL_TYPE_SCROLL, }; /** * @ingroup config * * Defines the acceleration function for a given movement type * in an acceleration configuration with the profile * @ref LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM. * * Movement types are specific to each device, @see libinput_config_accel_type. * * Each custom acceleration function is defined by ``n`` points spaced uniformly * along the x-axis starting from 0 and continuing in a constant step size. * There by the function is defined by the following points: * (0 * step, f[0]), (1 * step, f[1]), ..., ((n - 1) * step, f[n - 1]). * The x-axis represents the device-speed in device units per millisecond. * The y-axis represents the pointer-speed. * * It is up to the user to define those values in accordance with device DPI * and screen DPI. * * @param accel_config The acceleration configuration to modify. * @param accel_type The movement type to configure a custom function for. * @param step The distance between each point along the x-axis. * @param npoints The number of points of the custom acceleration function. * @param points The points' y-values of the custom acceleration function. * * @return A config status code. * * @see libinput_config_accel * @since 1.23 */ enum libinput_config_status libinput_config_accel_set_points(struct libinput_config_accel *accel_config, enum libinput_config_accel_type accel_type, double step, size_t npoints, double *points); /** * @ingroup config * * Returns a bitmask of the configurable acceleration modes available on * this device. * * @param device The device to configure * * @return A bitmask of all configurable modes available on this device. * * @since 1.1 */ uint32_t libinput_device_config_accel_get_profiles(struct libinput_device *device); /** * @ingroup config * * Set the pointer acceleration profile of this pointer device to the given * mode. * * @param device The device to configure * @param profile The profile to set the device to. * * @return A config status code * * @since 1.1 */ enum libinput_config_status libinput_device_config_accel_set_profile(struct libinput_device *device, enum libinput_config_accel_profile profile); /** * @ingroup config * * Get the current pointer acceleration profile for this pointer device. * * @param device The device to configure * * @return The currently configured pointer acceleration profile. * * @since 1.1 */ enum libinput_config_accel_profile libinput_device_config_accel_get_profile(struct libinput_device *device); /** * @ingroup config * * Return the default pointer acceleration profile for this pointer device. * * @param device The device to configure * * @return The default acceleration profile for this device. * * @since 1.1 */ enum libinput_config_accel_profile libinput_device_config_accel_get_default_profile(struct libinput_device *device); /** * @ingroup config * * Return non-zero if the device supports "natural scrolling". * * In traditional scroll mode, the movement of fingers on a touchpad when * scrolling matches the movement of the scroll bars. When the fingers move * down, the scroll bar moves down, a line of text on the screen moves * towards the upper end of the screen. This also matches scroll wheels on * mice (wheel down, content moves up). * * Natural scrolling is the term coined by Apple for inverted scrolling. * In this mode, the effect of scrolling movement of fingers on a touchpad * resemble physical manipulation of paper. When the fingers move down, a * line of text on the screen moves down (scrollbars move up). This is the * opposite of scroll wheels on mice. * * A device supporting natural scrolling can be switched between traditional * scroll mode and natural scroll mode. * * @param device The device to configure * * @return Zero if natural scrolling is not supported, non-zero if natural * scrolling is supported by this device * * @see libinput_device_config_scroll_set_natural_scroll_enabled * @see libinput_device_config_scroll_get_natural_scroll_enabled * @see libinput_device_config_scroll_get_default_natural_scroll_enabled */ int libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device); /** * @ingroup config * * Enable or disable natural scrolling on the device. * * @param device The device to configure * @param enable non-zero to enable, zero to disable natural scrolling * * @return A config status code * * @see libinput_device_config_scroll_has_natural_scroll * @see libinput_device_config_scroll_get_natural_scroll_enabled * @see libinput_device_config_scroll_get_default_natural_scroll_enabled */ enum libinput_config_status libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, int enable); /** * @ingroup config * * Get the current mode for scrolling on this device * * @param device The device to configure * * @return Zero if natural scrolling is disabled, non-zero if enabled * * @see libinput_device_config_scroll_has_natural_scroll * @see libinput_device_config_scroll_set_natural_scroll_enabled * @see libinput_device_config_scroll_get_default_natural_scroll_enabled */ int libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device); /** * @ingroup config * * Get the default mode for scrolling on this device * * @param device The device to configure * * @return Zero if natural scrolling is disabled by default, non-zero if enabled * * @see libinput_device_config_scroll_has_natural_scroll * @see libinput_device_config_scroll_set_natural_scroll_enabled * @see libinput_device_config_scroll_get_natural_scroll_enabled */ int libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device); /** * @ingroup config * * Check if a device has a configuration that supports left-handed usage. * * @param device The device to configure * @return Non-zero if the device can be set to left-handed, or zero * otherwise * * @see libinput_device_config_left_handed_set * @see libinput_device_config_left_handed_get * @see libinput_device_config_left_handed_get_default */ int libinput_device_config_left_handed_is_available(struct libinput_device *device); /** * @ingroup config * * Set the left-handed configuration of the device. * * The exact behavior is device-dependent. On a mouse and most pointing * devices, left and right buttons are swapped but the middle button is * unmodified. On a touchpad, physical buttons (if present) are swapped. On a * clickpad, the top and bottom software-emulated buttons are swapped where * present, the main area of the touchpad remains a left button. Tapping and * clickfinger behavior is not affected by this setting. * * Changing the left-handed configuration of a device may not take effect * until all buttons have been logically released. * * @param device The device to configure * @param left_handed Zero to disable, non-zero to enable left-handed mode * @return A configuration status code * * @see libinput_device_config_left_handed_is_available * @see libinput_device_config_left_handed_get * @see libinput_device_config_left_handed_get_default */ enum libinput_config_status libinput_device_config_left_handed_set(struct libinput_device *device, int left_handed); /** * @ingroup config * * Get the current left-handed configuration of the device. * * @param device The device to configure * @return Zero if the device is in right-handed mode, non-zero if the * device is in left-handed mode * * @see libinput_device_config_left_handed_is_available * @see libinput_device_config_left_handed_set * @see libinput_device_config_left_handed_get_default */ int libinput_device_config_left_handed_get(struct libinput_device *device); /** * @ingroup config * * Get the default left-handed configuration of the device. * * @param device The device to configure * @return Zero if the device is in right-handed mode by default, or non-zero * if the device is in left-handed mode by default * * @see libinput_device_config_left_handed_is_available * @see libinput_device_config_left_handed_set * @see libinput_device_config_left_handed_get */ int libinput_device_config_left_handed_get_default(struct libinput_device *device); /** * @ingroup config * * The click method defines when to generate software-emulated * buttons, usually on a device that does not have a specific physical * button available. */ enum libinput_config_click_method { /** * Do not send software-emulated button events. This has no effect * on events generated by physical buttons. */ LIBINPUT_CONFIG_CLICK_METHOD_NONE = 0, /** * Use software-button areas to generate button events. */ LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS = (1 << 0), /** * The number of fingers decides which button press to generate. */ LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER = (1 << 1), }; /** * @ingroup config * * Check which button click methods a device supports. The button click * method defines when to generate software-emulated buttons, usually on a * device that does not have a specific physical button available. * * @param device The device to configure * * @return A bitmask of possible methods. * * @see libinput_device_config_click_get_methods * @see libinput_device_config_click_set_method * @see libinput_device_config_click_get_method */ uint32_t libinput_device_config_click_get_methods(struct libinput_device *device); /** * @ingroup config * * Set the button click method for this device. The button click * method defines when to generate software-emulated buttons, usually on a * device that does not have a specific physical button available. * * @note The selected click method may not take effect immediately. The * device may require changing to a neutral state first before activating * the new method. * * @param device The device to configure * @param method The button click method * * @return A config status code * * @see libinput_device_config_click_get_methods * @see libinput_device_config_click_get_method * @see libinput_device_config_click_get_default_method */ enum libinput_config_status libinput_device_config_click_set_method(struct libinput_device *device, enum libinput_config_click_method method); /** * @ingroup config * * Get the button click method for this device. The button click * method defines when to generate software-emulated buttons, usually on a * device that does not have a specific physical button available. * * @param device The device to configure * * @return The current button click method for this device * * @see libinput_device_config_click_get_methods * @see libinput_device_config_click_set_method * @see libinput_device_config_click_get_default_method */ enum libinput_config_click_method libinput_device_config_click_get_method(struct libinput_device *device); /** * @ingroup config * * Get the default button click method for this device. The button click * method defines when to generate software-emulated buttons, usually on a * device that does not have a specific physical button available. * * @param device The device to configure * * @return The default button click method for this device * * @see libinput_device_config_click_get_methods * @see libinput_device_config_click_set_method * @see libinput_device_config_click_get_method */ enum libinput_config_click_method libinput_device_config_click_get_default_method(struct libinput_device *device); /** * @ingroup config * * Set the finger number to button number mapping for clickfinger. The * default mapping on most devices is to have a 1, 2 and 3 finger tap to map * to the left, right and middle button, respectively. * A device may permit changing the button mapping but disallow specific * maps. In this case @ref LIBINPUT_CONFIG_STATUS_UNSUPPORTED is returned, * the caller is expected to handle this case correctly. * * Changing the button mapping may not take effect immediately, * the device may wait until it is in a neutral state before applying any * changes. * * @param device The device to configure * @param map The new finger-to-button number mapping * * @return A config status code. Changing the order on a device that does not * support the clickfinger method always fails with @ref * LIBINPUT_CONFIG_STATUS_UNSUPPORTED. * * @see libinput_device_config_click_get_clickfinger_button_map * @see libinput_device_config_click_get_default_clickfinger_button_map */ enum libinput_config_status libinput_device_config_click_set_clickfinger_button_map(struct libinput_device *device, enum libinput_config_clickfinger_button_map map); /** * @ingroup config * * Get the finger number to button number mapping for clickfinger. * * The return value for a device that does not support clickfinger is always * @ref LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM. * * @param device The device to configure * @return The current finger-to-button number mapping * * @see libinput_device_config_click_set_clickfinger_button_map * @see libinput_device_config_click_get_default_clickfinger_button_map */ enum libinput_config_clickfinger_button_map libinput_device_config_click_get_clickfinger_button_map(struct libinput_device *device); /** * @ingroup config * * Get the default finger number to button number mapping for clickfinger. * * The return value for a device that does not support clickfinger is always * @ref LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM. * * @param device The device to configure * @return The default finger-to-button number mapping * * @see libinput_device_config_click_set_clickfinger_button_map * @see libinput_device_config_click_get_clickfinger_button_map */ enum libinput_config_clickfinger_button_map libinput_device_config_click_get_default_clickfinger_button_map(struct libinput_device *device); /** * @ingroup config */ enum libinput_config_middle_emulation_state { /** * Middle mouse button emulation is to be disabled, or * is currently disabled. */ LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED, /** * Middle mouse button emulation is to be enabled, or * is currently enabled. */ LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED, }; /** * @ingroup config * * Check if middle mouse button emulation configuration is available on this * device. See libinput_device_config_middle_emulation_set_enabled() for * more details. * * @note Some devices provide middle mouse button emulation but do not allow * enabling/disabling that emulation. These devices return zero in * libinput_device_config_middle_emulation_is_available(). * * @param device The device to query * * @return Non-zero if middle mouse button emulation is available and can be * configured, zero otherwise. * * @see libinput_device_config_middle_emulation_set_enabled * @see libinput_device_config_middle_emulation_get_enabled * @see libinput_device_config_middle_emulation_get_default_enabled */ int libinput_device_config_middle_emulation_is_available( struct libinput_device *device); /** * @ingroup config * * Enable or disable middle button emulation on this device. When enabled, a * simultaneous press of the left and right button generates a middle mouse * button event. Releasing the buttons generates a middle mouse button * release, the left and right button events are discarded otherwise. * * See the libinput documentation for more details. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED to * disable, @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED To enable * middle button emulation. * * @return A config status code. Disabling middle button emulation on a * device that does not support middle button emulation always succeeds. * * @see libinput_device_config_middle_emulation_is_available * @see libinput_device_config_middle_emulation_get_enabled * @see libinput_device_config_middle_emulation_get_default_enabled */ enum libinput_config_status libinput_device_config_middle_emulation_set_enabled( struct libinput_device *device, enum libinput_config_middle_emulation_state enable); /** * @ingroup config * * Check if configurable middle button emulation is enabled on this device. * See libinput_device_config_middle_emulation_set_enabled() for more * details. * * If the device does not have configurable middle button emulation, this * function returns @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED. * * @note Some devices provide middle mouse button emulation but do not allow * enabling/disabling that emulation. These devices always return @ref * LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED if disabled * or not available/configurable, @ref * LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED If enabled. * * @see libinput_device_config_middle_emulation_is_available * @see libinput_device_config_middle_emulation_set_enabled * @see libinput_device_config_middle_emulation_get_default_enabled */ enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_enabled( struct libinput_device *device); /** * @ingroup config * * Check if configurable middle button emulation is enabled by default on * this device. See libinput_device_config_middle_emulation_set_enabled() * for more details. * * If the device does not have configurable middle button * emulation, this function returns @ref * LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED. * * @note Some devices provide middle mouse button emulation but do not allow * enabling/disabling that emulation. These devices always return @ref * LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED If disabled * or not available, @ref LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED if * enabled. * * @see libinput_device_config_middle_emulation_is_available * @see libinput_device_config_middle_emulation_set_enabled * @see libinput_device_config_middle_emulation_get_enabled */ enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_default_enabled( struct libinput_device *device); /** * @ingroup config * * The scroll method of a device selects when to generate scroll axis events * instead of pointer motion events. */ enum libinput_config_scroll_method { /** * Never send scroll events instead of pointer motion events. * This has no effect on events generated by scroll wheels. */ LIBINPUT_CONFIG_SCROLL_NO_SCROLL = 0, /** * Send scroll events when two fingers are logically down on the * device. */ LIBINPUT_CONFIG_SCROLL_2FG = (1 << 0), /** * Send scroll events when a finger moves along the bottom or * right edge of a device. */ LIBINPUT_CONFIG_SCROLL_EDGE = (1 << 1), /** * Send scroll events when a button is down and the device moves * along a scroll-capable axis. */ LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN = (1 << 2), }; /** * @ingroup config * * Check which scroll methods a device supports. The method defines when to * generate scroll axis events instead of pointer motion events. * * @param device The device to configure * * @return A bitmask of possible methods. * * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ uint32_t libinput_device_config_scroll_get_methods(struct libinput_device *device); /** * @ingroup config * * Set the scroll method for this device. The method defines when to * generate scroll axis events instead of pointer motion events. * * @note Setting @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN enables * the scroll method, but scrolling is only activated when the configured * button is held down. If no button is set, i.e. * libinput_device_config_scroll_get_button() returns 0, scrolling * cannot activate. * * @param device The device to configure * @param method The scroll method for this device. * * @return A config status code. * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ enum libinput_config_status libinput_device_config_scroll_set_method(struct libinput_device *device, enum libinput_config_scroll_method method); /** * @ingroup config * * Get the scroll method for this device. The method defines when to * generate scroll axis events instead of pointer motion events. * * @param device The device to configure * @return The current scroll method for this device. * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ enum libinput_config_scroll_method libinput_device_config_scroll_get_method(struct libinput_device *device); /** * @ingroup config * * Get the default scroll method for this device. The method defines when to * generate scroll axis events instead of pointer motion events. * * @param device The device to configure * @return The default scroll method for this device. * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ enum libinput_config_scroll_method libinput_device_config_scroll_get_default_method(struct libinput_device *device); /** * @ingroup config * * Set the button for the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN method * for this device. * * When the current scroll method is set to @ref * LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN, no button press/release events * will be send for the configured button. * * When the configured button is pressed, any motion events along a * scroll-capable axis are turned into scroll axis events. * * @note Setting the button does not change the scroll method. To change the * scroll method call libinput_device_config_scroll_set_method(). * * If the button is 0, button scrolling is effectively disabled. * * @param device The device to configure * @param button The button which when pressed switches to sending scroll events * * @return A config status code * @retval LIBINPUT_CONFIG_STATUS_SUCCESS On success * @retval LIBINPUT_CONFIG_STATUS_UNSUPPORTED If @ref * LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN is not supported * @retval LIBINPUT_CONFIG_STATUS_INVALID The given button does not * exist on this device * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ enum libinput_config_status libinput_device_config_scroll_set_button(struct libinput_device *device, uint32_t button); /** * @ingroup config * * Get the button for the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN method * for this device. * * If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll method is not * supported, or no button is set, this function returns 0. * * @note The return value is independent of the currently selected * scroll-method. For button scrolling to activate, a device must have the * @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN method enabled, and a non-zero * button set as scroll button. * * @param device The device to configure * @return The button which when pressed switches to sending scroll events * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_default_button */ uint32_t libinput_device_config_scroll_get_button(struct libinput_device *device); /** * @ingroup config * * Get the default button for the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN * method for this device. * * If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll method is not supported, * or no default button is set, this function returns 0. * * @param device The device to configure * @return The default button for the @ref * LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN method * * @see libinput_device_config_scroll_get_methods * @see libinput_device_config_scroll_set_method * @see libinput_device_config_scroll_get_method * @see libinput_device_config_scroll_get_default_method * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button */ uint32_t libinput_device_config_scroll_get_default_button(struct libinput_device *device); enum libinput_config_scroll_button_lock_state { LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED, }; /** * @ingroup config * * Set the scroll button lock. If the state is * @ref LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED, the button must * physically be held down for button scrolling to work. * If the state is * @ref LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED, the button is considered * logically down after the first press and release sequence, and logically * up after the second press and release sequence. * * @param device The device to configure * @param state The state to set the scroll button lock to * * @return A config status code. Disabling the scroll button lock on * device that does not support button scrolling always succeeds. * * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_get_button * @see libinput_device_config_scroll_get_default_button */ enum libinput_config_status libinput_device_config_scroll_set_button_lock(struct libinput_device *device, enum libinput_config_scroll_button_lock_state state); /** * @ingroup config * * Get the current scroll button lock state. * * If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll method is not * supported, or no button is set, this function returns @ref * LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED. * * @note The return value is independent of the currently selected * scroll-method. For the scroll button lock to activate, a device must have * the @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN method enabled, and a * non-zero button set as scroll button. * * @param device The device to configure * @return The scroll button lock state * * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_set_button_lock * @see libinput_device_config_scroll_get_button_lock * @see libinput_device_config_scroll_get_default_button_lock */ enum libinput_config_scroll_button_lock_state libinput_device_config_scroll_get_button_lock(struct libinput_device *device); /** * @ingroup config * * Get the default scroll button lock state. * * If @ref LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN scroll method is not * supported, or no button is set, this function returns @ref * LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED. * * @param device The device to configure * @return The default scroll button lock state * * @see libinput_device_config_scroll_set_button * @see libinput_device_config_scroll_set_button_lock * @see libinput_device_config_scroll_get_button_lock * @see libinput_device_config_scroll_get_default_button_lock */ enum libinput_config_scroll_button_lock_state libinput_device_config_scroll_get_default_button_lock(struct libinput_device *device); /** * @ingroup config * * Possible states for the disable-while-typing feature. */ enum libinput_config_dwt_state { LIBINPUT_CONFIG_DWT_DISABLED, LIBINPUT_CONFIG_DWT_ENABLED, }; /** * @ingroup config * * Check if this device supports configurable disable-while-typing feature. * This feature is usually available on built-in touchpads and disables the * touchpad while typing. See the libinput documentation for details. * * @param device The device to configure * @return 0 if this device does not support disable-while-typing, or 1 * otherwise. * * @see libinput_device_config_dwt_set_enabled * @see libinput_device_config_dwt_get_enabled * @see libinput_device_config_dwt_get_default_enabled */ int libinput_device_config_dwt_is_available(struct libinput_device *device); /** * @ingroup config * * Enable or disable the disable-while-typing feature. When enabled, the * device will be disabled while typing and for a short period after. See * the libinput documentation for details. * * @note Enabling or disabling disable-while-typing may not take effect * immediately. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_DWT_DISABLED to disable * disable-while-typing, @ref LIBINPUT_CONFIG_DWT_ENABLED to enable * * @return A config status code. Disabling disable-while-typing on a * device that does not support the feature always succeeds. * * @see libinput_device_config_dwt_is_available * @see libinput_device_config_dwt_get_enabled * @see libinput_device_config_dwt_get_default_enabled */ enum libinput_config_status libinput_device_config_dwt_set_enabled(struct libinput_device *device, enum libinput_config_dwt_state enable); /** * @ingroup config * * Check if the disable-while typing feature is currently enabled on this * device. If the device does not support disable-while-typing, this * function returns @ref LIBINPUT_CONFIG_DWT_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_DWT_DISABLED if disabled, @ref * LIBINPUT_CONFIG_DWT_ENABLED if enabled. * * @see libinput_device_config_dwt_is_available * @see libinput_device_config_dwt_set_enabled * @see libinput_device_config_dwt_get_default_enabled */ enum libinput_config_dwt_state libinput_device_config_dwt_get_enabled(struct libinput_device *device); /** * @ingroup config * * Check if the disable-while typing feature is enabled on this device by * default. If the device does not support disable-while-typing, this * function returns @ref LIBINPUT_CONFIG_DWT_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_DWT_DISABLED if disabled, @ref * LIBINPUT_CONFIG_DWT_ENABLED if enabled. * * @see libinput_device_config_dwt_is_available * @see libinput_device_config_dwt_set_enabled * @see libinput_device_config_dwt_get_enabled */ enum libinput_config_dwt_state libinput_device_config_dwt_get_default_enabled(struct libinput_device *device); /** * @ingroup config * * Possible states for the disable-while-trackpointing feature. * * @since 1.21 */ enum libinput_config_dwtp_state { LIBINPUT_CONFIG_DWTP_DISABLED, LIBINPUT_CONFIG_DWTP_ENABLED, }; /** * @ingroup config * * Check if this device supports configurable disable-while-trackpointing * feature. This feature is usually available on Thinkpads and disables the * touchpad while using the trackpoint. See the libinput documentation for * details. * * @param device The device to configure * @return 0 if this device does not support disable-while-trackpointing, or 1 * otherwise. * * @see libinput_device_config_dwtp_set_enabled * @see libinput_device_config_dwtp_get_enabled * @see libinput_device_config_dwtp_get_default_enabled * * @since 1.21 */ int libinput_device_config_dwtp_is_available(struct libinput_device *device); /** * @ingroup config * * Enable or disable the disable-while-trackpointing feature. When enabled, the * device will be disabled while using the trackpoint and for a short period * after. See the libinput documentation for details. * * @note Enabling or disabling disable-while-trackpointing may not take effect * immediately. * * @param device The device to configure * @param enable @ref LIBINPUT_CONFIG_DWTP_DISABLED to disable * disable-while-trackpointing, @ref LIBINPUT_CONFIG_DWTP_ENABLED to enable * * @return A config status code. Disabling disable-while-trackpointing on a * device that does not support the feature always succeeds. * * @see libinput_device_config_dwtp_is_available * @see libinput_device_config_dwtp_get_enabled * @see libinput_device_config_dwtp_get_default_enabled * * @since 1.21 */ enum libinput_config_status libinput_device_config_dwtp_set_enabled(struct libinput_device *device, enum libinput_config_dwtp_state enable); /** * @ingroup config * * Check if the disable-while trackpointing feature is currently enabled on * this device. If the device does not support disable-while-trackpointing, * this function returns @ref LIBINPUT_CONFIG_DWTP_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_DWTP_DISABLED if disabled, @ref * LIBINPUT_CONFIG_DWTP_ENABLED if enabled. * * @see libinput_device_config_dwtp_is_available * @see libinput_device_config_dwtp_set_enabled * @see libinput_device_config_dwtp_get_default_enabled * * @since 1.21 */ enum libinput_config_dwtp_state libinput_device_config_dwtp_get_enabled(struct libinput_device *device); /** * @ingroup config * * Check if the disable-while trackpointing feature is enabled on this device * by default. If the device does not support disable-while-trackpointing, this * function returns @ref LIBINPUT_CONFIG_DWTP_DISABLED. * * @param device The device to configure * @return @ref LIBINPUT_CONFIG_DWTP_DISABLED if disabled, @ref * LIBINPUT_CONFIG_DWTP_ENABLED if enabled. * * @see libinput_device_config_dwtp_is_available * @see libinput_device_config_dwtp_set_enabled * @see libinput_device_config_dwtp_get_enabled * * @since 1.21 */ enum libinput_config_dwtp_state libinput_device_config_dwtp_get_default_enabled(struct libinput_device *device); /** * @ingroup config * * Check whether a device can have a custom rotation applied. * * @param device The device to configure * @return Non-zero if a device can be rotated, zero otherwise. * * @see libinput_device_config_rotation_set_angle * @see libinput_device_config_rotation_get_angle * @see libinput_device_config_rotation_get_default_angle * * @since 1.4 */ int libinput_device_config_rotation_is_available(struct libinput_device *device); /** * @ingroup config * * Set the rotation of a device in degrees clockwise off the logical neutral * position. Any subsequent motion events are adjusted according to the * given angle. * * The angle has to be in the range of [0, 360[ degrees, otherwise this * function returns LIBINPUT_CONFIG_STATUS_INVALID. If the angle is a * multiple of 360 or negative, the caller must ensure the correct ranging * before calling this function. * * The rotation angle is applied to all motion events emitted by the device. * Thus, rotating the device also changes the angle required or presented by * scrolling, gestures, etc. * * @param device The device to configure * @param degrees_cw The angle in degrees clockwise * @return A config status code. Setting a rotation of 0 degrees on a * device that does not support rotation always succeeds. * * @see libinput_device_config_rotation_is_available * @see libinput_device_config_rotation_get_angle * @see libinput_device_config_rotation_get_default_angle * * @since 1.4 */ enum libinput_config_status libinput_device_config_rotation_set_angle(struct libinput_device *device, unsigned int degrees_cw); /** * @ingroup config * * Get the current rotation of a device in degrees clockwise off the logical * neutral position. If this device does not support rotation, the return * value is always 0. * * @param device The device to configure * @return The angle in degrees clockwise * * @see libinput_device_config_rotation_is_available * @see libinput_device_config_rotation_set_angle * @see libinput_device_config_rotation_get_default_angle * * @since 1.4 */ unsigned int libinput_device_config_rotation_get_angle(struct libinput_device *device); /** * @ingroup config * * Get the default rotation of a device in degrees clockwise off the logical * neutral position. If this device does not support rotation, the return * value is always 0. * * @param device The device to configure * @return The default angle in degrees clockwise * * @see libinput_device_config_rotation_is_available * @see libinput_device_config_rotation_set_angle * @see libinput_device_config_rotation_get_angle * * @since 1.4 */ unsigned int libinput_device_config_rotation_get_default_angle(struct libinput_device *device); /** * @ingroup config * * Check if a tablet tool can have a custom pressure range. * * @param tool The libinput tool * @return Non-zero if a device has an adjustible pressure range, zero otherwise. * * @see libinput_tablet_tool_config_pressure_range_set * @see libinput_tablet_tool_config_pressure_range_get_minimum * @see libinput_tablet_tool_config_pressure_range_get_maximum * @see libinput_tablet_tool_config_pressure_range_get_default_minimum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ int libinput_tablet_tool_config_pressure_range_is_available(struct libinput_tablet_tool *tool); /** * @ingroup config * * Set the pressure range for this tablet tool. This maps the given logical * pressure range into the available hardware pressure range so that a hardware * pressure of the given minimum value maps into a logical pressure of 0.0 (as * returned by libinput_event_tablet_tool_get_pressure()) and the hardware * pressure of the given maximum value is mapped into the logical pressure * of 1.0 (as returned by libinput_event_tablet_tool_get_pressure()) * * The minimum value must be less than the maximum value, libinput may * require the values to have a specific distance to each other, * i.e. that (maximum - minimum > N) for an implementation-defined value of N. * * @param tool The libinput tool * @param minimum The minimum pressure value in the range [0.0, 1.0) * @param maximum The maximum pressure value in the range (0.0, 1.0] * * @return A config status code * * @see libinput_tablet_tool_config_pressure_range_is_available * @see libinput_tablet_tool_config_pressure_range_get_minimum * @see libinput_tablet_tool_config_pressure_range_get_maximum * @see libinput_tablet_tool_config_pressure_range_get_default_minimum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ enum libinput_config_status libinput_tablet_tool_config_pressure_range_set(struct libinput_tablet_tool *tool, double minimum, double maximum); /** * @ingroup config * * Get the minimum pressure value for this tablet tool, normalized to the * range [0.0, 1.0] of the available hardware pressure. * * If the tool does not support pressure range configuration, the return value * of this function is always 0.0. * * @param tool The libinput tool * @return The minimum pressure value for this tablet tool * * @see libinput_tablet_tool_config_pressure_range_is_available * @see libinput_tablet_tool_config_pressure_range_get_maximum * @see libinput_tablet_tool_config_pressure_range_get_default_minimum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ double libinput_tablet_tool_config_pressure_range_get_minimum(struct libinput_tablet_tool *tool); /** * @ingroup config * * Get the maximum pressure value for this tablet tool, normalized to the * range [0.0, 1.0] of the available hardware pressure. * * If the tool does not support pressure range configuration, the return value * of this function is always 1.0. * * @param tool The libinput tool * @return The maximum pressure value for this tablet tool * * @see libinput_tablet_tool_config_pressure_range_is_available * @see libinput_tablet_tool_config_pressure_range_get_minimum * @see libinput_tablet_tool_config_pressure_range_get_default_minimum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ double libinput_tablet_tool_config_pressure_range_get_maximum(struct libinput_tablet_tool *tool); /** * @ingroup config * * Get the minimum pressure value for this tablet tool, normalized to the * range [0.0, 1.0] of the available hardware pressure. * * If the tool does not support pressure range configuration, the return value * of this function is always 0.0. * * @param tool The libinput tool * @return The minimum pressure value for this tablet tool * * @see libinput_tablet_tool_config_pressure_range_is_available * @see libinput_tablet_tool_config_pressure_range_get_minimum * @see libinput_tablet_tool_config_pressure_range_get_maximum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ double libinput_tablet_tool_config_pressure_range_get_default_minimum(struct libinput_tablet_tool *tool); /** * @ingroup config * * Get the maximum pressure value for this tablet tool, normalized to the * range [0.0, 1.0] of the available hardware pressure. * * If the tool does not support pressure range configuration, the return value * of this function is always 1.0. * * @param tool The libinput tool * @return The maximum pressure value for this tablet tool * * @see libinput_tablet_tool_config_pressure_range_is_available * @see libinput_tablet_tool_config_pressure_range_get_minimum * @see libinput_tablet_tool_config_pressure_range_get_maximum * @see libinput_tablet_tool_config_pressure_range_get_default_maximum * * @since 1.26 */ double libinput_tablet_tool_config_pressure_range_get_default_maximum(struct libinput_tablet_tool *tool); #ifdef __cplusplus } #endif #endif /* LIBINPUT_H */ libinput-1.28.1/src/libinput.pc.in000066400000000000000000000004741477265155700170270ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ datarootdir=@datarootdir@ pkgdatadir=@datadir@/@PACKAGE@ libdir=@libdir@ includedir=@includedir@ Name: Libinput Description: Input device library Version: @LIBINPUT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -linput Libs.private: -lm -lrt Requires.private: libudev libinput-1.28.1/src/libinput.sym000066400000000000000000000306401477265155700166260ustar00rootroot00000000000000/* in alphabetical order! */ LIBINPUT_0.12.0 { global: libinput_config_status_to_str; libinput_device_config_accel_get_default_speed; libinput_device_config_accel_get_speed; libinput_device_config_accel_is_available; libinput_device_config_accel_set_speed; libinput_device_config_calibration_get_default_matrix; libinput_device_config_calibration_get_matrix; libinput_device_config_calibration_has_matrix; libinput_device_config_calibration_set_matrix; libinput_device_config_click_get_default_method; libinput_device_config_click_get_method; libinput_device_config_click_get_methods; libinput_device_config_click_set_method; libinput_device_config_left_handed_get; libinput_device_config_left_handed_get_default; libinput_device_config_left_handed_is_available; libinput_device_config_left_handed_set; libinput_device_config_scroll_get_button; libinput_device_config_scroll_get_default_button; libinput_device_config_scroll_get_default_method; libinput_device_config_scroll_get_default_natural_scroll_enabled; libinput_device_config_scroll_get_method; libinput_device_config_scroll_get_methods; libinput_device_config_scroll_get_natural_scroll_enabled; libinput_device_config_scroll_has_natural_scroll; libinput_device_config_scroll_set_button; libinput_device_config_scroll_set_method; libinput_device_config_scroll_set_natural_scroll_enabled; libinput_device_config_send_events_get_default_mode; libinput_device_config_send_events_get_mode; libinput_device_config_send_events_get_modes; libinput_device_config_send_events_set_mode; libinput_device_config_tap_get_default_enabled; libinput_device_config_tap_get_enabled; libinput_device_config_tap_get_finger_count; libinput_device_config_tap_set_enabled; libinput_device_get_context; libinput_device_get_device_group; libinput_device_get_id_product; libinput_device_get_id_vendor; libinput_device_get_name; libinput_device_get_output_name; libinput_device_get_seat; libinput_device_get_size; libinput_device_get_sysname; libinput_device_get_udev_device; libinput_device_get_user_data; libinput_device_group_get_user_data; libinput_device_group_ref; libinput_device_group_set_user_data; libinput_device_group_unref; libinput_device_has_capability; libinput_device_led_update; libinput_device_pointer_has_button; libinput_device_ref; libinput_device_set_seat_logical_name; libinput_device_set_user_data; libinput_device_unref; libinput_dispatch; libinput_event_destroy; libinput_event_device_notify_get_base_event; libinput_event_get_context; libinput_event_get_device; libinput_event_get_device_notify_event; libinput_event_get_keyboard_event; libinput_event_get_pointer_event; libinput_event_get_touch_event; libinput_event_get_type; libinput_event_keyboard_get_base_event; libinput_event_keyboard_get_key; libinput_event_keyboard_get_key_state; libinput_event_keyboard_get_seat_key_count; libinput_event_keyboard_get_time; libinput_event_pointer_get_absolute_x; libinput_event_pointer_get_absolute_x_transformed; libinput_event_pointer_get_absolute_y; libinput_event_pointer_get_absolute_y_transformed; libinput_event_pointer_get_axis_source; libinput_event_pointer_get_axis_value; libinput_event_pointer_get_axis_value_discrete; libinput_event_pointer_get_base_event; libinput_event_pointer_get_button; libinput_event_pointer_get_button_state; libinput_event_pointer_get_dx; libinput_event_pointer_get_dx_unaccelerated; libinput_event_pointer_get_dy; libinput_event_pointer_get_dy_unaccelerated; libinput_event_pointer_get_seat_button_count; libinput_event_pointer_get_time; libinput_event_pointer_has_axis; libinput_event_touch_get_base_event; libinput_event_touch_get_seat_slot; libinput_event_touch_get_slot; libinput_event_touch_get_time; libinput_event_touch_get_x; libinput_event_touch_get_x_transformed; libinput_event_touch_get_y; libinput_event_touch_get_y_transformed; libinput_get_event; libinput_get_fd; libinput_get_user_data; libinput_log_get_priority; libinput_log_set_handler; libinput_log_set_priority; libinput_next_event_type; libinput_path_add_device; libinput_path_create_context; libinput_path_remove_device; libinput_ref; libinput_resume; libinput_seat_get_context; libinput_seat_get_logical_name; libinput_seat_get_physical_name; libinput_seat_get_user_data; libinput_seat_ref; libinput_seat_set_user_data; libinput_seat_unref; libinput_set_user_data; libinput_suspend; libinput_udev_assign_seat; libinput_udev_create_context; libinput_unref; local: *; }; LIBINPUT_0.14.0 { global: libinput_device_config_middle_emulation_get_default_enabled; libinput_device_config_middle_emulation_get_enabled; libinput_device_config_middle_emulation_is_available; libinput_device_config_middle_emulation_set_enabled; } LIBINPUT_0.12.0; LIBINPUT_0.15.0 { global: libinput_device_keyboard_has_key; } LIBINPUT_0.14.0; LIBINPUT_0.19.0 { global: libinput_device_config_tap_set_drag_lock_enabled; libinput_device_config_tap_get_drag_lock_enabled; libinput_device_config_tap_get_default_drag_lock_enabled; } LIBINPUT_0.15.0; LIBINPUT_0.20.0 { libinput_event_gesture_get_angle_delta; libinput_event_gesture_get_base_event; libinput_event_gesture_get_cancelled; libinput_event_gesture_get_dx; libinput_event_gesture_get_dx_unaccelerated; libinput_event_gesture_get_dy; libinput_event_gesture_get_dy_unaccelerated; libinput_event_gesture_get_finger_count; libinput_event_gesture_get_scale; libinput_event_gesture_get_time; libinput_event_get_gesture_event; } LIBINPUT_0.19.0; LIBINPUT_0.21.0 { libinput_device_config_dwt_is_available; libinput_device_config_dwt_set_enabled; libinput_device_config_dwt_get_enabled; libinput_device_config_dwt_get_default_enabled; libinput_event_gesture_get_time_usec; libinput_event_keyboard_get_time_usec; libinput_event_pointer_get_time_usec; libinput_event_touch_get_time_usec; } LIBINPUT_0.20.0; LIBINPUT_1.1 { libinput_device_config_accel_get_profile; libinput_device_config_accel_get_profiles; libinput_device_config_accel_get_default_profile; libinput_device_config_accel_set_profile; } LIBINPUT_0.21.0; LIBINPUT_1.2 { libinput_device_config_tap_get_drag_enabled; libinput_device_config_tap_get_default_drag_enabled; libinput_device_config_tap_set_drag_enabled; libinput_event_get_tablet_tool_event; libinput_event_tablet_tool_x_has_changed; libinput_event_tablet_tool_y_has_changed; libinput_event_tablet_tool_pressure_has_changed; libinput_event_tablet_tool_distance_has_changed; libinput_event_tablet_tool_rotation_has_changed; libinput_event_tablet_tool_tilt_x_has_changed; libinput_event_tablet_tool_tilt_y_has_changed; libinput_event_tablet_tool_wheel_has_changed; libinput_event_tablet_tool_slider_has_changed; libinput_event_tablet_tool_get_dx; libinput_event_tablet_tool_get_dy; libinput_event_tablet_tool_get_x; libinput_event_tablet_tool_get_y; libinput_event_tablet_tool_get_pressure; libinput_event_tablet_tool_get_distance; libinput_event_tablet_tool_get_tilt_x; libinput_event_tablet_tool_get_tilt_y; libinput_event_tablet_tool_get_rotation; libinput_event_tablet_tool_get_slider_position; libinput_event_tablet_tool_get_wheel_delta; libinput_event_tablet_tool_get_wheel_delta_discrete; libinput_event_tablet_tool_get_base_event; libinput_event_tablet_tool_get_button; libinput_event_tablet_tool_get_button_state; libinput_event_tablet_tool_get_proximity_state; libinput_event_tablet_tool_get_seat_button_count; libinput_event_tablet_tool_get_time; libinput_event_tablet_tool_get_tip_state; libinput_event_tablet_tool_get_tool; libinput_event_tablet_tool_get_x_transformed; libinput_event_tablet_tool_get_y_transformed; libinput_event_tablet_tool_get_time_usec; libinput_tablet_tool_get_serial; libinput_tablet_tool_get_tool_id; libinput_tablet_tool_get_type; libinput_tablet_tool_get_user_data; libinput_tablet_tool_has_pressure; libinput_tablet_tool_has_distance; libinput_tablet_tool_has_rotation; libinput_tablet_tool_has_tilt; libinput_tablet_tool_has_wheel; libinput_tablet_tool_has_slider; libinput_tablet_tool_has_button; libinput_tablet_tool_is_unique; libinput_tablet_tool_ref; libinput_tablet_tool_set_user_data; libinput_tablet_tool_unref; } LIBINPUT_1.1; LIBINPUT_1.3 { libinput_device_tablet_pad_get_num_buttons; libinput_device_tablet_pad_get_num_rings; libinput_device_tablet_pad_get_num_strips; libinput_event_get_tablet_pad_event; libinput_event_tablet_pad_get_base_event; libinput_event_tablet_pad_get_button_number; libinput_event_tablet_pad_get_button_state; libinput_event_tablet_pad_get_ring_position; libinput_event_tablet_pad_get_ring_number; libinput_event_tablet_pad_get_ring_source; libinput_event_tablet_pad_get_strip_position; libinput_event_tablet_pad_get_strip_number; libinput_event_tablet_pad_get_strip_source; libinput_event_tablet_pad_get_time; libinput_event_tablet_pad_get_time_usec; } LIBINPUT_1.2; LIBINPUT_1.4 { libinput_device_config_rotation_get_angle; libinput_device_config_rotation_get_default_angle; libinput_device_config_rotation_is_available; libinput_device_config_rotation_set_angle; libinput_device_tablet_pad_get_mode_group; libinput_device_tablet_pad_get_num_mode_groups; libinput_event_tablet_pad_get_mode; libinput_event_tablet_pad_get_mode_group; libinput_tablet_pad_mode_group_button_is_toggle; libinput_tablet_pad_mode_group_get_index; libinput_tablet_pad_mode_group_get_mode; libinput_tablet_pad_mode_group_get_num_modes; libinput_tablet_pad_mode_group_get_user_data; libinput_tablet_pad_mode_group_has_button; libinput_tablet_pad_mode_group_has_strip; libinput_tablet_pad_mode_group_has_ring; libinput_tablet_pad_mode_group_ref; libinput_tablet_pad_mode_group_set_user_data; libinput_tablet_pad_mode_group_unref; } LIBINPUT_1.3; LIBINPUT_1.5 { libinput_device_config_tap_get_button_map; libinput_device_config_tap_get_default_button_map; libinput_device_config_tap_set_button_map; } LIBINPUT_1.4; LIBINPUT_1.7 { libinput_event_get_switch_event; libinput_event_switch_get_base_event; libinput_event_switch_get_switch_state; libinput_event_switch_get_switch; libinput_event_switch_get_time; libinput_event_switch_get_time_usec; } LIBINPUT_1.5; LIBINPUT_1.9 { libinput_device_switch_has_switch; } LIBINPUT_1.7; LIBINPUT_1.11 { libinput_device_touch_get_touch_count; } LIBINPUT_1.9; LIBINPUT_1.14 { libinput_tablet_tool_has_size; libinput_event_tablet_tool_get_size_major; libinput_event_tablet_tool_get_size_minor; libinput_event_tablet_tool_size_major_has_changed; libinput_event_tablet_tool_size_minor_has_changed; } LIBINPUT_1.11; LIBINPUT_1.15 { libinput_device_config_scroll_set_button_lock; libinput_device_config_scroll_get_button_lock; libinput_device_config_scroll_get_default_button_lock; libinput_device_tablet_pad_has_key; libinput_event_tablet_pad_get_key; libinput_event_tablet_pad_get_key_state; } LIBINPUT_1.14; LIBINPUT_1.19 { libinput_event_pointer_get_scroll_value_v120; libinput_event_pointer_get_scroll_value; } LIBINPUT_1.15; LIBINPUT_1.21 { libinput_device_config_dwtp_is_available; libinput_device_config_dwtp_set_enabled; libinput_device_config_dwtp_get_enabled; libinput_device_config_dwtp_get_default_enabled; } LIBINPUT_1.19; LIBINPUT_1.23 { libinput_config_accel_create; libinput_config_accel_destroy; libinput_device_config_accel_apply; libinput_config_accel_set_points; } LIBINPUT_1.21; LIBINPUT_1.26 { libinput_device_config_click_set_clickfinger_button_map; libinput_device_config_click_get_default_clickfinger_button_map; libinput_device_config_click_get_clickfinger_button_map; libinput_device_get_id_bustype; libinput_device_tablet_pad_get_num_dials; libinput_event_tablet_pad_get_dial_delta_v120; libinput_event_tablet_pad_get_dial_number; libinput_tablet_pad_mode_group_has_dial; libinput_tablet_tool_config_pressure_range_is_available; libinput_tablet_tool_config_pressure_range_set; libinput_tablet_tool_config_pressure_range_get_minimum; libinput_tablet_tool_config_pressure_range_get_maximum; libinput_tablet_tool_config_pressure_range_get_default_minimum; libinput_tablet_tool_config_pressure_range_get_default_maximum; } LIBINPUT_1.23; LIBINPUT_1.27 { libinput_device_config_area_has_rectangle; libinput_device_config_area_set_rectangle; libinput_device_config_area_get_rectangle; libinput_device_config_area_get_default_rectangle; } LIBINPUT_1.26; LIBINPUT_1.28 { libinput_device_config_3fg_drag_get_finger_count; libinput_device_config_3fg_drag_set_enabled; libinput_device_config_3fg_drag_get_enabled; libinput_device_config_3fg_drag_get_default_enabled; } LIBINPUT_1.27; libinput-1.28.1/src/path-seat.c000066400000000000000000000244351477265155700163050ustar00rootroot00000000000000/* * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "evdev.h" struct path_input { struct libinput base; struct udev *udev; struct list path_list; }; struct path_device { struct list link; struct udev_device *udev_device; }; struct path_seat { struct libinput_seat base; }; static const char default_seat[] = "seat0"; static const char default_seat_name[] = "default"; static void path_disable_device(struct evdev_device *device) { struct libinput_seat *seat = device->base.seat; struct evdev_device *dev; list_for_each_safe(dev, &seat->devices_list, base.link) { if (dev != device) continue; evdev_device_remove(device); break; } } static void path_input_disable(struct libinput *libinput) { struct path_input *input = (struct path_input*)libinput; struct path_seat *seat; struct evdev_device *device; list_for_each_safe(seat, &input->base.seat_list, base.link) { libinput_seat_ref(&seat->base); list_for_each_safe(device, &seat->base.devices_list, base.link) path_disable_device(device); libinput_seat_unref(&seat->base); } } static void path_seat_destroy(struct libinput_seat *seat) { struct path_seat *pseat = (struct path_seat*)seat; free(pseat); } static struct path_seat* path_seat_create(struct path_input *input, const char *seat_name, const char *seat_logical_name) { struct path_seat *seat; seat = zalloc(sizeof(*seat)); libinput_seat_init(&seat->base, &input->base, seat_name, seat_logical_name, path_seat_destroy); return seat; } static struct path_seat* path_seat_get_named(struct path_input *input, const char *seat_name_physical, const char *seat_name_logical) { struct path_seat *seat; list_for_each(seat, &input->base.seat_list, base.link) { if (streq(seat->base.physical_name, seat_name_physical) && streq(seat->base.logical_name, seat_name_logical)) return seat; } return NULL; } static struct path_seat * path_seat_get_for_device(struct path_input *input, struct udev_device *udev_device, const char *seat_logical_name_override) { struct path_seat *seat = NULL; char *seat_name = NULL, *seat_logical_name = NULL; const char *seat_prop; const char *devnode, *sysname; devnode = udev_device_get_devnode(udev_device); sysname = udev_device_get_sysname(udev_device); seat_prop = udev_device_get_property_value(udev_device, "ID_SEAT"); seat_name = safe_strdup(seat_prop ? seat_prop : default_seat); if (seat_logical_name_override) { seat_logical_name = safe_strdup(seat_logical_name_override); } else { seat_prop = udev_device_get_property_value(udev_device, "WL_SEAT"); seat_logical_name = safe_strdup(seat_prop ? seat_prop : default_seat_name); } if (!seat_logical_name) { log_error(&input->base, "%s: failed to create seat name for device '%s'.\n", sysname, devnode); goto out; } seat = path_seat_get_named(input, seat_name, seat_logical_name); if (!seat) seat = path_seat_create(input, seat_name, seat_logical_name); if (!seat) { log_info(&input->base, "%s: failed to create seat for device '%s'.\n", sysname, devnode); goto out; } libinput_seat_ref(&seat->base); out: free(seat_name); free(seat_logical_name); return seat; } static struct libinput_device * path_device_enable(struct path_input *input, struct udev_device *udev_device, const char *seat_logical_name_override) { struct path_seat *seat; struct evdev_device *device = NULL; const char *output_name; const char *devnode, *sysname; devnode = udev_device_get_devnode(udev_device); sysname = udev_device_get_sysname(udev_device); seat = path_seat_get_for_device(input, udev_device, seat_logical_name_override); if (!seat) goto out; device = evdev_device_create(&seat->base, udev_device); libinput_seat_unref(&seat->base); if (device == EVDEV_UNHANDLED_DEVICE) { device = NULL; log_info(&input->base, "%-7s - not using input device '%s'.\n", sysname, devnode); goto out; } else if (device == NULL) { log_info(&input->base, "%-7s - failed to create input device '%s'.\n", sysname, devnode); goto out; } evdev_read_calibration_prop(device); output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT"); device->output_name = safe_strdup(output_name); out: return device ? &device->base : NULL; } static int path_input_enable(struct libinput *libinput) { struct path_input *input = (struct path_input*)libinput; struct path_device *dev; list_for_each(dev, &input->path_list, link) { if (path_device_enable(input, dev->udev_device, NULL) == NULL) { path_input_disable(libinput); return -1; } } return 0; } static void path_device_destroy(struct path_device *dev) { list_remove(&dev->link); udev_device_unref(dev->udev_device); free(dev); } static void path_input_destroy(struct libinput *input) { struct path_input *path_input = (struct path_input*)input; struct path_device *dev; udev_unref(path_input->udev); list_for_each_safe(dev, &path_input->path_list, link) path_device_destroy(dev); } static struct libinput_device * path_create_device(struct libinput *libinput, struct udev_device *udev_device, const char *seat_name) { struct path_input *input = (struct path_input*)libinput; struct path_device *dev; struct libinput_device *device; dev = zalloc(sizeof *dev); dev->udev_device = udev_device_ref(udev_device); list_insert(&input->path_list, &dev->link); device = path_device_enable(input, udev_device, seat_name); if (!device) path_device_destroy(dev); return device; } static int path_device_change_seat(struct libinput_device *device, const char *seat_name) { struct libinput *libinput = device->seat->libinput; struct evdev_device *evdev = evdev_device(device); struct udev_device *udev_device = NULL; int rc = -1; udev_device = evdev->udev_device; udev_device_ref(udev_device); libinput_path_remove_device(device); if (path_create_device(libinput, udev_device, seat_name) != NULL) rc = 0; udev_device_unref(udev_device); return rc; } static const struct libinput_interface_backend interface_backend = { .resume = path_input_enable, .suspend = path_input_disable, .destroy = path_input_destroy, .device_change_seat = path_device_change_seat, }; LIBINPUT_EXPORT struct libinput * libinput_path_create_context(const struct libinput_interface *interface, void *user_data) { struct path_input *input; struct udev *udev; if (!interface) return NULL; udev = udev_new(); if (!udev) return NULL; input = zalloc(sizeof *input); if (libinput_init(&input->base, interface, &interface_backend, user_data) != 0) { udev_unref(udev); free(input); return NULL; } input->udev = udev; list_init(&input->path_list); return &input->base; } static inline struct udev_device * udev_device_from_devnode(struct libinput *libinput, struct udev *udev, const char *devnode) { struct udev_device *dev; struct stat st; size_t count = 0; if (stat(devnode, &st) < 0) return NULL; dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev); while (dev && !udev_device_get_is_initialized(dev)) { udev_device_unref(dev); count++; if (count > 200) { log_bug_libinput(libinput, "udev device never initialized (%s)\n", devnode); return NULL; } msleep(10); dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev); } return dev; } LIBINPUT_EXPORT struct libinput_device * libinput_path_add_device(struct libinput *libinput, const char *path) { struct path_input *input = (struct path_input *)libinput; struct udev *udev = input->udev; struct udev_device *udev_device; struct libinput_device *device; if (strlen(path) > PATH_MAX) { log_bug_client(libinput, "Unexpected path, limited to %d characters.\n", PATH_MAX); return NULL; } if (libinput->interface_backend != &interface_backend) { log_bug_client(libinput, "Mismatching backends.\n"); return NULL; } udev_device = udev_device_from_devnode(libinput, udev, path); if (!udev_device) { log_bug_client(libinput, "Invalid path %s\n", path); return NULL; } if (ignore_litest_test_suite_device(udev_device)) { udev_device_unref(udev_device); return NULL; } /* We cannot do this during path_create_context because the log * handler isn't set up there but we really want to log to the right * place if the quirks run into parser errors. So we have to do it * on the first call to add_device. */ libinput_init_quirks(libinput); device = path_create_device(libinput, udev_device, NULL); udev_device_unref(udev_device); return device; } LIBINPUT_EXPORT void libinput_path_remove_device(struct libinput_device *device) { struct libinput *libinput = device->seat->libinput; struct path_input *input = (struct path_input*)libinput; struct libinput_seat *seat; struct evdev_device *evdev = evdev_device(device); struct path_device *dev; if (libinput->interface_backend != &interface_backend) { log_bug_client(libinput, "Mismatching backends.\n"); return; } list_for_each_safe(dev, &input->path_list, link) { if (dev->udev_device == evdev->udev_device) { path_device_destroy(dev); break; } } seat = device->seat; libinput_seat_ref(seat); path_disable_device(evdev); libinput_seat_unref(seat); } libinput-1.28.1/src/quirks.c000066400000000000000000001252461477265155700157370ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" /* This has the hallmarks of a library to make it re-usable from the tests * and from the list-quirks tool. It doesn't have all of the features from a * library you'd expect though */ #undef NDEBUG /* You don't get to disable asserts here */ #include #include #include #include #include #include #ifdef __FreeBSD__ #include #endif #include "libinput-versionsort.h" #include "libinput-util.h" #include "quirks.h" /* Custom logging so we can have detailed output for the tool but minimal * logging for libinput itself. */ #define qlog_debug(ctx_, ...) quirk_log_msg((ctx_), QLOG_NOISE, __VA_ARGS__) #define qlog_info(ctx_, ...) quirk_log_msg((ctx_), QLOG_INFO, __VA_ARGS__) #define qlog_error(ctx_, ...) quirk_log_msg((ctx_), QLOG_ERROR, __VA_ARGS__) #define qlog_parser(ctx_, ...) quirk_log_msg((ctx_), QLOG_PARSER_ERROR, __VA_ARGS__) enum property_type { PT_UINT, PT_INT, PT_STRING, PT_BOOL, PT_DIMENSION, PT_RANGE, PT_DOUBLE, PT_TUPLES, PT_UINT_ARRAY, }; struct quirk_array { union { uint32_t u[32]; } data; size_t nelements; }; /** * Generic value holder for the property types we support. The type * identifies which value in the union is defined and we expect callers to * already know which type yields which value. */ struct property { size_t refcount; struct list link; /* struct sections.properties */ enum quirk id; enum property_type type; union { bool b; uint32_t u; int32_t i; char *s; double d; struct quirk_dimensions dim; struct quirk_range range; struct quirk_tuples tuples; struct quirk_array array; } value; }; enum match_flags { M_NAME = bit(0), M_BUS = bit(1), M_VID = bit(2), M_PID = bit(3), M_DMI = bit(4), M_UDEV_TYPE = bit(5), M_DT = bit(6), M_VERSION = bit(7), M_UNIQ = bit(8), M_LAST = M_UNIQ, }; enum bustype { BT_UNKNOWN, BT_USB, BT_BLUETOOTH, BT_PS2, BT_RMI, BT_I2C, BT_SPI, }; enum udev_type { UDEV_MOUSE = bit(1), UDEV_POINTINGSTICK = bit(2), UDEV_TOUCHPAD = bit(3), UDEV_TABLET = bit(4), UDEV_TABLET_PAD = bit(5), UDEV_JOYSTICK = bit(6), UDEV_KEYBOARD = bit(7), }; /** * Contains the combined set of matches for one section or the values for * one device. * * bits defines which fields are set, the rest is zero. */ struct match { uint32_t bits; char *name; char *uniq; enum bustype bus; uint32_t vendor; uint32_t product[64]; /* zero-terminated */ uint32_t version; char *dmi; /* dmi modalias with preceding "dmi:" */ /* We can have more than one type set, so this is a bitfield */ uint32_t udev_type; char *dt; /* device tree compatible (first) string */ }; /** * Represents one section in the .quirks file. */ struct section { struct list link; bool has_match; /* to check for empty sections */ bool has_property; /* to check for empty sections */ char *name; /* the [Section Name] */ struct match match; struct list properties; }; /** * The struct returned to the caller. It contains the * properties for a given device. */ struct quirks { size_t refcount; struct list link; /* struct quirks_context.quirks */ /* These are not ref'd, just a collection of pointers */ struct property **properties; size_t nproperties; /* Special properties for AttrEventCode and AttrInputCode, these are * owned by us, not the section */ struct list floating_properties; }; /** * Quirk matching context, initialized once with quirks_init_subsystem() */ struct quirks_context { size_t refcount; libinput_log_handler log_handler; enum quirks_log_type log_type; struct libinput *libinput; /* for logging */ char *dmi; char *dt; struct list sections; /* list of quirks handed to libinput, just for bookkeeping */ struct list quirks; }; LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static inline void quirk_log_msg_va(struct quirks_context *ctx, enum quirks_log_priorities priority, const char *format, va_list args) { switch (priority) { /* We don't use this if we're logging through libinput */ default: case QLOG_NOISE: case QLOG_PARSER_ERROR: if (ctx->log_type == QLOG_LIBINPUT_LOGGING) return; break; case QLOG_DEBUG: /* These map straight to libinput priorities */ case QLOG_INFO: case QLOG_ERROR: break; } ctx->log_handler(ctx->libinput, (enum libinput_log_priority)priority, format, args); } LIBINPUT_ATTRIBUTE_PRINTF(3, 4) static inline void quirk_log_msg(struct quirks_context *ctx, enum quirks_log_priorities priority, const char *format, ...) { va_list args; va_start(args, format); quirk_log_msg_va(ctx, priority, format, args); va_end(args); } const char * quirk_get_name(enum quirk q) { switch(q) { case QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD: return "ModelALPSSerialTouchpad"; case QUIRK_MODEL_APPLE_TOUCHPAD: return "ModelAppleTouchpad"; case QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON: return "ModelAppleTouchpadOneButton"; case QUIRK_MODEL_BOUNCING_KEYS: return "ModelBouncingKeys"; case QUIRK_MODEL_CHROMEBOOK: return "ModelChromebook"; case QUIRK_MODEL_CLEVO_W740SU: return "ModelClevoW740SU"; case QUIRK_MODEL_DELL_CANVAS_TOTEM: return "ModelDellCanvasTotem"; case QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD: return "ModelHPPavilionDM4Touchpad"; case QUIRK_MODEL_HP_ZBOOK_STUDIO_G3: return "ModelHPZBookStudioG3"; case QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING: return "ModelInvertHorizontalScrolling"; case QUIRK_MODEL_LENOVO_SCROLLPOINT: return "ModelLenovoScrollPoint"; case QUIRK_MODEL_LENOVO_T450_TOUCHPAD: return "ModelLenovoT450Touchpad"; case QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD: return "ModelLenovoX1Gen6Touchpad"; case QUIRK_MODEL_LENOVO_X230: return "ModelLenovoX230"; case QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD: return "ModelSynapticsSerialTouchpad"; case QUIRK_MODEL_SYSTEM76_BONOBO: return "ModelSystem76Bonobo"; case QUIRK_MODEL_SYSTEM76_GALAGO: return "ModelSystem76Galago"; case QUIRK_MODEL_SYSTEM76_KUDU: return "ModelSystem76Kudu"; case QUIRK_MODEL_TABLET_MODE_NO_SUSPEND: return "ModelTabletModeNoSuspend"; case QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE: return "ModelTabletModeSwitchUnreliable"; case QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER: return "ModelTouchpadVisibleMarker"; case QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS: return "ModelTouchpadPhantomClicks"; case QUIRK_MODEL_TRACKBALL: return "ModelTrackball"; case QUIRK_MODEL_WACOM_TOUCHPAD: return "ModelWacomTouchpad"; case QUIRK_MODEL_PRESSURE_PAD: return "ModelPressurePad"; case QUIRK_ATTR_SIZE_HINT: return "AttrSizeHint"; case QUIRK_ATTR_TOUCH_SIZE_RANGE: return "AttrTouchSizeRange"; case QUIRK_ATTR_PALM_SIZE_THRESHOLD: return "AttrPalmSizeThreshold"; case QUIRK_ATTR_LID_SWITCH_RELIABILITY: return "AttrLidSwitchReliability"; case QUIRK_ATTR_KEYBOARD_INTEGRATION: return "AttrKeyboardIntegration"; case QUIRK_ATTR_TRACKPOINT_INTEGRATION: return "AttrPointingStickIntegration"; case QUIRK_ATTR_TPKBCOMBO_LAYOUT: return "AttrTPKComboLayout"; case QUIRK_ATTR_PRESSURE_RANGE: return "AttrPressureRange"; case QUIRK_ATTR_PALM_PRESSURE_THRESHOLD: return "AttrPalmPressureThreshold"; case QUIRK_ATTR_RESOLUTION_HINT: return "AttrResolutionHint"; case QUIRK_ATTR_TRACKPOINT_MULTIPLIER: return "AttrTrackpointMultiplier"; case QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD: return "AttrThumbPressureThreshold"; case QUIRK_ATTR_USE_VELOCITY_AVERAGING: return "AttrUseVelocityAveraging"; case QUIRK_ATTR_TABLET_SMOOTHING: return "AttrTabletSmoothing"; case QUIRK_ATTR_THUMB_SIZE_THRESHOLD: return "AttrThumbSizeThreshold"; case QUIRK_ATTR_MSC_TIMESTAMP: return "AttrMscTimestamp"; case QUIRK_ATTR_EVENT_CODE: return "AttrEventCode"; case QUIRK_ATTR_INPUT_PROP: return "AttrInputProp"; default: abort(); } } static inline const char * matchflagname(enum match_flags f) { switch(f) { case M_NAME: return "MatchName"; break; case M_BUS: return "MatchBus"; break; case M_VID: return "MatchVendor"; break; case M_PID: return "MatchProduct"; break; case M_VERSION: return "MatchVersion"; break; case M_DMI: return "MatchDMIModalias"; break; case M_UDEV_TYPE: return "MatchUdevType"; break; case M_DT: return "MatchDeviceTree"; break; case M_UNIQ: return "MatchUniq"; break; default: abort(); } } static inline struct property * property_new(void) { struct property *p; p = zalloc(sizeof *p); p->refcount = 1; list_init(&p->link); return p; } static inline struct property * property_ref(struct property *p) { assert(p->refcount > 0); p->refcount++; return p; } static inline struct property * property_unref(struct property *p) { /* Note: we don't cleanup here, that is a separate call so we can abort if we haven't cleaned up correctly. */ assert(p->refcount > 0); p->refcount--; return NULL; } /* Separate call so we can verify that the caller unrefs the property * before shutting down the subsystem. */ static inline void property_cleanup(struct property *p) { /* If we get here, the quirks must've been removed already */ property_unref(p); assert(p->refcount == 0); list_remove(&p->link); if (p->type == PT_STRING) free(p->value.s); free(p); } /** * Return the system DMI info in modalias format. */ #ifdef __linux__ static inline char * init_dmi_linux(void) { struct udev *udev; struct udev_device *udev_device; const char *modalias = NULL; char *copy = NULL; const char *syspath = "/sys/devices/virtual/dmi/id"; udev = udev_new(); if (!udev) return NULL; udev_device = udev_device_new_from_syspath(udev, syspath); if (udev_device) modalias = udev_device_get_property_value(udev_device, "MODALIAS"); /* Not sure whether this could ever really fail, if so we should * open the sysfs file directly. But then udev wouldn't have failed, * so... */ if (!modalias) modalias = "dmi:*"; copy = safe_strdup(modalias); udev_device_unref(udev_device); udev_unref(udev); return copy; } #endif #ifdef __FreeBSD__ static inline char * init_dmi_freebsd(void) { #define LEN (KENV_MVALLEN + 1) char *modalias; char bios_vendor[LEN], bios_version[LEN], bios_date[LEN]; char sys_vendor[LEN], product_name[LEN], product_version[LEN]; char board_vendor[LEN], board_name[LEN], board_version[LEN]; char chassis_vendor[LEN], chassis_type[LEN], chassis_version[LEN]; int chassis_type_num = 0x2; kenv(KENV_GET, "smbios.bios.vendor", bios_vendor, LEN); kenv(KENV_GET, "smbios.bios.version", bios_version, LEN); kenv(KENV_GET, "smbios.bios.reldate", bios_date, LEN); kenv(KENV_GET, "smbios.system.maker", sys_vendor, LEN); kenv(KENV_GET, "smbios.system.product", product_name, LEN); kenv(KENV_GET, "smbios.system.version", product_version, LEN); kenv(KENV_GET, "smbios.planar.maker", board_vendor, LEN); kenv(KENV_GET, "smbios.planar.product", board_name, LEN); kenv(KENV_GET, "smbios.planar.version", board_version, LEN); kenv(KENV_GET, "smbios.chassis.vendor", chassis_vendor, LEN); kenv(KENV_GET, "smbios.chassis.type", chassis_type, LEN); kenv(KENV_GET, "smbios.chassis.version", chassis_version, LEN); #undef LEN if (strcmp(chassis_type, "Desktop") == 0) chassis_type_num = 0x3; else if (strcmp(chassis_type, "Portable") == 0) chassis_type_num = 0x8; else if (strcmp(chassis_type, "Laptop") == 0) chassis_type_num = 0x9; else if (strcmp(chassis_type, "Notebook") == 0) chassis_type_num = 0xA; else if (strcmp(chassis_type, "Tablet") == 0) chassis_type_num = 0x1E; else if (strcmp(chassis_type, "Convertible") == 0) chassis_type_num = 0x1F; else if (strcmp(chassis_type, "Detachable") == 0) chassis_type_num = 0x20; xasprintf(&modalias, "dmi:bvn%s:bvr%s:bd%s:svn%s:pn%s:pvr%s:rvn%s:rn%s:rvr%s:cvn%s:ct%d:cvr%s:", bios_vendor, bios_version, bios_date, sys_vendor, product_name, product_version, board_vendor, board_name, board_version, chassis_vendor, chassis_type_num, chassis_version); return modalias; } #endif static inline char * init_dmi(void) { if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) return safe_strdup("dmi:"); #if defined(__linux__) return init_dmi_linux(); #elif defined(__FreeBSD__) return init_dmi_freebsd(); #else return NULL; #endif } /** * Return the dt compatible string */ static inline char * init_dt(void) { char compatible[1024]; char *copy = NULL; const char *syspath = "/sys/firmware/devicetree/base/compatible"; FILE *fp; if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) return safe_strdup(""); fp = fopen(syspath, "r"); if (!fp) return NULL; /* devicetree/base/compatible has multiple null-terminated entries but we only care about the first one here, so strdup is enough */ if (fgets(compatible, sizeof(compatible), fp)) { copy = safe_strdup(compatible); } fclose(fp); return copy; } static inline struct section * section_new(const char *path, const char *name) { struct section *s = zalloc(sizeof(*s)); char *path_dup = safe_strdup(path); xasprintf(&s->name, "%s (%s)", name, basename(path_dup)); free(path_dup); list_init(&s->link); list_init(&s->properties); return s; } static inline void section_destroy(struct section *s) { struct property *p; free(s->name); free(s->match.name); free(s->match.uniq); free(s->match.dmi); free(s->match.dt); list_for_each_safe(p, &s->properties, link) property_cleanup(p); assert(list_empty(&s->properties)); list_remove(&s->link); free(s); } static inline bool parse_hex(const char *value, unsigned int *parsed) { return strstartswith(value, "0x") && safe_atou_base(value, parsed, 16) && strspn(value, "0123456789xABCDEF") == strlen(value) && *parsed <= 0xFFFF; } static int strv_parse_hex(const char *str, size_t index, void *data) { unsigned int *product = data; return !parse_hex(str, &product[index]); /* 0 for success */ } /** * Parse a MatchFooBar=banana line. * * @param section The section struct to be filled in * @param key The MatchFooBar part of the line * @param value The banana part of the line. * * @return true on success, false otherwise. */ static bool parse_match(struct quirks_context *ctx, struct section *s, const char *key, const char *value) { int rc = false; #define check_set_bit(s_, bit_) { \ if ((s_)->match.bits & (bit_)) goto out; \ (s_)->match.bits |= (bit_); \ } assert(strlen(value) >= 1); if (streq(key, "MatchName")) { check_set_bit(s, M_NAME); s->match.name = safe_strdup(value); } else if (streq(key, "MatchUniq")) { check_set_bit(s, M_UNIQ); s->match.uniq = safe_strdup(value); } else if (streq(key, "MatchBus")) { check_set_bit(s, M_BUS); if (streq(value, "usb")) s->match.bus = BT_USB; else if (streq(value, "bluetooth")) s->match.bus = BT_BLUETOOTH; else if (streq(value, "ps2")) s->match.bus = BT_PS2; else if (streq(value, "rmi")) s->match.bus = BT_RMI; else if (streq(value, "i2c")) s->match.bus = BT_I2C; else if (streq(value, "spi")) s->match.bus = BT_SPI; else goto out; } else if (streq(key, "MatchVendor")) { unsigned int vendor; check_set_bit(s, M_VID); if (!parse_hex(value, &vendor)) goto out; s->match.vendor = vendor; } else if (streq(key, "MatchProduct")) { unsigned int product[ARRAY_LENGTH(s->match.product)] = {0}; const size_t max = ARRAY_LENGTH(s->match.product) - 1; size_t nelems = 0; char **strs = strv_from_string(value, ";", &nelems); int rc = strv_for_each_n((const char**)strs, max, strv_parse_hex, product); strv_free(strs); if (rc != 0) goto out; check_set_bit(s, M_PID); memcpy(s->match.product, product, sizeof(product)); } else if (streq(key, "MatchVersion")) { unsigned int version; check_set_bit(s, M_VERSION); if (!parse_hex(value, &version)) goto out; s->match.version = version; } else if (streq(key, "MatchDMIModalias")) { check_set_bit(s, M_DMI); if (!strstartswith(value, "dmi:")) { qlog_parser(ctx, "%s: MatchDMIModalias must start with 'dmi:'\n", s->name); goto out; } s->match.dmi = safe_strdup(value); } else if (streq(key, "MatchUdevType")) { check_set_bit(s, M_UDEV_TYPE); if (streq(value, "touchpad")) s->match.udev_type = UDEV_TOUCHPAD; else if (streq(value, "mouse")) s->match.udev_type = UDEV_MOUSE; else if (streq(value, "pointingstick")) s->match.udev_type = UDEV_POINTINGSTICK; else if (streq(value, "keyboard")) s->match.udev_type = UDEV_KEYBOARD; else if (streq(value, "joystick")) s->match.udev_type = UDEV_JOYSTICK; else if (streq(value, "tablet")) s->match.udev_type = UDEV_TABLET; else if (streq(value, "tablet-pad")) s->match.udev_type = UDEV_TABLET_PAD; else goto out; } else if (streq(key, "MatchDeviceTree")) { check_set_bit(s, M_DT); s->match.dt = safe_strdup(value); } else { qlog_error(ctx, "Unknown match key '%s'\n", key); goto out; } #undef check_set_bit s->has_match = true; rc = true; out: return rc; } /** * Parse a ModelFooBar=1 line. * * @param section The section struct to be filled in * @param key The ModelFooBar part of the line * @param value The value after the =, must be 1 or 0. * * @return true on success, false otherwise. */ static bool parse_model(struct quirks_context *ctx, struct section *s, const char *key, const char *value) { bool b; enum quirk q = QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD; assert(strstartswith(key, "Model")); if (!parse_boolean_property(value, &b)) return false; do { if (streq(key, quirk_get_name(q))) { struct property *p = property_new(); p->id = q, p->type = PT_BOOL; p->value.b = b; list_append(&s->properties, &p->link); s->has_property = true; return true; } } while (++q < _QUIRK_LAST_MODEL_QUIRK_); qlog_error(ctx, "Unknown key %s in %s\n", key, s->name); return false; } /** * Parse a AttrFooBar=banana line. * * @param section The section struct to be filled in * @param key The AttrFooBar part of the line * @param value The banana part of the line. * * Value parsing depends on the attribute type. * * @return true on success, false otherwise. */ static inline bool parse_attr(struct quirks_context *ctx, struct section *s, const char *key, const char *value) { struct property *p = property_new(); bool rc = false; struct quirk_dimensions dim; struct quirk_range range; unsigned int v; bool b; double d; if (streq(key, quirk_get_name(QUIRK_ATTR_SIZE_HINT))) { p->id = QUIRK_ATTR_SIZE_HINT; if (!parse_dimension_property(value, &dim.x, &dim.y)) goto out; p->type = PT_DIMENSION; p->value.dim = dim; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_TOUCH_SIZE_RANGE))) { p->id = QUIRK_ATTR_TOUCH_SIZE_RANGE; if (!parse_range_property(value, &range.upper, &range.lower)) goto out; p->type = PT_RANGE; p->value.range = range; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_PALM_SIZE_THRESHOLD))) { p->id = QUIRK_ATTR_PALM_SIZE_THRESHOLD; if (!safe_atou(value, &v)) goto out; p->type = PT_UINT; p->value.u = v; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_LID_SWITCH_RELIABILITY))) { p->id = QUIRK_ATTR_LID_SWITCH_RELIABILITY; if (!streq(value, "reliable") && !streq(value, "write_open") && !streq(value, "unreliable")) goto out; p->type = PT_STRING; p->value.s = safe_strdup(value); rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_KEYBOARD_INTEGRATION))) { p->id = QUIRK_ATTR_KEYBOARD_INTEGRATION; if (!streq(value, "internal") && !streq(value, "external")) goto out; p->type = PT_STRING; p->value.s = safe_strdup(value); rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_TRACKPOINT_INTEGRATION))) { p->id = QUIRK_ATTR_TRACKPOINT_INTEGRATION; if (!streq(value, "internal") && !streq(value, "external")) goto out; p->type = PT_STRING; p->value.s = safe_strdup(value); rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_TPKBCOMBO_LAYOUT))) { p->id = QUIRK_ATTR_TPKBCOMBO_LAYOUT; if (!streq(value, "below")) goto out; p->type = PT_STRING; p->value.s = safe_strdup(value); rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_PRESSURE_RANGE))) { p->id = QUIRK_ATTR_PRESSURE_RANGE; if (!parse_range_property(value, &range.upper, &range.lower)) goto out; p->type = PT_RANGE; p->value.range = range; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_PALM_PRESSURE_THRESHOLD))) { p->id = QUIRK_ATTR_PALM_PRESSURE_THRESHOLD; if (!safe_atou(value, &v)) goto out; p->type = PT_UINT; p->value.u = v; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_RESOLUTION_HINT))) { p->id = QUIRK_ATTR_RESOLUTION_HINT; if (!parse_dimension_property(value, &dim.x, &dim.y)) goto out; p->type = PT_DIMENSION; p->value.dim = dim; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_TRACKPOINT_MULTIPLIER))) { p->id = QUIRK_ATTR_TRACKPOINT_MULTIPLIER; if (!safe_atod(value, &d)) goto out; p->type = PT_DOUBLE; p->value.d = d; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_USE_VELOCITY_AVERAGING))) { p->id = QUIRK_ATTR_USE_VELOCITY_AVERAGING; if (!parse_boolean_property(value, &b)) goto out; p->type = PT_BOOL; p->value.b = b; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_TABLET_SMOOTHING))) { p->id = QUIRK_ATTR_TABLET_SMOOTHING; if (!parse_boolean_property(value, &b)) goto out; p->type = PT_BOOL; p->value.b = b; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD))) { p->id = QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD; if (!safe_atou(value, &v)) goto out; p->type = PT_UINT; p->value.u = v; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_THUMB_SIZE_THRESHOLD))) { p->id = QUIRK_ATTR_THUMB_SIZE_THRESHOLD; if (!safe_atou(value, &v)) goto out; p->type = PT_UINT; p->value.u = v; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_MSC_TIMESTAMP))) { p->id = QUIRK_ATTR_MSC_TIMESTAMP; if (!streq(value, "watch")) goto out; p->type = PT_STRING; p->value.s = safe_strdup(value); rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_EVENT_CODE))) { struct input_event events[32]; size_t nevents = ARRAY_LENGTH(events); p->id = QUIRK_ATTR_EVENT_CODE; if (!parse_evcode_property(value, events, &nevents) || nevents == 0) goto out; for (size_t i = 0; i < nevents; i++) { p->value.tuples.tuples[i].first = events[i].type; p->value.tuples.tuples[i].second = events[i].code; p->value.tuples.tuples[i].third = events[i].value; } p->value.tuples.ntuples = nevents; p->type = PT_TUPLES; rc = true; } else if (streq(key, quirk_get_name(QUIRK_ATTR_INPUT_PROP))) { struct input_prop props[INPUT_PROP_CNT]; size_t nprops = ARRAY_LENGTH(props); p->id = QUIRK_ATTR_INPUT_PROP; if (!parse_input_prop_property(value, props, &nprops) || nprops == 0) goto out; for (size_t i = 0; i < nprops; i++) { p->value.tuples.tuples[i].first = props[i].prop; p->value.tuples.tuples[i].second = props[i].enabled; } p->value.tuples.ntuples = nprops; p->type = PT_TUPLES; rc = true; } else { qlog_error(ctx, "Unknown key %s in %s\n", key, s->name); } out: if (rc) { list_append(&s->properties, &p->link); s->has_property = true; } else { property_cleanup(p); } return rc; } /** * Parse a single line, expected to be in the format Key=value. Anything * else will be rejected with a failure. * * Our data files can only have Match, Model and Attr, so let's check for * those too. */ static bool parse_value_line(struct quirks_context *ctx, struct section *s, const char *line) { bool rc = false; size_t nelem; char **strv = strv_from_string(line, "=", &nelem); if (!strv || nelem != 2) goto out; const char *key = strv[0]; const char *value = strv[1]; if (strlen(key) == 0 || strlen(value) == 0) goto out; /* Whatever the value is, it's not supposed to be in quotes */ if (value[0] == '"' || value[0] == '\'') goto out; if (strstartswith(key, "Match")) rc = parse_match(ctx, s, key, value); else if (strstartswith(key, "Model")) rc = parse_model(ctx, s, key, value); else if (strstartswith(key, "Attr")) rc = parse_attr(ctx, s, key, value); else qlog_error(ctx, "Unknown value prefix %s\n", line); out: strv_free(strv); return rc; } static inline bool parse_file(struct quirks_context *ctx, const char *path) { enum state { STATE_SECTION, STATE_MATCH, STATE_MATCH_OR_VALUE, STATE_VALUE_OR_SECTION, STATE_ANY, }; FILE *fp; char line[512]; bool rc = false; enum state state = STATE_SECTION; struct section *section = NULL; int lineno = -1; qlog_debug(ctx, "%s\n", path); /* Not using open_restricted here, if we can't access * our own data files, our installation is screwed up. */ fp = fopen(path, "r"); if (!fp) { /* If the file doesn't exist that's fine. Only way this can * happen is for the custom override file, all others are * provided by scandir so they do exist. Short of races we * don't care about. */ if (errno == ENOENT) return true; qlog_error(ctx, "%s: failed to open file\n", path); goto out; } while (fgets(line, sizeof(line), fp)) { char *comment; lineno++; comment = strstr(line, "#"); if (comment) { /* comment points to # but we need to remove the * preceding whitespaces too */ comment--; while (comment >= line) { if (*comment != ' ' && *comment != '\t') break; comment--; } *(comment + 1) = '\0'; } else { /* strip the trailing newline */ comment = strstr(line, "\n"); if (comment) *comment = '\0'; } if (strlen(line) == 0) continue; /* We don't use quotes for strings, so we really don't want * erroneous trailing whitespaces */ switch (line[strlen(line) - 1]) { case ' ': case '\t': qlog_parser(ctx, "%s:%d: Trailing whitespace '%s'\n", path, lineno, line); goto out; } switch (line[0]) { case '\0': case '\n': case '#': break; /* white space not allowed */ case ' ': case '\t': qlog_parser(ctx, "%s:%d: Preceding whitespace '%s'\n", path, lineno, line); goto out; /* section title */ case '[': if (line[strlen(line) - 1] != ']') { qlog_parser(ctx, "%s:%d: Closing ] missing '%s'\n", path, lineno, line); goto out; } if (state != STATE_SECTION && state != STATE_VALUE_OR_SECTION) { qlog_parser(ctx, "%s:%d: expected section before %s\n", path, lineno, line); goto out; } if (section && (!section->has_match || !section->has_property)) { qlog_parser(ctx, "%s:%d: previous section %s was empty\n", path, lineno, section->name); goto out; /* Previous section was empty */ } state = STATE_MATCH; section = section_new(path, line); list_append(&ctx->sections, §ion->link); break; default: /* entries must start with A-Z */ if (line[0] < 'A' || line[0] > 'Z') { qlog_parser(ctx, "%s:%d: Unexpected line %s\n", path, lineno, line); goto out; } switch (state) { case STATE_SECTION: qlog_parser(ctx, "%s:%d: expected [Section], got %s\n", path, lineno, line); goto out; case STATE_MATCH: if (!strstartswith(line, "Match")) { qlog_parser(ctx, "%s:%d: expected MatchFoo=bar, have %s\n", path, lineno, line); goto out; } state = STATE_MATCH_OR_VALUE; break; case STATE_MATCH_OR_VALUE: if (!strstartswith(line, "Match")) state = STATE_VALUE_OR_SECTION; break; case STATE_VALUE_OR_SECTION: if (strstartswith(line, "Match")) { qlog_parser(ctx, "%s:%d: expected value or [Section], have %s\n", path, lineno, line); goto out; } break; case STATE_ANY: break; } if (!parse_value_line(ctx, section, line)) { qlog_parser(ctx, "%s:%d: failed to parse %s\n", path, lineno, line); goto out; } break; } } if (!section) { qlog_parser(ctx, "%s: is an empty file\n", path); goto out; } if ((!section->has_match || !section->has_property)) { qlog_parser(ctx, "%s:%d: previous section %s was empty\n", path, lineno, section->name); goto out; /* Previous section was empty */ } rc = true; out: if (fp) fclose(fp); return rc; } static int is_data_file(const struct dirent *dir) { return strendswith(dir->d_name, ".quirks"); } static inline bool parse_files(struct quirks_context *ctx, const char *data_path) { struct dirent **namelist; int ndev = -1; int idx = 0; ndev = scandir(data_path, &namelist, is_data_file, versionsort); if (ndev <= 0) { qlog_error(ctx, "%s: failed to find data files\n", data_path); return false; } for (idx = 0; idx < ndev; idx++) { char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", data_path, namelist[idx]->d_name); if (!parse_file(ctx, path)) break; } for (int i = 0; i < ndev; i++) free(namelist[i]); free(namelist); return idx == ndev; } struct quirks_context * quirks_init_subsystem(const char *data_path, const char *override_file, libinput_log_handler log_handler, struct libinput *libinput, enum quirks_log_type log_type) { struct quirks_context *ctx = zalloc(sizeof *ctx); assert(data_path); ctx->refcount = 1; ctx->log_handler = log_handler; ctx->log_type = log_type; ctx->libinput = libinput; list_init(&ctx->quirks); list_init(&ctx->sections); qlog_debug(ctx, "%s is data root\n", data_path); ctx->dmi = init_dmi(); ctx->dt = init_dt(); if (!ctx->dmi && !ctx->dt) goto error; if (!parse_files(ctx, data_path)) goto error; if (override_file && !parse_file(ctx, override_file)) goto error; return ctx; error: quirks_context_unref(ctx); return NULL; } struct quirks_context * quirks_context_ref(struct quirks_context *ctx) { assert(ctx->refcount > 0); ctx->refcount++; return ctx; } struct quirks_context * quirks_context_unref(struct quirks_context *ctx) { struct section *s; if (!ctx) return NULL; assert(ctx->refcount >= 1); ctx->refcount--; if (ctx->refcount > 0) return NULL; /* Caller needs to clean up before calling this */ assert(list_empty(&ctx->quirks)); list_for_each_safe(s, &ctx->sections, link) { section_destroy(s); } free(ctx->dmi); free(ctx->dt); free(ctx); return NULL; } static struct quirks * quirks_new(void) { struct quirks *q; q = zalloc(sizeof *q); q->refcount = 1; q->nproperties = 0; list_init(&q->link); list_init(&q->floating_properties); return q; } struct quirks * quirks_unref(struct quirks *q) { if (!q) return NULL; /* We don't really refcount, but might * as well have the API in place */ assert(q->refcount == 1); for (size_t i = 0; i < q->nproperties; i++) { property_unref(q->properties[i]); } /* Floating properties are owned by our quirks context, need to be * cleaned up here */ struct property *p; list_for_each_safe(p, &q->floating_properties, link) { property_cleanup(p); } list_remove(&q->link); free(q->properties); free(q); return NULL; } /** * Searches for the udev property on this device and its parent devices. * * @return the value of the property or NULL */ static const char * udev_prop(struct udev_device *device, const char *prop) { struct udev_device *d = device; const char *value = NULL; do { value = udev_device_get_property_value(d, prop); d = udev_device_get_parent(d); } while (value == NULL && d != NULL); return value; } static inline void match_fill_name(struct match *m, struct udev_device *device) { const char *str = udev_prop(device, "NAME"); size_t slen; if (!str) return; /* udev NAME is in quotes, strip them */ if (str[0] == '"') str++; m->name = safe_strdup(str); slen = strlen(m->name); if (slen > 1 && m->name[slen - 1] == '"') m->name[slen - 1] = '\0'; m->bits |= M_NAME; } static inline void match_fill_uniq(struct match *m, struct udev_device *device) { const char *str = udev_prop(device, "UNIQ"); size_t slen; if (!str) return; /* udev uniq is in quotes, strip them */ if (str[0] == '"') str++; m->uniq = safe_strdup(str); slen = safe_strlen(m->uniq); if (slen > 1 && m->uniq[slen - 1] == '"') m->uniq[slen - 1] = '\0'; m->bits |= M_UNIQ; } static inline void match_fill_bus_vid_pid(struct match *m, struct udev_device *device) { const char *str; unsigned int product, vendor, bus, version; str = udev_prop(device, "PRODUCT"); if (!str) return; /* ID_VENDOR_ID/ID_PRODUCT_ID/ID_BUS aren't filled in for virtual * devices so we have to resort to PRODUCT */ if (sscanf(str, "%x/%x/%x/%x", &bus, &vendor, &product, &version) != 4) return; m->product[0] = product; m->product[1] = 0; m->vendor = vendor; m->version = version; m->bits |= M_PID|M_VID|M_VERSION; switch (bus) { case BUS_USB: m->bus = BT_USB; m->bits |= M_BUS; break; case BUS_BLUETOOTH: m->bus = BT_BLUETOOTH; m->bits |= M_BUS; break; case BUS_I8042: m->bus = BT_PS2; m->bits |= M_BUS; break; case BUS_RMI: m->bus = BT_RMI; m->bits |= M_BUS; break; case BUS_I2C: m->bus = BT_I2C; m->bits |= M_BUS; break; case BUS_SPI: m->bus = BT_SPI; m->bits |= M_BUS; break; default: break; } } static inline void match_fill_udev_type(struct match *m, struct udev_device *device) { struct ut_map { const char *prop; enum udev_type flag; } mappings[] = { { "ID_INPUT_MOUSE", UDEV_MOUSE }, { "ID_INPUT_POINTINGSTICK", UDEV_POINTINGSTICK }, { "ID_INPUT_TOUCHPAD", UDEV_TOUCHPAD }, { "ID_INPUT_TABLET", UDEV_TABLET }, { "ID_INPUT_TABLET_PAD", UDEV_TABLET_PAD }, { "ID_INPUT_JOYSTICK", UDEV_JOYSTICK }, { "ID_INPUT_KEYBOARD", UDEV_KEYBOARD }, { "ID_INPUT_KEY", UDEV_KEYBOARD }, }; ARRAY_FOR_EACH(mappings, map) { if (udev_prop(device, map->prop)) m->udev_type |= map->flag; } m->bits |= M_UDEV_TYPE; } static inline void match_fill_dmi_dt(struct match *m, char *dmi, char *dt) { if (dmi) { m->dmi = dmi; m->bits |= M_DMI; } if (dt) { m->dt = dt; m->bits |= M_DT; } } static struct match * match_new(struct udev_device *device, char *dmi, char *dt) { struct match *m = zalloc(sizeof *m); match_fill_name(m, device); match_fill_uniq(m, device); match_fill_bus_vid_pid(m, device); match_fill_dmi_dt(m, dmi, dt); match_fill_udev_type(m, device); return m; } static void match_free(struct match *m) { /* dmi and dt are global */ free(m->name); free(m->uniq); free(m); } static void quirk_merge_event_codes(struct quirks_context *ctx, struct quirks *q, const struct property *property) { for (size_t i = 0; i < q->nproperties; i++) { struct property *p = q->properties[i]; if (p->id != property->id) continue; /* We have a duplicated property, merge in with ours */ size_t offset = p->value.tuples.ntuples; size_t max = ARRAY_LENGTH(p->value.tuples.tuples); for (size_t j = 0; j < property->value.tuples.ntuples; j++) { if (offset + j >= max) break; p->value.tuples.tuples[offset + j] = property->value.tuples.tuples[j]; p->value.tuples.ntuples++; } return; } /* First time we add AttrEventCode: create a new property. * Unlike the other properties, this one isn't part of a section, it belongs * to the quirks */ struct property *newprop = property_new(); newprop->id = property->id; newprop->type = property->type; newprop->value.tuples = property->value.tuples; /* Caller responsible for pre-allocating space */ q->properties[q->nproperties++] = property_ref(newprop); list_append(&q->floating_properties, &newprop->link); } static void quirk_apply_section(struct quirks_context *ctx, struct quirks *q, const struct section *s) { struct property *p; size_t nprops = 0; void *tmp; list_for_each(p, &s->properties, link) { nprops++; } nprops += q->nproperties; tmp = realloc(q->properties, nprops * sizeof(p)); if (!tmp) return; q->properties = tmp; list_for_each(p, &s->properties, link) { qlog_debug(ctx, "property added: %s from %s\n", quirk_get_name(p->id), s->name); /* All quirks but AttrEventCode and AttrInputProp * simply overwrite each other, so we can just append the * matching property and, later when checking the quirk, pick * the last one in the array. * * The event codes/input props are special because they're lists * that may *partially* override each other, e.g. a section may * enable BTN_LEFT and BTN_RIGHT but a later section may disable * only BTN_RIGHT. This should result in BTN_LEFT force-enabled * and BTN_RIGHT force-disabled. * * To hack around this, those are the only ones where only ever * have one struct property in the list (not owned by a section) * and we simply merge any extra sections onto that. */ if (p->id == QUIRK_ATTR_EVENT_CODE || p->id == QUIRK_ATTR_INPUT_PROP) quirk_merge_event_codes(ctx, q, p); else q->properties[q->nproperties++] = property_ref(p); } } static bool quirk_match_section(struct quirks_context *ctx, struct quirks *q, struct section *s, struct match *m, struct udev_device *device) { uint32_t matched_flags = 0x0; for (uint32_t flag = 0x1; flag <= M_LAST; flag <<= 1) { uint32_t prev_matched_flags = matched_flags; /* section doesn't have this bit set, continue */ if ((s->match.bits & flag) == 0) continue; /* Couldn't fill in this bit for the match, so we * do not match on it */ if ((m->bits & flag) == 0) { qlog_debug(ctx, "%s wants %s but we don't have that\n", s->name, matchflagname(flag)); continue; } /* now check the actual matching bit */ switch (flag) { case M_NAME: if (fnmatch(s->match.name, m->name, 0) == 0) matched_flags |= flag; break; case M_UNIQ: if (fnmatch(s->match.uniq, m->uniq, 0) == 0) matched_flags |= flag; break; case M_BUS: if (m->bus == s->match.bus) matched_flags |= flag; break; case M_VID: if (m->vendor == s->match.vendor) matched_flags |= flag; break; case M_PID: ARRAY_FOR_EACH(m->product, mi) { if (*mi == 0 || matched_flags & flag) break; ARRAY_FOR_EACH(s->match.product, si) { if (*si == 0) break; if (*mi == *si) { matched_flags |= flag; break; } } } break; case M_VERSION: if (m->version == s->match.version) matched_flags |= flag; break; case M_DMI: if (fnmatch(s->match.dmi, m->dmi, 0) == 0) matched_flags |= flag; break; case M_DT: if (fnmatch(s->match.dt, m->dt, 0) == 0) matched_flags |= flag; break; case M_UDEV_TYPE: if (s->match.udev_type & m->udev_type) matched_flags |= flag; break; default: abort(); } if (prev_matched_flags != matched_flags) { qlog_debug(ctx, "%s matches for %s\n", s->name, matchflagname(flag)); } } if (s->match.bits == matched_flags) { qlog_debug(ctx, "%s is full match\n", s->name); quirk_apply_section(ctx, q, s); } return true; } struct quirks * quirks_fetch_for_device(struct quirks_context *ctx, struct udev_device *udev_device) { struct quirks *q = NULL; struct section *s; struct match *m; if (!ctx) return NULL; qlog_debug(ctx, "%s: fetching quirks\n", udev_device_get_devnode(udev_device)); q = quirks_new(); m = match_new(udev_device, ctx->dmi, ctx->dt); list_for_each(s, &ctx->sections, link) { quirk_match_section(ctx, q, s, m, udev_device); } match_free(m); if (q->nproperties == 0) { quirks_unref(q); return NULL; } list_insert(&ctx->quirks, &q->link); return q; } static inline struct property * quirk_find_prop(struct quirks *q, enum quirk which) { /* Run backwards to only handle the last one assigned */ for (ssize_t i = q->nproperties - 1; i >= 0; i--) { struct property *p = q->properties[i]; if (p->id == which) return p; } return NULL; } bool quirks_has_quirk(struct quirks *q, enum quirk which) { return quirk_find_prop(q, which) != NULL; } bool quirks_get_int32(struct quirks *q, enum quirk which, int32_t *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_INT); *val = p->value.i; return true; } bool quirks_get_uint32(struct quirks *q, enum quirk which, uint32_t *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_UINT); *val = p->value.u; return true; } bool quirks_get_double(struct quirks *q, enum quirk which, double *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_DOUBLE); *val = p->value.d; return true; } bool quirks_get_string(struct quirks *q, enum quirk which, char **val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_STRING); *val = p->value.s; return true; } bool quirks_get_bool(struct quirks *q, enum quirk which, bool *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_BOOL); *val = p->value.b; return true; } bool quirks_get_dimensions(struct quirks *q, enum quirk which, struct quirk_dimensions *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_DIMENSION); *val = p->value.dim; return true; } bool quirks_get_range(struct quirks *q, enum quirk which, struct quirk_range *val) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_RANGE); *val = p->value.range; return true; } bool quirks_get_tuples(struct quirks *q, enum quirk which, const struct quirk_tuples **tuples) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_TUPLES); *tuples = &p->value.tuples; return true; } bool quirks_get_uint32_array(struct quirks *q, enum quirk which, const uint32_t **array, size_t *nelements) { struct property *p; if (!q) return false; p = quirk_find_prop(q, which); if (!p) return false; assert(p->type == PT_UINT_ARRAY); *array = p->value.array.data.u; *nelements = p->value.array.nelements; return true; } libinput-1.28.1/src/quirks.h000066400000000000000000000217561477265155700157450ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #include "libinput.h" /** * Handle to the quirks context. */ struct quirks_context; /** * Contains all quirks set for a single device. */ struct quirks; struct quirk_dimensions { size_t x, y; }; struct quirk_range { int lower, upper; }; struct quirk_tuples { struct { int first; int second; int third; } tuples[32]; size_t ntuples; }; /** * Quirks known to libinput */ enum quirk { QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD = 100, QUIRK_MODEL_APPLE_TOUCHPAD, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON, QUIRK_MODEL_BOUNCING_KEYS, QUIRK_MODEL_CHROMEBOOK, QUIRK_MODEL_CLEVO_W740SU, QUIRK_MODEL_DELL_CANVAS_TOTEM, QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD, QUIRK_MODEL_HP_ZBOOK_STUDIO_G3, QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING, QUIRK_MODEL_LENOVO_SCROLLPOINT, QUIRK_MODEL_LENOVO_T450_TOUCHPAD, QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD, QUIRK_MODEL_LENOVO_X230, QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD, QUIRK_MODEL_SYSTEM76_BONOBO, QUIRK_MODEL_SYSTEM76_GALAGO, QUIRK_MODEL_SYSTEM76_KUDU, QUIRK_MODEL_TABLET_MODE_NO_SUSPEND, QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE, QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER, QUIRK_MODEL_TRACKBALL, QUIRK_MODEL_WACOM_TOUCHPAD, QUIRK_MODEL_PRESSURE_PAD, QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS, _QUIRK_LAST_MODEL_QUIRK_, /* Guard: do not modify */ QUIRK_ATTR_SIZE_HINT = 300, QUIRK_ATTR_TOUCH_SIZE_RANGE, QUIRK_ATTR_PALM_SIZE_THRESHOLD, QUIRK_ATTR_LID_SWITCH_RELIABILITY, QUIRK_ATTR_KEYBOARD_INTEGRATION, QUIRK_ATTR_TRACKPOINT_INTEGRATION, QUIRK_ATTR_TPKBCOMBO_LAYOUT, QUIRK_ATTR_PRESSURE_RANGE, QUIRK_ATTR_PALM_PRESSURE_THRESHOLD, QUIRK_ATTR_RESOLUTION_HINT, QUIRK_ATTR_TRACKPOINT_MULTIPLIER, QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD, QUIRK_ATTR_USE_VELOCITY_AVERAGING, QUIRK_ATTR_TABLET_SMOOTHING, QUIRK_ATTR_THUMB_SIZE_THRESHOLD, QUIRK_ATTR_MSC_TIMESTAMP, QUIRK_ATTR_EVENT_CODE, QUIRK_ATTR_INPUT_PROP, _QUIRK_LAST_ATTR_QUIRK_, /* Guard: do not modify */ }; /** * Returns a printable name for the quirk. This name is for developer * tools, not user consumption. Do not display this in a GUI. */ const char* quirk_get_name(enum quirk q); /** * Log priorities used if custom logging is enabled. */ enum quirks_log_priorities { QLOG_NOISE, QLOG_DEBUG = LIBINPUT_LOG_PRIORITY_DEBUG, QLOG_INFO = LIBINPUT_LOG_PRIORITY_INFO, QLOG_ERROR = LIBINPUT_LOG_PRIORITY_ERROR, QLOG_PARSER_ERROR, }; /** * Log type to be used for logging. Use the libinput logging to hook up a * libinput log handler. This will cause the quirks to reduce the noise and * only provide useful messages. * * QLOG_CUSTOM_LOG_PRIORITIES enables more fine-grained and verbose logging, * allowing debugging tools to be more useful. */ enum quirks_log_type { QLOG_LIBINPUT_LOGGING, QLOG_CUSTOM_LOG_PRIORITIES, }; /** * Initialize the quirks subsystem. This function must be called * before anything else. * * If log_type is QLOG_CUSTOM_LOG_PRIORITIES, the log handler is called with * the custom QLOG_* log priorities. Otherwise, the log handler only uses * the libinput log priorities. * * @param data_path The directory containing the various data files * @param override_file A file path containing custom overrides * @param log_handler The libinput log handler called for debugging output * @param libinput The libinput struct passed to the log handler * * @return an opaque handle to the context */ struct quirks_context * quirks_init_subsystem(const char *data_path, const char *override_file, libinput_log_handler log_handler, struct libinput *libinput, enum quirks_log_type log_type); /** * Clean up after ourselves. This function must be called * as the last call to the quirks subsystem. * * All quirks returned to the caller in quirks_fetch_for_device() must be * unref'd before this call. * * @return Always NULL */ struct quirks_context * quirks_context_unref(struct quirks_context *ctx); struct quirks_context * quirks_context_ref(struct quirks_context *ctx); /** * Fetch the quirks for a given device. If no quirks are defined, this * function returns NULL. * * @return A new quirks struct, use quirks_unref() to release */ struct quirks * quirks_fetch_for_device(struct quirks_context *ctx, struct udev_device *device); /** * Reduce the refcount by one. When the refcount reaches zero, the * associated struct is released. * * @return Always NULL */ struct quirks * quirks_unref(struct quirks *q); /** * Returns true if the given quirk applies is in this quirk list. */ bool quirks_has_quirk(struct quirks *q, enum quirk which); /** * Get the value of the given quirk, as unsigned integer. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_uint32(struct quirks *q, enum quirk which, uint32_t *val); /** * Get the value of the given quirk, as signed integer. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_int32(struct quirks *q, enum quirk which, int32_t *val); /** * Get the value of the given quirk, as double. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_double(struct quirks *q, enum quirk which, double *val); /** * Get the value of the given quirk, as string. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * val is set to the string, do not modify or free it. The lifetime of the * returned string is bound to the lifetime of the quirk. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_string(struct quirks *q, enum quirk which, char **val); /** * Get the value of the given quirk, as bool. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_bool(struct quirks *q, enum quirk which, bool *val); /** * Get the value of the given quirk, as dimension. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_dimensions(struct quirks *q, enum quirk which, struct quirk_dimensions *val); /** * Get the value of the given quirk, as range. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, val is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_range(struct quirks *q, enum quirk which, struct quirk_range *val); /** * Get the tuples of the given quirk. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, tuples is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_tuples(struct quirks *q, enum quirk which, const struct quirk_tuples **tuples); /** * Get the uint32 array of the given quirk. * This function will assert if the quirk type does not match the * requested type. If the quirk is not set for this device, tuples is * unchanged. * * @return true if the quirk value is valid, false otherwise. */ bool quirks_get_uint32_array(struct quirks *q, enum quirk which, const uint32_t **array, size_t *nelements); libinput-1.28.1/src/timer.c000066400000000000000000000153611477265155700155350ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include "libinput-private.h" #include "timer.h" void libinput_timer_init(struct libinput_timer *timer, struct libinput *libinput, const char *timer_name, void (*timer_func)(uint64_t now, void *timer_func_data), void *timer_func_data) { timer->libinput = libinput; timer->timer_name = safe_strdup(timer_name); timer->timer_func = timer_func; timer->timer_func_data = timer_func_data; /* at most 5 "expiry in the past" log messages per hour */ ratelimit_init(&libinput->timer.expiry_in_past_limit, s2us(60 * 60), 5); } void libinput_timer_destroy(struct libinput_timer *timer) { if (timer->link.prev != NULL && timer->link.next != NULL && !list_empty(&timer->link)) { log_bug_libinput(timer->libinput, "timer: %s has not been cancelled\n", timer->timer_name); assert(!"timer not cancelled"); } free(timer->timer_name); } static void libinput_timer_arm_timer_fd(struct libinput *libinput) { int r; struct libinput_timer *timer; struct itimerspec its = { { 0, 0 }, { 0, 0 } }; uint64_t earliest_expire = UINT64_MAX; list_for_each(timer, &libinput->timer.list, link) { if (timer->expire < earliest_expire) earliest_expire = timer->expire; } if (earliest_expire != UINT64_MAX) { its.it_value.tv_sec = earliest_expire / ms2us(1000); its.it_value.tv_nsec = (earliest_expire % ms2us(1000)) * 1000; } r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL); if (r) log_error(libinput, "timer: timerfd_settime error: %s\n", strerror(errno)); libinput->timer.next_expiry = earliest_expire; } void libinput_timer_set_flags(struct libinput_timer *timer, uint64_t expire, uint32_t flags) { #ifndef NDEBUG /* We only warn if we're more than 20ms behind */ const uint64_t timer_warning_limit = ms2us(20); uint64_t now = libinput_now(timer->libinput); if (expire < now) { if ((flags & TIMER_FLAG_ALLOW_NEGATIVE) == 0 && now - expire > timer_warning_limit) log_bug_client_ratelimit(timer->libinput, &timer->libinput->timer.expiry_in_past_limit, "timer %s: scheduled expiry is in the past (-%dms), your system is too slow\n", timer->timer_name, us2ms(now - expire)); } else if ((expire - now) > ms2us(5000)) { log_bug_libinput(timer->libinput, "timer %s: offset more than 5s, now %d expire %d\n", timer->timer_name, us2ms(now), us2ms(expire)); } #endif assert(expire); if (!timer->expire) list_insert(&timer->libinput->timer.list, &timer->link); timer->expire = expire; libinput_timer_arm_timer_fd(timer->libinput); } void libinput_timer_set(struct libinput_timer *timer, uint64_t expire) { libinput_timer_set_flags(timer, expire, TIMER_FLAG_NONE); } void libinput_timer_cancel(struct libinput_timer *timer) { if (!timer->expire) return; timer->expire = 0; list_remove(&timer->link); libinput_timer_arm_timer_fd(timer->libinput); } static void libinput_timer_handler(struct libinput *libinput , uint64_t now) { struct libinput_timer *timer; restart: list_for_each_safe(timer, &libinput->timer.list, link) { if (timer->expire == 0) continue; if (timer->expire <= now) { /* Clear the timer before calling timer_func, as timer_func may re-arm it */ libinput_timer_cancel(timer); timer->timer_func(now, timer->timer_func_data); /* * Restart the loop. We can't use * list_for_each_safe() here because that only * allows removing one (our) timer per timer_func. * But the timer func may trigger another unrelated * timer to be cancelled and removed, causing a * segfault. */ goto restart; } } } static void libinput_timer_dispatch(void *data) { struct libinput *libinput = data; uint64_t now; uint64_t discard; int r; r = read(libinput->timer.fd, &discard, sizeof(discard)); if (r == -1 && errno != EAGAIN) log_bug_libinput(libinput, "timer: error %d reading from timerfd (%s)", errno, strerror(errno)); now = libinput_now(libinput); if (now == 0) return; libinput_timer_handler(libinput, now); } int libinput_timer_subsys_init(struct libinput *libinput) { libinput->timer.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); if (libinput->timer.fd < 0) return -1; list_init(&libinput->timer.list); libinput->timer.source = libinput_add_fd(libinput, libinput->timer.fd, libinput_timer_dispatch, libinput); if (!libinput->timer.source) { close(libinput->timer.fd); return -1; } return 0; } void libinput_timer_subsys_destroy(struct libinput *libinput) { #ifndef NDEBUG if (!list_empty(&libinput->timer.list)) { struct libinput_timer *t; list_for_each(t, &libinput->timer.list, link) { log_bug_libinput(libinput, "timer: %s still present on shutdown\n", t->timer_name); } } #endif /* All timer users should have destroyed their timers now */ assert(list_empty(&libinput->timer.list)); libinput_remove_source(libinput, libinput->timer.source); close(libinput->timer.fd); } /** * For a caller calling libinput_dispatch() only infrequently, we may have a * timer expiry *and* a later input event waiting in the pipe. We cannot * guarantee that we read the timer expiry first, so this hook exists to * flush any timers. * * Assume 'now' is the current time check if there is a current timer expiry * before this time. If so, trigger the timer func. */ void libinput_timer_flush(struct libinput *libinput, uint64_t now) { if (libinput->timer.next_expiry == 0 || libinput->timer.next_expiry > now) return; libinput_timer_handler(libinput, now); } libinput-1.28.1/src/timer.h000066400000000000000000000044271477265155700155430ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef TIMER_H #define TIMER_H #include #include "libinput-util.h" struct libinput; struct libinput_timer { struct libinput *libinput; char *timer_name; struct list link; uint64_t expire; /* in absolute us CLOCK_MONOTONIC */ void (*timer_func)(uint64_t now, void *timer_func_data); void *timer_func_data; }; void libinput_timer_init(struct libinput_timer *timer, struct libinput *libinput, const char *timer_name, void (*timer_func)(uint64_t now, void *timer_func_data), void *timer_func_data); void libinput_timer_destroy(struct libinput_timer *timer); /* Set timer expire time, in absolute us CLOCK_MONOTONIC */ void libinput_timer_set(struct libinput_timer *timer, uint64_t expire); enum timer_flags { TIMER_FLAG_NONE = 0, TIMER_FLAG_ALLOW_NEGATIVE = bit(0), }; void libinput_timer_set_flags(struct libinput_timer *timer, uint64_t expire, uint32_t flags); void libinput_timer_cancel(struct libinput_timer *timer); int libinput_timer_subsys_init(struct libinput *libinput); void libinput_timer_subsys_destroy(struct libinput *libinput); void libinput_timer_flush(struct libinput *libinput, uint64_t now); #endif libinput-1.28.1/src/udev-seat.c000066400000000000000000000257271477265155700163210ustar00rootroot00000000000000/* * Copyright © 2013 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "evdev.h" #include "udev-seat.h" static const char default_seat[] = "seat0"; static const char default_seat_name[] = "default"; static struct udev_seat * udev_seat_create(struct udev_input *input, const char *device_seat, const char *seat_name); static struct udev_seat * udev_seat_get_named(struct udev_input *input, const char *seat_name); static inline bool filter_duplicates(struct udev_seat *udev_seat, struct udev_device *udev_device) { struct libinput_device *device; const char *new_syspath = udev_device_get_syspath(udev_device); bool ignore_device = false; if (!udev_seat) return false; list_for_each(device, &udev_seat->base.devices_list, link) { const char *syspath; struct udev_device *ud; ud = libinput_device_get_udev_device(device); if (!ud) continue; syspath = udev_device_get_syspath(ud); if (syspath && new_syspath && streq(syspath, new_syspath)) ignore_device = true; udev_device_unref(ud); if (ignore_device) break; } return ignore_device; } static int device_added(struct udev_device *udev_device, struct udev_input *input, const char *seat_name) { struct evdev_device *device; const char *devnode, *sysname; const char *device_seat, *output_name; struct udev_seat *seat; device_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); if (!device_seat) device_seat = default_seat; if (!streq(device_seat, input->seat_id)) return 0; if (ignore_litest_test_suite_device(udev_device)) return 0; devnode = udev_device_get_devnode(udev_device); sysname = udev_device_get_sysname(udev_device); /* Search for matching logical seat */ if (!seat_name) seat_name = udev_device_get_property_value(udev_device, "WL_SEAT"); if (!seat_name) seat_name = default_seat_name; seat = udev_seat_get_named(input, seat_name); /* There is a race at startup: a device added between setting * up the udev monitor and enumerating all current devices may show * up in both lists. Filter those out. */ if (filter_duplicates(seat, udev_device)) return 0; if (seat) libinput_seat_ref(&seat->base); else { seat = udev_seat_create(input, device_seat, seat_name); if (!seat) return -1; } device = evdev_device_create(&seat->base, udev_device); libinput_seat_unref(&seat->base); if (device == EVDEV_UNHANDLED_DEVICE) { log_info(&input->base, "%-7s - not using input device '%s'\n", sysname, devnode); return 0; } if (device == NULL) { log_info(&input->base, "%-7s - failed to create input device '%s'\n", sysname, devnode); return 0; } evdev_read_calibration_prop(device); output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT"); device->output_name = safe_strdup(output_name); return 0; } static void device_removed(struct udev_device *udev_device, struct udev_input *input) { struct evdev_device *device; struct udev_seat *seat; const char *syspath; syspath = udev_device_get_syspath(udev_device); list_for_each(seat, &input->base.seat_list, base.link) { list_for_each_safe(device, &seat->base.devices_list, base.link) { if (streq(syspath, udev_device_get_syspath(device->udev_device))) { evdev_device_remove(device); break; } } } } static int udev_input_add_devices(struct udev_input *input, struct udev *udev) { struct udev_enumerate *e; struct udev_list_entry *entry; struct udev_device *device; const char *path, *sysname; e = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(e, "input"); udev_enumerate_scan_devices(e); udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { path = udev_list_entry_get_name(entry); device = udev_device_new_from_syspath(udev, path); if (!device) continue; sysname = udev_device_get_sysname(device); if (!strstartswith(sysname, "event")) { udev_device_unref(device); continue; } /* Skip unconfigured device. udev will send an event * when device is fully configured */ if (!udev_device_get_is_initialized(device)) { log_debug(&input->base, "%-7s - skip unconfigured input device '%s'\n", sysname, udev_device_get_devnode(device)); udev_device_unref(device); continue; } if (device_added(device, input, NULL) < 0) { udev_device_unref(device); udev_enumerate_unref(e); return -1; } udev_device_unref(device); } udev_enumerate_unref(e); return 0; } static void evdev_udev_handler(void *data) { struct udev_input *input = data; struct udev_device *udev_device; const char *action; udev_device = udev_monitor_receive_device(input->udev_monitor); if (!udev_device) return; action = udev_device_get_action(udev_device); if (!action) goto out; if (!strstartswith(udev_device_get_sysname(udev_device), "event")) goto out; if (streq(action, "add")) device_added(udev_device, input, NULL); else if (streq(action, "remove")) device_removed(udev_device, input); out: udev_device_unref(udev_device); } static void udev_input_remove_devices(struct udev_input *input) { struct evdev_device *device; struct udev_seat *seat; list_for_each_safe(seat, &input->base.seat_list, base.link) { libinput_seat_ref(&seat->base); list_for_each_safe(device, &seat->base.devices_list, base.link) { evdev_device_remove(device); } libinput_seat_unref(&seat->base); } } static void udev_input_disable(struct libinput *libinput) { struct udev_input *input = (struct udev_input*)libinput; if (!input->udev_monitor) return; udev_monitor_unref(input->udev_monitor); input->udev_monitor = NULL; libinput_remove_source(&input->base, input->udev_monitor_source); input->udev_monitor_source = NULL; udev_input_remove_devices(input); } static int udev_input_enable(struct libinput *libinput) { struct udev_input *input = (struct udev_input*)libinput; struct udev *udev = input->udev; int fd; if (input->udev_monitor || !input->seat_id) return 0; input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); if (!input->udev_monitor) { log_info(libinput, "udev: failed to create the udev monitor\n"); return -1; } if (udev_monitor_filter_add_match_subsystem_devtype( input->udev_monitor, "input", NULL)) { log_info(libinput, "udev: failed to set up filter\n"); return -1; } if (udev_monitor_enable_receiving(input->udev_monitor)) { log_info(libinput, "udev: failed to bind the udev monitor\n"); udev_monitor_unref(input->udev_monitor); input->udev_monitor = NULL; return -1; } fd = udev_monitor_get_fd(input->udev_monitor); input->udev_monitor_source = libinput_add_fd(&input->base, fd, evdev_udev_handler, input); if (!input->udev_monitor_source) { udev_monitor_unref(input->udev_monitor); input->udev_monitor = NULL; return -1; } if (udev_input_add_devices(input, udev) < 0) { udev_input_disable(libinput); return -1; } return 0; } static void udev_input_destroy(struct libinput *input) { struct udev_input *udev_input = (struct udev_input*)input; if (input == NULL) return; udev_unref(udev_input->udev); free(udev_input->seat_id); } static void udev_seat_destroy(struct libinput_seat *seat) { struct udev_seat *useat = (struct udev_seat*)seat; free(useat); } static struct udev_seat * udev_seat_create(struct udev_input *input, const char *device_seat, const char *seat_name) { struct udev_seat *seat; seat = zalloc(sizeof *seat); libinput_seat_init(&seat->base, &input->base, device_seat, seat_name, udev_seat_destroy); return seat; } static struct udev_seat * udev_seat_get_named(struct udev_input *input, const char *seat_name) { struct udev_seat *seat; list_for_each(seat, &input->base.seat_list, base.link) { if (streq(seat->base.logical_name, seat_name)) return seat; } return NULL; } static int udev_device_change_seat(struct libinput_device *device, const char *seat_name) { struct libinput *libinput = device->seat->libinput; struct udev_input *input = (struct udev_input *)libinput; struct evdev_device *evdev = evdev_device(device); struct udev_device *udev_device = evdev->udev_device; int rc; udev_device_ref(udev_device); device_removed(udev_device, input); rc = device_added(udev_device, input, seat_name); udev_device_unref(udev_device); return rc; } static const struct libinput_interface_backend interface_backend = { .resume = udev_input_enable, .suspend = udev_input_disable, .destroy = udev_input_destroy, .device_change_seat = udev_device_change_seat, }; LIBINPUT_EXPORT struct libinput * libinput_udev_create_context(const struct libinput_interface *interface, void *user_data, struct udev *udev) { struct udev_input *input; if (!interface || !udev) return NULL; input = zalloc(sizeof *input); if (libinput_init(&input->base, interface, &interface_backend, user_data) != 0) { libinput_unref(&input->base); free(input); return NULL; } input->udev = udev_ref(udev); return &input->base; } LIBINPUT_EXPORT int libinput_udev_assign_seat(struct libinput *libinput, const char *seat_id) { struct udev_input *input = (struct udev_input*)libinput; if (!seat_id) return -1; if (strlen(seat_id) > 256) { log_bug_client(libinput, "Unexpected seat id, limited to 256 characters.\n"); return -1; } if (libinput->interface_backend != &interface_backend) { log_bug_client(libinput, "Mismatching backends.\n"); return -1; } if (input->seat_id != NULL) return -1; /* We cannot do this during udev_create_context because the log * handler isn't set up there but we really want to log to the right * place if the quirks run into parser errors. So we have to do it * here since we can expect the log handler to be set up by now. */ libinput_init_quirks(libinput); input->seat_id = safe_strdup(seat_id); if (udev_input_enable(&input->base) < 0) return -1; return 0; } libinput-1.28.1/src/udev-seat.h000066400000000000000000000027321477265155700163150ustar00rootroot00000000000000/* * Copyright © 2013 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef _UDEV_SEAT_H_ #define _UDEV_SEAT_H_ #include "config.h" #include #include "libinput-private.h" struct udev_seat { struct libinput_seat base; }; struct udev_input { struct libinput base; struct udev *udev; struct udev_monitor *udev_monitor; struct libinput_source *udev_monitor_source; char *seat_id; }; #endif libinput-1.28.1/src/util-backtrace.h000066400000000000000000000064521477265155700173150ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include "util-macros.h" #include "util-strings.h" /** * Print a backtrace for this process using gstack. * * If use_colors is true, highlight_after may specify * a substring for a line after which the remaining backtrace is * colored. * * If use_colors is true, highlight_before may specify * a substring for a line before which the backtrace is * colored. * * If use_colors is true, highlight_extra may specify * a substring for a line that has extra highlighting. */ static inline void backtrace_print(FILE *fp, bool use_colors, const char *highlight_after, const char *highlight_before, const char *highlight_extra) { #if HAVE_GSTACK pid_t parent, child; int pipefd[2]; if (pipe(pipefd) == -1) return; parent = getpid(); child = fork(); if (child == 0) { char pid[8]; close(pipefd[0]); dup2(pipefd[1], STDOUT_FILENO); sprintf(pid, "%d", parent); execlp("gstack", "gstack", pid, NULL); exit(errno); } /* parent */ int status; close(pipefd[1]); waitpid(child, &status, 0); status = WEXITSTATUS(status); if (status != 0) { fprintf(fp, "ERROR: gstack failed, no backtrace available: %s\n", strerror(status)); goto out; } char buf[2048] = {0}; fprintf(fp, "\nBacktrace:\n"); read(pipefd[0], buf, sizeof(buf) - 1); if (!use_colors || (!highlight_after && !highlight_before)) { fprintf(fp, "%s\n", buf); } else { size_t nlines; char **lines = strv_from_string(buf, "\n", &nlines); char **line = lines; bool highlight = highlight_after == NULL; while (line && *line) { if (highlight && highlight_before && strstr(*line, highlight_before)) highlight = false; const char *hlcolor = highlight ? ANSI_BRIGHT_CYAN : ""; if (highlight && highlight_extra && strstr(*line, highlight_extra)) hlcolor = ANSI_BRIGHT_MAGENTA; fprintf(fp, "%s%s%s\n", hlcolor, *line, highlight ? ANSI_NORMAL : ""); if (!highlight && highlight_after && strstr(*line, highlight_after)) highlight = true; line++; } strv_free(lines); } out: close(pipefd[0]); #endif } libinput-1.28.1/src/util-bits.h000066400000000000000000000053041477265155700163320ustar00rootroot00000000000000/* * Copyright © 2008-2011 Kristian Høgsberg * Copyright © 2011 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #define bit(x_) (1UL << (x_)) #define NBITS(b) (b * 8) #define LONG_BITS (sizeof(long) * 8) #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) #define NCHARS(x) ((size_t)(((x) + 7) / 8)) /* This bitfield helper implementation is taken from from libevdev-util.h, * except that it has been modified to work with arrays of unsigned chars */ static inline bool bit_is_set(const unsigned char *array, int bit) { return !!(array[bit / 8] & (1 << (bit % 8))); } static inline void set_bit(unsigned char *array, int bit) { array[bit / 8] |= (1 << (bit % 8)); } static inline void clear_bit(unsigned char *array, int bit) { array[bit / 8] &= ~(1 << (bit % 8)); } static inline bool long_bit_is_set(const unsigned long *array, int bit) { return !!(array[bit / LONG_BITS] & (1ULL << (bit % LONG_BITS))); } static inline void long_set_bit(unsigned long *array, int bit) { array[bit / LONG_BITS] |= (1ULL << (bit % LONG_BITS)); } static inline void long_clear_bit(unsigned long *array, int bit) { array[bit / LONG_BITS] &= ~(1ULL << (bit % LONG_BITS)); } static inline void long_set_bit_state(unsigned long *array, int bit, int state) { if (state) long_set_bit(array, bit); else long_clear_bit(array, bit); } static inline bool long_any_bit_set(unsigned long *array, size_t size) { unsigned long i; assert(size > 0); for (i = 0; i < size; i++) if (array[i] != 0) return true; return false; } libinput-1.28.1/src/util-files.h000066400000000000000000000032271477265155700164750ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #include #include "util-strings.h" static inline int mkdir_p(const char *dir) { char *path, *parent; int rc; if (streq(dir, "/")) return 0; path = safe_strdup(dir); parent = dirname(path); if ((rc = mkdir_p(parent)) < 0) return rc; rc = mkdir(dir, 0755); free(path); return (rc == -1 && errno != EEXIST) ? -errno : 0; } static inline void xclose(int *fd) { if (*fd > -1) { close(*fd); *fd = -1; } } libinput-1.28.1/src/util-input-event.h000066400000000000000000000052621477265155700176520ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include "util-time.h" #include static inline struct input_event input_event_init(uint64_t time, unsigned int type, unsigned int code, int value) { struct input_event ev; struct timeval tval = us2tv(time); ev.input_event_sec = tval.tv_sec; ev.input_event_usec = tval.tv_usec; ev.type = type; ev.code = code; ev.value = value; return ev; } static inline uint64_t input_event_time(const struct input_event *e) { struct timeval tval; tval.tv_sec = e->input_event_sec; tval.tv_usec = e->input_event_usec; return tv2us(&tval); } static inline void input_event_set_time(struct input_event *e, uint64_t time) { struct timeval tval = us2tv(time); e->input_event_sec = tval.tv_sec; e->input_event_usec = tval.tv_usec; } static inline double absinfo_range(const struct input_absinfo *abs) { return (double)(abs->maximum - abs->minimum + 1); } static inline double absinfo_normalize_value(const struct input_absinfo *abs, int value) { return min(1.0, max(0.0, (double)(value - abs->minimum)/(abs->maximum - abs->minimum))); } static inline double absinfo_normalize(const struct input_absinfo *abs) { return absinfo_normalize_value(abs, abs->value); } static inline double absinfo_scale_axis(const struct input_absinfo *absinfo, double val, double to_range) { return (val - absinfo->minimum) * to_range / absinfo_range(absinfo); } static inline double absinfo_convert_to_mm(const struct input_absinfo *absinfo, double v) { double value = v - absinfo->minimum; return value/absinfo->resolution; } libinput-1.28.1/src/util-libinput.c000066400000000000000000000760641477265155700172250ustar00rootroot00000000000000/* * Copyright © 2025 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libevdev/libevdev.h" #include "util-strings.h" #include "util-libinput.h" static const char * event_type_to_str(enum libinput_event_type evtype) { const char *type; switch(evtype) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: type = "DEVICE_ADDED"; break; case LIBINPUT_EVENT_DEVICE_REMOVED: type = "DEVICE_REMOVED"; break; case LIBINPUT_EVENT_KEYBOARD_KEY: type = "KEYBOARD_KEY"; break; case LIBINPUT_EVENT_POINTER_MOTION: type = "POINTER_MOTION"; break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: type = "POINTER_MOTION_ABSOLUTE"; break; case LIBINPUT_EVENT_POINTER_BUTTON: type = "POINTER_BUTTON"; break; case LIBINPUT_EVENT_POINTER_AXIS: type = "POINTER_AXIS"; break; case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: type = "POINTER_SCROLL_WHEEL"; break; case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: type = "POINTER_SCROLL_FINGER"; break; case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: type = "POINTER_SCROLL_CONTINUOUS"; break; case LIBINPUT_EVENT_TOUCH_DOWN: type = "TOUCH_DOWN"; break; case LIBINPUT_EVENT_TOUCH_MOTION: type = "TOUCH_MOTION"; break; case LIBINPUT_EVENT_TOUCH_UP: type = "TOUCH_UP"; break; case LIBINPUT_EVENT_TOUCH_CANCEL: type = "TOUCH_CANCEL"; break; case LIBINPUT_EVENT_TOUCH_FRAME: type = "TOUCH_FRAME"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: type = "GESTURE_SWIPE_BEGIN"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: type = "GESTURE_SWIPE_UPDATE"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_END: type = "GESTURE_SWIPE_END"; break; case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: type = "GESTURE_PINCH_BEGIN"; break; case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: type = "GESTURE_PINCH_UPDATE"; break; case LIBINPUT_EVENT_GESTURE_PINCH_END: type = "GESTURE_PINCH_END"; break; case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: type = "GESTURE_HOLD_BEGIN"; break; case LIBINPUT_EVENT_GESTURE_HOLD_END: type = "GESTURE_HOLD_END"; break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: type = "TABLET_TOOL_AXIS"; break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: type = "TABLET_TOOL_PROXIMITY"; break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: type = "TABLET_TOOL_TIP"; break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: type = "TABLET_TOOL_BUTTON"; break; case LIBINPUT_EVENT_TABLET_PAD_BUTTON: type = "TABLET_PAD_BUTTON"; break; case LIBINPUT_EVENT_TABLET_PAD_RING: type = "TABLET_PAD_RING"; break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: type = "TABLET_PAD_STRIP"; break; case LIBINPUT_EVENT_TABLET_PAD_KEY: type = "TABLET_PAD_KEY"; break; case LIBINPUT_EVENT_TABLET_PAD_DIAL: type = "TABLET_PAD_DIAL"; break; case LIBINPUT_EVENT_SWITCH_TOGGLE: type = "SWITCH_TOGGLE"; break; } return type; } static char * print_event_header(struct libinput_event *ev, size_t event_count) { /* use for pointer value only, do not dereference */ static void *last_device = NULL; struct libinput_device *dev = libinput_event_get_device(ev); const char *type = event_type_to_str(libinput_event_get_type(ev)); char count[10]; if (event_count > 1) snprintf(count, sizeof(count), "%3zd ", event_count); else snprintf(count, sizeof(count), " "); char prefix = (last_device != dev) ? '-' : ' '; last_device = dev; return strdup_printf("%c%-7s %-23s %s", prefix, libinput_device_get_sysname(dev), type, count); } static void print_event_time(char buf[16], uint32_t start_time, uint32_t time) { snprintf(buf, 16, "%+6.3fs", start_time ? (time - start_time) / 1000.0 : 0); } static inline char * print_device_options(struct libinput_device *dev) { uint32_t scroll_methods, click_methods; char *tap = NULL, *scroll = NULL, *clickm = NULL, *dwt = NULL, *dwtp = NULL, *pad = NULL; if (libinput_device_config_tap_get_finger_count(dev)) { tap = strdup_printf(" tap (dl %s)", onoff(libinput_device_config_tap_get_drag_lock_enabled(dev))); } scroll_methods = libinput_device_config_scroll_get_methods(dev); if (scroll_methods != LIBINPUT_CONFIG_SCROLL_NO_SCROLL) { scroll = strdup_printf(" scroll%s%s%s", (scroll_methods & LIBINPUT_CONFIG_SCROLL_2FG) ? "-2fg" : "", (scroll_methods & LIBINPUT_CONFIG_SCROLL_EDGE) ? "-edge" : "", (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "-button" : ""); } click_methods = libinput_device_config_click_get_methods(dev); if (click_methods != LIBINPUT_CONFIG_CLICK_METHOD_NONE) { clickm = strdup_printf(" click%s%s", (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "-buttonareas" : "", (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "-clickfinger" : ""); } if (libinput_device_config_dwt_is_available(dev)) { dwt = strdup_printf(" dwt-%s", onoff(libinput_device_config_dwt_get_enabled(dev) == LIBINPUT_CONFIG_DWT_ENABLED)); } if (libinput_device_config_dwtp_is_available(dev)) { dwt = strdup_printf(" dwtp-%s", onoff(libinput_device_config_dwtp_get_enabled(dev) == LIBINPUT_CONFIG_DWTP_ENABLED)); } if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) { pad = strdup_printf(" buttons:%d strips:%d rings:%d mode groups:%d", libinput_device_tablet_pad_get_num_buttons(dev), libinput_device_tablet_pad_get_num_strips(dev), libinput_device_tablet_pad_get_num_rings(dev), libinput_device_tablet_pad_get_num_mode_groups(dev)); } char *str = strdup_printf("%s%s%s%s%s%s%s%s%s", tap ? tap : "", libinput_device_config_left_handed_is_available(dev) ? " left" : "", libinput_device_config_scroll_has_natural_scroll(dev) ? " scroll-nat" : "", libinput_device_config_calibration_has_matrix(dev) ? " calib" : "", scroll ? scroll : "", clickm ? clickm : "", dwt ? dwt : "", dwtp ? dwtp : "", pad ? pad : ""); free(tap); free(scroll); free(clickm); free(dwt); free(dwtp); free(pad); return str; } static char * print_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); struct libinput_seat *seat = libinput_device_get_seat(dev); struct libinput_device_group *group; double w, h; static int next_group_id = 0; intptr_t group_id; char *size = NULL, *ntouches = NULL, *options = NULL; group = libinput_device_get_device_group(dev); group_id = (intptr_t)libinput_device_group_get_user_data(group); if (!group_id) { group_id = ++next_group_id; libinput_device_group_set_user_data(group, (void*)group_id); } if (libinput_device_get_size(dev, &w, &h) == 0) size = strdup_printf(" size %.0fx%.0fmm", w, h); if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH)) ntouches = strdup_printf(" ntouches %d", libinput_device_touch_get_touch_count(dev)); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) options = print_device_options(dev); char *str = strdup_printf("%-33s %5s %7s group%-2d cap:%s%s%s%s%s%s%s%s%s%s", libinput_device_get_name(dev), libinput_seat_get_physical_name(seat), libinput_seat_get_logical_name(seat), (int)group_id, libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_KEYBOARD) ? "k" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_POINTER) ? "p" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH) ? "t" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_GESTURE) ? "g" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL) ? "T" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_PAD) ? "P" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_SWITCH) ? "S" : "", size ? size : "", ntouches ? ntouches : "", options ? options : ""); free(size); free(ntouches); free(options); return str; } static char * print_key_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev); enum libinput_key_state state; uint32_t key; const char *keyname; char time[16]; print_event_time(time, opts->start_time, libinput_event_keyboard_get_time(k)); state = libinput_event_keyboard_get_key_state(k); key = libinput_event_keyboard_get_key(k); if (!opts->show_keycodes && (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) { keyname = "***"; key = -1; } else { keyname = libevdev_event_code_get_name(EV_KEY, key); keyname = keyname ? keyname : "???"; } return strdup_printf("%s\t%s (%d) %s", time, keyname, key, state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released"); } static char * print_motion_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double x = libinput_event_pointer_get_dx(p); double y = libinput_event_pointer_get_dy(p); double ux = libinput_event_pointer_get_dx_unaccelerated(p); double uy = libinput_event_pointer_get_dy_unaccelerated(p); char time[16]; print_event_time(time, opts->start_time, libinput_event_pointer_get_time(p)); return strdup_printf("%s\t%6.2f/%6.2f (%+6.2f/%+6.2f)", time, x, y, ux, uy); } static char * print_absmotion_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double x = libinput_event_pointer_get_absolute_x_transformed( p, opts->screen_width); double y = libinput_event_pointer_get_absolute_y_transformed( p, opts->screen_height); char time[16]; print_event_time(time, opts->start_time, libinput_event_pointer_get_time(p)); return strdup_printf("%s\t%6.2f/%6.2f", time, x, y); } static char * print_pointer_button_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); enum libinput_button_state state; const char *buttonname; int button; char time[16]; print_event_time(time, opts->start_time, libinput_event_pointer_get_time(p)); button = libinput_event_pointer_get_button(p); buttonname = libevdev_event_code_get_name(EV_KEY, button); state = libinput_event_pointer_get_button_state(p); return strdup_printf("%s\t%s (%d) %s, seat count: %u", time, buttonname ? buttonname : "???", button, state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", libinput_event_pointer_get_seat_button_count(p)); } static char * print_tablet_axes(struct libinput_event_tablet_tool *t) { struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); double x, y; char *tilt = NULL, *distance = NULL, *rot = NULL, *whl = NULL, *sld = NULL, *size = NULL; #define changed_sym(ev, ax) \ (libinput_event_tablet_tool_##ax##_has_changed(ev) ? "*" : "") if (libinput_tablet_tool_has_tilt(tool)) { x = libinput_event_tablet_tool_get_tilt_x(t); y = libinput_event_tablet_tool_get_tilt_y(t); tilt = strdup_printf("\ttilt: %.2f%s/%.2f%s", x, changed_sym(t, tilt_x), y, changed_sym(t, tilt_y)); } if (libinput_tablet_tool_has_distance(tool) || libinput_tablet_tool_has_pressure(tool)) { double dist = libinput_event_tablet_tool_get_distance(t); double pressure = libinput_event_tablet_tool_get_pressure(t); if (dist) distance = strdup_printf("\tdistance: %.2f%s", dist, changed_sym(t, distance)); else distance = strdup_printf("\tpressure: %.2f%s", pressure, changed_sym(t, pressure)); } if (libinput_tablet_tool_has_rotation(tool)) { double rotation = libinput_event_tablet_tool_get_rotation(t); rot = strdup_printf("\trotation: %6.2f%s", rotation, changed_sym(t, rotation)); } if (libinput_tablet_tool_has_slider(tool)) { double slider = libinput_event_tablet_tool_get_slider_position(t); sld = strdup_printf("\tslider: %.2f%s", slider, changed_sym(t, slider)); } if (libinput_tablet_tool_has_wheel(tool)) { double wheel = libinput_event_tablet_tool_get_wheel_delta(t); double delta = libinput_event_tablet_tool_get_wheel_delta_discrete(t); whl = strdup_printf("\twheel: %.2f%s (%d)", wheel, changed_sym(t, wheel), (int)delta); } if (libinput_tablet_tool_has_size(tool)) { double major = libinput_event_tablet_tool_get_size_major(t); double minor = libinput_event_tablet_tool_get_size_minor(t); size = strdup_printf("\tsize: %.2f%s/%.2f%s", major, changed_sym(t, size_major), minor, changed_sym(t, size_minor)); } x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); char *str = strdup_printf("\t%.2f%s/%.2f%s%s%s%s%s%s%s", x, changed_sym(t, x), y, changed_sym(t, y), tilt ? tilt : "", distance ? distance : "", rot ? rot : "", whl ? whl : "", sld ? sld : "", size ? size : ""); free(tilt); free(distance); free(rot); free(whl); free(sld); free(size); return str; } static char * print_tablet_tip_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); enum libinput_tablet_tool_tip_state state; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_tool_get_time(t)); char *axes = print_tablet_axes(t); state = libinput_event_tablet_tool_get_tip_state(t); char *str = strdup_printf("%s\t%s %s", time, axes, state == LIBINPUT_TABLET_TOOL_TIP_DOWN ? "down" : "up"); free(axes); return str; } static char * print_tablet_button_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_tool *p = libinput_event_get_tablet_tool_event(ev); enum libinput_button_state state; const char *buttonname; int button; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_tool_get_time(p)); button = libinput_event_tablet_tool_get_button(p); buttonname = libevdev_event_code_get_name(EV_KEY, button); state = libinput_event_tablet_tool_get_button_state(p); return strdup_printf("%s\ts%3d (%s) %s, seat count: %u", time, button, buttonname ? buttonname : "???", state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", libinput_event_tablet_tool_get_seat_button_count(p)); } static char * print_pointer_axis_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double v = 0, h = 0, v120 = 0, h120 = 0; const char *have_vert = "", *have_horiz = ""; const char *source = NULL; enum libinput_pointer_axis axis; enum libinput_event_type type; char time[16]; type = libinput_event_get_type(ev); switch (type) { case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: source = "wheel"; break; case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: source = "finger"; break; case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: source = "continuous"; break; default: abort(); break; } axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; if (libinput_event_pointer_has_axis(p, axis)) { v = libinput_event_pointer_get_scroll_value(p, axis); if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) v120 = libinput_event_pointer_get_scroll_value_v120(p, axis); have_vert = "*"; } axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; if (libinput_event_pointer_has_axis(p, axis)) { h = libinput_event_pointer_get_scroll_value(p, axis); if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) h120 = libinput_event_pointer_get_scroll_value_v120(p, axis); have_horiz = "*"; } print_event_time(time, opts->start_time, libinput_event_pointer_get_time(p)); return strdup_printf("%s\tvert %.2f/%.1f%s horiz %.2f/%.1f%s (%s)", time, v, v120, have_vert, h, h120, have_horiz, source); } static char * print_tablet_axis_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_tool_get_time(t)); char *axes = print_tablet_axes(t); char *str = strdup_printf("%s\t%s", time, axes); free(axes); return str; } static char * print_proximity_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); enum libinput_tablet_tool_proximity_state state; const char *tool_str, *state_str; char time[16]; char *axes = NULL, *proxin = NULL; switch (libinput_tablet_tool_get_type(tool)) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: tool_str = "pen"; break; case LIBINPUT_TABLET_TOOL_TYPE_ERASER: tool_str = "eraser"; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: tool_str = "brush"; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: tool_str = "pencil"; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: tool_str = "airbrush"; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: tool_str = "mouse"; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: tool_str = "lens"; break; case LIBINPUT_TABLET_TOOL_TYPE_TOTEM: tool_str = "totem"; break; default: abort(); } state = libinput_event_tablet_tool_get_proximity_state(t); print_event_time(time, opts->start_time, libinput_event_tablet_tool_get_time(t)); if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { axes = print_tablet_axes(t); state_str = "proximity-in"; } else if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { axes = print_tablet_axes(t); state_str = "proximity-out"; } else { abort(); } if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { proxin = strdup_printf("\taxes:%s%s%s%s%s%s\tbtn:%s%s%s%s%s%s%s%s%s%s", libinput_tablet_tool_has_distance(tool) ? "d" : "", libinput_tablet_tool_has_pressure(tool) ? "p" : "", libinput_tablet_tool_has_tilt(tool) ? "t" : "", libinput_tablet_tool_has_rotation(tool) ? "r" : "", libinput_tablet_tool_has_slider(tool) ? "s" : "", libinput_tablet_tool_has_wheel(tool) ? "w" : "", libinput_tablet_tool_has_size(tool) ? "S" : "", libinput_tablet_tool_has_button(tool, BTN_TOUCH) ? "T" : "", libinput_tablet_tool_has_button(tool, BTN_STYLUS) ? "S" : "", libinput_tablet_tool_has_button(tool, BTN_STYLUS2) ? "S2" : "", libinput_tablet_tool_has_button(tool, BTN_LEFT) ? "L" : "", libinput_tablet_tool_has_button(tool, BTN_MIDDLE) ? "M" : "", libinput_tablet_tool_has_button(tool, BTN_RIGHT) ? "R" : "", libinput_tablet_tool_has_button(tool, BTN_SIDE) ? "Sd" : "", libinput_tablet_tool_has_button(tool, BTN_EXTRA) ? "Ex" : "", libinput_tablet_tool_has_button(tool, BTN_0) ? "0" : ""); } char *str = strdup_printf("%s\t%s\t%-8s (%#" PRIx64 ", id %#" PRIx64 ") %s%s", time, axes ? axes : "", tool_str, libinput_tablet_tool_get_serial(tool), libinput_tablet_tool_get_tool_id(tool), state_str, proxin ? proxin : ""); free(axes); free(proxin); return str; } static char * print_touch_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_touch *t = libinput_event_get_touch_event(ev); enum libinput_event_type type = libinput_event_get_type(ev); char time[16]; char *slot = NULL, *pos = NULL; print_event_time(time, opts->start_time, libinput_event_touch_get_time(t)); if (type != LIBINPUT_EVENT_TOUCH_FRAME) { slot = strdup_printf("%d (%d)", libinput_event_touch_get_slot(t), libinput_event_touch_get_seat_slot(t)); } if (type == LIBINPUT_EVENT_TOUCH_DOWN || type == LIBINPUT_EVENT_TOUCH_MOTION) { double x = libinput_event_touch_get_x_transformed(t, opts->screen_width); double y = libinput_event_touch_get_y_transformed(t, opts->screen_height); double xmm = libinput_event_touch_get_x(t); double ymm = libinput_event_touch_get_y(t); pos = strdup_printf(" %5.2f/%5.2f (%5.2f/%5.2fmm)", x, y, xmm, ymm); } char *str = strdup_printf("%s\t%s%s", time, slot ? slot : "", pos ? pos : ""); free(slot); free(pos); return str; } static char * print_gesture_event_without_coords(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_gesture *t = libinput_event_get_gesture_event(ev); int finger_count = libinput_event_gesture_get_finger_count(t); int cancelled = 0; enum libinput_event_type type; char time[16]; type = libinput_event_get_type(ev); if (type == LIBINPUT_EVENT_GESTURE_SWIPE_END || type == LIBINPUT_EVENT_GESTURE_PINCH_END || type == LIBINPUT_EVENT_GESTURE_HOLD_END) cancelled = libinput_event_gesture_get_cancelled(t); print_event_time(time, opts->start_time, libinput_event_gesture_get_time(t)); return strdup_printf("%s\t%d%s", time, finger_count, cancelled ? " cancelled" : ""); } static char * print_gesture_event_with_coords(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_gesture *t = libinput_event_get_gesture_event(ev); double dx = libinput_event_gesture_get_dx(t); double dy = libinput_event_gesture_get_dy(t); double dx_unaccel = libinput_event_gesture_get_dx_unaccelerated(t); double dy_unaccel = libinput_event_gesture_get_dy_unaccelerated(t); char time[16]; char *pinch = NULL; print_event_time(time, opts->start_time, libinput_event_gesture_get_time(t)); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_GESTURE_PINCH_UPDATE) { double scale = libinput_event_gesture_get_scale(t); double angle = libinput_event_gesture_get_angle_delta(t); pinch = strdup_printf(" %5.2f @ %5.2f", scale, angle); } char *str = strdup_printf("%s\t%d %5.2f/%5.2f (%5.2f/%5.2f unaccelerated)%s", time, libinput_event_gesture_get_finger_count(t), dx, dy, dx_unaccel, dy_unaccel, pinch ? pinch : ""); free(pinch); return str; } static char * print_tablet_pad_button_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); struct libinput_tablet_pad_mode_group *group; enum libinput_button_state state; unsigned int button, mode; char time[16]; char *toggle = NULL; print_event_time(time, opts->start_time, libinput_event_tablet_pad_get_time(p)); button = libinput_event_tablet_pad_get_button_number(p), state = libinput_event_tablet_pad_get_button_state(p); mode = libinput_event_tablet_pad_get_mode(p); group = libinput_event_tablet_pad_get_mode_group(p); if (libinput_tablet_pad_mode_group_button_is_toggle(group, button)) toggle = " "; return strdup_printf("%3d %s (mode %d)%s", button, state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", mode, toggle ? toggle : ""); } static char * print_tablet_pad_ring_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); const char *source = NULL; unsigned int mode; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_pad_get_time(p)); switch (libinput_event_tablet_pad_get_ring_source(p)) { case LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER: source = "finger"; break; case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN: source = "unknown"; break; } mode = libinput_event_tablet_pad_get_mode(p); return strdup_printf("%s\tring %d position %.2f (source %s) (mode %d)", time, libinput_event_tablet_pad_get_ring_number(p), libinput_event_tablet_pad_get_ring_position(p), source, mode); } static char * print_tablet_pad_strip_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); const char *source = NULL; unsigned int mode; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_pad_get_time(p)); switch (libinput_event_tablet_pad_get_strip_source(p)) { case LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER: source = "finger"; break; case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN: source = "unknown"; break; } mode = libinput_event_tablet_pad_get_mode(p); return strdup_printf("%s\tstrip %d position %.2f (source %s) (mode %d)", time, libinput_event_tablet_pad_get_strip_number(p), libinput_event_tablet_pad_get_strip_position(p), source, mode); } static char * print_tablet_pad_key_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); enum libinput_key_state state; uint32_t key; const char *keyname; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_pad_get_time(p)); key = libinput_event_tablet_pad_get_key(p); if (!opts->show_keycodes && (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) { keyname = "***"; key = -1; } else { keyname = libevdev_event_code_get_name(EV_KEY, key); keyname = keyname ? keyname : "???"; } state = libinput_event_tablet_pad_get_key_state(p); return strdup_printf("%s\t%s (%d) %s", time, keyname, key, state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released"); } static char * print_tablet_pad_dial_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); unsigned int mode; char time[16]; print_event_time(time, opts->start_time, libinput_event_tablet_pad_get_time(p)); mode = libinput_event_tablet_pad_get_mode(p); return strdup_printf("%s\tdial %d delta %.2f (mode %d)", time, libinput_event_tablet_pad_get_dial_number(p), libinput_event_tablet_pad_get_dial_delta_v120(p), mode); } static char * print_switch_event(struct libinput_event *ev, const struct libinput_print_options *opts) { struct libinput_event_switch *sw = libinput_event_get_switch_event(ev); enum libinput_switch_state state; const char *which; char time[16]; print_event_time(time, opts->start_time, libinput_event_switch_get_time(sw)); switch (libinput_event_switch_get_switch(sw)) { case LIBINPUT_SWITCH_LID: which = "lid"; break; case LIBINPUT_SWITCH_TABLET_MODE: which = "tablet-mode"; break; default: abort(); } state = libinput_event_switch_get_switch_state(sw); return strdup_printf("%s\tswitch %s state %d", time, which, state); } char * libinput_event_to_str(struct libinput_event *ev, size_t event_repeat_count, const struct libinput_print_options *options) { enum libinput_event_type type = libinput_event_get_type(ev); char *event_header = print_event_header(ev, event_repeat_count); char *event_str = NULL; struct libinput_print_options opts = { .start_time = options ? options->start_time : 0, .show_keycodes = options ? options->show_keycodes : true, .screen_width = (options && options->screen_width > 0) ? options->screen_width : 100, .screen_height = (options && options->screen_height > 0) ? options->screen_height : 100, }; switch (type) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: event_str = print_device_notify(ev); break; case LIBINPUT_EVENT_DEVICE_REMOVED: event_str = print_device_notify(ev); break; case LIBINPUT_EVENT_KEYBOARD_KEY: event_str = print_key_event(ev, &opts); break; case LIBINPUT_EVENT_POINTER_MOTION: event_str = print_motion_event(ev, &opts); break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: event_str = print_absmotion_event(ev, &opts); break; case LIBINPUT_EVENT_POINTER_BUTTON: event_str = print_pointer_button_event(ev, &opts); break; case LIBINPUT_EVENT_POINTER_AXIS: /* ignore */ break; case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: event_str = print_pointer_axis_event(ev, &opts); break; case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_CANCEL: event_str = print_touch_event(ev, &opts); break; case LIBINPUT_EVENT_TOUCH_FRAME: event_str = print_touch_event(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: event_str = print_gesture_event_with_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_SWIPE_END: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: event_str = print_gesture_event_with_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_PINCH_END: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_GESTURE_HOLD_END: event_str = print_gesture_event_without_coords(ev, &opts); break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: event_str = print_tablet_axis_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: event_str = print_proximity_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: event_str = print_tablet_tip_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: event_str = print_tablet_button_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_PAD_BUTTON: event_str = print_tablet_pad_button_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_PAD_RING: event_str = print_tablet_pad_ring_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: event_str = print_tablet_pad_strip_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_PAD_KEY: event_str = print_tablet_pad_key_event(ev, &opts); break; case LIBINPUT_EVENT_TABLET_PAD_DIAL: event_str = print_tablet_pad_dial_event(ev, &opts); break; case LIBINPUT_EVENT_SWITCH_TOGGLE: event_str = print_switch_event(ev, &opts); break; } char *str = strdup_printf("%s %s", event_header, event_str); free(event_header); free(event_str); return str; } libinput-1.28.1/src/util-libinput.h000066400000000000000000000027131477265155700172200ustar00rootroot00000000000000/* * Copyright © 2025 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include #include "libinput.h" struct libinput_print_options { uint32_t screen_width; uint32_t screen_height; uint32_t start_time; bool show_keycodes; }; char * libinput_event_to_str(struct libinput_event *ev, size_t event_repeat_count, const struct libinput_print_options *opts); libinput-1.28.1/src/util-list.c000066400000000000000000000051641477265155700163430ustar00rootroot00000000000000/* * Copyright © 2008-2011 Kristian Høgsberg * Copyright © 2011 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "util-list.h" void list_init(struct list *list) { *list = LIST_INIT(*list); } void list_insert(struct list *list, struct list *elm) { assert((list->next != NULL && list->prev != NULL) || !"list->next|prev is NULL, possibly missing list_init()"); assert(((elm->next == NULL && elm->prev == NULL) || list_empty(elm)) || !"elm->next|prev is not NULL, list node used twice?"); elm->prev = list; elm->next = list->next; list->next = elm; elm->next->prev = elm; } void list_append(struct list *list, struct list *elm) { assert((list->next != NULL && list->prev != NULL) || !"list->next|prev is NULL, possibly missing list_init()"); assert(((elm->next == NULL && elm->prev == NULL) || list_empty(elm)) || !"elm->next|prev is not NULL, list node used twice?"); elm->next = list; elm->prev = list->prev; list->prev = elm; elm->prev->next = elm; } void list_remove(struct list *elm) { assert((elm->next != NULL && elm->prev != NULL) || !"list->next|prev is NULL, possibly missing list_init()"); elm->prev->next = elm->next; elm->next->prev = elm->prev; elm->next = NULL; elm->prev = NULL; } bool list_empty(const struct list *list) { assert((list->next != NULL && list->prev != NULL) || !"list->next|prev is NULL, possibly missing list_init()"); return list->next == list; } libinput-1.28.1/src/util-list.h000066400000000000000000000133721477265155700163500ustar00rootroot00000000000000/* * Copyright © 2008-2011 Kristian Høgsberg * Copyright © 2011 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include /* * This list data structure is a verbatim copy from wayland-util.h from the * Wayland project; except that wl_ prefix has been removed. */ /** * Doubly linked list implementation. This struct is used for both the list * nodes and the list head. Use like this: * * @code * * struct foo { * struct list list_of_bars; // the list head * }; * * struct bar { * struct list link; // links between the bars * }; * * struct foo *f = zalloc(sizeof *f); * struct bar *b = make_some_bar(); * * list_init(&f->list_of_bars); * list_append(&f->list_of_bars, &b->link); * list_remove(&b->link); * @endcode */ struct list { struct list *prev; struct list *next; }; #define LIST_INIT(l) (struct list){ .prev = &(l), .next = &(l) } /** * Initialize a list head. This function *must* be called once for each list * head. This function *must not* be called for a node to be added to a * list. */ void list_init(struct list *list); /** * Insert an element at the front of the list */ void list_insert(struct list *list, struct list *elm); /** * Append an element to the back of the list */ void list_append(struct list *list, struct list *elm); /** * Remove an element from list. * * Removing a list element is only possible once, the caller must track * whether the list node has already been removed. * */ void list_remove(struct list *elm); /** * Returns true if the given list head is an empty list. */ bool list_empty(const struct list *list); /** * Return the 'type' parent container struct of 'ptr' of which * 'member' is our 'ptr' field. For example: * * @code * struct foo { // the parent container struct * uint32_t a; * struct bar bar_member; // the member field * }; * * struct foo *f = zalloc(sizeof *f); * struct bar *b = &f->bar_member; * struct foo *f2 = container_of(b, struct foo, bar_member); * * assert(f == f2); * @endcode */ #define container_of(ptr, type, member) \ (__typeof__(type) *)((char *)(ptr) - \ offsetof(__typeof__(type), member)) /** * Given a list 'head', return the first entry of type 'pos' that has a * member 'link'. * * The 'pos' argument is solely used to determine the type be returned and * not modified otherwise. It is common to use the same pointer that the * return value of list_first_entry() is assigned to, for example: * * @code * struct foo { * struct list list_of_bars; * }; * * struct bar { * struct list link; * } * * struct foo *f = get_a_foo(); * struct bar *b = 0; // initialize to avoid static analysis errors * b = list_first_entry(&f->list_of_bars, b, link); * @endcode */ #define list_first_entry(head, pointer_of_type, member) \ container_of((head)->next, __typeof__(*pointer_of_type), member) /** * Given a list 'head', return the first entry of type 'container_type' that * has a member 'link'. * * @code * struct foo { * struct list list_of_bars; * }; * * struct bar { * struct list link; * } * * struct foo *f = get_a_foo(); * struct bar *b = list_first_entry(&f->list_of_bars, struct bar, link); * @endcode */ #define list_first_entry_by_type(head, container_type, member) \ container_of((head)->next, container_type, member) /** * Iterate through the list. * * @code * struct foo *f = get_a_foo(); * struct bar *element; * list_for_each(element, &f->list_of_bars, link) { * } * @endcode * * If a list node needs to be removed during iteration, use * list_for_each_safe(). */ #define list_for_each(pos, head, member) \ for (pos = list_first_entry_by_type(head, __typeof__(*pos), member); \ &pos->member != (head); \ pos = list_first_entry_by_type(&pos->member, __typeof__(*pos), member)) /** * Iterate through the list. Equivalent to list_for_each() but allows * calling list_remove() on the element. * * @code * struct foo *f = get_a_foo(); * struct bar *element; * list_for_each(element, tmp, &f->list_of_bars, link) { * list_remove(&element->link); * } * @endcode */ #define list_for_each_safe(pos, head, member) \ for (__typeof__(pos) _tmp = ({ \ pos = list_first_entry_by_type(head, __typeof__(*pos), member); \ list_first_entry_by_type(&pos->member, __typeof__(*_tmp), member); \ }); \ &pos->member != (head); \ pos = _tmp, \ _tmp = list_first_entry_by_type(&pos->member, __typeof__(*_tmp), member)) libinput-1.28.1/src/util-macros.h000066400000000000000000000050511477265155700166540ustar00rootroot00000000000000/* * Copyright © 2008-2011 Kristian Høgsberg * Copyright © 2011 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) /** * Iterate through the array _arr, assigning the variable elem to each * element. elem only exists within the loop. */ #define ARRAY_FOR_EACH(_arr, _elem) \ for (__typeof__((_arr)[0]) *_elem = _arr; \ _elem < (_arr) + ARRAY_LENGTH(_arr); \ _elem++) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define ANSI_HIGHLIGHT "\x1B[0;1;39m" #define ANSI_RED "\x1B[0;31m" #define ANSI_GREEN "\x1B[0;32m" #define ANSI_YELLOW "\x1B[0;33m" #define ANSI_BLUE "\x1B[0;34m" #define ANSI_MAGENTA "\x1B[0;35m" #define ANSI_CYAN "\x1B[0;36m" #define ANSI_BRIGHT_RED "\x1B[0;31;1m" #define ANSI_BRIGHT_GREEN "\x1B[0;32;1m" #define ANSI_BRIGHT_YELLOW "\x1B[0;33;1m" #define ANSI_BRIGHT_BLUE "\x1B[0;34;1m" #define ANSI_BRIGHT_MAGENTA "\x1B[0;35;1m" #define ANSI_BRIGHT_CYAN "\x1B[0;36;1m" #define ANSI_NORMAL "\x1B[0m" #define ANSI_UP "\x1B[%dA" #define ANSI_DOWN "\x1B[%dB" #define ANSI_RIGHT "\x1B[%dC" #define ANSI_LEFT "\x1B[%dD" #define CASE_RETURN_STRING(a) case a: return #a /** * Concatenate two macro args into one, e.g.: * int CONCAT(foo_, __LINE__); * will produce: * int foo_123; */ #define CONCAT2(X,Y) X##Y #define CONCAT(X,Y) CONCAT2(X,Y) #define _fallthrough_ __attribute__((fallthrough)) libinput-1.28.1/src/util-matrix.h000066400000000000000000000100531477265155700166720ustar00rootroot00000000000000/* * Copyright © 2008 Kristian Høgsberg * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include struct matrix { float val[3][3]; /* [row][col] */ }; static inline double deg2rad(int degree) { return M_PI * degree / 180.0; } static inline double rad2deg(double rad) { return 180.0 / M_PI * rad; } static inline void matrix_init_identity(struct matrix *m) { memset(m, 0, sizeof(*m)); m->val[0][0] = 1; m->val[1][1] = 1; m->val[2][2] = 1; } static inline void matrix_from_farray6(struct matrix *m, const float values[6]) { matrix_init_identity(m); m->val[0][0] = values[0]; m->val[0][1] = values[1]; m->val[0][2] = values[2]; m->val[1][0] = values[3]; m->val[1][1] = values[4]; m->val[1][2] = values[5]; } static inline void matrix_init_scale(struct matrix *m, float sx, float sy) { matrix_init_identity(m); m->val[0][0] = sx; m->val[1][1] = sy; } static inline void matrix_init_translate(struct matrix *m, float x, float y) { matrix_init_identity(m); m->val[0][2] = x; m->val[1][2] = y; } static inline void matrix_init_rotate(struct matrix *m, int degrees) { double s, c; s = sin(deg2rad(degrees)); c = cos(deg2rad(degrees)); matrix_init_identity(m); m->val[0][0] = c; m->val[0][1] = -s; m->val[1][0] = s; m->val[1][1] = c; } static inline bool matrix_is_identity(const struct matrix *m) { return (m->val[0][0] == 1 && m->val[0][1] == 0 && m->val[0][2] == 0 && m->val[1][0] == 0 && m->val[1][1] == 1 && m->val[1][2] == 0 && m->val[2][0] == 0 && m->val[2][1] == 0 && m->val[2][2] == 1); } static inline void matrix_mult(struct matrix *dest, const struct matrix *m1, const struct matrix *m2) { struct matrix m; /* allow for dest == m1 or dest == m2 */ int row, col, i; for (row = 0; row < 3; row++) { for (col = 0; col < 3; col++) { double v = 0; for (i = 0; i < 3; i++) { v += m1->val[row][i] * m2->val[i][col]; } m.val[row][col] = v; } } memcpy(dest, &m, sizeof(m)); } static inline void matrix_mult_vec(const struct matrix *m, int *x, int *y) { float tx, ty; tx = *x * m->val[0][0] + *y * m->val[0][1] + m->val[0][2]; ty = *x * m->val[1][0] + *y * m->val[1][1] + m->val[1][2]; *x = (int)tx; *y = (int)ty; } static inline void matrix_mult_vec_double(const struct matrix *m, double *x, double *y) { double tx, ty; tx = *x * m->val[0][0] + *y * m->val[0][1] + m->val[0][2]; ty = *x * m->val[1][0] + *y * m->val[1][1] + m->val[1][2]; *x = tx; *y = ty; } static inline void matrix_to_farray6(const struct matrix *m, float out[6]) { out[0] = m->val[0][0]; out[1] = m->val[0][1]; out[2] = m->val[0][2]; out[3] = m->val[1][0]; out[4] = m->val[1][1]; out[5] = m->val[1][2]; } static inline void matrix_to_relative(struct matrix *dest, const struct matrix *src) { matrix_init_identity(dest); dest->val[0][0] = src->val[0][0]; dest->val[0][1] = src->val[0][1]; dest->val[1][0] = src->val[1][0]; dest->val[1][1] = src->val[1][1]; } libinput-1.28.1/src/util-multivalue.h000066400000000000000000000100631477265155700175560ustar00rootroot00000000000000 /* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include #include #include "util-strings.h" struct multivalue { char type; union { char s[256]; char c; double d; bool b; uint32_t u; int32_t i; } value; char name[64]; }; static inline void multivalue_extract(const struct multivalue *v, void *ptr) { /* ignore false positives from gcc: * ../src/util-multivalue.h:52:33: warning: array subscript ‘double[0]’ is partly outside array bounds of ‘int32_t[1]’ {aka ‘int[1]’} [-Warray-bounds=] * 52 | case 'd': *(double*)ptr = v->value.d; break; */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" switch (v->type) { case 'b': *(bool *)ptr = v->value.b; break; case 'c': *(char *)ptr = v->value.c; break; case 'u': *(uint32_t *)ptr = v->value.u; break; case 'i': *(int32_t *)ptr = v->value.i; break; case 'd': *(double *)ptr = v->value.d; break; case 's': *(const char **)ptr = v->value.s; break; default: abort(); } #pragma GCC diagnostic pop } static inline void multivalue_extract_typed(const struct multivalue *v, char type, void *ptr) { assert(type == v->type); multivalue_extract(v, ptr); } static inline struct multivalue multivalue_copy(const struct multivalue *v) { struct multivalue copy = *v; return copy; } static inline struct multivalue multivalue_new_string(const char *str) { struct multivalue v = { .type = 's' }; assert(strlen(str) < sizeof(v.value.s)); snprintf(v.value.s, sizeof(v.value.s), "%s", str); return v; } static inline struct multivalue multivalue_new_char(char c) { struct multivalue v = { .type = 'c', .value.c = c, }; return v; } static inline struct multivalue multivalue_new_double(double d) { struct multivalue v = { .type = 'd', .value.d = d, }; return v; } static inline struct multivalue multivalue_new_u32(uint32_t u) { struct multivalue v = { .type = 'u', .value.u = u, }; return v; } static inline struct multivalue multivalue_new_i32(int32_t i) { struct multivalue v = { .type = 'i', .value.i = i, }; return v; } static inline struct multivalue multivalue_new_bool(bool b) { struct multivalue v = { .type = 'b', .value.b = b, }; return v; } static inline struct multivalue multivalue_new_named_i32(int32_t value, const char *name) { struct multivalue v = multivalue_new_i32(value); assert(strlen(name) < sizeof(v.name)); snprintf(v.name, sizeof(v.name), "%s", name); return v; } static inline char * multivalue_as_str(const struct multivalue *v) { char *str; if (v->name[0]) return safe_strdup(v->name); switch (v->type) { case 'd': xasprintf(&str, "%f", v->value.d); break; case 'u': xasprintf(&str, "%u", v->value.u); break; case 'i': xasprintf(&str, "%d", v->value.i); break; case 'b': xasprintf(&str, "%s", truefalse(v->value.b)); break; case 'c': xasprintf(&str, "%c", v->value.c); break; case 's': str = safe_strdup(v->value.s); break; default: abort(); } return str; } libinput-1.28.1/src/util-prop-parsers.c000066400000000000000000000316241477265155700200250ustar00rootroot00000000000000/* * Copyright © 2013-2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "util-prop-parsers.h" #include #include #include "util-macros.h" #include "util-strings.h" /* Helper function to parse the mouse DPI tag from udev. * The tag is of the form: * MOUSE_DPI=400 *1000 2000 * or * MOUSE_DPI=400@125 *1000@125 2000@125 * Where the * indicates the default value and @number indicates device poll * rate. * Numbers should be in ascending order, and if rates are present they should * be present for all entries. * * When parsing the mouse DPI property, if we find an error we just return 0 * since it's obviously invalid, the caller will treat that as an error and * use a reasonable default instead. If the property contains multiple DPI * settings but none flagged as default, we return the last because we're * lazy and that's a silly way to set the property anyway. * * @param prop The value of the udev property (without the MOUSE_DPI=) * @return The default dpi value on success, 0 on error */ int parse_mouse_dpi_property(const char *prop) { bool is_default = false; int nread, dpi = 0, rate; if (!prop) return 0; while (*prop != 0) { if (*prop == ' ') { prop++; continue; } if (*prop == '*') { prop++; is_default = true; if (!isdigit(prop[0])) return 0; } /* While we don't do anything with the rate right now we * will validate that, if it's present, it is non-zero and * positive */ rate = 1; nread = 0; sscanf(prop, "%d@%d%n", &dpi, &rate, &nread); if (!nread) sscanf(prop, "%d%n", &dpi, &nread); if (!nread || dpi <= 0 || rate <= 0 || prop[nread] == '@') return 0; if (is_default) break; prop += nread; } return dpi; } /** * Helper function to parse the MOUSE_WHEEL_CLICK_COUNT property from udev. * Property is of the form: * MOUSE_WHEEL_CLICK_COUNT= * Where the number indicates the number of wheel clicks per 360 deg * rotation. * * @param prop The value of the udev property (without the MOUSE_WHEEL_CLICK_COUNT=) * @return The click count of the wheel (may be negative) or 0 on error. */ int parse_mouse_wheel_click_count_property(const char *prop) { int count = 0; if (!prop) return 0; if (!safe_atoi(prop, &count) || abs(count) > 360) return 0; return count; } /** * * Helper function to parse the MOUSE_WHEEL_CLICK_ANGLE property from udev. * Property is of the form: * MOUSE_WHEEL_CLICK_ANGLE= * Where the number indicates the degrees travelled for each click. * * @param prop The value of the udev property (without the MOUSE_WHEEL_CLICK_ANGLE=) * @return The angle of the wheel (may be negative) or 0 on error. */ int parse_mouse_wheel_click_angle_property(const char *prop) { int angle = 0; if (!prop) return 0; if (!safe_atoi(prop, &angle) || abs(angle) > 360) return 0; return angle; } /** * Parses a simple dimension string in the form of "10x40". The two * numbers must be positive integers in decimal notation. * On success, the two numbers are stored in w and h. On failure, w and h * are unmodified. * * @param prop The value of the property * @param w Returns the first component of the dimension * @param h Returns the second component of the dimension * @return true on success, false otherwise */ bool parse_dimension_property(const char *prop, size_t *w, size_t *h) { int x, y; if (!prop) return false; if (sscanf(prop, "%dx%d", &x, &y) != 2) return false; if (x <= 0 || y <= 0) return false; *w = (size_t)x; *h = (size_t)y; return true; } /** * Parses a set of 6 space-separated floats. * * @param prop The string value of the property * @param calibration Returns the six components * @return true on success, false otherwise */ bool parse_calibration_property(const char *prop, float calibration_out[6]) { if (!prop) return false; bool rc = false; size_t num_calibration; char **strv = strv_from_string(prop, " ", &num_calibration); if (!strv || num_calibration < 6) goto out; float calibration[6]; for (size_t idx = 0; idx < 6; idx++) { double v; if (!safe_atod(strv[idx], &v)) goto out; calibration[idx] = v; } memcpy(calibration_out, calibration, sizeof(calibration)); rc = true; out: strv_free(strv); return rc; } bool parse_switch_reliability_property(const char *prop, enum switch_reliability *reliability) { if (!prop) { *reliability = RELIABILITY_RELIABLE; return true; } if (streq(prop, "reliable")) *reliability = RELIABILITY_RELIABLE; else if (streq(prop, "unreliable")) *reliability = RELIABILITY_UNRELIABLE; else if (streq(prop, "write_open")) *reliability = RELIABILITY_WRITE_OPEN; else return false; return true; } /** * Parses a string with the allowed values: "below" * The value refers to the position of the touchpad (relative to the * keyboard, i.e. your average laptop would be 'below') * * @param prop The value of the property * @param layout The layout * @return true on success, false otherwise */ bool parse_tpkbcombo_layout_poperty(const char *prop, enum tpkbcombo_layout *layout) { if (!prop) return false; if (streq(prop, "below")) { *layout = TPKBCOMBO_LAYOUT_BELOW; return true; } return false; } /** * Parses a string of the format "a:b" where both a and b must be integer * numbers and a > b. Also allowed is the special string value "none" which * amounts to unsetting the property. * * @param prop The value of the property * @param hi Set to the first digit or 0 in case of 'none' * @param lo Set to the second digit or 0 in case of 'none' * @return true on success, false otherwise */ bool parse_range_property(const char *prop, int *hi, int *lo) { int first, second; if (!prop) return false; if (streq(prop, "none")) { *hi = 0; *lo = 0; return true; } if (sscanf(prop, "%d:%d", &first, &second) != 2) return false; if (second >= first) return false; *hi = first; *lo = second; return true; } bool parse_boolean_property(const char *prop, bool *b) { if (!prop) return false; if (streq(prop, "1")) *b = true; else if (streq(prop, "0")) *b = false; else return false; return true; } static bool parse_evcode_string(const char *s, int *type_out, int *code_out) { int type, code; if (strstartswith(s, "EV_")) { type = libevdev_event_type_from_name(s); if (type == -1) return false; code = EVENT_CODE_UNDEFINED; } else { struct map { const char *str; int type; } map[] = { { "KEY_", EV_KEY }, { "BTN_", EV_KEY }, { "ABS_", EV_ABS }, { "REL_", EV_REL }, { "SW_", EV_SW }, }; bool found = false; ARRAY_FOR_EACH(map, m) { if (!strstartswith(s, m->str)) continue; type = m->type; code = libevdev_event_code_from_name(type, s); if (code == -1) return false; found = true; break; } if (!found) return false; } *type_out = type; *code_out = code; return true; } /** * Parses a string of the format "+EV_ABS;+KEY_A;-BTN_TOOL_DOUBLETAP;-ABS_X;" * where each element must be + or - (enable/disable) followed by a named event * type OR a named event code OR a tuple in the form of EV_KEY:0x123, i.e. a * named event type followed by a hex event code. * * events must point to an existing array of size nevents. * nevents specifies the size of the array in events and returns the number * of items, elements exceeding nevents are simply ignored, just make sure * events is large enough for your use-case. * * The results are returned as input events with type and code set, all * other fields undefined. Where only the event type is specified, the code * is set to EVENT_CODE_UNDEFINED. * * On success, events contains nevents events with each event's value set to 1 * or 0 depending on the + or - prefix. */ bool parse_evcode_property(const char *prop, struct input_event *events, size_t *nevents) { bool rc = false; /* A randomly chosen max so we avoid crazy quirks */ struct input_event evs[32]; memset(evs, 0, sizeof evs); size_t ncodes; char **strv = strv_from_string(prop, ";", &ncodes); if (!strv || ncodes == 0 || ncodes > ARRAY_LENGTH(evs)) goto out; ncodes = min(*nevents, ncodes); for (size_t idx = 0; strv[idx]; idx++) { char *s = strv[idx]; bool enable; switch (*s) { case '+': enable = true; break; case '-': enable = false; break; default: goto out; } s++; int type, code; if (strstr(s, ":") == NULL) { if (!parse_evcode_string(s, &type, &code)) goto out; } else { int consumed; char stype[13] = {0}; /* EV_FF_STATUS + '\0' */ if (sscanf(s, "%12[A-Z_]:%x%n", stype, &code, &consumed) != 2 || strlen(s) != (size_t)consumed || (type = libevdev_event_type_from_name(stype)) == -1 || code < 0 || code > libevdev_event_type_get_max(type)) goto out; } evs[idx].type = type; evs[idx].code = code; evs[idx].value = enable; } memcpy(events, evs, ncodes * sizeof *events); *nevents = ncodes; rc = true; out: strv_free(strv); return rc; } /** * Parses a string of the format "+INPUT_PROP_BUTTONPAD;-INPUT_PROP_POINTER;+0x123;" * where each element must be a named input prop OR a hexcode in the form * 0x1234. The prefix for each element must be either '+' (enable) or '-' (disable). * * props must point to an existing array of size nprops. * nprops specifies the size of the array in props and returns the number * of elements, elements exceeding nprops are simply ignored, just make sure * props is large enough for your use-case. * * On success, props contains nprops elements. */ bool parse_input_prop_property(const char *prop, struct input_prop *props_out, size_t *nprops) { bool rc = false; struct input_prop props[INPUT_PROP_CNT]; /* doubling up on quirks is a bug */ size_t count; char **strv = strv_from_string(prop, ";", &count); if (!strv || count == 0 || count > ARRAY_LENGTH(props)) goto out; count = min(*nprops, count); for (size_t idx = 0; strv[idx]; idx++) { char *s = strv[idx]; unsigned int prop; bool enable; switch (*s) { case '+': enable = true; break; case '-': enable = false; break; default: goto out; } s++; if (safe_atou_base(s, &prop, 16)) { if (prop > INPUT_PROP_MAX) goto out; } else { int val = libevdev_property_from_name(s); if (val == -1) goto out; prop = (unsigned int)val; } props[idx].prop = prop; props[idx].enabled = enable; } memcpy(props_out, props, count * sizeof *props); *nprops = count; rc = true; out: strv_free(strv); return rc; } /** * Parse the property value for the EVDEV_ABS_00 properties. Spec is * EVDEV_ABS_00=min:max:res:fuzz:flat * where any element may be empty and subsequent elements may not be * present. So we have to parse * EVDEV_ABS_00=min:max:res * EVDEV_ABS_00=::res * EVDEV_ABS_00=::res:fuzz: * * Returns a mask of the bits set and the absinfo struct with the values. * The abs value for an unset bit is undefined. */ uint32_t parse_evdev_abs_prop(const char *prop, struct input_absinfo *abs) { char *str = safe_strdup(prop); char *current, *next; uint32_t mask = 0; int bit = ABS_MASK_MIN; int *val; int values[5]; /* basic sanity check: 5 digits for min/max, 3 for resolution, fuzz, * flat and the colons. That's plenty, anything over is garbage */ if (!prop || strlen(prop) > 24) goto out; current = str; val = values; while (current && *current != '\0' && bit <= ABS_MASK_FLAT) { if (*current != ':') { int v; next = index(current, ':'); if (next) *next = '\0'; if (!safe_atoi(current, &v)) { mask = 0; goto out; } *val = v; mask |= bit; current = next ? ++next : NULL; } else { current++; } bit <<= 1; val++; } if (mask & ABS_MASK_MIN) abs->minimum = values[0]; if (mask & ABS_MASK_MAX) abs->maximum = values[1]; if (mask & ABS_MASK_RES) abs->resolution = values[2]; if (mask & ABS_MASK_FUZZ) abs->fuzz = values[3]; if (mask & ABS_MASK_FLAT) abs->flat = values[4]; out: free(str); return mask; } libinput-1.28.1/src/util-prop-parsers.h000066400000000000000000000050261477265155700200270ustar00rootroot00000000000000/* * Copyright © 2013-2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #include struct input_prop { unsigned int prop; bool enabled; }; int parse_mouse_dpi_property(const char *prop); int parse_mouse_wheel_click_angle_property(const char *prop); int parse_mouse_wheel_click_count_property(const char *prop); bool parse_dimension_property(const char *prop, size_t *width, size_t *height); bool parse_calibration_property(const char *prop, float calibration[6]); bool parse_range_property(const char *prop, int *hi, int *lo); bool parse_boolean_property(const char *prop, bool *b); #define EVENT_CODE_UNDEFINED 0xffff bool parse_evcode_property(const char *prop, struct input_event *events, size_t *nevents); bool parse_input_prop_property(const char *prop, struct input_prop *props_out, size_t *nprops); enum tpkbcombo_layout { TPKBCOMBO_LAYOUT_UNKNOWN, TPKBCOMBO_LAYOUT_BELOW, }; bool parse_tpkbcombo_layout_poperty(const char *prop, enum tpkbcombo_layout *layout); enum switch_reliability { RELIABILITY_RELIABLE, RELIABILITY_UNRELIABLE, RELIABILITY_WRITE_OPEN, }; bool parse_switch_reliability_property(const char *prop, enum switch_reliability *reliability); enum { ABS_MASK_MIN = 0x1, ABS_MASK_MAX = 0x2, ABS_MASK_RES = 0x4, ABS_MASK_FUZZ = 0x8, ABS_MASK_FLAT = 0x10, }; uint32_t parse_evdev_abs_prop(const char *prop, struct input_absinfo *abs); libinput-1.28.1/src/util-range.h000066400000000000000000000035031477265155700164640ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef UTIL_RANGE_H #define UTIL_RANGE_H #include struct range { int lower; /* inclusive */ int upper; /* exclusive */ }; static inline struct range range_init_empty(void) { return (struct range){ .lower = 0, .upper = -1 }; } static inline struct range range_init_inclusive(int lower, int upper) { return (struct range) { .lower = lower, .upper = upper + 1}; } static inline struct range range_init_exclusive(int lower, int upper) { return (struct range){ .lower = lower, .upper = upper }; } static inline bool range_is_valid(const struct range *r) { return r->upper > r->lower; } #define range_for_each(range_, r_) \ for (r_ = (range_)->lower; r < (range_)->upper; r++) #endif libinput-1.28.1/src/util-ratelimit.c000066400000000000000000000051041477265155700173540ustar00rootroot00000000000000/* * Copyright © 2008-2011 Kristian Høgsberg * Copyright © 2011 Intel Corporation * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "util-ratelimit.h" #include "util-time.h" void ratelimit_init(struct ratelimit *r, uint64_t ival_us, unsigned int burst) { r->interval = ival_us; r->begin = 0; r->burst = burst; r->num = 0; } /* * Perform rate-limit test. Returns RATELIMIT_PASS if the rate-limited action * is still allowed, RATELIMIT_THRESHOLD if the limit has been reached with * this call, and RATELIMIT_EXCEEDED if you're beyond the threshold. * It's safe to treat the return-value as boolean, if you're not interested in * the exact state. It evaluates to "true" if the threshold hasn't been * exceeded, yet. * * The ratelimit object must be initialized via ratelimit_init(). * * Modelled after Linux' lib/ratelimit.c by Dave Young * , which is licensed GPLv2. */ enum ratelimit_state ratelimit_test(struct ratelimit *r) { struct timespec ts; uint64_t utime; if (r->interval <= 0 || r->burst <= 0) return RATELIMIT_PASS; clock_gettime(CLOCK_MONOTONIC, &ts); utime = s2us(ts.tv_sec) + ns2us(ts.tv_nsec); if (r->begin <= 0 || r->begin + r->interval < utime) { /* reset counter */ r->begin = utime; r->num = 1; return RATELIMIT_PASS; } if (r->num < r->burst) { /* continue burst */ return (++r->num == r->burst) ? RATELIMIT_THRESHOLD : RATELIMIT_PASS; } return RATELIMIT_EXCEEDED; } libinput-1.28.1/src/util-ratelimit.h000066400000000000000000000030531477265155700173620ustar00rootroot00000000000000/* * Copyright © 2008 Kristian Høgsberg * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include enum ratelimit_state { RATELIMIT_EXCEEDED, RATELIMIT_THRESHOLD, RATELIMIT_PASS, }; struct ratelimit { uint64_t interval; uint64_t begin; unsigned int burst; unsigned int num; }; void ratelimit_init(struct ratelimit *r, uint64_t ival_us, unsigned int burst); enum ratelimit_state ratelimit_test(struct ratelimit *r); libinput-1.28.1/src/util-stringbuf.h000066400000000000000000000067421477265155700174030ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "util-macros.h" struct stringbuf { char *data; size_t len; /* len of log */ size_t sz; /* allocated size */ }; static inline void stringbuf_init(struct stringbuf *b) { b->len = 0; b->sz = 64; b->data = calloc(1, b->sz); } static inline bool stringbuf_is_empty(struct stringbuf *b) { return b->len == 0; } static inline void stringbuf_reset(struct stringbuf *b) { free(b->data); b->data = NULL; b->sz = 0; b->len = 0; } static inline struct stringbuf * stringbuf_new(void) { struct stringbuf *b = calloc(1, sizeof(*b)); stringbuf_init(b); return b; } static inline void stringbuf_destroy(struct stringbuf *b) { stringbuf_reset(b); free(b); } static inline char * stringbuf_steal_destroy(struct stringbuf *b) { char *str = b->data; b->data = NULL; stringbuf_destroy(b); return str; } static inline char * stringbuf_steal(struct stringbuf *b) { char *str = b->data; b->data = NULL; stringbuf_reset(b); return str; } /** * Ensure the stringbuf has space for at least sz bytes */ static inline int stringbuf_ensure_size(struct stringbuf *b, size_t sz) { if (b->sz < sz) { char *tmp = realloc(b->data, sz); if (!tmp) return -errno; b->data = tmp; memset(&b->data[b->len], 0, sz - b->len); b->sz = sz; } return 0; } /** * Ensure the stringbuf has space for at least sz *more* bytes */ static inline int stringbuf_ensure_space(struct stringbuf *b, size_t sz) { return stringbuf_ensure_size(b, b->len + sz); } /** * Append the the data from the fd to the string buffer. */ static inline int stringbuf_append_from_fd(struct stringbuf *b, int fd, size_t maxlen) { while (1) { size_t inc = maxlen ? maxlen : 1024; do { int r = stringbuf_ensure_space(b, inc); if (r < 0) return r; r = read(fd, &b->data[b->len], min(b->sz - b->len, inc)); if (r <= 0) { if (r < 0 && errno != EAGAIN) return -errno; return 0; } b->len += r; } while (maxlen > 0); } return 0; } static inline int stringbuf_append_string(struct stringbuf *b, const char *msg) { int r = stringbuf_ensure_space(b, strlen(msg) + 1); if (r < 0) return r; size_t slen = strlen(msg); if (!b->data) /* cannot happen, but let's make scan-build happy */ abort(); memcpy(b->data + b->len, msg, slen); b->len += slen; return 0; } libinput-1.28.1/src/util-strings.c000066400000000000000000000154131477265155700170570ustar00rootroot00000000000000/* * Copyright © 2008 Kristian Høgsberg * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "util-strings.h" /** * Return the next word in a string pointed to by state before the first * separator character. Call repeatedly to tokenize a whole string. * * @param state Current state * @param len String length of the word returned * @param separators List of separator characters * * @return The first word in *state, NOT null-terminated */ static const char * next_word(const char **state, size_t *len, const char *separators) { assert(state != NULL); const char *next = *state; size_t l; if (!*next) return NULL; next += strspn(next, separators); if (!*next) { *state = next; return NULL; } l = strcspn(next, separators); *state = next + l; *len = l; return next; } /** * Return a null-terminated string array with the contents of argv * duplicated. * * Use strv_free() to free the array. * * @return A null-terminated string array or NULL on errors */ char** strv_from_argv(int argc, char **argv) { char **strv = NULL; assert(argc >= 0); assert(argv != NULL); if (argc == 0) return NULL; strv = zalloc((argc + 1) * sizeof *strv); for (int i = 0; i < argc; i++) { char *copy = safe_strdup(argv[i]); if (!copy) { strv_free(strv); return NULL; } strv[i] = copy; } return strv; } /** * Return a null-terminated string array with the tokens in the input * string, e.g. "one two\tthree" with a separator list of " \t" will return * an array [ "one", "two", "three", NULL ] and num elements 3. * * Use strv_free() to free the array. * * Another example: * result = strv_from_string("+1-2++3--4++-+5-+-", "+-", &nelem) * result == [ "1", "2", "3", "4", "5", NULL ] and nelem == 5 * * @param in Input string * @param separators List of separator characters * @param num_elements Number of elements found in the input string * * @return A null-terminated string array or NULL on errors */ char ** strv_from_string(const char *in, const char *separators, size_t *num_elements) { assert(in != NULL); assert(separators != NULL); assert(num_elements != NULL); const char *s = in; size_t l, nelems = 0; while (next_word(&s, &l, separators) != NULL) nelems++; if (nelems == 0) { *num_elements = 0; return NULL; } size_t strv_len = nelems + 1; /* NULL-terminated */ char **strv = zalloc(strv_len * sizeof *strv); size_t idx = 0; const char *word; s = in; while ((word = next_word(&s, &l, separators)) != NULL) { char *copy = strndup(word, l); if (!copy) { strv_free(strv); *num_elements = 0; return NULL; } strv[idx++] = copy; } *num_elements = nelems; return strv; } /** * Return a newly allocated string with all elements joined by the * joiner, same as Python's string.join() basically. * A strv of ["one", "two", "three", NULL] with a joiner of ", " results * in "one, two, three". * * An empty strv ([NULL]) returns NULL, same for passing NULL as either * argument. * * @param strv Input string array * @param joiner Joiner between the elements in the final string * * @return A null-terminated string joining all elements */ char * strv_join(char **strv, const char *joiner) { assert(strv != NULL); char **s; char *str; size_t slen = 0; size_t count = 0; if (!strv || !joiner) return NULL; if (strv[0] == NULL) return NULL; for (s = strv, count = 0; *s; s++, count++) { slen += strlen(*s); } assert(slen < 1000); assert(strlen(joiner) < 1000); assert(count > 0); assert(count < 100); slen += (count - 1) * strlen(joiner); str = zalloc(slen + 1); /* trailing \0 */ for (s = strv; *s; s++) { strcat(str, *s); --count; if (count > 0) strcat(str, joiner); } return str; } /** * Iterate through strv, calling func with each string and its respective index. * Iteration stops successfully after max elements or at the last element, * whichever occurs first. * * If func returns non-zero, iteration stops and strv_for_each returns * that value. * * @return zero on success, otherwise the error returned by the callback */ int strv_for_each_n(const char **strv, size_t max, strv_foreach_callback_t func, void *data) { for (size_t i = 0; i < max && strv && strv[i]; i++) { int ret = func(strv[i], i, data); if (ret) return ret; } return 0; } /** * Iterate through strv, calling func with each string and its respective index. * If func returns non-zero, iteration stops and strv_for_each returns * that value. * * @return zero on success, otherwise the error returned by the callback */ int strv_for_each(const char **strv, strv_foreach_callback_t func, void *data) { return strv_for_each_n(strv, SIZE_MAX, func, data); } /** * Return a pointer to the basename within filename. * If the filename the empty string or a directory (i.e. the last char of * filename is '/') NULL is returned. */ const char * safe_basename(const char *filename) { assert(filename != NULL); const char *basename; if (*filename == '\0') return NULL; basename = strrchr(filename, '/'); if (basename == NULL) return filename; if (*(basename + 1) == '\0') return NULL; return basename + 1; } /** * Similar to basename() but returns the trunk only without the (last) * trailing suffix, so that: * * - foo.c returns foo * - foo.a.b returns foo.a * - foo returns foo * - foo/ returns "" * * @return an allocated string representing the trunk name of the file */ char * trunkname(const char *filename) { assert(filename != NULL); const char *base = safe_basename(filename); char *suffix; if (base == NULL) return safe_strdup(""); suffix = rindex(base, '.'); if (suffix == NULL) return safe_strdup(base); else return strndup(base, suffix-base); } libinput-1.28.1/src/util-strings.h000066400000000000000000000254111477265155700170630ustar00rootroot00000000000000/* * Copyright © 2008 Kristian Høgsberg * Copyright © 2013-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_LOCALE_H #include #endif #ifdef HAVE_XLOCALE_H #include #endif #include "util-macros.h" #define yesno(b) ((b) ? "yes" : "no") #define truefalse(b) ((b) ? "true" : "false") #define YESNO(b) ((b) ? "YES" : "NO") #define TRUEFALSE(b) ((b) ? "TRUE" : "FALSE") #define onoff(b) ((b) ? "on" : "off") static inline bool streq(const char *str1, const char *str2) { /* one NULL, one not NULL is always false */ if (str1 && str2) return strcmp(str1, str2) == 0; return str1 == str2; } static inline bool strneq(const char *str1, const char *str2, int n) { /* one NULL, one not NULL is always false */ if (str1 && str2) return strncmp(str1, str2, n) == 0; return str1 == str2; } static inline void * zalloc(size_t size) { void *p; /* We never need to alloc anything more than 1,5 MB so we can assume * if we ever get above that something's going wrong */ if (size > 1536 * 1024) assert(!"bug: internal malloc size limit exceeded"); p = calloc(1, size); if (!p) abort(); return p; } /** * strdup guaranteed to succeed. If the input string is NULL, the output * string is NULL. If the input string is a string pointer, we strdup or * abort on failure. */ static inline char* safe_strdup(const char *str) { char *s; if (!str) return NULL; s = strdup(str); if (!s) abort(); return s; } /** * NULL-safe version of strlen */ static inline size_t safe_strlen(const char *str) { return str ? strlen(str) : 0; } /** * Simple wrapper for asprintf that ensures the passed in-pointer is set * to NULL upon error. * The standard asprintf() call does not guarantee the passed in pointer * will be NULL'ed upon failure, whereas this wrapper does. * * @param strp pointer to set to newly allocated string. * This pointer should be passed to free() to release when done. * @param fmt the format string to use for printing. * @return The number of bytes printed (excluding the null byte terminator) * upon success or -1 upon failure. In the case of failure the pointer is set * to NULL. */ __attribute__ ((format (printf, 2, 3))) static inline int xasprintf(char **strp, const char *fmt, ...) { int rc = 0; va_list args; va_start(args, fmt); rc = vasprintf(strp, fmt, args); va_end(args); if ((rc == -1) && strp) *strp = NULL; return rc; } __attribute__ ((format (printf, 2, 0))) static inline int xvasprintf(char **strp, const char *fmt, va_list args) { int rc = 0; rc = vasprintf(strp, fmt, args); if ((rc == -1) && strp) *strp = NULL; return rc; } __attribute__ ((format (printf, 1, 2))) static inline char * strdup_printf(const char *fmt, ...) { int rc = 0; va_list args; char *strp; va_start(args, fmt); rc = vasprintf(&strp, fmt, args); va_end(args); if (rc < 0) abort(); return strp; } __attribute__ ((format (printf, 1, 0))) static inline char * strdup_vprintf(const char *fmt, va_list args) { char *strp; int rc = xvasprintf(&strp, fmt, args); if (rc < 0) abort(); return strp; } static inline bool safe_atoi_base(const char *str, int *val, int base) { assert(str != NULL); char *endptr; long v; assert(base == 10 || base == 16 || base == 8); errno = 0; v = strtol(str, &endptr, base); if (errno > 0) return false; if (str == endptr) return false; if (*str != '\0' && *endptr != '\0') return false; if (v > INT_MAX || v < INT_MIN) return false; *val = v; return true; } static inline bool safe_atoi(const char *str, int *val) { assert(str != NULL); return safe_atoi_base(str, val, 10); } static inline bool safe_atou_base(const char *str, unsigned int *val, int base) { assert(str != NULL); char *endptr; unsigned long v; assert(base == 10 || base == 16 || base == 8); errno = 0; v = strtoul(str, &endptr, base); if (errno > 0) return false; if (str == endptr) return false; if (*str != '\0' && *endptr != '\0') return false; if ((long)v < 0) return false; *val = v; return true; } static inline bool safe_atou(const char *str, unsigned int *val) { assert(str != NULL); return safe_atou_base(str, val, 10); } static inline bool safe_atod(const char *str, double *val) { assert(str != NULL); char *endptr; double v; #ifdef HAVE_LOCALE_H locale_t c_locale; #endif size_t slen = strlen(str); /* We don't have a use-case where we want to accept hex for a double * or any of the other values strtod can parse */ for (size_t i = 0; i < slen; i++) { char c = str[i]; if (isdigit(c)) continue; switch(c) { case '+': case '-': case '.': break; default: return false; } } #ifdef HAVE_LOCALE_H /* Create a "C" locale to force strtod to use '.' as separator */ c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); if (c_locale == (locale_t)0) return false; errno = 0; v = strtod_l(str, &endptr, c_locale); freelocale(c_locale); #else /* No locale support in provided libc, assume it already uses '.' */ errno = 0; v = strtod(str, &endptr); #endif if (errno > 0) return false; if (str == endptr) return false; if (*str != '\0' && *endptr != '\0') return false; if (v != 0.0 && !isnormal(v)) return false; *val = v; return true; } char **strv_from_argv(int argc, char **argv); char **strv_from_string(const char *in, const char *separator, size_t *num_elements); char *strv_join(char **strv, const char *joiner); typedef int (*strv_foreach_callback_t)(const char *str, size_t index, void *data); int strv_for_each(const char **strv, strv_foreach_callback_t func, void *data); int strv_for_each_n(const char **strv, size_t max, strv_foreach_callback_t func, void *data); static inline void strv_free(char **strv) { char **s = strv; if (!strv) return; while (*s != NULL) { free(*s); *s = (char*)0x1; /* detect use-after-free */ s++; } free (strv); } /** * parse a string containing a list of doubles into a double array. * * @param in string to parse * @param separator string used to separate double in list e.g. "," * @param result double array * @param length length of double array * @return true when parsed successfully otherwise false */ static inline double * double_array_from_string(const char *in, const char *separator, size_t *length) { assert(in != NULL); assert(separator != NULL); assert(length != NULL); double *result = NULL; *length = 0; size_t nelem; char **strv = strv_from_string(in, separator, &nelem); if (!strv) return result; double *numv = zalloc(sizeof(double) * nelem); for (size_t idx = 0; idx < nelem; idx++) { double val; if (!safe_atod(strv[idx], &val)) goto out; numv[idx] = val; } result = numv; numv = NULL; *length = nelem; out: strv_free(strv); free(numv); return result; } struct key_value_str{ char *key; char *value; }; struct key_value_double { double key; double value; }; static inline ssize_t kv_double_from_string(const char *string, const char *pair_separator, const char *kv_separator, struct key_value_double **result_out) { struct key_value_double *result = NULL; if (!pair_separator || pair_separator[0] == '\0' || !kv_separator || kv_separator[0] == '\0') return -1; size_t npairs; char **pairs = strv_from_string(string, pair_separator, &npairs); if (!pairs || npairs == 0) goto error; result = zalloc(npairs * sizeof *result); for (size_t idx = 0; idx < npairs; idx++) { char *pair = pairs[idx]; size_t nelem; char **kv = strv_from_string(pair, kv_separator, &nelem); double k, v; if (!kv || nelem != 2 || !safe_atod(kv[0], &k) || !safe_atod(kv[1], &v)) { strv_free(kv); goto error; } result[idx].key = k; result[idx].value = v; strv_free(kv); } strv_free(pairs); *result_out = result; return npairs; error: strv_free(pairs); free(result); return -1; } /** * Strip any of the characters in what from the beginning and end of the * input string. * * @return a newly allocated string with none of "what" at the beginning or * end of string */ static inline char * strstrip(const char *input, const char *what) { assert(input != NULL); char *str, *last; str = safe_strdup(&input[strspn(input, what)]); last = str; for (char *c = str; c && *c != '\0'; c++) { if (!strchr(what, *c)) last = c + 1; } *last = '\0'; return str; } /** * Return true if str ends in suffix, false otherwise. If the suffix is the * empty string, strendswith() always returns false. */ static inline bool strendswith(const char *str, const char *suffix) { if (str == NULL) return false; size_t slen = strlen(str); size_t suffixlen = strlen(suffix); size_t offset; if (slen == 0 || suffixlen == 0 || suffixlen > slen) return false; offset = slen - suffixlen; return strneq(&str[offset], suffix, suffixlen); } static inline bool strstartswith(const char *str, const char *prefix) { if (str == NULL) return false; size_t prefixlen = strlen(prefix); return prefixlen > 0 ? strneq(str, prefix, strlen(prefix)) : false; } const char * safe_basename(const char *filename); char * trunkname(const char *filename); /** * Return a copy of str with all % converted to %% to make the string * acceptable as printf format. */ static inline char * str_sanitize(const char *str) { if (!str) return NULL; if (!strchr(str, '%')) return strdup(str); size_t slen = min(strlen(str), 512); char *sanitized = zalloc(2 * slen + 1); const char *src = str; char *dst = sanitized; for (size_t i = 0; i < slen; i++) { if (*src == '%') *dst++ = '%'; *dst++ = *src++; } *dst = '\0'; return sanitized; } libinput-1.28.1/src/util-time.h000066400000000000000000000063401477265155700163300ustar00rootroot00000000000000/* * Copyright © 2013-2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include #include #include #include #include #include #include "util-macros.h" static inline void msleep(unsigned int ms) { usleep(ms * 1000); } static inline uint64_t us(uint64_t us) { return us; } static inline uint64_t ns2us(uint64_t ns) { return us(ns / 1000); } static inline uint64_t ms2us(uint64_t ms) { return us(ms * 1000); } static inline uint32_t ms2s(uint64_t ms) { return ms / 1000; } static inline uint64_t s2us(uint64_t s) { return ms2us(s * 1000); } static inline uint64_t h2us(uint64_t h) { return s2us(h * 3600); } static inline uint32_t us2ms(uint64_t us) { return (uint32_t)(us / 1000); } static inline uint32_t us2s(uint64_t us) { return ms2s(us2ms(us)); } static inline double us2ms_f(uint64_t us) { return (double)us / 1000.0; } static inline uint64_t tv2us(const struct timeval *tv) { return s2us(tv->tv_sec) + tv->tv_usec; } static inline uint64_t tp2us(const struct timespec *tp) { return s2us(tp->tv_sec) + ns2us(tp->tv_nsec); } static inline struct timeval us2tv(uint64_t time) { struct timeval tv; tv.tv_sec = time / ms2us(1000); tv.tv_usec = time % ms2us(1000); return tv; } static inline int now_in_us(uint64_t *us) { struct timespec ts = { 0, 0 }; if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { *us = 0; return -errno; } *us = s2us(ts.tv_sec) + ns2us(ts.tv_nsec); return 0; } struct human_time { unsigned int value; const char *unit; }; /** * Converts a time delta in µs to a human-readable time like "2h" or "4d" */ static inline struct human_time to_human_time(uint64_t us) { struct human_time t; struct c { const char *unit; unsigned int change_from_previous; uint64_t limit; } conversion[] = { {"us", 1, 5000}, {"ms", 1000, 5000}, {"s", 1000, 120}, {"min", 60, 120}, {"h", 60, 48}, {"d", 24, ~0}, }; uint64_t value = us; ARRAY_FOR_EACH(conversion, c) { value = value/c->change_from_previous; if (value < c->limit) { t.unit = c->unit; t.value = value; return t; } } assert(!"We should never get here"); } libinput-1.28.1/test/000077500000000000000000000000001477265155700144335ustar00rootroot00000000000000libinput-1.28.1/test/50-litest.conf000066400000000000000000000003161477265155700170300ustar00rootroot00000000000000# Ignore devices created by libinput's test suite (litest) Section "InputClass" Identifier "Ignore libinput test suite devices" MatchProduct "litest" Option "Ignore" "on" EndSection libinput-1.28.1/test/build-cxx.cc000066400000000000000000000001541477265155700166410ustar00rootroot00000000000000#include /* This is a build-test only */ using namespace std; int main(void) { return 0; } libinput-1.28.1/test/build-pedantic.c000066400000000000000000000001261477265155700174620ustar00rootroot00000000000000#include /* This is a build-test only */ int main(void) { return 0; } libinput-1.28.1/test/check-leftover-udev-rules.sh000077500000000000000000000002731477265155700217660ustar00rootroot00000000000000#!/bin/bash ls /run/udev/rules.d/*litest*.rules 2>/dev/null if [[ $? -eq 0 ]]; then exit 1 fi ls /etc/udev/hwdb.d/*litest*REMOVEME*.hwdb 2>/dev/null if [[ $? -eq 0 ]]; then exit 1 fi libinput-1.28.1/test/generate-gcov-report.sh000077500000000000000000000021141477265155700210270ustar00rootroot00000000000000#!/bin/bash -e if [[ $# -lt 2 ]]; then echo "Usage: ./generate-gcov-report.sh [ ... ]" exit 1 fi target_dir=$1 shift source_dirs=$* if [[ "${target_dir:0:1}" != '/' ]]; then target_dir="$PWD/$target_dir" fi summary_file="$target_dir/summary.txt" mkdir -p "$target_dir" rm -f "$target_dir"/*.gcov for dir in $source_dirs; do pushd "$dir" > /dev/null for file in *.c; do find ./ -name "*${file/\.c/.gcda}" \ \! -path "*selftest*" \ -exec gcov {} \; > /dev/null done find ./ -name "*.gcov" \ \! -path "*/`basename "$target_dir"`/*" \ -exec mv {} "$target_dir" \; popd > /dev/null done echo "========== coverage report ========" > "$summary_file" for file in "$target_dir"/*.gcov; do total=`grep -v " -:" "$file" | wc -l` missing=`grep "#####" "$file" | wc -l` hit=$((total - missing)); percent=$((($hit * 100)/$total)) fname=`basename "$file"` printf "%-50s total lines: %4s not tested: %4s (%3s%%)\n" "$fname" "$total" "$missing" "$percent">> "$summary_file" done echo "========== =============== ========" >> "$summary_file" libinput-1.28.1/test/helper-copy-and-exec-from-tmp.sh000077500000000000000000000005671477265155700224520ustar00rootroot00000000000000#!/bin/bash -x # # Usage: helper-copy-and-exec-from-tmp.sh /path/to/binary [args] # # Copies the given binary into a unique file in /tmp and executes it with # [args]. Exits with the same return code as the binary did. executable="$1" shift target_name=$(mktemp) cp "$executable" "$target_name" chmod +x "$target_name" "$target_name" "$@" rc=$? rm "$target_name" exit $rc libinput-1.28.1/test/libinput-test-suite.man000066400000000000000000000061111477265155700210610ustar00rootroot00000000000000.TH libinput-test-suite "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-test\-suite \- run the libinput test suite .SH SYNOPSIS .B libinput test\-suite [OPTIONS] .PP .SH DESCRIPTION .PP The .B "libinput test\-suite" command runs the libinput test suite. Its primary purpose is to verify distribution composes after package updates. Test suite failures usually indicate missing patches and/or incompatible lower system layers. .PP .B The test suite should not be run by users. Data loss is possible. .PP The test suite must be run as root. The test suite installs several files on the host system (see section \fBFILES\fR), runs system commands and creates virtual kernel devices via uinput. These devices will interfere with any active session and may cause data loss. .PP It is recommended that the test suite is run in a virtual machine and/or on a system not otherwise in use. A graphical environment is not required to run the test suite. .SH OPTIONS Note that the options may change in future releases of libinput. Test names, test device names and test group names may change at any time. .TP 8 .B \-\-filter\-test \fI"testname"\fB A glob limiting the tests to run. Specifying a filter sets the \fB\-\-jobs\fR default to 1. .TP 8 .B \-\-filter\-device \fI"devicename"\fB A glob limiting the devices to run tests for. Specifying a filter sets the \fB\-\-jobs\fR default to 1. .TP 8 .B \-\-filter\-group \fI"groupname"\fB A glob limiting the tests to (arbitrarily named) groups. Specifying a filter sets the \fB\-\-jobs\fR default to 1. .TP 8 .B \-\-filter\-deviceless \fBFOR INTERNAL USE ONLY\fR .TP 8 .B \-h, \-\-help Print help .TP 8 .B \-j, \-\-jobs 8 Number of parallel processes to run. Default: 8. .TP 8 .B \-\-list List all test cases and the devices they are run for. Test names, test device names and test group names may change at any time. .TP 8 .B \-\-verbose Enable verbose output, including libinput debug messages. .SH FILES The following directories are modified: .TP 8 .B @LIBINPUT_DATA_DIR@ Test device-specific quirks are installed in this directory with a custom prefix. Files in this directory are untouched but new files are installed and removed on exit. Existing files (e.g. from a previous aborted run) with the same name will be silently overwritten and removed. .TP 8 .B /run/udev/rules.d Test-specific udev rules are installed in this directory and removed on exit. .PP .SH SYSTEM SETUP The \fBxorg.conf.d(5)\fR snippet below ensures the X server ignores the test devices created by this test suite: .PP .RS 4 .nf .B "Section ""InputClass"" .B " Identifier ""Ignore libinput test suite devices"" .B " MatchProduct ""litest"" .B " Option ""Ignore"" ""on"" .B "EndSection" .fi .RE .PP No configuration is required for Wayland compositors. libinput's default mode will ignore test devices from this test suite. .SH BUGS Some tests are sensitive to timing. Where a system is under heavy load, a test may fail. Re-running the test with \fB\-\-filter-test\fR can help verify whether a test case failure was a true failure. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/test/litest-device-absinfo-override.c000066400000000000000000000045001477265155700225730ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x11, .vendor = 0x1234, .product = 0x4567, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 2000, 0, 0, 0 }, { ABS_Y, 0, 1400, 0, 0, 0 }, { ABS_PRESSURE, 0, 127, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 2000, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 1400, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; /* This device only exists to verify that the EVDEV_ABS override bits work * correctly */ TEST_DEVICE(LITEST_ABSINFO_OVERRIDE, .features = LITEST_IGNORED, .interface = NULL, .name = "absinfo override", .id = &input_id, .absinfo = absinfo, .events = events, .udev_properties = { { "EVDEV_ABS_00", "1:1000:100:10" }, { "EVDEV_ABS_01", "2:2000:200:20" }, { "EVDEV_ABS_35", "3:3000:300:30" }, { "EVDEV_ABS_36", "4:4000:400:40" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-acer-hawaii-keyboard.c000066400000000000000000000106541477265155700233140ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x4f2, .product = 0x1558, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_LINEFEED, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MACRO, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_KPPLUSMINUS, EV_KEY, KEY_PAUSE, /* EV_KEY, KEY_SCALE, */ EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SETUP, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_SCREENLOCK, EV_KEY, KEY_DIRECTION, EV_KEY, KEY_CYCLEWINDOWS, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_COMPUTER, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_SEARCH, EV_KEY, KEY_MEDIA, EV_KEY, KEY_FN, -1, -1, }; TEST_DEVICE(LITEST_ACER_HAWAII_KEYBOARD, .features = LITEST_KEYS, .interface = NULL, .name = "Chicony ACER Hawaii Keyboard", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-device-acer-hawaii-touchpad.c000066400000000000000000000064521477265155700233240ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x4f2, .product = 0x1558, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1151, 0, 0, 12 }, { ABS_Y, 0, 738, 0, 0, 14 }, { ABS_MT_SLOT, 0, 14, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1151, 0, 0, 12 }, { ABS_MT_POSITION_Y, 0, 738, 0, 0, 14 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_ACER_HAWAII_TOUCHPAD, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "Chicony ACER Hawaii Keyboard Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TOUCHPAD_INTEGRATION", "external" }, { NULL }, } ) libinput-1.28.1/test/litest-device-aiptek-tablet.c000066400000000000000000000110211477265155700220570ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { /* Note: this device does not send BTN_TOOL_PEN */ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, /* Note: this device does not send tilt, despite claiming it has it */ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { /* This tablet doesn't report BTN_TOOL_PEN 0 on proximity out but I *think* * it still reports pressure values of zero? Who knows, we'd have to * get our hands on the tablet again. Meanwhile, let's force the * pressure to zero at least so other tests don't have to guess. */ { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, /* Note: this device does not send tilt, despite claiming it has it */ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 5999, 0, 0, 26 }, { ABS_Y, 0, 4499, 0, 0, 15 }, { ABS_WHEEL, 0, 1023, 0, 0, 0 }, /* mute axis */ { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { ABS_TILT_X, -128, 127, 0, 0, 0 }, /* mute axis */ { ABS_TILT_Y, -128, 127, 0, 0, 0 }, /* mute axis */ { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x8ca, .product = 0x10, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOOL_MOUSE, EV_KEY, BTN_TOOL_LENS, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_MSC, MSC_SERIAL, -1, -1, }; TEST_DEVICE(LITEST_AIPTEK, .features = LITEST_TABLET | LITEST_HOVER | LITEST_FORCED_PROXOUT, .interface = &interface, .name = "Aiptek", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-alps-3fg.c000066400000000000000000000117431477265155700207600ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" struct alps { unsigned int first, second; unsigned int active_touches; }; static bool alps_create(struct litest_device *d) { d->private = zalloc(sizeof(struct alps)); return true; /* we want litest to create our device */ } static bool touch_down(struct litest_device *d, unsigned int slot, double x, double y) { struct alps *alps = d->private; alps->active_touches++; if (alps->active_touches == 1) alps->first = slot; if (alps->active_touches == 2) alps->second = slot; /* This device announces 4 slots but only does two slots. So * anything over 2 slots we just drop for events, * litest takes care of BTN_TOOL_* for us. */ if (alps->active_touches > 2) { /* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */ litest_event(d, EV_SYN, SYN_REPORT, 0); return true; } return false; } static bool touch_move(struct litest_device *d, unsigned int slot, double x, double y) { struct alps *alps = d->private; if (alps->active_touches > 2 && slot != alps->first && slot != alps->second) return true; return false; } static bool touch_up(struct litest_device *d, unsigned int slot) { struct alps *alps = d->private; assert(alps->active_touches >= 1); alps->active_touches--; /* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */ if (alps->active_touches > 2 && slot != alps->first && slot != alps->second) { litest_event(d, EV_SYN, SYN_REPORT, 0); return true; } if (slot == alps->first) alps->first = UINT_MAX; if (slot == alps->second) alps->second = UINT_MAX; return false; } static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .touch_down = touch_down, .touch_move = touch_move, .touch_up = touch_up, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x8, .version = 0x700, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_TOOL_QUINTTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; /* Note: we use the user-supplied resolution here, see #408 */ static struct input_absinfo absinfo[] = { { ABS_X, 0, 4095, 0, 0, 37 }, { ABS_Y, 0, 2047, 0, 0, 26 }, { ABS_PRESSURE, 0, 127, 0, 0, 0 }, { ABS_MT_SLOT, 0, 3, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 4095, 0, 0, 37 }, { ABS_MT_POSITION_Y, 0, 2047, 0, 0, 26 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_ALPS_3FG, .features = LITEST_TOUCHPAD | LITEST_BUTTON, .interface = &interface, .name = "AlpsPS/2 ALPS GlidePoint", .id = &input_id, .events = events, .absinfo = absinfo, .create = alps_create, ) libinput-1.28.1/test/litest-device-alps-dualpoint.c000066400000000000000000000075441477265155700223040ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x8, .version = 0x310, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_SEMI_MT, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 2000, 0, 0, 25 }, { ABS_Y, 0, 1400, 0, 0, 32 }, { ABS_PRESSURE, 0, 127, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 2000, 0, 0, 25 }, { ABS_MT_POSITION_Y, 0, 1400, 0, 0, 32 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest ALPS Touchpad]\n" "MatchName=litest AlpsPS/2 ALPS DualPoint TouchPad\n" "ModelTouchpadVisibleMarker=1\n"; TEST_DEVICE(LITEST_ALPS_DUALPOINT, .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SEMI_MT, .interface = &interface, .name = "AlpsPS/2 ALPS DualPoint TouchPad", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-alps-semi-mt.c000066400000000000000000000072231477265155700216520ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x8, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_SEMI_MT, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 2000, 0, 0, 0 }, { ABS_Y, 0, 1400, 0, 0, 0 }, { ABS_PRESSURE, 0, 127, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 2000, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 1400, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_ALPS_SEMI_MT, .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SEMI_MT, .interface = &interface, .name = "AlpsPS/2 ALPS GlidePoint", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-anker-mouse-kbd.c000066400000000000000000000127351477265155700223320ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=93474 * This is the keyboard device for this mouse. */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x4d9, .product = 0xfa50, }; static int events[] = { EV_REL, REL_HWHEEL, EV_KEY, KEY_ESC, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_PAUSE, EV_KEY, KEY_STOP, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_NEW, EV_KEY, KEY_REDO, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_AUTO, EV_KEY, BTN_0, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_TASKMANAGER, EV_KEY, KEY_JOURNAL, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_APPSELECT, EV_KEY, KEY_SCREENSAVER, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_KEY, KEY_BRIGHTNESS_MAX, EV_KEY, KEY_KBDINPUTASSIST_PREV, EV_KEY, KEY_KBDINPUTASSIST_NEXT, EV_KEY, KEY_KBDINPUTASSIST_PREVGROUP, EV_KEY, KEY_KBDINPUTASSIST_NEXTGROUP, EV_KEY, KEY_KBDINPUTASSIST_ACCEPT, EV_KEY, KEY_KBDINPUTASSIST_CANCEL, EV_MSC, MSC_SCAN, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_VOLUME, 0, 4096, 0, 0, 0 }, { ABS_MISC, 0, 255, 0, 0, 0 }, { 0x29, 0, 255, 0, 0, 0 }, { 0x2a, 0, 255, 0, 0, 0 }, { 0x2b, 0, 255, 0, 0, 0 }, { 0x2c, 0, 255, 0, 0, 0 }, { 0x2d, 0, 255, 0, 0, 0 }, { 0x2e, 0, 255, 0, 0, 0 }, /* Note: slot count artificially reduced for kernel * commit 206f533a0a7c ("Input: uinput - reject requests with unreasonable number of slots") */ { ABS_MT_SLOT, 0, 64, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 255, 0, 0, 0 }, { ABS_MT_WIDTH_MINOR, 0, 255, 0, 0, 0 }, { ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0, 0 }, { ABS_MT_ORIENTATION, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 255, 0, 0, 0 }, { .value = -1 }, }; TEST_DEVICE(LITEST_ANKER_MOUSE_KBD, .features = LITEST_KEYS | LITEST_WHEEL, .interface = NULL, .name = "USB Laser Game Mouse", .id = &input_id, .absinfo = absinfo, .events = events, ) libinput-1.28.1/test/litest-device-apple-appletouch.c000066400000000000000000000056671477265155700226170ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 70; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x03, .vendor = 0x5ac, .product = 0x21a, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1215, 0, 0, 0 }, { ABS_Y, 0, 588, 0, 0, 0 }, { ABS_PRESSURE, 0, 300, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest Apple Touchpad]\n" "MatchName=litest appletouch\n" "ModelAppleTouchpadOneButton=1\n"; TEST_DEVICE(LITEST_APPLETOUCH, .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SINGLE_TOUCH, .interface = &interface, .name = "appletouch", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-apple-internal-keyboard.c000066400000000000000000000120061477265155700240460ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x5ac, .product = 0x273, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_SCALE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_REWIND, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_KPLEFTPAREN, EV_KEY, KEY_KPRIGHTPAREN, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_DASHBOARD, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_SWITCHVIDEOMODE, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_KBDILLUMDOWN, EV_KEY, KEY_KBDILLUMUP, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_FN, EV_MSC, MSC_SCAN, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, EV_LED, LED_COMPOSE, EV_LED, LED_KANA, -1, -1 }; TEST_DEVICE(LITEST_APPLE_KEYBOARD, .features = LITEST_KEYS, .interface = NULL, .name = "Apple Inc. Apple Internal Keyboard / Trackpad", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-device-apple-magicmouse.c000066400000000000000000000070341477265155700225720ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 272 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 400 }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 272 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 400 }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_id input_id = { .bustype = 0x5, .vendor = 0x5ac, .product = 0x30d, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_HWHEEL, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_MT_SLOT, 0, 15, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 1020, 0, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 1020, 0, 0, 0 }, { ABS_MT_ORIENTATION, -31, 32, 1, 0, 0 }, { ABS_MT_POSITION_X, -1100, 1258, 4, 0, 26 }, { ABS_MT_POSITION_Y, -1589, 2047, 4, 0, 26 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_MAGICMOUSE, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = &interface, .name = "Apple Magic Mouse", .id = &input_id, .events = events, .absinfo = absinfo, /* Force MOUSE_DPI to 1000. systemd commit f013e99e160f says it's 1300 * but our test were written with different assumptions and it's not worth * re-writing those, so let's assume the default */ .udev_properties = { { "MOUSE_DPI", "1000" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-asus-rog-gladius.c000066400000000000000000000161071477265155700225310ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* Note: this is the second event node of this mouse only, the first event * node is just a normal mouse */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x0b05, .product = 0x181a, }; static int events[] = { EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_HWHEEL, EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_KPLEFTPAREN, EV_KEY, KEY_KPRIGHTPAREN, EV_KEY, KEY_NEW, EV_KEY, KEY_REDO, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_CANCEL, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SEND, EV_KEY, KEY_REPLY, EV_KEY, KEY_FORWARDMAIL, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_AUTO, EV_KEY, BTN_0, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_TASKMANAGER, EV_KEY, KEY_JOURNAL, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_APPSELECT, EV_KEY, KEY_SCREENSAVER, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_KEY, KEY_BRIGHTNESS_MAX, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, EV_LED, LED_COMPOSE, EV_LED, LED_KANA, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_VOLUME, 0, 668, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_MOUSE_GLADIUS, .features = LITEST_RELATIVE | LITEST_WHEEL | LITEST_KEYS, .interface = NULL, .name = "ASUS ROG GLADIUS", .id = &input_id, .absinfo = absinfo, .events = events, ) libinput-1.28.1/test/litest-device-atmel-hover.c000066400000000000000000000110261477265155700215610ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event up[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 }, { .type = EV_ABS, .code = ABS_MT_DISTANCE, .value = 1 }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .touch_up_events = up, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x0, .product = 0x0, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_TOOL_QUINTTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 960, 0, 0, 10 }, { ABS_Y, 0, 540, 0, 0, 10 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0, 0 }, { ABS_MT_ORIENTATION, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 960, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 540, 0, 0, 10 }, { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_DISTANCE, 0, 1, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_ATMEL_HOVER, .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_CLICKPAD | LITEST_HOVER, .interface = &interface, .name = "Atmel maXTouch Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-bcm5974.c000066400000000000000000000106431477265155700204340ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; case ABS_MT_TOUCH_MAJOR: case ABS_MT_TOUCH_MINOR: *value = 200; return 0; case ABS_MT_ORIENTATION: return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, -4824, 4824, 0, 0, 0 }, { ABS_Y, -172, 4290, 0, 0, 0 }, { ABS_PRESSURE, 0, 256, 5, 0, 0 }, { ABS_TOOL_WIDTH, 0, 16, 0, 0, 0 }, { ABS_MT_SLOT, 0, 15, 0, 0, 0 }, { ABS_MT_POSITION_X, -4824, 4824, 17, 0, 0 }, { ABS_MT_POSITION_Y, -172, 4290, 17, 0, 0 }, { ABS_MT_ORIENTATION, -16384, 16384, 3276, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 2048, 81, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 2048, 81, 0, 0 }, { ABS_MT_WIDTH_MAJOR, 0, 2048, 81, 0, 0 }, { ABS_MT_WIDTH_MINOR, 0, 2048, 81, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x5ac, .product = 0x249, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1 }; TEST_DEVICE(LITEST_BCM5974, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON | LITEST_APPLE_CLICKPAD, .interface = &interface, .name = "bcm5974", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-calibrated-touchscreen.c000066400000000000000000000055501477265155700237550ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1500, 0, 0, 0 }, { ABS_Y, 0, 2500, 0, 0, 0 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1500, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 2500, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x22, .product = 0x33, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_CALIBRATED_TOUCHSCREEN, .features = LITEST_TOUCH|LITEST_PRECALIBRATED, .interface = &interface, .name = "Calibrated Touchscreen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_CALIBRATION_MATRIX", "1.2 3.4 5.6 7.8 9.10 11.12" }, { "WL_OUTPUT", "myOutput" }, { NULL } }, ) libinput-1.28.1/test/litest-device-cyborg-rat-5.c000066400000000000000000000034111477265155700215500ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x6a3, .product = 0xcd5, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, BTN_FORWARD, EV_KEY, BTN_TASK, EV_KEY, 0x118, EV_KEY, 0x119, EV_KEY, 0x11a, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, -1 , -1, }; TEST_DEVICE(LITEST_CYBORG_RAT, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Saitek Cyborg R.A.T.5 Mouse", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-dell-canvas-totem-touch.c000066400000000000000000000061751477265155700240060ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_X, 0, 32767, 0, 0, 55 }, { ABS_Y, 0, 32767, 0, 0, 98 }, { ABS_MT_POSITION_X, 0, 32767, 0, 0, 55 }, { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 98 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x2575, .product = 0x0204, .version = 0x111, }; static int events[] = { EV_KEY, BTN_TOUCH, EV_MSC, MSC_TIMESTAMP, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_DELL_CANVAS_TOTEM_TOUCH, .features = LITEST_TOUCH, .interface = &interface, .name = "Advanced Silicon S.A. CoolTouch® System", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "dell-canvas-totem-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-dell-canvas-totem.c000066400000000000000000000103011477265155700226500ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* We don't expect anything but slot 0 to be used, ever */ #define TOTEM_SLOT 0 static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = TOTEM_SLOT }, { .type = EV_ABS, .code = ABS_MT_TOOL_TYPE, .value = MT_TOOL_DIAL }, /* fixed value in device */ { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 718 }, /* fixed value in device */ { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 718 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = TOTEM_SLOT }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 718 }, /* fixed value in device */ { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 718 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event up[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = TOTEM_SLOT }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_MT_ORIENTATION: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = down, .tablet_proximity_out_events = up, .tablet_motion_events = move, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 32767, 0, 0, 10 }, { ABS_MT_TOUCH_MINOR, 0, 32767, 0, 0, 10 }, { ABS_MT_ORIENTATION, -89, 89, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 32767, 0, 0, 55 }, { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 98 }, /* The real device has a min/max of 10/10 but uinput didn't allow * this */ { ABS_MT_TOOL_TYPE, 9, 10, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x2575, .product = 0x0204, .version = 0x111, }; static int events[] = { EV_KEY, BTN_0, EV_MSC, MSC_TIMESTAMP, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_DELL_CANVAS_TOTEM, .features = LITEST_TOTEM | LITEST_TABLET, .interface = &interface, .name = "Advanced Silicon S.A. CoolTouch® System System Multi Axis", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "dell-canvas-totem-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-elan-tablet.c000066400000000000000000000106611477265155700215320ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in_events[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out_events[] = { { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion_events[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static bool proximity_in(struct litest_device *d, unsigned int tool_type, double *x, double *y, struct axis_replacement *axes) { /* nothing special needed for the pen tool, so let litest handle * this */ if (tool_type == BTN_TOOL_PEN) return false; /* a non-pen tool requires the pen to be in proximity as well. */ int sx = litest_scale(d, ABS_X, *x); int sy = litest_scale(d, ABS_Y, *y); litest_event(d, EV_ABS, ABS_X, sx); litest_event(d, EV_ABS, ABS_X, sy); litest_event(d, EV_KEY, BTN_TOOL_PEN, 1); litest_event(d, EV_SYN, SYN_REPORT, 0); /* litest will append the proximity_in_events if we return false, * including the right tool event */ return false; } static bool proximity_out(struct litest_device *d, unsigned int tool_type) { /* a non-pen tool requires the pen to go out of proximity as well. * litest will append the proximity_out_events if we return false */ if (tool_type != BTN_TOOL_PEN) litest_event(d, EV_KEY, BTN_TOOL_PEN, 0); return false; } static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in_events, .tablet_proximity_out_events = proximity_out_events, .tablet_motion_events = motion_events, .tablet_proximity_in = proximity_in, .tablet_proximity_out = proximity_out, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 18176, 0, 0, 62 }, { ABS_Y, 0, 10240, 0, 0, 62 }, { ABS_PRESSURE, 0, 4096, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x4f3, .product = 0x23b9, .version = 0x100, }; /* Note: this tablet is one that sets both BTN_TOOL_PEN and BTN_TOOL_RUBBER, * see https://gitlab.freedesktop.org/libinput/libinput/-/issues/259 * The one in the issue isn't the exact same model, but only the pid and x/y * axis max differs differs. */ static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_MSC, MSC_SCAN, -1, -1, }; TEST_DEVICE(LITEST_ELAN_TABLET, .features = LITEST_TABLET, .interface = &interface, .name = "ELAN2514:00 04F3:23B9", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-elantech-touchpad.c000066400000000000000000000071011477265155700227250ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0xe, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1280, 0, 0, 0 }, { ABS_Y, 0, 704, 0, 0, 0 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1280, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 704, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_ELANTECH_TOUCHPAD, .features = LITEST_TOUCHPAD | LITEST_BUTTON, .interface = &interface, .name = "ETPS/2 Elantech Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-format-string.c000066400000000000000000000032551477265155700221370ustar00rootroot00000000000000 /* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x0123, .product = 0x0456, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE_FORMAT_STRING, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Evil %s %d %x Mouse %p %", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-generic-pressurepad.c000066400000000000000000000103031477265155700233020ustar00rootroot00000000000000/* * Copyright © 2021 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* This is the same device as the one from https://gitlab.freedesktop.org/libinput/libinput/-/issues/562 Except this one has a different input_id and sets the pressure resolution to test the generic pressure handling. */ static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { /* Always set pressure to zero. The real device sends pressure * values > 30 when the device is clicked but until this is a) * handled by libinput and b) integrated into this test suite * a zero value does the job. */ case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x123, .product = 0x4567, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_TOOL_QUINTTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1224, 0, 0, 12 }, { ABS_Y, 0, 756, 0, 0, 12 }, { ABS_PRESSURE, 0, 255, 0, 0, 40 }, /* some random resolution */ { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1224, 0, 0, 12 }, { ABS_MT_POSITION_Y, 0, 756, 0, 0, 12 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 40 }, /* some random resolution */ { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_GENERIC_PRESSUREPAD, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "Some Generic Pressurepad Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-generic-singletouch.c000066400000000000000000000046261477265155700233040ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 10000, 20000, 0, 0, 10 }, { ABS_Y, -2000, 2000, 0, 0, 9 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x01, .vendor = 0x02, .product = 0x03, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_GENERIC_SINGLETOUCH, .features = LITEST_SINGLE_TOUCH, .interface = &interface, .name = "generic_singletouch", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-gpio-keys.c000066400000000000000000000034771477265155700212600ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x19, .vendor = 0x1, .product = 0x1, }; static int events[] = { EV_SW, SW_LID, EV_SW, SW_TABLET_MODE, EV_KEY, KEY_POWER, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_POWER, -1, -1, }; static const char quirk_file[] = "[litest gpio quirk]\n" "MatchName=litest gpio-keys\n" "AttrLidSwitchReliability=reliable\n"; TEST_DEVICE(LITEST_GPIO_KEYS, .features = LITEST_SWITCH, .interface = NULL, .name = "gpio-keys", .id = &input_id, .events = events, .absinfo = NULL, .quirk_file = quirk_file, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, } ) libinput-1.28.1/test/litest-device-hp-wmi-hotkeys.c000066400000000000000000000034511477265155700222260ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x19, .vendor = 0x000, .product = 0x000, }; static int events[] = { EV_KEY, KEY_HELP, EV_KEY, KEY_SETUP, EV_KEY, KEY_PROG1, EV_KEY, KEY_ROTATE_DISPLAY, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_MEDIA, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_INFO, EV_SW, SW_TABLET_MODE, EV_SW, SW_DOCK, -1, -1, }; TEST_DEVICE(LITEST_HP_WMI_HOTKEYS, .features = LITEST_SWITCH, .interface = NULL, .name = "HP WMI hotkeys", .id = &input_id, .events = events, .absinfo = NULL, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, } ) libinput-1.28.1/test/litest-device-huion-pentablet.c000066400000000000000000000067101477265155700224400ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { /* This tablet doesn't report BTN_TOOL_PEN 0 on proximity out but I *think* * it still reports pressure values of zero? Who knows, we'd have to * get our hands on the tablet again. Meanwhile, let's force the * pressure to zero at least so other tests don't have to guess. */ { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 40000, 0, 0, 157 }, { ABS_Y, 0, 25000, 0, 0, 157 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, /* Note: this VID/PID is shared with multiple devices, see the libwacom database for a list */ .vendor = 0x256c, .product = 0x6e, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SCAN, -1, -1, }; TEST_DEVICE(LITEST_HUION_TABLET, .features = LITEST_TABLET | LITEST_HOVER | LITEST_FORCED_PROXOUT, .interface = &interface, .name = "HUION PenTablet Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-huion-q620m-dial.c000066400000000000000000000043451477265155700222400ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_MISC, 0, 255, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, /* Note: this VID/PID is shared with multiple devices, see the libwacom database for a list */ .vendor = 0x256c, .product = 0x006d, }; static int events[] = { EV_KEY, BTN_0, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, -1, -1, }; /* Device from https://gitlab.freedesktop.org/libinput/libinput/-/issues/600 */ TEST_DEVICE(LITEST_HUION_Q620M_DIAL, .features = LITEST_TABLET_PAD | LITEST_DIAL, .interface = &interface, .name = "HUION Huion Tablet_Q620M Dial", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-ignored-mouse.c000066400000000000000000000033171477265155700221170ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x17ef, .product = 0x6019, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, -1 , -1, }; TEST_DEVICE(LITEST_IGNORED_MOUSE, .features = LITEST_IGNORED | LITEST_BUTTON | LITEST_RELATIVE, .interface = NULL, .name = "Ignored Mouse", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "LIBINPUT_IGNORE_DEVICE", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-keyboard-all-codes.c000066400000000000000000000040541477265155700230020ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" #define NAME "All event codes keyboard" static bool all_codes_create(struct litest_device *d); static struct input_id input_id = { .bustype = 0x11, .vendor = 0x1, .product = 0x1, }; TEST_DEVICE(LITEST_KEYBOARD_ALL_CODES, .features = LITEST_KEYS, .interface = NULL, .create = all_codes_create, .name = NAME, .id = &input_id, .events = NULL, .absinfo = NULL, ) static bool all_codes_create(struct litest_device *d) { int events[KEY_MAX * 2 + 2]; int code, idx; for (idx = 0, code = 0; code < KEY_MAX; code++) { const char *name = libevdev_event_code_get_name(EV_KEY, code); if (strstartswith(name, "BTN_")) continue; events[idx++] = EV_KEY; events[idx++] = code; } events[idx++] = -1; events[idx++] = -1; d->uinput = litest_create_uinput_device_from_description(NAME, &input_id, NULL, events); return false; } libinput-1.28.1/test/litest-device-keyboard-quirked.c000066400000000000000000000137771477265155700226170ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x11, .vendor = 0x1, .product = 0x1, }; static int events[] = { EV_REL, REL_X, EV_REL, REL_Y, EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_LINEFEED, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MACRO, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_KPPLUSMINUS, EV_KEY, KEY_PAUSE, /* EV_KEY, KEY_SCALE, */ EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SETUP, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_SCREENLOCK, EV_KEY, KEY_DIRECTION, EV_KEY, KEY_CYCLEWINDOWS, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_COMPUTER, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_SEARCH, EV_KEY, KEY_MEDIA, EV_KEY, KEY_FN, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, /* gets disabled */ INPUT_PROP_MAX, INPUT_PROP_POINTING_STICK, -1, -1, }; static const char quirk_file[] = "[litest Quirked Keyboard enable buttons]\n" "MatchName=litest Quirked Keyboard\n" "AttrEventCode=+BTN_RIGHT;+BTN_MIDDLE;+EV_KEY:0x110\n" /* BTN_LEFT */ "\n" "[litest Quirked Keyboard disable buttons]\n" "MatchName=litest Quirked Keyboard\n" "AttrEventCode=-BTN_MIDDLE;-BTN_RIGHT\n" "\n" "[litest Quirked Keyboard re-enable buttons]\n" "MatchName=litest Quirked Keyboard\n" "AttrEventCode=+BTN_RIGHT\n" "\n" "[litest Quirked keyboard disable F1-F3]\n" "MatchName=litest Quirked Keyboard\n" "AttrEventCode=-KEY_F1;-EV_KEY:0x3c;-KEY_F3\n" #if HAVE_LIBEVDEV_DISABLE_PROPERTY "\n" "[litest Quirked keyboard enable buttonpad]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=+INPUT_PROP_BUTTONPAD\n" "\n" "[litest Quirked keyboard disable pointingstick]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=-INPUT_PROP_POINTING_STICK\n" "\n" "[litest Quirked keyboard enable direct]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=+INPUT_PROP_DIRECT\n" "\n" "[litest Quirked keyboard disable direct]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=-INPUT_PROP_DIRECT\n" "\n" "[litest Quirked keyboard disable semi-mt]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=-INPUT_PROP_SEMI_MT\n" "\n" "[litest Quirked keyboard enable semi-mt]\n" "MatchName=litest Quirked Keyboard\n" "AttrInputProp=+INPUT_PROP_SEMI_MT\n" #endif ; TEST_DEVICE(LITEST_KEYBOARD_QUIRKED, .features = LITEST_KEYS | LITEST_IGNORED, /* Only use this keyboard in specific tests */ .interface = NULL, .name = "Quirked Keyboard", .id = &input_id, .events = events, .absinfo = NULL, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-keyboard-razer-blackwidow.c000066400000000000000000000174651477265155700244200ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=89783 * This is the second of 4 devices exported by this keyboard, the first is * just a basic keyboard that is identical to the normal litest-keyboard.c * file. */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1532, .product = 0x11b, }; static int events[] = { EV_REL, REL_HWHEEL, EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_KPLEFTPAREN, EV_KEY, KEY_KPRIGHTPAREN, EV_KEY, KEY_NEW, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_AUTO, EV_KEY, BTN_0, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_TASKMANAGER, EV_KEY, KEY_JOURNAL, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_APPSELECT, EV_KEY, KEY_SCREENSAVER, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_KEY, KEY_BRIGHTNESS_MAX, EV_MSC, MSC_SCAN, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_VOLUME, 0, 572, 0, 0, 0 }, { ABS_MISC, 0, 255, 0, 0, 0 }, { 0x29, 0, 255, 0, 0, 0 }, { 0x2a, 0, 255, 0, 0, 0 }, { 0x2b, 0, 255, 0, 0, 0 }, { 0x2c, 0, 255, 0, 0, 0 }, { 0x2d, 0, 255, 0, 0, 0 }, { 0x2e, 0, 255, 0, 0, 0 }, /* Note: slot count artificially reduced for kernel * commit 206f533a0a7c ("Input: uinput - reject requests with unreasonable number of slots") */ { 0x2f, 0, 64, 0, 0, 0 }, { 0x30, 0, 255, 0, 0, 0 }, { 0x31, 0, 255, 0, 0, 0 }, { 0x32, 0, 255, 0, 0, 0 }, { 0x33, 0, 255, 0, 0, 0 }, { 0x34, 0, 255, 0, 0, 0 }, { 0x35, 0, 255, 0, 0, 0 }, { 0x36, 0, 255, 0, 0, 0 }, { 0x37, 0, 255, 0, 0, 0 }, { 0x38, 0, 255, 0, 0, 0 }, { 0x39, 0, 255, 0, 0, 0 }, { 0x3a, 0, 255, 0, 0, 0 }, { 0x3b, 0, 255, 0, 0, 0 }, { 0x3c, 0, 255, 0, 0, 0 }, { 0x3d, 0, 255, 0, 0, 0 }, { 0x3e, 0, 255, 0, 0, 0 }, { 0x3f, 0, 255, 0, 0, 0 }, { .value = -1 }, }; TEST_DEVICE(LITEST_KEYBOARD_BLACKWIDOW, .features = LITEST_KEYS | LITEST_WHEEL, .interface = NULL, .name = "Razer Razer BlackWidow 2013", .id = &input_id, .absinfo = absinfo, .events = events, ) libinput-1.28.1/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c000066400000000000000000000115131477265155700273150ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=102039 * This is the 'video switch' of 2 devices exported by this keyboard. */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1532, .product = 0x220, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_KPLEFTPAREN, EV_KEY, KEY_KPRIGHTPAREN, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_UNKNOWN, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, EV_MSC, MSC_SCAN, -1 , -1, }; TEST_DEVICE(LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH, .features = LITEST_KEYS, .interface = NULL, .name = "Razer Razer Blade Stealth", .id = &input_id, .events = events, ) libinput-1.28.1/test/litest-device-keyboard-razer-blade-stealth.c000066400000000000000000000173411477265155700247740ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=102039 * This is the 'normal keyboard' of 2 devices exported by this keyboard. */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1532, .product = 0x220, }; static int events[] = { EV_REL, REL_HWHEEL, EV_KEY, BTN_0, EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_KPLEFTPAREN, EV_KEY, KEY_KPRIGHTPAREN, EV_KEY, KEY_NEW, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_AUTO, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_TASKMANAGER, EV_KEY, KEY_JOURNAL, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_APPSELECT, EV_KEY, KEY_SCREENSAVER, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_KEY, KEY_BRIGHTNESS_MAX, EV_MSC, MSC_SCAN, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_VOLUME, 0, 572, 0, 0, 0 }, { ABS_MISC, 0, 255, 0, 0, 0 }, { 0x29, 0, 255, 0, 0, 0 }, { 0x2a, 0, 255, 0, 0, 0 }, { 0x2b, 0, 255, 0, 0, 0 }, { 0x2c, 0, 255, 0, 0, 0 }, { 0x2d, 0, 255, 0, 0, 0 }, { 0x2e, 0, 255, 0, 0, 0 }, /* Note: slot count artificially reduced for kernel * commit 206f533a0a7c ("Input: uinput - reject requests with unreasonable number of slots") */ { 0x2f, 0, 64, 0, 0, 0 }, { 0x30, 0, 255, 0, 0, 0 }, { 0x31, 0, 255, 0, 0, 0 }, { 0x32, 0, 255, 0, 0, 0 }, { 0x33, 0, 255, 0, 0, 0 }, { 0x34, 0, 255, 0, 0, 0 }, { 0x35, 0, 255, 0, 0, 0 }, { 0x36, 0, 255, 0, 0, 0 }, { 0x37, 0, 255, 0, 0, 0 }, { 0x38, 0, 255, 0, 0, 0 }, { 0x39, 0, 255, 0, 0, 0 }, { 0x3a, 0, 255, 0, 0, 0 }, { 0x3b, 0, 255, 0, 0, 0 }, { 0x3c, 0, 255, 0, 0, 0 }, { 0x3d, 0, 255, 0, 0, 0 }, { 0x3e, 0, 255, 0, 0, 0 }, { 0x3f, 0, 255, 0, 0, 0 }, { .value = -1 }, }; TEST_DEVICE(LITEST_KEYBOARD_BLADE_STEALTH, .features = LITEST_KEYS | LITEST_WHEEL, .interface = NULL, .name = "Razer Razer Blade Stealth", .id = &input_id, .absinfo = absinfo, .events = events, ) libinput-1.28.1/test/litest-device-keyboard.c000066400000000000000000000107311477265155700211400ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x11, .vendor = 0x1, .product = 0x1, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_ZENKAKUHANKAKU, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_KATAKANA, EV_KEY, KEY_HIRAGANA, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_LINEFEED, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MACRO, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_KPPLUSMINUS, EV_KEY, KEY_PAUSE, /* EV_KEY, KEY_SCALE, */ EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SETUP, EV_KEY, KEY_SLEEP, EV_KEY, KEY_WAKEUP, EV_KEY, KEY_SCREENLOCK, EV_KEY, KEY_DIRECTION, EV_KEY, KEY_CYCLEWINDOWS, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_COMPUTER, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_SEARCH, EV_KEY, KEY_MEDIA, EV_KEY, KEY_FN, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, -1, -1, }; TEST_DEVICE(LITEST_KEYBOARD, .features = LITEST_KEYS, .interface = NULL, .name = "AT Translated Set 2 keyboard", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-device-lenovo-scrollpoint.c000066400000000000000000000035111477265155700232060ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x04b3, .product = 0x3109, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, EV_REL, REL_HWHEEL, -1 , -1, }; /* Note: device is not tagged with LITEST_WHEEL to avoid running the * "standard" wheel tests. Device has a custom wheel * behavior that is tested directly. */ TEST_DEVICE(LITEST_LENOVO_SCROLLPOINT, .features = LITEST_RELATIVE | LITEST_BUTTON, .interface = NULL, .name = "HID 04b3:3109", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-lid-switch-surface3.c000066400000000000000000000034431477265155700231220ustar00rootroot00000000000000/* * Copyright © 2017 James Ye * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x19, .vendor = 0x0, .product = 0x5, }; static int events[] = { EV_SW, SW_LID, -1, -1, }; static const char quirk_file[] = "[litest Surface Lid]\n" "MatchName=litest Lid Switch Surface3\n" "AttrLidSwitchReliability=write_open\n"; TEST_DEVICE(LITEST_LID_SWITCH_SURFACE3, .features = LITEST_SWITCH, .interface = NULL, .name = "Lid Switch Surface3", .id = &input_id, .events = events, .absinfo = NULL, .quirk_file = quirk_file, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-lid-switch.c000066400000000000000000000033421477265155700214070ustar00rootroot00000000000000/* * Copyright © 2017 James Ye * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x19, .vendor = 0x0, .product = 0x5, }; static int events[] = { EV_SW, SW_LID, -1, -1, }; static const char quirk_file[] = "[litest Lid Switch]\n" "MatchName=litest Lid Switch\n" "AttrLidSwitchReliability=reliable\n"; TEST_DEVICE(LITEST_LID_SWITCH, .features = LITEST_SWITCH, .interface = NULL, .name = "Lid Switch", .id = &input_id, .events = events, .absinfo = NULL, .quirk_file = quirk_file, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-logitech-media-keyboard-elite.c000066400000000000000000000046701477265155700251160ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" /* Description taken from * https://gitlab.freedesktop.org/libinput/libinput/-/issues/514 */ static struct input_id input_id = { .bustype = 0x3, .vendor = 0x46d, .product = 0x30f, }; static int events[] = { EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_UNDO, EV_KEY, KEY_HELP, EV_KEY, KEY_CALC, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_REWIND, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REDO, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_PRINT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_SAVE, EV_KEY, 319, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_STYLUS3, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_MESSENGER, EV_MSC, MSC_SCAN, -1, -1, }; TEST_DEVICE(LITEST_KEYBOARD_LOGITECH_MEDIA_KEYBOARD_ELITE, .features = LITEST_KEYS, .interface = NULL, .name = "Logitech Logitech USB Keyboard Consumer Control", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-device-logitech-trackball.c000066400000000000000000000032441477265155700230740ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x46d, .product = 0xc408, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_REL, REL_X, EV_REL, REL_Y, -1 , -1, }; TEST_DEVICE(LITEST_LOGITECH_TRACKBALL, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_TRACKBALL, .interface = NULL, .name = "Logitech USB Trackball", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-magic-trackpad.c000066400000000000000000000102241477265155700222040ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_MT_TOUCH_MAJOR: case ABS_MT_TOUCH_MINOR: *value = 200; return 0; case ABS_MT_ORIENTATION: return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, -2909, 3167, 4, 0, 46 }, { ABS_Y, -2456, 2565, 4, 0, 45 }, { ABS_MT_SLOT, 0, 15, 0, 0, 0 }, { ABS_MT_POSITION_X, -2909, 3167, 4, 0, 46 }, { ABS_MT_POSITION_Y, -2456, 2565, 4, 0, 45 }, { ABS_MT_ORIENTATION, -31, 32, 1, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 1020, 4, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 1020, 4, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x5, .vendor = 0x5ac, .product = 0x30e, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1 }; TEST_DEVICE(LITEST_MAGIC_TRACKPAD, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON | LITEST_APPLE_CLICKPAD, .interface = &interface, .name = "Apple Wireless Trackpad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TOUCHPAD_INTEGRATION", "external" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-mouse-low-dpi.c000066400000000000000000000034121477265155700220370ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1, .product = 0x1, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, EV_REL, REL_HWHEEL, EV_REL, REL_HWHEEL_HI_RES, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE_LOW_DPI, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Low DPI Mouse", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "MOUSE_DPI", "400@125" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-mouse-roccat.c000066400000000000000000000112711477265155700217410ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1e7d, .product = 0x2e22, }; static int events[] = { EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_HWHEEL, EV_REL, REL_DIAL, EV_KEY, KEY_ESC, EV_KEY, KEY_ENTER, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_UP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_DOWN, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_PAUSE, EV_KEY, KEY_STOP, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_NEW, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_AUTO, EV_KEY, BTN_0, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_TASKMANAGER, EV_KEY, KEY_JOURNAL, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_APPSELECT, EV_KEY, KEY_SCREENSAVER, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_KEY, KEY_BRIGHTNESS_MAX, -1 , -1, }; static struct input_absinfo absinfo[] = { { ABS_VOLUME, 0, 572, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { ABS_MISC + 1, 0, 0, 0, 0, 0 }, { ABS_MISC + 2, 0, 0, 0, 0, 0 }, { ABS_MISC + 3, 0, 0, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_MOUSE_ROCCAT, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL | LITEST_KEYS, .interface = NULL, .name = "ROCCAT ROCCAT Kone XTD", .id = &input_id, .absinfo = absinfo, .events = events, ) libinput-1.28.1/test/litest-device-mouse-wheel-click-angle.c000066400000000000000000000034231477265155700237410ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1234, .product = 0x5678, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE_WHEEL_CLICK_ANGLE, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Wheel Click Angle Mouse", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "MOUSE_WHEEL_CLICK_ANGLE", "-7" }, { "MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL", "13" }, { NULL }, } ) libinput-1.28.1/test/litest-device-mouse-wheel-click-count.c000066400000000000000000000035551477265155700240110ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1234, .product = 0x5678, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE_WHEEL_CLICK_COUNT, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Wheel Click Count Mouse", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "MOUSE_WHEEL_CLICK_ANGLE", "-15" }, { "MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL", "13" }, { "MOUSE_WHEEL_CLICK_COUNT", "-14" }, { "MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL", "27" }, { NULL }, } ) libinput-1.28.1/test/litest-device-mouse-wheel-tilt.c000066400000000000000000000034221477265155700225430ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x17ef, .product = 0x6019, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_HWHEEL, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE_WHEEL_TILT, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Wheel Tilt Mouse", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "MOUSE_WHEEL_TILT_HORIZONTAL", "1" }, { "MOUSE_WHEEL_TILT_VERTICAL", "1" }, { NULL }, } ) libinput-1.28.1/test/litest-device-mouse.c000066400000000000000000000032361477265155700204720ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x17ef, .product = 0x6019, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, -1 , -1, }; TEST_DEVICE(LITEST_MOUSE, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, .interface = NULL, .name = "Lenovo Optical USB Mouse", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-ms-nano-transceiver-mouse.c000066400000000000000000000034161477265155700243630ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x045e, .product = 0x0800, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_WHEEL, EV_REL, REL_DIAL, EV_REL, REL_HWHEEL, -1 , -1, }; TEST_DEVICE(LITEST_MS_NANO_TRANSCEIVER_MOUSE, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL | LITEST_NO_DEBOUNCE, .interface = NULL, .name = "Microsoft Microsoft® Nano Transceiver v2.0", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-ms-surface-cover.c000066400000000000000000000220071477265155700225200ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; /* We define down/move so that we can emulate fake touches on this device, to make sure nothing crashes. */ static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1022, 0, 0, 12 }, { ABS_Y, 0, 487, 0, 0, 12 }, { ABS_VOLUME, 0, 1023, 0, 0, 0 }, { ABS_MISC, 0, 255, 0, 0, 0 }, { 41, 0, 255, 0, 0, 0 }, { 42, -127, 127, 0, 0, 0 }, { 43, -127, 127, 0, 0, 0 }, { 44, -127, 127, 0, 0, 0 }, { 45, -127, 127, 0, 0, 0 }, { 46, -127, 127, 0, 0, 0 }, /* ABS_MT range overlap starts here */ /* Note: slot count artificially reduced for kernel * commit 206f533a0a7c ("Input: uinput - reject requests with unreasonable number of slots") */ { 47, 0, 64, 0, 0, 0 }, /* ABS_MT_SLOT */ { 48, -127, 127, 0, 0, 0 }, { 49, -127, 127, 0, 0, 0 }, { 50, -127, 127, 0, 0, 0 }, { 51, -127, 127, 0, 0, 0 }, { 52, -127, 127, 0, 0, 0 }, { 53, -127, 127, 0, 0, 0 }, { 54, -127, 127, 0, 0, 0 }, { 55, -127, 127, 0, 0, 0 }, { 56, -127, 127, 0, 0, 0 }, { 57, -127, 127, 0, 0, 0 }, { 58, -127, 127, 0, 0, 0 }, { 59, -127, 127, 0, 0, 0 }, { 60, -127, 127, 0, 0, 0 }, { 61, -127, 127, 0, 0, 0 }, /* ABS_MT_TOOL_Y */ { 62, -127, 127, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x45e, .product = 0x7dc, }; static int events[] = { EV_REL, REL_X, EV_REL, REL_Y, EV_REL, REL_HWHEEL, EV_REL, REL_DIAL, EV_REL, REL_WHEEL, EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_RO, EV_KEY, KEY_HENKAN, EV_KEY, KEY_KATAKANAHIRAGANA, EV_KEY, KEY_MUHENKAN, EV_KEY, KEY_KPJPCOMMA, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_POWER, EV_KEY, KEY_KPEQUAL, EV_KEY, KEY_PAUSE, EV_KEY, KEY_KPCOMMA, EV_KEY, KEY_HANGEUL, EV_KEY, KEY_HANJA, EV_KEY, KEY_YEN, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, KEY_STOP, EV_KEY, KEY_AGAIN, EV_KEY, KEY_PROPS, EV_KEY, KEY_UNDO, EV_KEY, KEY_FRONT, EV_KEY, KEY_COPY, EV_KEY, KEY_OPEN, EV_KEY, KEY_PASTE, EV_KEY, KEY_FIND, EV_KEY, KEY_CUT, EV_KEY, KEY_HELP, EV_KEY, KEY_MENU, EV_KEY, KEY_CALC, EV_KEY, KEY_SLEEP, EV_KEY, KEY_FILE, EV_KEY, KEY_WWW, EV_KEY, KEY_COFFEE, EV_KEY, KEY_MAIL, EV_KEY, KEY_BOOKMARKS, EV_KEY, KEY_BACK, EV_KEY, KEY_FORWARD, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_NEXTSONG, EV_KEY, KEY_PLAYPAUSE, EV_KEY, KEY_PREVIOUSSONG, EV_KEY, KEY_STOPCD, EV_KEY, KEY_RECORD, EV_KEY, KEY_REWIND, EV_KEY, KEY_PHONE, EV_KEY, KEY_CONFIG, EV_KEY, KEY_HOMEPAGE, EV_KEY, KEY_REFRESH, EV_KEY, KEY_EXIT, EV_KEY, KEY_EDIT, EV_KEY, KEY_SCROLLUP, EV_KEY, KEY_SCROLLDOWN, EV_KEY, KEY_NEW, EV_KEY, KEY_REDO, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F16, EV_KEY, KEY_F17, EV_KEY, KEY_F18, EV_KEY, KEY_F19, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F22, EV_KEY, KEY_F23, EV_KEY, KEY_F24, EV_KEY, KEY_CLOSE, EV_KEY, KEY_PLAY, EV_KEY, KEY_FASTFORWARD, EV_KEY, KEY_BASSBOOST, EV_KEY, KEY_PRINT, EV_KEY, KEY_CAMERA, EV_KEY, KEY_CHAT, EV_KEY, KEY_SEARCH, EV_KEY, KEY_FINANCE, EV_KEY, KEY_CANCEL, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_SEND, EV_KEY, KEY_REPLY, EV_KEY, KEY_FORWARDMAIL, EV_KEY, KEY_SAVE, EV_KEY, KEY_DOCUMENTS, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_VIDEO_NEXT, EV_KEY, KEY_BRIGHTNESS_ZERO, EV_KEY, BTN_0, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, KEY_SELECT, EV_KEY, KEY_GOTO, EV_KEY, KEY_INFO, EV_KEY, KEY_PROGRAM, EV_KEY, KEY_PVR, EV_KEY, KEY_SUBTITLE, EV_KEY, KEY_ZOOM, EV_KEY, KEY_KEYBOARD, EV_KEY, KEY_PC, EV_KEY, KEY_TV, EV_KEY, KEY_TV2, EV_KEY, KEY_VCR, EV_KEY, KEY_VCR2, EV_KEY, KEY_SAT, EV_KEY, KEY_CD, EV_KEY, KEY_TAPE, EV_KEY, KEY_TUNER, EV_KEY, KEY_PLAYER, EV_KEY, KEY_DVD, EV_KEY, KEY_AUDIO, EV_KEY, KEY_VIDEO, EV_KEY, KEY_MEMO, EV_KEY, KEY_CALENDAR, EV_KEY, KEY_RED, EV_KEY, KEY_GREEN, EV_KEY, KEY_YELLOW, EV_KEY, KEY_BLUE, EV_KEY, KEY_CHANNELUP, EV_KEY, KEY_CHANNELDOWN, EV_KEY, KEY_LAST, EV_KEY, KEY_NEXT, EV_KEY, KEY_RESTART, EV_KEY, KEY_SLOW, EV_KEY, KEY_SHUFFLE, EV_KEY, KEY_PREVIOUS, EV_KEY, KEY_VIDEOPHONE, EV_KEY, KEY_GAMES, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_ZOOMRESET, EV_KEY, KEY_WORDPROCESSOR, EV_KEY, KEY_EDITOR, EV_KEY, KEY_SPREADSHEET, EV_KEY, KEY_GRAPHICSEDITOR, EV_KEY, KEY_PRESENTATION, EV_KEY, KEY_DATABASE, EV_KEY, KEY_NEWS, EV_KEY, KEY_VOICEMAIL, EV_KEY, KEY_ADDRESSBOOK, EV_KEY, KEY_MESSENGER, EV_KEY, KEY_DISPLAYTOGGLE, EV_KEY, KEY_SPELLCHECK, EV_KEY, KEY_LOGOFF, EV_KEY, KEY_MEDIA_REPEAT, EV_KEY, KEY_IMAGES, EV_KEY, 576, EV_KEY, 577, EV_KEY, 578, EV_KEY, 579, EV_KEY, 580, EV_KEY, 581, EV_KEY, 582, EV_KEY, 592, EV_KEY, 593, EV_KEY, 608, EV_KEY, 609, EV_KEY, 610, EV_KEY, 611, EV_KEY, 612, EV_KEY, 613, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, -1, -1, }; TEST_DEVICE(LITEST_MS_SURFACE_COVER, .features = LITEST_KEYS | LITEST_ABSOLUTE | LITEST_RELATIVE | LITEST_FAKE_MT | LITEST_BUTTON | LITEST_WHEEL, .interface = &interface, .name = "Microsoft Surface Type Cover", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-nexus4-touch-screen.c000066400000000000000000000061351477265155700231660ustar00rootroot00000000000000/* * Copyright © 2015 Canonical, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1500, 0, 0, 0 }, { ABS_Y, 0, 2500, 0, 0, 0 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1500, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 2500, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 15, 1, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x1, .vendor = 0x43e, .product = 0x26, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_NEXUS4_TOUCH_SCREEN, .features = LITEST_TOUCH|LITEST_ELLIPSE, .interface = &interface, .name = "Nexus 4 touch screen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-protocol-a-touch-screen.c000066400000000000000000000122551477265155700240170ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" #define PROTOCOL_A_MAX_SLOTS 10 struct protocolA_device { struct slot { bool active; int x, y; int tracking_id; } slots[PROTOCOL_A_MAX_SLOTS]; unsigned int nslots; }; static bool protocolA_create(struct litest_device *d) { struct protocolA_device *dev = zalloc(sizeof(*dev)); dev->nslots = PROTOCOL_A_MAX_SLOTS; d->private = dev; return true; /* we want litest to create our device */ } static bool protocolA_down(struct litest_device *d, unsigned int slot, double x, double y) { struct protocolA_device *dev = d->private; static int tracking_id; bool first = true; assert(slot <= PROTOCOL_A_MAX_SLOTS); x = litest_scale(d, ABS_X, x); y = litest_scale(d, ABS_Y, y); for (unsigned int i = 0; i < dev->nslots; i++) { struct slot *s = &dev->slots[i]; if (slot == i) { assert(!s->active); s->active = true; s->x = x; s->y = y; s->tracking_id = ++tracking_id; } if (!s->active) continue; if (first) { litest_event(d, EV_ABS, ABS_X, s->x); litest_event(d, EV_ABS, ABS_Y, s->y); first = false; } litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id); litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x); litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y); litest_event(d, EV_SYN, SYN_MT_REPORT, 0); } if (!first) { litest_event(d, EV_KEY, BTN_TOUCH, 1); litest_event(d, EV_SYN, SYN_REPORT, 0); } return true; /* we handled the event */ } static bool protocolA_move(struct litest_device *d, unsigned int slot, double x, double y) { struct protocolA_device *dev = d->private; bool first = true; assert(slot <= PROTOCOL_A_MAX_SLOTS); x = litest_scale(d, ABS_X, x); y = litest_scale(d, ABS_Y, y); for (unsigned int i = 0; i < dev->nslots; i++) { struct slot *s = &dev->slots[i]; if (slot == i) { assert(s->active); s->x = x; s->y = y; } if (!s->active) continue; if (first) { litest_event(d, EV_ABS, ABS_X, s->x); litest_event(d, EV_ABS, ABS_X, s->y); first = false; } litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id); litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x); litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y); litest_event(d, EV_SYN, SYN_MT_REPORT, 0); } if (!first) litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool protocolA_up(struct litest_device *d, unsigned int slot) { struct protocolA_device *dev = d->private; bool first = true; assert(slot <= PROTOCOL_A_MAX_SLOTS); for (unsigned int i = 0; i < dev->nslots; i++) { struct slot *s = &dev->slots[i]; if (slot == i) { assert(s->active); s->active = false; litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id); litest_event(d, EV_SYN, SYN_MT_REPORT, 0); } if (!s->active) continue; if (first) { litest_event(d, EV_ABS, ABS_X, s->x); litest_event(d, EV_ABS, ABS_X, s->y); first = false; } litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id); litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x); litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y); litest_event(d, EV_SYN, SYN_MT_REPORT, 0); } if (first) litest_event(d, EV_KEY, BTN_TOUCH, 0); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static struct litest_device_interface interface = { .touch_down = protocolA_down, .touch_move = protocolA_move, .touch_up = protocolA_up, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 32767, 0, 0, 0 }, { ABS_Y, 0, 32767, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 32767, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 1, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0xeef, .product = 0x20, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_PROTOCOL_A_SCREEN, .features = LITEST_PROTOCOL_A|LITEST_TOUCH, .create = protocolA_create, .interface = &interface, .name = "Protocol A touch screen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-qemu-usb-tablet.c000066400000000000000000000052561477265155700223550ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" #include static bool touch_down(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_move(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_up(struct litest_device *d, unsigned int slot) { assert(slot == 0); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static struct litest_device_interface interface = { .touch_down = touch_down, .touch_move = touch_move, .touch_up = touch_up, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 32767, 0, 0, 0 }, { ABS_Y, 0, 32767, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x03, .vendor = 0x627, .product = 0x01, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_WHEEL, -1, -1, }; TEST_DEVICE(LITEST_QEMU_TABLET, .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE, .interface = &interface, .name = "QEMU 0.12.1 QEMU USB Tablet", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-sony-vaio-keys.c000066400000000000000000000047171477265155700222440ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" /* Description taken from * https://gitlab.freedesktop.org/libinput/libinput/-/issues/515 */ static struct input_id input_id = { .bustype = 0x10, .vendor = 0x104d, .product = 0x00, }; static int events[] = { EV_KEY, KEY_UP, EV_KEY, KEY_DOWN, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_HELP, EV_KEY, KEY_PROG1, EV_KEY, KEY_PROG2, EV_KEY, KEY_BACK, EV_KEY, KEY_EJECTCD, EV_KEY, KEY_F13, EV_KEY, KEY_F14, EV_KEY, KEY_F15, EV_KEY, KEY_F21, EV_KEY, KEY_PROG3, EV_KEY, KEY_PROG4, EV_KEY, KEY_SUSPEND, EV_KEY, KEY_CAMERA, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_MEDIA, EV_KEY, KEY_SWITCHVIDEOMODE, EV_KEY, KEY_BLUETOOTH, EV_KEY, KEY_WLAN, EV_KEY, BTN_THUMB, EV_KEY, KEY_VENDOR, EV_KEY, KEY_FULL_SCREEN, EV_KEY, KEY_ZOOMIN, EV_KEY, KEY_ZOOMOUT, EV_KEY, KEY_FN, EV_KEY, KEY_FN_ESC, EV_KEY, KEY_FN_F8, EV_KEY, KEY_FN_F11, EV_KEY, KEY_FN_1, EV_KEY, KEY_FN_2, EV_KEY, KEY_FN_D, EV_KEY, KEY_FN_E, EV_KEY, KEY_FN_F, EV_KEY, KEY_FN_S, EV_KEY, KEY_FN_B, EV_MSC, MSC_SCAN, -1, -1, }; TEST_DEVICE(LITEST_SONY_VAIO_KEYS, .features = LITEST_KEYS, .interface = NULL, .name = "Sony Vaio Keys", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-device-synaptics-hover.c000066400000000000000000000072451477265155700225040ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x7, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_SEMI_MT, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 1472, 5472, 0, 0, 60 }, { ABS_Y, 1408, 4498, 0, 0, 85 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1472, 5472, 0, 0, 60 }, { ABS_MT_POSITION_Y, 1408, 4498, 0, 0, 85 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_SYNAPTICS_HOVER_SEMI_MT, .features = LITEST_TOUCHPAD | LITEST_SEMI_MT | LITEST_BUTTON, .interface = &interface, .name = "SynPS/2 Synaptics TouchPad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-synaptics-i2c.c000066400000000000000000000065021477265155700220310ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x6cb, .product = 0x76ad, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1216, 0, 0, 12 }, { ABS_Y, 0, 680, 0, 0, 12 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1216, 0, 0, 12 }, { ABS_MT_POSITION_Y, 0, 680, 0, 0, 12 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest Synaptics i2c Touchpad]\n" "MatchName=litest DLL0704:01 06CB:76AD Touchpad\n" "ModelTouchpadVisibleMarker=1\n"; TEST_DEVICE(LITEST_SYNAPTICS_I2C, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "DLL0704:01 06CB:76AD Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-synaptics-phantomclicks.c000066400000000000000000000067201477265155700242150ustar00rootroot00000000000000/* * Copyright © 2023 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x4f3, .product = 0x311c, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_TOOL_QUINTTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 4654, 0, 0, 31 }, { ABS_Y, 0, 2730, 0, 0, 31 }, { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 4654, 0, 0, 31 }, { ABS_MT_POSITION_Y, 0, 2730, 0, 0, 31 }, { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest Dell XPS 15 9500 Touchpad]\n" "MatchName=litest DELL097D:00 04F3:311C Touchpad\n" "ModelTouchpadVisibleMarker=0\n" "ModelTouchpadPhantomClicks=1\n"; TEST_DEVICE(LITEST_SYNAPTICS_PHANTOMCLICKS, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "DELL097D:00 04F3:311C Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-synaptics-pressurepad.c000066400000000000000000000102261477265155700237070ustar00rootroot00000000000000/* * Copyright © 2021 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" /* * Device from https://gitlab.freedesktop.org/libinput/libinput/-/issues/562 * * This device relies on a quirk to disable the pressure axis, resolution is * not set on ABS_PRESSURE. */ static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { /* Always set pressure to zero. The real device sends pressure * values > 30 when the device is clicked but until this is a) * handled by libinput and b) integrated into this test suite * a zero value does the job. */ case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x6cb, .product = 0xce37, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_TOOL_QUINTTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1224, 0, 0, 12 }, { ABS_Y, 0, 756, 0, 0, 12 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, /* note: resolution zero */ { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1224, 0, 0, 12 }, { ABS_MT_POSITION_Y, 0, 756, 0, 0, 12 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, /* note: resolution zero */ { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_SYNAPTICS_PRESSUREPAD, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "SYNA2B31:00 06CB:CE37 Touchpad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-synaptics-rmi4.c000066400000000000000000000104511477265155700222250ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 2 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 2 }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 2 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 2 }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x1d, .vendor = 0x6cb, .product = 0x0, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1940, 0, 0, 20 }, { ABS_Y, 0, 1062, 0, 0, 20 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_SLOT, 0, 4, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 15, 0, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 15, 0, 0, 0 }, { ABS_MT_ORIENTATION, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1940, 0, 0, 20 }, { ABS_MT_POSITION_Y, 0, 1062, 0, 0, 20 }, { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_SYNAPTICS_RMI4, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "Synaptics TM3053-004", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-synaptics-st.c000066400000000000000000000056441477265155700220100ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TOOL_WIDTH, .value = 7 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event up[] = { { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .touch_up_events = up, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 1472, 5472, 0, 0, 75 }, { ABS_Y, 1408, 4448, 0, 0, 129 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x7, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, -1, -1, }; TEST_DEVICE(LITEST_SYNAPTICS_TOUCHPAD, .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SINGLE_TOUCH, .interface = &interface, .name = "SynPS/2 Synaptics TouchPad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-synaptics-t440.c000066400000000000000000000076301477265155700220520ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x7, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, INPUT_PROP_MAX, INPUT_PROP_TOPBUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 1024, 5112, 0, 0, 42 }, { ABS_Y, 2024, 4832, 0, 0, 42 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1024, 5112, 0, 0, 42 }, { ABS_MT_POSITION_Y, 2024, 4832, 0, 0, 42 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_SYNAPTICS_TOPBUTTONPAD, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON | LITEST_TOPBUTTONPAD, .interface = &interface, .name = "SynPS/2 Synaptics TouchPad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-synaptics-x1-carbon-3rd.c000066400000000000000000000101301477265155700236240ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x7, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 1266, 5676, 0, 0, 45 }, { ABS_Y, 1096, 4758, 0, 0, 68 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1266, 5676, 0, 0, 45 }, { ABS_MT_POSITION_Y, 1096, 4758, 0, 0, 68 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest Synaptics X1 Carbon 3rd Touchpad]\n" "MatchName=litest SynPS/2 Synaptics TouchPad X1C3rd\n" "ModelLenovoT450Touchpad=1\n"; TEST_DEVICE(LITEST_SYNAPTICS_TRACKPOINT_BUTTONS, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "SynPS/2 Synaptics TouchPad X1C3rd", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-synaptics-x220.c000066400000000000000000000075361477265155700220570ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x11, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 1472, 5472, 0, 0, 75 }, { ABS_Y, 1408, 4448, 0, 0, 129 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1472, 5472, 0, 0, 75 }, { ABS_MT_POSITION_Y, 1408, 4448, 0, 0, 129 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; TEST_DEVICE(LITEST_SYNAPTICS_CLICKPAD_X220, .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, .interface = &interface, .name = "SynPS/2 Synaptics TouchPad", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-tablet-doubledial.c000066400000000000000000000042461477265155700227210ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x123, .product = 0x678, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_STYLUS, EV_REL, REL_WHEEL, EV_REL, REL_WHEEL_HI_RES, EV_REL, REL_HWHEEL, EV_REL, REL_HWHEEL_HI_RES, -1, -1, }; TEST_DEVICE(LITEST_TABLET_DOUBLEDIAL_PAD, .features = LITEST_TABLET_PAD | LITEST_DIAL, .interface = &interface, .name = "Generic Double Dial Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-tablet-mode-switch.c000066400000000000000000000037611477265155700230410ustar00rootroot00000000000000/* * Copyright © 2020 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x18, .vendor = 0x123, .product = 0x456, }; static int events[] = { /* buttons are needed - the unreliable quirk removes SW_TABLET_MODE * so we'd end up with a device with no seat caps and that won't get * added */ EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_SW, SW_TABLET_MODE, -1, -1, }; static const char quirk_file[] = "[litest unreliable tablet mode switch]\n" "MatchName=litest Unreliable Tablet Mode Switch device\n" "ModelTabletModeSwitchUnreliable=1\n"; TEST_DEVICE(LITEST_TABLET_MODE_UNRELIABLE, .features = LITEST_SWITCH, .interface = NULL, .name = "Unreliable Tablet Mode Switch device", .id = &input_id, .events = events, .absinfo = NULL, .quirk_file = quirk_file, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, } ) libinput-1.28.1/test/litest-device-tablet-rel-dial.c000066400000000000000000000041231477265155700223000ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x123, .product = 0x456, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_STYLUS, EV_REL, REL_DIAL, -1, -1, }; TEST_DEVICE(LITEST_TABLET_REL_DIAL_PAD, .features = LITEST_TABLET_PAD | LITEST_DIAL, .interface = &interface, .name = "Generic Rel DialPad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-thinkpad-extrabuttons.c000066400000000000000000000044311477265155700237020ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x19, .vendor = 0x17aa, .product = 0x5054, }; static int events[] = { EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_SCALE, EV_KEY, KEY_SLEEP, EV_KEY, KEY_FILE, EV_KEY, KEY_PROG1, EV_KEY, KEY_COFFEE, EV_KEY, KEY_BACK, EV_KEY, KEY_CONFIG, EV_KEY, KEY_REFRESH, EV_KEY, KEY_F20, EV_KEY, KEY_F21, EV_KEY, KEY_F24, EV_KEY, KEY_SUSPEND, EV_KEY, KEY_CAMERA, EV_KEY, KEY_SEARCH, EV_KEY, KEY_BRIGHTNESSDOWN, EV_KEY, KEY_BRIGHTNESSUP, EV_KEY, KEY_SWITCHVIDEOMODE, EV_KEY, KEY_KBDILLUMTOGGLE, EV_KEY, KEY_BATTERY, EV_KEY, KEY_WLAN, EV_KEY, KEY_UNKNOWN, EV_KEY, KEY_ZOOM, EV_KEY, KEY_FN_F1, EV_KEY, KEY_FN_F10, EV_KEY, KEY_FN_F11, EV_KEY, KEY_VOICECOMMAND, EV_KEY, KEY_BRIGHTNESS_MIN, EV_SW, SW_RFKILL_ALL, EV_SW, SW_TABLET_MODE, -1, -1, }; TEST_DEVICE(LITEST_THINKPAD_EXTRABUTTONS, .features = LITEST_KEYS | LITEST_SWITCH, .interface = NULL, .name = "ThinkPad Extra Buttons", .id = &input_id, .events = events, .absinfo = NULL, .udev_properties = { { "ID_INPUT_SWITCH", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-touch-screen.c000066400000000000000000000067631477265155700217510ustar00rootroot00000000000000/* * Copyright © 2015 Canonical, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 50000, 0, 0, 100 }, { ABS_Y, 0, 33000, 0, 0, 100 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 50000, 0, 0, 100 }, { ABS_MT_POSITION_Y, 0, 33000, 0, 0, 100 }, { ABS_MT_ORIENTATION, -256, 255, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 255, 1, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 255, 1, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x1, .vendor = 0x0, .product = 0x25, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_GENERIC_MULTITOUCH_SCREEN, .features = LITEST_TOUCH|LITEST_ELLIPSE, .interface = &interface, .name = "generic-mt", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-touchpad-palm-threshold-zero.c000066400000000000000000000101161477265155700250420ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0x7, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD, -1, -1, }; static struct input_absinfo absinfo[] = { { ABS_X, 1266, 5676, 0, 0, 45 }, { ABS_Y, 1096, 4758, 0, 0, 68 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1266, 5676, 0, 0, 45 }, { ABS_MT_POSITION_Y, 1096, 4758, 0, 0, 68 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; static const char quirk_file[] = "[litest TouchpadPalmPressure Zero]\n" "MatchName=litest Touchpad PalmPressureThreshold 0\n" "AttrPalmPressureThreshold=0\n"; TEST_DEVICE(LITEST_TOUCHPAD_PALMPRESSURE_ZERO, .features = LITEST_IGNORED, /* Only use for specific tests */ .interface = &interface, .name = "Touchpad PalmPressureThreshold 0", .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-touchscreen-fuzz.c000066400000000000000000000056171477265155700226650ustar00rootroot00000000000000/* * Copyright © 2015 Canonical, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1500, 10, 0, 0 }, { ABS_Y, 0, 2500, 12, 0, 0 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 1500, 10, 0, 0 }, { ABS_MT_POSITION_Y, 0, 2500, 12, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x1, .vendor = 0x0, .product = 0x25, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_MULTITOUCH_FUZZ_SCREEN, .features = LITEST_TOUCH, .interface = &interface, .name = "touchscreen with fuzz", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-touchscreen-invalid-range.c000066400000000000000000000056361477265155700244100ustar00rootroot00000000000000/* * Copyright © 2015 Canonical, Ltd. * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 1000, 2500, 0, 0, 10 }, { ABS_Y, 2000, 4500, 0, 0, 10 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_POSITION_X, 1000, 2500, 0, 0, 10 }, { ABS_MT_POSITION_Y, 2000, 4500, 0, 0, 10 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x1, .vendor = 0x0, .product = 0x25, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_TOUCHSCREEN_INVALID_RANGE, .features = LITEST_TOUCH, .interface = &interface, .name = "touchscreen-invalid-range", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-touchscreen-mt-tool.c000066400000000000000000000061321477265155700232530ustar00rootroot00000000000000/* * Copyright © 2015 Canonical, Ltd. * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOOL_TYPE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOOL_TYPE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 1000, 2500, 0, 0, 10 }, { ABS_Y, 2000, 4500, 0, 0, 10 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_TOOL_TYPE, 0, 2, 0, 0, 0 }, { ABS_MT_POSITION_X, 1000, 2500, 0, 0, 10 }, { ABS_MT_POSITION_Y, 2000, 4500, 0, 0, 10 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x1, .vendor = 0x0, .product = 0x25, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1 }; TEST_DEVICE(LITEST_TOUCHSCREEN_MT_TOOL_TYPE, .features = LITEST_TOUCH, .interface = &interface, .name = "touchscreen-mt-tool-type", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-trackpoint.c000066400000000000000000000033051477265155700215150ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x11, .vendor = 0x2, .product = 0xa, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_REL, REL_X, EV_REL, REL_Y, INPUT_PROP_MAX, INPUT_PROP_POINTER, INPUT_PROP_MAX, INPUT_PROP_POINTING_STICK, -1, -1, }; TEST_DEVICE(LITEST_TRACKPOINT, .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_POINTINGSTICK, .interface = NULL, .name = "TPPS/2 IBM TrackPoint", .id = &input_id, .absinfo = NULL, .events = events, ) libinput-1.28.1/test/litest-device-uclogic-tablet.c000066400000000000000000000065661477265155700222510ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { /* This tablet doesn't report BTN_TOOL_PEN 0 on proximity out but I *think* * it still reports pressure values of zero? Who knows, we'd have to * get our hands on the tablet again. Meanwhile, let's force the * pressure to zero at least so other tests don't have to guess. */ { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 32767, 0, 0, 235 }, { ABS_Y, 0, 32767, 0, 0, 323 }, { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, /* Note: this VID/PID is shared with multiple devices, see the libwacom database for a list */ .vendor = 0x256c, .product = 0x6e, }; static int events[] = { EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SCAN, -1, -1, }; TEST_DEVICE(LITEST_UCLOGIC_TABLET, .features = LITEST_TABLET | LITEST_HOVER | LITEST_FORCED_PROXOUT, .interface = &interface, .name = "uclogic PenTablet Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-vmware-virtual-usb-mouse.c000066400000000000000000000056641477265155700242530ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" #include static bool touch_down(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_move(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_up(struct litest_device *d, unsigned int slot) { assert(slot == 0); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static struct litest_device_interface interface = { .touch_down = touch_down, .touch_move = touch_move, .touch_up = touch_up, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 32767, 0, 0, 0 }, { ABS_Y, 0, 32767, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x03, .vendor = 0xe0f, .product = 0x03, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, BTN_FORWARD, EV_KEY, BTN_BACK, EV_KEY, BTN_TASK, EV_KEY, 280, EV_KEY, 281, EV_KEY, 282, EV_KEY, 283, EV_KEY, 284, EV_KEY, 285, EV_KEY, 286, EV_KEY, 287, EV_REL, REL_WHEEL, EV_REL, REL_HWHEEL, -1, -1, }; TEST_DEVICE(LITEST_VMWARE_VIRTMOUSE, .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE | LITEST_NO_DEBOUNCE, .interface = &interface, .name = "VMware VMware Virtual USB Mouse", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-bamboo-16fg-pen.c000066400000000000000000000070221477265155700232230ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_DISTANCE: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 14720, 4, 0, 100 }, { ABS_Y, 0, 9200, 4, 0, 100 }, { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { ABS_DISTANCE, 0, 31, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xde, .version = 0x100, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_BAMBOO_16FG_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_HOVER, .interface = &interface, .name = "Wacom Bamboo 16FG 4x5 Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-bamboo-2fg-finger.c000066400000000000000000000063421477265155700236320ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 15360, 0, 0, 128 }, { ABS_Y, 0, 10240, 0, 0, 128 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 15360, 0, 0, 128 }, { ABS_MT_POSITION_Y, 0, 10240, 0, 0, 128 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xd1, .version = 0x110, }; static int events[] = { EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_BAMBOO_2FG_FINGER, .features = LITEST_TOUCHPAD, .interface = &interface, .name = "Wacom Bamboo 2FG 4x5 Finger", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-bamboo-2fg-group" }, { "ID_INPUT_TABLET", "1" }, { "ID_INPUT_TOUCHPAD", "1" }, } ) libinput-1.28.1/test/litest-device-wacom-bamboo-2fg-pad.c000066400000000000000000000041761477265155700231270ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xd1, .version = 0x100, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_FORWARD, EV_KEY, BTN_BACK, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_BAMBOO_2FG_PAD, .features = LITEST_TABLET_PAD, .interface = &interface, .name = "Wacom Bamboo 2FG 4x5 Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { .key = "ID_INPUT_TABLET_PAD", .value = "1" }, { .key = "LIBINPUT_DEVICE_GROUP", .value = "1" }, { NULL } } ) libinput-1.28.1/test/litest-device-wacom-bamboo-2fg-pen.c000066400000000000000000000071571477265155700231470ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_DISTANCE: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 14720, 4, 0, 100 }, { ABS_Y, 0, 9200, 4, 0, 100 }, { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { ABS_DISTANCE, 0, 31, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xd1, .version = 0x100, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_BAMBOO_2FG_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_HOVER, .interface = &interface, .name = "Wacom Bamboo 2FG 4x5 Pen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-bamboo-2fg-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-calibrated-tablet.c000066400000000000000000000101011477265155700237760ustar00rootroot00000000000000/* * Copyright © 2023 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static bool inverter(struct litest_device *dev, double *x, double *y, struct axis_replacement *axes) { /* Input data is in percent (0-100), so let's swap x and y around. * With our matrix this should be undone by libinput later * and the tablet behaves as if normal */ *x = 100 - *x; *y = 100 - *y; /* let the generic code handle the event */ return false; } static bool proximity_in_handler(struct litest_device *dev, unsigned int tool_type, double *x, double *y, struct axis_replacement *axes) { /* let the generic code handle the event */ return inverter(dev, x, y, axes); } static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in = proximity_in_handler, .tablet_tip_down = inverter, .tablet_tip_up = inverter, .tablet_motion = inverter, .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 29476, 4, 0, 100 }, { ABS_Y, 0, 16624, 4, 0, 100 }, { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x501e, .version = 0x111, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CALIBRATED_TABLET_PEN, .features = LITEST_TABLET|LITEST_PRECALIBRATED, .interface = &interface, .name = "Wacom MultiTouch Sensor Pen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_CALIBRATION_MATRIX", "-1 0 1 0 -1 1" }, { NULL } }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-12wx-pen.c000066400000000000000000000114031477265155700233070ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 2083 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; case ABS_DISTANCE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 53020, 4, 0, 200 }, { ABS_Y, 0, 33440, 4, 0, 200 }, { ABS_Z, -900, 899, 0, 0, 0 }, { ABS_RX, 0, 4096, 0, 0, 0 }, { ABS_RY, 0, 4096, 0, 0, 0 }, { ABS_WHEEL, 0, 1023, 0, 0, 0 }, { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, { ABS_DISTANCE, 0, 63, 0, 0, 0 }, { ABS_TILT_X, 0, 127, 0, 0, 0 }, { ABS_TILT_Y, 0, 127, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xc6, .version = 0x113, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_9, EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_12WX_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT | LITEST_DIRECT | LITEST_HOVER, .interface = &interface, .name = "Wacom Cintiq 12WX", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-cintiq-13hdt-finger.c000066400000000000000000000065261477265155700241330ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 2937, 0, 0, 10 }, { ABS_Y, 0, 1652, 0, 0, 10 }, { ABS_MT_SLOT, 0, 9, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 2937, 0, 0, 0 }, { ABS_MT_WIDTH_MAJOR, 0, 2937, 0, 0, 0 }, { ABS_MT_WIDTH_MINOR, 0, 1652, 0, 0, 0 }, { ABS_MT_ORIENTATION, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 2937, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 1652, 0, 0, 10 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x335, .version = 0x110, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_13HDT_FINGER, .features = LITEST_TOUCH, .interface = &interface, .name = "Wacom Cintiq 13 HD touch Finger", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-13hdt-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-13hdt-pad.c000066400000000000000000000060341477265155700234170ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event ring_start[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_change[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_end[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_ring_start_events = ring_start, .pad_ring_change_events = ring_change, .pad_ring_end_events = ring_end, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_WHEEL, 0, 71, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x333, .version = 0x110, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_13HDT_PAD, .features = LITEST_TABLET_PAD | LITEST_RING, .interface = &interface, .name = "Wacom Cintiq 13 HD touch Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { "LIBINPUT_DEVICE_GROUP", "wacom-13hdt-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-13hdt-pen.c000066400000000000000000000112711477265155700234340ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 2083 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; case ABS_DISTANCE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 400, 59152, 4, 0, 200 }, { ABS_Y, 400, 33448, 4, 0, 200 }, { ABS_Z, -900, 899, 0, 0, 287 }, { ABS_WHEEL, 0, 1023, 0, 0, 0 }, { ABS_THROTTLE, 0, 71, 0, 0, 0 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { ABS_DISTANCE, 0, 63, 1, 0, 0 }, { ABS_TILT_X, -64, 63, 1, 0, 57 }, { ABS_TILT_Y, -64, 63, 1, 0, 57 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x333, .version = 0x110, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_13HDT_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT | LITEST_DIRECT | LITEST_HOVER, .interface = &interface, .name = "Wacom Cintiq 13 HD touch Pen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-13hdt-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-24hd-pen.c000066400000000000000000000111261477265155700232510ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 2083 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; case ABS_DISTANCE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 400, 104080, 4, 0, 200 }, { ABS_Y, 400, 65200, 4, 0, 200 }, { ABS_Z, -900, 899, 0, 0, 0 }, { ABS_WHEEL, 0, 1023, 0, 0, 0 }, { ABS_THROTTLE, 0, 71, 0, 0, 0 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { ABS_DISTANCE, 0, 63, 0, 0, 0 }, { ABS_TILT_X, -64, 63, 0, 0, 57 }, { ABS_TILT_Y, -64, 63, 0, 0, 57 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xf4, .version = 0x113, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_24HD_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT | LITEST_DIRECT | LITEST_HOVER, .interface = &interface, .name = "Wacom Cintiq 24 HD Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-cintiq-24hdt-pad.c000066400000000000000000000067241477265155700234270ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "litest.h" #include "litest-int.h" static void litest_wacom_cintiq_pad_teardown(void) { litest_generic_device_teardown(); } static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event ring_start[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_change[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_end[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_ring_start_events = ring_start, .pad_ring_change_events = ring_change, .pad_ring_end_events = ring_end, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_WHEEL, 0, 71, 0, 0, 0 }, { ABS_THROTTLE, 0, 71, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xf8, .version = 0x110, }; static int events[] = { EV_KEY, KEY_PROG1, EV_KEY, KEY_PROG2, EV_KEY, KEY_PROG3, EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_9, EV_KEY, BTN_SOUTH, EV_KEY, BTN_EAST, EV_KEY, BTN_C, EV_KEY, BTN_NORTH, EV_KEY, BTN_WEST, EV_KEY, BTN_Z, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_24HDT_PAD, .features = LITEST_TABLET_PAD | LITEST_RING, .teardown = litest_wacom_cintiq_pad_teardown, .interface = &interface, .name = "Wacom Cintiq 24 HD touch Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { "LIBINPUT_DEVICE_GROUP", "wacom-24hdt-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-pro-16-finger.c000066400000000000000000000064431477265155700242320ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_ORIENTATION, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 13824, 0, 0, 40 }, { ABS_Y, 0, 7776, 0, 0, 40 }, { ABS_MT_SLOT, 0, 15, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 40, 0, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 40, 0, 0, 0 }, { ABS_MT_ORIENTATION, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 13824, 0, 0, 40 }, { ABS_MT_POSITION_Y, 0, 7776, 0, 0, 40 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x354, .version = 0xb, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_PRO16_FINGER, .features = LITEST_TOUCH, .interface = &interface, .name = "Wacom Cintiq Pro 16 Finger", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-pro16-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-pro-16-pad.c000066400000000000000000000042231477265155700235160ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x350, .version = 0xb, }; static int events[] = { EV_KEY, BTN_STYLUS, EV_KEY, KEY_BUTTONCONFIG, EV_KEY, KEY_CONTROLPANEL, EV_KEY, KEY_ONSCREEN_KEYBOARD, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_PRO16_PAD, .features = LITEST_TABLET_PAD, .interface = &interface, .name = "Wacom Cintiq Pro 16 Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { "LIBINPUT_DEVICE_GROUP", "wacom-pro16-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-cintiq-pro-16-pen.c000066400000000000000000000117531477265155700235420ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Z, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 2083 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_Z, .value = 0 }, { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Z, .value = 0 }, { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_Z: case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; case ABS_DISTANCE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 69920, 0, 0, 200 }, { ABS_Y, 0, 39980, 0, 0, 200 }, { ABS_Z, -900, 899, 0, 0, 287 }, { ABS_WHEEL, 0, 2047, 0, 0, 0 }, { ABS_PRESSURE, 0, 8191, 0, 0, 0 }, { ABS_DISTANCE, 0, 63, 1, 0, 0 }, { ABS_TILT_X, -64, 63, 1, 0, 57 }, { ABS_TILT_Y, -64, 63, 1, 0, 57 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x350, .version = 0xb, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_KEY, BTN_STYLUS3, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_CINTIQ_PRO16_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT | LITEST_DIRECT | LITEST_HOVER, .interface = &interface, .name = "Wacom Cintiq Pro 16 Pen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-pro16-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-ekr.c000066400000000000000000000061761477265155700212350ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event ring_start[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_change[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_end[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_ring_start_events = ring_start, .pad_ring_change_events = ring_change, .pad_ring_end_events = ring_end, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_WHEEL, 0, 71, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x331, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_9, EV_KEY, BTN_BASE, EV_KEY, BTN_BASE2, EV_KEY, BTN_SOUTH, EV_KEY, BTN_EAST, EV_KEY, BTN_C, EV_KEY, BTN_NORTH, EV_KEY, BTN_WEST, EV_KEY, BTN_Z, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_EKR, .features = LITEST_TABLET_PAD | LITEST_RING, .interface = &interface, .name = "Wacom Express Key Remote Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-hid4800-pen.c000066400000000000000000000066541477265155700223150ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 21696, 4, 0, 100 }, { ABS_Y, 0, 13560, 4, 0, 100 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x18, .vendor = 0x56a, .product = 0x4800, .version = 0x100, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_HID4800_PEN, .features = LITEST_TABLET | LITEST_HOVER, .interface = &interface, .name = "Wacom HID 4800 Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-intuos3-pad.c000066400000000000000000000055711477265155700226200ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event strip_start[] = { { .type = EV_ABS, .code = ABS_RX, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event strip_change[] = { { .type = EV_ABS, .code = ABS_RX, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event strip_end[] = { { .type = EV_ABS, .code = ABS_RX, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_strip_start_events = strip_start, .pad_strip_change_events = strip_change, .pad_strip_end_events = strip_end, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_RX, 0, 4096, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xb7, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_INTUOS3_PAD, .features = LITEST_TABLET_PAD | LITEST_STRIP, .interface = &interface, .name = "Wacom Intuos3 4x6 Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-intuos5-finger.c000066400000000000000000000077151477265155700233320ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: case ABS_MT_PRESSURE: *value = 30; return 0; case ABS_MT_TOUCH_MAJOR: case ABS_MT_TOUCH_MINOR: *value = 200; return 0; } return 1; } static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 4096, 0, 0, 18 }, { ABS_Y, 0, 4096, 0, 0, 29 }, { ABS_MT_SLOT, 0, 15, 0, 0, 0 }, { ABS_MT_TOUCH_MAJOR, 0, 4096, 0, 0, 0 }, { ABS_MT_TOUCH_MINOR, 0, 4096, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 4096, 0, 0, 18 }, { ABS_MT_POSITION_Y, 0, 4096, 0, 0, 29 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x27, }; static int events[] = { EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOOL_QUINTTAP, EV_KEY, BTN_TOUCH, EV_KEY, BTN_TOOL_DOUBLETAP, EV_KEY, BTN_TOOL_TRIPLETAP, EV_KEY, BTN_TOOL_QUADTAP, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_INTUOS5_FINGER, .features = LITEST_TOUCHPAD, .interface = &interface, .name = "Wacom Intuos5 touch M Finger", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET", "1" }, { "ID_INPUT_TOUCHPAD", "1" }, { "LIBINPUT_DEVICE_GROUP", "wacom-i5-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-intuos5-pad.c000066400000000000000000000057771477265155700226320ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event ring_start[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_change[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_end[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_ring_start_events = ring_start, .pad_ring_change_events = ring_change, .pad_ring_end_events = ring_end, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 1, 0, 0, 0 }, { ABS_Y, 0, 1, 0, 0, 0 }, { ABS_WHEEL, 0, 71, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 10 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x27, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_STYLUS, -1, -1, }; TEST_DEVICE(LITEST_WACOM_INTUOS5_PAD, .features = LITEST_TABLET_PAD | LITEST_RING, .interface = &interface, .name = "Wacom Intuos5 touch M Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET_PAD", "1" }, { "LIBINPUT_DEVICE_GROUP", "wacom-i5-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-intuos5-pen.c000066400000000000000000000117261477265155700226370ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 1050626 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; case ABS_DISTANCE: *value = 0; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 44704, 4, 0, 200 }, { ABS_Y, 0, 27940, 4, 0, 200 }, { ABS_Z, -900, 899, 0, 0, 0 }, { ABS_THROTTLE, -1023, 1023, 0, 0, 0 }, { ABS_WHEEL, 0, 1023, 0, 0, 0 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { ABS_DISTANCE, 0, 63, 0, 0, 0 }, { ABS_TILT_X, 0, 127, 0, 0, 0 }, { ABS_TILT_Y, 0, 127, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x27, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOOL_BRUSH, EV_KEY, BTN_TOOL_PENCIL, EV_KEY, BTN_TOOL_AIRBRUSH, EV_KEY, BTN_TOOL_MOUSE, EV_KEY, BTN_TOOL_LENS, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_REL, REL_WHEEL, EV_MSC, MSC_SERIAL, INPUT_PROP_MAX, INPUT_PROP_POINTER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_INTUOS5_PEN, .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT | LITEST_TOOL_MOUSE | LITEST_HOVER, .interface = &interface, .name = "Wacom Intuos5 touch M Pen", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "LIBINPUT_DEVICE_GROUP", "wacom-i5-group" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-wacom-isdv4-4200-pen.c000066400000000000000000000064671477265155700226530ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 4000; return 0; case ABS_TILT_X: case ABS_TILT_Y: abort(); } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 59674, 0, 0, 100 }, { ABS_Y, 0, 33566, 0, 0, 100 }, /* This pen has tilt, but doesn't send events */ { ABS_TILT_X, -9000, 9000, 0, 0, 5730 }, { ABS_TILT_Y, -9000, 9000, 0, 0, 5730 }, { ABS_PRESSURE, 0, 4096, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x4200, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, EV_KEY, BTN_STYLUS3, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_ISDV4_4200_PEN, .features = LITEST_TABLET|LITEST_HOVER, .interface = &interface, .name = "Wacom ISD-V4 Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-isdv4-524c-pen.c000066400000000000000000000107501477265155700227310ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" struct priv { unsigned int tool; }; static bool create(struct litest_device *d) { d->private = zalloc(sizeof(struct priv)); return true; /* we want litest to create our device */ } static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 4000; return 0; case ABS_TILT_X: case ABS_TILT_Y: abort(); } return 1; } static bool prox_in(struct litest_device *d, unsigned int tool_type, double *x, double *y, struct axis_replacement *axes) { struct priv *priv = d->private; priv->tool = tool_type; return false; } static bool prox_out(struct litest_device *d, unsigned int tool_type) { struct priv *priv = d->private; priv->tool = 0; return false; } static bool tip_down(struct litest_device *d, double *x, double *y, struct axis_replacement *axes) { litest_event(d, EV_KEY, BTN_TOOL_PEN, 1); return false; /* use the default behavior otherwise */ } static bool tip_up(struct litest_device *d, double* x, double *y, struct axis_replacement *axes) { struct priv *priv = d->private; if (priv->tool != BTN_TOOL_PEN) litest_event(d, EV_KEY, BTN_TOOL_PEN, 0); return false; /* use the default behavior otherwise */ } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .tablet_proximity_in = prox_in, .tablet_proximity_out = prox_out, .tablet_tip_down = tip_down, .tablet_tip_up = tip_up, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 30931, 0, 0, 100 }, { ABS_Y, 0, 17399, 0, 0, 100 }, /* This pen has tilt, but doesn't send events */ { ABS_TILT_X, -90, 90, 0, 0, 57 }, { ABS_TILT_Y, -90, 90, 0, 0, 57 }, { ABS_PRESSURE, 0, 4095, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x2d1f, /* Note: this is Wacom's Android VID */ .product = 0x524c, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_ISDV4_524C_PEN, .features = LITEST_TABLET|LITEST_HOVER, .interface = &interface, .name = "Wacom Co.,Ltd. Pen and multitouch sensor Stylus", .id = &input_id, .events = events, .absinfo = absinfo, .create = create, ) libinput-1.28.1/test/litest-device-wacom-isdv4-e6-finger.c000066400000000000000000000060741477265155700232620ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 2776, 0, 0, 10 }, { ABS_Y, 0, 1569, 0, 0, 9 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 2776, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 1569, 0, 0, 9 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xe6, }; static int events[] = { EV_KEY, BTN_TOUCH, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_ISDV4_E6_FINGER, .features = LITEST_TOUCH, .interface = &interface, .name = "Wacom ISDv4 E6 Finger", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-isdv4-e6-pen.c000066400000000000000000000061521477265155700225670ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 27760, 4, 0, 100 }, { ABS_Y, 0, 15694, 4, 0, 100 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0xe6, }; static int events[] = { EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_KEY, BTN_STYLUS2, INPUT_PROP_MAX, INPUT_PROP_DIRECT, -1, -1, }; TEST_DEVICE(LITEST_WACOM_ISDV4_E6_PEN, .features = LITEST_TABLET | LITEST_HOVER, .interface = &interface, .name = "Wacom ISDv4 E6 Pen", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-wacom-mobilestudio-pro-pad.c000066400000000000000000000062601477265155700245050ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event down[] = { { .type = -1, .code = -1 }, }; static struct input_event move[] = { { .type = -1, .code = -1 }, }; static struct input_event ring_start[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MISC, .value = 15 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_change[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct input_event ring_end[] = { { .type = EV_ABS, .code = ABS_WHEEL, .value = 0 }, { .type = EV_ABS, .code = ABS_MISC, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, } ; static struct litest_device_interface interface = { .touch_down_events = down, .touch_move_events = move, .pad_ring_start_events = ring_start, .pad_ring_change_events = ring_change, .pad_ring_end_events = ring_end, }; static struct input_absinfo absinfo[] = { { ABS_X, -2048, 2048, 0, 0, 0 }, { ABS_Y, -2048, 2048, 0, 0, 0 }, { ABS_Z, -2048, 2048, 0, 0, 0 }, { ABS_WHEEL, 0, 35, 0, 0, 0 }, { ABS_MISC, 0, 0, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x56a, .product = 0x34e, .version = 0x110, }; static int events[] = { EV_KEY, BTN_0, EV_KEY, BTN_1, EV_KEY, BTN_2, EV_KEY, BTN_3, EV_KEY, BTN_4, EV_KEY, BTN_5, EV_KEY, BTN_6, EV_KEY, BTN_7, EV_KEY, BTN_8, EV_KEY, BTN_9, EV_KEY, BTN_SOUTH, EV_KEY, BTN_EAST, EV_KEY, BTN_C, EV_KEY, BTN_STYLUS, INPUT_PROP_MAX, INPUT_PROP_ACCELEROMETER, -1, -1, }; TEST_DEVICE(LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD, .features = LITEST_TABLET_PAD | LITEST_RING, .interface = &interface, .name = "Wacom MobileStudio Pro 16 Pad", .id = &input_id, .events = events, .absinfo = absinfo, .udev_properties = { { "ID_INPUT_TABLET", "1" }, { "ID_INPUT_TABLET_PAD", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-waltop-tablet.c000066400000000000000000000140411477265155700221150ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_event proximity_in[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event proximity_out[] = { { .type = EV_ABS, .code = ABS_X, .value = 0 }, { .type = EV_ABS, .code = ABS_Y, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 }, { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static struct input_event motion[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; static int get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) { switch (evcode) { case ABS_TILT_X: case ABS_TILT_Y: *value = 0; return 0; case ABS_PRESSURE: *value = 100; return 0; } return 1; } static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 32000, 0, 0, 0 }, { ABS_Y, 0, 32000, 0, 0, 0 }, { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, { ABS_TILT_X, -127, 127, 0, 0, 0 }, { ABS_TILT_Y, -127, 127, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x3, .vendor = 0x172f, .product = 0x509, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_MUTE, EV_KEY, KEY_VOLUMEDOWN, EV_KEY, KEY_VOLUMEUP, EV_KEY, KEY_PAUSE, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_KEY, BTN_0, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, BTN_TOOL_PEN, EV_KEY, BTN_TOOL_RUBBER, EV_KEY, BTN_TOUCH, EV_KEY, BTN_STYLUS, EV_REL, REL_HWHEEL, EV_REL, REL_WHEEL, EV_MSC, MSC_SERIAL, -1, -1, }; static const char quirk_file[] = "[litest Waltop Tablet]\n" "MatchName=litest WALTOP Batteryless Tablet*\n" "AttrSizeHint=200x200\n"; TEST_DEVICE(LITEST_WALTOP, .features = LITEST_TABLET | LITEST_WHEEL | LITEST_TILT | LITEST_HOVER, .interface = &interface, .name = " WALTOP Batteryless Tablet ", /* sic */ .id = &input_id, .events = events, .absinfo = absinfo, .quirk_file = quirk_file, ) libinput-1.28.1/test/litest-device-wheel-only.c000066400000000000000000000030761477265155700214270ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1, .product = 0x2, }; static int events[] = { EV_REL, REL_WHEEL, -1 , -1, }; TEST_DEVICE(LITEST_WHEEL_ONLY, .features = LITEST_WHEEL, .interface = NULL, .name = "wheel only device", .id = &input_id, .absinfo = NULL, .events = events, .udev_properties = { { "ID_INPUT_KEY", "1" }, { NULL }, }, ) libinput-1.28.1/test/litest-device-xen-virtual-pointer.c000066400000000000000000000054201477265155700232730ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" #include static bool touch_down(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_move(struct litest_device *d, unsigned int slot, double x, double y) { assert(slot == 0); litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x)); litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y)); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static bool touch_up(struct litest_device *d, unsigned int slot) { assert(slot == 0); litest_event(d, EV_SYN, SYN_REPORT, 0); return true; /* we handled the event */ } static struct litest_device_interface interface = { .touch_down = touch_down, .touch_move = touch_move, .touch_up = touch_up, }; static struct input_absinfo absinfo[] = { { ABS_X, 0, 800, 0, 0, 0 }, { ABS_Y, 0, 800, 0, 0, 0 }, { .value = -1 }, }; static struct input_id input_id = { .bustype = 0x01, .vendor = 0x5853, .product = 0xfffe, }; static int events[] = { EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_SIDE, EV_KEY, BTN_EXTRA, EV_KEY, BTN_FORWARD, EV_KEY, BTN_BACK, EV_KEY, BTN_TASK, EV_REL, REL_WHEEL, -1, -1, }; TEST_DEVICE(LITEST_XEN_VIRTUAL_POINTER, .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE, .interface = &interface, .name = "Xen Virtual Pointer", .id = &input_id, .events = events, .absinfo = absinfo, ) libinput-1.28.1/test/litest-device-yubikey.c000066400000000000000000000070131477265155700210200ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest.h" #include "litest-int.h" static struct input_id input_id = { .bustype = 0x3, .vendor = 0x1050, .product = 0x10, }; static int events[] = { EV_KEY, KEY_ESC, EV_KEY, KEY_1, EV_KEY, KEY_2, EV_KEY, KEY_3, EV_KEY, KEY_4, EV_KEY, KEY_5, EV_KEY, KEY_6, EV_KEY, KEY_7, EV_KEY, KEY_8, EV_KEY, KEY_9, EV_KEY, KEY_0, EV_KEY, KEY_MINUS, EV_KEY, KEY_EQUAL, EV_KEY, KEY_BACKSPACE, EV_KEY, KEY_TAB, EV_KEY, KEY_Q, EV_KEY, KEY_W, EV_KEY, KEY_E, EV_KEY, KEY_R, EV_KEY, KEY_T, EV_KEY, KEY_Y, EV_KEY, KEY_U, EV_KEY, KEY_I, EV_KEY, KEY_O, EV_KEY, KEY_P, EV_KEY, KEY_LEFTBRACE, EV_KEY, KEY_RIGHTBRACE, EV_KEY, KEY_ENTER, EV_KEY, KEY_LEFTCTRL, EV_KEY, KEY_A, EV_KEY, KEY_S, EV_KEY, KEY_D, EV_KEY, KEY_F, EV_KEY, KEY_G, EV_KEY, KEY_H, EV_KEY, KEY_J, EV_KEY, KEY_K, EV_KEY, KEY_L, EV_KEY, KEY_SEMICOLON, EV_KEY, KEY_APOSTROPHE, EV_KEY, KEY_GRAVE, EV_KEY, KEY_LEFTSHIFT, EV_KEY, KEY_BACKSLASH, EV_KEY, KEY_Z, EV_KEY, KEY_X, EV_KEY, KEY_C, EV_KEY, KEY_V, EV_KEY, KEY_B, EV_KEY, KEY_N, EV_KEY, KEY_M, EV_KEY, KEY_COMMA, EV_KEY, KEY_DOT, EV_KEY, KEY_SLASH, EV_KEY, KEY_RIGHTSHIFT, EV_KEY, KEY_KPASTERISK, EV_KEY, KEY_LEFTALT, EV_KEY, KEY_SPACE, EV_KEY, KEY_CAPSLOCK, EV_KEY, KEY_F1, EV_KEY, KEY_F2, EV_KEY, KEY_F3, EV_KEY, KEY_F4, EV_KEY, KEY_F5, EV_KEY, KEY_F6, EV_KEY, KEY_F7, EV_KEY, KEY_F8, EV_KEY, KEY_F9, EV_KEY, KEY_F10, EV_KEY, KEY_NUMLOCK, EV_KEY, KEY_SCROLLLOCK, EV_KEY, KEY_KP7, EV_KEY, KEY_KP8, EV_KEY, KEY_KP9, EV_KEY, KEY_KPMINUS, EV_KEY, KEY_KP4, EV_KEY, KEY_KP5, EV_KEY, KEY_KP6, EV_KEY, KEY_KPPLUS, EV_KEY, KEY_KP1, EV_KEY, KEY_KP2, EV_KEY, KEY_KP3, EV_KEY, KEY_KP0, EV_KEY, KEY_KPDOT, EV_KEY, KEY_102ND, EV_KEY, KEY_F11, EV_KEY, KEY_F12, EV_KEY, KEY_KPENTER, EV_KEY, KEY_RIGHTCTRL, EV_KEY, KEY_KPSLASH, EV_KEY, KEY_SYSRQ, EV_KEY, KEY_RIGHTALT, EV_KEY, KEY_HOME, EV_KEY, KEY_UP, EV_KEY, KEY_PAGEUP, EV_KEY, KEY_LEFT, EV_KEY, KEY_RIGHT, EV_KEY, KEY_END, EV_KEY, KEY_DOWN, EV_KEY, KEY_PAGEDOWN, EV_KEY, KEY_INSERT, EV_KEY, KEY_DELETE, EV_KEY, KEY_PAUSE, EV_KEY, KEY_LEFTMETA, EV_KEY, KEY_RIGHTMETA, EV_KEY, KEY_COMPOSE, EV_LED, LED_NUML, EV_LED, LED_CAPSL, EV_LED, LED_SCROLLL, EV_LED, LED_COMPOSE, EV_LED, LED_KANA, -1, -1, }; TEST_DEVICE(LITEST_YUBIKEY, .features = LITEST_KEYS, .interface = NULL, .name = "Yubico Yubico Yubikey II", .id = &input_id, .events = events, .absinfo = NULL, ) libinput-1.28.1/test/litest-int.h000066400000000000000000000131161477265155700167020ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #ifndef LITEST_INT_H #define LITEST_INT_H #include "litest.h" /* Use as designater for litest to change the value */ #define LITEST_AUTO_ASSIGN INT_MIN /* Special event code to auto-assign the BTN_TOOL_PEN and friends */ #define LITEST_BTN_TOOL_AUTO (KEY_MAX << 1) struct litest_test_device { struct list node; /* global test device list */ enum litest_device_type type; int64_t features; const char *shortname; void (*setup)(void); /* test fixture, used by check */ void (*teardown)(void); /* test fixture, used by check */ /** * If create is non-NULL it will be called to initialize the device. * For such devices, no overrides are possible. If create is NULL, * the information in name, id, events, absinfo is used to * create the device instead. * * @return true if the device needs to be created by litest, false if * the device creates itself */ bool (*create)(struct litest_device *d); /** * The device name. Only used when create is NULL. */ const char *name; /** * The device id. Only used when create is NULL. */ const struct input_id *id; /** * List of event type/code tuples, terminated with -1, e.g. * EV_REL, REL_X, EV_KEY, BTN_LEFT, -1 * Special tuple is INPUT_PROP_MAX, to set. * * Any EV_ABS codes in this list will be initialized with a default * axis range. */ int *events; /** * List of abs codes to enable, with absinfo.value determining the * code to set. List must be terminated with absinfo.value -1 */ struct input_absinfo *absinfo; struct litest_device_interface *interface; const char *udev_rule; const char *quirk_file; const struct key_value_str udev_properties[32]; }; struct litest_device_interface { bool (*touch_down)(struct litest_device *d, unsigned int slot, double x, double y); bool (*touch_move)(struct litest_device *d, unsigned int slot, double x, double y); bool (*touch_up)(struct litest_device *d, unsigned int slot); /** * Default value for the given EV_ABS axis. * @return 0 on success, nonzero otherwise */ int (*get_axis_default)(struct litest_device *d, unsigned int code, int32_t *value); /** * Set of of events to execute on touch down, terminated by a .type * and .code value of -1. If the event value is LITEST_AUTO_ASSIGN, * it will be automatically assigned by the framework (valid for x, * y, tracking id and slot). * * These events are only used if touch_down is NULL. */ struct input_event *touch_down_events; struct input_event *touch_move_events; struct input_event *touch_up_events; /** * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE. */ struct input_event *tablet_proximity_in_events; struct input_event *tablet_proximity_out_events; struct input_event *tablet_motion_events; bool (*tablet_proximity_in)(struct litest_device *d, unsigned int tool_type, double *x, double *y, struct axis_replacement *axes); bool (*tablet_proximity_out)(struct litest_device *d, unsigned int tool_type); bool (*tablet_tip_down)(struct litest_device *d, double *x, double *y, struct axis_replacement *axes); bool (*tablet_tip_up)(struct litest_device *d, double *x, double *y, struct axis_replacement *axes); bool (*tablet_motion)(struct litest_device *d, double *x, double *y, struct axis_replacement *axes); /** * Pad events, LITEST_AUTO_ASSIGN is allowed on event values * for ABS_WHEEL */ struct input_event *pad_ring_start_events; struct input_event *pad_ring_change_events; struct input_event *pad_ring_end_events; /** * Pad events, LITEST_AUTO_ASSIGN is allowed on event values * for ABS_WHEEL */ struct input_event *pad_dial_start_events; struct input_event *pad_dial_change_events; struct input_event *pad_dial_end_events; /** * Pad events, LITEST_AUTO_ASSIGN is allowed on event values * for ABS_RX */ struct input_event *pad_strip_start_events; struct input_event *pad_strip_change_events; struct input_event *pad_strip_end_events; int min[2]; /* x/y axis minimum */ int max[2]; /* x/y axis maximum */ unsigned int tool_type; }; struct path { struct list link; char *path; int fd; }; struct litest_context { struct litest_user_data *user_data; struct list paths; }; void litest_set_current_device(struct litest_device *device); int litest_scale(const struct litest_device *d, unsigned int axis, double val); void litest_generic_device_teardown(void); #endif libinput-1.28.1/test/litest-runner.c000066400000000000000000000626521477265155700174250ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #ifdef HAVE_PIDFD_OPEN #include #endif #include #include #include #include #include #include "litest-runner.h" #include "util-files.h" #include "util-list.h" #include "util-multivalue.h" #include "util-stringbuf.h" static bool use_jmpbuf; /* only used for max_forks = 0 */ static jmp_buf jmpbuf; /* musl doesn't have this one but it's not that important */ #ifndef HAVE_SIGABBREV_NP #define sigabbrev_np(...) "???" #endif static struct litest_runner *global_runner = NULL; enum litest_runner_logfds { FD_STDOUT, FD_STDERR, FD_LOG, FD_VALGRIND, _FD_LAST, }; struct litest_runner_test { struct litest_runner_test_description desc; struct list node; enum litest_runner_result result; int sig_or_errno; struct stringbuf logs[_FD_LAST]; pid_t pid; /* the test's PID, if any */ int read_fds[_FD_LAST]; /* logging fds while the test is running */ int epollfd; int pidfd; int timerfd; struct { uint64_t start_millis; uint64_t end_millis; } times; }; struct litest_runner { size_t max_forks; unsigned int timeout; bool verbose; bool use_colors; bool exit_on_fail; FILE *fp; int terminating; struct list tests; /* struct litest_runner_test */ struct list tests_running; /* struct litest_runner_test */ struct list tests_complete; /* struct litest_runner_test */ struct { time_t start; time_t end; uint64_t start_millis; } times; struct { litest_runner_global_setup_func_t setup; litest_runner_global_teardown_func_t teardown; void *userdata; } global; }; /** * A global variable that the tests can use * to write log data to. Defaults to stdout * but if used by the tests it shows up as separate * from stdout in the logs. */ int testlog_fd = STDOUT_FILENO; static void close_pipes(int fds[_FD_LAST]) { for (int i = 0; i < _FD_LAST; i++) { fsync(fds[i]); xclose(&fds[i]); } } static int init_pipes(int read_fds[_FD_LAST], int write_fds[_FD_LAST]) { int r; int i; int pipe_max_size = 4194304; for (i = 0; i < _FD_LAST; i++) { read_fds[i] = -1; write_fds[i] = -1; } #ifdef __linux__ { FILE *f; f = fopen("/proc/sys/fs/pipe-max-size", "re"); if (f) { if (fscanf(f, "%d", &r) == 1) pipe_max_size = min(r, pipe_max_size); fclose(f); } } #endif for (i = 0; i < _FD_LAST; i++) { int pipe[2]; r = pipe2(pipe, O_CLOEXEC | O_NONBLOCK); if (r < 0) goto error; read_fds[i] = pipe[0]; write_fds[i] = pipe[1]; #ifdef __linux__ /* Max pipe buffers, to avoid scrambling if reading lags. * Can't use blocking write fds, since reading too slow * then affects execution. */ fcntl(write_fds[i], F_SETPIPE_SZ, pipe_max_size); #endif } return 0; error: r = -errno; close_pipes(read_fds); close_pipes(write_fds); return r; } static const char * litest_runner_result_as_str(enum litest_runner_result result) { switch (result) { CASE_RETURN_STRING(LITEST_PASS); CASE_RETURN_STRING(LITEST_NOT_APPLICABLE); CASE_RETURN_STRING(LITEST_FAIL); CASE_RETURN_STRING(LITEST_SYSTEM_ERROR); CASE_RETURN_STRING(LITEST_TIMEOUT); CASE_RETURN_STRING(LITEST_SKIP); } litest_abort_msg("Unknown result %d", result); return NULL; } static void litest_runner_test_close(struct litest_runner_test *t) { for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { xclose(&t->read_fds[i]); } xclose(&t->epollfd); xclose(&t->pidfd); xclose(&t->timerfd); } static void litest_runner_test_destroy(struct litest_runner_test *t) { list_remove(&t->node); close_pipes(t->read_fds); if (t->pid != 0) { kill(t->pid, SIGTERM); t->pid = 0; } litest_runner_test_close(t); for (int i = 0; i < _FD_LAST; i++) { stringbuf_reset(&t->logs[i]); } free(t); } static void litest_runner_detach_tests(struct litest_runner *runner) { struct litest_runner_test *t; list_for_each_safe(t, &runner->tests, node) { t->pid = 0; } list_for_each_safe(t, &runner->tests_complete, node) { t->pid = 0; } list_for_each_safe(t, &runner->tests_running, node) { t->pid = 0; } } void litest_runner_destroy(struct litest_runner *runner) { struct litest_runner_test *t; list_for_each_safe(t, &runner->tests, node) { litest_runner_test_destroy(t); } list_for_each_safe(t, &runner->tests_complete, node) { litest_runner_test_destroy(t); } list_for_each_safe(t, &runner->tests_running, node) { litest_runner_test_destroy(t); } free(runner); } static enum litest_runner_result litest_runner_test_run(const struct litest_runner_test_description *desc) { const struct litest_runner_test_env env = { .rangeval = desc->rangeval, .params = desc->params, }; if (desc->setup) desc->setup(desc); enum litest_runner_result result = desc->func(&env); if (desc->teardown) desc->teardown(desc); return result; } static void sighandler_forked_child(int signal) { struct sigaction act; sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = SIG_DFL; sigaction(signal, &act, NULL); /* abort() was probably called by litest_assert... which inserts * the backtrace anyway - we only need to backtrace the other signals */ if (signal != SIGABRT) litest_backtrace(NULL); raise(signal); } static int litest_runner_fork_test(struct litest_runner *runner, struct litest_runner_test *t) { pid_t pid; struct sigaction act; int write_fds[_FD_LAST]; int r; r = init_pipes(t->read_fds, write_fds); if (r < 0) { return -1; } pid = fork(); if (pid < 0) { int r = -errno; close_pipes(t->read_fds); close_pipes(write_fds); return r; } if (pid > 0) { /* parent */ close_pipes(write_fds); t->pid = pid; return pid; } /* child */ close_pipes(t->read_fds); /* Catch any crashers so we can insert a backtrace */ sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = sighandler_forked_child; sigaction(SIGSEGV, &act, NULL); sigaction(SIGBUS, &act, NULL); sigaction(SIGSEGV, &act, NULL); sigaction(SIGABRT, &act, NULL); /* SIGALARM is used for our timeout */ sigaction(SIGALRM, &act, NULL); r = dup2(write_fds[FD_STDERR], STDERR_FILENO); litest_assert_errno_success(r); setlinebuf(stderr); r = dup2(write_fds[FD_STDOUT], STDOUT_FILENO); litest_assert_errno_success(r); setlinebuf(stdout); /* For convenience in the tests, let this be a global variable. */ testlog_fd = write_fds[FD_LOG]; /* We're forked so we have a full copy of everything - but all we want * to do is avoid valgrind complaining about memleaks in the child * process. So let's cleanup everything, copy the one thing we * care about and proceed to the exit */ struct litest_runner_test_description desc = t->desc; litest_runner_detach_tests(runner); litest_runner_destroy(runner); /* Now run the actual test */ enum litest_runner_result result = litest_runner_test_run(&desc); close_pipes(write_fds); exit(result); } static char * valgrind_logfile(pid_t pid) { const char *prefix = getenv("LITEST_VALGRIND_LOGDIR"); if (!prefix) prefix = "."; char *filename = NULL; int rc = xasprintf(&filename, "%s/valgrind.%d.log", prefix, pid); litest_assert_neg_errno_success(rc); return filename; } static void collect_file(const char *filename, struct stringbuf *b) { int fd = open(filename, O_RDONLY); if (fd == -1) { char *msg; xasprintf(&msg, "Failed to find '%s': %m", filename); stringbuf_append_string(b, msg); free(msg); } else { stringbuf_append_from_fd(b, fd, 0); close(fd); } } static bool litest_runner_test_collect_child(struct litest_runner_test *t) { int r; int status; r = waitpid(t->pid, &status, WNOHANG); if (r <= 0) return false; if (WIFEXITED(status)) { t->result = WEXITSTATUS(status); if (RUNNING_ON_VALGRIND && t->result == 3) { char msg[64]; snprintf(msg, sizeof(msg), "valgrind exited with an error code, see logs\n"); stringbuf_append_string(&t->logs[FD_LOG], msg); t->result = LITEST_SYSTEM_ERROR; } switch (t->result) { case LITEST_PASS: case LITEST_SKIP: case LITEST_NOT_APPLICABLE: case LITEST_FAIL: case LITEST_TIMEOUT: case LITEST_SYSTEM_ERROR: break; /* if a test execve's itself allow for the normal * exit codes to map to the results */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch" case 0: t->result = LITEST_PASS; break; #pragma GCC diagnostic pop default: { char msg[64]; snprintf(msg, sizeof(msg), "Invalid test exit status %d", t->result); stringbuf_append_string(&t->logs[FD_LOG], msg); t->result = LITEST_FAIL; break; } } } else { if (WIFSIGNALED(status)) { t->sig_or_errno = WTERMSIG(status); t->result = (t->sig_or_errno == t->desc.args.signal) ? LITEST_PASS : LITEST_FAIL; } else { t->result = LITEST_FAIL; } } uint64_t now = 0; now_in_us(&now); t->times.end_millis = us2ms(now); if (RUNNING_ON_VALGRIND) { char *filename = valgrind_logfile(t->pid); collect_file(filename, &t->logs[FD_VALGRIND]); free(filename); } t->pid = 0; return true; } static int litest_runner_test_setup_monitoring(struct litest_runner *runner, struct litest_runner_test *t) { int pidfd = -1, timerfd = -1, epollfd = -1; struct epoll_event ev[10]; size_t nevents = 0; int r = 0; #ifdef HAVE_PIDFD_OPEN pidfd = syscall(SYS_pidfd_open, t->pid, 0); #else errno = ENOSYS; #endif /* If we don't have pidfd, we use a timerfd to ping us every 200ms */ if (pidfd < 0 && errno == ENOSYS) { pidfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); if (pidfd == -1) { r = -errno; goto error; } r = timerfd_settime(pidfd, 0, &((struct itimerspec ){ .it_interval.tv_nsec = 200 * 1000 * 1000, .it_value.tv_nsec = 200 * 1000 * 1000, }), NULL); if (r < 0) { r = -errno; goto error; } } /* Each test has an epollfd with: * - a timerfd so we can kill() it if it hangs * - a pidfd so we get notified when the test exits * - a pipe for stdout and a pipe for stderr * - a pipe for logging (the various pwtest functions) * - a pipe for the daemon's stdout */ timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); if (timerfd < 0) { r = -errno; goto error; } timerfd_settime(timerfd, 0, &((struct itimerspec ){ .it_value.tv_sec = runner->timeout}), NULL); epollfd = epoll_create(1); if (epollfd < 0) goto error; ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = pidfd }; ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = t->read_fds[FD_STDOUT] }; ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = t->read_fds[FD_STDERR] }; ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = t->read_fds[FD_LOG] }; ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = timerfd }; for (size_t i = 0; i < nevents; i++) { r = epoll_ctl(epollfd, EPOLL_CTL_ADD, ev[i].data.fd, &ev[i]); if (r < 0) { r = -errno; goto error; } } t->epollfd = epollfd; t->pidfd = pidfd; t->timerfd = timerfd; r = 0; error: if (r) { xclose(&pidfd); xclose(&timerfd); xclose(&epollfd); } return -r; } static int litest_runner_test_check_status(struct litest_runner_test *t) { struct epoll_event e; if (t->pid == 0) /* nofork case */ return 0; while (true) { /* FIXME: this is a busy wait ... */ int r = epoll_wait(t->epollfd, &e, 1, 50); if (r == 0) return -EAGAIN; if (r == -1) { goto error; } if (e.data.fd == t->pidfd) { uint64_t buf; int ignore = read(t->pidfd, &buf, sizeof(buf)); /* for timerfd fallback */ (void)ignore; if (litest_runner_test_collect_child(t)) { break; } } else if (e.data.fd == t->timerfd) { /* SIGALARM so we get the backtrace */ kill(t->pid, SIGALRM); t->result = LITEST_TIMEOUT; waitpid(t->pid, NULL, 0); t->pid = 0; break; } else { for (int i = 0; i < _FD_LAST; i++) { if (e.data.fd == t->read_fds[i]) { stringbuf_append_from_fd(&t->logs[i], e.data.fd, 1024); } } } }; errno = 0; error: return -errno; } static void litest_runner_test_update_errno(struct litest_runner_test *t, int error) { if (error) t->sig_or_errno = -error; if (error == SIGTERM) { char msg[64]; snprintf(msg, sizeof(msg), "litest: tests terminated by signal\n"); stringbuf_append_string(&t->logs[FD_LOG], msg); t->result = LITEST_SYSTEM_ERROR; } for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { stringbuf_append_from_fd(&t->logs[i], t->read_fds[i], 1024); } } __attribute__((noreturn)) void litest_runner_abort(void) { if (use_jmpbuf) { longjmp(jmpbuf, SIGABRT); } else { abort(); } } static int litest_runner_run_test(struct litest_runner *runner, struct litest_runner_test *t) { int r; t->result = LITEST_SYSTEM_ERROR; uint64_t now = 0; now_in_us(&now); t->times.start_millis = us2ms(now); if (runner->max_forks == 0) { if (use_jmpbuf && setjmp(jmpbuf) == 0) { t->result = litest_runner_test_run(&t->desc); } else { t->result = LITEST_FAIL; } r = 0; /* -Wclobbered */ } else { r = litest_runner_fork_test(runner, t); if (r >= 0) r = litest_runner_test_setup_monitoring(runner, t); litest_runner_test_update_errno(t, -r); } if (r >= 0) { list_remove(&t->node); list_append(&runner->tests_running, &t->node); } return r; } static void print_lines(FILE *fp, const char *log, const char *prefix) { size_t nlines = 0; char **lines = strv_from_string (log, "\n", &nlines); for (size_t i = 0; i < nlines; i++) { fprintf(fp, "%s%s\n", prefix, lines[i]); } strv_free(lines); } void _litest_test_param_fetch(const struct litest_test_parameters *params, ...) { struct litest_test_param *p; const char *name; va_list args; va_start(args, params); while ((name = va_arg(args, const char *))) { bool found = false; char type = (char)va_arg(args, int); void **ptr = va_arg(args, void *); list_for_each(p, ¶ms->test_params, link) { if (streq(p->name, name)) { if (tolower(p->value.type) != tolower(type)) litest_abort_msg("Paramter type mismatch: parameter '%s' is of type %c", p->name, p->value.type); found = true; multivalue_extract(&p->value, ptr); break; } } if (!found) litest_abort_msg("Unknown test parameter name '%s'", name); } va_end(args); } struct litest_test_parameters * litest_test_parameters_new(void) { struct litest_test_parameters *params = zalloc(sizeof *params); params->refcnt = 1; list_init(¶ms->test_params); return params; } struct litest_test_parameters * litest_test_parameters_unref(struct litest_test_parameters *params) { if (params) { assert(params->refcnt > 0); if (--params->refcnt == 0) { struct litest_test_param *p; list_for_each_safe(p, ¶ms->test_params, link) { free(p); } free(params); } } return NULL; } static void litest_runner_log_test_result(struct litest_runner *runner, struct litest_runner_test *t) { const char *color = NULL; const char *status = NULL; litest_assert_int_ge(t->result, (enum litest_runner_result)LITEST_PASS); litest_assert_int_le(t->result, (enum litest_runner_result)LITEST_SYSTEM_ERROR); switch (t->result) { case LITEST_PASS: color = ANSI_BRIGHT_GREEN; break; case LITEST_FAIL: color = ANSI_BRIGHT_RED; break; case LITEST_SKIP: color = ANSI_BRIGHT_YELLOW; break; case LITEST_NOT_APPLICABLE: color = ANSI_BLUE; break; case LITEST_TIMEOUT: color = ANSI_BRIGHT_CYAN; break; case LITEST_SYSTEM_ERROR: color = ANSI_BRIGHT_MAGENTA; break; } fprintf(runner->fp, " - name: \"%s\"\n", t->desc.name); int min = t->desc.args.range.lower, max = t->desc.args.range.upper; if (range_is_valid(&t->desc.args.range)) fprintf(runner->fp, " rangeval: %d # %d..%d\n", t->desc.rangeval, min, max); if (t->desc.params) { fprintf(runner->fp, " params:\n"); struct litest_test_param *p; list_for_each(p, &t->desc.params->test_params, link) { char *val = multivalue_as_str(&p->value); fprintf(runner->fp, " %s: %s\n", p->name, val); free(val); } } fprintf(runner->fp, " duration: %ld # (ms), total test run time: %02d:%02d\n", t->times.end_millis - t->times.start_millis, (ms2s(t->times.end_millis - runner->times.start_millis)) / 60, (ms2s(t->times.end_millis - runner->times.start_millis)) % 60); status = litest_runner_result_as_str(t->result); fprintf(runner->fp, " status: %s%s%s\n", runner->use_colors ? color : "", &status[7], /* skip LITEST_ prefix */ runner->use_colors ? ANSI_NORMAL : ""); switch (t->result) { case LITEST_PASS: case LITEST_SKIP: case LITEST_NOT_APPLICABLE: if (!runner->verbose) return; break; default: break; } if (t->sig_or_errno > 0) fprintf(runner->fp, " signal: %d # SIG%s \n", t->sig_or_errno, sigabbrev_np(t->sig_or_errno)); else if (t->sig_or_errno < 0) fprintf(runner->fp, " errno: %d # %s\n", -t->sig_or_errno, strerror(-t->sig_or_errno)); if (!stringbuf_is_empty(&t->logs[FD_LOG])) { fprintf(runner->fp, " log: |\n"); print_lines(runner->fp, t->logs[FD_LOG].data, " "); } if (!stringbuf_is_empty(&t->logs[FD_STDOUT])) { fprintf(runner->fp, " stdout: |\n"); print_lines(runner->fp, t->logs[FD_STDOUT].data, " "); } if (!stringbuf_is_empty(&t->logs[FD_STDERR])) { fprintf(runner->fp, " stderr: |\n"); print_lines(runner->fp, t->logs[FD_STDERR].data, " "); } if (!stringbuf_is_empty(&t->logs[FD_VALGRIND])) { fprintf(runner->fp, " valgrind: |\n"); print_lines(runner->fp, t->logs[FD_VALGRIND].data, " "); } } struct litest_runner * litest_runner_new(void) { struct litest_runner *runner = zalloc(sizeof *runner); list_init(&runner->tests); list_init(&runner->tests_complete); list_init(&runner->tests_running); runner->timeout = LITEST_RUNNER_DEFAULT_TIMEOUT; runner->max_forks = get_nprocs() * 2; runner->fp = stderr; return runner; } void litest_runner_set_timeout(struct litest_runner *runner, unsigned int timeout) { runner->timeout = timeout; } void litest_runner_set_output_file(struct litest_runner *runner, FILE *fp) { setlinebuf(fp); runner->fp = fp; } void litest_runner_set_num_parallel(struct litest_runner *runner, size_t num_jobs) { runner->max_forks = num_jobs; } void litest_runner_set_verbose(struct litest_runner *runner, bool verbose) { runner->verbose = verbose; } void litest_runner_set_use_colors(struct litest_runner *runner, bool use_colors) { runner->use_colors = use_colors; } void litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit) { runner->exit_on_fail = do_exit; } void litest_runner_set_setup_funcs(struct litest_runner *runner, litest_runner_global_setup_func_t setup, litest_runner_global_teardown_func_t teardown, void *userdata) { runner->global.setup = setup; runner->global.teardown = teardown; runner->global.userdata = userdata; } void litest_runner_add_test(struct litest_runner *runner, const struct litest_runner_test_description *desc) { struct litest_runner_test *t = zalloc(sizeof(*t)); t->desc = *desc; t->epollfd = -1; t->pidfd = -1; t->timerfd = -1; for (int i = 0; i < _FD_LAST; i++) { stringbuf_init(&t->logs[i]); } for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { t->read_fds[i] = -1; } list_append(&runner->tests, &t->node); } static int litest_runner_check_finished_tests(struct litest_runner *runner) { struct litest_runner_test *running; size_t count = 0; list_for_each_safe(running, &runner->tests_running, node) { int r = litest_runner_test_check_status(running); if (r == -EAGAIN) continue; uint64_t now = 0; now_in_us(&now); running->times.end_millis = us2ms(now); if (r < 0) litest_runner_test_update_errno(running, -r); litest_runner_log_test_result(runner, running); litest_runner_test_close(running); list_remove(&running->node); list_append(&runner->tests_complete, &running->node); count++; } return count; } static void runner_sighandler(int sig) { struct litest_runner_test *t; struct litest_runner *runner = global_runner; list_for_each(t, &runner->tests_running, node) { if (t->pid != 0) { kill(t->pid, SIGTERM); t->pid = 0; } } global_runner->terminating = true; } static inline void setup_sighandler(int sig) { struct sigaction act, oact; int rc; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, sig); act.sa_flags = 0; act.sa_handler = runner_sighandler; rc = sigaction(sig, &act, &oact); litest_assert_int_ne(rc, -1); } enum litest_runner_result litest_runner_run_tests(struct litest_runner *runner) { struct litest_runner_test *t; size_t available_jobs = max(runner->max_forks, 1); char timestamp[64]; struct tm *ltime; global_runner = runner; /* sigh, need this for signal handling */ if (runner->global.setup) runner->global.setup(runner->global.userdata); use_jmpbuf = runner->max_forks == 0; setup_sighandler(SIGINT); uint64_t now = 0; now_in_us(&now); runner->times.start_millis = us2ms(now); runner->times.start = time(NULL); ltime = localtime(&runner->times.start); strftime(timestamp, sizeof(timestamp), "%FT%H:%M", ltime); fprintf(runner->fp, "start: %ld # \"%s\"\n", runner->times.start, timestamp); fprintf(runner->fp, "jobs: %zd\n", runner->max_forks); fprintf(runner->fp, "tests:\n"); list_for_each_safe(t, &runner->tests, node) { int r = litest_runner_run_test(runner, t); if (r >= 0) { available_jobs--; } /* Wait for something to become available */ while (available_jobs == 0 && !runner->terminating) { int complete = litest_runner_check_finished_tests(runner); available_jobs += complete; } if (runner->terminating) { break; } if (runner->exit_on_fail) { bool do_exit = false; struct litest_runner_test *complete; list_for_each(complete, &runner->tests_complete, node) { switch (complete->result) { case LITEST_FAIL: case LITEST_SYSTEM_ERROR: case LITEST_TIMEOUT: do_exit = true; break; default: break; } if (do_exit) break; } if (do_exit) break; } } while (!runner->terminating && !list_empty(&runner->tests_running)) { litest_runner_check_finished_tests(runner); } if (runner->global.teardown) runner->global.teardown(runner->global.userdata); size_t npass = 0, nfail = 0, nskip = 0, nna = 0; size_t ncomplete = 0; list_for_each(t, &runner->tests_complete, node) { ncomplete++; switch (t->result) { case LITEST_PASS: npass++; break; case LITEST_NOT_APPLICABLE: nna++; break; case LITEST_FAIL: case LITEST_SYSTEM_ERROR: case LITEST_TIMEOUT: nfail++; break; case LITEST_SKIP: nskip++; break; } } runner->times.end = time(NULL); ltime = localtime(&runner->times.end); strftime(timestamp, sizeof(timestamp), "%FT%H:%M", ltime); fprintf(runner->fp, "end: %ld # \"%s\"\n", runner->times.end, timestamp); fprintf(runner->fp, "duration: %ld # (s) %02ld:%02ld\n", runner->times.end - runner->times.start, (runner->times.end - runner->times.start) / 60, (runner->times.end - runner->times.start) % 60); fprintf(runner->fp, "summary:\n"); fprintf(runner->fp, " completed: %zd\n", ncomplete); fprintf(runner->fp, " pass: %zd\n", npass); fprintf(runner->fp, " na: %zd\n", nna); fprintf(runner->fp, " fail: %zd\n", nfail); fprintf(runner->fp, " skip: %zd\n", nskip); if (nfail > 0) { fprintf(runner->fp, " failed:\n"); list_for_each(t, &runner->tests_complete, node) { switch (t->result) { case LITEST_FAIL: case LITEST_SYSTEM_ERROR: case LITEST_TIMEOUT: fprintf(runner->fp, " - \"%s\"\n", t->desc.name); break; default: break; } } } if (RUNNING_ON_VALGRIND) { char *filename = valgrind_logfile(getpid()); struct stringbuf *b = stringbuf_new(); collect_file(filename, b); fprintf(runner->fp, "valgrind:\n"); print_lines(runner->fp, b->data, " "); fprintf(runner->fp, "# Valgrind log is incomplete, see %s for full log\n", filename); free(filename); stringbuf_destroy(b); } enum litest_runner_result result = LITEST_PASS; /* Didn't finish */ if (!list_empty(&runner->tests) || !list_empty(&runner->tests_running)) { result = LITEST_SYSTEM_ERROR; } else { list_for_each(t, &runner->tests_complete, node) { switch (t->result) { case LITEST_PASS: case LITEST_NOT_APPLICABLE: break; default: result = LITEST_FAIL; break; } } } /* Status is always prefixed with LITEST_ */ fprintf(runner->fp, " status: %s\n", &litest_runner_result_as_str(result)[7]); return result; } libinput-1.28.1/test/litest-runner.h000066400000000000000000000134511477265155700174230ustar00rootroot00000000000000/* * Copyright © 2024 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #pragma once #include "config.h" #include "litest.h" #include "util-range.h" #define LITEST_RUNNER_DEFAULT_TIMEOUT 30 /** * Result returned from tests or suites. */ enum litest_runner_result { LITEST_PASS = 75, /**< test successful */ LITEST_FAIL = 76, /**< test failed. Should not be returned directly, Use the litest_ macros instead */ LITEST_SKIP = 77, /**< test was skipped */ LITEST_NOT_APPLICABLE = 78, /**< test does not apply */ LITEST_TIMEOUT = 79, /**< test aborted after timeout */ LITEST_SYSTEM_ERROR = 80, /**< unrelated error occurred */ }; /* For parametrized tests (litest_add_parametrized and friends) * a list of these is passed to every test. This struct isn't used * directly, use litest_test_param_fetch() instead. */ struct litest_test_param { struct list link; char name[128]; struct multivalue value; }; struct litest_test_parameters { int refcnt; struct list test_params; }; struct litest_test_parameters * litest_test_parameters_new(void); struct litest_test_parameters * litest_test_parameters_unref(struct litest_test_parameters *params); #define litest_test_param_fetch(...) \ _litest_test_param_fetch(__VA_ARGS__, NULL) void _litest_test_param_fetch(const struct litest_test_parameters *params, ...); static inline const char * litest_test_param_get_string(const struct litest_test_parameters *params, const char *name) { const char *p; litest_test_param_fetch(params, name, 's', &p); return p; } static inline bool litest_test_param_get_bool(const struct litest_test_parameters *params, const char *name) { bool p; litest_test_param_fetch(params, name, 'b', &p); return p; } static inline int32_t litest_test_param_get_i32(const struct litest_test_parameters *params, const char *name) { int32_t p; litest_test_param_fetch(params, name, 'i', &p); return p; } static inline uint32_t litest_test_param_get_u32(const struct litest_test_parameters *params, const char *name) { uint32_t p; litest_test_param_fetch(params, name, 'u', &p); return p; } static inline char litest_test_param_get_char(const struct litest_test_parameters *params, const char *name) { char p; litest_test_param_fetch(params, name, 'c', &p); return p; } static inline double litest_test_param_get_double(const struct litest_test_parameters *params, const char *name) { double p; litest_test_param_fetch(params, name, 'd', &p); return p; } /** * This struct is passed into every test. */ struct litest_runner_test_env { int rangeval; /* The current value within the args.range (or 0) */ const struct litest_test_parameters *params; }; struct litest_runner_test_description { char name[512]; /* The name of the test */ int rangeval; /* The current value within the args.range (or 0) */ struct litest_test_parameters *params; /* test function and corresponding setup/teardown, if any */ enum litest_runner_result (*func)(const struct litest_runner_test_env *); void (*setup)(const struct litest_runner_test_description *); void (*teardown)(const struct litest_runner_test_description *); struct { struct range range; /* The range this test applies to */ int signal; /* expected signal for fail tests */ } args; }; struct litest_runner; struct litest_runner *litest_runner_new(void); /** * Default is nprocs * 2. * Setting this to 0 means *no* forking. Setting this to 1 means only one test * is run at a time but in a child process. */ void litest_runner_set_num_parallel(struct litest_runner *runner, size_t num_jobs); void litest_runner_set_timeout(struct litest_runner *runner, unsigned int timeout); void litest_runner_set_verbose(struct litest_runner *runner, bool verbose); void litest_runner_set_use_colors(struct litest_runner *runner, bool use_colors); void litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit); void litest_runner_set_output_file(struct litest_runner *runner, FILE *fp); void litest_runner_add_test(struct litest_runner *runner, const struct litest_runner_test_description *t); enum litest_runner_result litest_runner_run_tests(struct litest_runner *runner); typedef enum litest_runner_result (*litest_runner_global_setup_func_t)(void *userdata); typedef void (*litest_runner_global_teardown_func_t)(void *userdata); void litest_runner_set_setup_funcs(struct litest_runner *runner, litest_runner_global_setup_func_t setup, litest_runner_global_teardown_func_t teardown, void *userdata); void litest_runner_destroy(struct litest_runner *runner); /* * Function to call abort(). Depending on the number of forks permitted, * this function may simply abort() or it may longjmp back out to collect * errors from non-forking tests. */ __attribute__((noreturn)) void litest_runner_abort(void); libinput-1.28.1/test/litest-selftest.c000066400000000000000000000302701477265155700177340ustar00rootroot00000000000000#include #include #include #include #include #include "litest.h" /* This is a bit messy but until we've completely switched over * to the litest runner it's easier like this */ #undef START_TEST #undef END_TEST #include START_TEST(litest_assert_trigger) { litest_assert(1 == 2); } END_TEST START_TEST(litest_assert_notrigger) { litest_assert(1 == 1); } END_TEST START_TEST(litest_assert_msg_trigger) { litest_assert_msg(1 == 2, "1 is not 2\n"); } END_TEST START_TEST(litest_assert_msg_NULL_trigger) { litest_assert_msg(1 == 2, NULL); } END_TEST START_TEST(litest_assert_msg_notrigger) { litest_assert_msg(1 == 1, "1 is not 2\n"); litest_assert_msg(1 == 1, NULL); } END_TEST START_TEST(litest_abort_msg_trigger) { litest_abort_msg("message\n"); } END_TEST START_TEST(litest_abort_msg_NULL_trigger) { litest_abort_msg(NULL); } END_TEST START_TEST(litest_int_eq_trigger) { int a = 10; int b = 20; litest_assert_int_eq(a, b); } END_TEST START_TEST(litest_int_eq_notrigger) { int a = 10; int b = 10; litest_assert_int_eq(a, b); } END_TEST START_TEST(litest_int_ne_trigger) { int a = 10; int b = 10; litest_assert_int_ne(a, b); } END_TEST START_TEST(litest_int_ne_notrigger) { int a = 10; int b = 20; litest_assert_int_ne(a, b); } END_TEST START_TEST(litest_int_lt_trigger_eq) { int a = 10; int b = 10; litest_assert_int_lt(a, b); } END_TEST START_TEST(litest_int_lt_trigger_gt) { int a = 11; int b = 10; litest_assert_int_lt(a, b); } END_TEST START_TEST(litest_int_lt_notrigger) { int a = 10; int b = 11; litest_assert_int_lt(a, b); } END_TEST START_TEST(litest_int_le_trigger) { int a = 11; int b = 10; litest_assert_int_le(a, b); } END_TEST START_TEST(litest_int_le_notrigger) { int a = 10; int b = 11; int c = 10; litest_assert_int_le(a, b); litest_assert_int_le(a, c); } END_TEST START_TEST(litest_int_gt_trigger_eq) { int a = 10; int b = 10; litest_assert_int_gt(a, b); } END_TEST START_TEST(litest_int_gt_trigger_lt) { int a = 9; int b = 10; litest_assert_int_gt(a, b); } END_TEST START_TEST(litest_int_gt_notrigger) { int a = 10; int b = 9; litest_assert_int_gt(a, b); } END_TEST START_TEST(litest_int_ge_trigger) { int a = 9; int b = 10; litest_assert_int_ge(a, b); } END_TEST START_TEST(litest_int_ge_notrigger) { int a = 10; int b = 9; int c = 10; litest_assert_int_ge(a, b); litest_assert_int_ge(a, c); } END_TEST START_TEST(litest_ptr_eq_notrigger) { int v = 10; int *a = &v; int *b = &v; int *c = NULL; int *d = NULL; litest_assert_ptr_eq(a, b); litest_assert_ptr_eq(c, d); } END_TEST START_TEST(litest_ptr_eq_trigger) { int v = 10; int v2 = 11; int *a = &v; int *b = &v2; litest_assert_ptr_eq(a, b); } END_TEST START_TEST(litest_ptr_eq_trigger_NULL) { int v = 10; int *a = &v; int *b = NULL; litest_assert_ptr_eq(a, b); } END_TEST START_TEST(litest_ptr_eq_trigger_NULL2) { int v = 10; int *a = &v; int *b = NULL; litest_assert_ptr_eq(b, a); } END_TEST START_TEST(litest_ptr_ne_trigger) { int v = 10; int *a = &v; int *b = &v; litest_assert_ptr_ne(a, b); } END_TEST START_TEST(litest_ptr_ne_trigger_NULL) { int *a = NULL; litest_assert_ptr_ne(a, NULL); } END_TEST START_TEST(litest_ptr_ne_trigger_NULL2) { int *a = NULL; litest_assert_ptr_ne(NULL, a); } END_TEST START_TEST(litest_ptr_ne_notrigger) { int v1 = 10; int v2 = 10; int *a = &v1; int *b = &v2; int *c = NULL; litest_assert_ptr_ne(a, b); litest_assert_ptr_ne(a, c); litest_assert_ptr_ne(c, b); } END_TEST START_TEST(litest_ptr_null_notrigger) { int *a = NULL; litest_assert_ptr_null(a); litest_assert_ptr_null(NULL); } END_TEST START_TEST(litest_ptr_null_trigger) { int v; int *a = &v; litest_assert_ptr_null(a); } END_TEST START_TEST(litest_ptr_notnull_notrigger) { int v; int *a = &v; litest_assert_ptr_notnull(a); } END_TEST START_TEST(litest_ptr_notnull_trigger) { int *a = NULL; litest_assert_ptr_notnull(a); } END_TEST START_TEST(litest_ptr_notnull_trigger_NULL) { litest_assert_ptr_notnull(NULL); } END_TEST START_TEST(litest_double_eq_and_ne) { litest_assert_double_eq(0.4,0.4); litest_assert_double_eq(0.4,0.4 + 1E-6); litest_assert_double_ne(0.4,0.4 + 1E-3); litest_assert_double_eq_epsilon(0.4, 0.5, 0.1); litest_assert_double_eq_epsilon(0.4, 0.5, 0.2); litest_assert_double_ne_epsilon(0.4, 0.6, 0.1); litest_assert_double_ne_epsilon(0.4, 0.41, 0.005); } END_TEST START_TEST(litest_double_lt_gt) { litest_assert_double_lt(12.0,13.0); litest_assert_double_gt(15.4,13.0); litest_assert_double_le(12.0,12.0); litest_assert_double_le(12.0,20.0); litest_assert_double_ge(12.0,12.0); litest_assert_double_ge(20.0,12.0); } END_TEST START_TEST(litest_double_eq_fails) { litest_assert_double_eq(0.41,0.4); } END_TEST START_TEST(litest_double_eq_epsilon_fails) { litest_assert_double_eq_epsilon(0.4,0.5,0.05); } END_TEST START_TEST(litest_double_ne_fails) { litest_assert_double_ne(0.4 + 1E-7,0.4); } END_TEST START_TEST(litest_double_ne_epsilon_fails) { litest_assert_double_ne_epsilon(0.4, 0.5, 0.2); } END_TEST START_TEST(litest_double_lt_fails) { litest_assert_double_lt(6.0, 5.0); } END_TEST START_TEST(litest_double_gt_fails) { litest_assert_double_gt(5.0, 6.0); } END_TEST START_TEST(litest_double_le_fails) { litest_assert_double_le(6.0, 5.0); } END_TEST START_TEST(litest_double_ge_fails) { litest_assert_double_ge(5.0, 6.0); } END_TEST START_TEST(litest_string_eq_ne) { litest_assert_str_eq("foo", "foo"); litest_assert_str_ne("foo", "bar"); litest_assert_str_ne("foo", "foobar"); litest_assert_str_ne("foobar", "foo"); const char *a1 = "a"; const char *a2 = "a"; const char *b = "b"; litest_assert_str_eq(NULL, NULL); litest_assert_str_eq(a1, a2); litest_assert_str_ne(a1, b); litest_assert_str_ne(a2, b); litest_assert_str_ne(a2, b); litest_assert_str_ne(b, NULL); } END_TEST START_TEST(litest_string_eq_fails) { litest_assert_str_eq("foo", "bar"); } END_TEST START_TEST(litest_string_ne_fails) { litest_assert_str_ne("foo", "foo"); } END_TEST START_TEST(zalloc_overflow) { zalloc((size_t)-1); } END_TEST START_TEST(zalloc_max_size) { /* Built-in alloc maximum */ free(zalloc(1536 * 1024)); } END_TEST START_TEST(zalloc_too_large) { zalloc(1536 * 1024 + 1); } END_TEST struct permutation { int32_t i; const char *s; bool b; bool found; }; static int permutation_func(struct litest_parameters_permutation *permutation, void *userdata) { struct litest_parameters_permutation_value *value; int32_t first; const char *second; bool third; value = list_first_entry(&permutation->values, value, link); multivalue_extract_typed(&value->value, 'i', &first); value = list_first_entry(&value->link, value, link); multivalue_extract_typed(&value->value, 's', &second); value = list_first_entry(&value->link, value, link); multivalue_extract_typed(&value->value, 'b', &third); struct permutation *p = userdata; while (p->s) { if (p->i == first && streq(p->s, second) && p->b == third) { p->found = true; break; } p++; } return 0; } START_TEST(parameter_permutations) { struct permutation permutations[] = { { 1, "a", true }, { 1, "a", false }, { 1, "ab", true }, { 1, "ab", false }, { 1, "abc", true }, { 1, "abc", false }, { 2, "a", true }, { 2, "a", false }, { 2, "ab", true }, { 2, "ab", false }, { 2, "abc", true }, { 2, "abc", false }, { 3, "a", true }, { 3, "a", false }, { 3, "ab", true }, { 3, "ab", false }, { 3, "abc", true }, { 3, "abc", false }, { 0, NULL, false, false }, }; struct litest_parameters *params = litest_parameters_new("first", 'i', 3, 1, 2, 3, "second", 's', 3, "a", "ab", "abc", "third", 'b', NULL); litest_parameters_permutations(params, permutation_func, permutations); ARRAY_FOR_EACH(permutations, p) { if (p->s == NULL) break; ck_assert_msg(p->found, "For %d/%s/%s", p->i, p->s, truefalse(p->b)); } } END_TEST static Suite * litest_assert_macros_suite(void) { TCase *tc; Suite *s; s = suite_create("litest:assert macros"); #if 0 tc = tcase_create("assert"); tcase_add_test_raise_signal(tc, litest_assert_trigger, SIGABRT); tcase_add_test(tc, litest_assert_notrigger); tcase_add_test_raise_signal(tc, litest_assert_msg_trigger, SIGABRT); tcase_add_test_raise_signal(tc, litest_assert_msg_NULL_trigger, SIGABRT); tcase_add_test(tc, litest_assert_msg_notrigger); suite_add_tcase(s, tc); tc = tcase_create("abort"); tcase_add_test_raise_signal(tc, litest_abort_msg_trigger, SIGABRT); tcase_add_test_raise_signal(tc, litest_abort_msg_NULL_trigger, SIGABRT); suite_add_tcase(s, tc); tc = tcase_create("int comparison "); tcase_add_test_raise_signal(tc, litest_int_eq_trigger, SIGABRT); tcase_add_test(tc, litest_int_eq_notrigger); tcase_add_test_raise_signal(tc, litest_int_ne_trigger, SIGABRT); tcase_add_test(tc, litest_int_ne_notrigger); tcase_add_test_raise_signal(tc, litest_int_le_trigger, SIGABRT); tcase_add_test(tc, litest_int_le_notrigger); tcase_add_test_raise_signal(tc, litest_int_lt_trigger_gt, SIGABRT); tcase_add_test_raise_signal(tc, litest_int_lt_trigger_eq, SIGABRT); tcase_add_test(tc, litest_int_lt_notrigger); tcase_add_test_raise_signal(tc, litest_int_ge_trigger, SIGABRT); tcase_add_test(tc, litest_int_ge_notrigger); tcase_add_test_raise_signal(tc, litest_int_gt_trigger_eq, SIGABRT); tcase_add_test_raise_signal(tc, litest_int_gt_trigger_lt, SIGABRT); tcase_add_test(tc, litest_int_gt_notrigger); suite_add_tcase(s, tc); tc = tcase_create("pointer comparison "); tcase_add_test_raise_signal(tc, litest_ptr_eq_trigger, SIGABRT); tcase_add_test_raise_signal(tc, litest_ptr_eq_trigger_NULL, SIGABRT); tcase_add_test_raise_signal(tc, litest_ptr_eq_trigger_NULL2, SIGABRT); tcase_add_test(tc, litest_ptr_eq_notrigger); tcase_add_test_raise_signal(tc, litest_ptr_ne_trigger, SIGABRT); tcase_add_test_raise_signal(tc, litest_ptr_ne_trigger_NULL, SIGABRT); tcase_add_test_raise_signal(tc, litest_ptr_ne_trigger_NULL2, SIGABRT); tcase_add_test(tc, litest_ptr_ne_notrigger); tcase_add_test_raise_signal(tc, litest_ptr_null_trigger, SIGABRT); tcase_add_test(tc, litest_ptr_null_notrigger); tcase_add_test_raise_signal(tc, litest_ptr_notnull_trigger, SIGABRT); tcase_add_test_raise_signal(tc, litest_ptr_notnull_trigger_NULL, SIGABRT); tcase_add_test(tc, litest_ptr_notnull_notrigger); suite_add_tcase(s, tc); tc = tcase_create("double comparison "); tcase_add_test(tc, litest_double_eq_and_ne); tcase_add_test(tc, litest_double_lt_gt); tcase_add_test_raise_signal(tc, litest_double_eq_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_eq_epsilon_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_ne_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_ne_epsilon_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_lt_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_gt_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_le_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_double_ge_fails, SIGABRT); suite_add_tcase(s, tc); tc = tcase_create("string comparison "); tcase_add_test(tc, litest_string_eq_ne); tcase_add_test_raise_signal(tc, litest_string_eq_fails, SIGABRT); tcase_add_test_raise_signal(tc, litest_string_ne_fails, SIGABRT); suite_add_tcase(s, tc); tc = tcase_create("zalloc "); tcase_add_test(tc, zalloc_max_size); tcase_add_test_raise_signal(tc, zalloc_overflow, SIGABRT); tcase_add_test_raise_signal(tc, zalloc_too_large, SIGABRT); suite_add_tcase(s, tc); #endif tc = tcase_create("parameters "); tcase_add_test(tc, parameter_permutations); suite_add_tcase(s, tc); return s; } int main (int argc, char **argv) { const struct rlimit corelimit = { 0, 0 }; int nfailed; Suite *s; SRunner *sr; /* when running under valgrind we're using nofork mode, so a signal * raised by a test will fail in valgrind. There's nothing to * memcheck here anyway, so just skip the valgrind test */ if (RUNNING_ON_VALGRIND) return 77; if (setrlimit(RLIMIT_CORE, &corelimit) != 0) perror("WARNING: Core dumps not disabled"); s = litest_assert_macros_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_ENV); nfailed = srunner_ntests_failed(sr); srunner_free(sr); return (nfailed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } libinput-1.28.1/test/litest.c000066400000000000000000003717521477265155700161220ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * Copyright © 2013 Marcin Slusarz * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "linux/input.h" #include #include #include #include #include #include #include #include #if HAVE_LIBSYSTEMD #include #endif #ifdef __FreeBSD__ #include #endif #include #include "util-files.h" #include "litest.h" #include "litest-runner.h" #include "litest-int.h" #include "libinput-util.h" #include "quirks.h" #include "builddir.h" #include "util-backtrace.h" #include "util-libinput.h" #include #define evbit(t, c) ((t) << 16U | (c & 0xffff)) #define UDEV_RULES_D "/run/udev/rules.d" #define UDEV_FUZZ_OVERRIDE_RULE_FILE UDEV_RULES_D \ "/91-litest-fuzz-override-REMOVEME-XXXXXX.rules" #define UDEV_TEST_DEVICE_RULE_FILE UDEV_RULES_D \ "/91-litest-test-device-REMOVEME-XXXXXXX.rules" #define UDEV_DEVICE_GROUPS_FILE UDEV_RULES_D \ "/80-libinput-device-groups-litest-XXXXXX.rules" static int jobs; static bool in_debugger = false; static bool verbose = false; static bool run_deviceless = false; static bool use_system_rules_quirks = false; static bool exit_first = false; static FILE * outfile = NULL; static const char *filter_test = NULL; static const char *filter_device = NULL; static const char *filter_group = NULL; static int filter_rangeval = INT_MIN; static bool use_colors = false; struct param_filter { char name[64]; char glob[64]; }; struct param_filter filter_params[8]; /* name=NULL terminated */ static struct quirks_context *quirks_context; struct created_file { struct list link; char *path; }; static void created_file_destroy(struct created_file *f) { list_remove(&f->link); free(f->path); free(f); } static void created_file_unlink(struct created_file *f) { unlink(f->path); rmdir(f->path); } static struct suite *current_suite = NULL; static void litest_init_udev_rules(struct list *created_files_list); static void litest_remove_udev_rules(struct list *created_files_list); static void litest_print_event(struct libinput_event *event, const char *message); enum quirks_setup_mode { QUIRKS_SETUP_USE_SRCDIR, QUIRKS_SETUP_ONLY_DEVICE, QUIRKS_SETUP_FULL, }; static void litest_setup_quirks(struct list *created_files_list, enum quirks_setup_mode mode); /* defined for the litest selftest */ #ifndef LITEST_DISABLE_BACKTRACE_LOGGING #define litest_log(...) fprintf(stderr, __VA_ARGS__) #define litest_vlog(format_, args_) vfprintf(stderr, format_, args_) #else #define litest_log(...) { /* __VA_ARGS__ */ } #define litest_vlog(...) { /* __VA_ARGS__ */ } #endif LIBINPUT_ATTRIBUTE_PRINTF(4, 5) void _litest_checkpoint(const char *func, int line, const char *color, const char *format, ...) { char buf[1024]; va_list args; va_start(args, format); if (verbose) { vsnprintf(buf, sizeof(buf), format, args); fprintf(stderr, "%s%s():%d - %s%s%s\n", use_colors ? ANSI_BRIGHT_BLUE : "", func, line, use_colors ? color : "", buf, use_colors ? ANSI_NORMAL : ""); } va_end(args); } void litest_backtrace(const char *func) { #ifndef LITEST_DISABLE_BACKTRACE_LOGGING if (RUNNING_ON_VALGRIND) { fprintf(stderr, "Using valgrind, omitting backtrace\n"); return; } char buf[256]; snprintf(buf, sizeof(buf), "in %s", func); backtrace_print(stderr, use_colors, "in litest_backtrace", "in litest_runner_test_run", func ? buf : NULL); #endif } LIBINPUT_ATTRIBUTE_PRINTF(5, 6) __attribute__((noreturn)) void litest_fail_condition(const char *file, int line, const char *func, const char *condition, const char *message, ...) { litest_log("FAILED: %s\n", condition); if (message) { char buf[1024]; va_list args; va_start(args, message); vsnprintf(buf, sizeof(buf), message, args); va_end(args); litest_log("%s\n", buf); } litest_log("in %s() (%s:%d)\n", func, file, line); litest_backtrace(func); litest_runner_abort(); } __attribute__((noreturn)) void litest_fail_comparison_int(const char *file, int line, const char *func, const char *operator, int a, int b, const char *astr, const char *bstr) { litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr); litest_log("Resolved to: %d %s %d\n", a, operator, b); litest_log("in %s() (%s:%d)\n", func, file, line); litest_backtrace(func); litest_runner_abort(); } __attribute__((noreturn)) void litest_fail_comparison_double(const char *file, int line, const char *func, const char *operator, double a, double b, const char *astr, const char *bstr) { litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr); litest_log("Resolved to: %.3f %s %.3f\n", a, operator, b); litest_log("in %s() (%s:%d)\n", func, file, line); litest_backtrace(func); litest_runner_abort(); } __attribute__((noreturn)) void litest_fail_comparison_ptr(const char *file, int line, const char *func, const char *comparison) { litest_log("FAILED COMPARISON: %s\n", comparison); litest_log("in %s() (%s:%d)\n", func, file, line); litest_backtrace(func); litest_runner_abort(); } __attribute__((noreturn)) void litest_fail_comparison_str(const char *file, int line, const char *func, const char *comparison, const char *operator, const char *astr, const char *bstr) { litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr); litest_log("Resolved to: %s %s %s\n", astr, operator, bstr); litest_log("in %s() (%s:%d)\n", func, file, line); litest_backtrace(func); litest_runner_abort(); } struct test { struct list node; char *name; char *devname; const void *func; void *setup; void *teardown; struct range range; int rangeval; bool deviceless; struct litest_test_parameters *params; }; struct suite { struct list node; struct list tests; char *name; }; struct litest_parameter_value { size_t refcnt; struct list link; /* litest_parameter->values */ struct multivalue value; }; struct litest_parameter { size_t refcnt; struct list link; /* litest_parameters.params */ char name[128]; char type; /* One of u, i, d, c, s, b */ struct list values; /* litest_parameter_value */ }; struct litest_parameters { size_t refcnt; struct list params; /* struct litest_parameter */ }; static struct litest_parameter_value * litest_parameter_value_new(void) { struct litest_parameter_value *pv = zalloc(sizeof *pv); list_init(&pv->link); pv->refcnt = 1; return pv; } static inline void litest_parameter_add_string(struct litest_parameter *p, const char *s) { assert(p->type == 's'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_string(s); list_append(&p->values, &pv->link); } static inline void litest_parameter_add_char(struct litest_parameter *p, char c) { assert(p->type == 'c'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_char(c); list_append(&p->values, &pv->link); } static inline void litest_parameter_add_bool(struct litest_parameter *p, bool b) { assert(p->type == 'b'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_bool(b); list_append(&p->values, &pv->link); } static inline void litest_parameter_add_u32(struct litest_parameter *p, uint32_t u) { assert(p->type == 'u'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_u32(u); list_append(&p->values, &pv->link); } static inline void litest_parameter_add_i32(struct litest_parameter *p, int32_t i) { assert(p->type == 'i'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_i32(i); list_append(&p->values, &pv->link); } static void litest_parameter_add_double(struct litest_parameter *p, double d) { assert(p->type == 'd'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_double(d); list_append(&p->values, &pv->link); } static inline void litest_parameter_add_named_i32(struct litest_parameter *p, const struct litest_named_i32 i) { assert(p->type == 'I'); struct litest_parameter_value *pv = litest_parameter_value_new(); pv->value = multivalue_new_named_i32(i.value, i.name); list_append(&p->values, &pv->link); } #if 0 static struct litest_parameter_value * litest_parameter_value_ref(struct litest_parameter_value *pv) { assert(pv); assert(pv->refcnt > 0); pv->refcnt++; return pv; } #endif static struct litest_parameter_value * litest_parameter_value_unref(struct litest_parameter_value *pv) { if (pv) { assert(pv->refcnt > 0); if (--pv->refcnt == 0) { list_remove(&pv->link); free(pv); } } return NULL; } static struct litest_parameter* litest_parameter_new(const char *name, char type) { struct litest_parameter *p = zalloc(sizeof *p); switch (type) { case 'b': case 'c': case 'd': case 'i': case 'I': case 's': case 'u': break; default: assert(!"Type not yet implemented"); } list_init(&p->link); list_init(&p->values); snprintf(p->name, sizeof(p->name), "%s", name); p->type = type; p->refcnt = 1; return p; } static struct litest_parameter * litest_parameter_ref(struct litest_parameter *p) { assert(p); assert(p->refcnt > 0); p->refcnt++; return p; } static struct litest_parameter * litest_parameter_unref(struct litest_parameter *p) { if (p) { assert(p->refcnt > 0); if (--p->refcnt == 0) { struct litest_parameter_value *pv; list_for_each_safe(pv, &p->values, link) { litest_parameter_value_unref(pv); } list_remove(&p->link); free(p); } } return NULL; } static void litest_parameters_add(struct litest_parameters *ps, struct litest_parameter *param) { struct litest_parameter *p; list_for_each(p, &ps->params, link) { assert(!streq(p->name, param->name)); } litest_parameter_ref(param); list_append(&ps->params, ¶m->link); } struct litest_parameters * _litest_parameters_new(const char *name, ...) { struct litest_parameters *ps = zalloc(sizeof *ps); list_init(&ps->params); ps->refcnt = 1; va_list args; va_start(args, name); while (name) { char type = va_arg(args, int); struct litest_parameter *param = litest_parameter_new(name, type); if (type == 'b') { litest_parameter_add_bool(param, true); litest_parameter_add_bool(param, false); } else { unsigned int nargs = va_arg(args, unsigned int); for (unsigned int _ = 0; _ < nargs; _++) { switch (type) { case 'c': { char b = va_arg(args, int); litest_parameter_add_char(param, b); break; } case 'u': { uint32_t b = va_arg(args, uint32_t); litest_parameter_add_u32(param, b); break; } case 'i': { int32_t b = va_arg(args, int32_t); litest_parameter_add_i32(param, b); break; } case 'd': { double b = va_arg(args, double); litest_parameter_add_double(param, b); break; } case 's': { const char *s = va_arg(args, const char *); litest_parameter_add_string(param, s); break; } case 'I': { struct litest_named_i32 p = va_arg(args, struct litest_named_i32); litest_parameter_add_named_i32(param, p); break; } default: abort(); break; } } } litest_parameters_add(ps, param); litest_parameter_unref(param); name = va_arg(args, const char *); } va_end(args); return ps; } struct litest_parameters * litest_parameters_ref(struct litest_parameters *p) { assert(p); assert(p->refcnt > 0); p->refcnt++; return p; } struct litest_parameters * litest_parameters_unref(struct litest_parameters *params) { if (params) { assert(params->refcnt > 0); if (--params->refcnt == 0) { struct litest_parameter *p; list_for_each_safe(p, ¶ms->params, link) { litest_parameter_unref(p); } free(params); } } return NULL; } static inline int _permutate(struct litest_parameters_permutation *permutation, struct list *next_param, void *list_head, litest_parameters_permutation_func_t func, void *userdata) { if (next_param->next == list_head) { func(permutation, userdata); return 0; } struct litest_parameter_value *pv; struct litest_parameter *param = list_first_entry(next_param, param, link); list_for_each(pv, ¶m->values, link) { struct litest_parameters_permutation_value v = { .value = pv->value, }; memcpy(v.name, param->name, min(sizeof(v.name), sizeof(param->name))); list_append(&permutation->values, &v.link); int rc = _permutate(permutation, ¶m->link, list_head, func, userdata); if (rc) return rc; list_remove(&v.link); } return 0; } /** * Calls the given function func with each permutation of * the given test parameters. */ int litest_parameters_permutations(struct litest_parameters *params, litest_parameters_permutation_func_t func, void *userdata) { struct litest_parameters_permutation permutation; list_init(&permutation.values); return _permutate(&permutation, ¶ms->params, ¶ms->params, func, userdata); } static struct litest_device *current_device; struct litest_device *litest_current_device(void) { return current_device; } int _litest_dispatch(struct libinput *li, const char *func, int line) { static int dispatch_counter = 0; ++dispatch_counter; _litest_checkpoint(func, line, ANSI_MAGENTA, "┌──────────────────── dispatch %3d ────────────────────┐", dispatch_counter); int rc = libinput_dispatch(li); enum libinput_event_type type = libinput_next_event_type(li); const char *evtype = type == LIBINPUT_EVENT_NONE ? "NONE" : litest_event_type_str(type); _litest_checkpoint(func, line, ANSI_MAGENTA, "└──────────────────── /dispatch %3d ────────────────────┘ pending %s", dispatch_counter, evtype); return rc; } static void grab_device(struct litest_device *device, bool mode) { struct libinput *li = libinput_device_get_context(device->libinput_device); struct litest_context *ctx = libinput_get_user_data(li); struct udev_device *udev_device; const char *devnode; struct path *p; udev_device = libinput_device_get_udev_device(device->libinput_device); litest_assert_ptr_notnull(udev_device); devnode = udev_device_get_devnode(udev_device); /* Note: in some tests we create multiple devices for the same path. * This will only grab the first device in the list but we're using * list_insert() so the first device is the latest that was * initialized, so we should be good. */ list_for_each(p, &ctx->paths, link) { if (streq(p->path, devnode)) { int rc = ioctl(p->fd, EVIOCGRAB, (void*)mode ? 1 : 0); litest_assert_errno_success(rc); udev_device_unref(udev_device); return; } } litest_abort_msg("Failed to find device %s to %sgrab", devnode, mode ? "" : "un"); } void litest_grab_device(struct litest_device *device) { grab_device(device, true); } void litest_ungrab_device(struct litest_device *device) { grab_device(device, false); } void litest_set_current_device(struct litest_device *device) { current_device = device; } void litest_generic_device_teardown(void) { litest_delete_device(current_device); current_device = NULL; } static struct list devices = LIST_INIT(devices); /* struct litest_test_device */ static struct list all_test_suites = LIST_INIT(all_test_suites); /* struct suite */ static inline void litest_system(const char *command) { int ret; ret = system(command); if (ret == -1) { litest_abort_msg("Failed to execute: %s", command); } else if (WIFEXITED(ret)) { if (WEXITSTATUS(ret)) litest_abort_msg("'%s' failed with %d", command, WEXITSTATUS(ret)); } else if (WIFSIGNALED(ret)) { litest_abort_msg("'%s' terminated with signal %d", command, WTERMSIG(ret)); } } static void litest_reload_udev_rules(void) { litest_system("udevadm control --reload-rules"); } static bool filter_for_rangeval(const struct range *range, int rangeval) { return !range || filter_rangeval == INT_MIN || filter_rangeval == rangeval; } static void litest_add_tcase_for_device(struct suite *suite, const char *funcname, const void *func, const struct litest_test_device *dev, const struct range *range) { const struct range no_range = range_init_empty(); if (run_deviceless) return; if (!range) range = &no_range; int rangeval = range->lower; do { if (filter_for_rangeval(range, rangeval)) { struct test *t; t = zalloc(sizeof(*t)); t->name = safe_strdup(funcname); t->devname = safe_strdup(dev->shortname); t->func = func; t->setup = dev->setup; t->teardown = dev->teardown ? dev->teardown : litest_generic_device_teardown; if (range) t->range = *range; t->rangeval = rangeval; list_append(&suite->tests, &t->node); } } while (++rangeval < range->upper); } struct permutation_userdata { struct suite *suite; const char *funcname; const void *func; const struct litest_test_device *dev; char devname[64]; /* set if dev == NULL */ const struct param_filter *param_filters; /* name=NULL terminated */ }; static int permutation_func(struct litest_parameters_permutation *permutation, void *userdata) { struct permutation_userdata *data = userdata; struct litest_test_parameters *params = litest_test_parameters_new(); struct litest_parameters_permutation_value *pmv; bool filtered = false; list_for_each(pmv, &permutation->values, link) { const struct param_filter *f = data->param_filters; while (!filtered && strlen(f->name)) { if (streq(pmv->name, f->name)) { char *s = multivalue_as_str(&pmv->value); if (fnmatch(f->glob, s, 0) != 0) filtered = true; free(s); } f++; } if (filtered) break; struct litest_test_param *tp = zalloc(sizeof *tp); snprintf(tp->name, sizeof(tp->name), "%s", pmv->name); tp->value = multivalue_copy(&pmv->value); list_append(¶ms->test_params, &tp->link); } if (filtered) { litest_test_parameters_unref(params); return 0; } struct test *t; t = zalloc(sizeof(*t)); t->name = safe_strdup(data->funcname); t->func = data->func; if (data->dev) { t->devname = safe_strdup(data->dev->shortname); t->setup = data->dev->setup; t->teardown = data->dev->teardown ? data->dev->teardown : litest_generic_device_teardown; } else { t->devname = safe_strdup(data->devname); t->setup = NULL; t->teardown = NULL; } t->rangeval = 0; t->params = params; list_append(&data->suite->tests, &t->node); return 0; } static void litest_add_tcase_for_device_with_params(struct suite *suite, const char *funcname, const void *func, const struct litest_test_device *dev, struct litest_parameters *params) { if (run_deviceless) return; struct permutation_userdata data = { .suite = suite, .funcname = funcname, .func = func, .dev = dev, .param_filters = filter_params, }; litest_parameters_permutations(params, permutation_func, &data); } static void litest_add_tcase_no_device(struct suite *suite, const void *func, const char *funcname, const struct range *range) { const char *test_name = funcname; const struct range no_range = range_init_empty(); if (filter_device && fnmatch(filter_device, test_name, 0) != 0) return; if (run_deviceless) return; if (!range) range = &no_range; int rangeval = range->lower; do { if (filter_for_rangeval(range, rangeval)) { struct test *t; t = zalloc(sizeof(*t)); t->name = safe_strdup(test_name); t->devname = safe_strdup("no device"); t->func = func; if (range) t->range = *range; t->rangeval = rangeval; t->setup = NULL; t->teardown = NULL; list_append(&suite->tests, &t->node); } } while (++rangeval < range->upper); } static void litest_add_tcase_no_device_with_params(struct suite *suite, const void *func, const char *funcname, struct litest_parameters *params) { const char *test_name = funcname; if (filter_device && fnmatch(filter_device, test_name, 0) != 0) return; if (run_deviceless) return; struct permutation_userdata data = { .suite = suite, .funcname = funcname, .func = func, .param_filters = filter_params, }; snprintf(data.devname, sizeof(data.devname), "no device"); litest_parameters_permutations(params, permutation_func, &data); } static void litest_add_tcase_deviceless(struct suite *suite, const void *func, const char *funcname, const struct range *range) { const char *test_name = funcname; const struct range no_range = range_init_empty(); if (filter_device && fnmatch(filter_device, test_name, 0) != 0) return; if (!range) range = &no_range; int rangeval = range->lower; do { if (filter_for_rangeval(range, rangeval)) { struct test *t; t = zalloc(sizeof(*t)); t->deviceless = true; t->name = safe_strdup(test_name); t->devname = safe_strdup("deviceless"); t->func = func; if (range) t->range = *range; t->rangeval = rangeval; t->setup = NULL; t->teardown = NULL; list_append(&suite->tests, &t->node); } } while (++rangeval < range->upper); } static void litest_add_tcase_deviceless_with_params(struct suite *suite, const void *func, const char *funcname, struct litest_parameters *params) { const char *test_name = funcname; if (filter_device && fnmatch(filter_device, test_name, 0) != 0) return; struct permutation_userdata data = { .suite = suite, .funcname = funcname, .func = func, .param_filters = filter_params, }; snprintf(data.devname, sizeof(data.devname), "deviceless"); litest_parameters_permutations(params, permutation_func, &data); } static void litest_add_tcase(const char *filename, const char *funcname, const void *func, int64_t required, int64_t excluded, const struct range *range, struct litest_parameters *params) { bool added = false; litest_assert(required >= LITEST_DEVICELESS); litest_assert(excluded >= LITEST_DEVICELESS); if (filter_test && fnmatch(filter_test, funcname, 0) != 0) return; struct suite *suite = current_suite; if (filter_group && fnmatch(filter_group, suite->name, 0) != 0) return; if (required == LITEST_DEVICELESS && excluded == LITEST_DEVICELESS) { if (params) litest_add_tcase_deviceless_with_params(suite, func, funcname, params); else litest_add_tcase_deviceless(suite, func, funcname, range); added = true; } else if (required == LITEST_DISABLE_DEVICE && excluded == LITEST_DISABLE_DEVICE) { if (params) litest_add_tcase_no_device_with_params(suite, func, funcname, params); else litest_add_tcase_no_device(suite, func, funcname, range); added = true; } else if (required != LITEST_ANY || excluded != LITEST_ANY) { struct litest_test_device *dev; list_for_each(dev, &devices, node) { if (dev->features & LITEST_IGNORED) continue; if (filter_device && fnmatch(filter_device, dev->shortname, 0) != 0) continue; if ((dev->features & required) != required || (dev->features & excluded) != 0) continue; if (params) { litest_add_tcase_for_device_with_params(suite, funcname, func, dev, params); } else { litest_add_tcase_for_device(suite, funcname, func, dev, range); } added = true; } } else { struct litest_test_device *dev; list_for_each(dev, &devices, node) { if (dev->features & LITEST_IGNORED) continue; if (filter_device && fnmatch(filter_device, dev->shortname, 0) != 0) continue; if (params) { litest_add_tcase_for_device_with_params(suite, funcname, func, dev, params); } else { litest_add_tcase_for_device(suite, funcname, func, dev, range); } added = true; } } if (!added && filter_test == NULL && filter_device == NULL && filter_group == NULL) { fprintf(stderr, "Test '%s' does not match any devices. Aborting.\n", funcname); abort(); } } void _litest_add_no_device(const char *name, const char *funcname, const void *func) { _litest_add(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE); } void _litest_add_parametrized_no_device(const char *name, const char *funcname, const void *func, struct litest_parameters *params) { _litest_add_parametrized(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE, params); } void _litest_add_ranged_no_device(const char *name, const char *funcname, const void *func, const struct range *range) { _litest_add_ranged(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE, range); } void _litest_add_deviceless(const char *name, const char *funcname, const void *func) { _litest_add_ranged(name, funcname, func, LITEST_DEVICELESS, LITEST_DEVICELESS, NULL); } void _litest_add_parametrized_deviceless(const char *name, const char *funcname, const void *func, struct litest_parameters *params) { _litest_add_parametrized(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE, params); } void _litest_add(const char *name, const char *funcname, const void *func, int64_t required, int64_t excluded) { _litest_add_ranged(name, funcname, func, required, excluded, NULL); } void _litest_add_ranged(const char *name, const char *funcname, const void *func, int64_t required, int64_t excluded, const struct range *range) { litest_add_tcase(name, funcname, func, required, excluded, range, NULL); } void _litest_add_parametrized(const char *name, const char *funcname, const void *func, int64_t required, int64_t excluded, struct litest_parameters *params) { litest_add_tcase(name, funcname, func, required, excluded, NULL, params); } void _litest_add_for_device(const char *name, const char *funcname, const void *func, enum litest_device_type type) { _litest_add_ranged_for_device(name, funcname, func, type, NULL); } void _litest_add_ranged_for_device(const char *filename, const char *funcname, const void *func, enum litest_device_type type, const struct range *range) { struct litest_test_device *dev; bool device_filtered = false; litest_assert(type < LITEST_NO_DEVICE); if (filter_test && fnmatch(filter_test, funcname, 0) != 0) return; struct suite *s = current_suite; if (filter_group && fnmatch(filter_group, s->name, 0) != 0) return; list_for_each(dev, &devices, node) { if (filter_device && fnmatch(filter_device, dev->shortname, 0) != 0) { device_filtered = true; continue; } if (dev->type == type) { litest_add_tcase_for_device(s, funcname, func, dev, range); return; } } /* only abort if no filter was set, that's a bug */ if (!device_filtered) litest_abort_msg("Invalid test device type"); } void _litest_add_parametrized_for_device(const char *filename, const char *funcname, const void *func, enum litest_device_type type, struct litest_parameters *params) { struct litest_test_device *dev; bool device_filtered = false; litest_assert(type < LITEST_NO_DEVICE); if (filter_test && fnmatch(filter_test, funcname, 0) != 0) return; struct suite *s = current_suite; if (filter_group && fnmatch(filter_group, s->name, 0) != 0) return; list_for_each(dev, &devices, node) { if (filter_device && fnmatch(filter_device, dev->shortname, 0) != 0) { device_filtered = true; continue; } if (dev->type == type) { litest_add_tcase_for_device_with_params(s, funcname, func, dev, params); return; } } /* only abort if no filter was set, that's a bug */ if (!device_filtered) litest_abort_msg("Invalid test device type"); } LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void litest_log_handler(struct libinput *libinput, enum libinput_log_priority pri, const char *format, va_list args) { const char *priority = NULL; const char *color; switch(pri) { case LIBINPUT_LOG_PRIORITY_INFO: priority = "info "; color = ANSI_HIGHLIGHT; break; case LIBINPUT_LOG_PRIORITY_ERROR: priority = "error"; color = ANSI_BRIGHT_RED; break; case LIBINPUT_LOG_PRIORITY_DEBUG: priority = "debug"; color = ANSI_NORMAL; break; default: abort(); } if (!use_colors) color = ""; else if (strstr(format, "tap:")) color = ANSI_BLUE; else if (strstr(format, "thumb state:")) color = ANSI_YELLOW; else if (strstr(format, "button state:")) color = ANSI_MAGENTA; else if (strstr(format, "touch-size:") || strstr(format, "pressure:")) color = ANSI_GREEN; else if (strstr(format, "palm:") || strstr(format, "thumb:")) color = ANSI_CYAN; else if (strstr(format, "edge-scroll:")) color = ANSI_BRIGHT_GREEN; else if (strstr(format, "gesture:")) color = ANSI_BRIGHT_YELLOW; fprintf(stderr, "%slitest %s ", color, priority); vfprintf(stderr, format, args); if (use_colors) fprintf(stderr, ANSI_NORMAL); if (strstr(format, "client bug: ") || strstr(format, "libinput bug: ")) { /* valgrind is too slow and some of our offsets are too * short, don't abort if during a valgrind run we get a * negative offset */ if ((RUNNING_ON_VALGRIND && in_debugger) || strstr(format, "scheduled expiry is in the past")) { /* noop */ } else if (strstr(format, "event processing lagging behind")) { /* noop */ } else { litest_abort_msg("libinput bug triggered, aborting."); } } if (strstr(format, "Touch jump detected and discarded")) { litest_abort_msg("libinput touch jump triggered, aborting."); } } static void litest_init_device_udev_rules(struct litest_test_device *dev, FILE *f) { const struct key_value_str *kv; static int count; bool need_keyboard_builtin = false; if (dev->udev_properties[0].key == NULL) return; count++; fprintf(f, "# %s\n", dev->shortname); fprintf(f, "ACTION==\"remove\", GOTO=\"rule%d_end\"\n", count); fprintf(f, "KERNEL!=\"event*\", GOTO=\"rule%d_end\"\n", count); fprintf(f, "ATTRS{name}==\"litest %s*\"", dev->name); kv = dev->udev_properties; while (kv->key) { fprintf(f, ", \\\n\tENV{%s}=\"%s\"", kv->key, kv->value); if (strstartswith(kv->key, "EVDEV_ABS_")) need_keyboard_builtin = true; kv++; } fprintf(f, "\n"); /* Special case: the udev keyboard builtin is only run for hwdb * matches but we don't set any up in litest. So instead scan the * device's udev properties for any EVDEV_ABS properties and where * they exist, force a (re-)run of the keyboard builtin to set up * the evdev device correctly. * This needs to be done as separate rule apparently, otherwise the * ENV variables aren't set yet by the time the builtin runs. */ if (need_keyboard_builtin) { fprintf(f, "" "ATTRS{name}==\"litest %s*\"," " IMPORT{builtin}=\"keyboard\"\n", dev->name); } fprintf(f, "LABEL=\"rule%d_end\"\n\n", count);; } static void litest_init_all_device_udev_rules(struct list *created_files) { struct created_file *file = zalloc(sizeof(*file)); struct litest_test_device *dev; char *path = NULL; FILE *f; int rc; int fd; rc = xasprintf(&path, "%s/99-litest-XXXXXX.rules", UDEV_RULES_D); litest_assert_errno_success(rc); fd = mkstemps(path, 6); litest_assert_errno_success(fd); f = fdopen(fd, "w"); litest_assert_notnull(f); list_for_each(dev, &devices, node) litest_init_device_udev_rules(dev, f); fclose(f); file->path = path; list_insert(created_files, &file->link); } static int open_restricted(const char *path, int flags, void *userdata) { const char prefix[] = "/dev/input/event"; struct litest_context *ctx = userdata; struct path *p; int fd; litest_assert_ptr_notnull(ctx); fd = open(path, flags); if (fd < 0) return -errno; if (strstartswith(path, prefix)) { p = zalloc(sizeof *p); p->path = safe_strdup(path); p->fd = fd; /* We specifically insert here so that the most-recently * opened path is the first one in the list. This helps when * we have multiple test devices with the same device path, * the fd of the most recent device is the first one to get * grabbed */ list_insert(&ctx->paths, &p->link); } return fd; } static void close_restricted(int fd, void *userdata) { struct litest_context *ctx = userdata; struct path *p; list_for_each_safe(p, &ctx->paths, link) { if (p->fd != fd) continue; list_remove(&p->link); free(p->path); free(p); } close(fd); } static struct libinput_interface interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static inline void quirk_log_handler(struct libinput *unused, enum libinput_log_priority priority, const char *format, va_list args) { if (priority < LIBINPUT_LOG_PRIORITY_ERROR) return; vfprintf(stderr, format, args); } static enum litest_runner_result init_quirks(void *userdata) { const char *data_path = getenv("LIBINPUT_QUIRKS_DIR"); if (!data_path) data_path = LIBINPUT_QUIRKS_DIR; quirks_context = quirks_init_subsystem(data_path, NULL, quirk_log_handler, NULL, QLOG_LIBINPUT_LOGGING); return LITEST_PASS; } static void teardown_quirks(void *userdata) { quirks_context_unref(quirks_context); } static int litest_run_suite(struct list *suites, int njobs) { size_t ntests = 0; enum litest_runner_result result = LITEST_SKIP; struct suite *s; struct litest_runner *runner = litest_runner_new(); litest_runner_set_num_parallel(runner, jobs > 0 ? jobs : 0); if (outfile) litest_runner_set_output_file(runner, outfile); litest_runner_set_verbose(runner, verbose); litest_runner_set_use_colors(runner, use_colors); litest_runner_set_timeout(runner, 30); litest_runner_set_exit_on_fail(runner, exit_first); litest_runner_set_setup_funcs(runner, init_quirks, teardown_quirks, NULL); list_for_each(s, suites, node) { struct test *t; list_for_each(t, &s->tests, node) { struct litest_runner_test_description tdesc = {0}; if (range_is_valid(&t->range)) { snprintf(tdesc.name, sizeof(tdesc.name), "%s:%s:%s:%d", s->name, t->name, t->devname, t->rangeval); } else if (t->params) { char buf[256] = {0}; struct litest_test_param *tp; bool is_first = true; list_for_each(tp, &t->params->test_params, link) { char *val = multivalue_as_str(&tp->value); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s%s:%s", is_first ? "" : ",", tp->name, val); free(val); is_first = false; } snprintf(tdesc.name, sizeof(tdesc.name), "%s:%s:%s:%s", s->name, t->name, t->devname, buf); } else { snprintf(tdesc.name, sizeof(tdesc.name), "%s:%s:%s", s->name, t->name, t->devname); } tdesc.func = t->func; tdesc.setup = t->setup; tdesc.teardown = t->teardown; tdesc.args.range = t->range; tdesc.rangeval = t->rangeval; tdesc.params = t->params; litest_runner_add_test(runner, &tdesc); ntests++; } } if (ntests > 0) result = litest_runner_run_tests(runner); litest_runner_destroy(runner); return result; } static inline int inhibit(void) { int lock_fd = -1; #if HAVE_LIBSYSTEMD sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_message *m = NULL; sd_bus *bus = NULL; int rc; if (run_deviceless) return -1; rc = sd_bus_open_system(&bus); if (rc != 0) { fprintf(stderr, "Warning: inhibit failed: %s\n", strerror(-rc)); goto out; } rc = sd_bus_call_method(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Inhibit", &error, &m, "ssss", "sleep:shutdown:handle-lid-switch:handle-power-key:handle-suspend-key:handle-hibernate-key", "libinput test-suite runner", "testing in progress", "block"); if (rc < 0) { fprintf(stderr, "Warning: inhibit failed: %s\n", error.message); goto out; } rc = sd_bus_message_read(m, "h", &lock_fd); if (rc < 0) { fprintf(stderr, "Warning: inhibit failed: %s\n", strerror(-rc)); goto out; } lock_fd = dup(lock_fd); out: sd_bus_error_free(&error); sd_bus_message_unref(m); sd_bus_close(bus); sd_bus_unref(bus); #endif return lock_fd; } static int disable_tty(void) { int tty_mode = -1; if (isatty(STDIN_FILENO) && ioctl(STDIN_FILENO, KDGKBMODE, &tty_mode) == 0) { #ifdef __linux__ ioctl(STDIN_FILENO, KDSKBMODE, K_OFF); #elif __FreeBSD__ ioctl(STDIN_FILENO, KDSKBMODE, K_RAW); /* Put the tty into raw mode */ struct termios tios; if (tcgetattr(STDIN_FILENO, &tios)) fprintf(stderr, "Failed to get terminal attribute: %d - %s\n", errno, strerror(errno)); cfmakeraw(&tios); if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios)) fprintf(stderr, "Failed to set terminal attribute: %d - %s\n", errno, strerror(errno)); #endif } return tty_mode; } static void restore_tty(int tty_mode) { if (tty_mode != -1) { ioctl(STDIN_FILENO, KDSKBMODE, tty_mode); #ifdef __FreeBSD__ /* Put the tty into "sane" mode */ struct termios tios; if (tcgetattr(STDIN_FILENO, &tios)) fprintf(stderr, "Failed to get terminal attribute: %d - %s\n", errno, strerror(errno)); cfmakesane(&tios); if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios)) fprintf(stderr, "Failed to set terminal attribute: %d - %s\n", errno, strerror(errno)); #endif } } static inline enum litest_runner_result litest_run(struct list *suites) { const struct rlimit corelimit = { 0, 0 }; int inhibit_lock_fd; int tty_mode = -1; setenv("LIBINPUT_RUNNING_TEST_SUITE", "1", 1); if (setrlimit(RLIMIT_CORE, &corelimit) != 0) perror("WARNING: Core dumps not disabled"); struct list created_files_list = LIST_INIT(created_files_list); if (run_deviceless) { litest_setup_quirks(&created_files_list, QUIRKS_SETUP_USE_SRCDIR); } else { enum quirks_setup_mode mode; litest_init_udev_rules(&created_files_list); mode = use_system_rules_quirks ? QUIRKS_SETUP_ONLY_DEVICE : QUIRKS_SETUP_FULL; litest_setup_quirks(&created_files_list, mode); } /* If we're running 'normally' on the VT, disable the keyboard to * avoid messing up our host. But if we're inside gdb or running * without forking, leave it as-is. */ if (!run_deviceless && jobs > 1 && !in_debugger) tty_mode = disable_tty(); inhibit_lock_fd = inhibit(); enum litest_runner_result result = litest_run_suite(suites, jobs); close(inhibit_lock_fd); restore_tty(tty_mode); litest_remove_udev_rules(&created_files_list); return result; } static struct input_absinfo * merge_absinfo(const struct input_absinfo *orig, const struct input_absinfo *override) { struct input_absinfo *abs; unsigned int nelem, i; size_t sz = ABS_MAX + 1; if (!orig) return NULL; abs = zalloc(sz * sizeof(*abs)); litest_assert_ptr_notnull(abs); nelem = 0; while (orig[nelem].value != -1) { abs[nelem] = orig[nelem]; nelem++; litest_assert_int_lt(nelem, sz); } /* just append, if the same axis is present twice, libevdev will only use the last value anyway */ i = 0; while (override && override[i].value != -1) { abs[nelem++] = override[i++]; litest_assert_int_lt(nelem, sz); } litest_assert_int_lt(nelem, sz); abs[nelem].value = -1; return abs; } static int* merge_events(const int *orig, const int *override) { int *events; unsigned int nelem, i; size_t sz = KEY_MAX * 3; if (!orig) return NULL; events = zalloc(sz * sizeof(int)); litest_assert_ptr_notnull(events); nelem = 0; while (orig[nelem] != -1) { events[nelem] = orig[nelem]; nelem++; litest_assert_int_lt(nelem, sz); } /* just append, if the same axis is present twice, libevdev will * ignore the double definition anyway */ i = 0; while (override && override[i] != -1) { events[nelem++] = override[i++]; litest_assert_int_le(nelem, sz); } litest_assert_int_lt(nelem, sz); events[nelem] = -1; return events; } static inline struct created_file * litest_copy_file(const char *dest, const char *src, const char *header, bool is_file) { int in, out, length; struct created_file *file; file = zalloc(sizeof(*file)); file->path = safe_strdup(dest); if (strstr(dest, "XXXXXX")) { int suffixlen; suffixlen = file->path + strlen(file->path) - rindex(file->path, '.'); out = mkstemps(file->path, suffixlen); } else { out = open(file->path, O_CREAT|O_WRONLY, 0644); } if (out == -1) litest_abort_msg("Failed to write to file %s (%s)", file->path, strerror(errno)); litest_assert_errno_success(chmod(file->path, 0644)); if (header) { length = strlen(header); litest_assert_int_eq(write(out, header, length), length); } if (is_file) { in = open(src, O_RDONLY); if (in == -1) litest_abort_msg("Failed to open file %s (%s)", src, strerror(errno)); /* lazy, just check for error and empty file copy */ litest_assert_int_gt(litest_send_file(out, in), 0); close(in); } else { size_t written = write(out, src, strlen(src)); litest_assert_int_eq(written, strlen(src)); } close(out); return file; } static inline void litest_install_model_quirks(struct list *created_files_list) { const char *warning = "#################################################################\n" "# WARNING: REMOVE THIS FILE\n" "# This is a run-time file for the libinput test suite and\n" "# should be removed on exit. If the test-suite is not currently \n" "# running, remove this file\n" "#################################################################\n\n"; struct created_file *file; const char *test_device_udev_rule = "KERNELS==\"*input*\", " "ATTRS{name}==\"litest *\", " "ENV{LIBINPUT_TEST_DEVICE}=\"1\""; file = litest_copy_file(UDEV_TEST_DEVICE_RULE_FILE, test_device_udev_rule, warning, false); list_insert(created_files_list, &file->link); /* Only install the litest device rule when we're running as system * test suite, we expect the others to be in place already */ if (use_system_rules_quirks) return; file = litest_copy_file(UDEV_DEVICE_GROUPS_FILE, LIBINPUT_DEVICE_GROUPS_RULES_FILE, warning, true); list_insert(created_files_list, &file->link); file = litest_copy_file(UDEV_FUZZ_OVERRIDE_RULE_FILE, LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE, warning, true); list_insert(created_files_list, &file->link); } static char * litest_init_device_quirk_file(const char *data_dir, struct litest_test_device *dev) { int fd; FILE *f; char path[PATH_MAX]; static int count; if (!dev->quirk_file) return NULL; snprintf(path, sizeof(path), "%s/99-%03d-%s.quirks", data_dir, ++count, dev->shortname); fd = open(path, O_CREAT|O_WRONLY, 0644); litest_assert_errno_success(fd); f = fdopen(fd, "w"); litest_assert_notnull(f); litest_assert_int_ge(fputs(dev->quirk_file, f), 0); fclose(f); return safe_strdup(path); } static int is_quirks_file(const struct dirent *dir) { return strendswith(dir->d_name, ".quirks"); } /** * Install the quirks from the quirks/ source directory. */ static void litest_install_source_quirks(struct list *created_files_list, const char *dirname) { struct dirent **namelist; int ndev; ndev = scandir(LIBINPUT_QUIRKS_SRCDIR, &namelist, is_quirks_file, versionsort); litest_assert_int_ge(ndev, 0); for (int idx = 0; idx < ndev; idx++) { struct created_file *file; char *filename; char dest[PATH_MAX]; char src[PATH_MAX]; filename = namelist[idx]->d_name; snprintf(src, sizeof(src), "%s/%s", LIBINPUT_QUIRKS_SRCDIR, filename); snprintf(dest, sizeof(dest), "%s/%s", dirname, filename); file = litest_copy_file(dest, src, NULL, true); list_append(created_files_list, &file->link); free(namelist[idx]); } free(namelist); } /** * Install the quirks from the various litest test devices */ static void litest_install_device_quirks(struct list *created_files_list, const char *dirname) { struct litest_test_device *dev; list_for_each(dev, &devices, node) { char *path; path = litest_init_device_quirk_file(dirname, dev); if (path) { struct created_file *file = zalloc(sizeof(*file)); file->path = path; list_insert(created_files_list, &file->link); } } } static void litest_setup_quirks(struct list *created_files_list, enum quirks_setup_mode mode) { struct created_file *file = NULL; const char *dirname; char tmpdir[] = "/run/litest-XXXXXX"; switch (mode) { case QUIRKS_SETUP_USE_SRCDIR: dirname = LIBINPUT_QUIRKS_SRCDIR; break; case QUIRKS_SETUP_ONLY_DEVICE: dirname = LIBINPUT_QUIRKS_DIR; litest_install_device_quirks(created_files_list, dirname); break; case QUIRKS_SETUP_FULL: litest_assert_notnull(mkdtemp(tmpdir)); litest_assert_errno_success(chmod(tmpdir, 0755)); file = zalloc(sizeof *file); file->path = safe_strdup(tmpdir); dirname = tmpdir; litest_install_source_quirks(created_files_list, dirname); litest_install_device_quirks(created_files_list, dirname); list_append(created_files_list, &file->link); break; } setenv("LIBINPUT_QUIRKS_DIR", dirname, 1); } static inline void litest_init_udev_rules(struct list *created_files) { litest_assert_neg_errno_success(mkdir_p(UDEV_RULES_D)); litest_install_model_quirks(created_files); litest_init_all_device_udev_rules(created_files); litest_reload_udev_rules(); } static inline void litest_remove_udev_rules(struct list *created_files_list) { struct created_file *f; bool reload_udev; reload_udev = !list_empty(created_files_list); list_for_each_safe(f, created_files_list, link) { created_file_unlink(f); created_file_destroy(f); } if (reload_udev) litest_reload_udev_rules(); } /** * Creates a uinput device but does not add it to a libinput context */ struct litest_device * litest_create(enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override) { struct litest_device *d = NULL; struct litest_test_device *dev; const char *name; const struct input_id *id; struct input_absinfo *abs; int *events, *e; const char *path; int fd, rc; bool found = false; bool create_device = true; list_for_each(dev, &devices, node) { if (dev->type == which) { found = true; break; } } if (!found) litest_abort_msg("Invalid device type %d", which); d = zalloc(sizeof(*d)); d->which = which; /* device has custom create method */ if (dev->create) { create_device = dev->create(d); if (abs_override || events_override) { litest_abort_msg("Custom create cannot be overridden"); } } abs = merge_absinfo(dev->absinfo, abs_override); events = merge_events(dev->events, events_override); name = name_override ? name_override : dev->name; id = id_override ? id_override : dev->id; if (create_device) { d->uinput = litest_create_uinput_device_from_description(name, id, abs, events); d->interface = dev->interface; for (e = events; *e != -1; e += 2) { unsigned int type = *e, code = *(e + 1); if (type == INPUT_PROP_MAX && code == INPUT_PROP_SEMI_MT) { d->semi_mt.is_semi_mt = true; break; } } } free(abs); free(events); path = libevdev_uinput_get_devnode(d->uinput); litest_assert_ptr_notnull(path); fd = open(path, O_RDWR|O_NONBLOCK); litest_assert_errno_success(fd); rc = libevdev_new_from_fd(fd, &d->evdev); litest_assert_neg_errno_success(rc); return d; } struct libinput * litest_create_context(void) { struct libinput *libinput; struct litest_context *ctx; ctx = zalloc(sizeof *ctx); list_init(&ctx->paths); libinput = libinput_path_create_context(&interface, ctx); litest_assert_notnull(libinput); libinput_log_set_handler(libinput, litest_log_handler); if (verbose) libinput_log_set_priority(libinput, LIBINPUT_LOG_PRIORITY_DEBUG); return libinput; } void litest_destroy_context(struct libinput *li) { struct path *p; struct litest_context *ctx; ctx = libinput_get_user_data(li); litest_assert_ptr_notnull(ctx); libinput_unref(li); list_for_each_safe(p, &ctx->paths, link) { litest_abort_msg("Device paths should be removed by now"); } free(ctx); } void litest_disable_log_handler(struct libinput *libinput) { libinput_log_set_handler(libinput, NULL); } void litest_restore_log_handler(struct libinput *libinput) { libinput_log_set_handler(libinput, litest_log_handler); if (verbose) libinput_log_set_priority(libinput, LIBINPUT_LOG_PRIORITY_DEBUG); } LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void litest_bug_log_handler(struct libinput *libinput, enum libinput_log_priority pri, const char *format, va_list args) { if (strstr(format, "client bug: ") || strstr(format, "libinput bug: ") || strstr(format, "kernel bug: ")) return; litest_abort_msg("Expected bug statement in log msg, aborting."); } void litest_set_log_handler_bug(struct libinput *libinput) { libinput_log_set_handler(libinput, litest_bug_log_handler); } struct litest_device * litest_add_device_with_overrides(struct libinput *libinput, enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override) { struct udev_device *ud; struct litest_device *d; const char *path; d = litest_create(which, name_override, id_override, abs_override, events_override); path = libevdev_uinput_get_devnode(d->uinput); litest_assert_ptr_notnull(path); d->libinput = libinput; d->libinput_device = libinput_path_add_device(d->libinput, path); litest_assert_ptr_notnull(d->libinput_device); ud = libinput_device_get_udev_device(d->libinput_device); d->quirks = quirks_fetch_for_device(quirks_context, ud); udev_device_unref(ud); libinput_device_ref(d->libinput_device); if (d->interface) { unsigned int code; code = ABS_X; if (!libevdev_has_event_code(d->evdev, EV_ABS, code)) code = ABS_MT_POSITION_X; if (libevdev_has_event_code(d->evdev, EV_ABS, code)) { d->interface->min[ABS_X] = libevdev_get_abs_minimum(d->evdev, code); d->interface->max[ABS_X] = libevdev_get_abs_maximum(d->evdev, code); } code = ABS_Y; if (!libevdev_has_event_code(d->evdev, EV_ABS, code)) code = ABS_MT_POSITION_Y; if (libevdev_has_event_code(d->evdev, EV_ABS, code)) { d->interface->min[ABS_Y] = libevdev_get_abs_minimum(d->evdev, code); d->interface->max[ABS_Y] = libevdev_get_abs_maximum(d->evdev, code); } d->interface->tool_type = BTN_TOOL_PEN; } return d; } struct litest_device * litest_add_device(struct libinput *libinput, enum litest_device_type which) { return litest_add_device_with_overrides(libinput, which, NULL, NULL, NULL, NULL); } struct litest_device * litest_create_device_with_overrides(enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override) { struct litest_device *dev = litest_add_device_with_overrides(litest_create_context(), which, name_override, id_override, abs_override, events_override); dev->owns_context = true; return dev; } struct litest_device * litest_create_device(enum litest_device_type which) { return litest_create_device_with_overrides(which, NULL, NULL, NULL, NULL); } static struct udev_monitor * udev_setup_monitor(void) { struct udev *udev; struct udev_monitor *udev_monitor; int rc; udev = udev_new(); litest_assert_notnull(udev); udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); litest_assert_notnull(udev_monitor); udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL); /* remove O_NONBLOCK */ rc = fcntl(udev_monitor_get_fd(udev_monitor), F_SETFL, 0); litest_assert_errno_success(rc); litest_assert_int_eq(udev_monitor_enable_receiving(udev_monitor), 0); udev_unref(udev); return udev_monitor; } static struct udev_device * udev_wait_for_device_event(struct udev_monitor *udev_monitor, const char *udev_event, const char *syspath) { struct udev_device *udev_device = NULL; /* blocking, we don't want to continue until udev is ready */ while (1) { const char *udev_syspath = NULL; const char *udev_action; udev_device = udev_monitor_receive_device(udev_monitor); litest_assert_notnull(udev_device); udev_action = udev_device_get_action(udev_device); if (!udev_action || !streq(udev_action, udev_event)) { udev_device_unref(udev_device); continue; } udev_syspath = udev_device_get_syspath(udev_device); if (strstartswith(udev_syspath, syspath)) break; udev_device_unref(udev_device); } return udev_device; } void litest_delete_device(struct litest_device *d) { struct udev_monitor *udev_monitor; struct udev_device *udev_device; char path[PATH_MAX]; if (!d) return; udev_monitor = udev_setup_monitor(); snprintf(path, sizeof(path), "%s/event", libevdev_uinput_get_syspath(d->uinput)); litest_assert_int_eq(d->skip_ev_syn, 0); quirks_unref(d->quirks); if (d->libinput_device) { libinput_path_remove_device(d->libinput_device); libinput_device_unref(d->libinput_device); } if (d->owns_context) { libinput_dispatch(d->libinput); litest_destroy_context(d->libinput); } close(libevdev_get_fd(d->evdev)); libevdev_free(d->evdev); libevdev_uinput_destroy(d->uinput); free(d->private); memset(d,0, sizeof(*d)); free(d); udev_device = udev_wait_for_device_event(udev_monitor, "remove", path); udev_device_unref(udev_device); udev_monitor_unref(udev_monitor); } void litest_event(struct litest_device *d, unsigned int type, unsigned int code, int value) { int ret; if (!libevdev_has_event_code(d->evdev, type, code)) return; if (d->skip_ev_syn && type == EV_SYN && code == SYN_REPORT) return; ret = libevdev_uinput_write_event(d->uinput, type, code, value); litest_assert_neg_errno_success(ret); } static bool axis_replacement_value(struct litest_device *d, struct axis_replacement *axes, int32_t evcode, int32_t *value) { struct axis_replacement *axis = axes; if (!axes) return false; while (axis->evcode != -1) { if (axis->evcode == evcode) { switch (evcode) { case ABS_MT_SLOT: case ABS_MT_TRACKING_ID: case ABS_MT_TOOL_TYPE: *value = axis->value; break; default: *value = litest_scale(d, evcode, axis->value); break; } return true; } axis++; } return false; } int litest_auto_assign_value(struct litest_device *d, const struct input_event *ev, int slot, double x, double y, struct axis_replacement *axes, bool touching) { static int tracking_id; int value = ev->value; if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS) return value; switch (ev->code) { case ABS_X: case ABS_MT_POSITION_X: value = litest_scale(d, ABS_X, x); break; case ABS_Y: case ABS_MT_POSITION_Y: value = litest_scale(d, ABS_Y, y); break; case ABS_MT_TRACKING_ID: value = ++tracking_id; break; case ABS_MT_SLOT: value = slot; break; case ABS_MT_DISTANCE: value = touching ? 0 : 1; break; case ABS_MT_TOOL_TYPE: if (!axis_replacement_value(d, axes, ev->code, &value)) value = MT_TOOL_FINGER; break; default: if (!axis_replacement_value(d, axes, ev->code, &value) && d->interface->get_axis_default) { int error = d->interface->get_axis_default(d, ev->code, &value); if (error) { litest_abort_msg("Failed to get default axis value for %s (%d)", libevdev_event_code_get_name(EV_ABS, ev->code), ev->code); } } break; } return value; } static void send_btntool(struct litest_device *d, bool hover) { litest_event(d, EV_KEY, BTN_TOUCH, d->ntouches_down != 0 && !hover); litest_event(d, EV_KEY, BTN_TOOL_FINGER, d->ntouches_down == 1); litest_event(d, EV_KEY, BTN_TOOL_DOUBLETAP, d->ntouches_down == 2); litest_event(d, EV_KEY, BTN_TOOL_TRIPLETAP, d->ntouches_down == 3); litest_event(d, EV_KEY, BTN_TOOL_QUADTAP, d->ntouches_down == 4); litest_event(d, EV_KEY, BTN_TOOL_QUINTTAP, d->ntouches_down == 5); } static void slot_start(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes, bool touching, bool filter_abs_xy) { struct input_event *ev; litest_assert_int_ge(d->ntouches_down, 0); d->ntouches_down++; send_btntool(d, !touching); /* If the test device overrides touch_down and says it didn't * handle the event, let's continue normally */ if (d->interface->touch_down && d->interface->touch_down(d, slot, x, y)) return; for (ev = d->interface->touch_down_events; ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1; ev++) { int value = litest_auto_assign_value(d, ev, slot, x, y, axes, touching); if (value == LITEST_AUTO_ASSIGN) continue; if (filter_abs_xy && ev->type == EV_ABS && (ev->code == ABS_X || ev->code == ABS_Y)) continue; litest_event(d, ev->type, ev->code, value); } } static void slot_move(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes, bool touching, bool filter_abs_xy) { struct input_event *ev; if (d->interface->touch_move && d->interface->touch_move(d, slot, x, y)) return; for (ev = d->interface->touch_move_events; ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1; ev++) { int value = litest_auto_assign_value(d, ev, slot, x, y, axes, touching); if (value == LITEST_AUTO_ASSIGN) continue; if (filter_abs_xy && ev->type == EV_ABS && (ev->code == ABS_X || ev->code == ABS_Y)) continue; litest_event(d, ev->type, ev->code, value); } } static void touch_up(struct litest_device *d, unsigned int slot) { struct input_event *ev; struct input_event up[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 }, { .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MAJOR, .value = 0 }, { .type = EV_ABS, .code = ABS_MT_TOUCH_MINOR, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 } }; litest_assert_int_gt(d->ntouches_down, 0); d->ntouches_down--; send_btntool(d, false); if (d->interface->touch_up && d->interface->touch_up(d, slot)) { return; } else if (d->interface->touch_up_events) { ev = d->interface->touch_up_events; } else ev = up; for ( /* */; ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1; ev++) { int value = litest_auto_assign_value(d, ev, slot, 0, 0, NULL, false); litest_event(d, ev->type, ev->code, value); } } static void litest_slot_start(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes, bool touching) { double t, l, r = 0, b = 0; /* top, left, right, bottom */ bool filter_abs_xy = false; if (!d->semi_mt.is_semi_mt) { slot_start(d, slot, x, y, axes, touching, filter_abs_xy); return; } if (d->ntouches_down >= 2 || slot > 1) return; slot = d->ntouches_down; if (d->ntouches_down == 0) { l = x; t = y; } else { int other = (slot + 1) % 2; l = min(x, d->semi_mt.touches[other].x); t = min(y, d->semi_mt.touches[other].y); r = max(x, d->semi_mt.touches[other].x); b = max(y, d->semi_mt.touches[other].y); } litest_push_event_frame(d); if (d->ntouches_down == 0) slot_start(d, 0, l, t, axes, touching, filter_abs_xy); else slot_move(d, 0, l, t, axes, touching, filter_abs_xy); if (slot == 1) { filter_abs_xy = true; slot_start(d, 1, r, b, axes, touching, filter_abs_xy); } litest_pop_event_frame(d); d->semi_mt.touches[slot].x = x; d->semi_mt.touches[slot].y = y; } void litest_touch_sequence(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, int steps) { litest_touch_down(d, slot, x_from, y_from); litest_touch_move_to(d, slot, x_from, y_from, x_to, y_to, steps); litest_touch_up(d, slot); } void litest_touch_down(struct litest_device *d, unsigned int slot, double x, double y) { litest_slot_start(d, slot, x, y, NULL, true); } void litest_touch_down_extended(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes) { litest_slot_start(d, slot, x, y, axes, true); } static void litest_slot_move(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes, bool touching) { double t, l, r = 0, b = 0; /* top, left, right, bottom */ bool filter_abs_xy = false; if (!d->semi_mt.is_semi_mt) { slot_move(d, slot, x, y, axes, touching, filter_abs_xy); return; } if (d->ntouches_down > 2 || slot > 1) return; if (d->ntouches_down == 1) { l = x; t = y; } else { int other = (slot + 1) % 2; l = min(x, d->semi_mt.touches[other].x); t = min(y, d->semi_mt.touches[other].y); r = max(x, d->semi_mt.touches[other].x); b = max(y, d->semi_mt.touches[other].y); } litest_push_event_frame(d); slot_move(d, 0, l, t, axes, touching, filter_abs_xy); if (d->ntouches_down == 2) { filter_abs_xy = true; slot_move(d, 1, r, b, axes, touching, filter_abs_xy); } litest_pop_event_frame(d); d->semi_mt.touches[slot].x = x; d->semi_mt.touches[slot].y = y; } void litest_touch_up(struct litest_device *d, unsigned int slot) { if (!d->semi_mt.is_semi_mt) { touch_up(d, slot); return; } if (d->ntouches_down > 2 || slot > 1) return; litest_push_event_frame(d); touch_up(d, d->ntouches_down - 1); /* if we have one finger left, send x/y coords for that finger left. this is likely to happen with a real touchpad */ if (d->ntouches_down == 1) { bool touching = true; bool filter_abs_xy = false; int other = (slot + 1) % 2; slot_move(d, 0, d->semi_mt.touches[other].x, d->semi_mt.touches[other].y, NULL, touching, filter_abs_xy); } litest_pop_event_frame(d); } void litest_touch_move(struct litest_device *d, unsigned int slot, double x, double y) { litest_slot_move(d, slot, x, y, NULL, true); } void litest_touch_move_extended(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes) { litest_slot_move(d, slot, x, y, axes, true); } void litest_touch_move_to(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, int steps) { litest_touch_move_to_extended(d, slot, x_from, y_from, x_to, y_to, NULL, steps); } void litest_touch_move_to_extended(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, struct axis_replacement *axes, int steps) { int sleep_ms = 10; for (int i = 1; i < steps; i++) { litest_touch_move_extended(d, slot, x_from + (x_to - x_from)/steps * i, y_from + (y_to - y_from)/steps * i, axes); libinput_dispatch(d->libinput); msleep(sleep_ms); libinput_dispatch(d->libinput); } litest_touch_move_extended(d, slot, x_to, y_to, axes); } static int auto_assign_tablet_value(struct litest_device *d, const struct input_event *ev, int x, int y, struct axis_replacement *axes) { static int tracking_id; int value = ev->value; if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS) return value; switch (ev->code) { case ABS_MT_TRACKING_ID: value = ++tracking_id; break; case ABS_X: case ABS_MT_POSITION_X: value = litest_scale(d, ABS_X, x); break; case ABS_Y: case ABS_MT_POSITION_Y: value = litest_scale(d, ABS_Y, y); break; default: if (!axis_replacement_value(d, axes, ev->code, &value) && d->interface->get_axis_default) { int error = d->interface->get_axis_default(d, ev->code, &value); if (error) { litest_abort_msg("Failed to get default axis value for %s (%d)", libevdev_event_code_get_name(EV_ABS, ev->code), ev->code); } } break; } return value; } static int tablet_ignore_event(const struct input_event *ev, int value) { return value == -1 && (ev->code == ABS_PRESSURE || ev->code == ABS_DISTANCE); } void litest_tablet_set_tool_type(struct litest_device *d, unsigned int code) { switch (code) { case BTN_TOOL_PEN: case BTN_TOOL_RUBBER: case BTN_TOOL_BRUSH: case BTN_TOOL_PENCIL: case BTN_TOOL_AIRBRUSH: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: break; default: abort(); } d->interface->tool_type = code; } static void litest_tool_event(struct litest_device *d, int value) { unsigned int tool = d->interface->tool_type; litest_event(d, EV_KEY, tool, value); } void litest_tablet_proximity_in(struct litest_device *d, double x, double y, struct axis_replacement *axes) { struct input_event *ev; /* If the test device overrides proximity_in and says it didn't * handle the event, let's continue normally */ if (d->interface->tablet_proximity_in && d->interface->tablet_proximity_in(d, d->interface->tool_type, &x, &y, axes)) return; ev = d->interface->tablet_proximity_in_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { int value; switch (evbit(ev->type, ev->code)) { case evbit(EV_KEY, LITEST_BTN_TOOL_AUTO): litest_tool_event(d, ev->value); break; default: value = auto_assign_tablet_value(d, ev, x, y, axes); if (!tablet_ignore_event(ev, value)) litest_event(d, ev->type, ev->code, value); } ev++; } } void litest_tablet_proximity_out(struct litest_device *d) { struct input_event *ev; /* If the test device overrides proximity_out and says it didn't * handle the event, let's continue normally */ if (d->interface->tablet_proximity_out && d->interface->tablet_proximity_out(d, d->interface->tool_type)) return; ev = d->interface->tablet_proximity_out_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { int value; switch (evbit(ev->type, ev->code)) { case evbit(EV_KEY, LITEST_BTN_TOOL_AUTO): litest_tool_event(d, ev->value); break; default: value = auto_assign_tablet_value(d, ev, -1, -1, NULL); if (!tablet_ignore_event(ev, value)) litest_event(d, ev->type, ev->code, value); break; } ev++; } } void litest_tablet_motion(struct litest_device *d, double x, double y, struct axis_replacement *axes) { struct input_event *ev; /* If the test device overrides proximity_out and says it didn't * handle the event, let's continue normally */ if (d->interface->tablet_motion && d->interface->tablet_motion(d, &x, &y, axes)) return; ev = d->interface->tablet_motion_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { int value = auto_assign_tablet_value(d, ev, x, y, axes); if (!tablet_ignore_event(ev, value)) litest_event(d, ev->type, ev->code, value); ev++; } } void litest_tablet_tip_down(struct litest_device *d, double x, double y, struct axis_replacement *axes) { /* If the test device overrides tip_down and says it didn't * handle the event, let's continue normally */ if (d->interface->tablet_tip_down && d->interface->tablet_tip_down(d, &x, &y, axes)) return; litest_event(d, EV_KEY, BTN_TOUCH, 1); litest_tablet_motion(d, x, y, axes); } void litest_tablet_tip_up(struct litest_device *d, double x, double y, struct axis_replacement *axes) { /* If the test device overrides tip_down and says it didn't * handle the event, let's continue normally */ if (d->interface->tablet_tip_up && d->interface->tablet_tip_up(d, &x, &y, axes)) return; litest_event(d, EV_KEY, BTN_TOUCH, 0); litest_tablet_motion(d, x, y, axes); } void litest_touch_move_two_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double dx, double dy, int steps) { int sleep_ms = 10; for (int i = 1; i < steps; i++) { litest_push_event_frame(d); litest_touch_move(d, 0, x0 + dx / steps * i, y0 + dy / steps * i); litest_touch_move(d, 1, x1 + dx / steps * i, y1 + dy / steps * i); litest_pop_event_frame(d); libinput_dispatch(d->libinput); msleep(sleep_ms); libinput_dispatch(d->libinput); } litest_push_event_frame(d); litest_touch_move(d, 0, x0 + dx, y0 + dy); litest_touch_move(d, 1, x1 + dx, y1 + dy); litest_pop_event_frame(d); } void litest_touch_move_three_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double x2, double y2, double dx, double dy, int steps) { int sleep_ms = 10; for (int i = 1; i <= steps; i++) { double step_x = dx / steps * i; double step_y = dy / steps * i; litest_push_event_frame(d); litest_touch_move(d, 0, x0 + step_x, y0 + step_y); litest_touch_move(d, 1, x1 + step_x, y1 + step_y); litest_touch_move(d, 2, x2 + step_x, y2 + step_y); litest_pop_event_frame(d); libinput_dispatch(d->libinput); msleep(sleep_ms); } libinput_dispatch(d->libinput); } void litest_hover_start(struct litest_device *d, unsigned int slot, double x, double y) { struct axis_replacement axes[] = { {ABS_MT_PRESSURE, 0 }, {ABS_PRESSURE, 0 }, {-1, -1 }, }; litest_slot_start(d, slot, x, y, axes, 0); } void litest_hover_end(struct litest_device *d, unsigned int slot) { struct input_event *ev; struct input_event up[] = { { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_DISTANCE, .value = 1 }, { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 } }; litest_assert_int_gt(d->ntouches_down, 0); d->ntouches_down--; send_btntool(d, true); if (d->interface->touch_up) { d->interface->touch_up(d, slot); return; } else if (d->interface->touch_up_events) { ev = d->interface->touch_up_events; } else ev = up; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { int value = litest_auto_assign_value(d, ev, slot, 0, 0, NULL, false); litest_event(d, ev->type, ev->code, value); ev++; } } void litest_hover_move(struct litest_device *d, unsigned int slot, double x, double y) { struct axis_replacement axes[] = { {ABS_MT_PRESSURE, 0 }, {ABS_PRESSURE, 0 }, {-1, -1 }, }; litest_slot_move(d, slot, x, y, axes, false); } void litest_hover_move_to(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, int steps) { int sleep_ms = 10; for (int i = 0; i < steps - 1; i++) { litest_hover_move(d, slot, x_from + (x_to - x_from)/steps * i, y_from + (y_to - y_from)/steps * i); libinput_dispatch(d->libinput); msleep(sleep_ms); libinput_dispatch(d->libinput); } litest_hover_move(d, slot, x_to, y_to); } void litest_hover_move_two_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double dx, double dy, int steps) { int sleep_ms = 10; for (int i = 0; i < steps - 1; i++) { litest_push_event_frame(d); litest_hover_move(d, 0, x0 + dx / steps * i, y0 + dy / steps * i); litest_hover_move(d, 1, x1 + dx / steps * i, y1 + dy / steps * i); litest_pop_event_frame(d); libinput_dispatch(d->libinput); msleep(sleep_ms); libinput_dispatch(d->libinput); } litest_push_event_frame(d); litest_hover_move(d, 0, x0 + dx, y0 + dy); litest_hover_move(d, 1, x1 + dx, y1 + dy); litest_pop_event_frame(d); } void litest_button_click(struct litest_device *d, unsigned int button, bool is_press) { struct input_event click[] = { { .type = EV_KEY, .code = button, .value = is_press ? 1 : 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, }; ARRAY_FOR_EACH(click, ev) litest_event(d, ev->type, ev->code, ev->value); } void litest_button_click_debounced(struct litest_device *d, struct libinput *li, unsigned int button, bool is_press) { litest_button_click(d, button, is_press); libinput_dispatch(li); litest_timeout_debounce(); libinput_dispatch(li); } void litest_button_scroll(struct litest_device *dev, unsigned int button, double dx, double dy) { struct libinput *li = dev->libinput; litest_button_click_debounced(dev, li, button, 1); libinput_dispatch(li); litest_timeout_buttonscroll(); libinput_dispatch(li); litest_event(dev, EV_REL, REL_X, dx); litest_event(dev, EV_REL, REL_Y, dy); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_button_click_debounced(dev, li, button, 0); libinput_dispatch(li); } void litest_button_scroll_locked(struct litest_device *dev, unsigned int button, double dx, double dy) { struct libinput *li = dev->libinput; litest_button_click_debounced(dev, li, button, 1); litest_button_click_debounced(dev, li, button, 0); libinput_dispatch(li); litest_timeout_buttonscroll(); libinput_dispatch(li); litest_event(dev, EV_REL, REL_X, dx); litest_event(dev, EV_REL, REL_Y, dy); litest_event(dev, EV_SYN, SYN_REPORT, 0); libinput_dispatch(li); } void litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) { struct input_event click[] = { { .type = EV_KEY, .code = key, .value = is_press ? 1 : 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, }; ARRAY_FOR_EACH(click, ev) litest_event(d, ev->type, ev->code, ev->value); } void litest_switch_action(struct litest_device *dev, enum libinput_switch sw, enum libinput_switch_state state) { unsigned int code; switch (sw) { case LIBINPUT_SWITCH_LID: code = SW_LID; break; case LIBINPUT_SWITCH_TABLET_MODE: code = SW_TABLET_MODE; break; default: litest_abort_msg("Invalid switch %d", sw); break; } litest_event(dev, EV_SW, code, state); litest_event(dev, EV_SYN, SYN_REPORT, 0); } static int litest_scale_axis(const struct litest_device *d, unsigned int axis, double val) { const struct input_absinfo *abs; litest_assert_double_ge(val, 0.0); /* major/minor must be able to beyond 100% for large fingers */ if (axis != ABS_MT_TOUCH_MAJOR && axis != ABS_MT_TOUCH_MINOR) { litest_assert_double_le(val, 100.0); } abs = libevdev_get_abs_info(d->evdev, axis); litest_assert_notnull(abs); return (abs->maximum - abs->minimum) * val/100.0 + abs->minimum; } static inline int litest_scale_range(int min, int max, double val) { litest_assert_int_ge((int)val, 0); litest_assert_int_le((int)val, 100); return (max - min) * val/100.0 + min; } int litest_scale(const struct litest_device *d, unsigned int axis, double val) { int min, max; litest_assert_double_ge(val, 0.0); /* major/minor must be able to beyond 100% for large fingers */ if (axis != ABS_MT_TOUCH_MAJOR && axis != ABS_MT_TOUCH_MINOR) litest_assert_double_le(val, 100.0); if (axis <= ABS_Y) { min = d->interface->min[axis]; max = d->interface->max[axis]; return litest_scale_range(min, max, val); } else { return litest_scale_axis(d, axis, val); } } static inline int auto_assign_pad_value(struct litest_device *dev, struct input_event *ev, double value) { const struct input_absinfo *abs; if (ev->value != LITEST_AUTO_ASSIGN) return value; if (ev->type == EV_REL) { switch (ev->code) { case REL_WHEEL: case REL_HWHEEL: case REL_DIAL: assert (fmod(value, 120.0) == 0.0); /* Fractions not supported yet */ return value/120.0; default: return value; } } else if (ev->type != EV_ABS) { return value; } abs = libevdev_get_abs_info(dev->evdev, ev->code); litest_assert_notnull(abs); if (ev->code == ABS_RX || ev->code == ABS_RY) { double min = abs->minimum != 0 ? log2(abs->minimum) : 0, max = abs->maximum != 0 ? log2(abs->maximum) : 0; /* Value 0 is reserved for finger up, so a value of 0% is * actually 1 */ if (value == 0.0) { return 1; } else { value = litest_scale_range(min, max, value); return pow(2, value); } } else { return litest_scale_range(abs->minimum, abs->maximum, value); } } void litest_pad_ring_start(struct litest_device *d, double value) { struct input_event *ev; ev = d->interface->pad_ring_start_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { value = auto_assign_pad_value(d, ev, value); litest_event(d, ev->type, ev->code, value); ev++; } } void litest_pad_ring_change(struct litest_device *d, double value) { struct input_event *ev; ev = d->interface->pad_ring_change_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { value = auto_assign_pad_value(d, ev, value); litest_event(d, ev->type, ev->code, value); ev++; } } void litest_pad_ring_end(struct litest_device *d) { struct input_event *ev; ev = d->interface->pad_ring_end_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { litest_event(d, ev->type, ev->code, ev->value); ev++; } } void litest_pad_strip_start(struct litest_device *d, double value) { struct input_event *ev; ev = d->interface->pad_strip_start_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { value = auto_assign_pad_value(d, ev, value); litest_event(d, ev->type, ev->code, value); ev++; } } void litest_pad_strip_change(struct litest_device *d, double value) { struct input_event *ev; ev = d->interface->pad_strip_change_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { value = auto_assign_pad_value(d, ev, value); litest_event(d, ev->type, ev->code, value); ev++; } } void litest_pad_strip_end(struct litest_device *d) { struct input_event *ev; ev = d->interface->pad_strip_end_events; while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { litest_event(d, ev->type, ev->code, ev->value); ev++; } } void litest_wait_for_event(struct libinput *li) { return litest_wait_for_event_of_type(li, -1); } void _litest_wait_for_event_of_type(struct libinput *li, const char *func, int lineno, ...) { va_list args; enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE}; size_t ntypes = 0; enum libinput_event_type type; struct pollfd fds; va_start(args, lineno); type = va_arg(args, int); while ((int)type != -1) { litest_assert_int_gt(type, 0U); litest_assert_int_lt(ntypes, ARRAY_LENGTH(types)); types[ntypes++] = type; type = va_arg(args, int); } va_end(args); fds.fd = libinput_get_fd(li); fds.events = POLLIN; fds.revents = 0; while (1) { size_t i; struct libinput_event *event; while ((type = libinput_next_event_type(li)) == LIBINPUT_EVENT_NONE) { int rc = poll(&fds, 1, 2000); litest_assert_errno_success(rc); litest_assert_int_gt(rc, 0); libinput_dispatch(li); } /* no event mask means wait for any event */ if (ntypes == 0) return; for (i = 0; i < ntypes; i++) { if (type == types[i]) return; } event = libinput_get_event(li); if (verbose) { litest_print_event(event, "Discarding event while waiting: "); } libinput_event_destroy(event); } } void litest_drain_events(struct libinput *li) { struct libinput_event *event; libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (verbose) { litest_print_event(event, "litest: draining event: "); } libinput_event_destroy(event); libinput_dispatch(li); } } void _litest_drain_events_of_type(struct libinput *li, ...) { enum libinput_event_type type; enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE}; size_t ntypes = 0; va_list args; va_start(args, li); type = va_arg(args, int); while ((int)type != -1) { litest_assert_int_gt(type, 0U); litest_assert_int_lt(ntypes, ARRAY_LENGTH(types)); types[ntypes++] = type; type = va_arg(args, int); } va_end(args); libinput_dispatch(li); type = libinput_next_event_type(li); while (type != LIBINPUT_EVENT_NONE) { struct libinput_event *event; bool found = false; type = libinput_next_event_type(li); for (size_t i = 0; i < ntypes; i++) { if (type == types[i]) { found = true; break; } } if (!found) return; event = libinput_get_event(li); libinput_event_destroy(event); libinput_dispatch(li); } } const char * litest_event_type_str(enum libinput_event_type type) { const char *str = NULL; switch (type) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: str = "ADDED"; break; case LIBINPUT_EVENT_DEVICE_REMOVED: str = "REMOVED"; break; case LIBINPUT_EVENT_KEYBOARD_KEY: str = "KEY"; break; case LIBINPUT_EVENT_POINTER_MOTION: str = "MOTION"; break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: str = "ABSOLUTE"; break; case LIBINPUT_EVENT_POINTER_BUTTON: str = "BUTTON"; break; case LIBINPUT_EVENT_POINTER_AXIS: str = "AXIS"; break; case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: str = "SCROLL_WHEEL"; break; case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: str = "SCROLL_FINGER"; break; case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: str = "SCROLL_CONTINUOUS"; break; case LIBINPUT_EVENT_TOUCH_DOWN: str = "TOUCH DOWN"; break; case LIBINPUT_EVENT_TOUCH_UP: str = "TOUCH UP"; break; case LIBINPUT_EVENT_TOUCH_MOTION: str = "TOUCH MOTION"; break; case LIBINPUT_EVENT_TOUCH_CANCEL: str = "TOUCH CANCEL"; break; case LIBINPUT_EVENT_TOUCH_FRAME: str = "TOUCH FRAME"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: str = "GESTURE SWIPE BEGIN"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: str = "GESTURE SWIPE UPDATE"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_END: str = "GESTURE SWIPE END"; break; case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: str = "GESTURE PINCH BEGIN"; break; case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: str = "GESTURE PINCH UPDATE"; break; case LIBINPUT_EVENT_GESTURE_PINCH_END: str = "GESTURE PINCH END"; break; case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: str = "GESTURE HOLD BEGIN"; break; case LIBINPUT_EVENT_GESTURE_HOLD_END: str = "GESTURE HOLD END"; break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: str = "TABLET TOOL AXIS"; break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: str = "TABLET TOOL PROX"; break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: str = "TABLET TOOL TIP"; break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: str = "TABLET TOOL BUTTON"; break; case LIBINPUT_EVENT_TABLET_PAD_BUTTON: str = "TABLET PAD BUTTON"; break; case LIBINPUT_EVENT_TABLET_PAD_RING: str = "TABLET PAD RING"; break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: str = "TABLET PAD STRIP"; break; case LIBINPUT_EVENT_TABLET_PAD_KEY: str = "TABLET PAD KEY"; break; case LIBINPUT_EVENT_TABLET_PAD_DIAL: str = "TABLET PAD DIAL"; break; case LIBINPUT_EVENT_SWITCH_TOGGLE: str = "SWITCH TOGGLE"; break; } return str; } static const char * litest_event_get_type_str(struct libinput_event *event) { return litest_event_type_str(libinput_event_get_type(event)); } static void litest_print_event(struct libinput_event *event, const char *message) { char *event_str = libinput_event_to_str(event, 0, NULL); fprintf(stderr, "litest: %s %s\n", message, event_str); free(event_str); } void _litest_assert_event_type_is_one_of(struct libinput_event *event, const char *func, int lineno, ...) { va_list args; enum libinput_event_type expected_type; enum libinput_event_type actual_type = libinput_event_get_type(event); bool match = false; va_start(args, lineno); expected_type = va_arg(args, int); while ((int)expected_type != -1 && !match) { match = (actual_type == expected_type); expected_type = va_arg(args, int); } va_end(args); if (match) return; fprintf(stderr, "FAILED EVENT TYPE: %s: have %s (%d) but want ", libinput_device_get_name(libinput_event_get_device(event)), litest_event_get_type_str(event), libinput_event_get_type(event)); va_start(args, lineno); expected_type = va_arg(args, int); while ((int)expected_type != -1) { fprintf(stderr, "%s (%d)", litest_event_type_str(expected_type), expected_type); expected_type = va_arg(args, int); if ((int)expected_type != -1) fprintf(stderr, " || "); } va_end(args); fprintf(stderr, "\n"); litest_print_event(event, "Wrong event is:"); litest_backtrace(func); litest_runner_abort(); } void _litest_assert_event_type(struct libinput_event *event, enum libinput_event_type want, const char *func, int lineno) { _litest_assert_event_type_is_one_of(event, func, lineno, want, -1); } void _litest_assert_event_type_not_one_of(struct libinput_event *event, const char *func, int lineno, ...) { va_list args; enum libinput_event_type not_expected_type; enum libinput_event_type actual_type = libinput_event_get_type(event); bool match = false; va_start(args, lineno); not_expected_type = va_arg(args, int); while ((int)not_expected_type != -1 && !match) { match = (actual_type == not_expected_type); not_expected_type = va_arg(args, int); } va_end(args); if (!match) return; fprintf(stderr, "FAILED EVENT TYPE: %s: have %s (%d) but didn't want that\n", libinput_device_get_name(libinput_event_get_device(event)), litest_event_get_type_str(event), libinput_event_get_type(event)); litest_print_event(event,"\nWrong event is: "); litest_backtrace(func); litest_runner_abort(); } void _litest_assert_empty_queue(struct libinput *li, const char *func, int line) { bool empty_queue = true; struct libinput_event *event; _litest_checkpoint(func, line, ANSI_BRIGHT_CYAN, "asserting empty queue"); libinput_dispatch(li); while ((event = libinput_get_event(li))) { empty_queue = false; litest_print_event(event, "Unexpected event: "); libinput_event_destroy(event); libinput_dispatch(li); } litest_assert(empty_queue); } static struct libevdev_uinput * litest_create_uinput(const char *name, const struct input_id *id, const struct input_absinfo *abs_info, const int *events) { struct libevdev_uinput *uinput; struct libevdev *dev; int type, code; int rc; const struct input_absinfo *abs; const struct input_absinfo default_abs = { .value = 0, .minimum = 0, .maximum = 100, .fuzz = 0, .flat = 0, .resolution = 100 }; /* See kernel commit 206f533a0a7c ("Input: uinput - reject requests with unreasonable number of slots") */ const struct input_absinfo default_abs_mt_slot = { .value = 0, .minimum = 0, .maximum = 64, .fuzz = 0, .flat = 0, .resolution = 100 }; char buf[512]; dev = libevdev_new(); litest_assert_ptr_notnull(dev); snprintf(buf, sizeof(buf), "litest %s", name); libevdev_set_name(dev, buf); if (id) { libevdev_set_id_bustype(dev, id->bustype); libevdev_set_id_vendor(dev, id->vendor); libevdev_set_id_product(dev, id->product); libevdev_set_id_version(dev, id->version); } abs = abs_info; while (abs && abs->value != -1) { struct input_absinfo a = *abs; /* abs_info->value is used for the code and may be outside of [min, max] */ a.value = abs->minimum; rc = libevdev_enable_event_code(dev, EV_ABS, abs->value, &a); litest_assert_int_eq(rc, 0); abs++; } while (events && (type = *events++) != -1 && (code = *events++) != -1) { if (type == INPUT_PROP_MAX) { rc = libevdev_enable_property(dev, code); } else { const struct input_absinfo *abs = (code == ABS_MT_SLOT) ? &default_abs_mt_slot : &default_abs; rc = libevdev_enable_event_code(dev, type, code, type == EV_ABS ? abs : NULL); } litest_assert_int_eq(rc, 0); } rc = libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput); litest_assert_msg(rc == 0, "Failed to create uinput device: %s\n", strerror(-rc)); libevdev_free(dev); return uinput; } struct libevdev_uinput * litest_create_uinput_device_from_description(const char *name, const struct input_id *id, const struct input_absinfo *abs_info, const int *events) { struct libevdev_uinput *uinput; const char *syspath; char path[PATH_MAX]; struct udev_monitor *udev_monitor; struct udev_device *udev_device; udev_monitor = udev_setup_monitor(); uinput = litest_create_uinput(name, id, abs_info, events); syspath = libevdev_uinput_get_syspath(uinput); snprintf(path, sizeof(path), "%s/event", syspath); udev_device = udev_wait_for_device_event(udev_monitor, "add", path); litest_assert(udev_device_get_property_value(udev_device, "ID_INPUT")); udev_device_unref(udev_device); udev_monitor_unref(udev_monitor); return uinput; } static struct libevdev_uinput * litest_create_uinput_abs_device_v(const char *name, struct input_id *id, const struct input_absinfo *abs, va_list args) { int events[KEY_MAX * 2 + 2]; /* increase this if not sufficient */ int *event = events; int type, code; while ((type = va_arg(args, int)) != -1 && (code = va_arg(args, int)) != -1) { *event++ = type; *event++ = code; litest_assert(event < &events[ARRAY_LENGTH(events) - 2]); } *event++ = -1; *event++ = -1; return litest_create_uinput_device_from_description(name, id, abs, events); } struct libevdev_uinput * litest_create_uinput_abs_device(const char *name, struct input_id *id, const struct input_absinfo *abs, ...) { struct libevdev_uinput *uinput; va_list args; va_start(args, abs); uinput = litest_create_uinput_abs_device_v(name, id, abs, args); va_end(args); return uinput; } struct libevdev_uinput * litest_create_uinput_device(const char *name, struct input_id *id, ...) { struct libevdev_uinput *uinput; va_list args; va_start(args, id); uinput = litest_create_uinput_abs_device_v(name, id, NULL, args); va_end(args); return uinput; } struct libinput_event_pointer* litest_is_button_event(struct libinput_event *event, unsigned int button, enum libinput_button_state state) { struct libinput_event_pointer *ptrev; enum libinput_event_type type = LIBINPUT_EVENT_POINTER_BUTTON; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); ptrev = libinput_event_get_pointer_event(event); litest_assert_int_eq(libinput_event_pointer_get_button(ptrev), button); litest_assert_int_eq(libinput_event_pointer_get_button_state(ptrev), state); return ptrev; } struct libinput_event_pointer * litest_is_axis_event(struct libinput_event *event, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, enum libinput_pointer_axis_source source) { struct libinput_event_pointer *ptrev; litest_assert(axis_type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_FINGER || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); litest_assert_ptr_notnull(event); litest_assert_event_type_is_one_of(event, LIBINPUT_EVENT_POINTER_AXIS, axis_type); ptrev = libinput_event_get_pointer_event(event); litest_assert(libinput_event_pointer_has_axis(ptrev, axis)); if (source != 0) litest_assert_int_eq(litest_event_pointer_get_axis_source(ptrev), source); return ptrev; } bool litest_is_high_res_axis_event(struct libinput_event *event) { litest_assert_event_type_is_one_of(event, LIBINPUT_EVENT_POINTER_AXIS, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); return (libinput_event_get_type(event) != LIBINPUT_EVENT_POINTER_AXIS); } struct libinput_event_pointer * litest_is_motion_event(struct libinput_event *event) { struct libinput_event_pointer *ptrev; enum libinput_event_type type = LIBINPUT_EVENT_POINTER_MOTION; double x, y, ux, uy; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); ptrev = libinput_event_get_pointer_event(event); x = libinput_event_pointer_get_dx(ptrev); y = libinput_event_pointer_get_dy(ptrev); ux = libinput_event_pointer_get_dx_unaccelerated(ptrev); uy = libinput_event_pointer_get_dy_unaccelerated(ptrev); /* No 0 delta motion events */ litest_assert(x != 0.0 || y != 0.0 || ux != 0.0 || uy != 0.0); return ptrev; } void _litest_assert_key_event(struct libinput *li, unsigned int key, enum libinput_key_state state, const char *func, int lineno) { struct libinput_event *event; litest_wait_for_event(li); event = libinput_get_event(li); litest_is_keyboard_event(event, key, state); libinput_event_destroy(event); } void _litest_assert_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int line) { struct libinput_event *event; _litest_checkpoint(func, line, ANSI_CYAN, "asserting button event %s (%d) state %d", libevdev_event_code_get_name(EV_KEY, button), button, state); litest_wait_for_event(li); event = libinput_get_event(li); litest_is_button_event(event, button, state); libinput_event_destroy(event); } struct libinput_event_touch * litest_is_touch_event(struct libinput_event *event, enum libinput_event_type type) { struct libinput_event_touch *touch; litest_assert_ptr_notnull(event); if (type == 0) type = libinput_event_get_type(event); switch (type) { case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TOUCH_CANCEL: litest_assert_event_type(event, type); break; default: litest_abort_msg("%s: invalid touch type %d", __func__, type); } touch = libinput_event_get_touch_event(event); return touch; } struct libinput_event_keyboard * litest_is_keyboard_event(struct libinput_event *event, unsigned int key, enum libinput_key_state state) { struct libinput_event_keyboard *kevent; enum libinput_event_type type = LIBINPUT_EVENT_KEYBOARD_KEY; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); kevent = libinput_event_get_keyboard_event(event); litest_assert_ptr_notnull(kevent); litest_assert_int_eq(libinput_event_keyboard_get_key(kevent), key); litest_assert_int_eq(libinput_event_keyboard_get_key_state(kevent), state); return kevent; } struct libinput_event_gesture * litest_is_gesture_event(struct libinput_event *event, enum libinput_event_type type, int nfingers) { struct libinput_event_gesture *gevent; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); gevent = libinput_event_get_gesture_event(event); litest_assert_ptr_notnull(gevent); if (nfingers != -1) litest_assert_int_eq(libinput_event_gesture_get_finger_count(gevent), nfingers); return gevent; } void _litest_assert_gesture_event(struct libinput *li, enum libinput_event_type type, int nfingers, const char *func, int line) { struct libinput_event *event; _litest_checkpoint(func, line, ANSI_CYAN, "asserting gesture event %s %dfg", litest_event_type_str(type), nfingers); litest_wait_for_event(li); event = libinput_get_event(li); litest_is_gesture_event(event, type, nfingers); libinput_event_destroy(event); } struct libinput_event_tablet_tool * litest_is_tablet_event(struct libinput_event *event, enum libinput_event_type type) { struct libinput_event_tablet_tool *tevent; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); tevent = libinput_event_get_tablet_tool_event(event); litest_assert_ptr_notnull(tevent); return tevent; } void _litest_assert_tablet_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int lineno) { struct libinput_event *event; struct libinput_event_tablet_tool *tev; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_BUTTON; litest_wait_for_event(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, type); tev = libinput_event_get_tablet_tool_event(event); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), state); libinput_event_destroy(event); } struct libinput_event_tablet_tool * litest_is_proximity_event(struct libinput_event *event, enum libinput_tablet_tool_proximity_state state) { struct libinput_event_tablet_tool *tev; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY; litest_assert_notnull(event); litest_assert_event_type(event, type); tev = libinput_event_get_tablet_tool_event(event); litest_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tev), state); return tev; } double litest_event_pointer_get_value(struct libinput_event_pointer *ptrev, enum libinput_pointer_axis axis) { struct libinput_event *event; enum libinput_event_type type; event = libinput_event_pointer_get_base_event(ptrev); type = libinput_event_get_type(event); switch (type) { case LIBINPUT_EVENT_POINTER_AXIS: return libinput_event_pointer_get_axis_value(ptrev, axis); case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: return libinput_event_pointer_get_scroll_value_v120(ptrev, axis); case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: return libinput_event_pointer_get_scroll_value(ptrev, axis); default: abort(); } } enum libinput_pointer_axis_source litest_event_pointer_get_axis_source(struct libinput_event_pointer *ptrev) { struct libinput_event *event; enum libinput_event_type type; event = libinput_event_pointer_get_base_event(ptrev); type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_POINTER_AXIS) return libinput_event_pointer_get_axis_source(ptrev); switch (type) { case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: return LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: return LIBINPUT_POINTER_AXIS_SOURCE_FINGER; case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: return LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS; default: abort(); } } void _litest_assert_tablet_proximity_event(struct libinput *li, enum libinput_tablet_tool_proximity_state state, const char *func, int lineno) { struct libinput_event *event; litest_wait_for_event(li); event = libinput_get_event(li); litest_is_proximity_event(event, state); libinput_event_destroy(event); } void _litest_assert_tablet_tip_event(struct libinput *li, enum libinput_tablet_tool_tip_state state, const char *func, int lineno) { struct libinput_event *event; struct libinput_event_tablet_tool *tev; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_TIP; litest_wait_for_event(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, type); tev = libinput_event_get_tablet_tool_event(event); litest_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tev), state); libinput_event_destroy(event); } struct libinput_event_tablet_pad * litest_is_pad_button_event(struct libinput_event *event, unsigned int button, enum libinput_button_state state) { struct libinput_event_tablet_pad *p; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_BUTTON; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); p = libinput_event_get_tablet_pad_event(event); litest_assert_ptr_notnull(p); litest_assert_int_eq(libinput_event_tablet_pad_get_button_number(p), button); litest_assert_int_eq(libinput_event_tablet_pad_get_button_state(p), state); return p; } struct libinput_event_tablet_pad * litest_is_pad_dial_event(struct libinput_event *event, unsigned int number) { struct libinput_event_tablet_pad *p; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_DIAL; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); p = libinput_event_get_tablet_pad_event(event); litest_assert_int_eq(libinput_event_tablet_pad_get_dial_number(p), number); return p; } struct libinput_event_tablet_pad * litest_is_pad_ring_event(struct libinput_event *event, unsigned int number, enum libinput_tablet_pad_ring_axis_source source) { struct libinput_event_tablet_pad *p; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_RING; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); p = libinput_event_get_tablet_pad_event(event); litest_assert_int_eq(libinput_event_tablet_pad_get_ring_number(p), number); litest_assert_int_eq(libinput_event_tablet_pad_get_ring_source(p), source); return p; } struct libinput_event_tablet_pad * litest_is_pad_strip_event(struct libinput_event *event, unsigned int number, enum libinput_tablet_pad_strip_axis_source source) { struct libinput_event_tablet_pad *p; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_STRIP; litest_assert_ptr_notnull(event); litest_assert_event_type(event, type); p = libinput_event_get_tablet_pad_event(event); litest_assert_int_eq(libinput_event_tablet_pad_get_strip_number(p), number); litest_assert_int_eq(libinput_event_tablet_pad_get_strip_source(p), source); return p; } struct libinput_event_tablet_pad * litest_is_pad_key_event(struct libinput_event *event, unsigned int key, enum libinput_key_state state) { struct libinput_event_tablet_pad *p; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_KEY; litest_assert(event != NULL); litest_assert_event_type(event, type); p = libinput_event_get_tablet_pad_event(event); litest_assert(p != NULL); litest_assert_int_eq(libinput_event_tablet_pad_get_key(p), key); litest_assert_int_eq(libinput_event_tablet_pad_get_key_state(p), state); return p; } struct libinput_event_switch * litest_is_switch_event(struct libinput_event *event, enum libinput_switch sw, enum libinput_switch_state state) { struct libinput_event_switch *swev; enum libinput_event_type type = LIBINPUT_EVENT_SWITCH_TOGGLE; litest_assert_notnull(event); litest_assert_event_type(event, type); swev = libinput_event_get_switch_event(event); litest_assert_int_eq(libinput_event_switch_get_switch(swev), sw); litest_assert_int_eq(libinput_event_switch_get_switch_state(swev), state); return swev; } void _litest_assert_switch_event(struct libinput *li, enum libinput_switch sw, enum libinput_switch_state state, const char *func, int lineno) { struct libinput_event *event; litest_wait_for_event(li); event = libinput_get_event(li); litest_is_switch_event(event, sw, state); libinput_event_destroy(event); } void _litest_assert_pad_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int lineno) { struct libinput_event *event; litest_wait_for_event(li); event = libinput_get_event(li); litest_is_pad_button_event(event, button, state); libinput_event_destroy(event); } void _litest_assert_pad_key_event(struct libinput *li, unsigned int key, enum libinput_key_state state, const char *func, int lineno) { struct libinput_event *event; litest_wait_for_event(li); event = libinput_get_event(li); litest_is_pad_key_event(event, key, state); libinput_event_destroy(event); } void litest_assert_scroll(struct libinput *li, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, int minimum_movement) { struct libinput_event *event; struct libinput_event_pointer *ptrev; bool last_hi_res_event_found, last_low_res_event_found; int value; int nevents = 0; litest_assert(axis_type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_FINGER || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); last_hi_res_event_found = false; last_low_res_event_found = false; event = libinput_get_event(li); litest_assert_ptr_notnull(event); while (event) { int min = minimum_movement; ptrev = litest_is_axis_event(event, axis_type, axis, 0); nevents++; /* Due to how the hysteresis works on touchpad * events, the first event is reduced by the * hysteresis margin that can cause the first event * go under the minimum we expect for all other * events */ if (nevents == 1) min = minimum_movement/2; value = litest_event_pointer_get_value(ptrev, axis); if (litest_is_high_res_axis_event(event)) { litest_assert(!last_hi_res_event_found); if (axis_type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) min *= 120; if (value == 0) last_hi_res_event_found = true; } else { litest_assert(!last_low_res_event_found); if (value == 0) last_low_res_event_found = true; } if (value != 0) { if (minimum_movement > 0) litest_assert_int_ge(value, min); else litest_assert_int_le(value, min); } libinput_event_destroy(event); event = libinput_get_event(li); } litest_assert(last_low_res_event_found); litest_assert(last_hi_res_event_found); } void litest_assert_axis_end_sequence(struct libinput *li, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, enum libinput_pointer_axis_source source) { struct libinput_event *event; struct libinput_event_pointer *ptrev; bool last_hi_res_event_found, last_low_res_event_found; double val; int i; litest_assert(axis_type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_FINGER || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); last_hi_res_event_found = false; last_low_res_event_found = false; /* both high and low scroll end events must be sent */ for (i = 0; i < 2; i++) { event = libinput_get_event(li); ptrev = litest_is_axis_event(event, axis_type, axis, source); val = litest_event_pointer_get_value(ptrev, axis); litest_assert(val == 0.0); if (litest_is_high_res_axis_event(event)) { litest_assert(!last_hi_res_event_found); last_hi_res_event_found = true; } else { litest_assert(!last_low_res_event_found); last_low_res_event_found = true; } libinput_event_destroy(event); } litest_assert(last_low_res_event_found); litest_assert(last_hi_res_event_found); } void _litest_assert_only_typed_events(struct libinput *li, enum libinput_event_type type, const char *func, int line) { struct libinput_event *event; litest_assert(type != LIBINPUT_EVENT_NONE); _litest_checkpoint(func, line, ANSI_CYAN, "asserting only typed events %s", litest_event_type_str(type)); libinput_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { litest_assert_event_type(event, type); libinput_event_destroy(event); libinput_dispatch(li); event = libinput_get_event(li); } } void litest_assert_only_axis_events(struct libinput *li, enum libinput_event_type axis_type) { struct libinput_event *event; litest_assert(axis_type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_FINGER || axis_type == LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); libinput_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { litest_assert_event_type_is_one_of(event, LIBINPUT_EVENT_POINTER_AXIS, axis_type); libinput_event_destroy(event); libinput_dispatch(li); event = libinput_get_event(li); } } void litest_assert_no_typed_events(struct libinput *li, enum libinput_event_type type) { struct libinput_event *event; litest_assert(type != LIBINPUT_EVENT_NONE); libinput_dispatch(li); event = libinput_get_event(li); while (event) { litest_assert_int_ne(libinput_event_get_type(event), type); libinput_event_destroy(event); libinput_dispatch(li); event = libinput_get_event(li); } } void litest_assert_touch_sequence(struct libinput *li) { struct libinput_event *event; struct libinput_event_touch *tev; int slot; event = libinput_get_event(li); tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); slot = libinput_event_touch_get_slot(tev); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); event = libinput_get_event(li); do { tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_MOTION); litest_assert_int_eq(slot, libinput_event_touch_get_slot(tev)); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_notnull(event); } while (libinput_event_get_type(event) != LIBINPUT_EVENT_TOUCH_UP); tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_UP); litest_assert_int_eq(slot, libinput_event_touch_get_slot(tev)); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); } void litest_assert_touch_motion_frame(struct libinput *li) { struct libinput_event *event; /* expect at least one, but maybe more */ event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_MOTION); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); event = libinput_get_event(li); while (event) { litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_MOTION); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); event = libinput_get_event(li); } } void litest_assert_touch_down_frame(struct libinput *li) { struct libinput_event *event; event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); } void litest_assert_touch_up_frame(struct libinput *li) { struct libinput_event *event; event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_UP); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); } void litest_assert_touch_cancel(struct libinput *li) { struct libinput_event *event; event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); } void litest_timeout_tap(void) { msleep(300); } void litest_timeout_tapndrag(void) { msleep(520); } void litest_timeout_debounce(void) { msleep(30); } void litest_timeout_softbuttons(void) { msleep(300); } void litest_timeout_buttonscroll(void) { msleep(300); } void litest_timeout_finger_switch(void) { msleep(140); } void litest_timeout_wheel_scroll(void) { msleep(600); } void litest_timeout_edgescroll(void) { msleep(300); } void litest_timeout_middlebutton(void) { msleep(70); } void litest_timeout_dwt_short(void) { msleep(220); } void litest_timeout_dwt_long(void) { msleep(520); } void litest_timeout_gesture(void) { msleep(120); } void litest_timeout_gesture_scroll(void) { msleep(180); } void litest_timeout_gesture_hold(void) { msleep(300); } void litest_timeout_gesture_quick_hold(void) { msleep(60); } void litest_timeout_trackpoint(void) { msleep(320); } void litest_timeout_tablet_proxout(void) { msleep(170); } void litest_timeout_touch_arbitration(void) { msleep(100); } void litest_timeout_hysteresis(void) { msleep(90); } void litest_timeout_3fg_drag(void) { msleep(800); } void litest_push_event_frame(struct litest_device *dev) { litest_assert_int_ge(dev->skip_ev_syn, 0); dev->skip_ev_syn++; } void litest_pop_event_frame(struct litest_device *dev) { litest_assert_int_gt(dev->skip_ev_syn, 0); dev->skip_ev_syn--; if (dev->skip_ev_syn == 0) litest_event(dev, EV_SYN, SYN_REPORT, 0); } void litest_filter_event(struct litest_device *dev, unsigned int type, unsigned int code) { libevdev_disable_event_code(dev->evdev, type, code); } void litest_unfilter_event(struct litest_device *dev, unsigned int type, unsigned int code) { /* would need an non-NULL argument for re-enabling, so simply abort * until we need to be more sophisticated */ litest_assert_int_ne(type, (unsigned int)EV_ABS); libevdev_enable_event_code(dev->evdev, type, code, NULL); } static void send_abs_xy(struct litest_device *d, double x, double y) { struct input_event e; int val; e.type = EV_ABS; e.code = ABS_X; e.value = LITEST_AUTO_ASSIGN; val = litest_auto_assign_value(d, &e, 0, x, y, NULL, true); litest_event(d, EV_ABS, ABS_X, val); e.code = ABS_Y; val = litest_auto_assign_value(d, &e, 0, x, y, NULL, true); litest_event(d, EV_ABS, ABS_Y, val); } static void send_abs_mt_xy(struct litest_device *d, double x, double y) { struct input_event e; int val; e.type = EV_ABS; e.code = ABS_MT_POSITION_X; e.value = LITEST_AUTO_ASSIGN; val = litest_auto_assign_value(d, &e, 0, x, y, NULL, true); litest_event(d, EV_ABS, ABS_MT_POSITION_X, val); e.code = ABS_MT_POSITION_Y; e.value = LITEST_AUTO_ASSIGN; val = litest_auto_assign_value(d, &e, 0, x, y, NULL, true); litest_event(d, EV_ABS, ABS_MT_POSITION_Y, val); } void litest_semi_mt_touch_down(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot, double x, double y) { double t, l, r = 0, b = 0; /* top, left, right, bottom */ if (d->ntouches_down > 2 || slot > 1) return; if (d->ntouches_down == 1) { l = x; t = y; } else { int other = (slot + 1) % 2; l = min(x, semi_mt->touches[other].x); t = min(y, semi_mt->touches[other].y); r = max(x, semi_mt->touches[other].x); b = max(y, semi_mt->touches[other].y); } send_abs_xy(d, l, t); litest_event(d, EV_ABS, ABS_MT_SLOT, 0); if (d->ntouches_down == 1) litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, ++semi_mt->tracking_id); send_abs_mt_xy(d, l, t); if (d->ntouches_down == 2) { litest_event(d, EV_ABS, ABS_MT_SLOT, 1); litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, ++semi_mt->tracking_id); send_abs_mt_xy(d, r, b); } litest_event(d, EV_SYN, SYN_REPORT, 0); semi_mt->touches[slot].x = x; semi_mt->touches[slot].y = y; } void litest_semi_mt_touch_move(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot, double x, double y) { double t, l, r = 0, b = 0; /* top, left, right, bottom */ if (d->ntouches_down > 2 || slot > 1) return; if (d->ntouches_down == 1) { l = x; t = y; } else { int other = (slot + 1) % 2; l = min(x, semi_mt->touches[other].x); t = min(y, semi_mt->touches[other].y); r = max(x, semi_mt->touches[other].x); b = max(y, semi_mt->touches[other].y); } send_abs_xy(d, l, t); litest_event(d, EV_ABS, ABS_MT_SLOT, 0); send_abs_mt_xy(d, l, t); if (d->ntouches_down == 2) { litest_event(d, EV_ABS, ABS_MT_SLOT, 1); send_abs_mt_xy(d, r, b); } litest_event(d, EV_SYN, SYN_REPORT, 0); semi_mt->touches[slot].x = x; semi_mt->touches[slot].y = y; } void litest_semi_mt_touch_up(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot) { /* note: ntouches_down is decreased before we get here */ if (d->ntouches_down >= 2 || slot > 1) return; litest_event(d, EV_ABS, ABS_MT_SLOT, d->ntouches_down); litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, -1); /* if we have one finger left, send x/y coords for that finger left. this is likely to happen with a real touchpad */ if (d->ntouches_down == 1) { int other = (slot + 1) % 2; send_abs_xy(d, semi_mt->touches[other].x, semi_mt->touches[other].y); litest_event(d, EV_ABS, ABS_MT_SLOT, 0); send_abs_mt_xy(d, semi_mt->touches[other].x, semi_mt->touches[other].y); } litest_event(d, EV_SYN, SYN_REPORT, 0); } enum litest_mode { LITEST_MODE_ERROR, LITEST_MODE_TEST, LITEST_MODE_LIST, }; static inline enum litest_mode litest_parse_argv(int argc, char **argv) { enum { OPT_EXIT_FIRST, OPT_FILTER_TEST, OPT_FILTER_DEVICE, OPT_FILTER_GROUP, OPT_FILTER_RANGEVAL, OPT_FILTER_DEVICELESS, OPT_FILTER_PARAMETER, OPT_OUTPUT_FILE, OPT_JOBS, OPT_LIST, OPT_VERBOSE, }; static const struct option opts[] = { { "filter-test", 1, 0, OPT_FILTER_TEST }, { "filter-device", 1, 0, OPT_FILTER_DEVICE }, { "filter-group", 1, 0, OPT_FILTER_GROUP }, { "filter-rangeval", 1, 0, OPT_FILTER_RANGEVAL }, { "filter-deviceless", 0, 0, OPT_FILTER_DEVICELESS }, { "filter-parameter", 1, 0, OPT_FILTER_PARAMETER }, { "output-file", 1, 0, OPT_OUTPUT_FILE }, { "exitfirst", 0, 0, OPT_EXIT_FIRST }, { "jobs", 1, 0, OPT_JOBS }, { "list", 0, 0, OPT_LIST }, { "verbose", 0, 0, OPT_VERBOSE }, { "help", 0, 0, 'h'}, { 0, 0, 0, 0} }; enum { JOBS_DEFAULT, JOBS_SINGLE, JOBS_CUSTOM } want_jobs = JOBS_DEFAULT; char *builddir; char *jobs_env; /* If we are not running from the builddir, we assume we're running * against the system as installed */ builddir = builddir_lookup(); if (!builddir) use_system_rules_quirks = true; free(builddir); if (in_debugger) want_jobs = JOBS_SINGLE; if ((jobs_env = getenv("LITEST_JOBS"))) { if (!safe_atoi(jobs_env, &jobs)) { fprintf(stderr, "LITEST_JOBS environment variable must be positive integer\n"); exit(EXIT_FAILURE); } } while(1) { int c; int option_index = 0; c = getopt_long(argc, argv, "j:x", opts, &option_index); if (c == -1) break; switch(c) { default: case 'h': printf("Usage: %s [--verbose] [--jobs] [--filter-...]\n" "\n" "Options:\n" " -x | --exitfirst\n" " Exit instantly on first failed test\n" " --filter-test=.... \n" " Glob to filter on test names\n" " --filter-device=.... \n" " Glob to filter on device names\n" " --filter-group=.... \n" " Glob to filter on test groups\n" " --filter-rangeval=N \n" " Only run tests with the given range value\n" " --filter-deviceless=.... \n" " Glob to filter on tests that do not create test devices\n" " --filter-parameter=param1:glob,param2:glob,... \n" " Glob(s) to filter on the given parameters in their string representation.\n" " Boolean parameters are filtered via 'true' and 'false'.\n" " --verbose\n" " Enable verbose output\n" " --jobs 8\n" " Number of parallel test suites to run (default: 8).\n" " This overrides the LITEST_JOBS environment variable.\n" " --list\n" " List all tests\n" "\n" "See the libinput-test-suite(1) man page for details.\n", program_invocation_short_name); exit(c != 'h'); break; case OPT_FILTER_TEST: filter_test = optarg; if (want_jobs == JOBS_DEFAULT) want_jobs = JOBS_SINGLE; break; case OPT_FILTER_DEVICE: filter_device = optarg; if (want_jobs == JOBS_DEFAULT) want_jobs = JOBS_SINGLE; break; case OPT_FILTER_DEVICELESS: run_deviceless = true; break; case OPT_FILTER_GROUP: filter_group = optarg; break; case OPT_FILTER_RANGEVAL: filter_rangeval = atoi(optarg); break; case OPT_FILTER_PARAMETER: { size_t nelems; char **params = strv_from_string(optarg, ",", &nelems); const size_t max_filters = ARRAY_LENGTH(filter_params) - 1; if (nelems >= max_filters) { fprintf(stderr, "Only %zd parameter filters are supported\n", max_filters); exit(1); } for (size_t i = 0; i < nelems; i++) { size_t n; char **strv = strv_from_string(params[i], ":", &n); assert(n == 2); const char *name = strv[0]; const char *glob = strv[1]; struct param_filter *f = &filter_params[i]; snprintf(f->name, sizeof(f->name), "%s", name); snprintf(f->glob, sizeof(f->glob), "%s", glob); strv_free(strv); } strv_free(params); break; } case 'j': case OPT_JOBS: jobs = atoi(optarg); want_jobs = JOBS_CUSTOM; break; case OPT_LIST: return LITEST_MODE_LIST; case OPT_VERBOSE: verbose = true; break; case OPT_OUTPUT_FILE: outfile = fopen(optarg, "w+"); if (!outfile) { fprintf(stderr, "Failed to open %s: %m\n", optarg); exit(1); } break; case 'x': case OPT_EXIT_FIRST: exit_first = true; break; } } if (want_jobs == JOBS_SINGLE) jobs = 1; return LITEST_MODE_TEST; } #ifndef LITEST_NO_MAIN static bool is_debugger_attached(void) { int status; bool rc; int pid = fork(); if (pid == -1) return 0; if (pid == 0) { int ppid = getppid(); if (ptrace(PTRACE_ATTACH, ppid, NULL, 0) == 0) { waitpid(ppid, NULL, 0); ptrace(PTRACE_CONT, ppid, NULL, 0); ptrace(PTRACE_DETACH, ppid, NULL, 0); rc = false; } else { rc = true; } _exit(rc); } else { waitpid(pid, &status, 0); rc = WEXITSTATUS(status); } return !!rc; } static void litest_list_tests(struct list *tests) { struct suite *s; const char *last_test_name = ""; const char *last_dev_name = ""; printf("groups:\n"); list_for_each(s, tests, node) { struct test *t; printf(" - group: \"%s\"\n", s->name); printf(" tests:\n"); list_for_each(t, &s->tests, node) { bool same_test = streq(last_test_name, t->name); bool same_dev = streq(last_dev_name, t->devname); if (!same_test) { printf(" - name: \"%s\"\n", t->name); printf(" devices:\n"); } if (!same_test || !same_dev) { last_test_name = t->name; last_dev_name = t->devname; printf(" - name: \"%s\"\n", t->devname); } } } } extern const struct test_device __start_test_device_section, __stop_test_device_section; static void litest_init_test_devices(struct list *devices) { const struct test_device *t; for (t = &__start_test_device_section; t < &__stop_test_device_section; t++) list_append(devices, &t->device->node); } extern const struct test_collection __start_test_collection_section, __stop_test_collection_section; static void setup_tests(void) { const struct test_collection *c; for (c = &__start_test_collection_section; c < &__stop_test_collection_section; c++) { struct suite *s; s = zalloc(sizeof(*s)); s->name = safe_strdup(c->name); list_init(&s->tests); list_append(&all_test_suites, &s->node); current_suite = s; c->setup(); current_suite = NULL; } } static int check_device_access(void) { if (getuid() != 0) { fprintf(stderr, "%s must be run as root.\n", program_invocation_short_name); return 77; } if (access("/dev/uinput", F_OK) == -1 && access("/dev/input/uinput", F_OK) == -1) { fprintf(stderr, "uinput device is missing, skipping tests.\n"); return 77; } return 0; } static void litest_free_test_list(struct list *tests) { struct suite *s; list_for_each_safe(s, tests, node) { struct test *t; list_for_each_safe(t, &s->tests, node) { litest_test_parameters_unref(t->params); free(t->name); free(t->devname); list_remove(&t->node); free(t); } list_remove(&s->node); free(s->name); free(s); } } int main(int argc, char **argv) { enum litest_mode mode; int rc; const char *meson_testthreads; use_colors = getenv("FORCE_COLOR") || isatty(STDERR_FILENO); if (getenv("NO_COLOR")) use_colors = false; in_debugger = is_debugger_attached(); if (in_debugger) { jobs = 0; } else if ((meson_testthreads = getenv("MESON_TESTTHREADS")) == NULL || !safe_atoi(meson_testthreads, &jobs)) { jobs = get_nprocs(); if (!RUNNING_ON_VALGRIND) jobs *= 2; } if (getenv("LITEST_VERBOSE")) verbose = true; mode = litest_parse_argv(argc, argv); if (mode == LITEST_MODE_ERROR) return EXIT_FAILURE; litest_init_test_devices(&devices); setup_tests(); if (list_empty(&all_test_suites)) { fprintf(stderr, "Error: filters are too strict, no tests to run.\n"); return EXIT_FAILURE; } if (mode == LITEST_MODE_LIST) { litest_list_tests(&all_test_suites); return EXIT_SUCCESS; } if (!run_deviceless && (rc = check_device_access()) != 0) return rc; enum litest_runner_result result = litest_run(&all_test_suites); litest_free_test_list(&all_test_suites); switch (result) { case LITEST_PASS: return EXIT_SUCCESS; case LITEST_SKIP: return 77; default: return result; } } #endif libinput-1.28.1/test/litest.h000066400000000000000000001334561477265155700161240ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "litest-config.h" #ifndef LITEST_H #define LITEST_H #include #include #include #include #include #include #include "libinput-private-config.h" #include "libinput-util.h" #include "quirks.h" #include "litest-runner.h" #define START_TEST(func_) \ static enum litest_runner_result func_(const struct litest_runner_test_env *test_env) { \ int _i __attribute__((unused)) = test_env->rangeval; #define END_TEST \ return LITEST_PASS; \ } struct test_device { const char *name; struct litest_test_device *device; } __attribute__((aligned(16))); #define TEST_DEVICE(which, ...) \ static struct litest_test_device _device; \ \ static void _setup(void) { \ struct litest_device *d = litest_create_device(_device.type); \ litest_set_current_device(d); \ } \ \ static const struct test_device _test_device \ __attribute__ ((used)) \ __attribute__ ((section ("test_device_section"))) = { \ #which, &_device \ }; \ static struct litest_test_device _device = { \ .setup = _setup, \ .shortname = #which, \ .type = which, \ __VA_ARGS__ \ }; struct test_collection { const char *name; void (*setup)(void); } __attribute__((aligned(16))); #define TEST_COLLECTION(name_) \ static void (CONCAT(name_ , __LINE__))(void); \ static const struct test_collection CONCAT(_test_collection_, __LINE__) \ __attribute__ ((used)) \ __attribute__ ((section ("test_collection_section"))) = { \ #name_, CONCAT(name_, __LINE__) \ }; \ static void (CONCAT(name_, __LINE__))(void) #define litest_mark_test_start() \ litest_checkpoint("==================== BOILERPLATE END. TEST CONTENT STARTING NOW ===================="); __attribute__ ((format (printf, 3, 0))) void _litest_checkpoint(const char *func, int line, const char *color, const char *format, ...); #define litest_checkpoint(...) \ _litest_checkpoint(__func__, __LINE__, ANSI_GREEN, __VA_ARGS__) /** * litest itself needs the user_data to store some test-suite-specific * information. Tests must not override this pointer, any data they need * they can hang off the private pointer in this struct. */ struct litest_user_data { void *private; }; void litest_fail_condition(const char *file, int line, const char *func, const char *condition, const char *message, ...); void litest_fail_comparison_int(const char *file, int line, const char *func, const char *operator, int a, int b, const char *astr, const char *bstr); void litest_fail_comparison_double(const char *file, int line, const char *func, const char *operator, double a, double b, const char *astr, const char *bstr); void litest_fail_comparison_ptr(const char *file, int line, const char *func, const char *comparison); void litest_fail_comparison_str(const char *file, int line, const char *func, const char *comparison, const char *operator, const char *astr, const char *bstr); #define litest_assert(cond) \ do { \ if (!(cond)) \ litest_fail_condition(__FILE__, __LINE__, __func__, \ #cond, NULL); \ } while(0) #define litest_assert_msg(cond, ...) \ do { \ if (!(cond)) \ litest_fail_condition(__FILE__, __LINE__, __func__, \ #cond, __VA_ARGS__); \ } while(0) #define litest_abort_msg(...) {\ litest_fail_condition(__FILE__, __LINE__, __func__, \ "aborting", __VA_ARGS__); \ abort(); \ } #define litest_assert_notnull(cond) \ do { \ if ((cond) == NULL) \ litest_fail_condition(__FILE__, __LINE__, __func__, \ #cond " != NULL", "\n"); \ } while(0) #define litest_assert_comparison_int_(a_, op_, b_) \ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (trunc(_a) != _a || trunc(_b) != _b) \ litest_abort_msg("litest_assert_int_* used for non-integer value\n"); \ if (!((_a) op_ (_b))) \ litest_fail_comparison_int(__FILE__, __LINE__, __func__,\ #op_, _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_neg_errno_success(a_) \ do { \ __typeof__(a_) _a = a_; \ if (_a < 0) \ litest_abort_msg("Unexpected negative errno: %d (%s)", _a, strerror(-_a)); \ } while(0); #define litest_assert_errno_success(a_) \ do { \ __typeof__(a_) _a = a_; \ __typeof__(a_) _e = errno; \ if (_a < 0) \ litest_abort_msg("Unexpected errno: %d (%s)", _e, strerror(_e)); \ } while(0); #define litest_assert_comparison_enum_(a_, op_, b_) \ do { \ __typeof__(a_) _a = a_; \ __typeof__(a_) _b = b_; \ if (!((_a) op_ (_b))) \ litest_fail_comparison_int(__FILE__, __LINE__, __func__,\ #op_, (int)_a, (int)_b, \ #a_, #b_); \ } while(0) #define litest_assert_enum_eq(a_, b_) \ litest_assert_comparison_enum_(a_, ==, b_) #define litest_assert_enum_ne(a_, b_) \ litest_assert_comparison_enum_(a_, !=, b_) #define litest_assert_int_eq(a_, b_) \ litest_assert_comparison_int_(a_, ==, b_) #define litest_assert_int_ne(a_, b_) \ litest_assert_comparison_int_(a_, !=, b_) #define litest_assert_int_lt(a_, b_) \ litest_assert_comparison_int_(a_, <, b_) #define litest_assert_int_le(a_, b_) \ litest_assert_comparison_int_(a_, <=, b_) #define litest_assert_int_ge(a_, b_) \ litest_assert_comparison_int_(a_, >=, b_) #define litest_assert_int_gt(a_, b_) \ litest_assert_comparison_int_(a_, >, b_) #define litest_assert_comparison_ptr_(a_, op_, b_) \ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!((_a) op_ (_b))) \ litest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\ #a_ " " #op_ " " #b_); \ } while(0) #define litest_assert_ptr_eq(a_, b_) \ litest_assert_comparison_ptr_(a_, ==, b_) #define litest_assert_ptr_ne(a_, b_) \ litest_assert_comparison_ptr_(a_, !=, b_) #define litest_assert_ptr_null(a_) \ litest_assert_comparison_ptr_(a_, ==, NULL) #define litest_assert_ptr_notnull(a_) \ litest_assert_comparison_ptr_(a_, !=, NULL) #define litest_assert_str_eq(a_, b_) \ do { \ const char *_a = a_; \ const char *_b = b_; \ if (!streq(_a, _b)) \ litest_fail_comparison_str(__FILE__, __LINE__, __func__,\ #a_ " == " #b_, \ "==", \ _a, _b); \ } while(0) #define litest_assert_str_ne(a_, b_) \ do { \ const char *_a = a_; \ const char *_b = b_; \ if (streq(_a, _b)) \ litest_fail_comparison_str(__FILE__, __LINE__, __func__,\ #a_ " != " #b_, \ "!=", \ _a, _b); \ } while(0) #define LITEST_DEFAULT_EPSILON 0.001 #define litest_assert_double_eq_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(fabs((_a) - (_b)) < epsilon_)) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ "==", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_double_ne_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(fabs((_a) - (_b)) > epsilon_)) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ "!=", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_double_gt_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(_a - (epsilon_) > _b)) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ ">", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_double_ge_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(_a > _b || fabs((_a) - (_b)) < epsilon_)) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ ">=", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_double_lt_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(_a < _b - (epsilon_))) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ "<", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_double_le_epsilon(a_, b_, epsilon_)\ do { \ __typeof__(a_) _a = a_; \ __typeof__(b_) _b = b_; \ if (!(_a < _b || fabs((_a) - (_b)) < epsilon_)) \ litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ "<=", _a, _b, \ #a_, #b_); \ } while(0) #define litest_assert_comparison_double_(a_, op_, b_) \ litest_assert_comparison_double_epsilon_(a_, op_, b_, LITEST_DEFAULT_EPSILON) #define litest_assert_double_eq(a_, b_)\ litest_assert_double_eq_epsilon((a_), (b_), LITEST_DEFAULT_EPSILON) #define litest_assert_double_ne(a_, b_)\ litest_assert_double_ne_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) #define litest_assert_double_lt(a_, b_)\ litest_assert_double_lt_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) #define litest_assert_double_le(a_, b_)\ litest_assert_double_le_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) #define litest_assert_double_gt(a_, b_)\ litest_assert_double_gt_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) #define litest_assert_double_ge(a_, b_)\ litest_assert_double_ge_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) void litest_backtrace(const char *func); enum litest_device_type { LITEST_NO_DEVICE = -1, /* Touchpads and associated devices */ LITEST_ACER_HAWAII_TOUCHPAD = -1000, LITEST_AIPTEK, LITEST_ALPS_3FG, LITEST_ALPS_DUALPOINT, LITEST_ALPS_SEMI_MT, LITEST_APPLETOUCH, LITEST_ATMEL_HOVER, LITEST_BCM5974, LITEST_ELANTECH_TOUCHPAD, LITEST_GENERIC_PRESSUREPAD, LITEST_MAGIC_TRACKPAD, LITEST_SYNAPTICS_CLICKPAD_X220, LITEST_SYNAPTICS_HOVER_SEMI_MT, LITEST_SYNAPTICS_I2C, LITEST_SYNAPTICS_PHANTOMCLICKS, LITEST_SYNAPTICS_PRESSUREPAD, LITEST_SYNAPTICS_RMI4, LITEST_SYNAPTICS_TOPBUTTONPAD, LITEST_SYNAPTICS_TOUCHPAD, LITEST_TOUCHPAD_PALMPRESSURE_ZERO, LITEST_WACOM_INTUOS5_FINGER, /* Touchscreens */ LITEST_CALIBRATED_TOUCHSCREEN, LITEST_GENERIC_MULTITOUCH_SCREEN, LITEST_GENERIC_SINGLETOUCH, LITEST_MS_SURFACE_COVER, LITEST_MULTITOUCH_FUZZ_SCREEN, LITEST_NEXUS4_TOUCH_SCREEN, LITEST_PROTOCOL_A_SCREEN, LITEST_TOUCHSCREEN_INVALID_RANGE, LITEST_TOUCHSCREEN_MT_TOOL_TYPE, LITEST_WACOM_ISDV4_E6_FINGER, /* Pointing devices and keyboards */ LITEST_MOUSE, LITEST_KEYBOARD, LITEST_TRACKPOINT, LITEST_ABSINFO_OVERRIDE, LITEST_ACER_HAWAII_KEYBOARD, LITEST_ANKER_MOUSE_KBD, LITEST_APPLE_KEYBOARD, LITEST_CYBORG_RAT, LITEST_HP_WMI_HOTKEYS, LITEST_IGNORED_MOUSE, LITEST_KEYBOARD_ALL_CODES, LITEST_KEYBOARD_BLACKWIDOW, LITEST_KEYBOARD_BLADE_STEALTH, LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH, LITEST_KEYBOARD_LOGITECH_MEDIA_KEYBOARD_ELITE, LITEST_KEYBOARD_QUIRKED, LITEST_LENOVO_SCROLLPOINT, LITEST_LOGITECH_TRACKBALL, LITEST_MAGICMOUSE, LITEST_MOUSE_FORMAT_STRING, LITEST_MOUSE_GLADIUS, LITEST_MOUSE_LOW_DPI, LITEST_MOUSE_ROCCAT, LITEST_MOUSE_WHEEL_CLICK_ANGLE, LITEST_MOUSE_WHEEL_CLICK_COUNT, LITEST_MOUSE_WHEEL_TILT, LITEST_MS_NANO_TRANSCEIVER_MOUSE, LITEST_SONY_VAIO_KEYS, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS, LITEST_THINKPAD_EXTRABUTTONS, LITEST_VMWARE_VIRTMOUSE, LITEST_WHEEL_ONLY, LITEST_XEN_VIRTUAL_POINTER, /* Switches */ LITEST_LID_SWITCH, LITEST_LID_SWITCH_SURFACE3, LITEST_TABLET_MODE_UNRELIABLE, /* Special devices */ LITEST_DELL_CANVAS_TOTEM, LITEST_DELL_CANVAS_TOTEM_TOUCH, LITEST_GPIO_KEYS, LITEST_YUBIKEY, /* Tablets */ LITEST_ELAN_TABLET, LITEST_HUION_TABLET, LITEST_HUION_Q620M_DIAL, LITEST_TABLET_DOUBLEDIAL_PAD, LITEST_TABLET_REL_DIAL_PAD, LITEST_QEMU_TABLET, LITEST_UCLOGIC_TABLET, LITEST_WACOM_BAMBOO_16FG_PEN, LITEST_WACOM_BAMBOO_2FG_FINGER, LITEST_WACOM_BAMBOO_2FG_PAD, LITEST_WACOM_BAMBOO_2FG_PEN, LITEST_WACOM_CALIBRATED_TABLET_PEN, LITEST_WACOM_CINTIQ_12WX_PEN, LITEST_WACOM_CINTIQ_13HDT_FINGER, LITEST_WACOM_CINTIQ_13HDT_PAD, LITEST_WACOM_CINTIQ_13HDT_PEN, LITEST_WACOM_CINTIQ_24HD_PEN, LITEST_WACOM_CINTIQ_24HDT_PAD, LITEST_WACOM_CINTIQ_PRO16_FINGER, LITEST_WACOM_CINTIQ_PRO16_PAD, LITEST_WACOM_CINTIQ_PRO16_PEN, LITEST_WACOM_EKR, LITEST_WACOM_HID4800_PEN, LITEST_WACOM_INTUOS3_PAD, LITEST_WACOM_INTUOS5_PAD, LITEST_WACOM_INTUOS5_PEN, LITEST_WACOM_ISDV4_E6_PEN, LITEST_WACOM_ISDV4_4200_PEN, LITEST_WACOM_ISDV4_524C_PEN, LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD, LITEST_WALTOP, }; #define LITEST_DEVICELESS -2 #define LITEST_DISABLE_DEVICE -1 #define LITEST_ANY 0 #define LITEST_TOUCHPAD bit(0) #define LITEST_CLICKPAD bit(1) #define LITEST_BUTTON bit(2) #define LITEST_KEYS bit(3) #define LITEST_RELATIVE bit(4) #define LITEST_WHEEL bit(5) #define LITEST_TOUCH bit(6) #define LITEST_SINGLE_TOUCH bit(7) #define LITEST_APPLE_CLICKPAD bit(8) #define LITEST_TOPBUTTONPAD bit(9) #define LITEST_SEMI_MT bit(10) #define LITEST_POINTINGSTICK bit(11) #define LITEST_FAKE_MT bit(12) #define LITEST_ABSOLUTE bit(13) #define LITEST_PROTOCOL_A bit(14) #define LITEST_HOVER bit(15) #define LITEST_ELLIPSE bit(16) #define LITEST_TABLET bit(17) #define LITEST_DISTANCE bit(18) #define LITEST_TOOL_SERIAL bit(19) #define LITEST_TILT bit(20) #define LITEST_TABLET_PAD bit(21) #define LITEST_RING bit(22) #define LITEST_STRIP bit(23) #define LITEST_TRACKBALL bit(24) #define LITEST_LEDS bit(25) #define LITEST_SWITCH bit(26) #define LITEST_IGNORED bit(27) #define LITEST_NO_DEBOUNCE bit(28) #define LITEST_TOOL_MOUSE bit(29) #define LITEST_DIRECT bit(30) #define LITEST_TOTEM bit(31) #define LITEST_FORCED_PROXOUT bit(32) #define LITEST_PRECALIBRATED bit(33) #define LITEST_DIAL bit(34) /* this is a semi-mt device, so we keep track of the touches that the tests * send and modify them so that the first touch is always slot 0 and sends * the top-left of the bounding box, the second is always slot 1 and sends * the bottom-right of the bounding box. * Lifting any of two fingers terminates slot 1 */ struct litest_semi_mt { bool is_semi_mt; int tracking_id; /* The actual touches requested by the test for the two slots * in the 0..100 range used by litest */ struct { double x, y; } touches[2]; }; struct litest_device { enum litest_device_type which; struct libevdev *evdev; struct libevdev_uinput *uinput; struct libinput *libinput; struct quirks *quirks; bool owns_context; struct libinput_device *libinput_device; struct litest_device_interface *interface; int ntouches_down; int skip_ev_syn; struct litest_semi_mt semi_mt; /** only used for semi-mt device */ void *private; /* device-specific data */ }; struct axis_replacement { int32_t evcode; double value; }; /** * Same as litest_axis_set_value but allows for ranges outside 0..100% */ static inline void litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value) { while (axes->evcode != -1) { if (axes->evcode == code) { axes->value = value; return; } axes++; } litest_abort_msg("Missing axis code %d\n", code); } /** * Takes a value in percent and sets the given axis to that code. */ static inline void litest_axis_set_value(struct axis_replacement *axes, int code, double value) { litest_assert_double_ge(value, 0.0); litest_assert_double_le(value, 100.0); litest_axis_set_value_unchecked(axes, code, value); } struct libinput *litest_create_context(void); void litest_destroy_context(struct libinput *li); void litest_disable_log_handler(struct libinput *libinput); void litest_restore_log_handler(struct libinput *libinput); void litest_set_log_handler_bug(struct libinput *libinput); struct litest_parameters; /** * Create a new set of parameters for a test case. * * This function takes a variable set of arguments in the format * [name, type, count, arg1, arg2, arg3, ..], for example: * * litest_parameter_new("axis", 'u', 2, ABS_X, ABS_Y, * "direction", 's', 4, "north", "south", "east", "west", * NULL); * * Parsing stops at the first null name argument. */ struct litest_parameters * _litest_parameters_new(const char *name, ...); /* Helper to ensure it's always null-terminated */ #define litest_parameters_new(name_, ...) \ _litest_parameters_new(name_, __VA_ARGS__, NULL) #define litest_with_parameters(params_, ...) \ for (struct litest_parameters *params_ = litest_parameters_new(__VA_ARGS__); \ params_; \ params_ = litest_parameters_unref(params_)) #define _LITEST_NAMED_I32(v_, n_, ...) (struct litest_named_i32){ .value = v_, .name = n_ } /* Helper to default second argument to stringification of first argument. * This allows for two uses of this macro: * - litest_named_i32(0) expands to { 0, "0" } * - litest_named_i32(0, "zero") expands to (effectively) { 0, "zero" } */ #define litest_named_i32(...) _LITEST_NAMED_I32(__VA_ARGS__, #__VA_ARGS__) struct litest_named_i32 { int32_t value; const char *name; }; struct litest_parameters_permutation_value { struct list link; char name[128]; const struct multivalue value; }; /** * Argument for the callback function to litest_parameters_permutations(). * This is simple wrapper around a linked list that contains all elements * of the current permutation. */ struct litest_parameters_permutation { struct list values; /* struct litest_parameters_permutation_value */ }; /** * Callback function invoked for each permutation of a struct litest_parameters. */ typedef int (*litest_parameters_permutation_func_t)(struct litest_parameters_permutation *permutation, void *userdata); /** * Permutates the given parameters and calls func for every possible * permutation. If func returns a nonzero status, permutation stops * and that nonzero status is returned to the caller. * * Userdata is passed through as-is. */ int litest_parameters_permutations(struct litest_parameters *params, litest_parameters_permutation_func_t func, void *userdata); struct litest_parameters * litest_parameters_ref(struct litest_parameters *p); struct litest_parameters * litest_parameters_unref(struct litest_parameters *params); #define litest_add(func_, ...) \ _litest_add(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_ranged(func_, ...) \ _litest_add_ranged(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_parametrized(func_, ...) \ _litest_add_parametrized(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_for_device(func_, ...) \ _litest_add_for_device(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_ranged_for_device(func_, ...) \ _litest_add_ranged_for_device(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_parametrized_for_device(func_, ...) \ _litest_add_parametrized_for_device(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_no_device(func_) \ _litest_add_no_device(__FILE__, #func_, func_) #define litest_add_parametrized_no_device(func_, ...) \ _litest_add_parametrized_no_device(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_ranged_no_device(func_, ...) \ _litest_add_ranged_no_device(__FILE__, #func_, func_, __VA_ARGS__) #define litest_add_deviceless(func_) \ _litest_add_deviceless(__FILE__, #func_, func_) #define litest_add_parametrized_deviceless(func_, params) \ _litest_add_parametrize_deviceless(__FILE__, #func_, func_, params) void _litest_add(const char *name, const char *funcname, const void *func, int64_t required_feature, int64_t excluded_feature); void _litest_add_ranged(const char *name, const char *funcname, const void *func, int64_t required, int64_t excluded, const struct range *range); void _litest_add_parametrized(const char *name, const char *funcname, const void *func, int64_t required, int64_t excluded, struct litest_parameters *params); void _litest_add_for_device(const char *name, const char *funcname, const void *func, enum litest_device_type type); void _litest_add_ranged_for_device(const char *name, const char *funcname, const void *func, enum litest_device_type type, const struct range *range); void _litest_add_parametrized_for_device(const char *name, const char *funcname, const void *func, enum litest_device_type type, struct litest_parameters *params); void _litest_add_no_device(const char *name, const char *funcname, const void *func); void _litest_add_parametrized_no_device(const char *name, const char *funcname, const void *func, struct litest_parameters *params); void _litest_add_ranged_no_device(const char *name, const char *funcname, const void *func, const struct range *range); void _litest_add_deviceless(const char *name, const char *funcname, const void *func); void _litest_add_parametrized_deviceless(const char *name, const char *funcname, const void *func, struct litest_parameters *params); struct litest_device * litest_create_device(enum litest_device_type which); struct litest_device * litest_add_device(struct libinput *libinput, enum litest_device_type which); struct libevdev_uinput * litest_create_uinput_device_from_description(const char *name, const struct input_id *id, const struct input_absinfo *abs, const int *events); struct litest_device * litest_create(enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override); struct litest_device * litest_create_device_with_overrides(enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override); struct litest_device * litest_add_device_with_overrides(struct libinput *libinput, enum litest_device_type which, const char *name_override, struct input_id *id_override, const struct input_absinfo *abs_override, const int *events_override); struct litest_device * litest_current_device(void); void litest_grab_device(struct litest_device *d); void litest_ungrab_device(struct litest_device *d); void litest_delete_device(struct litest_device *d); const char * litest_event_type_str(enum libinput_event_type type); int _litest_dispatch(struct libinput *li, const char *func, int line); #define litest_dispatch(li_) \ _litest_dispatch(li_, __func__, __LINE__) void litest_event(struct litest_device *t, unsigned int type, unsigned int code, int value); int litest_auto_assign_value(struct litest_device *d, const struct input_event *ev, int slot, double x, double y, struct axis_replacement *axes, bool touching); void litest_touch_up(struct litest_device *d, unsigned int slot); void litest_touch_move(struct litest_device *d, unsigned int slot, double x, double y); void litest_touch_move_extended(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes); void litest_touch_sequence(struct litest_device *d, unsigned int slot, double x1, double y1, double x2, double y2, int steps); void litest_touch_down(struct litest_device *d, unsigned int slot, double x, double y); void litest_touch_down_extended(struct litest_device *d, unsigned int slot, double x, double y, struct axis_replacement *axes); void litest_touch_move_to(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, int steps); void litest_touch_move_to_extended(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, struct axis_replacement *axes, int steps); void litest_touch_move_two_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double dx, double dy, int steps); void litest_touch_move_three_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double x2, double y2, double dx, double dy, int steps); void litest_tablet_set_tool_type(struct litest_device *d, unsigned int code); void litest_tablet_proximity_in(struct litest_device *d, double x, double y, struct axis_replacement *axes); void litest_tablet_proximity_out(struct litest_device *d); void litest_tablet_tip_down(struct litest_device *d, double x, double y, struct axis_replacement *axes); void litest_tablet_tip_up(struct litest_device *d, double x, double y, struct axis_replacement *axes); void litest_tablet_motion(struct litest_device *d, double x, double y, struct axis_replacement *axes); void litest_pad_ring_start(struct litest_device *d, double value); void litest_pad_ring_change(struct litest_device *d, double value); void litest_pad_ring_end(struct litest_device *d); void litest_pad_strip_start(struct litest_device *d, double value); void litest_pad_strip_change(struct litest_device *d, double value); void litest_pad_strip_end(struct litest_device *d); void litest_hover_start(struct litest_device *d, unsigned int slot, double x, double y); void litest_hover_end(struct litest_device *d, unsigned int slot); void litest_hover_move(struct litest_device *d, unsigned int slot, double x, double y); void litest_hover_move_to(struct litest_device *d, unsigned int slot, double x_from, double y_from, double x_to, double y_to, int steps); void litest_hover_move_two_touches(struct litest_device *d, double x0, double y0, double x1, double y1, double dx, double dy, int steps); void litest_button_click_debounced(struct litest_device *d, struct libinput *li, unsigned int button, bool is_press); void litest_button_click(struct litest_device *d, unsigned int button, bool is_press); void litest_button_scroll(struct litest_device *d, unsigned int button, double dx, double dy); void litest_button_scroll_locked(struct litest_device *d, unsigned int button, double dx, double dy); void litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press); void litest_switch_action(struct litest_device *d, enum libinput_switch sw, enum libinput_switch_state state); void litest_wait_for_event(struct libinput *li); void _litest_wait_for_event_of_type(struct libinput *li, const char *func, int lineno, ...); #define litest_wait_for_event_of_type(li_, ...) \ _litest_wait_for_event_of_type(li_, __func__, __LINE__, __VA_ARGS__, -1) void litest_drain_events(struct libinput *li); void _litest_drain_events_of_type(struct libinput *li, ...); #define litest_drain_events_of_type(li_, ...) \ _litest_drain_events_of_type(li_, __VA_ARGS__, -1) #define litest_assert_event_type(e_, want_) \ _litest_assert_event_type(e_, want_, __func__, __LINE__) void _litest_assert_event_type(struct libinput_event *event, enum libinput_event_type want, const char *func, int lineno); #define litest_assert_event_type_is_one_of(ev_, ...) \ _litest_assert_event_type_is_one_of(ev_, __func__, __LINE__, __VA_ARGS__, -1) void _litest_assert_event_type_is_one_of(struct libinput_event *event, const char *func, int lineno, ...); #define litest_assert_event_type_not_one_of(ev_, ...) \ _litest_assert_event_type_not_one_of(ev_, __func__, __LINE__, __VA_ARGS__, -1) void _litest_assert_event_type_not_one_of(struct libinput_event *event, const char *func, int lineno, ...); #define litest_assert_empty_queue(li_) \ _litest_assert_empty_queue(li_, __func__, __LINE__) void _litest_assert_empty_queue(struct libinput *li, const char *func, int line); void litest_assert_touch_sequence(struct libinput *li); void litest_assert_touch_motion_frame(struct libinput *li); void litest_assert_touch_down_frame(struct libinput *li); void litest_assert_touch_up_frame(struct libinput *li); void litest_assert_touch_cancel(struct libinput *li); struct libinput_event_pointer * litest_is_button_event(struct libinput_event *event, unsigned int button, enum libinput_button_state state); struct libinput_event_pointer * litest_is_axis_event(struct libinput_event *event, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, enum libinput_pointer_axis_source source); bool litest_is_high_res_axis_event(struct libinput_event *event); struct libinput_event_pointer * litest_is_motion_event(struct libinput_event *event); struct libinput_event_touch * litest_is_touch_event(struct libinput_event *event, enum libinput_event_type type); struct libinput_event_keyboard * litest_is_keyboard_event(struct libinput_event *event, unsigned int key, enum libinput_key_state state); struct libinput_event_gesture * litest_is_gesture_event(struct libinput_event *event, enum libinput_event_type type, int nfingers); struct libinput_event_tablet_tool * litest_is_tablet_event(struct libinput_event *event, enum libinput_event_type type); struct libinput_event_tablet_pad * litest_is_pad_button_event(struct libinput_event *event, unsigned int button, enum libinput_button_state state); struct libinput_event_tablet_pad * litest_is_pad_dial_event(struct libinput_event *event, unsigned int number); struct libinput_event_tablet_pad * litest_is_pad_ring_event(struct libinput_event *event, unsigned int number, enum libinput_tablet_pad_ring_axis_source source); struct libinput_event_tablet_pad * litest_is_pad_strip_event(struct libinput_event *event, unsigned int number, enum libinput_tablet_pad_strip_axis_source source); struct libinput_event_tablet_pad * litest_is_pad_key_event(struct libinput_event *event, unsigned int key, enum libinput_key_state state); struct libinput_event_switch * litest_is_switch_event(struct libinput_event *event, enum libinput_switch sw, enum libinput_switch_state state); struct libinput_event_tablet_tool * litest_is_proximity_event(struct libinput_event *event, enum libinput_tablet_tool_proximity_state state); double litest_event_pointer_get_value(struct libinput_event_pointer *ptrev, enum libinput_pointer_axis axis); enum libinput_pointer_axis_source litest_event_pointer_get_axis_source(struct libinput_event_pointer *event); #define litest_assert_key_event(li_, key_, state_) \ _litest_assert_key_event(li_, key_, state_, __func__, __LINE__) void _litest_assert_key_event(struct libinput *li, unsigned int key, enum libinput_key_state state, const char *func, int lineno); #define litest_assert_button_event(li_, button_, state_) \ _litest_assert_button_event(li_, button_, state_, __func__, __LINE__) void _litest_assert_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int line); #define litest_assert_switch_event(li_, sw_, state_) \ _litest_assert_switch_event(li_, sw_, state_, __func__, __LINE__) void _litest_assert_switch_event(struct libinput *li, enum libinput_switch sw, enum libinput_switch_state state, const char *func, int lineno); void litest_assert_scroll(struct libinput *li, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, int minimum_movement); void litest_assert_axis_end_sequence(struct libinput *li, enum libinput_event_type axis_type, enum libinput_pointer_axis axis, enum libinput_pointer_axis_source source); #define litest_assert_only_typed_events(...) \ _litest_assert_only_typed_events(__VA_ARGS__, __func__, __LINE__) void _litest_assert_only_typed_events(struct libinput *li, enum libinput_event_type type, const char *func, int line); void litest_assert_only_axis_events(struct libinput *li, enum libinput_event_type axis_type); void litest_assert_no_typed_events(struct libinput *li, enum libinput_event_type type); #define litest_assert_tablet_button_event(li_, button_, state_) \ _litest_assert_tablet_button_event(li_, button_, state_, __func__, __LINE__) void _litest_assert_tablet_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int lineno); #define litest_assert_tablet_proximity_event(li_, state_) \ _litest_assert_tablet_proximity_event(li_, state_, __func__, __LINE__) void _litest_assert_tablet_proximity_event(struct libinput *li, enum libinput_tablet_tool_proximity_state state, const char *func, int lineno); #define litest_assert_tablet_tip_event(li_, state_) \ _litest_assert_tablet_tip_event(li_, state_, __func__, __LINE__) void _litest_assert_tablet_tip_event(struct libinput *li, enum libinput_tablet_tool_tip_state state, const char *func, int lineno); #define litest_assert_pad_button_event(li_, button_, state_) \ _litest_assert_pad_button_event(li_, button_, state_, __func__, __LINE__) void _litest_assert_pad_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state, const char *func, int lineno); #define litest_assert_pad_key_event(li_, key_, state_) \ _litest_assert_pad_key_event(li_, key_, state_, __func__, __LINE__) void _litest_assert_pad_key_event(struct libinput *li, unsigned int key, enum libinput_key_state state, const char *func, int lineno); #define litest_assert_gesture_event(...) \ _litest_assert_gesture_event(__VA_ARGS__, __func__, __LINE__) void _litest_assert_gesture_event(struct libinput *li, enum libinput_event_type type, int nfingers, const char *func, int line); struct libevdev_uinput * litest_create_uinput_device(const char *name, struct input_id *id, ...); struct libevdev_uinput * litest_create_uinput_abs_device(const char *name, struct input_id *id, const struct input_absinfo *abs, ...); void litest_timeout_tap(void); void litest_timeout_tapndrag(void); void litest_timeout_debounce(void); void litest_timeout_softbuttons(void); void litest_timeout_buttonscroll(void); void litest_timeout_wheel_scroll(void); void litest_timeout_edgescroll(void); void litest_timeout_finger_switch(void); void litest_timeout_middlebutton(void); void litest_timeout_dwt_short(void); void litest_timeout_dwt_long(void); void litest_timeout_gesture(void); void litest_timeout_gesture_scroll(void); void litest_timeout_gesture_hold(void); void litest_timeout_gesture_quick_hold(void); void litest_timeout_trackpoint(void); void litest_timeout_tablet_proxout(void); void litest_timeout_touch_arbitration(void); void litest_timeout_hysteresis(void); void litest_timeout_3fg_drag(void); void litest_push_event_frame(struct litest_device *dev); void litest_pop_event_frame(struct litest_device *dev); void litest_filter_event(struct litest_device *dev, unsigned int type, unsigned int code); void litest_unfilter_event(struct litest_device *dev, unsigned int type, unsigned int code); void litest_semi_mt_touch_down(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot, double x, double y); void litest_semi_mt_touch_move(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot, double x, double y); void litest_semi_mt_touch_up(struct litest_device *d, struct litest_semi_mt *semi_mt, unsigned int slot); static inline void litest_enable_3fg_drag(struct libinput_device *device, unsigned int nfingers) { enum libinput_config_3fg_drag_state enabled; switch (nfingers) { case 3: enabled = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG; break; case 4: enabled = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG; break; default: litest_abort_msg("Invalid finger count"); break; } enum libinput_config_status status = libinput_device_config_3fg_drag_set_enabled(device, enabled); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } static inline void litest_enable_tap(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED); litest_assert_int_eq(status, expected); } static inline void litest_disable_tap(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_DISABLED); litest_assert_int_eq(status, expected); } static inline void litest_set_tap_map(struct libinput_device *device, enum libinput_config_tap_button_map map) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_int_eq(status, expected); } static inline void litest_enable_tap_drag(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_drag_enabled(device, LIBINPUT_CONFIG_DRAG_ENABLED); litest_assert_int_eq(status, expected); } static inline void litest_disable_tap_drag(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_drag_enabled(device, LIBINPUT_CONFIG_DRAG_DISABLED); litest_assert_int_eq(status, expected); } static inline bool litest_has_2fg_scroll(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; return !!(libinput_device_config_scroll_get_methods(device) & LIBINPUT_CONFIG_SCROLL_2FG); } static inline void litest_enable_2fg_scroll(struct litest_device *dev) { enum libinput_config_status status, expected; struct libinput_device *device = dev->libinput_device; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_2FG); expected = LIBINPUT_CONFIG_STATUS_SUCCESS; litest_assert_int_eq(status, expected); libinput_device_config_scroll_set_natural_scroll_enabled(device, 0); } static inline void litest_enable_edge_scroll(struct litest_device *dev) { enum libinput_config_status status, expected; struct libinput_device *device = dev->libinput_device; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_EDGE); expected = LIBINPUT_CONFIG_STATUS_SUCCESS; litest_assert_int_eq(status, expected); libinput_device_config_scroll_set_natural_scroll_enabled(device, 0); } static inline bool litest_has_clickfinger(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; uint32_t methods = libinput_device_config_click_get_methods(device); return methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; } static inline bool litest_has_btnareas(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; uint32_t methods = libinput_device_config_click_get_methods(device); return methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; } static inline void litest_enable_clickfinger(struct litest_device *dev) { enum libinput_config_status status, expected; struct libinput_device *device = dev->libinput_device; status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); expected = LIBINPUT_CONFIG_STATUS_SUCCESS; litest_assert_int_eq(status, expected); } static inline void litest_set_clickfinger_map(struct litest_device *dev, enum libinput_config_clickfinger_button_map map) { enum libinput_config_status status, expected; struct libinput_device *device = dev->libinput_device; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_click_set_clickfinger_button_map(device, map); litest_assert_int_eq(status, expected); } static inline void litest_enable_buttonareas(struct litest_device *dev) { enum libinput_config_status status, expected; struct libinput_device *device = dev->libinput_device; status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); expected = LIBINPUT_CONFIG_STATUS_SUCCESS; litest_assert_int_eq(status, expected); } static inline void litest_enable_drag_lock_sticky(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY); litest_assert_int_eq(status, expected); } static inline void litest_enable_drag_lock(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT); litest_assert_int_eq(status, expected); } static inline void litest_disable_drag_lock(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); litest_assert_int_eq(status, expected); } static inline void litest_enable_middleemu(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); litest_assert_int_eq(status, expected); } static inline void litest_disable_middleemu(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); litest_assert_int_eq(status, expected); } static inline void litest_sendevents_off(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_int_eq(status, expected); } static inline void litest_sendevents_on(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_int_eq(status, expected); } static inline void litest_sendevents_ext_mouse(struct litest_device *dev) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_assert_int_eq(status, expected); } static inline void litest_enable_hold_gestures(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_gesture_set_hold_enabled(device, LIBINPUT_CONFIG_HOLD_ENABLED); litest_assert_int_eq(status, expected); } static inline void litest_disable_hold_gestures(struct libinput_device *device) { enum libinput_config_status status, expected; expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_gesture_set_hold_enabled(device, LIBINPUT_CONFIG_HOLD_DISABLED); litest_assert_int_eq(status, expected); } static inline bool litest_touchpad_is_external(struct litest_device *dev) { struct udev_device *udev_device; const char *prop; bool is_external; if (libinput_device_get_id_vendor(dev->libinput_device) == VENDOR_ID_WACOM) return true; udev_device = libinput_device_get_udev_device(dev->libinput_device); prop = udev_device_get_property_value(udev_device, "ID_INPUT_TOUCHPAD_INTEGRATION"); is_external = prop && streq(prop, "external"); udev_device_unref(udev_device); return is_external; } static inline int litest_send_file(int sock, int fd) { char buf[40960]; int n = read(fd, buf, 40960); litest_assert_int_gt(n, 0); return write(sock, buf, n); } static inline int litest_slot_count(struct litest_device *dev) { if (dev->which == LITEST_ALPS_3FG) return 2; return libevdev_get_num_slots(dev->evdev); } static inline bool litest_has_palm_detect_size(struct litest_device *dev) { double width, height; unsigned int vendor; unsigned int bustype; int rc; vendor = libinput_device_get_id_vendor(dev->libinput_device); bustype = libevdev_get_id_bustype(dev->evdev); if (vendor == VENDOR_ID_WACOM) return 0; if (bustype == BUS_BLUETOOTH) return 0; if (vendor == VENDOR_ID_APPLE) return 0; rc = libinput_device_get_size(dev->libinput_device, &width, &height); return rc == 0 && width >= 70; } #endif /* LITEST_H */ libinput-1.28.1/test/symbols-leak-test000077500000000000000000000007711477265155700177450ustar00rootroot00000000000000#!/bin/bash # # simple check for exported symbols # # Usage: symbols-leak-test /path/to/mapfile /path/to/libinput/src mapfile="$1" shift srcdir="$1" shift if [[ -z "$mapfile" || -z "$srcdir" ]]; then echo "Usage: symbols-leak-test /path/to/mapfile /path/to/libinput/src" exit 2 fi set -e diff -a -u \ <(cat "$mapfile" | \ grep '^\s\+libinput_.*' | \ sed -e 's/^\s\+\(.*\);/\1/' | sort) \ <(cat "$srcdir"/*.c | \ grep LIBINPUT_EXPORT -A 1 | grep '^libinput_.*' | \ sed -e 's/(.*//' | sort) libinput-1.28.1/test/test-builddir-lookup.c000066400000000000000000000033341477265155700206640ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include "libinput-util.h" #include "builddir.h" int main(int argc, char **argv) { char *builddir; char *mode; assert(argc == 2); mode = argv[1]; builddir = builddir_lookup(); if (streq(mode, "--builddir-is-null")) { assert(builddir == NULL); } else if (streq(mode, "--builddir-is-set")) { /* In the case of release builds, the builddir is the empty string */ if (streq(MESON_BUILD_ROOT, "")) { assert(builddir == NULL); } else { assert(builddir); assert(streq(MESON_BUILD_ROOT, builddir)); } } else { abort(); } free(builddir); return 0; } libinput-1.28.1/test/test-device.c000066400000000000000000001451751477265155700170300ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include "litest.h" #include "libinput-util.h" START_TEST(device_sendevents_config) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; uint32_t modes; device = dev->libinput_device; modes = libinput_device_config_send_events_get_modes(device); litest_assert_int_eq(modes, (uint32_t)LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); } END_TEST START_TEST(device_sendevents_config_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | bit(4)); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(device_sendevents_config_touchpad) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; uint32_t modes, expected; expected = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; /* The wacom devices in the test suite are external */ if (libevdev_get_id_vendor(dev->evdev) != VENDOR_ID_WACOM && !litest_touchpad_is_external(dev)) expected |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; device = dev->libinput_device; modes = libinput_device_config_send_events_get_modes(device); litest_assert_int_eq(modes, expected); } END_TEST START_TEST(device_sendevents_config_touchpad_superset) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; enum libinput_config_status status; uint32_t modes; /* The wacom devices in the test suite are external */ if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM || litest_touchpad_is_external(dev)) return LITEST_NOT_APPLICABLE; device = dev->libinput_device; modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; status = libinput_device_config_send_events_set_mode(device, modes); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* DISABLED supersedes the rest, expect the rest to be dropped */ modes = libinput_device_config_send_events_get_mode(device); litest_assert_enum_eq(modes, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); } END_TEST START_TEST(device_sendevents_config_default) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; uint32_t mode; device = dev->libinput_device; mode = libinput_device_config_send_events_get_mode(device); litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); mode = libinput_device_config_send_events_get_default_mode(device); litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); } END_TEST START_TEST(device_disable) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; struct libinput_event *event; struct litest_device *tmp; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* no event from disabling */ litest_assert_empty_queue(li); /* no event from disabled device */ litest_event(dev, EV_REL, REL_X, 10); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); /* create a new device so the resumed fd isn't the same as the suspended one */ tmp = litest_add_device(li, LITEST_KEYBOARD); litest_assert_notnull(tmp); litest_drain_events(li); /* no event from resuming */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); /* event from re-enabled device */ litest_event(dev, EV_REL, REL_X, 10); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_MOTION); libinput_event_destroy(event); litest_delete_device(tmp); } END_TEST START_TEST(device_disable_tablet) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* no event from disabling */ litest_assert_empty_queue(li); litest_tablet_proximity_in(dev, 60, 60, axes); for (int i = 60; i < 70; i++) { litest_tablet_motion(dev, i, i, axes); litest_dispatch(li); } litest_tablet_proximity_out(dev); litest_assert_empty_queue(li); /* no event from resuming */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_touchpad) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* no event from disabling */ litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* no event from resuming */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* no event from disabling */ litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* no event from resuming */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_touch_during_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; struct libinput_event *event; device = dev->libinput_device; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* after disabling sendevents we require a touch up */ litest_dispatch(li); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_touch_move_to(dev, 0, 90, 90, 50, 50, 10); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* no event from resuming */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_events_pending) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; struct libinput_event *event; int i; device = dev->libinput_device; litest_drain_events(li); /* put a couple of events in the queue, enough to feed the ptraccel trackers */ for (i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 10); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* expect above events */ litest_wait_for_event(li); while ((event = libinput_get_event(li)) != NULL) { litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_MOTION); libinput_event_destroy(event); } } END_TEST START_TEST(device_double_disable) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_double_enable) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_empty_queue(li); } END_TEST START_TEST(device_reenable_syspath_changed) { struct libinput *li; struct litest_device *litest_device; struct libinput_device *device1; enum libinput_config_status status; struct libinput_event *event; li = litest_create_context(); litest_device = litest_add_device(li, LITEST_MOUSE); device1 = litest_device->libinput_device; libinput_device_ref(device1); status = libinput_device_config_send_events_set_mode(device1, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_delete_device(litest_device); litest_drain_events(li); litest_device = litest_add_device(li, LITEST_MOUSE); status = libinput_device_config_send_events_set_mode(device1, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* can't really check for much here, other than that if we pump events through libinput, none of them should be from the first device */ litest_event(litest_device, EV_REL, REL_X, 1); litest_event(litest_device, EV_REL, REL_Y, 1); litest_event(litest_device, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { litest_assert(libinput_event_get_device(event) != device1); libinput_event_destroy(event); } litest_delete_device(litest_device); libinput_device_unref(device1); litest_destroy_context(li); } END_TEST START_TEST(device_reenable_device_removed) { struct libinput *li; struct litest_device *litest_device; struct libinput_device *device; enum libinput_config_status status; li = litest_create_context(); litest_device = litest_add_device(li, LITEST_MOUSE); device = litest_device->libinput_device; libinput_device_ref(device); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_delete_device(litest_device); litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* can't really check for much here, this really just exercises the code path. */ litest_assert_empty_queue(li); libinput_device_unref(device); litest_destroy_context(li); } END_TEST START_TEST(device_disable_release_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; struct libinput_event *event; struct libinput_event_pointer *ptrevent; enum libinput_config_status status; device = dev->libinput_device; litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_wait_for_event(li); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_BUTTON); ptrevent = libinput_event_get_pointer_event(event); litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), (unsigned int)BTN_LEFT); litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_release_keys) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; struct libinput_event *event; struct libinput_event_keyboard *kbdevent; enum libinput_config_status status; device = dev->libinput_device; litest_keyboard_key(dev, KEY_A, true); litest_drain_events(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_wait_for_event(li); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_KEYBOARD_KEY); kbdevent = libinput_event_get_keyboard_event(event); litest_assert_int_eq(libinput_event_keyboard_get_key(kbdevent), (unsigned int)KEY_A); litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kbdevent), LIBINPUT_KEY_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_release_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_dispatch(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* tap happened before suspending, so we still expect the event */ litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* resume, make sure we don't get anything */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_release_tap_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_dispatch(li); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_release_softbutton) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; device = dev->libinput_device; litest_drain_events(li); litest_touch_down(dev, 0, 90, 90); litest_button_click_debounced(dev, li, BTN_LEFT, true); /* make sure softbutton works */ litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); /* disable */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* resume, make sure we don't get anything */ status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(device_disable_topsoftbutton) { struct litest_device *dev = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = dev->libinput; struct libinput_device *device; enum libinput_config_status status; struct libinput_event *event; struct libinput_event_pointer *ptrevent; device = dev->libinput_device; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); status = libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 90, 10); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_touch_up(dev, 0); litest_wait_for_event(li); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_BUTTON); litest_assert_ptr_eq(libinput_event_get_device(event), trackpoint->libinput_device); ptrevent = libinput_event_get_pointer_event(event); litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), (unsigned int)BTN_RIGHT); litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_BUTTON); litest_assert_ptr_eq(libinput_event_get_device(event), trackpoint->libinput_device); ptrevent = libinput_event_get_pointer_event(event); litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), (unsigned int)BTN_RIGHT); litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_delete_device(trackpoint); } END_TEST START_TEST(device_ids) { struct litest_device *dev = litest_current_device(); const char *name; unsigned int bus, pid, vid; name = libevdev_get_name(dev->evdev); bus = libevdev_get_id_bustype(dev->evdev); pid = libevdev_get_id_product(dev->evdev); vid = libevdev_get_id_vendor(dev->evdev); litest_assert_str_eq(name, libinput_device_get_name(dev->libinput_device)); litest_assert_int_eq(bus, libinput_device_get_id_bustype(dev->libinput_device)); litest_assert_int_eq(pid, libinput_device_get_id_product(dev->libinput_device)); litest_assert_int_eq(vid, libinput_device_get_id_vendor(dev->libinput_device)); } END_TEST START_TEST(device_get_udev_handle) { struct litest_device *dev = litest_current_device(); struct udev_device *udev_device; udev_device = libinput_device_get_udev_device(dev->libinput_device); litest_assert_notnull(udev_device); udev_device_unref(udev_device); } END_TEST START_TEST(device_context) { struct litest_device *dev = litest_current_device(); struct libinput_seat *seat; litest_assert(dev->libinput == libinput_device_get_context(dev->libinput_device)); seat = libinput_device_get_seat(dev->libinput_device); litest_assert(dev->libinput == libinput_seat_get_context(seat)); } END_TEST START_TEST(device_user_data) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; void *userdata = &dev; /* not referenced */ litest_assert(libinput_device_get_user_data(device) == NULL); libinput_device_set_user_data(device, userdata); litest_assert_ptr_eq(libinput_device_get_user_data(device), userdata); libinput_device_set_user_data(device, NULL); litest_assert(libinput_device_get_user_data(device) == NULL); } END_TEST START_TEST(device_group_get) { struct litest_device *dev = litest_current_device(); struct libinput_device_group *group; int userdata = 10; group = libinput_device_get_device_group(dev->libinput_device); litest_assert_notnull(group); libinput_device_group_ref(group); libinput_device_group_set_user_data(group, &userdata); litest_assert_ptr_eq(&userdata, libinput_device_group_get_user_data(group)); libinput_device_group_unref(group); } END_TEST START_TEST(device_group_ref) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_MOUSE); struct libinput_device *device = dev->libinput_device; struct libinput_device_group *group; group = libinput_device_get_device_group(device); litest_assert_notnull(group); libinput_device_group_ref(group); libinput_device_ref(device); litest_drain_events(li); litest_delete_device(dev); litest_drain_events(li); /* make sure the device is dead but the group is still around */ litest_assert(libinput_device_unref(device) == NULL); libinput_device_group_ref(group); litest_assert_notnull(libinput_device_group_unref(group)); litest_assert(libinput_device_group_unref(group) == NULL); litest_destroy_context(li); } END_TEST START_TEST(device_group_leak) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; struct libinput_device_group *group; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); group = libinput_device_get_device_group(device); libinput_device_group_ref(group); libinput_path_remove_device(device); libevdev_uinput_destroy(uinput); litest_destroy_context(li); /* the device group leaks, check valgrind */ } END_TEST START_TEST(abs_device_no_absx) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_ABS, ABS_Y, -1); li = litest_create_context(); litest_disable_log_handler(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_restore_log_handler(li); litest_assert(device == NULL); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(abs_device_no_absy) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_ABS, ABS_X, -1); li = litest_create_context(); litest_disable_log_handler(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_restore_log_handler(li); litest_assert(device == NULL); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(abs_mt_device_no_absy) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_ABS, ABS_X, EV_ABS, ABS_Y, EV_ABS, ABS_MT_SLOT, EV_ABS, ABS_MT_POSITION_X, -1); li = litest_create_context(); litest_disable_log_handler(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_restore_log_handler(li); litest_assert(device == NULL); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(abs_mt_device_no_absx) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_ABS, ABS_X, EV_ABS, ABS_Y, EV_ABS, ABS_MT_SLOT, EV_ABS, ABS_MT_POSITION_Y, -1); li = litest_create_context(); litest_disable_log_handler(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_restore_log_handler(li); litest_assert(device == NULL); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST static void assert_device_ignored(struct libinput *li, struct input_absinfo *absinfo) { struct libevdev_uinput *uinput; struct libinput_device *device; uinput = litest_create_uinput_abs_device("test device", NULL, absinfo, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, -1); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_ptr_null(device); libevdev_uinput_destroy(uinput); } START_TEST(abs_device_no_range) { struct libinput *li; int code = _i; /* looped test */ /* set x/y so libinput doesn't just reject for missing axes */ struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 0 }, { ABS_Y, 0, 10, 0, 0, 0 }, { code, 0, 0, 0, 0, 0 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); assert_device_ignored(li, absinfo); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(abs_mt_device_no_range) { struct libinput *li; int code = _i; /* looped test */ /* set x/y so libinput doesn't just reject for missing axes */ struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 0 }, { ABS_Y, 0, 10, 0, 0, 0 }, { ABS_MT_SLOT, 0, 10, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 10, 0, 0, 0 }, { ABS_MT_POSITION_Y, 0, 10, 0, 0, 0 }, { code, 0, 0, 0, 0, 0 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); if (code != ABS_MT_TOOL_TYPE && code != ABS_MT_TRACKING_ID) /* kernel overrides it */ assert_device_ignored(li, absinfo); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(abs_device_missing_res) { struct libinput *li; struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 0 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); assert_device_ignored(li, absinfo); absinfo[0].resolution = 0; absinfo[1].resolution = 20; assert_device_ignored(li, absinfo); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(abs_mt_device_missing_res) { struct libinput *li; struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { ABS_MT_SLOT, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 10, 0, 0, 0 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); assert_device_ignored(li, absinfo); absinfo[4].resolution = 0; absinfo[5].resolution = 20; assert_device_ignored(li, absinfo); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(ignore_joystick) { struct libinput *li; struct libevdev_uinput *uinput; struct libinput_device *device; struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { ABS_RX, 0, 10, 0, 0, 10 }, { ABS_RY, 0, 10, 0, 0, 10 }, { ABS_THROTTLE, 0, 2, 0, 0, 0 }, { ABS_RUDDER, 0, 255, 0, 0, 0 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); litest_drain_events(li); uinput = litest_create_uinput_abs_device("joystick test device", NULL, absinfo, EV_KEY, BTN_TRIGGER, EV_KEY, BTN_A, -1); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_ptr_null(device); libevdev_uinput_destroy(uinput); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(device_wheel_only) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)); } END_TEST START_TEST(device_accelerometer) { struct libinput *li; struct libevdev_uinput *uinput; struct libinput_device *device; struct input_absinfo absinfo[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { ABS_Z, 0, 10, 0, 0, 10 }, { -1, -1, -1, -1, -1, -1 } }; li = litest_create_context(); litest_disable_log_handler(li); uinput = litest_create_uinput_abs_device("test device", NULL, absinfo, -1); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_ptr_null(device); libevdev_uinput_destroy(uinput); litest_restore_log_handler(li); litest_destroy_context(li); } END_TEST START_TEST(device_udev_tag_wacom_tablet) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct udev_device *d; const char *prop; d = libinput_device_get_udev_device(device); prop = udev_device_get_property_value(d, "ID_INPUT_TABLET"); litest_assert_notnull(prop); udev_device_unref(d); } END_TEST START_TEST(device_nonpointer_rel) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; int i; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, KEY_A, EV_KEY, KEY_B, EV_REL, REL_X, EV_REL, REL_Y, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); litest_disable_log_handler(li); for (i = 0; i < 100; i++) { libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_restore_log_handler(li); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(device_touchpad_rel) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; const struct input_absinfo abs[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { ABS_MT_SLOT, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 }, { -1, -1, -1, -1, -1, -1 } }; int i; uinput = litest_create_uinput_abs_device("test device", NULL, abs, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, EV_REL, REL_X, EV_REL, REL_Y, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); for (i = 0; i < 100; i++) { libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(device_touch_rel) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; const struct input_absinfo abs[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { ABS_MT_SLOT, 0, 2, 0, 0, 0 }, { ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, { ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 }, { -1, -1, -1, -1, -1, -1 } }; int i; uinput = litest_create_uinput_abs_device("test device", NULL, abs, EV_KEY, BTN_TOUCH, EV_REL, REL_X, EV_REL, REL_Y, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); litest_disable_log_handler(li); for (i = 0; i < 100; i++) { libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_restore_log_handler(li); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(device_abs_rel) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; const struct input_absinfo abs[] = { { ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, { -1, -1, -1, -1, -1, -1 } }; int i; uinput = litest_create_uinput_abs_device("test device", NULL, abs, EV_KEY, BTN_TOUCH, EV_KEY, BTN_LEFT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); for (i = 0; i < 100; i++) { libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(device_quirks_no_abs_mt_y) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *pev; bool hi_res_event_found, low_res_event_found; int code, i; hi_res_event_found = false; low_res_event_found = false; litest_drain_events(li); litest_event(dev, EV_REL, REL_HWHEEL, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* both high and low scroll end events must be sent */ for (i = 0; i < 2; i++) { event = libinput_get_event(li); pev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); if (litest_is_high_res_axis_event(event)) { litest_assert(!hi_res_event_found); hi_res_event_found = true; } else { litest_assert(!low_res_event_found); low_res_event_found = true; } libinput_event_destroy(libinput_event_pointer_get_base_event(pev)); } litest_assert(low_res_event_found); litest_assert(hi_res_event_found); for (code = ABS_MISC + 1; code < ABS_MAX; code++) { litest_event(dev, EV_ABS, code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } } END_TEST START_TEST(device_quirks_cyborg_rat_mode_button) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; litest_assert(!libinput_device_pointer_has_button(device, 0x118)); litest_assert(!libinput_device_pointer_has_button(device, 0x119)); litest_assert(!libinput_device_pointer_has_button(device, 0x11a)); litest_drain_events(li); litest_event(dev, EV_KEY, 0x118, 0); litest_event(dev, EV_KEY, 0x119, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, 0x119, 0); litest_event(dev, EV_KEY, 0x11a, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, 0x11a, 0); litest_event(dev, EV_KEY, 0x118, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(device_quirks_apple_magicmouse) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* ensure we get no events from the touch */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(device_quirks_logitech_marble_mouse) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_assert(!libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE)); } END_TEST static char *debug_messages[64] = { NULL }; LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void debug_log_handler(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { char *message; int n; if (priority != LIBINPUT_LOG_PRIORITY_DEBUG) return; n = xvasprintf(&message, format, args); litest_assert_int_gt(n, 0); ARRAY_FOR_EACH(debug_messages, dmsg) { if (*dmsg == NULL) { *dmsg = message; return; } } litest_abort_msg("Out of space for debug messages"); } START_TEST(device_quirks) { struct libinput *li; struct litest_device *dev; struct libinput_device *device; char **message; bool disable_key_f1 = false, enable_btn_left = false; #if HAVE_LIBEVDEV_DISABLE_PROPERTY bool disable_pointingstick = false, enable_buttonpad = false, enable_direct = false, disable_direct = false, enable_semi_mt = false, disable_semi_mt = false; #endif li = litest_create_context(); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); libinput_log_set_handler(li, debug_log_handler); dev = litest_add_device(li, LITEST_KEYBOARD_QUIRKED); device = dev->libinput_device; litest_assert(libinput_device_pointer_has_button(device, BTN_LEFT)); litest_assert(libinput_device_pointer_has_button(dev->libinput_device, BTN_RIGHT)); litest_assert(!libinput_device_pointer_has_button(device, BTN_MIDDLE)); litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F1)); litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F2)); litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F3)); /* Scrape the debug messages for confirmation that our quirks are * triggered, the above checks cannot work non-key codes */ message = debug_messages; while (*message) { if (strstr(*message, "disabling EV_KEY KEY_F1")) disable_key_f1 = true; if (strstr(*message, "enabling EV_KEY BTN_LEFT")) enable_btn_left = true; #if HAVE_LIBEVDEV_DISABLE_PROPERTY if (strstr(*message, "enabling INPUT_PROP_BUTTONPAD")) enable_buttonpad = true; if (strstr(*message, "disabling INPUT_PROP_POINTING_STICK")) disable_pointingstick = true; if (strstr(*message, "enabling INPUT_PROP_DIRECT")) { litest_assert(!disable_direct); enable_direct = true; } if (strstr(*message, "disabling INPUT_PROP_DIRECT")) { litest_assert(enable_direct); disable_direct = true; } if (strstr(*message, "enabling INPUT_PROP_SEMI_MT")) { litest_assert(disable_semi_mt); enable_semi_mt = true; } if (strstr(*message, "disabling INPUT_PROP_SEMI_MT")) { litest_assert(!enable_semi_mt); disable_semi_mt = true; } #endif free(*message); message++; } litest_assert(disable_key_f1); litest_assert(enable_btn_left); #if HAVE_LIBEVDEV_DISABLE_PROPERTY litest_assert(enable_buttonpad); litest_assert(disable_pointingstick); litest_assert(enable_direct); litest_assert(disable_direct); litest_assert(enable_semi_mt); litest_assert(disable_semi_mt); #endif litest_disable_log_handler(li); litest_delete_device(dev); litest_destroy_context(li); } END_TEST START_TEST(device_capability_at_least_one) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_device_capability caps[] = { LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER, LIBINPUT_DEVICE_CAP_TOUCH, LIBINPUT_DEVICE_CAP_TABLET_TOOL, LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_GESTURE, LIBINPUT_DEVICE_CAP_SWITCH, }; int ncaps = 0; ARRAY_FOR_EACH(caps, cap) { if (libinput_device_has_capability(device, *cap)) ncaps++; } litest_assert_int_gt(ncaps, 0); } END_TEST START_TEST(device_capability_check_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(!libinput_device_has_capability(device, -1)); litest_assert(!libinput_device_has_capability(device, 7)); litest_assert(!libinput_device_has_capability(device, 0xffff)); } END_TEST START_TEST(device_capability_nocaps_ignored) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; /* SW_PEN_INSERTED isn't handled in libinput so the device is * processed but ends up without seat capabilities and is ignored. */ uinput = litest_create_uinput_device("test device", NULL, EV_SW, SW_PEN_INSERTED, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_ptr_null(device); litest_destroy_context(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(device_has_size) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; double w, h; int rc; rc = libinput_device_get_size(device, &w, &h); litest_assert_int_eq(rc, 0); /* This matches the current set of test devices but may fail if * newer ones are added */ litest_assert_double_gt(w, 30); litest_assert_double_gt(h, 20); } END_TEST START_TEST(device_has_no_size) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; double w = 45, h = 67; int rc; rc = libinput_device_get_size(device, &w, &h); litest_assert_int_eq(rc, -1); litest_assert_double_eq(w, 45); litest_assert_double_eq(h, 67); } END_TEST START_TEST(device_get_output) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; const char *output_name; output_name = libinput_device_get_output_name(device); litest_assert_str_eq(output_name, "myOutput"); } END_TEST START_TEST(device_no_output) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; const char *output_name; output_name = libinput_device_get_output_name(device); litest_assert(output_name == NULL); } END_TEST START_TEST(device_seat_phys_name) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_seat *seat = libinput_device_get_seat(device); const char *seat_name; seat_name = libinput_seat_get_physical_name(seat); litest_assert(streq(seat_name, "seat0")); } END_TEST START_TEST(device_button_down_remove) { struct litest_device *lidev = litest_current_device(); struct litest_device *dev; struct libinput *li; for (int code = 0; code < KEY_MAX; code++) { struct libinput_event *event; struct libinput_event_pointer *p; bool have_down = false, have_up = false; const char *keyname; int button_down = 0, button_up = 0; keyname = libevdev_event_code_get_name(EV_KEY, code); if (!keyname || !strstartswith(keyname, "BTN_") || strstartswith(keyname, "BTN_TOOL_")) continue; if (!libevdev_has_event_code(lidev->evdev, EV_KEY, code)) continue; li = litest_create_context(); dev = litest_add_device(li, lidev->which); litest_drain_events(li); /* Clickpads require a touch down to trigger the button * press */ if (libevdev_has_property(lidev->evdev, INPUT_PROP_BUTTONPAD)) { litest_touch_down(dev, 0, 20, 90); litest_dispatch(li); } litest_event(dev, EV_KEY, code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_delete_device(dev); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) != LIBINPUT_EVENT_POINTER_BUTTON) { libinput_event_destroy(event); continue; } p = libinput_event_get_pointer_event(event); if (libinput_event_pointer_get_button_state(p)) { litest_assert(button_down == 0); button_down = libinput_event_pointer_get_button(p); } else { litest_assert(button_up == 0); button_up = libinput_event_pointer_get_button(p); litest_assert_int_eq(button_down, button_up); } libinput_event_destroy(event); } litest_destroy_context(li); litest_assert_int_eq(have_down, have_up); } } END_TEST TEST_COLLECTION(device) { struct range abs_range = range_init_exclusive(0, ABS_MISC); struct range abs_mt_range = range_init_exclusive(ABS_MT_SLOT + 1, ABS_CNT); litest_add(device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET); litest_add(device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET); litest_add(device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); litest_add(device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET); litest_add(device_sendevents_config_default, LITEST_ANY, LITEST_TABLET); litest_add(device_disable, LITEST_RELATIVE, LITEST_TABLET); litest_add(device_disable_tablet, LITEST_TABLET, LITEST_ANY); litest_add(device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); litest_add(device_disable_touch, LITEST_TOUCH, LITEST_ANY); litest_add(device_disable_touch_during_touch, LITEST_TOUCH, LITEST_ANY); litest_add(device_disable_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add(device_disable_touch_during_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add(device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET); litest_add(device_double_disable, LITEST_ANY, LITEST_TABLET); litest_add(device_double_enable, LITEST_ANY, LITEST_TABLET); litest_add_no_device(device_reenable_syspath_changed); litest_add_no_device(device_reenable_device_removed); litest_add_for_device(device_disable_release_buttons, LITEST_MOUSE); litest_add_for_device(device_disable_release_keys, LITEST_KEYBOARD); litest_add(device_disable_release_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(device_disable_release_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY); litest_add(device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(device_ids, LITEST_ANY, LITEST_ANY); litest_add_for_device(device_context, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(device_user_data, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add(device_get_udev_handle, LITEST_ANY, LITEST_ANY); litest_add(device_group_get, LITEST_ANY, LITEST_ANY); litest_add_no_device(device_group_ref); litest_add_no_device(device_group_leak); litest_add_no_device(abs_device_no_absx); litest_add_no_device(abs_device_no_absy); litest_add_no_device(abs_mt_device_no_absx); litest_add_no_device(abs_mt_device_no_absy); litest_add_ranged_no_device(abs_device_no_range, &abs_range); litest_add_ranged_no_device(abs_mt_device_no_range, &abs_mt_range); litest_add_no_device(abs_device_missing_res); litest_add_no_device(abs_mt_device_missing_res); litest_add_no_device(ignore_joystick); litest_add(device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET); litest_add_no_device(device_accelerometer); litest_add(device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_TOTEM); litest_add_no_device(device_nonpointer_rel); litest_add_no_device(device_touchpad_rel); litest_add_no_device(device_touch_rel); litest_add_no_device(device_abs_rel); litest_add_for_device(device_quirks_no_abs_mt_y, LITEST_ANKER_MOUSE_KBD); litest_add_for_device(device_quirks_cyborg_rat_mode_button, LITEST_CYBORG_RAT); litest_add_for_device(device_quirks_apple_magicmouse, LITEST_MAGICMOUSE); litest_add_for_device(device_quirks_logitech_marble_mouse, LITEST_LOGITECH_TRACKBALL); litest_add_no_device(device_quirks); litest_add(device_capability_at_least_one, LITEST_ANY, LITEST_ANY); litest_add(device_capability_check_invalid, LITEST_ANY, LITEST_ANY); litest_add_no_device(device_capability_nocaps_ignored); litest_add(device_has_size, LITEST_TOUCHPAD, LITEST_ANY); litest_add(device_has_size, LITEST_TABLET, LITEST_ANY); litest_add(device_has_no_size, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET|LITEST_TOUCH|LITEST_ABSOLUTE|LITEST_SINGLE_TOUCH|LITEST_TOTEM); litest_add_for_device(device_get_output, LITEST_CALIBRATED_TOUCHSCREEN); litest_add(device_no_output, LITEST_RELATIVE, LITEST_ANY); litest_add(device_no_output, LITEST_KEYS, LITEST_ANY); litest_add(device_seat_phys_name, LITEST_ANY, LITEST_ANY); litest_add(device_button_down_remove, LITEST_BUTTON, LITEST_ANY); } libinput-1.28.1/test/test-gestures.c000066400000000000000000001760311477265155700174250ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include "libinput-util.h" #include "litest.h" enum cardinal { N, NE, E, SE, S, SW, W, NW, NCARDINALS }; enum hold_gesture_behaviour { HOLD_GESTURE_IGNORE, HOLD_GESTURE_REQUIRE, }; static void test_gesture_swipe_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) < 3) return; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 40, 40); litest_touch_down(dev, 1, 50, 40); litest_touch_down(dev, 2, 60, 40); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, dir_x, dir_y, 10); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); dx = libinput_event_gesture_get_dx_unaccelerated(gevent); dy = libinput_event_gesture_get_dy_unaccelerated(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); libinput_event_destroy(event); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_swipe_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int cardinals[NCARDINALS][2] = { { 0, 3 }, { 3, 3 }, { 3, 0 }, { 3, -3 }, { 0, -3 }, { -3, -3 }, { -3, 0 }, { -3, 3 }, }; int i; if (litest_slot_count(dev) < 4) return; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 40, 40); litest_touch_down(dev, 1, 50, 40); litest_touch_down(dev, 2, 60, 40); litest_touch_down(dev, 3, 70, 40); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); for (i = 0; i < 8; i++) { litest_push_event_frame(dev); dir_x += cardinals[cardinal][0]; dir_y += cardinals[cardinal][1]; litest_touch_move(dev, 0, 40 + dir_x, 40 + dir_y); litest_touch_move(dev, 1, 50 + dir_x, 40 + dir_y); litest_touch_move(dev, 2, 60 + dir_x, 40 + dir_y); litest_touch_move(dev, 3, 70 + dir_x, 40 + dir_y); litest_pop_event_frame(dev); litest_dispatch(li); } litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 4); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); dx = libinput_event_gesture_get_dx_unaccelerated(gevent); dy = libinput_event_gesture_get_dy_unaccelerated(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); libinput_event_destroy(event); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_touch_up(dev, 3); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_pinch_2fg(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int i; double scale, oldscale; double angle; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) < 2 || !libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return; /* If the device is too small to provide a finger spread wide enough * to avoid the scroll bias, skip the test */ if (cardinal == E || cardinal == W) { double w = 0, h = 0; libinput_device_get_size(dev->libinput_device, &w, &h); /* 0.6 because the code below gives us points like 20/y and * 80/y. 45 because the threshold in the code is 40mm */ if (w * 0.6 < 45) return; } dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); for (i = 0; i < 8; i++) { litest_push_event_frame(dev); if (dir_x > 0.0) dir_x -= 2; else if (dir_x < 0.0) dir_x += 2; if (dir_y > 0.0) dir_y -= 2; else if (dir_y < 0.0) dir_y += 2; litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y); litest_pop_event_frame(dev); litest_dispatch(li); } if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); scale = libinput_event_gesture_get_scale(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); litest_assert(scale == 1.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, 2); oldscale = scale; scale = libinput_event_gesture_get_scale(gevent); litest_assert(scale < oldscale); angle = libinput_event_gesture_get_angle_delta(gevent); litest_assert_double_le(fabs(angle), 1.0); libinput_event_destroy(event); litest_dispatch(li); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_pinch_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int i; double scale, oldscale; double angle; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) < 3) return; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y); litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); for (i = 0; i < 8; i++) { litest_push_event_frame(dev); if (dir_x > 0.0) dir_x -= 2; else if (dir_x < 0.0) dir_x += 2; if (dir_y > 0.0) dir_y -= 2; else if (dir_y < 0.0) dir_y += 2; litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y); litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y); litest_pop_event_frame(dev); litest_dispatch(li); } if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); scale = libinput_event_gesture_get_scale(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); litest_assert(scale == 1.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, 3); oldscale = scale; scale = libinput_event_gesture_get_scale(gevent); litest_assert(scale < oldscale); angle = libinput_event_gesture_get_angle_delta(gevent); litest_assert_double_le(fabs(angle), 1.0); libinput_event_destroy(event); litest_dispatch(li); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 3); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_pinch_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int i; double scale, oldscale; double angle; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) < 4) return; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y); litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y); litest_touch_down(dev, 3, 52 - dir_x, 52 - dir_y); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); for (i = 0; i < 7; i++) { litest_push_event_frame(dev); if (dir_x > 0.0) dir_x -= 2; else if (dir_x < 0.0) dir_x += 2; if (dir_y > 0.0) dir_y -= 2; else if (dir_y < 0.0) dir_y += 2; litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y); litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y); litest_touch_move(dev, 3, 52 - dir_x, 52 - dir_y); litest_pop_event_frame(dev); litest_dispatch(li); } if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 4); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); scale = libinput_event_gesture_get_scale(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); litest_assert(scale == 1.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, 4); oldscale = scale; scale = libinput_event_gesture_get_scale(gevent); litest_assert(scale < oldscale); angle = libinput_event_gesture_get_angle_delta(gevent); litest_assert_double_le(fabs(angle), 1.0); libinput_event_destroy(event); litest_dispatch(li); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_touch_up(dev, 3); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 4); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_spread(enum cardinal cardinal, enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; double dir_x, dir_y; int i; double scale, oldscale; double angle; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) < 2 || !libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return; /* If the device is too small to provide a finger spread wide enough * to avoid the scroll bias, skip the test */ if (cardinal == E || cardinal == W) { double w = 0, h = 0; libinput_device_get_size(dev->libinput_device, &w, &h); /* 0.6 because the code below gives us points like 20/y and * 80/y. 45 because the threshold in the code is 40mm */ if (w * 0.6 < 45) return; } dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); for (i = 0; i < 15; i++) { litest_push_event_frame(dev); if (dir_x > 0.0) dir_x += 1; else if (dir_x < 0.0) dir_x -= 1; if (dir_y > 0.0) dir_y += 1; else if (dir_y < 0.0) dir_y -= 1; litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y); litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y); litest_pop_event_frame(dev); litest_dispatch(li); } if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2); } event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); scale = libinput_event_gesture_get_scale(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); litest_assert(scale == 1.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, 2); oldscale = scale; scale = libinput_event_gesture_get_scale(gevent); litest_assert(scale > oldscale); angle = libinput_event_gesture_get_angle_delta(gevent); litest_assert_double_le(fabs(angle), 1.0); libinput_event_destroy(event); litest_dispatch(li); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } static void test_gesture_3fg_buttonarea_scroll(enum hold_gesture_behaviour hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < 3) return; litest_enable_buttonareas(dev); litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 40, 20); litest_touch_down(dev, 1, 30, 20); /* third finger in btnarea */ litest_touch_down(dev, 2, 50, 99); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) litest_timeout_gesture_hold(); litest_touch_move_two_touches(dev, 40, 20, 30, 20, 0, 40, 10); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); if (hold == HOLD_GESTURE_REQUIRE) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2); } litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); } static void test_gesture_hold(int nfingers) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < nfingers) return; litest_drain_events(li); switch (nfingers) { case 4: litest_touch_down(dev, 3, 70, 30); _fallthrough_; case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } litest_dispatch(li); litest_timeout_gesture_hold(); if (libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, nfingers); } else { litest_assert_empty_queue(li); } switch (nfingers) { case 4: litest_touch_up(dev, 3); _fallthrough_; case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); if (libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, nfingers); } litest_assert_empty_queue(li); } static void test_gesture_hold_cancel(int nfingers) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int last_finger = (nfingers - 1); if (litest_slot_count(dev) < nfingers) return; litest_drain_events(li); switch (nfingers) { case 4: litest_touch_down(dev, 3, 70, 30); _fallthrough_; case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } litest_dispatch(li); litest_timeout_gesture_hold(); litest_touch_up(dev, last_finger); if (libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, nfingers); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, nfingers); } litest_assert_empty_queue(li); } START_TEST(gestures_cap) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT)) litest_assert(!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)); else litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)); } END_TEST START_TEST(gestures_nocap) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)); } END_TEST START_TEST(gestures_swipe_3fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_swipe_3fg_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); double dir_x, dir_y; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) > 2 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) || !libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 40, 40); litest_touch_down(dev, 1, 50, 40); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); dx = libinput_event_gesture_get_dx_unaccelerated(gevent); dy = libinput_event_gesture_get_dy_unaccelerated(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); libinput_event_destroy(event); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } END_TEST START_TEST(gestures_swipe_3fg_btntool_pinch_like) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; if (litest_slot_count(dev) > 2 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) || !libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* Technically a pinch position + pinch movement, but expect swipe * for nfingers > nslots */ litest_touch_down(dev, 0, 20, 60); litest_touch_down(dev, 1, 50, 20); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_touch_move_to(dev, 0, 20, 60, 10, 80, 20); litest_dispatch(li); event = libinput_get_event(li); litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3); libinput_event_destroy(event); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } END_TEST START_TEST(gestures_swipe_4fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_swipe_4fg_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; double dx, dy; enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); double dir_x, dir_y; int cardinals[NCARDINALS][2] = { { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 }, { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 }, }; if (litest_slot_count(dev) > 2 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP) || !libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; dir_x = cardinals[cardinal][0]; dir_y = cardinals[cardinal][1]; litest_drain_events(li); litest_touch_down(dev, 0, 40, 40); litest_touch_down(dev, 1, 50, 40); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); while ((event = libinput_get_event(li)) != NULL) { gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 4); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); dx = libinput_event_gesture_get_dx_unaccelerated(gevent); dy = libinput_event_gesture_get_dy_unaccelerated(gevent); if (dir_x == 0.0) litest_assert(dx == 0.0); else if (dir_x < 0.0) litest_assert(dx < 0.0); else if (dir_x > 0.0) litest_assert(dx > 0.0); if (dir_y == 0.0) litest_assert(dy == 0.0); else if (dir_y < 0.0) litest_assert(dy < 0.0); else if (dir_y > 0.0) litest_assert(dy > 0.0); libinput_event_destroy(event); } litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4); litest_assert(!libinput_event_gesture_get_cancelled(gevent)); libinput_event_destroy(event); } END_TEST START_TEST(gestures_pinch) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_pinch_3fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_pinch_4fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_spread) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_spread(cardinal, HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_gesture *gevent; uint64_t time_usec; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 40, 40); litest_touch_down(dev, 1, 50, 40); litest_touch_down(dev, 2, 60, 40); litest_dispatch(li); litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, 0, 30, 30); litest_dispatch(li); event = libinput_get_event(li); gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); time_usec = libinput_event_gesture_get_time_usec(gevent); litest_assert_int_eq(libinput_event_gesture_get_time(gevent), (uint32_t) (time_usec / 1000)); libinput_event_destroy(event); } END_TEST START_TEST(gestures_3fg_buttonarea_scroll) { test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_IGNORE); } END_TEST START_TEST(gestures_3fg_buttonarea_scroll_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) > 2) return LITEST_NOT_APPLICABLE; litest_enable_buttonareas(dev); litest_enable_2fg_scroll(dev); litest_drain_events(li); /* first finger in btnarea */ litest_touch_down(dev, 0, 20, 99); litest_touch_down(dev, 1, 30, 20); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_touch_move_to(dev, 1, 30, 20, 30, 70, 10); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); } END_TEST START_TEST(gestures_swipe_3fg_unaccel) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double reference_ux = 0, reference_uy = 0; /** * This magic number is an artifact of the acceleration code. * The maximum factor in the touchpad accel profile is 4.8 times the * speed setting (1.000875 at default setting 0). The factor * applied to the const acceleration is the 0.9 baseline. * So our two sets of coordinates are: * accel = 4.8 * delta * normalize_magic * unaccel = 0.9 * delta * normalize_magic * * Since delta and the normalization magic are the same for both, * our accelerated deltas can be a maximum of 4.8/0.9 bigger than * the unaccelerated deltas. * * If any of the accel methods numbers change, this will have to * change here too. */ const double max_factor = 5.34; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 40, 20); litest_touch_down(dev, 1, 50, 20); litest_touch_down(dev, 2, 60, 20); litest_dispatch(li); litest_touch_move_three_touches(dev, 40, 20, 50, 20, 60, 20, 30, 40, 10); litest_dispatch(li); event = libinput_get_event(li); litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); libinput_event_destroy(event); event = libinput_get_event(li); do { struct libinput_event_gesture *gevent; double dx, dy; double ux, uy; gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3); dx = libinput_event_gesture_get_dx(gevent); dy = libinput_event_gesture_get_dy(gevent); ux = libinput_event_gesture_get_dx_unaccelerated(gevent); uy = libinput_event_gesture_get_dy_unaccelerated(gevent); litest_assert_double_ne(ux, 0.0); litest_assert_double_ne(uy, 0.0); if (!reference_ux) reference_ux = ux; if (!reference_uy) reference_uy = uy; /* The unaccelerated delta should be the same for every * event, but we have rounding errors since we only control * input data as percentage of the touchpad size. * so we just eyeball it */ litest_assert_double_gt(ux, reference_ux - 2); litest_assert_double_lt(ux, reference_ux + 2); litest_assert_double_gt(uy, reference_uy - 2); litest_assert_double_lt(uy, reference_uy + 2); /* All our touchpads are large enough to make this is a fast * swipe, we don't expect deceleration, unaccel should * always be less than accel delta */ litest_assert_double_lt(ux, dx); litest_assert_double_lt(ux, dx); /* Check our accelerated delta is within the expected * maximum. */ litest_assert_double_lt(dx, ux * max_factor); litest_assert_double_lt(dy, uy * max_factor); libinput_event_destroy(event); } while ((event = libinput_get_event(li))); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); } END_TEST START_TEST(gestures_hold_config_default_disabled) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device), 0); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_default_enabled(device), LIBINPUT_CONFIG_HOLD_DISABLED); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_default_enabled(device), LIBINPUT_CONFIG_HOLD_DISABLED); } END_TEST START_TEST(gestures_hold_config_default_enabled) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device), 1); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_default_enabled(device), LIBINPUT_CONFIG_HOLD_ENABLED); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device), LIBINPUT_CONFIG_HOLD_ENABLED); } END_TEST START_TEST(gestures_hold_config_set_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(device, -1), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(device, 2), LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(gestures_hold_config_is_available) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device), 1); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device), LIBINPUT_CONFIG_HOLD_ENABLED); litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(device, LIBINPUT_CONFIG_HOLD_DISABLED), LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device), LIBINPUT_CONFIG_HOLD_DISABLED); } END_TEST START_TEST(gestures_hold_config_is_not_available) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device), 0); litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device), LIBINPUT_CONFIG_HOLD_DISABLED); litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(device, LIBINPUT_CONFIG_HOLD_ENABLED), LIBINPUT_CONFIG_STATUS_UNSUPPORTED); litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(device, LIBINPUT_CONFIG_HOLD_DISABLED), LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(gestures_hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); litest_disable_tap(dev->libinput_device); litest_drain_events(li); test_gesture_hold(nfingers); } END_TEST START_TEST(gestures_hold_tap_enabled) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); litest_enable_tap(dev->libinput_device); litest_drain_events(li); test_gesture_hold(nfingers); } END_TEST START_TEST(gestures_hold_cancel) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); litest_disable_tap(dev->libinput_device); litest_drain_events(li); test_gesture_hold_cancel(nfingers); } END_TEST START_TEST(gestures_hold_cancel_tap_enabled) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); litest_enable_tap(dev->libinput_device); litest_drain_events(li); test_gesture_hold_cancel(nfingers); } END_TEST START_TEST(gestures_hold_then_swipe_3fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_swipe_4fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_pinch_2fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_pinch_3fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_pinch_4fg) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_spread) { enum cardinal cardinal = litest_test_param_get_i32(test_env->params, "direction"); test_gesture_spread(cardinal, HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_then_3fg_buttonarea_scroll) { test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_REQUIRE); } END_TEST START_TEST(gestures_hold_once_on_double_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_drain_events(li); /* First tap, a hold gesture must be generated */ litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_gesture_quick_hold(); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* Double tap, don't generate an extra hold gesture */ litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_gesture_quick_hold(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(gestures_hold_once_tap_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; if (!libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_drag_lock(dev->libinput_device); litest_drain_events(li); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: abort(); } switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } litest_dispatch(li); litest_timeout_gesture_quick_hold(); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); /* "Quick" hold gestures are only generated when using 1 or 2 fingers */ if (nfingers == 1 || nfingers == 2) { litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, nfingers); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, nfingers); } /* Tap and drag, don't generate an extra hold gesture */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(gestures_hold_and_motion_before_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1); litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1); litest_dispatch(li); litest_timeout_gesture_quick_hold(); litest_drain_events_of_type(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1); litest_assert_empty_queue(li); } END_TEST START_TEST(gestures_hold_and_motion_after_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_GESTURE)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_gesture_quick_hold(); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1); litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1); litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1); litest_assert_empty_queue(li); } END_TEST START_TEST(gestures_3fg_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; uint32_t finger_count; bool tap_enabled; litest_test_param_fetch(test_env->params, "fingers", 'u', &finger_count, "tap-enabled", 'b', &tap_enabled); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < (int)finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); if (tap_enabled) litest_enable_tap(dev->libinput_device); else litest_disable_tap(dev->libinput_device); litest_drain_events(li); double y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); litest_drain_events_of_type(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); if (tap_enabled) { litest_checkpoint("Expecting no immediate button press as tapping is enabled"); litest_assert_empty_queue(li); } else { litest_checkpoint("Expecting immediate button press as tapping is disabled"); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); } while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } if (tap_enabled) { litest_checkpoint("Expecting late button press as tapping is enabled"); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(gestures_3fg_drag_lock_resume_3fg_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; uint32_t finger_count; bool tap_enabled; bool wait_for_timeout; litest_test_param_fetch(test_env->params, "fingers", 'u', &finger_count, "tap-enabled", 'b', &tap_enabled, "wait", 'b', &wait_for_timeout); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < (int)finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); if (tap_enabled) litest_enable_tap(dev->libinput_device); else litest_disable_tap(dev->libinput_device); litest_drain_events(li); litest_checkpoint("Putting three fingers down + movement)"); double y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_checkpoint("Releasing all fingers"); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Putting three fingers down (no movement)"); y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); litest_assert_empty_queue(li); litest_dispatch(li); litest_checkpoint("Waiting past finger switch timeout"); litest_timeout_finger_switch(); litest_dispatch(li); if (wait_for_timeout) { litest_checkpoint("Waiting past tap/3fg drag timeout"); litest_timeout_3fg_drag(); litest_dispatch(li); litest_assert_empty_queue(li); } litest_checkpoint("Moving three fingers"); while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_checkpoint("Releasing three fingers"); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(gestures_3fg_drag_lock_resume_3fg_release_no_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; uint32_t finger_count; bool tap_enabled; bool wait_for_timeout; litest_test_param_fetch(test_env->params, "fingers", 'u', &finger_count, "tap-enabled", 'b', &tap_enabled, "wait", 'b', &wait_for_timeout); /* tap-enabled for 4fg finger count doesn't make a difference */ bool expect_tap = finger_count <= 3 && tap_enabled && !wait_for_timeout; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < (int)finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); if (tap_enabled) litest_enable_tap(dev->libinput_device); else litest_disable_tap(dev->libinput_device); litest_drain_events(li); litest_checkpoint("Putting 3 fingers down with motion for drag"); double y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Putting 3 fingers down again (no motion)"); y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Waiting past finger switch timeout"); litest_timeout_finger_switch(); litest_dispatch(li); if (wait_for_timeout) { litest_checkpoint("Waiting past tap/3fg drag timeout"); litest_timeout_3fg_drag(); litest_dispatch(li); litest_assert_empty_queue(li); } litest_checkpoint("Releasing three fingers"); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); if (expect_tap) { /* If we're not waiting and tapping is enabled, this is * the equivalent of a 3fg tap within the drag timeout */ litest_checkpoint("Expecting 3fg drag release"); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_checkpoint("Expecting 3fg tap"); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); if (!expect_tap) litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(gestures_3fg_drag_lock_resume_1fg_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; uint32_t finger_count; bool tap_enabled; litest_test_param_fetch(test_env->params, "fingers", 'u', &finger_count, "tap-enabled", 'b', &tap_enabled); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < (int)finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); if (tap_enabled) litest_enable_tap(dev->libinput_device); else litest_disable_tap(dev->libinput_device); litest_drain_events(li); litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag"); double y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_checkpoint("Releasing 3 fingers"); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Putting 1 finger down and moving it"); /* fingers are up, now let's put one finger down and move it */ y = 30.0; litest_touch_down(dev, 0, 10, y); litest_dispatch(li); litest_assert_empty_queue(li); /* We need to wait until the gesture code accepts this is one finger only */ litest_timeout_finger_switch(); litest_dispatch(li); while (y < 60.0) { y += 2; litest_touch_move(dev, 0, 10, y); litest_dispatch(li); } litest_checkpoint("Expecting drag button release and motion"); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); } END_TEST START_TEST(gestures_3fg_drag_lock_resume_2fg_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; uint32_t finger_count; bool tap_enabled; litest_test_param_fetch(test_env->params, "fingers", 'u', &finger_count, "tap-enabled", 'b', &tap_enabled); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < (int)finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); if (tap_enabled) litest_enable_tap(dev->libinput_device); else litest_disable_tap(dev->libinput_device); litest_drain_events(li); litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag"); double y = 30.0; for (uint32_t i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); while (y < 60.0) { y += 2; for (uint32_t i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_checkpoint("Releasing 3 fingers"); for (uint32_t i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Putting 2 fingers down and moving them"); y = 30.0; litest_touch_down(dev, 0, 10, y); litest_touch_down(dev, 1, 20, y); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_finger_switch(); litest_dispatch(li); while (y < 60.0) { y += 2; litest_touch_move(dev, 0, 10, y); litest_touch_move(dev, 1, 20, y); litest_dispatch(li); } litest_checkpoint("Expecting drag button release and scroll"); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); } END_TEST START_TEST(gestures_3fg_drag_lock_resume_1fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int finger_count = litest_test_param_get_i32(test_env->params, "fingers"); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) < finger_count) return LITEST_NOT_APPLICABLE; litest_enable_3fg_drag(dev->libinput_device, finger_count); litest_enable_tap(dev->libinput_device); litest_drain_events(li); litest_checkpoint("Putting 3 fingers down for 3fg drag"); double y = 30.0; for (int i = 0; i < finger_count; i++) litest_touch_down(dev, i, 10 + i, y); litest_dispatch(li); while (y < 60.0) { y += 2; for (int i = 0; i < finger_count; i++) litest_touch_move(dev, i, 10 + i, y); litest_dispatch(li); } litest_drain_events_of_type(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END, -1); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_checkpoint("Releasing 3 fingers"); for (int i = 0; i < finger_count; i++) litest_touch_up(dev, i); litest_dispatch(li); litest_assert_empty_queue(li); litest_checkpoint("Tapping with 1 finger"); /* fingers are up, now let's tap with one finger */ y = 30.0; litest_touch_down(dev, 0, 10, y); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_checkpoint("Expecting drag release followed by 1fg tap"); /* 3fg drag lock must be cancelled */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); /* And a 1fg tap */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_timeout_3fg_drag(); litest_dispatch(li); } END_TEST TEST_COLLECTION(gestures) { litest_add(gestures_cap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_nocap, LITEST_ANY, LITEST_TOUCHPAD); litest_add(gestures_swipe_3fg_btntool_pinch_like, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_3fg_buttonarea_scroll_btntool, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_time_usec, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_hold_config_default_disabled, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY); litest_add(gestures_hold_config_default_enabled, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(gestures_hold_config_set_invalid, LITEST_TOUCHPAD, LITEST_ANY); litest_add(gestures_hold_config_is_available, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(gestures_hold_config_is_not_available, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY); litest_with_parameters(params, "fingers", 'i', 4, 1, 2, 3, 4) { litest_add_parametrized(gestures_hold, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_tap_enabled, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_cancel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_cancel_tap_enabled, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "direction", 'I', 8, litest_named_i32(N), litest_named_i32(NE), litest_named_i32(E), litest_named_i32(SE), litest_named_i32(S), litest_named_i32(SW), litest_named_i32(W), litest_named_i32(NW)) { litest_add_parametrized(gestures_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_swipe_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_swipe_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_pinch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_pinch_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_hold_then_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_add(gestures_hold_then_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_hold_once_on_double_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) { litest_add_parametrized(gestures_hold_once_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_add(gestures_hold_and_motion_before_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(gestures_hold_and_motion_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); { struct litest_parameters *params = litest_parameters_new("fingers", 'u', 2, 3, 4, "tap-enabled", 'b'); litest_add_parametrized(gestures_3fg_drag, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_parameters_unref(params); } { struct litest_parameters *params = litest_parameters_new("fingers", 'u', 2, 3, 4, "tap-enabled", 'b', "wait", 'b'); litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_release_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_parameters_unref(params); } { struct litest_parameters *params = litest_parameters_new("fingers", 'u', 2, 3, 4, "tap-enabled", 'b'); litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(gestures_3fg_drag_lock_resume_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_parameters_unref(params); } litest_with_parameters(params, "fingers", 'i', 2, 3, 4) { litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } /* Timing-sensitive test, valgrind is too slow */ if (!RUNNING_ON_VALGRIND) litest_add(gestures_swipe_3fg_unaccel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); } libinput-1.28.1/test/test-keyboard.c000066400000000000000000000343771477265155700173720ustar00rootroot00000000000000/* * Copyright © 2014 Jonas Ådahl * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include "libinput-util.h" #include "litest.h" START_TEST(keyboard_seat_key_count) { struct litest_device *devices[4]; const int num_devices = ARRAY_LENGTH(devices); struct libinput *libinput; struct libinput_event *ev; struct libinput_event_keyboard *kev; int i; int seat_key_count = 0; int expected_key_button_count = 0; char device_name[255]; libinput = litest_create_context(); for (i = 0; i < num_devices; ++i) { sprintf(device_name, "litest Generic keyboard (%d)", i); devices[i] = litest_add_device_with_overrides(libinput, LITEST_KEYBOARD, device_name, NULL, NULL, NULL); } litest_drain_events(libinput); for (i = 0; i < num_devices; ++i) litest_keyboard_key(devices[i], KEY_A, true); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { kev = litest_is_keyboard_event(ev, KEY_A, LIBINPUT_KEY_STATE_PRESSED); ++expected_key_button_count; seat_key_count = libinput_event_keyboard_get_seat_key_count(kev); litest_assert_int_eq(expected_key_button_count, seat_key_count); libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert_int_eq(seat_key_count, num_devices); for (i = 0; i < num_devices; ++i) litest_keyboard_key(devices[i], KEY_A, false); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { kev = libinput_event_get_keyboard_event(ev); litest_assert_notnull(kev); litest_assert_int_eq(libinput_event_keyboard_get_key(kev), (unsigned int)KEY_A); litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kev), LIBINPUT_KEY_STATE_RELEASED); --expected_key_button_count; seat_key_count = libinput_event_keyboard_get_seat_key_count(kev); litest_assert_int_eq(expected_key_button_count, seat_key_count); libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert_int_eq(seat_key_count, 0); for (i = 0; i < num_devices; ++i) litest_delete_device(devices[i]); litest_destroy_context(libinput); } END_TEST START_TEST(keyboard_ignore_no_pressed_release) { struct litest_device *dev; struct libinput *unused_libinput; struct libinput *libinput; struct libinput_event *event; struct libinput_event_keyboard *kevent; int events[] = { EV_KEY, KEY_A, -1, -1, }; enum libinput_key_state expected_states[] = { LIBINPUT_KEY_STATE_PRESSED, LIBINPUT_KEY_STATE_RELEASED, }; /* We can't send pressed -> released -> pressed events using uinput * as such non-symmetric events are dropped. Work-around this by first * adding the test device to the tested context after having sent an * initial pressed event. */ unused_libinput = litest_create_context(); dev = litest_add_device_with_overrides(unused_libinput, LITEST_KEYBOARD, "Generic keyboard", NULL, NULL, events); litest_keyboard_key(dev, KEY_A, true); litest_drain_events(unused_libinput); libinput = litest_create_context(); libinput_path_add_device(libinput, libevdev_uinput_get_devnode(dev->uinput)); litest_drain_events(libinput); litest_keyboard_key(dev, KEY_A, false); litest_keyboard_key(dev, KEY_A, true); litest_keyboard_key(dev, KEY_A, false); litest_dispatch(libinput); ARRAY_FOR_EACH(expected_states, state) { event = libinput_get_event(libinput); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_KEYBOARD_KEY); kevent = libinput_event_get_keyboard_event(event); litest_assert_int_eq(libinput_event_keyboard_get_key(kevent), (unsigned int)KEY_A); litest_assert_int_eq(libinput_event_keyboard_get_key_state(kevent), *state); libinput_event_destroy(event); litest_dispatch(libinput); } litest_assert_empty_queue(libinput); litest_delete_device(dev); litest_destroy_context(libinput); litest_destroy_context(unused_libinput); } END_TEST START_TEST(keyboard_key_auto_release) { struct libinput *libinput; struct litest_device *dev; struct libinput_event *event; enum libinput_event_type type; struct libinput_event_keyboard *kevent; struct { int code; int released; } keys[] = { { .code = KEY_A, }, { .code = KEY_S, }, { .code = KEY_D, }, { .code = KEY_G, }, { .code = KEY_Z, }, { .code = KEY_DELETE, }, { .code = KEY_F24, }, }; int events[2 * (ARRAY_LENGTH(keys) + 1)]; unsigned i; int key; int valid_code; /* Enable all tested keys on the device */ i = 0; while (i < 2 * ARRAY_LENGTH(keys)) { key = keys[i / 2].code; events[i++] = EV_KEY; events[i++] = key; } events[i++] = -1; events[i++] = -1; libinput = litest_create_context(); dev = litest_add_device_with_overrides(libinput, LITEST_KEYBOARD, "Generic keyboard", NULL, NULL, events); litest_drain_events(libinput); /* Send pressed events, without releasing */ for (i = 0; i < ARRAY_LENGTH(keys); ++i) { key = keys[i].code; litest_event(dev, EV_KEY, key, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(libinput); event = libinput_get_event(libinput); litest_is_keyboard_event(event, key, LIBINPUT_KEY_STATE_PRESSED); libinput_event_destroy(event); } litest_drain_events(libinput); /* "Disconnect" device */ litest_delete_device(dev); /* Mark all released keys until device is removed */ while (1) { event = libinput_get_event(libinput); litest_assert_notnull(event); type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_REMOVED) { libinput_event_destroy(event); break; } litest_assert_event_type(event, LIBINPUT_EVENT_KEYBOARD_KEY); kevent = libinput_event_get_keyboard_event(event); litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kevent), LIBINPUT_KEY_STATE_RELEASED); key = libinput_event_keyboard_get_key(kevent); valid_code = 0; for (i = 0; i < ARRAY_LENGTH(keys); ++i) { if (keys[i].code == key) { litest_assert_int_eq(keys[i].released, 0); keys[i].released = 1; valid_code = 1; } } litest_assert_int_eq(valid_code, 1); libinput_event_destroy(event); } /* Check that all pressed keys has been released. */ for (i = 0; i < ARRAY_LENGTH(keys); ++i) { litest_assert_int_eq(keys[i].released, 1); } litest_destroy_context(libinput); } END_TEST START_TEST(keyboard_has_key) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; unsigned int code; int evdev_has, libinput_has; litest_assert(libinput_device_has_capability( device, LIBINPUT_DEVICE_CAP_KEYBOARD)); for (code = 0; code < KEY_CNT; code++) { evdev_has = libevdev_has_event_code(dev->evdev, EV_KEY, code); libinput_has = libinput_device_keyboard_has_key(device, code); litest_assert_int_eq(evdev_has, libinput_has); } } END_TEST START_TEST(keyboard_keys_bad_device) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; unsigned int code; int has_key; if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) return LITEST_NOT_APPLICABLE; for (code = 0; code < KEY_CNT; code++) { has_key = libinput_device_keyboard_has_key(device, code); litest_assert_int_eq(has_key, -1); } } END_TEST START_TEST(keyboard_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_keyboard *kev; struct libinput_event *event; uint64_t time_usec; if (!libevdev_has_event_code(dev->evdev, EV_KEY, KEY_A)) return LITEST_NOT_APPLICABLE; litest_drain_events(dev->libinput); litest_keyboard_key(dev, KEY_A, true); litest_dispatch(li); event = libinput_get_event(li); kev = litest_is_keyboard_event(event, KEY_A, LIBINPUT_KEY_STATE_PRESSED); time_usec = libinput_event_keyboard_get_time_usec(kev); litest_assert_int_eq(libinput_event_keyboard_get_time(kev), (uint32_t) (time_usec / 1000)); libinput_event_destroy(event); litest_drain_events(dev->libinput); } END_TEST START_TEST(keyboard_no_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int code; const char *name; litest_drain_events(dev->libinput); for (code = 0; code < KEY_MAX; code++) { if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; name = libevdev_event_code_get_name(EV_KEY, code); if (!strstartswith(name, "KEY_")) continue; litest_keyboard_key(dev, code, true); litest_keyboard_key(dev, code, false); litest_dispatch(li); event = libinput_get_event(li); litest_is_keyboard_event(event, code, LIBINPUT_KEY_STATE_PRESSED); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_keyboard_event(event, code, LIBINPUT_KEY_STATE_RELEASED); libinput_event_destroy(event); } } END_TEST START_TEST(keyboard_frame_order) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libevdev_has_event_code(dev->evdev, EV_KEY, KEY_A) || !libevdev_has_event_code(dev->evdev, EV_KEY, KEY_LEFTSHIFT)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 1); litest_event(dev, EV_KEY, KEY_A, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 0); litest_event(dev, EV_KEY, KEY_A, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_RELEASED); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); litest_event(dev, EV_KEY, KEY_A, 1); litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_PRESSED); litest_event(dev, EV_KEY, KEY_A, 0); litest_event(dev, EV_KEY, KEY_LEFTSHIFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); litest_assert_key_event(li, KEY_LEFTSHIFT, LIBINPUT_KEY_STATE_RELEASED); litest_dispatch(li); } END_TEST START_TEST(keyboard_leds) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; /* we can't actually test the results here without physically * looking at the LEDs. So all we do is trigger the code for devices * with and without LEDs and check that it doesn't go boom */ libinput_device_led_update(device, LIBINPUT_LED_NUM_LOCK); libinput_device_led_update(device, LIBINPUT_LED_CAPS_LOCK); libinput_device_led_update(device, LIBINPUT_LED_SCROLL_LOCK); libinput_device_led_update(device, LIBINPUT_LED_COMPOSE); libinput_device_led_update(device, LIBINPUT_LED_KANA); libinput_device_led_update(device, LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK); libinput_device_led_update(device, LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK | LIBINPUT_LED_SCROLL_LOCK); libinput_device_led_update(device, LIBINPUT_LED_NUM_LOCK | LIBINPUT_LED_CAPS_LOCK | LIBINPUT_LED_SCROLL_LOCK | LIBINPUT_LED_COMPOSE | LIBINPUT_LED_KANA); libinput_device_led_update(device, 0); libinput_device_led_update(device, -1); } END_TEST START_TEST(keyboard_no_scroll) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_scroll_method method; enum libinput_config_status status; method = libinput_device_config_scroll_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); method = libinput_device_config_scroll_get_default_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_2FG); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_EDGE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST TEST_COLLECTION(keyboard) { litest_add_no_device(keyboard_seat_key_count); litest_add_no_device(keyboard_ignore_no_pressed_release); litest_add_no_device(keyboard_key_auto_release); litest_add(keyboard_has_key, LITEST_KEYS, LITEST_ANY); litest_add(keyboard_keys_bad_device, LITEST_ANY, LITEST_ANY); litest_add(keyboard_time_usec, LITEST_KEYS, LITEST_ANY); litest_add(keyboard_no_buttons, LITEST_KEYS, LITEST_ANY); litest_add(keyboard_frame_order, LITEST_KEYS, LITEST_ANY); litest_add(keyboard_leds, LITEST_ANY, LITEST_ANY); litest_add(keyboard_no_scroll, LITEST_KEYS, LITEST_WHEEL); } libinput-1.28.1/test/test-library-version.c000066400000000000000000000006101477265155700207000ustar00rootroot00000000000000#include #include int main(void) { const char *version = LIBINPUT_LT_VERSION; int C, R, A; int rc; rc = sscanf(version, "%d:%d:%d", &C, &R, &A); assert(rc == 3); assert(C >= 17); assert(R >= 0); assert(A >= 7); /* Binary compatibility broken? */ assert(R != 0 || A != 0); /* The first stable API in 0.12 had 10:0:0 */ assert(C - A == 10); return 0; } libinput-1.28.1/test/test-log.c000066400000000000000000000131631477265155700163410ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include "litest.h" static int log_handler_called; static struct libinput *log_handler_context; static void simple_log_handler(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { log_handler_called++; if (log_handler_context) litest_assert_ptr_eq(libinput, log_handler_context); litest_assert_notnull(format); } static int open_restricted(const char *path, int flags, void *data) { int fd; fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *data) { close(fd); } static const struct libinput_interface simple_interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; START_TEST(log_default_priority) { enum libinput_log_priority pri; struct libinput *li; li = libinput_path_create_context(&simple_interface, NULL); pri = libinput_log_get_priority(li); litest_assert_enum_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR); libinput_unref(li); } END_TEST START_TEST(log_handler_invoked) { struct libinput *li; log_handler_context = NULL; log_handler_called = 0; li = litest_create_context(); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); libinput_log_set_handler(li, simple_log_handler); log_handler_context = li; libinput_path_add_device(li, "/tmp"); litest_assert_int_gt(log_handler_called, 0); litest_destroy_context(li); log_handler_context = NULL; log_handler_called = 0; } END_TEST START_TEST(log_handler_NULL) { struct libinput *li; log_handler_called = 0; li = litest_create_context(); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); libinput_log_set_handler(li, NULL); libinput_path_add_device(li, "/tmp"); litest_assert_int_eq(log_handler_called, 0); litest_destroy_context(li); log_handler_called = 0; } END_TEST START_TEST(log_priority) { struct libinput *li; log_handler_context = NULL; log_handler_called = 0; li = litest_create_context(); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR); libinput_log_set_handler(li, simple_log_handler); log_handler_context = li; libinput_path_add_device(li, "/tmp"); litest_assert_int_eq(log_handler_called, 1); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO); /* event0 exists on any box we care to run the test suite on and we * currently prints *something* for each device */ libinput_path_add_device(li, "/dev/input/event0"); litest_assert_int_gt(log_handler_called, 1); litest_destroy_context(li); log_handler_context = NULL; log_handler_called = 0; } END_TEST static int axisrange_log_handler_called = 0; static void axisrange_warning_log_handler(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { const char *substr; axisrange_log_handler_called++; litest_assert_notnull(format); substr = strstr(format, "is outside expected range"); litest_assert_notnull(substr); } START_TEST(log_axisrange_warning) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; const struct input_absinfo *abs; int axis = litest_test_param_get_i32(test_env->params, "axis"); litest_touch_down(dev, 0, 90, 100); litest_drain_events(li); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO); libinput_log_set_handler(li, axisrange_warning_log_handler); abs = libevdev_get_abs_info(dev->evdev, axis); for (int i = 0; i < 100; i++) { litest_event(dev, EV_ABS, ABS_MT_POSITION_X + axis, abs->maximum * 2 + i); litest_event(dev, EV_ABS, axis, abs->maximum * 2); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } /* Expect only one message per 5 min */ litest_assert_int_eq(axisrange_log_handler_called, 1); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR); litest_restore_log_handler(li); axisrange_log_handler_called = 0; } END_TEST TEST_COLLECTION(log) { litest_add_deviceless(log_default_priority); litest_add_deviceless(log_handler_invoked); litest_add_deviceless(log_handler_NULL); litest_add_no_device(log_priority); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { /* mtdev clips to axis ranges */ litest_add_parametrized(log_axisrange_warning, LITEST_TOUCH, LITEST_PROTOCOL_A, params); litest_add_parametrized(log_axisrange_warning, LITEST_TOUCHPAD, LITEST_ANY, params); } } libinput-1.28.1/test/test-misc.c000066400000000000000000000656701477265155700165250ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include "litest.h" #include "libinput-util.h" static int open_restricted(const char *path, int flags, void *data) { int fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *data) { close(fd); } static const struct libinput_interface simple_interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; static struct libevdev_uinput * create_simple_test_device(const char *name, ...) { va_list args; struct libevdev_uinput *uinput; struct libevdev *evdev; unsigned int type, code; int rc; struct input_absinfo abs = { .value = -1, .minimum = 0, .maximum = 100, .fuzz = 0, .flat = 0, .resolution = 100, }; evdev = libevdev_new(); litest_assert_notnull(evdev); libevdev_set_name(evdev, name); va_start(args, name); while ((type = va_arg(args, unsigned int)) != (unsigned int)-1 && (code = va_arg(args, unsigned int)) != (unsigned int)-1) { const struct input_absinfo *a = NULL; if (type == EV_ABS) a = &abs; libevdev_enable_event_code(evdev, type, code, a); } va_end(args); rc = libevdev_uinput_create_from_device(evdev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput); litest_assert_neg_errno_success(rc); libevdev_free(evdev); return uinput; } START_TEST(event_conversion_device_notify) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_event *event; int device_added = 0, device_removed = 0; uinput = create_simple_test_device("litest test device", EV_REL, REL_X, EV_REL, REL_Y, EV_KEY, BTN_LEFT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_LEFT, -1, -1); li = litest_create_context(); litest_restore_log_handler(li); /* use the default litest handler */ libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_dispatch(li); libinput_suspend(li); libinput_resume(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_ADDED || type == LIBINPUT_EVENT_DEVICE_REMOVED) { struct libinput_event_device_notify *dn; struct libinput_event *base; dn = libinput_event_get_device_notify_event(event); base = libinput_event_device_notify_get_base_event(dn); litest_assert(event == base); if (type == LIBINPUT_EVENT_DEVICE_ADDED) device_added++; else if (type == LIBINPUT_EVENT_DEVICE_REMOVED) device_removed++; litest_disable_log_handler(li); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_destroy_context(li); libevdev_uinput_destroy(uinput); litest_assert_int_gt(device_added, 0); litest_assert_int_gt(device_removed, 0); } END_TEST START_TEST(event_conversion_pointer) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int motion = 0, button = 0; /* Queue at least two relative motion events as the first one may * be absorbed by the pointer acceleration filter. */ litest_event(dev, EV_REL, REL_X, -1); litest_event(dev, EV_REL, REL_Y, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_REL, REL_X, -1); litest_event(dev, EV_REL, REL_Y, -1); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_POINTER_MOTION || type == LIBINPUT_EVENT_POINTER_BUTTON) { struct libinput_event_pointer *p; struct libinput_event *base; p = libinput_event_get_pointer_event(event); base = libinput_event_pointer_get_base_event(p); litest_assert(event == base); if (type == LIBINPUT_EVENT_POINTER_MOTION) motion++; else if (type == LIBINPUT_EVENT_POINTER_BUTTON) button++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(motion, 0); litest_assert_int_gt(button, 0); } END_TEST START_TEST(event_conversion_pointer_abs) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int motion = 0, button = 0; litest_event(dev, EV_ABS, ABS_X, 10); litest_event(dev, EV_ABS, ABS_Y, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_ABS, ABS_X, 30); litest_event(dev, EV_ABS, ABS_Y, 30); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE || type == LIBINPUT_EVENT_POINTER_BUTTON) { struct libinput_event_pointer *p; struct libinput_event *base; p = libinput_event_get_pointer_event(event); base = libinput_event_pointer_get_base_event(p); litest_assert(event == base); if (type == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE) motion++; else if (type == LIBINPUT_EVENT_POINTER_BUTTON) button++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(motion, 0); litest_assert_int_gt(button, 0); } END_TEST START_TEST(event_conversion_key) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int key = 0; litest_event(dev, EV_KEY, KEY_A, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, KEY_A, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_KEYBOARD_KEY) { struct libinput_event_keyboard *k; struct libinput_event *base; k = libinput_event_get_keyboard_event(event); base = libinput_event_keyboard_get_base_event(k); litest_assert(event == base); key++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(key, 0); } END_TEST START_TEST(event_conversion_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int touch = 0; litest_dispatch(li); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_ABS, ABS_X, 10); litest_event(dev, EV_ABS, ABS_Y, 10); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 10); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 10); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type >= LIBINPUT_EVENT_TOUCH_DOWN && type <= LIBINPUT_EVENT_TOUCH_FRAME) { struct libinput_event_touch *t; struct libinput_event *base; t = libinput_event_get_touch_event(event); base = libinput_event_touch_get_base_event(t); litest_assert(event == base); touch++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(touch, 0); } END_TEST START_TEST(event_conversion_gesture) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int gestures = 0; int i; litest_dispatch(li); litest_touch_down(dev, 0, 70, 30); litest_touch_down(dev, 1, 30, 70); litest_dispatch(li); litest_timeout_gesture_hold(); for (i = 0; i < 8; i++) { litest_push_event_frame(dev); litest_touch_move(dev, 0, 70 - i * 5, 30 + i * 5); litest_touch_move(dev, 1, 30 + i * 5, 70 - i * 5); litest_pop_event_frame(dev); litest_dispatch(li); } while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type >= LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN && type <= LIBINPUT_EVENT_GESTURE_HOLD_END) { struct libinput_event_gesture *g; struct libinput_event *base; g = libinput_event_get_gesture_event(event); base = libinput_event_gesture_get_base_event(g); litest_assert(event == base); gestures++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(gestures, 0); } END_TEST START_TEST(event_conversion_tablet) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int events = 0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 50, 50, axes); litest_tablet_motion(dev, 60, 50, axes); litest_button_click(dev, BTN_STYLUS, true); litest_button_click(dev, BTN_STYLUS, false); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type >= LIBINPUT_EVENT_TABLET_TOOL_AXIS && type <= LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { struct libinput_event_tablet_tool *t; struct libinput_event *base; t = libinput_event_get_tablet_tool_event(event); base = libinput_event_tablet_tool_get_base_event(t); litest_assert(event == base); events++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(events, 0); } END_TEST START_TEST(event_conversion_tablet_pad) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int events = 0; litest_button_click(dev, BTN_0, true); litest_pad_ring_start(dev, 10); litest_pad_ring_end(dev); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type >= LIBINPUT_EVENT_TABLET_PAD_BUTTON && type <= LIBINPUT_EVENT_TABLET_PAD_STRIP) { struct libinput_event_tablet_pad *p; struct libinput_event *base; p = libinput_event_get_tablet_pad_event(event); base = libinput_event_tablet_pad_get_base_event(p); litest_assert(event == base); events++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_switch_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(events, 0); } END_TEST START_TEST(event_conversion_switch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int sw = 0; litest_switch_action(dev, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_switch_action(dev, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_SWITCH_TOGGLE) { struct libinput_event_switch *s; struct libinput_event *base; s = libinput_event_get_switch_event(event); base = libinput_event_switch_get_base_event(s); litest_assert(event == base); sw++; litest_disable_log_handler(li); litest_assert(libinput_event_get_device_notify_event(event) == NULL); litest_assert(libinput_event_get_keyboard_event(event) == NULL); litest_assert(libinput_event_get_pointer_event(event) == NULL); litest_assert(libinput_event_get_touch_event(event) == NULL); litest_assert(libinput_event_get_gesture_event(event) == NULL); litest_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_assert(libinput_event_get_tablet_pad_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); } litest_assert_int_gt(sw, 0); } END_TEST START_TEST(context_ref_counting) { struct libinput *li; /* These tests rely on valgrind to detect memory leak and use after * free errors. */ li = libinput_path_create_context(&simple_interface, NULL); litest_assert_notnull(li); litest_assert_ptr_eq(libinput_unref(li), NULL); li = libinput_path_create_context(&simple_interface, NULL); litest_assert_notnull(li); litest_assert_ptr_eq(libinput_ref(li), li); litest_assert_ptr_eq(libinput_unref(li), li); litest_assert_ptr_eq(libinput_unref(li), NULL); } END_TEST START_TEST(config_status_string) { const char *strs[3]; const char *invalid; size_t i, j; strs[0] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_SUCCESS); strs[1] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_UNSUPPORTED); strs[2] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_INVALID); for (i = 0; i < ARRAY_LENGTH(strs) - 1; i++) for (j = i + 1; j < ARRAY_LENGTH(strs); j++) litest_assert_str_ne(strs[i], strs[j]); invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_INVALID + 1); litest_assert(invalid == NULL); invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_SUCCESS - 1); litest_assert(invalid == NULL); } END_TEST static int open_restricted_leak(const char *path, int flags, void *data) { return *(int*)data; } static void close_restricted_leak(int fd, void *data) { /* noop */ } static const struct libinput_interface leak_interface = { .open_restricted = open_restricted_leak, .close_restricted = close_restricted_leak, }; START_TEST(fd_no_event_leak) { struct libevdev_uinput *uinput; struct libinput *li; struct libinput_device *device; int fd = -1; const char *path; struct libinput_event *event; uinput = create_simple_test_device("litest test device", EV_REL, REL_X, EV_REL, REL_Y, EV_KEY, BTN_LEFT, EV_KEY, BTN_MIDDLE, EV_KEY, BTN_LEFT, -1, -1); path = libevdev_uinput_get_devnode(uinput); fd = open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC); litest_assert_int_gt(fd, -1); li = libinput_path_create_context(&leak_interface, &fd); litest_restore_log_handler(li); /* use the default litest handler */ /* Add the device, trigger an event, then remove it again. * Without it, we get a SYN_DROPPED immediately and no events. */ device = libinput_path_add_device(li, path); libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); libinput_path_remove_device(device); litest_dispatch(li); litest_drain_events(li); /* Device is removed, but fd is still open. Queue an event, add a * new device with the same fd, the queued event must be discarded * by libinput */ libevdev_uinput_write_event(uinput, EV_REL, REL_Y, 1); libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); libinput_path_add_device(li, path); litest_dispatch(li); event = libinput_get_event(li); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); litest_assert_empty_queue(li); close(fd); libinput_unref(li); libevdev_uinput_destroy(uinput); } END_TEST static void timer_offset_warning(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { struct litest_user_data *user_data = libinput_get_user_data(libinput); int *warning_triggered = user_data->private; if (priority == LIBINPUT_LOG_PRIORITY_ERROR && strstr(format, "scheduled expiry is in the past")) (*warning_triggered)++; } START_TEST(timer_offset_bug_warning) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int warning_triggered = 0; struct litest_user_data *user_data = libinput_get_user_data(li); litest_enable_tap(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_timeout_tap(); user_data->private = &warning_triggered; libinput_log_set_handler(li, timer_offset_warning); litest_dispatch(li); /* triggered for touch down and touch up */ litest_assert_int_eq(warning_triggered, 2); litest_restore_log_handler(li); } END_TEST static void timer_delay_warning(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { struct litest_user_data *user_data = libinput_get_user_data(libinput); int *warning_triggered = user_data->private; if (priority == LIBINPUT_LOG_PRIORITY_ERROR && strstr(format, "event processing lagging behind by")) (*warning_triggered)++; } START_TEST(timer_delay_bug_warning) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int warning_triggered = 0; struct litest_user_data *user_data = libinput_get_user_data(li); litest_drain_events(li); user_data->private = &warning_triggered; libinput_log_set_handler(li, timer_delay_warning); for (int i = 0; i < 20; i++) { litest_event(dev, EV_REL, REL_X, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); msleep(21); litest_dispatch(li); } litest_assert_int_ge(warning_triggered, 1); litest_restore_log_handler(li); } END_TEST START_TEST(timer_flush) { struct libinput *li; struct litest_device *keyboard, *touchpad; li = litest_create_context(); touchpad = litest_add_device(li, LITEST_SYNAPTICS_TOUCHPAD); litest_enable_tap(touchpad->libinput_device); litest_dispatch(li); keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_dispatch(li); litest_drain_events(li); /* make sure tapping works */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* make sure dwt-tap is ignored */ litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* Ignore 'timer offset negative' warnings */ litest_disable_log_handler(li); /* now mess with the timing - send a key event - expire dwt - send a tap and then call litest_dispatch(). libinput should notice that the tap event came in after the timeout and thus acknowledge the tap. */ litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_timeout_dwt_long(); litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_restore_log_handler(li); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_delete_device(keyboard); litest_delete_device(touchpad); litest_destroy_context(li); } END_TEST START_TEST(udev_absinfo_override) { struct litest_device *dev = litest_current_device(); struct libevdev *evdev = dev->evdev; const struct input_absinfo *abs; struct udev_device *ud; struct udev_list_entry *entry; bool found_x = false, found_y = false, found_mt_x = false, found_mt_y = false; ud = libinput_device_get_udev_device(dev->libinput_device); litest_assert_notnull(ud); /* Custom checks for this special litest device only */ entry = udev_device_get_properties_list_entry(ud); while (entry) { const char *key, *value; key = udev_list_entry_get_name(entry); value = udev_list_entry_get_value(entry); if (streq(key, "EVDEV_ABS_00")) { found_x = true; litest_assert(streq(value, "1:1000:100:10")); } if (streq(key, "EVDEV_ABS_01")) { found_y = true; litest_assert(streq(value, "2:2000:200:20")); } if (streq(key, "EVDEV_ABS_35")) { found_mt_x = true; litest_assert(streq(value, "3:3000:300:30")); } if (streq(key, "EVDEV_ABS_36")) { found_mt_y = true; litest_assert(streq(value, "4:4000:400:40")); } entry = udev_list_entry_get_next(entry); } udev_device_unref(ud); litest_assert(found_x); litest_assert(found_y); litest_assert(found_mt_x); litest_assert(found_mt_y); abs = libevdev_get_abs_info(evdev, ABS_X); litest_assert_int_eq(abs->minimum, 1); litest_assert_int_eq(abs->maximum, 1000); litest_assert_int_eq(abs->resolution, 100); /* if everything goes well, we override the fuzz to 0 */ litest_assert_int_eq(abs->fuzz, 0); abs = libevdev_get_abs_info(evdev, ABS_Y); litest_assert_int_eq(abs->minimum, 2); litest_assert_int_eq(abs->maximum, 2000); litest_assert_int_eq(abs->resolution, 200); /* if everything goes well, we override the fuzz to 0 */ litest_assert_int_eq(abs->fuzz, 0); abs = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X); litest_assert_int_eq(abs->minimum, 3); litest_assert_int_eq(abs->maximum, 3000); litest_assert_int_eq(abs->resolution, 300); /* if everything goes well, we override the fuzz to 0 */ litest_assert_int_eq(abs->fuzz, 0); abs = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y); litest_assert_int_eq(abs->minimum, 4); litest_assert_int_eq(abs->maximum, 4000); litest_assert_int_eq(abs->resolution, 400); /* if everything goes well, we override the fuzz to 0 */ litest_assert_int_eq(abs->fuzz, 0); } END_TEST TEST_COLLECTION(misc) { litest_add_no_device(event_conversion_device_notify); litest_add_for_device(event_conversion_pointer, LITEST_MOUSE); litest_add_for_device(event_conversion_pointer_abs, LITEST_XEN_VIRTUAL_POINTER); litest_add_for_device(event_conversion_key, LITEST_KEYBOARD); litest_add_for_device(event_conversion_touch, LITEST_WACOM_ISDV4_E6_FINGER); litest_add_for_device(event_conversion_gesture, LITEST_BCM5974); litest_add_for_device(event_conversion_tablet, LITEST_WACOM_CINTIQ_12WX_PEN); litest_add_for_device(event_conversion_tablet_pad, LITEST_WACOM_INTUOS5_PAD); litest_add_for_device(event_conversion_switch, LITEST_LID_SWITCH); litest_add_deviceless(context_ref_counting); litest_add_deviceless(config_status_string); litest_add_for_device(timer_offset_bug_warning, LITEST_SYNAPTICS_TOUCHPAD); litest_add_for_device(timer_delay_bug_warning, LITEST_MOUSE); litest_add_no_device(timer_flush); litest_add_no_device(fd_no_event_leak); litest_add_for_device(udev_absinfo_override, LITEST_ABSINFO_OVERRIDE); } libinput-1.28.1/test/test-pad.c000066400000000000000000001000321477265155700163140ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #if HAVE_LIBWACOM #include #endif #include "libinput-util.h" #include "litest.h" START_TEST(pad_cap) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_PAD)); } END_TEST START_TEST(pad_no_cap) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_PAD)); } END_TEST START_TEST(pad_time) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; unsigned int code; uint64_t time, time_usec, oldtime; bool has_buttons = false; litest_drain_events(li); for (code = BTN_0; code < BTN_DIGI; code++) { if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; has_buttons = true; litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); break; } if (!has_buttons) return LITEST_NOT_APPLICABLE; ev = libinput_get_event(li); litest_assert_notnull(ev); litest_assert_event_type(ev, LIBINPUT_EVENT_TABLET_PAD_BUTTON); pev = libinput_event_get_tablet_pad_event(ev); time = libinput_event_tablet_pad_get_time(pev); time_usec = libinput_event_tablet_pad_get_time_usec(pev); litest_assert(time != 0); litest_assert(time == time_usec/1000); libinput_event_destroy(ev); litest_drain_events(li); msleep(10); litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_TABLET_PAD_BUTTON); pev = libinput_event_get_tablet_pad_event(ev); oldtime = time; time = libinput_event_tablet_pad_get_time(pev); time_usec = libinput_event_tablet_pad_get_time_usec(pev); litest_assert(time > oldtime); litest_assert(time != 0); litest_assert(time == time_usec/1000); libinput_event_destroy(ev); } END_TEST START_TEST(pad_num_buttons_libwacom) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; WacomDeviceDatabase *db = NULL; WacomDevice *wacom = NULL; unsigned int nb_lw, nb; db = libwacom_database_new(); litest_assert_notnull(db); wacom = libwacom_new_from_usbid(db, libevdev_get_id_vendor(dev->evdev), libevdev_get_id_product(dev->evdev), NULL); litest_assert_notnull(wacom); nb_lw = libwacom_get_num_buttons(wacom); nb = libinput_device_tablet_pad_get_num_buttons(device); litest_assert_int_eq(nb, nb_lw); libwacom_destroy(wacom); libwacom_database_destroy(db); #endif } END_TEST START_TEST(pad_num_buttons) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; unsigned int code; int nbuttons = 0; for (code = BTN_0; code < KEY_OK; code++) { /* BTN_STYLUS is set for compatibility reasons but not * actually hooked up */ if (code == BTN_STYLUS) continue; if (libevdev_has_event_code(dev->evdev, EV_KEY, code)) nbuttons++; } litest_assert_int_eq(libinput_device_tablet_pad_get_num_buttons(device), nbuttons); } END_TEST START_TEST(pad_button_intuos) { #if !HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int code; unsigned int expected_number = 0; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; unsigned int count = 0; /* Intuos button mapping is sequential up from BTN_0 and continues * with BTN_A */ if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_0)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (code = BTN_0; code < BTN_DIGI; code++) { /* Skip over the BTN_MOUSE and BTN_JOYSTICK range */ if ((code >= BTN_MOUSE && code < BTN_JOYSTICK) || (code >= BTN_DIGI)) { litest_assert(!libevdev_has_event_code(dev->evdev, EV_KEY, code)); continue; } if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); count++; ev = libinput_get_event(li); pev = litest_is_pad_button_event(ev, expected_number, LIBINPUT_BUTTON_STATE_PRESSED); ev = libinput_event_tablet_pad_get_base_event(pev); libinput_event_destroy(ev); ev = libinput_get_event(li); pev = litest_is_pad_button_event(ev, expected_number, LIBINPUT_BUTTON_STATE_RELEASED); ev = libinput_event_tablet_pad_get_base_event(pev); libinput_event_destroy(ev); expected_number++; } litest_assert_empty_queue(li); litest_assert_int_ge(count, 1U); #endif } END_TEST START_TEST(pad_button_bamboo) { #if !HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int code; unsigned int expected_number = 0; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; unsigned int count = 0; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_LEFT)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (code = BTN_LEFT; code < BTN_JOYSTICK; code++) { if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); count++; ev = libinput_get_event(li); pev = litest_is_pad_button_event(ev, expected_number, LIBINPUT_BUTTON_STATE_PRESSED); ev = libinput_event_tablet_pad_get_base_event(pev); libinput_event_destroy(ev); ev = libinput_get_event(li); pev = litest_is_pad_button_event(ev, expected_number, LIBINPUT_BUTTON_STATE_RELEASED); ev = libinput_event_tablet_pad_get_base_event(pev); libinput_event_destroy(ev); expected_number++; } litest_assert_empty_queue(li); litest_assert_int_gt(count, 3U); #endif } END_TEST START_TEST(pad_button_libwacom) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; WacomDeviceDatabase *db = NULL; WacomDevice *wacom = NULL; db = libwacom_database_new(); assert(db); wacom = libwacom_new_from_usbid(db, libevdev_get_id_vendor(dev->evdev), libevdev_get_id_product(dev->evdev), NULL); assert(wacom); litest_drain_events(li); for (int i = 0; i < libwacom_get_num_buttons(wacom); i++) { unsigned int code; code = libwacom_get_button_evdev_code(wacom, 'A' + i); litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); litest_assert_pad_button_event(li, i, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_pad_button_event(li, i, LIBINPUT_BUTTON_STATE_RELEASED); } libwacom_destroy(wacom); libwacom_database_destroy(db); #endif } END_TEST START_TEST(pad_button_mode_groups) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; unsigned int expected_mode = 0; int evdev_codes[KEY_OK - BTN_0] = {0}; #if HAVE_LIBWACOM WacomDeviceDatabase *db = NULL; WacomDevice *wacom = NULL; db = libwacom_database_new(); litest_assert_notnull(db); wacom = libwacom_new_from_usbid(db, libevdev_get_id_vendor(dev->evdev), libevdev_get_id_product(dev->evdev), NULL); if (wacom) { for (size_t i = 0; i < ARRAY_LENGTH(evdev_codes); i++) { evdev_codes[i] = libwacom_get_button_evdev_code(wacom, 'A' + i); } } libwacom_destroy(wacom); libwacom_database_destroy(db); #else for (size_t i = 0; i < ARRAY_LENGTH(evdev_codes); i++) { evdev_codes[i] = BTN_0 + 1; } #endif litest_drain_events(li); for (unsigned int b = 0; b < ARRAY_LENGTH(evdev_codes) && evdev_codes[b] != 0; b++) { unsigned int code = evdev_codes[b]; unsigned int mode, index; struct libinput_tablet_pad_mode_group *group; if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; litest_button_click(dev, code, 1); litest_button_click(dev, code, 0); litest_dispatch(li); switch (code) { case BTN_STYLUS: litest_assert_empty_queue(li); continue; default: break; } ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_TABLET_PAD_BUTTON); pev = libinput_event_get_tablet_pad_event(ev); group = libinput_event_tablet_pad_get_mode_group(pev); #ifdef HAVE_LIBWACOM_BUTTON_MODESWITCH_MODE /* One of the few devices that has very specific mode switch buttons * so we hardcode these here in the test */ if (dev->which == LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD) { switch (code) { case BTN_9: expected_mode = 0; break; case BTN_A: expected_mode = 1; break; case BTN_B: expected_mode = 2; break; case BTN_C: expected_mode = 3; break; default: break; } } else #endif if (libinput_tablet_pad_mode_group_button_is_toggle(group, b)) { int num_modes = libinput_tablet_pad_mode_group_get_num_modes(group); expected_mode = (expected_mode + 1) % num_modes; } mode = libinput_event_tablet_pad_get_mode(pev); litest_assert_int_eq(mode, expected_mode); index = libinput_tablet_pad_mode_group_get_index(group); litest_assert_int_eq(index, 0U); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_TABLET_PAD_BUTTON); pev = libinput_event_get_tablet_pad_event(ev); mode = libinput_event_tablet_pad_get_mode(pev); litest_assert_int_eq(mode, expected_mode); group = libinput_event_tablet_pad_get_mode_group(pev); index = libinput_tablet_pad_mode_group_get_index(group); litest_assert_int_eq(index, 0U); libinput_event_destroy(ev); } litest_assert_empty_queue(li); } END_TEST START_TEST(pad_has_ring) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; int nrings; nrings = libinput_device_tablet_pad_get_num_rings(device); litest_assert_int_ge(nrings, 1); } END_TEST START_TEST(pad_ring) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; int val; double degrees, expected; int min, max; int step_size; int nevents = 0; litest_pad_ring_start(dev, 10); litest_drain_events(li); /* Wacom's 0 value is at 275 degrees */ expected = 270; min = libevdev_get_abs_minimum(dev->evdev, ABS_WHEEL); max = libevdev_get_abs_maximum(dev->evdev, ABS_WHEEL); step_size = 360/(max - min + 1); /* This is a bit strange because we rely on kernel filtering here. The litest_*() functions take a percentage, but mapping this to the pads 72 or 36 range pad ranges is lossy and a bit unpredictable. So instead we increase by a small percentage, expecting *most* events to be filtered by the kernel because they resolve to the same integer value as the previous event. Whenever an event gets through, we expect that to be the next integer value in the range and thus the next step on the circle. */ for (val = 0; val < 100.0; val += 1) { litest_pad_ring_change(dev, val); litest_dispatch(li); ev = libinput_get_event(li); if (!ev) continue; nevents++; pev = litest_is_pad_ring_event(ev, 0, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER); degrees = libinput_event_tablet_pad_get_ring_position(pev); litest_assert_double_ge(degrees, 0.0); litest_assert_double_lt(degrees, 360.0); litest_assert_double_eq(degrees, expected); libinput_event_destroy(ev); expected = fmod(degrees + step_size, 360); } litest_assert_int_eq(nevents, 360/step_size - 1); litest_pad_ring_end(dev); } END_TEST START_TEST(pad_ring_finger_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; double degrees; litest_pad_ring_start(dev, 10); litest_drain_events(li); litest_pad_ring_end(dev); litest_dispatch(li); ev = libinput_get_event(li); pev = litest_is_pad_ring_event(ev, 0, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER); degrees = libinput_event_tablet_pad_get_ring_position(pev); litest_assert_double_eq(degrees, -1.0); libinput_event_destroy(ev); litest_assert_empty_queue(li); } END_TEST START_TEST(pad_has_dial) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; int ndials; int expected_ndials = 1; if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) expected_ndials = 2; ndials = libinput_device_tablet_pad_get_num_dials(device); litest_assert_int_eq(ndials, expected_ndials); } END_TEST START_TEST(pad_dial_low_res) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int code = 0; if (libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) code = REL_WHEEL; if (libevdev_has_event_code(dev->evdev, EV_REL, REL_DIAL)) code = REL_DIAL; litest_drain_events(li); for (int i = 0; i < 10; i++) { int direction = -1 + 2 * i % 2; litest_event(dev, EV_REL, code, direction); if (code == REL_WHEEL) litest_event(dev, EV_REL, REL_WHEEL_HI_RES, direction * 120); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); struct libinput_event *ev = libinput_get_event(li); struct libinput_event_tablet_pad *pev = litest_is_pad_dial_event(ev, 0); double v120 = libinput_event_tablet_pad_get_dial_delta_v120(pev); switch (code) { case REL_WHEEL: /* inverted */ litest_assert_double_eq(v120, -120.0 * direction); break; case REL_DIAL: litest_assert_double_eq(v120, 120.0 * direction); break; default: litest_abort_msg("Invalid dial code"); } libinput_event_destroy(ev); } } END_TEST START_TEST(pad_dial_hi_res) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; const int increment = 30; int accumulated = 0; if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL_HI_RES)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_WHEEL_HI_RES, increment); accumulated += increment; if (accumulated % 120 == 0) litest_event(dev, EV_REL, REL_WHEEL, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); struct libinput_event *ev = libinput_get_event(li); struct libinput_event_tablet_pad *pev = litest_is_pad_dial_event(ev, 0); double v120 = libinput_event_tablet_pad_get_dial_delta_v120(pev); litest_assert_double_eq(v120, -increment); /* REL_WHEEL is inverted */ libinput_event_destroy(ev); } } END_TEST START_TEST(pad_has_strip) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; int nstrips; nstrips = libinput_device_tablet_pad_get_num_strips(device); litest_assert_int_ge(nstrips, 1); } END_TEST START_TEST(pad_strip) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; int val; double pos, expected; litest_pad_strip_start(dev, 10); litest_drain_events(li); expected = 0; /* 9.5 works with the generic axis scaling without jumping over a * value. */ for (val = 0; val < 100; val += 9.5) { litest_pad_strip_change(dev, val); litest_dispatch(li); ev = libinput_get_event(li); pev = litest_is_pad_strip_event(ev, 0, LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER); pos = libinput_event_tablet_pad_get_strip_position(pev); litest_assert_double_ge(pos, 0.0); litest_assert_double_lt(pos, 1.0); /* rounding errors, mostly caused by small physical range */ litest_assert_double_ge(pos, expected - 0.02); litest_assert_double_le(pos, expected + 0.02); libinput_event_destroy(ev); expected = pos + 0.08; } litest_pad_strip_change(dev, 100); litest_dispatch(li); ev = libinput_get_event(li); pev = litest_is_pad_strip_event(ev, 0, LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER); pos = libinput_event_tablet_pad_get_strip_position(pev); litest_assert_double_eq(pos, 1.0); libinput_event_destroy(ev); litest_pad_strip_end(dev); } END_TEST START_TEST(pad_strip_finger_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; double pos; litest_pad_strip_start(dev, 10); litest_drain_events(li); litest_pad_strip_end(dev); litest_dispatch(li); ev = libinput_get_event(li); pev = litest_is_pad_strip_event(ev, 0, LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER); pos = libinput_event_tablet_pad_get_strip_position(pev); litest_assert_double_eq(pos, -1.0); libinput_event_destroy(ev); litest_assert_empty_queue(li); } END_TEST START_TEST(pad_left_handed_default) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; litest_assert(libinput_device_config_left_handed_is_available(device)); litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 0); status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 1); litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); status = libinput_device_config_left_handed_set(dev->libinput_device, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 0); litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); #endif } END_TEST START_TEST(pad_no_left_handed) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; /* Without libwacom we default to left-handed being available */ #if HAVE_LIBWACOM litest_assert(!libinput_device_config_left_handed_is_available(device)); #else litest_assert(libinput_device_config_left_handed_is_available(device)); #endif litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 0); #if HAVE_LIBWACOM enum libinput_config_status status; status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 0); litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); status = libinput_device_config_left_handed_set(dev->libinput_device, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); litest_assert_int_eq(libinput_device_config_left_handed_get(device), 0); litest_assert_int_eq(libinput_device_config_left_handed_get_default(device), 0); #endif } END_TEST START_TEST(pad_left_handed_ring) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_tablet_pad *pev; int val; double degrees, expected; libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_pad_ring_start(dev, 10); litest_drain_events(li); /* Wacom's 0 value is at 275 degrees -> 90 in left-handed mode*/ expected = 90; for (val = 0; val < 100; val += 10) { litest_pad_ring_change(dev, val); litest_dispatch(li); ev = libinput_get_event(li); pev = litest_is_pad_ring_event(ev, 0, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER); degrees = libinput_event_tablet_pad_get_ring_position(pev); litest_assert_double_ge(degrees, 0.0); litest_assert_double_lt(degrees, 360.0); /* rounding errors, mostly caused by small physical range */ litest_assert_double_ge(degrees, expected - 2); litest_assert_double_le(degrees, expected + 2); libinput_event_destroy(ev); expected = fmod(degrees + 36, 360); } litest_pad_ring_end(dev); #endif } END_TEST static bool pad_has_groups(struct litest_device *dev) { bool rc = false; #if HAVE_LIBWACOM WacomDeviceDatabase *db = NULL; WacomDevice *wacom = NULL; db = libwacom_database_new(); litest_assert_notnull(db); wacom = libwacom_new_from_usbid(db, libevdev_get_id_vendor(dev->evdev), libevdev_get_id_product(dev->evdev), NULL); if (wacom && (libwacom_get_ring_num_modes(wacom) != 0 || libwacom_get_ring2_num_modes(wacom) != 0 || libwacom_get_strips_num_modes(wacom) != 0)) rc = true; libwacom_destroy(wacom); libwacom_database_destroy(db); #endif return rc; } START_TEST(pad_mode_groups) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group *group; int ngroups; unsigned int i; ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); litest_assert_int_ge(ngroups, 1); for (i = 0; i < (unsigned int)ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); litest_assert_notnull(group); litest_assert_int_eq(libinput_tablet_pad_mode_group_get_index(group), i); } group = libinput_device_tablet_pad_get_mode_group(device, ngroups); litest_assert(group == NULL); group = libinput_device_tablet_pad_get_mode_group(device, ngroups + 1); litest_assert(group == NULL); } END_TEST START_TEST(pad_mode_groups_userdata) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group *group; int rc; void *userdata = &rc; group = libinput_device_tablet_pad_get_mode_group(device, 0); litest_assert(libinput_tablet_pad_mode_group_get_user_data(group) == NULL); libinput_tablet_pad_mode_group_set_user_data(group, userdata); litest_assert(libinput_tablet_pad_mode_group_get_user_data(group) == &rc); libinput_tablet_pad_mode_group_set_user_data(group, NULL); litest_assert(libinput_tablet_pad_mode_group_get_user_data(group) == NULL); } END_TEST START_TEST(pad_mode_groups_ref) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group *group, *g; group = libinput_device_tablet_pad_get_mode_group(device, 0); g = libinput_tablet_pad_mode_group_ref(group); litest_assert_ptr_eq(g, group); /* We don't expect this to be freed. Any leaks should be caught by * valgrind. */ g = libinput_tablet_pad_mode_group_unref(group); litest_assert_ptr_eq(g, group); } END_TEST START_TEST(pad_mode_group_mode) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group *group; int ngroups; unsigned int nmodes, mode; if (pad_has_groups(dev)) return LITEST_NOT_APPLICABLE; ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); litest_assert_int_ge(ngroups, 1); group = libinput_device_tablet_pad_get_mode_group(device, 0); nmodes = libinput_tablet_pad_mode_group_get_num_modes(group); litest_assert_int_eq(nmodes, 1U); mode = libinput_tablet_pad_mode_group_get_mode(group); litest_assert_int_lt(mode, nmodes); } END_TEST START_TEST(pad_mode_group_has) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group *group; int ngroups, nbuttons, nrings, nstrips; int i, b, r, s; ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); litest_assert_int_ge(ngroups, 1); nbuttons = libinput_device_tablet_pad_get_num_buttons(device); nrings = libinput_device_tablet_pad_get_num_rings(device); nstrips = libinput_device_tablet_pad_get_num_strips(device); for (b = 0; b < nbuttons; b++) { bool found = false; for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); if (libinput_tablet_pad_mode_group_has_button(group, b)) { litest_assert(!found); found = true; } } litest_assert(found); } for (s = 0; s < nstrips; s++) { bool found = false; for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); if (libinput_tablet_pad_mode_group_has_strip(group, s)) { litest_assert(!found); found = true; } } litest_assert(found); } for (r = 0; r < nrings; r++) { bool found = false; for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); if (libinput_tablet_pad_mode_group_has_ring(group, r)) { litest_assert(!found); found = true; } } litest_assert(found); } } END_TEST START_TEST(pad_mode_group_has_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group* group; int ngroups, nbuttons, nrings, nstrips; int i; int rc; ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); litest_assert_int_ge(ngroups, 1); nbuttons = libinput_device_tablet_pad_get_num_buttons(device); nrings = libinput_device_tablet_pad_get_num_rings(device); nstrips = libinput_device_tablet_pad_get_num_strips(device); for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); rc = libinput_tablet_pad_mode_group_has_button(group, nbuttons); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_button(group, nbuttons + 1); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_button(group, 0x1000000); litest_assert_int_eq(rc, 0); } for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); rc = libinput_tablet_pad_mode_group_has_strip(group, nstrips); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_strip(group, nstrips + 1); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_strip(group, 0x1000000); litest_assert_int_eq(rc, 0); } for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); rc = libinput_tablet_pad_mode_group_has_ring(group, nrings); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_ring(group, nrings + 1); litest_assert_int_eq(rc, 0); rc = libinput_tablet_pad_mode_group_has_ring(group, 0x1000000); litest_assert_int_eq(rc, 0); } } END_TEST START_TEST(pad_mode_group_has_no_toggle) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput_tablet_pad_mode_group* group; int ngroups, nbuttons; int i, b; if (pad_has_groups(dev)) return LITEST_NOT_APPLICABLE; ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); litest_assert_int_eq(ngroups, 1); /* Button must not be toggle buttons */ nbuttons = libinput_device_tablet_pad_get_num_buttons(device); for (i = 0; i < ngroups; i++) { group = libinput_device_tablet_pad_get_mode_group(device, i); for (b = 0; b < nbuttons; b++) { litest_assert(!libinput_tablet_pad_mode_group_button_is_toggle( group, b)); } } #endif } END_TEST static bool pad_has_keys(struct litest_device *dev) { struct libevdev *evdev = dev->evdev; return (libevdev_has_event_code(evdev, EV_KEY, KEY_BUTTONCONFIG) || libevdev_has_event_code(evdev, EV_KEY, KEY_ONSCREEN_KEYBOARD) || libevdev_has_event_code(evdev, EV_KEY, KEY_CONTROLPANEL)); } static void pad_key_down(struct litest_device *dev, unsigned int which) { litest_event(dev, EV_ABS, ABS_MISC, 15); litest_event(dev, EV_KEY, which, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); } static void pad_key_up(struct litest_device *dev, unsigned int which) { litest_event(dev, EV_ABS, ABS_MISC, 0); litest_event(dev, EV_KEY, which, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); } START_TEST(pad_keys) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int key; if (!pad_has_keys(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); key = KEY_BUTTONCONFIG; pad_key_down(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED); pad_key_up(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED); key = KEY_ONSCREEN_KEYBOARD; pad_key_down(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED); pad_key_up(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED); key = KEY_CONTROLPANEL; pad_key_down(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED); pad_key_up(dev, key); litest_dispatch(li); litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED); } END_TEST TEST_COLLECTION(pad) { litest_add(pad_cap, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_no_cap, LITEST_ANY, LITEST_TABLET_PAD); litest_add(pad_time, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_num_buttons, LITEST_TABLET_PAD, LITEST_ANY); /* None of our dial devices have libwacom entries */ litest_add(pad_num_buttons_libwacom, LITEST_TABLET_PAD, LITEST_DIAL); litest_add(pad_button_intuos, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_button_bamboo, LITEST_TABLET_PAD, LITEST_ANY); /* None of our dial devices have libwacom entries */ litest_add(pad_button_libwacom, LITEST_TABLET_PAD, LITEST_DIAL); litest_add(pad_button_mode_groups, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_has_ring, LITEST_RING, LITEST_ANY); litest_add(pad_ring, LITEST_RING, LITEST_ANY); litest_add(pad_ring_finger_up, LITEST_RING, LITEST_ANY); litest_add(pad_has_strip, LITEST_STRIP, LITEST_ANY); litest_add(pad_strip, LITEST_STRIP, LITEST_ANY); litest_add(pad_strip_finger_up, LITEST_STRIP, LITEST_ANY); litest_add(pad_has_dial, LITEST_DIAL, LITEST_ANY); litest_add(pad_dial_low_res, LITEST_DIAL, LITEST_ANY); litest_add(pad_dial_hi_res, LITEST_DIAL, LITEST_ANY); litest_add_for_device(pad_left_handed_default, LITEST_WACOM_INTUOS5_PAD); litest_add_for_device(pad_no_left_handed, LITEST_WACOM_INTUOS3_PAD); litest_add_for_device(pad_left_handed_ring, LITEST_WACOM_INTUOS5_PAD); /* None of the current strip tablets are left-handed */ litest_add(pad_mode_groups, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_groups_userdata, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_groups_ref, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_group_mode, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_group_has, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_group_has_invalid, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_mode_group_has_no_toggle, LITEST_TABLET_PAD, LITEST_ANY); litest_add(pad_keys, LITEST_TABLET_PAD, LITEST_ANY); } libinput-1.28.1/test/test-path.c000066400000000000000000000626541477265155700165250ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include "litest.h" #include "libinput-util.h" struct counter { int open_func_count; int close_func_count; }; static int open_restricted_count(const char *path, int flags, void *data) { struct counter *c = data; int fd; c->open_func_count++; fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted_count(int fd, void *data) { struct counter *c = data; c->close_func_count++; close(fd); } static const struct libinput_interface counting_interface = { .open_restricted = open_restricted_count, .close_restricted = close_restricted_count, }; static int open_restricted(const char *path, int flags, void *data) { int fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *data) { close(fd); } static const struct libinput_interface simple_interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; START_TEST(path_create_NULL) { struct libinput *li; struct counter counter; counter.open_func_count = 0; counter.close_func_count = 0; li = libinput_path_create_context(NULL, NULL); litest_assert(li == NULL); li = libinput_path_create_context(&counting_interface, &counter); litest_assert_notnull(li); libinput_unref(li); litest_assert_int_eq(counter.open_func_count, 0); litest_assert_int_eq(counter.close_func_count, 0); } END_TEST START_TEST(path_create_invalid) { struct libinput *li; struct libinput_device *device; const char *path = "/tmp"; struct counter counter; counter.open_func_count = 0; counter.close_func_count = 0; li = libinput_path_create_context(&counting_interface, &counter); litest_assert_notnull(li); litest_disable_log_handler(li); device = libinput_path_add_device(li, path); litest_assert(device == NULL); litest_assert_int_eq(counter.open_func_count, 0); litest_assert_int_eq(counter.close_func_count, 0); litest_restore_log_handler(li); libinput_unref(li); litest_assert_int_eq(counter.close_func_count, 0); } END_TEST START_TEST(path_create_invalid_kerneldev) { struct libinput *li; struct libinput_device *device; const char *path = "/dev/uinput"; struct counter counter; counter.open_func_count = 0; counter.close_func_count = 0; li = libinput_path_create_context(&counting_interface, &counter); litest_assert_notnull(li); litest_disable_log_handler(li); device = libinput_path_add_device(li, path); litest_assert(device == NULL); litest_assert_int_eq(counter.open_func_count, 1); litest_assert_int_eq(counter.close_func_count, 1); litest_restore_log_handler(li); libinput_unref(li); litest_assert_int_eq(counter.close_func_count, 1); } END_TEST START_TEST(path_create_invalid_file) { struct libinput *li; struct libinput_device *device; char path[] = "/tmp/litest_path_XXXXXX"; int fd; struct counter counter; umask(002); fd = mkstemp(path); litest_assert_int_ge(fd, 0); close(fd); counter.open_func_count = 0; counter.close_func_count = 0; li = libinput_path_create_context(&counting_interface, &counter); unlink(path); litest_disable_log_handler(li); litest_assert_notnull(li); device = libinput_path_add_device(li, path); litest_assert(device == NULL); litest_assert_int_eq(counter.open_func_count, 0); litest_assert_int_eq(counter.close_func_count, 0); litest_restore_log_handler(li); libinput_unref(li); litest_assert_int_eq(counter.close_func_count, 0); } END_TEST START_TEST(path_create_pathmax_file) { struct libinput *li; struct libinput_device *device; char *path; struct counter counter; path = zalloc(PATH_MAX * 2); memset(path, 'a', PATH_MAX * 2 - 1); counter.open_func_count = 0; counter.close_func_count = 0; li = libinput_path_create_context(&counting_interface, &counter); litest_set_log_handler_bug(li); litest_assert_notnull(li); device = libinput_path_add_device(li, path); litest_assert(device == NULL); litest_assert_int_eq(counter.open_func_count, 0); litest_assert_int_eq(counter.close_func_count, 0); litest_restore_log_handler(li); libinput_unref(li); litest_assert_int_eq(counter.close_func_count, 0); free(path); } END_TEST START_TEST(path_create_destroy) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; struct counter counter; counter.open_func_count = 0; counter.close_func_count = 0; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&counting_interface, &counter); litest_assert_notnull(li); litest_disable_log_handler(li); litest_assert(libinput_get_user_data(li) == &counter); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); litest_assert_int_eq(counter.open_func_count, 1); libevdev_uinput_destroy(uinput); libinput_unref(li); litest_assert_int_eq(counter.close_func_count, 1); } END_TEST START_TEST(path_force_destroy) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_device *device; li = libinput_path_create_context(&simple_interface, NULL); litest_assert_notnull(li); libinput_ref(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_assert_notnull(device); while (libinput_unref(li) != NULL) ; } END_TEST START_TEST(path_set_user_data) { struct libinput *li; int data1, data2; li = libinput_path_create_context(&simple_interface, &data1); litest_assert_notnull(li); litest_assert(libinput_get_user_data(li) == &data1); libinput_set_user_data(li, &data2); litest_assert(libinput_get_user_data(li) == &data2); libinput_unref(li); } END_TEST START_TEST(path_added_seat) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat; const char *seat_name; litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); seat = libinput_device_get_seat(device); litest_assert_notnull(seat); seat_name = libinput_seat_get_logical_name(seat); litest_assert_str_eq(seat_name, "default"); libinput_event_destroy(event); } END_TEST START_TEST(path_seat_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat1, *seat2; const char *seat1_name; const char *seat2_name = "new seat"; int rc; litest_dispatch(li); event = libinput_get_event(li); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); libinput_device_ref(device); seat1 = libinput_device_get_seat(device); libinput_seat_ref(seat1); seat1_name = libinput_seat_get_logical_name(seat1); libinput_event_destroy(event); litest_drain_events(li); rc = libinput_device_set_seat_logical_name(device, seat2_name); litest_assert_int_eq(rc, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); litest_assert(libinput_event_get_device(event) == device); libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); litest_assert(libinput_event_get_device(event) != device); libinput_device_unref(device); device = libinput_event_get_device(event); seat2 = libinput_device_get_seat(device); litest_assert_str_ne(libinput_seat_get_logical_name(seat2), seat1_name); litest_assert_str_eq(libinput_seat_get_logical_name(seat2), seat2_name); libinput_event_destroy(event); libinput_seat_unref(seat1); /* litest: swap the new device in, so cleanup works */ libinput_device_unref(dev->libinput_device); libinput_device_ref(device); dev->libinput_device = device; } END_TEST START_TEST(path_added_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); litest_assert_notnull(device); libinput_event_destroy(event); } END_TEST START_TEST(path_add_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; char *sysname1 = NULL, *sysname2 = NULL; litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); litest_assert_notnull(device); sysname1 = safe_strdup(libinput_device_get_sysname(device)); libinput_event_destroy(event); litest_assert_empty_queue(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_assert_notnull(device); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(event); litest_assert_notnull(device); sysname2 = safe_strdup(libinput_device_get_sysname(device)); libinput_event_destroy(event); litest_assert_str_eq(sysname1, sysname2); free(sysname1); free(sysname2); } END_TEST START_TEST(path_add_invalid_path) { struct libinput *li; struct libinput_device *device; li = litest_create_context(); litest_disable_log_handler(li); device = libinput_path_add_device(li, "/tmp/"); litest_restore_log_handler(li); litest_assert(device == NULL); litest_dispatch(li); litest_assert_empty_queue(li); litest_destroy_context(li); } END_TEST START_TEST(path_device_sysname) { struct litest_device *dev = litest_current_device(); struct libinput_event *ev; struct libinput_device *device; const char *sysname; litest_dispatch(dev->libinput); ev = libinput_get_event(dev->libinput); litest_assert_notnull(ev); litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(ev); litest_assert_notnull(device); sysname = libinput_device_get_sysname(device); litest_assert_notnull(sysname); litest_assert_int_gt(strlen(sysname), 1U); litest_assert(strchr(sysname, '/') == NULL); litest_assert(strstartswith(sysname, "event")); libinput_event_destroy(ev); } END_TEST START_TEST(path_remove_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; int remove_event = 0; device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_assert_notnull(device); litest_drain_events(li); libinput_path_remove_device(device); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_REMOVED) remove_event++; libinput_event_destroy(event); } litest_assert_int_eq(remove_event, 1); } END_TEST START_TEST(path_double_remove_device) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; int remove_event = 0; device = libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_assert_notnull(device); litest_drain_events(li); libinput_path_remove_device(device); libinput_path_remove_device(device); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_REMOVED) remove_event++; libinput_event_destroy(event); } litest_assert_int_eq(remove_event, 1); } END_TEST START_TEST(path_suspend) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; int rc; void *userdata = &rc; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); libinput_suspend(li); libinput_resume(li); libevdev_uinput_destroy(uinput); libinput_unref(li); } END_TEST START_TEST(path_double_suspend) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; int rc; void *userdata = &rc; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); libinput_suspend(li); libinput_suspend(li); libinput_resume(li); libevdev_uinput_destroy(uinput); libinput_unref(li); } END_TEST START_TEST(path_double_resume) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; int rc; void *userdata = &rc; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); libinput_suspend(li); libinput_resume(li); libinput_resume(li); libevdev_uinput_destroy(uinput); libinput_unref(li); } END_TEST START_TEST(path_add_device_suspend_resume) { struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct libevdev_uinput *uinput1, *uinput2; int rc; int nevents; void *userdata = &rc; uinput1 = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); uinput2 = litest_create_uinput_device("test device 2", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput1)); litest_assert_notnull(device); libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libinput_suspend(li); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libinput_resume(li); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libevdev_uinput_destroy(uinput1); libevdev_uinput_destroy(uinput2); libinput_unref(li); } END_TEST START_TEST(path_add_device_suspend_resume_fail) { struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct libevdev_uinput *uinput1, *uinput2; int rc; int nevents; void *userdata = &rc; uinput1 = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); uinput2 = litest_create_uinput_device("test device 2", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput1)); litest_assert_notnull(device); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); litest_assert_notnull(device); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libinput_suspend(li); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); /* now drop one of the devices */ libevdev_uinput_destroy(uinput1); rc = libinput_resume(li); litest_assert_int_eq(rc, -1); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); /* We expect one device being added, second one fails, * causing a removed event for the first one */ if (type != LIBINPUT_EVENT_DEVICE_ADDED && type != LIBINPUT_EVENT_DEVICE_REMOVED) litest_abort_msg("Unexpected event type"); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libevdev_uinput_destroy(uinput2); libinput_unref(li); } END_TEST START_TEST(path_add_device_suspend_resume_remove_device) { struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct libevdev_uinput *uinput1, *uinput2; int rc; int nevents; void *userdata = &rc; uinput1 = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); uinput2 = litest_create_uinput_device("test device 2", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput1)); litest_assert_notnull(device); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); libinput_device_ref(device); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); libinput_suspend(li); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 2); /* now drop and remove one of the devices */ libevdev_uinput_destroy(uinput2); libinput_path_remove_device(device); libinput_device_unref(device); rc = libinput_resume(li); litest_assert_int_eq(rc, 0); litest_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } litest_assert_int_eq(nevents, 1); libevdev_uinput_destroy(uinput1); libinput_unref(li); } END_TEST START_TEST(path_device_gone) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; struct libinput_event *event; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, NULL); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); litest_drain_events(li); libevdev_uinput_destroy(uinput); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); libinput_unref(li); } END_TEST START_TEST(path_seat_recycle) { struct libinput *li; struct libevdev_uinput *uinput; int rc; void *userdata = &rc; struct libinput_event *ev; struct libinput_device *device; struct libinput_seat *saved_seat = NULL; struct libinput_seat *seat; int data = 0; int found = 0; void *user_data; uinput = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); litest_assert_notnull(li); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); litest_assert_notnull(device); litest_dispatch(li); ev = libinput_get_event(li); litest_assert_notnull(ev); litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(ev); litest_assert_notnull(device); saved_seat = libinput_device_get_seat(device); libinput_seat_set_user_data(saved_seat, &data); libinput_seat_ref(saved_seat); libinput_event_destroy(ev); litest_assert_notnull(saved_seat); litest_assert_empty_queue(li); libinput_suspend(li); litest_drain_events(li); libinput_resume(li); litest_dispatch(li); ev = libinput_get_event(li); litest_assert_notnull(ev); litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_ADDED); device = libinput_event_get_device(ev); litest_assert_notnull(device); seat = libinput_device_get_seat(device); user_data = libinput_seat_get_user_data(seat); if (user_data == &data) { found = 1; litest_assert(seat == saved_seat); } libinput_event_destroy(ev); litest_assert(found == 1); libinput_unref(li); libevdev_uinput_destroy(uinput); } END_TEST START_TEST(path_udev_assign_seat) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int rc; litest_set_log_handler_bug(li); rc = libinput_udev_assign_seat(li, "foo"); litest_assert_int_eq(rc, -1); litest_restore_log_handler(li); } END_TEST START_TEST(path_ignore_device) { struct litest_device *dev; struct libinput *li; struct libinput_device *device; const char *path; dev = litest_create(LITEST_IGNORED_MOUSE, NULL, NULL, NULL, NULL); path = libevdev_uinput_get_devnode(dev->uinput); litest_assert_notnull(path); li = litest_create_context(); device = libinput_path_add_device(li, path); litest_assert(device == NULL); litest_destroy_context(li); litest_delete_device(dev); } END_TEST TEST_COLLECTION(path) { litest_add_no_device(path_create_NULL); litest_add_no_device(path_create_invalid); litest_add_no_device(path_create_invalid_file); litest_add_no_device(path_create_invalid_kerneldev); litest_add_no_device(path_create_pathmax_file); litest_add_no_device(path_create_destroy); litest_add(path_force_destroy, LITEST_ANY, LITEST_ANY); litest_add_no_device(path_set_user_data); litest_add_no_device(path_suspend); litest_add_no_device(path_double_suspend); litest_add_no_device(path_double_resume); litest_add_no_device(path_add_device_suspend_resume); litest_add_no_device(path_add_device_suspend_resume_fail); litest_add_no_device(path_add_device_suspend_resume_remove_device); litest_add_for_device(path_added_seat, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(path_seat_change, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add(path_added_device, LITEST_ANY, LITEST_ANY); litest_add(path_device_sysname, LITEST_ANY, LITEST_ANY); litest_add_for_device(path_add_device, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_no_device(path_add_invalid_path); litest_add_for_device(path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(path_double_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_no_device(path_device_gone); litest_add_no_device(path_seat_recycle); litest_add_for_device(path_udev_assign_seat, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_no_device(path_ignore_device); } libinput-1.28.1/test/test-pointer.c000066400000000000000000003611571477265155700172510ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include "libinput-util.h" #include "litest.h" enum cardinal { N, NE, E, SE, S, SW, W, NW }; static void test_relative_event(struct litest_device *dev, double dx, double dy) { struct libinput *li = dev->libinput; struct libinput_event_pointer *ptrev; struct libinput_event *event; struct udev_device *ud; double ev_dx, ev_dy; double expected_dir; double expected_length; double actual_dir; double actual_length; const char *prop; int dpi = 1000; litest_event(dev, EV_REL, REL_X, dx); litest_event(dev, EV_REL, REL_Y, dy); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); /* low-dpi devices scale up, not down, especially for slow motion. * so a 1 unit movement in a 200dpi mouse still sends a 1 pixel * movement. Work aorund this here by checking for the MOUSE_DPI * property. */ ud = libinput_device_get_udev_device(dev->libinput_device); litest_assert_ptr_notnull(ud); prop = udev_device_get_property_value(ud, "MOUSE_DPI"); if (prop) { dpi = parse_mouse_dpi_property(prop); litest_assert_int_ne(dpi, 0); dx *= 1000.0/dpi; dy *= 1000.0/dpi; } udev_device_unref(ud); expected_length = sqrt(4 * dx*dx + 4 * dy*dy); expected_dir = atan2(dx, dy); ev_dx = libinput_event_pointer_get_dx(ptrev); ev_dy = libinput_event_pointer_get_dy(ptrev); actual_length = sqrt(ev_dx*ev_dx + ev_dy*ev_dy); actual_dir = atan2(ev_dx, ev_dy); /* Check the length of the motion vector (tolerate 1.0 indifference). */ litest_assert_double_ge(fabs(expected_length), actual_length); /* Check the direction of the motion vector (tolerate 2π/4 radians * indifference). */ litest_assert_double_lt(fabs(expected_dir - actual_dir), M_PI_2); libinput_event_destroy(event); litest_drain_events(dev->libinput); } static void disable_button_scrolling(struct litest_device *device) { struct libinput_device *dev = device->libinput_device; enum libinput_config_status status, expected; status = libinput_device_config_scroll_set_method(dev, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); expected = LIBINPUT_CONFIG_STATUS_SUCCESS; litest_assert_int_eq(status, expected); } START_TEST(pointer_motion_relative) { struct litest_device *dev = litest_current_device(); /* send a single event, the first movement is always decelerated by 0.3 */ litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(dev->libinput); litest_drain_events(dev->libinput); test_relative_event(dev, 1, 0); test_relative_event(dev, 1, 1); test_relative_event(dev, 1, -1); test_relative_event(dev, 0, 1); test_relative_event(dev, -1, 0); test_relative_event(dev, -1, 1); test_relative_event(dev, -1, -1); test_relative_event(dev, 0, -1); } END_TEST START_TEST(pointer_motion_relative_zero) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; /* NOTE: this test does virtually nothing. The kernel should not * allow 0/0 events to be passed to userspace. If it ever happens, * let's hope this test fails if we do the wrong thing. */ litest_drain_events(li); for (i = 0; i < 5; i++) { litest_event(dev, EV_REL, REL_X, 0); litest_event(dev, EV_REL, REL_Y, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_assert_empty_queue(li); /* send a single event, the first movement is always decelerated by 0.3 */ litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); libinput_event_destroy(libinput_get_event(li)); litest_assert_empty_queue(li); for (i = 0; i < 5; i++) { litest_event(dev, EV_REL, REL_X, 0); litest_event(dev, EV_REL, REL_Y, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(dev->libinput); } litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_motion_relative_min_decel) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_pointer *ptrev; struct libinput_event *event; double evx, evy; int dx, dy; double len; enum cardinal direction = litest_test_param_get_i32(test_env->params, "direction"); switch(direction) { case N: dx = 0; dy = 1; break; case NE: dx = 1; dy = 1; break; case E: dx = 1; dy = 0; break; case SE: dx = 1; dy = -1; break; case S: dx = 0; dy = -1; break; case SW: dx = -1; dy = -1; break; case W: dx = -1; dy = 0; break; case NW: dx = -1; dy = 1; break; default: litest_abort_msg("Invalid direction %d", direction); } litest_drain_events(dev->libinput); litest_event(dev, EV_REL, REL_X, dx); litest_event(dev, EV_REL, REL_Y, dy); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); evx = libinput_event_pointer_get_dx(ptrev); evy = libinput_event_pointer_get_dy(ptrev); litest_assert((evx == 0.0) == (dx == 0)); litest_assert((evy == 0.0) == (dy == 0)); len = hypot(evx, evy); litest_assert_double_ge(fabs(len), 0.3); libinput_event_destroy(event); } END_TEST static void test_absolute_event(struct litest_device *dev, double x, double y) { struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; double ex, ey; enum libinput_event_type type = LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE; litest_touch_down(dev, 0, x, y); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_int_eq(libinput_event_get_type(event), type); ptrev = libinput_event_get_pointer_event(event); litest_assert_ptr_notnull(ptrev); ex = libinput_event_pointer_get_absolute_x_transformed(ptrev, 100); ey = libinput_event_pointer_get_absolute_y_transformed(ptrev, 100); litest_assert_int_eq((int)(ex + 0.5), (int)x); litest_assert_int_eq((int)(ey + 0.5), (int)y); libinput_event_destroy(event); } START_TEST(pointer_motion_absolute) { struct litest_device *dev = litest_current_device(); litest_drain_events(dev->libinput); test_absolute_event(dev, 0, 100); test_absolute_event(dev, 100, 0); test_absolute_event(dev, 50, 50); } END_TEST START_TEST(pointer_absolute_initial_state) { struct litest_device *dev = litest_current_device(); struct libinput *libinput1, *libinput2; struct libinput_event *ev1, *ev2; struct libinput_event_pointer *p1, *p2; int axis = litest_test_param_get_i32(test_env->params, "axis"); libinput1 = dev->libinput; litest_touch_down(dev, 0, 40, 60); litest_touch_up(dev, 0); /* device is now on some x/y value */ litest_drain_events(libinput1); libinput2 = litest_create_context(); libinput_path_add_device(libinput2, libevdev_uinput_get_devnode(dev->uinput)); litest_drain_events(libinput2); if (axis == ABS_X) litest_touch_down(dev, 0, 40, 70); else litest_touch_down(dev, 0, 70, 60); litest_touch_up(dev, 0); litest_wait_for_event(libinput1); litest_wait_for_event(libinput2); while (libinput_next_event_type(libinput1)) { ev1 = libinput_get_event(libinput1); ev2 = libinput_get_event(libinput2); litest_assert_enum_eq(libinput_event_get_type(ev1), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); litest_assert_enum_eq(libinput_event_get_type(ev1), libinput_event_get_type(ev2)); p1 = libinput_event_get_pointer_event(ev1); p2 = libinput_event_get_pointer_event(ev2); litest_assert_double_eq(libinput_event_pointer_get_absolute_x(p1), libinput_event_pointer_get_absolute_x(p2)); litest_assert_double_eq(libinput_event_pointer_get_absolute_y(p1), libinput_event_pointer_get_absolute_y(p2)); libinput_event_destroy(ev1); libinput_event_destroy(ev2); } litest_destroy_context(libinput2); } END_TEST static void test_unaccel_event(struct litest_device *dev, int dx, int dy) { struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; double ev_dx, ev_dy; litest_event(dev, EV_REL, REL_X, dx); litest_event(dev, EV_REL, REL_Y, dy); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); ev_dx = libinput_event_pointer_get_dx_unaccelerated(ptrev); ev_dy = libinput_event_pointer_get_dy_unaccelerated(ptrev); litest_assert_int_eq(dx, ev_dx); litest_assert_int_eq(dy, ev_dy); libinput_event_destroy(event); litest_drain_events(dev->libinput); } START_TEST(pointer_motion_unaccel) { struct litest_device *dev = litest_current_device(); litest_drain_events(dev->libinput); test_unaccel_event(dev, 10, 0); test_unaccel_event(dev, 10, 10); test_unaccel_event(dev, 10, -10); test_unaccel_event(dev, 0, 10); test_unaccel_event(dev, -10, 0); test_unaccel_event(dev, -10, 10); test_unaccel_event(dev, -10, -10); test_unaccel_event(dev, 0, -10); } END_TEST static void test_button_event(struct litest_device *dev, unsigned int button, int state) { struct libinput *li = dev->libinput; litest_button_click_debounced(dev, li, button, state); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, button, state ? LIBINPUT_BUTTON_STATE_PRESSED : LIBINPUT_BUTTON_STATE_RELEASED); } START_TEST(pointer_button) { struct litest_device *dev = litest_current_device(); disable_button_scrolling(dev); litest_drain_events(dev->libinput); test_button_event(dev, BTN_LEFT, 1); test_button_event(dev, BTN_LEFT, 0); /* press it twice for good measure */ test_button_event(dev, BTN_LEFT, 1); test_button_event(dev, BTN_LEFT, 0); if (libinput_device_pointer_has_button(dev->libinput_device, BTN_RIGHT)) { test_button_event(dev, BTN_RIGHT, 1); test_button_event(dev, BTN_RIGHT, 0); } /* Skip middle button test on trackpoints (used for scrolling) */ if (libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE)) { test_button_event(dev, BTN_MIDDLE, 1); test_button_event(dev, BTN_MIDDLE, 0); } } END_TEST START_TEST(pointer_button_auto_release) { struct libinput *libinput; struct litest_device *dev; struct libinput_event *event; enum libinput_event_type type; struct libinput_event_pointer *pevent; struct { int code; int released; } buttons[] = { { .code = BTN_LEFT, }, { .code = BTN_MIDDLE, }, { .code = BTN_EXTRA, }, { .code = BTN_SIDE, }, { .code = BTN_BACK, }, { .code = BTN_FORWARD, }, { .code = BTN_4, }, }; int events[2 * (ARRAY_LENGTH(buttons) + 1)]; unsigned i; int button; int valid_code; /* Enable all tested buttons on the device */ for (i = 0; i < 2 * ARRAY_LENGTH(buttons);) { button = buttons[i / 2].code; events[i++] = EV_KEY; events[i++] = button; } events[i++] = -1; events[i++] = -1; libinput = litest_create_context(); dev = litest_add_device_with_overrides(libinput, LITEST_MOUSE, "Generic mouse", NULL, NULL, events); litest_drain_events(libinput); /* Send pressed events, without releasing */ for (i = 0; i < ARRAY_LENGTH(buttons); ++i) { test_button_event(dev, buttons[i].code, 1); } litest_drain_events(libinput); /* "Disconnect" device */ litest_delete_device(dev); /* Mark all released buttons until device is removed */ while (1) { event = libinput_get_event(libinput); litest_assert_notnull(event); type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_DEVICE_REMOVED) { libinput_event_destroy(event); break; } litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_BUTTON); pevent = libinput_event_get_pointer_event(event); litest_assert_enum_eq(libinput_event_pointer_get_button_state(pevent), LIBINPUT_BUTTON_STATE_RELEASED); button = libinput_event_pointer_get_button(pevent); valid_code = 0; for (i = 0; i < ARRAY_LENGTH(buttons); ++i) { if (buttons[i].code == button) { litest_assert_int_eq(buttons[i].released, 0); buttons[i].released = 1; valid_code = 1; } } litest_assert_int_eq(valid_code, 1); libinput_event_destroy(event); } /* Check that all pressed buttons has been released. */ for (i = 0; i < ARRAY_LENGTH(buttons); ++i) { litest_assert_int_eq(buttons[i].released, 1); } litest_destroy_context(libinput); } END_TEST START_TEST(pointer_button_has_no_button) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; unsigned int code; litest_assert(!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)); for (code = BTN_LEFT; code < KEY_OK; code++) litest_assert_int_eq(-1, libinput_device_pointer_has_button(device, code)); } END_TEST START_TEST(pointer_recover_from_lost_button_count) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libevdev *evdev = dev->evdev; disable_button_scrolling(dev); litest_drain_events(dev->libinput); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); /* Grab for the release to make libinput lose count */ libevdev_grab(evdev, LIBEVDEV_GRAB); litest_button_click_debounced(dev, li, BTN_LEFT, 0); libevdev_grab(evdev, LIBEVDEV_UNGRAB); litest_assert_empty_queue(li); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_assert_empty_queue(li); litest_button_click_debounced(dev, li, BTN_LEFT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST static inline double wheel_click_count(struct litest_device *dev, int which) { struct udev_device *d; const char *prop = NULL; int count; double angle = 0.0; d = libinput_device_get_udev_device(dev->libinput_device); litest_assert_ptr_notnull(d); if (which == REL_HWHEEL) prop = udev_device_get_property_value(d, "MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL"); if (!prop) prop = udev_device_get_property_value(d, "MOUSE_WHEEL_CLICK_COUNT"); if (!prop) goto out; count = parse_mouse_wheel_click_count_property(prop); litest_assert_int_ne(count, 0); angle = 360.0/count; out: udev_device_unref(d); return angle; } static inline double wheel_click_angle(struct litest_device *dev, int which) { struct udev_device *d; const char *prop = NULL; const int default_angle = 15; double angle; angle = wheel_click_count(dev, which); if (angle != 0.0) return angle; angle = default_angle; d = libinput_device_get_udev_device(dev->libinput_device); litest_assert_ptr_notnull(d); if (which == REL_HWHEEL) prop = udev_device_get_property_value(d, "MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL"); if (!prop) prop = udev_device_get_property_value(d, "MOUSE_WHEEL_CLICK_ANGLE"); if (!prop) goto out; angle = parse_mouse_wheel_click_angle_property(prop); if (angle == 0.0) angle = default_angle; out: udev_device_unref(d); return angle; } static void test_high_and_low_wheel_events_value(struct litest_device *dev, int which, int v120_amount) { struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; enum libinput_pointer_axis axis; enum libinput_pointer_axis_source source; double scroll_step, expected, discrete, v120; scroll_step = wheel_click_angle(dev, which); source = LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; expected = scroll_step * (v120_amount/120); discrete = v120_amount/120; v120 = v120_amount; if (libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device)) { expected *= -1; discrete *= -1; v120 *= -1; } double angle = libinput_device_config_rotation_get_angle(dev->libinput_device); if (angle >= 160.0 && angle <= 220.0) { expected *= -1; discrete *= -1; v120 *= -1; } axis = (which == REL_WHEEL || which == REL_WHEEL_HI_RES) ? LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL : LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; event = libinput_get_event(li); litest_assert_notnull(event); while(event) { ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, axis, source); if (!litest_is_high_res_axis_event(event)) { litest_assert_double_eq( libinput_event_pointer_get_axis_value(ptrev, axis), expected); litest_assert_double_eq( libinput_event_pointer_get_axis_value_discrete(ptrev, axis), discrete); } else { litest_assert_double_eq( libinput_event_pointer_get_scroll_value_v120(ptrev, axis), v120); } libinput_event_destroy(event); event = libinput_get_event(li); } } static void test_wheel_event(struct litest_device *dev, int which, int amount) { struct libinput *li = dev->libinput; int event_amount = amount; /* mouse scroll wheels are 'upside down' */ if (which == REL_WHEEL) event_amount *= -1; litest_event(dev, EV_REL, which, event_amount); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, which, amount * 120); } START_TEST(pointer_scroll_wheel) { struct litest_device *dev = litest_current_device(); litest_drain_events(dev->libinput); /* make sure we hit at least one of the below two conditions */ litest_assert(libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL) || libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)); if (libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) { test_wheel_event(dev, REL_WHEEL, -1); test_wheel_event(dev, REL_WHEEL, 1); test_wheel_event(dev, REL_WHEEL, -5); test_wheel_event(dev, REL_WHEEL, 6); } if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) { test_wheel_event(dev, REL_HWHEEL, -1); test_wheel_event(dev, REL_HWHEEL, 1); test_wheel_event(dev, REL_HWHEEL, -5); test_wheel_event(dev, REL_HWHEEL, 6); } } END_TEST static void test_hi_res_wheel_event(struct litest_device *dev, int which, int v120_amount) { struct libinput *li = dev->libinput; switch(which) { case REL_WHEEL_HI_RES: /* mouse scroll wheels are 'upside down' */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, -1 * v120_amount); litest_event(dev, EV_REL, REL_WHEEL, -1 * v120_amount/120); litest_event(dev, EV_SYN, SYN_REPORT, 0); break; case REL_HWHEEL_HI_RES: litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, v120_amount); litest_event(dev, EV_REL, REL_HWHEEL, v120_amount/120); litest_event(dev, EV_SYN, SYN_REPORT, 0); break; default: abort(); } litest_dispatch(li); test_high_and_low_wheel_events_value(dev, which, v120_amount); } START_TEST(pointer_scroll_wheel_hires) { struct litest_device *dev = litest_current_device(); if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL_HI_RES) && !libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL_HI_RES)) return LITEST_NOT_APPLICABLE; litest_drain_events(dev->libinput); for (int axis = REL_WHEEL_HI_RES; axis <= REL_HWHEEL_HI_RES; axis++) { if (!libevdev_has_event_code(dev->evdev, EV_REL, axis)) continue; test_hi_res_wheel_event(dev, axis, -120); test_hi_res_wheel_event(dev, axis, 120); test_hi_res_wheel_event(dev, axis, -5 * 120); test_hi_res_wheel_event(dev, axis, 6 * 120); test_hi_res_wheel_event(dev, axis, 30); test_hi_res_wheel_event(dev, axis, -60); test_hi_res_wheel_event(dev, axis, -40); test_hi_res_wheel_event(dev, axis, 180); } } END_TEST START_TEST(pointer_scroll_wheel_hires_send_only_lores) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int lores_code, hires_code; int direction; enum libinput_pointer_axis axis = litest_test_param_get_i32(test_env->params, "axis"); switch (axis) { case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL: lores_code = REL_WHEEL; hires_code = REL_WHEEL_HI_RES; direction = -1; break; case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL: lores_code = REL_HWHEEL; hires_code = REL_HWHEEL_HI_RES; direction = 1; break; default: litest_abort_msg("Invalid test axis '%d'", axis); } if (!libevdev_has_event_code(dev->evdev, EV_REL, lores_code) && !libevdev_has_event_code(dev->evdev, EV_REL, hires_code)) return LITEST_NOT_APPLICABLE; /* Device claims to have HI_RES, but doesn't send events for it. Make * sure we handle this correctly. */ litest_drain_events(dev->libinput); litest_set_log_handler_bug(li); litest_event(dev, EV_REL, lores_code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, lores_code, direction * 120); litest_event(dev, EV_REL, lores_code, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, lores_code, direction * -120); litest_event(dev, EV_REL, lores_code, 2); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, lores_code, direction * 240); litest_assert_empty_queue(li); litest_restore_log_handler(li); } END_TEST START_TEST(pointer_scroll_wheel_inhibit_small_deltas) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL_HI_RES) && !libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL_HI_RES)) return LITEST_NOT_APPLICABLE; litest_drain_events(dev->libinput); /* Scroll deltas below the threshold (60) must be ignored */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 15); litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 15); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); /* The accumulated scroll is 30, add 30 to trigger scroll */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 30); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, REL_WHEEL_HI_RES, -60); /* Once the threshold is reached, small scroll deltas are reported */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 5); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, REL_WHEEL_HI_RES, -5); /* When the scroll timeout is triggered, ignore small deltas again */ litest_timeout_wheel_scroll(); litest_event(dev, EV_REL, REL_WHEEL_HI_RES, -15); litest_event(dev, EV_REL, REL_WHEEL_HI_RES, -15); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, 15); litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, 15); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_scroll_wheel_inhibit_dir_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL_HI_RES) && !libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL_HI_RES)) return LITEST_NOT_APPLICABLE; litest_drain_events(dev->libinput); /* Scroll one detent and a bit */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 120); litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 30); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, REL_WHEEL_HI_RES, -150); /* Scroll below the threshold in the oposite direction should be ignored */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, -30); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); /* But should be triggered if the scroll continues in the same direction */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, -120); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, REL_WHEEL_HI_RES, 150); /* Scroll above the threshold in the same dir should be triggered */ litest_event(dev, EV_REL, REL_WHEEL_HI_RES, 80); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); test_high_and_low_wheel_events_value(dev, REL_WHEEL_HI_RES, -80); } END_TEST START_TEST(pointer_scroll_wheel_lenovo_scrollpoint) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; double v; litest_drain_events(dev->libinput); /* Lenovo ScrollPoint has a trackstick instead of a wheel, data sent * via REL_WHEEL is close to x/y coordinate space. */ litest_event(dev, EV_REL, REL_WHEEL, 30); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_REL, REL_WHEEL, -60); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* Hi-res scroll event first */ event = libinput_get_event(li); litest_assert(litest_is_high_res_axis_event(event)); ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); v = libinput_event_pointer_get_scroll_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert_double_eq(v, -30.0); libinput_event_destroy(event); /* legacy lo-res scroll event */ event = libinput_get_event(li); litest_assert(!litest_is_high_res_axis_event(event)); ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); v = libinput_event_pointer_get_axis_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert_double_eq(v, -30.0); libinput_event_destroy(event); /* Hi-res scroll event first */ event = libinput_get_event(li); ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); v = libinput_event_pointer_get_scroll_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert_double_eq(v, 60.0); libinput_event_destroy(event); /* legacy lo-res scroll event */ event = libinput_get_event(li); litest_assert(!litest_is_high_res_axis_event(event)); ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); v = libinput_event_pointer_get_axis_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert_double_eq(v, 60.0); libinput_event_destroy(event); } END_TEST START_TEST(pointer_scroll_natural_defaults) { struct litest_device *dev = litest_current_device(); litest_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); litest_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0); } END_TEST START_TEST(pointer_scroll_natural_defaults_noscroll) { struct litest_device *dev = litest_current_device(); if (libinput_device_config_scroll_has_natural_scroll(dev->libinput_device)) return LITEST_NOT_APPLICABLE; litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); litest_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0); } END_TEST START_TEST(pointer_scroll_natural_enable_config) { struct litest_device *dev = litest_current_device(); enum libinput_config_status status; status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 1); status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); } END_TEST START_TEST(pointer_scroll_natural_wheel) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_drain_events(dev->libinput); libinput_device_config_scroll_set_natural_scroll_enabled(device, 1); /* make sure we hit at least one of the below two conditions */ litest_assert(libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL) || libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)); if (libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) { test_wheel_event(dev, REL_WHEEL, -1); test_wheel_event(dev, REL_WHEEL, 1); test_wheel_event(dev, REL_WHEEL, -5); test_wheel_event(dev, REL_WHEEL, 6); } if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) { test_wheel_event(dev, REL_HWHEEL, -1); test_wheel_event(dev, REL_HWHEEL, 1); test_wheel_event(dev, REL_HWHEEL, -5); test_wheel_event(dev, REL_HWHEEL, 6); } } END_TEST START_TEST(pointer_scroll_has_axis_invalid) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *pev; litest_drain_events(dev->libinput); if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) return LITEST_NOT_APPLICABLE; litest_event(dev, EV_REL, REL_WHEEL, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); pev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); litest_assert_int_eq(libinput_event_pointer_has_axis(pev, -1), 0); litest_assert_int_eq(libinput_event_pointer_has_axis(pev, 2), 0); litest_assert_int_eq(libinput_event_pointer_has_axis(pev, 3), 0); litest_assert_int_eq(libinput_event_pointer_has_axis(pev, 0xffff), 0); libinput_event_destroy(event); } END_TEST START_TEST(pointer_scroll_with_rotation) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device = dev->libinput_device; double angle = litest_test_param_get_double(test_env->params, "angle"); litest_drain_events(li); libinput_device_config_rotation_set_angle(device, angle); /* make sure we hit at least one of the below two conditions */ litest_assert(libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL) || libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)); if (libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) { test_wheel_event(dev, REL_WHEEL, -1); test_wheel_event(dev, REL_WHEEL, 1); test_wheel_event(dev, REL_WHEEL, -5); test_wheel_event(dev, REL_WHEEL, 6); } if (libevdev_has_event_code(dev->evdev, EV_REL, REL_HWHEEL)) { test_wheel_event(dev, REL_HWHEEL, -1); test_wheel_event(dev, REL_HWHEEL, 1); test_wheel_event(dev, REL_HWHEEL, -5); test_wheel_event(dev, REL_HWHEEL, 6); } } END_TEST START_TEST(pointer_seat_button_count) { struct litest_device *devices[4]; const int num_devices = ARRAY_LENGTH(devices); struct libinput *libinput; struct libinput_event *ev; struct libinput_event_pointer *tev; int i; int seat_button_count = 0; int expected_seat_button_count = 0; char device_name[255]; libinput = litest_create_context(); for (i = 0; i < num_devices; ++i) { sprintf(device_name, "litest Generic mouse (%d)", i); devices[i] = litest_add_device_with_overrides(libinput, LITEST_MOUSE, device_name, NULL, NULL, NULL); } for (i = 0; i < num_devices; ++i) litest_button_click_debounced(devices[i], libinput, BTN_LEFT, true); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { if (libinput_event_get_type(ev) != LIBINPUT_EVENT_POINTER_BUTTON) { libinput_event_destroy(ev); litest_dispatch(libinput); continue; } tev = libinput_event_get_pointer_event(ev); litest_assert_notnull(tev); litest_assert_int_eq(libinput_event_pointer_get_button(tev), (unsigned int)BTN_LEFT); litest_assert_enum_eq(libinput_event_pointer_get_button_state(tev), LIBINPUT_BUTTON_STATE_PRESSED); ++expected_seat_button_count; seat_button_count = libinput_event_pointer_get_seat_button_count(tev); litest_assert_int_eq(expected_seat_button_count, seat_button_count); libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert_int_eq(seat_button_count, num_devices); for (i = 0; i < num_devices; ++i) litest_button_click_debounced(devices[i], libinput, BTN_LEFT, false); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { if (libinput_event_get_type(ev) != LIBINPUT_EVENT_POINTER_BUTTON) { libinput_event_destroy(ev); litest_dispatch(libinput); continue; } tev = libinput_event_get_pointer_event(ev); litest_assert_notnull(tev); litest_assert_int_eq(libinput_event_pointer_get_button(tev), (unsigned int)BTN_LEFT); litest_assert_enum_eq(libinput_event_pointer_get_button_state(tev), LIBINPUT_BUTTON_STATE_RELEASED); --expected_seat_button_count; seat_button_count = libinput_event_pointer_get_seat_button_count(tev); litest_assert_int_eq(expected_seat_button_count, seat_button_count); libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert_int_eq(seat_button_count, 0); for (i = 0; i < num_devices; ++i) litest_delete_device(devices[i]); litest_destroy_context(libinput); } END_TEST START_TEST(pointer_no_calibration) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; int rc; float calibration[6] = {0}; rc = libinput_device_config_calibration_has_matrix(d); litest_assert_int_eq(rc, 0); rc = libinput_device_config_calibration_get_matrix(d, calibration); litest_assert_int_eq(rc, 0); rc = libinput_device_config_calibration_get_default_matrix(d, calibration); litest_assert_int_eq(rc, 0); status = libinput_device_config_calibration_set_matrix(d, calibration); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(pointer_left_handed_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; int rc; if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE && libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH) return LITEST_NOT_APPLICABLE; rc = libinput_device_config_left_handed_is_available(d); litest_assert_int_ne(rc, 0); rc = libinput_device_config_left_handed_get(d); litest_assert_int_eq(rc, 0); rc = libinput_device_config_left_handed_get_default(d); litest_assert_int_eq(rc, 0); } END_TEST START_TEST(pointer_left_handed) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_button_click_debounced(dev, li, BTN_LEFT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_button_click_debounced(dev, li, BTN_RIGHT, 1); litest_button_click_debounced(dev, li, BTN_RIGHT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); if (libinput_device_pointer_has_button(d, BTN_MIDDLE)) { litest_button_click_debounced(dev, li, BTN_MIDDLE, 1); litest_button_click_debounced(dev, li, BTN_MIDDLE, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } } END_TEST START_TEST(pointer_left_handed_during_click) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_dispatch(li); /* Change while button is down, expect correct release event */ status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_button_click_debounced(dev, li, BTN_LEFT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(pointer_left_handed_during_click_multiple_buttons) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_pointer_has_button(d, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_dispatch(li); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* No left-handed until all buttons were down */ litest_button_click_debounced(dev, li, BTN_RIGHT, 1); litest_button_click_debounced(dev, li, BTN_RIGHT, 0); litest_button_click_debounced(dev, li, BTN_LEFT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(pointer_left_handed_disable_with_button_down) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_MOUSE); enum libinput_config_status status; status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, 1); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_delete_device(dev); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); struct libinput_event *event = libinput_get_event(li); litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); litest_assert_empty_queue(li); libinput_event_destroy(event); litest_destroy_context(li); } END_TEST START_TEST(pointer_scroll_button) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; /* Make left button switch to scrolling mode */ libinput_device_config_scroll_set_method(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); libinput_device_config_scroll_set_button(dev->libinput_device, BTN_LEFT); litest_drain_events(li); litest_button_scroll(dev, BTN_LEFT, 1, 6); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_button_scroll(dev, BTN_LEFT, 1, -7); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7); litest_button_scroll(dev, BTN_LEFT, 8, 1); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8); litest_button_scroll(dev, BTN_LEFT, -9, 1); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9); /* scroll smaller than the threshold should not generate axis events */ litest_button_scroll(dev, BTN_LEFT, 1, 1); litest_button_scroll(dev, BTN_LEFT, 0, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* Restore default scroll behavior */ libinput_device_config_scroll_set_method(dev->libinput_device, libinput_device_config_scroll_get_default_method( dev->libinput_device)); libinput_device_config_scroll_set_button(dev->libinput_device, libinput_device_config_scroll_get_default_button( dev->libinput_device)); } END_TEST START_TEST(pointer_scroll_button_noscroll) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; uint32_t methods, button; enum libinput_config_status status; methods = libinput_device_config_scroll_get_method(device); litest_assert_int_eq((methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN), 0U); button = libinput_device_config_scroll_get_button(device); litest_assert_int_eq(button, 0U); button = libinput_device_config_scroll_get_default_button(device); litest_assert_int_eq(button, 0U); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_scroll_set_button(device, BTN_LEFT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(pointer_scroll_button_no_event_before_timeout) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; int i; if (!libinput_device_pointer_has_button(device->libinput_device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(device); disable_button_scrolling(device); libinput_device_config_scroll_set_method(device->libinput_device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); libinput_device_config_scroll_set_button(device->libinput_device, BTN_LEFT); litest_drain_events(li); litest_button_click_debounced(device, li, BTN_LEFT, true); litest_assert_empty_queue(li); for (i = 0; i < 10; i++) { litest_event(device, EV_REL, REL_Y, 1); litest_event(device, EV_SYN, SYN_REPORT, 0); } litest_assert_empty_queue(li); litest_timeout_buttonscroll(); litest_dispatch(li); litest_button_click_debounced(device, li, BTN_LEFT, false); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_scroll_button_middle_emulation) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; int i; status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_scroll_set_button(device, BTN_MIDDLE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_RIGHT, 1); litest_dispatch(li); litest_timeout_buttonscroll(); litest_dispatch(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_Y, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); litest_button_click(dev, BTN_LEFT, 0); litest_button_click(dev, BTN_RIGHT, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -1); litest_assert_empty_queue(li); /* Restore default scroll behavior */ libinput_device_config_scroll_set_method(dev->libinput_device, libinput_device_config_scroll_get_default_method( dev->libinput_device)); libinput_device_config_scroll_set_button(dev->libinput_device, libinput_device_config_scroll_get_default_button( dev->libinput_device)); } END_TEST START_TEST(pointer_scroll_button_device_remove_while_down) { struct libinput *li; struct litest_device *dev; li = litest_create_context(); dev = litest_add_device(li, LITEST_MOUSE); libinput_device_config_scroll_set_method(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); libinput_device_config_scroll_set_button(dev->libinput_device, BTN_LEFT); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* delete the device while the timer is still active */ litest_delete_device(dev); litest_dispatch(li); litest_destroy_context(li); } END_TEST static void litest_enable_scroll_button_lock(struct litest_device *dev, unsigned int button) { struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_scroll_set_button(device, button); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_scroll_set_button_lock(device, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } START_TEST(pointer_scroll_button_lock) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_scroll_button_lock(dev, BTN_LEFT); litest_disable_middleemu(dev); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_empty_queue(li); litest_timeout_buttonscroll(); litest_dispatch(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_assert_empty_queue(li); /* back to motion */ for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(pointer_scroll_button_lock_defaults) { struct litest_device *dev = litest_current_device(); enum libinput_config_scroll_button_lock_state state; state = libinput_device_config_scroll_get_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); state = libinput_device_config_scroll_get_default_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); } END_TEST START_TEST(pointer_scroll_button_lock_config) { struct litest_device *dev = litest_current_device(); enum libinput_config_status status; enum libinput_config_scroll_button_lock_state state; state = libinput_device_config_scroll_get_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); state = libinput_device_config_scroll_get_default_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); status = libinput_device_config_scroll_set_button_lock(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); state = libinput_device_config_scroll_get_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED); status = libinput_device_config_scroll_set_button_lock(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); state = libinput_device_config_scroll_get_button_lock(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED); status = libinput_device_config_scroll_set_button_lock(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED + 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(pointer_scroll_button_lock_enable_while_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_LEFT, true); /* Enable lock while button is down */ litest_enable_scroll_button_lock(dev, BTN_LEFT); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } /* no scrolling yet */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* but on the next button press we scroll lock */ litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_dispatch(li); litest_timeout_buttonscroll(); litest_dispatch(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_assert_empty_queue(li); /* back to motion */ for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(pointer_scroll_button_lock_enable_while_down_just_lock) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); /* switch method first, but enable lock when we already have a * button down */ libinput_device_config_scroll_set_method(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); libinput_device_config_scroll_set_button(dev->libinput_device, BTN_LEFT); litest_button_click_debounced(dev, li, BTN_LEFT, true); libinput_device_config_scroll_set_button_lock(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } /* no scrolling yet */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* but on the next button press we scroll lock */ litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_dispatch(li); litest_timeout_buttonscroll(); litest_dispatch(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_assert_empty_queue(li); /* back to motion */ for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(pointer_scroll_button_lock_otherbutton) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); litest_enable_scroll_button_lock(dev, BTN_LEFT); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_empty_queue(li); litest_timeout_buttonscroll(); litest_dispatch(li); /* other button passes on normally */ litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); /* other button passes on normally */ litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); /* stop scroll lock */ litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); /* other button passes on normally */ litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_scroll_button_lock_enable_while_otherbutton_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_timeout_middlebutton(); litest_drain_events(li); /* Enable lock while button is down */ litest_enable_scroll_button_lock(dev, BTN_LEFT); /* We only enable once we go to a neutral state so this still counts * as normal button event */ for (int twice = 0; twice < 2; twice++) { litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* now we should trigger it */ litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_timeout_buttonscroll(); litest_assert_empty_queue(li); for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_assert_empty_queue(li); /* back to motion */ for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST enum mb_buttonorder { LLRR, /* left down, left up, r down, r up */ LRLR, /* left down, right down, left up, right up */ LRRL, RRLL, RLRL, RLLR }; START_TEST(pointer_scroll_button_lock_middlebutton) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; enum mb_buttonorder buttonorder = litest_test_param_get_i32(test_env->params, "buttonorder"); if (!libinput_device_config_middle_emulation_is_available(dev->libinput_device)) return LITEST_NOT_APPLICABLE; litest_enable_middleemu(dev); litest_enable_scroll_button_lock(dev, BTN_LEFT); litest_drain_events(li); /* We expect scroll lock to work only where left and right are never * held down simultaneously. Everywhere else we expect middle button * instead. */ switch (buttonorder) { case LLRR: litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); break; case LRLR: litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_button_click_debounced(dev, li, BTN_RIGHT, false); break; case LRRL: litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_button_click_debounced(dev, li, BTN_LEFT, false); break; case RRLL: litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); break; case RLRL: litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_button_click_debounced(dev, li, BTN_LEFT, false); break; case RLLR: litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_button_click_debounced(dev, li, BTN_RIGHT, false); break; default: abort(); } litest_dispatch(li); litest_timeout_middlebutton(); litest_timeout_buttonscroll(); litest_dispatch(li); /* motion events are the same for all of them */ for (int i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 6); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); switch (buttonorder) { case LLRR: case RRLL: litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); break; default: break; } litest_dispatch(li); switch (buttonorder) { case LLRR: case RRLL: litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_assert_empty_queue(li); break; case LRLR: case LRRL: case RLRL: case RLLR: litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); break; default: abort(); } } END_TEST START_TEST(pointer_scroll_button_lock_doubleclick_nomove) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_enable_scroll_button_lock(dev, BTN_LEFT); litest_drain_events(li); /* double click without move in between counts as single click */ litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_empty_queue(li); litest_button_click_debounced(dev, li, BTN_LEFT, true); litest_button_click_debounced(dev, li, BTN_LEFT, false); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* But a non-scroll button it should work normally */ litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_button_click_debounced(dev, li, BTN_RIGHT, true); litest_button_click_debounced(dev, li, BTN_RIGHT, false); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_scroll_nowheel_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_scroll_method method, expected; uint32_t button; /* button scrolling is only enabled if there is a middle button present */ if (libinput_device_pointer_has_button(device, BTN_MIDDLE) && dev->which != LITEST_LENOVO_SCROLLPOINT) expected = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; else expected = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; method = libinput_device_config_scroll_get_method(device); litest_assert_int_eq(method, expected); method = libinput_device_config_scroll_get_default_method(device); litest_assert_int_eq(method, expected); if (method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) { button = libinput_device_config_scroll_get_button(device); litest_assert_int_eq(button, (unsigned int)BTN_MIDDLE); button = libinput_device_config_scroll_get_default_button(device); litest_assert_int_eq(button, (unsigned int)BTN_MIDDLE); } } END_TEST START_TEST(pointer_scroll_defaults_logitech_marble) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_scroll_method method; uint32_t button; method = libinput_device_config_scroll_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); method = libinput_device_config_scroll_get_default_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); button = libinput_device_config_scroll_get_button(device); litest_assert_int_eq(button, (unsigned int)BTN_SIDE); } END_TEST START_TEST(pointer_accel_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; double speed; litest_assert(libinput_device_config_accel_is_available(device)); litest_assert_double_eq(libinput_device_config_accel_get_default_speed(device), 0.0); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 0.0); for (speed = -2.0; speed < -1.0; speed += 0.2) { status = libinput_device_config_accel_set_speed(device, speed); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 0.0); } for (speed = -1.0; speed <= 1.0; speed += 0.2) { status = libinput_device_config_accel_set_speed(device, speed); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), speed); } for (speed = 1.2; speed <= 2.0; speed += 0.2) { status = libinput_device_config_accel_set_speed(device, speed); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 1.0); } } END_TEST START_TEST(pointer_accel_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; litest_assert(libinput_device_config_accel_is_available(device)); status = libinput_device_config_accel_set_speed(device, NAN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_speed(device, INFINITY); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(pointer_accel_defaults_absolute) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; double speed; litest_assert(!libinput_device_config_accel_is_available(device)); litest_assert_double_eq(libinput_device_config_accel_get_default_speed(device), 0.0); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 0.0); for (speed = -2.0; speed <= 2.0; speed += 0.2) { status = libinput_device_config_accel_set_speed(device, speed); if (speed >= -1.0 && speed <= 1.0) litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); else litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 0.0); } } END_TEST START_TEST(pointer_accel_defaults_absolute_relative) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(libinput_device_config_accel_is_available(device)); litest_assert_double_eq(libinput_device_config_accel_get_default_speed(device), 0.0); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 0.0); } END_TEST START_TEST(pointer_accel_direction_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *pev; int i; double delta; litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_X, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); do { pev = libinput_event_get_pointer_event(event); delta = libinput_event_pointer_get_dx(pev); litest_assert_double_le(delta, 0.0); libinput_event_destroy(event); event = libinput_get_event(li); } while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE); pev = libinput_event_get_pointer_event(event); delta = libinput_event_pointer_get_dx(pev); litest_assert_double_gt(delta, 0.0); libinput_event_destroy(event); } END_TEST START_TEST(pointer_accel_profile_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_accel_profile profile; uint32_t profiles; litest_assert(libinput_device_config_accel_is_available(device)); profile = libinput_device_config_accel_get_default_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); profiles = libinput_device_config_accel_get_profiles(device); litest_assert(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); litest_assert(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); profile = libinput_device_config_accel_get_default_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); } END_TEST START_TEST(pointer_accel_config_reset_to_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; double default_speed = libinput_device_config_accel_get_default_speed(device); /* There are no settings for these profiles to toggle, so we expect it * to simply reset to defaults */ enum libinput_config_accel_profile profiles[] = { LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, }; ARRAY_FOR_EACH(profiles, profile) { litest_assert_enum_eq(libinput_device_config_accel_set_speed(device, 1.0), LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), 1.0); struct libinput_config_accel *config = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); litest_assert_enum_eq(libinput_device_config_accel_apply(device, config), LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_double_eq(libinput_device_config_accel_get_speed(device), default_speed); libinput_config_accel_destroy(config); } } END_TEST START_TEST(pointer_accel_config) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_accel_profile profile; enum libinput_config_status valid = LIBINPUT_CONFIG_STATUS_SUCCESS, invalid = LIBINPUT_CONFIG_STATUS_INVALID; enum libinput_config_accel_type accel_types[] = { LIBINPUT_ACCEL_TYPE_FALLBACK, LIBINPUT_ACCEL_TYPE_MOTION, LIBINPUT_ACCEL_TYPE_SCROLL, }; struct custom_config_test { double step; double points[4]; enum libinput_config_status expected_status; } tests[] = { { 0.5, { 1.0, 2.0, 2.5, 2.6 }, valid }, { 0.003, { 0.1, 0.3, 0.4, 0.45 }, valid }, { 2.7, { 1.0, 3.0, 4.5, 4.5 }, valid }, { 0, { 1.0, 2.0, 2.5, 2.6 }, invalid }, { -1, { 1.0, 2.0, 2.5, 2.6 }, invalid }, { 1e10, { 1.0, 2.0, 2.5, 2.6 }, invalid }, { 1, { 1.0, 2.0, -2.5, 2.6 }, invalid }, { 1, { 1.0, 2.0, 1e10, 2.6 }, invalid }, }; litest_assert(libinput_device_config_accel_is_available(device)); struct libinput_config_accel *config_custom_default = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); struct libinput_config_accel *config_custom_changed = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); litest_assert_ptr_notnull(config_custom_default); litest_assert_ptr_notnull(config_custom_changed); ARRAY_FOR_EACH(tests, t) { ARRAY_FOR_EACH(accel_types, accel_type) { status = libinput_config_accel_set_points(config_custom_changed, *accel_type, t->step, ARRAY_LENGTH(t->points), t->points); litest_assert_int_eq(status, t->expected_status); status = libinput_device_config_accel_apply(device, config_custom_changed); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); status = libinput_device_config_accel_apply(device, config_custom_default); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); } } libinput_config_accel_destroy(config_custom_default); libinput_config_accel_destroy(config_custom_changed); } END_TEST START_TEST(pointer_accel_profile_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; litest_assert(libinput_device_config_accel_is_available(device)); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE + 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM |LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(pointer_accel_profile_noaccel) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_accel_profile profile; litest_assert(!libinput_device_config_accel_is_available(device)); profile = libinput_device_config_accel_get_default_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE + 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(pointer_accel_profile_flat_motion_relative) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_drain_events(dev->libinput); test_relative_event(dev, 1, 0); test_relative_event(dev, 1, 1); test_relative_event(dev, 1, -1); test_relative_event(dev, 0, 1); test_relative_event(dev, -1, 0); test_relative_event(dev, -1, 1); test_relative_event(dev, -1, -1); test_relative_event(dev, 0, -1); } END_TEST START_TEST(middlebutton) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int i; const int btn[][4] = { { BTN_LEFT, BTN_RIGHT, BTN_LEFT, BTN_RIGHT }, { BTN_LEFT, BTN_RIGHT, BTN_RIGHT, BTN_LEFT }, { BTN_RIGHT, BTN_LEFT, BTN_LEFT, BTN_RIGHT }, { BTN_RIGHT, BTN_LEFT, BTN_RIGHT, BTN_LEFT }, }; disable_button_scrolling(device); status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (i = 0; i < ARRAY_LENGTH(btn); i++) { litest_button_click_debounced(device, li, btn[i][0], true); litest_button_click_debounced(device, li, btn[i][1], true); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, btn[i][2], false); litest_button_click_debounced(device, li, btn[i][3], false); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(middlebutton_nostart_while_down) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int i; const int btn[][4] = { { BTN_LEFT, BTN_RIGHT, BTN_LEFT, BTN_RIGHT }, { BTN_LEFT, BTN_RIGHT, BTN_RIGHT, BTN_LEFT }, { BTN_RIGHT, BTN_LEFT, BTN_LEFT, BTN_RIGHT }, { BTN_RIGHT, BTN_LEFT, BTN_RIGHT, BTN_LEFT }, }; if (!libinput_device_pointer_has_button(device->libinput_device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; disable_button_scrolling(device); status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_button_click_debounced(device, li, BTN_MIDDLE, true); litest_drain_events(li); for (i = 0; i < ARRAY_LENGTH(btn); i++) { litest_button_click_debounced(device, li, btn[i][0], true); litest_assert_button_event(li, btn[i][0], LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click_debounced(device, li, btn[i][1], true); litest_assert_button_event(li, btn[i][1], LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, btn[i][2], false); litest_assert_button_event(li, btn[i][2], LIBINPUT_BUTTON_STATE_RELEASED); litest_button_click_debounced(device, li, btn[i][3], false); litest_assert_button_event(li, btn[i][3], LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } litest_button_click_debounced(device, li, BTN_MIDDLE, false); litest_drain_events(li); } END_TEST START_TEST(middlebutton_timeout) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int button; disable_button_scrolling(device); status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; for (button = BTN_LEFT; button <= BTN_RIGHT; button++) { litest_drain_events(li); litest_button_click_debounced(device, li, button, true); litest_assert_empty_queue(li); litest_timeout_middlebutton(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click_debounced(device, li, button, false); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(middlebutton_doubleclick) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int i; const int btn[][4] = { { BTN_LEFT, BTN_RIGHT, BTN_LEFT, BTN_RIGHT }, { BTN_LEFT, BTN_RIGHT, BTN_RIGHT, BTN_LEFT }, { BTN_RIGHT, BTN_LEFT, BTN_LEFT, BTN_RIGHT }, { BTN_RIGHT, BTN_LEFT, BTN_RIGHT, BTN_LEFT }, }; disable_button_scrolling(device); status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (i = 0; i < ARRAY_LENGTH(btn); i++) { litest_button_click_debounced(device, li, btn[i][0], true); litest_button_click_debounced(device, li, btn[i][1], true); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, btn[i][2], false); litest_button_click_debounced(device, li, btn[i][2], true); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click_debounced(device, li, btn[i][3], false); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(middlebutton_middleclick) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int button; disable_button_scrolling(device); if (!libinput_device_pointer_has_button(device->libinput_device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; /* one button down, then middle -> release buttons */ for (button = BTN_LEFT; button <= BTN_RIGHT; button++) { /* release button before middle */ litest_drain_events(li); litest_button_click_debounced(device, li, button, true); litest_button_click_debounced(device, li, BTN_MIDDLE, true); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, button, false); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_button_click_debounced(device, li, BTN_MIDDLE, false); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* release middle before button */ litest_button_click_debounced(device, li, button, true); litest_button_click_debounced(device, li, BTN_MIDDLE, true); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, BTN_MIDDLE, false); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_button_click_debounced(device, li, button, false); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(middlebutton_middleclick_during) { struct litest_device *device = litest_current_device(); struct libinput *li = device->libinput; enum libinput_config_status status; unsigned int button; disable_button_scrolling(device); if (!libinput_device_pointer_has_button(device->libinput_device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_middle_emulation_set_enabled( device->libinput_device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* trigger emulation, then real middle */ for (button = BTN_LEFT; button <= BTN_RIGHT; button++) { litest_button_click_debounced(device, li, BTN_LEFT, true); litest_button_click_debounced(device, li, BTN_RIGHT, true); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click_debounced(device, li, BTN_MIDDLE, true); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); /* middle still down, release left/right */ litest_button_click_debounced(device, li, button, false); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, button, true); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); /* release both */ litest_button_click_debounced(device, li, BTN_LEFT, false); litest_button_click_debounced(device, li, BTN_RIGHT, false); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_button_click_debounced(device, li, BTN_MIDDLE, false); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(middlebutton_default_enabled) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; int available; enum libinput_config_middle_emulation_state state; if (!libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; available = libinput_device_config_middle_emulation_is_available(device); litest_assert(available); state = libinput_device_config_middle_emulation_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); state = libinput_device_config_middle_emulation_get_default_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_middle_emulation_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(middlebutton_default_clickpad) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_middle_emulation_state state; int available; available = libinput_device_config_middle_emulation_is_available(device); litest_assert(available); state = libinput_device_config_middle_emulation_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); state = libinput_device_config_middle_emulation_get_default_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_middle_emulation_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(middlebutton_default_touchpad) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_middle_emulation_state state; int available; const char *name = libinput_device_get_name(dev->libinput_device); if (streq(name, "litest AlpsPS/2 ALPS GlidePoint") || streq(name, "litest AlpsPS/2 ALPS DualPoint TouchPad")) return LITEST_NOT_APPLICABLE; available = libinput_device_config_middle_emulation_is_available(device); litest_assert(!available); if (libinput_device_pointer_has_button(device, BTN_MIDDLE)) return LITEST_NOT_APPLICABLE; state = libinput_device_config_middle_emulation_get_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); state = libinput_device_config_middle_emulation_get_default_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); } END_TEST START_TEST(middlebutton_default_alps) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_middle_emulation_state state; int available; available = libinput_device_config_middle_emulation_is_available(device); litest_assert(available); state = libinput_device_config_middle_emulation_get_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); state = libinput_device_config_middle_emulation_get_default_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); } END_TEST START_TEST(middlebutton_default_disabled) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_middle_emulation_state state; enum libinput_config_status status; int available; available = libinput_device_config_middle_emulation_is_available(device); litest_assert(!available); state = libinput_device_config_middle_emulation_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); state = libinput_device_config_middle_emulation_get_default_enabled( device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(middlebutton_button_scrolling) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; struct libinput_event *ev; struct libinput_event_pointer *pev; int i; status = libinput_device_config_middle_emulation_set_enabled( device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; status = libinput_device_config_scroll_set_button(device, BTN_LEFT); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* middle emulation discards */ litest_assert_empty_queue(li); litest_timeout_middlebutton(); litest_dispatch(li); /* scroll discards */ litest_assert_empty_queue(li); litest_timeout_buttonscroll(); litest_dispatch(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_REL, REL_Y, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } ev = libinput_get_event(li); do { pev = litest_is_axis_event(ev, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); litest_assert_double_gt(litest_event_pointer_get_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), 0.0); libinput_event_destroy(ev); ev = libinput_get_event(li); } while (ev); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_axis_end_sequence(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); /* no button release */ litest_assert_empty_queue(li); } END_TEST START_TEST(middlebutton_button_scrolling_middle) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; status = libinput_device_config_middle_emulation_set_enabled( device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; status = libinput_device_config_scroll_set_button(device, BTN_LEFT); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* button scrolling should not stop middle emulation */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(middlebutton_device_remove_while_down) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); status = libinput_device_config_middle_emulation_set_enabled( device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); } END_TEST START_TEST(middlebutton_device_remove_while_one_is_down) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); status = libinput_device_config_middle_emulation_set_enabled( device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(pointer_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_pointer *ptrev; struct libinput_event *event; uint64_t time_usec; litest_drain_events(dev->libinput); litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_REL, REL_Y, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); time_usec = libinput_event_pointer_get_time_usec(ptrev); litest_assert_int_eq(libinput_event_pointer_get_time(ptrev), (uint32_t) (time_usec / 1000)); libinput_event_destroy(event); litest_drain_events(dev->libinput); } END_TEST START_TEST(debounce_bounce) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = litest_test_param_get_i32(test_env->params, "button"); if (!libinput_device_pointer_has_button(dev->libinput_device, button)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_bounce_high_delay) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = litest_test_param_get_i32(test_env->params, "button"); if (!libinput_device_pointer_has_button(dev->libinput_device, button)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); /* Debouncing timeout is 25ms after a button down or up. Make sure we go * over 25ms for the total bouncing duration, but stay under 25ms for * each single event. */ litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(15); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(15); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(15); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(15); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_bounce_check_immediate) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); /* Press must be sent without delay */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_debounce(); litest_assert_empty_queue(li); /* held down & past timeout, we expect releases to be immediate */ litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_timeout_debounce(); litest_assert_empty_queue(li); } END_TEST /* Triggers the event sequence that initializes the spurious * debouncing behavior */ static inline void debounce_trigger_spurious(struct litest_device *dev, struct libinput *li) { litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); /* gets filtered now */ litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } START_TEST(debounce_spurious) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = litest_test_param_get_i32(test_env->params, "button"); if (!libinput_device_pointer_has_button(dev->libinput_device, button)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); debounce_trigger_spurious(dev, li); for (int i = 0; i < 3; i++) { litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); /* Not all devices can disable middle button emulation, time out on * middle button here to make sure the initial button press event * was flushed. */ litest_timeout_middlebutton(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); /* bouncy bouncy bouncy */ litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } } END_TEST START_TEST(debounce_spurious_multibounce) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); debounce_trigger_spurious(dev, li); litest_drain_events(li); /* Let's assume our button has ventricular fibrilation and sends a * lot of clicks. Debouncing is now enabled, ventricular * fibrillation should cause one button down for the first press and * one release for the last release. */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); /* Not all devices can disable middle button emulation, time out on * middle button here to make sure the initial button press event * was flushed. */ litest_dispatch(li); litest_timeout_middlebutton(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_timeout_debounce(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_spurious_trigger_high_delay) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_middleemu(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); /* Spurious timeout is 12ms after a button down or up. Make sure we go * over 12ms for the total bouncing duration, but stay under 12ms for * each single event. */ litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(5); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); /* gets filtered now */ litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_spurious_dont_enable_on_otherbutton) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; if (!libinput_device_config_middle_emulation_is_available(device)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); /* Don't trigger spurious debouncing on otherbutton events */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* Expect release to be immediate */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(debounce_spurious_cancel_debounce_otherbutton) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; if (!libinput_device_config_middle_emulation_is_available(device)) return LITEST_NOT_APPLICABLE; litest_disable_middleemu(dev); disable_button_scrolling(dev); litest_drain_events(li); debounce_trigger_spurious(dev, li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); /* spurious debouncing is on but the release should get flushed by * the other button */ litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_spurious_switch_to_otherbutton) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; if (!libinput_device_config_middle_emulation_is_available(device)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); debounce_trigger_spurious(dev, li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); /* release is now held back, * other button should flush the release */ litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); /* bouncing right button triggers debounce */ litest_event(dev, EV_KEY, BTN_RIGHT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_RIGHT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(debounce_remove_device_button_up) { struct libinput *li; struct litest_device *dev; li = litest_create_context(); dev = litest_add_device(li, LITEST_MOUSE); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* delete the device while the timer is still active */ litest_delete_device(dev); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_destroy_context(li); } END_TEST START_TEST(debounce_remove_device_button_down) { struct libinput *li; struct litest_device *dev; li = litest_create_context(); dev = litest_add_device(li, LITEST_MOUSE); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* delete the device the timer is still active */ litest_delete_device(dev); litest_dispatch(li); litest_timeout_debounce(); litest_dispatch(li); litest_destroy_context(li); } END_TEST TEST_COLLECTION(pointer) { litest_add(pointer_motion_relative, LITEST_RELATIVE, LITEST_POINTINGSTICK); litest_add_for_device(pointer_motion_relative_zero, LITEST_MOUSE); litest_with_parameters(params, "direction", 'I', 8, litest_named_i32(N), litest_named_i32(NE), litest_named_i32(E), litest_named_i32(SE), litest_named_i32(S), litest_named_i32(SW), litest_named_i32(W), litest_named_i32(NW)) { litest_add_parametrized(pointer_motion_relative_min_decel, LITEST_RELATIVE, LITEST_POINTINGSTICK, params); } litest_add(pointer_motion_absolute, LITEST_ABSOLUTE, LITEST_ANY); litest_add(pointer_motion_unaccel, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_button, LITEST_BUTTON, LITEST_CLICKPAD); litest_add_no_device(pointer_button_auto_release); litest_add_no_device(pointer_seat_button_count); litest_add_for_device(pointer_button_has_no_button, LITEST_KEYBOARD); litest_add(pointer_recover_from_lost_button_count, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_wheel_hires, LITEST_WHEEL, LITEST_TABLET); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, "vertical"), litest_named_i32(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, "horizontal")) { litest_add_parametrized(pointer_scroll_wheel_hires_send_only_lores, LITEST_WHEEL, LITEST_TABLET, params); } litest_add(pointer_scroll_wheel_inhibit_small_deltas, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_wheel_inhibit_dir_change, LITEST_WHEEL, LITEST_TABLET); litest_add_for_device(pointer_scroll_wheel_lenovo_scrollpoint, LITEST_LENOVO_SCROLLPOINT); litest_add(pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_noscroll, LITEST_ABSOLUTE|LITEST_BUTTON, LITEST_RELATIVE); litest_add(pointer_scroll_button_noscroll, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON); litest_add(pointer_scroll_button_no_event_before_timeout, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_middle_emulation, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add_no_device(pointer_scroll_button_device_remove_while_down); litest_add(pointer_scroll_button_lock, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_config, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_enable_while_down, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_enable_while_down_just_lock, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_otherbutton, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button_lock_enable_while_otherbutton_down, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_with_parameters(params, "buttonorder", 'I', 6, litest_named_i32(LLRR), litest_named_i32(LRLR), litest_named_i32(LRRL), litest_named_i32(RRLL), litest_named_i32(RLRL), litest_named_i32(RLLR)) { litest_add_parametrized(pointer_scroll_button_lock_middlebutton, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY, params); } litest_add(pointer_scroll_button_lock_doubleclick_nomove, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_nowheel_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_WHEEL); litest_add_for_device(pointer_scroll_defaults_logitech_marble , LITEST_LOGITECH_TRACKBALL); litest_add(pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_natural_defaults_noscroll, LITEST_ANY, LITEST_WHEEL); litest_add(pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_has_axis_invalid, LITEST_WHEEL, LITEST_TABLET); litest_with_parameters(params, "angle", 'd', 18, 0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 320.0, 340.0) { litest_add_parametrized(pointer_scroll_with_rotation, LITEST_WHEEL, LITEST_TABLET, params); } litest_add(pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE|LITEST_PROTOCOL_A|LITEST_TABLET); /* tests touchpads too */ litest_add(pointer_left_handed_defaults, LITEST_BUTTON, LITEST_ANY); litest_add(pointer_left_handed, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_left_handed_during_click, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_left_handed_during_click_multiple_buttons, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add_no_device(pointer_left_handed_disable_with_button_down); litest_add(pointer_accel_defaults, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_invalid, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_defaults_absolute, LITEST_ABSOLUTE, LITEST_RELATIVE); litest_add(pointer_accel_defaults_absolute_relative, LITEST_ABSOLUTE|LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_direction_change, LITEST_RELATIVE, LITEST_POINTINGSTICK); litest_add(pointer_accel_profile_defaults, LITEST_RELATIVE, LITEST_TOUCHPAD); litest_add(pointer_accel_profile_defaults, LITEST_TOUCHPAD, LITEST_ANY); litest_add(pointer_accel_config_reset_to_defaults, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_config, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_profile_invalid, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_profile_noaccel, LITEST_ANY, LITEST_TOUCHPAD|LITEST_RELATIVE|LITEST_TABLET); litest_add(pointer_accel_profile_flat_motion_relative, LITEST_RELATIVE, LITEST_TOUCHPAD); litest_add(middlebutton, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_nostart_while_down, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_timeout, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_doubleclick, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_middleclick, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_middleclick_during, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_default_enabled, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_POINTINGSTICK); litest_add(middlebutton_default_clickpad, LITEST_CLICKPAD, LITEST_ANY); litest_add(middlebutton_default_touchpad, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(middlebutton_default_disabled, LITEST_ANY, LITEST_BUTTON); litest_add_for_device(middlebutton_default_alps, LITEST_ALPS_SEMI_MT); litest_add(middlebutton_button_scrolling, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_button_scrolling_middle, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_device_remove_while_down, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(middlebutton_device_remove_while_one_is_down, LITEST_BUTTON, LITEST_CLICKPAD); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { litest_add_parametrized(pointer_absolute_initial_state, LITEST_ABSOLUTE, LITEST_ANY, params); } litest_add(pointer_time_usec, LITEST_RELATIVE, LITEST_ANY); litest_with_parameters(params, "button", 'I', 8, litest_named_i32(BTN_LEFT), litest_named_i32(BTN_RIGHT), litest_named_i32(BTN_MIDDLE), litest_named_i32(BTN_SIDE), litest_named_i32(BTN_EXTRA), litest_named_i32(BTN_FORWARD), litest_named_i32(BTN_BACK), litest_named_i32(BTN_TASK)) { litest_add_parametrized(debounce_bounce, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE, params); litest_add_parametrized(debounce_spurious, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE, params); /* Timing-sensitive test, valgrind is too slow */ if (!RUNNING_ON_VALGRIND) litest_add_parametrized(debounce_bounce_high_delay, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE, params); } litest_add(debounce_bounce_check_immediate, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); litest_add(debounce_spurious_multibounce, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); if (!RUNNING_ON_VALGRIND) litest_add(debounce_spurious_trigger_high_delay, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); litest_add(debounce_spurious_dont_enable_on_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); litest_add(debounce_spurious_cancel_debounce_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); litest_add(debounce_spurious_switch_to_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); litest_add_no_device(debounce_remove_device_button_down); litest_add_no_device(debounce_remove_device_button_up); } libinput-1.28.1/test/test-quirks.c000066400000000000000000001127731477265155700171050ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include "libinput-util.h" #include "litest.h" #include "quirks.h" static void log_handler(struct libinput *this_is_null, enum libinput_log_priority priority, const char *format, va_list args) { #if 0 vprintf(format, args); #endif } struct data_dir { char *dirname; char *filename; }; static struct data_dir make_data_dir(const char *file_content) { struct data_dir dir = {0}; char dirname[PATH_MAX] = "/tmp/litest-quirk-test-XXXXXX"; char *filename; FILE *fp; int rc; litest_assert_notnull(mkdtemp(dirname)); dir.dirname = safe_strdup(dirname); if (file_content) { rc = xasprintf(&filename, "%s/testfile.quirks", dirname); litest_assert_int_eq(rc, (int)(strlen(dirname) + 16)); fp = fopen(filename, "w+"); #ifndef __clang_analyzer__ litest_assert_notnull(fp); #else assert(fp); #endif rc = fputs(file_content, fp); litest_assert_errno_success(rc); fclose(fp); dir.filename = filename; } return dir; } static void cleanup_data_dir(struct data_dir dd) { if (dd.filename) { unlink(dd.filename); free(dd.filename); } if (dd.dirname) { rmdir(dd.dirname); free(dd.dirname); } } START_TEST(quirks_invalid_dir) { struct quirks_context *ctx; ctx = quirks_init_subsystem("/does-not-exist", NULL, log_handler, NULL, QLOG_LIBINPUT_LOGGING); litest_assert(ctx == NULL); } END_TEST START_TEST(quirks_empty_dir) { struct quirks_context *ctx; struct data_dir dd = make_data_dir(NULL); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_LIBINPUT_LOGGING); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_empty) { struct quirks_context *ctx; const char quirks_file[] = "[Empty Section]"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_double) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_missing_match) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_missing_attr) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_match_after_attr) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "AttrSizeHint=10x10\n" "MatchName=mouse\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_duplicate_match) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "MatchUdevType=mouse\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_section_duplicate_attr) { /* This shouldn't be allowed but the current parser is happy with it */ struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "AttrSizeHint=10x10\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_section) { struct quirks_context *ctx; const char quirks_file[] = "[Section Missing Bracket\n" "MatchUdevType=mouse\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_trailing_whitespace) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse \n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_unknown_match) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "Matchblahblah=mouse\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_unknown_attr) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "Attrblahblah=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_unknown_model) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "Modelblahblah=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_unknown_prefix) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "Fooblahblah=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_error_model_not_one) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=true\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_comment_inline) { struct quirks_context *ctx; const char quirks_file[] = "[Section name] # some inline comment\n" "MatchUdevType=mouse\t # another inline comment\n" "ModelAppleTouchpad=1#\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_comment_empty) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "#\n" " #\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_string_quotes_single) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "AttrKeyboardIntegration='internal'\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_string_quotes_double) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "AttrKeyboardIntegration=\"internal\"\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_bustype) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchBus=usb\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchBus=bluetooth\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchBus=i2c\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchBus=rmi\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchBus=ps2\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_bustype_invalid) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchBus=venga\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_vendor) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchVendor=0x0000\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchVendor=0x0001\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchVendor=0x2343\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_vendor_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchVendor=-1\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVendor=abc\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVendor=0xFFFFF\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVendor=123\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_product) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchProduct=0x12AB\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchProduct=0x0001;0x1234;0xABCD\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchProduct=0x2343\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_product_too_many) { struct quirks_context *ctx; const char prologue[] = "[Section name]\n" "MatchProduct=0x12AB\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchProduct="; const char epilogue[] = "\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchProduct=0x2343\n" "ModelAppleTouchpad=1\n"; char matches[4096] = {0}; for (int i = 0; i < 128; i++) { int len = strlen(matches); int remaining = sizeof(matches) - len; snprintf(&matches[len], remaining, "0x%04X", i); } char *quirks_file = NULL; xasprintf(&quirks_file, "%s%s%s", prologue, matches, epilogue); struct data_dir dd = make_data_dir(quirks_file); free(quirks_file); /* This test will only blow up in valgrind/asan */ ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_product_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchProduct=-1\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchProduct=abc\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchProduct=0xFFFFF\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchProduct=123\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_version) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchVersion=0x0000\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchVersion=0x0001\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchVersion=0x2343\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_version_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchVersion=-1\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVersion=abc\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVersion=0xFFFFF\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchVersion=123\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_name) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchName=1235\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchName=abc\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchName=*foo\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchName=foo*\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchName=foo[]\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchName=*foo*\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_name_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchName=\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_uniq) { struct quirks_context *ctx; const char quirks_file[] = "[Section Uniq]\n" "MatchUniq=1235\n" "ModelAppleTouchpad=1\n" "\n" "[Section Uniq]\n" "MatchUniq=abc\n" "ModelAppleTouchpad=1\n" "\n" "[Section Uniq]\n" "MatchUniq=*foo\n" "ModelAppleTouchpad=1\n" "\n" "[Section Uniq]\n" "MatchUniq=foo*\n" "ModelAppleTouchpad=1\n" "\n" "[Section Uniq]\n" "MatchUniq=foo[]\n" "ModelAppleTouchpad=1\n" "\n" "[Section Uniq]\n" "MatchUniq=*foo*\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_uniq_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchUniq=\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_udev) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=touchpad\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=pointingstick\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=tablet\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=tablet-pad\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=keyboard\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchUdevType=joystick\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_udev_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchUdevType=blah\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchUdevType=\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchUdevType=123\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST START_TEST(quirks_parse_dmi) { struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchDMIModalias=dmi:*\n" "ModelAppleTouchpad=1\n" "\n" "[Section name]\n" "MatchDMIModalias=dmi:*svn*pn*:\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); quirks_context_unref(ctx); cleanup_data_dir(dd); } END_TEST START_TEST(quirks_parse_dmi_invalid) { struct quirks_context *ctx; const char *quirks_file[] = { "[Section name]\n" "MatchDMIModalias=\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchDMIModalias=*pn*\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchDMIModalias=dmi*pn*\n" "ModelAppleTouchpad=1\n", "[Section name]\n" "MatchDMIModalias=foo\n" "ModelAppleTouchpad=1\n", }; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert(ctx == NULL); cleanup_data_dir(dd); } } END_TEST typedef bool (*qparsefunc) (struct quirks *q, enum quirk which, void* data); /* Helper for generic testing, matches on a mouse device with the given quirk set to the given string. Creates a data directory, inits the quirks and calls func() to return the value in data. The func has to take the right data, otherwise boom. Usage: rc = test_attr_parse(dev, QUIRK_ATTR_SIZE_HINT, "10x30", quirks_get_dimensions, &some_struct_quirks_dimensions); if (rc == false) // failed to parse else // struct now contains the 10, 30 values */ static bool test_attr_parse(struct litest_device *dev, enum quirk which, const char *str, qparsefunc func, void *data) { struct udev_device *ud = libinput_device_get_udev_device(dev->libinput_device); struct quirks_context *ctx; struct data_dir dd; char buf[512]; bool result; snprintf(buf, sizeof(buf), "[Section name]\n" "MatchUdevType=mouse\n" "%s=%s\n", quirk_get_name(which), str); dd = make_data_dir(buf); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); if (ctx != NULL) { struct quirks *q; q = quirks_fetch_for_device(ctx, ud); litest_assert_notnull(q); litest_assert(func(q, which, data)); litest_assert(quirks_has_quirk(q, which)); quirks_unref(q); quirks_context_unref(ctx); result = true; } else { result = false; } cleanup_data_dir(dd); udev_device_unref(ud); return result; } struct qtest_dim { const char *str; bool success; size_t w, h; }; START_TEST(quirks_parse_dimension_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_SIZE_HINT, QUIRK_ATTR_RESOLUTION_HINT, }; struct qtest_dim test_values[] = { { "10x10", true, 10, 10 }, { "20x30", true, 20, 30 }, { "-10x30", false, 0, 0 }, { "10:30", false, 0, 0 }, { "30", false, 0, 0 }, { "0x00", false, 0, 0 }, { "0xa0", false, 0, 0 }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { struct quirk_dimensions dim; bool rc; rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_dimensions, &dim); litest_assert_int_eq(rc, t->success); if (!rc) continue; litest_assert_int_eq(dim.x, t->w); litest_assert_int_eq(dim.y, t->h); } } } END_TEST struct qtest_range { const char *str; bool success; int hi, lo; }; START_TEST(quirks_parse_range_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_TOUCH_SIZE_RANGE, QUIRK_ATTR_PRESSURE_RANGE, }; struct qtest_range test_values[] = { { "20:10", true, 20, 10 }, { "30:5", true, 30, 5 }, { "30:-10", true, 30, -10 }, { "-30:-100", true, -30, -100 }, { "5:10", false, 0, 0 }, { "5:5", false, 0, 0 }, { "-10:5", false, 0, 0 }, { "-10:-5", false, 0, 0 }, { "10x30", false, 0, 0 }, { "30x10", false, 0, 0 }, { "30", false, 0, 0 }, { "0x00", false, 0, 0 }, { "0xa0", false, 0, 0 }, { "0x10:0x5", false, 0, 0 }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { struct quirk_range r; bool rc; rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_range, &r); litest_assert_int_eq(rc, t->success); if (!rc) continue; litest_assert_int_eq(r.lower, t->lo); litest_assert_int_eq(r.upper, t->hi); } } } END_TEST struct qtest_uint { const char *str; bool success; uint32_t val; }; START_TEST(quirks_parse_uint_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_PALM_SIZE_THRESHOLD, QUIRK_ATTR_PALM_PRESSURE_THRESHOLD, QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD, }; struct qtest_uint test_values[] = { { "10", true, 10 }, { "0", true, 0 }, { "5", true, 5 }, { "65535", true, 65535 }, { "4294967295", true, 4294967295 }, { "-10", false, 0 }, { "0x10", false, 0 }, { "0xab", false, 0 }, { "ab", false, 0 }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { uint32_t v; bool rc; rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_uint32, &v); litest_assert_int_eq(rc, t->success); if (!rc) continue; litest_assert_int_eq(v, t->val); } } } END_TEST struct qtest_double { const char *str; bool success; double val; }; START_TEST(quirks_parse_double_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_TRACKPOINT_MULTIPLIER, }; struct qtest_double test_values[] = { { "10", true, 10.0 }, { "10.0", true, 10.0 }, { "-10.0", true, -10.0 }, { "0", true, 0.0 }, { "0.0", true, 0.0 }, { "5.1", true, 5.1 }, { "-5.9", true, -5.9 }, { "65535", true, 65535 }, { "4294967295", true, 4294967295 }, { "4294967295.123", true, 4294967295.123 }, /* our safe_atoi parses hex even though we don't really want * to */ { "0x10", false, 0 }, { "0xab", false, 0 }, { "ab", false, 0 }, { "10:5", false, 0 }, { "10x5", false, 0 }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { double v; bool rc; rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_double, &v); litest_assert_int_eq(rc, t->success); if (!rc) continue; litest_assert_double_eq(v, t->val); } } } END_TEST struct qtest_str { const char *str; enum quirk where; }; START_TEST(quirks_parse_string_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_TPKBCOMBO_LAYOUT, QUIRK_ATTR_LID_SWITCH_RELIABILITY, QUIRK_ATTR_KEYBOARD_INTEGRATION, }; struct qtest_str test_values[] = { { "below", QUIRK_ATTR_TPKBCOMBO_LAYOUT }, { "reliable", QUIRK_ATTR_LID_SWITCH_RELIABILITY }, { "write_open", QUIRK_ATTR_LID_SWITCH_RELIABILITY }, { "internal", QUIRK_ATTR_KEYBOARD_INTEGRATION }, { "external", QUIRK_ATTR_KEYBOARD_INTEGRATION }, { "10", 0 }, { "-10", 0 }, { "0", 0 }, { "", 0 }, { "banana", 0 }, { "honk honk", 0 }, { "0x12", 0 }, { "0xa", 0 }, { "0.0", 0 }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { bool rc; char *do_not_use; /* freed before we can use it */ rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_string, &do_not_use); if (*a == t->where) litest_assert_int_eq(rc, true); else litest_assert_int_eq(rc, false); } } } END_TEST struct qtest_bool { const char *str; bool success; bool val; }; START_TEST(quirks_parse_bool_attr) { struct litest_device *dev = litest_current_device(); enum quirk attrs[] = { QUIRK_ATTR_USE_VELOCITY_AVERAGING, QUIRK_ATTR_TABLET_SMOOTHING, }; struct qtest_bool test_values[] = { { "0", true, false }, { "1", true, true }, { "2", false, false }, { "-1", false, false }, { "a", false, false }, }; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { bool v; bool rc; rc = test_attr_parse(dev, *a, t->str, (qparsefunc)quirks_get_bool, &v); litest_assert(rc == t->success); if (!rc) continue; litest_assert(v == t->val); } } } END_TEST START_TEST(quirks_parse_integration_attr) { struct litest_device *dev = litest_current_device(); char *do_not_use; /* freed before we can use it */ bool rc = test_attr_parse(dev, QUIRK_ATTR_KEYBOARD_INTEGRATION, "internal", (qparsefunc)quirks_get_string, &do_not_use); litest_assert(rc); rc = test_attr_parse(dev, QUIRK_ATTR_KEYBOARD_INTEGRATION, "external", (qparsefunc)quirks_get_string, &do_not_use); litest_assert(rc); rc = test_attr_parse(dev, QUIRK_ATTR_TRACKPOINT_INTEGRATION, "internal", (qparsefunc)quirks_get_string, &do_not_use); litest_assert(rc); rc = test_attr_parse(dev, QUIRK_ATTR_TRACKPOINT_INTEGRATION, "external", (qparsefunc)quirks_get_string, &do_not_use); litest_assert(rc); } END_TEST START_TEST(quirks_model_one) { struct litest_device *dev = litest_current_device(); struct udev_device *ud = libinput_device_get_udev_device(dev->libinput_device); struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=1\n"; struct data_dir dd = make_data_dir(quirks_file); struct quirks *q; bool isset; ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); q = quirks_fetch_for_device(ctx, ud); litest_assert_notnull(q); litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset)); litest_assert(isset == true); quirks_unref(q); quirks_context_unref(ctx); cleanup_data_dir(dd); udev_device_unref(ud); } END_TEST START_TEST(quirks_model_zero) { struct litest_device *dev = litest_current_device(); struct udev_device *ud = libinput_device_get_udev_device(dev->libinput_device); struct quirks_context *ctx; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=0\n"; struct data_dir dd = make_data_dir(quirks_file); struct quirks *q; bool isset; ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); q = quirks_fetch_for_device(ctx, ud); litest_assert_notnull(q); litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset)); litest_assert(isset == false); quirks_unref(q); quirks_context_unref(ctx); cleanup_data_dir(dd); udev_device_unref(ud); } END_TEST START_TEST(quirks_model_override) { struct litest_device *dev = litest_current_device(); struct udev_device *ud = libinput_device_get_udev_device(dev->libinput_device); struct quirks_context *ctx; char *quirks_file; struct data_dir dd; struct quirks *q; bool isset; bool set = litest_test_param_get_bool(test_env->params, "enable_model"); /* Test model quirks override by setting, then unsetting (or the other way round) */ int rc = xasprintf(&quirks_file, "[first]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=%d\n" "\n" "[second]\n" "MatchUdevType=mouse\n" "ModelAppleTouchpad=%d\n", set ? 0 : 1, set ? 1 : 0); litest_assert_int_ne(rc, -1); dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); q = quirks_fetch_for_device(ctx, ud); litest_assert_notnull(q); litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset)); litest_assert(isset == set); quirks_unref(q); quirks_context_unref(ctx); cleanup_data_dir(dd); udev_device_unref(ud); free(quirks_file); } END_TEST START_TEST(quirks_model_alps) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct quirks *q; bool exists, value = false; q = dev->quirks; exists = quirks_get_bool(q, QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD, &value); if (strstr(libinput_device_get_name(device), "ALPS")) { litest_assert(exists); litest_assert(value); } else { litest_assert(!exists); litest_assert(!value); } } END_TEST START_TEST(quirks_model_wacom) { struct litest_device *dev = litest_current_device(); struct quirks *q; bool exists, value = false; q = dev->quirks; exists = quirks_get_bool(q, QUIRK_MODEL_WACOM_TOUCHPAD, &value); if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM) { litest_assert(exists); litest_assert(value); } else { litest_assert(!exists); litest_assert(!value); } } END_TEST START_TEST(quirks_model_apple) { struct litest_device *dev = litest_current_device(); struct quirks *q; bool exists, value = false; q = dev->quirks; exists = quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &value); if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE) { litest_assert(exists); litest_assert(value); } else { litest_assert(!exists); litest_assert(!value); } } END_TEST START_TEST(quirks_model_synaptics_serial) { struct litest_device *dev = litest_current_device(); struct quirks *q; bool exists, value = false; q = dev->quirks; exists = quirks_get_bool(q, QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD, &value); if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_SYNAPTICS_SERIAL && libevdev_get_id_product(dev->evdev) == PRODUCT_ID_SYNAPTICS_SERIAL) { litest_assert(exists); litest_assert(value); } else { litest_assert(!exists); litest_assert(!value); } } END_TEST START_TEST(quirks_call_NULL) { litest_assert(!quirks_fetch_for_device(NULL, NULL)); litest_assert(!quirks_get_uint32(NULL, 0, NULL)); litest_assert(!quirks_get_int32(NULL, 0, NULL)); litest_assert(!quirks_get_range(NULL, 0, NULL)); litest_assert(!quirks_get_dimensions(NULL, 0, NULL)); litest_assert(!quirks_get_double(NULL, 0, NULL)); litest_assert(!quirks_get_string(NULL, 0, NULL)); litest_assert(!quirks_get_bool(NULL, 0, NULL)); } END_TEST START_TEST(quirks_ctx_ref) { struct quirks_context *ctx, *ctx2; const char quirks_file[] = "[Section name]\n" "MatchUdevType=mouse\n" "AttrSizeHint=10x10\n"; struct data_dir dd = make_data_dir(quirks_file); ctx = quirks_init_subsystem(dd.dirname, NULL, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); litest_assert_notnull(ctx); ctx2 = quirks_context_ref(ctx); litest_assert_ptr_eq(ctx, ctx2); ctx2 = quirks_context_unref(ctx); litest_assert_ptr_eq(ctx2, NULL); ctx2 = quirks_context_unref(ctx); litest_assert_ptr_eq(ctx2, NULL); cleanup_data_dir(dd); } END_TEST TEST_COLLECTION(quirks) { litest_add_deviceless(quirks_invalid_dir); litest_add_deviceless(quirks_empty_dir); litest_add_deviceless(quirks_section_empty); litest_add_deviceless(quirks_section_double); litest_add_deviceless(quirks_section_missing_match); litest_add_deviceless(quirks_section_missing_attr); litest_add_deviceless(quirks_section_match_after_attr); litest_add_deviceless(quirks_section_duplicate_match); litest_add_deviceless(quirks_section_duplicate_attr); litest_add_deviceless(quirks_parse_error_section); litest_add_deviceless(quirks_parse_error_trailing_whitespace); litest_add_deviceless(quirks_parse_error_unknown_match); litest_add_deviceless(quirks_parse_error_unknown_attr); litest_add_deviceless(quirks_parse_error_unknown_model); litest_add_deviceless(quirks_parse_error_unknown_prefix); litest_add_deviceless(quirks_parse_error_model_not_one); litest_add_deviceless(quirks_parse_comment_inline); litest_add_deviceless(quirks_parse_comment_empty); litest_add_deviceless(quirks_parse_string_quotes_single); litest_add_deviceless(quirks_parse_string_quotes_double); litest_add_deviceless(quirks_parse_bustype); litest_add_deviceless(quirks_parse_bustype_invalid); litest_add_deviceless(quirks_parse_vendor); litest_add_deviceless(quirks_parse_vendor_invalid); litest_add_deviceless(quirks_parse_product); litest_add_deviceless(quirks_parse_product_too_many); litest_add_deviceless(quirks_parse_product_invalid); litest_add_deviceless(quirks_parse_version); litest_add_deviceless(quirks_parse_version_invalid); litest_add_deviceless(quirks_parse_name); litest_add_deviceless(quirks_parse_name_invalid); litest_add_deviceless(quirks_parse_uniq); litest_add_deviceless(quirks_parse_uniq_invalid); litest_add_deviceless(quirks_parse_udev); litest_add_deviceless(quirks_parse_udev_invalid); litest_add_deviceless(quirks_parse_dmi); litest_add_deviceless(quirks_parse_dmi_invalid); litest_add_for_device(quirks_parse_dimension_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_range_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_uint_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_double_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_string_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_bool_attr, LITEST_MOUSE); litest_add_for_device(quirks_parse_integration_attr, LITEST_MOUSE); litest_add_for_device(quirks_model_one, LITEST_MOUSE); litest_add_for_device(quirks_model_zero, LITEST_MOUSE); litest_with_parameters(params, "enable_model", 'b') { litest_add_parametrized_for_device(quirks_model_override, LITEST_MOUSE, params); } litest_add(quirks_model_alps, LITEST_TOUCHPAD, LITEST_ANY); litest_add(quirks_model_wacom, LITEST_TOUCHPAD, LITEST_ANY); litest_add(quirks_model_apple, LITEST_TOUCHPAD, LITEST_ANY); litest_add(quirks_model_synaptics_serial, LITEST_TOUCHPAD, LITEST_ANY); litest_add_deviceless(quirks_call_NULL); litest_add_deviceless(quirks_ctx_ref); } libinput-1.28.1/test/test-switch.c000066400000000000000000001261771477265155700170730ustar00rootroot00000000000000/* * Copyright © 2017 James Ye * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include "libinput-util.h" #include "litest.h" static inline bool switch_has_lid(struct litest_device *dev) { return libinput_device_switch_has_switch(dev->libinput_device, LIBINPUT_SWITCH_LID) > 0; } static inline bool switch_has_tablet_mode(struct litest_device *dev) { return libinput_device_switch_has_switch(dev->libinput_device, LIBINPUT_SWITCH_TABLET_MODE) > 0; } START_TEST(switch_has_cap) { struct litest_device *dev = litest_current_device(); /* Need to check for this specific device here because the * unreliable tablet mode switch removes the capability too */ if (dev->which == LITEST_TABLET_MODE_UNRELIABLE) { litest_assert(!libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_SWITCH)); return LITEST_NOT_APPLICABLE; } litest_assert(libinput_device_has_capability(dev->libinput_device, LIBINPUT_DEVICE_CAP_SWITCH)); } END_TEST START_TEST(switch_has_lid_switch) { struct litest_device *dev = litest_current_device(); if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_LID)) return LITEST_NOT_APPLICABLE; litest_assert_int_eq(libinput_device_switch_has_switch(dev->libinput_device, LIBINPUT_SWITCH_LID), 1); } END_TEST static bool tablet_mode_switch_is_reliable(struct litest_device *dev) { bool is_unreliable = false; quirks_get_bool(dev->quirks, QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE, &is_unreliable); return !is_unreliable; } START_TEST(switch_has_tablet_mode_switch) { struct litest_device *dev = litest_current_device(); int has_switch; if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_TABLET_MODE)) return LITEST_NOT_APPLICABLE; has_switch = libinput_device_switch_has_switch(dev->libinput_device, LIBINPUT_SWITCH_TABLET_MODE); if (!tablet_mode_switch_is_reliable(dev)) litest_assert_int_ne(has_switch, 1); else litest_assert_int_eq(has_switch, 1); } END_TEST START_TEST(switch_toggle) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch"); litest_drain_events(li); litest_grab_device(dev); litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); litest_dispatch(li); if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) { event = libinput_get_event(li); litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON); libinput_event_destroy(event); } else { litest_assert_empty_queue(li); } litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF); litest_dispatch(li); if (libinput_device_switch_has_switch(dev->libinput_device, sw) > 0) { event = libinput_get_event(li); litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF); libinput_event_destroy(event); } litest_assert_empty_queue(li); litest_ungrab_device(dev); } END_TEST START_TEST(switch_toggle_double) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_grab_device(dev); litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); litest_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON); libinput_event_destroy(event); /* This will be filtered by the kernel, so this test is a bit * useless */ litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); litest_dispatch(li); litest_assert_empty_queue(li); litest_ungrab_device(dev); } END_TEST static bool lid_switch_is_reliable(struct litest_device *dev) { char *prop; bool is_reliable = false; if (quirks_get_string(dev->quirks, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) { is_reliable = streq(prop, "reliable"); } return is_reliable; } START_TEST(switch_down_on_init) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_event *event; enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0) return LITEST_NOT_APPLICABLE; if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev)) return LITEST_NOT_APPLICABLE; litest_grab_device(dev); litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(dev); /* need separate context to test */ li = litest_create_context(); libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_SWITCH_TOGGLE); event = libinput_get_event(li); litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON); libinput_event_destroy(event); while ((event = libinput_get_event(li))) { litest_assert_enum_ne(libinput_event_get_type(event), LIBINPUT_EVENT_SWITCH_TOGGLE); libinput_event_destroy(event); } litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF); litest_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_destroy_context(li); } END_TEST START_TEST(switch_not_down_on_init) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_event *event; enum libinput_switch sw = LIBINPUT_SWITCH_LID; if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0) return LITEST_NOT_APPLICABLE; if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev)) return LITEST_NOT_APPLICABLE; litest_grab_device(dev); litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(dev); /* need separate context to test */ li = litest_create_context(); libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_dispatch(li); while ((event = libinput_get_event(li)) != NULL) { litest_assert_enum_ne(libinput_event_get_type(event), LIBINPUT_EVENT_SWITCH_TOGGLE); libinput_event_destroy(event); } litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); litest_destroy_context(li); } END_TEST static inline struct litest_device * switch_init_paired_touchpad(struct libinput *li) { enum litest_device_type which = LITEST_SYNAPTICS_I2C; return litest_add_device(li, which); } START_TEST(switch_disable_touchpad) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_grab_device(sw); /* switch is on - no events */ litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); /* switch is off - motion events */ litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); litest_ungrab_device(sw); } END_TEST START_TEST(switch_disable_touchpad_during_touch) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_ungrab_device(sw); litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(touchpad); } END_TEST START_TEST(switch_disable_touchpad_edge_scroll) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_enable_edge_scroll(touchpad); litest_drain_events(li); litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_ungrab_device(sw); litest_touch_down(touchpad, 0, 99, 20); litest_dispatch(li); litest_timeout_edgescroll(); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(touchpad); } END_TEST START_TEST(switch_disable_touchpad_edge_scroll_interrupt) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; struct libinput_event *event; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_enable_edge_scroll(touchpad); litest_drain_events(li); litest_touch_down(touchpad, 0, 99, 20); litest_dispatch(li); litest_timeout_edgescroll(); litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10); litest_dispatch(li); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(sw); litest_dispatch(li); litest_assert_axis_end_sequence(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); event = libinput_get_event(li); litest_is_switch_event(event, which, LIBINPUT_SWITCH_STATE_ON); libinput_event_destroy(event); litest_delete_device(touchpad); } END_TEST START_TEST(switch_disable_touchpad_already_open) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); /* default: switch is off - motion events */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* disable switch - motion events */ litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(switch_dont_resume_disabled_touchpad) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); libinput_device_config_send_events_set_mode(touchpad->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_drain_events(li); /* switch is on - no events */ litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(sw); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); /* switch is off but but tp is still disabled */ litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(touchpad); } END_TEST START_TEST(switch_dont_resume_disabled_touchpad_external_mouse) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad, *mouse; struct libinput *li = sw->libinput; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); mouse = litest_add_device(li, LITEST_MOUSE); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); libinput_device_config_send_events_set_mode(touchpad->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); /* switch is on - no events */ litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(sw); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); /* switch is off but but tp is still disabled */ litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(touchpad); litest_delete_device(mouse); } END_TEST START_TEST(lid_open_on_key) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard; struct libinput *li = sw->libinput; struct libinput_event *event; if (!switch_has_lid(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_grab_device(sw); for (int i = 0; i < 3; i++) { litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_event(keyboard, EV_KEY, KEY_A, 1); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_event(keyboard, EV_KEY, KEY_A, 0); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); libinput_event_destroy(event); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); } litest_ungrab_device(sw); litest_delete_device(keyboard); } END_TEST START_TEST(lid_open_on_key_touchpad_enabled) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard, *touchpad; struct libinput *li = sw->libinput; if (!switch_has_lid(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); litest_disable_hold_gestures(touchpad->libinput_device); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(sw); litest_drain_events(li); litest_event(keyboard, EV_KEY, KEY_A, 1); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_event(keyboard, EV_KEY, KEY_A, 0); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); litest_timeout_dwt_long(); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 70, 10); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); litest_delete_device(touchpad); } END_TEST START_TEST(switch_suspend_with_keyboard) { struct libinput *li; struct litest_device *keyboard; struct litest_device *sw; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); li = litest_create_context(); switch(which) { case LIBINPUT_SWITCH_LID: sw = litest_add_device(li, LITEST_LID_SWITCH); break; case LIBINPUT_SWITCH_TABLET_MODE: sw = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); break; default: abort(); } litest_dispatch(li); keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_dispatch(li); litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); litest_ungrab_device(sw); litest_delete_device(keyboard); litest_drain_events(li); litest_delete_device(sw); litest_dispatch(li); litest_destroy_context(li); } END_TEST START_TEST(switch_suspend_with_touchpad) { struct libinput *li; struct litest_device *touchpad, *sw; enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch"); li = litest_create_context(); switch(which) { case LIBINPUT_SWITCH_LID: sw = litest_add_device(li, LITEST_LID_SWITCH); break; case LIBINPUT_SWITCH_TABLET_MODE: sw = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); break; default: abort(); } litest_drain_events(li); touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); litest_drain_events(li); litest_grab_device(sw); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); litest_ungrab_device(sw); litest_delete_device(sw); litest_drain_events(li); litest_delete_device(touchpad); litest_drain_events(li); litest_destroy_context(li); } END_TEST START_TEST(lid_update_hw_on_key) { struct litest_device *sw = litest_current_device(); struct libinput *li = sw->libinput; struct litest_device *keyboard; struct libevdev *evdev; struct input_event event; int fd; int rc; if (!switch_has_lid(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_ungrab_device(sw); /* Separate direct libevdev context to check if the HW event goes * through */ fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK); litest_assert_int_ge(fd, 0); litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0); litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1); /* Typing on the keyboard should trigger a lid open event */ litest_event(keyboard, EV_KEY, KEY_A, 1); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_event(keyboard, EV_KEY, KEY_A, 0); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SW); litest_assert_int_eq(event.code, SW_LID); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SYN); litest_assert_int_eq(event.code, SYN_REPORT); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, -EAGAIN); litest_delete_device(keyboard); close(fd); libevdev_free(evdev); } END_TEST START_TEST(lid_update_hw_on_key_closed_on_init) { struct litest_device *sw = litest_current_device(); struct libinput *li; struct litest_device *keyboard; struct libevdev *evdev = sw->evdev; struct input_event event; int fd; int rc; litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_ungrab_device(sw); /* Separate direct libevdev context to check if the HW event goes * through */ fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK); litest_assert_int_ge(fd, 0); litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0); litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1); keyboard = litest_add_device(sw->libinput, LITEST_KEYBOARD); /* separate context for the right state on init */ li = litest_create_context(); libinput_path_add_device(li, libevdev_uinput_get_devnode(sw->uinput)); libinput_path_add_device(li, libevdev_uinput_get_devnode(keyboard->uinput)); /* don't expect a switch waiting for us, this is run for an * unreliable device */ while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) { litest_assert_enum_ne(libinput_next_event_type(li), LIBINPUT_EVENT_SWITCH_TOGGLE); libinput_event_destroy(libinput_get_event(li)); } litest_event(keyboard, EV_KEY, KEY_A, 1); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); litest_event(keyboard, EV_KEY, KEY_A, 0); litest_event(keyboard, EV_SYN, SYN_REPORT, 0); /* No switch event, we're still in vanilla (open) state */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* Make sure kernel state has updated */ rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SW); litest_assert_int_eq(event.code, SW_LID); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SYN); litest_assert_int_eq(event.code, SYN_REPORT); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, -EAGAIN); litest_destroy_context(li); litest_delete_device(keyboard); close(fd); libevdev_free(evdev); } END_TEST START_TEST(lid_update_hw_on_key_multiple_keyboards) { struct litest_device *sw = litest_current_device(); struct libinput *li = sw->libinput; struct litest_device *keyboard1, *keyboard2; struct libevdev *evdev = sw->evdev; struct input_event event; int fd; int rc; if (!switch_has_lid(sw)) return LITEST_NOT_APPLICABLE; keyboard1 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH); litest_dispatch(li); keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH); litest_dispatch(li); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_ungrab_device(sw); /* Separate direct libevdev context to check if the HW event goes * through */ fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK); litest_assert_int_ge(fd, 0); litest_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0); litest_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1); /* Typing on the second keyboard should trigger a lid open event */ litest_event(keyboard2, EV_KEY, KEY_A, 1); litest_event(keyboard2, EV_SYN, SYN_REPORT, 0); litest_event(keyboard2, EV_KEY, KEY_A, 0); litest_event(keyboard2, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SW); litest_assert_int_eq(event.code, SW_LID); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); litest_assert_int_eq(event.type, EV_SYN); litest_assert_int_eq(event.code, SYN_REPORT); litest_assert_int_eq(event.value, 0); rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event); litest_assert_int_eq(rc, -EAGAIN); litest_delete_device(keyboard1); litest_delete_device(keyboard2); close(fd); libevdev_free(evdev); } END_TEST START_TEST(lid_key_press) { struct litest_device *sw = litest_current_device(); struct libinput *li = sw->libinput; litest_drain_events(li); litest_keyboard_key(sw, KEY_VOLUMEUP, true); litest_keyboard_key(sw, KEY_VOLUMEUP, false); litest_dispatch(li); /* Check that we're routing key events from a lid device too */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); } END_TEST START_TEST(tablet_mode_disable_touchpad_on_init) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); /* touchpad comes with switch already on - no events */ touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_ungrab_device(sw); litest_delete_device(touchpad); } END_TEST START_TEST(tablet_mode_disable_touchpad_on_resume) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; struct libinput_event *event; bool have_switch_toggle = false; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); libinput_suspend(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); libinput_resume(li); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); switch (type) { case LIBINPUT_EVENT_DEVICE_ADDED: break; case LIBINPUT_EVENT_SWITCH_TOGGLE: litest_is_switch_event(event, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); have_switch_toggle = true; break; default: litest_abort_msg("Unexpected event type"); } libinput_event_destroy(event); } litest_assert(have_switch_toggle); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); libinput_event_destroy(event); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(tablet_mode_enable_touchpad_on_resume) { struct litest_device *sw = litest_current_device(); struct litest_device *touchpad; struct libinput *li = sw->libinput; struct libinput_event *event; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; touchpad = switch_init_paired_touchpad(li); litest_disable_tap(touchpad->libinput_device); litest_drain_events(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); libinput_suspend(li); litest_drain_events(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); libinput_resume(li); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_drain_events_of_type(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, LIBINPUT_EVENT_GESTURE_HOLD_END); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); libinput_event_destroy(event); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(touchpad); } END_TEST START_TEST(tablet_mode_disable_keyboard) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, KEY_B, true); /* KEY_B down but not up */ litest_dispatch(li); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_PRESSED); /* KEY_B down but not up */ litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); /* The key currently down must be released */ litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED); litest_assert_switch_event(li, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_assert_empty_queue(li); litest_keyboard_key(keyboard, KEY_B, false); /* release the kernel device */ litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_assert_switch_event(li, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, KEY_B, true); litest_keyboard_key(keyboard, KEY_B, false); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_PRESSED); litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED); litest_delete_device(keyboard); } END_TEST START_TEST(tablet_mode_disable_keyboard_on_init) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); /* keyboard comes with switch already on - no events */ keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_delete_device(keyboard); } END_TEST START_TEST(tablet_mode_disable_keyboard_on_resume) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard; struct libinput *li = sw->libinput; struct libinput_event *event; bool have_switch_toggle = false; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_drain_events(li); libinput_suspend(li); /* We cannot grab this device because libinput doesn't have an open * fd to this device, we need an independent grab. */ libevdev_grab(sw->evdev, LIBEVDEV_GRAB); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); libevdev_grab(sw->evdev, LIBEVDEV_UNGRAB); litest_drain_events(li); libinput_resume(li); litest_dispatch(li); while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); switch (type) { case LIBINPUT_EVENT_DEVICE_ADDED: break; case LIBINPUT_EVENT_SWITCH_TOGGLE: litest_is_switch_event(event, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); have_switch_toggle = true; break; default: litest_abort_msg("Unexpected event type"); } libinput_event_destroy(event); } litest_assert(have_switch_toggle); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_empty_queue(li); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_ungrab_device(sw); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_delete_device(keyboard); } END_TEST START_TEST(tablet_mode_enable_keyboard_on_resume) { struct litest_device *sw = litest_current_device(); struct litest_device *keyboard; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_ungrab_device(sw); libinput_suspend(li); litest_drain_events(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); libinput_resume(li); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(tablet_mode_disable_trackpoint) { struct litest_device *sw = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_ungrab_device(sw); litest_delete_device(trackpoint); } END_TEST START_TEST(tablet_mode_disable_trackpoint_on_init) { struct litest_device *sw = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = sw->libinput; if (!switch_has_tablet_mode(sw)) return LITEST_NOT_APPLICABLE; litest_grab_device(sw); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); /* trackpoint comes with switch already on - no events */ trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_ungrab_device(sw); litest_delete_device(trackpoint); } END_TEST START_TEST(dock_toggle) { struct litest_device *sw = litest_current_device(); struct libinput *li = sw->libinput; if (!libevdev_has_event_code(sw->evdev, EV_SW, SW_DOCK)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_grab_device(sw); litest_event(sw, EV_SW, SW_DOCK, 1); litest_dispatch(li); litest_event(sw, EV_SW, SW_DOCK, 0); litest_dispatch(li); litest_ungrab_device(sw); litest_assert_empty_queue(li); } END_TEST TEST_COLLECTION(switch) { litest_add(switch_has_cap, LITEST_SWITCH, LITEST_ANY); litest_add(switch_has_lid_switch, LITEST_SWITCH, LITEST_ANY); litest_add(switch_has_tablet_mode_switch, LITEST_SWITCH, LITEST_ANY); litest_add(switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY); litest_with_parameters(params, "switch", 'I', 2, litest_named_i32(LIBINPUT_SWITCH_LID, "lid"), litest_named_i32(LIBINPUT_SWITCH_TABLET_MODE, "tablet_mode")) { litest_add_parametrized(switch_toggle, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_toggle_double, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_down_on_init, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_disable_touchpad, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_disable_touchpad_edge_scroll_interrupt, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_disable_touchpad_already_open, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_dont_resume_disabled_touchpad, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized(switch_dont_resume_disabled_touchpad_external_mouse, LITEST_SWITCH, LITEST_ANY, params); litest_add_parametrized_no_device(switch_suspend_with_keyboard, params); litest_add_parametrized_no_device(switch_suspend_with_touchpad, params); } litest_add(lid_open_on_key, LITEST_SWITCH, LITEST_ANY); litest_add(lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY); litest_add_for_device(lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3); litest_add_for_device(lid_update_hw_on_key_closed_on_init, LITEST_LID_SWITCH_SURFACE3); litest_add_for_device(lid_update_hw_on_key_multiple_keyboards, LITEST_LID_SWITCH_SURFACE3); litest_add_for_device(lid_key_press, LITEST_GPIO_KEYS); litest_add(tablet_mode_disable_touchpad_on_init, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_enable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_keyboard, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_keyboard_on_init, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_enable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_trackpoint, LITEST_SWITCH, LITEST_ANY); litest_add(tablet_mode_disable_trackpoint_on_init, LITEST_SWITCH, LITEST_ANY); litest_add(dock_toggle, LITEST_SWITCH, LITEST_ANY); } libinput-1.28.1/test/test-tablet.c000066400000000000000000006651451477265155700170500ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * Copyright © 2014 Lyude Paul * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #if HAVE_LIBWACOM #include #endif #include "libinput-util.h" #include "evdev-tablet.h" #include "litest.h" #include "util-input-event.h" enum { TILT_MINIMUM, TILT_CENTER, TILT_MAXIMUM, }; static inline unsigned int pick_stylus_or_btn0(struct litest_device *dev) { if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_STYLUS)) return BTN_STYLUS; if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_0)) return BTN_0; /* totem */ abort(); } START_TEST(button_down_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_button_click(dev, button, true); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_button_click(dev, button, false); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(button_seat_count) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct litest_device *dev2 = NULL; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); switch (button) { case BTN_STYLUS: dev2 = litest_add_device(li, LITEST_WACOM_CINTIQ_13HDT_PEN); break; case BTN_0: dev2 = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM); break; default: litest_abort_msg("Invalid button code"); } litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_in(dev2, 10, 10, axes); litest_drain_events(li); litest_button_click(dev, button, true); litest_button_click(dev2, button, true); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1U); libinput_event_destroy(event); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 2U); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_button_click(dev2, button, false); litest_button_click(dev, button, false); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1U); libinput_event_destroy(event); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tev), LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); litest_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 0U); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_delete_device(dev2); } END_TEST START_TEST(button_up_on_delete) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); struct libevdev *evdev = libevdev_new(); unsigned int code; litest_tablet_proximity_in(dev, 10, 10, NULL); litest_drain_events(li); for (code = BTN_LEFT; code <= BTN_TASK; code++) { if (!libevdev_has_event_code(dev->evdev, EV_KEY, code)) continue; libevdev_enable_event_code(evdev, EV_KEY, code, NULL); litest_event(dev, EV_KEY, code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); litest_delete_device(dev); litest_dispatch(li); for (code = BTN_LEFT; code <= BTN_TASK; code++) { if (!libevdev_has_event_code(evdev, EV_KEY, code)) continue; litest_assert_tablet_button_event(li, code, LIBINPUT_BUTTON_STATE_RELEASED); } litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libevdev_free(evdev); litest_destroy_context(li); } END_TEST START_TEST(tip_down_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_down_up_eraser) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) return LITEST_NOT_APPLICABLE; litest_tablet_set_tool_type(dev, BTN_TOOL_RUBBER); litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_ERASER); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_ERASER); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_down_prox_in) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 30 }, { -1, -1 } }; litest_drain_events(li); litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_tip_down(dev, 10, 10, axes); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_up_prox_out) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 30 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_tip_down(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 30); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_push_event_frame(dev); litest_tablet_tip_up(dev, 10, 10, axes); litest_tablet_proximity_out(dev); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_timeout_tablet_proxout(); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_up_btn_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 30 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_tip_down(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 30); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_push_event_frame(dev); litest_tablet_tip_up(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), (unsigned int)BTN_STYLUS); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, 10, 10, axes); litest_drain_events(li); /* same thing with a release at tip-up */ litest_axis_set_value(axes, ABS_DISTANCE, 30); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_push_event_frame(dev); litest_tablet_tip_up(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), (unsigned int)BTN_STYLUS); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_down_btn_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_push_event_frame(dev); litest_tablet_tip_down(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), (unsigned int)BTN_STYLUS); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 30); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 10, 20, axes); litest_drain_events(li); /* same thing with a release at tip-down */ litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_push_event_frame(dev); litest_tablet_tip_down(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), (unsigned int)BTN_STYLUS); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_down_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y, last_x, last_y; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); /* move x/y on tip down, make sure x/y changed */ litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_tip_down(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_lt(last_x, x); litest_assert_double_lt(last_y, y); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_up_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y, last_x, last_y; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_tip_down(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); /* move x/y on tip up, make sure x/y changed */ litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 40, 40, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_ne(last_x, x); litest_assert_double_ne(last_y, y); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_up_motion_one_axis) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y, last_x, last_y; double start_x = 20, start_y = 20; int axis = litest_test_param_get_i32(test_env->params, "axis"); switch (axis) { case ABS_X: start_x = 15; start_y = 20; break; case ABS_Y: start_x = 20; start_y = 15; break; default: abort(); } /* generate enough events to fill the history and move alonge the * current axis to avoid axis smoothing interference */ litest_tablet_proximity_in(dev, start_x, start_y, axes); litest_axis_set_value(axes, ABS_PRESSURE, 20); for (int i = 0; i < 5; i++) { litest_tablet_tip_down(dev, start_x, start_y, axes); switch (axis) { case ABS_X: start_x++; break; case ABS_Y: start_y++; break; } } litest_drain_events(li); litest_tablet_motion(dev, 20, 20, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); /* move x on tip up, make sure x/y changed */ litest_axis_set_value(axes, ABS_PRESSURE, 0); switch (axis) { case ABS_X: litest_tablet_tip_up(dev, 40, 20, axes); break; case ABS_Y: litest_tablet_tip_up(dev, 20, 40, axes); break; } litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); switch(axis) { case ABS_X: litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); litest_assert_double_ne(last_x, x); litest_assert_double_eq(last_y, y); break; case ABS_Y: litest_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); litest_assert_double_eq(last_x, x); litest_assert_double_ne(last_y, y); break; } libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_state_proximity) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_tablet_tip_down(dev, 10, 10, axes); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_tablet_tip_up(dev, 10, 10, axes); litest_drain_events(li); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); } END_TEST START_TEST(tip_state_axis) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_tablet_tip_down(dev, 40, 40, axes); litest_drain_events(li); litest_tablet_motion(dev, 30, 30, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_tablet_tip_up(dev, 40, 40, axes); litest_drain_events(li); litest_tablet_motion(dev, 40, 80, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_state_button) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_button_click(dev, button, true); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_tablet_tip_down(dev, 40, 40, axes); litest_drain_events(li); litest_button_click(dev, button, false); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_tablet_tip_up(dev, 40, 40, axes); litest_drain_events(li); litest_button_click(dev, button, true); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_button_click(dev, button, false); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(tip_up_on_delete) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, 10, 10, axes); litest_drain_events(li); litest_delete_device(dev); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_destroy_context(li); } END_TEST START_TEST(proximity_in_out) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; enum libinput_tablet_tool_type type; bool have_tool_update = false, have_proximity_out = false; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_drain_events(li); switch (dev->which) { case LITEST_DELL_CANVAS_TOTEM: type = LIBINPUT_TABLET_TOOL_TYPE_TOTEM; break; default: type = LIBINPUT_TABLET_TOOL_TYPE_PEN; break; } litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_tablet_tool * tool; litest_assert(!have_tool_update); have_tool_update = true; tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), type); } libinput_event_destroy(event); } litest_assert(have_tool_update); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(event); if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) have_proximity_out = true; } libinput_event_destroy(event); } litest_assert(have_proximity_out); /* Proximity out must not emit axis events */ litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_in_button_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); litest_drain_events(li); litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, button, 1); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_tablet_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_out_button_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_button_click(dev, button, true); litest_drain_events(li); litest_push_event_frame(dev); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, button, 0); litest_pop_event_frame(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_out_clear_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; uint32_t stylus_buttons[] = {BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3}; bool have_proximity = false; double x = 50, y = 50; litest_drain_events(li); /* Test that proximity out events send button releases for any currently * pressed stylus buttons */ ARRAY_FOR_EACH(stylus_buttons, button) { bool button_released = false; uint32_t event_button = 0; enum libinput_button_state state; if (!libevdev_has_event_code(dev->evdev, EV_KEY, *button)) continue; litest_tablet_proximity_in(dev, x++, y++, axes); litest_drain_events(li); litest_event(dev, EV_KEY, *button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_tablet_proximity_out(dev); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); do { tablet_event = libinput_event_get_tablet_tool_event(event); if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { have_proximity = true; libinput_event_destroy(event); break; } if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { event_button = libinput_event_tablet_tool_get_button(tablet_event); state = libinput_event_tablet_tool_get_button_state(tablet_event); if (event_button == *button && state == LIBINPUT_BUTTON_STATE_RELEASED) button_released = true; } libinput_event_destroy(event); } while ((event = libinput_get_event(li))); litest_assert_msg(button_released, "Button %s (%d) was not released.", libevdev_event_code_get_name(EV_KEY, *button), event_button); litest_assert(have_proximity); litest_assert_empty_queue(li); } } END_TEST START_TEST(proximity_has_axes) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; double x, y, distance; double last_x, last_y, last_distance = 0.0, last_tx = 0.0, last_ty = 0.0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 10 }, { ABS_TILT_Y, 10 }, { -1, -1} }; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); if (libinput_tablet_tool_has_distance(tool)) { litest_assert(libinput_event_tablet_tool_distance_has_changed( tablet_event)); distance = libinput_event_tablet_tool_get_distance(tablet_event); litest_assert_double_ne(distance, 0); } if (libinput_tablet_tool_has_tilt(tool)) { litest_assert(libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); litest_assert(libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)); x = libinput_event_tablet_tool_get_tilt_x(tablet_event); y = libinput_event_tablet_tool_get_tilt_y(tablet_event); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); } litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_empty_queue(li); libinput_event_destroy(event); litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_axis_set_value(axes, ABS_TILT_X, 15); litest_axis_set_value(axes, ABS_TILT_Y, 25); /* work around axis smoothing */ litest_tablet_motion(dev, 20, 30, axes); litest_tablet_motion(dev, 20, 29, axes); litest_tablet_motion(dev, 20, 31, axes); litest_drain_events(li); litest_tablet_motion(dev, 20, 30, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); if (libinput_tablet_tool_has_distance(tool)) last_distance = libinput_event_tablet_tool_get_distance( tablet_event); if (libinput_tablet_tool_has_tilt(tool)) { last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event); last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event); } libinput_event_destroy(event); /* Make sure that the axes are still present on proximity out */ litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); litest_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_ge(x, last_x - 1); litest_assert_double_le(x, last_x + 1); litest_assert_double_ge(y, last_y - 1); litest_assert_double_le(y, last_y + 1); if (libinput_tablet_tool_has_distance(tool)) { litest_assert(!libinput_event_tablet_tool_distance_has_changed( tablet_event)); distance = libinput_event_tablet_tool_get_distance( tablet_event); litest_assert_double_eq(distance, last_distance); } if (libinput_tablet_tool_has_tilt(tool)) { litest_assert(!libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); litest_assert(!libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)); x = libinput_event_tablet_tool_get_tilt_x(tablet_event); y = libinput_event_tablet_tool_get_tilt_y(tablet_event); litest_assert_double_eq(x, last_tx); litest_assert_double_eq(y, last_ty); } litest_assert_empty_queue(li); libinput_event_destroy(event); } END_TEST START_TEST(proximity_range_enter) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 90 }, { -1, -1 } }; litest_drain_events(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 10, 10, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_range_in_out) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { -1, -1 } }; litest_drain_events(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_tablet_motion(dev, 30, 30, axes); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 10, 10, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_range_button_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 90 }, { -1, -1 } }; litest_drain_events(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_range_button_press) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { -1, -1 } }; litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_tablet_button_event(li, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 15, 15, axes); litest_dispatch(li); /* expect fake button release */ litest_assert_tablet_button_event(li, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_range_button_release) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 90 }, { -1, -1 } }; litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 15, 15, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); /* expect fake button press */ litest_assert_tablet_button_event(li, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_tablet_button_event(li, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 0); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); } END_TEST START_TEST(proximity_out_slow_event) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 90 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_motion(dev, 12, 12, axes); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_dispatch(li); /* The forced prox out */ litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); litest_tablet_proximity_out(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_out_not_during_contact) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_motion(dev, 12, 12, axes); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_dispatch(li); /* No forced proxout yet */ litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_motion(dev, 14, 14, axes); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_dispatch(li); /* The forced prox out */ litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_tablet_proximity_out(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_out_not_during_buttonpress) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_motion(dev, 12, 12, axes); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_timeout_tablet_proxout(); litest_dispatch(li); /* No forced proxout yet */ litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_timeout_tablet_proxout(); litest_dispatch(li); /* The forced prox out */ litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_tablet_proximity_out(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(proximity_out_disables_forced) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; /* A correct proximity out sequence from the device should disable the forced proximity out */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); /* expect no timeout-based prox out */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_empty_queue(li); litest_tablet_proximity_out(dev); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_dispatch(li); } END_TEST START_TEST(proximity_out_disables_forced_after_forced) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; /* A correct proximity out sequence from the device should disable the forced proximity out, even when we had a forced prox-out */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); /* timeout-based forced prox out */ litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); /* now send the real prox out (we're already in proximity out) and * that should disable the proxout quirk */ litest_tablet_proximity_out(dev); litest_dispatch(li); litest_assert_empty_queue(li); /* same again, but this time we expect no timeout-based prox out */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_empty_queue(li); litest_tablet_proximity_out(dev); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_dispatch(li); } END_TEST START_TEST(proximity_out_on_delete) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); litest_tablet_proximity_in(dev, 10, 10, NULL); litest_drain_events(li); litest_delete_device(dev); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_destroy_context(li); } END_TEST START_TEST(motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; int test_x, test_y; double last_reported_x = 0, last_reported_y = 0; enum libinput_event_type type; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool x_changed, y_changed; double reported_x, reported_y; litest_drain_events(li); litest_tablet_proximity_in(dev, 5, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x_changed = libinput_event_tablet_tool_x_has_changed(tablet_event); y_changed = libinput_event_tablet_tool_y_has_changed(tablet_event); litest_assert(x_changed); litest_assert(y_changed); reported_x = libinput_event_tablet_tool_get_x(tablet_event); reported_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_lt(reported_x, reported_y); last_reported_x = reported_x; last_reported_y = reported_y; libinput_event_destroy(event); for (test_x = 10, test_y = 90; test_x <= 100; test_x += 10, test_y -= 10) { bool x_changed, y_changed; double reported_x, reported_y; litest_tablet_motion(dev, test_x, test_y, axes); litest_dispatch(li); while ((event = libinput_get_event(li))) { tablet_event = libinput_event_get_tablet_tool_event(event); type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { x_changed = libinput_event_tablet_tool_x_has_changed( tablet_event); y_changed = libinput_event_tablet_tool_y_has_changed( tablet_event); litest_assert(x_changed); litest_assert(y_changed); reported_x = libinput_event_tablet_tool_get_x( tablet_event); reported_y = libinput_event_tablet_tool_get_y( tablet_event); litest_assert_double_gt(reported_x, last_reported_x); litest_assert_double_lt(reported_y, last_reported_y); last_reported_x = reported_x; last_reported_y = reported_y; } libinput_event_destroy(event); } } } END_TEST START_TEST(left_handed) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; double libinput_max_x, libinput_max_y; double last_x = -1.0, last_y = -1.0; double x, y; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_drain_events(li); litest_assert(libinput_device_config_left_handed_is_available(dev->libinput_device)); libinput_device_get_size (dev->libinput_device, &libinput_max_x, &libinput_max_y); /* Test that left-handed mode doesn't go into effect until the tool has * left proximity of the tablet. In order to test this, we have to bring * the tool into proximity and make sure libinput processes the * proximity events so that it updates it's internal tablet state, and * then try setting it to left-handed mode. */ litest_tablet_proximity_in(dev, 0, 100, axes); litest_dispatch(li); libinput_device_config_left_handed_set(dev->libinput_device, 1); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(last_x, 0); litest_assert_double_eq(last_y, libinput_max_y); libinput_event_destroy(event); /* work around smoothing */ litest_axis_set_value(axes, ABS_DISTANCE, 9); litest_tablet_motion(dev, 100, 0, axes); litest_axis_set_value(axes, ABS_DISTANCE, 7); litest_tablet_motion(dev, 100, 0, axes); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_tablet_motion(dev, 100, 0, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 5); litest_tablet_motion(dev, 100, 0, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(x, libinput_max_x); litest_assert_double_eq(y, 0); litest_assert_double_gt(x, last_x); litest_assert_double_lt(y, last_y); libinput_event_destroy(event); litest_tablet_proximity_out(dev); litest_drain_events(li); /* Since we've drained the events and libinput's aware the tool is out * of proximity, it should have finally transitioned into left-handed * mode, so the axes should be inverted once we bring it back into * proximity */ litest_tablet_proximity_in(dev, 0, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(last_x, libinput_max_x); litest_assert_double_eq(last_y, 0); libinput_event_destroy(event); /* work around smoothing */ litest_axis_set_value(axes, ABS_DISTANCE, 9); litest_tablet_motion(dev, 100, 0, axes); litest_axis_set_value(axes, ABS_DISTANCE, 7); litest_tablet_motion(dev, 100, 0, axes); litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_tablet_motion(dev, 100, 0, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 5); litest_tablet_motion(dev, 100, 0, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(x, 0); litest_assert_double_eq(y, libinput_max_y); litest_assert_double_lt(x, last_x); litest_assert_double_gt(y, last_y); libinput_event_destroy(event); #endif } END_TEST START_TEST(no_left_handed) { struct litest_device *dev = litest_current_device(); /* Without libwacom we default to left-handed being available */ #if HAVE_LIBWACOM litest_assert(!libinput_device_config_left_handed_is_available(dev->libinput_device)); #else litest_assert(libinput_device_config_left_handed_is_available(dev->libinput_device)); #endif } END_TEST START_TEST(left_handed_tilt) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; enum libinput_config_status status; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 90 }, { ABS_TILT_Y, 10 }, { -1, -1 } }; double tx, ty; status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tx = libinput_event_tablet_tool_get_tilt_x(tev); ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_lt(tx, 0); litest_assert_double_gt(ty, 0); libinput_event_destroy(event); #endif } END_TEST static inline double rotate_event(struct litest_device *dev, int angle_degrees) { struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; double a = (angle_degrees - 90 - 175)/180.0 * M_PI; double val; int x, y; int tilt_center_x, tilt_center_y; abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X); litest_assert_notnull(abs); tilt_center_x = absinfo_range(abs) / 2; abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y); litest_assert_notnull(abs); tilt_center_y = absinfo_range(abs) / 2; x = cos(a) * 20 + tilt_center_x; y = sin(a) * 20 + tilt_center_y; litest_event(dev, EV_ABS, ABS_TILT_X, x); litest_event(dev, EV_ABS, ABS_TILT_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_rotation(tev); libinput_event_destroy(event); litest_assert_empty_queue(li); return val; } START_TEST(left_handed_mouse_rotation) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; enum libinput_config_status status; int angle; double val, old_val = 0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } }; status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_drain_events(li); /* cos/sin are 90 degrees offset from the north-is-zero that libinput uses. 175 is the CCW offset in the mouse HW */ for (angle = 185; angle < 540; angle += 5) { int expected_angle = angle - 180; val = rotate_event(dev, angle % 360); /* rounding error galore, we can't test for anything more precise than these */ litest_assert_double_lt(val, 360.0); litest_assert_double_gt(val, old_val); litest_assert_double_lt(val, expected_angle + 5); old_val = val; } #endif } END_TEST START_TEST(left_handed_artpen_rotation) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; enum libinput_config_status status; double val; double scale; int angle; if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_left_handed_set(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); abs = libevdev_get_abs_info(dev->evdev, ABS_Z); litest_assert_notnull(abs); scale = absinfo_range(abs)/360.0; litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_ABS, ABS_Z, abs->minimum); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); for (angle = 188; angle < 540; angle += 8) { int a = angle * scale + abs->minimum; int expected_angle = angle - 180; litest_event(dev, EV_ABS, ABS_Z, a); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_rotation(tev); /* artpen has a 90 deg offset cw */ litest_assert_int_eq(round(val), (expected_angle + 90) % 360); libinput_event_destroy(event); litest_assert_empty_queue(li); } #endif } END_TEST START_TEST(motion_event_state) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; int test_x, test_y; double last_x, last_y; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; unsigned int button = pick_stylus_or_btn0(dev); litest_drain_events(li); litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); /* couple of events that go left/bottom to right/top */ for (test_x = 0, test_y = 100; test_x < 100; test_x += 10, test_y -= 10) litest_tablet_motion(dev, test_x, test_y, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); /* mark with a button event, then go back to bottom/left */ litest_button_click(dev, button, true); for (test_x = 100, test_y = 0; test_x > 0; test_x -= 10, test_y += 10) litest_tablet_motion(dev, test_x, test_y, axes); libinput_event_destroy(event); litest_dispatch(li); litest_assert_enum_eq(libinput_next_event_type(li), LIBINPUT_EVENT_TABLET_TOOL_AXIS); /* we expect all events up to the button event to go from bottom/left to top/right */ while ((event = libinput_get_event(li))) { double x, y; if (libinput_event_get_type(event) != LIBINPUT_EVENT_TABLET_TOOL_AXIS) break; tablet_event = libinput_event_get_tablet_tool_event(event); litest_assert_notnull(tablet_event); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert(x > last_x); litest_assert(y < last_y); last_x = x; last_y = y; libinput_event_destroy(event); } litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_TABLET_TOOL_BUTTON); libinput_event_destroy(event); } END_TEST START_TEST(motion_outside_bounds) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; double val; int i; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 50, 50, axes); litest_drain_events(li); /* Work around smoothing */ for (i = 5; i > 0; i--) { litest_event(dev, EV_ABS, ABS_X, 0 + 5 * i); litest_event(dev, EV_ABS, ABS_Y, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); /* On the 24HD x/y of 0 is outside the limit */ litest_event(dev, EV_ABS, ABS_X, 0); litest_event(dev, EV_ABS, ABS_Y, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); val = libinput_event_tablet_tool_get_x(tablet_event); litest_assert_double_lt(val, 0.0); val = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_gt(val, 0.0); val = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); litest_assert_double_lt(val, 0.0); libinput_event_destroy(event); /* Work around smoothing */ for (i = 5; i > 0; i--) { litest_event(dev, EV_ABS, ABS_X, 1000); litest_event(dev, EV_ABS, ABS_Y, 0 + 5 * i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); /* On the 24HD x/y of 0 is outside the limit */ litest_event(dev, EV_ABS, ABS_X, 1000); litest_event(dev, EV_ABS, ABS_Y, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); val = libinput_event_tablet_tool_get_x(tablet_event); litest_assert_double_gt(val, 0.0); val = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_lt(val, 0.0); val = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); litest_assert_double_lt(val, 0.0); libinput_event_destroy(event); } END_TEST START_TEST(bad_distance_events) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; const struct input_absinfo *absinfo; struct axis_replacement axes[] = { { -1, -1 }, }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); absinfo = libevdev_get_abs_info(dev->evdev, ABS_DISTANCE); litest_assert_notnull(absinfo); litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->maximum); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(tool_unique) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert(libinput_tablet_tool_is_unique(tool)); libinput_event_destroy(event); } END_TEST START_TEST(tool_serial) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), (uint64_t)1000); libinput_event_destroy(event); } END_TEST START_TEST(tool_id) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; uint64_t tool_id = 0; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, NULL); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_int_eq(libinput_device_get_id_vendor(dev->libinput_device), (unsigned int)VENDOR_ID_WACOM); switch (libinput_device_get_id_product(dev->libinput_device)) { case 0x27: /* Intuos 5 */ tool_id = 1050626; break; case 0xc6: /* Cintiq 12WX */ case 0xf4: /* Cintiq 24HD */ case 0x333: /* Cintiq 13HD */ case 0x350: /* Cintiq Pro 16 */ tool_id = 2083; break; default: litest_abort_msg("Invalid button code"); } litest_assert(tool_id == libinput_tablet_tool_get_tool_id(tool)); libinput_event_destroy(event); } END_TEST START_TEST(serial_changes_tool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 2000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), (uint64_t)2000); libinput_event_destroy(event); } END_TEST START_TEST(invalid_serials) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_int_eq(libinput_tablet_tool_get_serial(tool), (uint64_t)1000); } libinput_event_destroy(event); } } END_TEST START_TEST(tool_ref) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_notnull(tool); litest_assert(tool == libinput_tablet_tool_ref(tool)); litest_assert(tool == libinput_tablet_tool_unref(tool)); libinput_event_destroy(event); } END_TEST START_TEST(tool_user_data) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; void *userdata = &dev; /* not dereferenced */ litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); litest_assert_notnull(tool); litest_assert(libinput_tablet_tool_get_user_data(tool) == NULL); libinput_tablet_tool_set_user_data(tool, userdata); litest_assert(libinput_tablet_tool_get_user_data(tool) == userdata); libinput_tablet_tool_set_user_data(tool, NULL); litest_assert(libinput_tablet_tool_get_user_data(tool) == NULL); libinput_event_destroy(event); } END_TEST START_TEST(pad_buttons_ignored) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; int button; litest_drain_events(li); for (button = BTN_0; button < BTN_MOUSE; button++) { litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_assert_empty_queue(li); /* same thing while in prox */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); for (button = BTN_0; button < BTN_MOUSE; button++) litest_event(dev, EV_KEY, button, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); for (button = BTN_0; button < BTN_MOUSE; button++) litest_event(dev, EV_KEY, button, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(tools_with_serials) { struct libinput *li = litest_create_context(); struct litest_device *dev[2]; struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; struct libinput_event_tablet_tool *tev; int i; for (i = 0; i < 2; i++) { dev[i] = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); litest_drain_events(li); /* WARNING: this test fails if UI_GET_SYSNAME isn't * available or isn't used by libevdev (1.3, commit 2ff45c73). * Put a sleep(1) here and that usually fixes it. */ litest_push_event_frame(dev[i]); litest_tablet_proximity_in(dev[i], 10, 10, NULL); litest_event(dev[i], EV_MSC, MSC_SERIAL, 100); litest_pop_event_frame(dev[i]); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool[i] = libinput_event_tablet_tool_get_tool(tev); libinput_event_destroy(event); } /* We should get the same object for both devices */ litest_assert_notnull(tool[0]); litest_assert_notnull(tool[1]); litest_assert_ptr_eq(tool[0], tool[1]); litest_delete_device(dev[0]); litest_delete_device(dev[1]); litest_destroy_context(li); } END_TEST START_TEST(tools_without_serials) { struct libinput *li = litest_create_context(); struct litest_device *dev[2]; struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; struct libinput_event_tablet_tool *tev; int i; for (i = 0; i < 2; i++) { dev[i] = litest_add_device_with_overrides(li, LITEST_WACOM_ISDV4_E6_PEN, NULL, NULL, NULL, NULL); litest_drain_events(li); /* WARNING: this test fails if UI_GET_SYSNAME isn't * available or isn't used by libevdev (1.3, commit 2ff45c73). * Put a sleep(1) here and that usually fixes it. */ litest_tablet_proximity_in(dev[i], 10, 10, NULL); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool[i] = libinput_event_tablet_tool_get_tool(tev); libinput_event_destroy(event); } /* We should get different tool objects for each device */ litest_assert_notnull(tool[0]); litest_assert_notnull(tool[1]); litest_assert_ptr_ne(tool[0], tool[1]); litest_delete_device(dev[0]); litest_delete_device(dev[1]); litest_destroy_context(li); } END_TEST START_TEST(tool_delayed_serial) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; unsigned int serial; litest_drain_events(li); litest_event(dev, EV_ABS, ABS_X, 4500); litest_event(dev, EV_ABS, ABS_Y, 2000); litest_event(dev, EV_MSC, MSC_SERIAL, 0); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); serial = libinput_tablet_tool_get_serial(tool); litest_assert_int_eq(serial, (uint64_t)0); libinput_event_destroy(event); for (int x = 4500; x < 8000; x += 1000) { litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, 2000); litest_event(dev, EV_MSC, MSC_SERIAL, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); /* Now send the serial */ litest_event(dev, EV_ABS, ABS_X, 4500); litest_event(dev, EV_ABS, ABS_Y, 2000); litest_event(dev, EV_MSC, MSC_SERIAL, 1234566); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); serial = libinput_tablet_tool_get_serial(tool); litest_assert_int_eq(serial, (uint64_t)0); libinput_event_destroy(event); for (int x = 4500; x < 8000; x += 500) { litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, 2000); litest_event(dev, EV_MSC, MSC_SERIAL, 1234566); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } event = libinput_get_event(li); do { tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); serial = libinput_tablet_tool_get_serial(tool); litest_assert_int_eq(serial, (uint64_t)0); libinput_event_destroy(event); event = libinput_get_event(li); } while (event != NULL); /* Quirk: tool out event is a serial of 0 */ litest_event(dev, EV_ABS, ABS_X, 4500); litest_event(dev, EV_ABS, ABS_Y, 2000); litest_event(dev, EV_MSC, MSC_SERIAL, 0); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); serial = libinput_tablet_tool_get_serial(tool); litest_assert_int_eq(serial, (uint64_t)0); libinput_event_destroy(event); } END_TEST START_TEST(tool_capability) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)); } END_TEST START_TEST(tool_capabilities) { struct libinput *li = litest_create_context(); struct litest_device *intuos; struct litest_device *bamboo; struct libinput_event *event; struct libinput_event_tablet_tool *t; struct libinput_tablet_tool *tool; /* The axis capabilities of a tool can differ depending on the type of * tablet the tool is being used with */ bamboo = litest_add_device(li, LITEST_WACOM_BAMBOO_16FG_PEN); intuos = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN); litest_drain_events(li); litest_event(bamboo, EV_KEY, BTN_TOOL_PEN, 1); litest_event(bamboo, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); litest_assert(libinput_tablet_tool_has_pressure(tool)); litest_assert(libinput_tablet_tool_has_distance(tool)); litest_assert(!libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_event(intuos, EV_KEY, BTN_TOOL_PEN, 1); litest_event(intuos, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); litest_assert(libinput_tablet_tool_has_pressure(tool)); litest_assert(libinput_tablet_tool_has_distance(tool)); litest_assert(libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_delete_device(bamboo); litest_delete_device(intuos); litest_destroy_context(li); } END_TEST static inline bool tablet_has_mouse(struct litest_device *dev) { return libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_MOUSE) && libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM; } START_TEST(tool_type) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } }; struct tool_type_match { int code; enum libinput_tablet_tool_type type; } types[] = { { BTN_TOOL_PEN, LIBINPUT_TABLET_TOOL_TYPE_PEN }, { BTN_TOOL_RUBBER, LIBINPUT_TABLET_TOOL_TYPE_ERASER }, { BTN_TOOL_BRUSH, LIBINPUT_TABLET_TOOL_TYPE_BRUSH }, { BTN_TOOL_PENCIL, LIBINPUT_TABLET_TOOL_TYPE_PENCIL }, { BTN_TOOL_AIRBRUSH, LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH }, { BTN_TOOL_MOUSE, LIBINPUT_TABLET_TOOL_TYPE_MOUSE }, { BTN_TOOL_LENS, LIBINPUT_TABLET_TOOL_TYPE_LENS }, { -1, -1 } }; struct tool_type_match *tt; double x = 50, y = 50; litest_drain_events(li); for (tt = types; tt->code != -1; tt++) { enum libinput_tablet_tool_type type; if (!libevdev_has_event_code(dev->evdev, EV_KEY, tt->code)) continue; if ((tt->code == BTN_TOOL_MOUSE || tt->code == BTN_TOOL_LENS) && !tablet_has_mouse(dev)) continue; litest_tablet_set_tool_type(dev, tt->code); litest_tablet_proximity_in(dev, x, y, axes); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); type = libinput_tablet_tool_get_type(tool); /* Devices with doubled-up tool bits send the pen * in-prox and immediately out-of-prox before the real tool * type. Drop those two and continue with what we expect is * the real prox in event */ if (tt->type != LIBINPUT_TABLET_TOOL_TYPE_PEN && type == LIBINPUT_TABLET_TOOL_TYPE_PEN) { libinput_event_destroy(event); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); type = libinput_tablet_tool_get_type(tool); } litest_assert_int_eq(type, tt->type); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_tablet_proximity_out(dev); litest_drain_events(li); x++; y++; } } END_TEST START_TEST(tool_in_prox_before_start) { struct libinput *li; struct litest_device *dev = litest_current_device(); struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } }; const char *devnode; uint64_t serial; litest_tablet_proximity_in(dev, 10, 10, axes); /* for simplicity, we create a new litest context */ devnode = libevdev_uinput_get_devnode(dev->uinput); li = litest_create_context(); libinput_path_add_device(li, devnode); litest_drain_events_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); litest_assert_empty_queue(li); litest_tablet_motion(dev, 10, 20, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); serial = libinput_tablet_tool_get_serial(tool); libinput_event_destroy(event); litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_tablet_motion(dev, 30, 40, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_int_eq(serial, libinput_tablet_tool_get_serial(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_button_click(dev, BTN_STYLUS, true); litest_button_click(dev, BTN_STYLUS, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); libinput_event_destroy(event); litest_destroy_context(li); } END_TEST START_TEST(tool_direct_switch_skip_tool_update) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); libinput_tablet_tool_ref(tool); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tev), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tev), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_assert_ptr_ne(libinput_event_tablet_tool_get_tool(tev), tool); libinput_tablet_tool_unref(tool); tool = libinput_event_tablet_tool_get_tool(tev); libinput_tablet_tool_ref(tool); libinput_event_destroy(event); litest_tablet_motion(dev, 20, 30, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tev), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); litest_push_event_frame(dev); litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); litest_tablet_motion(dev, 30, 40, axes); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(tev), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); litest_tablet_motion(dev, 40, 30, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); litest_push_event_frame(dev); litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); litest_tablet_proximity_out(dev); litest_pop_event_frame(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), tool); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); libinput_tablet_tool_unref(tool); } END_TEST START_TEST(tool_direct_switch_with_forced_proxout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* This is a *very* specific event sequence to trigger a bug: - pen proximity in - pen proximity forced out - eraser proximity in without axis movement - eraser axis move */ /* pen prox in */ litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); /* pen motion */ litest_tablet_motion(dev, 20, 30, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); /* pen forced prox out */ litest_timeout_tablet_proxout(); litest_dispatch(li); /* actual prox out for tablets that don't do forced prox out */ litest_tablet_proximity_out(dev); litest_dispatch(li); event = libinput_get_event(li); litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libinput_event_destroy(event); /* eraser prox in without axes */ litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); litest_is_proximity_event(event, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); /* eraser motion */ litest_tablet_motion(dev, 30, 40, axes); litest_tablet_motion(dev, 40, 50, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(stylus_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; uint32_t stylus_buttons[] = {BTN_STYLUS, BTN_STYLUS2, BTN_STYLUS3}; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x200); /* 3-button stylus tool_id */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); libinput_tablet_tool_ref(tool); libinput_event_destroy(event); ARRAY_FOR_EACH(stylus_buttons, code) { litest_event(dev, EV_KEY, *code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, *code, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_tablet_button_event(li, *code, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_tablet_button_event(li, *code, LIBINPUT_BUTTON_STATE_RELEASED); } libinput_tablet_tool_unref(tool); } END_TEST START_TEST(mouse_tool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_MOUSE); libinput_event_destroy(event); } END_TEST START_TEST(mouse_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; int code; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); libinput_tablet_tool_ref(tool); libinput_event_destroy(event); for (code = BTN_LEFT; code <= BTN_TASK; code++) { bool has_button = libevdev_has_event_code(dev->evdev, EV_KEY, code); litest_assert_int_eq(!!has_button, !!libinput_tablet_tool_has_button(tool, code)); if (!has_button) continue; litest_event(dev, EV_KEY, code, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, code, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_tablet_button_event(li, code, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_tablet_button_event(li, code, LIBINPUT_BUTTON_STATE_RELEASED); } libinput_tablet_tool_unref(tool); } END_TEST START_TEST(mouse_rotation) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int angle; double val, old_val = 0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } }; litest_drain_events(li); litest_push_event_frame(dev); litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); litest_pop_event_frame(dev); litest_drain_events(li); /* cos/sin are 90 degrees offset from the north-is-zero that libinput uses. 175 is the CCW offset in the mouse HW */ for (angle = 5; angle < 360; angle += 5) { val = rotate_event(dev, angle); /* rounding error galore, we can't test for anything more precise than these */ litest_assert_double_lt(val, 360.0); litest_assert_double_gt(val, old_val); litest_assert_double_lt(val, angle + 5); old_val = val; } } END_TEST START_TEST(mouse_wheel) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; const struct input_absinfo *abs; double val; int i; if (!libevdev_has_event_code(dev->evdev, EV_REL, REL_WHEEL)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); libinput_tablet_tool_ref(tool); libinput_event_destroy(event); litest_assert(libinput_tablet_tool_has_wheel(tool)); for (i = 0; i < 3; i++) { litest_event(dev, EV_REL, REL_WHEEL, -1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_wheel_delta(tev); litest_assert_int_eq(val, 15); val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); litest_assert_int_eq(val, 1); libinput_event_destroy(event); litest_assert_empty_queue(li); } for (i = 2; i < 5; i++) { /* send x/y events to make sure we reset the wheel */ abs = libevdev_get_abs_info(dev->evdev, ABS_X); litest_event(dev, EV_ABS, ABS_X, absinfo_range(abs)/i); abs = libevdev_get_abs_info(dev->evdev, ABS_Y); litest_event(dev, EV_ABS, ABS_Y, absinfo_range(abs)/i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_wheel_delta(tev); litest_assert_int_eq(val, 0); val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); litest_assert_int_eq(val, 0); libinput_event_destroy(event); litest_assert_empty_queue(li); } libinput_tablet_tool_unref(tool); } END_TEST START_TEST(airbrush_tool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_AIRBRUSH)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); litest_assert(libinput_tablet_tool_has_slider(tool)); libinput_event_destroy(event); } END_TEST START_TEST(airbrush_slider) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; double val; int v; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_AIRBRUSH)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); abs = libevdev_get_abs_info(dev->evdev, ABS_WHEEL); litest_assert_notnull(abs); litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1); litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); /* start with non-zero */ litest_event(dev, EV_ABS, ABS_WHEEL, 10); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); for (v = abs->minimum; v < abs->maximum; v += 8) { double expected = absinfo_normalize_value(abs, v) * 2 - 1; litest_event(dev, EV_ABS, ABS_WHEEL, v); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_slider_has_changed(tev)); val = libinput_event_tablet_tool_get_slider_position(tev); litest_assert_double_eq(val, expected); litest_assert_double_ge(val, -1.0); litest_assert_double_le(val, 1.0); libinput_event_destroy(event); litest_assert_empty_queue(li); } } END_TEST START_TEST(artpen_tool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert_notnull(tool); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); litest_assert(libinput_tablet_tool_has_rotation(tool)); libinput_event_destroy(event); } END_TEST START_TEST(artpen_rotation) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; double val; double scale; int angle; if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_Z)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); abs = libevdev_get_abs_info(dev->evdev, ABS_Z); litest_assert_notnull(abs); scale = absinfo_range(abs)/360.0; litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1); litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */ litest_event(dev, EV_MSC, MSC_SERIAL, 1000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_ABS, ABS_Z, abs->minimum); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); for (angle = 8; angle < 360; angle += 8) { int a = angle * scale + abs->minimum; litest_event(dev, EV_ABS, ABS_Z, a); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_rotation(tev); /* artpen has a 90 deg offset cw */ litest_assert_int_eq(round(val), (angle + 90) % 360); libinput_event_destroy(event); litest_assert_empty_queue(li); } } END_TEST START_TEST(tablet_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; uint64_t time_usec; litest_drain_events(li); litest_tablet_proximity_in(dev, 5, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); time_usec = libinput_event_tablet_tool_get_time_usec(tev); litest_assert_int_eq(libinput_event_tablet_tool_get_time(tev), (uint32_t) (time_usec / 1000)); libinput_event_destroy(event); } END_TEST START_TEST(tablet_pressure_distance_exclusive) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 }, }; double pressure, distance; litest_tablet_proximity_in(dev, 5, 50, axes); litest_drain_events(li); /* We have 0.1% pressure above minimum threshold but we're still below * the tip threshold */ litest_axis_set_value(axes, ABS_PRESSURE, 1.1); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); pressure = libinput_event_tablet_tool_get_pressure(tev); distance = libinput_event_tablet_tool_get_distance(tev); litest_assert_double_eq(pressure, 0.001); litest_assert_double_eq(distance, 0.0); libinput_event_destroy(event); /* We have pressure and we're above the tip threshold now */ litest_axis_set_value(axes, ABS_PRESSURE, 5.5); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); pressure = libinput_event_tablet_tool_get_pressure(tev); distance = libinput_event_tablet_tool_get_distance(tev); litest_assert_double_gt(pressure, 0.0); litest_assert_double_eq(distance, 0.0); libinput_event_destroy(event); } END_TEST static bool device_has_calibration(struct litest_device *dev) { if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return true; bool has_calibration = libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_PEN) || libevdev_has_event_code(dev->evdev, EV_KEY, BTN_STYLUS); #if HAVE_LIBWACOM WacomDeviceDatabase *db = libwacom_database_new(); if (db) { WacomDevice *d = libwacom_new_from_path(db, libevdev_uinput_get_devnode(dev->uinput), WFALLBACK_NONE, NULL); if (d) { has_calibration = !!(libwacom_get_integration_flags(d) & (WACOM_DEVICE_INTEGRATED_SYSTEM|WACOM_DEVICE_INTEGRATED_DISPLAY)); libwacom_destroy(d); } libwacom_database_destroy(db); } #endif return has_calibration; } START_TEST(tablet_calibration_has_matrix) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; int rc; float calibration[6] = {1, 0, 0, 0, 1, 0}; int has_calibration; has_calibration = device_has_calibration(dev); rc = libinput_device_config_calibration_has_matrix(d); litest_assert_int_eq(rc, has_calibration); rc = libinput_device_config_calibration_get_matrix(d, calibration); litest_assert_int_eq(rc, 0); rc = libinput_device_config_calibration_get_default_matrix(d, calibration); litest_assert_int_eq(rc, 0); status = libinput_device_config_calibration_set_matrix(d, calibration); if (has_calibration) litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); else litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(tablet_calibration_set_matrix_delta) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; float calibration[6] = {0.5, 0, 0, 0, 0.5, 0}; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 } }; double x, y, dx, dy, mdx, mdy; if (!device_has_calibration(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_tablet_proximity_in(dev, 100, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); libinput_event_destroy(event); litest_tablet_motion(dev, 80, 80, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_x(tablet_event) - x; dy = libinput_event_tablet_tool_get_y(tablet_event) - y; libinput_event_destroy(event); litest_tablet_proximity_out(dev); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_drain_events(li); status = libinput_device_config_calibration_set_matrix(d, calibration); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_tablet_proximity_in(dev, 100, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); libinput_event_destroy(event); litest_tablet_motion(dev, 80, 80, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); mdx = libinput_event_tablet_tool_get_x(tablet_event) - x; mdy = libinput_event_tablet_tool_get_y(tablet_event) - y; libinput_event_destroy(event); litest_drain_events(li); litest_assert_double_gt(dx, mdx * 2 - 1); litest_assert_double_lt(dx, mdx * 2 + 1); litest_assert_double_gt(dy, mdy * 2 - 1); litest_assert_double_lt(dy, mdy * 2 + 1); } END_TEST START_TEST(tablet_calibration_set_matrix) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; float calibration[6] = {0.5, 0, 0, 0, 1, 0}; struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; if (!device_has_calibration(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); status = libinput_device_config_calibration_set_matrix(d, calibration); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_tablet_proximity_in(dev, 100, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); libinput_event_destroy(event); litest_assert_double_gt(x, 49.0); litest_assert_double_lt(x, 51.0); litest_assert_double_gt(y, 99.0); litest_assert_double_lt(y, 100.0); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_tablet_proximity_in(dev, 50, 50, axes); litest_tablet_proximity_out(dev); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_drain_events(li); calibration[0] = 1; calibration[4] = 0.5; status = libinput_device_config_calibration_set_matrix(d, calibration); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_tablet_proximity_in(dev, 100, 100, axes); litest_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); libinput_event_destroy(event); litest_assert(x > 99.0); litest_assert(x < 100.0); litest_assert(y > 49.0); litest_assert(y < 51.0); litest_tablet_proximity_out(dev); } END_TEST START_TEST(tablet_area_has_rectangle) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; int rc; struct libinput_config_area_rectangle rect; int has_area = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); rc = libinput_device_config_area_has_rectangle(d); litest_assert_int_eq(rc, has_area); rect = libinput_device_config_area_get_rectangle(d); litest_assert_double_eq(rect.x1, 0.0); litest_assert_double_eq(rect.y1, 0.0); litest_assert_double_eq(rect.x2, 1.0); litest_assert_double_eq(rect.y2, 1.0); rect = libinput_device_config_area_get_default_rectangle(d); litest_assert_double_eq(rect.x1, 0.0); litest_assert_double_eq(rect.y1, 0.0); litest_assert_double_eq(rect.x2, 1.0); litest_assert_double_eq(rect.y2, 1.0); status = libinput_device_config_area_set_rectangle(d, &rect); if (has_area) litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); else litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(tablet_area_set_rectangle_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; int rc; struct libinput_config_area_rectangle rect; int has_area = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); if (!has_area) return LITEST_NOT_APPLICABLE; rect.x1 = 1.0; rect.x2 = 0.9; rect.y1 = 0.0; rect.y2 = 1.0; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); rect.x1 = 0.9; rect.x2 = 1.0; rect.y1 = 1.0; rect.y2 = 0.9; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); rect.x1 = 0.9; rect.x2 = 0.9; rect.y1 = 0.9; rect.y2 = 1.0; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); rect.x1 = 0.9; rect.x2 = 1.0; rect.y1 = 0.9; rect.y2 = 0.9; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); rect.x1 = 0.9; rect.x2 = 1.5; rect.y1 = 0.0; rect.y2 = 1.0; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); rect.x1 = 0.0; rect.x2 = 1.0; rect.y1 = 0.9; rect.y2 = 1.4; rc = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(rc, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST static void get_tool_xy(struct libinput *li, double *x, double *y) { struct libinput_event *event = libinput_get_event(li); struct libinput_event_tablet_tool *tev; litest_assert_ptr_notnull(event); switch (libinput_event_get_type(event)) { case LIBINPUT_EVENT_TABLET_TOOL_AXIS: tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); break; default: abort(); } *x = libinput_event_tablet_tool_get_x_transformed(tev, 100); *y = libinput_event_tablet_tool_get_y_transformed(tev, 100); libinput_event_destroy(event); } START_TEST(tablet_area_set_rectangle) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; double *scaled, *unscaled; const char *param_axis = litest_test_param_get_string(test_env->params, "axis"); const char *param_direction = litest_test_param_get_string(test_env->params, "direction"); bool use_vertical = streq(param_axis, "vertical"); int direction = streq(param_direction, "down") ? 1 : -1; if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; struct libinput_config_area_rectangle rect; if (use_vertical) { rect = (struct libinput_config_area_rectangle){ 0.25, 0.0, 0.75, 1.0, }; scaled = &x; unscaled = &y; } else { rect = (struct libinput_config_area_rectangle){ 0.0, 0.25, 1.0, 0.75, }; scaled = &y; unscaled = &x; } enum libinput_config_status status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); /* move from the center out */ litest_tablet_proximity_in(dev, 50, 50, axes); libinput_dispatch(li); get_tool_xy(li, &x, &y); litest_assert_double_eq_epsilon(*scaled, 50.0, 2); litest_assert_double_eq_epsilon(*unscaled, 50.0, 2); int i; for (i = 50; i > 0 && i <= 100; i += 5 * direction) { /* Negate any smoothing */ litest_tablet_motion(dev, i, i, axes); litest_tablet_motion(dev, i - 1, i, axes); litest_tablet_motion(dev, i, i - 1, axes); litest_drain_events(li); litest_tablet_motion(dev, i, i, axes); libinput_dispatch(li); get_tool_xy(li, &x, &y); if (i <= 25) litest_assert_double_eq(*scaled, 0.0); else if (i > 75) litest_assert_double_eq_epsilon(*scaled, 100.0, 1); else litest_assert_double_eq_epsilon(*scaled, (i - 25) * 2, 1); litest_assert_double_eq_epsilon(*unscaled, i, 2); } double final_stop = max(0.0, min(100.0, i)); /* Push through any smoothing */ litest_tablet_motion(dev, final_stop, final_stop, axes); litest_tablet_motion(dev, final_stop, final_stop, axes); libinput_dispatch(li); litest_drain_events(li); litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); libinput_dispatch(li); get_tool_xy(li, &x, &y); litest_assert_double_eq_epsilon(x, final_stop, 1); litest_assert_double_eq_epsilon(y, final_stop, 1); } END_TEST START_TEST(tablet_area_set_rectangle_move_outside) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; struct libinput_config_area_rectangle rect = { 0.25, 0.25, 0.75, 0.75, }; enum libinput_config_status status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); /* move in/out of prox outside the area */ litest_tablet_proximity_in(dev, 5, 5, axes); litest_tablet_proximity_out(dev); libinput_dispatch(li); litest_timeout_tablet_proxout(); libinput_dispatch(li); litest_assert_empty_queue(li); x = 5; y = 5; /* Move around the area - since we stay outside the area expect no events */ litest_tablet_proximity_in(dev, x, y, axes); libinput_dispatch(li); for (; x < 90; x += 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, x, y, axes); for (; y < 90; y += 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, x, y, axes); for (; x > 5; x -= 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, x, y, axes); for (; y > 5; y -= 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, x, y, axes); litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); libinput_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(tablet_area_set_rectangle_move_outside_to_inside) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; struct libinput_config_area_rectangle rect = { 0.25, 0.25, 0.75, 0.75, }; enum libinput_config_status status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); x = 5; y = 50; /* Move into the center of the area - since we started outside the area * expect no events */ litest_tablet_proximity_in(dev, x, y, axes); libinput_dispatch(li); for (; x < 50; x += 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, x, y, axes); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, x, y, axes); litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); libinput_dispatch(li); litest_assert_empty_queue(li); y = 5; x = 50; litest_tablet_proximity_in(dev, x, y, axes); for (; y < 50; y += 5) { litest_tablet_motion(dev, x, y, axes); libinput_dispatch(li); litest_assert_empty_queue(li); } litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click(dev, BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, x, y, axes); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, x, y, axes); litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); libinput_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(tablet_area_set_rectangle_move_in_margin) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; struct libinput_event *ev; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; struct libinput_config_area_rectangle rect = { 0.25, 0.25, 0.75, 0.75, }; enum libinput_config_status status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); /* move in/out of prox outside the area but within the margin */ litest_tablet_proximity_in(dev, 24, 24, axes); litest_tablet_proximity_out(dev); libinput_dispatch(li); litest_timeout_tablet_proxout(); libinput_dispatch(li); ev = libinput_get_event(li); tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); x = libinput_event_tablet_tool_get_x(tev); y = libinput_event_tablet_tool_get_y(tev); litest_assert_double_eq(x, 0.0); litest_assert_double_eq(y, 0.0); libinput_event_destroy(ev); ev = libinput_get_event(li); tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); x = libinput_event_tablet_tool_get_x(tev); y = libinput_event_tablet_tool_get_y(tev); litest_assert_double_eq(x, 0.0); litest_assert_double_eq(y, 0.0); libinput_event_destroy(ev); } END_TEST START_TEST(tablet_area_set_rectangle_while_outside) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *d = dev->libinput_device; struct libinput_event *ev; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; if (libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; litest_checkpoint("Set tablet area"); struct libinput_config_area_rectangle rect = { 0.25, 0.25, 0.75, 0.75, }; enum libinput_config_status status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_checkpoint("Proximity in + out outside tablet area"); litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_empty_queue(li); litest_dispatch(li); litest_checkpoint("Update tablet area"); rect = (struct libinput_config_area_rectangle) { 0.05, 0.05, 0.95, 0.95, }; status = libinput_device_config_area_set_rectangle(d, &rect); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_checkpoint("Proximity in + out inside tablet area"); litest_tablet_proximity_in(dev, 11, 11, axes); litest_tablet_motion(dev, 12, 12, axes); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); litest_assert_double_gt(x, 6); /* somewhere around 6%, precise number doesn't matter */ litest_assert_double_gt(y, 6); libinput_event_destroy(ev); ev = libinput_get_event(li); tev = litest_is_tablet_event(ev, LIBINPUT_EVENT_TABLET_TOOL_AXIS); x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); litest_assert_double_gt(x, 6); litest_assert_double_gt(y, 6); libinput_event_destroy(ev); ev = libinput_get_event(li); tev = litest_is_proximity_event(ev, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); x = libinput_event_tablet_tool_get_x_transformed(tev, 100.0); y = libinput_event_tablet_tool_get_y_transformed(tev, 100.0); litest_assert_double_gt(x, 6); litest_assert_double_gt(y, 6); libinput_event_destroy(ev); } END_TEST static void assert_pressure(struct libinput *li, enum libinput_event_type type, double expected_pressure) { struct libinput_event *event = libinput_get_event(li); struct libinput_event_tablet_tool *tev = litest_is_tablet_event(event, type); double pressure = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq_epsilon(pressure, expected_pressure, 0.01); libinput_event_destroy(event); } START_TEST(tablet_pressure_offset_set) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct axis_replacement axes[] = { { ABS_DISTANCE, 70 }, { ABS_PRESSURE, 20 }, { -1, -1 }, }; litest_drain_events(li); if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE)) { /* First two prox ins won't do anything, coming with 10% should give * us ~10% pressure */ for (int i = 0; i < 2; i++) { litest_tablet_proximity_in(dev, 5, 100, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.20); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.20); litest_tablet_proximity_out(dev); litest_drain_events(li); } } /* This activates the pressure offset */ litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); /* Put the pen down, with a pressure high enough to meet the * new offset */ litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 26); /* Tablet motion above threshold should trigger axis + tip down. Use * the litest motion helper here to avoid false positives caused by * BTN_TOUCH */ litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); libinput_event_destroy(event); /* Reduce pressure to just a tick over the offset, otherwise we get * the tip up event again */ litest_axis_set_value(axes, ABS_PRESSURE, 20.1); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); /* we can't actually get a real 0.0 because that would trigger a tip up. but it's close enough to zero. */ assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.01); litest_drain_events(li); litest_axis_set_value(axes, ABS_PRESSURE, 21); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.015); /* Make sure we can reach the upper range too */ litest_axis_set_value(axes, ABS_PRESSURE, 100); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0); /* Tablet motion at offset should trigger tip up. Use * the litest motion helper here to avoid false positives caused by * BTN_TOUCH */ litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 71, 71, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); libinput_event_destroy(event); } END_TEST START_TEST(tablet_pressure_offset_decrease) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 70 }, { ABS_PRESSURE, 20 }, { -1, -1 }, }; /* offset 20 on prox in */ litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); /* offset 15 on prox in - this one is so we trigger on the next prox * in for the no-distance tablets */ litest_axis_set_value(axes, ABS_PRESSURE, 15); litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); /* a reduced pressure value must reduce the offset */ litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); litest_tablet_proximity_in(dev, 5, 100, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.0); litest_drain_events(li); /* trigger the pressure threshold */ litest_axis_set_value(axes, ABS_PRESSURE, 15); litest_tablet_tip_down(dev, 70, 70, axes); litest_dispatch(li); /* offset 10 + lower threshold of ~1% of original range, * value 15 is 5% over original range but with the above taken into * account it's closer to 5% into the remaining effective 89% range */ assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.05); /* a reduced pressure value during motion events must reduce the offset * - here back down to 5%. * FIXME: this causes a tip up event which is a bug but working around * this is more effort than it's worth for what should be quite a niche * case. */ litest_axis_set_value(axes, ABS_PRESSURE, 5); litest_tablet_motion(dev, 75, 75, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.0); litest_drain_events(li); /* back to 10% should now give us 5% pressure because we reduced the * offset */ litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_motion(dev, 75, 75, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.05); litest_drain_events(li); } END_TEST START_TEST(tablet_pressure_offset_increase) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 70 }, { ABS_PRESSURE, 20 }, { -1, -1 }, }; /* offset 20 on first prox in */ litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); /* offset 25 on second prox in - must not change the offset */ litest_axis_set_value(axes, ABS_PRESSURE, 25); litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); /* offset 30 on third prox in - must not change the offset */ litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 31); litest_tablet_tip_down(dev, 70, 70, axes); litest_dispatch(li); litest_drain_events(li); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); /* offset 20 + lower threshold of 1% of original range, * value 30 is 5% over original range but with the above taken into * account it's closer to 12% into the remaining effective 79% range */ assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.12); litest_drain_events(li); litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.0); } END_TEST START_TEST(tablet_pressure_min_max) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 }, }; if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) return LITEST_NOT_APPLICABLE; litest_tablet_proximity_in(dev, 5, 50, axes); litest_drain_events(li); litest_dispatch(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); /* Default pressure threshold is 1% of range */ litest_axis_set_value(axes, ABS_PRESSURE, 1.1); litest_tablet_motion(dev, 5, 50, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.0); /* skip over pressure-based tip down */ litest_axis_set_value(axes, ABS_PRESSURE, 90); litest_tablet_motion(dev, 5, 50, axes); litest_drain_events(li); /* need to fill the motion history */ litest_axis_set_value(axes, ABS_PRESSURE, 100); litest_tablet_motion(dev, 5, 50, axes); litest_tablet_motion(dev, 6, 50, axes); litest_tablet_motion(dev, 7, 50, axes); litest_tablet_motion(dev, 8, 50, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 50, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0); } END_TEST START_TEST(tablet_pressure_range) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 }, }; int pressure; double p; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); for (pressure = 10; pressure <= 100; pressure += 10) { litest_axis_set_value(axes, ABS_PRESSURE, pressure); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_ge(p, 0.0); litest_assert_double_le(p, 1.0); libinput_event_destroy(event); } } END_TEST START_TEST(tablet_pressure_config) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 }, }; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(tev); litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_minimum(tool), 0.0); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_maximum(tool), 1.0); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_default_minimum(tool), 0.0); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_default_maximum(tool), 1.0); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.0), LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.2, 0.5), LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, -0.1, 1.0), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 0.0), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 1.0, 1.0), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 1.1), LIBINPUT_CONFIG_STATUS_INVALID); /* The last successful one */ litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_minimum(tool), 0.2); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_maximum(tool), 0.5); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_default_minimum(tool), 0.0); litest_assert_double_eq(libinput_tablet_tool_config_pressure_range_get_default_maximum(tool), 1.0); libinput_event_destroy(event); } END_TEST START_TEST(tablet_pressure_config_set_minimum) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 }, }; double p, old_pressure; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_gt(p, 0.0); old_pressure = p; litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.4, 1.0), LIBINPUT_CONFIG_STATUS_SUCCESS); libinput_event_destroy(event); /* config doesn't take effect until we're out of prox */ for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq(p, old_pressure); libinput_event_destroy(event); } litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); litest_drain_events(li); /* 10% hw value is below our thresholds, so logical zero */ litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_proximity_in(dev, 70, 70, axes); litest_drain_events(li); for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq(p, 0.00); libinput_event_destroy(event); } /* 50% hw value mapped into a reduced range of 60% from hw range, plus the 1% minimum offset, so our output pressure is actually ~15% */ litest_axis_set_value(axes, ABS_PRESSURE, 50); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_gt(p, 0.15); litest_assert_double_le(p, 0.16); libinput_event_destroy(event); for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_ge(p, 0.15); litest_assert_double_le(p, 0.16); libinput_event_destroy(event); } } END_TEST START_TEST(tablet_pressure_config_set_maximum) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 }, }; double p, old_pressure; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_gt(p, 0.0); old_pressure = p; litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.0, 0.6), LIBINPUT_CONFIG_STATUS_SUCCESS); libinput_event_destroy(event); /* config doesn't take effect until we're out of prox */ for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq(p, old_pressure); libinput_event_destroy(event); } litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_proximity_in(dev, 70, 70, axes); litest_drain_events(li); /* 10% hw value mapped into a reduced range of 60% from hw range, plus the 1% minimum offset so our output pressure is actually ~15% */ for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_ge(p, 0.15); litest_assert_double_le(p, 0.16); litest_assert_double_gt(p, old_pressure); libinput_event_destroy(event); } /* 50% hw value mapped into a reduced range of 60% from hw range, plus the 1% minimum offset, so our output pressure is actually ~83% */ litest_axis_set_value(axes, ABS_PRESSURE, 50); for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_ge(p, 0.82); litest_assert_double_le(p, 0.84); libinput_event_destroy(event); } for (int hwp = 60; hwp < 100; hwp += 10) { litest_axis_set_value(axes, ABS_PRESSURE, hwp); for (int pos = 71; pos < 80; pos++) { litest_tablet_motion(dev, pos, pos, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq(p, 1.0); libinput_event_destroy(event); } } } END_TEST START_TEST(tablet_pressure_config_set_range) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 10 }, { -1, -1 }, }; double p, old_pressure; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tool = libinput_event_tablet_tool_get_tool(tev); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_gt(p, 0.0); old_pressure = p; litest_assert(libinput_tablet_tool_config_pressure_range_is_available(tool)); litest_assert_enum_eq(libinput_tablet_tool_config_pressure_range_set(tool, 0.4, 0.6), LIBINPUT_CONFIG_STATUS_SUCCESS); libinput_event_destroy(event); /* config doesn't take effect until we're out of prox */ for (int i = 71; i < 80; i++) { litest_tablet_motion(dev, i, i, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_eq(p, old_pressure); libinput_event_destroy(event); } litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); litest_drain_events(li); litest_tablet_proximity_in(dev, 70, 70, axes); litest_drain_events(li); for (double pressure = 0.0, i = 71; pressure <= 100; pressure += 5, i += 0.2) { litest_axis_set_value(axes, ABS_PRESSURE, pressure); litest_tablet_motion(dev, i, i, axes); litest_dispatch(li); event = libinput_get_event(li); if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); else tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); p = libinput_event_tablet_tool_get_pressure(tev); if (pressure <= 40) { litest_assert_double_eq(p, 0.0); } else if (pressure >= 60) { litest_assert_double_eq(p, 1.0); } else { litest_assert_double_ge(p, (pressure - 1 - 40)/20.0); litest_assert_double_le(p, (pressure - 40)/20.0); } libinput_event_destroy(event); } } END_TEST static void pressure_threshold_warning(struct libinput *libinput, enum libinput_log_priority priority, const char *format, va_list args) { struct litest_user_data *user_data = libinput_get_user_data(libinput); int *warning_triggered = user_data->private; if (priority == LIBINPUT_LOG_PRIORITY_ERROR && strstr(format, "pressure offset greater")) (*warning_triggered)++; } START_TEST(tablet_pressure_offset_exceed_threshold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 70 }, { ABS_PRESSURE, 60 }, { -1, -1 }, }; int warning_triggered = 0; struct litest_user_data *user_data = libinput_get_user_data(li); /* Tablet without distance: offset takes effect on third prox-in */ if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE)) { for (int i = 0; i < 2; i++) { litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_proximity_out(dev); litest_dispatch(li); } } litest_drain_events(li); user_data->private = &warning_triggered; libinput_log_set_handler(li, pressure_threshold_warning); litest_tablet_proximity_in(dev, 5, 100, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.60); litest_assert_int_eq(warning_triggered, 1); litest_restore_log_handler(li); } END_TEST START_TEST(tablet_pressure_offset_none_for_zero_distance) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, { ABS_PRESSURE, 20 }, { -1, -1 }, }; litest_drain_events(li); /* we're going straight to touch on proximity, make sure we don't * offset the pressure here */ litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 5, 100, axes); litest_tablet_tip_down(dev, 5, 100, axes); litest_pop_event_frame(dev); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.20); } END_TEST START_TEST(tablet_pressure_offset_none_for_small_distance) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { ABS_PRESSURE, 20 }, { -1, -1 }, }; /* stylus too close to the tablet on the proximity in, ignore any * pressure offset */ litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 21); litest_tablet_tip_down(dev, 70, 70, axes); litest_drain_events(li); litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.20); } END_TEST START_TEST(tablet_pressure_across_multiple_tablets) { struct litest_device *cintiq12wx = litest_current_device(); struct libinput *li = cintiq12wx->libinput; struct litest_device *mobilestudio = litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); bool direction = litest_test_param_get_bool(test_env->params, "8k-to-1k"); struct litest_device *first = direction ? mobilestudio : cintiq12wx; struct litest_device *second = direction ? cintiq12wx : mobilestudio; struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { ABS_PRESSURE, 0 }, { -1, -1 }, }; bool have_cintiq12wx = false; bool have_mobilestudio = false; libinput_dispatch(li); while (!have_cintiq12wx || !have_mobilestudio) { litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); struct libinput_event *ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_ADDED); if (libinput_event_get_device(ev) == cintiq12wx->libinput_device) have_cintiq12wx = true; if (libinput_event_get_device(ev) == mobilestudio->libinput_device) have_mobilestudio = true; litest_checkpoint("Have Cintiq 12WX: %s, MobileStudio: %s", yesno(have_cintiq12wx), yesno(have_mobilestudio)); libinput_event_destroy(ev); libinput_dispatch(li); } litest_drain_events(li); /* Proximity in followed by pressure up to 70%, on the first * device, then on the second one. They have different pressure * ranges but we expect the normalized range to be the same * proportionate range */ struct litest_device *dev = first; for (int i = 0; i < 2; i++, dev = second) { litest_checkpoint("Putting pen into proximity on %s", libinput_device_get_name(dev->libinput_device)); litest_tablet_proximity_in(dev, 50, 50, axes); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_motion(dev, 50, 50, axes); litest_dispatch(li); for (size_t pressure = 10; pressure <= 70; pressure += 10) { litest_axis_set_value(axes, ABS_PRESSURE, pressure); litest_tablet_motion(dev, 50, 50, axes); litest_dispatch(li); } litest_tablet_proximity_out(dev); litest_timeout_tablet_proxout(); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); do { struct libinput_event *ev = libinput_get_event(li); struct libinput_event_tablet_tool *tev = litest_is_tablet_event(ev, LIBINPUT_EVENT_TABLET_TOOL_AXIS); double pressure = libinput_event_tablet_tool_get_pressure(tev); /* We start at device range 10% but we always have a small threshold */ litest_assert_double_gt_epsilon(pressure, 0.09, 0); litest_assert_double_le(pressure, 0.7); libinput_event_destroy(ev); } while (libinput_next_event_type(li) == LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); } litest_delete_device(mobilestudio); } END_TEST START_TEST(tablet_pressure_after_unplug) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { ABS_PRESSURE, 0 }, { -1, -1 }, }; litest_drain_events(li); litest_mark_test_start(); /* Unplug 10 times because that's more than however many tablets * we keep track of internally */ for (int iteration = 0; iteration < 10; iteration++) { litest_checkpoint("Putting pen into proximity"); litest_tablet_proximity_in(dev, 50, 50, axes); litest_tablet_motion(dev, 51, 51, axes); litest_dispatch(li); litest_tablet_proximity_out(dev); litest_checkpoint("Unplugging/replugging device"); litest_delete_device(dev); litest_dispatch(li); litest_drain_events(li); dev = litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN); litest_dispatch(li); litest_drain_events(li); } litest_checkpoint("Putting pen into proximity"); litest_tablet_proximity_in(dev, 49, 49, axes); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); for (int i = 1; i < 5; i++) { litest_tablet_motion(dev, 50 + i, 50 + i, axes); litest_dispatch(li); struct libinput_event *event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); } litest_checkpoint("Putting pen tip down"); litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_tablet_tip_down(dev, 50, 50, axes); litest_dispatch(li); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); double old_pressure = 0; for (int i = 1; i < 5; i++) { litest_axis_set_value(axes, ABS_PRESSURE, 10 + i); litest_tablet_motion(dev, 50 + i, 50 + i, axes); litest_dispatch(li); struct libinput_event *event = libinput_get_event(li); struct libinput_event_tablet_tool *tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); double pressure = libinput_event_tablet_tool_get_pressure(tev); litest_assert_double_gt(pressure, old_pressure); libinput_event_destroy(event); } litest_checkpoint("Putting pen tip up"); litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 50, 50, axes); litest_dispatch(li); litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); litest_checkpoint("Putting out of proximity"); litest_tablet_proximity_out(dev); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_delete_device(dev); litest_destroy_context(li); } END_TEST START_TEST(tablet_distance_range) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 20 }, { ABS_PRESSURE, 0 }, { -1, -1 }, }; int distance; double dist; litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); litest_dispatch(li); for (distance = 0; distance <= 100; distance += 10) { litest_axis_set_value(axes, ABS_DISTANCE, distance); litest_tablet_motion(dev, 70, 70, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dist = libinput_event_tablet_tool_get_distance(tev); litest_assert_double_ge(dist, 0.0); litest_assert_double_le(dist, 1.0); libinput_event_destroy(event); } } END_TEST START_TEST(tilt_available) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, { ABS_TILT_Y, 20 }, { -1, -1 } }; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert(libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); } END_TEST START_TEST(tilt_not_available) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, { ABS_TILT_Y, 20 }, { -1, -1 } }; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); litest_assert(!libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); } END_TEST START_TEST(tilt_x) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 10 }, { ABS_TILT_Y, 0 }, { -1, -1 } }; double tx, ty; int tilt; double expected_tx; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); /* 90% of the actual axis but mapped into a [-64, 64] tilt range, so * we expect 51 degrees ± rounding errors */ tx = libinput_event_tablet_tool_get_tilt_x(tev); litest_assert_double_le(tx, -50); litest_assert_double_ge(tx, -52); ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_ge(ty, -65); litest_assert_double_lt(ty, -63); libinput_event_destroy(event); expected_tx = -64.0; litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 1); for (tilt = 0; tilt <= 100; tilt += 5) { litest_axis_set_value(axes, ABS_TILT_X, tilt); /* work around smoothing */ litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 10, 11, axes); litest_tablet_motion(dev, 10, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 10, 11, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); tx = libinput_event_tablet_tool_get_tilt_x(tev); litest_assert_double_ge(tx, expected_tx - 2); litest_assert_double_le(tx, expected_tx + 2); ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_ge(ty, -65); litest_assert_double_lt(ty, -63); libinput_event_destroy(event); expected_tx = tx + 6.04; } /* the last event must reach the max */ litest_assert_double_ge(tx, 63.0); litest_assert_double_le(tx, 64.0); } END_TEST START_TEST(tilt_y) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 10 }, { -1, -1 } }; double tx, ty; int tilt; double expected_ty; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); /* 90% of the actual axis but mapped into a [-64, 64] tilt range, so * we expect 50 degrees ± rounding errors */ ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_le(ty, -50); litest_assert_double_ge(ty, -52); tx = libinput_event_tablet_tool_get_tilt_x(tev); litest_assert_double_ge(tx, -65); litest_assert_double_lt(tx, -63); libinput_event_destroy(event); expected_ty = -64; litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 1); for (tilt = 0; tilt <= 100; tilt += 5) { litest_axis_set_value(axes, ABS_TILT_Y, tilt); /* work around smoothing */ litest_tablet_motion(dev, 10, 11, axes); litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 10, 11, axes); litest_drain_events(li); litest_tablet_motion(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_ge(ty, expected_ty - 2); litest_assert_double_le(ty, expected_ty + 2); tx = libinput_event_tablet_tool_get_tilt_x(tev); litest_assert_double_ge(tx, -65); litest_assert_double_lt(tx, -63); libinput_event_destroy(event); expected_ty = ty + 6; } /* the last event must reach the max */ litest_assert_double_ge(ty, 63.0); litest_assert_double_le(tx, 64.0); } END_TEST START_TEST(tilt_fixed_points) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; /* On devices with a range of [-N, M], make sure we calculate the hw zero position * as zero and that the respective min/max resolve to our (hardcoded) min/max degree * values */ const struct input_absinfo *abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X); if (abs->minimum >= 0) return LITEST_NOT_APPLICABLE; /* If the tablet reports physical resolutions we don't need to test them */ if (abs->resolution != 0) return LITEST_NOT_APPLICABLE; /* see tablet_fix_tilt() */ bool is_adjusted = (int)absinfo_range(abs) % 2 == 0; int axis_value; double expected; int testcase = litest_test_param_get_i32(test_env->params, "tilt"); switch (testcase) { case TILT_MINIMUM: axis_value = abs->minimum; expected = -64.0; break; case TILT_CENTER: axis_value = 0; expected = 0.0; break; case TILT_MAXIMUM: axis_value = abs->maximum; expected = 64.0; break; default: litest_abort_msg("Invalid tilt testcase '%d'", testcase); } litest_drain_events(li); litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_event(dev, EV_ABS, ABS_TILT_X, axis_value); litest_event(dev, EV_ABS, ABS_TILT_Y, axis_value); litest_pop_event_frame(dev); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); double tx = libinput_event_tablet_tool_get_tilt_x(tev); double ty = libinput_event_tablet_tool_get_tilt_y(tev); litest_assert_double_eq(tx, expected); if (is_adjusted) { litest_assert_double_ge(ty, expected - 1); litest_assert_double_lt(ty, expected); } else { litest_assert_double_eq(ty, expected); } libinput_event_destroy(event); } END_TEST START_TEST(relative_no_profile) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_accel_profile profile; enum libinput_config_status status; uint32_t profiles; litest_assert(libinput_device_config_accel_is_available(device)); profile = libinput_device_config_accel_get_default_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); profiles = libinput_device_config_accel_get_profiles(device); litest_assert_enum_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, 0); litest_assert_enum_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, 0); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); status = libinput_device_config_accel_set_profile(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); profile = libinput_device_config_accel_get_profile(device); litest_assert_enum_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); } END_TEST START_TEST(relative_no_delta_prox_in) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double dx, dy; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); } END_TEST START_TEST(relative_delta) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double dx, dy; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); /* flush the motion history */ for (int i = 0; i < 5; i ++) litest_tablet_motion(dev, 10 + i, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 20, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx > 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); /* flush the motion history */ for (int i = 0; i < 5; i ++) litest_tablet_motion(dev, 20 - i, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx < 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); /* flush the motion history */ for (int i = 0; i < 5; i ++) litest_tablet_motion(dev, 5, 10 + i, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 20, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy > 0.0); libinput_event_destroy(event); /* flush the motion history */ for (int i = 0; i < 5; i ++) litest_tablet_motion(dev, 5, 20 - i, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy < 0.0); libinput_event_destroy(event); } END_TEST START_TEST(relative_no_delta_on_tip) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double dx, dy; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 20, 10, axes); litest_drain_events(li); /* tip down */ litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_tip_down(dev, 30, 20, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert(libinput_event_tablet_tool_x_has_changed(tev)); litest_assert(libinput_event_tablet_tool_y_has_changed(tev)); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); /* normal motion */ litest_tablet_motion(dev, 40, 30, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx > 0.0); litest_assert(dy > 0.0); libinput_event_destroy(event); /* tip up */ litest_axis_set_value(axes, ABS_DISTANCE, 10); litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_tablet_tip_up(dev, 50, 40, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert(libinput_event_tablet_tool_x_has_changed(tev)); litest_assert(libinput_event_tablet_tool_y_has_changed(tev)); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); } END_TEST START_TEST(relative_calibration) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double dx, dy; float calibration[] = { -1, 0, 1, 0, -1, 1 }; enum libinput_config_status status; if (!libinput_device_config_calibration_has_matrix(dev->libinput_device)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_calibration_set_matrix( dev->libinput_device, calibration); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 20, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx < 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); /* work around axis smoothing */ litest_tablet_motion(dev, 19, 10, axes); litest_tablet_motion(dev, 18, 10, axes); litest_tablet_motion(dev, 17, 10, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 10, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx > 0.0); litest_assert(dy == 0.0); libinput_event_destroy(event); /* work around axis smoothing */ litest_tablet_motion(dev, 5, 11, axes); litest_tablet_motion(dev, 5, 12, axes); litest_tablet_motion(dev, 5, 13, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 20, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy < 0.0); libinput_event_destroy(event); /* work around axis smoothing */ litest_tablet_motion(dev, 5, 19, axes); litest_tablet_motion(dev, 5, 18, axes); litest_tablet_motion(dev, 5, 17, axes); litest_drain_events(li); litest_tablet_motion(dev, 5, 5, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); dx = libinput_event_tablet_tool_get_dx(tev); dy = libinput_event_tablet_tool_get_dy(tev); litest_assert(dx == 0.0); litest_assert(dy > 0.0); libinput_event_destroy(event); } END_TEST static enum litest_device_type paired_device(struct litest_device *dev) { switch(dev->which) { case LITEST_WACOM_INTUOS5_PEN: return LITEST_WACOM_INTUOS5_FINGER; case LITEST_WACOM_INTUOS5_FINGER: return LITEST_WACOM_INTUOS5_PEN; case LITEST_WACOM_CINTIQ_13HDT_PEN: return LITEST_WACOM_CINTIQ_13HDT_FINGER; case LITEST_WACOM_CINTIQ_13HDT_FINGER: return LITEST_WACOM_CINTIQ_13HDT_PEN; default: return LITEST_NO_DEVICE; } } static void assert_touch_is_arbitrated(struct litest_device *dev, struct litest_device *finger) { struct libinput *li = dev->libinput; bool is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); struct axis_replacement axes[] = { { ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 20, 40, axes); litest_drain_events(li); double tx = 20; double ty = 40; double x = 21; double y = 41; litest_touch_down(finger, 0, x, y); /* We need to intersperce the touch events with tablets so we don't trigger the tablet proximity timeout. */ for (int i = 0; i < 60; i += 5) { litest_touch_move(finger, 0, x + i, y + i); litest_tablet_motion(dev, tx + 0.1 * i, ty + 0.1 * i, axes); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_tablet_proximity_out(dev); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_timeout_touch_arbitration(); litest_dispatch(li); /* finger still down */ litest_touch_move_to(finger, 0, 80, 80, 30, 30, 10); litest_touch_up(finger, 0); litest_assert_empty_queue(li); litest_timeout_touch_arbitration(); litest_dispatch(li); /* lift finger, expect expect events */ litest_touch_down(finger, 0, 30, 30); litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); litest_touch_up(finger, 0); litest_dispatch(li); if (is_touchpad) litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); else litest_assert_touch_sequence(li); } START_TEST(touch_arbitration) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct libinput *li = dev->libinput; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; struct litest_device *finger = litest_add_device(li, other); litest_drain_events(li); bool is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); if (is_touchpad) litest_disable_hold_gestures(finger->libinput_device); assert_touch_is_arbitrated(dev, finger); litest_delete_device(finger); } END_TEST START_TEST(touch_arbitration_outside_rect) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y; bool is_touchpad; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); if (is_touchpad) return LITEST_NOT_APPLICABLE; x = 20; y = 70; /* disable prox-out timer quirk */ litest_tablet_proximity_in(dev, x, y - 1, axes); litest_tablet_proximity_out(dev); litest_tablet_proximity_in(dev, x, y - 1, axes); litest_drain_events(li); /* these are in percent, but the pen/finger have different * resolution and the rect works in mm, so the numbers below are * hand-picked for the test device */ litest_tablet_motion(dev, x, y, axes); litest_drain_events(li); /* left of rect */ litest_touch_sequence(finger, 0, x - 10, y + 2, x - 10, y + 20, 3); litest_dispatch(li); litest_assert_touch_sequence(li); /* above rect */ litest_touch_sequence(finger, 0, x + 2, y - 65, x + 20, y - 40, 3); litest_dispatch(li); litest_assert_touch_sequence(li); /* right of rect */ litest_touch_sequence(finger, 0, x + 80, y + 2, x + 20, y + 10, 3); litest_dispatch(li); litest_assert_touch_sequence(li); #if 0 /* This *should* work but the Cintiq test devices is <200mm high, so we can't test for anything below the tip */ x = 20; y = 10; litest_tablet_proximity_out(dev); litest_tablet_motion(dev, x, y, axes); litest_tablet_proximity_in(dev, x, y - 1, axes); litest_drain_events(li); /* below rect */ litest_touch_sequence(finger, 0, x + 2, y + 80, x + 20, y + 20, 30); litest_dispatch(li); litest_assert_touch_sequence(li); #endif litest_delete_device(finger); } END_TEST START_TEST(touch_arbitration_remove_after) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_TILT_X, 80 }, { ABS_TILT_Y, 80 }, { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool is_touchpad; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); if (is_touchpad) return LITEST_NOT_APPLICABLE; litest_tablet_proximity_in(dev, 50, 50, axes); litest_drain_events(li); litest_touch_down(finger, 0, 70, 70); litest_drain_events(li); litest_tablet_proximity_out(dev); litest_dispatch(li); /* Delete the device immediately after the tablet goes out of prox. * This merely tests that the arbitration timer gets cleaned up */ litest_delete_device(finger); } END_TEST START_TEST(touch_arbitration_stop_touch) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool is_touchpad; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); if (is_touchpad) litest_disable_hold_gestures(finger->libinput_device); /* disable prox-out timer quirk */ litest_tablet_proximity_in(dev, 30, 30, axes); litest_tablet_proximity_out(dev); litest_drain_events(li); litest_touch_down(finger, 0, 30, 30); litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 20, 40, axes); litest_drain_events(li); litest_touch_move_to(finger, 0, 80, 80, 30, 30, 10); litest_assert_empty_queue(li); /* tablet event so we don't time out for proximity */ litest_tablet_motion(dev, 30, 40, axes); litest_drain_events(li); /* start another finger to make sure that one doesn't send events either */ litest_touch_down(finger, 1, 30, 30); litest_touch_move_to(finger, 1, 30, 30, 80, 80, 3); litest_assert_empty_queue(li); litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 20, 40, axes); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_tablet_proximity_out(dev); litest_drain_events(li); litest_timeout_tablet_proxout(); litest_drain_events(li); /* Finger needs to be lifted for events to happen*/ litest_touch_move_to(finger, 0, 30, 30, 80, 80, 3); litest_assert_empty_queue(li); litest_touch_move_to(finger, 1, 80, 80, 30, 30, 3); litest_assert_empty_queue(li); litest_touch_up(finger, 0); litest_touch_move_to(finger, 1, 30, 30, 80, 80, 3); litest_assert_empty_queue(li); litest_touch_up(finger, 1); litest_dispatch(li); litest_touch_down(finger, 0, 30, 30); litest_touch_move_to(finger, 0, 30, 30, 80, 80, 3); litest_touch_up(finger, 0); litest_dispatch(li); if (is_touchpad) litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); else litest_assert_touch_sequence(li); litest_delete_device(finger); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); } END_TEST START_TEST(touch_arbitration_suspend_touch_device) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *tablet; struct libinput *li = dev->libinput; enum libinput_config_status status; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool is_touchpad; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; tablet = litest_add_device(li, other); is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); if (is_touchpad) litest_disable_hold_gestures(dev->libinput_device); /* we can't force a device suspend, but we can at least make sure the device doesn't send events */ status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_tablet_proximity_in(tablet, 10, 10, axes); litest_tablet_motion(tablet, 10, 10, axes); litest_tablet_motion(tablet, 20, 40, axes); litest_drain_events(li); litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* Remove tablet device to unpair, still disabled though */ litest_delete_device(tablet); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_timeout_touch_arbitration(); litest_dispatch(li); litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* Touch device is still disabled */ litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_touch_up(dev, 0); litest_dispatch(li); if (is_touchpad) litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); else litest_assert_touch_sequence(li); } END_TEST START_TEST(touch_arbitration_remove_touch) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_touch_down(finger, 0, 30, 30); litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); litest_delete_device(finger); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_assert_empty_queue(li); litest_tablet_motion(dev, 10, 10, axes); litest_tablet_motion(dev, 20, 40, axes); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); } END_TEST START_TEST(touch_arbitration_remove_tablet) { struct litest_device *dev = litest_current_device(); enum litest_device_type other; struct litest_device *tablet; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool is_touchpad; other = paired_device(dev); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; tablet = litest_add_device(li, other); is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); if (is_touchpad) litest_disable_hold_gestures(dev->libinput_device); litest_dispatch(li); litest_tablet_proximity_in(tablet, 10, 10, axes); litest_tablet_motion(tablet, 10, 10, axes); litest_tablet_motion(tablet, 20, 40, axes); litest_drain_events(li); litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_assert_empty_queue(li); litest_delete_device(tablet); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_timeout_touch_arbitration(); litest_dispatch(li); /* Touch is still down, don't enable */ litest_touch_move_to(dev, 0, 80, 80, 30, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 30, 30); litest_touch_move_to(dev, 0, 30, 30, 80, 80, 10); litest_touch_up(dev, 0); litest_dispatch(li); if (is_touchpad) litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); else litest_assert_touch_sequence(li); } END_TEST START_TEST(touch_arbitration_keep_ignoring) { struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_tablet_proximity_in(tablet, 10, 10, axes); litest_tablet_motion(tablet, 10, 10, axes); litest_tablet_motion(tablet, 20, 40, axes); litest_touch_down(finger, 0, 30, 30); litest_drain_events(li); litest_tablet_proximity_out(tablet); litest_drain_events(li); /* a touch during pen interaction stays a palm after the pen lifts. */ litest_touch_move_to(finger, 0, 30, 30, 80, 80, 10); litest_touch_up(finger, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(finger); } END_TEST START_TEST(touch_arbitration_late_touch_lift) { struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; bool is_touchpad; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); if (is_touchpad) { litest_enable_tap(finger->libinput_device); litest_disable_hold_gestures(finger->libinput_device); } litest_tablet_proximity_in(tablet, 10, 10, axes); litest_tablet_motion(tablet, 10, 10, axes); litest_tablet_motion(tablet, 20, 40, axes); litest_drain_events(li); litest_tablet_proximity_out(tablet); litest_drain_events(li); /* with kernel arbitration, a finger + stylus in prox only generates * stylus events. When a user lifts the hand with the stylus, the * stylus usually goes out of prox while the hand is still touching * the surface. This causes a touch down event now that the stylus * is out of proximity. A few ms later, the hand really lifts off * the surface, causing a touch down and thus a fake tap event. */ litest_touch_down(finger, 0, 30, 30); litest_touch_up(finger, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(finger); } END_TEST START_TEST(touch_arbitration_swap_device) { struct litest_device *tablet = litest_current_device(); struct libinput *li = tablet->libinput; enum litest_device_type paired = paired_device(tablet); if (paired == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; /* First, add a normal touchscreen */ struct litest_device *touchscreen = litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN); libinput_device_config_gesture_set_hold_enabled(touchscreen->libinput_device, LIBINPUT_CONFIG_HOLD_DISABLED); litest_drain_events(li); assert_touch_is_arbitrated(tablet, touchscreen); /* Now add a better device to override the pairing */ struct litest_device *finger = litest_add_device(li, paired); libinput_device_config_gesture_set_hold_enabled(finger->libinput_device, LIBINPUT_CONFIG_HOLD_DISABLED); litest_drain_events(li); assert_touch_is_arbitrated(tablet, finger); litest_delete_device(touchscreen); litest_delete_device(finger); } END_TEST #if HAVE_LIBWACOM static void verify_left_handed_tablet_motion(struct litest_device *tablet, struct libinput *li, double x, double y, bool left_handed) { struct libinput_event *event; struct libinput_event_tablet_tool *t; /* proximity in/out must be handled by caller */ for (int i = 5; i < 25; i += 5) { litest_tablet_motion(tablet, x + i, y - i, NULL); litest_dispatch(li); } event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_ptr_notnull(event); while (event) { double last_x = x, last_y = y; t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); if (left_handed) { litest_assert_double_lt(x, last_x); litest_assert_double_gt(y, last_y); } else { litest_assert_double_gt(x, last_x); litest_assert_double_lt(y, last_y); } libinput_event_destroy(event); event = libinput_get_event(li); } } static void verify_left_handed_tablet_sequence(struct litest_device *tablet, struct libinput *li, bool left_handed) { double x, y; /* verifies a whole sequence, including prox in/out and timeouts */ x = 60; y = 60; litest_tablet_proximity_in(tablet, x, y, NULL); litest_dispatch(li); litest_drain_events(li); verify_left_handed_tablet_motion(tablet, li, x, y, left_handed); litest_tablet_proximity_out(tablet); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_drain_events(li); } static void verify_left_handed_touch_motion(struct litest_device *finger, struct libinput *li, double x, double y, bool left_handed) { struct libinput_event *event; struct libinput_event_pointer *p; /* touch down/up must be handled by caller */ litest_touch_move_to(finger, 0, x + 1, y - 1, x + 20, y - 20, 10); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { p = litest_is_motion_event(event); x = libinput_event_pointer_get_dx(p); y = libinput_event_pointer_get_dy(p); if (left_handed) { litest_assert_double_lt(x, 0); litest_assert_double_gt(y, 0); } else { litest_assert_double_gt(x, 0); litest_assert_double_lt(y, 0); } libinput_event_destroy(event); event = libinput_get_event(li); } } static void verify_left_handed_touch_sequence(struct litest_device *finger, struct libinput *li, bool left_handed) { double x, y; /* verifies a whole sequence, including prox in/out and timeouts */ x = 10; y = 30; litest_touch_down(finger, 0, x, y); litest_drain_events(li); verify_left_handed_touch_motion(finger, li, x, y, left_handed); litest_touch_up(finger, 0); litest_dispatch(li); } #endif START_TEST(tablet_rotation_left_handed) { #if HAVE_LIBWACOM struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; bool tablet_from, touch_from, tablet_to, touch_to; bool enabled_from, enabled_to; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) goto out; litest_test_param_fetch(test_env->params, "tablet_from", 'b', &tablet_from, "touch_from", 'b', &touch_from, "tablet_to", 'b', &tablet_to, "touch_to", 'b', &touch_to); enabled_from = tablet_from || touch_from; enabled_to = tablet_to || touch_to; litest_disable_hold_gestures(finger->libinput_device); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); libinput_device_config_left_handed_set(finger->libinput_device, touch_from); verify_left_handed_tablet_sequence(tablet, li, enabled_from); verify_left_handed_touch_sequence(finger, li, enabled_from); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); libinput_device_config_left_handed_set(finger->libinput_device, touch_to); verify_left_handed_tablet_sequence(tablet, li, enabled_to); verify_left_handed_touch_sequence(finger, li, enabled_to); out: litest_delete_device(finger); #endif } END_TEST START_TEST(tablet_rotation_left_handed_configuration) { #if HAVE_LIBWACOM struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; bool tablet_from, touch_from, tablet_to, touch_to; bool tablet_enabled, touch_enabled; struct libinput_device *tablet_dev, *touch_dev; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) goto out; litest_test_param_fetch(test_env->params, "tablet_from", 'b', &tablet_from, "touch_from", 'b', &touch_from, "tablet_to", 'b', &tablet_to, "touch_to", 'b', &touch_to); tablet_dev = tablet->libinput_device; touch_dev = finger->libinput_device; /* Make sure that toggling one device doesn't toggle the other one */ libinput_device_config_left_handed_set(tablet_dev, tablet_from); libinput_device_config_left_handed_set(touch_dev, touch_from); litest_dispatch(li); tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); touch_enabled = libinput_device_config_left_handed_get(touch_dev); litest_assert_int_eq(tablet_enabled, tablet_from); litest_assert_int_eq(touch_enabled, touch_from); libinput_device_config_left_handed_set(tablet_dev, tablet_to); libinput_device_config_left_handed_set(touch_dev, touch_to); litest_dispatch(li); tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); touch_enabled = libinput_device_config_left_handed_get(touch_dev); litest_assert_int_eq(tablet_enabled, tablet_to); litest_assert_int_eq(touch_enabled, touch_to); out: litest_delete_device(finger); #endif } END_TEST START_TEST(tablet_rotation_left_handed_while_in_prox) { #if HAVE_LIBWACOM struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; bool tablet_from, touch_from, tablet_to, touch_to; bool enabled_from, enabled_to; double x, y; double tx, ty; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) goto out; litest_test_param_fetch(test_env->params, "tablet_from", 'b', &tablet_from, "touch_from", 'b', &touch_from, "tablet_to", 'b', &tablet_to, "touch_to", 'b', &touch_to); enabled_from = tablet_from || touch_from; enabled_to = tablet_to || touch_to; litest_disable_hold_gestures(finger->libinput_device); libinput_device_config_left_handed_set(finger->libinput_device, touch_from); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); litest_checkpoint("Moving into proximity"); tx = 60; ty = 60; litest_tablet_proximity_in(tablet, tx, ty, NULL); litest_dispatch(li); litest_drain_events(li); litest_checkpoint("Changing tablet to left-handed: %s", truefalse(tablet_to)); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); litest_checkpoint("Changing touch to left-handed: %s", truefalse(touch_to)); libinput_device_config_left_handed_set(finger->libinput_device, touch_to); /* not yet neutral, so still whatever the original was */ litest_checkpoint("Expecting tablet motion with left-handed: %s", truefalse(enabled_from)); verify_left_handed_tablet_motion(tablet, li, tx, ty, enabled_from); litest_drain_events(li); /* test pointer, should be left-handed already */ #if 0 /* Touch arbitration discards events, so we can't check for the right behaviour here. */ verify_left_handed_touch_sequence(finger, li, enabled_to); #else x = 10; y = 30; litest_touch_down(finger, 0, x, y); /* We need to intersperse the touch events with tablets so we don't trigger the tablet proximity timeout. */ for (int i = 0; i < 10; i++) { litest_touch_move(finger, 0, x + i, y - i); litest_tablet_motion(tablet, tx + 0.1 * i, ty + 0.1 * i, NULL); } litest_touch_up(finger, 0); litest_dispatch(li); /* this will fail once we have location-based touch arbitration on * touchpads */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); #endif litest_checkpoint("Moving out of proximity"); litest_tablet_proximity_out(tablet); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_drain_events(li); litest_assert_empty_queue(li); /* now both should've switched */ litest_checkpoint("Expecting tablet motion with left-handed: %s", truefalse(enabled_to)); verify_left_handed_tablet_sequence(tablet, li, enabled_to); litest_checkpoint("Expecting touch motion with left-handed: %s", truefalse(enabled_to)); verify_left_handed_touch_sequence(finger, li, enabled_to); out: litest_delete_device(finger); #endif } END_TEST START_TEST(tablet_rotation_left_handed_while_touch_down) { #if HAVE_LIBWACOM struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; bool tablet_from, touch_from, tablet_to, touch_to; bool enabled_from, enabled_to; double x, y; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; finger = litest_add_device(li, other); litest_drain_events(li); if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) goto out; litest_test_param_fetch(test_env->params, "tablet_from", 'b', &tablet_from, "touch_from", 'b', &touch_from, "tablet_to", 'b', &tablet_to, "touch_to", 'b', &touch_to); enabled_from = tablet_from || touch_from; enabled_to = tablet_to || touch_to; litest_disable_hold_gestures(finger->libinput_device); libinput_device_config_left_handed_set(finger->libinput_device, touch_from); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); /* Touch down when setting to left-handed */ x = 10; y = 30; litest_touch_down(finger, 0, x, y); litest_dispatch(li); litest_drain_events(li); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); libinput_device_config_left_handed_set(finger->libinput_device, touch_to); /* not yet neutral, so still whatever the original was */ verify_left_handed_touch_motion(finger, li, x, y, enabled_from); litest_assert_empty_queue(li); /* test tablet, should be left-handed already */ verify_left_handed_tablet_sequence(tablet, li, enabled_to); litest_touch_up(finger, 0); litest_drain_events(li); /* now both should've switched */ verify_left_handed_tablet_sequence(tablet, li, enabled_to); verify_left_handed_touch_sequence(finger, li, enabled_to); out: litest_delete_device(finger); #endif } END_TEST START_TEST(tablet_rotation_left_handed_add_touchpad) { #if HAVE_LIBWACOM struct litest_device *tablet = litest_current_device(); enum litest_device_type other; struct litest_device *finger; struct libinput *li = tablet->libinput; bool tablet_from, touch_from, tablet_to, touch_to; bool enabled_from, enabled_to; other = paired_device(tablet); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; litest_test_param_fetch(test_env->params, "tablet_from", 'b', &tablet_from, "touch_from", 'b', &touch_from, "tablet_to", 'b', &tablet_to, "touch_to", 'b', &touch_to); enabled_from = tablet_from || touch_from; enabled_to = tablet_to || touch_to; /* change left-handed before touchpad appears */ libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); finger = litest_add_device(li, other); litest_drain_events(li); if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) goto out; libinput_device_config_left_handed_set(finger->libinput_device, touch_from); litest_disable_hold_gestures(finger->libinput_device); verify_left_handed_touch_sequence(finger, li, enabled_from); verify_left_handed_tablet_sequence(tablet, li, enabled_from); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); libinput_device_config_left_handed_set(finger->libinput_device, touch_to); verify_left_handed_touch_sequence(finger, li, enabled_to); verify_left_handed_tablet_sequence(tablet, li, enabled_to); out: litest_delete_device(finger); #endif } END_TEST START_TEST(tablet_rotation_left_handed_add_tablet) { #if HAVE_LIBWACOM struct litest_device *finger = litest_current_device(); enum litest_device_type other; struct litest_device *tablet; struct libinput *li = finger->libinput; unsigned int transition = _i; /* ranged test */ bool tablet_from, touch_from, tablet_to, touch_to; bool enabled_from, enabled_to; if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) return LITEST_NOT_APPLICABLE; other = paired_device(finger); if (other == LITEST_NO_DEVICE) return LITEST_NOT_APPLICABLE; tablet_from = !!(transition & bit(0)); touch_from = !!(transition & bit(1)); tablet_to = !!(transition & bit(2)); touch_to = !!(transition & bit(3)); enabled_from = tablet_from || touch_from; enabled_to = tablet_to || touch_to; /* change left-handed before tablet appears */ libinput_device_config_left_handed_set(finger->libinput_device, touch_from); litest_disable_hold_gestures(finger->libinput_device); tablet = litest_add_device(li, other); litest_drain_events(li); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_from); verify_left_handed_touch_sequence(finger, li, enabled_from); verify_left_handed_tablet_sequence(tablet, li, enabled_from); libinput_device_config_left_handed_set(tablet->libinput_device, tablet_to); libinput_device_config_left_handed_set(finger->libinput_device, touch_to); verify_left_handed_touch_sequence(finger, li, enabled_to); verify_left_handed_tablet_sequence(tablet, li, enabled_to); litest_delete_device(tablet); #endif } END_TEST START_TEST(huion_static_btn_tool_pen) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; bool send_btn_tool = litest_test_param_get_bool(test_env->params, "send-btn-tool"); litest_drain_events(li); litest_event(dev, EV_ABS, ABS_X, 20000); litest_event(dev, EV_ABS, ABS_Y, 20000); litest_event(dev, EV_ABS, ABS_PRESSURE, 100); if (send_btn_tool) litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); /* Wait past the timeout to expect a proximity out */ litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_dispatch(li); /* New events should fake a proximity in again */ litest_event(dev, EV_ABS, ABS_X, 20000); litest_event(dev, EV_ABS, ABS_Y, 20000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_dispatch(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_dispatch(li); /* New events, just to ensure cleanup paths are correct */ litest_event(dev, EV_ABS, ABS_X, 20000); litest_event(dev, EV_ABS, ABS_Y, 20000); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } END_TEST START_TEST(huion_static_btn_tool_pen_no_timeout_during_usage) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; bool send_btn_tool = litest_test_param_get_bool(test_env->params, "send-btn-tool"); litest_drain_events(li); litest_event(dev, EV_ABS, ABS_X, 20000); litest_event(dev, EV_ABS, ABS_Y, 20000); litest_event(dev, EV_ABS, ABS_PRESSURE, 100); if (send_btn_tool) litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); /* take longer than the no-activity timeout */ for (i = 0; i < 50; i++) { litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(5); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_dispatch(li); } END_TEST START_TEST(huion_static_btn_tool_pen_disable_quirk_on_prox_out) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; /* test is run twice, once where the real BTN_TOOL_PEN is triggered * during proximity out, one where the real BTN_TOOL_PEN is * triggered after we already triggered the quirk timeout */ bool with_timeout = litest_test_param_get_bool(test_env->params, "btn_tool_pen_timeout"); litest_drain_events(li); litest_event(dev, EV_ABS, ABS_X, 20000); litest_event(dev, EV_ABS, ABS_Y, 20000); litest_event(dev, EV_ABS, ABS_PRESSURE, 100); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(dev, EV_ABS, ABS_X, 20000 + 10 * i); litest_event(dev, EV_ABS, ABS_Y, 20000 - 10 * i); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); /* Wait past the timeout to expect a proximity out */ if (with_timeout) { litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); } /* Send a real prox out, expect quirk to be disabled */ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); if (with_timeout) { /* we got the proximity event above already */ litest_assert_empty_queue(li); } else { litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); } litest_tablet_proximity_in(dev, 50, 50, NULL); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); for (i = 0; i < 10; i++) { litest_tablet_motion(dev, 50 + i, 50 + i, NULL); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_dispatch(li); litest_timeout_tablet_proxout(); litest_dispatch(li); litest_assert_empty_queue(li); litest_push_event_frame(dev); litest_tablet_proximity_out(dev); litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); } END_TEST START_TEST(tablet_smoothing) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; double x, y; struct point { double x, y; } coordinates[100] = {0}; size_t npoints = 0; size_t idx = 0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); litest_drain_events(li); /* Move in a straight line, collect the resulting points */ for (x = 11, y = 11; x < 50; x++, y++) { struct libinput_event *event; struct libinput_event_tablet_tool *tev; struct point *p = &coordinates[npoints++]; litest_assert(npoints <= ARRAY_LENGTH(coordinates)); litest_tablet_motion(dev, x, y, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); p->x = libinput_event_tablet_tool_get_x(tev); p->y = libinput_event_tablet_tool_get_y(tev); libinput_event_destroy(event); } litest_tablet_proximity_out(dev); litest_tablet_proximity_in(dev, 10, 10, axes); litest_dispatch(li); litest_drain_events(li); /* Move in a wobbly line, collect every second point */ for (x = 11, y = 11; x < 50; x++, y++) { struct libinput_event *event; struct libinput_event_tablet_tool *tev; double ex, ey; struct point *p = &coordinates[idx++]; litest_assert(idx <= npoints); /* point off position */ litest_tablet_motion(dev, x - 2, y + 1, axes); litest_dispatch(li); event = libinput_get_event(li); litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); /* same position as before */ litest_tablet_motion(dev, x, y, axes); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); ex = libinput_event_tablet_tool_get_x(tev); ey = libinput_event_tablet_tool_get_y(tev); litest_assert_double_eq(ex, p->x); litest_assert_double_eq(ey, p->y); libinput_event_destroy(event); } #endif } END_TEST TEST_COLLECTION(tablet) { litest_add(tool_ref, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(tool_user_data, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(tool_capability, LITEST_TABLET, LITEST_ANY); litest_add_no_device(tool_capabilities); litest_add(tool_type, LITEST_TABLET, LITEST_FORCED_PROXOUT); litest_add(tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); litest_add(tool_direct_switch_skip_tool_update, LITEST_TABLET, LITEST_ANY); litest_add(tool_direct_switch_with_forced_proxout, LITEST_TABLET, LITEST_ANY); /* Tablets hold back the proximity until the first event from the * kernel, the totem sends it immediately */ litest_add(tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); litest_add(tool_unique, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(tool_serial, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(tool_id, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(serial_changes_tool, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add(invalid_serials, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); litest_add_no_device(tools_with_serials); litest_add_no_device(tools_without_serials); litest_add_for_device(tool_delayed_serial, LITEST_WACOM_HID4800_PEN); litest_add(proximity_out_clear_buttons, LITEST_TABLET, LITEST_FORCED_PROXOUT); litest_add(proximity_in_out, LITEST_TABLET, LITEST_ANY); litest_add(proximity_in_button_down, LITEST_TABLET, LITEST_ANY); litest_add(proximity_out_button_up, LITEST_TABLET, LITEST_ANY); litest_add(proximity_has_axes, LITEST_TABLET, LITEST_ANY); litest_add(bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add(proximity_range_enter, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(proximity_range_in_out, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(proximity_range_button_click, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(proximity_range_button_press, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(proximity_range_button_release, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(proximity_out_slow_event, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add(proximity_out_not_during_contact, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add(proximity_out_not_during_buttonpress, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add(proximity_out_disables_forced, LITEST_TABLET, LITEST_FORCED_PROXOUT|LITEST_TOTEM); litest_add(proximity_out_disables_forced_after_forced, LITEST_TABLET, LITEST_FORCED_PROXOUT|LITEST_TOTEM); litest_add_no_device(proximity_out_on_delete); litest_add(button_down_up, LITEST_TABLET, LITEST_ANY); litest_add(button_seat_count, LITEST_TABLET, LITEST_ANY); litest_add_no_device(button_up_on_delete); litest_add(tip_down_up, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_down_prox_in, LITEST_TABLET, LITEST_ANY); litest_add(tip_up_prox_out, LITEST_TABLET, LITEST_ANY); litest_add(tip_down_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_up_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_down_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_up_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_down_up_eraser, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { litest_add_parametrized(tip_up_motion_one_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY, params); } litest_add(tip_state_proximity, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_state_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(tip_state_button, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add_no_device(tip_up_on_delete); litest_add(motion, LITEST_TABLET, LITEST_ANY); litest_add(motion_event_state, LITEST_TABLET, LITEST_ANY); litest_add_for_device(motion_outside_bounds, LITEST_WACOM_CINTIQ_24HD_PEN); litest_add(tilt_available, LITEST_TABLET|LITEST_TILT, LITEST_ANY); litest_add(tilt_not_available, LITEST_TABLET, LITEST_TILT); litest_add(tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY); litest_add(tilt_y, LITEST_TABLET|LITEST_TILT, LITEST_ANY); litest_with_parameters(params, "tilt", 'I', 3, litest_named_i32(TILT_MINIMUM, "minimum"), litest_named_i32(TILT_CENTER, "center"), litest_named_i32(TILT_MAXIMUM, "maximum")) { litest_add_parametrized(tilt_fixed_points, LITEST_TABLET|LITEST_TILT, LITEST_ANY, params); } litest_add(pad_buttons_ignored, LITEST_TABLET, LITEST_TOTEM); litest_add_for_device(stylus_buttons, LITEST_WACOM_CINTIQ_PRO16_PEN); litest_add(mouse_tool, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(mouse_buttons, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(mouse_rotation, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); litest_add(mouse_wheel, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_WHEEL); litest_add(airbrush_tool, LITEST_TABLET, LITEST_ANY); litest_add(airbrush_slider, LITEST_TABLET, LITEST_ANY); litest_add(artpen_tool, LITEST_TABLET, LITEST_ANY); litest_add(artpen_rotation, LITEST_TABLET, LITEST_ANY); litest_add(tablet_time_usec, LITEST_TABLET, LITEST_ANY); litest_add(tablet_pressure_distance_exclusive, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); /* The totem doesn't need calibration */ litest_add(tablet_calibration_has_matrix, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); litest_add(tablet_calibration_set_matrix, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); litest_add(tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_TOTEM|LITEST_PRECALIBRATED); litest_add(tablet_area_has_rectangle, LITEST_TABLET, LITEST_ANY); litest_add(tablet_area_set_rectangle_invalid, LITEST_TABLET, LITEST_ANY); litest_with_parameters(params, "axis", 's', 2, "vertical", "horizontal", "direction", 's', 2, "down", "up") { litest_add_parametrized(tablet_area_set_rectangle, LITEST_TABLET, LITEST_ANY, params); } litest_add(tablet_area_set_rectangle_move_outside, LITEST_TABLET, LITEST_ANY); litest_add(tablet_area_set_rectangle_move_outside_to_inside, LITEST_TABLET, LITEST_ANY); litest_add(tablet_area_set_rectangle_move_in_margin, LITEST_TABLET, LITEST_ANY); litest_add(tablet_area_set_rectangle_while_outside, LITEST_TABLET, LITEST_ANY); litest_add(tablet_pressure_min_max, LITEST_TABLET, LITEST_ANY); /* Tests for pressure offset with distance */ litest_add_for_device(tablet_pressure_range, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_set, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_decrease, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_increase, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS5_PEN); /* Tests for pressure offset without distance */ litest_add_for_device(tablet_pressure_range, LITEST_WACOM_HID4800_PEN); litest_add_for_device(tablet_pressure_offset_set, LITEST_WACOM_HID4800_PEN); litest_add_for_device(tablet_pressure_offset_decrease, LITEST_WACOM_HID4800_PEN); litest_add_for_device(tablet_pressure_offset_increase, LITEST_WACOM_HID4800_PEN); litest_add_for_device(tablet_pressure_offset_exceed_threshold, LITEST_WACOM_HID4800_PEN); litest_with_parameters(params, "8k-to-1k", 'b') litest_add_parametrized_for_device(tablet_pressure_across_multiple_tablets, LITEST_WACOM_CINTIQ_12WX_PEN, params); litest_add_no_device(tablet_pressure_after_unplug); litest_add(tablet_pressure_config, LITEST_TABLET, LITEST_TOTEM); litest_add(tablet_pressure_config_set_minimum, LITEST_TABLET, LITEST_TOTEM); litest_add(tablet_pressure_config_set_maximum, LITEST_TABLET, LITEST_TOTEM); litest_add(tablet_pressure_config_set_range, LITEST_TABLET, LITEST_TOTEM); litest_add_for_device(tablet_distance_range, LITEST_WACOM_INTUOS5_PEN); litest_add(relative_no_profile, LITEST_TABLET, LITEST_ANY); litest_add(relative_no_delta_prox_in, LITEST_TABLET, LITEST_ANY); litest_add(relative_delta, LITEST_TABLET, LITEST_ANY); litest_add(relative_no_delta_on_tip, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); litest_add(relative_calibration, LITEST_TABLET, LITEST_PRECALIBRATED); litest_add(touch_arbitration, LITEST_TABLET, LITEST_ANY); litest_add(touch_arbitration_stop_touch, LITEST_TABLET, LITEST_ANY); litest_add(touch_arbitration_suspend_touch_device, LITEST_TOUCH, LITEST_ANY); litest_add(touch_arbitration_remove_touch, LITEST_TABLET, LITEST_ANY); litest_add(touch_arbitration_remove_tablet, LITEST_TOUCH, LITEST_ANY); litest_add(touch_arbitration_keep_ignoring, LITEST_TABLET, LITEST_ANY); litest_add(touch_arbitration_late_touch_lift, LITEST_TABLET, LITEST_ANY); litest_add(touch_arbitration_outside_rect, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); litest_add(touch_arbitration_remove_after, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); litest_add(touch_arbitration_swap_device, LITEST_TABLET, LITEST_ANY); litest_with_parameters(params, "send-btn-tool", 'b') { litest_add_parametrized_for_device(huion_static_btn_tool_pen, LITEST_HUION_TABLET, params); litest_add_parametrized_for_device(huion_static_btn_tool_pen_no_timeout_during_usage, LITEST_HUION_TABLET, params); } litest_with_parameters(params, "btn_tool_pen_timeout", 'b') { litest_add_parametrized_for_device(huion_static_btn_tool_pen_disable_quirk_on_prox_out, LITEST_HUION_TABLET, params); } litest_add_for_device(tablet_smoothing, LITEST_WACOM_HID4800_PEN); } TEST_COLLECTION(tablet_left_handed) { litest_add_for_device(left_handed, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(left_handed_tilt, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(left_handed_mouse_rotation, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(left_handed_artpen_rotation, LITEST_WACOM_INTUOS5_PEN); litest_add_for_device(no_left_handed, LITEST_WACOM_CINTIQ_12WX_PEN); litest_with_parameters(params, "tablet_from", 'b', "touch_from", 'b', "tablet_to", 'b', "touch_to", 'b') { litest_add_parametrized(tablet_rotation_left_handed, LITEST_TABLET, LITEST_ANY, params); litest_add_parametrized(tablet_rotation_left_handed_configuration, LITEST_TABLET, LITEST_ANY, params); litest_add_parametrized(tablet_rotation_left_handed_while_in_prox, LITEST_TABLET, LITEST_ANY, params); litest_add_parametrized(tablet_rotation_left_handed_while_touch_down, LITEST_TABLET, LITEST_ANY, params); litest_add_parametrized(tablet_rotation_left_handed_add_touchpad, LITEST_TABLET, LITEST_ANY, params); litest_add_parametrized(tablet_rotation_left_handed_add_tablet, LITEST_TOUCHPAD, LITEST_ANY, params); } } libinput-1.28.1/test/test-totem.c000066400000000000000000000425621477265155700167150ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include "libinput-util.h" #include "litest.h" #include "util-input-event.h" START_TEST(totem_type) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_tablet_proximity_in(dev, 50, 50, NULL); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); litest_assert_enum_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_TOTEM); libinput_event_destroy(event); } END_TEST START_TEST(totem_axes) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; struct libinput_tablet_tool *tool; litest_drain_events(li); litest_tablet_proximity_in(dev, 50, 50, NULL); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); litest_assert(libinput_tablet_tool_has_rotation(tool)); litest_assert(libinput_tablet_tool_has_size(tool)); litest_assert(libinput_tablet_tool_has_button(tool, BTN_0)); libinput_event_destroy(event); } END_TEST START_TEST(totem_proximity_in_out) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; litest_drain_events(li); litest_tablet_proximity_in(dev, 50, 50, NULL); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_tablet_proximity_out(dev); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libinput_event_destroy(event); } END_TEST START_TEST(totem_proximity_in_on_init) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_event *event; struct libinput_event_tablet_tool *t; const char *devnode; double x, y; double w, h; const struct input_absinfo *abs; abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_X); w = absinfo_range(abs)/abs->resolution; abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y); h = absinfo_range(abs)/abs->resolution; litest_tablet_proximity_in(dev, 50, 50, NULL); /* for simplicity, we create a new litest context */ devnode = libevdev_uinput_get_devnode(dev->uinput); li = litest_create_context(); libinput_path_add_device(li, devnode); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); event = libinput_get_event(li); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); litest_assert_double_gt(x, w/2 - 1); litest_assert_double_lt(x, w/2 + 1); litest_assert_double_gt(y, h/2 - 1); litest_assert_double_lt(y, h/2 + 1); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_DOWN); x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); litest_assert_double_gt(x, w/2 - 1); litest_assert_double_lt(x, w/2 + 1); litest_assert_double_gt(y, h/2 - 1); litest_assert_double_lt(y, h/2 + 1); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_destroy_context(li); } END_TEST START_TEST(totem_proximity_out_on_suspend) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_event *event; struct libinput_event_tablet_tool *t; const char *devnode; /* for simplicity, we create a new litest context */ devnode = libevdev_uinput_get_devnode(dev->uinput); li = litest_create_context(); libinput_path_add_device(li, devnode); litest_tablet_proximity_in(dev, 50, 50, NULL); litest_drain_events(li); libinput_suspend(li); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libinput_event_destroy(event); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_destroy_context(li); } END_TEST START_TEST(totem_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double x = 50, y = 50; double current_x, current_y, old_x, old_y; litest_tablet_proximity_in(dev, x, y, NULL); litest_drain_events(li); for (int i = 0; i < 30; i++, x++, y--) { struct libinput_event_tablet_tool *t; litest_tablet_motion(dev, x + 1, y + 1, NULL); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(libinput_event_tablet_tool_x_has_changed(t)); litest_assert(libinput_event_tablet_tool_y_has_changed(t)); current_x = libinput_event_tablet_tool_get_x(t); current_y = libinput_event_tablet_tool_get_y(t); if (i != 0) { litest_assert_double_gt(current_x, old_x); litest_assert_double_lt(current_y, old_y); } old_x = current_x; old_y = current_y; libinput_event_destroy(event); } } END_TEST START_TEST(totem_rotation) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double r, old_r; struct axis_replacement axes[] = { { ABS_MT_ORIENTATION, 50 }, /* mid-point is 0 */ { -1, -1 } }; litest_tablet_proximity_in(dev, 50, 50, axes); litest_drain_events(li); old_r = 360; for (int i = 1; i < 30; i++) { struct libinput_event_tablet_tool *t; litest_axis_set_value(axes, ABS_MT_ORIENTATION, 50 + i); litest_tablet_motion(dev, 50, 50, axes); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(!libinput_event_tablet_tool_x_has_changed(t)); litest_assert(!libinput_event_tablet_tool_y_has_changed(t)); litest_assert(libinput_event_tablet_tool_rotation_has_changed(t)); r = libinput_event_tablet_tool_get_rotation(t); litest_assert_double_lt(r, old_r); old_r = r; libinput_event_destroy(event); } old_r = 0; for (int i = 1; i < 30; i++) { struct libinput_event_tablet_tool *t; litest_axis_set_value(axes, ABS_MT_ORIENTATION, 50 - i); litest_tablet_motion(dev, 50, 50, axes); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_assert(!libinput_event_tablet_tool_x_has_changed(t)); litest_assert(!libinput_event_tablet_tool_y_has_changed(t)); litest_assert(libinput_event_tablet_tool_rotation_has_changed(t)); r = libinput_event_tablet_tool_get_rotation(t); litest_assert_double_gt(r, old_r); old_r = r; libinput_event_destroy(event); } } END_TEST START_TEST(totem_size) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; double smin, smaj; litest_drain_events(li); litest_tablet_proximity_in(dev, 50, 50, NULL); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert(libinput_event_tablet_tool_size_major_has_changed(t)); litest_assert(libinput_event_tablet_tool_size_minor_has_changed(t)); smaj = libinput_event_tablet_tool_get_size_major(t); smin = libinput_event_tablet_tool_get_size_minor(t); libinput_event_destroy(event); litest_assert_double_eq(smaj, 71.8); litest_assert_double_eq(smin, 71.8); litest_drain_events(li); } END_TEST START_TEST(totem_button) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet_tool *t; litest_tablet_proximity_in(dev, 30, 40, NULL); litest_drain_events(li); litest_button_click(dev, BTN_0, true); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(t), (unsigned int)BTN_0); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(t), LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_button_click(dev, BTN_0, false); litest_dispatch(li); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_assert_int_eq(libinput_event_tablet_tool_get_button(t), (unsigned int)BTN_0); litest_assert_enum_eq(libinput_event_tablet_tool_get_button_state(t), LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); } END_TEST START_TEST(totem_button_down_on_init) { struct litest_device *dev = litest_current_device(); struct libinput *li; struct libinput_event *event; struct libinput_event_tablet_tool *t; const char *devnode; litest_tablet_proximity_in(dev, 50, 50, NULL); litest_button_click(dev, BTN_0, true); /* for simplicity, we create a new litest context */ devnode = libevdev_uinput_get_devnode(dev->uinput); li = litest_create_context(); libinput_path_add_device(li, devnode); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); event = libinput_get_event(li); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); litest_assert_enum_eq(libinput_event_tablet_tool_get_proximity_state(t), LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); event = libinput_get_event(li); t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(t), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); /* The button is down on init but we don't expect an event */ litest_assert_empty_queue(li); litest_button_click(dev, BTN_0, false); litest_dispatch(li); litest_assert_empty_queue(li); /* but buttons after this should be sent */ litest_button_click(dev, BTN_0, true); litest_dispatch(li); litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click(dev, BTN_0, false); litest_dispatch(li); litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED); litest_destroy_context(li); } END_TEST START_TEST(totem_button_up_on_delete) { struct libinput *li = litest_create_context(); struct litest_device *dev = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM); struct libevdev *evdev = libevdev_new(); litest_tablet_proximity_in(dev, 10, 10, NULL); litest_drain_events(li); litest_button_click(dev, BTN_0, true); litest_drain_events(li); litest_delete_device(dev); litest_dispatch(li); litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libevdev_free(evdev); litest_destroy_context(li); } END_TEST START_TEST(totem_arbitration_below) { struct litest_device *totem = litest_current_device(); struct litest_device *touch; struct libinput *li = totem->libinput; touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); litest_drain_events(li); /* touches below the totem, cancelled once the totem is down */ litest_touch_down(touch, 0, 50, 50); litest_dispatch(li); litest_assert_touch_down_frame(li); litest_touch_move_to(touch, 0, 50, 50, 50, 70, 10); litest_dispatch(li); while (libinput_next_event_type(li)) { litest_assert_touch_motion_frame(li); } litest_tablet_proximity_in(totem, 50, 70, NULL); litest_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_DOWN); litest_assert_touch_cancel(li); litest_touch_move_to(touch, 0, 50, 70, 20, 50, 10); litest_assert_empty_queue(li); litest_tablet_motion(totem, 20, 50, NULL); litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS); litest_touch_up(touch, 0); litest_assert_empty_queue(li); litest_delete_device(touch); } END_TEST START_TEST(totem_arbitration_during) { struct litest_device *totem = litest_current_device(); struct litest_device *touch; struct libinput *li = totem->libinput; touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); litest_drain_events(li); litest_tablet_proximity_in(totem, 50, 50, NULL); litest_dispatch(li); litest_drain_events(li); for (int i = 0; i < 3; i++) { litest_touch_down(touch, 0, 51, 51); litest_touch_move_to(touch, 0, 51, 50, 90, 80, 10); litest_touch_up(touch, 0); litest_assert_empty_queue(li); } litest_delete_device(touch); } END_TEST START_TEST(totem_arbitration_outside_rect) { struct litest_device *totem = litest_current_device(); struct litest_device *touch; struct libinput *li = totem->libinput; touch = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM_TOUCH); litest_drain_events(li); litest_tablet_proximity_in(totem, 50, 50, NULL); litest_dispatch(li); litest_drain_events(li); for (int i = 0; i < 3; i++) { litest_touch_down(touch, 0, 81, 51); litest_touch_move_to(touch, 0, 81, 50, 90, 80, 10); litest_touch_up(touch, 0); litest_dispatch(li); litest_assert_touch_sequence(li); } /* moving onto the totem is fine */ litest_touch_down(touch, 0, 81, 51); litest_touch_move_to(touch, 0, 81, 50, 50, 50, 10); litest_touch_up(touch, 0); litest_dispatch(li); litest_assert_touch_sequence(li); litest_delete_device(touch); } END_TEST TEST_COLLECTION(totem) { litest_add(totem_type, LITEST_TOTEM, LITEST_ANY); litest_add(totem_axes, LITEST_TOTEM, LITEST_ANY); litest_add(totem_proximity_in_out, LITEST_TOTEM, LITEST_ANY); litest_add(totem_proximity_in_on_init, LITEST_TOTEM, LITEST_ANY); litest_add(totem_proximity_out_on_suspend, LITEST_TOTEM, LITEST_ANY); litest_add(totem_motion, LITEST_TOTEM, LITEST_ANY); litest_add(totem_rotation, LITEST_TOTEM, LITEST_ANY); litest_add(totem_size, LITEST_TOTEM, LITEST_ANY); litest_add(totem_button, LITEST_TOTEM, LITEST_ANY); litest_add(totem_button_down_on_init, LITEST_TOTEM, LITEST_ANY); litest_add_no_device(totem_button_up_on_delete); litest_add(totem_arbitration_below, LITEST_TOTEM, LITEST_ANY); litest_add(totem_arbitration_during, LITEST_TOTEM, LITEST_ANY); litest_add(totem_arbitration_outside_rect, LITEST_TOTEM, LITEST_ANY); } libinput-1.28.1/test/test-touch.c000066400000000000000000001125341477265155700167040ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include "libinput-util.h" #include "litest.h" START_TEST(touch_frame_events) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int have_frame_event = 0; litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 10, 10); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME) have_frame_event++; libinput_event_destroy(event); } litest_assert_int_eq(have_frame_event, 1); litest_touch_down(dev, 1, 10, 10); litest_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME) have_frame_event++; libinput_event_destroy(event); } litest_assert_int_eq(have_frame_event, 2); } END_TEST START_TEST(touch_downup_no_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 10, 10); litest_dispatch(li); litest_assert_touch_down_frame(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_touch_up_frame(li); } END_TEST START_TEST(touch_abs_transform) { struct litest_device *dev; struct libinput *libinput; struct libinput_event *ev; struct libinput_event_touch *tev; double fx, fy; bool tested = false; struct input_absinfo abs[] = { { ABS_X, 0, 32767, 75, 0, 10 }, { ABS_Y, 0, 32767, 129, 0, 9 }, { ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 }, { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 }, { .value = -1 }, }; dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER, "litest Highres touch device", NULL, abs, NULL); libinput = dev->libinput; litest_touch_down(dev, 0, 100, 100); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_DOWN) { libinput_event_destroy(ev); continue; } tev = libinput_event_get_touch_event(ev); fx = libinput_event_touch_get_x_transformed(tev, 1920); litest_assert_double_eq_epsilon(fx, 1920.0, 0.1); litest_assert_double_lt(fx, 1920.0); fy = libinput_event_touch_get_y_transformed(tev, 720); litest_assert_double_eq_epsilon(fy, 720.0, 0.1); litest_assert_double_lt(fy, 720.0); tested = true; libinput_event_destroy(ev); } litest_assert(tested); litest_delete_device(dev); } END_TEST static inline void touch_assert_seat_slot(struct libinput *li, enum libinput_event_type type, unsigned int slot, unsigned int seat_slot) { struct libinput_event *ev; struct libinput_event_touch *tev; litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_touch_event(ev, type); slot = libinput_event_touch_get_slot(tev); litest_assert_int_eq(slot, slot); slot = libinput_event_touch_get_seat_slot(tev); litest_assert_int_eq(slot, seat_slot); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); } START_TEST(touch_seat_slot) { struct litest_device *dev1 = litest_current_device(); struct litest_device *dev2; struct libinput *li = dev1->libinput; dev2 = litest_add_device(li, LITEST_WACOM_ISDV4_E6_FINGER); litest_drain_events(li); litest_touch_down(dev1, 0, 50, 50); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 0); litest_touch_down(dev2, 0, 50, 50); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 0, 1); litest_touch_down(dev2, 1, 60, 50); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 2); litest_touch_down(dev1, 1, 60, 50); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_DOWN, 1, 3); litest_touch_move_to(dev1, 0, 50, 50, 60, 70, 10); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 0, 0); litest_drain_events(li); litest_touch_move_to(dev2, 1, 50, 50, 60, 70, 10); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_MOTION, 1, 2); litest_drain_events(li); litest_touch_up(dev1, 0); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 0); litest_touch_up(dev2, 0); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 0, 1); litest_touch_up(dev2, 1); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 2); litest_touch_up(dev1, 1); touch_assert_seat_slot(li, LIBINPUT_EVENT_TOUCH_UP, 1, 3); litest_delete_device(dev2); } END_TEST START_TEST(touch_many_slots) { struct libinput *libinput; struct litest_device *dev; struct libinput_event *ev; int slot; const int num_tps = 100; int slot_count = 0; enum libinput_event_type type; struct input_absinfo abs[] = { { ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 }, { .value = -1 }, }; dev = litest_create_device_with_overrides(LITEST_WACOM_ISDV4_E6_FINGER, "litest Multi-touch device", NULL, abs, NULL); libinput = dev->libinput; for (slot = 0; slot < num_tps; ++slot) litest_touch_down(dev, slot, 0, 0); for (slot = 0; slot < num_tps; ++slot) litest_touch_up(dev, slot); litest_dispatch(libinput); while ((ev = libinput_get_event(libinput))) { type = libinput_event_get_type(ev); if (type == LIBINPUT_EVENT_TOUCH_DOWN) slot_count++; else if (type == LIBINPUT_EVENT_TOUCH_UP) break; libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert_notnull(ev); litest_assert_int_gt(slot_count, 0); litest_dispatch(libinput); do { type = libinput_event_get_type(ev); litest_assert_enum_ne(type, LIBINPUT_EVENT_TOUCH_DOWN); if (type == LIBINPUT_EVENT_TOUCH_UP) slot_count--; libinput_event_destroy(ev); litest_dispatch(libinput); } while ((ev = libinput_get_event(libinput))); litest_assert_int_eq(slot_count, 0); litest_delete_device(dev); } END_TEST START_TEST(touch_double_touch_down_up) { struct libinput *libinput; struct litest_device *dev; struct libinput_event *ev; bool got_down = false; bool got_up = false; dev = litest_current_device(); libinput = dev->libinput; litest_disable_log_handler(libinput); /* note: this test is a false negative, libevdev will filter * tracking IDs re-used in the same slot. */ litest_touch_down(dev, 0, 0, 0); litest_touch_down(dev, 0, 0, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 0); litest_dispatch(libinput); litest_restore_log_handler(libinput); while ((ev = libinput_get_event(libinput))) { switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TOUCH_DOWN: litest_assert(!got_down); got_down = true; break; case LIBINPUT_EVENT_TOUCH_UP: litest_assert(got_down); litest_assert(!got_up); got_up = true; break; default: break; } libinput_event_destroy(ev); litest_dispatch(libinput); } litest_assert(got_down); litest_assert(got_up); } END_TEST START_TEST(touch_calibration_scale) { struct libinput *li; struct litest_device *dev; struct libinput_event *ev; struct libinput_event_touch *tev; float matrix[6] = { 1, 0, 0, 0, 1, 0 }; float calibration; double x, y; const int width = 640, height = 480; dev = litest_current_device(); li = dev->libinput; for (calibration = 0.1; calibration < 1; calibration += 0.1) { libinput_device_config_calibration_set_matrix(dev->libinput_device, matrix); litest_drain_events(li); litest_touch_down(dev, 0, 100, 100); litest_touch_up(dev, 0); litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); x = libinput_event_touch_get_x_transformed(tev, width); y = libinput_event_touch_get_y_transformed(tev, height); litest_assert_int_eq(round(x), round(width * matrix[0])); litest_assert_int_eq(round(y), round(height * matrix[4])); libinput_event_destroy(ev); litest_drain_events(li); matrix[0] = calibration; matrix[4] = 1 - calibration; } } END_TEST START_TEST(touch_calibration_rotation) { struct libinput *li; struct litest_device *dev; struct libinput_event *ev; struct libinput_event_touch *tev; float matrix[6]; int i; double x, y; int width = 1024, height = 480; dev = litest_current_device(); li = dev->libinput; for (i = 0; i < 4; i++) { float angle = i * M_PI/2; /* [ cos -sin tx ] [ sin cos ty ] [ 0 0 1 ] */ matrix[0] = cos(angle); matrix[1] = -sin(angle); matrix[3] = sin(angle); matrix[4] = cos(angle); switch(i) { case 0: /* 0 deg */ matrix[2] = 0; matrix[5] = 0; break; case 1: /* 90 deg cw */ matrix[2] = 1; matrix[5] = 0; break; case 2: /* 180 deg cw */ matrix[2] = 1; matrix[5] = 1; break; case 3: /* 270 deg cw */ matrix[2] = 0; matrix[5] = 1; break; } libinput_device_config_calibration_set_matrix(dev->libinput_device, matrix); litest_drain_events(li); litest_touch_down(dev, 0, 80, 20); litest_touch_up(dev, 0); litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); x = libinput_event_touch_get_x_transformed(tev, width); y = libinput_event_touch_get_y_transformed(tev, height); /* rounding errors... */ switch(i) { case 0: /* 0 deg */ litest_assert_double_eq_epsilon(x, width * 0.8, 1.0); litest_assert_double_eq_epsilon(y, height * 0.2, 1.0); break; case 1: /* 90 deg cw */ litest_assert_double_eq_epsilon(x, width * 0.8, 1.0); litest_assert_double_eq_epsilon(y, height * 0.8, 1.0); break; case 2: /* 180 deg cw */ litest_assert_double_eq_epsilon(x, width * 0.2, 1.0); litest_assert_double_eq_epsilon(y, height * 0.8, 1.0); break; case 3: /* 270 deg cw */ litest_assert_double_eq_epsilon(x, width * 0.2, 1.0); litest_assert_double_eq_epsilon(y, height * 0.2, 1.0); break; } libinput_event_destroy(ev); litest_drain_events(li); } } END_TEST START_TEST(touch_calibration_translation) { struct libinput *li; struct litest_device *dev; struct libinput_event *ev; struct libinput_event_touch *tev; float matrix[6] = { 1, 0, 0, 0, 1, 0 }; float translate; double x, y; const int width = 640, height = 480; dev = litest_current_device(); li = dev->libinput; /* translating from 0 up to 1 device width/height */ for (translate = 0.1; translate <= 1; translate += 0.1) { libinput_device_config_calibration_set_matrix(dev->libinput_device, matrix); litest_drain_events(li); litest_touch_down(dev, 0, 100, 100); litest_touch_up(dev, 0); litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); x = libinput_event_touch_get_x_transformed(tev, width); y = libinput_event_touch_get_y_transformed(tev, height); /* sigh. rounding errors */ litest_assert_int_ge(round(x), width + round(width * matrix[2]) - 1); litest_assert_int_ge(round(y), height + round(height * matrix[5]) - 1); litest_assert_int_le(round(x), width + round(width * matrix[2]) + 1); litest_assert_int_le(round(y), height + round(height * matrix[5]) + 1); libinput_event_destroy(ev); litest_drain_events(li); matrix[2] = translate; matrix[5] = 1 - translate; } } END_TEST START_TEST(touch_calibrated_screen_path) { struct litest_device *dev = litest_current_device(); float matrix[6]; int rc; rc = libinput_device_config_calibration_has_matrix(dev->libinput_device); litest_assert_int_eq(rc, 1); rc = libinput_device_config_calibration_get_matrix(dev->libinput_device, matrix); litest_assert_int_eq(rc, 1); litest_assert_double_eq(matrix[0], 1.2); litest_assert_double_eq(matrix[1], 3.4); litest_assert_double_eq(matrix[2], 5.6); litest_assert_double_eq(matrix[3], 7.8); litest_assert_double_eq(matrix[4], 9.10); litest_assert_double_eq(matrix[5], 11.12); } END_TEST START_TEST(touch_calibration_config) { struct litest_device *dev = litest_current_device(); float identity[6] = {1, 0, 0, 0, 1, 0}; float nonidentity[6] = {1, 2, 3, 4, 5, 6}; float matrix[6]; enum libinput_config_status status; int rc; rc = libinput_device_config_calibration_has_matrix(dev->libinput_device); litest_assert_int_eq(rc, 1); /* Twice so we have every to-fro combination */ for (int i = 0; i < 2; i++) { status = libinput_device_config_calibration_set_matrix(dev->libinput_device, identity); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); libinput_device_config_calibration_get_matrix(dev->libinput_device, matrix); litest_assert_int_eq(memcmp(matrix, identity, sizeof(matrix)), 0); status = libinput_device_config_calibration_set_matrix(dev->libinput_device, nonidentity); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); libinput_device_config_calibration_get_matrix(dev->libinput_device, matrix); litest_assert_int_eq(memcmp(matrix, nonidentity, sizeof(matrix)), 0); } } END_TEST static int open_restricted(const char *path, int flags, void *data) { int fd; fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *data) { close(fd); } static const struct libinput_interface simple_interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; START_TEST(touch_calibrated_screen_udev) { struct libinput *li; struct libinput_event *ev; struct libinput_device *device = NULL; struct udev *udev; float matrix[6]; int rc; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); while ((ev = libinput_get_event(li))) { struct libinput_device *d; if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED) { libinput_event_destroy(ev); continue; } d = libinput_event_get_device(ev); if (libinput_device_get_id_vendor(d) == 0x22 && libinput_device_get_id_product(d) == 0x33) { device = libinput_device_ref(d); litest_drain_events(li); } libinput_event_destroy(ev); } litest_drain_events(li); litest_assert_notnull(device); rc = libinput_device_config_calibration_has_matrix(device); litest_assert_int_eq(rc, 1); rc = libinput_device_config_calibration_get_matrix(device, matrix); litest_assert_int_eq(rc, 1); litest_assert_double_eq(matrix[0], 1.2); litest_assert_double_eq(matrix[1], 3.4); litest_assert_double_eq(matrix[2], 5.6); litest_assert_double_eq(matrix[3], 7.8); litest_assert_double_eq(matrix[4], 9.10); litest_assert_double_eq(matrix[5], 11.12); libinput_device_unref(device); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(touch_no_left_handed) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; int rc; rc = libinput_device_config_left_handed_is_available(d); litest_assert_int_eq(rc, 0); rc = libinput_device_config_left_handed_get(d); litest_assert_int_eq(rc, 0); rc = libinput_device_config_left_handed_get_default(d); litest_assert_int_eq(rc, 0); status = libinput_device_config_left_handed_set(d, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(fake_mt_exists) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_device *device; litest_dispatch(li); event = libinput_get_event(li); device = libinput_event_get_device(event); litest_assert(!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)); /* This test may need fixing if we add other fake-mt devices that * have different capabilities */ litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)); libinput_event_destroy(event); } END_TEST START_TEST(fake_mt_no_touch_events) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 5); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_touch_move_to(dev, 0, 50, 50, 90, 40, 10); litest_touch_move_to(dev, 0, 70, 70, 40, 50, 10); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); } END_TEST START_TEST(touch_protocol_a_init) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device = dev->libinput_device; litest_wait_for_event(li); litest_assert(libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)); } END_TEST START_TEST(touch_protocol_a_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_touch *tev; double x, y, oldx, oldy; litest_drain_events(li); litest_touch_down(dev, 0, 5, 95); litest_dispatch(li); ev = libinput_get_event(li); tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); oldx = libinput_event_touch_get_x(tev); oldy = libinput_event_touch_get_y(tev); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); litest_touch_move_to(dev, 0, 10, 90, 90, 10, 20); litest_dispatch(li); while ((ev = libinput_get_event(li))) { if (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_FRAME) { libinput_event_destroy(ev); continue; } litest_assert_event_type(ev, LIBINPUT_EVENT_TOUCH_MOTION); tev = libinput_event_get_touch_event(ev); x = libinput_event_touch_get_x(tev); y = libinput_event_touch_get_y(tev); litest_assert_int_gt(x, oldx); litest_assert_int_lt(y, oldy); oldx = x; oldy = y; libinput_event_destroy(ev); } litest_touch_up(dev, 0); litest_dispatch(li); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP); libinput_event_destroy(ev); } END_TEST START_TEST(touch_protocol_a_2fg_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_touch *tev; int pos; litest_drain_events(li); litest_touch_down(dev, 0, 5, 95); litest_touch_down(dev, 1, 95, 5); litest_dispatch(li); litest_assert_touch_down_frame(li); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); for (pos = 10; pos < 100; pos += 10) { litest_touch_move(dev, 0, pos, 100 - pos); litest_touch_move(dev, 1, 100 - pos, pos); litest_dispatch(li); ev = libinput_get_event(li); tev = libinput_event_get_touch_event(ev); litest_assert_int_eq(libinput_event_touch_get_slot(tev), 0); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); ev = libinput_get_event(li); tev = libinput_event_get_touch_event(ev); litest_assert_int_eq(libinput_event_touch_get_slot(tev), 1); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); } litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_touch_up_frame(li); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_touch_up_frame(li); } END_TEST START_TEST(touch_initial_state) { struct litest_device *dev; struct libinput *libinput1, *libinput2; struct libinput_event *ev1 = NULL; struct libinput_event *ev2 = NULL; struct libinput_event_touch *t1, *t2; struct libinput_device *device1, *device2; int axis = litest_test_param_get_i32(test_env->params, "axis"); dev = litest_current_device(); device1 = dev->libinput_device; libinput_device_config_tap_set_enabled(device1, LIBINPUT_CONFIG_TAP_DISABLED); libinput1 = dev->libinput; litest_touch_down(dev, 0, 40, 60); litest_touch_up(dev, 0); /* device is now on some x/y value */ litest_drain_events(libinput1); libinput2 = litest_create_context(); device2 = libinput_path_add_device(libinput2, libevdev_uinput_get_devnode( dev->uinput)); libinput_device_config_tap_set_enabled(device2, LIBINPUT_CONFIG_TAP_DISABLED); litest_drain_events(libinput2); if (axis == ABS_X) litest_touch_down(dev, 0, 40, 70); else litest_touch_down(dev, 0, 70, 60); litest_touch_up(dev, 0); litest_dispatch(libinput1); litest_dispatch(libinput2); while (libinput_next_event_type(libinput1)) { ev1 = libinput_get_event(libinput1); ev2 = libinput_get_event(libinput2); t1 = litest_is_touch_event(ev1, 0); t2 = litest_is_touch_event(ev2, 0); litest_assert_int_eq(libinput_event_get_type(ev1), libinput_event_get_type(ev2)); if (libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_UP || libinput_event_get_type(ev1) == LIBINPUT_EVENT_TOUCH_FRAME) break; litest_assert_double_eq(libinput_event_touch_get_x(t1), libinput_event_touch_get_x(t2)); litest_assert_double_eq(libinput_event_touch_get_y(t1), libinput_event_touch_get_y(t2)); libinput_event_destroy(ev1); libinput_event_destroy(ev2); ev1 = NULL; ev2 = NULL; } libinput_event_destroy(ev1); libinput_event_destroy(ev2); litest_destroy_context(libinput2); } END_TEST START_TEST(touch_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_touch *tev; uint64_t time_usec; litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 10, 10); litest_dispatch(li); event = libinput_get_event(li); tev = litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); time_usec = libinput_event_touch_get_time_usec(tev); litest_assert_int_eq(libinput_event_touch_get_time(tev), (uint32_t) (time_usec / 1000)); libinput_event_destroy(event); } END_TEST START_TEST(touch_fuzz) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int i; int x = 700, y = 300; litest_drain_events(dev->libinput); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 30); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_DOWN); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(event); litest_drain_events(li); for (i = 0; i < 50; i++) { if (i % 2) { x++; y--; } else { x--; y++; } litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); } } END_TEST START_TEST(touch_fuzz_property) { struct litest_device *dev = litest_current_device(); struct udev_device *d; const char *prop; int fuzz = 0; litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_X), 0); litest_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_Y), 0); d = libinput_device_get_udev_device(dev->libinput_device); prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_00"); litest_assert_notnull(prop); litest_assert(safe_atoi(prop, &fuzz)); litest_assert_int_eq(fuzz, 10); /* device-specific */ prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_01"); litest_assert_notnull(prop); litest_assert(safe_atoi(prop, &fuzz)); litest_assert_int_eq(fuzz, 12); /* device-specific */ udev_device_unref(d); } END_TEST START_TEST(touch_release_on_unplug) { struct litest_device *dev; struct libinput *li; struct libinput_event *ev; li = litest_create_context(); dev = litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); /* Touch is still down when device is removed, expect a release */ litest_delete_device(dev); litest_dispatch(li); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_CANCEL); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME); libinput_event_destroy(ev); ev = libinput_get_event(li); litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(ev); litest_destroy_context(li); } END_TEST START_TEST(touch_invalid_range_over) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_touch *t; double x, y; litest_drain_events(li); /* Touch outside the valid area */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_X, 4000); litest_event(dev, EV_ABS, ABS_Y, 5000); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 5000); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* Expect the mm to be correct regardless */ ev = libinput_get_event(li); t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); x = libinput_event_touch_get_x(t); y = libinput_event_touch_get_y(t); litest_assert_double_eq(x, 300); /* device has resolution 10 */ litest_assert_double_eq(y, 300); /* device has resolution 10 */ /* Expect the percentage to be correct too, even if > 100% */ x = libinput_event_touch_get_x_transformed(t, 100); y = libinput_event_touch_get_y_transformed(t, 100); litest_assert_double_eq(round(x), 200); litest_assert_double_eq(round(y), 120); libinput_event_destroy(ev); } END_TEST START_TEST(touch_invalid_range_under) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_touch *t; double x, y; litest_drain_events(li); /* Touch outside the valid area */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_X, -500); litest_event(dev, EV_ABS, ABS_Y, 1000); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, -500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 1000); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* Expect the mm to be correct regardless */ ev = libinput_get_event(li); t = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN); x = libinput_event_touch_get_x(t); y = libinput_event_touch_get_y(t); litest_assert_double_eq(x, -150); /* device has resolution 10 */ litest_assert_double_eq(y, -100); /* device has resolution 10 */ /* Expect the percentage to be correct too, even if > 100% */ x = libinput_event_touch_get_x_transformed(t, 100); y = libinput_event_touch_get_y_transformed(t, 100); litest_assert_double_eq(round(x), -100); litest_assert_double_eq(round(y), -40); libinput_event_destroy(ev); } END_TEST START_TEST(touch_count_st) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 1); } END_TEST START_TEST(touch_count_mt) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libevdev *evdev = dev->evdev; litest_assert_int_eq(libinput_device_touch_get_touch_count(device), libevdev_get_num_slots(evdev)); } END_TEST START_TEST(touch_count_unknown) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_touch_get_touch_count(device), 0); } END_TEST START_TEST(touch_count_invalid) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; litest_assert_int_eq(libinput_device_touch_get_touch_count(device), -1); } END_TEST static inline bool touch_has_tool_palm(struct litest_device *dev) { return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE); } START_TEST(touch_palm_detect_tool_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_dispatch(li); litest_assert_touch_cancel(li); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touch_palm_detect_tool_palm_on_off) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_dispatch(li); litest_assert_touch_cancel(li); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touch_palm_detect_tool_palm_keep_type) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_touch_up(dev, 0); litest_drain_events(li); /* ABS_MT_TOOL_TYPE never reset to finger, so a new touch should be ignored outright */ litest_touch_down_extended(dev, 0, 50, 50, axes); /* Test the revert to finger case too */ litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touch_palm_detect_tool_palm_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_dispatch(li); litest_assert_touch_cancel(li); litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); litest_dispatch(li); litest_assert_touch_motion_frame(li); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_touch_up_frame(li); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touch_palm_detect_tool_palm_on_off_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_dispatch(li); litest_assert_touch_cancel(li); litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); litest_dispatch(li); litest_assert_touch_motion_frame(li); litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_touch_move_to_extended(dev, 0, 50, 40, 70, 70, axes, 10); litest_assert_empty_queue(li); litest_touch_move_to(dev, 1, 70, 70, 50, 40, 10); litest_dispatch(li); litest_assert_touch_motion_frame(li); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_touch_up_frame(li); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touch_palm_detect_tool_palm_keep_type_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOOL_TYPE, MT_TOOL_PALM }, { -1, 0 } }; if (!touch_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_touch_move_to_extended(dev, 0, 50, 50, 70, 70, axes, 10); litest_touch_up(dev, 0); litest_drain_events(li); litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); litest_dispatch(li); litest_assert_touch_motion_frame(li); /* ABS_MT_TOOL_TYPE never reset to finger, so a new touch should be ignored outright */ litest_touch_down_extended(dev, 0, 50, 50, axes); /* Test the revert to finger case too */ litest_axis_set_value(axes, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_touch_up_frame(li); } END_TEST TEST_COLLECTION(touch) { litest_add(touch_frame_events, LITEST_TOUCH, LITEST_ANY); litest_add(touch_downup_no_motion, LITEST_TOUCH, LITEST_ANY); litest_add(touch_downup_no_motion, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add_no_device(touch_abs_transform); litest_add(touch_seat_slot, LITEST_TOUCH, LITEST_TOUCHPAD); litest_add_no_device(touch_many_slots); litest_add(touch_double_touch_down_up, LITEST_TOUCH, LITEST_PROTOCOL_A); litest_add(touch_calibration_scale, LITEST_TOUCH, LITEST_TOUCHPAD); litest_add(touch_calibration_scale, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add(touch_calibration_rotation, LITEST_TOUCH, LITEST_TOUCHPAD); litest_add(touch_calibration_rotation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add(touch_calibration_translation, LITEST_TOUCH, LITEST_TOUCHPAD); litest_add(touch_calibration_translation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add_for_device(touch_calibrated_screen_path, LITEST_CALIBRATED_TOUCHSCREEN); litest_add_for_device(touch_calibrated_screen_udev, LITEST_CALIBRATED_TOUCHSCREEN); litest_add(touch_calibration_config, LITEST_TOUCH, LITEST_ANY); litest_add(touch_no_left_handed, LITEST_TOUCH, LITEST_ANY); litest_add(fake_mt_exists, LITEST_FAKE_MT, LITEST_ANY); litest_add(fake_mt_no_touch_events, LITEST_FAKE_MT, LITEST_ANY); litest_add(touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY); litest_add(touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY); litest_add(touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { litest_add_parametrized(touch_initial_state, LITEST_TOUCH, LITEST_PROTOCOL_A, params); } litest_add(touch_time_usec, LITEST_TOUCH, LITEST_TOUCHPAD); litest_add_for_device(touch_fuzz, LITEST_MULTITOUCH_FUZZ_SCREEN); litest_add_for_device(touch_fuzz_property, LITEST_MULTITOUCH_FUZZ_SCREEN); litest_add_no_device(touch_release_on_unplug); litest_add_for_device(touch_invalid_range_over, LITEST_TOUCHSCREEN_INVALID_RANGE); litest_add_for_device(touch_invalid_range_under, LITEST_TOUCHSCREEN_INVALID_RANGE); litest_add(touch_count_st, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); litest_add(touch_count_mt, LITEST_TOUCH, LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); litest_add(touch_count_unknown, LITEST_PROTOCOL_A, LITEST_ANY); litest_add(touch_count_invalid, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); litest_add(touch_palm_detect_tool_palm, LITEST_TOUCH, LITEST_ANY); litest_add(touch_palm_detect_tool_palm_on_off, LITEST_TOUCH, LITEST_ANY); litest_add(touch_palm_detect_tool_palm_keep_type, LITEST_TOUCH, LITEST_ANY); litest_add(touch_palm_detect_tool_palm_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); litest_add(touch_palm_detect_tool_palm_on_off_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); litest_add(touch_palm_detect_tool_palm_keep_type_2fg, LITEST_TOUCH, LITEST_ANY); } libinput-1.28.1/test/test-touchpad-buttons.c000066400000000000000000002026761477265155700210740ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "libinput-util.h" #include "litest.h" START_TEST(touchpad_button) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_LEFT)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_click_defaults_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; uint32_t methods, method; enum libinput_config_status status; /* call this test for apple touchpads */ methods = libinput_device_config_click_get_methods(device); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); method = libinput_device_config_click_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); method = libinput_device_config_click_get_default_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_NONE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(touchpad_click_default_clickfinger_map) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_clickfinger_button_map map; map = libinput_device_config_click_get_clickfinger_button_map(device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM); map = libinput_device_config_click_get_default_clickfinger_button_map(device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM); } END_TEST START_TEST(touchpad_click_set_clickfinger_map) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_clickfinger_button_map map; enum libinput_config_status status; map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; status = libinput_device_config_click_set_clickfinger_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); map = libinput_device_config_click_get_clickfinger_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM); map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR; status = libinput_device_config_click_set_clickfinger_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); map = libinput_device_config_click_get_clickfinger_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR); map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM - 1; status = libinput_device_config_click_set_clickfinger_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR + 1; status = libinput_device_config_click_set_clickfinger_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_click_defaults_btnarea) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; uint32_t methods, method; enum libinput_config_status status; /* call this test for non-apple clickpads */ methods = libinput_device_config_click_get_methods(device); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); method = libinput_device_config_click_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); method = libinput_device_config_click_get_default_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_NONE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(touchpad_click_defaults_none) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; uint32_t methods, method; enum libinput_config_status status; if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE && libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH) return LITEST_NOT_APPLICABLE; /* call this test for non-clickpads and non-touchpads */ methods = libinput_device_config_click_get_methods(device); litest_assert_int_eq(methods, 0U); method = libinput_device_config_click_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_NONE); method = libinput_device_config_click_get_default_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_NONE); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(touchpad_1fg_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_1fg_clickfinger_no_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (dev->which == LITEST_SYNAPTICS_PHANTOMCLICKS) { /* The XPS 15 9500 touchpad has the ModelTouchpadPhantomClicks * quirk enabled and doesn't generate events without touches. */ return LITEST_NOT_APPLICABLE; } litest_enable_clickfinger(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_1fg_clickfinger_no_touch_phantomclicks) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: button = BTN_RIGHT; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: button = BTN_MIDDLE; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_3fg_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 70); litest_touch_down(dev, 2, 70, 70); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_3fg_clickfinger_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) >= 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 70); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_4fg_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < 4) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 70); litest_touch_down(dev, 2, 70, 70); litest_touch_down(dev, 3, 80, 70); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_touch_up(dev, 3); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_4fg_clickfinger_btntool_2slots) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) >= 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 70); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_4fg_clickfinger_btntool_3slots) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) != 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 70); litest_touch_down(dev, 2, 70, 70); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_clickfinger_distance) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; double w, h; bool small_touchpad = false; unsigned int expected_button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (libinput_device_get_size(dev->libinput_device, &w, &h) == 0 && h < 50.0) small_touchpad = true; litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); litest_drain_events(li); litest_touch_down(dev, 0, 90, 50); litest_touch_down(dev, 1, 10, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 5); litest_touch_down(dev, 1, 50, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); /* if the touchpad is small enough, we expect all fingers to count * for clickfinger */ if (small_touchpad) switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: expected_button = BTN_RIGHT; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: expected_button = BTN_MIDDLE; break; } else expected_button = BTN_LEFT; litest_assert_button_event(li, expected_button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, expected_button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_3fg_clickfinger_distance) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 90, 20); litest_touch_down(dev, 1, 10, 15); litest_touch_down(dev, 2, 10, 15); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_3fg_clickfinger_distance_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_clickfinger_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) > 2) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_set_clickfinger_map(dev, map); switch (map) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 90, 15); litest_touch_down(dev, 1, 10, 15); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_2fg_clickfinger_bottom) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; /* this test is run for the T440s touchpad only, makes getting the * mm correct easier */ libinput_device_config_click_set_method(dev->libinput_device, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); litest_drain_events(li); /* one above, one below the magic line, vert spread ca 27mm */ litest_touch_down(dev, 0, 40, 60); litest_touch_down(dev, 1, 60, 100); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); /* both below the magic line */ litest_touch_down(dev, 0, 40, 100); litest_touch_down(dev, 1, 60, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); /* one above, one below the magic line, vert spread 17mm */ litest_touch_down(dev, 0, 50, 75); litest_touch_down(dev, 1, 55, 100); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_to_area_method) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_buttonareas(dev); litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_enable_clickfinger(dev); litest_drain_events(li); /* use bottom right corner to catch accidental softbutton right */ litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_to_area_method_while_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_buttonareas(dev); litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_enable_clickfinger(dev); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_drain_events(li); /* use bottom right corner to catch accidental softbutton right */ litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_area_to_clickfinger_method) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); /* use bottom right corner to catch accidental softbutton right */ litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_enable_buttonareas(dev); litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_area_to_clickfinger_method_while_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); /* use bottom right corner to catch accidental softbutton right */ litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_enable_buttonareas(dev); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_down(dev, 0, 95, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_3fg_tool_position) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); /* one in thumb area, one in normal area + TRIPLETAP. spread is wide * but any non-palm 3fg touch+click counts as middle */ litest_touch_down(dev, 0, 20, 99); litest_touch_down(dev, 1, 90, 15); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_4fg_tool_position) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 5, 99); litest_touch_down(dev, 1, 90, 15); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_appletouch_config) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; uint32_t methods, method; enum libinput_config_status status; methods = libinput_device_config_click_get_methods(device); litest_assert(!(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); method = libinput_device_config_click_get_method(device); litest_assert_enum_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_click_set_method(device, LIBINPUT_CONFIG_CLICK_METHOD_NONE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(touchpad_clickfinger_appletouch_1fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_appletouch_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_appletouch_3fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_clickfinger_click_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button; int nslots = litest_slot_count(dev); litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 40, 50); button = BTN_LEFT; if (nfingers > 1) { if (nslots > 1) { litest_touch_down(dev, 1, 50, 50); } else { litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); } button = BTN_RIGHT; } if (nfingers > 2) { if (nslots > 2) { litest_touch_down(dev, 2, 60, 50); } else { litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); } button = BTN_MIDDLE; } litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); for (int i = 0; i < 20; i++) { litest_push_event_frame(dev); switch (nfingers) { case 3: if (nslots >= nfingers) litest_touch_move(dev, 2, 60, 50 + i); _fallthrough_; case 2: if (nslots >= nfingers) litest_touch_move(dev, 1, 50, 50 + i); _fallthrough_; case 1: litest_touch_move(dev, 0, 40, 50 + i); break; } litest_pop_event_frame(dev); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_button_click(dev, BTN_LEFT, false); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); if (nfingers > 3) { if (nslots > 3) { litest_touch_up(dev, 2); } else { litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); } } if (nfingers > 2) { if (nslots > 2) { litest_touch_up(dev, 1); } else { litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); } } litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_btn_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_btn_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_drain_events(li); /* A clickpad always needs a finger down to tell where the click happens */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_click_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); /* now put a second finger down */ litest_touch_down(dev, 1, 70, 70); litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5); litest_touch_up(dev, 1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_finger_pin) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libevdev *evdev = dev->evdev; const struct input_absinfo *abs; double w, h; double dist; abs = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X); litest_assert_notnull(abs); if (abs->resolution == 0) return LITEST_NOT_APPLICABLE; if (libinput_device_get_size(dev->libinput_device, &w, &h) != 0) return LITEST_NOT_APPLICABLE; dist = 100.0/max(w, h); litest_drain_events(li); /* make sure the movement generates pointer events when not pinned */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 54, 54, 10); litest_touch_move_to(dev, 0, 54, 54, 46, 46, 10); litest_touch_move_to(dev, 0, 46, 46, 50, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_button_click(dev, BTN_LEFT, true); litest_drain_events(li); litest_touch_move_to(dev, 0, 50, 50, 50 + dist, 50 + dist, 10); litest_touch_move_to(dev, 0, 50 + dist, 50 + dist, 50, 50, 10); litest_touch_move_to(dev, 0, 50, 50, 50 - dist, 50 - dist, 10); litest_assert_empty_queue(li); litest_button_click(dev, BTN_LEFT, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); /* still pinned after release */ litest_touch_move_to(dev, 0, 50, 50, 50 + dist, 50 + dist, 10); litest_touch_move_to(dev, 0, 50 + dist, 50 + dist, 50, 50, 10); litest_touch_move_to(dev, 0, 50, 50, 50 - dist, 50 - dist, 10); litest_assert_empty_queue(li); /* move to unpin */ litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(clickpad_softbutton_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 10, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_middle) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 50, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_right) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 90, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_left_tap_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_drain_events(li); /* Tap in left button area, then finger down, button click -> expect left button press/release and left button press Release button, finger up -> expect right button release */ litest_touch_down(dev, 0, 20, 90); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 20, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_right_tap_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_drain_events(li); /* Tap in right button area, then finger down, button click -> expect left button press/release and right button press Release button, finger up -> expect right button release */ litest_touch_down(dev, 0, 90, 90); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 90, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_left_1st_fg_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double x = 0, y = 0; int nevents = 0; litest_drain_events(li); /* One finger down in the left button area, button press -> expect a button event Move finger up out of the area, wait for timeout Move finger around diagonally down left -> expect motion events down left Release finger -> expect a button event */ /* finger down, press in left button */ litest_touch_down(dev, 0, 20, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); /* move out of the area, then wait for softbutton timer */ litest_touch_move_to(dev, 0, 20, 90, 50, 50, 20); litest_dispatch(li); litest_timeout_softbuttons(); litest_dispatch(li); litest_drain_events(li); /* move down left, expect motion */ litest_touch_move_to(dev, 0, 50, 50, 20, 90, 20); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *p; litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION); p = libinput_event_get_pointer_event(event); /* we moved up/right, now down/left so the pointer accel code may lag behind with the dx/dy vectors. Hence, add up the x/y movements and expect that on average we moved left and down */ x += libinput_event_pointer_get_dx(p); y += libinput_event_pointer_get_dy(p); nevents++; libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); } litest_assert(x/nevents < 0); litest_assert(y/nevents > 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_left_2nd_fg_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_drain_events(li); /* One finger down in the left button area, button press -> expect a button event Put a second finger down in the area, move it right, release -> expect motion events right Put a second finger down in the area, move it down, release -> expect motion events down Release second finger, release first finger -> expect a button event */ litest_touch_down(dev, 0, 20, 90); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_touch_down(dev, 1, 20, 20); litest_touch_move_to(dev, 1, 20, 20, 80, 20, 25); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *p; double x, y; litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION); p = libinput_event_get_pointer_event(event); x = libinput_event_pointer_get_dx(p); y = libinput_event_pointer_get_dy(p); /* Ignore events only containing an unaccelerated motion * vector. */ if (x != 0 || y != 0) { litest_assert(x > 0); litest_assert(y == 0); } libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); } litest_touch_up(dev, 1); /* second finger down */ litest_touch_down(dev, 1, 20, 20); litest_touch_move_to(dev, 1, 20, 20, 20, 80, 15); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *p; double x, y; litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION); p = libinput_event_get_pointer_event(event); x = libinput_event_pointer_get_dx(p); y = libinput_event_pointer_get_dy(p); litest_assert(x == 0); litest_assert(y > 0); libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); } litest_touch_up(dev, 1); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_left_to_right) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* One finger down in left software button area, move to right button area immediately, click -> expect right button event */ litest_touch_down(dev, 0, 30, 90); litest_touch_move_to(dev, 0, 30, 90, 90, 90, 25); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_right_to_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* One finger down in right software button area, move to left button area immediately, click -> expect left button event */ litest_touch_down(dev, 0, 80, 90); litest_touch_move_to(dev, 0, 80, 90, 30, 90, 25); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_softbutton_hover_into_buttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_hover_start(dev, 0, 50, 50); litest_dispatch(li); litest_hover_move_to(dev, 0, 50, 50, 90, 90, 20); litest_dispatch(li); litest_touch_move_to(dev, 0, 90, 90, 91, 91, 1); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_topsoftbuttons_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 10, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_topsoftbuttons_right) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 90, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_topsoftbuttons_middle) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_touch_down(dev, 0, 50, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_topsoftbuttons_move_out_leftclick_before_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; /* Finger down in top right button area, wait past enter timeout Move into main area, wait past leave timeout Click -> expect left click */ litest_drain_events(li); litest_touch_down(dev, 0, 80, 5); litest_dispatch(li); litest_timeout_softbuttons(); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_move_to(dev, 0, 80, 5, 80, 90, 20); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_topsoftbuttons_move_out_leftclick) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; /* Finger down in top right button area, wait past enter timeout Move into main area, wait past leave timeout Click -> expect left click */ litest_drain_events(li); litest_touch_down(dev, 0, 80, 5); litest_dispatch(li); litest_timeout_softbuttons(); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_move_to(dev, 0, 80, 5, 80, 90, 20); litest_dispatch(li); litest_timeout_softbuttons(); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_topsoftbuttons_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 90, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 90, 5); litest_touch_down(dev, 1, 80, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(clickpad_topsoftbuttons_clickfinger_dev_disabled) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct litest_device *trackpoint = litest_add_device(li, LITEST_TRACKPOINT); libinput_device_config_send_events_set_mode(dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 90, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 90, 5); litest_touch_down(dev, 1, 10, 5); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_delete_device(trackpoint); } END_TEST START_TEST(clickpad_middleemulation_config_delayed) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; int enabled; enabled = libinput_device_config_middle_emulation_get_enabled(device); litest_assert(!enabled); litest_touch_down(dev, 0, 30, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* actual config is delayed, but status is immediate */ status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); enabled = libinput_device_config_middle_emulation_get_enabled(device); litest_assert(enabled); status = libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); enabled = libinput_device_config_middle_emulation_get_enabled(device); litest_assert(!enabled); } END_TEST START_TEST(clickpad_middleemulation_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_enable_middleemu(dev); litest_drain_events(li); litest_touch_down(dev, 0, 30, 95); litest_touch_down(dev, 1, 80, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_middleemulation_click_middle_left) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_enable_middleemu(dev); litest_drain_events(li); litest_touch_down(dev, 0, 49, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_middleemulation_click_middle_right) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_enable_middleemu(dev); litest_drain_events(li); litest_touch_down(dev, 0, 51, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_middleemulation_click_enable_while_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_drain_events(li); litest_touch_down(dev, 0, 49, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_enable_middleemu(dev); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 49, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); } END_TEST START_TEST(clickpad_middleemulation_click_disable_while_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_enable_middleemu(dev); litest_drain_events(li); litest_touch_down(dev, 0, 30, 95); litest_touch_down(dev, 1, 70, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_disable_middleemu(dev); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 49, 95); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); } END_TEST START_TEST(touchpad_non_clickpad_detection) { struct libinput *li; struct libinput_device *device; struct libevdev_uinput *uinput; static struct input_absinfo absinfo[] = { { ABS_X, 1472, 5472, 0, 0, 75 }, { ABS_Y, 1408, 4448, 0, 0, 129 }, { ABS_PRESSURE, 0, 255, 0, 0, 0 }, { ABS_TOOL_WIDTH, 0, 15, 0, 0, 0 }, { ABS_MT_SLOT, 0, 1, 0, 0, 0 }, { ABS_MT_POSITION_X, 1472, 5472, 0, 0, 75 }, { ABS_MT_POSITION_Y, 1408, 4448, 0, 0, 129 }, { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, { ABS_MT_PRESSURE, 0, 255, 0, 0, 0 }, { .value = -1 } }; uint32_t methods; /* Create a touchpad with only a left button but missing * INPUT_PROP_BUTTONPAD. We should treat this as clickpad. */ uinput = litest_create_uinput_abs_device("litest NonClickpad", NULL, absinfo, EV_KEY, BTN_LEFT, EV_KEY, BTN_TOOL_FINGER, EV_KEY, BTN_TOUCH, -1); li = litest_create_context(); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); methods = libinput_device_config_click_get_methods(device); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); libinput_path_remove_device(device); libevdev_uinput_destroy(uinput); litest_destroy_context(li); } END_TEST TEST_COLLECTION(touchpad_buttons) { litest_add(touchpad_button, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_1fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_1fg_clickfinger_no_touch, LITEST_CLICKPAD, LITEST_ANY); litest_with_parameters(params, "map", 'I', 2, litest_named_i32(LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM, "LRM"), litest_named_i32(LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR, "LMR")) { litest_add_parametrized(touchpad_2fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_3fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_3fg_clickfinger_btntool, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_2fg_clickfinger_distance, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_3fg_clickfinger_distance, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_3fg_clickfinger_distance_btntool, LITEST_CLICKPAD, LITEST_ANY, params); } litest_add_for_device(touchpad_2fg_clickfinger_bottom, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add(touchpad_4fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_4fg_clickfinger_btntool_2slots, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_4fg_clickfinger_btntool_3slots, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_clickfinger_to_area_method, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_clickfinger_to_area_method_while_down, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_area_to_clickfinger_method, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_area_to_clickfinger_method_while_down, LITEST_CLICKPAD, LITEST_ANY); /* run those two for the T440 one only so we don't have to worry * about small touchpads messing with thumb detection expectations */ litest_add_for_device(touchpad_clickfinger_3fg_tool_position, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add_for_device(touchpad_clickfinger_4fg_tool_position, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add_for_device(touchpad_clickfinger_appletouch_config, LITEST_APPLETOUCH); litest_add_for_device(touchpad_clickfinger_appletouch_1fg, LITEST_APPLETOUCH); litest_add_for_device(touchpad_clickfinger_appletouch_2fg, LITEST_APPLETOUCH); litest_add_for_device(touchpad_clickfinger_appletouch_3fg, LITEST_APPLETOUCH); litest_add_for_device(touchpad_1fg_clickfinger_no_touch_phantomclicks, LITEST_SYNAPTICS_PHANTOMCLICKS); litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_clickfinger_click_drag, LITEST_CLICKPAD, LITEST_ANY, params); } litest_add(touchpad_click_defaults_clickfinger, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_click_default_clickfinger_map, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_click_set_clickfinger_map, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_click_defaults_btnarea, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(touchpad_click_defaults_none, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_click_defaults_none, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_btn_left, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); litest_add(clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); litest_add(clickpad_finger_pin, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_middle, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(clickpad_softbutton_hover_into_buttons, LITEST_CLICKPAD|LITEST_HOVER, LITEST_APPLE_CLICKPAD); litest_add(clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_move_out_leftclick, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_move_out_leftclick_before_timeout, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_clickfinger, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_topsoftbuttons_clickfinger_dev_disabled, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(clickpad_middleemulation_config_delayed, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_middleemulation_click, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_middleemulation_click_middle_left, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_middleemulation_click_middle_right, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_middleemulation_click_enable_while_down, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_middleemulation_click_disable_while_down, LITEST_CLICKPAD, LITEST_ANY); litest_add_no_device(touchpad_non_clickpad_detection); } libinput-1.28.1/test/test-touchpad-tap.c000066400000000000000000004524221477265155700201560ustar00rootroot00000000000000/* * Copyright © 2014-2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "libinput-util.h" #include "litest.h" START_TEST(touchpad_1fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_doubletap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers_1st"), nfingers2 = litest_test_param_get_i32(test_env->params, "fingers_2nd"); unsigned int button = 0, button2 = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; if (nfingers2 > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } switch (nfingers2) { case 1: button2 = BTN_LEFT; break; case 2: button2 = BTN_RIGHT; break; case 3: button2 = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers2); } litest_drain_events(li); /* one to three finger down, all fingers up, repeat with possibly different number of fingers -> two button event pairs */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } msleep(10); switch (nfingers2) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers2) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); oldtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_lt(oldtime, curtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button2, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_lt(oldtime, curtime); oldtime = curtime; event = libinput_get_event(li); ptrev = litest_is_button_event(event, button2, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_lt(oldtime, curtime); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_timeout_tapndrag(); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } litest_timeout_tapndrag(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 30, 50, 10); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); litest_touch_move_to(dev, 1, 70, 50, 90, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_timeout_tapndrag(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t ptime, rtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_timeout_tapndrag(); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_lt(ptime, rtime); } litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); oldtime = curtime; } event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_high_delay) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { /* Tap timeout is 180ms after a touch or release. Make sure we * go over 180ms for touch+release, but stay under 180ms for * each single event. */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } litest_dispatch(li); msleep(100); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(100); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 50, 70, 10); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 70, 50); litest_touch_up(dev, 0); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_multitap_n_drag_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps < range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 70, 50); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); /* the physical click */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); /* don't use helper functions here, we expect the event be available * immediately, not after a timeout that the helper functions may * trigger. */ litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* lift finger, set down again, should continue dragging */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers_1st"), nfingers2 = litest_test_param_get_i32(test_env->params, "fingers_2nd"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; if (nfingers2 > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* lift finger, set down again, should continue dragging */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); switch (nfingers2) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers2) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50, 50); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); /* the physical click */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_sticky) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock_sticky(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tapndrag(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_2fg) { /* Test: tap with 1-3 fingers (multiple times), then a 1fg move * followed by a second finger down and *both* fingers moving. * This is a special behavior catering for the use-case when a user * needs a second finger down to "hold" the drag while resetting the * first finger. * Even though it's 2fg movement, we expect it to behave like a 1fg * drag. This behavior may change in the future. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 30, 70); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_down(dev, 1, 80, 70); litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_2fg_scroll) { /* Test: tap with 1-3 fingers, then immediate 2fg scroll. * We expect this to be a tap followed by a scroll. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_enable_tap(dev->libinput_device); litest_disable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } /* Two fingers down + move to trigger scrolling */ litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); litest_touch_move_two_touches(dev, 50, 50, 70, 50, 0, 20, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_2fg_scroll) { /* Test: tap with 1-3 fingers, trigger drag-lock, * then immediate 2fg scroll. * We expect this to be a tap-and-drag followed by a scroll. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } /* Drag with one finger */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 50, 70, 10); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* Release finger to trigger drag-lock */ litest_touch_up(dev, 0); /* Two fingers down + move to trigger scrolling */ litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); litest_touch_move_two_touches(dev, 50, 50, 70, 50, 0, 20, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_3fg_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (litest_slot_count(dev) > 2 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 0, 40, 30); litest_touch_down(dev, 1, 50, 30); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); break; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 30, 70); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_down(dev, 1, 80, 90); litest_touch_move_to(dev, 0, 30, 70, 30, 30, 5); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* Putting down a third finger should end the drag */ litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); /* Releasing the fingers should not cause any events */ litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_3fg) { /* Test: tap with 1-3 fingers (multiple times), then a 1fg move * followed by a second finger down and *both* fingers moving. * This is a special behavior catering for the use-case when a user * needs a second finger down to "hold" the drag while resetting the * first finger. * Even though it's 2fg movement, we expect it to behave like a 1fg * drag. This behavior may change in the future. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } /* 1fg down triggers the drag */ litest_touch_down(dev, 0, 30, 70); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); /* 2fg is allowed now without cancelling the drag */ litest_touch_down(dev, 1, 80, 90); litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* Putting down a third finger should end the drag */ litest_touch_down(dev, 2, 50, 50); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); /* Releasing the fingers should not cause any events */ litest_touch_up(dev, 2); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_3fg_swipe) { /* Test: tap with 1-3 fingers, then immediate 3fg swipe. * We expect this to be a tap followed by a swipe. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 30, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 80, 50); litest_dispatch(li); litest_touch_move_three_touches(dev, 30, 50, 50, 50, 80, 50, 0, 20, 10); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); litest_assert_only_typed_events(li, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE); litest_touch_up(dev, 2); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_draglock_3fg_swipe) { /* Test: tap with 1-3 fingers, trigger drag-lock, * then immediate 3fg swipe. * We expect this to be a tap-and-drag followed by a swipe. */ struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_drag_lock(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } /* Drag with one finger */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 50, 70, 10); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* Release finger to trigger drag-lock */ litest_touch_up(dev, 0); litest_touch_down(dev, 0, 30, 50); litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 80, 50); litest_dispatch(li); litest_touch_move_three_touches(dev, 30, 50, 50, 50, 80, 50, 0, 20, 10); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3); litest_assert_only_typed_events(li, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE); litest_touch_up(dev, 2); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; struct libinput_event *ev; struct libinput_event_pointer *ptrev; uint64_t ptime, rtime; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_RIGHT; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_MIDDLE; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); litest_assert_int_lt(ptime, rtime); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_inverted) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; struct libinput_event *ev; struct libinput_event_pointer *ptrev; uint64_t ptime, rtime; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_RIGHT; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_MIDDLE; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); litest_assert_int_lt(ptime, rtime); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_move_on_release) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_push_event_frame(dev); litest_touch_move(dev, 0, 55, 55); litest_touch_up(dev, 1); litest_pop_event_frame(dev); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_n_hold_first) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_n_hold_second) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_quickrelease) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_1fg_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* Finger down, finger up -> tap button press * Physical button click -> no button press/release * Tap timeout -> tap button release */ litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* two fingers down, left button click, fingers up -> one left button, one right button event pair */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_2fg_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* two fingers down, button click, fingers up -> only one button left event pair */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_tap_click_apple) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* two fingers down, button click, fingers up -> only one button right event pair (apple have clickfinger enabled by default) */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_no_2fg_tap_after_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* one finger down, move past threshold, second finger down, first finger up -> no event */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_drain_events(dev->libinput); litest_touch_down(dev, 1, 70, 50); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_no_2fg_tap_after_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* one finger down, wait past tap timeout, second finger down, first finger up -> no event */ litest_touch_down(dev, 0, 50, 50); litest_dispatch(dev->libinput); litest_timeout_tap(); litest_dispatch(dev->libinput); litest_drain_events(dev->libinput); litest_touch_down(dev, 1, 70, 50); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_no_first_fg_tap_after_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* one finger down, second finger down, second finger moves beyond threshold, first finger up -> no event */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(dev->libinput); litest_touch_move_to(dev, 1, 70, 50, 90, 90, 10); litest_dispatch(dev->libinput); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(dev->libinput); while ((event = libinput_get_event(li))) { litest_assert_event_type_not_one_of(event, LIBINPUT_EVENT_POINTER_BUTTON); libinput_event_destroy(event); } } END_TEST START_TEST(touchpad_double_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(dev->libinput); /* finger(s) down, up, one finger down, button click, finger up -> two button event pairs */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_n_drag_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(dev->libinput); /* finger(s) down, up, one finger down, move, button click, finger up -> two button event pairs, motion allowed */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; int i; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } for (i = 0; i < 3; i++) { uint64_t ptime, rtime; struct libinput_event *ev; struct libinput_event_pointer *ptrev; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); msleep(5); litest_touch_down(dev, 1, 70, 50); msleep(5); litest_touch_down(dev, 2, 80, 50); msleep(10); litest_touch_up(dev, (i + 2) % 3); litest_touch_up(dev, (i + 1) % 3); litest_touch_up(dev, (i + 0) % 3); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); litest_assert_int_lt(ptime, rtime); } } END_TEST START_TEST(touchpad_3fg_tap_tap_again) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); uint64_t ptime, rtime; struct libinput_event *ev; struct libinput_event_pointer *ptrev; litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); msleep(5); litest_touch_down(dev, 1, 70, 50); msleep(5); litest_touch_down(dev, 2, 80, 50); msleep(10); litest_touch_up(dev, 0); msleep(10); litest_touch_down(dev, 0, 80, 50); msleep(10); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (i = 0; i < 2; i++) { ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time_usec(ptrev); libinput_event_destroy(ev); litest_assert_int_lt(ptime, rtime); } } END_TEST START_TEST(touchpad_3fg_tap_quickrelease) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_touch_down(dev, 2, 80, 50); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 2); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap_pressure_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) >= 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; /* libinput doesn't export when it uses pressure detection, so we * need to reconstruct this here. Specifically, semi-mt devices are * non-mt in libinput, so if they have ABS_PRESSURE, they'll use it. */ if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_PRESSURE)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_edge_scroll(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_drain_events(li); /* drop below the pressure threshold in the same frame as starting a * third touch, see * E: 8713.954784 0001 014e 0001 # EV_KEY / BTN_TOOL_TRIPLETAP 1 * in https://bugs.freedesktop.org/attachment.cgi?id=137672 */ litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 3); litest_event(dev, EV_ABS, ABS_PRESSURE, 3); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_push_event_frame(dev); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_pop_event_frame(dev); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_3fg_tap_hover_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) >= 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; /* libinput doesn't export when it uses pressure detection, so we * need to reconstruct this here. Specifically, semi-mt devices are * non-mt in libinput, so if they have ABS_PRESSURE, they'll use it. */ if (libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_PRESSURE)) return LITEST_NOT_APPLICABLE; if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT) && libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_edge_scroll(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); litest_touch_move_to(dev, 0, 50, 50, 50, 70, 10); litest_touch_move_to(dev, 1, 70, 50, 50, 70, 10); litest_drain_events(li); /* drop below the pressure threshold in the same frame as starting a * third touch */ litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_push_event_frame(dev); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_pop_event_frame(dev); litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); } END_TEST START_TEST(touchpad_3fg_tap_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) >= 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap_btntool_inverted) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) > 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap_btntool_pointerjump) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; unsigned int button = 0; enum libinput_config_tap_button_map map = litest_test_param_get_i32(test_env->params, "map"); if (litest_slot_count(dev) > 3 || !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, map); litest_disable_hold_gestures(dev->libinput_device); switch (map) { case LIBINPUT_CONFIG_TAP_MAP_LRM: button = BTN_MIDDLE; break; case LIBINPUT_CONFIG_TAP_MAP_LMR: button = BTN_RIGHT; break; default: litest_abort_msg("Invalid map range %d", map); } litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); /* Pointer jump should be ignored */ litest_touch_move_to(dev, 0, 50, 50, 20, 20, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap_slot_release_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; /* Synaptics touchpads sometimes end one touch point after * setting BTN_TOOL_TRIPLETAP. * https://gitlab.freedesktop.org/libinput/libinput/issues/99 */ litest_drain_events(li); litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); /* touch 1 down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2200); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3200); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_X, 2200); litest_event(dev, EV_ABS, ABS_Y, 3200); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* touch 2 and TRIPLETAP down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3800); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* touch 2 up, coordinate jump + ends slot 1, TRIPLETAP stays */ litest_disable_log_handler(li); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3800); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_X, 2500); litest_event(dev, EV_ABS, ABS_Y, 3800); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* slot 2 reactivated */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3800); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 3); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_ABS, ABS_X, 2200); litest_event(dev, EV_ABS, ABS_Y, 3200); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_restore_log_handler(li); /* now end all three */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_3fg_tap_after_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) <= 3) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_touch_down(dev, 0, 40, 20); litest_touch_down(dev, 1, 50, 20); litest_drain_events(li); /* 2fg scroll */ litest_touch_move_two_touches(dev, 40, 20, 50, 20, 0, 20, 10); litest_drain_events(li); litest_timeout_tap(); litest_dispatch(li); /* third finger tap without the other two fingers moving */ litest_touch_down(dev, 2, 60, 40); litest_dispatch(li); litest_touch_up(dev, 2); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_4fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; if (litest_slot_count(dev) <= 4) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); for (i = 0; i < 4; i++) { litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_touch_down(dev, 2, 80, 50); litest_touch_down(dev, 3, 90, 50); litest_touch_up(dev, (i + 3) % 4); litest_touch_up(dev, (i + 2) % 4); litest_touch_up(dev, (i + 1) % 4); litest_touch_up(dev, (i + 0) % 4); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } } END_TEST START_TEST(touchpad_4fg_tap_quickrelease) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) <= 4) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_touch_down(dev, 2, 80, 50); litest_touch_down(dev, 3, 90, 50); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 2); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 3); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_move_after_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* respective number of fingers down */ switch(nfingers) { case 5: litest_touch_down(dev, 4, 80, 30); _fallthrough_; case 4: litest_touch_down(dev, 3, 70, 30); _fallthrough_; case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } /* move finger 1 */ litest_dispatch(li); litest_touch_move_to(dev, 0, 40, 30, 70, 60, 10); litest_dispatch(li); /* lift finger 1, put it back */ litest_touch_up(dev, 0); litest_dispatch(li); litest_touch_down(dev, 0, 40, 30); litest_dispatch(li); /* lift fingers up */ switch(nfingers) { case 5: litest_touch_up(dev, 4); _fallthrough_; case 4: litest_touch_up(dev, 3); _fallthrough_; case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_no_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); } END_TEST START_TEST(touchpad_5fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; if (litest_slot_count(dev) < 5) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); for (i = 0; i < 5; i++) { litest_drain_events(li); litest_touch_down(dev, 0, 20, 50); litest_touch_down(dev, 1, 30, 50); litest_touch_down(dev, 2, 40, 50); litest_touch_down(dev, 3, 50, 50); litest_touch_down(dev, 4, 60, 50); litest_touch_up(dev, (i + 4) % 5); litest_touch_up(dev, (i + 3) % 5); litest_touch_up(dev, (i + 2) % 5); litest_touch_up(dev, (i + 1) % 5); litest_touch_up(dev, (i + 0) % 5); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } } END_TEST START_TEST(touchpad_5fg_tap_quickrelease) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < 5) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 20, 50); litest_touch_down(dev, 1, 30, 50); litest_touch_down(dev, 2, 40, 50); litest_touch_down(dev, 3, 70, 50); litest_touch_down(dev, 4, 90, 50); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 2); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 3); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 4); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_QUINTTAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(clickpad_1fg_tap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); /* finger down, button click, finger up -> only one button left event pair */ litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_is_available) { struct litest_device *dev = litest_current_device(); litest_assert_int_ge(libinput_device_config_tap_get_finger_count(dev->libinput_device), 1); } END_TEST START_TEST(touchpad_tap_is_not_available) { struct litest_device *dev = litest_current_device(); litest_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0); litest_assert_enum_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), LIBINPUT_CONFIG_TAP_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_TAP_ENABLED), LIBINPUT_CONFIG_STATUS_UNSUPPORTED); litest_assert_enum_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_TAP_DISABLED), LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(touchpad_tap_default_disabled) { struct litest_device *dev = litest_current_device(); /* this test is only run on specific devices */ litest_assert_enum_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), LIBINPUT_CONFIG_TAP_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), LIBINPUT_CONFIG_TAP_DISABLED); } END_TEST START_TEST(touchpad_tap_default_enabled) { struct litest_device *dev = litest_current_device(); /* this test is only run on specific devices */ litest_assert_enum_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), LIBINPUT_CONFIG_TAP_ENABLED); litest_assert_enum_eq(libinput_device_config_tap_get_default_enabled(dev->libinput_device), LIBINPUT_CONFIG_TAP_ENABLED); } END_TEST START_TEST(touchpad_tap_invalid) { struct litest_device *dev = litest_current_device(); litest_assert_enum_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 2), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, -1), LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_tap_default_map) { struct litest_device *dev = litest_current_device(); enum libinput_config_tap_button_map map; map = libinput_device_config_tap_get_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); map = libinput_device_config_tap_get_default_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); } END_TEST START_TEST(touchpad_tap_map_unsupported) { struct litest_device *dev = litest_current_device(); enum libinput_config_tap_button_map map; enum libinput_config_status status; map = libinput_device_config_tap_get_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); map = libinput_device_config_tap_get_default_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); status = libinput_device_config_tap_set_button_map(dev->libinput_device, LIBINPUT_CONFIG_TAP_MAP_LMR); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_tap_set_button_map(dev->libinput_device, LIBINPUT_CONFIG_TAP_MAP_LRM); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(touchpad_tap_set_map) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_tap_button_map map; enum libinput_config_status status; map = LIBINPUT_CONFIG_TAP_MAP_LRM; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); map = libinput_device_config_tap_get_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); map = LIBINPUT_CONFIG_TAP_MAP_LMR; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); map = libinput_device_config_tap_get_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LMR); map = LIBINPUT_CONFIG_TAP_MAP_LRM - 1; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); map = LIBINPUT_CONFIG_TAP_MAP_LMR + 1; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_tap_set_map_no_tapping) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_tap_button_map map; enum libinput_config_status status; map = LIBINPUT_CONFIG_TAP_MAP_LRM; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); map = LIBINPUT_CONFIG_TAP_MAP_LMR; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); map = LIBINPUT_CONFIG_TAP_MAP_LRM - 1; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); map = LIBINPUT_CONFIG_TAP_MAP_LMR + 1; status = libinput_device_config_tap_set_button_map(device, map); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_tap_get_map_no_tapping) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_tap_button_map map; map = libinput_device_config_tap_get_button_map(device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); map = libinput_device_config_tap_get_default_button_map(device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); } END_TEST START_TEST(touchpad_tap_map_delayed) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; enum libinput_config_tap_button_map map; litest_enable_tap(dev->libinput_device); litest_set_tap_map(dev->libinput_device, LIBINPUT_CONFIG_TAP_MAP_LRM); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(dev->libinput); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 70); litest_dispatch(li); litest_set_tap_map(dev->libinput_device, LIBINPUT_CONFIG_TAP_MAP_LMR); map = libinput_device_config_tap_get_button_map(dev->libinput_device); litest_assert_enum_eq(map, LIBINPUT_CONFIG_TAP_MAP_LMR); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_drag_default_disabled) { struct litest_device *dev = litest_current_device(); /* this test is only run on specific devices */ litest_assert_enum_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_get_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_DISABLED); } END_TEST START_TEST(touchpad_drag_default_enabled) { struct litest_device *dev = litest_current_device(); /* this test is only run on specific devices */ litest_assert_enum_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_ENABLED); litest_assert_enum_eq(libinput_device_config_tap_get_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_ENABLED); } END_TEST START_TEST(touchpad_drag_config_invalid) { struct litest_device *dev = litest_current_device(); litest_assert_enum_eq(libinput_device_config_tap_set_drag_enabled(dev->libinput_device, 2), LIBINPUT_CONFIG_STATUS_INVALID); litest_assert_enum_eq(libinput_device_config_tap_set_drag_enabled(dev->libinput_device, -1), LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_drag_config_unsupported) { struct litest_device *dev = litest_current_device(); enum libinput_config_status status; litest_assert_enum_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_get_drag_enabled(dev->libinput_device), LIBINPUT_CONFIG_DRAG_DISABLED); status = libinput_device_config_tap_set_drag_enabled(dev->libinput_device, LIBINPUT_CONFIG_DRAG_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_tap_set_drag_enabled(dev->libinput_device, LIBINPUT_CONFIG_DRAG_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } END_TEST START_TEST(touchpad_drag_config_enabledisable) { struct litest_device *dev = litest_current_device(); enum libinput_config_drag_state state; litest_disable_hold_gestures(dev->libinput_device); litest_enable_tap(dev->libinput_device); litest_disable_tap_drag(dev->libinput_device); state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DRAG_DISABLED); litest_enable_tap_drag(dev->libinput_device); state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DRAG_ENABLED); /* same thing with tapping disabled */ litest_enable_tap(dev->libinput_device); litest_disable_tap_drag(dev->libinput_device); state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DRAG_DISABLED); litest_enable_tap_drag(dev->libinput_device); state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DRAG_ENABLED); } END_TEST START_TEST(touchpad_drag_disabled) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_tap_drag(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } /* lift fingers up */ switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_drag_disabled_immediate) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *ev; struct libinput_event_pointer *ptrev; uint64_t press_time, release_time; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_tap_drag(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } msleep(10); /* to force a time difference */ litest_dispatch(li); switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_PRESSED); press_time = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(ev); ev = libinput_get_event(li); ptrev = litest_is_button_event(ev, button, LIBINPUT_BUTTON_STATE_RELEASED); release_time = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(ev); litest_assert_int_gt(release_time, press_time); } END_TEST START_TEST(touchpad_drag_disabled_multitap_no_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint32_t oldtime = 0, curtime; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_tap_drag(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_PRESSED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_gt(curtime, oldtime); event = libinput_get_event(li); ptrev = litest_is_button_event(event, button, LIBINPUT_BUTTON_STATE_RELEASED); curtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_ge(curtime, oldtime); oldtime = curtime; } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_drag_lock_default_disabled) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_get_default_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* ENABLED is a legacy spelling for ENABLED_TIMEOUT */ litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY); status = libinput_device_config_tap_set_drag_lock_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_drag_lock_default_unavailable) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; litest_assert_enum_eq(libinput_device_config_tap_get_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); litest_assert_enum_eq(libinput_device_config_tap_get_default_drag_lock_enabled(device), LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_tap_set_drag_lock_enabled(device, LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_tap_set_drag_lock_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST static inline bool touchpad_has_palm_pressure(struct litest_device *dev) { struct libevdev *evdev = dev->evdev; if (dev->which == LITEST_SYNAPTICS_PRESSUREPAD) return false; if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) return libevdev_get_abs_resolution(evdev, ABS_MT_PRESSURE) == 0; return false; } START_TEST(touchpad_tap_palm_on_idle) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Finger down is immediately palm */ litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Finger down is palm after touch begin */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_hold_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Finger down is palm after tap timeout */ litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_hold_move) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Finger down is palm after tap move threshold */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 60, 60, 10); litest_drain_events(li); litest_touch_move_to_extended(dev, 0, 60, 60, 60, 60, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_tapped) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); /* tap + palm down */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_tapped_palm_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); /* tap + palm down */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_tapped_doubletap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers_1st"), nfingers2 = litest_test_param_get_i32(test_env->params, "fingers_2nd"); unsigned int button = 0, button2 = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; if (nfingers2 + 1 > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } switch (nfingers2) { case 1: button2 = BTN_LEFT; break; case 2: button2 = BTN_RIGHT; break; case 3: button2 = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers2); } litest_drain_events(li); /* tap + palm down + tap with additional finger(s) */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); switch (nfingers2) { case 3: litest_touch_down(dev, 3, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 2, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 1, 40, 30); break; } switch (nfingers2) { case 3: litest_touch_up(dev, 3); _fallthrough_; case 2: litest_touch_up(dev, 2); _fallthrough_; case 1: litest_touch_up(dev, 1); break; } litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, button2, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button2, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_drag) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); /* tap + finger down (->drag), finger turns into palm */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_drag_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 2, other = (which + 1) % 2, nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); /* tap + finger down, 2nd finger down, finger turns to palm */ switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down(dev, this, 50, 50); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_down(dev, other, 60, 50); litest_dispatch(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_dispatch(li); litest_touch_move_to(dev, other, 60, 50, 65, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, other); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, this); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_2) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 2, other = (which + 1) % 2; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* 2fg tap with one finger detected as palm */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 60, 60); litest_drain_events(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, this); litest_touch_up(dev, other); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_2_retouch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 2, other = (which + 1) % 2; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* 2fg tap with one finger detected as palm, that finger is lifted * and taps again as not-palm */ litest_touch_down(dev, this, 50, 50); litest_touch_down(dev, other, 60, 60); litest_drain_events(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, this); litest_dispatch(li); litest_touch_down(dev, this, 70, 70); litest_touch_up(dev, this); litest_touch_up(dev, other); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_3) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 3; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* 3fg tap with one finger detected as palm, that finger is lifted, other two fingers lifted cause 2fg tap */ litest_touch_down(dev, this, 50, 50); litest_touch_down(dev, (this + 1) % 3, 60, 50); litest_touch_down(dev, (this + 2) % 3, 70, 50); litest_drain_events(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, this); litest_dispatch(li); litest_touch_up(dev, (this + 1) % 3); litest_touch_up(dev, (this + 2) % 3); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_3_retouch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 3; if (litest_slot_count(dev) < 3) return LITEST_NOT_APPLICABLE; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* 3fg tap with one finger detected as palm, that finger is lifted, then put down again as normal finger -> 3fg tap */ litest_touch_down(dev, this, 50, 50); litest_touch_down(dev, (this + 1) % 3, 60, 50); litest_touch_down(dev, (this + 2) % 3, 70, 50); litest_drain_events(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, this); litest_dispatch(li); litest_touch_down(dev, this, 50, 50); litest_touch_up(dev, this); litest_touch_up(dev, (this + 1) % 3); litest_touch_up(dev, (this + 2) % 3); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_timeout_tap(); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_on_touch_4) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int which = litest_test_param_get_i32(test_env->params, "which"), this = which % 4; if (litest_slot_count(dev) < 4) return LITEST_NOT_APPLICABLE; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* 3fg tap with one finger detected as palm, that finger is lifted, other two fingers lifted cause 2fg tap */ litest_touch_down(dev, this, 50, 50); litest_touch_down(dev, (this + 1) % 4, 60, 50); litest_touch_down(dev, (this + 2) % 4, 70, 50); litest_touch_down(dev, (this + 3) % 4, 80, 50); litest_drain_events(li); litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, this); litest_dispatch(li); litest_touch_up(dev, (this + 1) % 4); litest_touch_up(dev, (this + 2) % 4); litest_touch_up(dev, (this + 3) % 4); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_after_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); litest_dispatch(li); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_multitap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_multitap_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_multitap_down_again) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers + 1 > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); /* keep palm finger down */ for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 3, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 2, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 1, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 3); _fallthrough_; case 2: litest_touch_up(dev, 2); _fallthrough_; case 1: litest_touch_up(dev, 1); break; } litest_dispatch(li); msleep(10); } litest_timeout_tap(); litest_dispatch(li); for (ntaps = 0; ntaps <= 2 * range + 1; ntaps++) { litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_multitap_click) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; int nfingers = litest_test_param_get_i32(test_env->params, "fingers"), range = litest_test_param_get_i32(test_env->params, "taps"), ntaps; unsigned int button = 0; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (nfingers > litest_slot_count(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); switch (nfingers) { case 1: button = BTN_LEFT; break; case 2: button = BTN_RIGHT; break; case 3: button = BTN_MIDDLE; break; default: litest_abort_msg("Unexpected number of fingers (%d)", nfingers); } litest_drain_events(li); for (ntaps = 0; ntaps <= range; ntaps++) { switch (nfingers) { case 3: litest_touch_down(dev, 2, 60, 30); _fallthrough_; case 2: litest_touch_down(dev, 1, 50, 30); _fallthrough_; case 1: litest_touch_down(dev, 0, 40, 30); break; } switch (nfingers) { case 3: litest_touch_up(dev, 2); _fallthrough_; case 2: litest_touch_up(dev, 1); _fallthrough_; case 1: litest_touch_up(dev, 0); break; } litest_dispatch(li); msleep(10); } litest_touch_down(dev, 0, 50, 50); litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); /* keep palm finger down */ litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); for (ntaps = 0; ntaps <= range; ntaps++) { litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED); } /* the click */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_click_then_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_dispatch(li); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_tap_palm_dwt_tap) { struct litest_device *dev = litest_current_device(); struct litest_device *keyboard; struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_B, true); litest_keyboard_key(keyboard, KEY_A, false); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_keyboard_key(keyboard, KEY_B, false); litest_drain_events(li); litest_timeout_dwt_long(); litest_dispatch(li); /* Changes to palm after dwt timeout */ litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); litest_dispatch(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_tap_palm_3fg_start) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (litest_slot_count(dev) < 3 || !litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_push_event_frame(dev); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 55, 55); litest_touch_down(dev, 2, 99, 55); /* edge palm */ litest_pop_event_frame(dev); litest_dispatch(li); litest_touch_up(dev, 2); /* release the palm */ litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST TEST_COLLECTION(touchpad_tap) { litest_add(touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_with_parameters(params, "fingers_1st", 'i', 3, 1, 2, 3, "fingers_2nd", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_doubletap, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3, "taps", 'i', 3, 3, 4, 5) { litest_add_parametrized(touchpad_multitap, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_multitap_timeout, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_add(touchpad_2fg_tap_move_on_release, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_tap_n_hold_first, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_tap_n_hold_second, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_1fg_tap_click, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); litest_add(touchpad_2fg_tap_click, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_SINGLE_TOUCH|LITEST_CLICKPAD); litest_add(touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_no_2fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_no_2fg_tap_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_3fg_tap_tap_again, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_3fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_3fg_tap_hover_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_3fg_tap_pressure_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add_for_device(touchpad_3fg_tap_slot_release_btntool, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add(touchpad_3fg_tap_after_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_4fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_4fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_5fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_5fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_with_parameters(params, "map", 'I', 2, litest_named_i32(LIBINPUT_CONFIG_TAP_MAP_LRM, "LRM"), litest_named_i32(LIBINPUT_CONFIG_TAP_MAP_LMR, "LMR")) { litest_add_parametrized(touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT, params); litest_add_parametrized(touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_3fg_tap_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_3fg_tap_btntool_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized_for_device(touchpad_3fg_tap_btntool_pointerjump, LITEST_SYNAPTICS_TOPBUTTONPAD, params); litest_add_parametrized(touchpad_3fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "fingers", 'i', 4, 2, 3, 4, 5) { litest_add_parametrized(touchpad_move_after_touch, LITEST_TOUCHPAD, LITEST_ANY, params); } /* Real buttons don't interfere with tapping, so don't run those for pads with buttons */ litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_double_tap_click, LITEST_CLICKPAD, LITEST_ANY, params); } litest_add(touchpad_tap_default_disabled, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_ANY); litest_add(touchpad_tap_default_enabled, LITEST_TOUCHPAD, LITEST_BUTTON); litest_add(touchpad_tap_invalid, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_tap_default_map, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_map_unsupported, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_tap_set_map, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_set_map_no_tapping, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_tap_get_map_no_tapping, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_tap_map_delayed, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(clickpad_1fg_tap_click, LITEST_CLICKPAD, LITEST_ANY); litest_add(clickpad_2fg_tap_click, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD); } TEST_COLLECTION(touchpad_tap_drag) { litest_add(touchpad_drag_lock_default_disabled, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_drag_lock_default_unavailable, LITEST_ANY, LITEST_TOUCHPAD); litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3, "taps", 'i', 3, 3, 4, 5) { litest_add_parametrized(touchpad_multitap_n_drag_tap_click, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_multitap_n_drag_timeout, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_multitap_n_drag_tap, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_multitap_n_drag_move, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_multitap_n_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_multitap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_drag_disabled_multitap_no_drag, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3, "taps", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_multitap_n_drag_high_delay, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_n_drag_draglock_tap_click, LITEST_CLICKPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_n_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_draglock_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD, params); litest_add_parametrized(touchpad_tap_n_drag_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_3fg_swipe, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_draglock_3fg_swipe, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_n_drag_draglock, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_n_drag_draglock_timeout, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_n_drag_draglock_sticky, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_drag_disabled, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_drag_disabled_immediate, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers_1st", 'i', 3, 1, 2, 3, "fingers_2nd", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_tap_n_drag_draglock_tap, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_add(touchpad_drag_default_disabled, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_drag_default_enabled, LITEST_TOUCHPAD, LITEST_BUTTON); litest_add(touchpad_drag_config_invalid, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_drag_config_unsupported, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_drag_config_enabledisable, LITEST_TOUCHPAD, LITEST_ANY); } TEST_COLLECTION(touchpad_tap_palm) { litest_add(touchpad_tap_palm_on_idle, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_palm_on_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_palm_on_touch_hold_timeout, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_palm_on_touch_hold_move, LITEST_TOUCHPAD, LITEST_ANY); litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_tap_palm_on_tapped, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_palm_on_tapped_palm_down, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_palm_on_drag, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_palm_after_tap, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers_1st", 'i', 3, 1, 2, 3, "fingers_2nd", 'i', 3, 1, 2, 3) { litest_add_parametrized(touchpad_tap_palm_on_tapped_doubletap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3, "which", 'I', 2, litest_named_i32(0, "first"), litest_named_i32(1, "second")) { litest_add_parametrized(touchpad_tap_palm_on_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "which", 'I', 2, litest_named_i32(0, "first"), litest_named_i32(1, "second")) { litest_add_parametrized(touchpad_tap_palm_on_touch_2, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_palm_on_touch_2_retouch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "which", 'I', 3, litest_named_i32(0, "first"), litest_named_i32(1, "second"), litest_named_i32(2, "third")) { litest_add_parametrized(touchpad_tap_palm_on_touch_3, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_palm_on_touch_3_retouch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "which", 'I', 4, litest_named_i32(0, "first"), litest_named_i32(1, "second"), litest_named_i32(2, "third"), litest_named_i32(3, "fourth")) { litest_add_parametrized(touchpad_tap_palm_on_touch_4, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); } litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3, "taps", 'i', 3, 3, 4, 5) { litest_add_parametrized(touchpad_tap_palm_multitap, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_palm_multitap_timeout, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_tap_palm_multitap_down_again, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params); litest_add_parametrized(touchpad_tap_palm_multitap_click, LITEST_CLICKPAD, LITEST_ANY, params); } litest_add(touchpad_tap_palm_click_then_tap, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_tap_palm_dwt_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_tap_palm_3fg_start, LITEST_TOUCHPAD, LITEST_ANY); } libinput-1.28.1/test/test-touchpad.c000066400000000000000000006606541477265155700174040ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "libinput-util.h" #include "litest.h" static inline bool has_disable_while_typing(struct litest_device *device) { return libinput_device_config_dwt_is_available(device->libinput_device); } static inline struct litest_device * dwt_init_paired_keyboard(struct libinput *li, struct litest_device *touchpad) { enum litest_device_type which = LITEST_KEYBOARD; if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_APPLE) which = LITEST_APPLE_KEYBOARD; if (libevdev_get_id_vendor(touchpad->evdev) == VENDOR_ID_CHICONY) which = LITEST_ACER_HAWAII_KEYBOARD; return litest_add_device(li, which); } START_TEST(touchpad_1fg_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 50, 20); litest_touch_up(dev, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *ptrev; ptrev = litest_is_motion_event(event); litest_assert_double_ge(libinput_event_pointer_get_dx(ptrev), 0); litest_assert_double_eq(libinput_event_pointer_get_dy(ptrev), 0); libinput_event_destroy(event); event = libinput_get_event(li); } } END_TEST START_TEST(touchpad_2fg_no_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; libinput_device_config_tap_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_TAP_DISABLED); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_down(dev, 1, 70, 20); litest_touch_move_two_touches(dev, 20, 20, 70, 20, 20, 30, 20); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); event = libinput_get_event(li); while (event) { litest_assert_enum_ne(libinput_event_get_type(event), LIBINPUT_EVENT_POINTER_MOTION); libinput_event_destroy(event); event = libinput_get_event(li); } } END_TEST static void test_2fg_scroll(struct litest_device *dev, double dx, double dy, bool want_sleep) { struct libinput *li = dev->libinput; litest_touch_down(dev, 0, 49, 50); litest_touch_down(dev, 1, 51, 50); litest_touch_move_two_touches(dev, 49, 50, 51, 50, dx, dy, 10); /* Avoid a small scroll being seen as a tap */ if (want_sleep) { litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); } litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); } START_TEST(touchpad_2fg_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); test_2fg_scroll(dev, 0.1, 40, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 9); test_2fg_scroll(dev, 0.1, -40, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -9); test_2fg_scroll(dev, 40, 0.1, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 9); test_2fg_scroll(dev, -40, 0.1, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9); /* 2fg scroll smaller than the threshold should not generate events */ test_2fg_scroll(dev, 0.1, 0.1, true); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_scroll_initially_diagonal) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int i; int expected_nevents; double w, h; double ratio; double ydelta; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_assert_int_eq(libinput_device_get_size(dev->libinput_device, &w, &h), 0); ratio = w/h; litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 45, 30); litest_touch_down(dev, 1, 55, 30); /* start diagonally */ ydelta = 15 * ratio; litest_touch_move_two_touches(dev, 45, 30, 55, 30, 15, ydelta, 10); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); litest_drain_events(li); /* get rid of any touch history still adding x deltas sideways */ for (i = 0; i < 5; i++) litest_touch_move(dev, 0, 60, 30 + ydelta + (i * ratio)); litest_drain_events(li); /* scroll vertical only and make sure the horiz axis is never set */ expected_nevents = 0; for (i = 6; i < 15; i++) { litest_touch_move(dev, 0, 60, 30 + ydelta + i * ratio); expected_nevents++; } /* both high-resolution and low-resolution events are generated */ expected_nevents *= 2; litest_dispatch(li); event = libinput_get_event(li); do { struct libinput_event_pointer *ptrev; ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); litest_assert(!libinput_event_pointer_has_axis(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)); libinput_event_destroy(event); event = libinput_get_event(li); expected_nevents--; } while (event); litest_assert_int_eq(expected_nevents, 0); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); } END_TEST static bool is_single_axis_2fg_scroll(struct litest_device *dev, enum libinput_pointer_axis axis) { struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; enum libinput_pointer_axis on_axis = axis; enum libinput_pointer_axis off_axis = (axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) ? LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL : LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; bool has_on_axis, has_off_axis; bool val = true; event = libinput_get_event(li); while (event) { ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, on_axis, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); has_on_axis = libinput_event_pointer_has_axis(ptrev, on_axis); has_off_axis = libinput_event_pointer_has_axis(ptrev, off_axis); if (has_on_axis && has_off_axis) { val = (litest_event_pointer_get_value(ptrev, off_axis) == 0.0); /* There must be an extra low/high-resolution event with * the same axis value (0.0). */ libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_notnull(event); ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, on_axis, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); litest_assert(val == (litest_event_pointer_get_value(ptrev, off_axis) == 0.0)); break; } litest_assert(has_on_axis); litest_assert(!has_off_axis); libinput_event_destroy(event); event = libinput_get_event(li); } libinput_event_destroy(event); return val; } START_TEST(touchpad_2fg_scroll_axis_lock) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; enum libinput_pointer_axis axis; double delta[4][2] = { { 7, 40}, { 7, -40}, {-7, 40}, {-7, -40} }; /* 10 degrees off from horiz/vert should count as straight */ if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; for (int i = 0; i < 4; i++) { test_2fg_scroll(dev, delta[i][0], delta[i][1], false); litest_assert(is_single_axis_2fg_scroll(dev, axis)); litest_assert_empty_queue(li); } axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; for (int i = 0; i < 4; i++) { test_2fg_scroll(dev, delta[i][1], delta[i][0], false); litest_assert(is_single_axis_2fg_scroll(dev, axis)); litest_assert_empty_queue(li); } } END_TEST START_TEST(touchpad_2fg_scroll_axis_lock_switch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; enum libinput_pointer_axis axis; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_down(dev, 1, 25, 20); /* Move roughly straight horizontally for >100ms to set axis lock */ litest_touch_move_two_touches(dev, 20, 20, 25, 20, 55, 10, 15); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; litest_assert(is_single_axis_2fg_scroll(dev, axis)); litest_drain_events(li); msleep(200); litest_dispatch(li); /* Move roughly vertically for >100ms to switch axis lock. This will * contain some horizontal movement while the lock changes; don't * check for single-axis yet */ litest_touch_move_two_touches(dev, 75, 30, 80, 30, 2, 20, 15); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); litest_drain_events(li); /* Move some more, roughly vertically, and check new axis lock */ litest_touch_move_two_touches(dev, 77, 50, 82, 50, 1, 40, 15); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; litest_assert(is_single_axis_2fg_scroll(dev, axis)); litest_drain_events(li); /* Move in a clear diagonal direction to ensure the lock releases */ litest_touch_move_two_touches(dev, 78, 90, 83, 90, -60, -60, 20); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; litest_assert(!is_single_axis_2fg_scroll(dev, axis)); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_drain_events(li); } END_TEST START_TEST(touchpad_2fg_scroll_slow_distance) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double width, height; double y_move = 100; bool last_hi_res_event_found, last_low_res_event_found; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; last_hi_res_event_found = false; last_low_res_event_found = false; /* We want to move > 5 mm. */ litest_assert_int_eq(libinput_device_get_size(dev->libinput_device, &width, &height), 0); y_move = 100.0/height * 7; litest_enable_2fg_scroll(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 49, 50); litest_touch_down(dev, 1, 51, 50); litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, y_move, 100); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *ptrev; double axisval; ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); axisval = litest_event_pointer_get_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); if (litest_is_high_res_axis_event(event)) { litest_assert(!last_hi_res_event_found); if (axisval == 0) last_hi_res_event_found = true; } else { litest_assert(!last_low_res_event_found); if (axisval == 0) last_low_res_event_found = true; } litest_assert(axisval >= 0.0); /* this is to verify we test the right thing, if the value is greater than scroll.threshold we triggered the wrong condition */ litest_assert(axisval < 5.0); libinput_event_destroy(event); event = libinput_get_event(li); } litest_assert(last_low_res_event_found); litest_assert(last_hi_res_event_found); litest_assert_empty_queue(li); libinput_event_destroy(event); } END_TEST START_TEST(touchpad_2fg_scroll_source) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); test_2fg_scroll(dev, 0, 30, false); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); while ((event = libinput_get_event(li))) { litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); libinput_event_destroy(event); } } END_TEST START_TEST(touchpad_2fg_scroll_semi_mt) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_down(dev, 1, 30, 20); litest_dispatch(li); litest_touch_move_two_touches(dev, 20, 20, 30, 20, 30, 40, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_2fg_scroll_return_to_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); /* start with motion */ litest_touch_down(dev, 0, 70, 70); litest_touch_move_to(dev, 0, 70, 70, 49, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* 2fg scroll */ litest_touch_down(dev, 1, 51, 50); litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5); litest_touch_up(dev, 1); litest_dispatch(li); litest_timeout_finger_switch(); litest_dispatch(li); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_touch_move_to(dev, 0, 49, 70, 49, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* back to 2fg scroll, lifting the other finger */ litest_touch_down(dev, 1, 51, 50); litest_touch_move_two_touches(dev, 49, 50, 51, 50, 0, 20, 5); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_finger_switch(); litest_dispatch(li); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* move with second finger */ litest_touch_move_to(dev, 1, 51, 70, 51, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 1); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_2fg_scroll_from_btnareas) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_2fg_scroll(dev) || !litest_has_btnareas(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_enable_buttonareas(dev); litest_drain_events(li); litest_touch_down(dev, 0, 30, 95); litest_touch_down(dev, 1, 50, 95); litest_dispatch(li); /* First finger moves out of the area first but it's a scroll * motion, should not trigger POINTER_MOTION */ for (int i = 0; i < 5; i++) { litest_touch_move(dev, 0, 30, 95 - i); } litest_dispatch(li); for (int i = 0; i < 20; i++) { litest_touch_move(dev, 0, 30, 90 - i); litest_touch_move(dev, 1, 50, 95 - i); } litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_scroll_natural_defaults) { struct litest_device *dev = litest_current_device(); int enabled = libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE; litest_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), enabled); litest_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), enabled); } END_TEST START_TEST(touchpad_scroll_natural_enable_config) { struct litest_device *dev = litest_current_device(); enum libinput_config_status status; status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 1); status = libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); } END_TEST START_TEST(touchpad_scroll_natural_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1); test_2fg_scroll(dev, 0.1, 40, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -9); test_2fg_scroll(dev, 0.1, -40, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 9); test_2fg_scroll(dev, 40, 0.1, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9); test_2fg_scroll(dev, -40, 0.1, false); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 9); } END_TEST START_TEST(touchpad_scroll_natural_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_edge_scroll(dev); litest_drain_events(li); libinput_device_config_scroll_set_natural_scroll_enabled(dev->libinput_device, 1); litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -4); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 99, 80); litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_vert) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10); litest_touch_up(dev, 0); litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 99, 80); litest_touch_move_to(dev, 0, 99, 80, 99, 20, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -4); litest_assert_empty_queue(li); } END_TEST static int touchpad_has_horiz_edge_scroll_size(struct litest_device *dev) { double width, height; int rc; rc = libinput_device_get_size(dev->libinput_device, &width, &height); return rc == 0 && height >= 40; } START_TEST(touchpad_edge_scroll_horiz) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10); litest_touch_up(dev, 0); if (!touchpad_has_horiz_edge_scroll_size(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 20, 99); litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 4); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 70, 99); litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -4); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_horiz_clickpad) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 20, 99); litest_touch_move_to(dev, 0, 20, 99, 70, 99, 15); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 4); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 70, 99); litest_touch_move_to(dev, 0, 70, 99, 20, 99, 15); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -4); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_no_horiz) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (touchpad_has_horiz_edge_scroll_size(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 20, 99); litest_touch_move_to(dev, 0, 20, 99, 70, 99, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_down(dev, 0, 70, 99); litest_touch_move_to(dev, 0, 70, 99, 20, 99, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_scroll_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct libevdev *evdev = dev->evdev; enum libinput_config_scroll_method method, expected; enum libinput_config_status status; bool should_have_2fg = false; if (libevdev_get_num_slots(evdev) > 1 || (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE && libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH)) should_have_2fg = true; method = libinput_device_config_scroll_get_methods(device); litest_assert(method & LIBINPUT_CONFIG_SCROLL_EDGE); if (should_have_2fg) litest_assert(method & LIBINPUT_CONFIG_SCROLL_2FG); else litest_assert((method & LIBINPUT_CONFIG_SCROLL_2FG) == 0); if (should_have_2fg) expected = LIBINPUT_CONFIG_SCROLL_2FG; else expected = LIBINPUT_CONFIG_SCROLL_EDGE; method = libinput_device_config_scroll_get_method(device); litest_assert_int_eq(method, expected); method = libinput_device_config_scroll_get_default_method(device); litest_assert_int_eq(method, expected); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_EDGE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_scroll_set_method(device, LIBINPUT_CONFIG_SCROLL_2FG); if (should_have_2fg) litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); else litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST START_TEST(touchpad_edge_scroll_timeout) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; double width = 0, height = 0; int nevents = 0; double mm; /* one mm in percent of the device */ litest_assert_int_eq(libinput_device_get_size(dev->libinput_device, &width, &height), 0); mm = 100.0/height; /* timeout-based scrolling is disabled when software buttons are * active, so switch to clickfinger. Not all test devices support * that, hence the extra check. */ if (libinput_device_config_click_get_methods(dev->libinput_device) & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) litest_enable_clickfinger(dev); litest_drain_events(li); litest_enable_edge_scroll(dev); /* move 0.5mm, enough to load up the motion history, but less than * the scroll threshold of 2mm */ litest_touch_down(dev, 0, 99, 20); litest_dispatch(li); litest_timeout_hysteresis(); litest_dispatch(li); litest_touch_move_to(dev, 0, 99, 20, 99, 20 + mm/2, 8); litest_dispatch(li); litest_assert_empty_queue(li); litest_timeout_edgescroll(); litest_dispatch(li); litest_assert_empty_queue(li); /* now move slowly up to the 2mm scroll threshold. we expect events */ litest_touch_move_to(dev, 0, 99, 20 + mm/2, 99, 20 + mm * 2, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); while ((event = libinput_get_event(li))) { struct libinput_event_pointer *ptrev; double value; ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); value = litest_event_pointer_get_value(ptrev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert_double_lt(value, 5.0); libinput_event_destroy(event); nevents++; } /* we sent 20 events but allow for some to be swallowed by rounding * errors, the hysteresis, etc. */ litest_assert_int_ge(nevents, 10); litest_assert_empty_queue(li); libinput_event_destroy(event); } END_TEST START_TEST(touchpad_edge_scroll_no_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 99, 10); litest_touch_move_to(dev, 0, 99, 10, 99, 70, 12); /* moving outside -> no motion event */ litest_touch_move_to(dev, 0, 99, 70, 20, 70, 12); /* moving down outside edge once scrolling had started -> scroll */ litest_touch_move_to(dev, 0, 20, 70, 40, 99, 12); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_no_edge_after_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_edge_scroll(dev); /* moving into the edge zone must not trigger scroll events */ litest_touch_down(dev, 0, 20, 20); litest_touch_move_to(dev, 0, 20, 20, 99, 20, 22); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 22); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_source) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10); litest_touch_up(dev, 0); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); while ((event = libinput_get_event(li))) { struct libinput_event_pointer *ptrev; ptrev = litest_is_axis_event(event, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); litest_assert_enum_eq(litest_event_pointer_get_axis_source(ptrev), LIBINPUT_POINTER_AXIS_SOURCE_FINGER); libinput_event_destroy(event); } } END_TEST START_TEST(touchpad_edge_scroll_no_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_enable_edge_scroll(dev); litest_touch_down(dev, 0, 49, 50); litest_touch_down(dev, 1, 51, 50); litest_touch_move_two_touches(dev, 49, 50, 51, 50, 20, 30, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_edge_scroll_into_buttonareas) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_buttonareas(dev); litest_enable_edge_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 99, 40); litest_touch_move_to(dev, 0, 99, 40, 99, 95, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* in the button zone now, make sure we still get events */ litest_touch_move_to(dev, 0, 99, 95, 99, 100, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* and out of the zone again */ litest_touch_move_to(dev, 0, 99, 100, 99, 70, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* still out of the zone */ litest_touch_move_to(dev, 0, 99, 70, 99, 50, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_edge_scroll_within_buttonareas) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_horiz_edge_scroll_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_buttonareas(dev); litest_enable_edge_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 99); /* within left button */ litest_touch_move_to(dev, 0, 20, 99, 40, 99, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* over to right button */ litest_touch_move_to(dev, 0, 40, 99, 60, 99, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* within right button */ litest_touch_move_to(dev, 0, 60, 99, 80, 99, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_edge_scroll_buttonareas_click_stops_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; if (!touchpad_has_horiz_edge_scroll_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_buttonareas(dev); litest_enable_edge_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 95); litest_touch_move_to(dev, 0, 20, 95, 70, 95, 15); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); litest_assert_axis_end_sequence(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); /* move within button areas but we cancelled the scroll so now we * get pointer motion events when moving. * * This is not ideal behavior, but the use-case of horizontal * edge scrolling, click, then scrolling without lifting the finger * is so small we'll let it pass. */ litest_touch_move_to(dev, 0, 70, 95, 90, 95, 15); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_button_click(dev, BTN_LEFT, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); litest_touch_up(dev, 0); } END_TEST START_TEST(touchpad_edge_scroll_clickfinger_click_stops_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; if (!touchpad_has_horiz_edge_scroll_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_enable_edge_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 95); litest_touch_move_to(dev, 0, 20, 95, 70, 95, 15); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); litest_assert_axis_end_sequence(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); /* clickfinger releases pointer -> expect movement */ litest_touch_move_to(dev, 0, 70, 95, 90, 95, 15); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_empty_queue(li); litest_button_click(dev, BTN_LEFT, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); litest_touch_up(dev, 0); } END_TEST START_TEST(touchpad_edge_scroll_into_area) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_edge_scroll(dev); litest_drain_events(li); /* move into area, move vertically, move back to edge */ litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15); litest_touch_move_to(dev, 0, 99, 50, 20, 50, 15); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_touch_move_to(dev, 0, 20, 50, 20, 20, 15); litest_touch_move_to(dev, 0, 20, 20, 99, 20, 15); litest_assert_empty_queue(li); litest_touch_move_to(dev, 0, 99, 20, 99, 50, 15); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST static bool touchpad_has_top_palm_detect_size(struct litest_device *dev) { double width, height; int rc; if (!litest_has_palm_detect_size(dev)) return false; rc = libinput_device_get_size(dev->libinput_device, &width, &height); return rc == 0 && height > 55; } START_TEST(touchpad_palm_detect_at_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 50); litest_touch_move_to(dev, 0, 5, 50, 5, 70, 5); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_at_top) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_top_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 20, 1); litest_touch_move_to(dev, 0, 20, 1, 70, 1, 15); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_no_palm_detect_at_edge_for_edge_scrolling) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_edge_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); litest_touch_move_to(dev, 0, 99, 50, 99, 70, 5); litest_touch_up(dev, 0); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_palm_detect_at_bottom_corners) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); /* Run for non-clickpads only: make sure the bottom corners trigger palm detection too */ litest_drain_events(li); litest_touch_down(dev, 0, 99, 95); litest_touch_move_to(dev, 0, 99, 95, 99, 99, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 95); litest_touch_move_to(dev, 0, 5, 95, 5, 99, 5); litest_touch_up(dev, 0); } END_TEST START_TEST(touchpad_palm_detect_at_top_corners) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); /* Run for non-clickpads only: make sure the bottom corners trigger palm detection too */ litest_drain_events(li); litest_touch_down(dev, 0, 99, 5); litest_touch_move_to(dev, 0, 99, 5, 99, 9, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 5); litest_touch_move_to(dev, 0, 5, 5, 5, 9, 5); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_palm_stays_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 99, 20); litest_touch_move_to(dev, 0, 99, 20, 75, 99, 20); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_top_palm_stays_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_top_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 20, 1); litest_touch_move_to(dev, 0, 20, 1, 50, 30, 20); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_palm_becomes_pointer) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); litest_touch_move_to(dev, 0, 99, 50, 0, 70, 25); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_top_palm_becomes_pointer) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_top_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 1); litest_touch_move_to(dev, 0, 50, 1, 50, 60, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_no_palm_moving_into_edges) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); /* moving non-palm into the edge does not label it as palm */ litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 99, 50, 15); litest_drain_events(li); litest_touch_move_to(dev, 0, 99, 50, 99, 90, 15); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_no_palm_moving_into_top) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_top_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); /* moving non-palm into the edge does not label it as palm */ litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 0, 2, 15); litest_drain_events(li); litest_touch_move_to(dev, 0, 0, 2, 50, 50, 15); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_no_tap_top_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_top_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_tap_hardbuttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 95, 5); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 5); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 95, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_tap_softbuttons) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_buttonareas(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Two touches in the software button area, but inside * the palm detection edge zone -> expect palm detection */ litest_touch_down(dev, 0, 99, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 1, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); /* Two touches in the software button area, but * not in the palm detection edge zone -> expect taps */ litest_touch_down(dev, 0, 10, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 90, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_tap_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_clickfinger(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Taps in each of the 4 corners of the touchpad, all * inside the palm detection edge zone*/ litest_touch_down(dev, 0, 95, 5); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 5); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 5, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 95, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_no_palm_detect_2fg_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); /* first finger is palm, second finger isn't so we trigger 2fg * scrolling */ litest_touch_down(dev, 0, 99, 50); litest_touch_move_to(dev, 0, 99, 50, 99, 40, 45); litest_touch_move_to(dev, 0, 99, 40, 99, 50, 45); litest_assert_empty_queue(li); litest_touch_down(dev, 1, 50, 50); litest_assert_empty_queue(li); litest_touch_move_two_touches(dev, 99, 50, 50, 50, 0, -20, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_palm_detect_both_edges) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); /* two fingers moving up/down in the left/right palm zone must not * generate events */ litest_touch_down(dev, 0, 99, 50); litest_touch_move_to(dev, 0, 99, 50, 99, 40, 10); litest_touch_move_to(dev, 0, 99, 40, 99, 50, 10); litest_assert_empty_queue(li); /* This set generates events */ litest_touch_down(dev, 1, 1, 50); litest_touch_move_to(dev, 1, 1, 50, 1, 40, 10); litest_touch_move_to(dev, 1, 1, 40, 1, 50, 10); litest_assert_empty_queue(li); litest_touch_move_two_touches(dev, 99, 50, 1, 50, 0, -20, 10); litest_assert_empty_queue(li); } END_TEST static inline bool touchpad_has_tool_palm(struct litest_device *dev) { return libevdev_has_event_code(dev->evdev, EV_ABS, ABS_MT_TOOL_TYPE); } START_TEST(touchpad_palm_detect_tool_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_tool_palm_on_off) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_drain_events(li); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_move_to(dev, 0, 70, 70, 50, 40, 10); litest_assert_empty_queue(li); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_touch_move_to(dev, 0, 50, 40, 70, 70, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_palm_detect_tool_palm_tap_after) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_push_event_frame(dev); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); litest_touch_down(dev, 0, 50, 50); litest_pop_event_frame(dev); litest_dispatch(li); litest_touch_move_to(dev, 0, 50, 50, 50, 80, 10); litest_dispatch(li); litest_assert_empty_queue(li); litest_push_event_frame(dev); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); litest_touch_up(dev, 0); litest_pop_event_frame(dev); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_tool_palm_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!touchpad_has_tool_palm(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_push_event_frame(dev); litest_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); litest_touch_down(dev, 0, 50, 50); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); } END_TEST static inline bool touchpad_has_palm_pressure(struct litest_device *dev) { struct libevdev *evdev = dev->evdev; if (dev->which == LITEST_SYNAPTICS_PRESSUREPAD) return false; if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) return libevdev_get_abs_resolution(evdev, ABS_MT_PRESSURE) == 0; return false; } START_TEST(touchpad_palm_detect_pressure) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 99, axes); litest_touch_move_to(dev, 0, 50, 50, 80, 99, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_pressure_late_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_clickfinger(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* event after touch down is palm */ litest_touch_down(dev, 0, 50, 80); litest_touch_move_extended(dev, 0, 51, 99, axes); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_empty_queue(li); /* make sure normal tap still works */ litest_touch_down(dev, 0, 50, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); } END_TEST START_TEST(touchpad_palm_detect_pressure_tap_hold) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_clickfinger(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* event in state HOLD is thumb */ litest_touch_down(dev, 0, 50, 99); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_extended(dev, 0, 51, 99, axes); litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* make sure normal tap still works */ litest_touch_down(dev, 0, 50, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); } END_TEST START_TEST(touchpad_palm_detect_pressure_tap_hold_2ndfg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_enable_clickfinger(dev); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* event in state HOLD is thumb */ litest_touch_down(dev, 0, 50, 99); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_extended(dev, 0, 51, 99, axes); litest_assert_empty_queue(li); /* one finger is a thumb, now get second finger down */ litest_touch_down(dev, 1, 60, 50); litest_assert_empty_queue(li); /* release thumb */ litest_touch_up(dev, 0); litest_assert_empty_queue(li); /* timeout -> into HOLD, no event on release */ litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_up(dev, 1); litest_assert_empty_queue(li); /* make sure normal tap still works */ litest_touch_down(dev, 0, 50, 99); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); } END_TEST START_TEST(touchpad_palm_detect_move_and_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* trigger thumb detection by pressure after a slight movement */ litest_touch_down(dev, 0, 50, 99); litest_touch_move(dev, 0, 51, 99); litest_touch_move_extended(dev, 0, 55, 99, axes); litest_dispatch(li); litest_assert_empty_queue(li); /* thumb is resting, check if tapping still works */ litest_touch_down(dev, 1, 50, 50); litest_touch_up(dev, 1); litest_dispatch(li); litest_timeout_tap(); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_pressure_late) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10); litest_drain_events(li); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_pressure_keep_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 80, 90); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_pressure_after_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev) || !litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 99, 50); litest_touch_move_to_extended(dev, 0, 99, 50, 20, 50, axes, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_pressure_after_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_drain_events(li); /* within dwt timeout, dwt blocks events */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to_extended(touchpad, 0, 50, 50, 20, 50, axes, 20); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_dispatch(li); litest_assert_empty_queue(li); /* after dwt timeout, pressure blocks events */ litest_touch_move_to_extended(touchpad, 0, 20, 50, 50, 50, axes, 20); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_palm_ignore_threshold_zero) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 99, axes); litest_touch_move_to(dev, 0, 50, 50, 80, 99, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_palm_clickfinger_pressure) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 95, axes); litest_touch_down(dev, 1, 50, 50); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_clickfinger_pressure_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; if (!touchpad_has_palm_pressure(dev)) return LITEST_NOT_APPLICABLE; if (libevdev_get_num_slots(dev->evdev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 95, axes); litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 50, 60); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST static inline bool touchpad_has_touch_size(struct litest_device *dev) { struct libevdev *evdev = dev->evdev; if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOUCH_MAJOR)) return false; if (libevdev_get_id_vendor(evdev) == VENDOR_ID_APPLE) return true; return false; } START_TEST(touchpad_palm_clickfinger_size) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { ABS_MT_ORIENTATION, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev)) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 95, axes); litest_touch_down(dev, 1, 50, 50); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_clickfinger_size_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { ABS_MT_ORIENTATION, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev)) return LITEST_NOT_APPLICABLE; if (libevdev_get_num_slots(dev->evdev) < 3) return LITEST_NOT_APPLICABLE; litest_enable_clickfinger(dev); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 95, axes); litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 50, 60); litest_button_click(dev, BTN_LEFT, true); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_left_handed) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE && libevdev_get_id_product(dev->evdev) == PRODUCT_ID_APPLE_APPLETOUCH) return LITEST_NOT_APPLICABLE; status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_button_click(dev, BTN_RIGHT, 1); litest_button_click(dev, BTN_RIGHT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); if (libevdev_has_event_code(dev->evdev, EV_KEY, BTN_MIDDLE)) { litest_button_click(dev, BTN_MIDDLE, 1); litest_button_click(dev, BTN_MIDDLE, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } } END_TEST START_TEST(touchpad_left_handed_appletouch) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; enum libinput_config_status status; litest_assert_int_eq(libinput_device_config_left_handed_is_available(d), 0); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); litest_assert_int_eq(libinput_device_config_left_handed_get(d), 0); } END_TEST START_TEST(touchpad_left_handed_clickpad) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 10, 90); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_drain_events(li); litest_touch_down(dev, 0, 90, 90); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_left_handed_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 10, 90); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); /* Clickfinger is unaffected by left-handed setting */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_drain_events(li); litest_touch_down(dev, 0, 10, 90); litest_touch_down(dev, 1, 30, 90); litest_button_click(dev, BTN_LEFT, 1); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_left_handed_tapping) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); /* Tapping is unaffected by left-handed setting */ litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_left_handed_tapping_2fg) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); /* Tapping is unaffected by left-handed setting */ litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_left_handed_delayed) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_button_click(dev, BTN_LEFT, 1); litest_dispatch(li); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_button_click(dev, BTN_LEFT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); /* left-handed takes effect now */ litest_button_click(dev, BTN_RIGHT, 1); litest_dispatch(li); litest_timeout_middlebutton(); litest_dispatch(li); litest_button_click(dev, BTN_LEFT, 1); litest_dispatch(li); status = libinput_device_config_left_handed_set(d, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_button_click(dev, BTN_RIGHT, 0); litest_button_click(dev, BTN_LEFT, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_left_handed_clickpad_delayed) { struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 10, 90); litest_button_click(dev, BTN_LEFT, 1); litest_dispatch(li); status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); /* left-handed takes effect now */ litest_drain_events(li); litest_touch_down(dev, 0, 90, 90); litest_button_click(dev, BTN_LEFT, 1); litest_dispatch(li); status = libinput_device_config_left_handed_set(d, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_button_click(dev, BTN_LEFT, 0); litest_touch_up(dev, 0); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST #if HAVE_LIBWACOM static inline bool touchpad_has_rotation(struct libevdev *evdev) { return libevdev_get_id_vendor(evdev) == VENDOR_ID_WACOM; } #endif /* HAVE_LIBWACOM */ START_TEST(touchpad_left_handed_rotation) { #if HAVE_LIBWACOM struct litest_device *dev = litest_current_device(); struct libinput_device *d = dev->libinput_device; struct libinput *li = dev->libinput; enum libinput_config_status status; struct libinput_event *event; bool rotate = touchpad_has_rotation(dev->evdev); if (!libinput_device_config_left_handed_is_available(d)) return LITEST_NOT_APPLICABLE; status = libinput_device_config_left_handed_set(d, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_touch_down(dev, 0, 20, 80); litest_touch_move_to(dev, 0, 20, 80, 80, 20, 20); litest_touch_up(dev, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); do { struct libinput_event_pointer *p; double x, y, ux, uy; p = litest_is_motion_event(event); x = libinput_event_pointer_get_dx(p); y = libinput_event_pointer_get_dy(p); ux = libinput_event_pointer_get_dx_unaccelerated(p); uy = libinput_event_pointer_get_dy_unaccelerated(p); if (rotate) { litest_assert_double_lt(x, 0); litest_assert_double_gt(y, 0); litest_assert_double_lt(ux, 0); litest_assert_double_gt(uy, 0); } else { litest_assert_double_gt(x, 0); litest_assert_double_lt(y, 0); litest_assert_double_gt(ux, 0); litest_assert_double_lt(uy, 0); } libinput_event_destroy(event); } while ((event = libinput_get_event(li))); #endif } END_TEST static void hover_continue(struct litest_device *dev, unsigned int slot, int x, int y) { litest_event(dev, EV_ABS, ABS_MT_SLOT, slot); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_ABS, ABS_PRESSURE, 10); litest_event(dev, EV_ABS, ABS_TOOL_WIDTH, 6); /* WARNING: no SYN_REPORT! */ } static void hover_start(struct litest_device *dev, unsigned int slot, int x, int y) { static unsigned int tracking_id; litest_event(dev, EV_ABS, ABS_MT_SLOT, slot); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, ++tracking_id); hover_continue(dev, slot, x, y); /* WARNING: no SYN_REPORT! */ } START_TEST(touchpad_semi_mt_hover_noevent) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; int x = 2400, y = 2400; litest_drain_events(li); hover_start(dev, 0, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (i = 0; i < 10; i++) { x += 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_semi_mt_hover_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int i; int x = 2400, y = 2400; litest_drain_events(li); hover_start(dev, 0, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (i = 0; i < 10; i++) { x += 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_empty_queue(li); litest_event(dev, EV_ABS, ABS_X, x + 100); litest_event(dev, EV_ABS, ABS_Y, y + 100); litest_event(dev, EV_ABS, ABS_PRESSURE, 50); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); for (i = 0; i < 10; i++) { x -= 200; y += 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); litest_wait_for_event(li); while ((event = libinput_get_event(li)) != NULL) { litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION); libinput_event_destroy(event); litest_dispatch(li); } /* go back to hover */ hover_continue(dev, 0, x, y); litest_event(dev, EV_ABS, ABS_PRESSURE, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (i = 0; i < 10; i++) { x += 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_semi_mt_hover_down_hover_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i, j; int x = 1400, y = 1400; litest_drain_events(li); /* hover */ hover_start(dev, 0, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); for (i = 0; i < 3; i++) { /* touch */ litest_event(dev, EV_ABS, ABS_X, x + 100); litest_event(dev, EV_ABS, ABS_Y, y + 100); litest_event(dev, EV_ABS, ABS_PRESSURE, 50); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); for (j = 0; j < 5; j++) { x += 200; y += 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* go back to hover */ hover_continue(dev, 0, x, y); litest_event(dev, EV_ABS, ABS_PRESSURE, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (j = 0; j < 5; j++) { x -= 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_assert_empty_queue(li); } /* touch */ litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); /* start a new touch to be sure */ litest_push_event_frame(dev); litest_touch_down(dev, 0, 50, 50); litest_event(dev, EV_ABS, ABS_PRESSURE, 50); litest_pop_event_frame(dev); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_semi_mt_hover_down_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; int x = 1400, y = 1400; litest_drain_events(li); /* hover two fingers, then touch */ hover_start(dev, 0, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); hover_start(dev, 1, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); /* hover first finger, end second in same frame */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_ABS, ABS_PRESSURE, 50); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* now move the finger */ for (i = 0; i < 10; i++) { litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); x -= 100; y -= 100; } litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } END_TEST START_TEST(touchpad_semi_mt_hover_2fg_noevent) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; int x = 2400, y = 2400; litest_drain_events(li); hover_start(dev, 0, x, y); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); hover_start(dev, 1, x + 500, y + 500); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (i = 0; i < 10; i++) { x += 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x + 500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y + 500); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_semi_mt_hover_2fg_1fg_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; int x = 2400, y = 2400; litest_drain_events(li); /* two slots active, but BTN_TOOL_FINGER only */ hover_start(dev, 0, x, y); hover_start(dev, 1, x + 500, y + 500); litest_event(dev, EV_ABS, ABS_PRESSURE, 50); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); for (i = 0; i < 10; i++) { x += 200; y -= 200; litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, x + 500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, y + 500); litest_event(dev, EV_ABS, ABS_X, x); litest_event(dev, EV_ABS, ABS_Y, y); litest_event(dev, EV_SYN, SYN_REPORT, 0); } litest_event(dev, EV_ABS, ABS_PRESSURE, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_semi_mt_hover_2fg_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_touch_down(dev, 0, 70, 50); litest_touch_down(dev, 1, 50, 50); litest_push_event_frame(dev); litest_touch_move(dev, 0, 72, 50); litest_touch_move(dev, 1, 52, 50); litest_event(dev, EV_ABS, ABS_PRESSURE, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_pop_event_frame(dev); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); } END_TEST START_TEST(touchpad_hover_noevent) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_hover_start(dev, 0, 50, 50); litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10); litest_hover_end(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_hover_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* hover the finger */ litest_hover_start(dev, 0, 50, 50); litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10); litest_assert_empty_queue(li); /* touch the finger on the sensor */ litest_touch_move_to(dev, 0, 70, 70, 50, 50, 10); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* go back to hover */ litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10); litest_hover_end(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_hover_down_hover_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; litest_drain_events(li); litest_hover_start(dev, 0, 50, 50); for (i = 0; i < 3; i++) { /* hover the finger */ litest_hover_move_to(dev, 0, 50, 50, 70, 70, 10); litest_assert_empty_queue(li); /* touch the finger */ litest_touch_move_to(dev, 0, 70, 70, 50, 50, 10); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } litest_hover_end(dev, 0); /* start a new touch to be sure */ litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_hover_down_up) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* hover two fingers, and a touch */ litest_push_event_frame(dev); litest_hover_start(dev, 0, 50, 50); litest_hover_start(dev, 1, 50, 50); litest_touch_down(dev, 2, 50, 50); litest_pop_event_frame(dev); litest_assert_empty_queue(li); /* hover first finger, end second and third in same frame */ litest_push_event_frame(dev); litest_hover_move(dev, 0, 55, 55); litest_hover_end(dev, 1); litest_touch_up(dev, 2); litest_pop_event_frame(dev); litest_assert_empty_queue(li); /* now move the finger */ litest_touch_move_to(dev, 0, 50, 50, 70, 70, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_hover_2fg_noevent) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); /* hover two fingers */ litest_push_event_frame(dev); litest_hover_start(dev, 0, 25, 25); litest_hover_start(dev, 1, 50, 50); litest_pop_event_frame(dev); litest_hover_move_two_touches(dev, 25, 25, 50, 50, 50, 50, 10); litest_push_event_frame(dev); litest_hover_end(dev, 0); litest_hover_end(dev, 1); litest_pop_event_frame(dev); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_hover_2fg_1fg_down) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int i; litest_drain_events(li); /* hover two fingers */ litest_push_event_frame(dev); litest_hover_start(dev, 0, 25, 25); litest_touch_down(dev, 1, 50, 50); litest_pop_event_frame(dev); for (i = 0; i < 10; i++) { litest_push_event_frame(dev); litest_hover_move(dev, 0, 25 + 5 * i, 25 + 5 * i); litest_touch_move(dev, 1, 50 + 5 * i, 50 - 5 * i); litest_pop_event_frame(dev); } litest_push_event_frame(dev); litest_hover_end(dev, 0); litest_touch_up(dev, 1); litest_pop_event_frame(dev); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_hover_1fg_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_hover_start(dev, 0, 50, 50); litest_hover_end(dev, 0); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST static void assert_btnevent_from_device(struct litest_device *device, unsigned int button, enum libinput_button_state state) { struct libinput *li = device->libinput; struct libinput_event *e; litest_dispatch(li); e = libinput_get_event(li); litest_is_button_event(e, button, state); litest_assert_ptr_eq(libinput_event_get_device(e), device->libinput_device); libinput_event_destroy(e); } START_TEST(touchpad_trackpoint_buttons) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; const struct buttons { unsigned int device_value; unsigned int real_value; } buttons[] = { { BTN_0, BTN_LEFT }, { BTN_1, BTN_RIGHT }, { BTN_2, BTN_MIDDLE }, }; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); libinput_device_config_scroll_set_method(trackpoint->libinput_device, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); litest_drain_events(li); ARRAY_FOR_EACH(buttons, b) { litest_button_click_debounced(touchpad, li, b->device_value, true); assert_btnevent_from_device(trackpoint, b->real_value, LIBINPUT_BUTTON_STATE_PRESSED); litest_button_click_debounced(touchpad, li, b->device_value, false); assert_btnevent_from_device(trackpoint, b->real_value, LIBINPUT_BUTTON_STATE_RELEASED); } litest_delete_device(trackpoint); } END_TEST START_TEST(touchpad_trackpoint_mb_scroll) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); litest_button_click(touchpad, BTN_2, true); /* middle */ litest_dispatch(li); litest_timeout_buttonscroll(); litest_dispatch(li); litest_event(trackpoint, EV_REL, REL_Y, -2); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -2); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -2); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_event(trackpoint, EV_REL, REL_Y, -2); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_button_click(touchpad, BTN_2, false); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS); litest_delete_device(trackpoint); } END_TEST START_TEST(touchpad_trackpoint_mb_click) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; enum libinput_config_status status; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); status = libinput_device_config_scroll_set_method( trackpoint->libinput_device, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_drain_events(li); litest_button_click_debounced(touchpad, li, BTN_2, true); /* middle */ litest_button_click_debounced(touchpad, li, BTN_2, false); assert_btnevent_from_device(trackpoint, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); assert_btnevent_from_device(trackpoint, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_delete_device(trackpoint); } END_TEST START_TEST(touchpad_trackpoint_buttons_softbuttons) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); litest_touch_down(touchpad, 0, 95, 90); litest_button_click_debounced(touchpad, li, BTN_LEFT, true); litest_button_click_debounced(touchpad, li, BTN_1, true); litest_button_click_debounced(touchpad, li, BTN_LEFT, false); litest_touch_up(touchpad, 0); litest_button_click_debounced(touchpad, li, BTN_1, false); assert_btnevent_from_device(touchpad, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); assert_btnevent_from_device(touchpad, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_touch_down(touchpad, 0, 95, 90); litest_button_click_debounced(touchpad, li, BTN_LEFT, true); litest_button_click_debounced(touchpad, li, BTN_1, true); litest_button_click_debounced(touchpad, li, BTN_1, false); litest_button_click_debounced(touchpad, li, BTN_LEFT, false); litest_touch_up(touchpad, 0); assert_btnevent_from_device(touchpad, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); assert_btnevent_from_device(touchpad, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); litest_delete_device(trackpoint); } END_TEST START_TEST(touchpad_trackpoint_buttons_2fg_scroll) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; struct libinput_event *e; double val; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); litest_touch_down(touchpad, 0, 40, 70); litest_touch_down(touchpad, 1, 60, 70); litest_touch_move_two_touches(touchpad, 40, 70, 60, 70, 0, -40, 10); litest_dispatch(li); litest_wait_for_event(li); /* Make sure we get scroll events but _not_ the scroll release */ while ((e = libinput_get_event(li))) { struct libinput_event_pointer *pev; pev = litest_is_axis_event(e, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); val = litest_event_pointer_get_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert(val != 0.0); libinput_event_destroy(e); } litest_button_click_debounced(touchpad, li, BTN_1, true); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); litest_touch_move_to(touchpad, 0, 40, 30, 40, 70, 10); litest_touch_move_to(touchpad, 1, 60, 30, 60, 70, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); while ((e = libinput_get_event(li))) { struct libinput_event_pointer *pev; pev = litest_is_axis_event(e, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); val = litest_event_pointer_get_value(pev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); litest_assert(val != 0.0); libinput_event_destroy(e); } litest_button_click_debounced(touchpad, li, BTN_1, false); assert_btnevent_from_device(trackpoint, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); /* the movement lags behind the touch movement, so the first couple events can be downwards even though we started scrolling up. do a short scroll up, drain those events, then we can use litest_assert_scroll() which tests for the trailing 0/0 scroll for us. */ litest_touch_move_to(touchpad, 0, 40, 70, 40, 60, 10); litest_touch_move_to(touchpad, 1, 60, 70, 60, 60, 10); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_touch_move_to(touchpad, 0, 40, 60, 40, 30, 10); litest_touch_move_to(touchpad, 1, 60, 60, 60, 30, 10); litest_touch_up(touchpad, 0); litest_touch_up(touchpad, 1); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -1); litest_delete_device(trackpoint); } END_TEST START_TEST(touchpad_trackpoint_no_trackpoint) { struct litest_device *touchpad = litest_current_device(); struct libinput *li = touchpad->libinput; litest_drain_events(li); litest_button_click(touchpad, BTN_0, true); /* left */ litest_button_click(touchpad, BTN_0, false); litest_assert_empty_queue(li); litest_button_click(touchpad, BTN_1, true); /* right */ litest_button_click(touchpad, BTN_1, false); litest_assert_empty_queue(li); litest_button_click(touchpad, BTN_2, true); /* middle */ litest_button_click(touchpad, BTN_2, false); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_initial_state) { struct litest_device *dev; struct libinput *libinput1, *libinput2; int x = 40, y = 60; int axis = litest_test_param_get_i32(test_env->params, "axis"); dev = litest_current_device(); libinput1 = dev->libinput; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_touch_down(dev, 0, x, y); litest_touch_up(dev, 0); /* device is now on some x/y value */ litest_drain_events(libinput1); libinput2 = litest_create_context(); libinput_path_add_device(libinput2, libevdev_uinput_get_devnode(dev->uinput)); litest_drain_events(libinput2); if (axis == ABS_X) x = 30; else y = 30; litest_touch_down(dev, 0, x, y); litest_touch_move_to(dev, 0, x, y, 70, 70, 10); litest_touch_up(dev, 0); litest_dispatch(libinput1); litest_dispatch(libinput2); litest_wait_for_event(libinput1); litest_wait_for_event(libinput2); while (libinput_next_event_type(libinput1)) { struct libinput_event *ev1, *ev2; struct libinput_event_pointer *p1, *p2; ev1 = libinput_get_event(libinput1); ev2 = libinput_get_event(libinput2); p1 = litest_is_motion_event(ev1); p2 = litest_is_motion_event(ev2); litest_assert_int_eq(libinput_event_get_type(ev1), libinput_event_get_type(ev2)); litest_assert_double_eq(libinput_event_pointer_get_dx(p1), libinput_event_pointer_get_dx(p2)); litest_assert_double_eq(libinput_event_pointer_get_dy(p1), libinput_event_pointer_get_dy(p2)); libinput_event_destroy(ev1); libinput_event_destroy(ev2); } litest_destroy_context(libinput2); } END_TEST START_TEST(touchpad_fingers_down_before_init) { struct litest_device *dev = litest_current_device(); struct libinput *li; int finger_count = litest_test_param_get_i32(test_env->params, "fingers"); unsigned int map[] = {0, BTN_TOOL_PEN, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP, BTN_TOOL_QUINTTAP}; if (!libevdev_has_event_code(dev->evdev, EV_KEY, map[finger_count])) return LITEST_NOT_APPLICABLE; /* Fingers down but before we have the real context */ for (int i = 0; i < finger_count; i++) { if (litest_slot_count(dev) >= finger_count) { litest_touch_down(dev, i, 20 + 10 * i, 30); } else { litest_event(dev, EV_KEY, map[finger_count], 1); } } litest_drain_events(dev->libinput); /* create anew context that already has the fingers down */ li = litest_create_context(); libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_drain_events(li); for (int x = 0; x < 10; x++) { for (int i = 0; i < finger_count; i++) { if (litest_slot_count(dev) < finger_count) break; litest_touch_move(dev, i, 20 + 10 * i + x, 30); } litest_dispatch(li); } litest_dispatch(li); litest_assert_empty_queue(li); for (int i = 0; i < finger_count; i++) { if (litest_slot_count(dev) >= finger_count) { litest_touch_up(dev, i); } else { litest_event(dev, EV_KEY, map[finger_count], 0); } litest_dispatch(li); } litest_assert_empty_queue(li); litest_destroy_context(li); } END_TEST /* This just tests that we don't completely screw up in one specific case. * The test likely needs to be removed if it starts failing in the future. * * Where we get touch releases during SYN_DROPPED, libevdev < 1.9.0 gives us * wrong event sequence during sync, see * https://gitlab.freedesktop.org/libevdev/libevdev/merge_requests/19 * * libinput 1.15.1 ended up dropping our slot count to 0, making the * touchpad unusable, see #422. This test just checks that we can still move * the pointer and scroll where we trigger such a sequence. This tests for * the worst-case scenario - where we previously reset to a slot count of 0. * * However, the exact behavior depends on how many slots were * stopped/restarted during SYN_DROPPED, a single test is barely useful. * libinput will still do the wrong thing if you start with e.g. 3fg on the * touchpad and release one or two of them. But since this needs to be fixed * in libevdev, here is the most important test. */ START_TEST(touchpad_state_after_syn_dropped_2fg_change) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_touch_down(dev, 0, 10, 10); litest_dispatch(li); /* Force a SYN_DROPPED */ for (int i = 0; i < 500; i++) litest_touch_move(dev, 0, 10 + 0.1 * i, 10 + 0.1 * i); /* still within SYN_DROPPED */ litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_dispatch(li); litest_drain_events(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); /* 2fg scrolling still works? */ litest_touch_down(dev, 0, 50, 50); litest_touch_down(dev, 1, 70, 50); litest_touch_move_two_touches(dev, 50, 50, 70, 50, 0, -20, 10); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); /* pointer motion still works? */ litest_touch_down(dev, 0, 50, 50); for (int i = 0; i < 10; i++) litest_touch_move(dev, 0, 10 + 0.1 * i, 10 + 0.1 * i); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_short(); litest_dispatch(li); /* after timeout - motion events*/ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_ext_and_int_keyboard) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard, *yubikey; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); /* Yubikey is initialized first */ yubikey = litest_add_device(li, LITEST_YUBIKEY); litest_drain_events(li); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_short(); litest_dispatch(li); /* after timeout - motion events*/ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); litest_delete_device(yubikey); } END_TEST START_TEST(touchpad_dwt_enable_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* finger down after last key event, but we're still within timeout - no events */ msleep(10); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_dispatch(li); /* same touch after timeout - motion events*/ litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_touch_hold) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); msleep(1); /* make sure touch starts after key press */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* touch still down - no events */ litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_touch_move_to(touchpad, 0, 70, 50, 30, 50, 5); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* touch still down - no events */ litest_timeout_dwt_short(); litest_dispatch(li); litest_touch_move_to(touchpad, 0, 30, 50, 50, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_key_hold) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_key_hold_timeout) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_long(); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* key is up, but still within timeout */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); /* expire timeout */ litest_timeout_dwt_long(); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_key_hold_timeout_existing_touch_cornercase) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; /* Note: this tests for the current behavior of a cornercase, and * the behaviour is essentially a bug. If this test fails it may be * because the buggy behavior was fixed. */ keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_long(); litest_dispatch(li); /* Touch starting after re-issuing the dwt timeout */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_assert_empty_queue(li); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* key is up, but still within timeout */ litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5); litest_assert_empty_queue(li); /* Expire dwt timeout. Because the touch started after re-issuing * the last timeout, it looks like the touch started after the last * key press. Such touches are enabled for pointer motion by * libinput when dwt expires. * This is buggy behavior and not what a user would typically * expect. But it's hard to trigger in real life too. */ litest_timeout_dwt_long(); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); /* If the below check for motion event fails because no events are * in the pipe, the buggy behavior was fixed and this test case * can be removed */ litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_key_hold_timeout_existing_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_dispatch(li); litest_timeout_dwt_long(); litest_dispatch(li); litest_assert_empty_queue(li); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* key is up, but still within timeout */ litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5); litest_assert_empty_queue(li); /* expire timeout, but touch started before release */ litest_timeout_dwt_long(); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_type) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; int i; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (i = 0; i < 5; i++) { litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_long(); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_type_short_timeout) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; int i; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (i = 0; i < 5; i++) { litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); } litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_modifier_no_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int modifiers[] = { KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTSHIFT, KEY_RIGHTSHIFT, KEY_FN, KEY_CAPSLOCK, KEY_TAB, KEY_COMPOSE, KEY_RIGHTMETA, KEY_LEFTMETA, KEY_ESC, KEY_KPASTERISK, KEY_F1, }; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); ARRAY_FOR_EACH(modifiers, key) { litest_keyboard_key(keyboard, *key, true); litest_keyboard_key(keyboard, *key, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_shift_combo_triggers_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int modifiers[] = { KEY_LEFTSHIFT, KEY_RIGHTSHIFT, }; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); ARRAY_FOR_EACH(modifiers, key) { litest_keyboard_key(keyboard, *key, true); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, *key, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); } litest_timeout_dwt_long(); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_modifier_combo_no_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int modifiers[] = { KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTALT, KEY_RIGHTALT, KEY_FN, KEY_CAPSLOCK, KEY_TAB, KEY_COMPOSE, KEY_RIGHTMETA, KEY_LEFTMETA, }; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); ARRAY_FOR_EACH(modifiers, key) { litest_keyboard_key(keyboard, *key, true); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, KEY_B, true); litest_keyboard_key(keyboard, KEY_B, false); litest_keyboard_key(keyboard, *key, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_modifier_combo_dwt_after) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int modifiers[] = { KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTALT, KEY_RIGHTALT, KEY_FN, KEY_CAPSLOCK, KEY_TAB, KEY_COMPOSE, KEY_RIGHTMETA, KEY_LEFTMETA, }; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); ARRAY_FOR_EACH(modifiers, key) { litest_keyboard_key(keyboard, *key, true); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, *key, false); litest_dispatch(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_long(); litest_dispatch(li); } litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_modifier_combo_dwt_remains) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int modifiers[] = { KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTALT, KEY_RIGHTALT, KEY_FN, KEY_CAPSLOCK, KEY_TAB, KEY_COMPOSE, KEY_RIGHTMETA, KEY_LEFTMETA, }; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); ARRAY_FOR_EACH(modifiers, key) { litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); /* this can't really be tested directly. The above key * should enable dwt, the next key continues and extends the * timeout as usual (despite the modifier combo). but * testing for timeout differences is fickle, so all we can * test though is that dwt is still on after the modifier * combo and does not get disabled immediately. */ litest_keyboard_key(keyboard, *key, true); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, *key, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_long(); litest_dispatch(li); } litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_fkeys_no_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; unsigned int key; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (key = KEY_F1; key < KEY_CNT; key++) { if (!libinput_device_keyboard_has_key(keyboard->libinput_device, key)) continue; litest_keyboard_key(keyboard, key, true); litest_keyboard_key(keyboard, key, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_tap) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_enable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_short(); litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_tap_drag) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_enable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_dispatch(li); msleep(1); /* make sure touch starts after key press */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_up(touchpad, 0); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_short(); litest_dispatch(li); litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_click) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_button_click(touchpad, BTN_LEFT, true); litest_button_click(touchpad, BTN_LEFT, false); litest_dispatch(li); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_edge_scroll) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; litest_enable_edge_scroll(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 99, 20); litest_dispatch(li); litest_timeout_edgescroll(); litest_dispatch(li); litest_assert_empty_queue(li); /* edge scroll timeout is 300ms atm, make sure we don't accidentally exit the DWT timeout */ litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60); litest_dispatch(li); litest_assert_empty_queue(li); litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_edge_scroll_interrupt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; litest_enable_edge_scroll(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_touch_down(touchpad, 0, 99, 20); litest_dispatch(li); litest_timeout_edgescroll(); litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10); litest_dispatch(li); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); /* scroll stop events (low and high resolution) */ litest_wait_for_event(li); litest_assert_axis_end_sequence(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SOURCE_FINGER); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_timeout_dwt_long(); /* Known bad behavior: a touch starting to edge-scroll before dwt * kicks in will stop to scroll but be recognized as normal * pointer-moving touch once the timeout expires. We'll fix that * when we need to. */ litest_touch_move_to(touchpad, 0, 99, 30, 99, 80, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_config_default_on) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_dwt_state state; if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM || libevdev_get_id_bustype(dev->evdev) == BUS_BLUETOOTH) { litest_assert(!libinput_device_config_dwt_is_available(device)); return LITEST_NOT_APPLICABLE; } litest_assert(libinput_device_config_dwt_is_available(device)); state = libinput_device_config_dwt_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWT_ENABLED); state = libinput_device_config_dwt_get_default_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWT_ENABLED); status = libinput_device_config_dwt_set_enabled(device, LIBINPUT_CONFIG_DWT_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwt_set_enabled(device, LIBINPUT_CONFIG_DWT_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwt_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_dwtp_config_default_on) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_dwtp_state state; if (litest_touchpad_is_external(dev)) { litest_assert(!libinput_device_config_dwtp_is_available(device)); return LITEST_NOT_APPLICABLE; } litest_assert(libinput_device_config_dwtp_is_available(device)); state = libinput_device_config_dwtp_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWTP_ENABLED); state = libinput_device_config_dwtp_get_default_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWTP_ENABLED); status = libinput_device_config_dwtp_set_enabled(device, LIBINPUT_CONFIG_DWTP_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwtp_set_enabled(device, LIBINPUT_CONFIG_DWTP_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwtp_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_dwt_config_default_off) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_dwt_state state; litest_assert(!libinput_device_config_dwt_is_available(device)); state = libinput_device_config_dwt_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWT_DISABLED); state = libinput_device_config_dwt_get_default_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWT_DISABLED); status = libinput_device_config_dwt_set_enabled(device, LIBINPUT_CONFIG_DWT_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_dwt_set_enabled(device, LIBINPUT_CONFIG_DWT_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwt_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(touchpad_dwtp_config_default_off) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; enum libinput_config_dwtp_state state; litest_assert(!libinput_device_config_dwtp_is_available(device)); state = libinput_device_config_dwtp_get_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWTP_DISABLED); state = libinput_device_config_dwtp_get_default_enabled(device); litest_assert_enum_eq(state, LIBINPUT_CONFIG_DWTP_DISABLED); status = libinput_device_config_dwtp_set_enabled(device, LIBINPUT_CONFIG_DWTP_ENABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); status = libinput_device_config_dwtp_set_enabled(device, LIBINPUT_CONFIG_DWTP_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_dwtp_set_enabled(device, 3); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST static inline void disable_dwt(struct litest_device *dev) { enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_dwt_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_DWT_DISABLED); litest_assert_int_eq(status, expected); } static inline void enable_dwt(struct litest_device *dev) { enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_dwt_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_DWT_ENABLED); litest_assert_int_eq(status, expected); } START_TEST(touchpad_dwt_disabled) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; disable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_disable_during_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; enable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_touch_down(touchpad, 0, 50, 50); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_empty_queue(li); litest_timeout_dwt_long(); litest_dispatch(li); disable_dwt(touchpad); /* touch already down -> keeps being ignored */ litest_touch_move_to(touchpad, 0, 70, 50, 50, 70, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_disable_before_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; enable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); disable_dwt(touchpad); litest_dispatch(li); /* touch down during timeout -> still discarded */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_disable_during_key_release) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; enable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); disable_dwt(touchpad); litest_dispatch(li); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); /* touch down during timeout, wait, should generate events */ litest_touch_down(touchpad, 0, 50, 50); litest_dispatch(li); litest_timeout_dwt_long(); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_disable_during_key_hold) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; enable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); disable_dwt(touchpad); litest_dispatch(li); /* touch down during timeout, wait, should generate events */ litest_touch_down(touchpad, 0, 50, 50); litest_dispatch(li); litest_timeout_dwt_long(); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_enable_during_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; disable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); enable_dwt(touchpad); /* touch already down -> still sends events */ litest_touch_move_to(touchpad, 0, 70, 50, 50, 70, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_enable_before_touch) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; disable_dwt(touchpad); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_disable_tap(touchpad->libinput_device); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); enable_dwt(touchpad); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_enable_during_tap) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; litest_enable_tap(touchpad->libinput_device); disable_dwt(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_dispatch(li); enable_dwt(touchpad); litest_dispatch(li); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_timeout_tap(); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_BUTTON); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_dwt_remove_kbd_while_active) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; if (!has_disable_while_typing(touchpad)) return LITEST_NOT_APPLICABLE; litest_enable_tap(touchpad->libinput_device); enable_dwt(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_dispatch(li); litest_touch_down(touchpad, 0, 50, 50); litest_dispatch(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_drain_events(li); litest_delete_device(keyboard); litest_drain_events(li); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_dwt_apple) { struct litest_device *touchpad = litest_current_device(); struct litest_device *apple_keyboard; struct libinput *li = touchpad->libinput; litest_assert(has_disable_while_typing(touchpad)); apple_keyboard = litest_add_device(li, LITEST_APPLE_KEYBOARD); litest_drain_events(li); litest_keyboard_key(apple_keyboard, KEY_A, true); litest_keyboard_key(apple_keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(apple_keyboard); } END_TEST START_TEST(touchpad_dwt_acer_hawaii) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard, *hawaii_keyboard; struct libinput *li = touchpad->libinput; litest_assert(has_disable_while_typing(touchpad)); /* Only the hawaii keyboard can trigger DWT */ keyboard = litest_add_device(li, LITEST_KEYBOARD); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); hawaii_keyboard = litest_add_device(li, LITEST_ACER_HAWAII_KEYBOARD); litest_drain_events(li); litest_keyboard_key(hawaii_keyboard, KEY_A, true); litest_keyboard_key(hawaii_keyboard, KEY_A, false); litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_dispatch(li); litest_assert_empty_queue(li); litest_delete_device(keyboard); litest_delete_device(hawaii_keyboard); } END_TEST START_TEST(touchpad_dwt_multiple_keyboards) { struct litest_device *touchpad = litest_current_device(); struct litest_device *k1, *k2; struct libinput *li = touchpad->libinput; litest_assert(has_disable_while_typing(touchpad)); enable_dwt(touchpad); k1 = litest_add_device(li, LITEST_KEYBOARD); k2 = litest_add_device(li, LITEST_KEYBOARD); litest_keyboard_key(k1, KEY_A, true); litest_keyboard_key(k1, KEY_A, false); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_keyboard_key(k2, KEY_A, true); litest_keyboard_key(k2, KEY_A, false); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_delete_device(k1); litest_delete_device(k2); } END_TEST START_TEST(touchpad_dwt_remove_before_keyboard) { struct litest_device *keyboard = litest_current_device(); struct litest_device *touchpad; struct libinput *li = keyboard->libinput; touchpad = litest_add_device(li, LITEST_SYNAPTICS_RMI4); litest_assert(has_disable_while_typing(touchpad)); litest_dispatch(li); /* remove the touchpad before the keyboard. * this test can fail in valgrind only */ litest_delete_device(touchpad); } END_TEST START_TEST(touchpad_dwt_multiple_keyboards_bothkeys) { struct litest_device *touchpad = litest_current_device(); struct litest_device *k1, *k2; struct libinput *li = touchpad->libinput; litest_assert(has_disable_while_typing(touchpad)); enable_dwt(touchpad); k1 = litest_add_device(li, LITEST_KEYBOARD); k2 = litest_add_device(li, LITEST_KEYBOARD); litest_keyboard_key(k1, KEY_A, true); litest_keyboard_key(k1, KEY_A, false); litest_keyboard_key(k2, KEY_B, true); litest_keyboard_key(k2, KEY_B, false); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(k1); litest_delete_device(k2); } END_TEST START_TEST(touchpad_dwt_multiple_keyboards_bothkeys_modifier) { struct litest_device *touchpad = litest_current_device(); struct litest_device *k1, *k2; struct libinput *li = touchpad->libinput; litest_assert(has_disable_while_typing(touchpad)); enable_dwt(touchpad); k1 = litest_add_device(li, LITEST_KEYBOARD); k2 = litest_add_device(li, LITEST_KEYBOARD); litest_keyboard_key(k1, KEY_RIGHTCTRL, true); litest_keyboard_key(k1, KEY_RIGHTCTRL, false); litest_keyboard_key(k2, KEY_B, true); litest_keyboard_key(k2, KEY_B, false); litest_drain_events(li); /* If the keyboard is a single physical device, the above should * trigger the modifier behavior for dwt. But libinput views it as * two separate devices and this is such a niche case that it * doesn't matter. So we test for the easy behavior: * ctrl+B across two devices is *not* a dwt modifier combo */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(k1); litest_delete_device(k2); } END_TEST START_TEST(touchpad_dwt_multiple_keyboards_remove) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboards[2]; struct libinput *li = touchpad->libinput; int which = litest_test_param_get_i32(test_env->params, "which"); struct litest_device *removed, *remained; litest_assert_int_le(which, 1); litest_assert(has_disable_while_typing(touchpad)); enable_dwt(touchpad); keyboards[0] = litest_add_device(li, LITEST_KEYBOARD); keyboards[1] = litest_add_device(li, LITEST_KEYBOARD); litest_keyboard_key(keyboards[0], KEY_A, true); litest_keyboard_key(keyboards[0], KEY_A, false); litest_keyboard_key(keyboards[1], KEY_B, true); litest_keyboard_key(keyboards[1], KEY_B, false); litest_drain_events(li); litest_timeout_dwt_short(); removed = keyboards[which % 2]; remained = keyboards[(which + 1) % 2]; litest_delete_device(removed); litest_keyboard_key(remained, KEY_C, true); litest_keyboard_key(remained, KEY_C, false); litest_drain_events(li); litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(remained); } END_TEST static int has_thumb_detect(struct litest_device *dev) { double w, h; if (libinput_device_get_size(dev->libinput_device, &w, &h) != 0) return 0; return h >= 50.0; } START_TEST(touchpad_thumb_lower_area_movement) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Thumb below lower line - slow movement - no events */ litest_touch_down(dev, 0, 50, 99); litest_touch_move_to(dev, 0, 55, 99, 60, 99, 50); litest_assert_empty_queue(li); /* Thumb below lower line - fast movement - events */ litest_touch_move_to(dev, 0, 60, 99, 90, 99, 30); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_thumb_lower_area_movement_rethumb) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Thumb below lower line - fast movement - events */ litest_touch_down(dev, 0, 50, 99); litest_touch_move_to(dev, 0, 50, 99, 90, 99, 30); litest_drain_events(li); /* slow movement after being a non-touch - still events */ litest_touch_move_to(dev, 0, 90, 99, 60, 99, 50); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_thumb_speed_empty_slots) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_tap(dev->libinput_device); litest_enable_2fg_scroll(dev); litest_disable_hold_gestures(dev->libinput_device); if (libevdev_get_num_slots(dev->evdev) < 3) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* exceed the speed movement threshold in slot 0, then lift the * finger */ litest_touch_down(dev, 0, 50, 20); litest_touch_move_to(dev, 0, 50, 20, 70, 99, 15); litest_touch_up(dev, 0); litest_drain_events(li); /* now scroll in slots 1 and 2, this should be a normal scroll event * despite slot 0 exceeding the speed threshold earlier */ litest_touch_down(dev, 1, 50, 50); litest_touch_down(dev, 2, 55, 50); litest_dispatch(li); for (int i = 0, y = 50; i < 10; i++, y++) { litest_touch_move_to(dev, 1, 50, y, 50, y + 1, 1); litest_touch_move_to(dev, 2, 55, y, 55, y + 1, 1); } litest_dispatch(li); litest_touch_up(dev, 1); litest_touch_up(dev, 2); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 2); } END_TEST START_TEST(touchpad_thumb_area_clickfinger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); libinput_device_config_click_set_method(dev->libinput_device, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); litest_drain_events(li); litest_touch_down(dev, 0, 50, 99); /* thumb */ litest_dispatch(li); litest_touch_down(dev, 1, 60, 50); litest_dispatch(li); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); litest_button_click(dev, BTN_LEFT, false); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_drain_events(li); litest_touch_down(dev, 1, 60, 99); /* thumb */ litest_dispatch(li); litest_touch_down(dev, 0, 50, 50); litest_dispatch(li); litest_button_click(dev, BTN_LEFT, true); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_thumb_area_btnarea) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); libinput_device_config_click_set_method(dev->libinput_device, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); litest_drain_events(li); litest_touch_down(dev, 0, 90, 99); /* thumb */ litest_dispatch(li); litest_button_click(dev, BTN_LEFT, true); /* button areas work as usual with a thumb */ litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_thumb_no_doublethumb) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_disable_tap(dev->libinput_device); litest_enable_clickfinger(dev); litest_disable_hold_gestures(dev->libinput_device); if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* two touches in thumb area but we can't have two thumbs */ litest_touch_down(dev, 0, 50, 99); /* random sleep interval. we don't have a thumb timer, but let's not * put both touches down and move them immediately because that * should always be a scroll event anyway. Go with a delay in * between to make it more likely that this is really testing thumb * detection. */ msleep(200); litest_dispatch(li); litest_touch_down(dev, 1, 70, 99); litest_dispatch(li); litest_touch_move_two_touches(dev, 50, 99, 70, 99, 0, -20, 10); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_tool_tripletap_touch_count) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; /* Synaptics touchpads sometimes end one touch point while * simultaneously setting BTN_TOOL_TRIPLETAP. * https://bugs.freedesktop.org/show_bug.cgi?id=91352 */ litest_drain_events(li); litest_enable_clickfinger(dev); /* touch 1 down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 1200); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3200); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_X, 1200); litest_event(dev, EV_ABS, ABS_Y, 3200); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* touch 2 down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* touch 3 down, coordinate jump + ends slot 1 */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_X, 4000); litest_event(dev, EV_ABS, ABS_Y, 4000); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* slot 2 reactivated */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 3); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_ABS, ABS_X, 4000); litest_event(dev, EV_ABS, ABS_Y, 4000); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(2); /* now a click should trigger middle click */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_wait_for_event(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); /* release everything */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); } END_TEST START_TEST(touchpad_tool_tripletap_touch_count_late) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; /* Synaptics touchpads sometimes end one touch point after * setting BTN_TOOL_TRIPLETAP. * https://gitlab.freedesktop.org/libinput/libinput/issues/99 */ litest_drain_events(li); litest_enable_clickfinger(dev); /* touch 1 down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 2200); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3200); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_X, 2200); litest_event(dev, EV_ABS, ABS_Y, 3200); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(10); /* touch 2 and TRIPLETAP down */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(10); /* touch 2 up, coordinate jump + ends slot 1, TRIPLETAP stays */ litest_disable_log_handler(li); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_X, 4000); litest_event(dev, EV_ABS, ABS_Y, 4000); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(10); /* slot 2 reactivated */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 4000); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 4000); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 78); litest_event(dev, EV_ABS, ABS_MT_SLOT, 1); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 3); litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 3500); litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 3500); litest_event(dev, EV_ABS, ABS_MT_PRESSURE, 73); litest_event(dev, EV_ABS, ABS_X, 4000); litest_event(dev, EV_ABS, ABS_Y, 4000); litest_event(dev, EV_ABS, ABS_PRESSURE, 78); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); msleep(10); litest_restore_log_handler(li); /* now a click should trigger middle click */ litest_event(dev, EV_KEY, BTN_LEFT, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_LEFT, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_wait_for_event(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); event = libinput_get_event(li); litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); /* release everything */ litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_ABS, ABS_MT_SLOT, 0); litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); } END_TEST START_TEST(touchpad_slot_swap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; int first, second; /* Synaptics touchpads sometimes end the wrong touchpoint on finger * up, causing the remaining slot to continue with the other slot's * coordinates. * https://bugs.freedesktop.org/show_bug.cgi?id=91352 */ litest_drain_events(li); for (first = 0; first <= 1; first++) { const double start[2][2] = {{50, 50}, {60, 60}}; second = 1 - first; litest_touch_down(dev, 0, start[0][0], start[0][1]); litest_dispatch(li); litest_touch_down(dev, 1, start[1][0], start[1][1]); litest_dispatch(li); litest_touch_move_two_touches(dev, start[first][0], start[first][1], start[second][0], start[second][1], 30, 30, 10); litest_drain_events(li); /* release touch 0, continue other slot with 0's coords */ litest_push_event_frame(dev); litest_touch_up(dev, first); litest_touch_move(dev, second, start[second][0] + 30, start[second][1] + 30.1); litest_pop_event_frame(dev); litest_dispatch(li); /* If a gesture was detected, we need to go past the gesture * timeout to trigger events. So let's move a bit first to * make sure it looks continuous, then wait, then move again * to make sure we trigger events */ litest_touch_move_to(dev, second, start[first][0] + 30, start[first][1] + 30, 50, 21, 10); litest_dispatch(li); litest_timeout_gesture(); litest_dispatch(li); /* drain a potential scroll stop */ litest_drain_events(li); litest_touch_move_to(dev, second, 50, 21, 50, 11, 20); litest_dispatch(li); event = libinput_get_event(li); do { struct libinput_event_pointer *ptrev; ptrev = litest_is_motion_event(event); litest_assert_double_eq(libinput_event_pointer_get_dx(ptrev), 0.0); litest_assert_double_lt(libinput_event_pointer_get_dy(ptrev), 1.0); libinput_event_destroy(event); event = libinput_get_event(li); } while (event); litest_assert_empty_queue(li); litest_touch_up(dev, second); } } END_TEST START_TEST(touchpad_finger_always_down) { struct litest_device *dev = litest_current_device(); struct libinput *li; /* Set BTN_TOOL_FINGER before a new context is initialized */ litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); li = litest_create_context(); libinput_path_add_device(li, libevdev_uinput_get_devnode(dev->uinput)); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_destroy_context(li); } END_TEST START_TEST(touchpad_time_usec) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_disable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 50, 80, 50, 20); litest_touch_up(dev, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { struct libinput_event_pointer *ptrev; uint64_t utime; ptrev = litest_is_motion_event(event); utime = libinput_event_pointer_get_time_usec(ptrev); litest_assert_int_eq(libinput_event_pointer_get_time(ptrev), (uint32_t) (utime / 1000)); libinput_event_destroy(event); event = libinput_get_event(li); } } END_TEST START_TEST(touchpad_jump_finger_motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_drain_events(li); /* this test uses a specific test device to trigger a >20mm jump to * test jumps. These numbers may not work on any other device */ litest_disable_log_handler(li); litest_touch_move_to(dev, 0, 90, 30, 20, 80, 1); litest_assert_empty_queue(li); litest_restore_log_handler(li); litest_touch_move_to(dev, 0, 20, 80, 21, 81, 10); litest_touch_up(dev, 0); /* expect lots of little events, no big jump */ litest_dispatch(li); event = libinput_get_event(li); do { struct libinput_event_pointer *ptrev; double dx, dy; ptrev = litest_is_motion_event(event); dx = libinput_event_pointer_get_dx(ptrev); dy = libinput_event_pointer_get_dy(ptrev); litest_assert_int_lt(abs((int)dx), 20); litest_assert_int_lt(abs((int)dy), 20); libinput_event_destroy(event); event = libinput_get_event(li); } while (event != NULL); } END_TEST START_TEST(touchpad_jump_delta) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_drain_events(li); /* this test uses a specific test device to trigger a >7mm but <20mm * jump to test the delta jumps. These numbers may not work on any * other device */ litest_disable_log_handler(li); litest_touch_move(dev, 0, 90, 88); litest_assert_empty_queue(li); litest_restore_log_handler(li); litest_touch_move_to(dev, 0, 90, 88, 91, 89, 10); litest_touch_up(dev, 0); /* expect lots of little events, no big jump */ litest_dispatch(li); event = libinput_get_event(li); do { struct libinput_event_pointer *ptrev; double dx, dy; ptrev = litest_is_motion_event(event); dx = libinput_event_pointer_get_dx(ptrev); dy = libinput_event_pointer_get_dy(ptrev); litest_assert_int_lt(abs((int)dx), 20); litest_assert_int_lt(abs((int)dy), 20); libinput_event_destroy(event); event = libinput_get_event(li); } while (event != NULL); } END_TEST START_TEST(touchpad_disabled_on_mouse) { struct litest_device *dev = litest_current_device(); struct litest_device *mouse; struct libinput *li = dev->libinput; enum libinput_config_status status; litest_drain_events(li); status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); mouse = litest_add_device(li, LITEST_MOUSE); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_delete_device(mouse); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_disabled_on_mouse_suspend_mouse) { struct litest_device *dev = litest_current_device(); struct litest_device *mouse; struct libinput *li = dev->libinput; enum libinput_config_status status; litest_drain_events(li); status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); mouse = litest_add_device(li, LITEST_MOUSE); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); /* Disable external mouse -> expect touchpad events */ status = libinput_device_config_send_events_set_mode( mouse->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(mouse); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_disabled_double_mouse) { struct litest_device *dev = litest_current_device(); struct litest_device *mouse1, *mouse2; struct libinput *li = dev->libinput; enum libinput_config_status status; litest_drain_events(li); status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); mouse1 = litest_add_device(li, LITEST_MOUSE); mouse2 = litest_add_device(li, LITEST_MOUSE_LOW_DPI); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_delete_device(mouse1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_delete_device(mouse2); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_disabled_double_mouse_one_suspended) { struct litest_device *dev = litest_current_device(); struct litest_device *mouse1, *mouse2; struct libinput *li = dev->libinput; enum libinput_config_status status; litest_drain_events(li); status = libinput_device_config_send_events_set_mode( dev->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); mouse1 = litest_add_device(li, LITEST_MOUSE); mouse2 = litest_add_device(li, LITEST_MOUSE_LOW_DPI); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_ADDED); /* Disable one external mouse -> don't expect touchpad events */ status = libinput_device_config_send_events_set_mode( mouse1->libinput_device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_delete_device(mouse1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_delete_device(mouse2); litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED); litest_touch_down(dev, 0, 20, 30); litest_touch_move_to(dev, 0, 20, 30, 90, 30, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST static inline bool touchpad_has_pressure(struct litest_device *dev) { struct libevdev *evdev = dev->evdev; if (dev->which == LITEST_SYNAPTICS_PRESSUREPAD) return false; if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) return libevdev_get_abs_resolution(evdev, ABS_MT_PRESSURE) == 0; if (libevdev_has_event_code(evdev, EV_ABS, ABS_PRESSURE) && !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT)) return true; return false; } START_TEST(touchpad_pressure) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 1 }, { ABS_PRESSURE, 1 }, { -1, 0 } }; double pressure; /* in percent */ double threshold = 12.0; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); for (pressure = 1; pressure <= threshold + 1; pressure++) { litest_axis_set_value(axes, ABS_MT_PRESSURE, pressure); litest_axis_set_value(axes, ABS_PRESSURE, pressure); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_touch_up(dev, 0); if (pressure < threshold) litest_assert_empty_queue(li); else litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } } END_TEST START_TEST(touchpad_pressure_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_touch_down(dev, 0, 30, 50); litest_touch_down_extended(dev, 1, 50, 50, axes); litest_dispatch(li); litest_touch_move_to(dev, 0, 30, 50, 80, 80, 10); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_move_to_extended(dev, 1, 50, 50, 80, 80, axes, 10); litest_assert_empty_queue(li); litest_touch_move_to(dev, 0, 80, 80, 20, 50, 10); litest_touch_move_to_extended(dev, 1, 80, 80, 50, 50, axes, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_pressure_2fg_st) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; /* This is a bit of a weird test. We expect two fingers to be down as * soon as doubletap is set, regardless of pressure. But we don't * have 2fg scrolling on st devices and 2 fingers down on a touchpad * without 2fg scrolling simply does not generate events. But that's * the same result as if the fingers were ignored because of * pressure and we cannot know the difference. * So this test only keeps your CPU warm, not much else. */ litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 0); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_pressure_tap) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_dispatch(li); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_pressure_tap_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* tap but too light */ litest_touch_down_extended(dev, 0, 40, 50, axes); litest_touch_down_extended(dev, 1, 50, 50, axes); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_pressure_tap_2fg_1fg_light) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* double-tap with one finger too light */ litest_touch_down(dev, 0, 40, 50); litest_touch_down_extended(dev, 1, 50, 50, axes); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); litest_timeout_tap(); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); } END_TEST START_TEST(touchpad_pressure_btntool) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_PRESSURE, 5 }, { ABS_PRESSURE, 5 }, { -1, 0 } }; /* we only have tripletap, can't test 4 slots because nothing will * happen */ if (libevdev_get_num_slots(dev->evdev) != 2) return LITEST_NOT_APPLICABLE; if (!touchpad_has_pressure(dev)) return LITEST_NOT_APPLICABLE; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); /* Two light touches down, doesn't count */ litest_touch_down_extended(dev, 0, 40, 50, axes); litest_touch_down_extended(dev, 1, 45, 50, axes); litest_dispatch(li); litest_assert_empty_queue(li); /* Tripletap but since no finger is logically down, it doesn't count */ litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); /* back to two fingers */ litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); /* make one finger real */ litest_touch_move(dev, 0, 40, 50); litest_drain_events(li); /* tripletap should now be 3 fingers tap */ litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_timeout_tap(); litest_dispatch(li); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); } END_TEST START_TEST(touchpad_pressure_semi_mt_2fg_goes_light) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_PRESSURE, 2 }, { -1, 0 } }; litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 40, 50); litest_touch_down(dev, 1, 60, 50); litest_touch_move_two_touches(dev, 40, 50, 60, 50, 0, -20, 10); /* This should trigger a scroll end event */ litest_push_event_frame(dev); litest_touch_move_extended(dev, 0, 40, 31, axes); litest_touch_move_extended(dev, 1, 60, 31, axes); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 0); litest_push_event_frame(dev); litest_touch_move_extended(dev, 0, 40, 35, axes); litest_touch_move_extended(dev, 1, 60, 35, axes); litest_pop_event_frame(dev); litest_push_event_frame(dev); litest_touch_move_extended(dev, 0, 40, 40, axes); litest_touch_move_extended(dev, 1, 60, 40, axes); litest_pop_event_frame(dev); litest_dispatch(li); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_touch_size) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { ABS_MT_ORIENTATION, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 1); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 1); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_touch_size_2fg) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { ABS_MT_ORIENTATION, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 1); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 1); litest_touch_down_extended(dev, 1, 70, 70, axes); litest_touch_move_to_extended(dev, 1, 70, 70, 80, 90, axes, 10); litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 15); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 15); litest_touch_move_to_extended(dev, 0, 80, 80, 50, 50, axes, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_touch_up(dev, 1); litest_touch_up(dev, 0); } END_TEST START_TEST(touchpad_palm_detect_touch_size) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev) || litest_touchpad_is_external(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* apply insufficient pressure */ litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30); litest_touch_down_extended(dev, 0, 50, 50, axes); litest_touch_move_to_extended(dev, 0, 50, 50, 80, 80, axes, 10); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* apply sufficient pressure */ litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90); litest_touch_move_to_extended(dev, 0, 80, 80, 50, 50, axes, 10); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_touch_size_late) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev) || litest_touchpad_is_external(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* apply insufficient pressure */ litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10); litest_drain_events(li); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* apply sufficient pressure */ litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90); litest_touch_down(dev, 0, 50, 50); litest_touch_move_to(dev, 0, 50, 70, 80, 90, 10); litest_drain_events(li); litest_dispatch(li); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_touch_size_keep_palm) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev) || litest_touchpad_is_external(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* apply insufficient pressure */ litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 30); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 30); litest_touch_down(dev, 0, 80, 90); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* apply sufficient pressure */ litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90); litest_touch_down(dev, 0, 80, 90); litest_touch_move_to_extended(dev, 0, 80, 90, 50, 20, axes, 10); litest_touch_move_to(dev, 0, 50, 20, 80, 90, 10); litest_touch_up(dev, 0); litest_assert_empty_queue(li); } END_TEST START_TEST(touchpad_palm_detect_touch_size_after_edge) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(dev) || litest_touchpad_is_external(dev) || !litest_has_palm_detect_size(dev) || !litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; litest_enable_2fg_scroll(dev); litest_drain_events(li); /* apply sufficient pressure */ litest_axis_set_value_unchecked(axes, ABS_MT_TOUCH_MAJOR, 90); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90); litest_touch_down(dev, 0, 99, 50); litest_touch_move_to_extended(dev, 0, 99, 50, 20, 50, axes, 20); litest_touch_up(dev, 0); litest_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_palm_detect_touch_size_after_dwt) { struct litest_device *touchpad = litest_current_device(); struct litest_device *keyboard; struct libinput *li = touchpad->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 0 }, { ABS_MT_TOUCH_MINOR, 0 }, { -1, 0 } }; if (!touchpad_has_touch_size(touchpad) || litest_touchpad_is_external(touchpad)) return LITEST_NOT_APPLICABLE; keyboard = dwt_init_paired_keyboard(li, touchpad); litest_drain_events(li); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_drain_events(li); /* apply sufficient pressure */ litest_axis_set_value(axes, ABS_MT_TOUCH_MAJOR, 90); litest_axis_set_value(axes, ABS_MT_TOUCH_MINOR, 90); /* within dwt timeout, dwt blocks events */ litest_touch_down(touchpad, 0, 50, 50); litest_touch_move_to_extended(touchpad, 0, 50, 50, 20, 50, axes, 20); litest_assert_empty_queue(li); litest_timeout_dwt_short(); litest_dispatch(li); litest_assert_empty_queue(li); /* after dwt timeout, pressure blocks events */ litest_touch_move_to_extended(touchpad, 0, 20, 50, 50, 50, axes, 20); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_delete_device(keyboard); } END_TEST START_TEST(touchpad_speed_ignore_finger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; if (litest_has_clickfinger(dev)) litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_move_to(dev, 0, 20, 20, 85, 80, 20); litest_touch_down(dev, 1, 20, 80); litest_touch_move_two_touches(dev, 85, 80, 20, 80, -20, -20, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_speed_allow_nearby_finger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; if (!litest_has_2fg_scroll(dev)) return LITEST_NOT_APPLICABLE; if (litest_has_clickfinger(dev)) litest_enable_clickfinger(dev); litest_enable_2fg_scroll(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_move_to(dev, 0, 20, 20, 80, 80, 20); litest_drain_events(li); litest_touch_down(dev, 1, 79, 80); litest_touch_move_two_touches(dev, 80, 80, 79, 80, -20, -20, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_touch_up(dev, 1); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST START_TEST(touchpad_speed_ignore_finger_edgescroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_enable_edge_scroll(dev); if (litest_has_clickfinger(dev)) litest_enable_clickfinger(dev); litest_drain_events(li); litest_touch_down(dev, 0, 20, 20); litest_touch_move_to(dev, 0, 20, 20, 60, 80, 20); litest_drain_events(li); litest_touch_down(dev, 1, 59, 80); litest_touch_move_two_touches(dev, 60, 80, 59, 80, -20, -20, 10); litest_dispatch(li); litest_touch_up(dev, 0); litest_dispatch(li); litest_touch_up(dev, 1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_speed_ignore_hovering_finger) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_MT_TOUCH_MAJOR, 1 }, { ABS_MT_TOUCH_MINOR, 1 }, { -1, 0 } }; if (!has_thumb_detect(dev)) return LITEST_NOT_APPLICABLE; litest_drain_events(li); /* first finger down but below touch size. we use slot 2 because * it's easier this way for litest */ litest_touch_down_extended(dev, 2, 20, 20, axes); litest_touch_move_to_extended(dev, 2, 20, 20, 60, 80, axes, 20); litest_drain_events(li); /* second, third finger down withn same frame */ litest_push_event_frame(dev); litest_touch_down(dev, 0, 59, 70); litest_touch_down(dev, 1, 65, 70); litest_pop_event_frame(dev); litest_touch_move_two_touches(dev, 59, 70, 65, 70, 0, 30, 10); litest_dispatch(li); litest_touch_up(dev, 2); litest_dispatch(li); litest_touch_up(dev, 1); litest_touch_up(dev, 0); litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER); } END_TEST enum suspend { SUSPEND_EXT_MOUSE = 1, SUSPEND_SENDEVENTS, SUSPEND_LID, SUSPEND_TABLETMODE, SUSPEND_COUNT, }; static void assert_touchpad_moves(struct litest_device *tp) { struct libinput *li = tp->libinput; litest_touch_down(tp, 0, 50, 50); litest_touch_move_to(tp, 0, 50, 50, 60, 80, 20); litest_touch_up(tp, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } static void assert_touchpad_does_not_move(struct litest_device *tp) { struct libinput *li = tp->libinput; litest_touch_down(tp, 0, 20, 20); litest_touch_move_to(tp, 0, 20, 20, 60, 80, 20); litest_touch_up(tp, 0); litest_assert_empty_queue(li); } START_TEST(touchpad_suspend_abba) { struct litest_device *tp = litest_current_device(); struct litest_device *lid, *tabletmode, *extmouse; struct libinput *li = tp->libinput; enum suspend first = litest_test_param_get_i32(test_env->params, "mode"); if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) return LITEST_NOT_APPLICABLE; lid = litest_add_device(li, LITEST_LID_SWITCH); tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); extmouse = litest_add_device(li, LITEST_MOUSE); litest_grab_device(lid); litest_grab_device(tabletmode); litest_disable_tap(tp->libinput_device); litest_disable_hold_gestures(tp->libinput_device); /* ABBA test for touchpad internal suspend: * reason A on * reason B on * reason B off * reason A off */ for (enum suspend other = SUSPEND_EXT_MOUSE; other < SUSPEND_COUNT; other++) { if (other == first) continue; if (other == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) goto out; /* That transition is tested elsewhere and has a different * behavior */ if ((other == SUSPEND_SENDEVENTS && first == SUSPEND_EXT_MOUSE) || (first == SUSPEND_SENDEVENTS && other == SUSPEND_EXT_MOUSE)) continue; litest_drain_events(li); assert_touchpad_moves(tp); /* First reason for suspend: on */ switch (first) { case SUSPEND_EXT_MOUSE: litest_sendevents_ext_mouse(tp); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); break; case SUSPEND_SENDEVENTS: litest_sendevents_off(tp); break; default: litest_abort_msg("Unexpected suspend option"); } litest_drain_events(li); assert_touchpad_does_not_move(tp); /* Second reason to suspend: on/off while first reason remains */ switch (other) { case SUSPEND_EXT_MOUSE: litest_sendevents_ext_mouse(tp); litest_sendevents_on(tp); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); break; case SUSPEND_SENDEVENTS: litest_sendevents_off(tp); litest_sendevents_on(tp); break; default: litest_abort_msg("Unexpected suspend option"); } assert_touchpad_does_not_move(tp); /* First reason for suspend: off */ switch (first) { case SUSPEND_EXT_MOUSE: litest_sendevents_on(tp); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); break; case SUSPEND_SENDEVENTS: litest_sendevents_on(tp); break; default: litest_abort_msg("Unexpected suspend option"); } litest_drain_events(li); assert_touchpad_moves(tp); } out: litest_ungrab_device(lid); litest_ungrab_device(tabletmode); litest_delete_device(lid); litest_delete_device(tabletmode); litest_delete_device(extmouse); } END_TEST START_TEST(touchpad_suspend_abab) { struct litest_device *tp = litest_current_device(); struct litest_device *lid, *tabletmode, *extmouse; struct libinput *li = tp->libinput; enum suspend first = litest_test_param_get_i32(test_env->params, "mode"); if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) return LITEST_NOT_APPLICABLE; lid = litest_add_device(li, LITEST_LID_SWITCH); tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); extmouse = litest_add_device(li, LITEST_MOUSE); litest_grab_device(lid); litest_grab_device(tabletmode); litest_disable_tap(tp->libinput_device); litest_disable_hold_gestures(tp->libinput_device); /* ABAB test for touchpad internal suspend: * reason A on * reason B on * reason A off * reason B off */ for (enum suspend other = SUSPEND_EXT_MOUSE; other < SUSPEND_COUNT; other++) { if (other == first) continue; if (other == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) goto out; /* That transition is tested elsewhere and has a different * behavior */ if ((other == SUSPEND_SENDEVENTS && first == SUSPEND_EXT_MOUSE) || (first == SUSPEND_SENDEVENTS && other == SUSPEND_EXT_MOUSE)) continue; litest_drain_events(li); assert_touchpad_moves(tp); /* First reason for suspend: on */ switch (first) { case SUSPEND_EXT_MOUSE: litest_sendevents_ext_mouse(tp); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); break; case SUSPEND_SENDEVENTS: litest_sendevents_off(tp); break; default: litest_abort_msg("Unexpected suspend option"); } litest_drain_events(li); assert_touchpad_does_not_move(tp); /* Second reason to suspend: on */ switch (other) { case SUSPEND_EXT_MOUSE: litest_sendevents_ext_mouse(tp); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); break; case SUSPEND_SENDEVENTS: litest_sendevents_off(tp); break; default: litest_abort_msg("Unexpected suspend option"); } assert_touchpad_does_not_move(tp); /* First reason for suspend: off */ switch (first) { case SUSPEND_EXT_MOUSE: litest_sendevents_on(tp); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); break; case SUSPEND_SENDEVENTS: litest_sendevents_on(tp); break; default: litest_abort_msg("Unexpected suspend option"); } litest_drain_events(li); assert_touchpad_does_not_move(tp); /* Second reason to suspend: off */ switch (other) { case SUSPEND_EXT_MOUSE: litest_sendevents_on(tp); break; case SUSPEND_LID: litest_switch_action(lid, LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); break; case SUSPEND_TABLETMODE: litest_switch_action(tabletmode, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); break; case SUSPEND_SENDEVENTS: litest_sendevents_on(tp); break; default: litest_abort_msg("Unexpected suspend option"); } litest_drain_events(li); assert_touchpad_moves(tp); } out: litest_ungrab_device(lid); litest_ungrab_device(tabletmode); litest_delete_device(lid); litest_delete_device(tabletmode); litest_delete_device(extmouse); } END_TEST START_TEST(touchpad_end_start_touch) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_enable_tap(dev->libinput_device); litest_disable_hold_gestures(dev->libinput_device); litest_drain_events(li); litest_touch_down(dev, 0, 50, 50); litest_touch_move(dev, 0, 50.1, 50.1); litest_dispatch(li); litest_push_event_frame(dev); litest_touch_up(dev, 0); litest_touch_down(dev, 0, 50.2, 50.2); litest_pop_event_frame(dev); litest_disable_log_handler(li); litest_dispatch(li); litest_restore_log_handler(li); litest_assert_empty_queue(li); litest_timeout_tap(); litest_dispatch(li); litest_touch_move_to(dev, 0, 50.2, 50.2, 50, 70, 10); litest_touch_up(dev, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); } END_TEST START_TEST(touchpad_fuzz) { struct litest_device *dev = litest_current_device(); struct libevdev *evdev = dev->evdev; /* We expect our udev callout to always set this to 0 */ litest_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_X), 0); litest_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_Y), 0); if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X)) litest_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_MT_POSITION_X), 0); if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) litest_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_MT_POSITION_Y), 0); } END_TEST TEST_COLLECTION(touchpad) { litest_add(touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_2fg_scroll_initially_diagonal, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_2fg_scroll_axis_lock, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_2fg_scroll_axis_lock_switch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_2fg_scroll_slow_distance, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_scroll_return_to_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_scroll_source, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_scroll_semi_mt, LITEST_SEMI_MT, LITEST_SINGLE_TOUCH); litest_add(touchpad_2fg_scroll_from_btnareas, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_scroll_natural_defaults, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_scroll_natural_enable_config, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_scroll_natural_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_scroll_natural_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_scroll_defaults, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_vert, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_edge_scroll_horiz_clickpad, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_no_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_edge_scroll_no_motion, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_no_edge_after_motion, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_timeout, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_source, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_no_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_edge_scroll_into_buttonareas, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_within_buttonareas, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_buttonareas_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_clickfinger_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_edge_scroll_into_area, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_left_handed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); litest_add_for_device(touchpad_left_handed_appletouch, LITEST_APPLETOUCH); litest_add(touchpad_left_handed_clickpad, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(touchpad_left_handed_clickfinger, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_left_handed_tapping, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_left_handed_tapping_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_left_handed_delayed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); litest_add(touchpad_left_handed_clickpad_delayed, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); litest_add(touchpad_left_handed_rotation, LITEST_TOUCHPAD, LITEST_ANY); /* Semi-MT hover tests aren't generic, they only work on this device and * ignore the semi-mt capability (it doesn't matter for the tests) */ litest_add_for_device(touchpad_semi_mt_hover_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_down_up, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_down_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_2fg_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_2fg_1fg_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add_for_device(touchpad_semi_mt_hover_2fg_up, LITEST_SYNAPTICS_HOVER_SEMI_MT); litest_add(touchpad_hover_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_down_up, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_down_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_2fg_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_2fg_1fg_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add(touchpad_hover_1fg_tap, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); litest_add_for_device(touchpad_trackpoint_buttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_add_for_device(touchpad_trackpoint_mb_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_add_for_device(touchpad_trackpoint_mb_click, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_add_for_device(touchpad_trackpoint_buttons_softbuttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_add_for_device(touchpad_trackpoint_buttons_2fg_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_add_for_device(touchpad_trackpoint_no_trackpoint, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); litest_with_parameters(params, "axis", 'I', 2, litest_named_i32(ABS_X), litest_named_i32(ABS_Y)) { litest_add_parametrized(touchpad_initial_state, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_with_parameters(params, "fingers", 'i', 5, 1, 2, 3, 4, 5) { litest_add_parametrized(touchpad_fingers_down_before_init, LITEST_TOUCHPAD, LITEST_ANY, params); } litest_add(touchpad_state_after_syn_dropped_2fg_change, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_thumb_lower_area_movement, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_thumb_lower_area_movement_rethumb, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_thumb_speed_empty_slots, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_thumb_area_clickfinger, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_thumb_area_btnarea, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_thumb_no_doublethumb, LITEST_CLICKPAD, LITEST_ANY); litest_add_for_device(touchpad_tool_tripletap_touch_count, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add_for_device(touchpad_tool_tripletap_touch_count_late, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add_for_device(touchpad_slot_swap, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add_for_device(touchpad_finger_always_down, LITEST_SYNAPTICS_TOPBUTTONPAD); litest_add(touchpad_time_usec, LITEST_TOUCHPAD, LITEST_ANY); litest_add_for_device(touchpad_jump_finger_motion, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(touchpad_jump_delta, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(touchpad_disabled_on_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(touchpad_disabled_on_mouse_suspend_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(touchpad_disabled_double_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(touchpad_disabled_double_mouse_one_suspended, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add(touchpad_pressure, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_pressure_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_pressure_2fg_st, LITEST_TOUCHPAD|LITEST_SINGLE_TOUCH, LITEST_ANY); litest_add(touchpad_pressure_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_pressure_tap_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_pressure_tap_2fg_1fg_light, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_pressure_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_pressure_semi_mt_2fg_goes_light, LITEST_SEMI_MT, LITEST_ANY); litest_add(touchpad_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_touch_size_2fg, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_speed_ignore_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_speed_allow_nearby_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add(touchpad_speed_ignore_finger_edgescroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); litest_add_for_device(touchpad_speed_ignore_hovering_finger, LITEST_BCM5974); litest_with_parameters(params, "mode", 'I', 4, litest_named_i32(SUSPEND_EXT_MOUSE, "external_mouse"), litest_named_i32(SUSPEND_SENDEVENTS, "sendevents"), litest_named_i32(SUSPEND_LID, "lid"), litest_named_i32(SUSPEND_TABLETMODE, "tabletmode")) { litest_add_parametrized(touchpad_suspend_abba, LITEST_TOUCHPAD, LITEST_ANY, params); litest_add_parametrized(touchpad_suspend_abab, LITEST_TOUCHPAD, LITEST_ANY, params); } /* Happens on the "Wacom Intuos Pro M Finger" but our test device * has the same properties */ litest_add_for_device(touchpad_end_start_touch, LITEST_WACOM_INTUOS5_FINGER); litest_add(touchpad_fuzz, LITEST_TOUCHPAD, LITEST_ANY); } TEST_COLLECTION(touchpad_dwt) { litest_add(touchpad_dwt, LITEST_TOUCHPAD, LITEST_ANY); litest_add_for_device(touchpad_dwt_ext_and_int_keyboard, LITEST_SYNAPTICS_I2C); litest_add(touchpad_dwt_enable_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_touch_hold, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_key_hold, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_key_hold_timeout, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_key_hold_timeout_existing_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_key_hold_timeout_existing_touch_cornercase, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_type, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_type_short_timeout, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_shift_combo_triggers_dwt, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_modifier_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_modifier_combo_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_modifier_combo_dwt_after, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_modifier_combo_dwt_remains, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_fkeys_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_tap_drag, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_click, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_edge_scroll, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_dwt_edge_scroll_interrupt, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_dwt_config_default_on, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_config_default_off, LITEST_ANY, LITEST_TOUCHPAD); litest_add(touchpad_dwt_disabled, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_disable_during_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_disable_before_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_disable_during_key_release, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_disable_during_key_hold, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_enable_during_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_enable_before_touch, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_enable_during_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwt_remove_kbd_while_active, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwtp_config_default_on, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_dwtp_config_default_off, LITEST_ANY, LITEST_TOUCHPAD); litest_add_for_device(touchpad_dwt_apple, LITEST_BCM5974); litest_add_for_device(touchpad_dwt_acer_hawaii, LITEST_ACER_HAWAII_TOUCHPAD); litest_add_for_device(touchpad_dwt_multiple_keyboards, LITEST_SYNAPTICS_I2C); litest_add_for_device(touchpad_dwt_multiple_keyboards_bothkeys, LITEST_SYNAPTICS_I2C); litest_add_for_device(touchpad_dwt_multiple_keyboards_bothkeys_modifier, LITEST_SYNAPTICS_I2C); litest_with_parameters(params, "which", 'I', 2, litest_named_i32(0, "first"), litest_named_i32(1, "second")) { litest_add_parametrized_for_device(touchpad_dwt_multiple_keyboards_remove, LITEST_SYNAPTICS_I2C, params); } litest_add_for_device(touchpad_dwt_remove_before_keyboard, LITEST_KEYBOARD); } TEST_COLLECTION(touchpad_palm) { litest_add(touchpad_palm_detect_at_edge, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_palm_detect_at_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_at_bottom_corners, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_palm_detect_at_top_corners, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_palm_detect_top_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_palm_stays_palm, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_palm_detect_top_palm_stays_palm, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_no_palm_moving_into_edges, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_palm_detect_no_palm_moving_into_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_no_tap_top_edge, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); litest_add(touchpad_palm_detect_tap_hardbuttons, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_palm_detect_tap_softbuttons, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_tap_clickfinger, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_no_palm_detect_at_edge_for_edge_scrolling, LITEST_TOUCHPAD, LITEST_CLICKPAD); litest_add(touchpad_no_palm_detect_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_both_edges, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_tool_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_tool_palm_on_off, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_tool_palm_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_tool_palm_tap_after, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_touch_size_late, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_touch_size_keep_palm, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_touch_size_after_edge, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_touch_size_after_dwt, LITEST_APPLE_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_pressure, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_pressure_late_tap, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_pressure_tap_hold, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_detect_pressure_tap_hold_2ndfg, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_move_and_tap, LITEST_TOUCHPAD, LITEST_ANY); litest_add(touchpad_palm_detect_pressure_late, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_pressure_keep_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_pressure_after_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add(touchpad_palm_detect_pressure_after_dwt, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); litest_add_for_device(touchpad_palm_ignore_threshold_zero, LITEST_TOUCHPAD_PALMPRESSURE_ZERO); litest_add(touchpad_palm_clickfinger_pressure, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_clickfinger_pressure_2fg, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_clickfinger_size, LITEST_CLICKPAD, LITEST_ANY); litest_add(touchpad_palm_clickfinger_size_2fg, LITEST_CLICKPAD, LITEST_ANY); } libinput-1.28.1/test/test-trackball.c000066400000000000000000000200511477265155700175110ustar00rootroot00000000000000/* * Copyright © 2016 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "libinput-util.h" #include "litest.h" START_TEST(trackball_rotation_config_defaults) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; int angle; litest_assert(libinput_device_config_rotation_is_available(device)); angle = libinput_device_config_rotation_get_angle(device); litest_assert_int_eq(angle, 0); angle = libinput_device_config_rotation_get_default_angle(device); litest_assert_int_eq(angle, 0); } END_TEST START_TEST(trackball_rotation_config_invalid_range) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; status = libinput_device_config_rotation_set_angle(device, 360); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_rotation_set_angle(device, 361); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); status = libinput_device_config_rotation_set_angle(device, -1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); } END_TEST START_TEST(trackball_rotation_config_no_rotation) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; int angle; litest_assert(!libinput_device_config_rotation_is_available(device)); angle = libinput_device_config_rotation_get_angle(device); litest_assert_int_eq(angle, 0); angle = libinput_device_config_rotation_get_default_angle(device); litest_assert_int_eq(angle, 0); /* 0 always succeeds */ status = libinput_device_config_rotation_set_angle(device, 0); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); for (angle = 1; angle < 360; angle++) { status = libinput_device_config_rotation_set_angle(device, angle); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } } END_TEST START_TEST(trackball_rotation_config_right_angle) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; int angle; litest_assert(libinput_device_config_rotation_is_available(device)); for (angle = 0; angle < 360; angle += 90) { status = libinput_device_config_rotation_set_angle(device, angle); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } } END_TEST START_TEST(trackball_rotation_config_odd_angle) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; enum libinput_config_status status; int angle; litest_assert(libinput_device_config_rotation_is_available(device)); for (angle = 0; angle < 360; angle++) { status = libinput_device_config_rotation_set_angle(device, angle); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); } } END_TEST START_TEST(trackball_rotation_x) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device = dev->libinput_device; struct libinput_event *event; struct libinput_event_pointer *ptrev; int angle; double dx, dy; litest_drain_events(li); for (angle = 0; angle < 360; angle++) { libinput_device_config_rotation_set_angle(device, angle); litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); /* Test unaccelerated because pointer accel may mangle the other coords */ dx = libinput_event_pointer_get_dx_unaccelerated(ptrev); dy = libinput_event_pointer_get_dy_unaccelerated(ptrev); switch (angle) { case 0: litest_assert_double_eq(dx, 1.0); litest_assert_double_eq(dy, 0.0); break; case 90: litest_assert_double_eq(dx, 0.0); litest_assert_double_eq(dy, 1.0); break; case 180: litest_assert_double_eq(dx, -1.0); litest_assert_double_eq(dy, 0.0); break; case 270: litest_assert_double_eq(dx, 0.0); litest_assert_double_eq(dy, -1.0); break; } libinput_event_destroy(event); } } END_TEST START_TEST(trackball_rotation_y) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device = dev->libinput_device; struct libinput_event *event; struct libinput_event_pointer *ptrev; int angle; double dx, dy; litest_drain_events(li); for (angle = 0; angle < 360; angle++) { libinput_device_config_rotation_set_angle(device, angle); litest_event(dev, EV_REL, REL_Y, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); /* Test unaccelerated because pointer accel may mangle the other coords */ dx = libinput_event_pointer_get_dx_unaccelerated(ptrev); dy = libinput_event_pointer_get_dy_unaccelerated(ptrev); switch (angle) { case 0: litest_assert_double_eq(dx, 0.0); litest_assert_double_eq(dy, 1.0); break; case 90: litest_assert_double_eq(dx, -1.0); litest_assert_double_eq(dy, 0.0); break; case 180: litest_assert_double_eq(dx, 0.0); litest_assert_double_eq(dy, -1.0); break; case 270: litest_assert_double_eq(dx, 1.0); litest_assert_double_eq(dy, 0.0); break; } libinput_event_destroy(event); } } END_TEST START_TEST(trackball_rotation_accel) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_device *device = dev->libinput_device; struct libinput_event *event; struct libinput_event_pointer *ptrev; double dx, dy; litest_drain_events(li); /* Pointer accel mangles the coordinates, so we only test one angle * and rely on the unaccelerated tests above to warn us when * something's off */ libinput_device_config_rotation_set_angle(device, 90); litest_event(dev, EV_REL, REL_Y, 1); litest_event(dev, EV_REL, REL_X, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); event = libinput_get_event(li); ptrev = litest_is_motion_event(event); dx = libinput_event_pointer_get_dx(ptrev); dy = libinput_event_pointer_get_dy(ptrev); litest_assert_double_lt(dx, 0.0); litest_assert_double_gt(dy, 0.0); libinput_event_destroy(event); } END_TEST TEST_COLLECTION(trackball) { litest_add(trackball_rotation_config_defaults, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_config_invalid_range, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_config_no_rotation, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackball_rotation_config_right_angle, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_config_odd_angle, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_x, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_y, LITEST_TRACKBALL, LITEST_ANY); litest_add(trackball_rotation_accel, LITEST_TRACKBALL, LITEST_ANY); } libinput-1.28.1/test/test-trackpoint.c000066400000000000000000000376461477265155700177520ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include "libinput-util.h" #include "litest.h" static inline bool has_disable_while_trackpointing(struct litest_device *device) { return libinput_device_config_dwtp_is_available(device->libinput_device); } START_TEST(trackpoint_middlebutton) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; uint64_t ptime, rtime; litest_drain_events(li); /* A quick middle button click should get reported normally */ litest_button_click_debounced(dev, li, BTN_MIDDLE, 1); msleep(2); litest_button_click_debounced(dev, li, BTN_MIDDLE, 0); litest_wait_for_event(li); event = libinput_get_event(li); ptrev = litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); ptime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); event = libinput_get_event(li); ptrev = litest_is_button_event(event, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); rtime = libinput_event_pointer_get_time(ptrev); libinput_event_destroy(event); litest_assert_int_lt(ptime, rtime); litest_assert_empty_queue(li); } END_TEST START_TEST(trackpoint_scroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; litest_drain_events(li); litest_button_scroll(dev, BTN_MIDDLE, 1, 6); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6); litest_button_scroll(dev, BTN_MIDDLE, 1, -7); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7); litest_button_scroll(dev, BTN_MIDDLE, 8, 1); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8); litest_button_scroll(dev, BTN_MIDDLE, -9, 1); litest_assert_scroll(li, LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9); /* scroll smaller than the threshold should not generate axis events */ litest_button_scroll(dev, BTN_MIDDLE, 1, 1); litest_button_scroll(dev, BTN_MIDDLE, 0, 0); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED); litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_empty_queue(li); } END_TEST START_TEST(trackpoint_middlebutton_noscroll) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; /* Disable middle button scrolling */ libinput_device_config_scroll_set_method(dev->libinput_device, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); litest_drain_events(li); /* A long middle button click + motion should get reported normally now */ litest_button_scroll(dev, BTN_MIDDLE, 0, 10); litest_assert_button_event(li, BTN_MIDDLE, 1); event = libinput_get_event(li); litest_assert_notnull(event); litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION); libinput_event_destroy(event); litest_assert_button_event(li, BTN_MIDDLE, 0); litest_assert_empty_queue(li); /* Restore default scroll behavior */ libinput_device_config_scroll_set_method(dev->libinput_device, libinput_device_config_scroll_get_default_method( dev->libinput_device)); } END_TEST START_TEST(trackpoint_scroll_source) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_pointer *ptrev; litest_drain_events(li); litest_button_scroll(dev, BTN_MIDDLE, 0, 6); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS); while ((event = libinput_get_event(li))) { ptrev = libinput_event_get_pointer_event(event); litest_assert_enum_eq(litest_event_pointer_get_axis_source(ptrev), LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); libinput_event_destroy(event); } } END_TEST START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; enum libinput_config_status status; struct libinput_event *event; struct libinput_device *device; litest_disable_hold_gestures(touchpad->libinput_device); trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); /* touchpad right-handed, trackpoint left-handed */ status = libinput_device_config_left_handed_set( trackpoint->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(touchpad, 0, 5, 5); litest_dispatch(li); litest_button_click_debounced(touchpad, li, BTN_LEFT, true); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_button_click_debounced(touchpad, li, BTN_LEFT, false); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_delete_device(trackpoint); } END_TEST START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; enum libinput_config_status status; struct libinput_event *event; struct libinput_device *device; litest_disable_hold_gestures(touchpad->libinput_device); trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); /* touchpad left-handed, trackpoint right-handed */ status = libinput_device_config_left_handed_set( touchpad->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(touchpad, 0, 5, 5); litest_dispatch(li); litest_button_click_debounced(touchpad, li, BTN_LEFT, true); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_button_click_debounced(touchpad, li, BTN_LEFT, false); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_delete_device(trackpoint); } END_TEST START_TEST(trackpoint_topsoftbuttons_left_handed_both) { struct litest_device *touchpad = litest_current_device(); struct litest_device *trackpoint; struct libinput *li = touchpad->libinput; enum libinput_config_status status; struct libinput_event *event; struct libinput_device *device; litest_disable_hold_gestures(touchpad->libinput_device); trackpoint = litest_add_device(li, LITEST_TRACKPOINT); litest_drain_events(li); /* touchpad left-handed, trackpoint left-handed */ status = libinput_device_config_left_handed_set( touchpad->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); status = libinput_device_config_left_handed_set( trackpoint->libinput_device, 1); litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_touch_down(touchpad, 0, 5, 5); litest_dispatch(li); litest_button_click_debounced(touchpad, li, BTN_LEFT, true); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_button_click_debounced(touchpad, li, BTN_LEFT, false); litest_dispatch(li); event = libinput_get_event(li); litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); device = libinput_event_get_device(event); litest_assert(device == trackpoint->libinput_device); libinput_event_destroy(event); litest_delete_device(trackpoint); } END_TEST static inline void enable_dwtp(struct litest_device *dev) { enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_dwtp_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_DWTP_ENABLED); litest_assert_enum_eq(status, expected); } static inline void disable_dwtp(struct litest_device *dev) { enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS; status = libinput_device_config_dwtp_set_enabled(dev->libinput_device, LIBINPUT_CONFIG_DWTP_DISABLED); litest_assert_enum_eq(status, expected); } START_TEST(trackpoint_palmdetect) { struct litest_device *trackpoint = litest_current_device(); struct litest_device *touchpad; struct libinput *li = trackpoint->libinput; int i; touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); if (has_disable_while_trackpointing(touchpad)) enable_dwtp(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(trackpoint, EV_REL, REL_X, 1); litest_event(trackpoint, EV_REL, REL_Y, 1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_touch_up(touchpad, 0); litest_assert_empty_queue(li); litest_timeout_trackpoint(); litest_dispatch(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(trackpoint_palmdetect_dwtp_disabled) { struct litest_device *trackpoint = litest_current_device(); struct litest_device *touchpad; struct libinput *li = trackpoint->libinput; int i; touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); if (has_disable_while_trackpointing(touchpad)) disable_dwtp(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(trackpoint, EV_REL, REL_X, 1); litest_event(trackpoint, EV_REL, REL_Y, 1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(trackpoint_palmdetect_resume_touch) { struct litest_device *trackpoint = litest_current_device(); struct litest_device *touchpad; struct libinput *li = trackpoint->libinput; int i; touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); if (has_disable_while_trackpointing(touchpad)) enable_dwtp(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (i = 0; i < 10; i++) { litest_event(trackpoint, EV_REL, REL_X, 1); litest_event(trackpoint, EV_REL, REL_Y, 1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); } litest_drain_events(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_assert_empty_queue(li); litest_timeout_trackpoint(); litest_dispatch(li); /* touch started after last tp event, expect resume */ litest_touch_move_to(touchpad, 0, 80, 80, 30, 30, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(trackpoint_palmdetect_require_min_events) { struct litest_device *trackpoint = litest_current_device(); struct litest_device *touchpad; struct libinput *li = trackpoint->libinput; touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); if (has_disable_while_trackpointing(touchpad)) enable_dwtp(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); /* A single event does not trigger palm detection */ litest_event(trackpoint, EV_REL, REL_X, 1); litest_event(trackpoint, EV_REL, REL_Y, 1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_drain_events(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_delete_device(touchpad); } END_TEST START_TEST(trackpoint_palmdetect_require_min_events_timeout) { struct litest_device *trackpoint = litest_current_device(); struct litest_device *touchpad; struct libinput *li = trackpoint->libinput; touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); if (has_disable_while_trackpointing(touchpad)) enable_dwtp(touchpad); litest_disable_hold_gestures(touchpad->libinput_device); litest_drain_events(li); for (int i = 0; i < 10; i++) { /* A single event does not trigger palm detection */ litest_event(trackpoint, EV_REL, REL_X, 1); litest_event(trackpoint, EV_REL, REL_Y, 1); litest_event(trackpoint, EV_SYN, SYN_REPORT, 0); litest_dispatch(li); litest_drain_events(li); litest_touch_down(touchpad, 0, 30, 30); litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10); litest_touch_up(touchpad, 0); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); litest_timeout_trackpoint(); } litest_delete_device(touchpad); } END_TEST TEST_COLLECTION(trackpoint) { litest_add(trackpoint_middlebutton, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_middlebutton_noscroll, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_scroll, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_scroll_source, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_topsoftbuttons_left_handed_trackpoint, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(trackpoint_topsoftbuttons_left_handed_touchpad, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(trackpoint_topsoftbuttons_left_handed_both, LITEST_TOPBUTTONPAD, LITEST_ANY); litest_add(trackpoint_palmdetect, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_palmdetect_dwtp_disabled, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_palmdetect_resume_touch, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_palmdetect_require_min_events, LITEST_POINTINGSTICK, LITEST_ANY); litest_add(trackpoint_palmdetect_require_min_events_timeout, LITEST_POINTINGSTICK, LITEST_ANY); } libinput-1.28.1/test/test-udev.c000066400000000000000000000416501477265155700165250ustar00rootroot00000000000000/* * Copyright © 2013 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include "litest.h" static int open_restricted(const char *path, int flags, void *data) { int fd; fd = open(path, flags); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *data) { close(fd); } static const struct libinput_interface simple_interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; START_TEST(udev_create_NULL) { struct libinput *li; struct udev *udev; udev = udev_new(); li = libinput_udev_create_context(NULL, NULL, NULL); litest_assert(li == NULL); li = libinput_udev_create_context(&simple_interface, NULL, NULL); litest_assert(li == NULL); li = libinput_udev_create_context(NULL, NULL, udev); litest_assert(li == NULL); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, NULL), -1); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_create_seat0) { struct libinput *li; struct libinput_event *event; struct udev *udev; int fd; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); fd = libinput_get_fd(li); litest_assert_int_ge(fd, 0); /* expect at least one event */ litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_create_empty_seat) { struct libinput *li; struct libinput_event *event; struct udev *udev; int fd; udev = udev_new(); litest_assert_notnull(udev); /* expect a libinput reference, but no events */ li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seatdoesntexist"), 0); fd = libinput_get_fd(li); litest_assert_int_ge(fd, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert(event == NULL); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_create_seat_too_long) { struct libinput *li; struct udev *udev; char seatname[258]; memset(seatname, 'a', sizeof(seatname) - 1); seatname[sizeof(seatname) - 1] = '\0'; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_set_log_handler_bug(li); litest_assert_int_eq(libinput_udev_assign_seat(li, seatname), -1); litest_assert_empty_queue(li); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_set_user_data) { struct libinput *li; struct udev *udev; int data1, data2; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, &data1, udev); litest_assert_notnull(li); litest_assert(libinput_get_user_data(li) == &data1); libinput_set_user_data(li, &data2); litest_assert(libinput_get_user_data(li) == &data2); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_added_seat_default) { struct libinput *li; struct libinput_event *event; struct udev *udev; struct libinput_device *device; struct libinput_seat *seat; const char *seat_name; struct litest_device *dev; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); /* Drop any events from other devices */ litest_drain_events(li); /* Now create our own device, it should be in the "default" * logical seat. This test may fail if there is a local rule changing * that, but it'll be fine for the 99% case. */ dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); event = libinput_get_event(li); device = libinput_event_get_device(event); seat = libinput_device_get_seat(device); litest_assert_notnull(seat); seat_name = libinput_seat_get_logical_name(seat); litest_assert_str_eq(seat_name, "default"); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); litest_delete_device(dev); } END_TEST START_TEST(udev_change_seat) { struct libinput *li; struct udev *udev; struct libinput_event *event; struct libinput_device *device; struct libinput_seat *seat1, *seat2; const char *seat1_name; const char *seat2_name = "new seat"; int rc; struct litest_device *dev; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); /* Drop any events from other devices */ litest_drain_events(li); /* Now create our own device, it should be in the "default" * logical seat. This test may fail if there is a local rule changing * that, but it'll be fine for the 99% case. */ dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); event = libinput_get_event(li); device = libinput_event_get_device(event); libinput_device_ref(device); seat1 = libinput_device_get_seat(device); libinput_seat_ref(seat1); seat1_name = libinput_seat_get_logical_name(seat1); libinput_event_destroy(event); litest_drain_events(li); /* Changing the logical seat name will remove and re-add the device */ rc = libinput_device_set_seat_logical_name(device, seat2_name); litest_assert_int_eq(rc, 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_REMOVED); litest_assert(libinput_event_get_device(event) == device); libinput_event_destroy(event); event = libinput_get_event(li); litest_assert_enum_eq(libinput_event_get_type(event), LIBINPUT_EVENT_DEVICE_ADDED); litest_assert(libinput_event_get_device(event) != device); libinput_device_unref(device); device = libinput_event_get_device(event); seat2 = libinput_device_get_seat(device); litest_assert_str_ne(libinput_seat_get_logical_name(seat2), seat1_name); litest_assert_str_eq(libinput_seat_get_logical_name(seat2), seat2_name); libinput_event_destroy(event); libinput_seat_unref(seat1); libinput_unref(li); udev_unref(udev); litest_delete_device(dev); } END_TEST START_TEST(udev_double_suspend) { struct libinput *li; struct libinput_event *event; struct udev *udev; int fd; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); fd = libinput_get_fd(li); litest_assert_int_ge(fd, 0); /* expect at least one event */ litest_assert_int_ge(litest_dispatch(li), 0); event = libinput_get_event(li); litest_assert_notnull(event); libinput_suspend(li); libinput_suspend(li); libinput_resume(li); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_double_resume) { struct libinput *li; struct libinput_event *event; struct udev *udev; int fd; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); fd = libinput_get_fd(li); litest_assert_int_ge(fd, 0); /* expect at least one event */ litest_assert_int_ge(litest_dispatch(li), 0); event = libinput_get_event(li); litest_assert_notnull(event); libinput_suspend(li); libinput_resume(li); libinput_resume(li); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); } END_TEST static void process_events_count_devices(struct libinput *li, int *device_count) { struct libinput_event *event; while ((event = libinput_get_event(li))) { switch (libinput_event_get_type(event)) { case LIBINPUT_EVENT_DEVICE_ADDED: (*device_count)++; break; case LIBINPUT_EVENT_DEVICE_REMOVED: (*device_count)--; break; default: break; } libinput_event_destroy(event); } } START_TEST(udev_suspend_resume) { struct libinput *li; struct udev *udev; int fd; int num_devices = 0; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); fd = libinput_get_fd(li); litest_assert_int_ge(fd, 0); /* Check that at least one device was discovered after creation. */ litest_assert_int_ge(litest_dispatch(li), 0); process_events_count_devices(li, &num_devices); litest_assert_int_gt(num_devices, 0); /* Check that after a suspend, no devices are left. */ libinput_suspend(li); litest_assert_int_ge(litest_dispatch(li), 0); process_events_count_devices(li, &num_devices); litest_assert_int_eq(num_devices, 0); /* Check that after a resume, at least one device is discovered. */ libinput_resume(li); litest_assert_int_ge(litest_dispatch(li), 0); process_events_count_devices(li, &num_devices); litest_assert_int_gt(num_devices, 0); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_resume_before_seat) { struct libinput *li; struct udev *udev; int rc; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); rc = libinput_resume(li); litest_assert_int_eq(rc, 0); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_suspend_resume_before_seat) { struct libinput *li; struct udev *udev; int rc; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); libinput_suspend(li); rc = libinput_resume(li); litest_assert_int_eq(rc, 0); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_device_sysname) { struct libinput *li; struct libinput_event *ev; struct libinput_device *device; const char *sysname; struct udev *udev; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); while ((ev = libinput_get_event(li))) { if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED) { libinput_event_destroy(ev); continue; } device = libinput_event_get_device(ev); sysname = libinput_device_get_sysname(device); litest_assert_notnull(sysname); litest_assert_int_gt(strlen(sysname), 1U); litest_assert(strchr(sysname, '/') == NULL); litest_assert(strstartswith(sysname, "event")); libinput_event_destroy(ev); } libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_seat_recycle) { struct udev *udev; struct libinput *li; struct libinput_event *ev; struct libinput_device *device; struct libinput_seat *saved_seat = NULL; struct libinput_seat *seat; int data = 0; int found = 0; void *user_data; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); while ((ev = libinput_get_event(li))) { switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_DEVICE_ADDED: if (saved_seat) break; device = libinput_event_get_device(ev); litest_assert_notnull(device); saved_seat = libinput_device_get_seat(device); libinput_seat_set_user_data(saved_seat, &data); libinput_seat_ref(saved_seat); break; default: break; } libinput_event_destroy(ev); } litest_assert_notnull(saved_seat); libinput_suspend(li); litest_drain_events(li); libinput_resume(li); litest_dispatch(li); while ((ev = libinput_get_event(li))) { switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_DEVICE_ADDED: device = libinput_event_get_device(ev); litest_assert_notnull(device); seat = libinput_device_get_seat(device); user_data = libinput_seat_get_user_data(seat); if (user_data == &data) { found = 1; litest_assert(seat == saved_seat); } break; default: break; } libinput_event_destroy(ev); } litest_assert(found == 1); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_path_add_device) { struct udev *udev; struct libinput *li; struct libinput_device *device; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_set_log_handler_bug(li); device = libinput_path_add_device(li, "/dev/input/event0"); litest_assert(device == NULL); litest_restore_log_handler(li); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_path_remove_device) { struct udev *udev; struct libinput *li; struct libinput_device *device; struct libinput_event *event; udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED); event = libinput_get_event(li); device = libinput_event_get_device(event); litest_assert_notnull(device); /* no effect bug a bug log msg */ litest_set_log_handler_bug(li); libinput_path_remove_device(device); litest_restore_log_handler(li); libinput_event_destroy(event); libinput_unref(li); udev_unref(udev); } END_TEST START_TEST(udev_ignore_device) { struct udev *udev; struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct litest_device *dev; const char *devname; dev = litest_create(LITEST_IGNORED_MOUSE, NULL, NULL, NULL, NULL); devname = libevdev_get_name(dev->evdev); udev = udev_new(); litest_assert_notnull(udev); li = libinput_udev_create_context(&simple_interface, NULL, udev); litest_assert_notnull(li); litest_restore_log_handler(li); litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); litest_dispatch(li); event = libinput_get_event(li); litest_assert_notnull(event); while (event) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_DEVICE_ADDED) { const char *name; device = libinput_event_get_device(event); name = libinput_device_get_name(device); litest_assert_str_ne(devname, name); } libinput_event_destroy(event); litest_dispatch(li); event = libinput_get_event(li); } libinput_unref(li); udev_unref(udev); litest_delete_device(dev); } END_TEST TEST_COLLECTION(udev) { litest_add_no_device(udev_create_NULL); litest_add_no_device(udev_create_seat0); litest_add_no_device(udev_create_empty_seat); litest_add_no_device(udev_create_seat_too_long); litest_add_no_device(udev_set_user_data); litest_add_no_device(udev_added_seat_default); litest_add_no_device(udev_change_seat); litest_add_for_device(udev_double_suspend, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_double_resume, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_suspend_resume, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_suspend_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_device_sysname, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_for_device(udev_seat_recycle, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_no_device(udev_path_add_device); litest_add_for_device(udev_path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); litest_add_no_device(udev_ignore_device); } libinput-1.28.1/test/test-util-includes.c000066400000000000000000000001251477265155700203330ustar00rootroot00000000000000/* compile test for the util files */ #include @FILE@ int main(void) { return 0; } libinput-1.28.1/test/test-utils.c000066400000000000000000001417751477265155700167330ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include "litest.h" #include "litest-runner.h" #include "util-list.h" #include "util-strings.h" #include "util-time.h" #include "util-prop-parsers.h" #include "util-macros.h" #include "util-bits.h" #include "util-range.h" #include "util-ratelimit.h" #include "util-stringbuf.h" #include "util-matrix.h" #include "util-input-event.h" #include "litest.h" #define TEST_VERSIONSORT #include "libinput-versionsort.h" START_TEST(array_for_each) { int ai[6]; char ac[10]; struct as { int a; char b; int *ptr; } as[32]; for (size_t i = 0; i < 6; i++) ai[i] = 20 + i; for (size_t i = 0; i < 10; i++) ac[i] = 100 + i; for (size_t i = 0; i < 32; i++) { as[i].a = 10 + i; as[i].b = 20 + i; as[i].ptr = (int*)0xab + i; } int iexpected = 20; ARRAY_FOR_EACH(ai, entry) { litest_assert_int_eq(*entry, iexpected); ++iexpected; } litest_assert_int_eq(iexpected, 26); int cexpected = 100; ARRAY_FOR_EACH(ac, entry) { litest_assert_int_eq(*entry, cexpected); ++cexpected; } litest_assert_int_eq(cexpected, 110); struct as sexpected = { .a = 10, .b = 20, .ptr = (int*)0xab, }; ARRAY_FOR_EACH(as, entry) { litest_assert_int_eq(entry->a, sexpected.a); litest_assert_int_eq(entry->b, sexpected.b); litest_assert_ptr_eq(entry->ptr, sexpected.ptr); ++sexpected.a; ++sexpected.b; ++sexpected.ptr; } litest_assert_int_eq(sexpected.a, 42); } END_TEST START_TEST(bitfield_helpers) { /* This value has a bit set on all of the word boundaries we want to * test: 0, 1, 7, 8, 31, 32, and 33 */ unsigned char read_bitfield[] = { 0x83, 0x1, 0x0, 0x80, 0x3 }; unsigned char write_bitfield[ARRAY_LENGTH(read_bitfield)] = {0}; size_t i; /* Now check that the bitfield we wrote to came out to be the same as * the bitfield we were writing from */ for (i = 0; i < ARRAY_LENGTH(read_bitfield) * 8; i++) { switch (i) { case 0: case 1: case 7: case 8: case 31: case 32: case 33: litest_assert(bit_is_set(read_bitfield, i)); set_bit(write_bitfield, i); break; default: litest_assert(!bit_is_set(read_bitfield, i)); clear_bit(write_bitfield, i); break; } } litest_assert_int_eq(memcmp(read_bitfield, write_bitfield, sizeof(read_bitfield)), 0); } END_TEST START_TEST(matrix_helpers) { struct matrix m1, m2, m3; float f[6] = { 1, 2, 3, 4, 5, 6 }; int x, y; int row, col; matrix_init_identity(&m1); for (row = 0; row < 3; row++) { for (col = 0; col < 3; col++) { litest_assert_int_eq(m1.val[row][col], (row == col) ? 1 : 0); } } litest_assert(matrix_is_identity(&m1)); matrix_from_farray6(&m2, f); litest_assert_int_eq(m2.val[0][0], 1); litest_assert_int_eq(m2.val[0][1], 2); litest_assert_int_eq(m2.val[0][2], 3); litest_assert_int_eq(m2.val[1][0], 4); litest_assert_int_eq(m2.val[1][1], 5); litest_assert_int_eq(m2.val[1][2], 6); litest_assert_int_eq(m2.val[2][0], 0); litest_assert_int_eq(m2.val[2][1], 0); litest_assert_int_eq(m2.val[2][2], 1); x = 100; y = 5; matrix_mult_vec(&m1, &x, &y); litest_assert_int_eq(x, 100); litest_assert_int_eq(y, 5); matrix_mult(&m3, &m1, &m1); litest_assert(matrix_is_identity(&m3)); matrix_init_scale(&m2, 2, 4); litest_assert_int_eq(m2.val[0][0], 2); litest_assert_int_eq(m2.val[0][1], 0); litest_assert_int_eq(m2.val[0][2], 0); litest_assert_int_eq(m2.val[1][0], 0); litest_assert_int_eq(m2.val[1][1], 4); litest_assert_int_eq(m2.val[1][2], 0); litest_assert_int_eq(m2.val[2][0], 0); litest_assert_int_eq(m2.val[2][1], 0); litest_assert_int_eq(m2.val[2][2], 1); matrix_mult_vec(&m2, &x, &y); litest_assert_int_eq(x, 200); litest_assert_int_eq(y, 20); matrix_init_translate(&m2, 10, 100); litest_assert_int_eq(m2.val[0][0], 1); litest_assert_int_eq(m2.val[0][1], 0); litest_assert_int_eq(m2.val[0][2], 10); litest_assert_int_eq(m2.val[1][0], 0); litest_assert_int_eq(m2.val[1][1], 1); litest_assert_int_eq(m2.val[1][2], 100); litest_assert_int_eq(m2.val[2][0], 0); litest_assert_int_eq(m2.val[2][1], 0); litest_assert_int_eq(m2.val[2][2], 1); matrix_mult_vec(&m2, &x, &y); litest_assert_int_eq(x, 210); litest_assert_int_eq(y, 120); matrix_to_farray6(&m2, f); litest_assert_int_eq(f[0], 1); litest_assert_int_eq(f[1], 0); litest_assert_int_eq(f[2], 10); litest_assert_int_eq(f[3], 0); litest_assert_int_eq(f[4], 1); litest_assert_int_eq(f[5], 100); } END_TEST START_TEST(ratelimit_helpers) { struct ratelimit rl; unsigned int i, j; /* 10 attempts every 1000ms */ ratelimit_init(&rl, ms2us(1000), 10); for (j = 0; j < 3; ++j) { /* a burst of 9 attempts must succeed */ for (i = 0; i < 9; ++i) { litest_assert_enum_eq(ratelimit_test(&rl), RATELIMIT_PASS); } /* the 10th attempt reaches the threshold */ litest_assert_enum_eq(ratelimit_test(&rl), RATELIMIT_THRESHOLD); /* ..then further attempts must fail.. */ litest_assert_enum_eq(ratelimit_test(&rl), RATELIMIT_EXCEEDED); /* ..regardless of how often we try. */ for (i = 0; i < 100; ++i) { litest_assert_enum_eq(ratelimit_test(&rl), RATELIMIT_EXCEEDED); } /* ..even after waiting 20ms */ msleep(100); for (i = 0; i < 100; ++i) { litest_assert_enum_eq(ratelimit_test(&rl), RATELIMIT_EXCEEDED); } /* but after 1000ms the counter is reset */ msleep(950); /* +50ms to account for time drifts */ } } END_TEST struct parser_test { char *tag; int expected_value; }; START_TEST(dpi_parser) { struct parser_test tests[] = { { "450 *1800 3200", 1800 }, { "*450 1800 3200", 450 }, { "450 1800 *3200", 3200 }, { "450 1800 3200", 3200 }, { "450 1800 failboat", 0 }, { "450 1800 *failboat", 0 }, { "0 450 1800 *3200", 0 }, { "450@37 1800@12 *3200@6", 3200 }, { "450@125 1800@125 *3200@125 ", 3200 }, { "450@125 *1800@125 3200@125", 1800 }, { "*this @string fails", 0 }, { "12@34 *45@", 0 }, { "12@a *45@", 0 }, { "12@a *45@25", 0 }, { " * 12, 450, 800", 0 }, { " *12, 450, 800", 12 }, { "*12, *450, 800", 12 }, { "*-23412, 450, 800", 0 }, { "112@125, 450@125, 800@125, 900@-125", 0 }, { "", 0 }, { " ", 0 }, { "* ", 0 }, { NULL, 0 } }; int i, dpi; for (i = 0; tests[i].tag != NULL; i++) { dpi = parse_mouse_dpi_property(tests[i].tag); litest_assert_int_eq(dpi, tests[i].expected_value); } dpi = parse_mouse_dpi_property(NULL); litest_assert_int_eq(dpi, 0); } END_TEST START_TEST(wheel_click_parser) { struct parser_test tests[] = { { "1", 1 }, { "10", 10 }, { "-12", -12 }, { "360", 360 }, { "0", 0 }, { "-0", 0 }, { "a", 0 }, { "10a", 0 }, { "10-", 0 }, { "sadfasfd", 0 }, { "361", 0 }, { NULL, 0 } }; int i, angle; for (i = 0; tests[i].tag != NULL; i++) { angle = parse_mouse_wheel_click_angle_property(tests[i].tag); litest_assert_int_eq(angle, tests[i].expected_value); } } END_TEST START_TEST(wheel_click_count_parser) { struct parser_test tests[] = { { "1", 1 }, { "10", 10 }, { "-12", -12 }, { "360", 360 }, { "0", 0 }, { "-0", 0 }, { "a", 0 }, { "10a", 0 }, { "10-", 0 }, { "sadfasfd", 0 }, { "361", 0 }, { NULL, 0 } }; int i, angle; for (i = 0; tests[i].tag != NULL; i++) { angle = parse_mouse_wheel_click_count_property(tests[i].tag); litest_assert_int_eq(angle, tests[i].expected_value); } angle = parse_mouse_wheel_click_count_property(NULL); litest_assert_int_eq(angle, 0); } END_TEST START_TEST(dimension_prop_parser) { struct parser_test_dimension { char *tag; bool success; size_t x, y; } tests[] = { { "10x10", true, 10, 10 }, { "1x20", true, 1, 20 }, { "1x8000", true, 1, 8000 }, { "238492x428210", true, 238492, 428210 }, { "0x0", false, 0, 0 }, { "-10x10", false, 0, 0 }, { "-1", false, 0, 0 }, { "1x-99", false, 0, 0 }, { "0", false, 0, 0 }, { "100", false, 0, 0 }, { "", false, 0, 0 }, { "abd", false, 0, 0 }, { "xabd", false, 0, 0 }, { "0xaf", false, 0, 0 }, { "0x0x", false, 0, 0 }, { "x10", false, 0, 0 }, { NULL, false, 0, 0 } }; int i; size_t x, y; bool success; for (i = 0; tests[i].tag != NULL; i++) { x = y = 0xad; success = parse_dimension_property(tests[i].tag, &x, &y); litest_assert(success == tests[i].success); if (success) { litest_assert_int_eq(x, tests[i].x); litest_assert_int_eq(y, tests[i].y); } else { litest_assert_int_eq(x, 0xadU); litest_assert_int_eq(y, 0xadU); } } success = parse_dimension_property(NULL, &x, &y); litest_assert(success == false); } END_TEST START_TEST(reliability_prop_parser) { struct parser_test_reliability { char *tag; bool success; enum switch_reliability reliability; } tests[] = { { "reliable", true, RELIABILITY_RELIABLE }, { "unreliable", true, RELIABILITY_UNRELIABLE }, { "write_open", true, RELIABILITY_WRITE_OPEN }, { "", false, 0 }, { "0", false, 0 }, { "1", false, 0 }, { NULL, false, 0, } }; enum switch_reliability r; bool success; int i; for (i = 0; tests[i].tag != NULL; i++) { r = 0xaf; success = parse_switch_reliability_property(tests[i].tag, &r); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(r, tests[i].reliability); else litest_assert_int_eq(r, 0xafU); } success = parse_switch_reliability_property(NULL, &r); litest_assert(success == true); litest_assert_enum_eq(r, RELIABILITY_RELIABLE); success = parse_switch_reliability_property("foo", NULL); litest_assert(success == false); } END_TEST START_TEST(calibration_prop_parser) { #define DEFAULT_VALUES { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 } const float untouched[6] = DEFAULT_VALUES; struct parser_test_calibration { char *prop; bool success; float values[6]; } tests[] = { { "", false, DEFAULT_VALUES }, { "banana", false, DEFAULT_VALUES }, { "1 2 3 a 5 6", false, DEFAULT_VALUES }, { "2", false, DEFAULT_VALUES }, { "2 3 4 5 6", false, DEFAULT_VALUES }, { "1 2 3 4 5 6", true, DEFAULT_VALUES }, { "6.00012 3.244 4.238 5.2421 6.0134 8.860", true, { 6.00012, 3.244, 4.238, 5.2421, 6.0134, 8.860 }}, { "0xff 2 3 4 5 6", false, DEFAULT_VALUES }, { NULL, false, DEFAULT_VALUES } }; bool success; float calibration[6]; int rc; int i; for (i = 0; tests[i].prop != NULL; i++) { memcpy(calibration, untouched, sizeof(calibration)); success = parse_calibration_property(tests[i].prop, calibration); litest_assert_int_eq(success, tests[i].success); if (success) rc = memcmp(tests[i].values, calibration, sizeof(calibration)); else rc = memcmp(untouched, calibration, sizeof(calibration)); litest_assert_int_eq(rc, 0); } memcpy(calibration, untouched, sizeof(calibration)); success = parse_calibration_property(NULL, calibration); litest_assert(success == false); rc = memcmp(untouched, calibration, sizeof(calibration)); litest_assert_int_eq(rc, 0); } END_TEST START_TEST(range_prop_parser) { struct parser_test_range { char *tag; bool success; int hi, lo; } tests[] = { { "10:8", true, 10, 8 }, { "100:-1", true, 100, -1 }, { "-203813:-502023", true, -203813, -502023 }, { "238492:28210", true, 238492, 28210 }, { "none", true, 0, 0 }, { "0:0", false, 0, 0 }, { "", false, 0, 0 }, { "abcd", false, 0, 0 }, { "10:30:10", false, 0, 0 }, { NULL, false, 0, 0 } }; int i; int hi, lo; bool success; for (i = 0; tests[i].tag != NULL; i++) { hi = lo = 0xad; success = parse_range_property(tests[i].tag, &hi, &lo); litest_assert(success == tests[i].success); if (success) { litest_assert_int_eq(hi, tests[i].hi); litest_assert_int_eq(lo, tests[i].lo); } else { litest_assert_int_eq(hi, 0xad); litest_assert_int_eq(lo, 0xad); } } success = parse_range_property(NULL, NULL, NULL); litest_assert(success == false); } END_TEST START_TEST(boolean_prop_parser) { struct parser_test_range { char *tag; bool success; bool b; } tests[] = { { "0", true, false }, { "1", true, true }, { "-1", false, false }, { "2", false, false }, { "abcd", false, false }, { NULL, false, false } }; int i; bool success, b; for (i = 0; tests[i].tag != NULL; i++) { b = false; success = parse_boolean_property(tests[i].tag, &b); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(b, tests[i].b); else litest_assert_int_eq(b, false); } success = parse_boolean_property(NULL, NULL); litest_assert(success == false); } END_TEST START_TEST(evcode_prop_parser) { struct parser_test_tuple { const char *prop; bool success; size_t nevents; struct input_event events[20]; } tests[] = { { "+EV_KEY", true, 1, {{ .type = EV_KEY, .code = 0xffff, .value = 1 }} }, { "-EV_ABS;", true, 1, {{ .type = EV_ABS, .code = 0xffff, .value = 0 }} }, { "+ABS_X;", true, 1, {{ .type = EV_ABS, .code = ABS_X, .value = 1 }} }, { "-SW_TABLET_MODE;", true, 1, {{ .type = EV_SW, .code = SW_TABLET_MODE, .value = 0 }} }, { "+EV_SW", true, 1, {{ .type = EV_SW, .code = 0xffff, .value = 1 }} }, { "-ABS_Y", true, 1, {{ .type = EV_ABS, .code = ABS_Y, .value = 0 }} }, { "+EV_ABS:0x00", true, 1, {{ .type = EV_ABS, .code = ABS_X, .value = 1 }} }, { "-EV_ABS:01", true, 1, {{ .type = EV_ABS, .code = ABS_Y, .value = 0 }} }, { "+ABS_TILT_X;-ABS_TILT_Y;", true, 2, {{ .type = EV_ABS, .code = ABS_TILT_X, .value = 1 }, { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0}} }, { "+BTN_TOOL_DOUBLETAP;+EV_KEY;-KEY_A", true, 3, {{ .type = EV_KEY, .code = BTN_TOOL_DOUBLETAP, .value = 1 } , { .type = EV_KEY, .code = 0xffff, .value = 1 }, { .type = EV_KEY, .code = KEY_A, .value = 0 }} }, { "+REL_Y;-ABS_Z;+BTN_STYLUS", true, 3, {{ .type = EV_REL, .code = REL_Y, .value = 1}, { .type = EV_ABS, .code = ABS_Z, .value = 0}, { .type = EV_KEY, .code = BTN_STYLUS, .value = 1 }} }, { "-REL_Y;+EV_KEY:0x123;-BTN_STYLUS", true, 3, {{ .type = EV_REL, .code = REL_Y, .value = 0 }, { .type = EV_KEY, .code = 0x123, .value = 1 }, { .type = EV_KEY, .code = BTN_STYLUS, .value = 0 }} }, { .prop = "", .success = false }, { .prop = "+", .success = false }, { .prop = "-", .success = false }, { .prop = "!", .success = false }, { .prop = "+EV_FOO", .success = false }, { .prop = "+EV_KEY;-EV_FOO", .success = false }, { .prop = "+BTN_STYLUS;-EV_FOO", .success = false }, { .prop = "-BTN_UNKNOWN", .success = false }, { .prop = "+BTN_UNKNOWN;+EV_KEY", .success = false }, { .prop = "-PR_UNKNOWN", .success = false }, { .prop = "-BTN_STYLUS;+PR_UNKNOWN;-ABS_X", .success = false }, { .prop = "-EV_REL:0xffff", .success = false }, { .prop = "-EV_REL:0x123.", .success = false }, { .prop = "-EV_REL:ffff", .success = false }, { .prop = "-EV_REL:blah", .success = false }, { .prop = "+KEY_A:0x11", .success = false }, { .prop = "+EV_KEY:0x11 ", .success = false }, { .prop = "+EV_KEY:0x11not", .success = false }, { .prop = "none", .success = false }, { .prop = NULL }, }; struct parser_test_tuple *t; for (int i = 0; tests[i].prop; i++) { bool success; struct input_event events[32]; size_t nevents = ARRAY_LENGTH(events); t = &tests[i]; success = parse_evcode_property(t->prop, events, &nevents); litest_assert(success == t->success); if (!success) continue; litest_assert_int_eq(nevents, t->nevents); for (size_t j = 0; j < nevents; j++) { unsigned int type = events[j].type; unsigned int code = events[j].code; int value = events[j].value; litest_assert_int_eq(t->events[j].type, type); litest_assert_int_eq(t->events[j].code, code); litest_assert_int_eq(t->events[j].value, value); } } } END_TEST START_TEST(input_prop_parser) { struct parser_test_val { const char *prop; bool success; size_t nvals; struct input_prop values[20]; } tests[] = { { "+INPUT_PROP_BUTTONPAD", true, 1, {{ INPUT_PROP_BUTTONPAD, true }}}, { "+INPUT_PROP_BUTTONPAD;-INPUT_PROP_POINTER", true, 2, { { INPUT_PROP_BUTTONPAD, true }, { INPUT_PROP_POINTER, false }}}, { "+INPUT_PROP_BUTTONPAD;-0x00;+0x03", true, 3, { { INPUT_PROP_BUTTONPAD, true }, { INPUT_PROP_POINTER, false }, { INPUT_PROP_SEMI_MT, true }}}, { .prop = "", .success = false }, { .prop = "0xff", .success = false }, { .prop = "INPUT_PROP", .success = false }, { .prop = "INPUT_PROP_FOO", .success = false }, { .prop = "INPUT_PROP_FOO;INPUT_PROP_FOO", .success = false }, { .prop = "INPUT_PROP_POINTER;INPUT_PROP_FOO", .success = false }, { .prop = "none", .success = false }, { .prop = NULL }, }; struct parser_test_val *t; for (int i = 0; tests[i].prop; i++) { bool success; struct input_prop props[32]; size_t nprops = ARRAY_LENGTH(props); t = &tests[i]; success = parse_input_prop_property(t->prop, props, &nprops); litest_assert(success == t->success); if (!success) continue; litest_assert_int_eq(nprops, t->nvals); for (size_t j = 0; j < t->nvals; j++) { litest_assert_int_eq(t->values[j].prop, props[j].prop); litest_assert_int_eq(t->values[j].enabled, props[j].enabled); } } } END_TEST START_TEST(evdev_abs_parser) { struct test { uint32_t which; const char *prop; int min, max, res, fuzz, flat; } tests[] = { { .which = (ABS_MASK_MIN|ABS_MASK_MAX), .prop = "1:2", .min = 1, .max = 2 }, { .which = (ABS_MASK_MIN|ABS_MASK_MAX), .prop = "1:2:", .min = 1, .max = 2 }, { .which = (ABS_MASK_MIN|ABS_MASK_MAX|ABS_MASK_RES), .prop = "10:20:30", .min = 10, .max = 20, .res = 30 }, { .which = (ABS_MASK_RES), .prop = "::100", .res = 100 }, { .which = (ABS_MASK_MIN), .prop = "10:", .min = 10 }, { .which = (ABS_MASK_MAX|ABS_MASK_RES), .prop = ":10:1001", .max = 10, .res = 1001 }, { .which = (ABS_MASK_MIN|ABS_MASK_MAX|ABS_MASK_RES|ABS_MASK_FUZZ), .prop = "1:2:3:4", .min = 1, .max = 2, .res = 3, .fuzz = 4}, { .which = (ABS_MASK_MIN|ABS_MASK_MAX|ABS_MASK_RES|ABS_MASK_FUZZ|ABS_MASK_FLAT), .prop = "1:2:3:4:5", .min = 1, .max = 2, .res = 3, .fuzz = 4, .flat = 5}, { .which = (ABS_MASK_MIN|ABS_MASK_RES|ABS_MASK_FUZZ|ABS_MASK_FLAT), .prop = "1::3:4:50", .min = 1, .res = 3, .fuzz = 4, .flat = 50}, { .which = ABS_MASK_FUZZ|ABS_MASK_FLAT, .prop = ":::5:60", .fuzz = 5, .flat = 60}, { .which = ABS_MASK_FUZZ, .prop = ":::5:", .fuzz = 5 }, { .which = ABS_MASK_RES, .prop = "::12::", .res = 12 }, /* Malformed property but parsing this one makes us more * future proof */ { .which = (ABS_MASK_RES|ABS_MASK_FUZZ|ABS_MASK_FLAT), .prop = "::12:1:2:3:4:5:6", .res = 12, .fuzz = 1, .flat = 2 }, { .which = 0, .prop = ":::::" }, { .which = 0, .prop = ":" }, { .which = 0, .prop = "" }, { .which = 0, .prop = ":asb::::" }, { .which = 0, .prop = "foo" }, }; ARRAY_FOR_EACH(tests, t) { struct input_absinfo abs; uint32_t mask; mask = parse_evdev_abs_prop(t->prop, &abs); litest_assert_int_eq(mask, t->which); if (t->which & ABS_MASK_MIN) litest_assert_int_eq(abs.minimum, t->min); if (t->which & ABS_MASK_MAX) litest_assert_int_eq(abs.maximum, t->max); if (t->which & ABS_MASK_RES) litest_assert_int_eq(abs.resolution, t->res); if (t->which & ABS_MASK_FUZZ) litest_assert_int_eq(abs.fuzz, t->fuzz); if (t->which & ABS_MASK_FLAT) litest_assert_int_eq(abs.flat, t->flat); } } END_TEST START_TEST(time_conversion) { litest_assert_int_eq(us(10), 10U); litest_assert_int_eq(ns2us(10000), 10U); litest_assert_int_eq(ms2us(10), 10000U); litest_assert_int_eq(s2us(1), 1000000U); litest_assert_int_eq(h2us(2), s2us(2 * 60 * 60)); litest_assert_int_eq(us2ms(10000), 10U); } END_TEST START_TEST(human_time) { struct ht_tests { uint64_t interval; unsigned int value; const char *unit; } tests[] = { { 0, 0, "us" }, { 123, 123, "us" }, { ms2us(5), 5, "ms" }, { ms2us(100), 100, "ms" }, { s2us(5), 5, "s" }, { s2us(100), 100, "s" }, { s2us(120), 2, "min" }, { 5 * s2us(60), 5, "min" }, { 120 * s2us(60), 2, "h" }, { 5 * 60 * s2us(60), 5, "h" }, { 48 * 60 * s2us(60), 2, "d" }, { 1000 * 24 * 60 * s2us(60), 1000, "d" }, { 0, 0, NULL }, }; for (int i = 0; tests[i].unit != NULL; i++) { struct human_time ht; ht = to_human_time(tests[i].interval); litest_assert_int_eq(ht.value, tests[i].value); litest_assert_str_eq(ht.unit, tests[i].unit); } } END_TEST struct atoi_test { char *str; bool success; int val; }; START_TEST(safe_atoi_test) { struct atoi_test tests[] = { { "10", true, 10 }, { "20", true, 20 }, { "-1", true, -1 }, { "2147483647", true, 2147483647 }, { "-2147483648", true, -2147483648 }, { "4294967295", false, 0 }, { "0x0", false, 0 }, { "-10x10", false, 0 }, { "1x-99", false, 0 }, { "", false, 0 }, { "abd", false, 0 }, { "xabd", false, 0 }, { "0xaf", false, 0 }, { "0x0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atoi(tests[i].str, &v); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xad); } } END_TEST START_TEST(safe_atoi_base_16_test) { struct atoi_test tests[] = { { "10", true, 0x10 }, { "20", true, 0x20 }, { "-1", true, -1 }, { "0x10", true, 0x10 }, { "0xff", true, 0xff }, { "abc", true, 0xabc }, { "-10", true, -0x10 }, { "0x0", true, 0 }, { "0", true, 0 }, { "0x-99", false, 0 }, { "0xak", false, 0 }, { "0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atoi_base(tests[i].str, &v, 16); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xad); } } END_TEST START_TEST(safe_atoi_base_8_test) { struct atoi_test tests[] = { { "7", true, 07 }, { "10", true, 010 }, { "20", true, 020 }, { "-1", true, -1 }, { "010", true, 010 }, { "0ff", false, 0 }, { "abc", false, 0}, { "0xabc", false, 0}, { "-10", true, -010 }, { "0", true, 0 }, { "00", true, 0 }, { "0x0", false, 0 }, { "0x-99", false, 0 }, { "0xak", false, 0 }, { "0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atoi_base(tests[i].str, &v, 8); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xad); } } END_TEST struct atou_test { char *str; bool success; unsigned int val; }; START_TEST(safe_atou_test) { struct atou_test tests[] = { { "10", true, 10 }, { "20", true, 20 }, { "-1", false, 0 }, { "2147483647", true, 2147483647 }, { "-2147483648", false, 0}, { "0x0", false, 0 }, { "-10x10", false, 0 }, { "1x-99", false, 0 }, { "", false, 0 }, { "abd", false, 0 }, { "xabd", false, 0 }, { "0xaf", false, 0 }, { "0x0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; unsigned int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atou(tests[i].str, &v); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xadU); } } END_TEST START_TEST(safe_atou_base_16_test) { struct atou_test tests[] = { { "10", true, 0x10 }, { "20", true, 0x20 }, { "-1", false, 0 }, { "0x10", true, 0x10 }, { "0xff", true, 0xff }, { "abc", true, 0xabc }, { "-10", false, 0 }, { "0x0", true, 0 }, { "0", true, 0 }, { "0x-99", false, 0 }, { "0xak", false, 0 }, { "0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; unsigned int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atou_base(tests[i].str, &v, 16); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xadU); } } END_TEST START_TEST(safe_atou_base_8_test) { struct atou_test tests[] = { { "7", true, 07 }, { "10", true, 010 }, { "20", true, 020 }, { "-1", false, 0 }, { "010", true, 010 }, { "0ff", false, 0 }, { "abc", false, 0}, { "0xabc", false, 0}, { "-10", false, 0 }, { "0", true, 0 }, { "00", true, 0 }, { "0x0", false, 0 }, { "0x-99", false, 0 }, { "0xak", false, 0 }, { "0x", false, 0 }, { "x10", false, 0 }, { NULL, false, 0 } }; unsigned int v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atou_base(tests[i].str, &v, 8); litest_assert(success == tests[i].success); if (success) litest_assert_int_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xadU); } } END_TEST START_TEST(safe_atod_test) { struct atod_test { char *str; bool success; double val; } tests[] = { { "10", true, 10 }, { "20", true, 20 }, { "-1", true, -1 }, { "2147483647", true, 2147483647 }, { "-2147483648", true, -2147483648 }, { "4294967295", true, 4294967295 }, { "0x0", false, 0 }, { "0x10", false, 0 }, { "0xaf", false, 0 }, { "x80", false, 0 }, { "0.0", true, 0.0 }, { "0.1", true, 0.1 }, { "1.2", true, 1.2 }, { "-324.9", true, -324.9 }, { "9324.9", true, 9324.9 }, { "NAN", false, 0 }, { "INFINITY", false, 0 }, { "-10x10", false, 0 }, { "1x-99", false, 0 }, { "", false, 0 }, { "abd", false, 0 }, { "xabd", false, 0 }, { "0x0x", false, 0 }, { NULL, false, 0 } }; double v; bool success; for (int i = 0; tests[i].str != NULL; i++) { v = 0xad; success = safe_atod(tests[i].str, &v); litest_assert(success == tests[i].success); if (success) litest_assert_double_eq(v, tests[i].val); else litest_assert_int_eq(v, 0xad); } } END_TEST START_TEST(strsplit_test) { struct strsplit_test { const char *string; const char *delim; const char *results[10]; const size_t nresults; } tests[] = { { "one two three", " ", { "one", "two", "three", NULL }, 3 }, { "one two\tthree", " \t", { "one", "two", "three", NULL }, 3 }, { "one", " ", { "one", NULL }, 1 }, { "one two ", " ", { "one", "two", NULL }, 2 }, { "one two", " ", { "one", "two", NULL }, 2 }, { " one two", " ", { "one", "two", NULL }, 2 }, { "one", "\t \r", { "one", NULL }, 1 }, { "one two three", " t", { "one", "wo", "hree", NULL }, 3 }, { " one two three", "te", { " on", " ", "wo ", "hr", NULL }, 4 }, { "one", "ne", { "o", NULL }, 1 }, { "onene", "ne", { "o", NULL }, 1 }, { "+1-2++3--4++-+5-+-", "+-", { "1", "2", "3", "4", "5", NULL }, 5 }, /* special cases */ { "", " ", { NULL }, 0 }, { " ", " ", { NULL }, 0 }, { " ", " ", { NULL }, 0 }, { "oneoneone", "one", { NULL} , 0 }, { NULL, NULL, { NULL }, 0} }; struct strsplit_test *t = tests; while (t->string) { size_t nelem; char **strv = strv_from_string(t->string, t->delim, &nelem); for (size_t idx = 0; idx < t->nresults; idx++) litest_assert_str_eq(t->results[idx], strv[idx]); litest_assert_int_eq(nelem, t->nresults); /* When there are no elements validate return value is Null, otherwise validate result array is Null terminated. */ if(t->nresults == 0) litest_assert_ptr_eq(strv, NULL); else litest_assert_ptr_eq(strv[t->nresults], NULL); strv_free(strv); t++; } } END_TEST struct strv_test_data { const char *terminate_at; unsigned char bitmask[1]; }; static int strv_test_set_bitmask(const char *str, size_t index, void *data) { struct strv_test_data *td = data; if (streq(str, td->terminate_at)) return index + 1; set_bit(td->bitmask, index); return 0; } START_TEST(strv_for_each_test) { struct test_data { const char *terminator; int index; unsigned int bitmask; } test_data[] = { { "one", 1, 0x0 }, { "two", 2, 0x1 }, { "three", 3, 0x3 }, { "four", 4, 0x7 }, { "five", 5, 0xf }, { "does-not-exist", 0, 0x1f }, { NULL, 0, 0x1f }, { NULL, 0 }, }; const char *array[] = { "one", "two", "three", "four", "five", NULL }; struct test_data *t = test_data; while (t->terminator || t->bitmask) { const int max = 3; struct strv_test_data td = { .terminate_at = t->terminator, .bitmask = { 0 }, }; int rc = strv_for_each(array, strv_test_set_bitmask, &td); litest_assert_int_eq(rc, t->index); litest_assert_int_eq(td.bitmask[0], t->bitmask); struct strv_test_data tdmax = { .terminate_at = t->terminator, .bitmask = { 0 }, }; rc = strv_for_each_n(array, max, strv_test_set_bitmask, &tdmax); if (max < t->index) litest_assert_int_eq(rc, 0); else litest_assert_int_eq(rc, t->index); litest_assert_int_eq(tdmax.bitmask[0], t->bitmask & ((1 << max) - 1)); t++; } } END_TEST START_TEST(double_array_from_string_test) { struct double_array_from_string_test { const char *string; const char *delim; const double array[10]; const size_t len; const bool result; } tests[] = { { "1 2 3", " ", { 1, 2, 3 }, 3 }, { "1", " ", { 1 }, 1 }, { "1,2.5,", ",", { 1, 2.5 }, 2 }, { "1.0 2", " ", { 1, 2.0 }, 2 }, { " 1 2", " ", { 1, 2 }, 2 }, { " ; 1;2 3.5 ;;4.1", "; ", { 1, 2, 3.5, 4.1 }, 4 }, /* special cases */ { "1 two", " ", { 0 }, 0 }, { "one two", " ", { 0 }, 0 }, { "one 2", " ", { 0 }, 0 }, { "", " ", { 0 }, 0 }, { " ", " ", { 0 }, 0 }, { " ", " ", { 0 }, 0 }, { "", " ", { 0 }, 0 }, { "oneoneone", "one", { 0 }, 0 }, { NULL, NULL, { 0 }, 0 } }; struct double_array_from_string_test *t = tests; while (t->string) { size_t len; double *array = double_array_from_string(t->string, t->delim, &len); litest_assert_int_eq(len, t->len); for (size_t idx = 0; idx < len; idx++) { litest_assert_ptr_notnull(array); litest_assert_double_eq(array[idx], t->array[idx]); } free(array); t++; } } END_TEST START_TEST(strargv_test) { struct argv_test { int argc; char *argv[10]; int expected; } tests[] = { { 0, {NULL}, 0 }, { 1, {"hello", "World"}, 1 }, { 2, {"hello", "World"}, 2 }, { 2, {"", " "}, 2 }, { 2, {"", NULL}, 0 }, { 2, {NULL, NULL}, 0 }, { 1, {NULL, NULL}, 0 }, { 3, {"hello", NULL, "World"}, 0 }, }; ARRAY_FOR_EACH(tests, t) { char **strv = strv_from_argv(t->argc, t->argv); if (t->expected == 0) { litest_assert(strv == NULL); } else { int count = 0; char **s = strv; while (*s) { litest_assert_str_eq(*s, t->argv[count]); count++; s++; } litest_assert_int_eq(t->expected, count); strv_free(strv); } } } END_TEST START_TEST(kvsplit_double_test) { struct kvsplit_dbl_test { const char *string; const char *psep; const char *kvsep; ssize_t nresults; struct { double a; double b; } results[32]; } tests[] = { { "1:2;3:4;5:6", ";", ":", 3, { {1, 2}, {3, 4}, {5, 6}}}, { "1.0x2.3 -3.2x4.5 8.090909x-6.00", " ", "x", 3, { {1.0, 2.3}, {-3.2, 4.5}, {8.090909, -6}}}, { "1:2", "x", ":", 1, {{1, 2}}}, { "1:2", ":", "x", -1, {}}, { "1:2", NULL, "x", -1, {}}, { "1:2", "", "x", -1, {}}, { "1:2", "x", NULL, -1, {}}, { "1:2", "x", "", -1, {}}, { "a:b", "x", ":", -1, {}}, { "", " ", "x", -1, {}}, { "1.2.3.4.5", ".", "", -1, {}}, { NULL } }; struct kvsplit_dbl_test *t = tests; while (t->string) { struct key_value_double *result = NULL; ssize_t npairs; npairs = kv_double_from_string(t->string, t->psep, t->kvsep, &result); litest_assert_int_eq(npairs, t->nresults); for (ssize_t i = 0; i < npairs; i++) { litest_assert_double_eq(t->results[i].a, result[i].key); litest_assert_double_eq(t->results[i].b, result[i].value); } free(result); t++; } } END_TEST START_TEST(strjoin_test) { struct strjoin_test { char *strv[10]; const char *joiner; const char *result; } tests[] = { { { "one", "two", "three", NULL }, " ", "one two three" }, { { "one", NULL }, "x", "one" }, { { "one", "two", NULL }, "x", "onextwo" }, { { "one", "two", NULL }, ",", "one,two" }, { { "one", "two", NULL }, ", ", "one, two" }, { { "one", "two", NULL }, "one", "oneonetwo" }, { { "one", "two", NULL }, NULL, NULL }, { { "", "", "", NULL }, " ", " " }, { { "a", "b", "c", NULL }, "", "abc" }, { { "", "b", "c", NULL }, "x", "xbxc" }, { { "", "", "", NULL }, "", "" }, { { NULL }, NULL, NULL } }; struct strjoin_test *t = tests; struct strjoin_test nulltest = { {NULL}, "x", NULL }; while (t->strv[0]) { char *str; str = strv_join(t->strv, t->joiner); if (t->result == NULL) litest_assert(str == NULL); else litest_assert_str_eq(str, t->result); free(str); t++; } litest_assert(strv_join(nulltest.strv, "x") == NULL); } END_TEST START_TEST(strstrip_test) { struct strstrip_test { const char *string; const char *expected; const char *what; } tests[] = { { "foo", "foo", "1234" }, { "\"bar\"", "bar", "\"" }, { "'bar'", "bar", "'" }, { "\"bar\"", "\"bar\"", "'" }, { "'bar'", "'bar'", "\"" }, { "\"bar\"", "bar", "\"" }, { "\"\"", "", "\"" }, { "\"foo\"bar\"", "foo\"bar", "\"" }, { "\"'foo\"bar\"", "foo\"bar", "\"'" }, { "abcfooabcbarbca", "fooabcbar", "abc" }, { "xxxxfoo", "foo", "x" }, { "fooyyyy", "foo", "y" }, { "xxxxfooyyyy", "foo", "xy" }, { "x xfooy y", " xfooy ", "xy" }, { " foo\n", "foo", " \n" }, { "", "", "abc" }, { "", "", "" }, { NULL , NULL, NULL } }; struct strstrip_test *t = tests; while (t->string) { char *str; str = strstrip(t->string, t->what); litest_assert_str_eq(str, t->expected); free(str); t++; } } END_TEST START_TEST(strendswith_test) { struct strendswith_test { const char *string; const char *suffix; bool expected; } tests[] = { { "foobar", "bar", true }, { "foobar", "foo", false }, { "foobar", "foobar", true }, { "foo", "foobar", false }, { "foobar", "", false }, { "", "", false }, { "", "foo", false }, { NULL, NULL, false }, }; for (struct strendswith_test *t = tests; t->string; t++) { litest_assert_int_eq(strendswith(t->string, t->suffix), t->expected); } } END_TEST START_TEST(strstartswith_test) { struct strstartswith_test { const char *string; const char *suffix; bool expected; } tests[] = { { "foobar", "foo", true }, { "foobar", "bar", false }, { "foobar", "foobar", true }, { "foo", "foobar", false }, { "foo", "", false }, { "", "", false }, { "foo", "", false }, { NULL, NULL, false }, }; for (struct strstartswith_test *t = tests; t->string; t++) { litest_assert_int_eq(strstartswith(t->string, t->suffix), t->expected); } } END_TEST START_TEST(strsanitize_test) { struct strsanitize_test { const char *string; const char *expected; } tests[] = { { "foobar", "foobar" }, { "", "" }, { "%", "%%" }, { "%%%%", "%%%%%%%%" }, { "x %s", "x %%s" }, { "x %", "x %%" }, { "%sx", "%%sx" }, { "%s%s", "%%s%%s" }, { NULL, NULL }, }; for (struct strsanitize_test *t = tests; t->string; t++) { char *sanitized = str_sanitize(t->string); litest_assert_str_eq(sanitized, t->expected); free(sanitized); } } END_TEST START_TEST(list_test_insert) { struct list_test { int val; struct list node; } tests[] = { { .val = 1 }, { .val = 2 }, { .val = 3 }, { .val = 4 }, }; struct list_test *t; struct list head; int val; list_init(&head); ARRAY_FOR_EACH(tests, t) { list_insert(&head, &t->node); } val = 4; list_for_each(t, &head, node) { litest_assert_int_eq(t->val, val); val--; } litest_assert_int_eq(val, 0); } END_TEST START_TEST(list_test_append) { struct list_test { int val; struct list node; } tests[] = { { .val = 1 }, { .val = 2 }, { .val = 3 }, { .val = 4 }, }; struct list_test *t; struct list head; int val; list_init(&head); ARRAY_FOR_EACH(tests, t) { list_append(&head, &t->node); } val = 1; list_for_each(t, &head, node) { litest_assert_int_eq(t->val, val); val++; } litest_assert_int_eq(val, 5); } END_TEST START_TEST(list_test_foreach) { struct list_test { int val; struct list node; } tests[] = { { .val = 1 }, { .val = 2 }, { .val = 3 }, { .val = 4 }, }; struct list_test *t; struct list head; list_init(&head); ARRAY_FOR_EACH(tests, t) { list_append(&head, &t->node); } /* Make sure both loop macros are a single line statement */ if (false) list_for_each(t, &head, node) { litest_abort_msg("We should not get here"); } if (false) list_for_each_safe(t, &head, node) { litest_abort_msg("We should not get here"); } } END_TEST START_TEST(strverscmp_test) { litest_assert_int_eq(libinput_strverscmp("", ""), 0); litest_assert_int_gt(libinput_strverscmp("0.0.1", ""), 0); litest_assert_int_lt(libinput_strverscmp("", "0.0.1"), 0); litest_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.1"), 0); litest_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.2"), -1); litest_assert_int_eq(libinput_strverscmp("0.0.2", "0.0.1"), 1); litest_assert_int_eq(libinput_strverscmp("0.0.1", "0.1.0"), -1); litest_assert_int_eq(libinput_strverscmp("0.1.0", "0.0.1"), 1); } END_TEST START_TEST(streq_test) { litest_assert(streq("", "") == true); litest_assert(streq(NULL, NULL) == true); litest_assert(streq("0.0.1", "") == false); litest_assert(streq("foo", NULL) == false); litest_assert(streq(NULL, "foo") == false); litest_assert(streq("0.0.1", "0.0.1") == true); } END_TEST START_TEST(strneq_test) { litest_assert(strneq("", "", 1) == true); litest_assert(strneq(NULL, NULL, 1) == true); litest_assert(strneq("0.0.1", "", 6) == false); litest_assert(strneq("foo", NULL, 5) == false); litest_assert(strneq(NULL, "foo", 5) == false); litest_assert(strneq("0.0.1", "0.0.1", 6) == true); } END_TEST START_TEST(basename_test) { struct test { const char *path; const char *expected; } tests[] = { { "a", "a" }, { "foo.c", "foo.c" }, { "foo", "foo" }, { "/path/to/foo.h", "foo.h" }, { "../bar.foo", "bar.foo" }, { "./bar.foo.baz", "bar.foo.baz" }, { "./", NULL }, { "/", NULL }, { "/bar/", NULL }, { "/bar", "bar" }, { "", NULL }, }; ARRAY_FOR_EACH(tests, t) { const char *result = safe_basename(t->path); if (t->expected == NULL) litest_assert(result == NULL); else litest_assert_str_eq(result, t->expected); } } END_TEST START_TEST(trunkname_test) { struct test { const char *path; const char *expected; } tests[] = { { "foo.c", "foo" }, { "/path/to/foo.h", "foo" }, { "/path/to/foo", "foo" }, { "../bar.foo", "bar" }, { "./bar.foo.baz", "bar.foo" }, { "./", "" }, { "/", "" }, { "/bar/", "" }, { "/bar", "bar" }, { "", "" }, }; ARRAY_FOR_EACH(tests, t) { char *result = trunkname(t->path); litest_assert_str_eq(result, t->expected); free(result); } } END_TEST START_TEST(absinfo_normalize_value_test) { struct input_absinfo abs = { .minimum = 0, .maximum = 100, }; litest_assert_double_eq(absinfo_normalize_value(&abs, -100), 0.0); litest_assert_double_eq(absinfo_normalize_value(&abs, -1), 0.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 0), 0.0); litest_assert_double_gt(absinfo_normalize_value(&abs, 1), 0.0); litest_assert_double_lt(absinfo_normalize_value(&abs, 99), 1.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 100), 1.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 101), 1.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 200), 1.0); abs.minimum = -50; abs.maximum = 50; litest_assert_double_eq(absinfo_normalize_value(&abs, -51), 0.0); litest_assert_double_eq(absinfo_normalize_value(&abs, -50), 0.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 0), 0.5); litest_assert_double_eq(absinfo_normalize_value(&abs, 50), 1.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 51), 1.0); abs.minimum = -50; abs.maximum = 0; litest_assert_double_eq(absinfo_normalize_value(&abs, -51), 0.0); litest_assert_double_eq(absinfo_normalize_value(&abs, -50), 0.0); litest_assert_double_gt(absinfo_normalize_value(&abs, -49), 0.0); litest_assert_double_lt(absinfo_normalize_value(&abs, -1), 1.0); litest_assert_double_eq(absinfo_normalize_value(&abs, 0), 1.0); } END_TEST START_TEST(range_test) { struct range incl = range_init_inclusive(1, 100); litest_assert_int_eq(incl.lower, 1); litest_assert_int_eq(incl.upper, 101); struct range excl = range_init_exclusive(1, 100); litest_assert_int_eq(excl.lower, 1); litest_assert_int_eq(excl.upper, 100); struct range zero = range_init_exclusive(0, 0); litest_assert_int_eq(zero.lower, 0); litest_assert_int_eq(zero.upper, 0); struct range empty = range_init_empty(); litest_assert_int_eq(empty.lower, 0); litest_assert_int_eq(empty.upper, -1); litest_assert(range_is_valid(&incl)); litest_assert(range_is_valid(&excl)); litest_assert(!range_is_valid(&zero)); litest_assert(!range_is_valid(&empty)); int expected = 1; int r = 0; range_for_each(&incl, r) { litest_assert_int_eq(r, expected); expected++; } litest_assert_int_eq(r, 101); } END_TEST START_TEST(stringbuf_test) { struct stringbuf buf; struct stringbuf *b = &buf; int rc; stringbuf_init(b); litest_assert_int_eq(b->len, 0u); rc = stringbuf_append_string(b, "foo"); litest_assert_neg_errno_success(rc); rc = stringbuf_append_string(b, "bar"); litest_assert_neg_errno_success(rc); rc = stringbuf_append_string(b, "baz"); litest_assert_neg_errno_success(rc); litest_assert_str_eq(b->data, "foobarbaz"); litest_assert_int_eq(b->len, strlen("foobarbaz")); rc = stringbuf_ensure_space(b, 500); litest_assert_neg_errno_success(rc); litest_assert_int_ge(b->sz, 500u); rc = stringbuf_ensure_size(b, 0); litest_assert_neg_errno_success(rc); rc = stringbuf_ensure_size(b, 1024); litest_assert_neg_errno_success(rc); litest_assert_int_ge(b->sz, 1024u); char *data = stringbuf_steal(b); litest_assert_str_eq(data, "foobarbaz"); litest_assert_int_eq(b->sz, 0u); litest_assert_int_eq(b->len, 0u); litest_assert_ptr_null(b->data); free(data); const char *str = "1234567890"; rc = stringbuf_append_string(b, str); litest_assert_neg_errno_success(rc); litest_assert_str_eq(b->data, str); litest_assert_int_eq(b->len, 10u); stringbuf_reset(b); /* intentional double-reset */ stringbuf_reset(b); int pipefd[2]; rc = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK); litest_assert_neg_errno_success(rc); str = "foo bar baz"; char *compare = NULL; for (int i = 0; i < 100; i++) { rc = write(pipefd[1], str, strlen(str)); litest_assert_neg_errno_success(rc); rc = stringbuf_append_from_fd(b, pipefd[0], 64); litest_assert_neg_errno_success(rc); char *expected; rc = xasprintf(&expected, "%s%s", compare ? compare : "", str); litest_assert_neg_errno_success(rc); litest_assert_str_eq(b->data, expected); free(compare); compare = expected; } free(compare); close(pipefd[0]); close(pipefd[1]); stringbuf_reset(b); rc = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK); litest_assert_neg_errno_success(rc); const size_t stride = 256; const size_t maxsize = 4096; for (size_t i = 0; i < maxsize; i += stride) { char buf[stride]; memset(buf, i/stride, sizeof(buf)); rc = write(pipefd[1], buf, sizeof(buf)); litest_assert_neg_errno_success(rc); } stringbuf_append_from_fd(b, pipefd[0], 0); litest_assert_int_eq(b->len, maxsize); litest_assert_int_ge(b->sz, maxsize); for (size_t i = 0; i < maxsize; i+= stride) { char buf[stride]; memset(buf, i/stride, sizeof(buf)); litest_assert_int_eq(memcmp(buf, b->data + i, sizeof(buf)), 0); } close(pipefd[0]); close(pipefd[1]); stringbuf_reset(b); } END_TEST START_TEST(multivalue_test) { { struct multivalue v = multivalue_new_string("test"); litest_assert_int_eq(v.type, 's'); litest_assert_str_eq(v.value.s, "test"); const char *s; multivalue_extract_typed(&v, 's', &s); litest_assert_str_eq(s, "test"); litest_assert_ptr_eq(s, (const char*)v.value.s); multivalue_extract(&v, &s); litest_assert_str_eq(s, "test"); litest_assert_ptr_eq(s, (const char*)v.value.s); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_str_eq(copy.value.s, v.value.s); char *p1 = copy.value.s; char *p2 = v.value.s; litest_assert_ptr_ne(p1, p2); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "test"); free(str); } { struct multivalue v = multivalue_new_char('x'); litest_assert_int_eq(v.type, 'c'); litest_assert_int_eq(v.value.c, 'x'); char c; multivalue_extract_typed(&v, 'c', &c); litest_assert_int_eq(c, 'x'); multivalue_extract(&v, &c); litest_assert_int_eq(c, 'x'); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_int_eq(copy.value.c, v.value.c); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "x"); free(str); } { struct multivalue v = multivalue_new_u32(0x1234); litest_assert_int_eq(v.type, 'u'); litest_assert_int_eq(v.value.u, 0x1234u); uint32_t c; multivalue_extract_typed(&v, 'u', &c); litest_assert_int_eq(c, 0x1234u); multivalue_extract(&v, &c); litest_assert_int_eq(c, 0x1234u); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_int_eq(copy.value.u, v.value.u); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "4660"); free(str); } { struct multivalue v = multivalue_new_i32(-123); litest_assert_int_eq(v.type, 'i'); litest_assert_int_eq(v.value.i, -123); int32_t c; multivalue_extract_typed(&v, 'i', &c); litest_assert_int_eq(c, -123); multivalue_extract(&v, &c); litest_assert_int_eq(c, -123); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_int_eq(copy.value.i, v.value.i); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "-123"); free(str); } { struct multivalue v = multivalue_new_bool(true); litest_assert_int_eq(v.type, 'b'); litest_assert_int_eq(v.value.b, true); bool c; multivalue_extract_typed(&v, 'b', &c); litest_assert_int_eq(c, true); multivalue_extract(&v, &c); litest_assert_int_eq(c, true); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_int_eq(copy.value.b, v.value.b); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "true"); free(str); } { struct multivalue v = multivalue_new_double(0.1234); litest_assert_int_eq(v.type, 'd'); litest_assert_double_eq(v.value.d, 0.1234); double c; multivalue_extract_typed(&v, 'd', &c); litest_assert_double_eq(c, 0.1234); multivalue_extract(&v, &c); litest_assert_double_eq(c, 0.1234); struct multivalue copy = multivalue_copy(&v); litest_assert_int_eq(copy.type, v.type); litest_assert_double_eq(copy.value.d, v.value.d); char *str = multivalue_as_str(&v); litest_assert_str_eq(str, "0.123400"); free(str); } } END_TEST int main(void) { struct litest_runner *runner = litest_runner_new(); /* not worth forking the tests here */ litest_runner_set_num_parallel(runner, 0); #define ADD_TEST(func_) do { \ struct litest_runner_test_description tdesc = { \ .func = func_, \ };\ snprintf(tdesc.name, sizeof(tdesc.name), # func_); \ litest_runner_add_test(runner, &tdesc); \ } while(0) ADD_TEST(array_for_each); ADD_TEST(bitfield_helpers); ADD_TEST(matrix_helpers); ADD_TEST(ratelimit_helpers); ADD_TEST(dpi_parser); ADD_TEST(wheel_click_parser); ADD_TEST(wheel_click_count_parser); ADD_TEST(dimension_prop_parser); ADD_TEST(reliability_prop_parser); ADD_TEST(calibration_prop_parser); ADD_TEST(range_prop_parser); ADD_TEST(boolean_prop_parser); ADD_TEST(evcode_prop_parser); ADD_TEST(input_prop_parser); ADD_TEST(evdev_abs_parser); ADD_TEST(safe_atoi_test); ADD_TEST(safe_atoi_base_16_test); ADD_TEST(safe_atoi_base_8_test); ADD_TEST(safe_atou_test); ADD_TEST(safe_atou_base_16_test); ADD_TEST(safe_atou_base_8_test); ADD_TEST(safe_atod_test); ADD_TEST(strsplit_test); ADD_TEST(strv_for_each_test); ADD_TEST(double_array_from_string_test); ADD_TEST(strargv_test); ADD_TEST(kvsplit_double_test); ADD_TEST(strjoin_test); ADD_TEST(strstrip_test); ADD_TEST(strendswith_test); ADD_TEST(strstartswith_test); ADD_TEST(strsanitize_test); ADD_TEST(time_conversion); ADD_TEST(human_time); ADD_TEST(list_test_insert); ADD_TEST(list_test_append); ADD_TEST(list_test_foreach); ADD_TEST(strverscmp_test); ADD_TEST(streq_test); ADD_TEST(strneq_test); ADD_TEST(trunkname_test); ADD_TEST(basename_test); ADD_TEST(absinfo_normalize_value_test); ADD_TEST(range_test); ADD_TEST(stringbuf_test); ADD_TEST(multivalue_test); enum litest_runner_result result = litest_runner_run_tests(runner); litest_runner_destroy(runner); if (result == LITEST_SKIP) return 77; return result - LITEST_PASS; } libinput-1.28.1/test/test_quirks_files.py000077500000000000000000000063731477265155700205600ustar00rootroot00000000000000#!/usr/bin/env python3 # # This file is formatted with Python Black # # Run with pytest from pathlib import Path import configparser import os import pytest import re # see the IDs from # https://github.com/torvalds/linux/blob/master/drivers/hid/hid-ids.h#L772 # https://github.com/torvalds/linux/blob/master/drivers/hid/hid-logitech-dj.c#L1826 logitech_receivers = [ 0xC50C, # USB_DEVICE_ID_S510_RECEIVER 0xC517, # USB_DEVICE_ID_S510_RECEIVER_2 0xC512, # USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xC513, # USB_DEVICE_ID_MX3000_RECEIVER 0xC51B, # USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER 0xC52B, # USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER 0xC52F, # USB_DEVICE_ID_LOGITECH_NANO_RECEIVER 0xC532, # USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2 0xC534, # USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2 0xC539, # USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1 0xC53F, # USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1 0xC53A, # USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY 0xC545, # Bolt receiver, not listed in the kernel (yet) 0xC547, # Bolt receiver, not listed in the kernel (yet) 0xC548, # Bolt receiver, not listed in the kernel (yet) ] def quirksdir(): return Path(os.getenv("MESON_SOURCE_ROOT") or ".") / "quirks" def pytest_generate_tests(metafunc): # for any function that takes a "quirksfile" argument return the path to # a quirks file if "quirksfile" in metafunc.fixturenames: metafunc.parametrize("quirksfile", [f for f in quirksdir().glob("*.quirks")]) def test_matches_are_valid(quirksfile): quirks = configparser.ConfigParser(strict=True) # Don't convert to lowercase quirks.optionxform = lambda option: option # type: ignore quirks.read(quirksfile) for name, section in filter(lambda n: n != "DEFAULT", quirks.items()): bus = section.get("MatchBus") if bus is not None: assert bus in ("ps2", "usb", "bluetooth", "i2c", "spi") vid = section.get("MatchVendor") if vid is not None: assert re.match( "0x[0-9A-F]{4}", vid ), f"{quirksfile}: {name}: {vid} must be uppercase hex (0xAB12)" pid = section.get("MatchProduct") if pid is not None: assert re.match( "0x[0-9A-F]{4}", pid ), f"{quirksfile}: {name}: {pid} must be uppercase hex (0xAB12)" def test_match_product_is_not_a_logitech_receiver(quirksfile): quirks = configparser.ConfigParser(strict=True) # Don't convert to lowercase quirks.optionxform = lambda option: option # type: ignore quirks.read(quirksfile) for name, section in filter(lambda n: n != "DEFAULT", quirks.items()): vid = int(section.get("MatchVendor", "0x0"), 16) if vid == 0x046D: pid = int(section.get("MatchProduct", "0x0"), 16) assert ( pid not in logitech_receivers ), f"{quirksfile}: {name}: applies to a Logitech Receiver" def main(): args = [__file__] try: import xdist # noqa ncores = os.environ.get("FDO_CI_CONCURRENT", "auto") args += ["-n", ncores] except ImportError: pass return pytest.main(args) if __name__ == "__main__": raise SystemExit(main()) libinput-1.28.1/test/valgrind.suppressions000066400000000000000000000026441477265155700207460ustar00rootroot00000000000000{ srunner_run::timer_create-uninitialized-bytes Memcheck:Param timer_create(evp) fun:timer_create@@GLIBC_2.3.3 fun:srunner_run fun:litest_run fun:main } { mtdev:conditional_jumps_uninitialized_value Memcheck:Cond ... fun:mtdev_put_event } { Memcheck:Leak ... fun:g_type_register_static } { Memcheck:Leak ... fun:g_type_register_fundamental } { Memcheck:Leak ... fun:g_malloc0 } { Memcheck:Leak fun:malloc ... fun:g_get_language_names_with_category } { libunwind:msync_uninitialized_bytes Memcheck:Param msync(start) fun:__msync_nocancel ... fun:litest_backtrace } { python:PyUnicode_New Memcheck:Leak ... obj:/usr/lib*/libpython3*.so* } { libevdev:grab Memcheck:Param ioctl(generic) fun:ioctl fun:libevdev_grab } { ioctl:grab Memcheck:Param ioctl(generic) fun:ioctl fun:grab_device } { bash:execute_command Memcheck:Cond ... fun:execute_command } { bash:execute_command Memcheck:Leak ... fun:execute_command } { bash:execute_command Memcheck:Addr16 ... fun:execute_command } { python:Py_GetProgramFullPath Memcheck:Cond ... fun:Py_GetProgramFullPath } { python:_PyEval_EvalFrameDefault Memcheck:Cond ... fun:_PyEval_EvalFrameDefault } libinput-1.28.1/tools/000077500000000000000000000000001477265155700146145ustar00rootroot00000000000000libinput-1.28.1/tools/libinput-analyze-buttons.man000066400000000000000000000011531477265155700222740ustar00rootroot00000000000000.TH libinput-analyze-buttons "1" .SH NAME libinput\-analyze\-buttons \- analyze the button states of a recording .SH SYNOPSIS .B libinput analyze buttons [\-\-help] [options] \fIrecording.yml\fI .SH DESCRIPTION .PP The .B "libinput analyze buttons" tool analyzes a recording made with .B "libinput record" and prints information about the button states. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-threshold= Color any delta time less than the threshold in red. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-analyze-buttons.py000077500000000000000000000155171477265155700221650ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2024 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # # Prints the data from a libinput recording in a table format to ease # debugging. # # Input is a libinput record yaml file from dataclasses import dataclass import argparse import os import sys import yaml import libevdev COLOR_RESET = "\x1b[0m" COLOR_RED = "\x1b[6;31m" def micros(e: libevdev.InputEvent): return e.usec + e.sec * 1_000_000 @dataclass class Timestamp: sec: int usec: int @property def micros(self) -> int: return self.usec + self.sec * 1_000_000 @dataclass class ButtonFrame: delta_ms: int # delta time to last button (not evdev!) frame evdev_delta_ms: int # delta time to last evdev frame events: list[libevdev.InputEvent] # BTN_ events only @property def timestamp(self) -> Timestamp: e = self.events[0] return Timestamp(e.sec, e.usec) def value(self, code: libevdev.EventCode) -> bool | None: for e in self.events: if e.matches(code): return e.value return None def values(self, codes: list[libevdev.EventCode]) -> list[bool | None]: return [self.value(code) for code in codes] def frames(events): last_timestamp = None current_frame = None last_frame = None for e in events: if last_timestamp is None: last_timestamp = micros(e) if e.type == libevdev.EV_SYN: last_timestamp = micros(e) if current_frame is not None: yield current_frame last_frame = current_frame current_frame = None elif e.type == libevdev.EV_KEY: if e.code.name.startswith("BTN_") and not e.code.name.startswith( "BTN_TOOL_" ): timestamp = micros(e) evdev_delta = (timestamp - last_timestamp) // 1000 if last_frame is not None: delta = (timestamp - last_frame.timestamp.micros) // 1000 else: delta = 0 if current_frame is None: current_frame = ButtonFrame( delta_ms=delta, evdev_delta_ms=evdev_delta, events=[e] ) else: current_frame.events.append(e) def main(argv): parser = argparse.ArgumentParser(description="Display button events in a recording") parser.add_argument( "--threshold", type=int, default=25, help="Mark any time delta above this threshold (in ms)", ) parser.add_argument( "path", metavar="recording", nargs=1, help="Path to libinput-record YAML file" ) args = parser.parse_args() isatty = os.isatty(sys.stdout.fileno()) if not isatty: global COLOR_RESET global COLOR_RED COLOR_RESET = "" COLOR_RED = "" yml = yaml.safe_load(open(args.path[0])) if yml["ndevices"] > 1: print(f"WARNING: Using only first {yml['ndevices']} devices in recording") device = yml["devices"][0] if not device["events"]: print("No events found in recording") sys.exit(1) def events(): """ Yields the next event in the recording """ for event in device["events"]: for evdev in event.get("evdev", []): yield libevdev.InputEvent( code=libevdev.evbit(evdev[2], evdev[3]), value=evdev[4], sec=evdev[0], usec=evdev[1], ) # These are the buttons we possibly care about, but we filter to the ones # found on this device anyway buttons = [ libevdev.EV_KEY.BTN_LEFT, libevdev.EV_KEY.BTN_MIDDLE, libevdev.EV_KEY.BTN_RIGHT, libevdev.EV_KEY.BTN_SIDE, libevdev.EV_KEY.BTN_EXTRA, libevdev.EV_KEY.BTN_FORWARD, libevdev.EV_KEY.BTN_BACK, libevdev.EV_KEY.BTN_TASK, libevdev.EV_KEY.BTN_TOUCH, libevdev.EV_KEY.BTN_STYLUS, libevdev.EV_KEY.BTN_STYLUS2, libevdev.EV_KEY.BTN_STYLUS3, libevdev.EV_KEY.BTN_0, libevdev.EV_KEY.BTN_1, libevdev.EV_KEY.BTN_2, libevdev.EV_KEY.BTN_3, libevdev.EV_KEY.BTN_4, libevdev.EV_KEY.BTN_5, libevdev.EV_KEY.BTN_6, libevdev.EV_KEY.BTN_7, libevdev.EV_KEY.BTN_8, libevdev.EV_KEY.BTN_9, ] def filter_buttons(buttons): return filter( lambda c: c in buttons, map(lambda c: libevdev.evbit("EV_KEY", c), device["evdev"]["codes"][1]), ) buttons = list(filter_buttons(buttons)) # all BTN_STYLUS will have a header of S - meh btn_headers = " │ ".join(b.name[4] for b in buttons) print(f"{'Timestamp':^13s} │ {'Delta':^8s} │ {btn_headers}") last_btn_vals = [None] * len(buttons) def btnchar(b, last): if b == 1: return "┬" if b == 0: return "┴" return "│" if last else " " for frame in frames(events()): ts = frame.timestamp if frame.timestamp.micros > 0 and frame.delta_ms < args.threshold: color = COLOR_RED else: color = "" btn_vals = frame.values(buttons) btn_strs = " │ ".join( [btnchar(b, last) for b, last in zip(btn_vals, last_btn_vals)] ) last_btn_vals = [ b if b is not None else last for b, last in zip(btn_vals, last_btn_vals) ] print( f"{color}{ts.sec:6d}.{ts.usec:06d} │ {frame.delta_ms:6d}ms │ {btn_strs}{COLOR_RESET}" ) if __name__ == "__main__": try: main(sys.argv) except BrokenPipeError: pass libinput-1.28.1/tools/libinput-analyze-per-slot-delta.man000066400000000000000000000053331477265155700234360ustar00rootroot00000000000000.TH libinput-analyze-per-slot-delta "1" .SH NAME libinput\-analyze\-per\-slot\-delta \- analyze the per-event delta movement for touch slots .SH SYNOPSIS .B libinput analyze per-slot-delta [\-\-help] [options] \fIrecording.yml\fI .SH DESCRIPTION .PP The .B "libinput analyze per\-slot\-delta" tool analyzes a recording made with .B "libinput record" and prints the delta movement per touch slot. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-ignore-below= Ignore any movement below the given threshold. The threshold is in mm if \fB\-\-use-mm\fR is selected or in device units otherwise. .TP 8 .B \-\-show-distance Also show the distance relative to the initial position of the current touch. The distance is mm if \fB\-\-use-mm\fR is selected or in device units otherwise. .TP 8 .B \-\-threshold= Color any movement above this threshold in red. The threshold is in mm if \fB\-\-use-mm\fR is selected or in device units otherwise. .TP 8 .B \-\-use-mm Print data in mm instead of device units .TP 8 .B \-\-use-st Use the single-touch ABS_X/ABS_Y instead of the multitouch axes .TP 8 .B \-\-use-absolute Print absolute coordinates, not deltas .SH OUTPUT An example output for a single finger touch on a touchpad supporting two slots is below. This output is with the use of the .B --use-mm flag. .PP .nf .sf 0.000000 +0ms TOU: ++++++ | ************* | 0.021900 +21ms TOU: →↘ +1.10/+0.14 | ************* | 0.033468 +11ms TOU: →↘ +1.15/+0.19 | ************* | 0.043856 +10ms TOU: →↘ +1.76/+0.22 | ************* | 0.053237 +9ms TOU: →↘ +2.20/+0.19 | ************* | .fi .in .PP The entry .B ++++++ indicates a finger has been put down, .B ------ indicates the finger has lifted. The left-most column is the absolute timestamp in seconds.microseconds followed by the relative time of the event to the previous event. .PP The word .B TOU in this example represents BTN_TOUCH, similar abbreviations exist for BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP, and BTN_TOOL_QUINTTAP. .PP The arrows indicate the approximate direction on a 16-point compass, in this example EastSouthEast. .PP Each multitouch slot supported by the hardware has one column, where the column shows asterisk .B ******** no finger is down for that slot. Where the column shows spaces only, a finger is down but no data is currently available. .PP In the above example, the third events occurs ~33ms into the recording, is 11ms after the previous event and has an east south-east direction. The movement for this event was x: 1.15 and y: 0.19 mm. A second finger is not currently down. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-analyze-per-slot-delta.py000077500000000000000000000352771477265155700233300ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # # # Measures the relative motion between touch events (based on slots) # # Input is a libinput record yaml file from dataclasses import dataclass, field, replace from enum import Enum import argparse import math import sys import yaml import libevdev COLOR_RESET = "\x1b[0m" COLOR_RED = "\x1b[6;31m" class SlotFormatter: def __init__( self, is_absolute=False, resolution=None, threshold=None, ignore_below=None, show_distance=False, ): self.threshold = threshold self.ignore_below = ignore_below self.resolution = resolution self.is_absolute = is_absolute self.show_distance = show_distance self.slots = [] self.have_data = False self.filtered = False self.width = 35 if show_distance else 16 def __str__(self): return " | ".join(self.slots) def format_slot(self, slot): if slot.state == SlotState.BEGIN: self.slots.append("+++++++".center(self.width)) self.have_data = True elif slot.state == SlotState.END: self.slots.append("-------".center(self.width)) self.have_data = True elif slot.state == SlotState.NONE: self.slots.append(("*" * (self.width - 2)).center(self.width)) elif not slot.dirty: self.slots.append(" ".center(self.width)) else: if self.resolution is not None: delta = Point( slot.delta.x / self.resolution[0], slot.delta.y / self.resolution[1], ) distx = abs(slot.position.x - slot.origin.x) disty = abs(slot.position.y - slot.origin.y) distance = Point( distx / self.resolution[0], disty / self.resolution[1], ) else: delta = Point(slot.delta.x, slot.delta.y) distance = Point( abs(slot.position.x - slot.origin.x), abs(slot.position.y - slot.origin.y), ) if delta.x != 0 and delta.y != 0: t = math.atan2(delta.x, delta.y) t += math.pi # in [0, 2pi] range now if t == 0: t = 0.01 else: t = t * 180.0 / math.pi directions = ["↖↑", "↖←", "↙←", "↙↓", "↓↘", "→↘", "→↗", "↑↗"] direction = directions[int(t / 45)] elif delta.y == 0: if delta.x < 0: direction = "←←" else: direction = "→→" else: if delta.y < 0: direction = "↑↑" else: direction = "↓↓" color = "" reset = "" if not self.is_absolute: if self.ignore_below is not None or self.threshold is not None: dist = math.hypot(delta.x, delta.y) if self.ignore_below is not None and dist < self.ignore_below: self.slots.append(" ".center(self.width)) self.filtered = True return if self.threshold is not None and dist >= self.threshold: color = COLOR_RED reset = COLOR_RESET if isinstance(delta.x, int) and isinstance(delta.y, int): coords = f"{delta.x:+4d}/{delta.y:+4d}" else: coords = f"{delta.x:+3.2f}/{delta.y:+03.2f}" if self.show_distance: hypot = math.hypot(distance.x, distance.y) distance = ( f"dist: ({distance.x:3.1f}/{distance.y:3.1f}, {hypot:3.1f})" ) else: distance = "" components = [ f"{direction}", f"{color}", coords, distance, f"{reset}", ] string = " ".join(c for c in components if c) else: x, y = slot.position.x, slot.position.y string = "{} {}{:4d}/{:4d}{}".format(direction, color, x, y, reset) self.have_data = True self.slots.append(string.ljust(self.width + len(color) + len(reset))) class SlotState(Enum): NONE = 0 BEGIN = 1 UPDATE = 2 END = 3 @dataclass class Point: x: float = 0.0 y: float = 0.0 @dataclass class Slot: index: int state: SlotState = SlotState.NONE position: Point = field(default_factory=Point) delta: Point = field(default_factory=Point) origin: Point = field(default_factory=Point) used: bool = False dirty: bool = False def main(argv): global COLOR_RESET global COLOR_RED slots = [] xres, yres = 1, 1 parser = argparse.ArgumentParser( description="Measure delta between event frames for each slot" ) parser.add_argument( "--use-mm", action="store_true", help="Use mm instead of device deltas" ) parser.add_argument( "--show-distance", action="store_true", help="Show the absolute distance relative to the first position", ) parser.add_argument( "--use-st", action="store_true", help="Use ABS_X/ABS_Y instead of ABS_MT_POSITION_X/Y", ) parser.add_argument( "--use-absolute", action="store_true", help="Use absolute coordinates, not deltas", ) parser.add_argument( "path", metavar="recording", nargs=1, help="Path to libinput-record YAML file" ) parser.add_argument( "--threshold", type=float, default=None, help="Mark any delta above this threshold", ) parser.add_argument( "--ignore-below", type=float, default=None, help="Ignore any delta below this threshold", ) args = parser.parse_args() if not sys.stdout.isatty(): COLOR_RESET = "" COLOR_RED = "" yml = yaml.safe_load(open(args.path[0])) device = yml["devices"][0] absinfo = device["evdev"]["absinfo"] try: nslots = absinfo[libevdev.EV_ABS.ABS_MT_SLOT.value][1] + 1 except KeyError: args.use_st = True if args.use_st: nslots = 1 slots = [Slot(i) for i in range(0, nslots)] slots[0].used = True if args.use_mm: xres = 1.0 * absinfo[libevdev.EV_ABS.ABS_X.value][4] yres = 1.0 * absinfo[libevdev.EV_ABS.ABS_Y.value][4] if not xres or not yres: print("Error: device doesn't have a resolution, cannot use mm") sys.exit(1) if args.use_st: print("Warning: slot coordinates on FINGER/DOUBLETAP change may be incorrect") slots[0].used = True slot = 0 last_time = None tool_bits = { libevdev.EV_KEY.BTN_TOUCH: 0, libevdev.EV_KEY.BTN_TOOL_DOUBLETAP: 0, libevdev.EV_KEY.BTN_TOOL_TRIPLETAP: 0, libevdev.EV_KEY.BTN_TOOL_QUADTAP: 0, libevdev.EV_KEY.BTN_TOOL_QUINTTAP: 0, } btn_state = { libevdev.EV_KEY.BTN_LEFT: 0, libevdev.EV_KEY.BTN_MIDDLE: 0, libevdev.EV_KEY.BTN_RIGHT: 0, } nskipped_lines = 0 for event in device["events"]: for evdev in event["evdev"]: s = slots[slot] e = libevdev.InputEvent( code=libevdev.evbit(evdev[2], evdev[3]), value=evdev[4], sec=evdev[0], usec=evdev[1], ) if e.code in tool_bits: tool_bits[e.code] = e.value if e.code in btn_state: btn_state[e.code] = e.value if args.use_st: # Note: this relies on the EV_KEY events to come in before the # x/y events, otherwise the last/first event in each slot will # be wrong. if ( e.code == libevdev.EV_KEY.BTN_TOOL_FINGER or e.code == libevdev.EV_KEY.BTN_TOOL_PEN ): slot = 0 s = slots[slot] s.dirty = True if e.value: s.state = SlotState.BEGIN else: s.state = SlotState.END elif e.code == libevdev.EV_KEY.BTN_TOOL_DOUBLETAP: if len(slots) > 1: slot = 1 s = slots[slot] s.dirty = True if e.value: s.state = SlotState.BEGIN else: s.state = SlotState.END else: if e.code == libevdev.EV_ABS.ABS_MT_SLOT: slot = e.value s = slots[slot] s.dirty = True # bcm5974 cycles through slot numbers, so let's say all below # our current slot number was used for sl in slots[: slot + 1]: sl.used = True elif e.code == libevdev.EV_ABS.ABS_MT_TRACKING_ID: if e.value == -1: s.state = SlotState.END else: s.state = SlotState.BEGIN s.delta.x, s.delta.y = 0, 0 s.dirty = True if args.use_st: axes = [libevdev.EV_ABS.ABS_X, libevdev.EV_ABS.ABS_Y] else: axes = [ libevdev.EV_ABS.ABS_MT_POSITION_X, libevdev.EV_ABS.ABS_MT_POSITION_Y, ] if e.code in axes: s.dirty = True # If recording started after touch down if s.state == SlotState.NONE: s.state = SlotState.BEGIN s.delta = Point(0, 0) if e.code in [ libevdev.EV_ABS.ABS_X, libevdev.EV_ABS.ABS_MT_POSITION_X, ]: if s.state == SlotState.UPDATE: s.delta.x = e.value - s.position.x s.position.x = e.value elif e.code in [ libevdev.EV_ABS.ABS_Y, libevdev.EV_ABS.ABS_MT_POSITION_Y, ]: if s.state == SlotState.UPDATE: s.delta.y = e.value - s.position.y s.position.y = e.value else: assert False, f"Invalid axis {e.code}" if e.code == libevdev.EV_SYN.SYN_REPORT: if last_time is None: last_time = e.sec * 1000000 + e.usec tdelta = 0 else: t = e.sec * 1000000 + e.usec tdelta = int((t - last_time) / 1000) # ms last_time = t tools = [ (libevdev.EV_KEY.BTN_TOOL_QUINTTAP, "QIN"), (libevdev.EV_KEY.BTN_TOOL_QUADTAP, "QAD"), (libevdev.EV_KEY.BTN_TOOL_TRIPLETAP, "TRI"), (libevdev.EV_KEY.BTN_TOOL_DOUBLETAP, "DBL"), (libevdev.EV_KEY.BTN_TOUCH, "TOU"), ] for bit, string in tools: if tool_bits[bit]: tool_state = string break else: tool_state = " " buttons = [ (libevdev.EV_KEY.BTN_LEFT, "L"), (libevdev.EV_KEY.BTN_MIDDLE, "M"), (libevdev.EV_KEY.BTN_RIGHT, "R"), ] button_state = ( "".join([string for bit, string in buttons if btn_state[bit]]) or "." ) fmt = SlotFormatter( is_absolute=args.use_absolute, resolution=(xres, yres) if args.use_mm else None, threshold=args.threshold, ignore_below=args.ignore_below, show_distance=args.show_distance, ) for sl in [s for s in slots if s.used]: fmt.format_slot(sl) sl.dirty = False sl.delta.x, sl.delta.y = 0, 0 if sl.state == SlotState.BEGIN: sl.origin = replace(sl.position) sl.state = SlotState.UPDATE elif sl.state == SlotState.END: sl.state = SlotState.NONE if fmt.have_data: if nskipped_lines > 0: print("") nskipped_lines = 0 print( "{:2d}.{:06d} {:+5d}ms {} {} {}".format( e.sec, e.usec, tdelta, tool_state, button_state, fmt ) ) elif fmt.filtered: nskipped_lines += 1 print( "\r", " " * 21, "... {} below threshold".format(nskipped_lines), flush=True, end="", ) if __name__ == "__main__": try: main(sys.argv) except KeyboardInterrupt: pass libinput-1.28.1/tools/libinput-analyze-recording.man000066400000000000000000000025121477265155700225520ustar00rootroot00000000000000.TH libinput-analyze-recording "1" .SH NAME libinput\-analyze\-recording \- analyze a device recording .SH SYNOPSIS .B libinput analyze recording [\-\-help] [options] \fIrecording.yml\fI .SH DESCRIPTION .PP The .B "libinput analyze recording" tool analyzes a recording made with .B "libinput record" and prints a tabular summary of the events in that recording. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .SH OPTIONS .TP 8 .B \-\-help Print help .SH OUTPUT An example output for a tablet sequence is below. .PP .nf .sf Time | X | Y | PRESSURE | DISTANCE | MISC | SERIAL ----------------------------------------------------------------- 0.000 | 9717 | 6266 | | 63 | 0x862 | 0x9a805597 | BTN_TOOL_PEN 0.005 | 9709 | | | | | 0x9a805597 | BTN_TOOL_PEN 0.012 | 9701 | | | | | 0x9a805597 | BTN_TOOL_PEN 0.020 | 9692 | 6269 | | | | 0x9a805597 | BTN_TOOL_PEN 0.028 | 9680 | 6277 | | | | 0x9a805597 | BTN_TOOL_PEN 0.034 | 9668 | 6279 | | | | 0x9a805597 | BTN_TOOL_PEN 0.042 | 9654 | 6282 | | | | 0x9a805597 | BTN_TOOL_PEN .fi .in .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-analyze-recording.py000077500000000000000000000172371477265155700224440ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2021 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # # Prints the data from a libinput recording in a table format to ease # debugging. # # Input is a libinput record yaml file import argparse import os import sys import yaml import libevdev # minimum width of a field in the table MIN_FIELD_WIDTH = 6 # Default is to just return the value of an axis, but some axes want special # formatting. def format_value(code, value): if code in (libevdev.EV_ABS.ABS_MISC, libevdev.EV_MSC.MSC_SERIAL): return f"{value & 0xFFFFFFFF:#x}" # Rel axes we always print the sign if code.type == libevdev.EV_REL: return f"{value:+d}" return f"{value}" # The list of axes we want to track def is_tracked_axis(code, allowlist, denylist): if code.type in (libevdev.EV_KEY, libevdev.EV_SW, libevdev.EV_SYN): return False # We don't do slots in this tool if code.type == libevdev.EV_ABS: if libevdev.EV_ABS.ABS_MT_SLOT <= code <= libevdev.EV_ABS.ABS_MAX: return False if allowlist: return code in allowlist else: return code not in denylist def main(argv): parser = argparse.ArgumentParser( description="Display a recording in a tabular format" ) parser.add_argument( "path", metavar="recording", nargs=1, help="Path to libinput-record YAML file" ) parser.add_argument( "--ignore", metavar="ABS_X,ABS_Y,...", default="", help="A comma-separated list of axis names to ignore", ) parser.add_argument( "--only", metavar="ABS_X,ABS_Y,...", default="", help="A comma-separated list of axis names to print, ignoring all others", ) parser.add_argument( "--print-state", action="store_true", default=False, help="Always print all axis values, even unchanged ones", ) args = parser.parse_args() if args.ignore and args.only: print("Only one of --ignore and --only may be given", file=sys.stderr) sys.exit(2) ignored_axes = [libevdev.evbit(axis) for axis in args.ignore.split(",") if axis] only_axes = [libevdev.evbit(axis) for axis in args.only.split(",") if axis] isatty = os.isatty(sys.stdout.fileno()) yml = yaml.safe_load(open(args.path[0])) if yml["ndevices"] > 1: print(f"WARNING: Using only first {yml['ndevices']} devices in recording") device = yml["devices"][0] if not device["events"]: print("No events found in recording") sys.exit(1) def events(): """ Yields the next event in the recording """ for event in device["events"]: for evdev in event.get("evdev", []): yield libevdev.InputEvent( code=libevdev.evbit(evdev[2], evdev[3]), value=evdev[4], sec=evdev[0], usec=evdev[1], ) def interesting_axes(events): """ Yields the libevdev codes with the axes in this recording """ used_axes = [] for e in events: if e.code not in used_axes and is_tracked_axis( e.code, only_axes, ignored_axes ): yield e.code used_axes.append(e.code) # Compile all axes that we want to print first axes = sorted( interesting_axes(events()), key=lambda x: x.type.value * 1000 + x.value ) # Strip the REL_/ABS_ prefix for the headers headers = [a.name[4:].rjust(MIN_FIELD_WIDTH) for a in axes] # for easier formatting later, we keep the header field width in a dict axes = {a: len(h) for a, h in zip(axes, headers)} # Time is a special case, always the first entry # Format uses ms only, we rarely ever care about µs headers = [f"{'Time':<7s}"] + headers + ["Keys"] header_line = f"{' | '.join(headers)}" print(header_line) print("-" * len(header_line)) current_codes = [] current_frame = {} # {evdev-code: value} axes_in_use = {} # to print axes never sending events last_fields = [] # to skip duplicate lines continuation_count = 0 keystate = {} keystate_changed = False for e in events(): axes_in_use[e.code] = True if e.code.type == libevdev.EV_KEY: keystate[e.code] = e.value keystate_changed = True elif is_tracked_axis(e.code, only_axes, ignored_axes): current_frame[e.code] = e.value current_codes.append(e.code) elif e.code == libevdev.EV_SYN.SYN_REPORT: fields = [] for a in axes: if args.print_state or a in current_codes: s = format_value(a, current_frame.get(a, 0)) else: s = "" fields.append(s.rjust(max(MIN_FIELD_WIDTH, axes[a]))) current_codes = [] if last_fields != fields or keystate_changed: last_fields = fields.copy() keystate_changed = False if continuation_count: if not isatty: print(f" ... +{continuation_count}", end="") print("") continuation_count = 0 fields.insert(0, f"{e.sec: 3d}.{e.usec//1000:03d}") keys_down = [k.name for k, v in keystate.items() if v] fields.append(", ".join(keys_down)) print(" | ".join(fields)) else: continuation_count += 1 if isatty: print(f"\r ... +{continuation_count}", end="", flush=True) # Print out any rel/abs axes that not generate events in # this recording unused_axes = [] for evtype, evcodes in device["evdev"]["codes"].items(): for c in evcodes: code = libevdev.evbit(int(evtype), int(c)) if ( is_tracked_axis(code, only_axes, ignored_axes) and code not in axes_in_use ): unused_axes.append(code) if unused_axes: print( f"Axes present but without events: {', '.join([a.name for a in unused_axes])}" ) for e in events(): if libevdev.EV_ABS.ABS_MT_SLOT <= code <= libevdev.EV_ABS.ABS_MAX: print( "WARNING: This recording contains multitouch data that is not supported by this tool." ) break if __name__ == "__main__": try: main(sys.argv) except BrokenPipeError: pass libinput-1.28.1/tools/libinput-analyze-touch-down-state.man000066400000000000000000000022411477265155700240020ustar00rootroot00000000000000.TH libinput-analyze-touch-down-state "1" .SH NAME libinput\-analyze\-touch\-down\-state \- analyze the touch states .SH SYNOPSIS .B libinput analyze touch-down-state [\-\-help] [options] \fIrecording.yml\fI .SH DESCRIPTION .PP The .B "libinput analyze touch\-down\state" tool analyzes a recording made with .B "libinput record" and prints "down" state of each touch. This tool aids with the detection of stuck touches. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-use-st Use the single-touch BTN_TOOL_ bits instead of the slot state. The output will only show the "highest" finger down at any time. For examples, where two fingers are down, only the second slot will be marked as down. .SH OUTPUT An example output for a two-finger alternating sequence below. .PP .nf .sf 6.140281 +1062ms: x | x 7.410377 +1257ms: | x 7.420200 +9ms: | 11.233108 +3812ms: x | x 11.245721 +12ms: x | x 11.850206 +604ms: | 13.827740 +1977ms: x | 13.839723 +11ms: x | 14.704027 +864ms: x | x 14.716691 +12ms: x | x .fi .in .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-analyze-touch-down-state.py000077500000000000000000000147641477265155700236770ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2020 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # # # Prints the down/up state of each touch slot # # Input is a libinput record yaml file import argparse import enum import sys import yaml import libevdev class Slot: class State(enum.Enum): NONE = "NONE" BEGIN = "BEGIN" UPDATE = "UPDATE" END = "END" def __init__(self, index): self._state = Slot.State.NONE self.index = index self.used = False def begin(self): assert self.state == Slot.State.NONE self.state = Slot.State.BEGIN def end(self): assert self.state in (Slot.State.BEGIN, Slot.State.UPDATE) self.state = Slot.State.END def sync(self): if self.state == Slot.State.BEGIN: self.state = Slot.State.UPDATE elif self.state == Slot.State.END: self.state = Slot.State.NONE @property def state(self): return self._state @state.setter def state(self, newstate): assert newstate in Slot.State if newstate != Slot.State.NONE: self.used = True self._state = newstate @property def is_active(self): return self.state in (Slot.State.BEGIN, Slot.State.UPDATE) def __str__(self): return "+" if self.state in (Slot.State.BEGIN, Slot.State.UPDATE) else " " def main(argv): parser = argparse.ArgumentParser(description="Print the state of touches over time") parser.add_argument( "--use-st", action="store_true", help="Ignore slots, use the BTN_TOOL bits" ) parser.add_argument( "path", metavar="recording", nargs=1, help="Path to libinput-record YAML file" ) args = parser.parse_args() yml = yaml.safe_load(open(args.path[0])) device = yml["devices"][0] absinfo = device["evdev"]["absinfo"] try: nslots = absinfo[libevdev.EV_ABS.ABS_MT_SLOT.value][1] + 1 except KeyError: args.use_st = True tool_slot_map = { libevdev.EV_KEY.BTN_TOOL_FINGER: 0, libevdev.EV_KEY.BTN_TOOL_PEN: 0, libevdev.EV_KEY.BTN_TOOL_DOUBLETAP: 1, libevdev.EV_KEY.BTN_TOOL_TRIPLETAP: 2, libevdev.EV_KEY.BTN_TOOL_QUADTAP: 3, libevdev.EV_KEY.BTN_TOOL_QUINTTAP: 4, } if args.use_st: for bit in tool_slot_map: if bit.value in device["evdev"]["codes"][libevdev.EV_KEY.value]: nslots = max(nslots, tool_slot_map[bit]) slots = [Slot(i) for i in range(0, nslots)] # We claim the first slots are used just to make the formatting # more consistent for i in range(min(5, len(slots))): slots[i].used = True slot = 0 last_time = None last_slot_state = None header = "Timestamp | Rel time | Slots |" print(header) print("-" * len(header)) def events(): for event in device["events"]: for evdev in event["evdev"]: yield evdev for evdev in events(): e = libevdev.InputEvent( code=libevdev.evbit(evdev[2], evdev[3]), value=evdev[4], sec=evdev[0], usec=evdev[1], ) # single-touch formatting is simpler than multitouch, it'll just # show the highest finger down rather than the correct output. if args.use_st: if e.code in tool_slot_map: slot = tool_slot_map[e.code] s = slots[slot] if e.value: s.begin() else: s.end() else: if e.code == libevdev.EV_ABS.ABS_MT_SLOT: slot = e.value s = slots[slot] # bcm5974 cycles through slot numbers, so let's say all below # our current slot number was used for sl in slots[: slot + 1]: sl.used = True else: s = slots[slot] if e.code == libevdev.EV_ABS.ABS_MT_TRACKING_ID: if e.value == -1: s.end() else: s.begin() elif e.code in ( libevdev.EV_ABS.ABS_MT_POSITION_X, libevdev.EV_ABS.ABS_MT_POSITION_Y, libevdev.EV_ABS.ABS_MT_PRESSURE, libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR, libevdev.EV_ABS.ABS_MT_TOUCH_MINOR, ): # If recording started after touch down if s.state == Slot.State.NONE: s.begin() if e.code == libevdev.EV_SYN.SYN_REPORT: current_slot_state = tuple(s.is_active for s in slots) if current_slot_state != last_slot_state: if last_time is None: last_time = e.sec * 1000000 + e.usec tdelta = 0 else: t = e.sec * 1000000 + e.usec tdelta = int((t - last_time) / 1000) / 1000 last_time = t fmt = " | ".join([str(s) for s in slots if s.used]) print( "{:2d}.{:06d} | {:+7.3f}s | {}".format(e.sec, e.usec, tdelta, fmt) ) last_slot_state = current_slot_state for s in slots: s.sync() if __name__ == "__main__": main(sys.argv) libinput-1.28.1/tools/libinput-analyze.c000066400000000000000000000034641477265155700202560ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include "shared.h" static inline void usage(void) { printf("Usage: libinput analyze [--help] \n"); } int main(int argc, char **argv) { int option_index = 0; while (1) { int c; static struct option opts[] = { { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "+h", opts, &option_index); if (c == -1) break; switch(c) { case 'h': usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } if (optind >= argc) { usage(); return EXIT_FAILURE; } argc--; argv++; return tools_exec_command("libinput-analyze", argc, argv); } libinput-1.28.1/tools/libinput-analyze.man000066400000000000000000000020011477265155700205710ustar00rootroot00000000000000.TH libinput-analyze "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-analyze \- analyze device data .SH SYNOPSIS .B libinput analyze [\-\-help] \fI []\fR .SH DESCRIPTION .PP The .B "libinput analyze" tool analyzes device data. Depending on what is to be analyzed, this tool may not create a libinput context. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool may need to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS .TP 8 .B \-\-help Print help .SH FEATURES Features that can be analyzed include .TP 8 .B libinput\-analyze\-buttons(1) analyze the button states of a recording .TP 8 .B libinput\-analyze\-per-slot-delta(1) analyze the delta per event per slot .TP 8 .B libinput\-analyze\-recording(1) analyze a recording made with .B libinput\-record(1) .TP 8 .B libinput\-analyze\-touch-down-state(1) analyze the state of each touch in a recording .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-debug-events.c000066400000000000000000000202731477265155700212000ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "linux/input.h" #include #include #include "libinput-version.h" #include "util-strings.h" #include "util-macros.h" #include "util-libinput.h" #include "shared.h" static struct tools_options options; static bool show_keycodes; static volatile sig_atomic_t stop = 0; static bool be_quiet = false; static bool compress_motion_events = false; static bool is_tty = false; #define printq(...) ({ if (!be_quiet) printf(__VA_ARGS__); }) static int handle_and_print_events(struct libinput *li, const struct libinput_print_options *opts) { int rc = -1; struct libinput_event *ev; static struct libinput_device *last_device = NULL; static enum libinput_event_type last_event_type = LIBINPUT_EVENT_NONE; static size_t event_repeat_count = 0; static uint32_t last_log_serial = 0; tools_dispatch(li); while ((ev = libinput_get_event(li))) { struct libinput_device *device = libinput_event_get_device(ev); enum libinput_event_type type = libinput_event_get_type(ev); if (type == LIBINPUT_EVENT_POINTER_AXIS) { libinput_event_destroy(ev); continue; } bool is_repeat = false; switch (type) { case LIBINPUT_EVENT_POINTER_MOTION: case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TABLET_TOOL_AXIS: case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: is_repeat = last_event_type == type && last_device == device && log_serial == last_log_serial; break; default: break; } if (is_repeat) { event_repeat_count++; if (compress_motion_events) printq("\e[1A"); } else { event_repeat_count = 0; } if (type != LIBINPUT_EVENT_TOUCH_FRAME || !compress_motion_events) { char *event_str = libinput_event_to_str(ev, event_repeat_count + 1, opts); switch (type) { case LIBINPUT_EVENT_DEVICE_ADDED: tools_device_apply_config(libinput_event_get_device(ev), &options); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: { struct libinput_event_tablet_tool *tev = libinput_event_get_tablet_tool_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(tev); tools_tablet_tool_apply_config(tool, &options); break; } default: break; } printq("%s\n", event_str); free(event_str); } last_device = device; if (type != LIBINPUT_EVENT_TOUCH_FRAME) last_event_type = type; last_log_serial = log_serial; libinput_event_destroy(ev); rc = 0; } fflush(stdout); return rc; } static void sighandler(int signal, siginfo_t *siginfo, void *userdata) { stop = 1; } static void mainloop(struct libinput *li) { struct pollfd fds; fds.fd = libinput_get_fd(li); fds.events = POLLIN; fds.revents = 0; struct libinput_print_options opts = { .screen_width = 100, .screen_height = 100, .show_keycodes = show_keycodes, .start_time = 0, }; /* Handle already-pending device added events */ if (handle_and_print_events(li, &opts)) fprintf(stderr, "Expected device added events on startup but got none. " "Maybe you don't have the right permissions?\n"); /* time offset starts with our first received event */ if (poll(&fds, 1, -1) > -1) { struct timespec tp; clock_gettime(CLOCK_MONOTONIC, &tp); opts.start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; do { handle_and_print_events(li, &opts); } while (!stop && poll(&fds, 1, -1) > -1); } printf("\n"); } static void usage(struct option *opts) { printf("Usage: libinput debug-events [options] [--udev |--device /dev/input/event0 ...]\n"); if (opts) tools_print_usage_option_list(opts); } int main(int argc, char **argv) { struct libinput *li; enum tools_backend backend = BACKEND_NONE; const char *seat_or_devices[60] = {NULL}; size_t ndevices = 0; bool grab = false; bool verbose = false; struct sigaction act; tools_init_options(&options); is_tty = isatty(STDOUT_FILENO); while (1) { int c; int option_index = 0; enum { OPT_DEVICE = 1, OPT_UDEV, OPT_GRAB, OPT_VERBOSE, OPT_SHOW_KEYCODES, OPT_QUIET, OPT_COMPRESS_MOTION_EVENTS, }; static struct option opts[] = { CONFIGURATION_OPTIONS, { "help", no_argument, 0, 'h' }, { "show-keycodes", no_argument, 0, OPT_SHOW_KEYCODES }, { "device", required_argument, 0, OPT_DEVICE }, { "udev", required_argument, 0, OPT_UDEV }, { "grab", no_argument, 0, OPT_GRAB }, { "verbose", no_argument, 0, OPT_VERBOSE }, { "quiet", no_argument, 0, OPT_QUIET }, { "compress-motion-events", no_argument, 0, OPT_COMPRESS_MOTION_EVENTS }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "h", opts, &option_index); if (c == -1) break; switch(c) { case '?': exit(EXIT_INVALID_USAGE); break; case 'h': usage(opts); exit(EXIT_SUCCESS); break; case OPT_SHOW_KEYCODES: show_keycodes = true; break; case OPT_QUIET: be_quiet = true; break; case OPT_DEVICE: if (backend == BACKEND_UDEV || ndevices >= ARRAY_LENGTH(seat_or_devices)) { usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; seat_or_devices[ndevices++] = optarg; break; case OPT_UDEV: if (backend == BACKEND_DEVICE || ndevices >= ARRAY_LENGTH(seat_or_devices)) { usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_UDEV; seat_or_devices[0] = optarg; ndevices = 1; break; case OPT_GRAB: grab = true; break; case OPT_VERBOSE: verbose = true; break; case OPT_COMPRESS_MOTION_EVENTS: /* We compress by using ansi escape sequences */ compress_motion_events = is_tty; break; default: if (tools_parse_option(c, optarg, &options) != 0) { usage(NULL); return EXIT_INVALID_USAGE; } break; } } if (optind < argc) { if (backend == BACKEND_UDEV) { usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; do { if (ndevices >= ARRAY_LENGTH(seat_or_devices)) { usage(NULL); return EXIT_INVALID_USAGE; } seat_or_devices[ndevices++] = argv[optind]; } while(++optind < argc); } else if (backend == BACKEND_NONE) { backend = BACKEND_UDEV; seat_or_devices[0] = "seat0"; } memset(&act, 0, sizeof(act)); act.sa_sigaction = sighandler; act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &act, NULL) == -1) { fprintf(stderr, "Failed to set up signal handling (%s)\n", strerror(errno)); return EXIT_FAILURE; } if (verbose) printf("libinput version: %s\n", LIBINPUT_VERSION); li = tools_open_backend(backend, seat_or_devices, verbose, &grab); if (!li) return EXIT_FAILURE; mainloop(li); libinput_unref(li); return EXIT_SUCCESS; } libinput-1.28.1/tools/libinput-debug-events.man000066400000000000000000000121051477265155700215240ustar00rootroot00000000000000.TH libinput-debug-events "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-debug\-events \- debug helper for libinput .SH SYNOPSIS .B libinput debug\-events \fI[options]\fB .PP .B libinput debug\-events \fI[options]\fB \-\-udev \fI\fB .PP .B libinput debug\-events \fI[options]\fB [\-\-device] \fI/dev/input/event0\fB [\fI/dev/input/event1\fB...] .SH DESCRIPTION .PP The .B "libinput debug\-events" tool creates a libinput context and prints all events from these devices. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS .TP 8 .B \-\-device \fI/dev/input/event0\fR Use the given device(s) with the path backend. The \fB\-\-device\fR argument may be omitted. .TP 8 .B \-\-grab Exclusively grab all opened devices. This will prevent events from being delivered to the host system. .TP 8 .B \-\-help Print help .TP 8 .B \-\-quiet Only print libinput messages, don't print anything from this tool. This is useful in combination with --verbose for internal state debugging. .TP 8 .B \-\-show\-keycodes Key events shown by this tool are partially obfuscated to avoid passwords and other sensitive information showing up in the output. Use the .B \-\-show\-keycodes argument to make all keycodes visible. .TP 8 .B \-\-udev \fI\fR Use the udev backend to listen for device notifications on the given seat. The default behavior is equivalent to \-\-udev "seat0". .TP 8 .B \-\-verbose Use verbose output .SS libinput configuration options .TP 8 .B \-\-apply-to="pattern" Configuration options are only applied where the device name matches the pattern. This pattern has no effect on the \fB\-\-disable-sendevents\fR option. .TP 8 .B \-\-disable-sendevents="pattern" Set the send-events option to disabled for the devices matching patterns. This option is not affected by the \fB\-\-apply-to="pattern"\fR option. .TP 8 .B \-\-enable-drag|\-\-disable\-drag Enable or disable tap-and-drag .TP 8 .B \-\-enable\-drag\-lock|\-\-disable\-drag\-lock Enable (in timeout mode) or disable drag-lock .B \-\-enable\-drag\-lock=[sticky|timeout] Enable drag-lock in sticky or timeout mode .TP 8 .B \-\-enable\-dwt|\-\-disable\-dwt Enable or disable disable-while-typing .TP 8 .B \-\-enable\-dwtp|\-\-disable\-dwtp Enable or disable disable-while-trackpointing .TP 8 .B \-\-enable\-left\-handed|\-\-disable\-left\-handed Enable or disable left handed button configuration .TP 8 .B \-\-enable\-middlebutton|\-\-disable\-middlebutton Enable or disable middle button emulation .TP 8 .B \-\-enable\-natural\-scrolling|\-\-disable\-natural\-scrolling Enable or disable natural scrolling .TP 8 .B \-\-enable\-scroll-button-lock|\-\-disable\-scroll-button-lock Enable or disable the scroll button lock .TP 8 .B \-\-enable\-tap|\-\-disable\-tap Enable or disable tap-to-click .TP 8 .B \-\-set\-area="x1/y1 x2/y2" Set the tablet area to the rectangle described by the two points x1/y1 and x2/y2. All coordinates must be in the range [0.0, 1.0]. .TP 8 .B \-\-set\-calibration="1.0 0.0 0.0 0.0 1.0 0.0" Set the first 6 elements of a 3x3 matrix to use for calibration. The third row of the matrix is always "0.0 0.0 0.1". .TP 8 .B \-\-set\-click\-method=[none|clickfinger|buttonareas] Set the desired click method .TP 8 .B \-\-set\-clickfinger\-map=[lrm|lmr] Set button mapping for clickfinger .TP 8 .B \-\-set\-custom\-points=";...;" Sets the n points defining a custom acceleration function The points are defined in a semicolon-separated list of floating point non-negative numbers. Defaults to "0.0;1.0". This only applies to the custom profile. .TP 8 .B \-\-set\-custom\-step= Sets the distance along the x-axis between each point, starting from 0. Defaults to 1.0. This only applies to the custom profile. .TP 8 .B \-\-set\-custom\-type=[fallback|motion|scroll] Sets the type of the custom acceleration function. Defaults to fallback. This only applies to the custom profile. .TP 8 .B \-\-set\-pressure\-range=: Set the tablet tool pressure range to min:max. min and max must be in range [0.0, 1.0]. .TP 8 .B \-\-set\-profile=[adaptive|flat|custom] Set pointer acceleration profile .TP 8 .B \-\-set\-rotation\-angle= Set the rotation angle in degrees (0 to 360). .TP 8 .B \-\-set\-scroll\-button=BTN_MIDDLE Set the button to the given button code .TP 8 .B \-\-set\-scroll\-method=[none|twofinger|edge|button] Set the desired scroll method .TP 8 .B \-\-set\-sendevents=[disabled|enabled|disabled-on-external-mouse] Set the given sendevents mode. This option overrides \fB\-\-disable-sendevents="pattern"\fR for any devices it matches via the \fB\-\-apply-to="pattern"\fR option. .TP 8 .B \-\-set\-speed= Set pointer acceleration speed. The allowed range is [-1, 1]. This only applies to the flat or adaptive profile. .TP 8 .B \-\-set\-tap\-map=[lrm|lmr] Set button mapping for tapping .SH NOTES .PP Events shown by this tool may not correspond to the events seen by a different user of libinput. This tool initializes a separate context. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-debug-gui.c000066400000000000000000001373071477265155700204670ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "util-strings.h" #include "util-macros.h" #include "util-list.h" #include "shared.h" #if HAVE_GTK_WAYLAND #include #include "pointer-constraints-unstable-v1-client-protocol.h" #if HAVE_GTK4 #include #else #include #endif #endif #if HAVE_GTK_X11 #include #include #if HAVE_GTK4 #include #else #include #endif #endif #define clip(val_, min_, max_) min((max_), max((min_), (val_))) enum touch_state { TOUCH_ACTIVE, TOUCH_ENDED, TOUCH_CANCELLED, }; struct touch { enum touch_state state; int x, y; }; struct point { double x, y; }; struct evdev_device { struct list node; struct libevdev *evdev; struct libinput_device *libinput_device; int fd; guint source_id; }; struct window { bool grab; struct tools_options options; struct list evdev_devices; GMainLoop *event_loop; GtkWidget *win; GtkWidget *area; int width, height; /* of window */ /* sprite position */ struct point pointer; struct point unaccelerated; /* these are for the delta coordinates, but they're not * deltas, they are converted into abs positions */ size_t ndeltas; struct point deltas[64]; /* abs position */ struct point abs; /* Wayland and X11 pointer locking */ struct { bool locked; #if HAVE_GTK_WAYLAND struct zwp_pointer_constraints_v1 *wayland_pointer_constraints; struct zwp_locked_pointer_v1 *wayland_locked_pointer; #endif } lock_pointer; /* scroll bar positions */ struct { double vx, vy; double hx, hy; double vx_discrete, vy_discrete; double hx_discrete, hy_discrete; } scroll; /* touch positions */ struct touch touches[32]; /* l/m/r mouse buttons */ struct { bool l, m, r; bool other; const char *other_name; } buttons; /* touchpad swipe */ struct { int nfingers; double x, y; } swipe; struct { int nfingers; double scale; double angle; double x, y; } pinch; struct { int nfingers; bool active; } hold; struct { double x, y; double x_in, y_in; double x_down, y_down; double x_up, y_up; double pressure; double distance; double tilt_x, tilt_y; double rotation; double size_major, size_minor; bool is_down; /* these are for the delta coordinates, but they're not * deltas, they are converted into abs positions */ size_t ndeltas; struct point deltas[64]; } tool; struct { struct { double position; int number; } ring; struct { double position; int number; } strip; struct { double position; int number; } dial; } pad; struct { int rel_x, rel_y; /* REL_X/Y */ int x, y; /* ABS_X/Y */ struct { int x, y; /* ABS_MT_POSITION_X/Y */ bool active; } slots[16]; unsigned int slot; /* ABS_MT_SLOT */ /* So we know when to re-fetch the abs axes */ uintptr_t device, last_device; } evdev; struct libinput_device *devices[50]; }; #if HAVE_GTK_WAYLAND static void wayland_registry_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { struct window *w = data; if (!g_strcmp0(interface, "zwp_pointer_constraints_v1")) { w->lock_pointer.wayland_pointer_constraints = wl_registry_bind(registry, name, &zwp_pointer_constraints_v1_interface, 1); } } static void wayland_registry_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name) { } static struct wl_registry_listener registry_listener = { wayland_registry_global, wayland_registry_global_remove }; static bool wayland_lock_pointer(struct window *w) { GdkDisplay *gdk_display; GdkSeat *gdk_seat; GdkDevice *gdk_device; struct wl_display *display; struct wl_registry *registry; struct wl_pointer *wayland_pointer; struct wl_surface *surface; w->lock_pointer.wayland_pointer_constraints = NULL; gdk_display = gdk_display_get_default(); display = gdk_wayland_display_get_wl_display(gdk_display); gdk_seat = gdk_display_get_default_seat(gdk_display); gdk_device = gdk_seat_get_pointer(gdk_seat); wayland_pointer = gdk_wayland_device_get_wl_pointer(gdk_device); registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, w); wl_display_roundtrip(display); if (!w->lock_pointer.wayland_pointer_constraints) return false; #if HAVE_GTK4 GtkNative *window = gtk_widget_get_native(w->win); GdkSurface *gdk_surface = gtk_native_get_surface(window); surface = gdk_wayland_surface_get_wl_surface(gdk_surface); #else GdkWindow *window = gtk_widget_get_window(w->win); surface = gdk_wayland_window_get_wl_surface(window); #endif w->lock_pointer.wayland_locked_pointer = zwp_pointer_constraints_v1_lock_pointer(w->lock_pointer.wayland_pointer_constraints, surface, wayland_pointer, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); return true; } static void wayland_unlock_pointer(struct window *w) { w->lock_pointer.wayland_pointer_constraints = NULL; zwp_locked_pointer_v1_destroy(w->lock_pointer.wayland_locked_pointer); } static inline bool backend_is_wayland(void) { return GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()); } #endif /* HAVE_GTK_WAYLAND */ #if HAVE_GTK_X11 static bool x_lock_pointer(struct window *w) { Display *x_display; Window x_win; int result; x_display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); #if HAVE_GTK4 GtkNative *window = gtk_widget_get_native(w->win); GdkSurface *surface = gtk_native_get_surface(window); x_win = GDK_SURFACE_XID(surface); #else GdkWindow *window = gtk_widget_get_window(w->win); x_win = GDK_WINDOW_XID(window); #endif result = XGrabPointer(x_display, x_win, False, NoEventMask, GrabModeAsync, GrabModeAsync, x_win, None, CurrentTime); return (result == GrabSuccess); } static void x_unlock_pointer(struct window *w) { Display *x_display; x_display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); XUngrabPointer(x_display, CurrentTime); } static inline bool backend_is_x11(void) { return GDK_IS_X11_DISPLAY(gdk_display_get_default()); } #endif /* HAVE_GTK_X11 */ static bool window_lock_pointer(struct window *w) { if (w->lock_pointer.locked) return true; #if HAVE_GTK_WAYLAND if (backend_is_wayland()) w->lock_pointer.locked = wayland_lock_pointer(w); #endif #if HAVE_GTK_X11 if (backend_is_x11()) w->lock_pointer.locked = x_lock_pointer(w); #endif return w->lock_pointer.locked; } static void window_unlock_pointer(struct window *w) { if (!w->lock_pointer.locked) return; w->lock_pointer.locked = false; #if HAVE_GTK_WAYLAND if (backend_is_wayland()) wayland_unlock_pointer(w); #endif #if HAVE_GTK_X11 if (backend_is_x11()) x_unlock_pointer(w); #endif } LIBINPUT_ATTRIBUTE_PRINTF(1, 2) static inline void msg(const char *fmt, ...) { va_list args; printf("info: "); va_start(args, fmt); vprintf(fmt, args); va_end(args); } static inline void draw_evdev_rel(struct window *w, cairo_t *cr) { int center_x, center_y; cairo_save(cr); cairo_set_source_rgb(cr, .2, .2, .8); center_x = w->width/2 - 400; center_y = w->height/2; cairo_arc(cr, center_x, center_y, 10, 0, 2 * M_PI); cairo_stroke(cr); if (w->evdev.rel_x) { int dir = w->evdev.rel_x > 0 ? 1 : -1; for (int i = 0; i < abs(w->evdev.rel_x); i++) { cairo_move_to(cr, center_x + (i + 1) * 20 * dir, center_y - 20); cairo_rel_line_to(cr, 0, 40); cairo_rel_line_to(cr, 20 * dir, -20); cairo_rel_line_to(cr, -20 * dir, -20); cairo_fill(cr); } } if (w->evdev.rel_y) { int dir = w->evdev.rel_y > 0 ? 1 : -1; for (int i = 0; i < abs(w->evdev.rel_y); i++) { cairo_move_to(cr, center_x - 20, center_y + (i + 1) * 20 * dir); cairo_rel_line_to(cr, 40, 0); cairo_rel_line_to(cr, -20, 20 * dir); cairo_rel_line_to(cr, -20, -20 * dir); cairo_fill(cr); } } cairo_restore(cr); } static inline void draw_evdev_abs(struct window *w, cairo_t *cr) { static const struct input_absinfo *ax = NULL, *ay = NULL; const int normalized_width = 200; int outline_width = normalized_width, outline_height = normalized_width * 0.75; int center_x, center_y; int width, height; int x, y; cairo_save(cr); center_x = w->width/2 + 400; center_y = w->height/2; /* Always the outline even if we didn't get any abs events yet so it * doesn't just appear out of nowhere */ if (w->evdev.device == 0) goto draw_outline; /* device has changed, so the abs proportions/dimensions have * changed. */ if (w->evdev.device != w->evdev.last_device) { struct evdev_device *d; ax = NULL; ay = NULL; list_for_each(d, &w->evdev_devices, node) { if ((uintptr_t)d->libinput_device != w->evdev.device) continue; ax = libevdev_get_abs_info(d->evdev, ABS_X); ay = libevdev_get_abs_info(d->evdev, ABS_Y); w->evdev.last_device = w->evdev.device; } } if (ax == NULL || ay == NULL) goto draw_outline; width = ax->maximum - ax->minimum; height = ay->maximum - ay->minimum; outline_height = 1.0 * height/width * normalized_width; outline_width = normalized_width; cairo_set_source_rgb(cr, .2, .2, .8); x = 1.0 * (w->evdev.x - ax->minimum)/width * outline_width; y = 1.0 * (w->evdev.y - ay->minimum)/height * outline_height; x += center_x - outline_width/2; y += center_y - outline_height/2; cairo_arc(cr, x, y, 10, 0, 2 * M_PI); cairo_fill(cr); for (size_t i = 0; i < ARRAY_LENGTH(w->evdev.slots); i++) { if (!w->evdev.slots[i].active) continue; cairo_set_source_rgb(cr, .2 + .2 * (i % 5), .2 + .2 * (i % 5), .8 - .2 * (i % 5)); x = w->evdev.slots[i].x; y = w->evdev.slots[i].y; x = 1.0 * (x - ax->minimum)/width * outline_width; y = 1.0 * (y - ay->minimum)/height * outline_height; x += center_x - outline_width/2; y += center_y - outline_height/2; cairo_arc(cr, x, y, 10, 0, 2 * M_PI); cairo_fill(cr); char finger_text[3]; cairo_text_extents_t finger_text_extents; snprintf(finger_text, 3, "%zu", i); cairo_set_source_rgb(cr, 1.f, 1.f, 1.f); cairo_set_font_size(cr, 12.0); cairo_text_extents(cr, finger_text, &finger_text_extents); cairo_move_to(cr, x - finger_text_extents.width/2, y + finger_text_extents.height/2); cairo_show_text(cr, finger_text); } draw_outline: /* The touchpad outline */ cairo_set_source_rgb(cr, .2, .2, .8); cairo_rectangle(cr, center_x - outline_width/2, center_y - outline_height/2, outline_width, outline_height); cairo_stroke(cr); cairo_restore(cr); } static inline void draw_gestures(struct window *w, cairo_t *cr) { int offset; /* swipe */ cairo_save(cr); cairo_translate(cr, w->swipe.x, w->swipe.y); for (int i = 0; i < w->swipe.nfingers; i++) { cairo_set_source_rgb(cr, .8, .8, .4); cairo_arc(cr, (i - 2) * 40, 0, 20, 0, 2 * M_PI); cairo_fill(cr); } for (int i = 0; i < 4; i++) { /* 4 fg max */ cairo_set_source_rgb(cr, 0, 0, 0); cairo_arc(cr, (i - 2) * 40, 0, 20, 0, 2 * M_PI); cairo_stroke(cr); } cairo_restore(cr); /* pinch */ cairo_save(cr); offset = w->pinch.scale * 100; cairo_translate(cr, w->pinch.x, w->pinch.y); cairo_rotate(cr, w->pinch.angle * M_PI/180.0); if (w->pinch.nfingers > 0) { cairo_set_source_rgb(cr, .4, .4, .8); cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI); cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI); cairo_fill(cr); } cairo_set_source_rgb(cr, 0, 0, 0); cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI); cairo_stroke(cr); cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI); cairo_stroke(cr); cairo_restore(cr); /* hold */ cairo_save(cr); cairo_translate(cr, w->width/2, w->height/2 + 100); for (int i = 4; i > 0; i--) { /* 4 fg max */ double r, g, b, hold_alpha; r = .4 + .2 * (i % 2); g = .2; b = .2; hold_alpha = (w->hold.active && i <= w->hold.nfingers) ? 1 : .5; cairo_set_source_rgba(cr, r, g, b, hold_alpha); cairo_arc(cr, 0, 0, 20 * i, 0, 2 * M_PI); cairo_fill(cr); cairo_set_source_rgba(cr, 0, 0, 0, hold_alpha); cairo_arc(cr, 0, 0, 20 * i, 0, 2 * M_PI); cairo_stroke(cr); } cairo_restore(cr); } static inline void draw_scrollbars(struct window *w, cairo_t *cr) { /* normal scrollbars */ cairo_save(cr); cairo_set_source_rgb(cr, .4, .8, 0); cairo_rectangle(cr, w->scroll.vx - 10, w->scroll.vy - 20, 20, 40); cairo_rectangle(cr, w->scroll.hx - 20, w->scroll.hy - 10, 40, 20); cairo_fill(cr); /* discrete scrollbars */ cairo_set_source_rgb(cr, .8, .4, 0); cairo_rectangle(cr, w->scroll.vx_discrete - 5, w->scroll.vy_discrete - 10, 10, 20); cairo_rectangle(cr, w->scroll.hx_discrete - 10, w->scroll.hy_discrete - 5, 20, 10); cairo_fill(cr); cairo_restore(cr); } static inline void draw_touchpoints(struct window *w, cairo_t *cr) { cairo_save(cr); ARRAY_FOR_EACH(w->touches, t) { if (t->state == TOUCH_ACTIVE) cairo_set_source_rgb(cr, .8, .2, .2); else cairo_set_source_rgb(cr, .8, .4, .4); cairo_arc(cr, t->x, t->y, 10, 0, 2 * M_PI); if (t->state == TOUCH_CANCELLED) cairo_stroke(cr); else cairo_fill(cr); } cairo_restore(cr); } static inline void draw_abs_pointer(struct window *w, cairo_t *cr) { cairo_save(cr); cairo_set_source_rgb(cr, .2, .4, .8); cairo_arc(cr, w->abs.x, w->abs.y, 10, 0, 2 * M_PI); cairo_fill(cr); cairo_restore(cr); } static inline void draw_text(cairo_t *cr, const char *text, double x, double y) { cairo_text_extents_t te; cairo_font_extents_t fe; cairo_text_extents(cr, text, &te); cairo_font_extents(cr, &fe); /* center of the rectangle */ cairo_move_to(cr, x, y); cairo_rel_move_to(cr, -te.width/2, -fe.descent + te.height/2); cairo_show_text(cr, text); } static inline void draw_other_button (struct window *w, cairo_t *cr) { const char *name = w->buttons.other_name; cairo_save(cr); if (!w->buttons.other) goto outline; if (!name) name = "undefined"; cairo_set_source_rgb(cr, .2, .8, .8); cairo_rectangle(cr, w->width/2 - 40, w->height - 150, 80, 30); cairo_fill(cr); cairo_set_source_rgb(cr, 0, 0, 0); draw_text(cr, name, w->width/2, w->height - 150 + 15); outline: cairo_set_source_rgb(cr, 0, 0, 0); cairo_rectangle(cr, w->width/2 - 40, w->height - 150, 80, 30); cairo_stroke(cr); cairo_restore(cr); } static inline void draw_buttons(struct window *w, cairo_t *cr) { cairo_save(cr); if (w->buttons.l || w->buttons.m || w->buttons.r) { cairo_set_source_rgb(cr, .2, .8, .8); if (w->buttons.l) cairo_rectangle(cr, w->width/2 - 100, w->height - 200, 70, 30); if (w->buttons.m) cairo_rectangle(cr, w->width/2 - 20, w->height - 200, 40, 30); if (w->buttons.r) cairo_rectangle(cr, w->width/2 + 30, w->height - 200, 70, 30); cairo_fill(cr); } cairo_set_source_rgb(cr, 0, 0, 0); cairo_rectangle(cr, w->width/2 - 100, w->height - 200, 70, 30); cairo_rectangle(cr, w->width/2 - 20, w->height - 200, 40, 30); cairo_rectangle(cr, w->width/2 + 30, w->height - 200, 70, 30); cairo_stroke(cr); cairo_restore(cr); draw_other_button(w, cr); } static inline void draw_pad(struct window *w, cairo_t *cr) { double rx, ry; double pos; char number[3]; rx = w->width/2 - 200; ry = w->height/2 + 100; cairo_save(cr); /* outer ring (for ring) */ cairo_set_source_rgb(cr, .7, .7, .0); cairo_arc(cr, rx, ry, 50, 0, 2 * M_PI); cairo_fill(cr); /* inner ring (for dial) */ cairo_set_source_rgb(cr, 1., 1., 1.); cairo_arc(cr, rx, ry, 30, 0, 2 * M_PI); cairo_fill(cr); /* marker */ /* libinput has degrees and 0 is north, cairo has radians and 0 is * east */ if (w->pad.ring.position != -1) { pos = (w->pad.ring.position + 270) * M_PI/180.0; cairo_set_source_rgb(cr, .0, .0, .0); cairo_set_line_width(cr, 20); cairo_arc(cr, rx, ry, 40, pos - M_PI/8 , pos + M_PI/8); cairo_stroke(cr); snprintf(number, sizeof(number), "%d", w->pad.ring.number); cairo_set_source_rgb(cr, .0, .0, .0); draw_text(cr, number, rx, ry); } if (w->pad.dial.position != -1) { const int degrees_per_click = 15.0; double degrees = fmod(w->pad.dial.position/120 * degrees_per_click, 360); pos = (degrees + 270) * M_PI/180.0; cairo_set_source_rgb(cr, .0, .0, .0); cairo_set_line_width(cr, 20); cairo_arc(cr, rx, ry, 20, pos - M_PI/12 , pos + M_PI/12); cairo_stroke(cr); snprintf(number, sizeof(number), "%d", w->pad.dial.number); cairo_set_source_rgb(cr, .0, .0, .0); draw_text(cr, number, rx, ry); } cairo_restore(cr); rx = w->width/2 - 300; ry = w->height/2 + 50; cairo_save(cr); cairo_set_source_rgb(cr, .7, .7, .0); cairo_rectangle(cr, rx, ry, 20, 100); cairo_fill(cr); if (w->pad.strip.position != -1) { pos = w->pad.strip.position * 80; cairo_set_source_rgb(cr, .0, .0, .0); cairo_rectangle(cr, rx, ry + pos, 20, 20); cairo_fill(cr); snprintf(number, sizeof(number), "%d", w->pad.strip.number); cairo_set_source_rgb(cr, .0, .0, .0); draw_text(cr, number, rx + 10, ry - 10); } cairo_restore(cr); } static inline void draw_tablet(struct window *w, cairo_t *cr) { double x, y; int first, last; size_t mask; int rx, ry; /* pressure/distance bars */ rx = w->width/2 + 100; ry = w->height/2 + 50; cairo_save(cr); cairo_set_source_rgb(cr, .2, .6, .6); cairo_rectangle(cr, rx, ry, 20, 100); cairo_stroke(cr); if (w->tool.distance > 0) { double pos = w->tool.distance * 100; cairo_rectangle(cr, rx, ry + 100 - pos, 20, 5); cairo_fill(cr); } if (w->tool.pressure > 0) { double pos = w->tool.pressure * 100; if (w->tool.is_down) cairo_rectangle(cr, rx + 25, ry + 95, 5, 5); cairo_rectangle(cr, rx, ry + 100 - pos, 20, pos); cairo_fill(cr); } cairo_restore(cr); /* tablet tool, square for prox-in location */ cairo_save(cr); cairo_set_source_rgb(cr, .2, .6, .6); if (w->tool.x_in && w->tool.y_in) { cairo_rectangle(cr, w->tool.x_in - 15, w->tool.y_in - 15, 30, 30); cairo_stroke(cr); } if (w->tool.x_down && w->tool.y_down) { cairo_rectangle(cr, w->tool.x_down - 10, w->tool.y_down - 10, 20, 20); cairo_stroke(cr); } if (w->tool.x_up && w->tool.y_up) { cairo_rectangle(cr, w->tool.x_up - 10, w->tool.y_up - 10, 20, 20); cairo_stroke(cr); } if (w->tool.pressure) cairo_set_source_rgb(cr, .2, .8, .8); cairo_translate(cr, w->tool.x, w->tool.y); /* scale of 2.5 is large enough to make the marker visible around the physical totem */ cairo_scale(cr, 1.0 + w->tool.size_major * 2.5, 1.0 + w->tool.size_minor * 2.5); cairo_scale(cr, 1.0 + w->tool.tilt_x/30.0, 1.0 + w->tool.tilt_y/30.0); if (w->tool.rotation) cairo_rotate(cr, w->tool.rotation * M_PI/180.0); if (w->tool.pressure) cairo_set_source_rgb(cr, .8, .8, .2); cairo_arc(cr, 0, 0, 1 + 10 * max(w->tool.pressure, w->tool.distance), 0, 2 * M_PI); cairo_fill(cr); cairo_restore(cr); /* The line to indicate the origin */ if (w->tool.size_major) { cairo_save(cr); cairo_scale(cr, 1.0, 1.0); cairo_translate(cr, w->tool.x, w->tool.y); if (w->tool.rotation) cairo_rotate(cr, w->tool.rotation * M_PI/180.0); cairo_set_source_rgb(cr, .0, .0, .0); cairo_move_to(cr, 0, 0); cairo_rel_line_to(cr, 0, -w->tool.size_major * 2.5); cairo_stroke(cr); cairo_restore(cr); } /* tablet deltas */ mask = ARRAY_LENGTH(w->tool.deltas); first = max(w->tool.ndeltas + 1, mask) - mask; last = w->tool.ndeltas; cairo_save(cr); cairo_set_source_rgb(cr, .8, .8, .2); x = w->tool.deltas[first % mask].x; y = w->tool.deltas[first % mask].y; cairo_move_to(cr, x, y); for (int i = first + 1; i < last; i++) { x = w->tool.deltas[i % mask].x; y = w->tool.deltas[i % mask].y; cairo_line_to(cr, x, y); } cairo_stroke(cr); cairo_restore(cr); } static inline void draw_pointer(struct window *w, cairo_t *cr) { double x, y; int first, last; size_t mask; /* draw pointer sprite */ cairo_set_source_rgb(cr, 0, 0, 0); cairo_save(cr); cairo_move_to(cr, w->pointer.x, w->pointer.y); cairo_rel_line_to(cr, 10, 15); cairo_rel_line_to(cr, -10, 0); cairo_rel_line_to(cr, 0, -15); cairo_fill(cr); /* draw unaccelerated sprite */ cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_save(cr); cairo_move_to(cr, w->unaccelerated.x, w->unaccelerated.y); cairo_rel_line_to(cr, -5, -10); cairo_rel_line_to(cr, 10, 0); cairo_rel_line_to(cr, -5, 10); cairo_fill(cr); /* pointer deltas */ mask = ARRAY_LENGTH(w->deltas); first = max(w->ndeltas + 1, mask) - mask; last = w->ndeltas; cairo_set_source_rgb(cr, .8, .5, .2); x = w->deltas[first % mask].x; y = w->deltas[first % mask].y; cairo_move_to(cr, x, y); for (int i = first + 1; i < last; i++) { x = w->deltas[i % mask].x; y = w->deltas[i % mask].y; cairo_line_to(cr, x, y); } cairo_stroke(cr); cairo_restore(cr); } static inline void draw_background(struct window *w, cairo_t *cr) { int x1, x2, y1, y2, x3, y3, x4, y4; int cols; /* 10px and 5px grids */ cairo_save(cr); cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); x1 = w->width/2 - 200; y1 = w->height/2 - 200; x2 = w->width/2 + 200; y2 = w->height/2 - 200; for (cols = 1; cols < 10; cols++) { cairo_move_to(cr, x1 + 10 * cols, y1); cairo_rel_line_to(cr, 0, 100); cairo_move_to(cr, x1, y1 + 10 * cols); cairo_rel_line_to(cr, 100, 0); cairo_move_to(cr, x2 + 5 * cols, y2); cairo_rel_line_to(cr, 0, 50); cairo_move_to(cr, x2, y2 + 5 * cols); cairo_rel_line_to(cr, 50, 0); } /* 3px horiz/vert bar codes */ x3 = w->width/2 - 200; y3 = w->height/2 + 200; x4 = w->width/2 + 200; y4 = w->height/2 + 100; for (cols = 0; cols < 50; cols++) { cairo_move_to(cr, x3 + 3 * cols, y3); cairo_rel_line_to(cr, 0, 20); cairo_move_to(cr, x4, y4 + 3 * cols); cairo_rel_line_to(cr, 20, 0); } cairo_stroke(cr); /* round targets */ for (int i = 0; i <= 3; i++) { x1 = w->width * i/4.0; x2 = w->width * i/4.0; y1 = w->height * 1.0/4.0; y2 = w->height * 3.0/4.0; cairo_arc(cr, x1, y1, 10, 0, 2 * M_PI); cairo_stroke(cr); cairo_arc(cr, x2, y2, 10, 0, 2 * M_PI); cairo_stroke(cr); } cairo_restore(cr); } static gboolean draw(GtkWidget *widget, cairo_t *cr, gpointer data) { struct window *w = data; cairo_set_font_size(cr, 12.0); cairo_set_source_rgb(cr, 1, 1, 1); cairo_rectangle(cr, 0, 0, w->width, w->height); cairo_fill(cr); draw_background(w, cr); draw_evdev_rel(w, cr); draw_evdev_abs(w, cr); draw_pad(w, cr); draw_tablet(w, cr); draw_gestures(w, cr); draw_scrollbars(w, cr); draw_touchpoints(w, cr); draw_abs_pointer(w, cr); draw_buttons(w, cr); draw_pointer(w, cr); return TRUE; } #if HAVE_GTK4 static void draw_gtk4(GtkDrawingArea *widget, cairo_t *cr, int width, int height, gpointer data) { draw(GTK_WIDGET(widget), cr, data); } #endif static void window_place_ui_elements(GtkWidget *widget, struct window *w) { #if HAVE_GTK4 w->width = gtk_widget_get_width(w->area); w->height = gtk_widget_get_height(w->area); #else gtk_window_get_size(GTK_WINDOW(widget), &w->width, &w->height); #endif w->pointer.x = w->width/2; w->pointer.y = w->height/2; w->unaccelerated.x = w->width/2; w->unaccelerated.y = w->height/2; w->deltas[0].x = w->pointer.x; w->deltas[0].y = w->pointer.y; w->scroll.vx = w->width/2; w->scroll.vy = w->height/2; w->scroll.hx = w->width/2; w->scroll.hy = w->height/2; w->scroll.vx_discrete = w->width/2; w->scroll.vy_discrete = w->height/2; w->scroll.hx_discrete = w->width/2; w->scroll.hy_discrete = w->height/2; w->swipe.x = w->width/2; w->swipe.y = w->height/2; w->pinch.scale = 1.0; w->pinch.x = w->width/2; w->pinch.y = w->height/2; } #if HAVE_GTK4 static void map_event_cb(GtkDrawingArea *widget, int width, int height, gpointer data) { struct window *w = data; window_place_ui_elements(GTK_WIDGET(widget), w); gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(w->area), draw_gtk4, w, NULL); gtk_widget_set_cursor_from_name(w->win, "none"); window_lock_pointer(w); } #else static void map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { struct window *w = data; GdkDisplay *display; GdkWindow *window; window_place_ui_elements(widget, w); g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w); window = gdk_event_get_window(event); display = gdk_window_get_display(window); gdk_window_set_cursor(gtk_widget_get_window(w->win), gdk_cursor_new_for_display(display, GDK_BLANK_CURSOR)); window_lock_pointer(w); } #endif static void window_quit(struct window *w) { g_main_loop_quit(w->event_loop); } #if HAVE_GTK4 static gboolean window_delete_event_cb(GtkWindow *window, gpointer data) { struct window *w = data; window_quit(w); return TRUE; } #else static void window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { struct window *w = data; window_quit(w); } #endif static void window_init(struct window *w) { list_init(&w->evdev_devices); #if HAVE_GTK4 w->win = gtk_window_new(); #else w->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) { #if HAVE_GTK4 gtk_window_minimize(GTK_WINDOW(w->win)); #else gtk_window_iconify(GTK_WINDOW(w->win)); #endif } gtk_window_set_title(GTK_WINDOW(w->win), "libinput debugging tool"); gtk_window_set_default_size(GTK_WINDOW(w->win), 1024, 768); gtk_window_maximize(GTK_WINDOW(w->win)); gtk_window_set_resizable(GTK_WINDOW(w->win), TRUE); gtk_widget_realize(w->win); w->area = gtk_drawing_area_new(); #if HAVE_GTK4 g_signal_connect(G_OBJECT(w->area), "resize", G_CALLBACK(map_event_cb), w); g_signal_connect(G_OBJECT(w->win), "close-request", G_CALLBACK(window_delete_event_cb), w); gtk_window_set_child(GTK_WINDOW(w->win), w->area); gtk_widget_set_visible(w->win, TRUE); #else g_signal_connect(G_OBJECT(w->win), "map-event", G_CALLBACK(map_event_cb), w); g_signal_connect(G_OBJECT(w->win), "delete-event", G_CALLBACK(window_delete_event_cb), w); gtk_widget_set_events(w->win, 0); gtk_widget_set_events(w->area, 0); gtk_container_add(GTK_CONTAINER(w->win), w->area); gtk_widget_show_all(w->win); #endif w->pad.ring.position = -1; w->pad.strip.position = -1; w->pad.dial.position = -1; } static void window_cleanup(struct window *w) { ARRAY_FOR_EACH(w->devices, dev) { if (*dev) libinput_device_unref(*dev); } } static void change_ptraccel(struct window *w, double amount) { ARRAY_FOR_EACH(w->devices, dev) { double speed; enum libinput_config_status status; if (*dev == NULL) continue; if (!libinput_device_config_accel_is_available(*dev)) continue; speed = libinput_device_config_accel_get_speed(*dev); speed = clip(speed + amount, -1, 1); status = libinput_device_config_accel_set_speed(*dev, speed); if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) { msg("%s: failed to change accel to %.2f (%s)\n", libinput_device_get_name(*dev), speed, libinput_config_status_to_str(status)); } else { printf("%s: speed is %.2f\n", libinput_device_get_name(*dev), speed); } } } static int handle_event_evdev(GIOChannel *source, GIOCondition condition, gpointer data) { struct libinput_device *dev = data; struct libinput *li = libinput_device_get_context(dev); struct window *w = libinput_get_user_data(li); struct evdev_device *d, *device = NULL; struct input_event e; int rc; list_for_each(d, &w->evdev_devices, node) { if (d->libinput_device == dev) { device = d; break; } } if (device == NULL) { msg("Unknown device: %s\n", libinput_device_get_name(dev)); return FALSE; } do { rc = libevdev_next_event(device->evdev, LIBEVDEV_READ_FLAG_NORMAL, &e); if (rc == -EAGAIN) { break; } else if (rc == LIBEVDEV_READ_STATUS_SYNC) { msg("SYN_DROPPED received\n"); goto out; } else if (rc != LIBEVDEV_READ_STATUS_SUCCESS) { msg("Error reading event: %s\n", strerror(-rc)); goto out; } #define EVENT(t_, c_) (t_ << 16 | c_) switch (EVENT(e.type, e.code)) { case EVENT(EV_REL, REL_X): w->evdev.rel_x = e.value; break; case EVENT(EV_REL, REL_Y): w->evdev.rel_y = e.value; break; case EVENT(EV_ABS, ABS_MT_SLOT): w->evdev.slot = min((unsigned int)e.value, ARRAY_LENGTH(w->evdev.slots) - 1); w->evdev.device = (uintptr_t)dev; break; case EVENT(EV_ABS, ABS_MT_TRACKING_ID): w->evdev.slots[w->evdev.slot].active = (e.value != -1); w->evdev.device = (uintptr_t)dev; break; case EVENT(EV_ABS, ABS_X): w->evdev.x = e.value; w->evdev.device = (uintptr_t)dev; break; case EVENT(EV_ABS, ABS_Y): w->evdev.y = e.value; w->evdev.device = (uintptr_t)dev; break; case EVENT(EV_ABS, ABS_MT_POSITION_X): w->evdev.slots[w->evdev.slot].x = e.value; w->evdev.device = (uintptr_t)dev; break; case EVENT(EV_ABS, ABS_MT_POSITION_Y): w->evdev.slots[w->evdev.slot].y = e.value; w->evdev.device = (uintptr_t)dev; break; } } while (rc == LIBEVDEV_READ_STATUS_SUCCESS); gtk_widget_queue_draw(w->area); out: return TRUE; } static void register_evdev_device(struct window *w, struct libinput_device *dev) { GIOChannel *c; struct udev_device *ud; struct libevdev *evdev; const char *device_node; int fd; struct evdev_device *d; ud = libinput_device_get_udev_device(dev); device_node = udev_device_get_devnode(ud); fd = open(device_node, O_RDONLY|O_NONBLOCK); if (fd == -1) { msg("failed to open %s, evdev events unavailable\n", device_node); goto out; } if (libevdev_new_from_fd(fd, &evdev) != 0) { msg("failed to create context for %s, evdev events unavailable\n", device_node); goto out; } d = zalloc(sizeof *d); list_append(&w->evdev_devices, &d->node); d->fd = fd; d->evdev = evdev; d->libinput_device =libinput_device_ref(dev); c = g_io_channel_unix_new(fd); g_io_channel_set_encoding(c, NULL, NULL); d->source_id = g_io_add_watch(c, G_IO_IN, handle_event_evdev, d->libinput_device); fd = -1; out: close(fd); udev_device_unref(ud); } static void unregister_evdev_device(struct window *w, struct libinput_device *dev) { struct evdev_device *d; list_for_each_safe(d, &w->evdev_devices, node) { if (d->libinput_device != dev) continue; list_remove(&d->node); g_source_remove(d->source_id); free(libinput_device_get_user_data(d->libinput_device)); libinput_device_unref(d->libinput_device); libevdev_free(d->evdev); close(d->fd); free(d); w->evdev.last_device = 0; break; } } static void handle_event_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); struct libinput *li; struct window *w; const char *type; li = libinput_event_get_context(ev); w = libinput_get_user_data(li); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) { type = "added"; register_evdev_device(w, dev); tools_device_apply_config(libinput_event_get_device(ev), &w->options); } else { type = "removed"; unregister_evdev_device(w, dev); } msg("%s %-30s %s\n", libinput_device_get_sysname(dev), libinput_device_get_name(dev), type); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) { ARRAY_FOR_EACH(w->devices, device) { if (*device == NULL) { *device = libinput_device_ref(dev); break; } } } else { ARRAY_FOR_EACH(w->devices, device) { if (*device == dev) { libinput_device_unref(*device); *device = NULL; break; } } } } static void handle_event_motion(struct libinput_event *ev, struct window *w) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double dx = libinput_event_pointer_get_dx(p), dy = libinput_event_pointer_get_dy(p); double dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(p), dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(p); struct point point; const int mask = ARRAY_LENGTH(w->deltas); size_t idx; w->pointer.x = clip(w->pointer.x + dx, 0.0, w->width); w->pointer.y = clip(w->pointer.y + dy, 0.0, w->height); w->unaccelerated.x = clip(w->unaccelerated.x + dx_unaccel, 0.0, w->width); w->unaccelerated.y = clip(w->unaccelerated.y + dy_unaccel, 0.0, w->height); idx = w->ndeltas % mask; point = w->deltas[idx]; idx = (w->ndeltas + 1) % mask; point.x += dx_unaccel; point.y += dy_unaccel; w->deltas[idx] = point; w->ndeltas++; } static void handle_event_absmotion(struct libinput_event *ev, struct window *w) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double x = libinput_event_pointer_get_absolute_x_transformed(p, w->width), y = libinput_event_pointer_get_absolute_y_transformed(p, w->height); w->abs.x = x; w->abs.y = y; } static void handle_event_touch(struct libinput_event *ev, struct window *w) { struct libinput_event_touch *t = libinput_event_get_touch_event(ev); int slot = libinput_event_touch_get_seat_slot(t); struct touch *touch; double x, y; if (slot == -1 || slot >= (int) ARRAY_LENGTH(w->touches)) return; touch = &w->touches[slot]; switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TOUCH_UP: touch->state = TOUCH_ENDED; return; case LIBINPUT_EVENT_TOUCH_CANCEL: touch->state = TOUCH_CANCELLED; return; default: break; } x = libinput_event_touch_get_x_transformed(t, w->width), y = libinput_event_touch_get_y_transformed(t, w->height); touch->state = TOUCH_ACTIVE; touch->x = (int)x; touch->y = (int)y; } static void handle_event_axis(struct libinput_event *ev, struct window *w) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); double value; enum libinput_pointer_axis axis; enum libinput_event_type type; type = libinput_event_get_type(ev); axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; if (libinput_event_pointer_has_axis(p, axis)) { value = libinput_event_pointer_get_scroll_value(p, axis); w->scroll.vy += value; w->scroll.vy = clip(w->scroll.vy, 0, w->height); if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) { w->scroll.vy_discrete += value; w->scroll.vy_discrete = clip(w->scroll.vy_discrete, 0, w->height); } } axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; if (libinput_event_pointer_has_axis(p, axis)) { value = libinput_event_pointer_get_scroll_value(p, axis); w->scroll.hx += value; w->scroll.hx = clip(w->scroll.hx, 0, w->width); if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) { w->scroll.hx_discrete += value; w->scroll.hx_discrete = clip(w->scroll.hx_discrete, 0, w->width); } } } static int handle_event_keyboard(struct libinput_event *ev, struct window *w) { struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev); unsigned int key = libinput_event_keyboard_get_key(k); if (libinput_event_keyboard_get_key_state(k) == LIBINPUT_KEY_STATE_RELEASED) return 0; switch(key) { case KEY_ESC: return 1; case KEY_UP: change_ptraccel(w, 0.1); break; case KEY_DOWN: change_ptraccel(w, -0.1); break; default: break; } return 0; } static void handle_event_button(struct libinput_event *ev, struct window *w) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); unsigned int button = libinput_event_pointer_get_button(p); bool is_press; is_press = libinput_event_pointer_get_button_state(p) == LIBINPUT_BUTTON_STATE_PRESSED; switch (button) { case BTN_LEFT: w->buttons.l = is_press; break; case BTN_RIGHT: w->buttons.r = is_press; break; case BTN_MIDDLE: w->buttons.m = is_press; break; default: w->buttons.other = is_press; w->buttons.other_name = libevdev_event_code_get_name(EV_KEY, button); } } static void handle_event_swipe(struct libinput_event *ev, struct window *w) { struct libinput_event_gesture *g = libinput_event_get_gesture_event(ev); int nfingers; double dx, dy; nfingers = libinput_event_gesture_get_finger_count(g); switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: w->swipe.nfingers = nfingers; w->swipe.x = w->width/2; w->swipe.y = w->height/2; break; case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: dx = libinput_event_gesture_get_dx(g); dy = libinput_event_gesture_get_dy(g); w->swipe.x += dx; w->swipe.y += dy; break; case LIBINPUT_EVENT_GESTURE_SWIPE_END: w->swipe.nfingers = 0; w->swipe.x = w->width/2; w->swipe.y = w->height/2; break; default: abort(); } } static void handle_event_pinch(struct libinput_event *ev, struct window *w) { struct libinput_event_gesture *g = libinput_event_get_gesture_event(ev); int nfingers; double dx, dy; nfingers = libinput_event_gesture_get_finger_count(g); switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: w->pinch.nfingers = nfingers; w->pinch.x = w->width/2; w->pinch.y = w->height/2; break; case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: dx = libinput_event_gesture_get_dx(g); dy = libinput_event_gesture_get_dy(g); w->pinch.x += dx; w->pinch.y += dy; w->pinch.scale = libinput_event_gesture_get_scale(g); w->pinch.angle += libinput_event_gesture_get_angle_delta(g); break; case LIBINPUT_EVENT_GESTURE_PINCH_END: w->pinch.nfingers = 0; w->pinch.x = w->width/2; w->pinch.y = w->height/2; w->pinch.angle = 0.0; w->pinch.scale = 1.0; break; default: abort(); } } static void handle_event_hold(struct libinput_event *ev, struct window *w) { struct libinput_event_gesture *g = libinput_event_get_gesture_event(ev); int nfingers; nfingers = libinput_event_gesture_get_finger_count(g); switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: w->hold.nfingers = nfingers; w->hold.active = true; break; case LIBINPUT_EVENT_GESTURE_HOLD_END: w->hold.nfingers = nfingers; w->hold.active = false; break; default: abort(); } } static void handle_event_tablet(struct libinput_event *ev, struct window *w) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); double x, y; struct point point; int idx; const int mask = ARRAY_LENGTH(w->tool.deltas); bool is_press; unsigned int button; x = libinput_event_tablet_tool_get_x_transformed(t, w->width); y = libinput_event_tablet_tool_get_y_transformed(t, w->height); switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: tools_tablet_tool_apply_config(tool, &w->options); if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { w->tool.x_in = 0; w->tool.y_in = 0; w->tool.x_down = 0; w->tool.y_down = 0; w->tool.x_up = 0; w->tool.y_up = 0; } else { w->tool.x_in = x; w->tool.y_in = y; w->tool.ndeltas = 0; w->tool.deltas[0].x = w->width/2; w->tool.deltas[0].y = w->height/2; } break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); w->tool.distance = libinput_event_tablet_tool_get_distance(t); w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); if (libinput_event_tablet_tool_get_tip_state(t) == LIBINPUT_TABLET_TOOL_TIP_DOWN) { w->tool.x_down = x; w->tool.y_down = y; w->tool.is_down = true; } else { w->tool.x_up = x; w->tool.y_up = y; w->tool.is_down = false; } _fallthrough_; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: w->tool.x = x; w->tool.y = y; w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); w->tool.distance = libinput_event_tablet_tool_get_distance(t); w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); w->tool.rotation = libinput_event_tablet_tool_get_rotation(t); w->tool.size_major = libinput_event_tablet_tool_get_size_major(t); w->tool.size_minor = libinput_event_tablet_tool_get_size_minor(t); /* Add the delta to the last position and store them as abs * coordinates */ idx = w->tool.ndeltas % mask; point = w->tool.deltas[idx]; idx = (w->tool.ndeltas + 1) % mask; point.x += libinput_event_tablet_tool_get_dx(t); point.y += libinput_event_tablet_tool_get_dy(t); w->tool.deltas[idx] = point; w->tool.ndeltas++; break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: is_press = libinput_event_tablet_tool_get_button_state(t) == LIBINPUT_BUTTON_STATE_PRESSED; button = libinput_event_tablet_tool_get_button(t); w->buttons.other = is_press; w->buttons.other_name = libevdev_event_code_get_name(EV_KEY, button); break; default: abort(); } } static void handle_event_tablet_pad(struct libinput_event *ev, struct window *w) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); bool is_press; unsigned int button; static const char *pad_buttons[] = { "Pad 0", "Pad 1", "Pad 2", "Pad 3", "Pad 4", "Pad 5", "Pad 6", "Pad 7", "Pad 8", "Pad 9", "Pad >= 10" }; double position, delta; double number; switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_PAD_BUTTON: is_press = libinput_event_tablet_pad_get_button_state(p) == LIBINPUT_BUTTON_STATE_PRESSED; button = libinput_event_tablet_pad_get_button_number(p); w->buttons.other = is_press; w->buttons.other_name = pad_buttons[min(button, 10)]; break; case LIBINPUT_EVENT_TABLET_PAD_RING: position = libinput_event_tablet_pad_get_ring_position(p); number = libinput_event_tablet_pad_get_ring_number(p); w->pad.ring.number = number; w->pad.ring.position = position; break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: position = libinput_event_tablet_pad_get_strip_position(p); number = libinput_event_tablet_pad_get_strip_number(p); w->pad.strip.number = number; w->pad.strip.position = position; break; case LIBINPUT_EVENT_TABLET_PAD_DIAL: delta = libinput_event_tablet_pad_get_dial_delta_v120(p); number = libinput_event_tablet_pad_get_dial_number(p); if (w->pad.dial.number != number) w->pad.dial.position = -delta; w->pad.dial.number = number; w->pad.dial.position += delta; break; default: abort(); } } static gboolean handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) { struct libinput *li = data; struct window *w = libinput_get_user_data(li); struct libinput_event *ev; tools_dispatch(li); while ((ev = libinput_get_event(li))) { switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: case LIBINPUT_EVENT_DEVICE_REMOVED: handle_event_device_notify(ev); break; case LIBINPUT_EVENT_POINTER_MOTION: handle_event_motion(ev, w); break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: handle_event_absmotion(ev, w); break; case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_CANCEL: handle_event_touch(ev, w); break; case LIBINPUT_EVENT_TOUCH_FRAME: break; case LIBINPUT_EVENT_POINTER_AXIS: /* ignore */ break; case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: handle_event_axis(ev, w); break; case LIBINPUT_EVENT_POINTER_BUTTON: handle_event_button(ev, w); break; case LIBINPUT_EVENT_KEYBOARD_KEY: if (handle_event_keyboard(ev, w)) { libinput_event_destroy(ev); window_quit(w); return FALSE; } break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: case LIBINPUT_EVENT_GESTURE_SWIPE_END: handle_event_swipe(ev, w); break; case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: case LIBINPUT_EVENT_GESTURE_PINCH_END: handle_event_pinch(ev, w); break; case LIBINPUT_EVENT_GESTURE_HOLD_BEGIN: case LIBINPUT_EVENT_GESTURE_HOLD_END: handle_event_hold(ev, w); break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: case LIBINPUT_EVENT_TABLET_TOOL_TIP: case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: handle_event_tablet(ev, w); break; case LIBINPUT_EVENT_TABLET_PAD_BUTTON: case LIBINPUT_EVENT_TABLET_PAD_RING: case LIBINPUT_EVENT_TABLET_PAD_STRIP: case LIBINPUT_EVENT_TABLET_PAD_DIAL: handle_event_tablet_pad(ev, w); break; case LIBINPUT_EVENT_TABLET_PAD_KEY: break; case LIBINPUT_EVENT_SWITCH_TOGGLE: break; } libinput_event_destroy(ev); } gtk_widget_queue_draw(w->area); return TRUE; } static void sockets_init(struct libinput *li) { GIOChannel *c = g_io_channel_unix_new(libinput_get_fd(li)); g_io_channel_set_encoding(c, NULL, NULL); g_io_add_watch(c, G_IO_IN, handle_event_libinput, li); } static void usage(struct option *opts) { printf("Usage: libinput debug-gui [options] [--udev |[--device] /dev/input/event0]\n"); if (opts) tools_print_usage_option_list(opts); } static gboolean signal_handler(void *data) { struct libinput *li = data; struct window *w = libinput_get_user_data(li); window_quit(w); return FALSE; } int main(int argc, char **argv) { struct window w = {0}; struct tools_options options; struct libinput *li; enum tools_backend backend = BACKEND_NONE; const char *seat_or_device[2] = {"seat0", NULL}; bool verbose = false; bool gtk_init = false; #if HAVE_GTK4 gtk_init = gtk_init_check(); #else gtk_init = gtk_init_check(&argc, &argv); #endif if (!gtk_init) return 77; tools_init_options(&options); while (1) { int c; int option_index = 0; enum { OPT_DEVICE = 1, OPT_UDEV, OPT_GRAB, OPT_VERBOSE, }; static struct option opts[] = { CONFIGURATION_OPTIONS, { "help", no_argument, 0, 'h' }, { "device", required_argument, 0, OPT_DEVICE }, { "udev", required_argument, 0, OPT_UDEV }, { "grab", no_argument, 0, OPT_GRAB }, { "verbose", no_argument, 0, OPT_VERBOSE }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "h", opts, &option_index); if (c == -1) break; switch(c) { case '?': exit(EXIT_INVALID_USAGE); break; case 'h': usage(opts); exit(0); break; case OPT_DEVICE: backend = BACKEND_DEVICE; seat_or_device[0] = optarg; break; case OPT_UDEV: backend = BACKEND_UDEV; seat_or_device[0] = optarg; break; case OPT_GRAB: w.grab = true; break; case OPT_VERBOSE: verbose = true; break; default: if (tools_parse_option(c, optarg, &options) != 0) { usage(NULL); return EXIT_INVALID_USAGE; } break; } } if (optind < argc) { if (optind < argc - 1 || backend != BACKEND_NONE) { usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; seat_or_device[0] = argv[optind]; } else if (backend == BACKEND_NONE) { backend = BACKEND_UDEV; } li = tools_open_backend(backend, seat_or_device, verbose, &w.grab); if (!li) return EXIT_FAILURE; libinput_set_user_data(li, &w); g_unix_signal_add(SIGINT, signal_handler, li); window_init(&w); w.options = options; sockets_init(li); handle_event_libinput(NULL, 0, li); w.event_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(w.event_loop); window_unlock_pointer(&w); window_cleanup(&w); libinput_unref(li); return EXIT_SUCCESS; } libinput-1.28.1/tools/libinput-debug-gui.man000066400000000000000000000103461477265155700210110ustar00rootroot00000000000000.TH libinput-debug-gui "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-debug\-gui \- visual debug helper for libinput .SH SYNOPSIS .B libinput debug\-gui \fI[options]\fB .PP .B libinput debug\-gui \fI[options]\fB \-\-udev \fI\fB .PP .B libinput debug\-gui \fI[options]\fB [\-\-device] \fI/dev/input/event0\fB .SH DESCRIPTION .PP The .B "libinput debug\-gui" tool creates a libinput context and a full-screen GTK window to visualize events processed by libinput. This tool exclusively grabs pointing devices and stops them from interacting with the rest of the GUI. .PP .B Hit Esc to exit this tool. .PP This is a debugging tool only, its output or behavior may change at any time. Do not rely on the output or the behavior. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS .TP 8 .B \-\-device \fI/dev/input/event0\fR Use the given device with the path backend. The \fB\-\-device\fR argument may be omitted. .TP 8 .B \-\-grab Exclusively grab all opened devices. This will prevent events from being delivered to the host system. .TP 8 .B \-\-help Print help .TP 8 .B \-\-udev \fI\fR Use the udev backend to listen for device notifications on the given seat. The default behavior is equivalent to \-\-udev "seat0". .TP 8 .B \-\-verbose Use verbose output .PP For libinput configuration options, see libinput-debug-events(1) .SH FEATURES .PP .TP 8 .B Cursor movement The cursor is displayed as black triangle. Various markers are displayed in light grey to help debug cusor positioning. The cursor movement is the one as seen by libinput and may not match the cursor movement of the display server. .PP The unaccelerated cusor motion is displayed as a grey upside-down triangle. The movement of this cursor typically reflects the relative motion in device units and can differ significantly to the normal cursor movement. .PP The unaccelerated cursor motion is also displayed as a yellow snake. This is the connected set of recent deltas. Unlike the unaccelerated cursor, these coordinates are not clipped to the window. .TP 8 .B Button testing Four oblongs are displayed at the bottom. The top three are left, middle, right, the bottom one is for any other button and displays the button name on press. .TP 8 .B Scrolling The green oblongs show the scrolling in continuous space, the smaller red oblongs the scroll steps in discrete steps. .TP 8 .B Gestures A set of four horizontal black rings show swipe gestures, with the number of detected fingers filled in. A set of two black rings show pinch gestures, filled when events are detected. .TP 8 .B Touch and absolute mouse events Touch and absolute mouse events are displayed as red and blue circles, respectively, at the touch point or absolute position. .TP 8 .B Tablet tools Events from tablet tools show a cyan square at the proximity-in and proximity-out positions. The tool position is shown as circle and increases in radius with increasing pressure or distance. Pressure and distance are also shown in the vertical bar south-east of center. Where tilt is available, the circle changes to an ellipsis to indicate the tilt angle. Relative events from the tablet tool are displayed as a yellow snake, always starting from the center of the window on proximity in. Button events are displayed in the bottom-most button oblong, with the name of the button displayed on press. .TP 8 .B Tablet pads Button events are displayed in the bottom-most button oblong, with the name of the button displayed on press. Dials, ring and strip events are displayed in the yellow 'IO' symbol, with the position of the ring or strip or the delta of the dial filled in when events are available. The number of the dial, ring or strip is displayed when an event is available. .TP 8 .B Kernel events Left of the center is a blue ring to debug kernel relative events (REL_X and REL_Y). Each unit is displayed as one arrow in the respective direction. Right of the center is a blue oblong representing the most recently-used touch device. Touch events are displayed as they are read from the kernel. .SH NOTES .PP Events shown by this tool may not correspond to the events seen by a different user of libinput. This tool initializes a separate context. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-debug-tablet.c000066400000000000000000000365521477265155700211560ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "shared.h" #include "util-macros.h" #include "util-input-event.h" static volatile sig_atomic_t stop = 0; static struct tools_options options; static int termwidth = 78; struct context { struct libinput *libinput; struct libinput_device *device; struct libinput_tablet_tool *tool; struct libevdev *evdev; /* fd[0] ... libinput fd fd[1] ... libevdev fd */ struct pollfd fds[2]; /* libinput device state */ bool tip_is_down; double x, y; double x_norm, y_norm; double tx, ty; double dist, pressure; double rotation, slider; unsigned int buttons_down[32]; unsigned int evdev_buttons_down[32]; /* libevdev device state */ struct { int x, y, z; int tilt_x, tilt_y; int distance, pressure; } abs; }; LIBINPUT_ATTRIBUTE_PRINTF(1, 2) static void print_line(const char *format, ...) { char empty[] = " "; const int width = 80; int n; va_list args; printf("\r"); va_start(args, format); n = vprintf(format, args); va_end(args); printf("%.*s\n", width - n, empty); } static void print_buttons(struct context *ctx, unsigned int *buttons, size_t sz) { char buf[256] = {0}; size_t len = 0; for (size_t i = 0; i < sz; i++) { const char *name; if (buttons[i] == 0) continue; name = libevdev_event_code_get_name(EV_KEY, buttons[i]); len += snprintf(&buf[len], sizeof(buf) - len, "%s ", name); } print_line(" buttons: %s", buf); } static void print_bar(const char *header, double value, double normalized) { char empty[termwidth]; bool oob = false; /* the bar is minimum 10 chars, otherwise 78 or whatever fits. 32 is the manually-added up length of the prefix + [|] */ const int width = max(10, min(78, termwidth - 32)); int left_pad, right_pad; memset(empty, '-', sizeof empty); if (normalized < 0.0 || normalized > 1.0) { normalized = min(max(normalized, 0.0), 1.0); oob = true; } left_pad = width * normalized + 0.5; right_pad = width - left_pad; printf("\r %s%-16s %8.2f [%.*s|%.*s]%s\n", oob ? ANSI_RED : "", header, value, left_pad, empty, right_pad, empty, oob ? ANSI_NORMAL : ""); } static double normalize(struct libevdev *evdev, int code, int value) { const struct input_absinfo *abs; if (!evdev) return 0.0; abs = libevdev_get_abs_info(evdev, code); if (!abs) return 0.0; return 1.0 * (value - abs->minimum)/absinfo_range(abs); } static int print_state(struct context *ctx) { const char *tool_str; double w, h; int lines_printed = 0; if (!ctx->device) { print_line(ANSI_RED "No device connected" ANSI_NORMAL); lines_printed++; } else { libinput_device_get_size(ctx->device, &w, &h); print_line("Device: %s (%s)", libinput_device_get_name(ctx->device), libinput_device_get_sysname(ctx->device)); lines_printed++; } if (!ctx->tool) { print_line(ANSI_RED "No tool in proximity " ANSI_NORMAL); lines_printed++; } else { switch (libinput_tablet_tool_get_type(ctx->tool)) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: tool_str = "pen"; break; case LIBINPUT_TABLET_TOOL_TYPE_ERASER: tool_str = "eraser"; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: tool_str = "brush"; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: tool_str = "pencil"; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: tool_str = "airbrush"; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: tool_str = "mouse"; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: tool_str = "lens"; break; case LIBINPUT_TABLET_TOOL_TYPE_TOTEM: tool_str = "totem"; break; default: abort(); } printf("\rTool: %s serial %#" PRIx64 ", id %#" PRIx64 "\n", tool_str, libinput_tablet_tool_get_serial(ctx->tool), libinput_tablet_tool_get_tool_id(ctx->tool)); lines_printed++; } printf("libinput:\n"); print_line("tip: %s", ctx->tip_is_down ? "down" : "up"); print_bar("x:", ctx->x, ctx->x_norm); print_bar("y:", ctx->y, ctx->y_norm); print_bar("tilt x:", ctx->tx, (ctx->tx + 90)/180); print_bar("tilt y:", ctx->ty, (ctx->ty + 90)/180); print_bar("dist:", ctx->dist, ctx->dist); print_bar("pressure:", ctx->pressure, ctx->pressure); print_bar("rotation:", ctx->rotation, ctx->rotation/360.0); print_bar("slider:", ctx->slider, (ctx->slider + 1.0)/2.0); print_buttons(ctx, ctx->buttons_down, ARRAY_LENGTH(ctx->buttons_down)); lines_printed += 11; printf("evdev:\n"); print_bar("ABS_X:", ctx->abs.x, normalize(ctx->evdev, ABS_X, ctx->abs.x)); print_bar("ABS_Y:", ctx->abs.y, normalize(ctx->evdev, ABS_Y, ctx->abs.y)); print_bar("ABS_Z:", ctx->abs.z, normalize(ctx->evdev, ABS_Z, ctx->abs.z)); print_bar("ABS_TILT_X:", ctx->abs.tilt_x, normalize(ctx->evdev, ABS_TILT_X, ctx->abs.tilt_x)); print_bar("ABS_TILT_Y:", ctx->abs.tilt_y, normalize(ctx->evdev, ABS_TILT_Y, ctx->abs.tilt_y)); print_bar("ABS_DISTANCE:", ctx->abs.distance, normalize(ctx->evdev, ABS_DISTANCE, ctx->abs.distance)); print_bar("ABS_PRESSURE:", ctx->abs.pressure, normalize(ctx->evdev, ABS_PRESSURE, ctx->abs.pressure)); print_buttons(ctx, ctx->evdev_buttons_down, ARRAY_LENGTH(ctx->evdev_buttons_down)); lines_printed += 9; return lines_printed; } static void handle_device_added(struct context *ctx, struct libinput_event *ev) { struct libinput_device *device = libinput_event_get_device(ev); struct udev_device *udev_device; const char *devnode; if (ctx->device) return; if (!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) return; ctx->device = libinput_device_ref(device); udev_device = libinput_device_get_udev_device(device); if (!udev_device) return; devnode = udev_device_get_devnode(udev_device); if (devnode) { int fd = open(devnode, O_RDONLY|O_NONBLOCK); assert(fd != -1); assert(libevdev_new_from_fd(fd, &ctx->evdev) == 0); } udev_device_unref(udev_device); } static void handle_device_removed(struct context *ctx, struct libinput_event *ev) { struct libinput_device *device = libinput_event_get_device(ev); if (ctx->device != device) return; libinput_device_unref(ctx->device); ctx->device = NULL; libevdev_free(ctx->evdev); ctx->evdev = NULL; close(ctx->fds[1].fd); ctx->fds[1].fd = -1; } static void update_tablet_axes(struct context *ctx, struct libinput_event_tablet_tool *t) { ctx->x = libinput_event_tablet_tool_get_x(t); ctx->y = libinput_event_tablet_tool_get_y(t); ctx->x_norm = libinput_event_tablet_tool_get_x_transformed(t, 1.0); ctx->y_norm = libinput_event_tablet_tool_get_y_transformed(t, 1.0); ctx->tx = libinput_event_tablet_tool_get_tilt_x(t); ctx->ty = libinput_event_tablet_tool_get_tilt_y(t); ctx->dist = libinput_event_tablet_tool_get_distance(t); ctx->pressure = libinput_event_tablet_tool_get_pressure(t); ctx->rotation = libinput_event_tablet_tool_get_rotation(t); ctx->slider = libinput_event_tablet_tool_get_slider_position(t); } static void handle_tablet_button_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); unsigned int button = libinput_event_tablet_tool_get_button(t); enum libinput_button_state state = libinput_event_tablet_tool_get_button_state(t); ARRAY_FOR_EACH(ctx->buttons_down, btn) { if (state == LIBINPUT_BUTTON_STATE_PRESSED) { if (*btn == 0) { *btn = button; break; } } else { if (*btn == button) { *btn = 0; break; } } } } static void handle_tablet_axis_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); update_tablet_axes(ctx, t); } static void handle_tablet_proximity_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); if (ctx->tool) { libinput_tablet_tool_unref(ctx->tool); ctx->tool = NULL; } if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) ctx->tool = libinput_tablet_tool_ref(tool); } static void handle_tablet_tip_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); ctx->tip_is_down = libinput_event_tablet_tool_get_tip_state(t) == LIBINPUT_TABLET_TOOL_TIP_DOWN; } static void handle_libinput_events(struct context *ctx) { struct libinput *li = ctx->libinput; struct libinput_event *ev; libinput_dispatch(li); while ((ev = libinput_get_event(li))) { switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: handle_device_added(ctx, ev); tools_device_apply_config(libinput_event_get_device(ev), &options); break; case LIBINPUT_EVENT_DEVICE_REMOVED: handle_device_removed(ctx, ev); break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: handle_tablet_button_event(ctx, ev); break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: handle_tablet_axis_event(ctx, ev); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: { struct libinput_event_tablet_tool *tev = libinput_event_get_tablet_tool_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(tev); tools_tablet_tool_apply_config(tool, &options); handle_tablet_proximity_event(ctx, ev); break; } case LIBINPUT_EVENT_TABLET_TOOL_TIP: handle_tablet_tip_event(ctx, ev); break; default: break; } libinput_event_destroy(ev); } } static void handle_libevdev_events(struct context *ctx) { struct libevdev *evdev = ctx->evdev; struct input_event event; #define evbit(_t, _c) (((_t) << 16) | (_c)) if (!evdev) return; while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event) == LIBEVDEV_READ_STATUS_SUCCESS) { switch(evbit(event.type, event.code)) { case evbit(EV_KEY, BTN_TOOL_PEN): case evbit(EV_KEY, BTN_TOOL_RUBBER): case evbit(EV_KEY, BTN_TOOL_BRUSH): case evbit(EV_KEY, BTN_TOOL_PENCIL): case evbit(EV_KEY, BTN_TOOL_AIRBRUSH): case evbit(EV_KEY, BTN_TOOL_MOUSE): case evbit(EV_KEY, BTN_TOOL_LENS): ctx->evdev_buttons_down[event.code - BTN_TOOL_PEN] = event.value ? event.code : 0; break; /* above tools should be mutually exclusive but let's leave * enough space */ case evbit(EV_KEY, BTN_TOUCH): ctx->evdev_buttons_down[7] = event.value ? event.code : 0; break; case evbit(EV_KEY, BTN_STYLUS): ctx->evdev_buttons_down[8] = event.value ? event.code : 0; break; case evbit(EV_KEY, BTN_STYLUS2): ctx->evdev_buttons_down[9] = event.value ? event.code : 0; break; case evbit(EV_KEY, BTN_STYLUS3): ctx->evdev_buttons_down[10] = event.value ? event.code : 0; break; case evbit(EV_ABS, ABS_X): ctx->abs.x = event.value; break; case evbit(EV_ABS, ABS_Y): ctx->abs.y = event.value; break; case evbit(EV_ABS, ABS_Z): ctx->abs.z = event.value; break; case evbit(EV_ABS, ABS_PRESSURE): ctx->abs.pressure = event.value; break; case evbit(EV_ABS, ABS_TILT_X): ctx->abs.tilt_x = event.value; break; case evbit(EV_ABS, ABS_TILT_Y): ctx->abs.tilt_y = event.value; break; case evbit(EV_ABS, ABS_DISTANCE): ctx->abs.distance = event.value; break; } } } static void sighandler(int signal, siginfo_t *siginfo, void *userdata) { stop = 1; } static void mainloop(struct context *ctx) { unsigned int lines_printed = 20; ctx->fds[0].fd = libinput_get_fd(ctx->libinput); /* pre-load the lines */ for (unsigned int i = 0; i < lines_printed; i++) printf("\n"); do { handle_libinput_events(ctx); handle_libevdev_events(ctx); printf(ANSI_LEFT, 1000); printf(ANSI_UP, lines_printed); lines_printed = print_state(ctx); } while (!stop && poll(ctx->fds, 2, -1) > -1); printf("\n"); } static void usage(void) { printf("Usage: libinput debug-tablet [options] [--udev |--device /dev/input/event0]\n"); } static void init_context(struct context *ctx) { memset(ctx, 0, sizeof *ctx); ctx->fds[0].fd = -1; /* libinput fd */ ctx->fds[0].events = POLLIN; ctx->fds[0].revents = 0; ctx->fds[1].fd = -1; /* libevdev fd */ ctx->fds[1].events = POLLIN; ctx->fds[1].revents = 0; } int main(int argc, char **argv) { struct context ctx; struct libinput *li; enum tools_backend backend = BACKEND_NONE; const char *seat_or_device[2] = {"seat0", NULL}; struct sigaction act; bool grab = false; init_context(&ctx); tools_init_options(&options); while (1) { int c; int option_index = 0; enum { OPT_DEVICE = 1, OPT_UDEV, }; static struct option opts[] = { CONFIGURATION_OPTIONS, { "help", no_argument, 0, 'h' }, { "device", required_argument, 0, OPT_DEVICE }, { "udev", required_argument, 0, OPT_UDEV }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "h", opts, &option_index); if (c == -1) break; switch(c) { case '?': exit(EXIT_INVALID_USAGE); break; case 'h': usage(); exit(EXIT_SUCCESS); break; case OPT_DEVICE: backend = BACKEND_DEVICE; seat_or_device[0] = optarg; break; case OPT_UDEV: backend = BACKEND_UDEV; seat_or_device[0] = optarg; break; default: if (tools_parse_option(c, optarg, &options) != 0) { usage(); return EXIT_INVALID_USAGE; } break; } } if (optind < argc) { if (optind < argc - 1 || backend != BACKEND_NONE) { usage(); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; seat_or_device[0] = argv[optind]; } else if (backend == BACKEND_NONE) { backend = BACKEND_UDEV; } memset(&act, 0, sizeof(act)); act.sa_sigaction = sighandler; act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &act, NULL) == -1) { fprintf(stderr, "Failed to set up signal handling (%s)\n", strerror(errno)); return EXIT_FAILURE; } li = tools_open_backend(backend, seat_or_device, false, &grab); if (!li) return EXIT_FAILURE; struct winsize w; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) termwidth = w.ws_col; ctx.libinput = li; mainloop(&ctx); libinput_unref(li); return EXIT_SUCCESS; } libinput-1.28.1/tools/libinput-debug-tablet.man000066400000000000000000000017761477265155700215070ustar00rootroot00000000000000.TH libinput-debug-tablet "1" .SH NAME libinput\-debug\-tablet\ \- debug and visualize tablet axes .SH SYNOPSIS .B libinput debug-tablet [\-\-help] [options] [\fI/dev/input/event0\fI] .SH DESCRIPTION .PP The .B "libinput debug-tablet" tool debugs the values of the various axes on a tablet. This is an interactive tool. When executed, the tool will prompt the user to interact with the tablet and display the current value on each available axis. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a tablet and uses that node. .TP 8 .B \-\-help Print help .PP Events shown by this tool may not correspond to the events seen by a different user of libinput. This tool initializes a separate context. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-list-devices.c000066400000000000000000000400431477265155700212000ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "util-strings.h" #include "shared.h" static const char * tap_default(struct libinput_device *device) { if (!libinput_device_config_tap_get_finger_count(device)) return "n/a"; if (libinput_device_config_tap_get_default_enabled(device)) return "enabled"; return "disabled"; } static const char * tap_button_map(struct libinput_device *device) { if (!libinput_device_config_tap_get_finger_count(device)) return "n/a"; switch (libinput_device_config_tap_get_button_map(device)) { case LIBINPUT_CONFIG_TAP_MAP_LRM: return "left/right/middle"; case LIBINPUT_CONFIG_TAP_MAP_LMR: return "left/middle/right"; } return ""; } static const char * drag_default(struct libinput_device *device) { if (!libinput_device_config_tap_get_finger_count(device)) return "n/a"; if (libinput_device_config_tap_get_default_drag_enabled(device)) return "enabled"; return "disabled"; } static const char * draglock_default(struct libinput_device *device) { if (!libinput_device_config_tap_get_finger_count(device)) return "n/a"; if (libinput_device_config_tap_get_default_drag_lock_enabled(device)) return "enabled"; return "disabled"; } static const char* left_handed_default(struct libinput_device *device) { if (!libinput_device_config_left_handed_is_available(device)) return "n/a"; if (libinput_device_config_left_handed_get_default(device)) return "enabled"; return "disabled"; } static const char * nat_scroll_default(struct libinput_device *device) { if (!libinput_device_config_scroll_has_natural_scroll(device)) return "n/a"; if (libinput_device_config_scroll_get_default_natural_scroll_enabled(device)) return "enabled"; return "disabled"; } static const char * middle_emulation_default(struct libinput_device *device) { if (!libinput_device_config_middle_emulation_is_available(device)) return "n/a"; if (libinput_device_config_middle_emulation_get_default_enabled(device)) return "enabled"; return "disabled"; } static char * calibration_default(struct libinput_device *device) { char *str; float calibration[6]; if (!libinput_device_config_calibration_has_matrix(device)) { xasprintf(&str, "n/a"); return str; } if (libinput_device_config_calibration_get_default_matrix(device, calibration) == 0) { xasprintf(&str, "identity matrix"); return str; } xasprintf(&str, "%.2f %.2f %.2f %.2f %.2f %.2f", calibration[0], calibration[1], calibration[2], calibration[3], calibration[4], calibration[5]); return str; } static char * scroll_defaults(struct libinput_device *device) { uint32_t scroll_methods; char *str; enum libinput_config_scroll_method method; scroll_methods = libinput_device_config_scroll_get_methods(device); if (scroll_methods == LIBINPUT_CONFIG_SCROLL_NO_SCROLL) { xasprintf(&str, "none"); return str; } method = libinput_device_config_scroll_get_default_method(device); xasprintf(&str, "%s%s%s%s%s%s", (method == LIBINPUT_CONFIG_SCROLL_2FG) ? "*" : "", (scroll_methods & LIBINPUT_CONFIG_SCROLL_2FG) ? "two-finger " : "", (method == LIBINPUT_CONFIG_SCROLL_EDGE) ? "*" : "", (scroll_methods & LIBINPUT_CONFIG_SCROLL_EDGE) ? "edge " : "", (method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "*" : "", (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) ? "button" : ""); return str; } static const char * scroll_button_default(struct libinput_device *device) { uint32_t scroll_methods = libinput_device_config_scroll_get_methods(device); if (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) { uint32_t button = libinput_device_config_scroll_get_default_button(device); return libevdev_event_code_get_name(EV_KEY, button); } return "n/a"; } static const char * scroll_button_lock_default(struct libinput_device *device) { uint32_t scroll_methods = libinput_device_config_scroll_get_methods(device); if (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) { switch (libinput_device_config_scroll_get_default_button_lock(device)) { case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED: return "enabled"; case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED: return "disabled"; } return ""; } return "n/a"; } static char* click_defaults(struct libinput_device *device) { uint32_t click_methods; char *str; enum libinput_config_click_method method; click_methods = libinput_device_config_click_get_methods(device); if (click_methods == LIBINPUT_CONFIG_CLICK_METHOD_NONE) { xasprintf(&str, "none"); return str; } method = libinput_device_config_click_get_default_method(device); xasprintf(&str, "%s%s%s%s", (method == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "*" : "", (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) ? "button-areas " : "", (method == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "*" : "", (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) ? "clickfinger " : ""); return str; } static const char * clickfinger_button_map(struct libinput_device *device) { uint32_t click_methods = libinput_device_config_click_get_methods(device); if (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) { switch (libinput_device_config_click_get_default_clickfinger_button_map(device)) { case LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR: return "left/middle/right"; case LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM: return "left/right/middle"; } return ""; } else { return "n/a"; } } static char* accel_profiles(struct libinput_device *device) { uint32_t profiles; char *str; enum libinput_config_accel_profile profile; if (!libinput_device_config_accel_is_available(device)) { xasprintf(&str, "n/a"); return str; } profiles = libinput_device_config_accel_get_profiles(device); if (profiles == LIBINPUT_CONFIG_ACCEL_PROFILE_NONE) { xasprintf(&str, "none"); return str; } profile = libinput_device_config_accel_get_default_profile(device); xasprintf(&str, "%s%s %s%s %s%s", (profile == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) ? "*" : "", (profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) ? "flat" : "", (profile == LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE) ? "*" : "", (profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE) ? "adaptive" : "", (profile == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) ? "*" : "", (profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) ? "custom" : ""); return str; } static const char * dwt_default(struct libinput_device *device) { if (!libinput_device_config_dwt_is_available(device)) return "n/a"; if (libinput_device_config_dwt_get_default_enabled(device)) return "enabled"; return "disabled"; } static const char * dwtp_default(struct libinput_device *device) { if (!libinput_device_config_dwtp_is_available(device)) return "n/a"; if (libinput_device_config_dwtp_get_default_enabled(device)) return "enabled"; return "disabled"; } static char * rotation_default(struct libinput_device *device) { char *str; double angle; if (!libinput_device_config_rotation_is_available(device)) { xasprintf(&str, "n/a"); return str; } angle = libinput_device_config_rotation_get_angle(device); xasprintf(&str, "%.1f", angle); return str; } static char * area_rectangle(struct libinput_device *device) { if (libinput_device_config_area_has_rectangle(device)) { struct libinput_config_area_rectangle rect = libinput_device_config_area_get_default_rectangle(device); char *str; xasprintf(&str, "(%.2f, %.2f) - (%.2f, %.2f)", rect.x1, rect.y1, rect.x2, rect.y2); return str; } return safe_strdup("n/a"); } static void print_pad_info(struct libinput_device *device) { int nbuttons, nrings, nstrips, ndials, ngroups, nmodes; struct libinput_tablet_pad_mode_group *group; nbuttons = libinput_device_tablet_pad_get_num_buttons(device); nrings = libinput_device_tablet_pad_get_num_rings(device); nstrips = libinput_device_tablet_pad_get_num_strips(device); ndials = libinput_device_tablet_pad_get_num_dials(device); ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); printf("Pad:\n"); printf(" Rings: %d\n", nrings); printf(" Strips: %d\n", nstrips); printf(" Dials: %d\n", ndials); printf(" Buttons: %d\n", nbuttons); printf(" Mode groups: %d\n", ngroups); for (int g = 0; g < ngroups; g++) { group = libinput_device_tablet_pad_get_mode_group(device, g); nmodes = libinput_tablet_pad_mode_group_get_num_modes(group); printf(" Group %d:\n", g); printf(" Modes: %d\n", nmodes); if (nbuttons > 0) { printf(" Buttons:"); for (int b = 0; b < nbuttons; b++) { if (libinput_tablet_pad_mode_group_has_button(group, b)) printf("%s%s%d", b == 0 ? " " : ", ", libinput_tablet_pad_mode_group_button_is_toggle(group, b) ? "*" : "", b); } printf("\n"); } if (nrings > 0) { printf(" Rings:"); for (int r = 0; r < nrings; r++) { if (libinput_tablet_pad_mode_group_has_ring(group, r)) printf("%s%d", r == 0 ? " " : ", ", r); } printf("\n"); } if (nstrips > 0) { printf(" Strips:"); for (int s = 0; s < nstrips; s++) { if (libinput_tablet_pad_mode_group_has_strip(group, s)) printf("%s%d", s == 0 ? " " : ", ", s); } printf("\n"); } if (ndials > 0) { printf(" Dials:"); for (int d = 0; d < ndials; d++) { if (libinput_tablet_pad_mode_group_has_dial(group, d)) printf("%s%d", d == 0 ? " " : ", ", d); } printf("\n"); } } } #define print_aligned(topic, fmt, ...) do {\ printf("%-25s" fmt "\n", topic ":", __VA_ARGS__); \ } while (0) static void print_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); struct libinput_seat *seat = libinput_device_get_seat(dev); struct libinput_device_group *group; struct udev_device *udev_device; double w, h; static int next_group_id = 0; intptr_t group_id; const char *devnode; char *str; const char *bustype = ""; group = libinput_device_get_device_group(dev); group_id = (intptr_t)libinput_device_group_get_user_data(group); if (!group_id) { group_id = ++next_group_id; libinput_device_group_set_user_data(group, (void*)group_id); } udev_device = libinput_device_get_udev_device(dev); devnode = udev_device_get_devnode(udev_device); print_aligned("Device", "%s", libinput_device_get_name(dev)); print_aligned("Kernel", "%s", devnode); switch (libinput_device_get_id_bustype(dev)) { case BUS_USB: bustype = "usb"; break; case BUS_BLUETOOTH: bustype = "bluetooth"; break; case BUS_VIRTUAL: bustype = "virtual"; break; case BUS_I2C: bustype = "i2c"; break; case BUS_HOST: bustype = "host"; break; case BUS_I8042: bustype = "serial"; break; } print_aligned("Id", "%s:%04x:%04x", bustype, libinput_device_get_id_vendor(dev), libinput_device_get_id_product(dev)); print_aligned("Group" , "%d", (int)group_id); print_aligned("Seat", "%s, %s", libinput_seat_get_physical_name(seat), libinput_seat_get_logical_name(seat)); udev_device_unref(udev_device); if (libinput_device_get_size(dev, &w, &h) == 0) print_aligned("Size", "%.fx%.fmm", w, h); print_aligned("Capabilities", "%s%s%s%s%s%s%s", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_KEYBOARD) ? "keyboard " : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_POINTER) ? "pointer " : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH) ? "touch " : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL) ? "tablet " : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_PAD) ? "tablet-pad" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_GESTURE) ? "gesture" : "", libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_SWITCH) ? "switch" : ""); print_aligned("Tap-to-click", "%s", tap_default(dev)); print_aligned("Tap-and-drag", "%s", drag_default(dev)); print_aligned("Tap button map", "%s", tap_button_map(dev)); print_aligned("Tap drag lock", "%s", draglock_default(dev)); print_aligned("Left-handed", "%s", left_handed_default(dev)); print_aligned("Nat.scrolling", "%s", nat_scroll_default(dev)); print_aligned("Middle emulation", "%s", middle_emulation_default(dev)); str = calibration_default(dev); print_aligned("Calibration", "%s", str); free(str); str = scroll_defaults(dev); print_aligned("Scroll methods", "%s", str); free(str); print_aligned("Scroll button", "%s", scroll_button_default(dev)); print_aligned("Scroll button lock", "%s", scroll_button_lock_default(dev)); str = click_defaults(dev); print_aligned("Click methods", "%s", str); free(str); print_aligned("Clickfinger button map", "%s", clickfinger_button_map(dev)); print_aligned("Disable-w-typing", "%s", dwt_default(dev)); print_aligned("Disable-w-trackpointing", "%s", dwtp_default(dev)); str = accel_profiles(dev); print_aligned("Accel profiles", "%s", str); free(str); str = rotation_default(dev); print_aligned("Rotation", "%s", str); free(str); str = area_rectangle(dev); print_aligned("Area rectangle", "%s", str); free(str); if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) print_pad_info(dev); printf("\n"); } static inline void usage(void) { printf("Usage: libinput list-devices [--help|--version]\n"); printf("\n" "--help ...... show this help and exit\n" "--version ... show version information and exit\n" "\n"); } int main(int argc, char **argv) { struct libinput *li; struct libinput_event *ev; bool grab = false; while (1) { int c; int option_index = 0; enum { OPT_HELP = 1, OPT_VERBOSE, }; static struct option opts[] = { CONFIGURATION_OPTIONS, { "help", no_argument, 0, 'h' }, { "verbose", no_argument, 0, OPT_VERBOSE }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "h", opts, &option_index); if (c == -1) break; switch(c) { case '?': return EXIT_INVALID_USAGE; case 'h': case OPT_HELP: usage(); return EXIT_SUCCESS; default: return EXIT_INVALID_USAGE; } } if (optind < argc) { const char *devices[32] = {NULL}; size_t ndevices = 0; do { if (ndevices >= ARRAY_LENGTH(devices) - 1) { usage(); return EXIT_INVALID_USAGE; } devices[ndevices++] = argv[optind]; } while (++optind < argc); li = tools_open_backend(BACKEND_DEVICE, devices, false, &grab); } else { const char *seat[2] = {"seat0", NULL}; li = tools_open_backend(BACKEND_UDEV, seat, false, &grab); } if (!li) return 1; libinput_dispatch(li); while ((ev = libinput_get_event(li))) { if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) print_device_notify(ev); libinput_event_destroy(ev); libinput_dispatch(li); } libinput_unref(li); return EXIT_SUCCESS; } libinput-1.28.1/tools/libinput-list-devices.man000066400000000000000000000034071477265155700215340ustar00rootroot00000000000000.TH libinput-list-devices "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-list\-devices \- list local devices as recognized by libinput and default values of their configuration .SH SYNOPSIS .B libinput list\-devices [\-\-help] .PP .B libinput list\-devices \fI/dev/input/event0\fB [\fI/dev/input/event1\fB...] .SH DESCRIPTION .PP The .B "libinput list\-devices" tool creates a libinput context on the default seat "seat0" and lists devices recognized by libinput. Each device shows available configurations the respective default configuration setting. .PP For options that allow more settings than "enabled/disabled", all available ones are listed. The default setting is prefixed by an asterisk (*). .PP If one or more event node paths are given, only those devices are listed. By default all devices recognized by libinput are listed. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-verbose Use verbose output .SH NOTES .PP libinput\-list\-devices only lists available configuration options for a feature. In some cases a device may support a specific feature but does not expose configuration for it, e.g. when using the device without that particular feature does not make sense. A lack of a configuration option thus does not necessarily mean that this feature does not work. .PP A device may be recognized by libinput but not handled by the X.Org libinput driver or the Wayland compositor. .PP An xorg.conf(5) configuration entry or Wayland compositor setting may have changed configurations on a device. The .B "libinput list\-devices" tool only shows the device's default configuration, not the current configuration. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-list-kernel-devices.man000066400000000000000000000014251477265155700230100ustar00rootroot00000000000000.TH libinput-list-kernel-devices "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-list\-kernel\-devices \- list all kernel input devices .SH SYNOPSIS .B libinput list\-kernel\-devices [\-\-help] .SH DESCRIPTION .PP The .B "libinput list\-kernel\-devices" tool iterates through the list of available kernel devices and prints their device node and device name. By default this tool lists evdev event nodes. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-hid List HID devices instead of evdev device nodes .SH NOTES .PP A device may be available but not recognized by libinput. This may indicate a bug with the udev configuration. See the .B "libinput list\-devices" tools for the devices recognized by libinput. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-list-kernel-devices.py000077500000000000000000000101261477265155700226660ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import argparse import sys try: import pyudev except ModuleNotFoundError as e: print("Error: {}".format(str(e)), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) def list_devices(): devices = {} context = pyudev.Context() for device in context.list_devices(subsystem="input"): if (device.device_node or "").startswith("/dev/input/event"): parent = device.parent if parent is not None: name = parent.properties["NAME"] or "" # The udev name includes enclosing quotes devices[device.device_node] = name[1:-1] def versionsort(key): return int(key[len("/dev/input/event") :]) for k in sorted(devices, key=versionsort): print(f"{k}:\t{devices[k]}") class HidDevice: def __init__(self, name, driver, vendor, product, devpath): self.name = name self.driver = driver self.vendor = vendor self.product = product self.devpath = devpath self.hidraws = [] self.evdevs = [] def list_hid_devices(): devices = [] context = pyudev.Context() for device in context.list_devices(subsystem="hid"): name = device.properties.get("HID_NAME") driver = device.properties.get("DRIVER") devpath = device.properties.get("DEVPATH") id = device.properties.get("HID_ID") or "0:0:0" _, vendor, product = (int(x, 16) for x in id.split(":")) devices.append(HidDevice(name, driver, vendor, product, devpath)) for device in context.list_devices(subsystem="hidraw"): devpath = device.properties["DEVPATH"] for hid in devices: if devpath.startswith(hid.devpath): hid.hidraws.append(f"'{device.device_node}'") for device in context.list_devices(subsystem="input"): if (device.device_node or "").startswith("/dev/input/event"): devpath = device.properties["DEVPATH"] for hid in devices: if devpath.startswith(hid.devpath): hid.evdevs.append(f"'{device.device_node}'") print("hid:") for d in devices: print(f"- name: '{d.name}'") print(f" id: '{d.vendor:04x}:{d.product:04x}'") print(f" driver: '{d.driver}'") print(f" hidraw: [{', '.join(h for h in d.hidraws)}]") print(f" evdev: [{', '.join(h for h in d.evdevs)}]") print("") def main(): parser = argparse.ArgumentParser(description="List kernel devices") parser.add_argument("--hid", action="store_true", default=False) args = parser.parse_args() if args.hid: list_hid_devices() else: list_devices() if __name__ == "__main__": try: main() except KeyboardInterrupt: print("Exited on user request") libinput-1.28.1/tools/libinput-measure-fuzz.man000066400000000000000000000015511477265155700215740ustar00rootroot00000000000000.TH libinput-measure-fuzz "1" .SH NAME libinput\-measure\-fuzz \- measure absolute axis fuzz .SH SYNOPSIS .B libinput measure fuzz [\-\-help] [options] [\fI/dev/input/event0\fI] .SH DESCRIPTION .PP The .B "libinput measure fuzz" tool measures the fuzz for an absolute axis on a kernel device. The current implementation does not actually measure anything, it only prints the relevant information available and suggests a udev rule. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a touchpad device and uses that node. .TP 8 .B \-\-help Print help .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-measure-fuzz.py000077500000000000000000000403431477265155700214560ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the 'Software'), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # import os import sys import argparse import subprocess try: import libevdev import pyudev except ModuleNotFoundError as e: print("Error: {}".format(str(e)), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) DEFAULT_HWDB_FILE = "/usr/lib/udev/hwdb.d/60-evdev.hwdb" OVERRIDE_HWDB_FILE = "/etc/udev/hwdb.d/99-touchpad-fuzz-override.hwdb" class tcolors: GREEN = "\033[92m" RED = "\033[91m" YELLOW = "\033[93m" BOLD = "\033[1m" NORMAL = "\033[0m" def print_bold(msg, **kwargs): print(tcolors.BOLD + msg + tcolors.NORMAL, **kwargs) def print_green(msg, **kwargs): print(tcolors.BOLD + tcolors.GREEN + msg + tcolors.NORMAL, **kwargs) def print_yellow(msg, **kwargs): print(tcolors.BOLD + tcolors.YELLOW + msg + tcolors.NORMAL, **kwargs) def print_red(msg, **kwargs): print(tcolors.BOLD + tcolors.RED + msg + tcolors.NORMAL, **kwargs) class InvalidConfigurationError(Exception): pass class InvalidDeviceError(Exception): pass class Device(libevdev.Device): def __init__(self, path): if path is None: self.path = self.find_touch_device() else: self.path = path fd = open(self.path, "rb") super().__init__(fd) context = pyudev.Context() self.udev_device = pyudev.Devices.from_device_file(context, self.path) def find_touch_device(self): context = pyudev.Context() for device in context.list_devices(subsystem="input"): if not device.get("ID_INPUT_TOUCHPAD", 0): continue if not device.device_node or not device.device_node.startswith( "/dev/input/event" ): continue return device.device_node print("Unable to find a touch device.", file=sys.stderr) sys.exit(1) def check_property(self): """Return a tuple of (xfuzz, yfuzz) with the fuzz as set in the libinput property. Returns None if the property doesn't exist""" axes = { 0x00: self.udev_device.get("LIBINPUT_FUZZ_00"), 0x01: self.udev_device.get("LIBINPUT_FUZZ_01"), 0x35: self.udev_device.get("LIBINPUT_FUZZ_35"), 0x36: self.udev_device.get("LIBINPUT_FUZZ_36"), } if axes[0x35] is not None: if axes[0x35] != axes[0x00]: print_bold( "WARNING: fuzz mismatch ABS_X: {}, ABS_MT_POSITION_X: {}".format( axes[0x00], axes[0x35] ) ) if axes[0x36] is not None: if axes[0x36] != axes[0x01]: print_bold( "WARNING: fuzz mismatch ABS_Y: {}, ABS_MT_POSITION_Y: {}".format( axes[0x01], axes[0x36] ) ) xfuzz = axes[0x35] or axes[0x00] yfuzz = axes[0x36] or axes[0x01] if xfuzz is None and yfuzz is None: return None if (xfuzz is not None and yfuzz is None) or ( xfuzz is None and yfuzz is not None ): raise InvalidConfigurationError("fuzz should be set for both axes") return (int(xfuzz), int(yfuzz)) def check_axes(self): """ Returns a tuple of (xfuzz, yfuzz) with the fuzz as set on the device axis. Returns None if no fuzz is set. """ if not self.has(libevdev.EV_ABS.ABS_X) or not self.has(libevdev.EV_ABS.ABS_Y): raise InvalidDeviceError("device does not have x/y axes") if self.has(libevdev.EV_ABS.ABS_MT_POSITION_X) != self.has( libevdev.EV_ABS.ABS_MT_POSITION_Y ): raise InvalidDeviceError("device does not have both multitouch axes") xfuzz = ( self.absinfo[libevdev.EV_ABS.ABS_X].fuzz or self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_X].fuzz ) yfuzz = ( self.absinfo[libevdev.EV_ABS.ABS_Y].fuzz or self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_Y].fuzz ) if xfuzz == 0 and yfuzz == 0: return None return (xfuzz, yfuzz) def print_fuzz(what, fuzz): print(" Checking {}... ".format(what), end="") if fuzz is None: print("not set") elif fuzz == (0, 0): print("is zero") else: print("x={} y={}".format(*fuzz)) def handle_existing_entry(device, fuzz): # This is getting messy because we don't really know where the entry # could be or how the match rule looks like. So we just check the # default location only. # For the match comparison, we search for the property value in the # file. If there is more than one entry that uses the same # overrides this will generate false positives. # If the lines aren't in the same order in the file, it'll be a false # negative. overrides = { 0x00: device.udev_device.get("EVDEV_ABS_00"), 0x01: device.udev_device.get("EVDEV_ABS_01"), 0x35: device.udev_device.get("EVDEV_ABS_35"), 0x36: device.udev_device.get("EVDEV_ABS_36"), } has_existing_rules = False for key, value in overrides.items(): if value is not None: has_existing_rules = True break if not has_existing_rules: return False print_red("Error! ", end="") print("This device already has axis overrides defined") print("") print_bold("Searching for existing override...") # Construct a template that looks like a hwdb entry (values only) from # the udev property values template = [ " EVDEV_ABS_00={}".format(overrides[0x00]), " EVDEV_ABS_01={}".format(overrides[0x01]), ] if overrides[0x35] is not None: template += [ " EVDEV_ABS_35={}".format(overrides[0x35]), " EVDEV_ABS_36={}".format(overrides[0x36]), ] print("Checking in {}... ".format(OVERRIDE_HWDB_FILE), end="") entry, prefix, lineno = check_file_for_lines(OVERRIDE_HWDB_FILE, template) if entry is not None: print_green("found") print("The existing hwdb entry can be overwritten") return False else: print_red("not found") print("Checking in {}... ".format(DEFAULT_HWDB_FILE), end="") entry, prefix, lineno = check_file_for_lines(DEFAULT_HWDB_FILE, template) if entry is not None: print_green("found") else: print_red("not found") print( "The device has a hwdb override defined but it's not where I expected it to be." ) print("Please look at the libinput documentation for more details.") print("Exiting now.") return True print_bold("Probable entry for this device found in line {}:".format(lineno)) print("\n".join(prefix + entry)) print("") print_bold("Suggested new entry for this device:") new_entry = [] for i in range(0, len(template)): parts = entry[i].split(":") while len(parts) < 4: parts.append("") parts[3] = str(fuzz) new_entry.append(":".join(parts)) print("\n".join(prefix + new_entry)) print("") # Not going to overwrite the 60-evdev.hwdb entry with this program, too # risky. And it may not be our device match anyway. print_bold("You must now:") print( "\n".join( ( "1. Check the above suggestion for sanity. Does it match your device?", "2. Open {} and amend the existing entry".format(DEFAULT_HWDB_FILE), " as recommended above", "", " The property format is:", " EVDEV_ABS_00=min:max:resolution:fuzz", "", " Leave the entry as-is and only add or amend the fuzz value.", " A non-existent value can be skipped, e.g. this entry sets the ", " resolution to 32 and the fuzz to 8", " EVDEV_ABS_00=::32:8", "", "3. Save the edited file", "4. Say Y to the next prompt", ) ) ) cont = input("Continue? [Y/n] ") if cont == "n": raise KeyboardInterrupt if test_hwdb_entry(device, fuzz): print_bold("Please test the new fuzz setting by restarting libinput") print_bold( "Then submit a pull request for this hwdb entry change to " "to systemd at http://github.com/systemd/systemd" ) else: print_bold("The new fuzz setting did not take effect.") print_bold("Did you edit the correct file?") print("Please look at the libinput documentation for more details.") print("Exiting now.") return True def reload_and_trigger_udev(device): import time print("Running systemd-hwdb update") subprocess.run(["systemd-hwdb", "update"], check=True) syspath = device.path.replace("/dev/input/", "/sys/class/input/") time.sleep(2) print("Running udevadm trigger {}".format(syspath)) subprocess.run(["udevadm", "trigger", syspath], check=True) time.sleep(2) def test_hwdb_entry(device, fuzz): reload_and_trigger_udev(device) print_bold("Testing... ", end="") d = Device(device.path) f = d.check_axes() if f is not None: if f == (fuzz, fuzz): print_yellow("Warning") print_bold( "The hwdb applied to the device but libinput's udev " "rules have not picked it up. This should only happen" "if libinput is not installed" ) return True else: print_red("Error") return False else: f = d.check_property() if f is not None and f == (fuzz, fuzz): print_green("Success") return True else: print_red("Error") return False def check_file_for_lines(path, template): """ Checks file at path for the lines given in template. If found, the return value is a tuple of the matching lines and the prefix (i.e. the two lines before the matching lines) """ try: lines = [l[:-1] for l in open(path).readlines()] idx = -1 try: while idx < len(lines) - 1: idx += 1 line = lines[idx] if not line.startswith(" EVDEV_ABS_00"): continue if lines[idx : idx + len(template)] != template: continue return (lines[idx : idx + len(template)], lines[idx - 2 : idx], idx) except IndexError: pass except FileNotFoundError: pass return (None, None, None) def write_udev_rule(device, fuzz): """Write out a udev rule that may match the device, run udevadm trigger and check if the udev rule worked. Of course, there's plenty to go wrong... """ print("") print_bold("Guessing a udev rule to overwrite the fuzz") # Some devices match better on pvr, others on pn, so we get to try both. yay modalias = open("/sys/class/dmi/id/modalias").readlines()[0] ms = modalias.split(":") svn, pn, pvr = None, None, None for m in ms: if m.startswith("svn"): svn = m elif m.startswith("pn"): pn = m elif m.startswith("pvr"): pvr = m # Let's print out both to inform and/or confuse the user template = "\n".join( ( "# {} {}", "evdev:name:{}:dmi:*:{}*:{}*:", " EVDEV_ABS_00=:::{}", " EVDEV_ABS_01=:::{}", " EVDEV_ABS_35=:::{}", " EVDEV_ABS_36=:::{}", "", ) ) rule1 = template.format( svn[3:], device.name, device.name, svn, pvr, fuzz, fuzz, fuzz, fuzz ) rule2 = template.format( svn[3:], device.name, device.name, svn, pn, fuzz, fuzz, fuzz, fuzz ) print("Full modalias is: {}".format(modalias)) print() print_bold("Suggested udev rule, option 1:") print(rule1) print() print_bold("Suggested udev rule, option 2:") print(rule2) print("") # The weird hwdb matching behavior means we match on the least specific # rule (i.e. most wildcards) first although that was supposed to be fixed in # systemd 3a04b789c6f1. # Our rule uses dmi strings and will be more specific than what 60-evdev.hwdb # already has. So we basically throw up our hands because we can't do anything # then. if handle_existing_entry(device, fuzz): return while True: print_bold("Wich rule do you want to to test? 1 or 2? ", end="") yesno = input("Ctrl+C to exit ") if yesno == "1": rule = rule1 break elif yesno == "2": rule = rule2 break fname = OVERRIDE_HWDB_FILE try: fd = open(fname, "x") except FileExistsError: yesno = input("File {} exists, overwrite? [Y/n] ".format(fname)) if yesno.lower == "n": return fd = open(fname, "w") fd.write("# File generated by libinput measure fuzz\n\n") fd.write(rule) fd.close() if test_hwdb_entry(device, fuzz): print("Your hwdb override file is in {}".format(fname)) print_bold("Please test the new fuzz setting by restarting libinput") print_bold( "Then submit a pull request for this hwdb entry to " "systemd at http://github.com/systemd/systemd" ) else: print("The hwdb entry failed to apply to the device.") print("Removing hwdb file again.") os.remove(fname) reload_and_trigger_udev(device) print_bold("What now?") print( "1. Re-run this program and try the other suggested udev rule. If that fails," ) print( "2. File a bug with the suggested udev rule at http://github.com/systemd/systemd" ) def main(args): parser = argparse.ArgumentParser( description="Print fuzz settings and/or suggest udev rules for the fuzz to be adjusted." ) parser.add_argument( "path", metavar="/dev/input/event0", nargs="?", type=str, help="Path to device (optional)", ) parser.add_argument("--fuzz", type=int, help="Suggested fuzz") args = parser.parse_args() try: device = Device(args.path) print_bold("Using {}: {}".format(device.name, device.path)) fuzz = device.check_property() print_fuzz("udev property", fuzz) fuzz = device.check_axes() print_fuzz("axes", fuzz) userfuzz = args.fuzz if userfuzz is not None: write_udev_rule(device, userfuzz) except PermissionError: print("Permission denied, please re-run as root") except InvalidConfigurationError as e: print("Error: {}".format(e)) except InvalidDeviceError as e: print("Error: {}".format(e)) except KeyboardInterrupt: print("Exited on user request") if __name__ == "__main__": main(sys.argv) libinput-1.28.1/tools/libinput-measure-touch-size.man000066400000000000000000000032721477265155700226720ustar00rootroot00000000000000.TH libinput-measure-touch-size "1" .SH NAME libinput\-measure\-touch-size \- measure touch size and orientation of devices .SH SYNOPSIS .B libinput measure touch\-size [\-\-help] [options] [\fI/dev/input/event0\fI] .SH DESCRIPTION .PP The .B "libinput measure touch\-size" tool measures the size and orientation of a touch as provided by the kernel. This is an interactive tool. When executed, the tool will prompt the user to interact with the touch device. On termination, the tool prints a summary of the values seen. This data should be attached to any touch\-size\-related bug report. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a touch-capable device and uses that node. .TP 8 .B \-\-help Print help .TP 8 .B \-\-touch\-thresholds=\fI"down:up"\fR Set the logical touch size thresholds to .I down and .I up, respectively. When a touch exceeds the size in .I down it is considered logically down. If a touch is logically down and goes below the size in .I up, it is considered logically up. The thresholds have to be in device-specific pressure values and it is required that .I down >= .I up. .TP 8 .B \-\-palm\-threshold=\fIN\fR Assume a palm threshold of .I N. The threshold has to be in device-specific pressure values. .PP If the touch-thresholds or the palm-threshold are not provided, this tool uses the thresholds provided by the device quirks (if any) or the built-in defaults. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-measure-touch-size.py000077500000000000000000000270311477265155700225510ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2017 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # import sys import subprocess import argparse try: import libevdev import pyudev except ModuleNotFoundError as e: print("Error: {}".format(str(e)), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) class Range(object): """Class to keep a min/max of a value around""" def __init__(self): self.min = float("inf") self.max = float("-inf") def update(self, value): self.min = min(self.min, value) self.max = max(self.max, value) class Touch(object): """A single data point of a sequence (i.e. one event frame)""" def __init__(self, major=None, minor=None, orientation=None): self._major = major self._minor = minor self._orientation = orientation self.dirty = False @property def major(self): return self._major @major.setter def major(self, major): self._major = major self.dirty = True @property def minor(self): return self._minor @minor.setter def minor(self, minor): self._minor = minor self.dirty = True @property def orientation(self): return self._orientation @orientation.setter def orientation(self, orientation): self._orientation = orientation self.dirty = True def __str__(self): s = "Touch: major {:3d}".format(self.major) if self.minor is not None: s += ", minor {:3d}".format(self.minor) if self.orientation is not None: s += ", orientation {:+3d}".format(self.orientation) return s class TouchSequence(object): """A touch sequence from beginning to end""" def __init__(self, device, tracking_id): self.device = device self.tracking_id = tracking_id self.points = [] self.is_active = True self.is_down = False self.was_down = False self.is_palm = False self.was_palm = False self.is_thumb = False self.was_thumb = False self.major_range = Range() self.minor_range = Range() def append(self, touch): """Add a Touch to the sequence""" self.points.append(touch) self.major_range.update(touch.major) self.minor_range.update(touch.minor) if touch.major < self.device.up or touch.minor < self.device.up: self.is_down = False elif touch.major > self.device.down or touch.minor > self.device.down: self.is_down = True self.was_down = True self.is_palm = touch.major > self.device.palm if self.is_palm: self.was_palm = True self.is_thumb = self.device.thumb != 0 and touch.major > self.device.thumb if self.is_thumb: self.was_thumb = True def finalize(self): """Mark the TouchSequence as complete (finger is up)""" self.is_active = False def __str__(self): return self._str_state() if self.is_active else self._str_summary() def _str_summary(self): if not self.points: return "{:78s}".format("Sequence: no major/minor values recorded") s = "Sequence: major: [{:3d}..{:3d}] ".format( self.major_range.min, self.major_range.max ) if self.device.has_minor: s += "minor: [{:3d}..{:3d}] ".format( self.minor_range.min, self.minor_range.max ) if self.was_down: s += " down" if self.was_palm: s += " palm" if self.was_thumb: s += " thumb" return s def _str_state(self): touch = self.points[-1] s = "{}, tags: {} {} {}".format( touch, "down" if self.is_down else " ", "palm" if self.is_palm else " ", "thumb" if self.is_thumb else " ", ) return s class InvalidDeviceError(Exception): pass class Device(libevdev.Device): def __init__(self, path): if path is None: self.path = self.find_touch_device() else: self.path = path fd = open(self.path, "rb") super().__init__(fd) print("Using {}: {}\n".format(self.name, self.path)) if not self.has(libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR): raise InvalidDeviceError("Device does not have ABS_MT_TOUCH_MAJOR") self.has_minor = self.has(libevdev.EV_ABS.ABS_MT_TOUCH_MINOR) self.has_orientation = self.has(libevdev.EV_ABS.ABS_MT_ORIENTATION) self.up = 0 self.down = 0 self.palm = 0 self.thumb = 0 self._init_thresholds_from_quirks() self.sequences = [] self.touch = Touch(0, 0) self.warned = False def find_touch_device(self): context = pyudev.Context() for device in context.list_devices(subsystem="input"): if not device.get("ID_INPUT_TOUCHPAD", 0) and not device.get( "ID_INPUT_TOUCHSCREEN", 0 ): continue if not device.device_node or not device.device_node.startswith( "/dev/input/event" ): continue return device.device_node print("Unable to find a touch device.", file=sys.stderr) sys.exit(1) def _init_thresholds_from_quirks(self): command = ["libinput", "quirks", "list", self.path] cmd = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if cmd.returncode != 0: print( "Error querying quirks: {}".format(cmd.stderr.decode("utf-8")), file=sys.stderr, ) return stdout = cmd.stdout.decode("utf-8") quirks = [q.split("=") for q in stdout.split("\n")] for q in quirks: if q[0] == "AttrPalmSizeThreshold": self.palm = int(q[1]) elif q[0] == "AttrTouchSizeRange": self.down, self.up = colon_tuple(q[1]) elif q[0] == "AttrThumbSizeThreshold": self.thumb = int(q[1]) def start_new_sequence(self, tracking_id): self.sequences.append(TouchSequence(self, tracking_id)) def current_sequence(self): return self.sequences[-1] def handle_key(self, event): tapcodes = [ libevdev.EV_KEY.BTN_TOOL_DOUBLETAP, libevdev.EV_KEY.BTN_TOOL_TRIPLETAP, libevdev.EV_KEY.BTN_TOOL_QUADTAP, libevdev.EV_KEY.BTN_TOOL_QUINTTAP, ] if event.code in tapcodes and event.value > 0: if not self.warned: self.warned = True print( "\rThis tool cannot handle multiple fingers, " "output will be invalid", file=sys.stderr, ) def handle_abs(self, event): if event.matches(libevdev.EV_ABS.ABS_MT_TRACKING_ID): if event.value > -1: self.start_new_sequence(event.value) else: try: s = self.current_sequence() s.finalize() print("\r{}".format(s)) except IndexError: # If the finger was down during start pass elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MAJOR): self.touch.major = event.value elif event.matches(libevdev.EV_ABS.ABS_MT_TOUCH_MINOR): self.touch.minor = event.value elif event.matches(libevdev.EV_ABS.ABS_MT_ORIENTATION): self.touch.orientation = event.value def handle_syn(self, event): if self.touch.dirty: try: self.current_sequence().append(self.touch) print("\r{}".format(self.current_sequence()), end="") self.touch = Touch( major=self.touch.major, minor=self.touch.minor, orientation=self.touch.orientation, ) except IndexError: pass def handle_event(self, event): if event.matches(libevdev.EV_ABS): self.handle_abs(event) elif event.matches(libevdev.EV_KEY): self.handle_key(event) elif event.matches(libevdev.EV_SYN): self.handle_syn(event) def read_events(self): print("Ready for recording data.") print("Touch sizes used: {}:{}".format(self.down, self.up)) print("Palm size used: {}".format(self.palm)) print("Thumb size used: {}".format(self.thumb)) print( "Place a single finger on the device to measure touch size.\n" "Ctrl+C to exit\n" ) while True: for event in self.events(): self.handle_event(event) def colon_tuple(string): try: ts = string.split(":") t = tuple([int(x) for x in ts]) if len(t) == 2 and t[0] >= t[1]: return t except: # noqa pass msg = "{} is not in format N:M (N >= M)".format(string) raise argparse.ArgumentTypeError(msg) def main(args): parser = argparse.ArgumentParser(description="Measure touch size and orientation") parser.add_argument( "path", metavar="/dev/input/event0", nargs="?", type=str, help="Path to device (optional)", ) parser.add_argument( "--touch-thresholds", metavar="down:up", type=colon_tuple, help="Thresholds when a touch is logically down or up", ) parser.add_argument( "--palm-threshold", metavar="t", type=int, help="Threshold when a touch is a palm", ) args = parser.parse_args() try: device = Device(args.path) if args.touch_thresholds is not None: device.down, device.up = args.touch_thresholds if args.palm_threshold is not None: device.palm = args.palm_threshold device.read_events() except KeyboardInterrupt: pass except (PermissionError, OSError): print("Error: failed to open device") except InvalidDeviceError as e: print( "This device does not have the capabilities for size-based touch detection." ) print("Details: {}".format(e)) if __name__ == "__main__": main(sys.argv) libinput-1.28.1/tools/libinput-measure-touchpad-pressure.man000066400000000000000000000041151477265155700242520ustar00rootroot00000000000000.TH libinput-measure-touchpad-pressure "1" .SH NAME libinput\-measure\-touchpad\-pressure \- measure pressure properties of devices .SH SYNOPSIS .B libinput measure touchpad\-pressure [\-\-help] [options] [\fI/dev/input/event0\fI] .SH DESCRIPTION .PP The .B "libinput measure touchpad\-pressure" tool measures the pressure of touches on a touchpad. This is an interactive tool. When executed, the tool will prompt the user to interact with the touchpad. On termination, the tool prints a summary of the pressure values seen. This data should be attached to any pressure\-related bug report. .PP For a full description on how libinput's pressure-to-click behavior works, see the online documentation here: .I https://wayland.freedesktop.org/libinput/doc/latest/touchpad_pressure.html and .I https://wayland.freedesktop.org/libinput/doc/latest/palm_detection.html .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a touchpad and uses that node. .TP 8 .B \-\-help Print help .TP 8 .B \-\-touch\-thresholds=\fI"down:up"\fR Set the logical touch pressure thresholds to .I down and .I up, respectively. When a touch exceeds the pressure in .I down it is considered logically down. If a touch is logically down and goes below the pressure in .I up, it is considered logically up. The thresholds have to be in device-specific pressure values and it is required that .I down >= .I up. .TP 8 .B \-\-palm\-threshold=\fIN\fR Assume a palm threshold of .I N. The threshold has to be in device-specific pressure values. .TP 8 .B \-\-thumb\-threshold=\fIN\fR Assume a thumb threshold of .I N. The threshold has to be in device-specific pressure values. .PP If the touch-thresholds or the palm-threshold are not provided, this tool uses the thresholds provided by the device quirks (if any) or the built-in defaults. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-measure-touchpad-pressure.py000077500000000000000000000312541477265155700241360ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2017 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # import sys import subprocess import argparse try: import libevdev import pyudev except ModuleNotFoundError as e: print("Error: {}".format(str(e)), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) class TableFormatter(object): ALIGNMENT = 3 def __init__(self): self.colwidths = [] @property def width(self): return sum(self.colwidths) + 1 def headers(self, args): s = "|" align = self.ALIGNMENT - 1 # account for | for arg in args: # +2 because we want space left/right of text w = ((len(arg) + 2 + align) // align) * align self.colwidths.append(w + 1) s += " {:^{width}s} |".format(arg, width=w - 2) return s def values(self, args): s = "|" for w, arg in zip(self.colwidths, args): w -= 1 # width includes | separator if isinstance(arg, str): # We want space margins for strings s += " {:{width}s} |".format(arg, width=w - 2) elif isinstance(arg, bool): s += "{:^{width}s}|".format("x" if arg else " ", width=w) else: s += "{:^{width}d}|".format(arg, width=w) if len(args) < len(self.colwidths): s += "|".rjust(self.width - len(s), " ") return s def separator(self): return "+" + "-" * (self.width - 2) + "+" fmt = TableFormatter() class Range(object): """Class to keep a min/max of a value around""" def __init__(self): self.min = float("inf") self.max = float("-inf") def update(self, value): self.min = min(self.min, value) self.max = max(self.max, value) class Touch(object): """A single data point of a sequence (i.e. one event frame)""" def __init__(self, pressure=None): self.pressure = pressure class TouchSequence(object): """A touch sequence from beginning to end""" def __init__(self, device, tracking_id): self.device = device self.tracking_id = tracking_id self.points = [] self.is_active = True self.is_down = False self.was_down = False self.is_palm = False self.was_palm = False self.is_thumb = False self.was_thumb = False self.prange = Range() def append(self, touch): """Add a Touch to the sequence""" self.points.append(touch) self.prange.update(touch.pressure) if touch.pressure < self.device.up: self.is_down = False elif touch.pressure > self.device.down: self.is_down = True self.was_down = True self.is_palm = touch.pressure > self.device.palm if self.is_palm: self.was_palm = True self.is_thumb = touch.pressure > self.device.thumb if self.is_thumb: self.was_thumb = True def finalize(self): """Mark the TouchSequence as complete (finger is up)""" self.is_active = False def avg(self): """Average pressure value of this sequence""" return int(sum([p.pressure for p in self.points]) / len(self.points)) def median(self): """Median pressure value of this sequence""" ps = sorted([p.pressure for p in self.points]) idx = int(len(self.points) / 2) return ps[idx] def __str__(self): return self._str_state() if self.is_active else self._str_summary() def _str_summary(self): if not self.points: return fmt.values( [ self.tracking_id, False, False, False, False, "No pressure values recorded", ] ) s = fmt.values( [ self.tracking_id, self.was_down, True, self.was_palm, self.was_thumb, self.prange.min, self.prange.max, 0, self.avg(), self.median(), ] ) return s def _str_state(self): s = fmt.values( [ self.tracking_id, self.is_down, not self.is_down, self.is_palm, self.is_thumb, self.prange.min, self.prange.max, self.points[-1].pressure, ] ) return s class InvalidDeviceError(Exception): pass class Device(libevdev.Device): def __init__(self, path): if path is None: self.path = self.find_touchpad_device() else: self.path = path fd = open(self.path, "rb") super().__init__(fd) print("Using {}: {}\n".format(self.name, self.path)) self.has_mt_pressure = True absinfo = self.absinfo[libevdev.EV_ABS.ABS_MT_PRESSURE] if absinfo is None: absinfo = self.absinfo[libevdev.EV_ABS.ABS_PRESSURE] self.has_mt_pressure = False if absinfo is None: raise InvalidDeviceError( "Device does not have ABS_PRESSURE or ABS_MT_PRESSURE" ) prange = absinfo.maximum - absinfo.minimum # libinput defaults self.down = int(absinfo.minimum + 0.12 * prange) self.up = int(absinfo.minimum + 0.10 * prange) self.palm = 130 # the libinput default self.thumb = absinfo.maximum self._init_thresholds_from_quirks() self.sequences = [] def find_touchpad_device(self): context = pyudev.Context() for device in context.list_devices(subsystem="input"): if not device.get("ID_INPUT_TOUCHPAD", 0): continue if not device.device_node or not device.device_node.startswith( "/dev/input/event" ): continue return device.device_node print("Unable to find a touchpad device.", file=sys.stderr) sys.exit(1) def _init_thresholds_from_quirks(self): command = ["libinput", "quirks", "list", self.path] cmd = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if cmd.returncode != 0: print( "Error querying quirks: {}".format(cmd.stderr.decode("utf-8")), file=sys.stderr, ) return stdout = cmd.stdout.decode("utf-8") quirks = [q.split("=") for q in stdout.split("\n")] for q in quirks: if q[0] == "AttrPalmPressureThreshold": self.palm = int(q[1]) elif q[0] == "AttrPressureRange": self.down, self.up = colon_tuple(q[1]) elif q[0] == "AttrThumbPressureThreshold": self.thumb = int(q[1]) def start_new_sequence(self, tracking_id): self.sequences.append(TouchSequence(self, tracking_id)) def current_sequence(self): return self.sequences[-1] def handle_key(device, event): tapcodes = [ libevdev.EV_KEY.BTN_TOOL_DOUBLETAP, libevdev.EV_KEY.BTN_TOOL_TRIPLETAP, libevdev.EV_KEY.BTN_TOOL_QUADTAP, libevdev.EV_KEY.BTN_TOOL_QUINTTAP, ] if event.code in tapcodes and event.value > 0: try: if handle_key.warned: return except AttributeError: handle_key.warned = True print( "\r\033[2KThis tool cannot handle multiple fingers, " "output will be invalid" ) def handle_abs(device, event): if event.matches(libevdev.EV_ABS.ABS_MT_TRACKING_ID): if event.value > -1: device.start_new_sequence(event.value) else: try: s = device.current_sequence() s.finalize() print("\r\033[2K{}".format(s)) except IndexError: # If the finger was down at startup pass elif event.matches(libevdev.EV_ABS.ABS_MT_PRESSURE) or ( event.matches(libevdev.EV_ABS.ABS_PRESSURE) and not device.has_mt_pressure ): try: s = device.current_sequence() s.append(Touch(pressure=event.value)) print("\r\033[2K{}".format(s), end="") except IndexError: # If the finger was down at startup pass def handle_event(device, event): if event.matches(libevdev.EV_ABS): handle_abs(device, event) elif event.matches(libevdev.EV_KEY): handle_key(device, event) def loop(device): print("This is an interactive tool") print() print("Place a single finger on the touchpad to measure pressure values.") print("Check that:") print("- touches subjectively perceived as down are tagged as down") print("- touches with a thumb are tagged as thumb") print("- touches with a palm are tagged as palm") print() print("If the touch states do not match the interaction, re-run") print("with --touch-thresholds=down:up using observed pressure values.") print("See --help for more options.") print() print("Press Ctrl+C to exit") print() headers = fmt.headers( ["Touch", "down", "up", "palm", "thumb", "min", "max", "p", "avg", "median"] ) print(fmt.separator()) print(fmt.values(["Thresh", device.down, device.up, device.palm, device.thumb])) print(fmt.separator()) print(headers) print(fmt.separator()) while True: for event in device.events(): handle_event(device, event) def colon_tuple(string): try: ts = string.split(":") t = tuple([int(x) for x in ts]) if len(t) == 2 and t[0] > t[1]: return t except: # noqa pass msg = "{} is not in format N:M (N > M)".format(string) raise argparse.ArgumentTypeError(msg) def main(args): parser = argparse.ArgumentParser(description="Measure touchpad pressure values") parser.add_argument( "path", metavar="/dev/input/event0", nargs="?", type=str, help="Path to device (optional)", ) parser.add_argument( "--touch-thresholds", metavar="down:up", type=colon_tuple, help="Thresholds when a touch is logically down or up", ) parser.add_argument( "--palm-threshold", metavar="t", type=int, help="Threshold when a touch is a palm", ) parser.add_argument( "--thumb-threshold", metavar="t", type=int, help="Threshold when a touch is a thumb", ) args = parser.parse_args() try: device = Device(args.path) if args.touch_thresholds is not None: device.down, device.up = args.touch_thresholds if args.palm_threshold is not None: device.palm = args.palm_threshold if args.thumb_threshold is not None: device.thumb = args.thumb_threshold loop(device) except KeyboardInterrupt: print("\r\033[2K{}".format(fmt.separator())) print() except (PermissionError, OSError): print("Error: failed to open device") except InvalidDeviceError as e: print( "This device does not have the capabilities for pressure-based touch detection." ) print("Details: {}".format(e)) if __name__ == "__main__": main(sys.argv) libinput-1.28.1/tools/libinput-measure-touchpad-size.man000066400000000000000000000025361477265155700233610ustar00rootroot00000000000000.TH libinput-measure-touchpad-size "1" .SH NAME libinput\-measure\-touchpad\-size \- measure the size of a touchpad .SH SYNOPSIS .B libinput measure touchpad\-size [\-\-help] WxH [\fI/dev/input/event0\fI] .SH DESCRIPTION .PP The .B "libinput measure touchpad\-size" tool measures the size of a touchpad. This is an interactive tool. When executed, the tool will prompt the user to interact with the touchpad. The tool records the axis ranges and calculates the size and resolution based on those. On termination, the tool prints a hwdb entry that can be added to the .B 60-evdev.hwdb file provided by system. .PP For details see the online documentation here: .I https://wayland.freedesktop.org/libinput/doc/latest/absolute-coordinate-ranges.html .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS This tool must be provided the physical dimensions of the device in mm. For example, if your touchpad is 100mm wide and 55mm high, run this tool as .B libinput measure touchpad-size 100x55 .PP If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a touchpad and uses that node. .TP 8 .B \-\-help Print help .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-measure-touchpad-size.py000077500000000000000000000330141477265155700232340ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2020 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import sys import argparse try: import libevdev import pyudev except ModuleNotFoundError as e: print("Error: {}".format(str(e)), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) class DeviceError(Exception): pass class Point: def __init__(self, x=None, y=None): self.x = x self.y = y class Touchpad(object): def __init__(self, evdev): x = evdev.absinfo[libevdev.EV_ABS.ABS_X] y = evdev.absinfo[libevdev.EV_ABS.ABS_Y] if not x or not y: raise DeviceError("Device does not have an x or axis") if not x.resolution or not y.resolution: print("Device does not have resolutions.", file=sys.stderr) x.resolution = 1 y.resolution = 1 self.xrange = x.maximum - x.minimum self.yrange = y.maximum - y.minimum self.width = self.xrange / x.resolution self.height = self.yrange / y.resolution self._x = x self._y = y # We try to make the touchpad at least look proportional. The # terminal character space is (guesswork) ca 2.3 times as high as # wide. self.columns = 30 self.rows = int( self.columns * (self.yrange // y.resolution) // (self.xrange // x.resolution) / 2.3 ) self.pos = Point(0, 0) self.min = Point() self.max = Point() @property def x(self): return self._x @property def y(self): return self._y @x.setter def x(self, x): self._x.minimum = min(self.x.minimum, x) self._x.maximum = max(self.x.maximum, x) self.min.x = min(x, self.min.x or 0xFFFFFFFF) self.max.x = max(x, self.max.x or -0xFFFFFFFF) # we calculate the position based on the original range. # this means on devices with a narrower range than advertised, not # all corners may be reachable in the touchpad drawing. self.pos.x = min(0.99, (x - self._x.minimum) / self.xrange) @y.setter def y(self, y): self._y.minimum = min(self.y.minimum, y) self._y.maximum = max(self.y.maximum, y) self.min.y = min(y, self.min.y or 0xFFFFFFFF) self.max.y = max(y, self.max.y or -0xFFFFFFFF) # we calculate the position based on the original range. # this means on devices with a narrower range than advertised, not # all corners may be reachable in the touchpad drawing. self.pos.y = min(0.99, (y - self._y.minimum) / self.yrange) def update_from_data(self): if None in [self.min.x, self.min.y, self.max.x, self.max.y]: raise DeviceError("Insufficient data to continue") self._x.minimum = self.min.x self._x.maximum = self.max.x self._y.minimum = self.min.y self._y.maximum = self.max.y def draw(self): print( "Detected axis range: x [{:4d}..{:4d}], y [{:4d}..{:4d}]".format( self.min.x if self.min.x is not None else 0, self.max.x if self.max.x is not None else 0, self.min.y if self.min.y is not None else 0, self.max.y if self.max.y is not None else 0, ) ) print() print("Move one finger along all edges of the touchpad".center(self.columns)) print("until the detected axis range stops changing.".center(self.columns)) top = int(self.pos.y * self.rows) print("+{}+".format("".ljust(self.columns, "-"))) for row in range(0, top): print("|{}|".format("".ljust(self.columns))) left = int(self.pos.x * self.columns) right = max(0, self.columns - 1 - left) print("|{}{}{}|".format("".ljust(left), "O", "".ljust(right))) for row in range(top + 1, self.rows): print("|{}|".format("".ljust(self.columns))) print("+{}+".format("".ljust(self.columns, "-"))) print("Press Ctrl+C to stop".center(self.columns)) print("\033[{}A".format(self.rows + 8), flush=True) self.rows_printed = self.rows + 8 def erase(self): # Erase all previous lines so we're not left with rubbish for row in range(self.rows_printed): print("\033[K") print("\033[{}A".format(self.rows_printed)) def dimension(string): try: ts = string.split("x") t = tuple([int(x) for x in ts]) if len(t) == 2: return t except: # noqa pass msg = "{} is not in format WxH".format(string) raise argparse.ArgumentTypeError(msg) def between(v1, v2, deviation): return v1 - deviation < v2 < v1 + deviation def dmi_modalias_match(modalias): modalias = modalias.split(":") dmi = {"svn": None, "pvr": None, "pn": None} for m in modalias: for key in dmi: if m.startswith(key): dmi[key] = m[len(key) :] # Based on the current 60-evdev.hwdb, Lenovo uses pvr and everyone else # uses pn to provide a human-identifiable match if dmi["svn"] == "LENOVO": return "dmi:*svn{}:*pvr{}*".format(dmi["svn"], dmi["pvr"]) else: return "dmi:*svn{}:*pn{}*".format(dmi["svn"], dmi["pn"]) def main(args): parser = argparse.ArgumentParser(description="Measure the touchpad size") parser.add_argument( "size", metavar="WxH", type=dimension, help="Touchpad size (width by height) in mm", ) parser.add_argument( "path", metavar="/dev/input/event0", nargs="?", type=str, help="Path to device (optional)", ) context = pyudev.Context() args = parser.parse_args() if not args.path: for device in context.list_devices(subsystem="input"): if device.get("ID_INPUT_TOUCHPAD", 0) and ( device.device_node or "" ).startswith("/dev/input/event"): args.path = device.device_node name = "unknown" parent = device while parent is not None: n = parent.get("NAME", None) if n: name = n break parent = parent.parent print("Using {}: {}".format(name, device.device_node)) break else: print("Unable to find a touchpad device.", file=sys.stderr) return 1 dev = pyudev.Devices.from_device_file(context, args.path) overrides = [p for p in dev.properties if p.startswith("EVDEV_ABS")] if overrides: print() print("********************************************************************") print("WARNING: axis overrides already in place for this device:") for prop in overrides: print(" {}={}".format(prop, dev.properties[prop])) print("The systemd hwdb already overrides the axis ranges and/or resolution.") print("This tool is not needed unless you want to verify the axis overrides.") print("********************************************************************") print() try: fd = open(args.path, "rb") evdev = libevdev.Device(fd) touchpad = Touchpad(evdev) print( "Kernel specified touchpad size: {:.1f}x{:.1f}mm".format( touchpad.width, touchpad.height ) ) print("User specified touchpad size: {:.1f}x{:.1f}mm".format(*args.size)) print() print( "Kernel axis range: x [{:4d}..{:4d}], y [{:4d}..{:4d}]".format( touchpad.x.minimum, touchpad.x.maximum, touchpad.y.minimum, touchpad.y.maximum, ) ) print("Put your finger on the touchpad to start\033[1A") try: touchpad.draw() while True: for event in evdev.events(): if event.matches(libevdev.EV_ABS.ABS_X): touchpad.x = event.value elif event.matches(libevdev.EV_ABS.ABS_Y): touchpad.y = event.value elif event.matches(libevdev.EV_SYN.SYN_REPORT): touchpad.draw() except KeyboardInterrupt: touchpad.erase() touchpad.update_from_data() print( "Detected axis range: x [{:4d}..{:4d}], y [{:4d}..{:4d}]".format( touchpad.x.minimum, touchpad.x.maximum, touchpad.y.minimum, touchpad.y.maximum, ) ) touchpad.x.resolution = round( (touchpad.x.maximum - touchpad.x.minimum) / args.size[0] ) touchpad.y.resolution = round( (touchpad.y.maximum - touchpad.y.minimum) / args.size[1] ) print( "Resolutions calculated based on user-specified size: x {}, y {} units/mm".format( touchpad.x.resolution, touchpad.y.resolution ) ) # If both x/y are within some acceptable deviation, we skip the axis # overrides and only override the resolution xorig = evdev.absinfo[libevdev.EV_ABS.ABS_X] yorig = evdev.absinfo[libevdev.EV_ABS.ABS_Y] deviation = 1.5 * touchpad.x.resolution # 1.5 mm rounding on each side skip = between(xorig.minimum, touchpad.x.minimum, deviation) skip = skip and between(xorig.maximum, touchpad.x.maximum, deviation) deviation = 1.5 * touchpad.y.resolution # 1.5 mm rounding on each side skip = skip and between(yorig.minimum, touchpad.y.minimum, deviation) skip = skip and between(yorig.maximum, touchpad.y.maximum, deviation) if skip: print() print( "Note: Axis ranges within acceptable deviation, skipping min/max override" ) print() print() print("Suggested hwdb entry:") use_dmi = evdev.id["bustype"] not in [0x03, 0x05] # USB, Bluetooth if use_dmi: modalias = open("/sys/class/dmi/id/modalias").read().strip() print( "Note: the dmi modalias match is a guess based on your machine's modalias:" ) print(" ", modalias) print( "Please verify that this is the most sensible match and adjust if necessary." ) print("-8<--------------------------") print("# Laptop model description (e.g. Lenovo X1 Carbon 5th)") if use_dmi: print("evdev:name:{}:{}*".format(evdev.name, dmi_modalias_match(modalias))) else: print( "evdev:input:b{:04X}v{:04X}p{:04X}*".format( evdev.id["bustype"], evdev.id["vendor"], evdev.id["product"] ) ) print( " EVDEV_ABS_00={}:{}:{}".format( touchpad.x.minimum if not skip else "", touchpad.x.maximum if not skip else "", touchpad.x.resolution, ) ) print( " EVDEV_ABS_01={}:{}:{}".format( touchpad.y.minimum if not skip else "", touchpad.y.maximum if not skip else "", touchpad.y.resolution, ) ) if evdev.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_X]: print( " EVDEV_ABS_35={}:{}:{}".format( touchpad.x.minimum if not skip else "", touchpad.x.maximum if not skip else "", touchpad.x.resolution, ) ) print( " EVDEV_ABS_36={}:{}:{}".format( touchpad.y.minimum if not skip else "", touchpad.y.maximum if not skip else "", touchpad.y.resolution, ) ) print("-8<--------------------------") print( "Instructions on what to do with this snippet are in /usr/lib/udev/hwdb.d/60-evdev.hwdb" ) except DeviceError as e: print("Error: {}".format(e), file=sys.stderr) return 1 except PermissionError: print("Unable to open device. Please run me as root", file=sys.stderr) return 1 return 0 if __name__ == "__main__": sys.exit(main(sys.argv)) libinput-1.28.1/tools/libinput-measure-touchpad-tap.man000066400000000000000000000054061477265155700231720ustar00rootroot00000000000000.TH libinput-measure-touchpad-tap "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-measure\-touchpad\-tap \- measure tap-to-click properties of devices .SH SYNOPSIS .B libinput measure touchpad\-tap [\-\-help] [\-\-format=\fI\fB] \fI[/dev/input/event0]\fR .SH DESCRIPTION .PP The .B "libinput measure touchpad\-tap" tool measures properties of the tap\-to\-click behavior of the user. This is an interactive tool. When executed, the tool will prompt the user to interact with the touchpad. On termination, the tool prints a summary of the tap interactions seen. This data should be attached to any tap\-related bug report. .PP For a full description on how libinput's tap-to-click behavior works, see the online documentation here: .I https://wayland.freedesktop.org/libinput/doc/latest/tapping.html .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS If a device node is given, this tool opens that device node. Otherwise, this tool searches for the first node that looks like a touchpad and uses that node. .TP 8 .B \-\-help Print help .TP 8 .B \-\-format=summary|dat Specify the data format to be printed. The default (or if .B \-\-format is omitted) is "summary". See section .B DATA FORMATS .SH DATA FORMATS This section describes the data formats printed with the .B \-\-format commandline argument. Note that any of the output may change at any time. .RE .PP summary .RS 4 The .I summary format prints a summary of the data collected. This format is useful to get a quick overview of a user's tapping behavior and why some taps may or may not be detected. .RE .PP dat .RS 4 The .I dat format prints the touch sequence data (raw and processed) in column-style format, suitable for processing by other tools such as .B gnuplot(1). The data is aligned in one row per touch with each column containing a separate data entry. .B libinput\-measure\-touchpad\-tap prints comments at the top of the file to describe each column. .PP .B WARNING: The data contained in the output is grouped by different sort orders. For example, the first few columns may list tap information in the 'natural' sort order (i.e. as they occurred), the data in the next few columns may list tap information sorted by the delta time between touch down and touch up. Comparing columns across these group boundaries will compare data of two different touch points and result in invalid analysis. .SH BUGS This tool does not take finger pressure into account. The tap it detects may be different to those detected by libinput if libinput's pressure thresholds differ significantly to the kernel's pressure thresholds. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-measure-touchpad-tap.py000077500000000000000000000207241477265155700230520ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2017 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # import sys import argparse try: import libevdev import textwrap import pyudev except ModuleNotFoundError as e: print("Error: {}".format(e), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) print_dest = sys.stdout def error(msg, **kwargs): print(msg, **kwargs, file=sys.stderr) def msg(msg, **kwargs): print(msg, **kwargs, file=print_dest, flush=True) def tv2us(sec, usec): return sec * 1000000 + usec def us2ms(us): return int(us / 1000) class Touch(object): def __init__(self, down): self._down = down self._up = down @property def up(self): return us2ms(self._up) @up.setter def up(self, up): assert up > self.down self._up = up @property def down(self): return us2ms(self._down) @property def tdelta(self): return self.up - self.down class InvalidDeviceError(Exception): pass class Device(libevdev.Device): def __init__(self, path): if path is None: self.path = self._find_touch_device() else: self.path = path fd = open(self.path, "rb") super().__init__(fd) print("Using {}: {}\n".format(self.name, self.path)) if not self.has(libevdev.EV_KEY.BTN_TOUCH): raise InvalidDeviceError("device does not have BTN_TOUCH") self.touches = [] self.warned = False def _find_touch_device(self): context = pyudev.Context() device_node = None for device in context.list_devices(subsystem="input"): if not device.device_node or not device.device_node.startswith( "/dev/input/event" ): continue # pick the touchpad by default, fallback to the first # touchscreen only when there is no touchpad if device.get("ID_INPUT_TOUCHPAD", 0): device_node = device.device_node break if device.get("ID_INPUT_TOUCHSCREEN", 0) and device_node is None: device_node = device.device_node if device_node is not None: return device_node error("Unable to find a touch device.") sys.exit(1) def handle_btn_touch(self, event): if event.value != 0: t = Touch(tv2us(event.sec, event.usec)) self.touches.append(t) else: self.touches[-1].up = tv2us(event.sec, event.usec) msg("\rTouch sequences detected: {}".format(len(self.touches)), end="") def handle_key(self, event): tapcodes = [ libevdev.EV_KEY.BTN_TOOL_DOUBLETAP, libevdev.EV_KEY.BTN_TOOL_TRIPLETAP, libevdev.EV_KEY.BTN_TOOL_QUADTAP, libevdev.EV_KEY.BTN_TOOL_QUINTTAP, ] if event.code in tapcodes and event.value > 0: if not self.warned: self.warned = True error( "\rThis tool cannot handle multiple fingers, " "output will be invalid" ) return if event.matches(libevdev.EV_KEY.BTN_TOUCH): self.handle_btn_touch(event) def handle_syn(self, event): if self.touch.dirty: self.current_sequence().append(self.touch) self.touch = Touch( major=self.touch.major, minor=self.touch.minor, orientation=self.touch.orientation, ) def handle_event(self, event): if event.matches(libevdev.EV_KEY): self.handle_key(event) def read_events(self): while True: for event in self.events(): self.handle_event(event) def print_summary(self): deltas = sorted(t.tdelta for t in self.touches) dmax = max(deltas) dmin = min(deltas) ndeltas = len(deltas) davg = sum(deltas) / ndeltas dmedian = deltas[int(ndeltas / 2)] d95pc = deltas[int(ndeltas * 0.95)] d90pc = deltas[int(ndeltas * 0.90)] print("Time: ") print(" Max delta: {}ms".format(int(dmax))) print(" Min delta: {}ms".format(int(dmin))) print(" Average delta: {}ms".format(int(davg))) print(" Median delta: {}ms".format(int(dmedian))) print(" 90th percentile: {}ms".format(int(d90pc))) print(" 95th percentile: {}ms".format(int(d95pc))) def print_dat(self): print("# libinput-measure-touchpad-tap") print( textwrap.dedent( """\ # File contents: # This file contains multiple prints of the data in # different sort order. Row number is index of touch # point within each group. Comparing data across groups # will result in invalid analysis. # Columns (1-indexed): # Group 1, sorted by time of occurrence # 1: touch down time in ms, offset by first event # 2: touch up time in ms, offset by first event # 3: time delta in ms); # Group 2, sorted by touch down-up delta time (ascending) # 4: touch down time in ms, offset by first event # 5: touch up time in ms, offset by first event # 6: time delta in ms """ ) ) deltas = [t for t in self.touches] deltas_sorted = sorted(deltas, key=lambda t: t.tdelta) offset = deltas[0].down for t1, t2 in zip(deltas, deltas_sorted): print( t1.down - offset, t1.up - offset, t1.tdelta, t2.down - offset, t2.up - offset, t2.tdelta, ) def print(self, format): if not self.touches: error("No tap data available") return if format == "summary": self.print_summary() elif format == "dat": self.print_dat() def main(args): parser = argparse.ArgumentParser( description="Measure tap-to-click properties of devices" ) parser.add_argument( "path", metavar="/dev/input/event0", nargs="?", type=str, help="Path to device (optional)", ) parser.add_argument( "--format", metavar="format", choices=["summary", "dat"], default="summary", help='data format to print ("summary" or "dat")', ) args = parser.parse_args() if not sys.stdout.isatty(): global print_dest print_dest = sys.stderr try: device = Device(args.path) error( "Ready for recording data.\n" "Tap the touchpad multiple times with a single finger only.\n" "For useful data we recommend at least 20 taps.\n" "Ctrl+C to exit" ) device.read_events() except KeyboardInterrupt: msg("") device.print(args.format) except (PermissionError, OSError) as e: error("Error: failed to open device. {}".format(e)) except InvalidDeviceError as e: error("Error: {}".format(e)) if __name__ == "__main__": main(sys.argv) libinput-1.28.1/tools/libinput-measure.c000066400000000000000000000035101477265155700202440ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include "shared.h" static inline void usage(void) { printf("Usage: libinput measure [--help] [/dev/input/event0]\n"); } int main(int argc, char **argv) { int option_index = 0; while (1) { int c; static struct option opts[] = { { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "+h", opts, &option_index); if (c == -1) break; switch(c) { case 'h': usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } if (optind >= argc) { usage(); return EXIT_FAILURE; } argc--; argv++; return tools_exec_command("libinput-measure", argc, argv); } libinput-1.28.1/tools/libinput-measure.man000066400000000000000000000021021477265155700205710ustar00rootroot00000000000000.TH libinput-measure "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-measure \- measure properties of devices .SH SYNOPSIS .B libinput measure [\-\-help] \fI []\fR .SH DESCRIPTION .PP The .B "libinput measure" tool measures properties of one (or more) devices. Depending on what is to be measured, this tool may not create a libinput context. .PP This is a debugging tool only, its output may change at any time. Do not rely on the output. .PP This tool usually needs to be run as root to have access to the /dev/input/eventX nodes. .SH OPTIONS .TP 8 .B \-\-help Print help .SH FEATURES Features that can be measured include .TP 8 .B libinput\-measure\-fuzz(1) Measure touch fuzz to avoid pointer jitter .TP 8 .B libinput\-measure\-touch\-size(1) Measure touch size and orientation .TP 8 .B libinput\-measure\-touchpad\-size(1) Measure the size of a touchpad .TP 8 .B libinput\-measure\-touchpad\-tap(1) Measure tap-to-click time .TP 8 .B libinput\-measure\-touchpad\-pressure(1) Measure touch pressure .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-quirks.c000066400000000000000000000117251477265155700201300ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include "quirks.h" #include "shared.h" #include "builddir.h" static bool verbose = false; LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void log_handler(struct libinput *this_is_null, enum libinput_log_priority priority, const char *format, va_list args) { FILE *out = stdout; enum quirks_log_priorities p = (enum quirks_log_priorities)priority; char buf[256] = {0}; const char *prefix = NULL; switch (p) { case QLOG_NOISE: case QLOG_DEBUG: if (!verbose) return; prefix = "quirks debug"; break; case QLOG_INFO: prefix = "quirks info"; break; case QLOG_ERROR: out = stderr; prefix = "quirks error"; break; case QLOG_PARSER_ERROR: out = stderr; prefix = "quirks parser error"; break; } snprintf(buf, sizeof(buf), "%s: %s", prefix, format); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" vfprintf(out, buf, args); #pragma GCC diagnostic pop } static void usage(void) { printf("Usage:\n" " libinput quirks list [--data-dir /path/to/quirks/dir] /dev/input/event0\n" " Print the quirks for the given device\n" "\n" " libinput quirks validate [--data-dir /path/to/quirks/dir]\n" " Validate the database\n"); } static void simple_printf(void *userdata, const char *val) { printf("%s\n", val); } int main(int argc, char **argv) { struct udev *udev = NULL; struct udev_device *device = NULL; const char *path; const char *data_path = NULL, *override_file = NULL; int rc = 1; struct quirks_context *quirks; bool validate = false; while (1) { int c; int option_index = 0; enum { OPT_VERBOSE, OPT_DATADIR, }; static struct option opts[] = { { "help", no_argument, 0, 'h' }, { "verbose", no_argument, 0, OPT_VERBOSE }, { "data-dir", required_argument, 0, OPT_DATADIR }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "h", opts, &option_index); if (c == -1) break; switch(c) { case '?': exit(1); break; case 'h': usage(); exit(0); break; case OPT_VERBOSE: verbose = true; break; case OPT_DATADIR: data_path = optarg; break; default: usage(); return 1; } } if (optind >= argc) { usage(); return 1; } if (streq(argv[optind], "list")) { optind++; if (optind >= argc) { usage(); return 1; } } else if (streq(argv[optind], "validate")) { optind++; if (optind < argc) { usage(); return 1; } validate = true; } else { fprintf(stderr, "Unnkown action '%s'\n", argv[optind]); return 1; } /* Overriding the data dir means no custom override file */ if (!data_path) { char *builddir = builddir_lookup(); if (builddir) { data_path = LIBINPUT_QUIRKS_SRCDIR; free(builddir); } else { data_path = LIBINPUT_QUIRKS_DIR; override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE; } } quirks = quirks_init_subsystem(data_path, override_file, log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); if (!quirks) { fprintf(stderr, "Failed to initialize the device quirks. " "Please see the above errors " "and/or re-run with --verbose for more details\n"); return 1; } if (validate) { rc = 0; goto out; } udev = udev_new(); if (!udev) goto out; path = argv[optind]; if (strstartswith(path, "/sys/")) { device = udev_device_new_from_syspath(udev, path); } else { struct stat st; if (stat(path, &st) < 0) { fprintf(stderr, "Error: %s: %m\n", path); goto out; } device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); } if (device) { tools_list_device_quirks(quirks, device, simple_printf, NULL); rc = 0; } else { usage(); rc = 1; } udev_device_unref(device); out: udev_unref(udev); quirks_context_unref(quirks); return rc; } libinput-1.28.1/tools/libinput-quirks.man000066400000000000000000000021311477265155700204500ustar00rootroot00000000000000.TH libinput-quirks "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-quirks \- quirk debug helper for libinput .SH SYNOPSIS .B libinput quirks list [\-\-data\-dir /path/to/dir] [\-\-verbose\fB] \fI/dev/input/event0\fB .br .sp .B libinput quirks validate [\-\-data\-dir /path/to/dir] [\-\-verbose\fB] .br .sp .B libinput quirks \-\-help .SH DESCRIPTION .PP The .B "libinput quirks" tool interacts with libinput's quirks database. .PP When invoked as .B libinput quirks list, the tool lists all quirks applied to the given device. .PP When invoked as .B libinput quirks validate, the tool checks for parsing errors in the quirks files and fails if a parsing error is encountered. .PP This is a debugging tool only, its output and behavior may change at any time. Do not rely on the output. .SH OPTIONS .TP 8 .B \-\-data\-dir \fI/path/to/dir\fR Use the given directory as data directory for quirks files. When omitted, the default directories are used. .TP 8 .B \-\-help Print help .TP 8 .B \-\-verbose Use verbose output, useful for debugging. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-record-verify-yaml.py000077500000000000000000000572161477265155700225500ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import argparse import os import sys import unittest import yaml import re from pkg_resources import parse_version class TestYaml(unittest.TestCase): filename = "" @classmethod def setUpClass(cls): with open(cls.filename) as f: cls.yaml = yaml.safe_load(f) def dict_key_crosscheck(self, d, keys): """Check that each key in d is in keys, and that each key is in d""" self.assertEqual(sorted(d.keys()), sorted(keys)) def libinput_events(self, filter=None): """Returns all libinput events in the recording, regardless of the device""" devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: try: libinput = e["libinput"] except KeyError: continue for ev in libinput: if ( filter is None or ev["type"] == filter or isinstance(filter, list) and ev["type"] in filter ): yield ev def test_sections_exist(self): sections = ["version", "ndevices", "libinput", "system", "devices"] for section in sections: self.assertIn(section, self.yaml) def test_version(self): version = self.yaml["version"] self.assertTrue(isinstance(version, int)) self.assertEqual(version, 1) def test_ndevices(self): ndevices = self.yaml["ndevices"] self.assertTrue(isinstance(ndevices, int)) self.assertGreaterEqual(ndevices, 1) self.assertEqual(ndevices, len(self.yaml["devices"])) def test_libinput(self): libinput = self.yaml["libinput"] version = libinput["version"] self.assertTrue(isinstance(version, str)) self.assertGreaterEqual(parse_version(version), parse_version("1.10.0")) git = libinput["git"] self.assertTrue(isinstance(git, str)) self.assertNotEqual(git, "unknown") def test_system(self): system = self.yaml["system"] kernel = system["kernel"] self.assertTrue(isinstance(kernel, str)) self.assertEqual(kernel, os.uname().release) dmi = system["dmi"] self.assertTrue(isinstance(dmi, str)) with open("/sys/class/dmi/id/modalias") as f: sys_dmi = f.read()[:-1] # trailing newline self.assertEqual(dmi, sys_dmi) def test_devices_sections_exist(self): devices = self.yaml["devices"] for d in devices: self.assertIn("node", d) self.assertIn("evdev", d) self.assertIn("udev", d) def test_evdev_sections_exist(self): sections = ["name", "id", "codes", "properties"] devices = self.yaml["devices"] for d in devices: evdev = d["evdev"] for s in sections: self.assertIn(s, evdev) def test_evdev_name(self): devices = self.yaml["devices"] for d in devices: evdev = d["evdev"] name = evdev["name"] self.assertTrue(isinstance(name, str)) self.assertGreaterEqual(len(name), 5) def test_evdev_id(self): devices = self.yaml["devices"] for d in devices: evdev = d["evdev"] id = evdev["id"] self.assertTrue(isinstance(id, list)) self.assertEqual(len(id), 4) self.assertGreater(id[0], 0) self.assertGreater(id[1], 0) def test_evdev_properties(self): devices = self.yaml["devices"] for d in devices: evdev = d["evdev"] properties = evdev["properties"] self.assertTrue(isinstance(properties, list)) def test_hid(self): devices = self.yaml["devices"] for d in devices: hid = d["hid"] self.assertTrue(isinstance(hid, list)) for byte in hid: self.assertGreaterEqual(byte, 0) self.assertLessEqual(byte, 255) def test_udev_sections_exist(self): sections = ["properties"] devices = self.yaml["devices"] for d in devices: udev = d["udev"] for s in sections: self.assertIn(s, udev) def test_udev_properties(self): devices = self.yaml["devices"] for d in devices: udev = d["udev"] properties = udev["properties"] self.assertTrue(isinstance(properties, list)) self.assertGreater(len(properties), 0) self.assertIn("ID_INPUT=1", properties) for p in properties: self.assertTrue(re.match("[A-Z0-9_]+=.+", p)) def test_udev_id_inputs(self): devices = self.yaml["devices"] for d in devices: udev = d["udev"] properties = udev["properties"] id_inputs = [p for p in properties if p.startswith("ID_INPUT")] # We expect ID_INPUT and ID_INPUT_something, but might get more # than one of the latter self.assertGreaterEqual(len(id_inputs), 2) def test_events_have_section(self): devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: self.assertTrue("evdev" in e or "libinput" in e) def test_events_evdev(self): devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: try: evdev = e["evdev"] except KeyError: continue for ev in evdev: self.assertEqual(len(ev), 5) # Last event in each frame is SYN_REPORT ev_syn = evdev[-1] self.assertEqual(ev_syn[2], 0) self.assertEqual(ev_syn[3], 0) # SYN_REPORT value is 1 in case of some key repeats self.assertLessEqual(ev_syn[4], 1) def test_events_evdev_syn_report(self): devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: try: evdev = e["evdev"] except KeyError: continue for ev in evdev[:-1]: self.assertFalse(ev[2] == 0 and ev[3] == 0) def test_events_libinput(self): devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: try: libinput = e["libinput"] except KeyError: continue self.assertTrue(isinstance(libinput, list)) for ev in libinput: self.assertTrue(isinstance(ev, dict)) def test_events_libinput_type(self): types = [ "POINTER_MOTION", "POINTER_MOTION_ABSOLUTE", "POINTER_AXIS", "POINTER_BUTTON", "DEVICE_ADDED", "KEYBOARD_KEY", "TOUCH_DOWN", "TOUCH_MOTION", "TOUCH_UP", "TOUCH_FRAME", "GESTURE_SWIPE_BEGIN", "GESTURE_SWIPE_UPDATE", "GESTURE_SWIPE_END", "GESTURE_PINCH_BEGIN", "GESTURE_PINCH_UPDATE", "GESTURE_PINCH_END", "TABLET_TOOL_AXIS", "TABLET_TOOL_PROXIMITY", "TABLET_TOOL_BUTTON", "TABLET_TOOL_TIP", "TABLET_PAD_STRIP", "TABLET_PAD_RING", "TABLET_PAD_BUTTON", "SWITCH_TOGGLE", ] for e in self.libinput_events(): self.assertIn("type", e) self.assertIn(e["type"], types) def test_events_libinput_time(self): # DEVICE_ADDED has no time # first event may have 0.0 time if the first frame generates a # libinput event. try: for e in list(self.libinput_events())[2:]: self.assertIn("time", e) self.assertGreater(e["time"], 0.0) self.assertLess(e["time"], 60.0) except IndexError: pass def test_events_libinput_device_added(self): keys = ["type", "seat", "logical_seat"] for e in self.libinput_events("DEVICE_ADDED"): self.dict_key_crosscheck(e, keys) self.assertEqual(e["seat"], "seat0") self.assertEqual(e["logical_seat"], "default") def test_events_libinput_pointer_motion(self): keys = ["type", "time", "delta", "unaccel"] for e in self.libinput_events("POINTER_MOTION"): self.dict_key_crosscheck(e, keys) delta = e["delta"] self.assertTrue(isinstance(delta, list)) self.assertEqual(len(delta), 2) for d in delta: self.assertTrue(isinstance(d, float)) unaccel = e["unaccel"] self.assertTrue(isinstance(unaccel, list)) self.assertEqual(len(unaccel), 2) for d in unaccel: self.assertTrue(isinstance(d, float)) def test_events_libinput_pointer_button(self): keys = ["type", "time", "button", "state", "seat_count"] for e in self.libinput_events("POINTER_BUTTON"): self.dict_key_crosscheck(e, keys) button = e["button"] self.assertGreater(button, 0x100) # BTN_0 self.assertLess(button, 0x160) # KEY_OK state = e["state"] self.assertIn(state, ["pressed", "released"]) scount = e["seat_count"] self.assertGreaterEqual(scount, 0) def test_events_libinput_pointer_absolute(self): keys = ["type", "time", "point", "transformed"] for e in self.libinput_events("POINTER_MOTION_ABSOLUTE"): self.dict_key_crosscheck(e, keys) point = e["point"] self.assertTrue(isinstance(point, list)) self.assertEqual(len(point), 2) for p in point: self.assertTrue(isinstance(p, float)) self.assertGreater(p, 0.0) self.assertLess(p, 300.0) transformed = e["transformed"] self.assertTrue(isinstance(transformed, list)) self.assertEqual(len(transformed), 2) for t in transformed: self.assertTrue(isinstance(t, float)) self.assertGreater(t, 0.0) self.assertLess(t, 100.0) def test_events_libinput_touch(self): keys = ["type", "time", "slot", "seat_slot"] for e in self.libinput_events(): if not e["type"].startswith("TOUCH_") or e["type"] == "TOUCH_FRAME": continue for k in keys: self.assertIn(k, e.keys()) slot = e["slot"] seat_slot = e["seat_slot"] self.assertGreaterEqual(slot, 0) self.assertGreaterEqual(seat_slot, 0) def test_events_libinput_touch_down(self): keys = ["type", "time", "slot", "seat_slot", "point", "transformed"] for e in self.libinput_events("TOUCH_DOWN"): self.dict_key_crosscheck(e, keys) point = e["point"] self.assertTrue(isinstance(point, list)) self.assertEqual(len(point), 2) for p in point: self.assertTrue(isinstance(p, float)) self.assertGreater(p, 0.0) self.assertLess(p, 300.0) transformed = e["transformed"] self.assertTrue(isinstance(transformed, list)) self.assertEqual(len(transformed), 2) for t in transformed: self.assertTrue(isinstance(t, float)) self.assertGreater(t, 0.0) self.assertLess(t, 100.0) def test_events_libinput_touch_motion(self): keys = ["type", "time", "slot", "seat_slot", "point", "transformed"] for e in self.libinput_events("TOUCH_MOTION"): self.dict_key_crosscheck(e, keys) point = e["point"] self.assertTrue(isinstance(point, list)) self.assertEqual(len(point), 2) for p in point: self.assertTrue(isinstance(p, float)) self.assertGreater(p, 0.0) self.assertLess(p, 300.0) transformed = e["transformed"] self.assertTrue(isinstance(transformed, list)) self.assertEqual(len(transformed), 2) for t in transformed: self.assertTrue(isinstance(t, float)) self.assertGreater(t, 0.0) self.assertLess(t, 100.0) def test_events_libinput_touch_frame(self): devices = self.yaml["devices"] for d in devices: events = d["events"] if not events: raise unittest.SkipTest() for e in events: try: evdev = e["libinput"] except KeyError: continue need_frame = False for ev in evdev: t = ev["type"] if not t.startswith("TOUCH_"): self.assertFalse(need_frame) continue if t == "TOUCH_FRAME": self.assertTrue(need_frame) need_frame = False else: need_frame = True self.assertFalse(need_frame) def test_events_libinput_gesture_pinch(self): keys = ["type", "time", "nfingers", "delta", "unaccel", "angle_delta", "scale"] for e in self.libinput_events( ["GESTURE_PINCH_BEGIN", "GESTURE_PINCH_UPDATE", "GESTURE_PINCH_END"] ): self.dict_key_crosscheck(e, keys) delta = e["delta"] self.assertTrue(isinstance(delta, list)) self.assertEqual(len(delta), 2) for d in delta: self.assertTrue(isinstance(d, float)) unaccel = e["unaccel"] self.assertTrue(isinstance(unaccel, list)) self.assertEqual(len(unaccel), 2) for d in unaccel: self.assertTrue(isinstance(d, float)) adelta = e["angle_delta"] self.assertTrue(isinstance(adelta, list)) self.assertEqual(len(adelta), 2) for d in adelta: self.assertTrue(isinstance(d, float)) scale = e["scale"] self.assertTrue(isinstance(scale, list)) self.assertEqual(len(scale), 2) for d in scale: self.assertTrue(isinstance(d, float)) def test_events_libinput_gesture_swipe(self): keys = ["type", "time", "nfingers", "delta", "unaccel"] for e in self.libinput_events( ["GESTURE_SWIPE_BEGIN", "GESTURE_SWIPE_UPDATE", "GESTURE_SWIPE_END"] ): self.dict_key_crosscheck(e, keys) delta = e["delta"] self.assertTrue(isinstance(delta, list)) self.assertEqual(len(delta), 2) for d in delta: self.assertTrue(isinstance(d, float)) unaccel = e["unaccel"] self.assertTrue(isinstance(unaccel, list)) self.assertEqual(len(unaccel), 2) for d in unaccel: self.assertTrue(isinstance(d, float)) def test_events_libinput_tablet_pad_button(self): keys = ["type", "time", "button", "state", "mode", "is-toggle"] for e in self.libinput_events("TABLET_PAD_BUTTON"): self.dict_key_crosscheck(e, keys) b = e["button"] self.assertTrue(isinstance(b, int)) self.assertGreaterEqual(b, 0) self.assertLessEqual(b, 16) state = e["state"] self.assertIn(state, ["pressed", "released"]) m = e["mode"] self.assertTrue(isinstance(m, int)) self.assertGreaterEqual(m, 0) self.assertLessEqual(m, 3) t = e["is-toggle"] self.assertTrue(isinstance(t, bool)) def test_events_libinput_tablet_pad_ring(self): keys = ["type", "time", "number", "position", "source", "mode"] for e in self.libinput_events("TABLET_PAD_RING"): self.dict_key_crosscheck(e, keys) n = e["number"] self.assertTrue(isinstance(n, int)) self.assertGreaterEqual(n, 0) self.assertLessEqual(n, 4) p = e["position"] self.assertTrue(isinstance(p, float)) if p != -1.0: # special 'end' case self.assertGreaterEqual(p, 0.0) self.assertLess(p, 360.0) m = e["mode"] self.assertTrue(isinstance(m, int)) self.assertGreaterEqual(m, 0) self.assertLessEqual(m, 3) s = e["source"] self.assertIn(s, ["finger", "unknown"]) def test_events_libinput_tablet_pad_strip(self): keys = ["type", "time", "number", "position", "source", "mode"] for e in self.libinput_events("TABLET_PAD_STRIP"): self.dict_key_crosscheck(e, keys) n = e["number"] self.assertTrue(isinstance(n, int)) self.assertGreaterEqual(n, 0) self.assertLessEqual(n, 4) p = e["position"] self.assertTrue(isinstance(p, float)) if p != -1.0: # special 'end' case self.assertGreaterEqual(p, 0.0) self.assertLessEqual(p, 1.0) m = e["mode"] self.assertTrue(isinstance(m, int)) self.assertGreaterEqual(m, 0) self.assertLessEqual(m, 3) s = e["source"] self.assertIn(s, ["finger", "unknown"]) def test_events_libinput_tablet_tool_proximity(self): keys = ["type", "time", "proximity", "tool-type", "serial", "axes"] for e in self.libinput_events("TABLET_TOOL_PROXIMITY"): for k in keys: self.assertIn(k, e) p = e["proximity"] self.assertIn(p, ["in", "out"]) p = e["tool-type"] self.assertIn( p, ["pen", "eraser", "brush", "airbrush", "mouse", "lens", "unknown"] ) s = e["serial"] self.assertTrue(isinstance(s, int)) self.assertGreaterEqual(s, 0) a = e["axes"] for ax in e["axes"]: self.assertIn(a, "pdtrsw") def test_events_libinput_tablet_tool(self): keys = ["type", "time", "tip"] for e in self.libinput_events(["TABLET_TOOL_AXIS", "TABLET_TOOL_TIP"]): for k in keys: self.assertIn(k, e) t = e["tip"] self.assertIn(t, ["down", "up"]) def test_events_libinput_tablet_tool_button(self): keys = ["type", "time", "button", "state"] for e in self.libinput_events("TABLET_TOOL_BUTTON"): self.dict_key_crosscheck(e, keys) b = e["button"] # STYLUS, STYLUS2, STYLUS3 self.assertIn(b, [0x14B, 0x14C, 0x139]) s = e["state"] self.assertIn(s, ["pressed", "released"]) def test_events_libinput_tablet_tool_axes(self): for e in self.libinput_events( ["TABLET_TOOL_PROXIMITY", "TABLET_TOOL_AXIS", "TABLET_TOOL_TIP"] ): point = e["point"] self.assertTrue(isinstance(point, list)) self.assertEqual(len(point), 2) for p in point: self.assertTrue(isinstance(p, float)) self.assertGreater(p, 0.0) try: tilt = e["tilt"] self.assertTrue(isinstance(tilt, list)) self.assertEqual(len(tilt), 2) for t in tilt: self.assertTrue(isinstance(t, float)) except KeyError: pass try: d = e["distance"] self.assertTrue(isinstance(d, float)) self.assertGreaterEqual(d, 0.0) self.assertNotIn("pressure", e) except KeyError: pass try: p = e["pressure"] self.assertTrue(isinstance(p, float)) self.assertGreaterEqual(p, 0.0) self.assertNotIn("distance", e) except KeyError: pass try: r = e["rotation"] self.assertTrue(isinstance(r, float)) self.assertGreaterEqual(r, 0.0) except KeyError: pass try: s = e["slider"] self.assertTrue(isinstance(s, float)) self.assertGreaterEqual(s, 0.0) except KeyError: pass try: w = e["wheel"] self.assertTrue(isinstance(w, float)) self.assertGreaterEqual(w, 0.0) self.assertIn("wheel-discrete", e) wd = e["wheel-discrete"] self.assertTrue(isinstance(wd, 1)) self.assertGreaterEqual(wd, 0.0) def sign(x): (1, -1)[x < 0] self.assertTrue(sign(w), sign(wd)) except KeyError: pass def test_events_libinput_switch(self): keys = ["type", "time", "switch", "state"] for e in self.libinput_events("SWITCH_TOGGLE"): self.dict_key_crosscheck(e, keys) s = e["switch"] self.assertTrue(isinstance(s, int)) self.assertIn(s, [0x00, 0x01]) # yaml converts on/off to true/false state = e["state"] self.assertTrue(isinstance(state, bool)) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Verify a YAML recording") parser.add_argument( "recording", metavar="recorded-file.yaml", type=str, help="Path to device recording", ) parser.add_argument("--verbose", action="store_true") args, remainder = parser.parse_known_args() TestYaml.filename = args.recording verbosity = 1 if args.verbose: verbosity = 3 argv = [sys.argv[0], *remainder] unittest.main(argv=argv, verbosity=verbosity) libinput-1.28.1/tools/libinput-record.c000066400000000000000000002030401477265155700200610ustar00rootroot00000000000000/* * Copyright © 2018 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libinput-versionsort.h" #include "libinput-version.h" #include "libinput-git-version.h" #include "shared.h" #include "builddir.h" #include "util-bits.h" #include "util-list.h" #include "util-time.h" #include "util-input-event.h" #include "util-macros.h" #include "util-strings.h" static const int FILE_VERSION_NUMBER = 1; /* Indentation levels for the various data nodes */ enum indent { I_NONE = 0, I_TOPLEVEL = 0, I_LIBINPUT = 2, /* nodes inside libinput: */ I_SYSTEM = 2, /* nodes inside system: */ I_DEVICE = 2, /* nodes inside devices: */ I_EVDEV = 4, /* nodes inside evdev: */ I_EVDEV_DATA = 6, /* nodes below evdev: */ I_UDEV = 4, /* nodes inside udev: */ I_UDEV_DATA = 6, /* nodes below udev: */ I_QUIRKS = 4, /* nodes inside quirks: */ I_LIBINPUTDEV = 4, /* nodes inside libinput: (the device description */ I_EVENTTYPE = 4, /* event type (evdev:, libinput:, hidraw:) */ I_EVENT = 6, /* event data */ }; struct record_device { struct record_context *ctx; struct list link; char *devnode; /* device node of the source device */ struct libevdev *evdev; struct libevdev *evdev_prev; /* previous value, used for EV_ABS deltas */ struct libinput_device *device; struct list hidraw_devices; struct { bool is_touch_device; uint16_t slot_state; uint16_t last_slot_state; } touch; FILE *fp; }; struct hidraw { struct list link; struct record_device *device; int fd; char *name; }; struct record_context { int timeout; bool show_keycodes; uint64_t offset; /* The first device to be added */ struct record_device *first_device; struct list devices; int ndevices; struct { char *name; /* file name given on cmdline */ char *name_with_suffix; /* full file name with suffix */ } output_file; struct libinput *libinput; int epoll_fd; struct list sources; struct { bool had_events_since_last_time; bool skipped_timer_print; } timestamps; bool had_events; bool stop; }; #define resize(array_, sz_) \ { \ size_t new_size = (sz_) + 1000; \ void *tmp = realloc((array_), new_size * sizeof(*(array_))); \ assert(tmp); \ (array_) = tmp; \ (sz_) = new_size; \ } typedef void (*source_dispatch_t)(struct record_context *ctx, int fd, void *user_data); struct source { source_dispatch_t dispatch; void *user_data; int fd; struct list link; }; static bool obfuscate_keycode(struct input_event *ev) { switch (ev->type) { case EV_KEY: switch (ev->code) { case KEY_ESC: case KEY_TAB: case KEY_ENTER: case KEY_LEFTCTRL: break; default: if ((ev->code > KEY_ESC && ev->code < KEY_CAPSLOCK) || (ev->code >= KEY_KP7 && ev->code <= KEY_KPDOT)) { ev->code = KEY_A; return true; } } break; case EV_MSC: if (ev->code == MSC_SCAN) { ev->value = 30; /* KEY_A scancode */ return true; } break; } return false; } /** * Indented dprintf, indentation is in the context */ LIBINPUT_ATTRIBUTE_PRINTF(3, 4) static void iprintf(FILE *fp, enum indent indent, const char *format, ...) { va_list args; char fmt[1024]; static const char space[] = " "; static const size_t len = sizeof(space); int rc; assert(indent < len); assert(strlen(format) >= 1); /* Special case: if we're printing a new list item, we want less * indentation because the '- ' takes up one level of indentation * * This is only needed because I don't want to deal with open/close * lists statements. */ if (format[0] == '-' && indent > 0) indent -= 2; snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format); va_start(args, format); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" rc = vfprintf(fp, fmt, args); #pragma GCC diagnostic pop va_end(args); assert(rc != -1 && (unsigned int)rc > indent); } static uint64_t time_offset(struct record_context *ctx, uint64_t time) { return ctx->offset ? time - ctx->offset : 0; } static void print_evdev_event(struct record_device *dev, struct input_event *ev) { const char *tname, *cname; bool was_modified = false; char desc[1024]; uint64_t time = input_event_time(ev) - dev->ctx->offset; input_event_set_time(ev, time); /* Don't leak passwords unless the user wants to */ if (!dev->ctx->show_keycodes) was_modified = obfuscate_keycode(ev); tname = libevdev_event_type_get_name(ev->type); cname = libevdev_event_code_get_name(ev->type, ev->code); if (ev->type == EV_SYN && ev->code == SYN_MT_REPORT) { snprintf(desc, sizeof(desc), "++++++++++++ %s (%d) ++++++++++", cname, ev->value); } else if (ev->type == EV_SYN) { static unsigned long last_ms = 0; unsigned long time, dt; time = us2ms(input_event_time(ev)); dt = time - last_ms; last_ms = time; snprintf(desc, sizeof(desc), "------------ %s (%d) ---------- %+ldms", cname, ev->value, dt); } else if (ev->type == EV_ABS) { int oldval = 0; enum { DELTA, SLOT_DELTA, NO_DELTA } want = DELTA; int delta = 0; /* We want to print deltas for abs axes but there are a few * that we don't care about for actual deltas because * they're meaningless. * * Also, any slotted axis needs to be printed per slot */ switch (ev->code) { case ABS_MT_SLOT: libevdev_set_event_value(dev->evdev_prev, ev->type, ev->code, ev->value); want = NO_DELTA; break; case ABS_MT_TRACKING_ID: case ABS_MT_BLOB_ID: want = NO_DELTA; break; case ABS_MT_TOUCH_MAJOR ... ABS_MT_POSITION_Y: case ABS_MT_PRESSURE ... ABS_MT_TOOL_Y: if (libevdev_get_num_slots(dev->evdev_prev) > 0) want = SLOT_DELTA; break; default: break; } switch (want) { case DELTA: oldval = libevdev_get_event_value(dev->evdev_prev, ev->type, ev->code); libevdev_set_event_value(dev->evdev_prev, ev->type, ev->code, ev->value); break; case SLOT_DELTA: { int slot = libevdev_get_current_slot(dev->evdev_prev); oldval = libevdev_get_slot_value(dev->evdev_prev, slot, ev->code); libevdev_set_slot_value(dev->evdev_prev, slot, ev->code, ev->value); break; } case NO_DELTA: break; } delta = ev->value - oldval; switch (want) { case DELTA: case SLOT_DELTA: snprintf(desc, sizeof(desc), "%s / %-20s %6d (%+d)", tname, cname, ev->value, delta); break; case NO_DELTA: snprintf(desc, sizeof(desc), "%s / %-20s %6d", tname, cname, ev->value); break; } } else { snprintf(desc, sizeof(desc), "%s / %-20s %6d%s", tname, cname, ev->value, was_modified ? " (obfuscated)" : ""); } iprintf(dev->fp, I_EVENT, "- [%3lu, %6u, %3d, %3d, %7d] # %s\n", ev->input_event_sec, (unsigned int)ev->input_event_usec, ev->type, ev->code, ev->value, desc); } static bool handle_evdev_frame(struct record_device *d) { struct libevdev *evdev = d->evdev; struct input_event e; if (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &e) != LIBEVDEV_READ_STATUS_SUCCESS) return false; iprintf(d->fp, I_EVENTTYPE, "- evdev:\n"); do { if (d->ctx->offset == 0) { uint64_t time = input_event_time(&e); d->ctx->offset = time; } print_evdev_event(d, &e); if (d->touch.is_touch_device && e.type == EV_ABS && e.code == ABS_MT_TRACKING_ID) { unsigned int slot = libevdev_get_current_slot(evdev); assert(slot < sizeof(d->touch.slot_state) * 8); if (e.value != -1) d->touch.slot_state |= bit(slot); else d->touch.slot_state &= ~bit(slot); } if (e.type == EV_SYN && e.code == SYN_REPORT) break; } while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &e) == LIBEVDEV_READ_STATUS_SUCCESS); if (d->touch.slot_state != d->touch.last_slot_state) { d->touch.last_slot_state = d->touch.slot_state; if (d->touch.slot_state == 0) { iprintf(d->fp, I_EVENT, " # Touch device in neutral state\n"); } } return true; } static void print_device_notify(struct record_device *dev, struct libinput_event *e) { struct libinput_device *d = libinput_event_get_device(e); struct libinput_seat *seat = libinput_device_get_seat(d); const char *type = NULL; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_DEVICE_ADDED: type = "DEVICE_ADDED"; break; case LIBINPUT_EVENT_DEVICE_REMOVED: type = "DEVICE_REMOVED"; break; default: abort(); } iprintf(dev->fp, I_EVENT, "- {type: %s, seat: %5s, logical_seat: %7s}\n", type, libinput_seat_get_physical_name(seat), libinput_seat_get_logical_name(seat)); } static void print_key_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(e); enum libinput_key_state state; uint32_t key; uint64_t time; const char *type; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_KEYBOARD_KEY: type = "KEYBOARD_KEY"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_keyboard_get_time_usec(k)); state = libinput_event_keyboard_get_key_state(k); key = libinput_event_keyboard_get_key(k); if (!dev->ctx->show_keycodes && (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) key = -1; iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, key: %d, state: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, key, state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released"); } static void print_motion_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(e); double x = libinput_event_pointer_get_dx(p), y = libinput_event_pointer_get_dy(p); double uax = libinput_event_pointer_get_dx_unaccelerated(p), uay = libinput_event_pointer_get_dy_unaccelerated(p); uint64_t time; const char *type; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_POINTER_MOTION: type = "POINTER_MOTION"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_pointer_get_time_usec(p)); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f]}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, x, y, uax, uay); } static void print_absmotion_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(e); double x = libinput_event_pointer_get_absolute_x(p), y = libinput_event_pointer_get_absolute_y(p); double tx = libinput_event_pointer_get_absolute_x_transformed(p, 100), ty = libinput_event_pointer_get_absolute_y_transformed(p, 100); uint64_t time; const char *type; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: type = "POINTER_MOTION_ABSOLUTE"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_pointer_get_time_usec(p)); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, point: [%6.2f, %6.2f], transformed: [%6.2f, %6.2f]}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, x, y, tx, ty); } static void print_pointer_button_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(e); enum libinput_button_state state; int button; uint64_t time; const char *type; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_POINTER_BUTTON: type = "POINTER_BUTTON"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_pointer_get_time_usec(p)); button = libinput_event_pointer_get_button(p); state = libinput_event_pointer_get_button_state(p); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, button: %d, state: %s, seat_count: %u}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, button, state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", libinput_event_pointer_get_seat_button_count(p)); } static void print_pointer_axis_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(e); uint64_t time; const char *type, *source; double h = 0, v = 0; int hd = 0, vd = 0; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_POINTER_AXIS: type = "POINTER_AXIS"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_pointer_get_time_usec(p)); if (libinput_event_pointer_has_axis(p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { h = libinput_event_pointer_get_axis_value(p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); hd = libinput_event_pointer_get_axis_value_discrete(p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); } if (libinput_event_pointer_has_axis(p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { v = libinput_event_pointer_get_axis_value(p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); vd = libinput_event_pointer_get_axis_value_discrete(p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); } switch(libinput_event_pointer_get_axis_source(p)) { case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL: source = "wheel"; break; case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: source = "finger"; break; case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: source = "continuous"; break; case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: source = "wheel-tilt"; break; default: source = "unknown"; break; } iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, axes: [%2.2f, %2.2f], discrete: [%d, %d], source: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, h, v, hd, vd, source); } static void print_touch_event(struct record_device *dev, struct libinput_event *e) { enum libinput_event_type etype = libinput_event_get_type(e); struct libinput_event_touch *t = libinput_event_get_touch_event(e); const char *type; double x, y; double tx, ty; uint64_t time; int32_t slot, seat_slot; switch(etype) { case LIBINPUT_EVENT_TOUCH_DOWN: type = "TOUCH_DOWN"; break; case LIBINPUT_EVENT_TOUCH_UP: type = "TOUCH_UP"; break; case LIBINPUT_EVENT_TOUCH_MOTION: type = "TOUCH_MOTION"; break; case LIBINPUT_EVENT_TOUCH_CANCEL: type = "TOUCH_CANCEL"; break; case LIBINPUT_EVENT_TOUCH_FRAME: type = "TOUCH_FRAME"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_touch_get_time_usec(t)); if (etype != LIBINPUT_EVENT_TOUCH_FRAME) { slot = libinput_event_touch_get_slot(t); seat_slot = libinput_event_touch_get_seat_slot(t); } switch (etype) { case LIBINPUT_EVENT_TOUCH_FRAME: iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type); break; case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_MOTION: x = libinput_event_touch_get_x(t); y = libinput_event_touch_get_y(t); tx = libinput_event_touch_get_x_transformed(t, 100); ty = libinput_event_touch_get_y_transformed(t, 100); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, slot: %d, seat_slot: %d, " "point: [%6.2f, %6.2f], transformed: [%6.2f, %6.2f]}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, slot, seat_slot, x, y, tx, ty); break; case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_CANCEL: iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, slot: %d, seat_slot: %d}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, slot, seat_slot); break; default: abort(); } } static void print_gesture_event(struct record_device *dev, struct libinput_event *e) { enum libinput_event_type etype = libinput_event_get_type(e); struct libinput_event_gesture *g = libinput_event_get_gesture_event(e); const char *type; uint64_t time; switch(etype) { case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: type = "GESTURE_PINCH_BEGIN"; break; case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: type = "GESTURE_PINCH_UPDATE"; break; case LIBINPUT_EVENT_GESTURE_PINCH_END: type = "GESTURE_PINCH_END"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: type = "GESTURE_SWIPE_BEGIN"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: type = "GESTURE_SWIPE_UPDATE"; break; case LIBINPUT_EVENT_GESTURE_SWIPE_END: type = "GESTURE_SWIPE_END"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_gesture_get_time_usec(g)); switch (etype) { case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: case LIBINPUT_EVENT_GESTURE_PINCH_END: iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, nfingers: %d, " "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f], " "angle_delta: %6.2f, scale: %6.2f}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, libinput_event_gesture_get_finger_count(g), libinput_event_gesture_get_dx(g), libinput_event_gesture_get_dy(g), libinput_event_gesture_get_dx_unaccelerated(g), libinput_event_gesture_get_dy_unaccelerated(g), libinput_event_gesture_get_angle_delta(g), libinput_event_gesture_get_scale(g) ); break; case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: case LIBINPUT_EVENT_GESTURE_SWIPE_END: iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, nfingers: %d, " "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f]}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, libinput_event_gesture_get_finger_count(g), libinput_event_gesture_get_dx(g), libinput_event_gesture_get_dy(g), libinput_event_gesture_get_dx_unaccelerated(g), libinput_event_gesture_get_dy_unaccelerated(g) ); break; default: abort(); } } static char * buffer_tablet_axes(struct libinput_event_tablet_tool *t) { const int MAX_AXES = 10; struct libinput_tablet_tool *tool; char *s = NULL; int idx = 0; int len; double x, y; char **strv; tool = libinput_event_tablet_tool_get_tool(t); strv = zalloc(MAX_AXES * sizeof *strv); x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_y(t); len = xasprintf(&strv[idx++], "point: [%.2f, %.2f]", x, y); if (len <= 0) goto out; if (libinput_tablet_tool_has_tilt(tool)) { x = libinput_event_tablet_tool_get_tilt_x(t); y = libinput_event_tablet_tool_get_tilt_y(t); len = xasprintf(&strv[idx++], "tilt: [%.2f, %.2f]", x, y); if (len <= 0) goto out; } if (libinput_tablet_tool_has_distance(tool) || libinput_tablet_tool_has_pressure(tool)) { double dist, pressure; dist = libinput_event_tablet_tool_get_distance(t); pressure = libinput_event_tablet_tool_get_pressure(t); if (dist) len = xasprintf(&strv[idx++], "distance: %.2f", dist); else len = xasprintf(&strv[idx++], "pressure: %.2f", pressure); if (len <= 0) goto out; } if (libinput_tablet_tool_has_rotation(tool)) { double rotation; rotation = libinput_event_tablet_tool_get_rotation(t); len = xasprintf(&strv[idx++], "rotation: %.2f", rotation); if (len <= 0) goto out; } if (libinput_tablet_tool_has_slider(tool)) { double slider; slider = libinput_event_tablet_tool_get_slider_position(t); len = xasprintf(&strv[idx++], "slider: %.2f", slider); if (len <= 0) goto out; } if (libinput_tablet_tool_has_wheel(tool)) { double wheel; int delta; wheel = libinput_event_tablet_tool_get_wheel_delta(t); len = xasprintf(&strv[idx++], "wheel: %.2f", wheel); if (len <= 0) goto out; delta = libinput_event_tablet_tool_get_wheel_delta_discrete(t); len = xasprintf(&strv[idx++], "wheel-discrete: %d", delta); if (len <= 0) goto out; } assert(idx < MAX_AXES); s = strv_join(strv, ", "); out: strv_free(strv); return s; } static void print_tablet_tool_proximity_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(e); struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); uint64_t time; const char *type, *tool_type; char *axes; char caps[10] = {0}; enum libinput_tablet_tool_proximity_state prox; size_t idx; switch (libinput_event_get_type(e)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: type = "TABLET_TOOL_PROXIMITY"; break; default: abort(); } switch (libinput_tablet_tool_get_type(tool)) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: tool_type = "pen"; break; case LIBINPUT_TABLET_TOOL_TYPE_ERASER: tool_type = "eraser"; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: tool_type = "brush"; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: tool_type = "brush"; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: tool_type = "airbrush"; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: tool_type = "mouse"; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: tool_type = "lens"; break; default: tool_type = "unknown"; break; } prox = libinput_event_tablet_tool_get_proximity_state(t); time = time_offset(dev->ctx, libinput_event_tablet_tool_get_time_usec(t)); axes = buffer_tablet_axes(t); idx = 0; if (libinput_tablet_tool_has_pressure(tool)) caps[idx++] = 'p'; if (libinput_tablet_tool_has_distance(tool)) caps[idx++] = 'd'; if (libinput_tablet_tool_has_tilt(tool)) caps[idx++] = 't'; if (libinput_tablet_tool_has_rotation(tool)) caps[idx++] = 'r'; if (libinput_tablet_tool_has_slider(tool)) caps[idx++] = 's'; if (libinput_tablet_tool_has_wheel(tool)) caps[idx++] = 'w'; assert(idx <= ARRAY_LENGTH(caps)); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, proximity: %s, tool-type: %s, serial: %" PRIu64 ", axes: %s, %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, prox ? "in" : "out", tool_type, libinput_tablet_tool_get_serial(tool), caps, axes); free(axes); } static void print_tablet_tool_button_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(e); uint64_t time; const char *type; uint32_t button; enum libinput_button_state state; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: type = "TABLET_TOOL_BUTTON"; break; default: abort(); } button = libinput_event_tablet_tool_get_button(t); state = libinput_event_tablet_tool_get_button_state(t); time = time_offset(dev->ctx, libinput_event_tablet_tool_get_time_usec(t)); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, button: %d, state: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, button, state ? "pressed" : "released"); } static void print_tablet_tool_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(e); uint64_t time; const char *type; char *axes; enum libinput_tablet_tool_tip_state tip; char btn_buffer[30] = {0}; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_TABLET_TOOL_AXIS: type = "TABLET_TOOL_AXIS"; break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: type = "TABLET_TOOL_TIP"; break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: type = "TABLET_TOOL_BUTTON"; break; default: abort(); } if (libinput_event_get_type(e) == LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { uint32_t button; enum libinput_button_state state; button = libinput_event_tablet_tool_get_button(t); state = libinput_event_tablet_tool_get_button_state(t); snprintf(btn_buffer, sizeof(btn_buffer), ", button: %d, state: %s\n", button, state ? "pressed" : "released"); } tip = libinput_event_tablet_tool_get_tip_state(t); time = time_offset(dev->ctx, libinput_event_tablet_tool_get_time_usec(t)); axes = buffer_tablet_axes(t); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s%s, tip: %s, %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, btn_buffer, /* may be empty string */ tip ? "down" : "up", axes); free(axes); } static void print_tablet_pad_button_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(e); struct libinput_tablet_pad_mode_group *group; enum libinput_button_state state; unsigned int button, mode; const char *type; uint64_t time; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_TABLET_PAD_BUTTON: type = "TABLET_PAD_BUTTON"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_tablet_pad_get_time_usec(p)); button = libinput_event_tablet_pad_get_button_number(p), state = libinput_event_tablet_pad_get_button_state(p); mode = libinput_event_tablet_pad_get_mode(p); group = libinput_event_tablet_pad_get_mode_group(p); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, button: %d, state: %s, mode: %d, is-toggle: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, button, state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", mode, truefalse(libinput_tablet_pad_mode_group_button_is_toggle(group, button)) ); } static void print_tablet_pad_ringstrip_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(e); const char *source = NULL; unsigned int mode, number; const char *type; uint64_t time; double pos; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_TABLET_PAD_RING: type = "TABLET_PAD_RING"; number = libinput_event_tablet_pad_get_ring_number(p); pos = libinput_event_tablet_pad_get_ring_position(p); switch (libinput_event_tablet_pad_get_ring_source(p)) { case LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER: source = "finger"; break; case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN: source = "unknown"; break; } break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: type = "TABLET_PAD_STRIP"; number = libinput_event_tablet_pad_get_strip_number(p); pos = libinput_event_tablet_pad_get_strip_position(p); switch (libinput_event_tablet_pad_get_strip_source(p)) { case LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER: source = "finger"; break; case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN: source = "unknown"; break; } break; default: abort(); } time = time_offset(dev->ctx, libinput_event_tablet_pad_get_time_usec(p)); mode = libinput_event_tablet_pad_get_mode(p); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, number: %d, position: %.2f, source: %s, mode: %d}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, number, pos, source, mode); } static void print_switch_event(struct record_device *dev, struct libinput_event *e) { struct libinput_event_switch *s = libinput_event_get_switch_event(e); enum libinput_switch_state state; uint32_t sw; const char *type; uint64_t time; switch(libinput_event_get_type(e)) { case LIBINPUT_EVENT_SWITCH_TOGGLE: type = "SWITCH_TOGGLE"; break; default: abort(); } time = time_offset(dev->ctx, libinput_event_switch_get_time_usec(s)); sw = libinput_event_switch_get_switch(s); state = libinput_event_switch_get_switch_state(s); iprintf(dev->fp, I_EVENT, "- {time: %ld.%06ld, type: %s, switch: %d, state: %s}\n", (long)(time / (int)1e6), (long)(time % (int)1e6), type, sw, state == LIBINPUT_SWITCH_STATE_ON ? "on" : "off"); } static void print_libinput_event(struct record_device *dev, struct libinput_event *e) { switch (libinput_event_get_type(e)) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: case LIBINPUT_EVENT_DEVICE_REMOVED: print_device_notify(dev, e); break; case LIBINPUT_EVENT_KEYBOARD_KEY: print_key_event(dev, e); break; case LIBINPUT_EVENT_POINTER_MOTION: print_motion_event(dev, e); break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: print_absmotion_event(dev, e); break; case LIBINPUT_EVENT_POINTER_BUTTON: print_pointer_button_event(dev, e); break; case LIBINPUT_EVENT_POINTER_AXIS: print_pointer_axis_event(dev, e); break; case LIBINPUT_EVENT_TOUCH_DOWN: case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: print_touch_event(dev, e); break; case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: case LIBINPUT_EVENT_GESTURE_PINCH_END: case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: case LIBINPUT_EVENT_GESTURE_SWIPE_END: print_gesture_event(dev, e); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: print_tablet_tool_proximity_event(dev, e); break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_TIP: print_tablet_tool_event(dev, e); break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: print_tablet_tool_button_event(dev, e); break; case LIBINPUT_EVENT_TABLET_PAD_BUTTON: print_tablet_pad_button_event(dev, e); break; case LIBINPUT_EVENT_TABLET_PAD_RING: case LIBINPUT_EVENT_TABLET_PAD_STRIP: print_tablet_pad_ringstrip_event(dev, e); break; case LIBINPUT_EVENT_SWITCH_TOGGLE: print_switch_event(dev, e); break; default: break; } } static bool handle_hidraw(struct hidraw *hidraw) { struct record_device *d = hidraw->device; unsigned char report[4096]; const char *sep = ""; struct timespec ts; struct timeval tv; uint64_t time; int rc = read(hidraw->fd, report, sizeof(report)); if (rc <= 0) return false; /* hidraw doesn't give us a timestamps, we have to make them up */ clock_gettime(CLOCK_MONOTONIC, &ts); time = s2us(ts.tv_sec) + ns2us(ts.tv_nsec); /* The first evdev event is guaranteed to have an event time earlier than now, so we don't set the offset here, we rely on the evdev events to do so. This potentially leaves us with multiple hidraw events at timestap 0 but it's too niche to worry about. */ if (d->ctx->offset == 0) time = 0; else time = time_offset(d->ctx, time); tv = us2tv(time); iprintf(d->fp, I_EVENTTYPE, "- hid:\n"); iprintf(d->fp, I_EVENT, "time: [%3lu, %6lu]\n", tv.tv_sec, tv.tv_usec); iprintf(d->fp, I_EVENT, "%s: [", hidraw->name); for (int byte = 0; byte < rc; byte++) { if (byte % 16 == 0) { iprintf(d->fp, I_NONE, "%s\n", sep); iprintf(d->fp, I_EVENT, " "); iprintf(d->fp, I_NONE, "0x%02x", report[byte]); } else { iprintf(d->fp, I_NONE, "%s0x%02x", sep, report[byte]); } sep = ", "; } iprintf(d->fp, I_NONE, "\n"); iprintf(d->fp, I_EVENT, "]\n"); return true; } static bool handle_libinput_events(struct record_context *ctx, struct record_device *d, bool start_frame) { struct libinput_event *e; struct record_device *current = d; libinput_dispatch(ctx->libinput); e = libinput_get_event(ctx->libinput); if (!e) return false; if (start_frame) iprintf(d->fp, I_EVENTTYPE, "- libinput:\n"); else iprintf(d->fp, I_EVENTTYPE, "libinput:\n"); do { struct libinput_device *device = libinput_event_get_device(e); if (device != current->device) { struct record_device *tmp; bool found = false; list_for_each(tmp, &ctx->devices, link) { if (device == tmp->device) { current = tmp; found = true; break; } } assert(found); } print_libinput_event(current, e); libinput_event_destroy(e); } while ((e = libinput_get_event(ctx->libinput)) != NULL); return true; } static void handle_events(struct record_context *ctx, struct record_device *d) { bool has_events = true; while (has_events) { has_events = handle_evdev_frame(d); if (ctx->libinput) has_events |= handle_libinput_events(ctx, d, !has_events); } fflush(d->fp); } static void print_libinput_header(FILE *fp, int timeout) { iprintf(fp, I_TOPLEVEL, "libinput:\n"); iprintf(fp, I_LIBINPUT, "version: \"%s\"\n", LIBINPUT_VERSION); iprintf(fp, I_LIBINPUT, "git: \"%s\"\n", LIBINPUT_GIT_VERSION); if (timeout > 0) iprintf(fp, I_LIBINPUT, "autorestart: %d\n", timeout); } static void print_system_header(FILE *fp) { struct utsname u; const char *kernel = "unknown"; FILE *dmi, *osrelease; char dmistr[2048] = "unknown"; iprintf(fp, I_TOPLEVEL, "system:\n"); /* /etc/os-release version and distribution name */ osrelease = fopen("/etc/os-release", "r"); if (!osrelease) osrelease = fopen("/usr/lib/os-release", "r"); if (osrelease) { char *distro = NULL, *version = NULL; char osrstr[256] = "unknown"; while (fgets(osrstr, sizeof(osrstr), osrelease)) { osrstr[strlen(osrstr) - 1] = '\0'; /* linebreak */ if (!distro && strstartswith(osrstr, "ID=")) distro = strstrip(&osrstr[3], "\"'"); else if (!version && strstartswith(osrstr, "VERSION_ID=")) version = strstrip(&osrstr[11], "\"'"); if (distro && version) { iprintf(fp, I_SYSTEM, "os: \"%s:%s\"\n", distro, version); break; } } free(distro); free(version); fclose(osrelease); } /* kernel version */ if (uname(&u) != -1) kernel = u.release; iprintf(fp, I_SYSTEM, "kernel: \"%s\"\n", kernel); /* dmi modalias */ dmi = fopen("/sys/class/dmi/id/modalias", "r"); if (dmi) { if (fgets(dmistr, sizeof(dmistr), dmi)) { dmistr[strlen(dmistr) - 1] = '\0'; /* linebreak */ } else { sprintf(dmistr, "unknown"); } fclose(dmi); } iprintf(fp, I_SYSTEM, "dmi: \"%s\"\n", dmistr); } static void print_header(FILE *fp, struct record_context *ctx) { iprintf(fp, I_TOPLEVEL, "# libinput record\n"); iprintf(fp, I_TOPLEVEL, "version: %d\n", FILE_VERSION_NUMBER); iprintf(fp, I_TOPLEVEL, "ndevices: %d\n", ctx->ndevices); print_libinput_header(fp, ctx->timeout); print_system_header(fp); } static void print_description_abs(FILE *fp, struct libevdev *dev, unsigned int code) { const struct input_absinfo *abs; abs = libevdev_get_abs_info(dev, code); assert(abs); iprintf(fp, I_EVDEV, "# Value %6d\n", abs->value); iprintf(fp, I_EVDEV, "# Min %6d\n", abs->minimum); iprintf(fp, I_EVDEV, "# Max %6d\n", abs->maximum); iprintf(fp, I_EVDEV, "# Fuzz %6d\n", abs->fuzz); iprintf(fp, I_EVDEV, "# Flat %6d\n", abs->flat); iprintf(fp, I_EVDEV, "# Resolution %6d\n", abs->resolution); } static void print_description_state(FILE *fp, struct libevdev *dev, unsigned int type, unsigned int code) { int state = libevdev_get_event_value(dev, type, code); iprintf(fp, I_EVDEV, "# State %d\n", state); } static void print_description_codes(FILE *fp, struct libevdev *dev, unsigned int type) { int max; max = libevdev_event_type_get_max(type); if (max == -1) return; iprintf(fp, I_EVDEV, "# Event type %d (%s)\n", type, libevdev_event_type_get_name(type)); if (type == EV_SYN) return; for (unsigned int code = 0; code <= (unsigned int)max; code++) { if (!libevdev_has_event_code(dev, type, code)) continue; iprintf(fp, I_EVDEV, "# Event code %d (%s)\n", code, libevdev_event_code_get_name(type, code)); switch (type) { case EV_ABS: print_description_abs(fp, dev, code); break; case EV_LED: case EV_SW: print_description_state(fp, dev, type, code); break; } } } static void print_description(FILE *fp, struct libevdev *dev) { const struct input_absinfo *x, *y; int bustype; const char *busname; bustype = libevdev_get_id_bustype(dev); switch (bustype) { case BUS_USB: busname = " (usb) "; break; case BUS_BLUETOOTH: busname = " (bluetooth) "; break; case BUS_I2C: busname = " (i2c) "; break; case BUS_SPI: busname = " (spi) "; break; case BUS_RMI: busname = " (rmi) "; break; default: busname = " "; break; } iprintf(fp, I_EVDEV, "# Name: %s\n", libevdev_get_name(dev)); iprintf(fp, I_EVDEV, "# ID: bus 0x%04x%svendor 0x%04x product 0x%04x version 0x%04x\n", bustype, busname, libevdev_get_id_vendor(dev), libevdev_get_id_product(dev), libevdev_get_id_version(dev)); x = libevdev_get_abs_info(dev, ABS_X); y = libevdev_get_abs_info(dev, ABS_Y); if (x && y) { if (x->resolution && y->resolution) { int w, h; w = (x->maximum - x->minimum)/x->resolution; h = (y->maximum - y->minimum)/y->resolution; iprintf(fp, I_EVDEV, "# Size in mm: %dx%d\n", w, h); } else { iprintf(fp, I_EVDEV, "# Size in mm: unknown, missing resolution\n"); } } iprintf(fp, I_EVDEV, "# Supported Events:\n"); for (unsigned int type = 0; type < EV_CNT; type++) { if (!libevdev_has_event_type(dev, type)) continue; print_description_codes(fp, dev, type); } iprintf(fp, I_EVDEV, "# Properties:\n"); for (unsigned int prop = 0; prop < INPUT_PROP_CNT; prop++) { if (libevdev_has_property(dev, prop)) { iprintf(fp, I_EVDEV, "# Property %d (%s)\n", prop, libevdev_property_get_name(prop)); } } } static void print_bits_info(FILE *fp, struct libevdev *dev) { iprintf(fp, I_EVDEV, "name: \"%s\"\n", libevdev_get_name(dev)); iprintf(fp, I_EVDEV, "id: [%d, %d, %d, %d]\n", libevdev_get_id_bustype(dev), libevdev_get_id_vendor(dev), libevdev_get_id_product(dev), libevdev_get_id_version(dev)); } static void print_bits_absinfo(FILE *fp, struct libevdev *dev) { const struct input_absinfo *abs; if (!libevdev_has_event_type(dev, EV_ABS)) return; iprintf(fp, I_EVDEV, "absinfo:\n"); for (unsigned int code = 0; code < ABS_CNT; code++) { abs = libevdev_get_abs_info(dev, code); if (!abs) continue; iprintf(fp, I_EVDEV_DATA, "%d: [%d, %d, %d, %d, %d]\n", code, abs->minimum, abs->maximum, abs->fuzz, abs->flat, abs->resolution); } } static void print_bits_codes(FILE *fp, struct libevdev *dev, unsigned int type) { int max; const char *sep = ""; max = libevdev_event_type_get_max(type); if (max == -1) return; iprintf(fp, I_EVDEV_DATA, "%d: [", type); for (unsigned int code = 0; code <= (unsigned int)max; code++) { if (!libevdev_has_event_code(dev, type, code)) continue; iprintf(fp, I_NONE, "%s%d", sep, code); sep = ", "; } iprintf(fp, I_NONE, "] # %s\n", libevdev_event_type_get_name(type)); } static void print_bits_types(FILE *fp, struct libevdev *dev) { iprintf(fp, I_EVDEV, "codes:\n"); for (unsigned int type = 0; type < EV_CNT; type++) { if (!libevdev_has_event_type(dev, type)) continue; print_bits_codes(fp, dev, type); } } static void print_bits_props(FILE *fp, struct libevdev *dev) { const char *sep = ""; iprintf(fp, I_EVDEV, "properties: ["); for (unsigned int prop = 0; prop < INPUT_PROP_CNT; prop++) { if (libevdev_has_property(dev, prop)) { iprintf(fp, I_NONE, "%s%d", sep, prop); sep = ", "; } } iprintf(fp, I_NONE, "]\n"); /* last entry, no comma */ } static void print_evdev_description(struct record_device *dev) { struct libevdev *evdev = dev->evdev; iprintf(dev->fp, I_DEVICE, "evdev:\n"); print_description(dev->fp, evdev); print_bits_info(dev->fp, evdev); print_bits_types(dev->fp, evdev); print_bits_absinfo(dev->fp, evdev); print_bits_props(dev->fp, evdev); } static void print_hid_report_descriptor(struct record_device *dev) { const char *prefix = "/dev/input/event"; char syspath[PATH_MAX]; unsigned char buf[1024]; int len; int fd; const char *sep = ""; /* we take the shortcut rather than the proper udev approach, the report_descriptor is available in sysfs and two devices up from our device. This approach won't work for /dev/input/by-id devices. */ if (!strstartswith(dev->devnode, prefix)) return; len = snprintf(syspath, sizeof(syspath), "/sys/class/input/%s/device/device/report_descriptor", safe_basename(dev->devnode)); if (len <= 0) return; fd = open(syspath, O_RDONLY); if (fd == -1) return; iprintf(dev->fp, I_DEVICE, "hid: ["); while ((len = read(fd, buf, sizeof(buf))) > 0) { for (int i = 0; i < len; i++) { /* We can't have a trailing comma, so our line-break * handling is awkward. * For a linebreak: print the comma, break, indent, * then just the hex code. * For the other values: print the comma plus the * hex code, unindented. */ if (i % 16 == 0) { iprintf(dev->fp, I_NONE, "%s\n", sep); iprintf(dev->fp, I_DEVICE, " "); iprintf(dev->fp, I_NONE, "0x%02x", buf[i]); } else { iprintf(dev->fp, I_NONE, "%s0x%02x", sep, buf[i]); } sep = ", "; } } iprintf(dev->fp, I_NONE, "\n"); iprintf(dev->fp, I_DEVICE, "]\n"); close(fd); } static void print_udev_properties(struct record_device *dev) { struct udev *udev = NULL; struct udev_device *udev_device = NULL; struct udev_list_entry *entry; struct stat st; if (stat(dev->devnode, &st) < 0) return; udev = udev_new(); if (!udev) goto out; udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); if (!udev_device) goto out; iprintf(dev->fp, I_DEVICE, "udev:\n"); iprintf(dev->fp, I_UDEV, "properties:\n"); entry = udev_device_get_properties_list_entry(udev_device); while (entry) { const char *key, *value; key = udev_list_entry_get_name(entry); if (strstartswith(key, "ID_INPUT") || strstartswith(key, "HID_BPF") || strstartswith(key, "LIBINPUT") || strstartswith(key, "EVDEV_ABS") || strstartswith(key, "MOUSE_DPI") || strstartswith(key, "POINTINGSTICK_")) { value = udev_list_entry_get_value(entry); iprintf(dev->fp, I_UDEV_DATA, "- %s=%s\n", key, value); } entry = udev_list_entry_get_next(entry); } for (struct udev_device *parent = udev_device; parent; parent = udev_device_get_parent(parent)) { const char *driver = udev_device_get_property_value(parent, "DRIVER"); if (driver) { iprintf(dev->fp, I_UDEV_DATA, "- DRIVER=%s\n", driver); break; } } out: udev_device_unref(udev_device); udev_unref(udev); } static void quirks_log_handler(struct libinput *this_is_null, enum libinput_log_priority priority, const char *format, va_list args) { } static void list_print(void *userdata, const char *val) { FILE *fp = userdata; iprintf(fp, I_QUIRKS, "- %s\n", val); } static void print_device_quirks(struct record_device *dev) { struct udev *udev = NULL; struct udev_device *udev_device = NULL; struct stat st; struct quirks_context *quirks; const char *data_path = LIBINPUT_QUIRKS_DIR; const char *override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE; char *builddir = NULL; if (stat(dev->devnode, &st) < 0) return; if ((builddir = builddir_lookup())) { setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0); data_path = LIBINPUT_QUIRKS_SRCDIR; override_file = NULL; } free(builddir); quirks = quirks_init_subsystem(data_path, override_file, quirks_log_handler, NULL, QLOG_CUSTOM_LOG_PRIORITIES); if (!quirks) { fprintf(stderr, "Failed to load the device quirks from %s%s%s. " "This will negatively affect device behavior. " "See %s/device-quirks.html for details.\n", data_path, override_file ? " and " : "", override_file ? override_file : "", HTTP_DOC_LINK); return; } udev = udev_new(); if (!udev) goto out; udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); if (!udev_device) goto out; iprintf(dev->fp, I_DEVICE, "quirks:\n"); tools_list_device_quirks(quirks, udev_device, list_print, dev->fp); out: udev_device_unref(udev_device); udev_unref(udev); quirks_context_unref(quirks); } static void print_libinput_description(struct record_device *dev) { struct libinput_device *device = dev->device; double w, h; struct cap { enum libinput_device_capability cap; const char *name; } caps[] = { {LIBINPUT_DEVICE_CAP_KEYBOARD, "keyboard"}, {LIBINPUT_DEVICE_CAP_POINTER, "pointer"}, {LIBINPUT_DEVICE_CAP_TOUCH, "touch"}, {LIBINPUT_DEVICE_CAP_TABLET_TOOL, "tablet"}, {LIBINPUT_DEVICE_CAP_TABLET_PAD, "pad"}, {LIBINPUT_DEVICE_CAP_GESTURE, "gesture"}, {LIBINPUT_DEVICE_CAP_SWITCH, "switch"}, }; const char *sep = ""; if (!device) return; iprintf(dev->fp, I_DEVICE, "libinput:\n"); if (libinput_device_get_size(device, &w, &h) == 0) iprintf(dev->fp, I_LIBINPUTDEV, "size: [%.f, %.f]\n", w, h); iprintf(dev->fp, I_LIBINPUTDEV, "capabilities: ["); ARRAY_FOR_EACH(caps, cap) { if (!libinput_device_has_capability(device, cap->cap)) continue; iprintf(dev->fp, I_NONE, "%s%s", sep, cap->name); sep = ", "; } iprintf(dev->fp, I_NONE, "]\n"); /* Configuration options should be printed here, but since they * don't reflect the user-configured ones their usefulness is * questionable. We need the ability to specify the options like in * debug-events. */ } static void print_device_description(struct record_device *dev) { iprintf(dev->fp, I_DEVICE, "- node: %s\n", dev->devnode); print_evdev_description(dev); print_hid_report_descriptor(dev); print_udev_properties(dev); print_device_quirks(dev); print_libinput_description(dev); } static int is_event_node(const struct dirent *dir) { return strstartswith(dir->d_name, "event"); } static char * select_device(void) { struct dirent **namelist; int ndev, selected_device; int rc; char *device_path; bool has_eaccess = false; int available_devices = 0; const char *prefix = ""; if (!isatty(STDERR_FILENO)) prefix = "# "; ndev = scandir("/dev/input", &namelist, is_event_node, versionsort); if (ndev <= 0) return NULL; fprintf(stderr, "%sAvailable devices:\n", prefix); for (int i = 0; i < ndev; i++) { struct libevdev *device; char path[PATH_MAX]; int fd = -1; snprintf(path, sizeof(path), "/dev/input/%s", namelist[i]->d_name); fd = open(path, O_RDONLY); if (fd < 0) { if (errno == EACCES) has_eaccess = true; continue; } rc = libevdev_new_from_fd(fd, &device); close(fd); if (rc != 0) continue; fprintf(stderr, "%s%s: %s\n", prefix, path, libevdev_get_name(device)); libevdev_free(device); available_devices++; } for (int i = 0; i < ndev; i++) free(namelist[i]); free(namelist); if (available_devices == 0) { fprintf(stderr, "No devices available.%s\n", has_eaccess ? " Please re-run as root." : ""); return NULL; } fprintf(stderr, "%sSelect the device event number: ", prefix); rc = scanf("%d", &selected_device); if (rc != 1 || selected_device < 0) return NULL; rc = xasprintf(&device_path, "/dev/input/event%d", selected_device); if (rc == -1) return NULL; return device_path; } static char ** all_devices(void) { struct dirent **namelist; int ndev; char **devices = NULL; ndev = scandir("/dev/input", &namelist, is_event_node, versionsort); if (ndev <= 0) return NULL; devices = zalloc((ndev + 1)* sizeof *devices); /* NULL-terminated */ for (int i = 0; i < ndev; i++) { char *device_path; int rc = xasprintf(&device_path, "/dev/input/%s", namelist[i]->d_name); if (rc == -1) goto error; devices[i] = device_path; } return devices; error: for (int i = 0; i < ndev; i++) free(namelist[i]); free(namelist); if (devices) strv_free(devices); return NULL; } static char * init_output_file(const char *file, bool is_prefix) { char name[PATH_MAX]; assert(file != NULL); if (is_prefix) { struct tm *tm; time_t t; char suffix[64]; t = time(NULL); tm = localtime(&t); strftime(suffix, sizeof(suffix), "%F-%T", tm); snprintf(name, sizeof(name), "%s.%s", file, suffix); } else { snprintf(name, sizeof(name), "%s", file); } return safe_strdup(name); } static bool open_output_files(struct record_context *ctx, bool is_prefix) { FILE *out_file; struct record_device *d; if (ctx->output_file.name) { char *fname = init_output_file(ctx->output_file.name, is_prefix); ctx->output_file.name_with_suffix = fname; out_file = fopen(fname, "w"); if (!out_file) return false; } else { ctx->output_file.name_with_suffix = safe_strdup("stdout"); out_file = stdout; } ctx->first_device->fp = out_file; list_for_each(d, &ctx->devices, link) { if (d->fp) continue; d->fp = tmpfile(); } return true; } static void print_progress_bar(void) { static uint8_t foo = 0; if (!isatty(STDERR_FILENO)) return; if (++foo > 20) foo = 1; fprintf(stderr, "\rReceiving events: [%*s%*s]", foo, "*", 21 - foo, " "); } static void print_wall_time(struct record_context *ctx) { time_t t = time(NULL); struct tm tm; struct record_device *d; localtime_r(&t, &tm); list_for_each(d, &ctx->devices, link) { iprintf(d->fp, I_DEVICE, "# Current time is %02d:%02d:%02d\n", tm.tm_hour, tm.tm_min, tm.tm_sec); fflush(d->fp); } } static void arm_timer(int timerfd) { time_t t = time(NULL); struct tm tm; struct itimerspec interval = { .it_value = { 0, 0 }, .it_interval = { 5, 0 }, }; localtime_r(&t, &tm); interval.it_value.tv_sec = 5 - (tm.tm_sec % 5); timerfd_settime(timerfd, 0, &interval, NULL); } static struct source * add_source(struct record_context *ctx, int fd, source_dispatch_t dispatch, void *user_data) { struct source *source; struct epoll_event ep; assert(fd != -1); source = zalloc(sizeof *source); source->dispatch = dispatch; source->user_data = user_data; source->fd = fd; list_append(&ctx->sources, &source->link); memset(&ep, 0, sizeof ep); ep.events = EPOLLIN; ep.data.ptr = source; if (epoll_ctl(ctx->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) { free(source); return NULL; } return source; } static void destroy_source(struct record_context *ctx, struct source *source) { list_remove(&source->link); epoll_ctl(ctx->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL); close(source->fd); free(source); } static void signalfd_dispatch(struct record_context *ctx, int fd, void *data) { struct signalfd_siginfo fdsi; (void)read(fd, &fdsi, sizeof(fdsi)); ctx->stop = true; } static void timefd_dispatch(struct record_context *ctx, int fd, void *data) { char discard[64]; (void)read(fd, discard, sizeof(discard)); if (ctx->timestamps.had_events_since_last_time) { print_wall_time(ctx); ctx->timestamps.had_events_since_last_time = false; ctx->timestamps.skipped_timer_print = false; } else { ctx->timestamps.skipped_timer_print = true; } } static void evdev_dispatch(struct record_context *ctx, int fd, void *data) { struct record_device *this_device = data; if (ctx->timestamps.skipped_timer_print) { print_wall_time(ctx); ctx->timestamps.skipped_timer_print = false; } ctx->had_events = true; ctx->timestamps.had_events_since_last_time = true; handle_events(ctx, this_device); } static void libinput_ctx_dispatch(struct record_context *ctx, int fd, void *data) { /* This function should only handle events caused by internal * timeouts etc. The real input events caused by the evdev devices * are already processed in handle_events */ libinput_dispatch(ctx->libinput); handle_libinput_events(ctx, ctx->first_device, true); } static void hidraw_dispatch(struct record_context *ctx, int fd, void *data) { struct hidraw *hidraw = data; ctx->had_events = true; ctx->timestamps.had_events_since_last_time = true; handle_hidraw(hidraw); } static int dispatch_sources(struct record_context *ctx) { struct source *source; struct epoll_event ep[64]; int i, count; count = epoll_wait(ctx->epoll_fd, ep, ARRAY_LENGTH(ep), ctx->timeout); if (count < 0) return -errno; for (i = 0; i < count; ++i) { source = ep[i].data.ptr; if (source->fd == -1) continue; source->dispatch(ctx, source->fd, source->user_data); } return count; } static int mainloop(struct record_context *ctx) { bool autorestart = (ctx->timeout > 0); struct source *source; struct record_device *d = NULL; sigset_t mask; int sigfd, timerfd; assert(ctx->timeout != 0); assert(!list_empty(&ctx->devices)); ctx->epoll_fd = epoll_create1(0); assert(ctx->epoll_fd >= 0); sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGQUIT); sigprocmask(SIG_BLOCK, &mask, NULL); sigfd = signalfd(-1, &mask, SFD_NONBLOCK); add_source(ctx, sigfd, signalfd_dispatch, NULL); timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC|TFD_NONBLOCK); add_source(ctx, timerfd, timefd_dispatch, NULL); arm_timer(timerfd); list_for_each(d, &ctx->devices, link) { struct hidraw *hidraw; add_source(ctx, libevdev_get_fd(d->evdev), evdev_dispatch, d); list_for_each(hidraw, &d->hidraw_devices, link) { add_source(ctx, hidraw->fd, hidraw_dispatch, hidraw); } } if (ctx->libinput) { /* See the note in the dispatch function */ add_source(ctx, libinput_get_fd(ctx->libinput), libinput_ctx_dispatch, NULL); } /* If we have more than one device, the time starts at recording * start time. Otherwise, the first event starts the recording time. */ if (ctx->ndevices > 1) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); ctx->offset = s2us(ts.tv_sec) + ns2us(ts.tv_nsec); } do { struct record_device *d; if (!open_output_files(ctx, autorestart)) { fprintf(stderr, "Failed to open '%s'\n", ctx->output_file.name_with_suffix); break; } fprintf(stderr, "%sRecording to '%s'.\n", isatty(STDERR_FILENO) ? "" : "# ", ctx->output_file.name_with_suffix); ctx->had_events = false; print_header(ctx->first_device->fp, ctx); if (autorestart) iprintf(ctx->first_device->fp, I_NONE, "# Autorestart timeout: %d\n", ctx->timeout); iprintf(ctx->first_device->fp, I_TOPLEVEL, "devices:\n"); /* we only print the first device's description, the * rest is assembled after CTRL+C */ list_for_each(d, &ctx->devices, link) { print_device_description(d); iprintf(d->fp, I_DEVICE, "events:\n"); } print_wall_time(ctx); if (ctx->libinput) { libinput_dispatch(ctx->libinput); handle_libinput_events(ctx, ctx->first_device, true); } while (true) { int rc = dispatch_sources(ctx); if (rc < 0) { /* error */ fprintf(stderr, "Error: %s\n", strerror(-rc)); ctx->stop = true; break; } /* set by the signalfd handler */ if (ctx->stop) break; if (rc == 0) { fprintf(stderr, " ... timeout%s\n", ctx->had_events ? "" : " (file is empty)"); break; } if (ctx->first_device->fp != stdout) print_progress_bar(); } if (autorestart) { list_for_each(d, &ctx->devices, link) { iprintf(d->fp, I_NONE, "# Closing after %ds inactivity", ctx->timeout/1000); } } /* First device is printed, now append all the data from the * other devices, if any */ list_for_each(d, &ctx->devices, link) { char buf[4096]; size_t n; if (d == ctx->first_device) continue; rewind(d->fp); do { n = fread(buf, 1, sizeof(buf), d->fp); if (n > 0) fwrite(buf, 1, n, ctx->first_device->fp); } while (n == sizeof(buf)); fclose(d->fp); d->fp = NULL; } /* If we didn't have events, delete the file. */ if (!isatty(fileno(ctx->first_device->fp))) { struct record_device *d; if (!ctx->had_events && ctx->output_file.name_with_suffix) { fprintf(stderr, "No events recorded, deleting '%s'\n", ctx->output_file.name_with_suffix); unlink(ctx->output_file.name_with_suffix); } list_for_each(d, &ctx->devices, link) { if (d->fp && d->fp != stdout) { fclose(d->fp); d->fp = NULL; } } } free(ctx->output_file.name_with_suffix); ctx->output_file.name_with_suffix = NULL; } while (autorestart && !ctx->stop); sigprocmask(SIG_UNBLOCK, &mask, NULL); list_for_each_safe(source, &ctx->sources, link) { destroy_source(ctx, source); } close(ctx->epoll_fd); return 0; } static bool init_device(struct record_context *ctx, const char *path, bool grab) { struct record_device *d; int fd, rc; d = zalloc(sizeof(*d)); d->ctx = ctx; d->devnode = safe_strdup(path); list_init(&d->hidraw_devices); fd = open(d->devnode, O_RDONLY|O_NONBLOCK); if (fd < 0) { fprintf(stderr, "Failed to open device %s (%m)\n", d->devnode); goto error; } rc = libevdev_new_from_fd(fd, &d->evdev); if (rc == 0) rc = libevdev_new_from_fd(fd, &d->evdev_prev); if (rc != 0) { fprintf(stderr, "Failed to create context for %s (%s)\n", d->devnode, strerror(-rc)); goto error; } if (grab) { rc = libevdev_grab(d->evdev, LIBEVDEV_GRAB); if (rc != 0) { fprintf(stderr, "Grab failed on %s: %s\n", path, strerror(-rc)); goto error; } } libevdev_set_clock_id(d->evdev, CLOCK_MONOTONIC); if (libevdev_get_num_slots(d->evdev) > 0) d->touch.is_touch_device = true; list_append(&ctx->devices, &d->link); if (!ctx->first_device) ctx->first_device = d; ctx->ndevices++; return true; error: close(fd); free(d); return false; } static int open_restricted(const char *path, int flags, void *user_data) { int fd = open(path, flags); return fd == -1 ? -errno : fd; } static void close_restricted(int fd, void *user_data) { close(fd); } static const struct libinput_interface interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; static bool init_libinput(struct record_context *ctx) { struct record_device *dev; struct libinput *li; li = libinput_path_create_context(&interface, NULL); if (li == NULL) { fprintf(stderr, "Failed to create libinput context\n"); return false; } ctx->libinput = li; list_for_each(dev, &ctx->devices, link) { struct libinput_device *d; d = libinput_path_add_device(li, dev->devnode); if (!d) { fprintf(stderr, "Failed to add device %s\n", dev->devnode); continue; } dev->device = libinput_device_ref(d); /* FIXME: this needs to be a commandline option */ libinput_device_config_tap_set_enabled(d, LIBINPUT_CONFIG_TAP_ENABLED); } return true; } static bool init_hidraw(struct record_context *ctx) { struct record_device *dev; list_for_each(dev, &ctx->devices, link) { char syspath[PATH_MAX]; DIR *dir; struct dirent *entry; snprintf(syspath, sizeof(syspath), "/sys/class/input/%s/device/device/hidraw", safe_basename(dev->devnode)); dir = opendir(syspath); if (!dir) continue; while ((entry = readdir(dir))) { char hidraw_node[PATH_MAX]; int fd; struct hidraw *hidraw = NULL; if (!strstartswith(entry->d_name, "hidraw")) continue; snprintf(hidraw_node, sizeof(hidraw_node), "/dev/%s", entry->d_name); fd = open(hidraw_node, O_RDONLY|O_NONBLOCK); if (fd == -1) continue; hidraw = zalloc(sizeof(*hidraw)); hidraw->fd = fd; hidraw->name = safe_strdup(entry->d_name); hidraw->device = dev; list_insert(&dev->hidraw_devices, &hidraw->link); } closedir(dir); } return true; } static void usage(void) { printf("Usage: %s [--help] [--all] [--autorestart] [--output-file filename] [/dev/input/event0] [...]\n" "Common use-cases:\n" "\n" " sudo %s -o recording.yml\n" " Then select the device to record and it Ctrl+C to stop.\n" " The recorded data is in recording.yml and can be attached to a bug report.\n" "\n" " sudo %s -o recording.yml --autorestart 2\n" " As above, but restarts after 2s of inactivity on the device.\n" " Note, the output file is only the prefix.\n" "\n" " sudo %s -o recording.yml /dev/input/event3 /dev/input/event4\n" " Records the two devices into the same recordings file.\n" "\n" "For more information, see the %s(1) man page\n", program_invocation_short_name, program_invocation_short_name, program_invocation_short_name, program_invocation_short_name, program_invocation_short_name); } enum ftype { F_FILE = 8, F_DEVICE, F_NOEXIST, }; static enum ftype is_char_dev(const char *path) { struct stat st; if (strstartswith(path, "/dev")) return F_DEVICE; if (stat(path, &st) != 0) { if (errno == ENOENT) return F_NOEXIST; return F_FILE; } return S_ISCHR(st.st_mode) ? F_DEVICE : F_FILE; } enum fposition { ERROR, NO_FILE, FIRST, LAST, }; static enum fposition find_output_file(int argc, char *argv[], const char **output_file) { char *first, *last; enum ftype ftype_first, ftype_last; first = argv[0]; ftype_first = is_char_dev(first); if (argc == 1) { /* arg is *not* a char device, so let's assume it's * the output file */ if (ftype_first != F_DEVICE) { *output_file = first; return FIRST; } } /* multiple arguments, yay */ last = argv[argc - 1]; ftype_last = is_char_dev(last); /* first is device, last is file -> last first is device, last is device -> noop first is device, last !exist -> last first is file, last is device -> first first is file, last is file -> error first is file, last !exist -> error first !exist, last is device -> first first !exist, last is file -> error first !exit, last !exist -> error */ #define _m(f, l) (((f) << 8) | (l)) switch (_m(ftype_first, ftype_last)) { case _m(F_FILE, F_DEVICE): case _m(F_FILE, F_NOEXIST): case _m(F_NOEXIST, F_DEVICE): *output_file = first; return FIRST; case _m(F_DEVICE, F_FILE): case _m(F_DEVICE, F_NOEXIST): *output_file = last; return LAST; case _m(F_DEVICE, F_DEVICE): break; case _m(F_FILE, F_FILE): case _m(F_NOEXIST, F_FILE): case _m(F_NOEXIST, F_NOEXIST): return ERROR; } #undef _m return NO_FILE; } enum options { OPT_AUTORESTART, OPT_HELP, OPT_OUTFILE, OPT_KEYCODES, OPT_MULTIPLE, OPT_ALL, OPT_LIBINPUT, OPT_HIDRAW, OPT_GRAB, }; int main(int argc, char **argv) { struct record_context ctx = { .timeout = -1, .show_keycodes = false, }; struct option opts[] = { { "autorestart", required_argument, 0, OPT_AUTORESTART }, { "output-file", required_argument, 0, OPT_OUTFILE }, { "show-keycodes", no_argument, 0, OPT_KEYCODES }, { "multiple", no_argument, 0, OPT_MULTIPLE }, { "all", no_argument, 0, OPT_ALL }, { "help", no_argument, 0, OPT_HELP }, { "with-libinput", no_argument, 0, OPT_LIBINPUT }, { "with-hidraw", no_argument, 0, OPT_HIDRAW }, { "grab", no_argument, 0, OPT_GRAB }, { 0, 0, 0, 0 }, }; struct record_device *d; const char *output_arg = NULL; bool all = false, with_libinput = false, with_hidraw = false, grab = false; int ndevices; int rc = EXIT_FAILURE; char **paths = NULL; list_init(&ctx.devices); list_init(&ctx.sources); while (1) { int c; int option_index = 0; c = getopt_long(argc, argv, "ho:", opts, &option_index); if (c == -1) break; switch (c) { case 'h': case OPT_HELP: usage(); rc = EXIT_SUCCESS; goto out; case OPT_AUTORESTART: if (!safe_atoi(optarg, &ctx.timeout) || ctx.timeout <= 0) { usage(); rc = EXIT_INVALID_USAGE; goto out; } ctx.timeout = ctx.timeout * 1000; break; case 'o': case OPT_OUTFILE: output_arg = optarg; break; case OPT_KEYCODES: ctx.show_keycodes = true; break; case OPT_MULTIPLE: /* deprecated */ break; case OPT_ALL: all = true; break; case OPT_LIBINPUT: with_libinput = true; break; case OPT_HIDRAW: with_hidraw = true; fprintf(stderr, "# WARNING: do not type passwords while recording HID reports\n"); break; case OPT_GRAB: grab = true; break; default: usage(); rc = EXIT_INVALID_USAGE; goto out; } } ndevices = argc - optind; /* We allow for multiple arguments after the options, *one* of which * may be the output file. That one must be the first or the last to * prevent users from running * libinput record /dev/input/event0 output.yml /dev/input/event1 * because this will only backfire anyway. */ if (ndevices >= 1 && output_arg == NULL) { enum fposition pos = find_output_file(argc - optind, &argv[optind], &output_arg); if (pos == ERROR) { fprintf(stderr, "Ambiguous device vs output file list. " "Please use --output-file.\n"); return EXIT_INVALID_USAGE; } if (pos == FIRST || pos == LAST) ndevices--; if (pos == FIRST) optind++; } if (ctx.timeout > 0 && output_arg == NULL) { fprintf(stderr, "Option --autorestart requires --output-file\n"); rc = EXIT_INVALID_USAGE; goto out; } ctx.output_file.name = safe_strdup(output_arg); if (output_arg == NULL && (all || ndevices > 1)) { fprintf(stderr, "Recording multiple devices requires an output file\n"); rc = EXIT_INVALID_USAGE; goto out; } /* Now collect all device paths and init our device struct */ if (all) { paths = all_devices(); } else if (ndevices >= 1) { paths = strv_from_argv(ndevices, &argv[optind]); } else { char *path = select_device(); if (path == NULL) { goto out; } paths = strv_from_argv(1, &path); free(path); } for (char **p = paths; *p; p++) { if (!init_device(&ctx, *p, grab)) { goto out; } } if (with_libinput && !init_libinput(&ctx)) goto out; if (with_hidraw && !init_hidraw(&ctx)) goto out; rc = mainloop(&ctx); out: strv_free(paths); list_for_each_safe(d, &ctx.devices, link) { struct hidraw *hidraw; list_for_each_safe(hidraw, &d->hidraw_devices, link) { close(hidraw->fd); list_remove(&hidraw->link); free(hidraw->name); free(hidraw); } if (d->device) libinput_device_unref(d->device); free(d->devnode); libevdev_free(d->evdev); } libinput_unref(ctx.libinput); return rc; } libinput-1.28.1/tools/libinput-record.man000066400000000000000000000264531477265155700204250ustar00rootroot00000000000000.TH libinput-record "1" .SH NAME libinput\-record \- record kernel events .SH SYNOPSIS .B libinput record [options] [\fI/dev/input/event0\fB [\fI/dev/input/event1\fB ...]] .SH DESCRIPTION .PP The \fBlibinput record\fR tool records kernel events from a device and prints them in a format that can later be replayed with the \fBlibinput replay(1)\fR tool. This tool needs to run as root to read from the device. .PP The output of this tool is YAML, see \fBFILE FORMAT\fR for more details. By default it prints to stdout unless an output file is provided. For example, these are valid invocations: .B libinput record /dev/input/event3 touchpad.yml .B libinput record recording.yml .B libinput record --all all-devices.yml .B libinput record /dev/input/event3 /dev/input/event4 tp-and-keyboard.yml .PP The events recorded are independent of libinput itself, updating or removing libinput will not change the event stream. .SH OPTIONS If one or more device nodes are given, this tool opens those device nodes. Otherwise, a list of devices is presented and the user can select the device to record. If unsure, run without any arguments. .TP 8 .B \-\-help Print help .TP 8 .B \-\-all Record all \fI/dev/input/event*\fR devices available on the system. This option should be used in exceptional cases only, the output file is almost always too noisy and replaying the recording may not be possible. This option requires \fB\-\-output-file\fR and no device nodes may be provided on the commandline. .TP 8 .B \-\-autorestart=s Terminate the current recording after .I s seconds of device inactivity. This option requires that a \fB\-\-output-file\fR is specified. The output filename is used as prefix, suffixed with the date and time of the recording. The timeout must be greater than 0. .TP 8 .B \-o filename.yml .PD 0 .TP 8 .B \-\-output-file=filename.yml .PD 1 Specifies the output file to use. If \fB\-\-autorestart\fR is given, the filename is used as prefix only. Where \-\-output-file is not given and the first \fBor\fR last argument is not an input device, the first \fBor\fR last argument will be the output file. .TP 8 .B \-\-grab Exclusively grab all opened devices. This will prevent events from being delivered to the host system. .TP 8 .B \-\-show\-keycodes Show keycodes as-is in the recording. By default, common keys are obfuscated and printed as \fBKEY_A\fR to avoid information leaks. .TP 8 .B \-\-with-libinput Record libinput events alongside device events. .B THIS FEATURE IS EXPERIMENTAL. See section .B RECORDING LIBINPUT EVENTS for more details. .TP 8 .B \-\-with-hidraw Record hidraw events alongside device events. .B DO NOT TYPE SENSITIVE DATA. See .B RECORDING HID REPORTS for more details. .SH RECORDING MULTIPLE DEVICES Sometimes it is necessary to record the events from multiple devices simultaneously, e.g. when an interaction between a touchpad and a keyboard causes a bug. \fBlibinput record\fR records multiple devices with an identical time offset, allowing for correct replay of the interaction. .PP If multiple devices are recorded, an output filename must be provided. .PP All devices to be recorded must be provided on the commandline, an example invocation is: .B libinput record \-o tap-bug /dev/input/event3 /dev/input/event7 Note that when recording multiple devices, only the first device is printed immediately, all other devices and their events are printed on exit. .SH RECORDING LIBINPUT EVENTS When the \fB\-\-with-libinput\fR commandline option is given, \fBlibinput\-record\fR initializes a libinput context for the devices being recorded. Events from these contexts are printed alongside the evdev events. .B THIS FEATURE IS EXPERIMENTAL. .PP The primary purpose of this feature is debugging and event analysis, no caller may rely on any specific format of the events. .PP Note that while libinput and \fBlibinput\-record\fR see the same events from the device nodes, no guarantee can be given about the correct order of events. libinput events may come in earlier or later than the events from the device nodes and for some devices, libinput may internally alter the event stream before processing. .PP Note that the libinput context created by \fBlibinput\-record\fR does not affect the running desktop session and does not (can not!) copy any configuration options from that session. .SH RECORDING HID REPORTS When the \fB\-\-with-hidraw\fR commandline option is given, \fBlibinput\-record\fR searches for the hidraw node(s) of the given devices and prints any incoming HID reports from those devices. .PP HID reports are \fBnot obfuscated\fR and a sufficiently motivated person could recover the key strokes from the logs. Do not type passwords while recording HID reports. .SH FILE FORMAT The output file format is in YAML and intended to be both human-readable and machine-parseable. Below is a short example YAML file, all keys are detailed further below. .PP Any parsers must ignore keys not specified in the file format description. The version number field is only used for backwards-incompatible changes. .PP .nf .sp version: 1 ndevices: 2 libinput: version: 1.10.0 system: os: "fedora:26" kernel: "4.13.9-200.fc26.x86_64" dmi: "dmi:bvnLENOVO:bvrGJET72WW(2.22):bd02/21/2014:svnLENOVO:..." devices: - node: /dev/input/event9 evdev: # Name: Synaptics TM2668-002 # ID: bus 0x1d vendor 0x6cb product 00 version 00 # Size in mm: 97x68 # Supported Events: # Event type 0 (EV_SYN) #.. abbreviated for man page ... # name: Synaptics TM2668-002 id: [29, 1739, 0, 0] codes: 0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] # EV_SYN 1: [272, 325, 328, 330, 333, 334, 335] # EV_KEY 3: [0, 1, 24, 47, 48, 49, 52, 53, 54, 55, 57, 58] # EV_ABS absinfo: 0: [0, 4089, 0, 0, 42] 1: [0, 2811, 0, 0, 41] 24: [0, 255, 0, 0, 0] 47: [0, 4, 0, 0, 0] 48: [0, 15, 0, 0, 0] 49: [0, 15, 0, 0, 0] 52: [0, 1, 0, 0, 0] 53: [0, 4089, 0, 0, 42] 54: [0, 2811, 0, 0, 41] 55: [0, 2, 0, 0, 0] 57: [0, 65535, 0, 0, 0] 58: [0, 255, 0, 0, 0] properties: [0, 2, 4] hid: [12, 23, 34, 45, ...] udev: properties: - ID_INPUT_MOUSE=1 - ID_INPUT=1 quirks: - ModelAppleTouchpad=1 - AttrSizeHint=32x32 events: - hid: time: [ 0, 0] hidraw0: [1, 2, 3, 4] - evdev: - [ 0, 0, 3, 57, 1420] # EV_ABS / ABS_MT_TRACKING_ID 1420 - [ 0, 0, 3, 53, 1218] # EV_ABS / ABS_MT_POSITION_X 1218 - [ 0, 0, 3, 54, 1922] # EV_ABS / ABS_MT_POSITION_Y 1922 - [ 0, 0, 3, 52, 0] # EV_ABS / ABS_MT_ORIENTATION 0 - [ 0, 0, 3, 58, 47] # EV_ABS / ABS_MT_PRESSURE 47 - [ 0, 0, 1, 330, 1] # EV_KEY / BTN_TOUCH 1 - [ 0, 0, 1, 325, 1] # EV_KEY / BTN_TOOL_FINGER 1 - [ 0, 0, 3, 0, 1218] # EV_ABS / ABS_X 1218 - [ 0, 0, 3, 1, 1922] # EV_ABS / ABS_Y 1922 - [ 0, 0, 3, 24, 47] # EV_ABS / ABS_PRESSURE 47 - [ 0, 0, 0, 0, 0] # ------------ SYN_REPORT (0) ------- +0ms - evdev: - [ 0, 11879, 3, 53, 1330] # EV_ABS / ABS_MT_POSITION_X 1330 - [ 0, 11879, 3, 54, 1928] # EV_ABS / ABS_MT_POSITION_Y 1928 - [ 0, 11879, 3, 58, 46] # EV_ABS / ABS_MT_PRESSURE 46 - [ 0, 11879, 3, 0, 1330] # EV_ABS / ABS_X 1330 - [ 0, 11879, 3, 1, 1928] # EV_ABS / ABS_Y 1928 - [ 0, 11879, 3, 24, 46] # EV_ABS / ABS_PRESSURE 46 - [ 0, 11879, 0, 0, 0] # ------------ SYN_REPORT (0) ------- +0ms # second device (if any) - node: /dev/input/event9 evdev: ... .PP .fi .in Top-level keys are listed below, see the respective subsection for details on each key. .PP .TP 8 .B version: int The file format version. This version is only increased for backwards-incompatible changes. A parser must ignore unknown keys to be forwards-compatible. .TP 8 .B ndevices: int The number of device recordings in this file. Always 1 unless recorded with .B --multiple .TP 8 .B libinput: {...} A dictionary with libinput-specific information. .TP 8 .B system: {...} A dictionary with system information. .TP 8 .B devices: {...} A list of devices containing the description and and events of each device. .SS libinput .TP 8 .B version: string libinput version .SS system Information about the system .TP 8 .B os: string Distribution ID and version, see \fIos-release(5)\fR .TP 8 .B kernel: string Kernel version, see \fIuname(1)\fR .TP 8 .B dmi: string DMI modalias, see \fI/sys/class/dmi/id/modalias\fR .SS devices Information about and events from the recorded device nodes .TP 8 .B node: string the device node recorded .TP 8 .B evdev A dictionary with the evdev device information. .TP 8 .B hid A list of integers representing the HID report descriptor bytes. .TP 8 .B udev A dictionary with the udev device information. .TP 8 .B events A list of dictionaries with the recorded events .SS evdev .TP 8 .B name: string The device name .TP 8 .B id: [bustype, vendor, product, version] The data from the \fBstruct input_id\fR, bustype, vendor, product, version. .TP 8 .B codes: {type: [a, b, c ], ...} All evdev types and codes as nested dictionary. The evdev type is the key, the codes are a list. .TP 8 .B absinfo: {code: [min, max, fuzz, flat, resolution], ...} An array of arrays with 6 decimal elements each, denoting the contents of a \fBstruct input_absinfo\fR. The first element is the code (e.g. \fBABS_X\fR) in decimal format. .TP 8 .B properties: [0, 1, ...] Array with all \fBINPUT_PROP_FOO\fR constants. May be an empty array. .SS udev .TP 8 .B properties: list of strings A list of udev properties in the \fBkey=value\fR format. This is not the complete list of properties assigned to the device but a subset that is relevant to libinput. These properties may include properties set on a parent device. .TP 8 .B quirks: list of strings A list of device quirks the \fBkey=value\fR format. .SS events A list of the recorded events. The list contains dictionaries Information about the events. The content is a list of dictionaries, with the string identifying the type of event sequence. .TP 8 .B { evdev: [ [sec, usec, type, code, value], ...] } Each \fBevdev\fR dictionary contains the contents of a \fBstruct input_event\fR in decimal format. The last item in the list is always the \fBSYN_REPORT\fR of this event frame. The next event frame starts a new \fBevdev\fR dictionary entry in the parent \fBevents\fR list. .TP 8 .B { hid: "hidrawX": [ 12, 34, 56 ], ...] } The \fBhid\fR dictionary contains the hid reports in decimal format, with the hidraw node as key. The special key \fBtime\fR denotes the current time when the report was read from the kernel. .PP Note that the kernel does not provide timestamps for hidraw events and the timestamps provided are from \fBclock_gettime(3)\fR. They may be greater than a subsequent evdev event's timestamp. .SH NOTES .PP This tool records events from the kernel and is independent of libinput. In other words, updating or otherwise changing libinput will not alter the output from this tool. libinput itself does not need to be in use to record events. .SH LIBINPUT .PP Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-replay.man000066400000000000000000000021551477265155700204340ustar00rootroot00000000000000.TH libinput-replay "1" .SH NAME libinput\-replay \- replay kernel events from a recording .SH SYNOPSIS .B libinput replay [options] \fIrecording\fB .SH DESCRIPTION .PP The \fBlibinput replay\fR tool replays kernel events from a device recording made by the \fBlibinput record(1)\fR tool. This tool needs to run as root to create a device and/or replay events. .PP If the recording contains more than one device, all devices are replayed simultaneously. .SH OPTIONS .TP 8 .B \-\-help Print help .TP 8 .B \-\-once Only replay the recording once, then exit. .TP 8 .B \-\-replay-after=s Replay the recording after waiting for s seconds. This replaces the default interactive prompt to start the replay. .SH NOTES .PP This tool replays events from a recording through the the kernel and is independent of libinput. In other words, updating or otherwise changing libinput will not alter the output from this tool. libinput itself does not need to be in use to replay events. .PP This tool does not replay kernel-emulated key repeat events (events of type \fIEV_KEY\fR with a value of 2). .SH LIBINPUT .PP Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-replay.py000077500000000000000000000301531477265155700203130ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import os import sys import time import math import multiprocessing import argparse from pathlib import Path try: import libevdev import yaml import pyudev except ModuleNotFoundError as e: print("Error: {}".format(e), file=sys.stderr) print( "One or more python modules are missing. Please install those " "modules and re-run this tool." ) sys.exit(1) SUPPORTED_FILE_VERSION = 1 def error(msg, **kwargs): print(msg, **kwargs, file=sys.stderr) class YamlException(Exception): pass def fetch(yaml, key): """Helper function to avoid confusing a YAML error with a normal KeyError bug""" try: return yaml[key] except KeyError: raise YamlException("Failed to get '{}' from recording.".format(key)) def check_udev_properties(yaml_data, uinput): """ Compare the properties our new uinput device has with the ones from the recording and ring the alarm bell if one of them is off. """ yaml_udev_section = fetch(yaml_data, "udev") yaml_udev_props = fetch(yaml_udev_section, "properties") ignore = ["LIBINPUT_DEVICE_GROUP", "DRIVER"] yaml_props = { k: v for (k, v) in [prop.split("=", maxsplit=1) for prop in yaml_udev_props] if k not in ignore } # give udev some time to catch up time.sleep(0.2) context = pyudev.Context() udev_device = pyudev.Devices.from_device_file(context, uinput.devnode) for name, value in udev_device.properties.items(): if name in yaml_props: if yaml_props[name] != value: error( f"Warning: udev property mismatch: recording has {name}={yaml_props[name]}, device has {name}={value}" ) del yaml_props[name] else: # The list of properties we add to the recording, see libinput-record.c prefixes = ( "ID_INPUT", "LIBINPUT", "EVDEV_ABS", "MOUSE_DPI", "POINTINGSTICK_", ) for prefix in prefixes: if name.startswith(prefix): error(f"Warning: unexpected property: {name}={value}") # the ones we found above were removed from the dict for name, value in yaml_props.items(): error(f"Warning: device is missing recorded udev property: {name}={value}") def create(device): evdev = fetch(device, "evdev") d = libevdev.Device() d.name = fetch(evdev, "name") ids = fetch(evdev, "id") if len(ids) != 4: raise YamlException("Invalid ID format: {}".format(ids)) d.id = dict(zip(["bustype", "vendor", "product", "version"], ids)) codes = fetch(evdev, "codes") for evtype, evcodes in codes.items(): for code in evcodes: data = None if evtype == libevdev.EV_ABS.value: values = fetch(evdev, "absinfo")[code] absinfo = libevdev.InputAbsInfo( minimum=values[0], maximum=values[1], fuzz=values[2], flat=values[3], resolution=values[4], ) data = absinfo elif evtype == libevdev.EV_REP.value: if code == libevdev.EV_REP.REP_DELAY.value: data = 500 elif code == libevdev.EV_REP.REP_PERIOD.value: data = 20 d.enable(libevdev.evbit(evtype, code), data=data) properties = fetch(evdev, "properties") for prop in properties: d.enable(libevdev.propbit(prop)) uinput = d.create_uinput_device() check_udev_properties(device, uinput) return uinput def print_events(devnode, indent, evs): devnode = os.path.basename(devnode) for e in evs: print( "{}: {}{:06d}.{:06d} {} / {:<20s} {:4d}".format( devnode, " " * (indent * 8), e.sec, e.usec, e.type.name, e.code.name, e.value, ) ) if e.type == libevdev.EV_SYN: print( "{}: ------------------------------------------------".format(devnode) ) def collect_events(frame): evs = [] events_skipped = False for sec, usec, evtype, evcode, value in frame: if evtype == libevdev.EV_KEY.value and value == 2: # key repeat events_skipped = True continue e = libevdev.InputEvent( libevdev.evbit(evtype, evcode), value=value, sec=sec, usec=usec ) evs.append(e) # If we skipped some events and now all we have left is the # SYN_REPORTs, we drop the SYN_REPORTs as well. if events_skipped and all(e for e in evs if e.matches(libevdev.EV_SYN.SYN_REPORT)): return [] else: return evs def replay(device, verbose): events = fetch(device, "events") if events is None: return uinput = device["__uinput"] # The first event may have a nonzero offset but we want to replay # immediately regardless. When replaying multiple devices, the first # offset is the offset from the first event on any device. offset = time.time() - device["__first_event_offset"] if offset < 0: error("WARNING: event time offset is in the future, refusing to replay") return # each 'evdev' set contains one SYN_REPORT so we only need to check for # the time offset once per event for event in events: try: evdev = fetch(event, "evdev") except YamlException: continue evs = collect_events(evdev) if not evs: continue evtime = evs[0].sec + evs[0].usec / 1e6 + offset now = time.time() if evtime - now > 150 / 1e6: # 150 µs error margin time.sleep(evtime - now - 150 / 1e6) uinput.send_events(evs) if verbose: print_events(uinput.devnode, device["__index"], evs) def first_timestamp(device): events = fetch(device, "events") for e in events or []: try: evdev = fetch(e, "evdev") (sec, usec, *_) = evdev[0] return sec + usec / 1.0e6 except YamlException: pass return None def wrap(func, *args): try: func(*args) except KeyboardInterrupt: pass def loop(args, recording): devices = fetch(recording, "devices") first_timestamps = tuple( filter(lambda x: x is not None, [first_timestamp(d) for d in devices]) ) # All devices need to start replaying at the same time, so let's find # the very first event and offset everything by that timestamp. toffset = min(first_timestamps or [math.inf]) for idx, d in enumerate(devices): uinput = create(d) print("{}: {}".format(uinput.devnode, uinput.name)) d["__uinput"] = uinput # cheaper to hide it in the dict then work around it d["__index"] = idx d["__first_event_offset"] = toffset if not first_timestamps: input("No events in recording. Hit enter to quit") return while True: if args.replay_after >= 0: time.sleep(args.replay_after) else: input("Hit enter to start replaying") try: processes = [ multiprocessing.Process(target=wrap, args=(replay, d, args.verbose)) for d in devices ] for p in processes: p.start() for p in processes: p.join() if args.once: break except KeyboardInterrupt: print("Event replay interrupted, press Ctrl+C again to exit.") print("Note that the device may not be in a neutral state now.") def create_device_quirk(device): try: quirks = fetch(device, "quirks") if not quirks: return None except YamlException: return None # Where the device has a quirk, we match on name, vendor and product. # That's the best match we can assemble here from the info we have. evdev = fetch(device, "evdev") name = fetch(evdev, "name") id = fetch(evdev, "id") quirk = ( "[libinput-replay {name}]\n" "MatchName={name}\n" "MatchVendor=0x{id[1]:04X}\n" "MatchProduct=0x{id[2]:04X}\n" ).format(name=name, id=id) quirk += "\n".join(quirks) return quirk def setup_quirks(recording): devices = fetch(recording, "devices") overrides = None quirks = [] for d in devices: if "quirks" in d: quirk = create_device_quirk(d) if quirk: quirks.append(quirk) if not quirks: return None overrides = Path("/etc/libinput/local-overrides.quirks") if overrides.exists(): print( "{} exists, please move it out of the way first".format(overrides), file=sys.stderr, ) sys.exit(1) overrides.parent.mkdir(exist_ok=True) with overrides.open("w+") as fd: fd.write("# This file was generated by libinput replay\n") fd.write("# Unless libinput replay is running right now, remove this file.\n") fd.write("\n\n".join(quirks)) return overrides def check_file(recording): version = fetch(recording, "version") if version != SUPPORTED_FILE_VERSION: raise YamlException( "Invalid file format: {}, expected {}".format( version, SUPPORTED_FILE_VERSION ) ) ndevices = fetch(recording, "ndevices") devices = fetch(recording, "devices") if ndevices != len(devices): error( "WARNING: truncated file, expected {} devices, got {}".format( ndevices, len(devices) ) ) def main(): parser = argparse.ArgumentParser(description="Replay a device recording") parser.add_argument( "recording", metavar="recorded-file.yaml", type=str, help="Path to device recording", ) parser.add_argument( "--replay-after", type=int, default=-1, help="Automatically replay once after N seconds", ) parser.add_argument( "--once", action="store_true", default=False, help="Stop and exit after one replay", ) parser.add_argument("--verbose", action="store_true") args = parser.parse_args() quirks_file = None try: with open(args.recording) as f: y = yaml.safe_load(f) check_file(y) quirks_file = setup_quirks(y) loop(args, y) except KeyboardInterrupt: pass except (PermissionError, OSError) as e: error("Error: failed to open device: {}".format(e)) except YamlException as e: error("Error: failed to parse recording: {}".format(e)) finally: if quirks_file: quirks_file.unlink() if __name__ == "__main__": main() libinput-1.28.1/tools/libinput-test.c000066400000000000000000000036411477265155700175670ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include "shared.h" static inline void usage(void) { #if HAVE_INSTALLED_TESTS printf("Usage: libinput test [--help] \n"); #else fprintf(stderr, "libinput test was disabled in the build configuration\n"); #endif } int main(int argc, char **argv) { int option_index = 0; while (1) { int c; static struct option opts[] = { { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "+h", opts, &option_index); if (c == -1) break; switch(c) { case 'h': usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } if (optind >= argc) { usage(); return EXIT_FAILURE; } argc--; argv++; return tools_exec_command("libinput-test", argc, argv); } libinput-1.28.1/tools/libinput-test.man000066400000000000000000000017511477265155700201200ustar00rootroot00000000000000 .TH libinput-test "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput\-test \- test various components of libinput itself .SH SYNOPSIS .B libinput test [\-\-help] \fI []\fR .SH DESCRIPTION .PP The .B "libinput test" tool runs tests against libinput itself. There is usually no need for a user to use this tool, it is provided for distribution vendors. @HAVE_INSTALLED_TESTS@.B This tool was disabled at build time! .PP This is a testing tool only, its output may change at any time. Do not rely on the output. .PP This tool may need to be run as root to have access to the /dev/input/eventX nodes and/or create /dev/uinput devices. .SH OPTIONS .TP 8 .B \-\-help Print help .SH FEATURES Tests that can be run are .TP 8 .B libinput\-test\-suite(1) Run the full test suite. This is the most complete set of tests to run in libinput. .TP 8 .B libinput\-test\-utils Run the test suite suite for internal utility functions. .SH LIBINPUT Part of the .B libinput(1) suite libinput-1.28.1/tools/libinput-tool.c000066400000000000000000000060201477265155700175570ustar00rootroot00000000000000/* * Copyright © 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include "shared.h" static void usage(void) { printf("Usage: libinput [--help|--version] []\n" "\n" "Global options:\n" " --help ...... show this help and exit\n" " --version ... show version information and exit\n" "\n" "Commands:\n" " list-devices\n" " List all devices with their default configuration options\n" "\n" " debug-events\n" " Print events to stdout\n" "\n" #if HAVE_DEBUG_GUI " debug-gui\n" " Display a simple GUI to visualize libinput's events.\n" "\n" #endif " measure \n" " Measure various device properties. See the man page for more info\n" "\n" " analyze \n" " Analyze device events. See the man page for more info\n" "\n" " record\n" " Record event stream from a device node. See the man page for more info\n" "\n" " replay\n" " Replay a previously recorded event stream. See the man page for more info\n" "\n"); } enum global_opts { GOPT_HELP = 1, GOPT_VERSION, }; int main(int argc, char **argv) { int option_index = 0; while (1) { int c; static struct option opts[] = { { "help", no_argument, 0, GOPT_HELP }, { "version", no_argument, 0, GOPT_VERSION }, { 0, 0, 0, 0} }; c = getopt_long(argc, argv, "+h", opts, &option_index); if (c == -1) break; switch(c) { case 'h': case GOPT_HELP: usage(); return EXIT_SUCCESS; case GOPT_VERSION: printf("%s\n", LIBINPUT_VERSION); return EXIT_SUCCESS; default: usage(); return EXIT_INVALID_USAGE; } } if (optind >= argc) { usage(); return EXIT_INVALID_USAGE; } argv += optind; argc -= optind; return tools_exec_command("libinput", argc, argv); } libinput-1.28.1/tools/libinput.man000066400000000000000000000036531477265155700171460ustar00rootroot00000000000000.TH libinput "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" .SH NAME libinput \- tool to interface with libinput .SH SYNOPSIS .B libinput [\-\-help|\-\-version] \fI\fR \fI[]\fR .SH DESCRIPTION .PP libinput is a library to handle input devices and provides device detection and input device event processing for most Wayland compositors and the X.Org xf86-input-libinput driver. .PP The .B "libinput" tools are a set of tools to debug, interface with and analyze data for libinput. These tools create libinput contexts separate from that of the compositor/X server and cannot change settings in a running session. See section .B COMMANDS for a list of available commands. .PP libinput's API documentation and details on features and various high-level concepts are available online at .I https://wayland.freedesktop.org/libinput/doc/latest/ .PP The man page for the X.Org xf86-input-libinput driver is .B libinput(4). .SH OPTIONS .TP 8 .B \-\-help Print help and exit .TP 8 .B \-\-version Print the version and exit .SH COMMANDS .TP 8 .B libinput\-debug\-events(1) Print all events as seen by libinput @HAVE_DEBUG_GUI@.TP 8 @HAVE_DEBUG_GUI@.B libinput\-debug\-gui(1) @HAVE_DEBUG_GUI@Show a GUI to visualize libinput's events .TP 8 .B libinput\-debug\-tablet(1) A commandline tool to debug tablet axis values .TP 8 .B libinput\-list\-devices(1) List all devices recognized by libinput .TP 8 .B libinput\-list\-kernel-devices(1) List all kernel devices available on this system .TP 8 .B libinput\-measure(1) Measure various properties of devices .TP 8 .B libinput\-record(1) Record the events from a device .TP 8 .B libinput\-replay(1) Replay the events from a device .TP 8 .B libinput\-analyze(1) Analyze events from a device .TP 8 .B libinput\-test(1) Test libinput itself. .SH LIBINPUT Part of the .B libinput(1) suite .PP .SH SEE ALSO libinput(4) .PP libinput's online documentation .I https://wayland.freedesktop.org/libinput/doc/latest/ libinput-1.28.1/tools/make-ptraccel-graphs.sh000077500000000000000000000040211477265155700211420ustar00rootroot00000000000000#!/bin/bash tool=`dirname $0`/../build/ptraccel-debug gnuplot=/usr/bin/gnuplot if [[ -e '$tool' ]]; then echo "Unable to find $tool" exit 1 fi speeds="-1 -0.75 -0.5 -0.25 0 0.5 1" outfile="ptraccel-linear" for speed in $speeds; do $tool --mode=accel --dpi=1000 --filter=linear --speed=$speed > $outfile-$speed.gnuplot done $gnuplot < $outfile-$dpi.gnuplot done $gnuplot < $outfile-$speed.gnuplot done $gnuplot < $outfile-$speed.gnuplot done $gnuplot < #include #include #include #include #include #include #include #include "filter.h" #include "libinput-util.h" static void print_ptraccel_deltas(struct motion_filter *filter, double step) { struct device_float_coords motion; struct normalized_coords accel; uint64_t time = 0; double i; printf("# gnuplot:\n"); printf("# set xlabel dx unaccelerated\n"); printf("# set ylabel dx accelerated\n"); printf("# set style data lines\n"); printf("# plot \"gnuplot.data\" using 1:2 title \"step %.2f\"\n", step); printf("#\n"); /* Accel flattens out after 15 and becomes linear */ for (i = 0.0; i < 15.0; i += step) { motion.x = i; motion.y = 0; time += us(12500); /* pretend 80Hz data */ accel = filter_dispatch(filter, &motion, NULL, time); printf("%.2f %.3f\n", i, accel.x); } } static void print_ptraccel_movement(struct motion_filter *filter, int nevents, double max_dx, double step) { struct device_float_coords motion; struct normalized_coords accel; uint64_t time = 0; double dx; int i; printf("# gnuplot:\n"); printf("# set xlabel \"event number\"\n"); printf("# set ylabel \"delta motion\"\n"); printf("# set style data lines\n"); printf("# plot \"gnuplot.data\" using 1:2 title \"dx out\", \\\n"); printf("# \"gnuplot.data\" using 1:3 title \"dx in\"\n"); printf("#\n"); if (nevents == 0) { if (step > 1.0) nevents = max_dx; else nevents = 1.0 * max_dx/step + 0.5; /* Print more events than needed so we see the curve * flattening out */ nevents *= 1.5; } dx = 0; for (i = 0; i < nevents; i++) { motion.x = dx; motion.y = 0; time += us(12500); /* pretend 80Hz data */ accel = filter_dispatch(filter, &motion, NULL, time); printf("%d %.3f %.3f\n", i, accel.x, dx); if (dx < max_dx) dx += step; } } static void print_ptraccel_sequence(struct motion_filter *filter, int nevents, double *deltas) { struct device_float_coords motion; struct normalized_coords accel; uint64_t time = 0; double *dx; int i; printf("# gnuplot:\n"); printf("# set xlabel \"event number\"\n"); printf("# set ylabel \"delta motion\"\n"); printf("# set style data lines\n"); printf("# plot \"gnuplot.data\" using 1:2 title \"dx out\", \\\n"); printf("# \"gnuplot.data\" using 1:3 title \"dx in\"\n"); printf("#\n"); dx = deltas; for (i = 0; i < nevents; i++, dx++) { motion.x = *dx; motion.y = 0; time += us(12500); /* pretend 80Hz data */ accel = filter_dispatch(filter, &motion, NULL, time); printf("%d %.3f %.3f\n", i, accel.x, *dx); } } /* mm/s → units/µs */ static inline double mmps_to_upus(double mmps, int dpi) { return mmps * (dpi/25.4) / 1e6; } static void print_accel_func(struct motion_filter *filter, accel_profile_func_t profile, int dpi) { double mmps; printf("# gnuplot:\n"); printf("# set xlabel \"speed (mm/s)\"\n"); printf("# set ylabel \"raw accel factor\"\n"); printf("# set style data lines\n"); printf("# plot \"gnuplot.data\" using 1:2 title 'accel factor'\n"); printf("#\n"); printf("# data: velocity(mm/s) factor velocity(units/us) velocity(units/ms)\n"); for (mmps = 0.0; mmps < 1000.0; mmps += 1) { double units_per_us = mmps_to_upus(mmps, dpi); double units_per_ms = units_per_us * 1000.0; double result = profile(filter, NULL, units_per_us, 0 /* time */); printf("%.8f\t%.4f\t%.8f\t%.8f\n", mmps, result, units_per_us, units_per_ms); } } static void usage(void) { printf("Usage: %s [options] [dx1] [dx2] [...] > gnuplot.data\n", program_invocation_short_name); printf("\n" "Options:\n" "--mode= \n" " accel ... print accel factor (default)\n" " motion ... print motion to accelerated motion\n" " delta ... print delta to accelerated delta\n" " sequence ... print motion for custom delta sequence\n" "--maxdx= ... in motion mode only. Stop increasing dx at maxdx\n" "--steps= ... in motion and delta modes only. Increase dx by step each round\n" "--speed= ... accel speed [-1, 1], default 0\n" "--dpi= ... device resolution in DPI (default: 1000)\n" "--filter= \n" " linear ... the default motion filter\n" " low-dpi ... low-dpi filter, use --dpi with this argument\n" " touchpad ... the touchpad motion filter\n" " x230 ... custom filter for the Lenovo x230 touchpad\n" " trackpoint... trackpoint motion filter\n" " custom ... custom motion filter, use --custom-points and --custom-step with this argument\n" "--custom-points=\";...;\" ... n points defining a custom acceleration function\n" "--custom-step= ... distance along the x-axis between each point, \n" " starting from 0. defaults to 1.0\n" "\n" "If extra arguments are present and mode is not given, mode defaults to 'sequence'\n" "and the arguments are interpreted as sequence of delta x coordinates\n" "\n" "If stdin is a pipe, mode defaults to 'sequence' and the pipe is read \n" "for delta coordinates\n" "\n" "Delta coordinates passed into this tool must be in dpi as\n" "specified by the --dpi argument\n" "\n" "Output best viewed with gnuplot. See output for gnuplot commands\n"); } enum mode { ACCEL, MOTION, DELTA, SEQUENCE, }; int main(int argc, char **argv) { struct motion_filter *filter; double step = 0.1, max_dx = 10; int nevents = 0; enum mode mode = ACCEL; double custom_deltas[1024]; double speed = 0.0; int dpi = 1000; bool use_averaging = false; const char *filter_type = "linear"; accel_profile_func_t profile = NULL; double tp_multiplier = 1.0; struct libinput_config_accel_custom_func custom_func = { .step = 1.0, .npoints = 2, .points = {0.0, 1.0}, }; struct libinput_config_accel *accel_config = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); enum { OPT_HELP = 1, OPT_MODE, OPT_NEVENTS, OPT_MAXDX, OPT_STEP, OPT_SPEED, OPT_DPI, OPT_FILTER, OPT_CUSTOM_POINTS, OPT_CUSTOM_STEP, }; while (1) { int c; int option_index = 0; static struct option long_options[] = { {"help", 0, 0, OPT_HELP }, {"mode", 1, 0, OPT_MODE }, {"nevents", 1, 0, OPT_NEVENTS }, {"maxdx", 1, 0, OPT_MAXDX }, {"step", 1, 0, OPT_STEP }, {"speed", 1, 0, OPT_SPEED }, {"dpi", 1, 0, OPT_DPI }, {"filter", 1, 0, OPT_FILTER }, {"custom-points", 1, 0, OPT_CUSTOM_POINTS }, {"custom-step", 1, 0, OPT_CUSTOM_STEP }, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "", long_options, &option_index); if (c == -1) break; switch (c) { case OPT_HELP: usage(); exit(0); break; case OPT_MODE: if (streq(optarg, "accel")) mode = ACCEL; else if (streq(optarg, "motion")) mode = MOTION; else if (streq(optarg, "delta")) mode = DELTA; else if (streq(optarg, "sequence")) mode = SEQUENCE; else { usage(); return 1; } break; case OPT_NEVENTS: nevents = atoi(optarg); if (nevents == 0) { usage(); return 1; } break; case OPT_MAXDX: max_dx = strtod(optarg, NULL); if (max_dx == 0.0) { usage(); return 1; } break; case OPT_STEP: step = strtod(optarg, NULL); if (step == 0.0) { usage(); return 1; } break; case OPT_SPEED: speed = strtod(optarg, NULL); break; case OPT_DPI: dpi = strtod(optarg, NULL); break; case OPT_FILTER: filter_type = optarg; break; case OPT_CUSTOM_POINTS: { size_t npoints; double *points = double_array_from_string(optarg, ";", &npoints); if (!points || npoints < LIBINPUT_ACCEL_NPOINTS_MIN || npoints > LIBINPUT_ACCEL_NPOINTS_MAX) { fprintf(stderr, "Invalid --custom-points\n" "Please provide at least 2 points separated by a semicolon\n" " e.g. --custom-points=\"1.0;1.5\"\n"); free(points); return 1; } custom_func.npoints = npoints; memcpy(custom_func.points, points, sizeof(*points) * npoints); free(points); break; } case OPT_CUSTOM_STEP: custom_func.step = strtod(optarg, NULL); break; default: usage(); exit(1); break; } } if (streq(filter_type, "linear")) { filter = create_pointer_accelerator_filter_linear(dpi, use_averaging); profile = pointer_accel_profile_linear; } else if (streq(filter_type, "low-dpi")) { filter = create_pointer_accelerator_filter_linear_low_dpi(dpi, use_averaging); profile = pointer_accel_profile_linear_low_dpi; } else if (streq(filter_type, "touchpad")) { filter = create_pointer_accelerator_filter_touchpad(dpi, 0, 0, use_averaging); profile = touchpad_accel_profile_linear; } else if (streq(filter_type, "x230")) { filter = create_pointer_accelerator_filter_lenovo_x230(dpi, use_averaging); profile = touchpad_lenovo_x230_accel_profile; } else if (streq(filter_type, "trackpoint")) { filter = create_pointer_accelerator_filter_trackpoint(tp_multiplier, use_averaging); profile = trackpoint_accel_profile; } else if (streq(filter_type, "custom")) { libinput_config_accel_set_points(accel_config, LIBINPUT_ACCEL_TYPE_MOTION, custom_func.step, custom_func.npoints, custom_func.points); filter = create_custom_accelerator_filter(); profile = custom_accel_profile_motion; filter_set_accel_config(filter, accel_config); } else { fprintf(stderr, "Invalid filter type %s\n", filter_type); return 1; } assert(filter != NULL); filter_set_speed(filter, speed); if (!isatty(STDIN_FILENO)) { char buf[12]; mode = SEQUENCE; nevents = 0; memset(custom_deltas, 0, sizeof(custom_deltas)); while(fgets(buf, sizeof(buf), stdin) && nevents < 1024) { custom_deltas[nevents++] = strtod(buf, NULL); } } else if (optind < argc) { mode = SEQUENCE; nevents = 0; memset(custom_deltas, 0, sizeof(custom_deltas)); while (optind < argc) custom_deltas[nevents++] = strtod(argv[optind++], NULL); } else if (mode == SEQUENCE) { usage(); return 1; } switch (mode) { case ACCEL: print_accel_func(filter, profile, dpi); break; case DELTA: print_ptraccel_deltas(filter, step); break; case MOTION: print_ptraccel_movement(filter, nevents, max_dx, step); break; case SEQUENCE: print_ptraccel_sequence(filter, nevents, custom_deltas); break; } libinput_config_accel_destroy(accel_config); filter_destroy(filter); return 0; } libinput-1.28.1/tools/razer-quirks-lister.py000077500000000000000000000051031477265155700211270ustar00rootroot00000000000000#!/usr/bin/env python3 # # SPDX-License-Identifier: MIT # # This utility clones the openrazer repository, extracts the known VID/PID combos # for "RazerBlade" keyboards and spits out a libinput-compatible quirks file # with those keyboards listed as "Internal". # # Usage: # $ cd path/to/libinput.git/ # $ ./tools/razer-quirks-list.py from pathlib import Path from collections import namedtuple import tempfile import shutil import subprocess import sys KeyboardDescriptor = namedtuple("KeyboardDescriptor", ["vid", "pid", "name"]) with tempfile.TemporaryDirectory() as tmpdir: # Clone the openrazer directory and add its Python modyle basedir # to our sys.path so we can import it subprocess.run( [ "git", "clone", "--quiet", "--depth=1", "https://github.com/openrazer/openrazer", ], cwd=tmpdir, check=True, ) sys.path.append(str(Path(tmpdir) / "openrazer" / "daemon")) import openrazer_daemon.hardware.keyboards as razer_keyboards # type: ignore keyboards: list[KeyboardDescriptor] = [] # All classnames for the keyboards we care about start with RazerBlade for clsname in filter(lambda c: c.startswith("RazerBlade"), dir(razer_keyboards)): kbd = getattr(razer_keyboards, clsname) try: k = KeyboardDescriptor(name=clsname, vid=kbd.USB_VID, pid=kbd.USB_PID) keyboards.append(k) except AttributeError: continue tmpfile = Path(tmpdir) / "30-vendor-razer.quirks" try: quirksfile = next(Path("quirks").glob("30-vendor-razer.quirks")) except StopIteration: print("Unable to find the razer quirks file.") raise SystemExit(1) with open(tmpfile, "w") as output: with open(quirksfile) as input: for line in input: output.write(line) if line.startswith("# AUTOGENERATED"): output.write("\n") break for kbd in sorted(keyboards, key=lambda k: k.vid << 16 | k.pid): print( "\n".join( ( f"[{kbd.name} Keyboard]", "MatchUdevType=keyboard", "MatchBus=usb", f"MatchVendor=0x{kbd.vid:04X}", f"MatchProduct=0x{kbd.pid:04X}", "AttrKeyboardIntegration=internal", ) ), file=output, ) print(file=output) shutil.copy(tmpfile, quirksfile) libinput-1.28.1/tools/shared.c000066400000000000000000000602641477265155700162360ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "builddir.h" #include "libinput.h" #include "shared.h" #include "util-macros.h" #include "util-strings.h" static uint32_t dispatch_counter = 0; uint32_t log_serial = 0; void tools_dispatch(struct libinput *libinput) { dispatch_counter++; libinput_dispatch(libinput); } LIBINPUT_ATTRIBUTE_PRINTF(3, 0) static void log_handler(struct libinput *li, enum libinput_log_priority priority, const char *format, va_list args) { static int is_tty = -1; static uint32_t last_dispatch_no = 0; static bool color_toggle = false; if (is_tty == -1) is_tty = isatty(STDOUT_FILENO); if (is_tty) { if (priority >= LIBINPUT_LOG_PRIORITY_ERROR) { if (strstr(format, "client bug: ") || strstr(format, "libinput bug: ") || strstr(format, "kernel bug: ")) printf(ANSI_BRIGHT_RED); else printf(ANSI_RED); } else if (priority >= LIBINPUT_LOG_PRIORITY_INFO) { printf(ANSI_HIGHLIGHT); } else if (priority == LIBINPUT_LOG_PRIORITY_DEBUG) { if (dispatch_counter != last_dispatch_no) color_toggle = !color_toggle; uint8_t r = 0, g = 135, b = 95 + (color_toggle ? 80 :0); printf("\x1B[38;2;%u;%u;%um", r, g, b); } } if (priority < LIBINPUT_LOG_PRIORITY_INFO) { if (dispatch_counter != last_dispatch_no) { last_dispatch_no = dispatch_counter; printf("%4u: ", dispatch_counter); } else { printf(" %4s ", "..."); } } vprintf(format, args); if (is_tty) printf(ANSI_NORMAL); log_serial++; } void tools_init_options(struct tools_options *options) { memset(options, 0, sizeof(*options)); options->tapping = -1; options->tap_map = -1; options->drag = -1; options->drag_lock = -1; options->natural_scroll = -1; options->left_handed = -1; options->middlebutton = -1; options->dwt = -1; options->dwtp = -1; options->click_method = -1; options->scroll_method = -1; options->scroll_button = -1; options->scroll_button_lock = -1; options->speed = 0.0; options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; /* initialize accel args */ static double points[] = {0.0, 1.0}; options->custom_points = points; options->custom_npoints = ARRAY_LENGTH(points); options->custom_type = LIBINPUT_ACCEL_TYPE_FALLBACK; options->custom_step = 1.0; options->pressure_range[0] = 0.0; options->pressure_range[1] = 1.0; options->calibration[0] = 1.0; options->calibration[4] = 1.0; options->area.x1 = 0.0; options->area.y1 = 0.0; options->area.x2 = 1.0; options->area.y2 = 1.0; options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } int tools_parse_option(int option, const char *optarg, struct tools_options *options) { switch(option) { case OPT_TAP_ENABLE: options->tapping = 1; break; case OPT_TAP_DISABLE: options->tapping = 0; break; case OPT_TAP_MAP: if (!optarg) return 1; if (streq(optarg, "lrm")) { options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LRM; } else if (streq(optarg, "lmr")) { options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LMR; } else { return 1; } break; case OPT_DRAG_ENABLE: options->drag = 1; break; case OPT_DRAG_DISABLE: options->drag = 0; break; case OPT_DRAG_LOCK_ENABLE: if (optarg) { if (streq(optarg, "sticky")) { options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY; } else if (streq(optarg, "timeout")) { options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT; } else { return 1; } } else { options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT; } break; case OPT_DRAG_LOCK_DISABLE: options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; break; case OPT_NATURAL_SCROLL_ENABLE: options->natural_scroll = 1; break; case OPT_NATURAL_SCROLL_DISABLE: options->natural_scroll = 0; break; case OPT_LEFT_HANDED_ENABLE: options->left_handed = 1; break; case OPT_LEFT_HANDED_DISABLE: options->left_handed = 0; break; case OPT_MIDDLEBUTTON_ENABLE: options->middlebutton = 1; break; case OPT_MIDDLEBUTTON_DISABLE: options->middlebutton = 0; break; case OPT_DWT_ENABLE: options->dwt = LIBINPUT_CONFIG_DWT_ENABLED; break; case OPT_DWT_DISABLE: options->dwt = LIBINPUT_CONFIG_DWT_DISABLED; break; case OPT_DWTP_ENABLE: options->dwtp = LIBINPUT_CONFIG_DWTP_ENABLED; break; case OPT_DWTP_DISABLE: options->dwtp = LIBINPUT_CONFIG_DWTP_DISABLED; break; case OPT_CLICK_METHOD: if (!optarg) return 1; if (streq(optarg, "none")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; } else if (streq(optarg, "clickfinger")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; } else if (streq(optarg, "buttonareas")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; } else { return 1; } break; case OPT_CLICKFINGER_MAP: if (!optarg) return 1; if (streq(optarg, "lrm")) { options->clickfinger_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; } else if (streq(optarg, "lmr")) { options->clickfinger_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR; } else { return 1; } break; case OPT_SCROLL_METHOD: if (!optarg) return 1; if (streq(optarg, "none")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } else if (streq(optarg, "twofinger")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; } else if (streq(optarg, "edge")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; } else if (streq(optarg, "button")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } else { return 1; } break; case OPT_SCROLL_BUTTON: if (!optarg) { return 1; } options->scroll_button = libevdev_event_code_from_name(EV_KEY, optarg); if (options->scroll_button == -1) { fprintf(stderr, "Invalid button %s\n", optarg); return 1; } break; case OPT_SCROLL_BUTTON_LOCK_ENABLE: options->scroll_button_lock = true; break; case OPT_SCROLL_BUTTON_LOCK_DISABLE: options->scroll_button_lock = false; break; case OPT_SPEED: if (!optarg) return 1; options->speed = atof(optarg); break; case OPT_PROFILE: if (!optarg) return 1; if (streq(optarg, "adaptive")) options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; else if (streq(optarg, "flat")) options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; else if (streq(optarg, "custom")) options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM; else return 1; break; case OPT_DISABLE_SENDEVENTS: if (!optarg) return 1; snprintf(options->disable_pattern, sizeof(options->disable_pattern), "%s", optarg); break; case OPT_SENDEVENTS: if (streq(optarg, "disabled")) options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; else if (streq(optarg, "enabled")) options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; else if (streq(optarg, "disabled-on-external-mouse")) options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; else { fprintf(stderr, "Invalid sendevents mode: %s\n", optarg); return 1; } break; case OPT_APPLY_TO: if (!optarg) return 1; snprintf(options->match, sizeof(options->match), "%s", optarg); break; case OPT_CUSTOM_POINTS: if (!optarg) return 1; options->custom_points = double_array_from_string(optarg, ";", &options->custom_npoints); if (!options->custom_points || options->custom_npoints < 2) { fprintf(stderr, "Invalid --set-custom-points\n" "Please provide at least 2 points separated by a semicolon\n" " e.g. --set-custom-points=\"1.0;1.5\"\n"); return 1; } break; case OPT_CUSTOM_STEP: if (!optarg) return 1; options->custom_step = strtod(optarg, NULL); break; case OPT_CUSTOM_TYPE: if (!optarg) return 1; if (streq(optarg, "fallback")) options->custom_type = LIBINPUT_ACCEL_TYPE_FALLBACK; else if (streq(optarg, "motion")) options->custom_type = LIBINPUT_ACCEL_TYPE_MOTION; else if (streq(optarg, "scroll")) options->custom_type = LIBINPUT_ACCEL_TYPE_SCROLL; else { fprintf(stderr, "Invalid --set-custom-type\n" "Valid custom types: fallback|motion|scroll\n"); return 1; } break; case OPT_ROTATION_ANGLE: if (!optarg) return 1; if (!safe_atou(optarg, &options->angle)) { fprintf(stderr, "Invalid --set-rotation-angle value\n"); return 1; } break; case OPT_PRESSURE_RANGE: { if (!optarg) return 1; size_t npoints = 0; double *range = double_array_from_string(optarg, ":", &npoints); if (npoints != 2 || !range || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) { free(range); fprintf(stderr, "Invalid pressure range, must be in format \"min:max\"\n"); return 1; } options->pressure_range[0] = range[0]; options->pressure_range[1] = range[1]; free(range); break; } case OPT_CALIBRATION: { if (!optarg) return 1; size_t npoints = 0; double *matrix = double_array_from_string(optarg, " ", &npoints); if (!matrix || npoints != 6) { free(matrix); fprintf(stderr, "Invalid calibration matrix, must be 6 space-separated values\n"); return 1; } for (size_t i = 0; i < 6; i++) options->calibration[i] = matrix[i]; free(matrix); break; } case OPT_AREA: { if (!optarg) return 1; double x1, x2, y1, y2; if (sscanf(optarg, "%lf/%lf %lf/%lf", &x1, &y1, &x2, &y2) != 4) { fprintf(stderr, "Invalid --set-area values\n"); return 1; } options->area.x1 = x1; options->area.y1 = y1; options->area.x2 = x2; options->area.y2 = y2; break; } case OPT_3FG_DRAG: if (!optarg) return 1; if (streq(optarg, "3fg")) options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG; else if (streq(optarg, "4fg")) options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG; else if (streq(optarg, "disabled")) options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_DISABLED; else { fprintf(stderr, "Invalid --enable-3fg-drag\n" "Valid options: 3fg|4fg|disabled\n"); return 1; } break; } return 0; } static int open_restricted(const char *path, int flags, void *user_data) { bool *grab = user_data; int fd = open(path, flags); if (fd < 0) fprintf(stderr, "Failed to open %s (%s)\n", path, strerror(errno)); else if (grab && *grab && ioctl(fd, EVIOCGRAB, (void*)1) == -1) fprintf(stderr, "Grab requested, but failed for %s (%s)\n", path, strerror(errno)); return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void *user_data) { close(fd); } static const struct libinput_interface interface = { .open_restricted = open_restricted, .close_restricted = close_restricted, }; static struct libinput * tools_open_udev(const char *seat, bool verbose, bool *grab) { struct libinput *li; struct udev *udev = udev_new(); if (!udev) { fprintf(stderr, "Failed to initialize udev\n"); return NULL; } li = libinput_udev_create_context(&interface, grab, udev); if (!li) { fprintf(stderr, "Failed to initialize context from udev\n"); goto out; } libinput_log_set_handler(li, log_handler); if (verbose) libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); if (libinput_udev_assign_seat(li, seat)) { fprintf(stderr, "Failed to set seat\n"); libinput_unref(li); li = NULL; goto out; } out: udev_unref(udev); return li; } static struct libinput * tools_open_device(const char **paths, bool verbose, bool *grab) { struct libinput_device *device; struct libinput *li; const char **p = paths; li = libinput_path_create_context(&interface, grab); if (!li) { fprintf(stderr, "Failed to initialize path context\n"); return NULL; } if (verbose) { libinput_log_set_handler(li, log_handler); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); } while (*p) { device = libinput_path_add_device(li, *p); if (!device) { fprintf(stderr, "Failed to initialize device %s\n", *p); libinput_unref(li); li = NULL; break; } p++; } return li; } static void tools_setenv_quirks_dir(void) { char *builddir = builddir_lookup(); if (builddir) { setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0); free(builddir); } } struct libinput * tools_open_backend(enum tools_backend which, const char **seat_or_device, bool verbose, bool *grab) { struct libinput *li; tools_setenv_quirks_dir(); switch (which) { case BACKEND_UDEV: li = tools_open_udev(seat_or_device[0], verbose, grab); break; case BACKEND_DEVICE: li = tools_open_device(seat_or_device, verbose, grab); break; default: abort(); } return li; } void tools_device_apply_config(struct libinput_device *device, struct tools_options *options) { const char *name = libinput_device_get_name(device); if (libinput_device_config_send_events_get_modes(device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED && fnmatch(options->disable_pattern, name, 0) != FNM_NOMATCH) { libinput_device_config_send_events_set_mode(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); } if (strlen(options->match) > 0 && fnmatch(options->match, name, 0) == FNM_NOMATCH) return; libinput_device_config_send_events_set_mode(device, options->sendevents); if (options->tapping != -1) libinput_device_config_tap_set_enabled(device, options->tapping); if (options->tap_map != (enum libinput_config_tap_button_map)-1) libinput_device_config_tap_set_button_map(device, options->tap_map); if (options->drag != -1) libinput_device_config_tap_set_drag_enabled(device, options->drag); if (options->drag_lock != -1) libinput_device_config_tap_set_drag_lock_enabled(device, options->drag_lock); if (options->natural_scroll != -1) libinput_device_config_scroll_set_natural_scroll_enabled(device, options->natural_scroll); if (options->left_handed != -1) libinput_device_config_left_handed_set(device, options->left_handed); if (options->middlebutton != -1) libinput_device_config_middle_emulation_set_enabled(device, options->middlebutton); if (options->dwt != -1) libinput_device_config_dwt_set_enabled(device, options->dwt); if (options->dwtp != -1) libinput_device_config_dwtp_set_enabled(device, options->dwtp); if (options->click_method != (enum libinput_config_click_method)-1) libinput_device_config_click_set_method(device, options->click_method); if (options->clickfinger_map != (enum libinput_config_clickfinger_button_map)-1) libinput_device_config_click_set_clickfinger_button_map(device, options->clickfinger_map); if (options->scroll_method != (enum libinput_config_scroll_method)-1) libinput_device_config_scroll_set_method(device, options->scroll_method); if (options->scroll_button != -1) libinput_device_config_scroll_set_button(device, options->scroll_button); if (options->scroll_button_lock != -1) libinput_device_config_scroll_set_button_lock(device, options->scroll_button_lock); if (libinput_device_config_accel_is_available(device)) { libinput_device_config_accel_set_speed(device, options->speed); if (options->profile != LIBINPUT_CONFIG_ACCEL_PROFILE_NONE) libinput_device_config_accel_set_profile(device, options->profile); } if (options->profile == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) { struct libinput_config_accel *config = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); libinput_config_accel_set_points(config, options->custom_type, options->custom_step, options->custom_npoints, options->custom_points); libinput_device_config_accel_apply(device, config); libinput_config_accel_destroy(config); } if (options->angle != 0) libinput_device_config_rotation_set_angle(device, options->angle % 360); if (libinput_device_config_calibration_has_matrix(device)) libinput_device_config_calibration_set_matrix(device, options->calibration); if (libinput_device_config_area_has_rectangle(device)) libinput_device_config_area_set_rectangle(device, &options->area); if (libinput_device_config_3fg_drag_get_finger_count(device) >= 3) libinput_device_config_3fg_drag_set_enabled(device, options->drag_3fg); } void tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool, struct tools_options *options) { libinput_tablet_tool_config_pressure_range_set(tool, options->pressure_range[0], options->pressure_range[1]); } static char* find_device(const char *udev_tag) { struct udev *udev; struct udev_enumerate *e = NULL; struct udev_list_entry *entry = NULL; struct udev_device *device; const char *path, *sysname; char *device_node = NULL; udev = udev_new(); if (!udev) goto out; e = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(e, "input"); udev_enumerate_scan_devices(e); udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { path = udev_list_entry_get_name(entry); device = udev_device_new_from_syspath(udev, path); if (!device) continue; sysname = udev_device_get_sysname(device); if (!strstartswith("event", sysname)) { udev_device_unref(device); continue; } if (udev_device_get_property_value(device, udev_tag)) device_node = safe_strdup(udev_device_get_devnode(device)); udev_device_unref(device); if (device_node) break; } out: udev_enumerate_unref(e); udev_unref(udev); return device_node; } bool find_touchpad_device(char *path, size_t path_len) { char *devnode = find_device("ID_INPUT_TOUCHPAD"); if (devnode) { snprintf(path, path_len, "%s", devnode); free(devnode); } return devnode != NULL; } bool is_touchpad_device(const char *devnode) { struct udev *udev; struct udev_device *dev = NULL; struct stat st; bool is_touchpad = false; if (stat(devnode, &st) < 0) return false; udev = udev_new(); if (!udev) goto out; dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev); if (!dev) goto out; is_touchpad = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"); out: if (dev) udev_device_unref(dev); udev_unref(udev); return is_touchpad; } static inline void setup_path(void) { const char *path = getenv("PATH"); char new_path[PATH_MAX]; const char *extra_path = LIBINPUT_TOOL_PATH; char *builddir = builddir_lookup(); snprintf(new_path, sizeof(new_path), "%s:%s", builddir ? builddir : extra_path, path ? path : ""); setenv("PATH", new_path, 1); free(builddir); } int tools_exec_command(const char *prefix, int real_argc, char **real_argv) { char *argv[64] = {NULL}; char executable[128]; const char *command; int rc; assert((size_t)real_argc < ARRAY_LENGTH(argv)); command = real_argv[0]; rc = snprintf(executable, sizeof(executable), "%s-%s", prefix, command); if (rc >= (int)sizeof(executable)) { fprintf(stderr, "Failed to assemble command.\n"); return EXIT_FAILURE; } argv[0] = executable; for (int i = 1; i < real_argc; i++) argv[i] = real_argv[i]; setup_path(); rc = execvp(executable, argv); if (rc) { if (errno == ENOENT) { fprintf(stderr, "libinput: %s is not installed\n", command); return EXIT_INVALID_USAGE; } fprintf(stderr, "Failed to execute '%s' (%s)\n", command, strerror(errno)); } return EXIT_FAILURE; } static void sprintf_event_codes(char *buf, size_t sz, struct quirks *quirks, enum quirk q) { const struct quirk_tuples *t; size_t off = 0; int printed; const char *name; quirks_get_tuples(quirks, q, &t); name = quirk_get_name(q); printed = snprintf(buf, sz, "%s=", name); assert(printed != -1); off += printed; for (size_t i = 0; off < sz && i < t->ntuples; i++) { unsigned int type = t->tuples[i].first; unsigned int code = t->tuples[i].second; bool enable = t->tuples[i].third; const char *name = libevdev_event_code_get_name(type, code); printed = snprintf(buf + off, sz - off, "%c%s;", enable ? '+' : '-', name); assert(printed != -1); off += printed; } } static void sprintf_input_props(char *buf, size_t sz, struct quirks *quirks, enum quirk q) { const struct quirk_tuples *t; size_t off = 0; int printed; const char *name; quirks_get_tuples(quirks, q, &t); name = quirk_get_name(q); printed = snprintf(buf, sz, "%s=", name); assert(printed != -1); off += printed; for (size_t i = 0; off < sz && i < t->ntuples; i++) { unsigned int prop = t->tuples[i].first; bool enable = t->tuples[i].second; const char *name = libevdev_property_get_name(prop); printed = snprintf(buf + off, sz - off, "%c%s;", enable ? '+' : '-', name); assert(printed != -1); off += printed; } } void tools_list_device_quirks(struct quirks_context *ctx, struct udev_device *device, void (*callback)(void *data, const char *str), void *userdata) { char buf[256]; struct quirks *quirks; enum quirk q; quirks = quirks_fetch_for_device(ctx, device); if (!quirks) return; q = QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD; do { if (quirks_has_quirk(quirks, q)) { const char *name; bool b; name = quirk_get_name(q); quirks_get_bool(quirks, q, &b); snprintf(buf, sizeof(buf), "%s=%d", name, b ? 1 : 0); callback(userdata, buf); } } while(++q < _QUIRK_LAST_MODEL_QUIRK_); q = QUIRK_ATTR_SIZE_HINT; do { if (quirks_has_quirk(quirks, q)) { const char *name; struct quirk_dimensions dim; struct quirk_range r; uint32_t v; char *s; double d; bool b; name = quirk_get_name(q); switch (q) { case QUIRK_ATTR_SIZE_HINT: case QUIRK_ATTR_RESOLUTION_HINT: quirks_get_dimensions(quirks, q, &dim); snprintf(buf, sizeof(buf), "%s=%zdx%zd", name, dim.x, dim.y); callback(userdata, buf); break; case QUIRK_ATTR_TOUCH_SIZE_RANGE: case QUIRK_ATTR_PRESSURE_RANGE: quirks_get_range(quirks, q, &r); snprintf(buf, sizeof(buf), "%s=%d:%d", name, r.upper, r.lower); callback(userdata, buf); break; case QUIRK_ATTR_PALM_SIZE_THRESHOLD: case QUIRK_ATTR_PALM_PRESSURE_THRESHOLD: case QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD: case QUIRK_ATTR_THUMB_SIZE_THRESHOLD: quirks_get_uint32(quirks, q, &v); snprintf(buf, sizeof(buf), "%s=%u", name, v); callback(userdata, buf); break; case QUIRK_ATTR_LID_SWITCH_RELIABILITY: case QUIRK_ATTR_KEYBOARD_INTEGRATION: case QUIRK_ATTR_TRACKPOINT_INTEGRATION: case QUIRK_ATTR_TPKBCOMBO_LAYOUT: case QUIRK_ATTR_MSC_TIMESTAMP: quirks_get_string(quirks, q, &s); snprintf(buf, sizeof(buf), "%s=%s", name, s); callback(userdata, buf); break; case QUIRK_ATTR_TRACKPOINT_MULTIPLIER: quirks_get_double(quirks, q, &d); snprintf(buf, sizeof(buf), "%s=%0.2f", name, d); callback(userdata, buf); break; case QUIRK_ATTR_USE_VELOCITY_AVERAGING: case QUIRK_ATTR_TABLET_SMOOTHING: quirks_get_bool(quirks, q, &b); snprintf(buf, sizeof(buf), "%s=%d", name, b); callback(userdata, buf); break; case QUIRK_ATTR_EVENT_CODE: sprintf_event_codes(buf, sizeof(buf), quirks, q); callback(userdata, buf); break; case QUIRK_ATTR_INPUT_PROP: sprintf_input_props(buf, sizeof(buf), quirks, q); callback(userdata, buf); break; default: abort(); break; } } } while(++q < _QUIRK_LAST_ATTR_QUIRK_); quirks_unref(quirks); } libinput-1.28.1/tools/shared.h000066400000000000000000000157251477265155700162450ustar00rootroot00000000000000/* * Copyright © 2014 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #ifndef _SHARED_H_ #define _SHARED_H_ #include #include #include #include #include "util-strings.h" #define EXIT_INVALID_USAGE 2 extern uint32_t log_serial; enum configuration_options { OPT_TAP_ENABLE = 256, OPT_TAP_DISABLE, OPT_TAP_MAP, OPT_DRAG_ENABLE, OPT_DRAG_DISABLE, OPT_DRAG_LOCK_ENABLE, OPT_DRAG_LOCK_DISABLE, OPT_NATURAL_SCROLL_ENABLE, OPT_NATURAL_SCROLL_DISABLE, OPT_LEFT_HANDED_ENABLE, OPT_LEFT_HANDED_DISABLE, OPT_MIDDLEBUTTON_ENABLE, OPT_MIDDLEBUTTON_DISABLE, OPT_DWT_ENABLE, OPT_DWT_DISABLE, OPT_DWTP_ENABLE, OPT_DWTP_DISABLE, OPT_CLICK_METHOD, OPT_CLICKFINGER_MAP, OPT_SCROLL_METHOD, OPT_SCROLL_BUTTON, OPT_SCROLL_BUTTON_LOCK_ENABLE, OPT_SCROLL_BUTTON_LOCK_DISABLE, OPT_SPEED, OPT_PROFILE, OPT_DISABLE_SENDEVENTS, OPT_APPLY_TO, OPT_CUSTOM_POINTS, OPT_CUSTOM_STEP, OPT_CUSTOM_TYPE, OPT_ROTATION_ANGLE, OPT_PRESSURE_RANGE, OPT_CALIBRATION, OPT_AREA, OPT_3FG_DRAG, OPT_SENDEVENTS, }; #define CONFIGURATION_OPTIONS \ { "disable-sendevents", required_argument, 0, OPT_DISABLE_SENDEVENTS }, \ { "enable-tap", no_argument, 0, OPT_TAP_ENABLE }, \ { "disable-tap", no_argument, 0, OPT_TAP_DISABLE }, \ { "enable-drag", no_argument, 0, OPT_DRAG_ENABLE }, \ { "disable-drag", no_argument, 0, OPT_DRAG_DISABLE }, \ { "enable-drag-lock", optional_argument, 0, OPT_DRAG_LOCK_ENABLE }, \ { "disable-drag-lock", no_argument, 0, OPT_DRAG_LOCK_DISABLE }, \ { "enable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_ENABLE }, \ { "disable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_DISABLE }, \ { "enable-left-handed", no_argument, 0, OPT_LEFT_HANDED_ENABLE }, \ { "disable-left-handed", no_argument, 0, OPT_LEFT_HANDED_DISABLE }, \ { "enable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_ENABLE }, \ { "disable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_DISABLE }, \ { "enable-dwt", no_argument, 0, OPT_DWT_ENABLE }, \ { "disable-dwt", no_argument, 0, OPT_DWT_DISABLE }, \ { "enable-dwtp", no_argument, 0, OPT_DWTP_ENABLE }, \ { "disable-dwtp", no_argument, 0, OPT_DWTP_DISABLE }, \ { "enable-scroll-button-lock", no_argument, 0, OPT_SCROLL_BUTTON_LOCK_ENABLE }, \ { "disable-scroll-button-lock",no_argument, 0, OPT_SCROLL_BUTTON_LOCK_DISABLE }, \ { "enable-3fg-drag", required_argument, 0, OPT_3FG_DRAG }, \ { "set-click-method", required_argument, 0, OPT_CLICK_METHOD }, \ { "set-clickfinger-map", required_argument, 0, OPT_CLICKFINGER_MAP }, \ { "set-scroll-method", required_argument, 0, OPT_SCROLL_METHOD }, \ { "set-scroll-button", required_argument, 0, OPT_SCROLL_BUTTON }, \ { "set-profile", required_argument, 0, OPT_PROFILE }, \ { "set-tap-map", required_argument, 0, OPT_TAP_MAP }, \ { "set-speed", required_argument, 0, OPT_SPEED },\ { "set-sendevents", required_argument, 0, OPT_SENDEVENTS },\ { "apply-to", required_argument, 0, OPT_APPLY_TO },\ { "set-custom-points", required_argument, 0, OPT_CUSTOM_POINTS },\ { "set-custom-step", required_argument, 0, OPT_CUSTOM_STEP },\ { "set-custom-type", required_argument, 0, OPT_CUSTOM_TYPE },\ { "set-rotation-angle", required_argument, 0, OPT_ROTATION_ANGLE }, \ { "set-pressure-range", required_argument, 0, OPT_PRESSURE_RANGE }, \ { "set-calibration", required_argument, 0, OPT_CALIBRATION }, \ { "set-area", required_argument, 0, OPT_AREA } static inline void tools_print_usage_option_list(struct option *opts) { printf("Options:\n"); struct option *o = opts; while (o && o->name) { if (strstartswith(o->name, "enable-") && strstartswith((o+1)->name, "disable-")) { printf(" --%s/--%s\n", o->name, (o+1)->name); o++; } else { printf(" --%s\n", o->name); } o++; } } enum tools_backend { BACKEND_NONE, BACKEND_DEVICE, BACKEND_UDEV }; struct tools_options { char match[256]; int tapping; int drag; int drag_lock; int natural_scroll; int left_handed; int middlebutton; enum libinput_config_click_method click_method; enum libinput_config_clickfinger_button_map clickfinger_map; enum libinput_config_scroll_method scroll_method; enum libinput_config_tap_button_map tap_map; int scroll_button; int scroll_button_lock; double speed; int dwt; int dwtp; enum libinput_config_accel_profile profile; char disable_pattern[64]; enum libinput_config_accel_type custom_type; double custom_step; size_t custom_npoints; double *custom_points; unsigned int angle; double pressure_range[2]; float calibration[6]; struct libinput_config_area_rectangle area; enum libinput_config_3fg_drag_state drag_3fg; enum libinput_config_send_events_mode sendevents; }; void tools_init_options(struct tools_options *options); int tools_parse_option(int option, const char *optarg, struct tools_options *options); struct libinput* tools_open_backend(enum tools_backend which, const char **seat_or_devices, bool verbose, bool *grab); void tools_device_apply_config(struct libinput_device *device, struct tools_options *options); void tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool, struct tools_options *options); int tools_exec_command(const char *prefix, int argc, char **argv); bool find_touchpad_device(char *path, size_t path_len); bool is_touchpad_device(const char *devnode); void tools_list_device_quirks(struct quirks_context *ctx, struct udev_device *device, void (*callback)(void *userdata, const char *str), void *userdata); void tools_dispatch(struct libinput *libinput); #endif libinput-1.28.1/tools/test_tool_option_parsing.py000077500000000000000000000307451477265155700223310ustar00rootroot00000000000000#!/usr/bin/env python3 # vim: set expandtab shiftwidth=4: # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # # Copyright © 2018 Red Hat, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice (including the next # paragraph) shall be included in all copies or substantial portions of the # Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. import os import resource import sys import subprocess import logging try: import pytest except ImportError: print("Failed to import pytest. Skipping.", file=sys.stderr) sys.exit(77) logger = logging.getLogger("test") logger.setLevel(logging.DEBUG) if "@DISABLE_WARNING@" != "yes": print("This is the source file, run the one in the meson builddir instead") sys.exit(1) def _disable_coredump(): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) def run_command(args): logger.debug("run command: {}".format(" ".join(args))) with subprocess.Popen( args, preexec_fn=_disable_coredump, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) as p: try: p.wait(0.7) except subprocess.TimeoutExpired: p.send_signal(3) # SIGQUIT stdout, stderr = p.communicate(timeout=5) if p.returncode == -3: p.returncode = 0 return p.returncode, stdout.decode("UTF-8"), stderr.decode("UTF-8") class LibinputTool(object): libinput_tool = "libinput" subtool = None def __init__(self, subtool=None): self.libinput_tool = "@TOOL_PATH@" self.subtool = subtool def run_command(self, args): args = [self.libinput_tool] + args if self.subtool is not None: args.insert(1, self.subtool) return run_command(args) def run_command_success(self, args): rc, stdout, stderr = self.run_command(args) # if we're running as user, we might fail the command but we should # never get rc 2 (invalid usage) assert rc in [0, 1], (stdout, stderr) return stdout, stderr def run_command_invalid(self, args): rc, stdout, stderr = self.run_command(args) assert rc == 2, (rc, stdout, stderr) return rc, stdout, stderr def run_command_unrecognized_option(self, args): rc, stdout, stderr = self.run_command(args) assert rc == 2, (rc, stdout, stderr) assert stdout.startswith("Usage") or stdout == "" assert "unrecognized option" in stderr def run_command_missing_arg(self, args): rc, stdout, stderr = self.run_command(args) assert rc == 2, (rc, stdout, stderr) assert stdout.startswith("Usage") or stdout == "" assert "requires an argument" in stderr def run_command_unrecognized_tool(self, args): rc, stdout, stderr = self.run_command(args) assert rc == 2, (rc, stdout, stderr) assert stdout.startswith("Usage") or stdout == "" assert "is not installed" in stderr class LibinputDebugGui(LibinputTool): def __init__(self, subtool="debug-gui"): assert subtool == "debug-gui" super().__init__(subtool) debug_gui_enabled = "@MESON_ENABLED_DEBUG_GUI@" == "True" if not debug_gui_enabled: pytest.skip() if not os.getenv("DISPLAY") and not os.getenv("WAYLAND_DISPLAY"): pytest.skip() # 77 means gtk_init() failed, which is probably because you can't # connect to the display server. rc, _, _ = self.run_command(["--help"]) if rc == 77: pytest.skip() def get_tool(subtool=None): if subtool == "debug-gui": return LibinputDebugGui() else: return LibinputTool(subtool) @pytest.fixture def libinput(): return get_tool() @pytest.fixture(params=["debug-events", "debug-gui"]) def libinput_debug_tool(request): yield get_tool(request.param) @pytest.fixture def libinput_debug_events(): return get_tool("debug-events") @pytest.fixture def libinput_debug_gui(): return get_tool("debug-gui") @pytest.fixture def libinput_record(): return get_tool("record") def test_help(libinput): stdout, stderr = libinput.run_command_success(["--help"]) assert stdout.startswith("Usage:") assert stderr == "" def test_version(libinput): stdout, stderr = libinput.run_command_success(["--version"]) assert stdout.startswith("1") assert stderr == "" @pytest.mark.parametrize("argument", ["--banana", "--foo", "--quiet", "--verbose"]) def test_invalid_arguments(libinput, argument): libinput.run_command_unrecognized_option([argument]) @pytest.mark.parametrize("tool", [["foo"], ["debug"], ["foo", "--quiet"]]) def test_invalid_tool(libinput, tool): libinput.run_command_unrecognized_tool(tool) def test_udev_seat(libinput_debug_tool): libinput_debug_tool.run_command_missing_arg(["--udev"]) libinput_debug_tool.run_command_success(["--udev", "seat0"]) libinput_debug_tool.run_command_success(["--udev", "seat1"]) @pytest.mark.skipif(os.environ.get("UDEV_NOT_AVAILABLE"), reason="udev required") def test_device_arg(libinput_debug_tool): libinput_debug_tool.run_command_missing_arg(["--device"]) libinput_debug_tool.run_command_success(["--device", "/dev/input/event0"]) libinput_debug_tool.run_command_success(["--device", "/dev/input/event1"]) libinput_debug_tool.run_command_success(["/dev/input/event0"]) options = { "pattern": ["sendevents"], # enable/disable options "enable-disable": [ "tap", "drag", "drag-lock", "middlebutton", "natural-scrolling", "left-handed", "dwt", "dwtp", ], # options with distinct values "enums": { "set-click-method": ["none", "clickfinger", "buttonareas"], "set-scroll-method": ["none", "twofinger", "edge", "button"], "set-profile": ["adaptive", "flat"], "set-tap-map": ["lrm", "lmr"], "set-clickfinger-map": ["lrm", "lmr"], "enable-drag-lock": ["sticky", "timeout"], }, # options with a range (and increment) "ranges": { "set-speed": (-1.0, +1.0, 0.1), "set-rotation": (0, 360, 10), }, } # Options that allow for glob patterns @pytest.mark.parametrize("option", options["pattern"]) def test_options_pattern(libinput_debug_tool, option): libinput_debug_tool.run_command_success(["--disable-{}".format(option), "*"]) libinput_debug_tool.run_command_success(["--disable-{}".format(option), "abc*"]) @pytest.mark.parametrize("option", options["enable-disable"]) def test_options_enable_disable(libinput_debug_tool, option): libinput_debug_tool.run_command_success(["--enable-{}".format(option)]) libinput_debug_tool.run_command_success(["--disable-{}".format(option)]) @pytest.mark.parametrize("option", options["enums"].items()) def test_options_enums(libinput_debug_tool, option): name, values = option for v in values: libinput_debug_tool.run_command_success(["--{}".format(name), v]) libinput_debug_tool.run_command_success(["--{}={}".format(name, v)]) @pytest.mark.parametrize("option", options["ranges"].items()) def test_options_ranges(libinput_debug_tool, option): name, values = option minimum, maximum, step = values value = minimum while value < maximum: libinput_debug_tool.run_command_success(["--{}".format(name), str(value)]) libinput_debug_tool.run_command_success(["--{}={}".format(name, value)]) value += step libinput_debug_tool.run_command_success(["--{}".format(name), str(maximum)]) libinput_debug_tool.run_command_success(["--{}={}".format(name, maximum)]) def test_apply_to(libinput_debug_tool): libinput_debug_tool.run_command_missing_arg(["--apply-to"]) libinput_debug_tool.run_command_success(["--apply-to", "*foo*"]) libinput_debug_tool.run_command_success(["--apply-to", "foobar"]) libinput_debug_tool.run_command_success(["--apply-to", "any"]) @pytest.mark.parametrize( "args", [["--verbose"], ["--quiet"], ["--verbose", "--quiet"], ["--quiet", "--verbose"]], ) def test_debug_events_verbose_quiet(libinput_debug_events, args): libinput_debug_events.run_command_success(args) @pytest.mark.parametrize("arg", ["--banana", "--foo", "--version"]) def test_invalid_args(libinput_debug_tool, arg): libinput_debug_tool.run_command_unrecognized_option([arg]) def test_libinput_debug_events_multiple_devices(libinput_debug_events): libinput_debug_events.run_command_success( ["--device", "/dev/input/event0", "/dev/input/event1"] ) # same event path multiple times? meh, your problem libinput_debug_events.run_command_success( ["--device", "/dev/input/event0", "/dev/input/event0"] ) libinput_debug_events.run_command_success( ["/dev/input/event0", "/dev/input/event1"] ) def test_libinput_debug_events_too_many_devices(libinput_debug_events): # Too many arguments just bails with the usage message rc, stdout, stderr = libinput_debug_events.run_command(["/dev/input/event0"] * 61) assert rc == 2, (stdout, stderr) @pytest.mark.parametrize("arg", ["--quiet"]) def test_libinput_debug_gui_invalid_arg(libinput_debug_gui, arg): libinput_debug_gui.run_command_unrecognized_option([arg]) def test_libinput_debug_gui_verbose(libinput_debug_gui): libinput_debug_gui.run_command_success(["--verbose"]) @pytest.mark.parametrize( "arg", ["--help", "--show-keycodes", "--with-libinput", "--with-hidraw"] ) def test_libinput_record_args(libinput_record, arg): libinput_record.run_command_success([arg]) def test_libinput_record_multiple_arg(libinput_record): # this arg is deprecated and a noop libinput_record.run_command_success(["--multiple"]) @pytest.fixture def recording(tmp_path): return str((tmp_path / "record.out").resolve()) def test_libinput_record_all(libinput_record, recording): libinput_record.run_command_success(["--all", "-o", recording]) libinput_record.run_command_success(["--all", recording]) def test_libinput_record_outfile(libinput_record, recording): libinput_record.run_command_success(["-o", recording]) libinput_record.run_command_success(["--output-file", recording]) libinput_record.run_command_success(["--output-file={}".format(recording)]) def test_libinput_record_single(libinput_record, recording): libinput_record.run_command_success(["/dev/input/event0"]) libinput_record.run_command_success(["-o", recording, "/dev/input/event0"]) libinput_record.run_command_success(["/dev/input/event0", recording]) libinput_record.run_command_success([recording, "/dev/input/event0"]) def test_libinput_record_multiple(libinput_record, recording): libinput_record.run_command_success( ["-o", recording, "/dev/input/event0", "/dev/input/event1"] ) libinput_record.run_command_success( [recording, "/dev/input/event0", "/dev/input/event1"] ) libinput_record.run_command_success( ["/dev/input/event0", "/dev/input/event1", recording] ) def test_libinput_record_autorestart(libinput_record, recording): libinput_record.run_command_invalid(["--autorestart"]) libinput_record.run_command_invalid(["--autorestart=2"]) libinput_record.run_command_success(["-o", recording, "--autorestart=2"]) def main(): args = ["-m", "pytest"] try: import xdist # noqa ncores = os.environ.get("FDO_CI_CONCURRENT", "auto") args += ["-n", ncores] except ImportError: logger.info("python-xdist missing, this test will be slow") pass args += ["@MESON_BUILD_ROOT@"] os.environ["LIBINPUT_RUNNING_TEST_SUITE"] = "1" return subprocess.run([sys.executable] + args).returncode if __name__ == "__main__": raise SystemExit(main()) libinput-1.28.1/udev/000077500000000000000000000000001477265155700144175ustar00rootroot00000000000000libinput-1.28.1/udev/80-libinput-device-groups.rules.in000066400000000000000000000003371477265155700227300ustar00rootroot00000000000000ACTION=="remove", GOTO="libinput_device_group_end" KERNEL!="event[0-9]*", GOTO="libinput_device_group_end" ATTRS{phys}=="?*", IMPORT{program}="@UDEV_TEST_PATH@libinput-device-group %S%p" LABEL="libinput_device_group_end" libinput-1.28.1/udev/90-libinput-fuzz-override.rules.in000066400000000000000000000022121477265155700227620ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update # # This file contains lookup rules for libinput model-specific quirks. # IT IS NOT A STABLE API AND SUBJECT TO CHANGE AT ANY TIME ACTION=="remove", GOTO="libinput_fuzz_override_end" KERNEL!="event*", GOTO="libinput_fuzz_override_end" # Two-step process: fuzz-extract sets the LIBINPUT_FUZZ property and # fuzz-to-zero sets the kernel fuzz to zero. They must be in IMPORT and RUN, # respectively, to correctly interact with the 60-evdev.hwdb # # Drawback: if this rule is triggered more than once, we'll lose the fuzz # information (because the kernel fuzz will then be zero). Nothing we can do # about that. ATTRS{capabilities/abs}!="0", \ ENV{ID_INPUT_TOUCHPAD}=="1", \ IMPORT{program}="@UDEV_TEST_PATH@libinput-fuzz-extract %S%p", \ RUN{program}+="@UDEV_TEST_PATH@libinput-fuzz-to-zero %S%p", \ GOTO="libinput_fuzz_override_end" ATTRS{capabilities/abs}!="0", \ ENV{ID_INPUT_TOUCHSCREEN}=="1", \ IMPORT{program}="@UDEV_TEST_PATH@libinput-fuzz-extract %S%p", \ RUN{program}+="@UDEV_TEST_PATH@libinput-fuzz-to-zero %S%p", \ GOTO="libinput_fuzz_override_end" LABEL="libinput_fuzz_override_end" libinput-1.28.1/udev/libinput-device-group.c000066400000000000000000000143431477265155700210050ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include "libinput-util.h" #if HAVE_LIBWACOM #include static void wacom_handle_paired(struct udev_device *device, int *vendor_id, int *product_id) { WacomDeviceDatabase *db = NULL; WacomDevice *tablet = NULL; const WacomMatch *paired; db = libwacom_database_new(); if (!db) goto out; tablet = libwacom_new_from_usbid(db, *vendor_id, *product_id, NULL); if (!tablet) goto out; paired = libwacom_get_paired_device(tablet); if (!paired) goto out; *vendor_id = libwacom_match_get_vendor_id(paired); *product_id = libwacom_match_get_product_id(paired); out: if (tablet) libwacom_destroy(tablet); if (db) libwacom_database_destroy(db); } static int find_tree_distance(struct udev_device *a, struct udev_device *b) { struct udev_device *ancestor_a = a; int dist_a = 0; while (ancestor_a != NULL) { const char *path_a = udev_device_get_syspath(ancestor_a); struct udev_device *ancestor_b = b; int dist_b = 0; while (ancestor_b != NULL) { const char *path_b = udev_device_get_syspath(ancestor_b); if (streq(path_a, path_b)) return dist_a + dist_b; dist_b++; ancestor_b = udev_device_get_parent(ancestor_b); } dist_a++; ancestor_a = udev_device_get_parent(ancestor_a); } return -1; } static void wacom_handle_ekr(struct udev_device *device, int *vendor_id, int *product_id, char **phys_attr) { struct udev *udev; struct udev_enumerate *e; struct udev_list_entry *entry = NULL; int best_dist = -1; udev = udev_device_get_udev(device); e = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(e, "input"); udev_enumerate_add_match_sysname(e, "input*"); udev_enumerate_scan_devices(e); udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { struct udev_device *d; const char *path, *phys; const char *pidstr, *vidstr; int pid, vid, dist; /* Find and use the closest Wacom device on the system, * relying on wacom_handle_paired() to fix our ID later * if needed. */ path = udev_list_entry_get_name(entry); d = udev_device_new_from_syspath(udev, path); if (!d) continue; vidstr = udev_device_get_property_value(d, "ID_VENDOR_ID"); pidstr = udev_device_get_property_value(d, "ID_MODEL_ID"); phys = udev_device_get_sysattr_value(d, "phys"); if (vidstr && pidstr && phys && safe_atoi_base(vidstr, &vid, 16) && safe_atoi_base(pidstr, &pid, 16) && vid == VENDOR_ID_WACOM && pid != PRODUCT_ID_WACOM_EKR) { dist = find_tree_distance(device, d); if (dist > 0 && (dist < best_dist || best_dist < 0)) { *vendor_id = vid; *product_id = pid; best_dist = dist; free(*phys_attr); *phys_attr = safe_strdup(phys); } } udev_device_unref(d); } udev_enumerate_unref(e); } #endif int main(int argc, char **argv) { int rc = 1; struct udev *udev = NULL; struct udev_device *device = NULL; const char *syspath, *phys = NULL; const char *product; int bustype, vendor_id, product_id, version; char group[1024]; char *str; if (argc != 2) return 1; syspath = argv[1]; udev = udev_new(); if (!udev) goto out; device = udev_device_new_from_syspath(udev, syspath); if (!device) goto out; /* Find the first parent with ATTRS{phys} set. For tablets that * value looks like usb-0000:00:14.0-1/input1. Drop the /input1 * bit and use the remainder as device group identifier */ while (device != NULL) { struct udev_device *parent; phys = udev_device_get_sysattr_value(device, "phys"); if (phys) break; parent = udev_device_get_parent(device); udev_device_ref(parent); udev_device_unref(device); device = parent; } if (!phys) goto out; /* udev sets PRODUCT on the same device we find PHYS on, let's rely on that*/ product = udev_device_get_property_value(device, "PRODUCT"); if (!product) product = "00/00/00/00"; if (sscanf(product, "%x/%x/%x/%x", &bustype, &vendor_id, &product_id, &version) != 4) { snprintf(group, sizeof(group), "%s:%s", product, phys); } else { char *physmatch = NULL; #if HAVE_LIBWACOM if (vendor_id == VENDOR_ID_WACOM) { if (product_id == PRODUCT_ID_WACOM_EKR) wacom_handle_ekr(device, &vendor_id, &product_id, &physmatch); /* This is called for the EKR as well */ wacom_handle_paired(device, &vendor_id, &product_id); } #endif snprintf(group, sizeof(group), "%x/%x/%x:%s", bustype, vendor_id, product_id, physmatch ? physmatch : phys); free(physmatch); } str = strstr(group, "/input"); if (str) *str = '\0'; /* Cintiq 22HD Touch has usb-0000:00:14.0-6.3.1/input0 for the touch usb-0000:00:14.0-6.3.0/input0 for the pen Check if there's a . after the last -, if so, cut off the string there. */ str = strrchr(group, '.'); if (str && str > strrchr(group, '-')) *str = '\0'; printf("LIBINPUT_DEVICE_GROUP=%s\n", group); rc = 0; out: if (device) udev_device_unref(device); if (udev) udev_unref(udev); return rc; } libinput-1.28.1/udev/libinput-fuzz-extract.c000066400000000000000000000066421477265155700210650ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include #include "util-prop-parsers.h" #include "util-macros.h" /** * For a non-zero fuzz on the x/y axes, print that fuzz as property and * reset the kernel's fuzz to 0. * https://bugs.freedesktop.org/show_bug.cgi?id=105202 */ static void handle_absfuzz(struct udev_device *device) { const char *devnode; struct libevdev *evdev = NULL; int fd = -1; int rc; unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, ABS_MT_POSITION_Y}; devnode = udev_device_get_devnode(device); if (!devnode) goto out; fd = open(devnode, O_RDONLY); if (fd < 0) goto out; rc = libevdev_new_from_fd(fd, &evdev); if (rc != 0) goto out; if (!libevdev_has_event_type(evdev, EV_ABS)) goto out; ARRAY_FOR_EACH(axes, code) { int fuzz; fuzz = libevdev_get_abs_fuzz(evdev, *code); if (fuzz) printf("LIBINPUT_FUZZ_%02x=%d\n", *code, fuzz); } out: close(fd); libevdev_free(evdev); } /** * Where a device has EVDEV_ABS_... set with a fuzz, that fuzz hasn't been * applied to the kernel yet. So we need to extract it ourselves **and** * update the property so the kernel won't actually set it later. */ static void handle_evdev_abs(struct udev_device *device) { unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, ABS_MT_POSITION_Y}; ARRAY_FOR_EACH(axes, code) { const char *prop; char name[64]; uint32_t mask; struct input_absinfo abs; snprintf(name, sizeof(name), "EVDEV_ABS_%02X", *code); prop = udev_device_get_property_value(device, name); if (!prop) continue; mask = parse_evdev_abs_prop(prop, &abs); if (mask & ABS_MASK_FUZZ) printf("LIBINPUT_FUZZ_%02x=%d\n", *code, abs.fuzz); } } int main(int argc, char **argv) { int rc = 1; struct udev *udev = NULL; struct udev_device *device = NULL; const char *syspath; if (argc != 2) return 1; syspath = argv[1]; udev = udev_new(); if (!udev) goto out; device = udev_device_new_from_syspath(udev, syspath); if (!device) goto out; handle_absfuzz(device); handle_evdev_abs(device); rc = 0; out: if (device) udev_device_unref(device); if (udev) udev_unref(udev); return rc; } libinput-1.28.1/udev/libinput-fuzz-to-zero.c000066400000000000000000000050351477265155700210050ustar00rootroot00000000000000/* * Copyright © 2015 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include #include #include #include #include #include #include "util-macros.h" static void reset_absfuzz_to_zero(struct udev_device *device) { const char *devnode; struct libevdev *evdev = NULL; int fd = -1; int rc; unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, ABS_MT_POSITION_Y}; devnode = udev_device_get_devnode(device); if (!devnode) goto out; fd = open(devnode, O_RDWR); if (fd < 0) goto out; rc = libevdev_new_from_fd(fd, &evdev); if (rc != 0) goto out; if (!libevdev_has_event_type(evdev, EV_ABS)) goto out; ARRAY_FOR_EACH(axes, code) { struct input_absinfo abs; int fuzz; fuzz = libevdev_get_abs_fuzz(evdev, *code); if (!fuzz) continue; abs = *libevdev_get_abs_info(evdev, *code); abs.fuzz = 0; libevdev_kernel_set_abs_info(evdev, *code, &abs); } out: close(fd); libevdev_free(evdev); } int main(int argc, char **argv) { int rc = 1; struct udev *udev = NULL; struct udev_device *device = NULL; const char *syspath; if (argc != 2) return 1; syspath = argv[1]; udev = udev_new(); if (!udev) goto out; device = udev_device_new_from_syspath(udev, syspath); if (!device) goto out; reset_absfuzz_to_zero(device); rc = 0; out: if (device) udev_device_unref(device); if (udev) udev_unref(udev); return rc; } libinput-1.28.1/udev/test-libinput-fuzz-extract.c000066400000000000000000000071271477265155700220410ustar00rootroot00000000000000/* * Copyright © 2019 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "config.h" #include /* remove the main() from the included program so we can define our own */ #define main __disabled int main(int argc, char **argv); #include "libinput-fuzz-extract.c" #undef main START_TEST(test_parse_ev_abs) { struct test { uint32_t which; const char *prop; int min, max, res, fuzz, flat; } tests[] = { { .which = (MIN|MAX), .prop = "1:2", .min = 1, .max = 2 }, { .which = (MIN|MAX), .prop = "1:2:", .min = 1, .max = 2 }, { .which = (MIN|MAX|RES), .prop = "10:20:30", .min = 10, .max = 20, .res = 30 }, { .which = (RES), .prop = "::100", .res = 100 }, { .which = (MIN), .prop = "10:", .min = 10 }, { .which = (MAX|RES), .prop = ":10:1001", .max = 10, .res = 1001 }, { .which = (MIN|MAX|RES|FUZZ), .prop = "1:2:3:4", .min = 1, .max = 2, .res = 3, .fuzz = 4}, { .which = (MIN|MAX|RES|FUZZ|FLAT), .prop = "1:2:3:4:5", .min = 1, .max = 2, .res = 3, .fuzz = 4, .flat = 5}, { .which = (MIN|RES|FUZZ|FLAT), .prop = "1::3:4:50", .min = 1, .res = 3, .fuzz = 4, .flat = 50}, { .which = FUZZ|FLAT, .prop = ":::5:60", .fuzz = 5, .flat = 60}, { .which = FUZZ, .prop = ":::5:", .fuzz = 5 }, { .which = RES, .prop = "::12::", .res = 12 }, /* Malformed property but parsing this one makes us more * future proof */ { .which = (RES|FUZZ|FLAT), .prop = "::12:1:2:3:4:5:6", .res = 12, .fuzz = 1, .flat = 2 }, { .which = 0, .prop = ":::::" }, { .which = 0, .prop = ":" }, { .which = 0, .prop = "" }, { .which = 0, .prop = ":asb::::" }, { .which = 0, .prop = "foo" }, }; struct test *t; ARRAY_FOR_EACH(tests, t) { struct input_absinfo abs; uint32_t mask; mask = parse_ev_abs_prop(t->prop, &abs); ck_assert_int_eq(mask, t->which); if (t->which & MIN) ck_assert_int_eq(abs.minimum, t->min); if (t->which & MAX) ck_assert_int_eq(abs.maximum, t->max); if (t->which & RES) ck_assert_int_eq(abs.resolution, t->res); if (t->which & FUZZ) ck_assert_int_eq(abs.fuzz, t->fuzz); if (t->which & FLAT) ck_assert_int_eq(abs.flat, t->flat); } } END_TEST int main(int argc, char **argv) { SRunner *sr = srunner_create(NULL); Suite *s = suite_create("fuzz-override"); TCase *tc = tcase_create("parser"); int nfailed; tcase_add_test(tc, test_parse_ev_abs); suite_add_tcase(s, tc); srunner_add_suite(sr, s); srunner_run_all(sr, CK_NORMAL); nfailed = srunner_ntests_failed(sr); srunner_free(sr); return nfailed; }