From 8783e50a3661383b1e167d6da7d3c5ac7877b3d6 Mon Sep 17 00:00:00 2001 From: Packit Date: Aug 25 2020 08:59:19 +0000 Subject: libinput-1.14.3 base --- diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..4ef2d13 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,4 @@ +((nil . ((indent-tabs-mode . t) + (tab-width . 8) + (fill-column . 80))) + (c-mode . ((c-basic-offset . 8)))) diff --git a/.vimdir b/.vimdir new file mode 100644 index 0000000..e3ef2d8 --- /dev/null +++ b/.vimdir @@ -0,0 +1 @@ +set noexpandtab shiftwidth=8 cinoptions=:0,+0,(0 diff --git a/CODING_STYLE.md b/CODING_STYLE.md new file mode 100644 index 0000000..4fe97ed --- /dev/null +++ b/CODING_STYLE.md @@ -0,0 +1,135 @@ + +- 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 at the top, try to keep them as local as possible. + Exception: if the same variable is re-used in multiple blocks, declare it + at the top. + Exception: basic loop variables, e.g. for (int i = 0; ...) + +```c +int a; +int c; + +if (foo) { + int b; + + c = get_value(); + usevalue(c); +} + +if (bar) { + c = get_value(); + useit(c); +} +``` + +- do not mix function invocations and variable definitions. + + wrong: + +```c +{ + int a = foo(); + int b = 7; +} +``` + + right: +```c +{ + int a; + int b = 7; + + a = foo(); +} +``` + + There are exceptions here, e.g. `tp_libinput_context()`, + `litest_current_device()` + +- 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. diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5340337 --- /dev/null +++ b/COPYING @@ -0,0 +1,34 @@ +Copyright © 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/master/include/linux/input.h diff --git a/README.md b/README.md new file mode 100644 index 0000000..9872a4c --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +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 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/master/tools/libinput-debug-events.c +- A GTK application that draws cursor/touch/tablet positions: https://gitlab.freedesktop.org/libinput/libinput/tree/master/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/master/COPYING) +file for the full license information. + +About +----- + +Documentation generated by from git commit [__GIT_VERSION__](https://gitlab.freedesktop.org/libinput/libinput/commit/__GIT_VERSION__) diff --git a/completion/zsh/_libinput b/completion/zsh/_libinput new file mode 100644 index 0000000..49179dc --- /dev/null +++ b/completion/zsh/_libinput @@ -0,0 +1,199 @@ +#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" + "measure:Measure various properties of devices" + "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-click-method=[Set the desired click method]:click-method:(none clickfinger buttonareas)' \ + '--set-scroll-method=[Set the desired scroll method]:scroll-method:(none twofinger edge button)' \ + '--set-scroll-button=[Set the button to the given button code]' \ + '--set-profile=[Set pointer acceleration profile]:accel-profile:(adaptive flat)' \ + '--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 \ + ))' \ + + '(tap-to-click)' \ + '--enable-tap[Enable tap-to-click]' \ + '--disable-tap[Disable tap-to-click]' \ + + '(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]' \ + + '(natural-scrolling)' \ + '--enable-natural-scrolling[Enable natural scrolling]' \ + '--disable-natural-scrolling[Disable natural scrolling]' \ + + '(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]' \ + + '(dwt)' \ + '--enable-dwt[Enable disable-while-typing]' \ + '--disable-dwt[Disable enable-while-typing]' +} + +(( $+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_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_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=}'[Speficy 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]' \ + '*::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 diff --git a/completion/zsh/meson.build b/completion/zsh/meson.build new file mode 100644 index 0000000..2d4edcd --- /dev/null +++ b/completion/zsh/meson.build @@ -0,0 +1,12 @@ +zshcompletiondir = get_option('zshcompletiondir') +if zshcompletiondir == '' + zshcompletiondir = join_paths(get_option('datadir'), 'zsh', 'site-functions') +endif + +if zshcompletiondir != 'no' + install_data( + '_libinput', + install_dir: zshcompletiondir, + install_mode: 'rw-r--r--', + ) +endif diff --git a/doc/api/libinput.doxygen.in b/doc/api/libinput.doxygen.in new file mode 100644 index 0000000..0dffbbd --- /dev/null +++ b/doc/api/libinput.doxygen.in @@ -0,0 +1,33 @@ +PROJECT_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@" +FILTER_PATTERNS = *.h *.dox +IMAGE_PATH = "@builddir@" +GENERATE_HTML = YES +HTML_OUTPUT = api +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 + +HTML_HEADER = "@builddir@/header.html" +HTML_FOOTER = "@builddir@/footer.html" +HTML_EXTRA_STYLESHEET = "@builddir@/bootstrap.css" \ + "@builddir@/customdoxygen.css" \ + "@builddir@/libinputdoxygen.css" diff --git a/doc/api/mainpage.dox b/doc/api/mainpage.dox new file mode 100644 index 0000000..d843050 --- /dev/null +++ b/doc/api/mainpage.dox @@ -0,0 +1,135 @@ +/** +@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 by from git commit [__GIT_VERSION__](https://gitlab.freedesktop.org/libinput/libinput/commit/__GIT_VERSION__) + +*/ diff --git a/doc/api/meson.build b/doc/api/meson.build new file mode 100644 index 0000000..7eac152 --- /dev/null +++ b/doc/api/meson.build @@ -0,0 +1,80 @@ +prg_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 + +doxygen_version_cmd = run_command(doxygen.path(), '--version') +if doxygen_version_cmd.returncode() != 0 + error('Command "doxygen --version" failed.') +endif +doxygen_version = doxygen_version_cmd.stdout() +if doxygen_version.version_compare('< 1.8.3') + error('doxygen needs to be at least version 1.8.3 (have @0@)'.format(doxygen_version)) +endif +grep = find_program('grep') +dot_version_cmd = run_command(dot.path(), '-V') +if dot_version_cmd.returncode() != 0 + error('Command "dot -V" failed.') +endif +# dot -V output is (to stderr): +# dot - graphviz version 2.38.0 (20140413.2041) +dot_version = dot_version_cmd.stderr().split(' ')[4] +if dot_version.version_compare('< 2.26') + error('Graphviz dot needs to be at least version 2.26 (have @0@)'.format(dot_version)) +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 + join_paths(meson.source_root(), 'src', 'libinput.h'), + # style files + 'style/header.html', + 'style/footer.html', + 'style/customdoxygen.css', + 'style/bootstrap.css', + 'style/libinputdoxygen.css', +) + +config_noop = configuration_data() +# Set a dummy replacement to silence meson warnings: +# meson.build:487: WARNING: Got an empty configuration_data() object and +# found no substitutions in the input file 'foo'. If you +# want to copy a file to the build dir, use the 'copy:' +# keyword argument added in 0.47.0 +config_noop.set('dummy', 'dummy') + +doxyfiles = [] +foreach f : src_doxygen + df = configure_file(input: f, + output: '@PLAINNAME@', + configuration : config_noop) + 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 : [ '.' ], + command : [ doxygen, doxyfile ], + install : false, + depends: [ mainpage ], + build_by_default : true) diff --git a/doc/api/page-hierarchy.dox b/doc/api/page-hierarchy.dox new file mode 100644 index 0000000..f59a720 --- /dev/null +++ b/doc/api/page-hierarchy.dox @@ -0,0 +1,7 @@ +/** + +@page Tablets + +- @subpage tablet serial numbers + +*/ diff --git a/doc/api/style/LICENSE b/doc/api/style/LICENSE new file mode 100644 index 0000000..5d618ad --- /dev/null +++ b/doc/api/style/LICENSE @@ -0,0 +1,229 @@ +These 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. diff --git a/doc/api/style/bootstrap.css b/doc/api/style/bootstrap.css new file mode 100644 index 0000000..05dc925 --- /dev/null +++ b/doc/api/style/bootstrap.css @@ -0,0 +1,7500 @@ +@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; +} diff --git a/doc/api/style/customdoxygen.css b/doc/api/style/customdoxygen.css new file mode 100644 index 0000000..9395d8b --- /dev/null +++ b/doc/api/style/customdoxygen.css @@ -0,0 +1,254 @@ +h1, .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; +} diff --git a/doc/api/style/footer.html b/doc/api/style/footer.html new file mode 100644 index 0000000..f2fa204 --- /dev/null +++ b/doc/api/style/footer.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + diff --git a/doc/api/style/header.html b/doc/api/style/header.html new file mode 100644 index 0000000..cb1c1b1 --- /dev/null +++ b/doc/api/style/header.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + $projectname: $title + $title + + + $treeview + $search + $mathjax + + $extrastylesheet + + + + + +
+
+
+
+
+
+ diff --git a/doc/api/style/libinputdoxygen.css b/doc/api/style/libinputdoxygen.css new file mode 100644 index 0000000..ec5d0f7 --- /dev/null +++ b/doc/api/style/libinputdoxygen.css @@ -0,0 +1,120 @@ +@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; +} diff --git a/doc/button-debouncing-state-machine.svg b/doc/button-debouncing-state-machine.svg new file mode 100644 index 0000000..53c0830 --- /dev/null +++ b/doc/button-debouncing-state-machine.svg @@ -0,0 +1,3 @@ + + +

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.

[Not supported by viewer]

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.
[Not supported by viewer]
button
press
button<br>press
button
release
button<br>release
DISABLED
DISABLED
button
press
button<br>press
notify
button
press
[Not supported by viewer]
button
release
button<br>release
notify
button
release
[Not supported by viewer]
other
button
other<br>button
IS_UP
IS_UP
button
press
button<br>press
IS_DOWN_WAITING
IS_DOWN_WAITING
IS_UP_DELAYING
IS_UP_DELAYING
notify
button
release
[Not supported by viewer]
notify
button
press
[Not supported by viewer]
IS_UP
IS_UP
notify
button
release
[Not supported by viewer]
IS_DOWN_DETECTING_SPURIOUS
IS_DOWN_DETECTING_SPURIOUS
spurious
enabled?
spurious<br>enabled?
no
no
yes
yes
set
timer
set<br>timer
notify
button
press
[Not supported by viewer]
other
button
other<br>button
enable
spurious
enable<br>spurious
IS_DOWN
IS_DOWN
IS_DOWN
IS_DOWN
button
release
button<br>release
set
timer
set<br>timer
set short
timer
set short<br>timer
other
button
other<br>button
IS_UP_DELAYING_SPURIOUS
IS_UP_DELAYING_SPURIOUS
IS_UP_DETECTING_SPURIOUS
IS_UP_DETECTING_SPURIOUS
button
press
button<br>press
timeout
short
timeout<br>short
other
button
other<br>button
timeout
timeout
button
release
button<br>release
timeout
short
timeout<br>short
other
button
other<br>button
timeout
timeout
timeout
timeout
other
button
other<br>button
timeout
timeout
other
button
other<br>button
IS_DOWN_DELAYING
IS_DOWN_DELAYING
notify
button
press
[Not supported by viewer]
timeout
timeout
button
press
button<br>press
other
button
other<br>button
notify
button
release
[Not supported by viewer]
notify
button
release
[Not supported by viewer]
timeout
short
timeout<br>short
button
press
button<br>press
other
button
other<br>button
IS_UP_WAITING
IS_UP_WAITING
button
release
button<br>release
timeout
timeout
other
button
other<br>button
\ No newline at end of file diff --git a/doc/button-debouncing-wave-diagram.txt b/doc/button-debouncing-wave-diagram.txt new file mode 100644 index 0000000..fe637af --- /dev/null +++ b/doc/button-debouncing-wave-diagram.txt @@ -0,0 +1,50 @@ +# 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', + }, +} diff --git a/doc/middle-button-emulation.svg b/doc/middle-button-emulation.svg new file mode 100644 index 0000000..338af38 --- /dev/null +++ b/doc/middle-button-emulation.svg @@ -0,0 +1,1315 @@ + + + + + + + + + +
+
+ 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] +
+
+
+
diff --git a/doc/touchpad-edge-scrolling-state-machine.svg b/doc/touchpad-edge-scrolling-state-machine.svg new file mode 100644 index 0000000..7a82d88 --- /dev/null +++ b/doc/touchpad-edge-scrolling-state-machine.svg @@ -0,0 +1,262 @@ + + + + + + + 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 + + + diff --git a/doc/touchpad-softbutton-state-machine.svg b/doc/touchpad-softbutton-state-machine.svg new file mode 100644 index 0000000..ffa17a2 --- /dev/null +++ b/doc/touchpad-softbutton-state-machine.svg @@ -0,0 +1,386 @@ + + + + + + + + + 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 + + + diff --git a/doc/touchpad-tap-state-machine.svg b/doc/touchpad-tap-state-machine.svg new file mode 100644 index 0000000..5dd1036 --- /dev/null +++ b/doc/touchpad-tap-state-machine.svg @@ -0,0 +1,1508 @@ + + + + + + + + + + + + + + IDLE + + + + + TOUCH + + + + + first + + finger down + + + + + + + finger up + + + + + + + button 1 + + press + + + + + timeout + + + + + + + move > + + threshold + + + + + + + second + + finger down + + + + + + + TOUCH_2 + + + + + second + + finger up + + + + + + + button 2 + + press + + + + + move > + + threshold + + + + + timeout + + + + + + + + + button 1 + + release + + + + + button 2 + + release + + + + + + + + + + + TAPPED + + + + + timeout + + + + + + + first + + finger down + + + + + + + DRAGGING + + + + + first + + finger up + + + + + btn1 + + release + + + + + + + + + + + IDLE + + + + + third + + finger down + + + + + + + TOUCH_3 + + + + + + + button 3 + + press + + + + + button 3 + + release + + + + + + + move > + + threshold + + + + + + + IDLE + + + + + timeout + + + + + + + first + + finger up + + + + + + + IDLE + + + + + fourth + + finger down + + + + + + + + + DRAGGING_OR_DOUBLETAP + + + + + + + timeout + + + + + + + first + + finger up + + + + + + + button 1 + + release + + + + + button 1 + + press + + + + + btn1 + + release + + + + + + + second + + finger down + + + + + + + move > + + threshold + + + + + + + + + HOLD + + + + + first + + finger up + + + + + + + + + second + + finger down + + + + + + + + + TOUCH_2_HOLD + + + + + second + + finger up + + + + + + + first + + finger up + + + + + + + + + third + + finger down + + + + + + + + + + + TOUCH_3_HOLD + + + + + + + fourth + + finger down + + + + + DEAD + + + + + + + + + + + any finger up + + + + + fourth + + finger up + + + + + any finger up + + + + + + + + + yes + + + + + any finger up + + + + + + + + + + + + + IDLE + + + + + if finger + + count == 0 + + + + + + + + + + + second + + finger up + + + + + DRAGGING_2 + + + + + + + + + first + + finger up + + + + + + + + + + + second + + finger down + + + + + + + + + + + third + + finger down + + + + + + + btn1 + + release + + + + + + + phys + + button + + press + + + + + + + + + + + + + + + + + phys + + button + + press + + + + + + + button 1 + + release + + + + + + + + + + + + + + + DRAGGING_WAIT + + + + + timeout + + + + + + + + + + + first + + finger down + + + + + + + TOUCH_TOUCH + + + + + TOUCH_IDLE + + + + + + + + + + + + + TOUCH_DEAD + + + + + + + + + + + + + TOUCH_DEAD + + + + + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_TOUCH + + + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_TOUCH + + + + + + + that finger + + TOUCH_IDLE + + + + + + + TOUCH_DEAD + + + + + + + + + + + that finger + + TOUCH_IDLE + + + + + + + + + no + + + + + TOUCH_TOUCH + + + + + + + TOUCH_IDLE + + + + + TOUCH_TOUCH + + + + + + + TOUCH_DEAD + + + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_TOUCH + + + + + TOUCH_TOUCH + + + + + TOUCH_IDLE + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_TOUCH + + + + + + + TOUCH_IDLE + + + + + + + TOUCH_TOUCH + + + + + + + that finger + + TOUCH_IDLE + + + + + + + TOUCH_DEAD + + + + + + + TOUCH_DEAD + + + + + TOUCH_DEAD + + + + + TOUCH_DEAD + + + + + + + TOUCH_DEAD + + + + + + + TOUCH_DEAD + + + + + + + that finger state == + + TOUCH_TOUCH + + + + + TOUCH_DEAD + + + + + + + TOUCH_DEAD + + + + + TOUCH_DEAD + + + + + first + + finger down + + + + + MULTITAP + + + + + + + + + timeout + + + + + + + + + IDLE + + + + + + + + + + + MULTITAP_DOWN + + + + + first + + finger up + + + + + + + timeout + + + + + second + + finger down + + + + + move > + + threshold + + + + + + + + + + + TOUCH_TOUCH + + + + + + + TOUCH_IDLE + + + + + phys + + button + + press + + + + + + + + + + + DRAGGING_OR_TAP + + + + + first + + finger up + + + + + + + timeout + + + + + + + + + move > + + threshold + + + + + + + + + + + + + + + TOUCH_IDLE + + + + + + + + + + + +
+
+ drag lock
+ enabled?
+
+
+
+ + [Not supported by viewer] +
+
+ + + + + +
+
+ no
+
+
+ + no +
+
+ + + + + +
+
+ yes
+
+
+
+ + yes<br> +
+
+ + + + thumb + + + + + + + TOUCH_DEAD + + + + + + + + + + + TOUCH_2_RELEASE + + + + + second + + finger up + + + + + + + timeout + + + + + + + move > + + threshold + + + + + + + + + + + + + first + + finger down + + + + + + + + + TOUCH_IDLE + + + + + + + first + + finger up + + + + + + + + + second + + finger down + + + + + + + TOUCH_DEAD + + + + + TOUCH_DEAD + + + + + + + + + + + + + +
+
+ drag
+ disabled?
+
+
+
+ + drag<br>disabled?<br> +
+
+ + + + + +
+
+ no
+
+
+ + no +
+
+ + + + + +
+
+ yes
+
+
+ + yes +
+
+ + + + palm + + + + + + + either finger + + palm + + + + + + + remaining + +  finger + + palm + + + + + + + any finger + + palm + + + + + + + + + that finger + + TOUCH_DEAD + + + + + + + that finger + + TOUCH_DEAD + + + + + + + + + + + palm + + + + + + + + + + + any finger + + palm + + + + + + + that finger + + TOUCH_DEAD + + + + + + + + + TOUCH_DEAD + + + + + + + + + palm + + + + + TOUCH_DEAD + + + + + + + + + + + any finger + + palm + + + + + + + + + that finger + + TOUCH_DEAD + + + + + + + either finger + + palm + + + + + + + that finger + + TOUCH_DEAD + + + + + + + + + palm + + + + + + + + + TOUCH_DEAD + + + + + + + + + any finger + + palm + + + + + + + that finger + + TOUCH_DEAD + + + + + + + + + + + palm + + + + + + + + + + + + + button 1 + + press + + + + + + + + + + + TOUCH_DEAD + + + + + + + + + + + + + btn1 + + release + + + + + + + MULTITAP_PALM + + + + + first + + finger down + + + + + + + TOUCH_TOUCH + + + + + + + + + timeout + + + + + + + + + phys + + button + + press + + + + + +
+
diff --git a/doc/user/404.rst b/doc/user/404.rst new file mode 100644 index 0000000..811fb77 --- /dev/null +++ b/doc/user/404.rst @@ -0,0 +1,9 @@ +:orphan: + +=== +404 +=== + +This page has permanently moved, probably to `<@TARGET@>`_ + +This placeholder page will be removed soon. diff --git a/doc/user/absolute-axes.rst b/doc/user/absolute-axes.rst new file mode 100644 index 0000000..24a95f7 --- /dev/null +++ b/doc/user/absolute-axes.rst @@ -0,0 +1,144 @@ +.. _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. diff --git a/doc/user/absolute-coordinate-ranges.rst b/doc/user/absolute-coordinate-ranges.rst new file mode 100644 index 0000000..db61376 --- /dev/null +++ b/doc/user/absolute-coordinate-ranges.rst @@ -0,0 +1,134 @@ +.. _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 touchpad-edge-detector +#. trim the udev match rule to something sensible +#. replace the resolution with the calculated resolution based on physical settings +#. test locally +#. send a patch to the systemd project + +Detailed explanations are below. + +`libevdev `_ provides a tool +called **touchpad-edge-detector** that allows measuring the touchpad's input +ranges. Run the tool as root against the device node of your touchpad device +and repeatedly move a finger around the whole outside area of the +touchpad. Then control+c the process and note the output. +An example output is below: + + +:: + + $> sudo touchpad-edge-detector /dev/input/event4 + Touchpad SynPS/2 Synaptics TouchPad on /dev/input/event4 + Move one finger around the touchpad to detect the actual edges + Kernel says: x [1024..3112], y [2024..4832] + Touchpad sends: x [2445..4252], y [3464..4071] + + Touchpad size as listed by the kernel: 49x66mm + Calculate resolution as: + x axis: 2088/ + y axis: 2808/ + + Suggested udev rule: + # + evdev:name:SynPS/2 Synaptics TouchPad:dmi:bvnLENOVO:bvrGJET72WW(2.22):bd02/21/2014:svnLENOVO:pn20ARS25701:pvrThinkPadT440s:rvnLENOVO:rn20ARS25701:rvrSDK0E50512STD:cvnLENOVO:ct10:cvrNotAvailable:* + EVDEV_ABS_00=2445:4252: + EVDEV_ABS_01=3464:4071: + EVDEV_ABS_35=2445:4252: + EVDEV_ABS_36=3464:4071: + + + +Note the discrepancy between the coordinate range the kernels advertises vs. +what the touchpad sends. +To fix the advertised ranges, the udev rule should be taken and trimmed +before being sent to the `systemd project `_. +An example commit can be found +`here `_. + +In most cases the match can and should be trimmed to the system vendor (svn) +and the product version (pvr), with everything else replaced by a wildcard +(*). In this case, a Lenovo T440s, a suitable match string would be: +:: + + evdev:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*pvrThinkPadT440s* + + +.. 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=2445:4252:42 + +or, if the range is correct but the resolution is wrong + +:: + + # axis number=::resolution + EVDEV_ABS_00=::42 + + +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 `_. diff --git a/doc/user/architecture.rst b/doc/user/architecture.rst new file mode 100644 index 0000000..7fb167a --- /dev/null +++ b/doc/user/architecture.rst @@ -0,0 +1,327 @@ +.. _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 diff --git a/doc/user/building.rst b/doc/user/building.rst new file mode 100644 index 0000000..5099526 --- /dev/null +++ b/doc/user/building.rst @@ -0,0 +1,265 @@ +.. _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. + +.. _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 --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 --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 --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. + +:: + + $> ls -l /usr/lib64/libinput.* + -rwxr-xr-x 1 root root 946 Apr 28 2015 /usr/lib64/libinput.la + lrwxrwxrwx 1 root root 19 Feb 1 15:12 /usr/lib64/libinput.so -> libinput.so.10.13.0 + lrwxrwxrwx 1 root root 19 Feb 1 15:12 /usr/lib64/libinput.so.10 -> libinput.so.10.13.0 + -rwxr-xr-x 1 root root 204992 Feb 1 15:12 /usr/lib64/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 packman -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_RPMS** 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. + +.. _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 --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') + +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. diff --git a/doc/user/button-debouncing.rst b/doc/user/button-debouncing.rst new file mode 100644 index 0000000..47be1d2 --- /dev/null +++ b/doc/user/button-debouncing.rst @@ -0,0 +1,56 @@ + +.. _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. diff --git a/doc/user/clickpad-softbuttons.rst b/doc/user/clickpad-softbuttons.rst new file mode 100644 index 0000000..781aad9 --- /dev/null +++ b/doc/user/clickpad-softbuttons.rst @@ -0,0 +1,143 @@ +.. _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. The location of the fingers does not matter and there are no +software-defined button areas. + +.. 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. diff --git a/doc/user/conf.py.in b/doc/user/conf.py.in new file mode 100644 index 0000000..8ec0ac5 --- /dev/null +++ b/doc/user/conf.py.in @@ -0,0 +1,193 @@ +# -*- 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 = '2018, 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 = None + +# 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 ') +} + +# -- 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) diff --git a/doc/user/configuration.rst b/doc/user/configuration.rst new file mode 100644 index 0000000..1b1686e --- /dev/null +++ b/doc/user/configuration.rst @@ -0,0 +1,162 @@ +.. _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. + +------------------------------------------------------------------------------ +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 the touchpad is disabled, the touchpad is enabled 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. + +------------------------------------------------------------------------------ +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. +This is currently only available on trackpoints which may be used sideways +or upside-down. The angle can be freely chosen but not all devices support +rotation other than 0, 90, 180, or 270 degrees. Rotation is off (0 degrees) +by default. diff --git a/doc/user/contributing.rst b/doc/user/contributing.rst new file mode 100644 index 0000000..54d69e4 --- /dev/null +++ b/doc/user/contributing.rst @@ -0,0 +1,173 @@ + +.. _contributing: + +============================================================================== +Contributing to libinput +============================================================================== + +Contributions to libinput are always welcome. Please see the steps below for +details on how to create merge requests, correct git formatting and other +topics: + +.. contents:: + :local: + +Questions regarding this process can be asked on ``#wayland-devel`` on +freenode or on the `wayland-devel@lists.freedesktop.org +`_ mailing +list. + +------------------------------------------------------------------------------ +Submitting Code +------------------------------------------------------------------------------ + +Any patches should be sent via a Merge Request (see the `GitLab docs +`_) +in the `libinput GitLab instance hosted by freedesktop.org +`_. + +To submit a merge request, you need to + +- `Register an account `_ in + the freedesktop.org GitLab instance. +- `Fork libinput `_ + into your username's namespace +- Get libinput's main repository: :: + + git clone https://gitlab.freedesktop.org/libinput/libinput.git + +- Add the forked git repository to your remotes (replace ``USERNAME`` + with your username): :: + + cd /path/to/libinput.git + git remote add gitlab git@gitlab.freedesktop.org:USERNAME/libinput.git + git fetch gitlab + +- Push your changes to your fork: :: + + git push gitlab BRANCHNAME + +- Submit a merge request. The URL for a merge request is: :: + + https://gitlab.freedesktop.org/USERNAME/libinput/merge_requests + + Select your branch name to merge and ``libinput/libinput`` ``master`` as target branch. + +------------------------------------------------------------------------------ +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. + +------------------------------------------------------------------------------ +Commit Messages +------------------------------------------------------------------------------ + +Read `on commit messages `_ +as a general guideline on what commit messages should contain. + +Commit messages **should** contain a **Signed-off-by** line with your name +and email address. If you're not the patch's original author, you should +also gather S-o-b's by them (and/or whomever gave the patch to you.) The +significance of this is that it certifies that you created the patch, that +it was created under an appropriate open source license, or provided to you +under those terms. This lets us indicate a chain of responsibility for the +copyright status of the code. + +We won't reject patches that lack S-o-b, but it is strongly recommended. + +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. + +------------------------------------------------------------------------------ +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. + +------------------------------------------------------------------------------ +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. diff --git a/doc/user/development.rst b/doc/user/development.rst new file mode 100644 index 0000000..adf5341 --- /dev/null +++ b/doc/user/development.rst @@ -0,0 +1,53 @@ +.. _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 + +.. _hacking_on_libinput: + +------------------------------------------------------------------------------ +Hacking on libinput +------------------------------------------------------------------------------ + +.. toctree:: + :maxdepth: 1 + + contributing.rst + architecture + test-suite.rst + pointer-acceleration.rst + device-configuration-via-udev.rst diff --git a/doc/user/device-configuration-via-udev.rst b/doc/user/device-configuration-via-udev.rst new file mode 100644 index 0000000..735a041 --- /dev/null +++ b/doc/user/device-configuration-via-udev.rst @@ -0,0 +1,266 @@ +.. _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. :: + + ACTION=="add|change", 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. :: + + ACTION=="add|change", KERNEL=="event[0-9]*", ENV{ID_VENDOR_ID}=="012a", \ + ENV{ID_MODEL_ID}=="034b", ENV{ID_INPUT_TOUCHPAD}="", ENV{ID_INPUT_TABLET}="1" + + + +.. _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. + + +.. _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 +continuos 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 avaialable in: https://wayland.freedesktop.org/libinput/doc/ diff --git a/doc/user/device-quirks.rst b/doc/user/device-quirks.rst new file mode 100644 index 0000000..0a055a3 --- /dev/null +++ b/doc/user/device-quirks.rst @@ -0,0 +1,182 @@ +.. _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 containting 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 ``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=reliable + +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 supported device quirks +------------------------------------------------------------------------------ + +This list is a guide for developers to ease the process of submitting +patches upstream. This section shows device quirks supported 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 +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. +AttrTouchPressureRange=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. +AttrLidSwitchReliability=reliable|write_open + Indicates the reliability of the lid switch. This is a string enum. Do not + use "reliable" for any specific device. Very few devices need this, if in + doubt do not set. See :ref:`switches_lid` for details. +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. +AttrEventCodeDisable=EV_ABS;BTN_STYLUS;EV_KEY:0x123; + Disables the evdev event type/code tuples on the device. 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. +AttrPointingStickIntegration=internal|external + Indicates the integration of the pointing stick. This is a string enum. + Only needed for external pointing sticks. These are rare. diff --git a/doc/user/dot/evemu.gv b/doc/user/dot/evemu.gv new file mode 100644 index 0000000..85e93f3 --- /dev/null +++ b/doc/user/dot/evemu.gv @@ -0,0 +1,19 @@ +digraph stack +{ + compound=true; + rankdir="LR"; + node [ + shape="box"; + ] + + kernel [label="Kernel"]; + + libinput; + xserver [label="X Server"]; + + kernel -> libinput + libinput -> xserver + + kernel -> evemu + evemu -> stdout +} diff --git a/doc/user/dot/libinput-record.gv b/doc/user/dot/libinput-record.gv new file mode 100644 index 0000000..a6ece21 --- /dev/null +++ b/doc/user/dot/libinput-record.gv @@ -0,0 +1,20 @@ +digraph 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 +} diff --git a/doc/user/dot/libinput-stack-gnome.gv b/doc/user/dot/libinput-stack-gnome.gv new file mode 100644 index 0000000..fd9a737 --- /dev/null +++ b/doc/user/dot/libinput-stack-gnome.gv @@ -0,0 +1,30 @@ +digraph 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 +} diff --git a/doc/user/dot/libinput-stack-wayland.gv b/doc/user/dot/libinput-stack-wayland.gv new file mode 100644 index 0000000..7ef6746 --- /dev/null +++ b/doc/user/dot/libinput-stack-wayland.gv @@ -0,0 +1,25 @@ +digraph 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"]; +} diff --git a/doc/user/dot/libinput-stack-xorg.gv b/doc/user/dot/libinput-stack-xorg.gv new file mode 100644 index 0000000..faa9448 --- /dev/null +++ b/doc/user/dot/libinput-stack-xorg.gv @@ -0,0 +1,29 @@ +digraph 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"]; +} diff --git a/doc/user/dot/seats-sketch-libinput.gv b/doc/user/dot/seats-sketch-libinput.gv new file mode 100644 index 0000000..b021656 --- /dev/null +++ b/doc/user/dot/seats-sketch-libinput.gv @@ -0,0 +1,29 @@ +digraph 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 +} diff --git a/doc/user/dot/seats-sketch.gv b/doc/user/dot/seats-sketch.gv new file mode 100644 index 0000000..3647cef --- /dev/null +++ b/doc/user/dot/seats-sketch.gv @@ -0,0 +1,51 @@ +digraph 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 +} diff --git a/doc/user/faqs.rst b/doc/user/faqs.rst new file mode 100644 index 0000000..a6f5dee --- /dev/null +++ b/doc/user/faqs.rst @@ -0,0 +1,326 @@ +.. _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_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 commmon 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 "timer offset negative" warning? +------------------------------------------------------------------------------ + +libinput relies on the caller to call **libinput_dispatch()** whenever data is +available on the epoll-fd. Doing so will process the state of all devices +and can trigger some timers to be set (e.g. palm detection, tap-to-click, +disable-while-typing, etc.). Internally, libinput's time offsets are always +based on the event time of the triggering event. + +For example, a touch event with time T may trigger a timer for the time T + +180ms. When setting a timer, libinput checks the wall clock time to ensure +that this time T + offset is still in the future. If not, the warning is +logged. + +When this warning appears, it simply means that too much time has passed +between the event occurring (and the epoll-fd triggering) 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 (e.g. palms are not +detected as they should be). + +.. _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. Until 2018 the most common use +of libinput is with the X.Org X server through the xf86-input-libinput +driver. As Wayland compositors become more commonplace they will eventually +overtake X. + +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. diff --git a/doc/user/features.rst b/doc/user/features.rst new file mode 100644 index 0000000..55c9cbb --- /dev/null +++ b/doc/user/features.rst @@ -0,0 +1,28 @@ +.. _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 capabilties. +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 + tablet-support.rst + switches.rst + touchpad-pressure.rst + trackpoints.rst diff --git a/doc/user/gestures.rst b/doc/user/gestures.rst new file mode 100644 index 0000000..4213c28 --- /dev/null +++ b/doc/user/gestures.rst @@ -0,0 +1,151 @@ +.. _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 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_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. diff --git a/doc/user/git_version.py.in b/doc/user/git_version.py.in new file mode 100644 index 0000000..c191f17 --- /dev/null +++ b/doc/user/git_version.py.in @@ -0,0 +1,5 @@ +def get_git_version(): + return "__GIT_VERSION__"[:7] + +def get_git_version_full(): + return "__GIT_VERSION__" diff --git a/doc/user/index.rst b/doc/user/index.rst new file mode 100644 index 0000000..aaa84d7 --- /dev/null +++ b/doc/user/index.rst @@ -0,0 +1,71 @@ + +.. toctree:: + :maxdepth: 2 + :hidden: + + what-is-libinput + features + configuration + building + faqs + reporting-bugs + troubleshooting + development + + +++++++++++++++++++++++++++++++ +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: + http://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| diff --git a/doc/user/meson.build b/doc/user/meson.build new file mode 100644 index 0000000..f9904f1 --- /dev/null +++ b/doc/user/meson.build @@ -0,0 +1,194 @@ +# 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 + +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()) + +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'], + [ '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-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-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', + 'contributing.rst', + 'device-configuration-via-udev.rst', + 'device-quirks.rst', + 'faqs.rst', + 'gestures.rst', + 'index.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', + 'features.rst', + 'development.rst', + 'troubleshooting.rst', + 'configuration.rst', +) + +config_noop = configuration_data() +# Set a dummy replacement to silence meson warnings: +# meson.build:487: WARNING: Got an empty configuration_data() object and +# found no substitutions in the input file 'foo'. If you +# want to copy a file to the build dir, use the 'copy:' +# keyword argument added in 0.47.0 +config_noop.set('dummy', 'dummy') +src_sphinx = [] +foreach f : src_rst + sf = configure_file(input: f, + output: '@PLAINNAME@', + configuration : config_noop) + src_sphinx += [ sf ] +endforeach + + +# 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', + meson.current_build_dir(), sphinx_output_dir], + build_by_default : true) diff --git a/doc/user/middle-button-emulation.rst b/doc/user/middle-button-emulation.rst new file mode 100644 index 0000000..e1f74cd --- /dev/null +++ b/doc/user/middle-button-emulation.rst @@ -0,0 +1,35 @@ +.. _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. diff --git a/doc/user/normalization-of-relative-motion.rst b/doc/user/normalization-of-relative-motion.rst new file mode 100644 index 0000000..99c62f8 --- /dev/null +++ b/doc/user/normalization-of-relative-motion.rst @@ -0,0 +1,92 @@ +.. _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. + +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. diff --git a/doc/user/palm-detection.rst b/doc/user/palm-detection.rst new file mode 100644 index 0000000..9e469b9 --- /dev/null +++ b/doc/user/palm-detection.rst @@ -0,0 +1,210 @@ +.. _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:`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. + +Each side edge exclusion zone is divided into a top part and a bottom part. +A touch starting in the top part of 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 top part of the exclusion zone. Despite being a +tapping motion, it does not generate an emulated button event. Touch 'D' +likewise occurs within the exclusion zone but in the bottom half. libinput +will generate a button event for this touch. + +.. 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 `. + +Disable-while-typing can be enabled and disabled by calling +**libinput_device_config_dwt_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. diff --git a/doc/user/pointer-acceleration.rst b/doc/user/pointer-acceleration.rst new file mode 100644 index 0000000..fafa4dd --- /dev/null +++ b/doc/user/pointer-acceleration.rst @@ -0,0 +1,198 @@ +.. _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 two profiles: "adaptive" and "flat". 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`). 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 touchpad 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. diff --git a/doc/user/reporting-bugs.rst b/doc/user/reporting-bugs.rst new file mode 100644 index 0000000..ab22c5c --- /dev/null +++ b/doc/user/reporting-bugs.rst @@ -0,0 +1,344 @@ +.. _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. +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 output of ``libinput measure trackpoint-range`` +- the sensitivity of the trackpoint (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 likelyhood 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. diff --git a/doc/user/scrolling.rst b/doc/user/scrolling.rst new file mode 100644 index 0000000..c828a3d --- /dev/null +++ b/doc/user/scrolling.rst @@ -0,0 +1,142 @@ +.. _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). + +.. _scroll_sources: + +------------------------------------------------------------------------------ +Scroll sources +------------------------------------------------------------------------------ + +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 diff --git a/doc/user/seats.rst b/doc/user/seats.rst new file mode 100644 index 0000000..eff5d1a --- /dev/null +++ b/doc/user/seats.rst @@ -0,0 +1,85 @@ +.. _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. diff --git a/doc/user/svg/button-debouncing-wave-diagram.svg b/doc/user/svg/button-debouncing-wave-diagram.svg new file mode 100644 index 0000000..7c43c94 --- /dev/null +++ b/doc/user/svg/button-debouncing-wave-diagram.svg @@ -0,0 +1,4 @@ + + + +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 \ No newline at end of file diff --git a/doc/user/svg/button-scrolling.svg b/doc/user/svg/button-scrolling.svg new file mode 100644 index 0000000..476c9c7 --- /dev/null +++ b/doc/user/svg/button-scrolling.svg @@ -0,0 +1,292 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C + V + B + N + M + J + H + G + F + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/clickfinger-distance.svg b/doc/user/svg/clickfinger-distance.svg new file mode 100644 index 0000000..ac659cf --- /dev/null +++ b/doc/user/svg/clickfinger-distance.svg @@ -0,0 +1,106 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/clickfinger.svg b/doc/user/svg/clickfinger.svg new file mode 100644 index 0000000..b92dcb4 --- /dev/null +++ b/doc/user/svg/clickfinger.svg @@ -0,0 +1,207 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/edge-scrolling.svg b/doc/user/svg/edge-scrolling.svg new file mode 100644 index 0000000..c768e80 --- /dev/null +++ b/doc/user/svg/edge-scrolling.svg @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/gesture-2fg-ambiguity.svg b/doc/user/svg/gesture-2fg-ambiguity.svg new file mode 100644 index 0000000..e4996ca --- /dev/null +++ b/doc/user/svg/gesture-2fg-ambiguity.svg @@ -0,0 +1,496 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Touch 1 + + + Touch 2 + + diff --git a/doc/user/svg/palm-detection.svg b/doc/user/svg/palm-detection.svg new file mode 100644 index 0000000..2849e26 --- /dev/null +++ b/doc/user/svg/palm-detection.svg @@ -0,0 +1,232 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + A + + B + + + C + D + + + + + diff --git a/doc/user/svg/pinch-gestures-softbuttons.svg b/doc/user/svg/pinch-gestures-softbuttons.svg new file mode 100644 index 0000000..959cb4f --- /dev/null +++ b/doc/user/svg/pinch-gestures-softbuttons.svg @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/pinch-gestures.svg b/doc/user/svg/pinch-gestures.svg new file mode 100644 index 0000000..4dca4cf --- /dev/null +++ b/doc/user/svg/pinch-gestures.svg @@ -0,0 +1,612 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + logicalcenter + initial scale (1.0) + current scale (> 1.0) + + logicalcenter + + + + + deltaangle + + diff --git a/doc/user/svg/ptraccel-linear.svg b/doc/user/svg/ptraccel-linear.svg new file mode 100644 index 0000000..d67e227 --- /dev/null +++ b/doc/user/svg/ptraccel-linear.svg @@ -0,0 +1,518 @@ + + + +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 + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/ptraccel-low-dpi.svg b/doc/user/svg/ptraccel-low-dpi.svg new file mode 100644 index 0000000..5e66f01 --- /dev/null +++ b/doc/user/svg/ptraccel-low-dpi.svg @@ -0,0 +1,3747 @@ + + + + +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 + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/ptraccel-touchpad.svg b/doc/user/svg/ptraccel-touchpad.svg new file mode 100644 index 0000000..0bae041 --- /dev/null +++ b/doc/user/svg/ptraccel-touchpad.svg @@ -0,0 +1,579 @@ + + + +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 + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/ptraccel-trackpoint.svg b/doc/user/svg/ptraccel-trackpoint.svg new file mode 100644 index 0000000..cdc3cf9 --- /dev/null +++ b/doc/user/svg/ptraccel-trackpoint.svg @@ -0,0 +1,211 @@ + + + +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 + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/software-buttons-conditions.svg b/doc/user/svg/software-buttons-conditions.svg new file mode 100644 index 0000000..9865648 --- /dev/null +++ b/doc/user/svg/software-buttons-conditions.svg @@ -0,0 +1,210 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/software-buttons-thumbpress.svg b/doc/user/svg/software-buttons-thumbpress.svg new file mode 100644 index 0000000..61e546f --- /dev/null +++ b/doc/user/svg/software-buttons-thumbpress.svg @@ -0,0 +1,107 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/software-buttons-visualized.svg b/doc/user/svg/software-buttons-visualized.svg new file mode 100644 index 0000000..a13f8ca --- /dev/null +++ b/doc/user/svg/software-buttons-visualized.svg @@ -0,0 +1,146 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + main area + right button + left button + middle + diff --git a/doc/user/svg/software-buttons.svg b/doc/user/svg/software-buttons.svg new file mode 100644 index 0000000..c0bc610 --- /dev/null +++ b/doc/user/svg/software-buttons.svg @@ -0,0 +1,151 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/swipe-gestures.svg b/doc/user/svg/swipe-gestures.svg new file mode 100644 index 0000000..a88f646 --- /dev/null +++ b/doc/user/svg/swipe-gestures.svg @@ -0,0 +1,512 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + logicalcenter + + + + + + + diff --git a/doc/user/svg/tablet-axes.svg b/doc/user/svg/tablet-axes.svg new file mode 100644 index 0000000..c0ce5b7 --- /dev/null +++ b/doc/user/svg/tablet-axes.svg @@ -0,0 +1,564 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + Distance + + + + + + + + + + Pressure + + + + + + + Tilt (angle) + + + + + diff --git a/doc/user/svg/tablet-cintiq24hd-modes.svg b/doc/user/svg/tablet-cintiq24hd-modes.svg new file mode 100644 index 0000000..f1be53e --- /dev/null +++ b/doc/user/svg/tablet-cintiq24hd-modes.svg @@ -0,0 +1,460 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + mode indicators + mode indicators + mode toggle buttons + + + + + + + + + + + + + + + + + + + + + + + mode toggle buttons + + + diff --git a/doc/user/svg/tablet-interfaces.svg b/doc/user/svg/tablet-interfaces.svg new file mode 100644 index 0000000..d64fe9f --- /dev/null +++ b/doc/user/svg/tablet-interfaces.svg @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pad buttons + + Pad buttons + Pad buttons + Pad ring + + + + Pad ring + Tool buttons + + Tool tip + + + diff --git a/doc/user/svg/tablet-intuos-modes.svg b/doc/user/svg/tablet-intuos-modes.svg new file mode 100644 index 0000000..74ef836 --- /dev/null +++ b/doc/user/svg/tablet-intuos-modes.svg @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + mode indicators + mode indicators + + mode toggle button + + diff --git a/doc/user/svg/tablet-left-handed.svg b/doc/user/svg/tablet-left-handed.svg new file mode 100644 index 0000000..ff73fd9 --- /dev/null +++ b/doc/user/svg/tablet-left-handed.svg @@ -0,0 +1,469 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + origin + origin + + + zero + + + + zero + + + diff --git a/doc/user/svg/tablet-out-of-bounds.svg b/doc/user/svg/tablet-out-of-bounds.svg new file mode 100644 index 0000000..83e5021 --- /dev/null +++ b/doc/user/svg/tablet-out-of-bounds.svg @@ -0,0 +1,271 @@ + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/tablet.svg b/doc/user/svg/tablet.svg new file mode 100644 index 0000000..7a9dda8 --- /dev/null +++ b/doc/user/svg/tablet.svg @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/tap-n-drag.svg b/doc/user/svg/tap-n-drag.svg new file mode 100644 index 0000000..5c84beb --- /dev/null +++ b/doc/user/svg/tap-n-drag.svg @@ -0,0 +1,810 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a) Tap + b) Hold down + c) Move + d) Reset finger, move (optional) + f) Tap to end (optional) + e) Release + diff --git a/doc/user/svg/thumb-detection.svg b/doc/user/svg/thumb-detection.svg new file mode 100644 index 0000000..bc74698 --- /dev/null +++ b/doc/user/svg/thumb-detection.svg @@ -0,0 +1,116 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/top-software-buttons.svg b/doc/user/svg/top-software-buttons.svg new file mode 100644 index 0000000..ab31124 --- /dev/null +++ b/doc/user/svg/top-software-buttons.svg @@ -0,0 +1,213 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/touchscreen-gestures.svg b/doc/user/svg/touchscreen-gestures.svg new file mode 100644 index 0000000..8452c7e --- /dev/null +++ b/doc/user/svg/touchscreen-gestures.svg @@ -0,0 +1,440 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/trackpoint-delta-illustration.svg b/doc/user/svg/trackpoint-delta-illustration.svg new file mode 100644 index 0000000..8423dfa --- /dev/null +++ b/doc/user/svg/trackpoint-delta-illustration.svg @@ -0,0 +1,126 @@ + + + +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 + + + + + + + + + + + + + + + + + diff --git a/doc/user/svg/twofinger-scrolling.svg b/doc/user/svg/twofinger-scrolling.svg new file mode 100644 index 0000000..7830c25 --- /dev/null +++ b/doc/user/svg/twofinger-scrolling.svg @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/user/switches.rst b/doc/user/switches.rst new file mode 100644 index 0000000..96155df --- /dev/null +++ b/doc/user/switches.rst @@ -0,0 +1,59 @@ +.. _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 +openend. + +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 physicall +open. libinput employs some heuristics to detect user input (specificially +typing) to re-enable the touchpad on those devices. + +.. _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. diff --git a/doc/user/t440-support.rst b/doc/user/t440-support.rst new file mode 100644 index 0000000..1fc6e1f --- /dev/null +++ b/doc/user/t440-support.rst @@ -0,0 +1,128 @@ +.. _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"). diff --git a/doc/user/tablet-debugging.rst b/doc/user/tablet-debugging.rst new file mode 100644 index 0000000..2676650 --- /dev/null +++ b/doc/user/tablet-debugging.rst @@ -0,0 +1,44 @@ +.. _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 `__. diff --git a/doc/user/tablet-support.rst b/doc/user/tablet-support.rst new file mode 100644 index 0000000..c9adb81 --- /dev/null +++ b/doc/user/tablet-support.rst @@ -0,0 +1,424 @@ +.. _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 20% or less of the pressure range + available to the tool. A pressure offset higher than 20% 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-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. + diff --git a/doc/user/tapping.rst b/doc/user/tapping.rst new file mode 100644 index 0000000..afce206 --- /dev/null +++ b/doc/user/tapping.rst @@ -0,0 +1,91 @@ +.. _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. 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. + +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. + +Also optional is a feature called "drag lock". With drag lock disabled, lifting +the finger will stop any drag process. When enabled, libinput will ignore a +finger up event during a drag process, provided the finger is set down again +within a 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 be 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 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`) diff --git a/doc/user/test-suite.rst b/doc/user/test-suite.rst new file mode 100644 index 0000000..29484b2 --- /dev/null +++ b/doc/user/test-suite.rst @@ -0,0 +1,243 @@ +.. _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 but not the ``libinput-test-suite``. +This CI 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 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. diff --git a/doc/user/timestamps.rst b/doc/user/timestamps.rst new file mode 100644 index 0000000..4c45007 --- /dev/null +++ b/doc/user/timestamps.rst @@ -0,0 +1,44 @@ + +.. _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. diff --git a/doc/user/tools.rst b/doc/user/tools.rst new file mode 100644 index 0000000..d470085 --- /dev/null +++ b/doc/user/tools.rst @@ -0,0 +1,317 @@ +.. _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, + 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 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-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-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=reliable + +If the tool's output is empty, no quirk is applied. See :ref:`device-quirks` +for more information. diff --git a/doc/user/touchpad-jitter.rst b/doc/user/touchpad-jitter.rst new file mode 100644 index 0000000..b375cbc --- /dev/null +++ b/doc/user/touchpad-jitter.rst @@ -0,0 +1,105 @@ +.. _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. diff --git a/doc/user/touchpad-jumping-cursors.rst b/doc/user/touchpad-jumping-cursors.rst new file mode 100644 index 0000000..d09cd44 --- /dev/null +++ b/doc/user/touchpad-jumping-cursors.rst @@ -0,0 +1,58 @@ +.. _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. + +In most cases, this is a bug in the 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. However, +the bug should be fixed at the kernel level. + +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. diff --git a/doc/user/touchpad-pressure-debugging.rst b/doc/user/touchpad-pressure-debugging.rst new file mode 100644 index 0000000..7389e98 --- /dev/null +++ b/doc/user/touchpad-pressure-debugging.rst @@ -0,0 +1,210 @@ +============================================================================== +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 + Ready for recording data. + Pressure range used: 8:10 + Palm pressure range used: 65535 + Place a single finger on the touchpad to measure pressure values. + Ctrl+C to exit +   + Sequence 1190 pressure: min: 39 max: 48 avg: 43 median: 44 tags: down + Sequence 1191 pressure: min: 49 max: 65 avg: 62 median: 64 tags: down + Sequence 1192 pressure: min: 40 max: 78 avg: 64 median: 66 tags: down + Sequence 1193 pressure: min: 36 max: 83 avg: 70 median: 73 tags: down + Sequence 1194 pressure: min: 43 max: 76 avg: 72 median: 74 tags: down + Touchpad pressure: 47 min: 47 max: 86 tags: down + + +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 ``tags`` show that sequence was considered +logically down at some point. 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 + +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. + diff --git a/doc/user/touchpad-pressure.rst b/doc/user/touchpad-pressure.rst new file mode 100644 index 0000000..7e9793b --- /dev/null +++ b/doc/user/touchpad-pressure.rst @@ -0,0 +1,59 @@ +.. _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. + diff --git a/doc/user/touchpad-thumb-detection.rst b/doc/user/touchpad-thumb-detection.rst new file mode 100644 index 0000000..caf26dc --- /dev/null +++ b/doc/user/touchpad-thumb-detection.rst @@ -0,0 +1,89 @@ +.. _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). diff --git a/doc/user/touchpads.rst b/doc/user/touchpads.rst new file mode 100644 index 0000000..608a360 --- /dev/null +++ b/doc/user/touchpads.rst @@ -0,0 +1,225 @@ +: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. diff --git a/doc/user/trackpoint-configuration.rst b/doc/user/trackpoint-configuration.rst new file mode 100644 index 0000000..a8ac8a7 --- /dev/null +++ b/doc/user/trackpoint-configuration.rst @@ -0,0 +1,155 @@ +.. _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 accomodate 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-trackpont-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 `_ + diff --git a/doc/user/trackpoints.rst b/doc/user/trackpoints.rst new file mode 100644 index 0000000..fd5d54c --- /dev/null +++ b/doc/user/trackpoints.rst @@ -0,0 +1,68 @@ +.. _trackpoints: + +============================================================================== +Trackpoints and Pointing Sticks +============================================================================== + +This page provides an overview of trackpoint handling in libinput, also +refered 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. + diff --git a/doc/user/troubleshooting.rst b/doc/user/troubleshooting.rst new file mode 100644 index 0000000..a66f96c --- /dev/null +++ b/doc/user/troubleshooting.rst @@ -0,0 +1,16 @@ +.. _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 diff --git a/doc/user/what-is-libinput.rst b/doc/user/what-is-libinput.rst new file mode 100644 index 0000000..123f096 --- /dev/null +++ b/doc/user/what-is-libinput.rst @@ -0,0 +1,154 @@ + +.. _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. diff --git a/include/linux/freebsd/input-event-codes.h b/include/linux/freebsd/input-event-codes.h new file mode 100644 index 0000000..7f14d4a --- /dev/null +++ b/include/linux/freebsd/input-event-codes.h @@ -0,0 +1,861 @@ +/* SPDX-License-Identifier: GPL-2.0 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_ZOOM 0x174 +#define KEY_MODE 0x175 +#define KEY_KEYBOARD 0x176 +#define KEY_SCREEN 0x177 +#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_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 + +#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_MAX 0x0f +#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 diff --git a/include/linux/freebsd/input.h b/include/linux/freebsd/input.h new file mode 100644 index 0000000..8907499 --- /dev/null +++ b/include/linux/freebsd/input.h @@ -0,0 +1,508 @@ +/* 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 */ diff --git a/include/linux/input.h b/include/linux/input.h new file mode 100644 index 0000000..03c512e --- /dev/null +++ b/include/linux/input.h @@ -0,0 +1,5 @@ +#ifdef __linux__ +#include "linux/input.h" +#elif __FreeBSD__ +#include "freebsd/input.h" +#endif diff --git a/include/linux/linux/input-event-codes.h b/include/linux/linux/input-event-codes.h new file mode 100644 index 0000000..7f14d4a --- /dev/null +++ b/include/linux/linux/input-event-codes.h @@ -0,0 +1,861 @@ +/* SPDX-License-Identifier: GPL-2.0 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_ZOOM 0x174 +#define KEY_MODE 0x175 +#define KEY_KEYBOARD 0x176 +#define KEY_SCREEN 0x177 +#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_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 + +#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_MAX 0x0f +#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 diff --git a/include/linux/linux/input.h b/include/linux/linux/input.h new file mode 100644 index 0000000..8574807 --- /dev/null +++ b/include/linux/linux/input.h @@ -0,0 +1,507 @@ +/* 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 */ diff --git a/include/valgrind/valgrind.h b/include/valgrind/valgrind.h new file mode 100644 index 0000000..7e32358 --- /dev/null +++ b/include/valgrind/valgrind.h @@ -0,0 +1,6647 @@ +/* -*- 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__ 15 + + +#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_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_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(__MINGW32__) && !defined(__MINGW64__)) \ + || defined(__CYGWIN32__) \ + || (defined(_WIN32) && defined(_M_IX86)) +# define PLAT_x86_win32 1 +#elif defined(__MINGW64__) \ + || (defined(_WIN64) && defined(_M_X64)) +# 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!=64) +# define PLAT_mips32_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) + +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_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" (_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 */ + +/* 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) + +/* 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) + +/* 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. */ +#define __CALLER_SAVED_REGS "0","1","2","3","4","5","14", \ + "f0","f1","f2","f3","f4","f5","f6","f7" + +/* 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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,160\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,168\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,176\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,184\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,192\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,200\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,208\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 \ + "lgr %0, 2\n\t" \ + "aghi 15,216\n\t" \ + VALGRIND_CFI_EPILOGUE \ + : /*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 */ + +/* ------------------------- 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, + + /* 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) + + +#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_x86_solaris +#undef PLAT_amd64_solaris + +#endif /* __VALGRIND_H */ diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..91bc273 --- /dev/null +++ b/meson.build @@ -0,0 +1,928 @@ +project('libinput', 'c', + version : '1.14.3', + license : 'MIT/Expat', + default_options : [ 'c_std=gnu99', 'warning_level=2' ], + meson_version : '>= 0.41.0') + +libinput_version = meson.project_version().split('.') + +dir_data = join_paths(get_option('prefix'), get_option('datadir'), 'libinput') +dir_sysconf = join_paths(get_option('prefix'), get_option('sysconfdir'), 'libinput') +dir_libexec = join_paths(get_option('prefix'), get_option('libexecdir'), 'libinput') +dir_lib = join_paths(get_option('prefix'), get_option('libdir')) +dir_man1 = join_paths(get_option('prefix'), get_option('mandir'), 'man1') +dir_system_udev = join_paths(get_option('prefix'), 'lib', 'udev') +dir_src_quirks = join_paths(meson.source_root(), 'quirks') +dir_src_test = join_paths(meson.source_root(), 'test') +dir_src = join_paths(meson.source_root(), 'src') + +dir_udev = get_option('udev-dir') +if dir_udev == '' + dir_udev = dir_system_udev +endif +dir_udev_callouts = dir_udev +dir_udev_rules = join_paths(dir_udev, 'rules.d') +dir_udev_hwdb = join_paths(dir_udev, 'hwdb.d') + + +# 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') +cppflags = ['-Wno-unused-parameter', '-g', '-fvisibility=hidden'] +cflags = cppflags + ['-Wmissing-prototypes', '-Wstrict-prototypes'] +add_project_arguments(cflags, language : 'c') +add_project_arguments(cppflags, language : 'cpp') + +# config.h +config_h = configuration_data() +config_h.set('_GNU_SOURCE', '1') +if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized' + config_h.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +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 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 + +# Dependencies +pkgconfig = import('pkgconfig') +dep_udev = dependency('libudev') +dep_mtdev = dependency('mtdev', version : '>= 1.1.0') +dep_libevdev = dependency('libevdev') +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.20') + + result = cc.has_function('libwacom_get_paired_device', + dependencies: dep_libwacom) + config_h.set10('HAVE_LIBWACOM_GET_PAIRED_DEVICE', result) + + result = cc.has_function('libwacom_get_button_evdev_code', + dependencies: dep_libwacom) + config_h.set10('HAVE_LIBWACOM_GET_BUTTON_EVDEV_CODE', result) +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-override', + 'udev/libinput-fuzz-override.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.build_root() + '/') +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(join_paths(dir_libepoll, 'include/libepoll-shim')) + dep_libepoll = cc.find_library('epoll-shim', dirs : join_paths(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 ############ +src_libinput_util = [ + 'src/libinput-util.c', + 'src/libinput-util.h' +] +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-flat.c', + 'src/filter-low-dpi.c', + 'src/filter-mouse.c', + 'src/filter-touchpad.c', + 'src/filter-touchpad-x230.c', + 'src/filter-tablet.c', + 'src/filter-trackpoint.c', + 'src/filter.h', + 'src/filter-private.h' +] +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 = join_paths(dir_sysconf, 'local-overrides.quirks') +config_h.set_quoted('LIBINPUT_QUIRKS_DIR', dir_data) +config_h.set_quoted('LIBINPUT_QUIRKS_OVERRIDE_FILE', libinput_data_override_path) + +quirks_data = [ + 'quirks/10-generic-keyboard.quirks', + 'quirks/10-generic-lid.quirks', + 'quirks/10-generic-trackball.quirks', + 'quirks/30-vendor-aiptek.quirks', + 'quirks/30-vendor-alps.quirks', + 'quirks/30-vendor-contour.quirks', + 'quirks/30-vendor-cypress.quirks', + 'quirks/30-vendor-elantech.quirks', + 'quirks/30-vendor-ibm.quirks', + 'quirks/30-vendor-kensington.quirks', + 'quirks/30-vendor-logitech.quirks', + 'quirks/30-vendor-microsoft.quirks', + 'quirks/30-vendor-razer.quirks', + 'quirks/30-vendor-synaptics.quirks', + 'quirks/30-vendor-vmware.quirks', + 'quirks/30-vendor-wacom.quirks', + 'quirks/50-system-acer.quirks', + 'quirks/50-system-apple.quirks', + 'quirks/50-system-asus.quirks', + 'quirks/50-system-chicony.quirks', + 'quirks/50-system-cyborg.quirks', + 'quirks/50-system-dell.quirks', + 'quirks/50-system-google.quirks', + 'quirks/50-system-hp.quirks', + 'quirks/50-system-lenovo.quirks', + 'quirks/50-system-system76.quirks', + 'quirks/50-system-toshiba.quirks', +] + +test('quirks-in-meson.build', + find_program('quirks/test-quirks-in-meson.build.sh'), + args : [meson.source_root()], + suite : ['all'] + ) + +config_h.set_quoted('LIBINPUT_QUIRKS_FILES', ':'.join(quirks_data)) +config_h.set_quoted('LIBINPUT_QUIRKS_SRCDIR', dir_src_quirks) + +install_data(quirks_data, install_dir : dir_data) + +src_libquirks = [ + 'src/quirks.c', + 'src/quirks.h', + 'src/builddir.h', +] + +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) + +############ libinput.so ############ +install_headers('src/libinput.h') +src_libinput = src_libfilter + [ + 'src/libinput.c', + 'src/libinput.h', + 'src/libinput-private.h', + 'src/evdev.c', + 'src/evdev.h', + 'src/evdev-debounce.c', + 'src/evdev-fallback.c', + 'src/evdev-fallback.h', + 'src/evdev-totem.c', + 'src/evdev-middle-button.c', + 'src/evdev-mt-touchpad.c', + 'src/evdev-mt-touchpad.h', + '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.h', + 'src/evdev-tablet-pad.c', + 'src/evdev-tablet-pad.h', + 'src/evdev-tablet-pad-leds.c', + 'src/path-seat.c', + 'src/udev-seat.c', + 'src/udev-seat.h', + 'src/timer.c', + 'src/timer.h', + 'include/linux/input.h' +] + +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 = join_paths(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) + +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') + +if meson.version().version_compare('<0.43.0') + # Restore the SELinux context for the libinput.so.a.b.c on install + # meson bug https://github.com/mesonbuild/meson/issues/1967 + meson.add_install_script('src/libinput-restore-selinux-context.sh', + dir_lib, lib_libinput.full_path()) +endif + +############ documentation ############ + +if get_option('documentation') + subdir('doc/api') + subdir('doc/user') +endif + +############ shell completion ######### + +subdir('completion/zsh') + +############ tools ############ +libinput_tool_path = dir_libexec +config_h.set_quoted('LIBINPUT_TOOL_PATH', libinput_tool_path) +tools_shared_sources = [ 'tools/shared.c', + 'tools/shared.h', + 'src/builddir.h' ] +deps_tools_shared = [ dep_libinput, dep_libevdev ] +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) + +man_config = configuration_data() +man_config.set('LIBINPUT_VERSION', meson.project_version()) +man_config.set('LIBINPUT_DATA_DIR', dir_data) + +deps_tools = [ dep_tools_shared, dep_libinput ] +libinput_debug_events_sources = [ 'tools/libinput-debug-events.c' ] +executable('libinput-debug-events', + libinput_debug_events_sources, + dependencies : deps_tools, + include_directories : [includes_src, includes_include], + install_dir : libinput_tool_path, + install : true + ) +configure_file(input : 'tools/libinput-debug-events.man', + output : 'libinput-debug-events.1', + configuration : man_config, + install_dir : dir_man1, + ) + +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'] + ) + +configure_file(input : 'tools/libinput-quirks.man', + output : 'libinput-quirks.1', + configuration : man_config, + install_dir : dir_man1, + ) +# 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, + ) + +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']) + +configure_file(input : 'tools/libinput-list-devices.man', + output : 'libinput-list-devices.1', + configuration : man_config, + install_dir : dir_man1, + ) + +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, + ) +configure_file(input : 'tools/libinput-measure.man', + output : 'libinput-measure.1', + configuration : man_config, + install_dir : dir_man1, + ) + +src_python_tools = files( + 'tools/libinput-measure-fuzz.py', + 'tools/libinput-measure-touchpad-tap.py', + 'tools/libinput-measure-touchpad-pressure.py', + 'tools/libinput-measure-touch-size.py', +) + +config_noop = configuration_data() +# Set a dummy replacement to silence meson warnings: +# meson.build:487: WARNING: Got an empty configuration_data() object and +# found no substitutions in the input file 'foo'. If you +# want to copy a file to the build dir, use the 'copy:' +# keyword argument added in 0.47.0 +config_noop.set('dummy', 'dummy') +foreach t : src_python_tools + configure_file(input: t, + output: '@BASENAME@', + configuration : config_noop, + install_dir : libinput_tool_path + ) +endforeach + +src_man = files( + 'tools/libinput-measure-fuzz.man', + 'tools/libinput-measure-touchpad-tap.man', + 'tools/libinput-measure-touchpad-pressure.man', + 'tools/libinput-measure-touch-size.man', +) + +foreach m : src_man + configure_file(input : m, + output : '@BASENAME@.1', + configuration : man_config, + install_dir : dir_man1) +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, + ) +configure_file(input : 'tools/libinput-record.man', + output : 'libinput-record.1', + configuration : man_config, + install_dir : dir_man1, + ) + +install_data('tools/libinput-replay', + install_dir : libinput_tool_path) +configure_file(input : 'tools/libinput-replay.man', + output : 'libinput-replay.1', + configuration : man_config, + install_dir : dir_man1, + ) + +if get_option('debug-gui') + dep_gtk = dependency('gtk+-3.0', version : '>= 3.20') + dep_cairo = dependency('cairo') + dep_glib = dependency('glib-2.0') + + debug_gui_sources = [ 'tools/libinput-debug-gui.c' ] + deps_debug_gui = [ + dep_gtk, + dep_cairo, + dep_glib, + ] + 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 + ) + configure_file(input : 'tools/libinput-debug-gui.man', + output : 'libinput-debug-gui.1', + configuration : man_config, + install_dir : dir_man1, + ) +endif + +libinput_sources = [ 'tools/libinput-tool.c' ] + +libinput_tool = executable('libinput', + libinput_sources, + dependencies : deps_tools, + include_directories : [includes_src, includes_include], + install : true + ) +configure_file(input : 'tools/libinput.man', + output : 'libinput.1', + configuration : man_config, + install_dir : dir_man1, + ) + +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('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui')) + tool_option_test = configure_file(input: 'tools/test-tool-option-parsing.py', + output: '@BASENAME@', + configuration : config_tool_option_test) + test('tool-option-parsing', + tool_option_test, + args : ['--tool-path', libinput_tool.full_path()], + 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.build_root())], + suite : ['all'], + workdir : '/tmp') + +############ tests ############ + +test('symbols-leak-test', + find_program('test/symbols-leak-test'), + args : [ join_paths(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', required: false) + executable('test-build-cxx', + 'test/build-cxx.cc', + dependencies : [dep_udev], + include_directories : [includes_src, includes_include], + install : false) +endif + +# 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') + + 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 = [ + 'test/litest.h', + 'test/litest-int.h', + 'test/litest-device-acer-hawaii-keyboard.c', + 'test/litest-device-acer-hawaii-touchpad.c', + 'test/litest-device-aiptek-tablet.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-generic-singletouch.c', + 'test/litest-device-gpio-keys.c', + 'test/litest-device-huion-pentablet.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-razer-blackwidow.c', + 'test/litest-device-keyboard-razer-blade-stealth.c', + 'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c', + 'test/litest-device-lid-switch.c', + 'test/litest-device-lid-switch-surface3.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-synaptics-x220.c', + 'test/litest-device-synaptics-hover.c', + 'test/litest-device-synaptics-i2c.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-thinkpad-extrabuttons.c', + 'test/litest-device-trackpoint.c', + 'test/litest-device-touch-screen.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-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-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.c', + 'include/valgrind/valgrind.h' + ] + + dep_dl = cc.find_library('dl') + deps_litest = [ + dep_libinput, + dep_check, + dep_udev, + dep_libevdev, + dep_dl, + dep_lm, + dep_libsystemd, + dep_libquirks, + ] + + litest_config_h = configuration_data() + litest_config_h.set_quoted('LIBINPUT_DEVICE_GROUPS_RULES_FILE', + join_paths(meson.build_root(), + '80-libinput-device-groups-litest.rules')) + litest_config_h.set_quoted('LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE', + join_paths(meson.build_root(), + '90-libinput-fuzz-override-litest.rules')) + + def_no_main = '-DLITEST_NO_MAIN' + def_disable_backtrace = '-DLITEST_DISABLE_BACKTRACE_LOGGING' + defs_litest_selftest = [ + def_no_main, + def_disable_backtrace + ] + test_litest_selftest_sources = [ + 'test/litest-selftest.c', + 'test/litest.c', + 'test/litest.h' + ] + test_litest_selftest = executable('test-litest-selftest', + test_litest_selftest_sources, + include_directories : [includes_src, includes_include], + dependencies : deps_litest, + c_args : defs_litest_selftest, + install : false) + test('test-litest-selftest', + test_litest_selftest, + suite : ['all'], + timeout : 100) + + 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 = [ + 'src/libinput-util.h', + 'src/libinput-util.c', + 'test/test-utils.c', + ] + test_utils = executable('test-utils', + test_utils_sources, + include_directories : [includes_src, includes_include], + dependencies : deps_litest, + install: false) + test('test-utils', + test_utils, + suite : ['all']) + + libinput_test_runner_sources = litest_sources + [ + 'src/libinput-util.h', + 'src/libinput-util.c', + '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 = 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')) + configure_file(input : 'test/libinput-test-suite.man', + output : 'libinput-test-suite.1', + configuration : man_config, + install_dir : dir_man1, + ) + + # Update this list and the one in litest.c when new group names are + # required + groups = [ + 'config', 'context', 'device', 'events', 'gestures', 'keyboard', 'lid', + 'log', 'misc', 'pad', 'path', 'pointer', 'quirks', 'switch', 'tablet', + 'tablet-mode', 'tap', 'timer', 'totem', 'touch', 'touchpad', 'trackball', + 'trackpoint', 'udev', + ] + foreach group : groups + 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_env.set('LITEST_JOBS', '4') + valgrind_suppressions_file = join_paths(dir_src_test, 'valgrind.suppressions') + add_test_setup('valgrind', + exe_wrapper : [ valgrind, + '--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 +############ output files ############ +configure_file(output : 'config.h', configuration : config_h) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..7819449 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,36 @@ +option('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: true, + description: 'Build the documentation [default=true]') +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]') diff --git a/quirks/10-generic-keyboard.quirks b/quirks/10-generic-keyboard.quirks new file mode 100644 index 0000000..882f97b --- /dev/null +++ b/quirks/10-generic-keyboard.quirks @@ -0,0 +1,11 @@ +# 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 diff --git a/quirks/10-generic-lid.quirks b/quirks/10-generic-lid.quirks new file mode 100644 index 0000000..1c20acd --- /dev/null +++ b/quirks/10-generic-lid.quirks @@ -0,0 +1,11 @@ +# Do not edit this file, it will be overwritten on update + +[Lid Switch Ct9] +MatchName=*Lid Switch* +MatchDMIModalias=dmi:*:ct9:* +AttrLidSwitchReliability=reliable + +[Lid Switch Ct10] +MatchName=*Lid Switch* +MatchDMIModalias=dmi:*:ct10:* +AttrLidSwitchReliability=reliable diff --git a/quirks/10-generic-trackball.quirks b/quirks/10-generic-trackball.quirks new file mode 100644 index 0000000..eba32af --- /dev/null +++ b/quirks/10-generic-trackball.quirks @@ -0,0 +1,5 @@ +# Do not edit this file, it will be overwritten on update + +[Trackball] +MatchName=*Trackball* +ModelTrackball=1 diff --git a/quirks/30-vendor-aiptek.quirks b/quirks/30-vendor-aiptek.quirks new file mode 100644 index 0000000..23194e0 --- /dev/null +++ b/quirks/30-vendor-aiptek.quirks @@ -0,0 +1,7 @@ +# Do not edit this file, it will be overwritten on update + +[Aiptek No Tilt Tablet] +MatchUdevType=tablet +MatchBus=usb +MatchVendor=0x08CA +AttrEventCodeDisable=ABS_TILT_X;ABS_TILT_Y; diff --git a/quirks/30-vendor-alps.quirks b/quirks/30-vendor-alps.quirks new file mode 100644 index 0000000..e4e5d47 --- /dev/null +++ b/quirks/30-vendor-alps.quirks @@ -0,0 +1,36 @@ +# 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 +ModelALPSTouchpad=1 + +[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 diff --git a/quirks/30-vendor-contour.quirks b/quirks/30-vendor-contour.quirks new file mode 100644 index 0000000..a880f85 --- /dev/null +++ b/quirks/30-vendor-contour.quirks @@ -0,0 +1,17 @@ +[Contour Design RollerMouse Free 2] +MatchVendor=0x0B33 +MatchProduct=0x0401 +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 diff --git a/quirks/30-vendor-cypress.quirks b/quirks/30-vendor-cypress.quirks new file mode 100644 index 0000000..7d416df --- /dev/null +++ b/quirks/30-vendor-cypress.quirks @@ -0,0 +1,11 @@ +# 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 diff --git a/quirks/30-vendor-elantech.quirks b/quirks/30-vendor-elantech.quirks new file mode 100644 index 0000000..9b3a1ba --- /dev/null +++ b/quirks/30-vendor-elantech.quirks @@ -0,0 +1,11 @@ +# 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 diff --git a/quirks/30-vendor-ibm.quirks b/quirks/30-vendor-ibm.quirks new file mode 100644 index 0000000..9990205 --- /dev/null +++ b/quirks/30-vendor-ibm.quirks @@ -0,0 +1,47 @@ +# 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 diff --git a/quirks/30-vendor-kensington.quirks b/quirks/30-vendor-kensington.quirks new file mode 100644 index 0000000..f4d83a0 --- /dev/null +++ b/quirks/30-vendor-kensington.quirks @@ -0,0 +1,7 @@ +# Kensington Orbit claims to have a middle button, same for +[Kensington Orbit Scroll Wheel] +MatchBus=usb +MatchVendor=0x047D +MatchProduct=0x2048 +ModelTrackball=1 +AttrEventCodeDisable=BTN_MIDDLE diff --git a/quirks/30-vendor-logitech.quirks b/quirks/30-vendor-logitech.quirks new file mode 100644 index 0000000..23b6c88 --- /dev/null +++ b/quirks/30-vendor-logitech.quirks @@ -0,0 +1,63 @@ +# Do not edit this file, it will be overwritten on update + +[Logitech M570] +MatchName=*Logitech M570* +ModelTrackball=1 + +# Logitech Marble Mouse claims to have a middle button +[Logitech Marble Mouse Trackball] +MatchUdevType=mouse +MatchBus=usb +MatchVendor=0x46D +MatchProduct=0xC408 +AttrEventCodeDisable=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 2S] +MatchVendor=0x46D +MatchProduct=0x4069 +ModelInvertHorizontalScrolling=1 + +[Logitech MX Master 3] +MatchVendor=0x46D +MatchProduct=0x4082 +ModelInvertHorizontalScrolling=1 + +# MX Master 3 has a different PID on bluetooth +[Logitech MX Master 3] +MatchVendor=0x46D +MatchProduct=0xB023 +ModelInvertHorizontalScrolling=1 diff --git a/quirks/30-vendor-microsoft.quirks b/quirks/30-vendor-microsoft.quirks new file mode 100644 index 0000000..36eb992 --- /dev/null +++ b/quirks/30-vendor-microsoft.quirks @@ -0,0 +1,18 @@ +# 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 + +[Microsoft Surface 3 Type Cover Keyboard] +MatchName=*Microsoft Surface Type Cover Keyboard* +MatchDMIModalias=dmi:*svnMicrosoftCorporation:pnSurface3:* +AttrKeyboardIntegration=internal + +[Microsoft Nano Transceiver v2.0] +MatchUdevType=mouse +MatchBus=usb +MatchVendor=0x045E +MatchProduct=0x0800 +ModelBouncingKeys=1 diff --git a/quirks/30-vendor-razer.quirks b/quirks/30-vendor-razer.quirks new file mode 100644 index 0000000..b3cd817 --- /dev/null +++ b/quirks/30-vendor-razer.quirks @@ -0,0 +1,13 @@ +# Do not edit this file, it will be overwritten on update + +[Razer Blade Keyboard] +MatchUdevType=keyboard +MatchBus=usb +MatchVendor=0x1532 +MatchProduct=0x0220 +AttrKeyboardIntegration=internal + +[Razer Blade Lid Switch] +MatchName=*Lid Switch* +MatchDMIModalias=dmi:*svnRazer:pnBlade* +AttrLidSwitchReliability=write_open diff --git a/quirks/30-vendor-synaptics.quirks b/quirks/30-vendor-synaptics.quirks new file mode 100644 index 0000000..3cdeb45 --- /dev/null +++ b/quirks/30-vendor-synaptics.quirks @@ -0,0 +1,8 @@ +# Do not edit this file, it will be overwritten on update + +[Synaptics Serial Touchpads] +MatchUdevType=touchpad +MatchBus=ps2 +MatchVendor=0x0002 +MatchProduct=0x0007 +ModelSynapticsSerialTouchpad=1 diff --git a/quirks/30-vendor-vmware.quirks b/quirks/30-vendor-vmware.quirks new file mode 100644 index 0000000..5a3d90e --- /dev/null +++ b/quirks/30-vendor-vmware.quirks @@ -0,0 +1,10 @@ +# 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 + diff --git a/quirks/30-vendor-wacom.quirks b/quirks/30-vendor-wacom.quirks new file mode 100644 index 0000000..73ccf2f --- /dev/null +++ b/quirks/30-vendor-wacom.quirks @@ -0,0 +1,22 @@ +# Do not edit this file, it will be overwritten on update + +[Wacom Touchpads] +MatchUdevType=touchpad +MatchBus=usb +MatchVendor=0x056A +ModelWacomTouchpad=1 + +[Wacom Intuos Pro PTH660] +MatchUdevType=touchpad +MatchBus=usb +MatchVendor=0x056A +MatchProduct=0x0357 +AttrPalmSizeThreshold=5 + +[Wacom ISDV4 Pen] +MatchUdevType=tablet +MatchBus=usb +MatchVendor=0x56A +MatchProduct=0x4200 +ModelWacomISDV4Pen=1 +AttrEventCodeDisable=ABS_TILT_X;ABS_TILT_Y; diff --git a/quirks/50-system-acer.quirks b/quirks/50-system-acer.quirks new file mode 100644 index 0000000..80b0c70 --- /dev/null +++ b/quirks/50-system-acer.quirks @@ -0,0 +1,9 @@ +[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 \ No newline at end of file diff --git a/quirks/50-system-apple.quirks b/quirks/50-system-apple.quirks new file mode 100644 index 0000000..b104f0a --- /dev/null +++ b/quirks/50-system-apple.quirks @@ -0,0 +1,69 @@ +# 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=800 + +[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 + +# 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 +AttrEventCodeDisable=EV_ABS + +[Apple Magic Trackpad v1 (2010, clickpad)] +MatchUdevType=touchpad +MatchBus=bluetooth +MatchVendor=0x5AC +MatchProduct=0x030E +AttrSizeHint=130x110 +AttrTouchSizeRange=20:10 +AttrPalmSizeThreshold=900 +AttrThumbSizeThreshold=700 + +[Apple Touchpad OneButton] +MatchUdevType=touchpad +MatchBus=usb +MatchVendor=0x5AC +MatchProduct=0x021A +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=0x5AC +MatchProduct=0x0262 +AttrPalmSizeThreshold=1600 diff --git a/quirks/50-system-asus.quirks b/quirks/50-system-asus.quirks new file mode 100644 index 0000000..aa8f89a --- /dev/null +++ b/quirks/50-system-asus.quirks @@ -0,0 +1,26 @@ +# 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:* +AttrEventCodeDisable=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 diff --git a/quirks/50-system-chicony.quirks b/quirks/50-system-chicony.quirks new file mode 100644 index 0000000..911b7d6 --- /dev/null +++ b/quirks/50-system-chicony.quirks @@ -0,0 +1,17 @@ +# 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=0x4F2 +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 diff --git a/quirks/50-system-cyborg.quirks b/quirks/50-system-cyborg.quirks new file mode 100644 index 0000000..6a21f64 --- /dev/null +++ b/quirks/50-system-cyborg.quirks @@ -0,0 +1,31 @@ +# 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 +AttrEventCodeDisable=EV_KEY:0x118;EV_KEY:0x119;EV_KEY:0x11a diff --git a/quirks/50-system-dell.quirks b/quirks/50-system-dell.quirks new file mode 100644 index 0000000..232c309 --- /dev/null +++ b/quirks/50-system-dell.quirks @@ -0,0 +1,75 @@ +# 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 Lattitude 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 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 + +# 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 diff --git a/quirks/50-system-google.quirks b/quirks/50-system-google.quirks new file mode 100644 index 0000000..cd31297 --- /dev/null +++ b/quirks/50-system-google.quirks @@ -0,0 +1,88 @@ +# Do not edit this file, it will be overwritten on update + +[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 diff --git a/quirks/50-system-hp.quirks b/quirks/50-system-hp.quirks new file mode 100644 index 0000000..3f43cb3 --- /dev/null +++ b/quirks/50-system-hp.quirks @@ -0,0 +1,61 @@ +# 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* +AttrEventCodeDisable=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* +AttrEventCodeDisable=BTN_TOOL_DOUBLETAP;BTN_TOOL_TRIPLETAP; + +[HP Pavillion dmi4] +MatchName=*SynPS/2 Synaptics TouchPad +MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPPaviliondm4NotebookPC* +ModelHPPavilionDM4Touchpad=1 + +[HP Stream 11] +MatchName=SYN1EDE:00 06CB:7442 +MatchDMIModalias=dmi:*svnHewlett-Packard:pnHPStreamNotebookPC11* +ModelHPStream11Touchpad=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 Convertable 15-bl1xx] +MatchUdevType=touchpad +MatchName=*SynPS/2 Synaptics TouchPad +MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-bl1XX:* +AttrPressureRange=55:40 +AttrThumbPressureThreshold=90 +AttrPalmPressureThreshold=100 + +[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 \ No newline at end of file diff --git a/quirks/50-system-lenovo.quirks b/quirks/50-system-lenovo.quirks new file mode 100644 index 0000000..2f0ca56 --- /dev/null +++ b/quirks/50-system-lenovo.quirks @@ -0,0 +1,179 @@ +# Do not edit this file, it will be overwritten on update + +[Lenovo Thinkpad Touchpad] +MatchName=*Synaptics* +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad*:* +AttrThumbPressureThreshold=100 + +[Lenovo ThinkPad 13 2nd Generation TrackPoint] +MatchUdevType=pointingstick +MatchName=*ETPS/2 Elantech TrackPoint* +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad132ndGen* +AttrTrackpointMultiplier=1.75 + +[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 T480 Trackpoint] +MatchName=*TPPS/2 IBM TrackPoint +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480:* +AttrTrackpointMultiplier=0.4 + +[Lenovo T480s Touchpad] +MatchName=Elan Touchpad +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480s* +ModelLenovoT480sTouchpad=1 + +[Lenovo T490s Touchpad] +MatchName=Elan Touchpad +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s* +ModelLenovoT490sTouchpad=1 + +[Lenovo T490s Trackpoint] +MatchName=*TPPS/2 IBM TrackPoint +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s:* +AttrTrackpointMultiplier=0.4 + +[Lenovo L380 Touchpad] +MatchName=Elan Touchpad +MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadL380* +ModelLenovoL380Touchpad=1 + +[Lenovo X200 Trackpoint] +MatchName=*TPPS/2 IBM TrackPoint +MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20?:* +AttrTrackpointMultiplier=1.25 + +[Lenovo X200x Trackpoint] +MatchName=*TPPS/2 IBM TrackPoint +MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20??:* +AttrTrackpointMultiplier=1.25 + +[Lenovo X230 Trackpoint] +MatchName=*TPPS/2 IBM TrackPoint +MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX230:* +AttrTrackpointMultiplier=0.25 + +[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 + +# 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:* +AttrEventCodeDisable=ABS_MT_TOOL_TYPE + +[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 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 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 diff --git a/quirks/50-system-system76.quirks b/quirks/50-system-system76.quirks new file mode 100644 index 0000000..2e8eb80 --- /dev/null +++ b/quirks/50-system-system76.quirks @@ -0,0 +1,21 @@ +# 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 diff --git a/quirks/50-system-toshiba.quirks b/quirks/50-system-toshiba.quirks new file mode 100644 index 0000000..9eba411 --- /dev/null +++ b/quirks/50-system-toshiba.quirks @@ -0,0 +1,4 @@ +[Toshiba Satellite L855-14E Touchpad] +MatchName=*SynPS/2 Synaptics TouchPad +MatchDMIModalias=dmi:*svnTOSHIBA:pnSATELLITEL855* +AttrPressureRange=45:44 \ No newline at end of file diff --git a/quirks/README.md b/quirks/README.md new file mode 100644 index 0000000..55b9056 --- /dev/null +++ b/quirks/README.md @@ -0,0 +1,77 @@ += libinput data 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 data 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. +The quirks are hardware quirks only. + +== Data file naming == + +Data files are read in versionsort order, read order determines how values +override each other. A values read later override previously 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. + +== 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 will cause parser errors and are considered invalid data +files: + +* Whitespace at the beginning of the line +* Sections without at least one `Match*` entry +* Sections with the same `Match*` entry repeated +* Sections without at least one of `Model*` or `Attr` entries +* A `Model` tag with a value other than `1` or `0` +* A string property with enclosing quotes + +== 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/data/ --verbose /dev/input/event0 +``` diff --git a/quirks/test-quirks-in-meson.build.sh b/quirks/test-quirks-in-meson.build.sh new file mode 100755 index 0000000..fed8d1d --- /dev/null +++ b/quirks/test-quirks-in-meson.build.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +pushd "$1" > /dev/null +diff -u1 <(grep -o 'quirks/.*\.quirks' meson.build) <(ls quirks/*.quirks) +popd > /dev/null diff --git a/src/builddir.h b/src/builddir.h new file mode 100644 index 0000000..7fc377c --- /dev/null +++ b/src/builddir.h @@ -0,0 +1,61 @@ +/* + * 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 + +/** + * 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] = {0}; + 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); +} diff --git a/src/evdev-debounce.c b/src/evdev-debounce.c new file mode 100644 index 0000000..33ff05d --- /dev/null +++ b/src/evdev-debounce.c @@ -0,0 +1,594 @@ +/* + * 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 currently unhandled. +*/ + +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 %sbutton-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); + + evdev_pointer_notify_physical_button(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_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_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: + /* 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_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: + /* 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_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); +} diff --git a/src/evdev-fallback.c b/src/evdev-fallback.c new file mode 100644 index 0000000..1a9113b --- /dev/null +++ b/src/evdev-fallback.c @@ -0,0 +1,1757 @@ +/* + * 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" + +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; + } +} + +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 void +normalize_delta(struct evdev_device *device, + const struct device_coords *delta, + struct normalized_coords *normalized) +{ + normalized->x = delta->x * DEFAULT_MOUSE_DPI / (double)device->dpi; + normalized->y = delta->y * DEFAULT_MOUSE_DPI / (double)device->dpi; +} + +static inline bool +post_trackpoint_scroll(struct evdev_device *device, + struct normalized_coords unaccel, + 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: + evdev_post_scroll(device, time, + LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, + &unaccel); + 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 void +fallback_rotate_relative(struct fallback_dispatch *dispatch, + struct evdev_device *device) +{ + struct device_coords rel = dispatch->rel; + + if (!device->base.config.rotation) + return; + + /* loss of precision for non-90 degrees, but we only support 90 deg + * right now anyway */ + matrix_mult_vec(&dispatch->rotation.matrix, &rel.x, &rel.y); + + dispatch->rel = 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, unaccel; + struct device_float_coords raw; + + if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) + return; + + fallback_rotate_relative(dispatch, device); + + normalize_delta(device, &dispatch->rel, &unaccel); + raw.x = dispatch->rel.x; + raw.y = dispatch->rel.y; + dispatch->rel.x = 0; + dispatch->rel.y = 0; + + /* Use unaccelerated deltas for pointing stick scroll */ + if (post_trackpoint_scroll(device, unaccel, 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 = unaccel; + } + + if (normalized_is_zero(accel) && normalized_is_zero(unaccel)) + return; + + pointer_notify_motion(base, time, &accel, &raw); +} + +static void +fallback_flush_wheels(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 }; + enum libinput_pointer_axis_source source; + + if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) + return; + + if (device->model_flags & EVDEV_MODEL_LENOVO_SCROLLPOINT) { + struct normalized_coords unaccel = { 0.0, 0.0 }; + + dispatch->wheel.y *= -1; + normalize_delta(device, &dispatch->wheel, &unaccel); + evdev_post_scroll(device, + time, + LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, + &unaccel); + dispatch->wheel.x = 0; + dispatch->wheel.y = 0; + + return; + } + + if (dispatch->wheel.y != 0) { + wheel_degrees.y = -1 * dispatch->wheel.y * + device->scroll.wheel_click_angle.y; + discrete.y = -1 * dispatch->wheel.y; + + source = device->scroll.is_tilt.vertical ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; + + evdev_notify_axis( + device, + time, + bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), + source, + &wheel_degrees, + &discrete); + dispatch->wheel.y = 0; + } + + if (dispatch->wheel.x != 0) { + wheel_degrees.x = dispatch->wheel.x * + device->scroll.wheel_click_angle.x; + discrete.x = dispatch->wheel.x; + + source = device->scroll.is_tilt.horizontal ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; + + evdev_notify_axis( + device, + time, + bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL), + source, + &wheel_degrees, + &discrete); + dispatch->wheel.x = 0; + } +} + +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] = { + {{ 0, 0 }, EV_SW, SW_LID, 0 }, + {{ 0, 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; + case REL_WHEEL: + dispatch->wheel.y += e->value; + dispatch->pending_event |= EVDEV_WHEEL; + break; + case REL_HWHEEL: + dispatch->wheel.x += e->value; + dispatch->pending_event |= EVDEV_WHEEL; + break; + } +} + +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; + + if (dispatch->arbitration.state == ARBITRATION_IGNORE_RECT && + point_in_rect(&slot->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_flush_wheels(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); + + if (dispatch->arbitration.in_arbitration) + return; + + 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; + + if (!rect || point_in_rect(&dispatch->abs.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]; + + if (slot->seat_slot == -1) + continue; + + if ((!rect || point_in_rect(&slot->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: + evdev_pointer_notify_button( + device, + time, + evdev_to_left_handed(device, 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, *tmp; + + 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, + tmp, + &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 = {0}; + + 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}; + + 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)); + 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; + break; + case ARBITRATION_IGNORE_ALL: + libinput_timer_cancel(&dispatch->arbitration.arbitration_timer); + fallback_return_to_neutral_state(dispatch, device); + dispatch->arbitration.in_arbitration = true; + break; + } + + 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->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, *tmp; + + list_for_each_safe(kbd, + tmp, + &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; + } +} + +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) + return; + + if (fallback_any_button_down(dispatch, device)) + return; + + device->scroll.method = device->scroll.want_method; + device->scroll.button = device->scroll.want_button; +} + +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->model_flags & EVDEV_MODEL_TRACKBALL) == 0) + 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; + dispatch->rotation.is_enabled = false; + 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; +} + +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_debounce(dispatch); + fallback_init_arbitration(dispatch, device); + + return &dispatch->base; +} diff --git a/src/evdev-fallback.h b/src/evdev-fallback.h new file mode 100644 index 0000000..0f75827 --- /dev/null +++ b/src/evdev-fallback.h @@ -0,0 +1,245 @@ +/* + * 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 */ +}; + +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 { + bool is_enabled; + 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 device_coords 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 <= KEY_ONSCREEN_KEYBOARD) + 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); + +#endif diff --git a/src/evdev-middle-button.c b/src/evdev-middle-button.c new file mode 100644 index 0000000..8c0685c --- /dev/null +++ b/src/evdev-middle-button.c @@ -0,0 +1,727 @@ +/* + * 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, or online at + * https://drive.google.com/file/d/0B1NwWmji69nodUJncXRMc1FvY1k/view?usp=sharing + * (it's a http://draw.io diagram) + * + * 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, + "middlebuttonstate: %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 bit = (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 || + bit >= 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 |= 1 << bit; + else + device->middlebutton.button_mask &= ~(1 << bit); + + 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; +} diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c new file mode 100644 index 0000000..6e72193 --- /dev/null +++ b/src/evdev-mt-touchpad-buttons.c @@ -0,0 +1,1311 @@ +/* + * 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 "linux/input.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, or online at + * https://drive.google.com/file/d/0B1NwWmji69nocUs1cVJTbkdwMFk/edit?usp=sharing + * (it's a http://draw.io diagram) + * + * 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_bottom_left_area(const struct tp_dispatch *tp, + const struct tp_touch *t) +{ + return is_inside_bottom_button_area(tp, t) && + !is_inside_bottom_middle_area(tp, t) && + !is_inside_bottom_right_area(tp, t); +} + +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_left_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; +} + +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) +{ + libinput_timer_set(&t->button.timer, + t->time + DEFAULT_BUTTON_ENTER_TIMEOUT); +} + +static void +tp_button_set_leave_timer(struct tp_dispatch *tp, struct tp_touch *t) +{ + libinput_timer_set(&t->button.timer, + t->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) +{ + 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); + break; + case BUTTON_STATE_TOP_TO_IGNORE: + tp_button_set_leave_timer(tp, t); + 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) +{ + 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); + 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); + break; + case BUTTON_EVENT_IN_AREA: + tp_button_set_state(tp, t, BUTTON_STATE_AREA, event); + break; + case BUTTON_EVENT_UP: + tp_button_set_state(tp, t, BUTTON_STATE_NONE, event); + 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) +{ + 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); + 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) +{ + 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); + 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); + + /* 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); + 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) +{ + 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); + 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); + break; + case BUTTON_EVENT_IN_AREA: + tp_button_set_state(tp, t, BUTTON_STATE_TOP_TO_IGNORE, event); + break; + case BUTTON_EVENT_UP: + tp_button_set_state(tp, t, BUTTON_STATE_NONE, event); + 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) +{ + 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); + 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); + break; + case BUTTON_EVENT_IN_AREA: + tp_button_set_state(tp, t, BUTTON_STATE_AREA, event); + break; + case BUTTON_EVENT_UP: + tp_button_set_state(tp, t, BUTTON_STATE_NONE, event); + break; + case BUTTON_EVENT_PRESS: + tp_button_set_state(tp, t, BUTTON_STATE_TOP, event); + break; + case BUTTON_EVENT_RELEASE: + break; + case BUTTON_EVENT_TIMEOUT: + tp_button_set_state(tp, t, BUTTON_STATE_TOP, event); + break; + } +} + +static void +tp_button_top_to_ignore_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum button_event event) +{ + 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); + else + tp_button_set_state(tp, + t, + BUTTON_STATE_TOP_NEW, + event); + 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); + break; + case BUTTON_EVENT_PRESS: + case BUTTON_EVENT_RELEASE: + break; + case BUTTON_EVENT_TIMEOUT: + tp_button_set_state(tp, t, BUTTON_STATE_IGNORE, event); + break; + } +} + +static void +tp_button_ignore_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum button_event event) +{ + 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); + 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); + break; + case BUTTON_STATE_AREA: + tp_button_area_handle_event(tp, t, event); + break; + case BUTTON_STATE_BOTTOM: + tp_button_bottom_handle_event(tp, t, event); + break; + case BUTTON_STATE_TOP: + tp_button_top_handle_event(tp, t, event); + break; + case BUTTON_STATE_TOP_NEW: + tp_button_top_new_handle_event(tp, t, event); + break; + case BUTTON_STATE_TOP_TO_IGNORE: + tp_button_top_to_ignore_handle_event(tp, t, event); + break; + case BUTTON_STATE_IGNORE: + tp_button_ignore_handle_event(tp, t, event); + 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 = 1 << (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; + else 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_TOUCHPAD)) { + enable_by_default = true; + want_config_option = true; + } else + return; + + evdev_init_middlebutton(tp->device, + enable_by_default, + want_config_option); +} + +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 = libevdev_has_property(device->evdev, + INPUT_PROP_BUTTONPAD); + tp->buttons.has_topbuttons = libevdev_has_property(device->evdev, + INPUT_PROP_TOPBUTTONPAD); + + if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || + libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { + if (tp->buttons.is_clickpad) + evdev_log_bug_kernel(device, + "clickpad advertising right button\n"); + } else if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) && + !tp->buttons.is_clickpad && + libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) { + evdev_log_bug_kernel(device, + "non clickpad without right button?\n"); + } + + 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->device->base.config.click_method = &tp->buttons.config_method; + + 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; + + 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: + switch (nfingers) { + case 0: + case 1: button = BTN_LEFT; break; + case 2: button = BTN_RIGHT; break; + default: + button = BTN_MIDDLE; break; + 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; + struct input_event syn_report = {{ 0, 0 }, EV_SYN, SYN_REPORT, 0 }; + + event.time = us2tv(time); + event.type = EV_KEY; + event.code = button; + event.value = (state == LIBINPUT_BUTTON_STATE_PRESSED) ? 1 : 0; + syn_report.time = event.time; + 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; + + 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); + else + 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); +} diff --git a/src/evdev-mt-touchpad-edge-scroll.c b/src/evdev-mt-touchpad-edge-scroll.c new file mode 100644 index 0000000..25e92a6 --- /dev/null +++ b/src/evdev-mt-touchpad-edge-scroll.c @@ -0,0 +1,506 @@ +/* + * 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 "linux/input.h" + +#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) +{ + 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, + t->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) +{ + 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); + 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) +{ + 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); + } else { + tp_edge_scroll_set_state(tp, t, + EDGE_SCROLL_TOUCH_STATE_AREA); + } + 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) +{ + 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); + break; + case SCROLL_EVENT_RELEASE: + tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_NONE); + break; + case SCROLL_EVENT_TIMEOUT: + case SCROLL_EVENT_POSTED: + tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_EDGE); + break; + } +} + +static void +tp_edge_scroll_handle_edge(struct tp_dispatch *tp, + struct tp_touch *t, + enum scroll_event event) +{ + 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); + } + break; + case SCROLL_EVENT_RELEASE: + tp_edge_scroll_set_state(tp, t, EDGE_SCROLL_TOUCH_STATE_NONE); + 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) +{ + 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); + break; + } +} + +static void +tp_edge_scroll_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum scroll_event event) +{ + 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); + break; + case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW: + tp_edge_scroll_handle_edge_new(tp, t, event); + break; + case EDGE_SCROLL_TOUCH_STATE_EDGE: + tp_edge_scroll_handle_edge(tp, t, event); + break; + case EDGE_SCROLL_TOUCH_STATE_AREA: + tp_edge_scroll_handle_area(tp, t, event); + 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); +} + +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); + break; + case TOUCH_UPDATE: + tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_MOTION); + 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); + 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 }; + const struct discrete_coords zero_discrete = { 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(device, time, + bit(t->scroll.direction), + LIBINPUT_POINTER_AXIS_SOURCE_FINGER, + &zero, + &zero_discrete); + 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(device, time, + bit(axis), + LIBINPUT_POINTER_AXIS_SOURCE_FINGER, + &normalized, + &zero_discrete); + t->scroll.direction = axis; + + tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED); + } + + 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 }; + const struct discrete_coords zero_discrete = { 0.0, 0.0 }; + + tp_for_each_touch(tp, t) { + if (t->scroll.direction != -1) { + evdev_notify_axis(device, time, + bit(t->scroll.direction), + LIBINPUT_POINTER_AXIS_SOURCE_FINGER, + &zero, + &zero_discrete); + 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; +} diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c new file mode 100644 index 0000000..59e18bd --- /dev/null +++ b/src/evdev-mt-touchpad-gestures.c @@ -0,0 +1,890 @@ +/* + * 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 "evdev-mt-touchpad.h" + +#define DEFAULT_GESTURE_SWITCH_TIMEOUT ms2us(100) +#define DEFAULT_GESTURE_SWIPE_TIMEOUT ms2us(150) +#define DEFAULT_GESTURE_PINCH_TIMEOUT ms2us(150) + +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_SCROLL); + CASE_RETURN_STRING(GESTURE_STATE_PINCH); + CASE_RETURN_STRING(GESTURE_STATE_SWIPE); + } + 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 void +tp_gesture_start(struct tp_dispatch *tp, uint64_t time) +{ + const struct normalized_coords zero = { 0.0, 0.0 }; + + if (tp->gesture.started) + return; + + switch (tp->gesture.state) { + case GESTURE_STATE_NONE: + case GESTURE_STATE_UNKNOWN: + evdev_log_bug_libinput(tp->device, + "%s in unknown gesture mode\n", + __func__); + break; + case GESTURE_STATE_SCROLL: + tp_gesture_init_scroll(tp); + break; + case GESTURE_STATE_PINCH: + gesture_notify_pinch(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, + tp->gesture.finger_count, + &zero, &zero, 1.0, 0.0); + break; + case GESTURE_STATE_SWIPE: + gesture_notify_swipe(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, + tp->gesture.finger_count, + &zero, &zero); + break; + } + + tp->gesture.started = true; +} + +static void +tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time) +{ + struct device_float_coords raw; + struct normalized_coords delta; + + /* 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); + + 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 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 = atan2(normalized.y, normalized.x) * 180.0 / M_PI; + + *center = device_average(first->point, second->point); +} + +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 enum tp_gesture_state +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); + if (ntouches < 2) + return GESTURE_STATE_NONE; + + if (!tp->gesture.enabled) { + if (ntouches == 2) + return GESTURE_STATE_SCROLL; + else + return GESTURE_STATE_NONE; + } + + first = touches[0]; + second = touches[1]; + + /* For 3+ finger gestures we cheat. A human hand's finger + * arrangement means that for a 3 or 4 finger swipe gesture, the + * fingers are roughly arranged in a horizontal line. + * They will all move in the same direction, so we can simply look + * at the left and right-most ones only. If we have fake touches, we + * just take the left/right-most real touch position, since the fake + * touch has the same location as one of those. + * + * For a 3 or 4 finger pinch gesture, 2 or 3 fingers are roughly in + * a horizontal line, with the thumb below and left (right-handed + * users) or right (left-handed users). Again, the row of non-thumb + * fingers moves identically so we can look at the left and + * right-most only and then treat it like a two-finger + * gesture. + */ + if (ntouches > 2) { + second = touches[0]; + + for (i = 1; i < ntouches && i < tp->num_slots; i++) { + if (touches[i]->point.x < first->point.x) + first = touches[i]; + else if (touches[i]->point.x > second->point.x) + second = touches[i]; + } + + if (first == second) + return GESTURE_STATE_NONE; + + } + + 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; + + return GESTURE_STATE_UNKNOWN; +} + +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 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 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 enum tp_gesture_state +tp_gesture_handle_state_unknown(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 thumb_mm, finger_mm; + double inner = 1.5; /* inner threshold in mm - count this touch */ + double outer = 4.0; /* outer threshold in mm - ignore other touch */ + + /* If we have more fingers than slots, we don't know where the + * fingers are. Default to swipe */ + if (tp->gesture.enabled && tp->gesture.finger_count > 2 && + tp->gesture.finger_count > tp->num_slots) + return GESTURE_STATE_SWIPE; + + /* Need more margin for error when there are more fingers */ + outer += 2.0 * (tp->gesture.finger_count - 2); + inner += 0.5 * (tp->gesture.finger_count - 2); + + first_moved = tp_gesture_mm_moved(tp, first); + first_mm = hypot(first_moved.x, first_moved.y); + + 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 GESTURE_STATE_UNKNOWN; + + /* 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 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_set_scroll_buildup(tp); + return GESTURE_STATE_SCROLL; + } else { + return GESTURE_STATE_SWIPE; + } + } + + /* If one touch exceeds the outer threshold while the other has not + * yet passed the inner 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 >= outer || second_mm >= outer) { + /* 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 < inner) { + tp_thumb_suppress(tp, thumb); + return GESTURE_STATE_NONE; + } + + /* 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 < inner) && + tp->gesture.finger_count == 2) { + tp_gesture_set_scroll_buildup(tp); + return GESTURE_STATE_SCROLL; + } + + /* If more than 2 fingers are involved, and the thumb moves + * while the fingers stay still, assume a pinch if eligible. + */ + if (finger_mm < inner && + tp->gesture.finger_count > 2 && + tp->gesture.enabled && + tp->thumb.pinch_eligible) { + tp_gesture_init_pinch(tp); + return GESTURE_STATE_PINCH; + } + } + + /* If either touch is still inside the inner threshold, we can't + * tell what kind of gesture this is. + */ + if ((first_mm < inner) || (second_mm < inner)) + return GESTURE_STATE_UNKNOWN; + + /* Both touches have exceeded the inner 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_set_scroll_buildup(tp); + return GESTURE_STATE_SCROLL; + } else if (tp->gesture.enabled) { + return GESTURE_STATE_SWIPE; + } + } + + /* If the touches are moving away from each other, this is a pinch */ + tp_gesture_init_pinch(tp); + return GESTURE_STATE_PINCH; +} + +static enum tp_gesture_state +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 GESTURE_STATE_SCROLL; + + raw = tp_get_average_touches_delta(tp); + + /* scroll is not accelerated */ + delta = tp_filter_motion_unaccelerated(tp, &raw, time); + + if (normalized_is_zero(delta)) + return GESTURE_STATE_SCROLL; + + tp_gesture_start(tp, time); + tp_gesture_apply_scroll_constraints(tp, &raw, &delta, time); + evdev_post_scroll(tp->device, + time, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER, + &delta); + + return GESTURE_STATE_SCROLL; +} + +static enum tp_gesture_state +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_normalize_delta(tp, raw); + tp_gesture_start(tp, time); + gesture_notify_swipe(&tp->device->base, time, + LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, + tp->gesture.finger_count, + &delta, &unaccel); + } + + return GESTURE_STATE_SWIPE; +} + +static enum tp_gesture_state +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 GESTURE_STATE_PINCH; + + unaccel = tp_normalize_delta(tp, fdelta); + tp_gesture_start(tp, 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; + + return GESTURE_STATE_PINCH; +} + +static void +tp_gesture_post_gesture(struct tp_dispatch *tp, uint64_t time) +{ + enum tp_gesture_state oldstate = tp->gesture.state; + + if (tp->gesture.state == GESTURE_STATE_NONE) + tp->gesture.state = + tp_gesture_handle_state_none(tp, time); + + if (tp->gesture.state == GESTURE_STATE_UNKNOWN) + tp->gesture.state = + tp_gesture_handle_state_unknown(tp, time); + + if (tp->gesture.state == GESTURE_STATE_SCROLL) + tp->gesture.state = + tp_gesture_handle_state_scroll(tp, time); + + if (tp->gesture.state == GESTURE_STATE_SWIPE) + tp->gesture.state = + tp_gesture_handle_state_swipe(tp, time); + + if (tp->gesture.state == GESTURE_STATE_PINCH) + tp->gesture.state = + tp_gesture_handle_state_pinch(tp, time); + + if (oldstate != tp->gesture.state) + evdev_log_debug(tp->device, + "gesture state: %s → %s\n", + gesture_state_to_str(oldstate), + gesture_state_to_str(tp->gesture.state)); +} + +void +tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time) +{ + 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)) { + tp_gesture_cancel(tp, 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; + + switch (tp->gesture.finger_count) { + case 1: + if (tp->queued & TOUCHPAD_EVENT_MOTION) + tp_gesture_post_pointer_motion(tp, time); + break; + case 2: + case 3: + case 4: + tp_gesture_post_gesture(tp, time); + break; + } +} + +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, bool cancelled) +{ + enum tp_gesture_state state = tp->gesture.state; + + tp->gesture.state = GESTURE_STATE_NONE; + + if (!tp->gesture.started) + return; + + switch (state) { + case GESTURE_STATE_NONE: + case GESTURE_STATE_UNKNOWN: + evdev_log_bug_libinput(tp->device, + "%s in unknown gesture mode\n", + __func__); + break; + case GESTURE_STATE_SCROLL: + tp_gesture_stop_twofinger_scroll(tp, time); + break; + case GESTURE_STATE_PINCH: + gesture_notify_pinch_end(&tp->device->base, time, + tp->gesture.finger_count, + tp->gesture.prev_scale, + cancelled); + break; + case GESTURE_STATE_SWIPE: + gesture_notify_swipe_end(&tp->device->base, + time, + tp->gesture.finger_count, + cancelled); + break; + } + + tp->gesture.started = false; +} + +void +tp_gesture_cancel(struct tp_dispatch *tp, uint64_t time) +{ + tp_gesture_end(tp, time, true); +} + +void +tp_gesture_stop(struct tp_dispatch *tp, uint64_t time) +{ + tp_gesture_end(tp, time, false); +} + +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_cancel(tp, now); /* End current gesture */ + tp->gesture.finger_count = tp->gesture.finger_count_pending; + tp->gesture.finger_count_pending = 0; +} + +void +tp_gesture_handle_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.started) { + tp->gesture.finger_count = active_touches; + tp->gesture.finger_count_pending = 0; + /* If in UNKNOWN state, go back to NONE to + * re-evaluate leftmost and rightmost touches + */ + tp->gesture.state = GESTURE_STATE_NONE; + /* 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; + } +} + +void +tp_init_gesture(struct tp_dispatch *tp) +{ + char timer_name[64]; + + /* 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->semi_mt && tp->num_slots > 1; + + tp->gesture.state = GESTURE_STATE_NONE; + + 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); +} + +void +tp_remove_gesture(struct tp_dispatch *tp) +{ + libinput_timer_cancel(&tp->gesture.finger_count_switch_timer); +} diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c new file mode 100644 index 0000000..a482849 --- /dev/null +++ b/src/evdev-mt-touchpad-tap.c @@ -0,0 +1,1408 @@ +/* + * 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 +#include +#include + +#include "evdev-mt-touchpad.h" + +#define DEFAULT_TAP_TIMEOUT_PERIOD ms2us(180) +#define DEFAULT_DRAG_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, or + * online at + * https://drive.google.com/file/d/0B1NwWmji69noYTdMcU1kTUZuUVE/edit?usp=sharing + * (it's a http://draw.io diagram) + * + * 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_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_DRAGGING); + CASE_RETURN_STRING(TAP_STATE_DRAGGING_WAIT); + CASE_RETURN_STRING(TAP_STATE_DRAGGING_OR_DOUBLETAP); + CASE_RETURN_STRING(TAP_STATE_DRAGGING_OR_TAP); + CASE_RETURN_STRING(TAP_STATE_DRAGGING_2); + CASE_RETURN_STRING(TAP_STATE_MULTITAP); + CASE_RETURN_STRING(TAP_STATE_MULTITAP_DOWN); + CASE_RETURN_STRING(TAP_STATE_MULTITAP_PALM); + 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 > 3) + return; + + button = button_map[tp->tap.map][nfingers - 1]; + + if (state == LIBINPUT_BUTTON_STATE_PRESSED) + tp->tap.buttons_pressed |= (1 << nfingers); + else + tp->tap.buttons_pressed &= ~(1 << 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) +{ + libinput_timer_set(&tp->tap.timer, time + DEFAULT_DRAG_TIMEOUT_PERIOD); +} + +static void +tp_tap_clear_timer(struct tp_dispatch *tp) +{ + libinput_timer_cancel(&tp->tap.timer); +} + +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_TAPPED; + tp->tap.saved_release_time = time; + tp_tap_set_timer(tp, time); + } else { + tp_tap_notify(tp, + time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp->tap.state = TAP_STATE_IDLE; + } + break; + case TAP_EVENT_TIMEOUT: + case TAP_EVENT_MOTION: + tp->tap.state = TAP_STATE_HOLD; + tp_tap_clear_timer(tp); + 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: + 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) +{ + switch (event) { + case TAP_EVENT_MOTION: + case TAP_EVENT_RELEASE: + log_tap_bug(tp, t, event); + break; + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP; + 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, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + log_tap_bug(tp, t, event); + break; + case TAP_EVENT_PALM: + 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_clear_timer(tp); + /* fallthrough */ + 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_TOUCH; + tp_tap_set_timer(tp, time); /* overwrite timer */ + 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: + 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); + 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: + 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) { + tp->tap.state = TAP_STATE_TAPPED; + tp->tap.saved_release_time = time; + tp_tap_set_timer(tp, time); + } else { + tp_tap_notify(tp, + 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: + case TAP_EVENT_TIMEOUT: + tp->tap.state = TAP_STATE_TOUCH_3_HOLD; + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_RELEASE: + tp->tap.state = TAP_STATE_TOUCH_2_HOLD; + if (t->tap.state == TAP_TOUCH_STATE_TOUCH) { + tp_tap_notify(tp, + tp->tap.saved_press_time, + 3, + LIBINPUT_BUTTON_STATE_PRESSED); + tp_tap_notify(tp, time, 3, LIBINPUT_BUTTON_STATE_RELEASED); + } + 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: + 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_dragging_or_doubletap_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_DRAGGING_2; + break; + case TAP_EVENT_RELEASE: + tp->tap.state = TAP_STATE_MULTITAP; + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp->tap.saved_release_time = time; + tp_tap_set_timer(tp, time); + break; + case TAP_EVENT_MOTION: + case TAP_EVENT_TIMEOUT: + tp->tap.state = TAP_STATE_DRAGGING; + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + break; + case TAP_EVENT_PALM: + tp->tap.state = TAP_STATE_TAPPED; + 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) +{ + + switch (event) { + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_DRAGGING_2; + break; + case TAP_EVENT_RELEASE: + if (tp->tap.drag_lock_enabled) { + tp->tap.state = TAP_STATE_DRAGGING_WAIT; + tp_tap_set_drag_timer(tp, time); + } else { + tp_tap_notify(tp, + time, + 1, + 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, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + break; + case TAP_EVENT_PALM: + 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_dragging_wait_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_DRAGGING_OR_TAP; + tp_tap_set_timer(tp, time); + break; + case TAP_EVENT_RELEASE: + case TAP_EVENT_MOTION: + break; + case TAP_EVENT_TIMEOUT: + tp->tap.state = TAP_STATE_IDLE; + tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + case TAP_EVENT_PALM: + 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) +{ + + switch (event) { + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_DRAGGING_2; + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_RELEASE: + tp->tap.state = TAP_STATE_IDLE; + tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_MOTION: + case TAP_EVENT_TIMEOUT: + tp->tap.state = TAP_STATE_DRAGGING; + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, time, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + break; + case TAP_EVENT_PALM: + 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_dragging2_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum tap_event event, uint64_t time) +{ + + switch (event) { + case TAP_EVENT_RELEASE: + tp->tap.state = TAP_STATE_DRAGGING; + break; + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, time, 1, 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, 1, LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + break; + case TAP_EVENT_PALM: + tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP; + break; + case TAP_EVENT_PALM_UP: + break; + } +} + +static void +tp_tap_multitap_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum tap_event event, uint64_t time) +{ + switch (event) { + case TAP_EVENT_RELEASE: + log_tap_bug(tp, t, event); + break; + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_MULTITAP_DOWN; + tp_tap_notify(tp, + tp->tap.saved_press_time, + 1, + LIBINPUT_BUTTON_STATE_PRESSED); + tp->tap.saved_press_time = time; + tp_tap_set_timer(tp, time); + break; + 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, + tp->tap.saved_press_time, + 1, + LIBINPUT_BUTTON_STATE_PRESSED); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_IDLE; + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_THUMB: + case TAP_EVENT_PALM: + break; + case TAP_EVENT_PALM_UP: + break; + } +} + +static void +tp_tap_multitap_down_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum tap_event event, + uint64_t time) +{ + switch (event) { + case TAP_EVENT_RELEASE: + tp->tap.state = TAP_STATE_MULTITAP; + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp->tap.saved_release_time = time; + tp_tap_set_timer(tp, time); + break; + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_DRAGGING_2; + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_MOTION: + case TAP_EVENT_TIMEOUT: + tp->tap.state = TAP_STATE_DRAGGING; + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_DEAD; + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + tp_tap_clear_timer(tp); + break; + case TAP_EVENT_THUMB: + break; + case TAP_EVENT_PALM: + tp->tap.state = TAP_STATE_MULTITAP_PALM; + break; + case TAP_EVENT_PALM_UP: + break; + } +} + +static void +tp_tap_multitap_palm_handle_event(struct tp_dispatch *tp, + struct tp_touch *t, + enum tap_event event, + uint64_t time) +{ + switch (event) { + case TAP_EVENT_RELEASE: + log_tap_bug(tp, t, event); + break; + case TAP_EVENT_TOUCH: + tp->tap.state = TAP_STATE_MULTITAP_DOWN; + break; + case TAP_EVENT_MOTION: + break; + case TAP_EVENT_TIMEOUT: + case TAP_EVENT_BUTTON: + tp->tap.state = TAP_STATE_IDLE; + tp_tap_clear_timer(tp); + tp_tap_notify(tp, + tp->tap.saved_release_time, + 1, + LIBINPUT_BUTTON_STATE_RELEASED); + break; + case TAP_EVENT_THUMB: + case TAP_EVENT_PALM: + 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_TAPPED: + tp_tap_tapped_handle_event(tp, t, event, time); + 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_DRAGGING_OR_DOUBLETAP: + tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time); + break; + case TAP_STATE_DRAGGING: + tp_tap_dragging_handle_event(tp, t, event, time); + break; + case TAP_STATE_DRAGGING_WAIT: + tp_tap_dragging_wait_handle_event(tp, t, event, time); + break; + case TAP_STATE_DRAGGING_OR_TAP: + tp_tap_dragging_tap_handle_event(tp, t, event, time); + break; + case TAP_STATE_DRAGGING_2: + tp_tap_dragging2_handle_event(tp, t, event, time); + break; + case TAP_STATE_MULTITAP: + tp_tap_multitap_handle_event(tp, t, event, time); + break; + case TAP_STATE_MULTITAP_DOWN: + tp_tap_multitap_down_handle_event(tp, t, event, time); + break; + case TAP_STATE_MULTITAP_PALM: + tp_tap_multitap_palm_handle_event(tp, t, event, time); + 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 state %s → %s → %s\n", + t ? (int)t->index : -1, + 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 relased 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); + tp_tap_handle_event(tp, t, TAP_EVENT_PALM, time); + t->tap.is_palm = true; + t->tap.state = TAP_TOUCH_STATE_DEAD; + if (t->state != TOUCH_BEGIN) { + 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); + + /* If we think this is a palm, pretend there's a + * motion event which will prevent tap clicks + * without requiring extra states in the FSM. + */ + if (tp_palm_tap_is_palm(tp, t)) + tp_tap_handle_event(tp, t, TAP_EVENT_MOTION, 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_TAPPED: + case TAP_STATE_DRAGGING_OR_DOUBLETAP: + case TAP_STATE_DRAGGING_OR_TAP: + case TAP_STATE_TOUCH_2: + case TAP_STATE_TOUCH_3: + case TAP_STATE_MULTITAP_DOWN: + 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 = 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_enabled; +} + +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_enabled = 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 & (1 << 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_DRAGGING: + case TAP_STATE_DRAGGING_2: + case TAP_STATE_DRAGGING_WAIT: + case TAP_STATE_DRAGGING_OR_TAP: + return true; + default: + return false; + } +} diff --git a/src/evdev-mt-touchpad-thumb.c b/src/evdev-mt-touchpad-thumb.c new file mode 100644 index 0000000..19531e0 --- /dev/null +++ b/src/evdev-mt-touchpad-thumb.c @@ -0,0 +1,420 @@ +/* + * 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 + +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; + 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 touch (or one of them, if more). + */ + 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 (!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; + + assert(first); + assert(second); + + 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. + */ + 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; + } + + /* Position-based thumb detection: When a new touch arrives, check the + * two lowest touches. If they qualify for 2-finger scrolling, clear + * thumb status. + * + * If they were in distinct diagonal position, then mark the lower + * touch (based on pinch_eligible) as either PINCH or SUPPRESSED. If + * we're too close together for a thumb, lift that. + */ + if (mm.y > SCROLL_MM_Y && mm.x > SCROLL_MM_X) { + if (tp->thumb.pinch_eligible) + tp_thumb_pinch(tp, first); + else + tp_thumb_suppress(tp, first); + } else if (mm.x < SCROLL_MM_X && mm.y < SCROLL_MM_Y) { + 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; + + /* 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" : ""); +} diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c new file mode 100644 index 0000000..4ffc4a3 --- /dev/null +++ b/src/evdev-mt-touchpad.c @@ -0,0 +1,3749 @@ +/* + * 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" + +#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 (1 << 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); +} + +static inline void +tp_calculate_motion_speed(struct tp_dispatch *tp, struct tp_touch *t) +{ + 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/(t->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) +{ + 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 = t->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 contraints 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 |= (1 << 2); + if (t->hysteresis.x_motion_history == r_l_r) { + tp->hysteresis.enabled = true; + evdev_log_debug(tp->device, + "hysteresis enabled. " + "See %stouchpad-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; + else /* 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 |= 1 << shift; + + } else { + tp->fake_touches &= ~(0x1 << 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->time = time; + 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->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->time = time; + 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->time = time; + 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->time = time; + 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_new_touch(tp, t, time); + else + tp_end_sequence(tp, t, time); + break; + case ABS_MT_PRESSURE: + t->pressure = e->value; + t->time = time; + t->dirty = true; + tp->queued |= TOUCHPAD_EVENT_OTHERAXIS; + break; + case ABS_MT_TOOL_TYPE: + t->is_tool_palm = e->value == MT_TOOL_PALM; + t->time = time; + 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->time = time; + 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->time = time; + t->dirty = true; + tp->queued |= TOUCHPAD_EVENT_MOTION; + break; + case ABS_PRESSURE: + t->pressure = e->value; + t->time = time; + 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 BTN_TOOL_TRIPLETAP + * and start it again on the next frame with different coordinates + * (#91352). 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. + */ + 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); + + 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) +{ + 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); +} + +bool +tp_palm_tap_is_palm(const struct tp_dispatch *tp, const struct tp_touch *t) +{ + if (t->state != TOUCH_BEGIN) + return false; + + if (!tp_palm_in_edge(tp, t)) + return false; + + evdev_log_debug(tp->device, + "palm: touch %d: palm-tap detected\n", + t->index); + return true; +} + +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; + } else 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; + } else 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; + } else 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; + + /* don't detect palm in software button areas, it's + likely that legitimate touches start in the area + covered by the exclusion zone */ + if (tp->buttons.is_clickpad && + tp_button_is_inside_softbutton_area(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, palm detected (%s)\n", + t->index, + 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); + + /* 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 25ms ago, we have irregular + * frames, who knows what's a pointer jump here and what's + * legitimate movement.... */ + if (tdelta > 2 * 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; + + /* 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 fictious + 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); + continue; + } + + if (tp_detect_jumps(tp, t, time)) { + if (!tp->semi_mt) + evdev_log_bug_kernel(tp->device, + "Touch jump detected and discarded.\n" + "See %stouchpad-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); + + /* 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); + + 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_handle_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); +} + +static void +tp_post_events(struct tp_dispatch *tp, uint64_t time) +{ + int filter_motion = 0; + + /* Only post (top) button events while suspended */ + if (tp->device->is_suspended) { + tp_post_button_events(tp, time); + return; + } + + filter_motion |= tp_tap_handle_state(tp, time); + filter_motion |= tp_post_button_events(tp, time); + + if (filter_motion || + tp->palm.trackpoint_active || + tp->dwt.keyboard_active) { + tp_edge_scroll_stop_events(tp, time); + tp_gesture_cancel(tp, time); + return; + } + + if (tp_edge_scroll_post_events(tp, time) != 0) + return; + + tp_gesture_post_events(tp, time); +} + +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); +} + +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); + + libinput_timer_cancel(&tp->arbitration.arbitration_timer); + + 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); + 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; + + 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); +} + +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; + + /* 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_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; + + 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 */ + is_modifier = tp_key_is_modifier(key); + if (is_modifier) { + 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; + else 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_tp = libevdev_get_id_bustype(touchpad->evdev), + 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 = bus_tp != BUS_USB && bus_tp != BUS_BLUETOOTH; + 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, *tmp; + + 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, tmp, &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; + } else if (streq(prop, "external")) { + evdev_tag_touchpad_external(device); + return; + } else { + evdev_log_info(device, + "tagged with unknown value %s\n", + prop); + } + } + + /* simple approach: touchpads on USB or Bluetooth are considered + * external, anything else is internal. Exception is Apple - + * internal touchpads are connected over USB and it doesn't have + * external USB touchpads anyway. + */ + bustype = libevdev_get_id_bustype(device->evdev); + vendor = libevdev_get_id_vendor(device->evdev); + + switch (bustype) { + case BUS_USB: + if (evdev_device_has_model_quirk(device, + QUIRK_MODEL_APPLE_TOUCHPAD)) + evdev_tag_touchpad_internal(device); + break; + 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 }, + }; + struct map *m; + 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 uint32_t +tp_accel_config_get_profiles(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static enum libinput_config_status +tp_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 +tp_accel_config_get_profile(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static enum libinput_config_accel_profile +tp_accel_config_get_default_profile(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static bool +tp_init_accel(struct tp_dispatch *tp) +{ + 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 elipse 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 (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 if (libevdev_get_id_bustype(device->evdev) == BUS_BLUETOOTH) + filter = create_pointer_accelerator_filter_touchpad(dpi, + ms2us(50), + ms2us(10), + use_v_avg); + else + filter = create_pointer_accelerator_filter_touchpad(dpi, 0, 0, use_v_avg); + + if (!filter) + return false; + + evdev_device_init_pointer_acceleration(tp->device, filter); + + /* we override the profile hooks for accel configuration with hooks + * that don't allow selection of profiles */ + device->pointer.config.get_profiles = tp_accel_config_get_profiles; + device->pointer.config.set_profile = tp_accel_config_set_profile; + device->pointer.config.get_profile = tp_accel_config_get_profile; + device->pointer.config.get_default_profile = tp_accel_config_get_default_profile; + + return true; +} + +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 void +tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device) +{ + tp_edge_scroll_init(tp, device); + + evdev_init_natural_scroll(device); + + 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 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; + + return; +} + +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; + + 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); + 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) { + evdev_log_bug_client(device, + "palm: ignoring invalid threshold %d\n", + threshold); + } else { + 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 %stouchpad-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 { + unsigned int range = abs->maximum - abs->minimum; + + /* 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 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); + + 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); + + /* 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)) + return false; + + tp_init_tap(tp); + tp_init_buttons(tp, device); + tp_init_dwt(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); + + 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; +} diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h new file mode 100644 index 0000000..5df284f --- /dev/null +++ b/src/evdev-mt-touchpad.h @@ -0,0 +1,716 @@ +/* + * 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 "filter.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, +}; + +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_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_DRAGGING_OR_DOUBLETAP, + TAP_STATE_DRAGGING_OR_TAP, + TAP_STATE_DRAGGING, + TAP_STATE_DRAGGING_WAIT, + TAP_STATE_DRAGGING_2, + TAP_STATE_MULTITAP, + TAP_STATE_MULTITAP_DOWN, + TAP_STATE_MULTITAP_PALM, + 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_SCROLL, + GESTURE_STATE_PINCH, + GESTURE_STATE_SWIPE, +}; + +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 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 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; + + /* 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 { + bool enabled; + bool started; + 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; + } 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; + } 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; + bool drag_lock_enabled; + + unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */ + } tap; + + struct { + 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); + +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_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 time); + +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); + +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_handle_state(struct tp_dispatch *tp, uint64_t time); + +void +tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time); + +void +tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time); + +bool +tp_palm_tap_is_palm(const struct tp_dispatch *tp, const struct tp_touch *t); + +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); + +#endif diff --git a/src/evdev-tablet-pad-leds.c b/src/evdev-tablet-pad-leds.c new file mode 100644 index 0000000..b741d0c --- /dev/null +++ b/src/evdev-tablet-pad-leds.c @@ -0,0 +1,637 @@ +/* + * 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 "evdev-tablet-pad.h" + +#if HAVE_LIBWACOM +#include +#endif + +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; +}; + +struct pad_mode_led { + struct list link; + /* /sys/devices/..../input1235/input1235::wacom-led_0.1/brightness */ + int brightness_fd; + int mode_idx; +}; + +static inline struct pad_mode_toggle_button * +pad_mode_toggle_button_new(struct pad_dispatch *pad, + struct libinput_tablet_pad_mode_group *group, + unsigned int button_index) +{ + struct pad_mode_toggle_button *button; + + button = zalloc(sizeof *button); + button->button_index = button_index; + + return button; +} + +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; + } + + return -EINVAL; +} + +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); +} + +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; + + 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); + if (fd < 0) { + errno = -fd; + goto error; + } + + led->brightness_fd = fd; + + return led; + +error: + pad_led_destroy(libinput, led); + return NULL; +} + +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, *tmp; + struct pad_mode_led *led, *tmpled; + + list_for_each_safe(button, tmp, &group->toggle_button_list, link) + pad_mode_toggle_button_destroy(button); + + list_for_each_safe(led, tmpled, &group->led_list, link) + pad_led_destroy(g->device->seat->libinput, led); + + free(group); +} + +static struct pad_led_group * +pad_group_new_basic(struct pad_dispatch *pad, + unsigned int group_index, + int nleds) +{ + 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 = nleds; + group->base.destroy = pad_led_group_destroy; + list_init(&group->toggle_button_list); + list_init(&group->led_list); + + return group; +} + +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_led_group * +pad_group_new(struct pad_dispatch *pad, + unsigned int group_index, + int nleds, + const char *syspath) +{ + struct libinput *libinput = pad->device->base.seat->libinput; + struct pad_led_group *group; + int rc; + + group = pad_group_new_basic(pad, group_index, nleds); + if (!group) + return NULL; + + while (nleds--) { + struct pad_mode_led *led; + + led = pad_led_new(libinput, syspath, group_index, nleds); + if (!led) + goto error; + + list_insert(&group->led_list, &led->link); + } + + rc = pad_led_group_get_mode(group); + if (rc < 0) { + errno = -rc; + goto error; + } + + group->base.current_mode = rc; + + return group; + +error: + if (!is_litest_device(pad->device)) + evdev_log_error(pad->device, + "unable to init LED group: %s\n", + strerror(errno)); + pad_led_group_destroy(&group->base); + + return NULL; +} + +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; +} + +#if HAVE_LIBWACOM +static int +pad_init_led_groups(struct pad_dispatch *pad, + struct evdev_device *device, + WacomDevice *wacom) +{ + const WacomStatusLEDs *leds; + int nleds, nmodes; + int i; + struct pad_led_group *group; + char syspath[PATH_MAX]; + + leds = libwacom_get_status_leds(wacom, &nleds); + if (nleds == 0) + return 1; + + /* 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 1; + + for (i = 0; i < nleds; i++) { + switch(leds[i]) { + case WACOM_STATUS_LED_UNAVAILABLE: + evdev_log_bug_libinput(device, + "Invalid led type %d\n", + leds[i]); + return 1; + case WACOM_STATUS_LED_RING: + nmodes = libwacom_get_ring_num_modes(wacom); + group = pad_group_new(pad, i, nmodes, syspath); + if (!group) + return 1; + list_insert(&pad->modes.mode_group_list, &group->base.link); + break; + case WACOM_STATUS_LED_RING2: + nmodes = libwacom_get_ring2_num_modes(wacom); + group = pad_group_new(pad, i, nmodes, syspath); + if (!group) + return 1; + list_insert(&pad->modes.mode_group_list, &group->base.link); + break; + case WACOM_STATUS_LED_TOUCHSTRIP: + nmodes = libwacom_get_strips_num_modes(wacom); + group = pad_group_new(pad, i, nmodes, syspath); + if (!group) + return 1; + list_insert(&pad->modes.mode_group_list, &group->base.link); + break; + case WACOM_STATUS_LED_TOUCHSTRIP2: + /* there is no get_strips2_... */ + nmodes = libwacom_get_strips_num_modes(wacom); + group = pad_group_new(pad, i, nmodes, syspath); + if (!group) + return 1; + list_insert(&pad->modes.mode_group_list, &group->base.link); + break; + } + } + + return 0; +} + +#endif + +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 int +pad_find_button_group(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 libwacom_get_button_led_group(wacom, 'A' + i); + } + + return -1; +} + +static int +pad_init_mode_buttons(struct pad_dispatch *pad, + WacomDevice *wacom) +{ + struct libinput_tablet_pad_mode_group *group; + unsigned int group_idx; + int i; + WacomButtonFlags flags; + + /* libwacom numbers buttons as 'A', 'B', etc. We number them with 0, + * 1, ... + */ + for (i = 0; i < libwacom_get_num_buttons(wacom); i++) { + group_idx = libwacom_get_button_led_group(wacom, 'A' + i); + flags = libwacom_get_button_flag(wacom, 'A' + i); + + /* If this button is not a mode toggle button, find the mode + * toggle button with the same position flags and take that + * button's group idx */ + if ((int)group_idx == -1) { + group_idx = pad_find_button_group(wacom, i, flags); + } + + if ((int)group_idx == -1) { + evdev_log_bug_libinput(pad->device, + "unhandled position for button %i\n", + i); + return 1; + } + + group = pad_get_mode_group(pad, group_idx); + if (!group) { + evdev_log_bug_libinput(pad->device, + "Failed to find group %d for button %i\n", + group_idx, + i); + return 1; + } + + group->button_mask |= 1 << i; + + if (flags & WACOM_BUTTON_MODESWITCH) { + struct pad_mode_toggle_button *b; + struct pad_led_group *g; + + b = pad_mode_toggle_button_new(pad, group, i); + if (!b) + return 1; + g = (struct pad_led_group*)group; + list_insert(&g->toggle_button_list, &b->link); + group->toggle_button_mask |= 1 << i; + } + } + + return 0; +} + +static void +pad_init_mode_rings(struct pad_dispatch *pad, WacomDevice *wacom) +{ + struct libinput_tablet_pad_mode_group *group; + const WacomStatusLEDs *leds; + int i, nleds; + + leds = libwacom_get_status_leds(wacom, &nleds); + if (nleds == 0) + return; + + for (i = 0; i < nleds; i++) { + switch(leds[i]) { + case WACOM_STATUS_LED_RING: + group = pad_get_mode_group(pad, i); + group->ring_mask |= 0x1; + break; + case WACOM_STATUS_LED_RING2: + group = pad_get_mode_group(pad, i); + group->ring_mask |= 0x2; + break; + default: + break; + } + } +} + +static void +pad_init_mode_strips(struct pad_dispatch *pad, WacomDevice *wacom) +{ + struct libinput_tablet_pad_mode_group *group; + const WacomStatusLEDs *leds; + int i, nleds; + + leds = libwacom_get_status_leds(wacom, &nleds); + if (nleds == 0) + return; + + for (i = 0; i < nleds; i++) { + switch(leds[i]) { + case WACOM_STATUS_LED_TOUCHSTRIP: + group = pad_get_mode_group(pad, i); + group->strip_mask |= 0x1; + break; + case WACOM_STATUS_LED_TOUCHSTRIP2: + group = pad_get_mode_group(pad, i); + group->strip_mask |= 0x2; + break; + default: + break; + } + } +} + +static int +pad_init_leds_from_libwacom(struct pad_dispatch *pad, + struct evdev_device *device) +{ + struct libinput *li = pad_libinput_context(pad); + WacomDeviceDatabase *db = NULL; + WacomDevice *wacom = NULL; + int rc = 1; + + db = libinput_libwacom_ref(li); + if (!db) + goto out; + + wacom = libwacom_new_from_path(db, + udev_device_get_devnode(device->udev_device), + WFALLBACK_NONE, + NULL); + if (!wacom) + goto out; + + rc = pad_init_led_groups(pad, device, wacom); + if (rc != 0) + goto out; + + if ((rc = pad_init_mode_buttons(pad, wacom)) != 0) + goto out; + + pad_init_mode_rings(pad, wacom); + pad_init_mode_strips(pad, wacom); + +out: + if (wacom) + libwacom_destroy(wacom); + if (db) + libinput_libwacom_unref(li); + + if (rc != 0) + 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_basic(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.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) +{ + 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); +#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, *tmpgrp; + + list_for_each_safe(group, tmpgrp, &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; + + if (state != LIBINPUT_BUTTON_STATE_PRESSED) + return; + + if (!libinput_tablet_pad_mode_group_button_is_toggle(g, button_index)) + return; + + 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); +} diff --git a/src/evdev-tablet-pad.c b/src/evdev-tablet-pad.c new file mode 100644 index 0000000..cb02726 --- /dev/null +++ b/src/evdev-tablet-pad.c @@ -0,0 +1,757 @@ +/* + * 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 +#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_absolute(struct pad_dispatch *pad, + struct evdev_device *device, + struct input_event *e, + uint64_t time) +{ + switch (e->code) { + case ABS_WHEEL: + pad->changed_axes |= PAD_AXIS_RING1; + pad_set_status(pad, PAD_AXES_UPDATED); + break; + case ABS_THROTTLE: + pad->changed_axes |= PAD_AXIS_RING2; + pad_set_status(pad, PAD_AXES_UPDATED); + break; + case ABS_RX: + pad->changed_axes |= PAD_AXIS_STRIP1; + pad_set_status(pad, PAD_AXES_UPDATED); + break; + case ABS_RY: + pad->changed_axes |= PAD_AXIS_STRIP2; + pad_set_status(pad, PAD_AXES_UPDATED); + 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; + } +} + +static inline double +normalize_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->maximum - absinfo->minimum + 1; + double value = (absinfo->value - absinfo->minimum) / range - 0.25; + + if (value < 0.0) + value += 1.0; + + return value; +} + +static inline double +normalize_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 +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_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; + + pos = normalize_strip(absinfo); + + if (device->left_handed.enabled) + pos = 1.0 - pos; + + return pos; +} + +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; + + 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; + + 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; + char map; + + code++; + enabled = (buttons_slice & 1); + buttons_slice >>= 1; + + if (!enabled) + continue; + + map = pad->button_map[code - 1]; + if (map != -1) { + group = pad_button_get_mode_group(pad, map); + pad_button_update_mode(group, map, state); + tablet_pad_notify_button(base, time, map, state, group); + } + } + } +} + +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)); +} + +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_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) +{ + bool rc = false; +#if HAVE_LIBWACOM_GET_BUTTON_EVDEV_CODE + struct libinput *li = pad_libinput_context(pad); + WacomDeviceDatabase *db = NULL; + WacomDevice *tablet = NULL; + int num_buttons; + int map = 0; + + db = libinput_libwacom_ref(li); + if (!db) + goto out; + + tablet = libwacom_new_from_usbid(db, + evdev_device_get_id_vendor(device), + evdev_device_get_id_product(device), + NULL); + if (!tablet) + goto out; + + num_buttons = libwacom_get_num_buttons(tablet); + for (int i = 0; i < num_buttons; i++) { + unsigned int code; + + code = libwacom_get_button_evdev_code(tablet, 'A' + i); + if (code == 0) + continue; + + pad->button_map[code] = map++; + } + + pad->nbuttons = map; + + rc = true; +out: + if (tablet) + libwacom_destroy(tablet); + if (db) + libinput_libwacom_unref(li); +#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)) + pad->button_map[code] = map++; + } + + for (code = BTN_BASE; code < BTN_BASE + 2; code++) { + if (libevdev_has_event_code(device->evdev, EV_KEY, code)) + pad->button_map[code] = map++; + } + + for (code = BTN_A; code < BTN_A + 6; code++) { + if (libevdev_has_event_code(device->evdev, EV_KEY, code)) + pad->button_map[code] = map++; + } + + for (code = BTN_LEFT; code < BTN_LEFT + 7; code++) { + if (libevdev_has_event_code(device->evdev, EV_KEY, code)) + pad->button_map[code] = map++; + } + + pad->nbuttons = map; +} + +static void +pad_init_buttons(struct pad_dispatch *pad, + struct evdev_device *device) +{ + size_t i; + + for (i = 0; i < ARRAY_LENGTH(pad->button_map); i++) + pad->button_map[i] = -1; + + if (!pad_init_buttons_from_libwacom(pad, device)) + pad_init_buttons_from_kernel(pad, device); + +} + +static void +pad_init_left_handed(struct evdev_device *device) +{ + if (evdev_tablet_has_left_handed(device)) + evdev_init_left_handed(device, + pad_change_to_left_handed); +} + +static int +pad_init(struct pad_dispatch *pad, struct evdev_device *device) +{ + 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; + + pad_init_buttons(pad, device); + pad_init_left_handed(device); + if (pad_init_leds(pad, device) != 0) + return 1; + + return 0; +} + +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_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_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; +} diff --git a/src/evdev-tablet-pad.h b/src/evdev-tablet-pad.h new file mode 100644 index 0000000..6208caf --- /dev/null +++ b/src/evdev-tablet-pad.h @@ -0,0 +1,96 @@ +/* + * 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" + +#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), +}; + +struct button_state { + unsigned char bits[NCHARS(KEY_CNT)]; +}; + +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; + + char button_map[KEY_CNT]; + unsigned int nbuttons; + + bool have_abs_misc_terminator; + + struct { + struct libinput_device_config_send_events config; + enum libinput_config_send_events_mode current_mode; + } sendevents; + + struct { + struct list mode_group_list; + } modes; +}; + +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); +void +pad_destroy_leds(struct pad_dispatch *pad); +void +pad_button_update_mode(struct libinput_tablet_pad_mode_group *g, + unsigned int pressed_button, + enum libinput_button_state state); +#endif diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c new file mode 100644 index 0000000..6358dc4 --- /dev/null +++ b/src/evdev-tablet.c @@ -0,0 +1,2382 @@ +/* + * 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 "libinput-version.h" +#include "evdev-tablet.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]); +} + +/* 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 ARRAY_LENGTH(tablet->history.samples); +} + +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 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) +{ + double range = absinfo->maximum - absinfo->minimum; + double value = (absinfo->value - absinfo->minimum) / range; + + return value * 2 - 1; +} + +static inline double +normalize_distance(const struct input_absinfo *absinfo) +{ + double range = absinfo->maximum - absinfo->minimum; + double value = (absinfo->value - absinfo->minimum) / range; + + return value; +} + +static inline double +normalize_pressure(const struct input_absinfo *absinfo, + struct libinput_tablet_tool *tool) +{ + int offset; + double range; + double value; + + /** + * If the tool has a pressure offset, we use that as the lower bound + * for the scaling range. If not, we use the upper threshold as the + * lower bound, so once we get past that minimum physical pressure + * we have logical 0 pressure. + * + * This means that there is a small range (lower-upper) where + * different physical pressure (default: 1-5%) result in the same + * logical pressure. This is, hopefully, not noticable. + * + * Note that that lower-upper range gives us a negative pressure, so + * we have to clip to 0 for those. + */ + + if (tool->has_pressure_offset) + offset = tool->pressure_offset; + else + offset = tool->pressure_threshold.upper; + range = absinfo->maximum - offset; + value = (absinfo->value - offset) / range; + + return max(0.0, value); +} + +static inline double +adjust_tilt(const struct input_absinfo *absinfo) +{ + double range = absinfo->maximum - absinfo->minimum; + double value = (absinfo->value - absinfo->minimum) / range; + 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 = 180.0/M_PI * 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 = ((180.0 * atan2(-x, y)) / M_PI); + + 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 range = absinfo->maximum - absinfo->minimum + 1; + double value = (absinfo->value - absinfo->minimum) / range; + + 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 inline void +tablet_update_xy(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + const struct input_absinfo *absinfo; + int value; + + if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) || + bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) { + absinfo = libevdev_get_abs_info(device->evdev, ABS_X); + + if (tablet->rotation.rotate) + value = invert_axis(absinfo); + else + value = absinfo->value; + + tablet->axes.point.x = value; + + absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); + + if (tablet->rotation.rotate) + value = invert_axis(absinfo); + else + value = absinfo->value; + + tablet->axes.point.y = value; + + evdev_transform_absolute(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 *absinfo; + + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); + tablet->axes.pressure = normalize_pressure(absinfo, tool); + } +} + +static inline void +tablet_update_distance(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + const struct input_absinfo *absinfo; + + 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 (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; + + /* 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 (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: + 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; + + 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 int +tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, + struct libinput_tablet_tool *tool) +{ + int rc = 1; + +#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) >= 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 = 0; +#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 HAVE_LIBWACOM + if (tool_set_bits_from_libwacom(tablet, tool) == 0) + return; +#endif + /* 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); + 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 inline int +axis_range_percentage(const struct input_absinfo *a, double percent) +{ + return (a->maximum - a->minimum) * percent/100.0 + a->minimum; +} + +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) { + const struct input_absinfo *pressure; + + tool = zalloc(sizeof *tool); + + *tool = (struct libinput_tablet_tool) { + .type = type, + .serial = serial, + .tool_id = tool_id, + .refcount = 1, + }; + + tool->pressure_offset = 0; + tool->has_pressure_offset = false; + tool->pressure_threshold.lower = 0; + tool->pressure_threshold.upper = 1; + + pressure = libevdev_get_abs_info(tablet->device->evdev, + ABS_PRESSURE); + if (pressure) { + tool->pressure_offset = pressure->minimum; + + /* 5 and 1% of the pressure range */ + tool->pressure_threshold.upper = + axis_range_percentage(pressure, 5); + tool->pressure_threshold.lower = + axis_range_percentage(pressure, 1); + } + + tool_set_bits(tablet, tool); + + list_insert(tool_list, &tool->link); + } + + 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; + + tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? + LIBINPUT_TABLET_TOOL_TIP_DOWN : 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); + } +} + +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); + pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); + + if (!pressure || !distance) + return; + + if (!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) && + !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + return; + + tool_in_contact = (pressure->value > tool->pressure_offset); + + /* Keep distance and pressure mutually exclusive */ + if (distance && + (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || + bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) && + 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 (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE) && + !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 +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 (!bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + return; + + pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); + distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); + + if (!pressure || !distance) + return; + + offset = pressure->value; + + /* 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 (tool->has_pressure_offset) { + if (offset < tool->pressure_offset) + tool->pressure_offset = offset; + return; + } + + if (offset <= pressure->minimum) + return; + + /* we only set a pressure offset on proximity in */ + if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) + return; + + /* 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; + + if (offset > axis_range_percentage(pressure, 20)) { + evdev_log_error(device, + "Ignoring pressure offset greater than 20%% detected on tool %s (serial %#x). " + "See %stablet-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 %stablet-support.html\n", + tablet_tool_type_to_string(tool->type), + tool->serial, + HTTP_DOC_LINK); + tool->pressure_offset = offset; + tool->has_pressure_offset = true; + tool->pressure_threshold.lower = pressure->minimum; +} + +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; + + if (tool->has_pressure_offset) + pressure -= (tool->pressure_offset - p->minimum); + + if (pressure <= tool->pressure_threshold.lower && + tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { + tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + } else if (pressure >= tool->pressure_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, 50mm north of the + * tip, and 200x200mm 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 rescale 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 - 50; + r.h = 200; + 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_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 bool +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)) + return false; + + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, + tablet->changed_axes, + axes); + + tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); + tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); + + tablet_reset_changed_axes(tablet); + axes->delta.x = 0; + axes->delta.y = 0; + + return true; +} + +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_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_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_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; + + /* Dont' 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); + + if (tablet_send_proximity_out(tablet, tool, device, &axes, time)) { + tablet_change_to_left_handed(device); + tablet_apply_rotation(device); + tablet_history_reset(tablet); + } +} + +/** + * 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 void +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; + + /* 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; + + /* Kernel tools are supposed to be mutually exclusive, if we have + * two set discard the most recent one. */ + if (tablet->tool_state & (tablet->tool_state - 1)) { + evdev_log_bug_kernel(device, + "Multiple tools active simultaneously (%#x)\n", + tablet->tool_state); + tablet->tool_state = tablet->prev_tool_state; + goto out; + } + + 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. + * + * We can't do so permanently though, some tablets + * send the correct event sequence occasionally but + * are broken otherwise. + */ + libinput_timer_cancel(&tablet->quirks.prox_out_timer); + } + } + +out: + tablet->prev_tool_state = tablet->tool_state; + +} + +static void +tablet_flush(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint64_t time) +{ + struct libinput_tablet_tool *tool; + + tablet_update_tool_state(tablet, device, time); + if (tablet->current_tool.type == LIBINPUT_TOOL_NONE) + return; + + tool = tablet_get_tool(tablet, + tablet->current_tool.type, + tablet->current_tool.id, + tablet->current_tool.serial); + + 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); + } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) || + tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { + if (tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) + tablet_mark_all_axes_changed(tablet, tool); + detect_pressure_offset(tablet, device, tool); + detect_tool_contact(tablet, device, tool); + sanitize_tablet_axes(tablet, tool); + } + + tablet_send_events(tablet, tool, device, time); +} + +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) +{ + /* Update state */ + memcpy(&tablet->prev_button_state, + &tablet->button_state, + sizeof(tablet->button_state)); + tablet_unset_status(tablet, TABLET_TOOL_UPDATED); +} + +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 }, + }; + struct input_event *e; + + if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { + 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"); + + ARRAY_FOR_EACH(events, e) { + tablet->base.interface->process(&tablet->base, + tablet->device, + e, + now); + } + + 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, *tmp; + 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_safe(tool, tmp, &tablet->tool_list, link) { + libinput_tablet_tool_unref(tool); + } + + libinput_libwacom_unref(li); + + free(tablet); +} + +static void +tablet_device_added(struct evdev_device *device, + struct evdev_device *added_device) +{ + struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); + bool is_touchscreen, is_ext_touchpad; + + if (libinput_device_get_device_group(&device->base) != + libinput_device_get_device_group(&added_device->base)) + return; + + 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); + /* Touch screens or external touchpads only */ + if (is_touchscreen || is_ext_touchpad) { + evdev_log_debug(device, + "touch-arbitration: activated for %s<->%s\n", + device->devname, + added_device->devname); + tablet->touch_device = added_device; + } + + if (is_ext_touchpad) { + evdev_log_debug(device, + "tablet-rotation: %s will rotate %s\n", + device->devname, + added_device->devname); + tablet->rotation.touch_device = added_device; + + if (libinput_device_config_left_handed_get(&added_device->base)) { + tablet->rotation.touch_device_left_handed_state = true; + tablet_change_rotation(device, DO_NOTIFY); + } + } + +} + +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); + 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) +{ + if (libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) + evdev_init_calibration(device, &tablet->calibration); +} + +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) +{ + if (evdev_tablet_has_left_handed(device)) + evdev_init_left_handed(device, + tablet_change_to_left_handed); +} + +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 int +tablet_init(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + struct libevdev *evdev = device->evdev; + enum libinput_tablet_tool_axis axis; + int rc; + + 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)) + return -1; + + 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_init_calibration(tablet, device); + tablet_init_proximity_threshold(tablet, device); + rc = tablet_init_accel(tablet, device); + if (rc != 0) + return rc; + + tablet_init_left_handed(device); + + 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; + if (evdev_device_has_model_quirk(device, QUIRK_MODEL_WACOM_ISDV4_PEN)) + tablet->quirks.need_to_force_prox_out = false; + + libinput_timer_init(&tablet->quirks.prox_out_timer, + tablet_libinput_context(tablet), + "proxout", + tablet_proximity_out_quirk_timer_func, + tablet); + + return 0; +} + +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; +} diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h new file mode 100644 index 0000000..ab95b61 --- /dev/null +++ b/src/evdev-tablet.h @@ -0,0 +1,264 @@ +/* + * 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" + +#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_RELEASED = bit(2), + TABLET_TOOL_UPDATED = bit(3), + TABLET_TOOL_IN_CONTACT = bit(4), + TABLET_TOOL_LEAVING_PROXIMITY = bit(5), + TABLET_TOOL_OUT_OF_PROXIMITY = bit(6), + TABLET_TOOL_ENTERING_PROXIMITY = bit(7), + TABLET_TOOL_ENTERING_CONTACT = bit(8), + TABLET_TOOL_LEAVING_CONTACT = bit(9), + TABLET_TOOL_OUT_OF_RANGE = bit(10), +}; + +struct button_state { + unsigned char bits[NCHARS(KEY_CNT)]; +}; + +struct tablet_dispatch { + struct evdev_dispatch base; + struct evdev_device *device; + 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]; + } 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; + + /* 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; + } 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 diff --git a/src/evdev-totem.c b/src/evdev-totem.c new file mode 100644 index 0000000..6f0a851 --- /dev/null +++ b/src/evdev-totem.c @@ -0,0 +1,829 @@ +/* + * 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, + }; + + tool->pressure_offset = 0; + tool->has_pressure_offset = false; + tool->pressure_threshold.lower = 0; + tool->pressure_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) +{ + 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); + totem_slot_reset_changed_axes(totem, slot); + tablet_notify_tip(&device->base, + time, + slot->tool, + tip_state, + slot->changed_axes, + &axes); + 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); + } + 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); + + 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); + 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); + 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); + + 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); + } + tablet_notify_proximity(&device->base, + now, + slot->tool, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, + slot->changed_axes, + &axes); + } + 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); + totem_slot_reset_changed_axes(totem, slot); + tablet_notify_tip(&device->base, + now, + slot->tool, + LIBINPUT_TABLET_TOOL_TIP_DOWN, + slot->changed_axes, + &axes); + slot->state = SLOT_STATE_UPDATE; + enable_touch = false; + } + + totem_set_touch_device_enabled(totem, enable_touch, now); +} + +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_added, /* treat as remove */ + .device_resumed = totem_interface_device_removed, /* 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; + 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_size |= libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MAJOR) > 0; + has_size |= libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MINOR) > 0; + + if (has_xy && has_slot && has_tool_dial && has_size) + return false; + + evdev_log_bug_libinput(device, + "missing totem capabilities:%s%s%s%s. " + "Ignoring this device.\n", + has_xy ? "" : " xy", + has_slot ? "" : " slot", + has_tool_dial ? "" : " dial", + has_size ? "" : " resolutions"); + 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; +} diff --git a/src/evdev.c b/src/evdev.c new file mode 100644 index 0000000..99713f2 --- /dev/null +++ b/src/evdev.c @@ -0,0 +1,2810 @@ +/* + * 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 + +#include "libinput.h" +#include "evdev.h" +#include "filter.h" +#include "libinput-private.h" +#include "quirks.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 inline bool +parse_udev_flag(struct evdev_device *device, + struct udev_device *udev_device, + const char *property) +{ + const char *val; + + val = udev_device_get_property_value(udev_device, property); + if (!val) + return false; + + if (streq(val, "1")) + return true; + if (!streq(val, "0")) + evdev_log_error(device, + "property %s has invalid value '%s'\n", + property, + val); + return false; +} + +int +evdev_update_key_down_count(struct evdev_device *device, + int code, + int pressed) +{ + int key_count; + assert(code >= 0 && code < KEY_CNT); + + if (pressed) { + key_count = ++device->key_count[code]; + } else { + assert(device->key_count[code] > 0); + key_count = --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) +{ + if (is_press) { + 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); + 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 }, + }; + 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); +} + +static inline double +scale_axis(const struct input_absinfo *absinfo, double val, double to_range) +{ + return (val - absinfo->minimum) * to_range / + (absinfo->maximum - absinfo->minimum + 1); +} + +double +evdev_device_transform_x(struct evdev_device *device, + double x, + uint32_t width) +{ + return scale_axis(device->abs.absinfo_x, x, width); +} + +double +evdev_device_transform_y(struct evdev_device *device, + double y, + uint32_t height) +{ + return scale_axis(device->abs.absinfo_y, y, height); +} + +void +evdev_notify_axis(struct evdev_device *device, + uint64_t time, + uint32_t axes, + enum libinput_pointer_axis_source source, + 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(&device->base, + time, + axes, + source, + &delta, + &discrete); +} + +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; +} + +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->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) +{ + /* could enable this on Apple touchpads. could do that, could + * very well do that... */ + 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_UNKNOWN; + } 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_UNKNOWN; + } else if (r == RELIABILITY_WRITE_OPEN) { + evdev_log_info(device, "will write switch open events\n"); + } + + quirks_unref(q); + + return r; +} + +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(tv2us(&e->time)); + + 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 = tv2us(&e->time); + +#if 0 + 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 void +evdev_device_dispatch(void *data) +{ + struct evdev_device *device = data; + struct libinput *libinput = evdev_libinput_context(device); + struct input_event ev; + int rc; + + /* 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) { + evdev_device_dispatch_one(device, &ev); + } + } 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; + + if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) + filter = create_pointer_accelerator_filter_flat(device->dpi); + else if (device->tags & EVDEV_TAG_TRACKPOINT) + filter = create_pointer_accelerator_filter_trackpoint(device->trackpoint_multiplier, + device->use_velocity_averaging); + else if (device->dpi < DEFAULT_MOUSE_DPI) + filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi, + device->use_velocity_averaging); + else + 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; +} + +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; +} + +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->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.y); + } else { + angles.x = angles.y; + } + + return angles; +} + +static inline struct wheel_tilt_flags +evdev_read_wheel_tilt_props(struct evdev_device *device) +{ + struct wheel_tilt_flags flags; + + flags.vertical = parse_udev_flag(device, + device->udev_device, + "MOUSE_WHEEL_TILT_VERTICAL"); + + flags.horizontal = parse_udev_flag(device, + device->udev_device, + "MOUSE_WHEEL_TILT_HORIZONTAL"); + return flags; +} + +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(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 = (absx->maximum - absx->minimum)/widthmm; + yres = (absy->maximum - absy->minimum)/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(device->abs.absinfo_x->maximum - + device->abs.absinfo_x->minimum); + device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum - + device->abs.absinfo_y->minimum); + + 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(device->abs.absinfo_x->maximum - + device->abs.absinfo_x->minimum); + device->abs.dimensions.y = abs(device->abs.absinfo_y->maximum - + device->abs.absinfo_y->minimum); + 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 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; + } else if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) { + evdev_disable_accelerometer_axes(device); + } + + /* libwacom *adds* TABLET, TOUCHPAD but leaves JOYSTICK in place, so + make sure we only ignore real joystick devices */ + if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_JOYSTICK)) { + evdev_log_info(device, + "device is a joystick, 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; + + } else 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); + device->dpi = evdev_read_dpi_prop(device); + device->trackpoint_multiplier = evdev_get_trackpoint_multiplier(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; + evdev_log_info(device, "device is a switch device\n"); + } + + 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.\n"); + else + device->tags |= EVDEV_TAG_TABLET_MODE_SWITCH; + + 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 is a clickpad but INPUT_PROP_BUTTONPAD is not set, see + * fdo bug 97147. Remove when RMI4 is commonplace */ + if (evdev_device_has_model_quirk(device, QUIRK_MODEL_HP_STREAM11_TOUCHPAD)) + libevdev_enable_property(device->evdev, + INPUT_PROP_BUTTONPAD); + + /* Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see + * https://gitlab.freedesktop.org/libinput/libinput/issues/177 and + * https://gitlab.freedesktop.org/libinput/libinput/issues/234 */ + if (evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_T480S_TOUCHPAD) || + evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_T490S_TOUCHPAD) || + evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_L380_TOUCHPAD)) + libevdev_enable_property(device->evdev, + INPUT_PROP_BUTTONPAD); + + /* 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 (q && quirks_get_tuples(q, QUIRK_ATTR_EVENT_CODE_DISABLE, &t)) { + int type, code; + + for (size_t i = 0; i < t->ntuples; i++) { + type = t->tuples[i].first; + code = t->tuples[i].second; + + if (code == EVENT_CODE_UNDEFINED) + libevdev_disable_event_type(device->evdev, + type); + else + libevdev_disable_event_code(device->evdev, + type, + code); + evdev_log_debug(device, + "quirks: disabling %s %s (%#x %#x)\n", + libevdev_event_type_get_name(type), + libevdev_event_code_get_name(type, code), + type, + code); + } + } + + 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); + + log_msg_va(libinput, pri, fmt, args); +} + +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; + int unhandled_device = 0; + const char *devnode = udev_device_get_devnode(udev_device); + const char *sysname = udev_device_get_sysname(udev_device); + + if (!devnode) { + log_info(libinput, "%s: no device node associated\n", sysname); + return NULL; + } + + if (udev_device_should_be_ignored(udev_device)) { + log_debug(libinput, "%s: device is ignored\n", sysname); + return NULL; + } + + /* 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)); + return NULL; + } + + if (!evdev_device_have_same_syspath(udev_device, fd)) + goto err; + + device = zalloc(sizeof *device); + + 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); + 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->scroll.is_tilt = evdev_read_wheel_tilt_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 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) { + if (device->seat_caps == 0) + unhandled_device = 1; + 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: + close_restricted(libinput, fd); + if (device) + evdev_device_destroy(device); + + 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 udev_device_get_sysname(device->udev_device); +} + +const char * +evdev_device_get_name(struct evdev_device *device) +{ + return device->devname; +} + +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 = device->abs.absinfo_x->maximum - device->abs.absinfo_x->minimum + 1; + sy = device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum + 1; + + /* 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 || !y || device->abs.is_fake_resolution || + !x->resolution || !y->resolution) + return -1; + + *width = evdev_convert_to_mm(x, x->maximum); + *height = evdev_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)) { + const struct discrete_coords zero_discrete = { 0.0, 0.0 }; + 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); + + evdev_notify_axis(device, + time, + axes, + source, + &event, + &zero_discrete); + } +} + +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 }; + const struct discrete_coords zero_discrete = { 0.0, 0.0 }; + + /* terminate scrolling with a zero scroll event */ + if (device->scroll.direction != 0) + pointer_notify_axis(&device->base, + time, + device->scroll.direction, + source, + &zero, + &zero_discrete); + + 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->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); +} + +bool +evdev_tablet_has_left_handed(struct evdev_device *device) +{ + bool has_left_handed = false; +#if HAVE_LIBWACOM + struct libinput *li = evdev_libinput_context(device); + WacomDeviceDatabase *db = NULL; + WacomDevice *d = NULL; + WacomError *error; + const char *devnode; + + db = libinput_libwacom_ref(li); + if (!db) + goto out; + + error = libwacom_error_new(); + devnode = udev_device_get_devnode(device->udev_device); + + d = libwacom_new_from_path(db, + devnode, + WFALLBACK_NONE, + error); + + if (d) { + if (libwacom_is_reversible(d)) + has_left_handed = true; + } else if (libwacom_error_get_code(error) == WERROR_UNKNOWN_MODEL) { + evdev_log_info(device, + "tablet '%s' unknown to libwacom\n", + device->devname); + } else { + evdev_log_error(device, + "libwacom error: %s\n", + libwacom_error_get_message(error)); + } + + if (error) + libwacom_error_free(&error); + if (d) + libwacom_destroy(d); + if (db) + libinput_libwacom_unref(li); + +out: +#endif + return has_left_handed; +} diff --git a/src/evdev.h b/src/evdev.h new file mode 100644 index 0000000..7de1fea --- /dev/null +++ b/src/evdev.h @@ -0,0 +1,1002 @@ +/* + * 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" + +/* 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_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_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; + 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 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; + + struct wheel_tilt_flags is_tilt; + } 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_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_get_num_buttons(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 *)); + +int +evdev_update_key_down_count(struct evdev_device *device, + int code, + int pressed); + +void +evdev_notify_axis(struct evdev_device *device, + uint64_t time, + uint32_t axes, + enum libinput_pointer_axis_source source, + const struct normalized_coords *delta_in, + const struct discrete_coords *discrete_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 double +evdev_convert_to_mm(const struct input_absinfo *absinfo, double v) +{ + double value = v - absinfo->minimum; + return value/absinfo->resolution; +} + +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 = evdev_convert_to_mm(device->abs.absinfo_x, x); + mm.y = evdev_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 *)); + +bool +evdev_tablet_has_left_handed(struct evdev_device *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->devname : "", + (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "", + format); + + va_start(args, format); + log_msg_va(evdev_libinput_context(device), priority, buf, args); + 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->devname : "", + (priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "", + format); + + va_start(args, format); + log_msg_va(evdev_libinput_context(device), priority, buf, args); + va_end(args); + + if (state == RATELIMIT_THRESHOLD) + evdev_log_msg(device, + priority, + "WARNING: log rate limit exceeded (%d msgs per %dms). Discarding future messages.\n", + ratelimit->burst, + us2ms(ratelimit->interval)); +} + +#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 %sabsolute_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 */ diff --git a/src/filter-flat.c b/src/filter-flat.c new file mode 100644 index 0000000..1aa0bef --- /dev/null +++ b/src/filter-flat.c @@ -0,0 +1,124 @@ +/* + * 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 + +#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) +{ + struct pointer_accelerator_flat *accel = + (struct pointer_accelerator_flat *) filter; + + return normalize_for_dpi(unaccelerated, accel->dpi); +} + +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); +} + +struct motion_filter_interface accelerator_interface_flat = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, + .filter = accelerator_filter_flat, + .filter_constant = 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; +} diff --git a/src/filter-low-dpi.c b/src/filter-low-dpi.c new file mode 100644 index 0000000..9a39f52 --- /dev/null +++ b/src/filter-low-dpi.c @@ -0,0 +1,269 @@ +/* + * 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 + +#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 device_float_coords +accelerator_filter_generic(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; + double accel_value; /* unitless factor */ + struct device_float_coords accelerated; + + accel_value = calculate_acceleration_factor(accel, + unaccelerated, + data, + time); + + accelerated.x = accel_value * unaccelerated->x; + accelerated.y = accel_value * unaccelerated->y; + + return accelerated; +} + +static struct normalized_coords +accelerator_filter_unnormalized(struct motion_filter *filter, + const struct device_float_coords *unaccelerated, + void *data, uint64_t time) +{ + struct device_float_coords accelerated; + struct normalized_coords normalized; + + /* Accelerate for device units and return device units */ + accelerated = accelerator_filter_generic(filter, + unaccelerated, + data, + time); + normalized.x = accelerated.x; + normalized.y = accelerated.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) +{ + struct pointer_accelerator_low_dpi *accel = + (struct pointer_accelerator_low_dpi *) filter; + + return normalize_for_dpi(unaccelerated, accel->dpi); +} + +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; +} + +struct motion_filter_interface accelerator_interface_low_dpi = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, + .filter = accelerator_filter_unnormalized, + .filter_constant = 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; +} diff --git a/src/filter-mouse.c b/src/filter-mouse.c new file mode 100644 index 0000000..89c3919 --- /dev/null +++ b/src/filter-mouse.c @@ -0,0 +1,343 @@ +/* + * 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 + +#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 { + 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; +}; + +/** + * 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 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; +} + +/** + * Generic filter that calculates the acceleration factor and applies it to + * the 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 accelerated + * motion, still in device units. + */ +static struct device_float_coords +accelerator_filter_generic(struct motion_filter *filter, + const struct device_float_coords *unaccelerated, + void *data, uint64_t time) +{ + struct pointer_accelerator *accel = + (struct pointer_accelerator *) filter; + double accel_value; /* unitless factor */ + struct device_float_coords accelerated; + + accel_value = calculate_acceleration_factor(accel, + unaccelerated, + data, + time); + + accelerated.x = accel_value * unaccelerated->x; + accelerated.y = accel_value * unaccelerated->y; + + return accelerated; +} + +static struct normalized_coords +accelerator_filter_pre_normalized(struct motion_filter *filter, + const struct device_float_coords *unaccelerated, + void *data, uint64_t time) +{ + struct pointer_accelerator *accel = + (struct pointer_accelerator *) filter; + struct normalized_coords normalized; + struct device_float_coords converted, accelerated; + + /* Accelerate for normalized units and return normalized units. + API requires device_floats, so we just copy the bits around */ + normalized = normalize_for_dpi(unaccelerated, accel->dpi); + converted.x = normalized.x; + converted.y = normalized.y; + + accelerated = accelerator_filter_generic(filter, + &converted, + data, + time); + normalized.x = accelerated.x; + normalized.y = accelerated.y; + return normalized; +} + +/** + * 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 device units (units/µs) */ + 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; /* units/us */ + const double incline = accel_filter->incline; + double factor; /* unitless */ + + /* Normalize to 1000dpi, because the rest below relies on that */ + speed_in = speed_in * DEFAULT_MOUSE_DPI/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 + + 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; +} + +struct motion_filter_interface accelerator_interface = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, + .filter = accelerator_filter_pre_normalized, + .filter_constant = 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; +} diff --git a/src/filter-private.h b/src/filter-private.h new file mode 100644 index 0000000..b24a5c9 --- /dev/null +++ b/src/filter-private.h @@ -0,0 +1,130 @@ +/* + * 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); + 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); +}; + +struct motion_filter { + double speed_adjustment; /* normalized [-1, 1] */ + 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; +}; + +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 diff --git a/src/filter-tablet.c b/src/filter-tablet.c new file mode 100644 index 0000000..24afb56 --- /dev/null +++ b/src/filter-tablet.c @@ -0,0 +1,182 @@ +/* + * 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); +} + +struct motion_filter_interface accelerator_interface_tablet = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, + .filter = tablet_accelerator_filter_flat, + .filter_constant = 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; +} diff --git a/src/filter-touchpad-x230.c b/src/filter-touchpad-x230.c new file mode 100644 index 0000000..d4cc3e1 --- /dev/null +++ b/src/filter-touchpad-x230.c @@ -0,0 +1,320 @@ +/* + * 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 + +#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 avarage 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; +} + +struct motion_filter_interface accelerator_interface_x230 = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, + .filter = accelerator_filter_x230, + .filter_constant = 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; +} diff --git a/src/filter-touchpad.c b/src/filter-touchpad.c new file mode 100644 index 0000000..9f833a0 --- /dev/null +++ b/src/filter-touchpad.c @@ -0,0 +1,353 @@ +/* + * 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 + +#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; /* units/us */ + 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; +} + +/** + * Generic filter that calculates the acceleration factor and applies it to + * the 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 accelerated + * motion, still in device units. + */ +static struct device_float_coords +accelerator_filter_generic(struct motion_filter *filter, + const struct device_float_coords *unaccelerated, + void *data, uint64_t time) +{ + struct touchpad_accelerator *accel = + (struct touchpad_accelerator *) filter; + double accel_value; /* unitless factor */ + struct device_float_coords accelerated; + + accel_value = calculate_acceleration_factor(accel, + unaccelerated, + data, + time); + + accelerated.x = accel_value * unaccelerated->x; + accelerated.y = accel_value * unaccelerated->y; + + return accelerated; +} + +static struct normalized_coords +accelerator_filter_post_normalized(struct motion_filter *filter, + const struct device_float_coords *unaccelerated, + void *data, uint64_t time) +{ + struct touchpad_accelerator *accel = + (struct touchpad_accelerator *) filter; + struct device_float_coords accelerated; + + /* Accelerate for device units, normalize afterwards */ + accelerated = accelerator_filter_generic(filter, + unaccelerated, + data, + time); + 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 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 +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; /* units/us */ + 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; +} + +struct motion_filter_interface accelerator_interface_touchpad = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, + .filter = accelerator_filter_post_normalized, + .filter_constant = 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; + struct pointer_delta_smoothener *smoothener; + + 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; + + smoothener = zalloc(sizeof(*smoothener)); + smoothener->threshold = event_delta_smooth_threshold, + smoothener->value = event_delta_smooth_value, + filter->trackers.smoothener = smoothener; + + return &filter->base; +} diff --git a/src/filter-trackpoint.c b/src/filter-trackpoint.c new file mode 100644 index 0000000..c85a082 --- /dev/null +++ b/src/filter-trackpoint.c @@ -0,0 +1,220 @@ +/* + * 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 + +#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); +} + +struct motion_filter_interface accelerator_interface_trackpoint = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, + .filter = trackpoint_accelerator_filter, + .filter_constant = 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; + struct pointer_delta_smoothener *smoothener; + + 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; + + smoothener = zalloc(sizeof(*smoothener)); + smoothener->threshold = ms2us(10); + smoothener->value = ms2us(10); + filter->trackers.smoothener = smoothener; + + return &filter->base; +} diff --git a/src/filter.c b/src/filter.c new file mode 100644 index 0000000..ef081dd --- /dev/null +++ b/src/filter.c @@ -0,0 +1,300 @@ +/* + * 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 + +#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); +} + +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; +} + +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); + free(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(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(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 */ + struct pointer_tracker *tracker; + double velocity; + double result = 0.0; + double initial_velocity = 0.0; + double velocity_diff; + unsigned int offset; + + unsigned int dir = trackers_by_offset(trackers, 0)->dir; + + /* Find least recent vector within a timelimit, maximum velocity diff + * and direction threshold. */ + for (offset = 1; offset < trackers->ntrackers; offset++) { + 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; + } + + 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 */ + 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 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 + */ +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 avarage 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 */ +} diff --git a/src/filter.h b/src/filter.h new file mode 100644 index 0000000..177acbd --- /dev/null +++ b/src/filter.h @@ -0,0 +1,160 @@ +/* + * 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 coordiantes 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); + +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); + +/* 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_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_tablet(int xres, int yres); + +/* + * 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 delta, + uint64_t time); +#endif /* FILTER_H */ diff --git a/src/libinput-git-version.h.in b/src/libinput-git-version.h.in new file mode 100644 index 0000000..c2d68af --- /dev/null +++ b/src/libinput-git-version.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define LIBINPUT_GIT_VERSION "@VCS_TAG@" diff --git a/src/libinput-private.h b/src/libinput-private.h new file mode 100644 index 0000000..1950e66 --- /dev/null +++ b/src/libinput-private.h @@ -0,0 +1,872 @@ +/* + * 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-util.h" +#include "libinput-version.h" + +#if LIBINPUT_VERSION_MICRO >= 90 +#define HTTP_DOC_LINK "https://wayland.freedesktop.org/libinput/doc/latest/" +#else +#define HTTP_DOC_LINK "https://wayland.freedesktop.org/libinput/doc/" LIBINPUT_VERSION "/" +#endif + +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 pair of angles in degrees */ +struct wheel_angle { + double 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; +}; + +/* A pair of tilt flags */ +struct wheel_tilt_flags { + bool vertical, horizontal; +}; + +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; + } 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; + + 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_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_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); +}; + +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); +}; + +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); +}; + +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); +}; + +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_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 { + struct libinput_device_config_tap *tap; + struct libinput_device_config_calibration *calibration; + 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_rotation *rotation; +}; + +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; +}; + +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; + + /* The pressure threshold assumes a pressure_offset of 0 */ + struct threshold pressure_threshold; + /* pressure_offset includes axis->minimum */ + int pressure_offset; + bool has_pressure_offset; +}; + +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 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(struct libinput_device *device, + uint64_t time, + uint32_t axes, + enum libinput_pointer_axis_source source, + const struct normalized_coords *delta, + const struct discrete_coords *discrete); + +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, + int 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, + int 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); + +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); + +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); + +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); + +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_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 +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) +{ + struct timespec ts = { 0, 0 }; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { + log_error(libinput, "clock_gettime failed: %s\n", strerror(errno)); + return 0; + } + + return s2us(ts.tv_sec) + ns2us(ts.tv_nsec); +} + +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 = (1 << d1) | (1 << 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 */ diff --git a/src/libinput-restore-selinux-context.sh b/src/libinput-restore-selinux-context.sh new file mode 100644 index 0000000..606b5b0 --- /dev/null +++ b/src/libinput-restore-selinux-context.sh @@ -0,0 +1,12 @@ +#!/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 diff --git a/src/libinput-uninstalled.pc.in b/src/libinput-uninstalled.pc.in new file mode 100644 index 0000000..fa76ca5 --- /dev/null +++ b/src/libinput-uninstalled.pc.in @@ -0,0 +1,10 @@ +libdir=@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 diff --git a/src/libinput-util.c b/src/libinput-util.c new file mode 100644 index 0000000..dcc4a16 --- /dev/null +++ b/src/libinput-util.c @@ -0,0 +1,649 @@ +/* + * 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. + */ + +/* + * This list data structure is verbatim copy from wayland-util.h from the + * Wayland project; except that wl_ prefix has been removed. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "libinput-util.h" +#include "libinput-private.h" + +void +list_init(struct list *list) +{ + list->prev = list; + list->next = 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; +} + +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; + } else if (r->num < r->burst) { + /* continue burst */ + return (++r->num == r->burst) ? RATELIMIT_THRESHOLD + : RATELIMIT_PASS; + } + + return RATELIMIT_EXCEEDED; +} + +/* 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]) +{ + int idx; + char **strv; + float calibration[6]; + + if (!prop) + return false; + + strv = strv_from_string(prop, " "); + if (!strv) + return false; + + for (idx = 0; idx < 6; idx++) { + double v; + if (strv[idx] == NULL || !safe_atod(strv[idx], &v)) { + strv_free(strv); + return false; + } + + calibration[idx] = v; + } + + strv_free(strv); + + memcpy(calibration_out, calibration, sizeof(calibration)); + + return true; +} + +bool +parse_switch_reliability_property(const char *prop, + enum switch_reliability *reliability) +{ + if (!prop) { + *reliability = RELIABILITY_UNKNOWN; + return true; + } + + if (streq(prop, "reliable")) + *reliability = RELIABILITY_RELIABLE; + 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 vaule "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; +} + +static bool +parse_evcode_string(const char *s, int *type_out, int *code_out) +{ + int type, code; + + if (strneq(s, "EV_", 3)) { + 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 }, + }; + struct map *m; + bool found = false; + + ARRAY_FOR_EACH(map, m) { + if (!strneq(s, m->str, strlen(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 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. + */ +bool +parse_evcode_property(const char *prop, struct input_event *events, size_t *nevents) +{ + char **strv = NULL; + bool rc = false; + size_t ncodes = 0; + size_t idx; + /* A randomly chosen max so we avoid crazy quirks */ + struct input_event evs[32]; + + memset(evs, 0, sizeof evs); + + strv = strv_from_string(prop, ";"); + if (!strv) + goto out; + + for (idx = 0; strv[idx]; idx++) + ncodes++; + + if (ncodes == 0 || ncodes > ARRAY_LENGTH(evs)) + goto out; + + ncodes = min(*nevents, ncodes); + for (idx = 0; strv[idx]; idx++) { + char *s = strv[idx]; + + 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; + } + + memcpy(events, evs, ncodes * sizeof *events); + *nevents = ncodes; + rc = true; + +out: + strv_free(strv); + return rc; +} + +/** + * 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) +{ + 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 tokens in the input + * string, e.g. "one two\tthree" with a separator list of " \t" will return + * an array [ "one", "two", "three", NULL ]. + * + * Use strv_free() to free the array. + * + * @param in Input string + * @param separators List of separator characters + * + * @return A null-terminated string array or NULL on errors + */ +char ** +strv_from_string(const char *in, const char *separators) +{ + const char *s, *word; + char **strv = NULL; + int nelems = 0, idx; + size_t l; + + assert(in != NULL); + + s = in; + while ((word = next_word(&s, &l, separators)) != NULL) + nelems++; + + if (nelems == 0) + return NULL; + + nelems++; /* NULL-terminated */ + strv = zalloc(nelems * sizeof *strv); + + idx = 0; + + s = in; + while ((word = next_word(&s, &l, separators)) != NULL) { + char *copy = strndup(word, l); + if (!copy) { + strv_free(strv); + return NULL; + } + + strv[idx++] = copy; + } + + 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 arrray + * @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) +{ + 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; +} diff --git a/src/libinput-util.h b/src/libinput-util.h new file mode 100644 index 0000000..680e724 --- /dev/null +++ b/src/libinput-util.h @@ -0,0 +1,704 @@ +/* + * 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 +#include +#include +#include +#ifdef HAVE_LOCALE_H +#include +#endif +#ifdef HAVE_XLOCALE_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libinput.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 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 CASE_RETURN_STRING(a) case a: return #a + +#define bit(x_) (1UL << (x_)) +/* + * This list data structure is a verbatim copy from wayland-util.h from the + * Wayland project; except that wl_ prefix has been removed. + */ + +struct list { + struct list *prev; + struct list *next; +}; + +void list_init(struct list *list); +void list_insert(struct list *list, struct list *elm); +void list_append(struct list *list, struct list *elm); +void list_remove(struct list *elm); +bool list_empty(const struct list *list); + +#define container_of(ptr, type, member) \ + (__typeof__(type) *)((char *)(ptr) - \ + offsetof(__typeof__(type), member)) + +#define list_first_entry(head, pos, member) \ + container_of((head)->next, __typeof__(*pos), member) + +#define list_for_each(pos, head, member) \ + for (pos = 0, pos = list_first_entry(head, pos, member); \ + &pos->member != (head); \ + pos = list_first_entry(&pos->member, pos, member)) + +#define list_for_each_safe(pos, tmp, head, member) \ + for (pos = 0, tmp = 0, \ + pos = list_first_entry(head, pos, member), \ + tmp = list_first_entry(&pos->member, tmp, member); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = list_first_entry(&pos->member, tmp, member)) + +#define NBITS(b) (b * 8) +#define LONG_BITS (sizeof(long) * 8) +#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) +#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) +#define ARRAY_FOR_EACH(_arr, _elem) \ + for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) + +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#define streq(s1, s2) (strcmp((s1), (s2)) == 0) +#define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0) + +#define NCHARS(x) ((size_t)(((x) + 7) / 8)) + +#ifdef DEBUG_TRACE +#define debug_trace(...) \ + do { \ + printf("%s:%d %s() - ", __FILE__, __LINE__, __func__); \ + printf(__VA_ARGS__); \ + } while (0) +#else +#define debug_trace(...) { } +#endif + +#define LIBINPUT_EXPORT __attribute__ ((visibility("default"))) + +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; +} + +/* 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 void +msleep(unsigned int ms) +{ + usleep(ms * 1000); +} + +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; +} + +static inline double +deg2rad(int degree) +{ + return M_PI * degree / 180.0; +} + +struct matrix { + float val[3][3]; /* [row][col] */ +}; + +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) +{ + int 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]; +} + +/** + * 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. + */ +LIBINPUT_ATTRIBUTE_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; +} + +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_ms, unsigned int burst); +enum ratelimit_state ratelimit_test(struct ratelimit *r); + +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); +#define EVENT_CODE_UNDEFINED 0xffff +bool parse_evcode_property(const char *prop, struct input_event *events, size_t *nevents); + +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_UNKNOWN, + RELIABILITY_RELIABLE, + RELIABILITY_WRITE_OPEN, +}; + +bool +parse_switch_reliability_property(const char *prop, + enum switch_reliability *reliability); + +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 uint64_t +s2us(uint64_t s) +{ + return ms2us(s * 1000); +} + +static inline uint32_t +us2ms(uint64_t us) +{ + return (uint32_t)(us / 1000); +} + +static inline uint64_t +tv2us(const struct timeval *tv) +{ + return s2us(tv->tv_sec) + tv->tv_usec; +} + +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 bool +safe_atoi_base(const char *str, int *val, int base) +{ + 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) +{ + return safe_atoi_base(str, val, 10); +} + +static inline bool +safe_atou_base(const char *str, unsigned int *val, int base) +{ + 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) +{ + return safe_atou_base(str, val, 10); +} + +static inline bool +safe_atod(const char *str, double *val) +{ + 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_string(const char *string, const char *separator); +char *strv_join(char **strv, const char *separator); + +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); +} + +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) + +{ + char **pairs; + char **pair; + struct key_value_double *result = NULL; + ssize_t npairs = 0; + unsigned int idx = 0; + + if (!pair_separator || pair_separator[0] == '\0' || + !kv_separator || kv_separator[0] == '\0') + return -1; + + pairs = strv_from_string(string, pair_separator); + if (!pairs) + return -1; + + for (pair = pairs; *pair; pair++) + npairs++; + + if (npairs == 0) + goto error; + + result = zalloc(npairs * sizeof *result); + + for (pair = pairs; *pair; pair++) { + char **kv = strv_from_string(*pair, kv_separator); + double k, v; + + if (!kv || !kv[0] || !kv[1] || kv[2] || + !safe_atod(kv[0], &k) || + !safe_atod(kv[1], &v)) { + strv_free(kv); + goto error; + } + + result[idx].key = k; + result[idx].value = v; + idx++; + + strv_free(kv); + } + + strv_free(pairs); + + *result_out = result; + + return npairs; + +error: + strv_free(pairs); + free(result); + return -1; +} +#endif /* LIBINPUT_UTIL_H */ diff --git a/src/libinput-version.h.in b/src/libinput-version.h.in new file mode 100644 index 0000000..0bcd7e5 --- /dev/null +++ b/src/libinput-version.h.in @@ -0,0 +1,32 @@ +/* + * 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 diff --git a/src/libinput-versionsort.h b/src/libinput-versionsort.h new file mode 100644 index 0000000..62fc31a --- /dev/null +++ b/src/libinput-versionsort.h @@ -0,0 +1,79 @@ +#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 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 diff --git a/src/libinput.c b/src/libinput.c new file mode 100644 index 0000000..6d00a00 --- /dev/null +++ b/src/libinput.c @@ -0,0 +1,4270 @@ +/* + * 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 "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_middle_emulation_state); +ASSERT_INT_SIZE(enum libinput_config_scroll_method); +ASSERT_INT_SIZE(enum libinput_config_dwt_state); + +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) + log_bug_client(libinput, + "Invalid event type %d passed to %s()\n", + type_in, function_name); + + return rc; +} + +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_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_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_SWITCH_TOGGLE); + case LIBINPUT_EVENT_NONE: + abort(); + } + + return NULL; +} + +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; + 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 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 { + 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_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); + + 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_STRIP, + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + + 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_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_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 evdev_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 evdev_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_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 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 evdev_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 evdev_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); + + 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); + + 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); + + 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); + + 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) +{ + struct evdev_device *device = evdev_device(event->base.device); + + 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 evdev_convert_to_mm(device->abs.absinfo_x, + event->axes.point.x); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *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_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return evdev_convert_to_mm(device->abs.absinfo_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) +{ + struct evdev_device *device = evdev_device(event->base.device); + + 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 evdev_device_transform_x(device, + event->axes.point.x, + width); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *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_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return evdev_device_transform_y(device, + 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 %sdevice-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, *next; + + list_for_each_safe(source, next, &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, *next_device; + struct libinput_seat *seat, *next_seat; + struct libinput_tablet_tool *tool, *next_tool; + struct libinput_device_group *group, *next_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, next_seat, &libinput->seat_list, link) { + list_for_each_safe(device, next_device, + &seat->devices_list, + link) + libinput_device_destroy(device); + + libinput_seat_destroy(seat); + } + + list_for_each_safe(group, + next_group, + &libinput->device_group_list, + link) { + libinput_device_group_destroy(group); + } + + list_for_each_safe(tool, next_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) +{ + 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_STRIP: + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + 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; + } else { + 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; + } else { + return device; + } +} + +LIBINPUT_EXPORT int +libinput_get_fd(struct libinput *libinput) +{ + return libinput->epoll_fd; +} + +LIBINPUT_EXPORT int +libinput_dispatch(struct libinput *libinput) +{ + struct libinput_source *source; + struct epoll_event ep[32]; + int i, count; + + 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, *tmp; +#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, tmp, &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(struct libinput_device *device, + uint64_t time, + uint32_t axes, + enum libinput_pointer_axis_source source, + const struct normalized_coords *delta, + const struct discrete_coords *discrete) +{ + 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 = source, + .axes = axes, + .discrete = *discrete, + }; + + post_device_event(device, time, + LIBINPUT_EVENT_POINTER_AXIS, + &axis_event->base); +} + +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) +{ + 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, + }; + + 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) +{ + 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, + }; + 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) +{ + 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, + }; + 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) +{ + 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, + }; + + 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_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); +} + +static void +gesture_notify(struct libinput_device *device, + uint64_t time, + enum libinput_event_type type, + int finger_count, + int 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, + int 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, + int 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 +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 +} + +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 0 + log_debug(libinput, "Queuing %s\n", event_type_to_str(event->type)); +#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_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_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_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 & (1 << button)); +} + +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 & (1 << 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 & (1 << 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 & (1 << 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_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); + + 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_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 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_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_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_STRIP, + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + + 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_STRIP, + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + + 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_STRIP, + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + + 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; + } else { + 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 && + 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_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 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); + else /* 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); + else + 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: + 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); +} + +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); + else + 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); + else /* 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); + else + 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); + else + return LIBINPUT_CONFIG_CLICK_METHOD_NONE; +} + +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); + else + 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); + else + 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); + else /* 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); + else + 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); + else + 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 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_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 || degrees_cw % 90) + 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); +} + +#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 diff --git a/src/libinput.h b/src/libinput.h new file mode 100644 index 0000000..bde76f8 --- /dev/null +++ b/src/libinput.h @@ -0,0 +1,5780 @@ +/* + * 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 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 and + * @ref LIBINPUT_EVENT_TABLET_PAD_STRIP. + * + * @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) +}; + +/** + * @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. + */ +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. + */ + 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() 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 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, + LIBINPUT_EVENT_POINTER_AXIS, + + 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_BUTTON + * + * @since 1.2 + */ + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + + /** + * A button pressed on a device with the @ref + * LIBINPUT_DEVICE_CAP_TABLET_PAD capability. + * + * 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, + + 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.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, + * this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_POINTER_AXIS. + * + * @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. + * + * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, no + * terminating event is guaranteed (though it may happen). + * 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_TILT, no + * terminating event is guaranteed (though it may happen). + * Scrolling is in discrete steps and there is no physical equivalent for + * the value returned here. For backwards compatibility, the value returned + * by this function is identical to a single mouse wheel rotation by this + * device (see the documentation for @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL + * above). Callers should not use this value but instead exclusively refer + * to the value returned by libinput_event_pointer_get_axis_value_discrete(). + * + * 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 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. + * + * 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 + */ +double +libinput_event_pointer_get_axis_value_discrete(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. + * + * @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. + * + * @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 counterclockwise + * 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 + * + * 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. + * + * 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. + * + * 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 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.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.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. + * + * @since 1.3 + */ +int +libinput_device_tablet_pad_get_num_buttons(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. + * + * @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. + * + * @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 + * + * 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_scroll_set_method() + * - libinput_device_config_dwt_set_enabled() + * - Touchscreens: + * - libinput_device_config_calibration_set_matrix() + * - 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 + * + * 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 + * single-finger 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_drag_get_enabled + * @see libinput_device_config_tap_drag_get_default_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_drag_set_enabled + * @see libinput_device_config_tap_drag_get_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_drag_set_enabled + * @see libinput_device_config_tap_drag_get_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, or is currently disabled */ + LIBINPUT_CONFIG_DRAG_LOCK_ENABLED, +}; + +/** + * @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 within a timeout and + * the drag process continues. 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 disabled is permitted, + * but has no effect until tapping is enabled. + * + * @param device The device to configure + * @param enable @ref LIBINPUT_CONFIG_DRAG_LOCK_ENABLED to enable drag lock + * 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 is disabled. + * + * @param device The device to configure + * + * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED If drag lock is currently enabled + * @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 is disabled by + * default. + * + * @param device The device to configure + * + * @retval LIBINPUT_CONFIG_DRAG_LOCK_ENABLED If drag lock is enabled 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 + * + * 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 + * + * 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. + * + * @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), +}; + +/** + * @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 mode The mode 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 mode); + +/** + * @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 + */ +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); + +/** + * @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 + * + * 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. + * + * libinput guarantees that this function accepts multiples of 90 degrees. + * If a value is within the [0, 360[ range but not a multiple of 90 degrees, + * this function may return LIBINPUT_CONFIG_STATUS_INVALID if the underlying + * device or implementation does not support finer-grained rotation angles. + * + * 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); + +#ifdef __cplusplus +} +#endif +#endif /* LIBINPUT_H */ diff --git a/src/libinput.pc.in b/src/libinput.pc.in new file mode 100644 index 0000000..03e70e7 --- /dev/null +++ b/src/libinput.pc.in @@ -0,0 +1,14 @@ +prefix=@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 diff --git a/src/libinput.sym b/src/libinput.sym new file mode 100644 index 0000000..ef9d917 --- /dev/null +++ b/src/libinput.sym @@ -0,0 +1,307 @@ +/* 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; diff --git a/src/path-seat.c b/src/path-seat.c new file mode 100644 index 0000000..334aa7c --- /dev/null +++ b/src/path-seat.c @@ -0,0 +1,431 @@ +/* + * 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 +#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 libinput *libinput, + struct evdev_device *device) +{ + struct libinput_seat *seat = device->base.seat; + struct evdev_device *dev, *next; + + list_for_each_safe(dev, next, + &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, *tmp; + struct evdev_device *device, *next; + + list_for_each_safe(seat, tmp, &input->base.seat_list, base.link) { + libinput_seat_ref(&seat->base); + list_for_each_safe(device, next, + &seat->base.devices_list, base.link) + path_disable_device(libinput, 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 = 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, *tmp; + + udev_unref(path_input->udev); + + list_for_each_safe(dev, tmp, &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(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(libinput, evdev); + libinput_seat_unref(seat); +} diff --git a/src/quirks.c b/src/quirks.c new file mode 100644 index 0000000..7c0b75a --- /dev/null +++ b/src/quirks.c @@ -0,0 +1,1594 @@ +/* + * 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 + +#include "libinput-versionsort.h" +#include "libinput-util.h" +#include "libinput-private.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, +}; + +/** + * 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; + } 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_LAST = M_VERSION, +}; + +enum bustype { + BT_UNKNOWN, + BT_USB, + BT_BLUETOOTH, + BT_PS2, + BT_RMI, + BT_I2C, +}; + +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; + enum bustype bus; + uint32_t vendor; + uint32_t product; + 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; +}; + +/** + * 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_TOUCHPAD: return "ModelALPSTouchpad"; + 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_HP_PAVILION_DM4_TOUCHPAD: return "ModelHPPavilionDM4Touchpad"; + case QUIRK_MODEL_HP_STREAM11_TOUCHPAD: return "ModelHPStream11Touchpad"; + case QUIRK_MODEL_HP_ZBOOK_STUDIO_G3: return "ModelHPZBookStudioG3"; + case QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING: return "ModelInvertHorizontalScrolling"; + case QUIRK_MODEL_LENOVO_L380_TOUCHPAD: return "ModelLenovoL380Touchpad"; + case QUIRK_MODEL_LENOVO_SCROLLPOINT: return "ModelLenovoScrollPoint"; + case QUIRK_MODEL_LENOVO_T450_TOUCHPAD: return "ModelLenovoT450Touchpad"; + case QUIRK_MODEL_LENOVO_T480S_TOUCHPAD: return "ModelLenovoT480sTouchpad"; + case QUIRK_MODEL_LENOVO_T490S_TOUCHPAD: return "ModelLenovoT490sTouchpad"; + 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_TRACKBALL: return "ModelTrackball"; + case QUIRK_MODEL_WACOM_TOUCHPAD: return "ModelWacomTouchpad"; + case QUIRK_MODEL_WACOM_ISDV4_PEN: return "ModelWacomISDV4Pen"; + case QUIRK_MODEL_DELL_CANVAS_TOTEM: return "ModelDellCanvasTotem"; + + 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_THUMB_SIZE_THRESHOLD: return "AttrThumbSizeThreshold"; + case QUIRK_ATTR_MSC_TIMESTAMP: return "AttrMscTimestamp"; + case QUIRK_ATTR_EVENT_CODE_DISABLE: return "AttrEventCodeDisable"; + 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; + 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 dmi modalias from the udev device. + */ +static inline char * +init_dmi(void) +{ + struct udev *udev; + struct udev_device *udev_device; + const char *modalias = NULL; + char *copy = NULL; + const char *syspath = "/sys/devices/virtual/dmi/id"; + + if (getenv("LIBINPUT_RUNNING_TEST_SUITE")) + return safe_strdup("dmi:"); + + 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; +} + +/** + * 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, *tmp; + + free(s->name); + free(s->match.name); + free(s->match.dmi); + free(s->match.dt); + + list_for_each_safe(p, tmp, &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 strneq(value, "0x", 2) && + safe_atou_base(value, parsed, 16) && + strspn(value, "0123456789xABCDEF") == strlen(value) && + *parsed <= 0xFFFF; +} + +/** + * 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, "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 + 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; + + check_set_bit(s, M_PID); + if (!parse_hex(value, &product)) + goto out; + + s->match.product = 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 (!strneq(value, "dmi:", 4)) { + 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_TOUCHPAD; + + assert(strneq(key, "Model", 5)); + + if (streq(value, "1")) + b = true; + else if (streq(value, "0")) + b = false; + else + 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")) + 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 (streq(value, "1")) + b = true; + else if (streq(value, "0")) + b = false; + else + 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_DISABLE))) { + struct input_event events[32]; + size_t nevents = ARRAY_LENGTH(events); + p->id = QUIRK_ATTR_EVENT_CODE_DISABLE; + 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.ntuples = nevents; + 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) +{ + char **strv; + const char *key, *value; + bool rc = false; + + strv = strv_from_string(line, "="); + if (strv[0] == NULL || strv[1] == NULL || strv[2] != NULL) { + goto out; + } + + + key = strv[0]; + 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 (strneq(key, "Match", 5)) + rc = parse_match(ctx, s, key, value); + else if (strneq(key, "Model", 5)) + rc = parse_model(ctx, s, key, value); + else if (strneq(key, "Attr", 4)) + 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 (!strneq(line, "Match", 5)) { + 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 (!strneq(line, "Match", 5)) + state = STATE_VALUE_OR_SECTION; + break; + case STATE_VALUE_OR_SECTION: + if (strneq(line, "Match", 5)) { + 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) { + const char *suffix = ".quirks"; + const int slen = strlen(suffix); + int offset; + + offset = strlen(dir->d_name) - slen; + if (offset <= 0) + return 0; + + return strneq(&dir->d_name[offset], suffix, slen); +} + +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, *tmp; + + 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, tmp, &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); + + 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]); + } + + 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_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 = product; + 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; + 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 }, + }; + struct ut_map *map; + + 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_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); +} + +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); + + 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_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: + if (m->product == s->match.product) + matched_flags |= flag; + 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; +} diff --git a/src/quirks.h b/src/quirks.h new file mode 100644 index 0000000..88159b5 --- /dev/null +++ b/src/quirks.h @@ -0,0 +1,314 @@ +/* + * 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; + } tuples[32]; + size_t ntuples; +}; + +/** + * Quirks known to libinput + */ +enum quirk { + QUIRK_MODEL_ALPS_TOUCHPAD = 100, + QUIRK_MODEL_APPLE_TOUCHPAD, + QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON, + QUIRK_MODEL_BOUNCING_KEYS, + QUIRK_MODEL_CHROMEBOOK, + QUIRK_MODEL_CLEVO_W740SU, + QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD, + QUIRK_MODEL_HP_STREAM11_TOUCHPAD, + QUIRK_MODEL_HP_ZBOOK_STUDIO_G3, + QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING, + QUIRK_MODEL_LENOVO_L380_TOUCHPAD, + QUIRK_MODEL_LENOVO_SCROLLPOINT, + QUIRK_MODEL_LENOVO_T450_TOUCHPAD, + QUIRK_MODEL_LENOVO_T480S_TOUCHPAD, + QUIRK_MODEL_LENOVO_T490S_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_WACOM_ISDV4_PEN, + QUIRK_MODEL_DELL_CANVAS_TOTEM, + + _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_THUMB_SIZE_THRESHOLD, + QUIRK_ATTR_MSC_TIMESTAMP, + QUIRK_ATTR_EVENT_CODE_DISABLE, + + _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 which); + +/** + * 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); diff --git a/src/timer.c b/src/timer.c new file mode 100644 index 0000000..3deaf5e --- /dev/null +++ b/src/timer.c @@ -0,0 +1,246 @@ +/* + * 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 + +#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; +} + +void +libinput_timer_destroy(struct libinput_timer *timer) +{ + if (timer->link.prev != NULL && timer->link.prev != 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 + uint64_t now = libinput_now(timer->libinput); + if (expire < now) { + if ((flags & TIMER_FLAG_ALLOW_NEGATIVE) == 0) + log_bug_client(timer->libinput, + "timer %s: offset negative (-%dms)\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(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); +} diff --git a/src/timer.h b/src/timer.h new file mode 100644 index 0000000..828f506 --- /dev/null +++ b/src/timer.h @@ -0,0 +1,77 @@ +/* + * 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 = (1 << 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 diff --git a/src/udev-seat.c b/src/udev-seat.c new file mode 100644 index 0000000..b548dfe --- /dev/null +++ b/src/udev-seat.c @@ -0,0 +1,415 @@ +/* + * 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 +#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 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); + + 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; + } else 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, *next; + 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, next, + &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 (strncmp("event", sysname, 5) != 0) { + 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 (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0) + 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, *next; + struct udev_seat *seat, *tmp; + + list_for_each_safe(seat, tmp, &input->base.seat_list, base.link) { + libinput_seat_ref(&seat->base); + list_for_each_safe(device, next, + &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; + } + + udev_monitor_filter_add_match_subsystem_devtype(input->udev_monitor, + "input", NULL); + + 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; +} diff --git a/src/udev-seat.h b/src/udev-seat.h new file mode 100644 index 0000000..ee54b42 --- /dev/null +++ b/src/udev-seat.h @@ -0,0 +1,44 @@ +/* + * 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 diff --git a/test/50-litest.conf b/test/50-litest.conf new file mode 100644 index 0000000..76579d7 --- /dev/null +++ b/test/50-litest.conf @@ -0,0 +1,6 @@ +# Ignore devices created by libinput's test suite (litest) +Section "InputClass" + Identifier "libinput test suite blacklist" + MatchProduct "litest" + Option "Ignore" "on" +EndSection diff --git a/test/build-cxx.cc b/test/build-cxx.cc new file mode 100644 index 0000000..c3ad499 --- /dev/null +++ b/test/build-cxx.cc @@ -0,0 +1,11 @@ +#include + +/* This is a build-test only */ + +using namespace std; + +int +main(int argc, char **argv) +{ + return 0; +} diff --git a/test/build-pedantic.c b/test/build-pedantic.c new file mode 100644 index 0000000..f602127 --- /dev/null +++ b/test/build-pedantic.c @@ -0,0 +1,9 @@ +#include + +/* This is a build-test only */ + +int +main(void) +{ + return 0; +} diff --git a/test/check-double-macros.h b/test/check-double-macros.h new file mode 100644 index 0000000..8346c14 --- /dev/null +++ b/test/check-double-macros.h @@ -0,0 +1,93 @@ +/* + * 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 + +#undef ck_assert_double_eq +#undef ck_assert_double_ne +#undef ck_assert_double_lt +#undef ck_assert_double_le +#undef ck_assert_double_gt +#undef ck_assert_double_ge +#undef ck_assert_double_eq_tol +#undef ck_assert_double_ne_tol + +#define CK_DOUBLE_EQ_EPSILON 1E-3 +#define _ck_assert_double_eq(X,Y, epsilon) \ + do { \ + double _ck_x = X; \ + double _ck_y = Y; \ + ck_assert_msg(fabs(_ck_x - _ck_y) < epsilon, \ + "Assertion '" #X " == " #Y \ + "' failed: "#X"==%f, "#Y"==%f", \ + _ck_x, \ + _ck_y); \ + } while (0) + +#define _ck_assert_double_ne(X,Y, epsilon) \ + do { \ + double _ck_x = X; \ + double _ck_y = Y; \ + ck_assert_msg(fabs(_ck_x - _ck_y) > epsilon, \ + "Assertion '" #X " != " #Y \ + "' failed: "#X"==%f, "#Y"==%f", \ + _ck_x, \ + _ck_y); \ + } while (0) + +#define ck_assert_double_eq(X, Y) _ck_assert_double_eq(X, Y, CK_DOUBLE_EQ_EPSILON) +#define ck_assert_double_eq_tol(X, Y, tol) _ck_assert_double_eq(X, Y, tol) +#define ck_assert_double_ne(X, Y) _ck_assert_double_ne(X, Y, CK_DOUBLE_EQ_EPSILON) +#define ck_assert_double_ne_tol(X, Y, tol) _ck_assert_double_ne(X, Y, tol) + +#define _ck_assert_double_eq_op(X, OP, Y) \ + do { \ + double _ck_x = X; \ + double _ck_y = Y; \ + ck_assert_msg(_ck_x OP _ck_y || \ + fabs(_ck_x - _ck_y) < CK_DOUBLE_EQ_EPSILON, \ + "Assertion '" #X#OP#Y \ + "' failed: "#X"==%f, "#Y"==%f", \ + _ck_x, \ + _ck_y); \ + } while (0) + +#define _ck_assert_double_ne_op(X, OP,Y) \ + do { \ + double _ck_x = X; \ + double _ck_y = Y; \ + ck_assert_msg(_ck_x OP _ck_y && \ + fabs(_ck_x - _ck_y) > CK_DOUBLE_EQ_EPSILON, \ + "Assertion '" #X#OP#Y \ + "' failed: "#X"==%f, "#Y"==%f", \ + _ck_x, \ + _ck_y); \ + } while (0) + +#define ck_assert_double_lt(X, Y) _ck_assert_double_ne_op(X, <, Y) +#define ck_assert_double_le(X, Y) _ck_assert_double_eq_op(X, <=, Y) +#define ck_assert_double_gt(X, Y) _ck_assert_double_ne_op(X, >, Y) +#define ck_assert_double_ge(X, Y) _ck_assert_double_eq_op(X, >=, Y) + diff --git a/test/check-leftover-udev-rules.sh b/test/check-leftover-udev-rules.sh new file mode 100755 index 0000000..8baef0c --- /dev/null +++ b/test/check-leftover-udev-rules.sh @@ -0,0 +1,11 @@ +#!/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 diff --git a/test/generate-gcov-report.sh b/test/generate-gcov-report.sh new file mode 100755 index 0000000..2d91371 --- /dev/null +++ b/test/generate-gcov-report.sh @@ -0,0 +1,42 @@ +#!/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" diff --git a/test/helper-copy-and-exec-from-tmp.sh b/test/helper-copy-and-exec-from-tmp.sh new file mode 100755 index 0000000..2ae8ec6 --- /dev/null +++ b/test/helper-copy-and-exec-from-tmp.sh @@ -0,0 +1,18 @@ +#!/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 diff --git a/test/libinput-test-suite.man b/test/libinput-test-suite.man new file mode 100644 index 0000000..906dfe6 --- /dev/null +++ b/test/libinput-test-suite.man @@ -0,0 +1,95 @@ +.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 ""libinput test suite blacklist"" +.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 diff --git a/test/litest-device-acer-hawaii-keyboard.c b/test/litest-device-acer-hawaii-keyboard.c new file mode 100644 index 0000000..040a26a --- /dev/null +++ b/test/litest-device-acer-hawaii-keyboard.c @@ -0,0 +1,200 @@ +/* + * 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("hawaii-keyboard", + .type = LITEST_ACER_HAWAII_KEYBOARD, + .features = LITEST_KEYS, + .interface = NULL, + + .name = "Chicony ACER Hawaii Keyboard", + .id = &input_id, + .events = events, + .absinfo = NULL, +) diff --git a/test/litest-device-acer-hawaii-touchpad.c b/test/litest-device-acer-hawaii-touchpad.c new file mode 100644 index 0000000..366c381 --- /dev/null +++ b/test/litest-device-acer-hawaii-touchpad.c @@ -0,0 +1,97 @@ +/* + * 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("hawaii-touchpad", + .type = 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 }, + } +) diff --git a/test/litest-device-aiptek-tablet.c b/test/litest-device-aiptek-tablet.c new file mode 100644 index 0000000..e417aa4 --- /dev/null +++ b/test/litest-device-aiptek-tablet.c @@ -0,0 +1,150 @@ +/* + * 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 }, + /* 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 struct input_event proximity_out[] = { + { .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("aiptek-tablet", + .type = LITEST_AIPTEK, + .features = LITEST_TABLET | LITEST_HOVER, + .interface = &interface, + + .name = "Aiptek", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-alps-dualpoint.c b/test/litest-device-alps-dualpoint.c new file mode 100644 index 0000000..57008f6 --- /dev/null +++ b/test/litest-device-alps-dualpoint.c @@ -0,0 +1,122 @@ +/* + * 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("alps-dualpoint", + .type = 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, +) diff --git a/test/litest-device-alps-semi-mt.c b/test/litest-device-alps-semi-mt.c new file mode 100644 index 0000000..59aac96 --- /dev/null +++ b/test/litest-device-alps-semi-mt.c @@ -0,0 +1,115 @@ +/* + * 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("alps-semi-mt", + .type = 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, +) diff --git a/test/litest-device-anker-mouse-kbd.c b/test/litest-device-anker-mouse-kbd.c new file mode 100644 index 0000000..ef51536 --- /dev/null +++ b/test/litest-device-anker-mouse-kbd.c @@ -0,0 +1,215 @@ +/* + * 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 }, + { ABS_MT_SLOT, 0, 255, 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("anker-kbd", + .type = LITEST_ANKER_MOUSE_KBD, + .features = LITEST_KEYS | LITEST_WHEEL, + .interface = NULL, + + .name = "USB Laser Game Mouse", + .id = &input_id, + .absinfo = absinfo, + .events = events, +) diff --git a/test/litest-device-apple-appletouch.c b/test/litest-device-apple-appletouch.c new file mode 100644 index 0000000..26f94fc --- /dev/null +++ b/test/litest-device-apple-appletouch.c @@ -0,0 +1,101 @@ +/* + * 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("appletouch", + .type = 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, +) diff --git a/test/litest-device-apple-internal-keyboard.c b/test/litest-device-apple-internal-keyboard.c new file mode 100644 index 0000000..ca1159e --- /dev/null +++ b/test/litest-device-apple-internal-keyboard.c @@ -0,0 +1,229 @@ +/* + * 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("apple-keyboard", + .type = LITEST_APPLE_KEYBOARD, + .features = LITEST_KEYS, + .interface = NULL, + + .name = "Apple Inc. Apple Internal Keyboard / Trackpad", + .id = &input_id, + .events = events, + .absinfo = NULL, +) diff --git a/test/litest-device-apple-magicmouse.c b/test/litest-device-apple-magicmouse.c new file mode 100644 index 0000000..fa8e3f2 --- /dev/null +++ b/test/litest-device-apple-magicmouse.c @@ -0,0 +1,107 @@ +/* + * 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("magicmouse", + .type = 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 the empty string. As of systemd commit f013e99e160f + * ID_BUS=bluetooth now triggers the hwdb entry for this device. This causes + * test case failures because deltas change. Detecting old vs new systemd is + * hard, and because our rules are 99-prefixed we can't set ID_BUS ourselves + * on older systemd. + * So let's go the easy way and unset MOUSE_DPI so we can continue to use + * the current tests. + */ + .udev_properties = { + { "MOUSE_DPI", "" }, + { NULL }, + }, +) diff --git a/test/litest-device-asus-rog-gladius.c b/test/litest-device-asus-rog-gladius.c new file mode 100644 index 0000000..2617713 --- /dev/null +++ b/test/litest-device-asus-rog-gladius.c @@ -0,0 +1,324 @@ +/* + * 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("mouse-gladius", + .type = LITEST_MOUSE_GLADIUS, + .features = LITEST_RELATIVE | LITEST_WHEEL | LITEST_KEYS, + .interface = NULL, + + .name = "ASUS ROG GLADIUS", + .id = &input_id, + .absinfo = absinfo, + .events = events, +) diff --git a/test/litest-device-atmel-hover.c b/test/litest-device-atmel-hover.c new file mode 100644 index 0000000..f94bd53 --- /dev/null +++ b/test/litest-device-atmel-hover.c @@ -0,0 +1,133 @@ +/* + * 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("atmel-hover", + .type = 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, +) diff --git a/test/litest-device-bcm5974.c b/test/litest-device-bcm5974.c new file mode 100644 index 0000000..0a3002f --- /dev/null +++ b/test/litest-device-bcm5974.c @@ -0,0 +1,128 @@ +/* + * 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("bcm5974", + .type = LITEST_BCM5974, + .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | + LITEST_BUTTON | LITEST_APPLE_CLICKPAD, + .interface = &interface, + + .name = "bcm5974", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-calibrated-touchscreen.c b/test/litest-device-calibrated-touchscreen.c new file mode 100644 index 0000000..1684648 --- /dev/null +++ b/test/litest-device-calibrated-touchscreen.c @@ -0,0 +1,87 @@ +/* + * 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("calibrated-touchscreen", + .type = LITEST_CALIBRATED_TOUCHSCREEN, + .features = LITEST_TOUCH, + .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 } + }, +) diff --git a/test/litest-device-cyborg-rat-5.c b/test/litest-device-cyborg-rat-5.c new file mode 100644 index 0000000..9fd0978 --- /dev/null +++ b/test/litest-device-cyborg-rat-5.c @@ -0,0 +1,61 @@ +/* + * 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("cyborg-rat", + .type = 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, +) diff --git a/test/litest-device-dell-canvas-totem-touch.c b/test/litest-device-dell-canvas-totem-touch.c new file mode 100644 index 0000000..ba5009f --- /dev/null +++ b/test/litest-device-dell-canvas-totem-touch.c @@ -0,0 +1,92 @@ +/* + * 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("dell-canvas-totem-touch", + .type = 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 }, + }, +) diff --git a/test/litest-device-dell-canvas-totem.c b/test/litest-device-dell-canvas-totem.c new file mode 100644 index 0000000..74cb73d --- /dev/null +++ b/test/litest-device-dell-canvas-totem.c @@ -0,0 +1,123 @@ +/* + * 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("dell-canvas-totem", + .type = 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 }, + }, +) diff --git a/test/litest-device-elantech-touchpad.c b/test/litest-device-elantech-touchpad.c new file mode 100644 index 0000000..ab87f10 --- /dev/null +++ b/test/litest-device-elantech-touchpad.c @@ -0,0 +1,110 @@ +/* + * 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("elantech", + .type = LITEST_ELANTECH_TOUCHPAD, + .features = LITEST_TOUCHPAD | LITEST_BUTTON, + .interface = &interface, + + .name = "ETPS/2 Elantech Touchpad", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-generic-singletouch.c b/test/litest-device-generic-singletouch.c new file mode 100644 index 0000000..306fd73 --- /dev/null +++ b/test/litest-device-generic-singletouch.c @@ -0,0 +1,77 @@ +/* + * 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("generic-singletouch", + .type = LITEST_GENERIC_SINGLETOUCH, + .features = LITEST_SINGLE_TOUCH, + .interface = &interface, + + .name = "generic_singletouch", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-gpio-keys.c b/test/litest-device-gpio-keys.c new file mode 100644 index 0000000..92145e9 --- /dev/null +++ b/test/litest-device-gpio-keys.c @@ -0,0 +1,65 @@ +/* + * 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("gpio-keys", + .type = 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 }, + } +) diff --git a/test/litest-device-hp-wmi-hotkeys.c b/test/litest-device-hp-wmi-hotkeys.c new file mode 100644 index 0000000..025fda7 --- /dev/null +++ b/test/litest-device-hp-wmi-hotkeys.c @@ -0,0 +1,64 @@ +/* + * 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("wmi-hotkeys", + .type = 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 }, + } +) diff --git a/test/litest-device-huion-pentablet.c b/test/litest-device-huion-pentablet.c new file mode 100644 index 0000000..fbf1ae8 --- /dev/null +++ b/test/litest-device-huion-pentablet.c @@ -0,0 +1,100 @@ +/* + * 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 = BTN_TOOL_PEN, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static struct input_event proximity_out[] = { + { .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, + .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("huion-tablet", + .type = LITEST_HUION_TABLET, + .features = LITEST_TABLET | LITEST_HOVER, + .interface = &interface, + + .name = "HUION PenTablet Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-ignored-mouse.c b/test/litest-device-ignored-mouse.c new file mode 100644 index 0000000..b384616 --- /dev/null +++ b/test/litest-device-ignored-mouse.c @@ -0,0 +1,58 @@ +/* + * 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("ignored-mouse", + .type = 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 }, + }, +) diff --git a/test/litest-device-keyboard-all-codes.c b/test/litest-device-keyboard-all-codes.c new file mode 100644 index 0000000..3f5d0d4 --- /dev/null +++ b/test/litest-device-keyboard-all-codes.c @@ -0,0 +1,74 @@ +/* + * 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("keyboard-all-codes", + .type = 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 (name && strneq(name, "BTN_", 4)) + 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; +} diff --git a/test/litest-device-keyboard-razer-blackwidow.c b/test/litest-device-keyboard-razer-blackwidow.c new file mode 100644 index 0000000..5dee7f4 --- /dev/null +++ b/test/litest-device-keyboard-razer-blackwidow.c @@ -0,0 +1,341 @@ +/* + * 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 }, + { 0x2f, 0, 255, 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("blackwidow", + .type = LITEST_KEYBOARD_BLACKWIDOW, + .features = LITEST_KEYS | LITEST_WHEEL, + .interface = NULL, + + .name = "Razer Razer BlackWidow 2013", + .id = &input_id, + .absinfo = absinfo, + .events = events, +) diff --git a/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c b/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c new file mode 100644 index 0000000..0f12d85 --- /dev/null +++ b/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c @@ -0,0 +1,218 @@ +/* + * 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("blade-stealth-video-switch", + .type = LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH, + .features = LITEST_KEYS, + .interface = NULL, + + .name = "Razer Razer Blade Stealth", + .id = &input_id, + .events = events, +) diff --git a/test/litest-device-keyboard-razer-blade-stealth.c b/test/litest-device-keyboard-razer-blade-stealth.c new file mode 100644 index 0000000..b08ee43 --- /dev/null +++ b/test/litest-device-keyboard-razer-blade-stealth.c @@ -0,0 +1,339 @@ +/* + * 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 }, + { 0x2f, 0, 255, 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("blade-stealth", + .type = LITEST_KEYBOARD_BLADE_STEALTH, + .features = LITEST_KEYS | LITEST_WHEEL, + .interface = NULL, + + .name = "Razer Razer Blade Stealth", + .id = &input_id, + .absinfo = absinfo, + .events = events, +) diff --git a/test/litest-device-keyboard.c b/test/litest-device-keyboard.c new file mode 100644 index 0000000..6f6c626 --- /dev/null +++ b/test/litest-device-keyboard.c @@ -0,0 +1,203 @@ +/* + * 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("default-keyboard", + .type = LITEST_KEYBOARD, + .features = LITEST_KEYS, + .interface = NULL, + + .name = "AT Translated Set 2 keyboard", + .id = &input_id, + .events = events, + .absinfo = NULL, +) diff --git a/test/litest-device-lid-switch-surface3.c b/test/litest-device-lid-switch-surface3.c new file mode 100644 index 0000000..5e913d9 --- /dev/null +++ b/test/litest-device-lid-switch-surface3.c @@ -0,0 +1,61 @@ +/* + * 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("lid-switch-surface3", + .type = 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 }, + }, +) diff --git a/test/litest-device-lid-switch.c b/test/litest-device-lid-switch.c new file mode 100644 index 0000000..9f3a869 --- /dev/null +++ b/test/litest-device-lid-switch.c @@ -0,0 +1,60 @@ +/* + * 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("lid-switch", + .type = 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 }, + }, +) diff --git a/test/litest-device-logitech-trackball.c b/test/litest-device-logitech-trackball.c new file mode 100644 index 0000000..747b66c --- /dev/null +++ b/test/litest-device-logitech-trackball.c @@ -0,0 +1,55 @@ +/* + * 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("logitech-trackball", + .type = LITEST_LOGITECH_TRACKBALL, + .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_TRACKBALL, + .interface = NULL, + + .name = "Logitech USB Trackball", + .id = &input_id, + .absinfo = NULL, + .events = events, +) diff --git a/test/litest-device-magic-trackpad.c b/test/litest-device-magic-trackpad.c new file mode 100644 index 0000000..8dfde8b --- /dev/null +++ b/test/litest-device-magic-trackpad.c @@ -0,0 +1,123 @@ +/* + * 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("magic-trackpad", + .type = 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 }, + }, +) diff --git a/test/litest-device-mouse-low-dpi.c b/test/litest-device-mouse-low-dpi.c new file mode 100644 index 0000000..9525058 --- /dev/null +++ b/test/litest-device-mouse-low-dpi.c @@ -0,0 +1,58 @@ +/* + * 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, + -1 , -1, +}; + +TEST_DEVICE("low-dpi-mouse", + .type = 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 }, + }, +) diff --git a/test/litest-device-mouse-roccat.c b/test/litest-device-mouse-roccat.c new file mode 100644 index 0000000..c7d41ce --- /dev/null +++ b/test/litest-device-mouse-roccat.c @@ -0,0 +1,196 @@ +/* + * 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("mouse-roccat", + .type = 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, +) diff --git a/test/litest-device-mouse-wheel-click-angle.c b/test/litest-device-mouse-wheel-click-angle.c new file mode 100644 index 0000000..0f6f51a --- /dev/null +++ b/test/litest-device-mouse-wheel-click-angle.c @@ -0,0 +1,60 @@ +/* + * 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("mouse-wheelclickangle", + .type = 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 }, + } +) diff --git a/test/litest-device-mouse-wheel-click-count.c b/test/litest-device-mouse-wheel-click-count.c new file mode 100644 index 0000000..f9a0931 --- /dev/null +++ b/test/litest-device-mouse-wheel-click-count.c @@ -0,0 +1,61 @@ +/* + * 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("mouse-wheelclickcount", + .type = 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 }, + } +) diff --git a/test/litest-device-mouse-wheel-tilt.c b/test/litest-device-mouse-wheel-tilt.c new file mode 100644 index 0000000..38a6c48 --- /dev/null +++ b/test/litest-device-mouse-wheel-tilt.c @@ -0,0 +1,60 @@ +/* + * 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("mouse-wheel-tilt", + .type = 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 }, + } +) diff --git a/test/litest-device-mouse.c b/test/litest-device-mouse.c new file mode 100644 index 0000000..68275be --- /dev/null +++ b/test/litest-device-mouse.c @@ -0,0 +1,54 @@ +/* + * 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, + -1 , -1, +}; + +TEST_DEVICE("mouse", + .type = LITEST_MOUSE, + .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, + .interface = NULL, + + .name = "Lenovo Optical USB Mouse", + .id = &input_id, + .absinfo = NULL, + .events = events, +) diff --git a/test/litest-device-ms-nano-transceiver-mouse.c b/test/litest-device-ms-nano-transceiver-mouse.c new file mode 100644 index 0000000..d481cb7 --- /dev/null +++ b/test/litest-device-ms-nano-transceiver-mouse.c @@ -0,0 +1,58 @@ +/* + * 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("ms-nano-mouse", + .type = 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, +) diff --git a/test/litest-device-ms-surface-cover.c b/test/litest-device-ms-surface-cover.c new file mode 100644 index 0000000..3114721 --- /dev/null +++ b/test/litest-device-ms-surface-cover.c @@ -0,0 +1,379 @@ +/* + * 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 }, + { 47, -127, 127, 0, 0, 0 }, + /* ABS_MT range overlap starts here */ + { 48, -127, 127, 0, 0, 0 }, /* ABS_MT_SLOT */ + { 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("ms-surface-cover", + .type = 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, +) diff --git a/test/litest-device-nexus4-touch-screen.c b/test/litest-device-nexus4-touch-screen.c new file mode 100644 index 0000000..9e70aa2 --- /dev/null +++ b/test/litest-device-nexus4-touch-screen.c @@ -0,0 +1,88 @@ +/* + * 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("nexus4", + .type = LITEST_NEXUS4_TOUCH_SCREEN, + .features = LITEST_TOUCH|LITEST_ELLIPSE, + .interface = &interface, + + .name = "Nexus 4 touch screen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-protocol-a-touch-screen.c b/test/litest-device-protocol-a-touch-screen.c new file mode 100644 index 0000000..258955c --- /dev/null +++ b/test/litest-device-protocol-a-touch-screen.c @@ -0,0 +1,209 @@ +/* + * 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 void +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_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, 1); + litest_event(d, EV_SYN, SYN_REPORT, 0); + } +} + +static void +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); +} + +static void +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); +} + +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("protocol-a", + .type = 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, +) diff --git a/test/litest-device-qemu-usb-tablet.c b/test/litest-device-qemu-usb-tablet.c new file mode 100644 index 0000000..bfcbc73 --- /dev/null +++ b/test/litest-device-qemu-usb-tablet.c @@ -0,0 +1,91 @@ +/* + * 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 void 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); +} + +static void 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); +} + +static void touch_up(struct litest_device *d, unsigned int slot) +{ + assert(slot == 0); + litest_event(d, EV_SYN, SYN_REPORT, 0); +} + +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("qemu-tablet", + .type = 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, +) diff --git a/test/litest-device-synaptics-hover.c b/test/litest-device-synaptics-hover.c new file mode 100644 index 0000000..1752901 --- /dev/null +++ b/test/litest-device-synaptics-hover.c @@ -0,0 +1,114 @@ +/* + * 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("synaptics-hover", + .type = 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, +) diff --git a/test/litest-device-synaptics-i2c.c b/test/litest-device-synaptics-i2c.c new file mode 100644 index 0000000..ce2d905 --- /dev/null +++ b/test/litest-device-synaptics-i2c.c @@ -0,0 +1,97 @@ +/* + * 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("synaptics-i2c", + .type = 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, +) diff --git a/test/litest-device-synaptics-rmi4.c b/test/litest-device-synaptics-rmi4.c new file mode 100644 index 0000000..c44bb68 --- /dev/null +++ b/test/litest-device-synaptics-rmi4.c @@ -0,0 +1,123 @@ +/* + * 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("synaptics-rmi4", + .type = LITEST_SYNAPTICS_RMI4, + .features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON, + .interface = &interface, + + .name = "Synaptics TM3053-004", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-synaptics-st.c b/test/litest-device-synaptics-st.c new file mode 100644 index 0000000..e23dcd8 --- /dev/null +++ b/test/litest-device-synaptics-st.c @@ -0,0 +1,100 @@ +/* + * 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 }, +}; + +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("synaptics-st", + .type = 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, +) diff --git a/test/litest-device-synaptics-t440.c b/test/litest-device-synaptics-t440.c new file mode 100644 index 0000000..e9f552b --- /dev/null +++ b/test/litest-device-synaptics-t440.c @@ -0,0 +1,115 @@ +/* + * 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("synaptics-t440", + .type = 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, +) diff --git a/test/litest-device-synaptics-x1-carbon-3rd.c b/test/litest-device-synaptics-x1-carbon-3rd.c new file mode 100644 index 0000000..b3efe47 --- /dev/null +++ b/test/litest-device-synaptics-x1-carbon-3rd.c @@ -0,0 +1,123 @@ +/* + * 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("synaptics-carbon3rd", + .type = 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, +) diff --git a/test/litest-device-synaptics-x220.c b/test/litest-device-synaptics-x220.c new file mode 100644 index 0000000..c570297 --- /dev/null +++ b/test/litest-device-synaptics-x220.c @@ -0,0 +1,114 @@ +/* + * 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("synaptics-x220", + .type = 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, +) diff --git a/test/litest-device-thinkpad-extrabuttons.c b/test/litest-device-thinkpad-extrabuttons.c new file mode 100644 index 0000000..9643127 --- /dev/null +++ b/test/litest-device-thinkpad-extrabuttons.c @@ -0,0 +1,86 @@ +/* + * 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("thinkpad-extrabuttons", + .type = 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 }, + }, +) diff --git a/test/litest-device-touch-screen.c b/test/litest-device-touch-screen.c new file mode 100644 index 0000000..3cdbc2d --- /dev/null +++ b/test/litest-device-touch-screen.c @@ -0,0 +1,94 @@ +/* + * 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, 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_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("generic-mt", + .type = LITEST_GENERIC_MULTITOUCH_SCREEN, + .features = LITEST_TOUCH|LITEST_ELLIPSE, + .interface = &interface, + + .name = "generic-mt", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-touchscreen-fuzz.c b/test/litest-device-touchscreen-fuzz.c new file mode 100644 index 0000000..97369ee --- /dev/null +++ b/test/litest-device-touchscreen-fuzz.c @@ -0,0 +1,85 @@ +/* + * 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("touchscreen-fuzz", + .type = LITEST_MULTITOUCH_FUZZ_SCREEN, + .features = LITEST_TOUCH, + .interface = &interface, + + .name = "touchscreen with fuzz", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-touchscreen-invalid-range.c b/test/litest-device-touchscreen-invalid-range.c new file mode 100644 index 0000000..d42cd35 --- /dev/null +++ b/test/litest-device-touchscreen-invalid-range.c @@ -0,0 +1,85 @@ +/* + * 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("touchscreen-invalid-range", + .type = LITEST_TOUCHSCREEN_INVALID_RANGE, + .features = LITEST_TOUCH, + .interface = &interface, + + .name = "touchscreen-invalid-range", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-touchscreen-mt-tool.c b/test/litest-device-touchscreen-mt-tool.c new file mode 100644 index 0000000..811e95d --- /dev/null +++ b/test/litest-device-touchscreen-mt-tool.c @@ -0,0 +1,88 @@ +/* + * 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("touchscreen-mt-tool-type", + .type = LITEST_TOUCHSCREEN_MT_TOOL_TYPE, + .features = LITEST_TOUCH, + .interface = &interface, + + .name = "touchscreen-mt-tool-type", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-trackpoint.c b/test/litest-device-trackpoint.c new file mode 100644 index 0000000..eaad8b7 --- /dev/null +++ b/test/litest-device-trackpoint.c @@ -0,0 +1,56 @@ +/* + * 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("trackpoint", + .type = LITEST_TRACKPOINT, + .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_POINTINGSTICK, + .interface = NULL, + + .name = "TPPS/2 IBM TrackPoint", + .id = &input_id, + .absinfo = NULL, + .events = events, + +) diff --git a/test/litest-device-uclogic-tablet.c b/test/litest-device-uclogic-tablet.c new file mode 100644 index 0000000..9b6c399 --- /dev/null +++ b/test/litest-device-uclogic-tablet.c @@ -0,0 +1,98 @@ +/* + * 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[] = { + { .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, + .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("uclogic-tablet", + .type = LITEST_UCLOGIC_TABLET, + .features = LITEST_TABLET | LITEST_HOVER, + .interface = &interface, + + .name = "uclogic PenTablet Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-vmware-virtual-usb-mouse.c b/test/litest-device-vmware-virtual-usb-mouse.c new file mode 100644 index 0000000..faefda3 --- /dev/null +++ b/test/litest-device-vmware-virtual-usb-mouse.c @@ -0,0 +1,105 @@ +/* + * 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 void 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); +} + +static void 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); +} + +static void touch_up(struct litest_device *d, unsigned int slot) +{ + assert(slot == 0); + litest_event(d, EV_SYN, SYN_REPORT, 0); +} + +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("vmware-virtmouse", + .type = 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, +) diff --git a/test/litest-device-wacom-bamboo-16fg-pen.c b/test/litest-device-wacom-bamboo-16fg-pen.c new file mode 100644 index 0000000..2427fc7 --- /dev/null +++ b/test/litest-device-wacom-bamboo-16fg-pen.c @@ -0,0 +1,113 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-bamboo-tablet", + .type = LITEST_WACOM_BAMBOO, + .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_HOVER, + .interface = &interface, + + .name = "Wacom Bamboo 16FG 4x5 Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-wacom-bamboo-2fg-finger.c b/test/litest-device-wacom-bamboo-2fg-finger.c new file mode 100644 index 0000000..08ba28c --- /dev/null +++ b/test/litest-device-wacom-bamboo-2fg-finger.c @@ -0,0 +1,95 @@ +/* + * 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("wacom-bamboo-2fg-finger", + .type = 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" }, + } +) diff --git a/test/litest-device-wacom-bamboo-2fg-pad.c b/test/litest-device-wacom-bamboo-2fg-pad.c new file mode 100644 index 0000000..05f71ef --- /dev/null +++ b/test/litest-device-wacom-bamboo-2fg-pad.c @@ -0,0 +1,78 @@ +/* + * 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("wacom-bamboo-2fg-pad", + .type = 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 } + } +) diff --git a/test/litest-device-wacom-bamboo-2fg-pen.c b/test/litest-device-wacom-bamboo-2fg-pen.c new file mode 100644 index 0000000..aa1e3c2 --- /dev/null +++ b/test/litest-device-wacom-bamboo-2fg-pen.c @@ -0,0 +1,117 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-bamboo-2fg-pen", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-12wx-pen.c b/test/litest-device-wacom-cintiq-12wx-pen.c new file mode 100644 index 0000000..ca33137 --- /dev/null +++ b/test/litest-device-wacom-cintiq-12wx-pen.c @@ -0,0 +1,149 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-cintiq-tablet", + .type = LITEST_WACOM_CINTIQ, + .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, +) diff --git a/test/litest-device-wacom-cintiq-13hdt-finger.c b/test/litest-device-wacom-cintiq-13hdt-finger.c new file mode 100644 index 0000000..7988f04 --- /dev/null +++ b/test/litest-device-wacom-cintiq-13hdt-finger.c @@ -0,0 +1,97 @@ +/* + * 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("wacom-cintiq-13hdt-finger", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-13hdt-pad.c b/test/litest-device-wacom-cintiq-13hdt-pad.c new file mode 100644 index 0000000..307eaa7 --- /dev/null +++ b/test/litest-device-wacom-cintiq-13hdt-pad.c @@ -0,0 +1,107 @@ +/* + * 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("wacom-cintiq-13hdt-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-13hdt-pen.c b/test/litest-device-wacom-cintiq-13hdt-pen.c new file mode 100644 index 0000000..5975510 --- /dev/null +++ b/test/litest-device-wacom-cintiq-13hdt-pen.c @@ -0,0 +1,142 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-cintiq-13hdt-pen-tablet", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-24hd-pen.c b/test/litest-device-wacom-cintiq-24hd-pen.c new file mode 100644 index 0000000..2e47df9 --- /dev/null +++ b/test/litest-device-wacom-cintiq-24hd-pen.c @@ -0,0 +1,138 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-cintiq-24hd-tablet", + .type = LITEST_WACOM_CINTIQ_24HD, + .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, +) diff --git a/test/litest-device-wacom-cintiq-24hdt-pad.c b/test/litest-device-wacom-cintiq-24hdt-pad.c new file mode 100644 index 0000000..d3e4712 --- /dev/null +++ b/test/litest-device-wacom-cintiq-24hdt-pad.c @@ -0,0 +1,131 @@ +/* + * 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("wacom-cintiq-24hdt-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-pro-16-finger.c b/test/litest-device-wacom-cintiq-pro-16-finger.c new file mode 100644 index 0000000..a51a138 --- /dev/null +++ b/test/litest-device-wacom-cintiq-pro-16-finger.c @@ -0,0 +1,96 @@ +/* + * 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("wacom-cintiq-pro16-finger", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-pro-16-pad.c b/test/litest-device-wacom-cintiq-pro-16-pad.c new file mode 100644 index 0000000..c5dcfb1 --- /dev/null +++ b/test/litest-device-wacom-cintiq-pro-16-pad.c @@ -0,0 +1,77 @@ +/* + * 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("wacom-cintiq-pro16-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-cintiq-pro-16-pen.c b/test/litest-device-wacom-cintiq-pro-16-pen.c new file mode 100644 index 0000000..35997ae --- /dev/null +++ b/test/litest-device-wacom-cintiq-pro-16-pen.c @@ -0,0 +1,149 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-cintiq-pro16-pen", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-ekr.c b/test/litest-device-wacom-ekr.c new file mode 100644 index 0000000..e2fee26 --- /dev/null +++ b/test/litest-device-wacom-ekr.c @@ -0,0 +1,116 @@ +/* + * 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("wacom-ekr", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-hid4800-pen.c b/test/litest-device-wacom-hid4800-pen.c new file mode 100644 index 0000000..3f42485 --- /dev/null +++ b/test/litest-device-wacom-hid4800-pen.c @@ -0,0 +1,110 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-hid4800-tablet", + .type = LITEST_WACOM_HID4800_PEN, + .features = LITEST_TABLET | LITEST_HOVER, + .interface = &interface, + + .name = "Wacom HID 4800 Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-wacom-intuos3-pad.c b/test/litest-device-wacom-intuos3-pad.c new file mode 100644 index 0000000..7c972c8 --- /dev/null +++ b/test/litest-device-wacom-intuos3-pad.c @@ -0,0 +1,101 @@ +/* + * 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("wacom-intuos3-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-intuos5-finger.c b/test/litest-device-wacom-intuos5-finger.c new file mode 100644 index 0000000..4b5d8f6 --- /dev/null +++ b/test/litest-device-wacom-intuos5-finger.c @@ -0,0 +1,121 @@ +/* + * 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("wacom-intuos5-finger", + .type = LITEST_WACOM_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 }, + }, +) diff --git a/test/litest-device-wacom-intuos5-pad.c b/test/litest-device-wacom-intuos5-pad.c new file mode 100644 index 0000000..4091c7b --- /dev/null +++ b/test/litest-device-wacom-intuos5-pad.c @@ -0,0 +1,107 @@ +/* + * 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("wacom-intuos5-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-wacom-intuos5-pen.c b/test/litest-device-wacom-intuos5-pen.c new file mode 100644 index 0000000..ae8439c --- /dev/null +++ b/test/litest-device-wacom-intuos5-pen.c @@ -0,0 +1,158 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("wacom-intuos5-tablet", + .type = LITEST_WACOM_INTUOS, + .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 }, + }, +) diff --git a/test/litest-device-wacom-isdv4-4200-pen.c b/test/litest-device-wacom-isdv4-4200-pen.c new file mode 100644 index 0000000..2627138 --- /dev/null +++ b/test/litest-device-wacom-isdv4-4200-pen.c @@ -0,0 +1,110 @@ +/* + * 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 = BTN_TOOL_PEN, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static struct input_event proximity_out[] = { + { .type = EV_KEY, .code = BTN_TOOL_PEN, .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("wacom-isdv4-4200-tablet", + .type = LITEST_WACOM_ISDV4_4200_PEN, + .features = LITEST_TABLET|LITEST_HOVER, + .interface = &interface, + + .name = "Wacom ISD-V4 Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-wacom-isdv4-e6-finger.c b/test/litest-device-wacom-isdv4-e6-finger.c new file mode 100644 index 0000000..68cd1fe --- /dev/null +++ b/test/litest-device-wacom-isdv4-e6-finger.c @@ -0,0 +1,88 @@ +/* + * 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("wacom-touch", + .type = LITEST_WACOM_TOUCH, + .features = LITEST_TOUCH, + .interface = &interface, + + .name = "Wacom ISDv4 E6 Finger", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-wacom-isdv4-e6-pen.c b/test/litest-device-wacom-isdv4-e6-pen.c new file mode 100644 index 0000000..07c250a --- /dev/null +++ b/test/litest-device-wacom-isdv4-e6-pen.c @@ -0,0 +1,103 @@ +/* + * 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 = BTN_TOOL_PEN, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static struct input_event proximity_out[] = { + { .type = EV_KEY, .code = BTN_TOOL_PEN, .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("wacom-isdv4-tablet", + .type = LITEST_WACOM_ISDV4, + .features = LITEST_TABLET | LITEST_HOVER, + .interface = &interface, + + .name = "Wacom ISDv4 E6 Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-wacom-mobilestudio-pro-pad.c b/test/litest-device-wacom-mobilestudio-pro-pad.c new file mode 100644 index 0000000..b810f59 --- /dev/null +++ b/test/litest-device-wacom-mobilestudio-pro-pad.c @@ -0,0 +1,113 @@ +/* + * 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("wacom-mobilestudio-pro16-pad", + .type = 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 }, + }, +) diff --git a/test/litest-device-waltop-tablet.c b/test/litest-device-waltop-tablet.c new file mode 100644 index 0000000..1952286 --- /dev/null +++ b/test/litest-device-waltop-tablet.c @@ -0,0 +1,238 @@ +/* + * 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 = BTN_TOOL_PEN, .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 = BTN_TOOL_PEN, .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("waltop-tablet", + .type = 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, +) diff --git a/test/litest-device-wheel-only.c b/test/litest-device-wheel-only.c new file mode 100644 index 0000000..c2bbecb --- /dev/null +++ b/test/litest-device-wheel-only.c @@ -0,0 +1,53 @@ +/* + * 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("wheel-only", + .type = 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 }, + }, +) diff --git a/test/litest-device-xen-virtual-pointer.c b/test/litest-device-xen-virtual-pointer.c new file mode 100644 index 0000000..44d3013 --- /dev/null +++ b/test/litest-device-xen-virtual-pointer.c @@ -0,0 +1,96 @@ +/* + * 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 void 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); +} + +static void 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); +} + +static void touch_up(struct litest_device *d, unsigned int slot) +{ + assert(slot == 0); + litest_event(d, EV_SYN, SYN_REPORT, 0); +} + +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("xen-pointer", + .type = LITEST_XEN_VIRTUAL_POINTER, + .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE, + .interface = &interface, + + .name = "Xen Virtual Pointer", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest-device-yubikey.c b/test/litest-device-yubikey.c new file mode 100644 index 0000000..78b2279 --- /dev/null +++ b/test/litest-device-yubikey.c @@ -0,0 +1,159 @@ +/* + * 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("yubikey", + .type = LITEST_YUBIKEY, + .features = LITEST_KEYS, + .interface = NULL, + + .name = "Yubico Yubico Yubikey II", + .id = &input_id, + .events = events, + .absinfo = NULL, +) diff --git a/test/litest-int.h b/test/litest-int.h new file mode 100644 index 0000000..598c8d0 --- /dev/null +++ b/test/litest-int.h @@ -0,0 +1,138 @@ +/* + * 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 + +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 { + void (*touch_down)(struct litest_device *d, unsigned int slot, double x, double y); + void (*touch_move)(struct litest_device *d, unsigned int slot, double x, double y); + void (*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; + + /** + * 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_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 */ +}; + +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 diff --git a/test/litest-selftest.c b/test/litest-selftest.c new file mode 100644 index 0000000..75662a0 --- /dev/null +++ b/test/litest-selftest.c @@ -0,0 +1,468 @@ +#include + +#include +#include +#include +#include + +#include + +#include "litest.h" + +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(ck_double_eq_and_ne) +{ + ck_assert_double_eq(0.4,0.4); + ck_assert_double_eq(0.4,0.4 + 1E-6); + ck_assert_double_ne(0.4,0.4 + 1E-3); +} +END_TEST + +START_TEST(ck_double_lt_gt) +{ + ck_assert_double_lt(12.0,13.0); + ck_assert_double_gt(15.4,13.0); + ck_assert_double_le(12.0,12.0); + ck_assert_double_le(12.0,20.0); + ck_assert_double_ge(12.0,12.0); + ck_assert_double_ge(20.0,12.0); +} +END_TEST + +START_TEST(ck_double_eq_fails) +{ + ck_assert_double_eq(0.41,0.4); +} +END_TEST + +START_TEST(ck_double_ne_fails) +{ + ck_assert_double_ne(0.4 + 1E-7,0.4); +} +END_TEST + +START_TEST(ck_double_lt_fails) +{ + ck_assert_double_lt(6,5); +} +END_TEST + +START_TEST(ck_double_gt_fails) +{ + ck_assert_double_gt(5,6); +} +END_TEST + +START_TEST(ck_double_le_fails) +{ + ck_assert_double_le(6,5); +} +END_TEST + +START_TEST(ck_double_ge_fails) +{ + ck_assert_double_ge(5,6); +} +END_TEST + +START_TEST(zalloc_overflow) +{ + zalloc(-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 + +static Suite * +litest_assert_macros_suite(void) +{ + TCase *tc; + Suite *s; + + s = suite_create("litest:assert macros"); + 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, ck_double_eq_and_ne); + tcase_add_test(tc, ck_double_lt_gt); + tcase_add_exit_test(tc, ck_double_eq_fails, 1); + tcase_add_exit_test(tc, ck_double_ne_fails, 1); + tcase_add_exit_test(tc, ck_double_lt_fails, 1); + tcase_add_exit_test(tc, ck_double_gt_fails, 1); + tcase_add_exit_test(tc, ck_double_le_fails, 1); + tcase_add_exit_test(tc, ck_double_ge_fails, 1); + 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); + + 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; +} diff --git a/test/litest.c b/test/litest.c new file mode 100644 index 0000000..5b09ec4 --- /dev/null +++ b/test/litest.c @@ -0,0 +1,4298 @@ +/* + * 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 +#include +#include "linux/input.h" +#include +#include +#include +#include +#include +#include +#include +#if HAVE_LIBSYSTEMD +#include +#endif +#ifdef __FreeBSD__ +#include +#endif + +#include + +#include "litest.h" +#include "litest-int.h" +#include "libinput-util.h" +#include "quirks.h" +#include "builddir.h" + +#include + +#define UDEV_RULES_D "/run/udev/rules.d" +#define UDEV_RULE_PREFIX "99-litest-" +#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 = 8; +static bool in_debugger = false; +static bool verbose = false; +static bool run_deviceless = false; +static bool use_system_rules_quirks = false; +const char *filter_test = NULL; +const char *filter_device = NULL; +const char *filter_group = NULL; +static struct quirks_context *quirks_context; + +struct created_file { + struct list link; + char *path; +}; + +struct list created_files_list; /* list of all files to remove at the end of + the test run */ + +static void litest_init_udev_rules(struct list *created_files_list); +static void litest_remove_udev_rules(struct list *created_files_list); + +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 + +static void +litest_backtrace(void) +{ +#if HAVE_GSTACK + pid_t parent, child; + int pipefd[2]; + + if (RUNNING_ON_VALGRIND) { + litest_log(" Using valgrind, omitting backtrace\n"); + return; + } + + 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 */ + char buf[1024]; + int status, nread; + + close(pipefd[1]); + waitpid(child, &status, 0); + + status = WEXITSTATUS(status); + if (status != 0) { + litest_log("ERROR: gstack failed, no backtrace available: %s\n", + strerror(status)); + } else { + litest_log("\nBacktrace:\n"); + while ((nread = read(pipefd[0], buf, sizeof(buf) - 1)) > 0) { + buf[nread] = '\0'; + litest_log("%s", buf); + } + litest_log("\n"); + } + close(pipefd[0]); +#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) { + va_list args; + va_start(args, message); + litest_vlog(message, args); + va_end(args); + } + + litest_log("in %s() (%s:%d)\n", func, file, line); + litest_backtrace(); + 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(); + 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(); + 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(); + abort(); +} + +struct test { + struct list node; + char *name; + char *devname; + void *func; + void *setup; + void *teardown; + + struct range range; + bool deviceless; +}; + +struct suite { + struct list node; + struct list tests; + char *name; +}; + +static struct litest_device *current_device; + +struct litest_device *litest_current_device(void) +{ + return current_device; +} + +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; +} + +struct list devices; + +static struct list all_tests; + +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 void +litest_add_tcase_for_device(struct suite *suite, + const char *funcname, + void *func, + const struct litest_test_device *dev, + const struct range *range) +{ + 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; + + list_insert(&suite->tests, &t->node); +} + +static void +litest_add_tcase_no_device(struct suite *suite, + void *func, + const char *funcname, + const struct range *range) +{ + struct test *t; + const char *test_name = funcname; + + if (filter_device && + fnmatch(filter_device, test_name, 0) != 0) + return; + + 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->setup = NULL; + t->teardown = NULL; + + list_insert(&suite->tests, &t->node); +} + +static void +litest_add_tcase_deviceless(struct suite *suite, + void *func, + const char *funcname, + const struct range *range) +{ + struct test *t; + const char *test_name = funcname; + + if (filter_device && + fnmatch(filter_device, test_name, 0) != 0) + return; + + 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->setup = NULL; + t->teardown = NULL; + + list_insert(&suite->tests, &t->node); +} + +static struct suite * +get_suite(const char *name) +{ + struct suite *s; + /* this is the list meson calls, ensure we don't miss out on tests */ + const char * allowed_suites[] = { + "config:", "context:", "device:", "events:", "gestures:", + "keyboard:", "lid:", "log:", "misc:", "pad:", "path:", + "pointer:", "quirks:", "switch:", "tablet:", "tablet-mode:", + "tap:", "timer:", "totem:", "touch:", "touchpad:", + "trackball:", "trackpoint:", "udev:", + }; + const char **allowed; + bool found = false; + + ARRAY_FOR_EACH(allowed_suites, allowed) { + if (strneq(name, *allowed, strlen(*allowed))) { + found = true; + break; + } + } + if (!found) + litest_abort_msg("Suite name '%s' is not allowed\n", name); + + list_for_each(s, &all_tests, node) { + if (streq(s->name, name)) + return s; + } + + s = zalloc(sizeof(*s)); + s->name = safe_strdup(name); + + list_init(&s->tests); + list_insert(&all_tests, &s->node); + + return s; +} + +static void +litest_add_tcase(const char *suite_name, + const char *funcname, + void *func, + int64_t required, + int64_t excluded, + const struct range *range) +{ + struct suite *suite; + bool added = false; + + litest_assert(required >= LITEST_DEVICELESS); + litest_assert(excluded >= LITEST_DEVICELESS); + + if (filter_test && + fnmatch(filter_test, funcname, 0) != 0) + return; + + if (filter_group && + fnmatch(filter_group, suite_name, 0) != 0) + return; + + suite = get_suite(suite_name); + + if (required == LITEST_DEVICELESS && + excluded == LITEST_DEVICELESS) { + litest_add_tcase_deviceless(suite, func, funcname, range); + added = true; + } else if (required == LITEST_DISABLE_DEVICE && + excluded == LITEST_DISABLE_DEVICE) { + 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; + + 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; + + 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, void *func) +{ + _litest_add(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE); +} + +void +_litest_add_ranged_no_device(const char *name, + const char *funcname, + 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, + void *func) +{ + _litest_add_ranged(name, + funcname, + func, + LITEST_DEVICELESS, + LITEST_DEVICELESS, + NULL); +} + +void +_litest_add(const char *name, + const char *funcname, + 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, + void *func, + int64_t required, + int64_t excluded, + const struct range *range) +{ + litest_add_tcase(name, funcname, func, required, excluded, range); +} + +void +_litest_add_for_device(const char *name, + const char *funcname, + 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 *name, + const char *funcname, + void *func, + enum litest_device_type type, + const struct range *range) +{ + struct suite *s; + 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; + + if (filter_group && + fnmatch(filter_group, name, 0) != 0) + return; + + s = get_suite(name); + 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\n"); +} + +LIBINPUT_ATTRIBUTE_PRINTF(3, 0) +static void +litest_log_handler(struct libinput *libinput, + enum libinput_log_priority pri, + const char *format, + va_list args) +{ + static int is_tty = -1; + const char *priority = NULL; + const char *color; + + if (is_tty == -1) + is_tty = isatty(STDERR_FILENO); + + 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 (!is_tty) + 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; + + fprintf(stderr, "%slitest %s ", color, priority); + vfprintf(stderr, format, args); + if (is_tty) + 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, "offset negative")) + litest_abort_msg("libinput bug triggered, aborting.\n"); + } + + if (strstr(format, "Touch jump detected and discarded")) { + litest_abort_msg("libinput touch jump triggered, aborting.\n"); + } +} + +static void +litest_init_device_udev_rules(struct litest_test_device *dev, FILE *f) +{ + const struct key_value_str *kv; + static int count; + + 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); + kv++; + } + + fprintf(f, "\n"); + 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/%s-XXXXXX.rules", + UDEV_RULES_D, + UDEV_RULE_PREFIX); + litest_assert_int_gt(rc, 0); + + fd = mkstemps(path, 6); + litest_assert_int_ne(fd, -1); + 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) +{ + int fd = open(path, flags); + return fd < 0 ? -errno : fd; +} + +static void +close_restricted(int fd, void *userdata) +{ + close(fd); +} + +struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +static void +litest_signal(int sig) +{ + struct created_file *f, *tmp; + + list_for_each_safe(f, tmp, &created_files_list, link) { + list_remove(&f->link); + unlink(f->path); + rmdir(f->path); + /* in the sighandler, we can't free */ + } + + if (fork() == 0) { + /* child, we can run system() */ + litest_reload_udev_rules(); + exit(0); + } + + exit(1); +} + +static inline void +litest_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 = litest_signal; + rc = sigaction(sig, &act, &oact); + litest_assert_int_ne(rc, -1); +} + +static void +litest_free_test_list(struct list *tests) +{ + struct suite *s, *snext; + + list_for_each_safe(s, snext, tests, node) { + struct test *t, *tnext; + + list_for_each_safe(t, tnext, &s->tests, node) { + free(t->name); + free(t->devname); + list_remove(&t->node); + free(t); + } + + list_remove(&s->node); + free(s->name); + free(s); + } +} + +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 int +litest_run_suite(struct list *tests, int which, int max, int error_fd) +{ + int failed = 0; + SRunner *sr = NULL; + struct suite *s; + struct test *t; + int count = -1; + struct name { + struct list node; + char *name; + }; + struct name *n, *tmp; + struct list testnames; + const char *data_path; + + 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); + + /* Check just takes the suite/test name pointers but doesn't strdup + * them - we have to keep them around */ + list_init(&testnames); + + /* For each test, create one test suite with one test case, then + add it to the test runner. The only benefit suites give us in + check is that we can filter them, but our test runner has a + --filter-group anyway. */ + list_for_each(s, tests, node) { + list_for_each(t, &s->tests, node) { + Suite *suite; + TCase *tc; + char *sname, *tname; + + /* We run deviceless tests as part of the normal + * test suite runner, just in case. Filtering + * all the other ones out just for the case where + * we can't run the full runner. + */ + if (run_deviceless && !t->deviceless) + continue; + + count = (count + 1) % max; + if (max != 1 && (count % max) != which) + continue; + + xasprintf(&sname, + "%s:%s:%s", + s->name, + t->name, + t->devname); + litest_assert_ptr_notnull(sname); + n = zalloc(sizeof(*n)); + n->name = sname; + list_insert(&testnames, &n->node); + + xasprintf(&tname, + "%s:%s", + t->name, + t->devname); + litest_assert_ptr_notnull(tname); + n = zalloc(sizeof(*n)); + n->name = tname; + list_insert(&testnames, &n->node); + + tc = tcase_create(tname); + tcase_add_checked_fixture(tc, + t->setup, + t->teardown); + if (t->range.upper != t->range.lower) + tcase_add_loop_test(tc, + t->func, + t->range.lower, + t->range.upper); + else + tcase_add_test(tc, t->func); + + suite = suite_create(sname); + suite_add_tcase(suite, tc); + + if (!sr) + sr = srunner_create(suite); + else + srunner_add_suite(sr, suite); + } + } + + if (!sr) + goto out; + + srunner_run_all(sr, CK_ENV); + failed = srunner_ntests_failed(sr); + if (failed) { + TestResult **trs; + + trs = srunner_failures(sr); + for (int i = 0; i < failed; i++) { + char tname[256]; + char *c = tname; + + /* tr_tcname is in the form "suite:testcase", let's + * convert this to "suite(testcase)" to make + * double-click selection in the terminal a bit + * easier. */ + snprintf(tname, sizeof(tname), "%s)", tr_tcname(trs[i])); + if ((c = index(c, ':'))) + *c = '('; + + dprintf(error_fd, + ":: Failure: %s:%d: %s\n", + tr_lfile(trs[i]), + tr_lno(trs[i]), + tname); + } + free(trs); + } + srunner_free(sr); +out: + list_for_each_safe(n, tmp, &testnames, node) { + free(n->name); + free(n); + } + + quirks_context_unref(quirks_context); + + return failed; +} + +static int +litest_fork_subtests(struct list *tests, int max_forks) +{ + int failed = 0; + int status; + pid_t pid; + int f; + int pipes[max_forks]; + + for (f = 0; f < max_forks; f++) { + int rc; + int pipefd[2]; + + rc = pipe2(pipefd, O_NONBLOCK); + assert(rc != -1); + + pid = fork(); + if (pid == 0) { + close(pipefd[0]); + failed = litest_run_suite(tests, + f, + max_forks, + pipefd[1]); + + litest_free_test_list(&all_tests); + exit(failed); + /* child always exits here */ + } else { + pipes[f] = pipefd[0]; + close(pipefd[1]); + } + } + + /* parent process only */ + while (wait(&status) != -1 && errno != ECHILD) { + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + failed = 1; + } + + for (f = 0; f < max_forks; f++) { + char buf[1024] = {0}; + int rc; + + while ((rc = read(pipes[f], buf, sizeof(buf) - 1)) > 0) { + buf[rc] = '\0'; + fprintf(stderr, "%s", buf); + } + + close(pipes[f]); + } + + return failed; +} + +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", + "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 inline int +litest_run(int argc, char **argv) +{ + int failed = 0; + int inhibit_lock_fd; + + list_init(&created_files_list); + + if (list_empty(&all_tests)) { + fprintf(stderr, + "Error: filters are too strict, no tests to run.\n"); + return 1; + } + + if (getenv("LITEST_VERBOSE")) + verbose = true; + + 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); + } + + litest_setup_sighandler(SIGINT); + + inhibit_lock_fd = inhibit(); + + if (jobs == 1) + failed = litest_run_suite(&all_tests, 1, 1, STDERR_FILENO); + else + failed = litest_fork_subtests(&all_tests, jobs); + + close(inhibit_lock_fd); + + litest_free_test_list(&all_tests); + + litest_remove_udev_rules(&created_files_list); + + return failed; +} + +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)\n", + file->path, + strerror(errno)); + litest_assert_int_ne(chmod(file->path, 0644), -1); + + 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)\n", + 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); + + /* Ony 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_int_ne(fd, -1); + f = fdopen(fd, "w"); + litest_assert_notnull(f); + litest_assert_int_ge(fputs(dev->quirk_file, f), 0); + fclose(f); + + return safe_strdup(path); +} + +/** + * Install the quirks from the quirks/ source directory. + */ +static void +litest_install_source_quirks(struct list *created_files_list, + const char *dirname) +{ + const char *quirksdir = "quirks/"; + char **quirks, **q; + + quirks = strv_from_string(LIBINPUT_QUIRKS_FILES, ":"); + litest_assert(quirks); + + q = quirks; + while (*q) { + struct created_file *file; + char *filename; + char dest[PATH_MAX]; + char src[PATH_MAX]; + + litest_assert(strneq(*q, quirksdir, strlen(quirksdir))); + filename = &(*q)[strlen(quirksdir)]; + + 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); + q++; + } + strv_free(quirks); +} + +/** + * 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_int_ne(chmod(tmpdir, 0755), -1); + 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 +mkdir_p(const char *dir) +{ + char *path, *parent; + int rc; + + if (streq(dir, "/")) + return; + + path = strdup(dir); + parent = dirname(path); + + mkdir_p(parent); + rc = mkdir(dir, 0755); + + if (rc == -1 && errno != EEXIST) { + litest_abort_msg("Failed to create directory %s (%s)\n", + dir, + strerror(errno)); + } + + free(path); +} + +static inline void +litest_init_udev_rules(struct list *created_files) +{ + 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, *tmp; + bool reload_udev; + + reload_udev = !list_empty(created_files_list); + + list_for_each_safe(f, tmp, created_files_list, link) { + list_remove(&f->link); + unlink(f->path); + rmdir(f->path); + free(f->path); + free(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) + ck_abort_msg("Invalid device type %d\n", 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_int_ne(fd, -1); + + rc = libevdev_new_from_fd(fd, &d->evdev); + litest_assert_int_eq(rc, 0); + + return d; + +} + +struct libinput * +litest_create_context(void) +{ + struct libinput *libinput = + libinput_path_create_context(&interface, NULL); + 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_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: ")) + return; + + litest_abort_msg("Expected bug statement in log msg, aborting.\n"); +} + +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); + } + } + 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_int_ne(rc, -1); + 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 (!streq(udev_action, udev_event)) { + udev_device_unref(udev_device); + continue; + } + + udev_syspath = udev_device_get_syspath(udev_device); + if (udev_syspath && strneq(udev_syspath, + syspath, + strlen(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); + libinput_unref(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_int_eq(ret, 0); +} + +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)\n", + 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 (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)\n", + 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_proximity_in(struct litest_device *d, int x, int y, struct axis_replacement *axes) +{ + struct input_event *ev; + + ev = d->interface->tablet_proximity_in_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_proximity_out(struct litest_device *d) +{ + struct input_event *ev; + + ev = d->interface->tablet_proximity_out_events; + while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) { + int value = auto_assign_tablet_value(d, ev, -1, -1, NULL); + if (!tablet_ignore_event(ev, value)) + litest_event(d, ev->type, ev->code, value); + ev++; + } +} + +void +litest_tablet_motion(struct litest_device *d, int x, int y, struct axis_replacement *axes) +{ + struct input_event *ev; + + 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_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 = 0; i < steps - 1; i++) { + 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_touch_move(d, 2, x2 + dx / steps * i, + y2 + dy / steps * i); + + libinput_dispatch(d->libinput); + msleep(sleep_ms); + libinput_dispatch(d->libinput); + } + litest_touch_move(d, 0, x0 + dx, y0 + dy); + litest_touch_move(d, 1, x1 + dx, y1 + dy); + litest_touch_move(d, 2, x2 + dx, y2 + dy); +} + +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 *ev; + 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_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) +{ + struct input_event *ev; + 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 || + 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, ...) +{ + 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, 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); + + 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_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); + libinput_event_destroy(event); + } +} + +void +litest_drain_events(struct libinput *li) +{ + struct libinput_event *event; + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + 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); + } +} + +static 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_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 START"; + 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 START"; + 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_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_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) +{ + struct libinput_event_pointer *p; + struct libinput_event_tablet_tool *t; + struct libinput_event_tablet_pad *pad; + struct libinput_device *dev; + enum libinput_event_type type; + double x, y; + + dev = libinput_event_get_device(event); + type = libinput_event_get_type(event); + + fprintf(stderr, + "device %s (%s) type %s ", + libinput_device_get_sysname(dev), + libinput_device_get_name(dev), + litest_event_get_type_str(event)); + switch (type) { + case 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); + fprintf(stderr, "%.2f/%.2f", x, y); + break; + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + p = libinput_event_get_pointer_event(event); + x = libinput_event_pointer_get_absolute_x(p); + y = libinput_event_pointer_get_absolute_y(p); + fprintf(stderr, "%.2f/%.2f", x, y); + break; + case LIBINPUT_EVENT_POINTER_BUTTON: + p = libinput_event_get_pointer_event(event); + fprintf(stderr, + "button %d state %d", + libinput_event_pointer_get_button(p), + libinput_event_pointer_get_button_state(p)); + break; + case LIBINPUT_EVENT_POINTER_AXIS: + p = libinput_event_get_pointer_event(event); + x = 0.0; + y = 0.0; + if (libinput_event_pointer_has_axis(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) + y = libinput_event_pointer_get_axis_value(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + if (libinput_event_pointer_has_axis(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) + x = libinput_event_pointer_get_axis_value(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + fprintf(stderr, "vert %.2f horiz %.2f", y, x); + break; + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + t = libinput_event_get_tablet_tool_event(event); + fprintf(stderr, "proximity %d", + libinput_event_tablet_tool_get_proximity_state(t)); + break; + case LIBINPUT_EVENT_TABLET_TOOL_TIP: + t = libinput_event_get_tablet_tool_event(event); + fprintf(stderr, "tip %d", + libinput_event_tablet_tool_get_tip_state(t)); + break; + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: + t = libinput_event_get_tablet_tool_event(event); + fprintf(stderr, "button %d state %d", + libinput_event_tablet_tool_get_button(t), + libinput_event_tablet_tool_get_button_state(t)); + break; + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + pad = libinput_event_get_tablet_pad_event(event); + fprintf(stderr, "button %d state %d", + libinput_event_tablet_pad_get_button_number(pad), + libinput_event_tablet_pad_get_button_state(pad)); + break; + case LIBINPUT_EVENT_TABLET_PAD_RING: + pad = libinput_event_get_tablet_pad_event(event); + fprintf(stderr, "ring %d position %.2f source %d", + libinput_event_tablet_pad_get_ring_number(pad), + libinput_event_tablet_pad_get_ring_position(pad), + libinput_event_tablet_pad_get_ring_source(pad)); + break; + case LIBINPUT_EVENT_TABLET_PAD_STRIP: + pad = libinput_event_get_tablet_pad_event(event); + fprintf(stderr, "strip %d position %.2f source %d", + libinput_event_tablet_pad_get_ring_number(pad), + libinput_event_tablet_pad_get_ring_position(pad), + libinput_event_tablet_pad_get_ring_source(pad)); + break; + default: + break; + } + + fprintf(stderr, "\n"); +} + +void +litest_assert_event_type(struct libinput_event *event, + enum libinput_event_type want) +{ + if (libinput_event_get_type(event) == want) + return; + + fprintf(stderr, + "FAILED EVENT TYPE: %s: have %s (%d) but want %s (%d)\n", + libinput_device_get_name(libinput_event_get_device(event)), + litest_event_get_type_str(event), + libinput_event_get_type(event), + litest_event_type_str(want), + want); + fprintf(stderr, "Wrong event is: "); + litest_print_event(event); + litest_backtrace(); + abort(); +} + +void +litest_assert_empty_queue(struct libinput *li) +{ + bool empty_queue = true; + struct libinput_event *event; + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + empty_queue = false; + fprintf(stderr, + "Unexpected event: "); + litest_print_event(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, fd; + const struct input_absinfo *abs; + const struct input_absinfo default_abs = { + .value = 0, + .minimum = 0, + .maximum = 100, + .fuzz = 0, + .flat = 0, + .resolution = 100 + }; + char buf[512]; + const char *devnode; + + 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 { + rc = libevdev_enable_event_code(dev, type, code, + type == EV_ABS ? &default_abs : NULL); + } + litest_assert_int_eq(rc, 0); + } + + rc = libevdev_uinput_create_from_device(dev, + LIBEVDEV_UINPUT_OPEN_MANAGED, + &uinput); + /* workaround for a bug in libevdev pre-1.3 + http://cgit.freedesktop.org/libevdev/commit/?id=debe9b030c8069cdf78307888ef3b65830b25122 */ + if (rc == -EBADF) + rc = -EACCES; + litest_assert_msg(rc == 0, "Failed to create uinput device: %s\n", strerror(-rc)); + + libevdev_free(dev); + + devnode = libevdev_uinput_get_devnode(uinput); + litest_assert_notnull(devnode); + fd = open(devnode, O_RDONLY); + litest_assert_int_gt(fd, -1); + rc = libevdev_new_from_fd(fd, &dev); + litest_assert_int_eq(rc, 0); + + /* uinput before kernel 4.5 + libevdev 1.5.0 does not support + * setting the resolution, so we set it afterwards. This is of + * course racy as hell but the way we _generally_ use this function + * by the time libinput uses the device, we're finished here. + * + * If you have kernel 4.5 and libevdev 1.5.0 or later, this code + * just keeps the room warm. + */ + abs = abs_info; + while (abs && abs->value != -1) { + if (abs->resolution != 0) { + if (libevdev_get_abs_resolution(dev, abs->value) == + abs->resolution) + break; + + rc = libevdev_kernel_set_abs_info(dev, + abs->value, + abs); + litest_assert_int_eq(rc, 0); + } + abs++; + } + close(fd); + 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_pointer_axis axis, + enum libinput_pointer_axis_source source) +{ + struct libinput_event_pointer *ptrev; + enum libinput_event_type type = LIBINPUT_EVENT_POINTER_AXIS; + + litest_assert_ptr_notnull(event); + litest_assert_event_type(event, type); + ptrev = libinput_event_get_pointer_event(event); + litest_assert(libinput_event_pointer_has_axis(ptrev, axis)); + + if (source != 0) + litest_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev), + source); + + return ptrev; +} + +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) +{ + 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) +{ + struct libinput_event *event; + + 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: + ck_abort_msg("%s: invalid touch type %d\n", __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; +} + +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) +{ + 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); +} + +void litest_assert_tablet_proximity_event(struct libinput *li, + enum libinput_tablet_tool_proximity_state state) +{ + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY; + + 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_proximity_state(tev), + state); + libinput_event_destroy(event); +} + +void litest_assert_tablet_tip_event(struct libinput *li, + enum libinput_tablet_tool_tip_state state) +{ + 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_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_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_pad_button_event(struct libinput *li, + unsigned int button, + enum libinput_button_state state) +{ + struct libinput_event *event; + struct libinput_event_tablet_pad *pev; + + litest_wait_for_event(li); + event = libinput_get_event(li); + + pev = litest_is_pad_button_event(event, button, state); + libinput_event_destroy(libinput_event_tablet_pad_get_base_event(pev)); +} + +void +litest_assert_scroll(struct libinput *li, + enum libinput_pointer_axis axis, + int minimum_movement) +{ + struct libinput_event *event, *next_event; + struct libinput_event_pointer *ptrev; + int value; + int nevents = 0; + + event = libinput_get_event(li); + next_event = libinput_get_event(li); + litest_assert_ptr_notnull(next_event); /* At least 1 scroll + stop scroll */ + + while (event) { + ptrev = litest_is_axis_event(event, axis, 0); + nevents++; + + if (next_event) { + int min = minimum_movement; + + value = libinput_event_pointer_get_axis_value(ptrev, + axis); + /* 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; + + /* Normal scroll event, check dir */ + if (minimum_movement > 0) + litest_assert_int_ge(value, min); + else + litest_assert_int_le(value, min); + } else { + /* Last scroll event, must be 0 */ + ck_assert_double_eq( + libinput_event_pointer_get_axis_value(ptrev, axis), + 0.0); + } + libinput_event_destroy(event); + event = next_event; + next_event = libinput_get_event(li); + } +} + +void +litest_assert_only_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); + litest_assert_notnull(event); + + while (event) { + litest_assert_int_eq(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(200); +} + +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(120); +} + +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_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_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_FILTER_TEST, + OPT_FILTER_DEVICE, + OPT_FILTER_GROUP, + OPT_FILTER_DEVICELESS, + 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-deviceless", 0, 0, OPT_FILTER_DEVICELESS }, + { "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:", opts, &option_index); + if (c == -1) + break; + switch(c) { + default: + case 'h': + printf("Usage: %s [--verbose] [--jobs] [--filter-...]\n" + "\n" + "Options:\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-deviceless=.... \n" + " Glob to filter on tests that do not create test devices\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_GROUP: + filter_group = optarg; + 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_FILTER_DEVICELESS: + run_deviceless = 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 = NULL; + + list_for_each(s, tests, node) { + struct test *t; + printf("%s:\n", s->name); + list_for_each(t, &s->tests, node) { + if (!last_test_name || + !streq(last_test_name, t->name)) + printf(" %s:\n", t->name); + + last_test_name = t->name; + + printf(" %s\n", t->devname); + } + } +} + +extern const struct test_device __start_test_section, __stop_test_section; + +static void +litest_init_test_devices(void) +{ + const struct test_device *t; + + list_init(&devices); + + for (t = &__start_test_section; t < &__stop_test_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++) { + c->setup(); + } +} + +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 int +disable_tty(void) +{ + int tty_mode = -1; + + /* 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 && + getenv("CK_FORK") == NULL && + 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; +} + +int +main(int argc, char **argv) +{ + const struct rlimit corelimit = { 0, 0 }; + enum litest_mode mode; + int tty_mode = -1; + int failed_tests; + int rc; + + in_debugger = is_debugger_attached(); + if (in_debugger || RUNNING_ON_VALGRIND) + setenv("CK_FORK", "no", 0); + + mode = litest_parse_argv(argc, argv); + if (mode == LITEST_MODE_ERROR) + return EXIT_FAILURE; + + if (!run_deviceless && (rc = check_device_access()) != 0) + return rc; + + litest_init_test_devices(); + + list_init(&all_tests); + + setenv("CK_DEFAULT_TIMEOUT", "30", 0); + setenv("LIBINPUT_RUNNING_TEST_SUITE", "1", 1); + + setup_tests(); + + if (mode == LITEST_MODE_LIST) { + litest_list_tests(&all_tests); + return EXIT_SUCCESS; + } + + if (setrlimit(RLIMIT_CORE, &corelimit) != 0) + perror("WARNING: Core dumps not disabled"); + + tty_mode = disable_tty(); + + failed_tests = litest_run(argc, argv); + + 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 + } + + return min(failed_tests, 255); +} +#endif diff --git a/test/litest.h b/test/litest.h new file mode 100644 index 0000000..85a0a1f --- /dev/null +++ b/test/litest.h @@ -0,0 +1,1136 @@ +/* + * 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 + +#include "check-double-macros.h" + +#include "libinput-util.h" +#include "quirks.h" + +struct test_device { + const char *name; + struct litest_test_device *device; +} __attribute__((aligned(16))); + +#define TEST_DEVICE(name, ...) \ + 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_section"))) = { \ + name, &_device \ + }; \ + static struct litest_test_device _device = { \ + .setup = _setup, \ + .shortname = name, \ + __VA_ARGS__ \ + }; + +struct test_collection { + const char *name; + void (*setup)(void); +} __attribute__((aligned(16))); + +#define TEST_COLLECTION(name) \ + static void (name##_setup)(void); \ + static const struct test_collection _test_collection \ + __attribute__ ((used)) \ + __attribute__ ((section ("test_collection_section"))) = { \ + #name, name##_setup \ + }; \ + static void (name##_setup)(void) + +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); + +#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__); \ + +#define litest_assert_notnull(cond) \ + do { \ + if ((cond) == NULL) \ + litest_fail_condition(__FILE__, __LINE__, __func__, \ + #cond, " expected to be not 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_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_comparison_double_(a_, op_, b_) \ + do { \ + const double EPSILON = 1.0/256; \ + __typeof__(a_) _a = a_; \ + __typeof__(b_) _b = b_; \ + if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON) \ + litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ + #op_, _a, _b, \ + #a_, #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_double_eq(a_, b_)\ + litest_assert_comparison_double_((a_), ==, (b_)) + +#define litest_assert_double_ne(a_, b_)\ + litest_assert_comparison_double_((a_), !=, (b_)) + +#define litest_assert_double_lt(a_, b_)\ + litest_assert_comparison_double_((a_), <, (b_)) + +#define litest_assert_double_le(a_, b_)\ + litest_assert_comparison_double_((a_), <=, (b_)) + +#define litest_assert_double_gt(a_, b_)\ + litest_assert_comparison_double_((a_), >, (b_)) + +#define litest_assert_double_ge(a_, b_)\ + litest_assert_comparison_double_((a_), >=, (b_)) + +enum litest_device_type { + LITEST_NO_DEVICE = -1, + LITEST_SYNAPTICS_CLICKPAD_X220 = -1000, + LITEST_SYNAPTICS_TOUCHPAD, + LITEST_SYNAPTICS_TOPBUTTONPAD, + LITEST_BCM5974, + LITEST_KEYBOARD, + LITEST_TRACKPOINT, + LITEST_MOUSE, + LITEST_WACOM_TOUCH, + LITEST_ALPS_SEMI_MT, + LITEST_GENERIC_SINGLETOUCH, + LITEST_MS_SURFACE_COVER, + LITEST_QEMU_TABLET, + LITEST_XEN_VIRTUAL_POINTER, + LITEST_VMWARE_VIRTMOUSE, + LITEST_SYNAPTICS_HOVER_SEMI_MT, + LITEST_SYNAPTICS_TRACKPOINT_BUTTONS, + LITEST_PROTOCOL_A_SCREEN, + LITEST_WACOM_FINGER, + LITEST_KEYBOARD_BLACKWIDOW, + LITEST_WHEEL_ONLY, + LITEST_MOUSE_ROCCAT, + LITEST_LOGITECH_TRACKBALL, + LITEST_ATMEL_HOVER, + LITEST_ALPS_DUALPOINT, + LITEST_MOUSE_LOW_DPI, + LITEST_GENERIC_MULTITOUCH_SCREEN, + LITEST_NEXUS4_TOUCH_SCREEN, + LITEST_MAGIC_TRACKPAD, + LITEST_ELANTECH_TOUCHPAD, + LITEST_MOUSE_GLADIUS, + LITEST_MOUSE_WHEEL_CLICK_ANGLE, + LITEST_APPLE_KEYBOARD, + LITEST_ANKER_MOUSE_KBD, + LITEST_WACOM_BAMBOO, + LITEST_WACOM_CINTIQ, + LITEST_WACOM_INTUOS, + LITEST_WACOM_ISDV4, + LITEST_WALTOP, + LITEST_HUION_TABLET, + LITEST_CYBORG_RAT, + LITEST_YUBIKEY, + LITEST_SYNAPTICS_I2C, + LITEST_WACOM_CINTIQ_24HD, + LITEST_MULTITOUCH_FUZZ_SCREEN, + LITEST_WACOM_INTUOS3_PAD, + LITEST_WACOM_INTUOS5_PAD, + LITEST_KEYBOARD_ALL_CODES, + LITEST_MAGICMOUSE, + LITEST_WACOM_EKR, + LITEST_WACOM_CINTIQ_24HDT_PAD, + LITEST_WACOM_CINTIQ_13HDT_PEN, + LITEST_WACOM_CINTIQ_13HDT_PAD, + LITEST_WACOM_CINTIQ_13HDT_FINGER, + LITEST_WACOM_CINTIQ_PRO16_PAD, + LITEST_WACOM_CINTIQ_PRO16_PEN, + LITEST_WACOM_CINTIQ_PRO16_FINGER, + LITEST_WACOM_HID4800_PEN, + LITEST_MOUSE_WHEEL_CLICK_COUNT, + LITEST_CALIBRATED_TOUCHSCREEN, + LITEST_ACER_HAWAII_KEYBOARD, + LITEST_ACER_HAWAII_TOUCHPAD, + LITEST_SYNAPTICS_RMI4, + LITEST_MOUSE_WHEEL_TILT, + LITEST_LID_SWITCH, + LITEST_LID_SWITCH_SURFACE3, + LITEST_APPLETOUCH, + LITEST_GPIO_KEYS, + LITEST_IGNORED_MOUSE, + LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD, + LITEST_THINKPAD_EXTRABUTTONS, + LITEST_UCLOGIC_TABLET, + LITEST_KEYBOARD_BLADE_STEALTH, + LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH, + LITEST_WACOM_BAMBOO_2FG_PAD, + LITEST_WACOM_BAMBOO_2FG_PEN, + LITEST_WACOM_BAMBOO_2FG_FINGER, + LITEST_HP_WMI_HOTKEYS, + LITEST_MS_NANO_TRANSCEIVER_MOUSE, + LITEST_AIPTEK, + LITEST_TOUCHSCREEN_INVALID_RANGE, + LITEST_TOUCHSCREEN_MT_TOOL_TYPE, + LITEST_DELL_CANVAS_TOTEM, + LITEST_DELL_CANVAS_TOTEM_TOUCH, + LITEST_WACOM_ISDV4_4200_PEN, +}; + +#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) + +/* 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); +} + +/* A loop range, resolves to: + for (i = lower; i < upper; i++) + */ +struct range { + int lower; /* inclusive */ + int upper; /* exclusive */ +}; + +struct libinput *litest_create_context(void); +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); + +#define litest_add(name_, func_, ...) \ + _litest_add(name_, #func_, func_, __VA_ARGS__) +#define litest_add_ranged(name_, func_, ...) \ + _litest_add_ranged(name_, #func_, func_, __VA_ARGS__) +#define litest_add_for_device(name_, func_, ...) \ + _litest_add_for_device(name_, #func_, func_, __VA_ARGS__) +#define litest_add_ranged_for_device(name_, func_, ...) \ + _litest_add_ranged_for_device(name_, #func_, func_, __VA_ARGS__) +#define litest_add_no_device(name_, func_) \ + _litest_add_no_device(name_, #func_, func_) +#define litest_add_ranged_no_device(name_, func_, ...) \ + _litest_add_ranged_no_device(name_, #func_, func_, __VA_ARGS__) +#define litest_add_deviceless(name_, func_) \ + _litest_add_deviceless(name_, #func_, func_) + +void +_litest_add(const char *name, + const char *funcname, + void *func, + int64_t required_feature, + int64_t excluded_feature); +void +_litest_add_ranged(const char *name, + const char *funcname, + void *func, + int64_t required, + int64_t excluded, + const struct range *range); +void +_litest_add_for_device(const char *name, + const char *funcname, + void *func, + enum litest_device_type type); +void +_litest_add_ranged_for_device(const char *name, + const char *funcname, + void *func, + enum litest_device_type type, + const struct range *range); +void +_litest_add_no_device(const char *name, + const char *funcname, + void *func); +void +_litest_add_ranged_no_device(const char *name, + const char *funcname, + void *func, + const struct range *range); +void +_litest_add_deviceless(const char *name, + const char *funcname, + void *func); + +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_delete_device(struct litest_device *d); + +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_proximity_in(struct litest_device *d, + int x, int y, + struct axis_replacement *axes); + +void +litest_tablet_proximity_out(struct litest_device *d); + +void +litest_tablet_motion(struct litest_device *d, + int x, int 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_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, ...); + +void +litest_drain_events(struct libinput *li); + +void +litest_drain_events_of_type(struct libinput *li, ...); + +void +litest_assert_event_type(struct libinput_event *event, + enum libinput_event_type want); + +void +litest_assert_empty_queue(struct libinput *li); + +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_pointer_axis axis, + enum libinput_pointer_axis_source source); + +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_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_switch * +litest_is_switch_event(struct libinput_event *event, + enum libinput_switch sw, + enum libinput_switch_state state); + +void +litest_assert_key_event(struct libinput *li, unsigned int key, + enum libinput_key_state state); + +void +litest_assert_button_event(struct libinput *li, + unsigned int button, + enum libinput_button_state state); + +void +litest_assert_scroll(struct libinput *li, + enum libinput_pointer_axis axis, + int minimum_movement); + +void +litest_assert_only_typed_events(struct libinput *li, + enum libinput_event_type type); + +void +litest_assert_tablet_button_event(struct libinput *li, + unsigned int button, + enum libinput_button_state state); + +void +litest_assert_tablet_proximity_event(struct libinput *li, + enum libinput_tablet_tool_proximity_state state); + +void +litest_assert_tablet_tip_event(struct libinput *li, + enum libinput_tablet_tool_tip_state state); + +void +litest_assert_pad_button_event(struct libinput *li, + unsigned int button, + enum libinput_button_state state); +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_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_trackpoint(void); + +void +litest_timeout_tablet_proxout(void); + +void +litest_timeout_touch_arbitration(void); + +void +litest_timeout_hysteresis(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); + +#ifndef ck_assert_notnull +#define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL) +#endif + +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); +} + +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); +} + +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_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(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); + + 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 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); +} + +#endif /* LITEST_H */ diff --git a/test/symbols-leak-test b/test/symbols-leak-test new file mode 100755 index 0000000..7b612f4 --- /dev/null +++ b/test/symbols-leak-test @@ -0,0 +1,18 @@ +#!/bin/bash -e +# +# simple check for exported symbols +# +# Usage: symbols-leak-test /path/to/mapfile /path/to/libinput/src + +mapfile="$1" +shift +srcdir="$1" +shift + +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) diff --git a/test/test-builddir-lookup.c b/test/test-builddir-lookup.c new file mode 100644 index 0000000..348daaa --- /dev/null +++ b/test/test-builddir-lookup.c @@ -0,0 +1,56 @@ +/* + * 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; +} diff --git a/test/test-device.c b/test/test-device.c new file mode 100644 index 0000000..3f79201 --- /dev/null +++ b/test/test-device.c @@ -0,0 +1,1642 @@ +/* + * 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" + +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); + ck_assert_int_eq(modes, + 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 | (1 << 4)); + ck_assert_int_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); + ck_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; + + 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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_eq(mode, + LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); + + mode = libinput_device_config_send_events_get_default_mode(device); + ck_assert_int_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); + ck_assert_int_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); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + litest_assert_empty_queue(li); + + /* event from renabled device */ + litest_event(dev, EV_REL, REL_X, 10); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_notnull(event); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_MOTION); + libinput_event_destroy(event); + + litest_delete_device(tmp); +} +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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + /* after disabling sendevents we require a touch up */ + libinput_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); + ck_assert_int_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); + } + libinput_dispatch(li); + + status = libinput_device_config_send_events_set_mode(device, + LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + /* expect above events */ + litest_wait_for_event(li); + while ((event = libinput_get_event(li)) != NULL) { + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_send_events_set_mode(device, + LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_send_events_set_mode(device, + LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + ck_assert(libinput_event_get_device(event) != device1); + libinput_event_destroy(event); + } + + litest_delete_device(litest_device); + libinput_device_unref(device1); + libinput_unref(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); + ck_assert_int_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); + ck_assert_int_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); + libinput_unref(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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_wait_for_event(li); + event = libinput_get_event(li); + + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_BUTTON); + ptrevent = libinput_event_get_pointer_event(event); + ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent), + BTN_LEFT); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_wait_for_event(li); + event = libinput_get_event(li); + + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_KEYBOARD_KEY); + kbdevent = libinput_event_get_keyboard_event(event); + ck_assert_int_eq(libinput_event_keyboard_get_key(kbdevent), + KEY_A); + ck_assert_int_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); + + libinput_dispatch(li); + + status = libinput_device_config_send_events_set_mode(device, + LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + status = libinput_device_config_send_events_set_mode(device, + LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + libinput_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); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + libinput_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); + ck_assert_int_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); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_BUTTON); + ck_assert_ptr_eq(libinput_event_get_device(event), + trackpoint->libinput_device); + ptrevent = libinput_event_get_pointer_event(event); + ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent), + BTN_RIGHT); + ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrevent), + LIBINPUT_BUTTON_STATE_PRESSED); + libinput_event_destroy(event); + + event = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_BUTTON); + ck_assert_ptr_eq(libinput_event_get_device(event), + trackpoint->libinput_device); + ptrevent = libinput_event_get_pointer_event(event); + ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent), + BTN_RIGHT); + ck_assert_int_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 pid, vid; + + name = libevdev_get_name(dev->evdev); + pid = libevdev_get_id_product(dev->evdev); + vid = libevdev_get_id_vendor(dev->evdev); + + ck_assert_str_eq(name, + libinput_device_get_name(dev->libinput_device)); + ck_assert_int_eq(pid, + libinput_device_get_id_product(dev->libinput_device)); + ck_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); + ck_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; + + ck_assert(dev->libinput == libinput_device_get_context(dev->libinput_device)); + seat = libinput_device_get_seat(dev->libinput_device); + ck_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 */ + + ck_assert(libinput_device_get_user_data(device) == NULL); + libinput_device_set_user_data(device, userdata); + ck_assert_ptr_eq(libinput_device_get_user_data(device), userdata); + libinput_device_set_user_data(device, NULL); + ck_assert(libinput_device_get_user_data(device) == NULL); +} +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); +} + +const struct libinput_interface simple_interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +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); + ck_assert_notnull(group); + + libinput_device_group_ref(group); + + libinput_device_group_set_user_data(group, &userdata); + ck_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); + ck_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 */ + ck_assert(libinput_device_unref(device) == NULL); + + libinput_device_group_ref(group); + ck_assert_notnull(libinput_device_group_unref(group)); + ck_assert(libinput_device_group_unref(group) == NULL); + + libinput_unref(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 = libinput_path_create_context(&simple_interface, NULL); + 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); + libinput_unref(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); + ck_assert(device == NULL); + libinput_unref(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); + ck_assert(device == NULL); + libinput_unref(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); + ck_assert(device == NULL); + libinput_unref(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); + ck_assert(device == NULL); + libinput_unref(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); + libinput_unref(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); + libinput_unref(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); + libinput_unref(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); + libinput_unref(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); + libinput_unref(li); +} +END_TEST + +START_TEST(device_wheel_only) +{ + struct litest_device *dev = litest_current_device(); + struct libinput_device *device = dev->libinput_device; + + ck_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); + libinput_unref(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"); + + ck_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)); + ck_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); + libinput_dispatch(li); + } + litest_restore_log_handler(li); + + libinput_unref(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)); + ck_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); + libinput_dispatch(li); + } + + libinput_unref(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)); + ck_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); + libinput_dispatch(li); + } + litest_restore_log_handler(li); + + libinput_unref(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)); + ck_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); + libinput_dispatch(li); + } + + libinput_unref(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; + int code; + + litest_drain_events(li); + + litest_event(dev, EV_REL, REL_HWHEEL, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + pev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); + libinput_event_destroy(libinput_event_pointer_get_base_event(pev)); + + 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; + + ck_assert(!libinput_device_pointer_has_button(device, 0x118)); + ck_assert(!libinput_device_pointer_has_button(device, 0x119)); + ck_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); + + ck_assert(!libinput_device_pointer_has_button(dev->libinput_device, + BTN_MIDDLE)); +} +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, + }; + enum libinput_device_capability *cap; + int ncaps = 0; + + ARRAY_FOR_EACH(caps, cap) { + if (libinput_device_has_capability(device, *cap)) + ncaps++; + } + ck_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; + + ck_assert(!libinput_device_has_capability(device, -1)); + ck_assert(!libinput_device_has_capability(device, 7)); + ck_assert(!libinput_device_has_capability(device, 0xffff)); + +} +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); + ck_assert_int_eq(rc, 0); + /* This matches the current set of test devices but may fail if + * newer ones are added */ + ck_assert_double_gt(w, 40); + ck_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); + ck_assert_int_eq(rc, -1); + ck_assert_double_eq(w, 45); + ck_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); + ck_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); + ck_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); + ck_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 || + !strneq(keyname, "BTN_", 4) || + strneq(keyname, "BTN_TOOL_", 9)) + 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); + libinput_dispatch(li); + } + + litest_event(dev, EV_KEY, code, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + litest_delete_device(dev); + libinput_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)) { + ck_assert(button_down == 0); + button_down = libinput_event_pointer_get_button(p); + } else { + ck_assert(button_up == 0); + button_up = libinput_event_pointer_get_button(p); + ck_assert_int_eq(button_down, button_up); + } + libinput_event_destroy(event); + } + + libinput_unref(li); + ck_assert_int_eq(have_down, have_up); + } +} +END_TEST + +TEST_COLLECTION(device) +{ + struct range abs_range = { 0, ABS_MISC }; + struct range abs_mt_range = { ABS_MT_SLOT + 1, ABS_CNT }; + + litest_add("device:sendevents", device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET); + litest_add("device:sendevents", device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET); + litest_add("device:sendevents", device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); + litest_add("device:sendevents", device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET); + litest_add("device:sendevents", device_sendevents_config_default, LITEST_ANY, LITEST_TABLET); + litest_add("device:sendevents", device_disable, LITEST_RELATIVE, LITEST_TABLET); + litest_add("device:sendevents", device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); + litest_add("device:sendevents", device_disable_touch, LITEST_TOUCH, LITEST_ANY); + litest_add("device:sendevents", device_disable_touch_during_touch, LITEST_TOUCH, LITEST_ANY); + litest_add("device:sendevents", device_disable_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add("device:sendevents", device_disable_touch_during_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add("device:sendevents", device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET); + litest_add("device:sendevents", device_double_disable, LITEST_ANY, LITEST_TABLET); + litest_add("device:sendevents", device_double_enable, LITEST_ANY, LITEST_TABLET); + litest_add_no_device("device:sendevents", device_reenable_syspath_changed); + litest_add_no_device("device:sendevents", device_reenable_device_removed); + litest_add_for_device("device:sendevents", device_disable_release_buttons, LITEST_MOUSE); + litest_add_for_device("device:sendevents", device_disable_release_keys, LITEST_KEYBOARD); + litest_add("device:sendevents", device_disable_release_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("device:sendevents", device_disable_release_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("device:sendevents", device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("device:sendevents", device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("device:id", device_ids, LITEST_ANY, LITEST_ANY); + litest_add_for_device("device:context", device_context, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("device:context", device_user_data, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add("device:udev", device_get_udev_handle, LITEST_ANY, LITEST_ANY); + + litest_add("device:group", device_group_get, LITEST_ANY, LITEST_ANY); + litest_add_no_device("device:group", device_group_ref); + litest_add_no_device("device:group", device_group_leak); + + litest_add_no_device("device:invalid devices", abs_device_no_absx); + litest_add_no_device("device:invalid devices", abs_device_no_absy); + litest_add_no_device("device:invalid devices", abs_mt_device_no_absx); + litest_add_no_device("device:invalid devices", abs_mt_device_no_absy); + litest_add_ranged_no_device("device:invalid devices", abs_device_no_range, &abs_range); + litest_add_ranged_no_device("device:invalid devices", abs_mt_device_no_range, &abs_mt_range); + litest_add_no_device("device:invalid devices", abs_device_missing_res); + litest_add_no_device("device:invalid devices", abs_mt_device_missing_res); + litest_add_no_device("device:invalid devices", ignore_joystick); + + litest_add("device:wheel", device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET); + litest_add_no_device("device:accelerometer", device_accelerometer); + + litest_add("device:udev tags", device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_TOTEM); + + litest_add_no_device("device:invalid rel events", device_nonpointer_rel); + litest_add_no_device("device:invalid rel events", device_touchpad_rel); + litest_add_no_device("device:invalid rel events", device_touch_rel); + litest_add_no_device("device:invalid rel events", device_abs_rel); + + litest_add_for_device("device:quirks", device_quirks_no_abs_mt_y, LITEST_ANKER_MOUSE_KBD); + litest_add_for_device("device:quirks", device_quirks_cyborg_rat_mode_button, LITEST_CYBORG_RAT); + litest_add_for_device("device:quirks", device_quirks_apple_magicmouse, LITEST_MAGICMOUSE); + litest_add_for_device("device:quirks", device_quirks_logitech_marble_mouse, LITEST_LOGITECH_TRACKBALL); + + litest_add("device:capability", device_capability_at_least_one, LITEST_ANY, LITEST_ANY); + litest_add("device:capability", device_capability_check_invalid, LITEST_ANY, LITEST_ANY); + + litest_add("device:size", device_has_size, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("device:size", device_has_size, LITEST_TABLET, LITEST_ANY); + litest_add("device:size", device_has_no_size, LITEST_ANY, + LITEST_TOUCHPAD|LITEST_TABLET|LITEST_TOUCH|LITEST_ABSOLUTE|LITEST_SINGLE_TOUCH|LITEST_TOTEM); + + litest_add_for_device("device:output", device_get_output, LITEST_CALIBRATED_TOUCHSCREEN); + litest_add("device:output", device_no_output, LITEST_RELATIVE, LITEST_ANY); + litest_add("device:output", device_no_output, LITEST_KEYS, LITEST_ANY); + + litest_add("device:seat", device_seat_phys_name, LITEST_ANY, LITEST_ANY); + + litest_add("device:button", device_button_down_remove, LITEST_BUTTON, LITEST_ANY); +} diff --git a/test/test-gestures.c b/test/test-gestures.c new file mode 100644 index 0000000..ff1df2b --- /dev/null +++ b/test/test-gestures.c @@ -0,0 +1,1088 @@ +/* + * 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 +}; + +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)) + ck_assert(!libinput_device_has_capability(device, + LIBINPUT_DEVICE_CAP_GESTURE)); + else + ck_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; + + ck_assert(!libinput_device_has_capability(device, + LIBINPUT_DEVICE_CAP_GESTURE)); +} +END_TEST + +START_TEST(gestures_swipe_3fg) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, dir_x, + dir_y, 10); + libinput_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); + ck_assert(dx == 0.0); + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_assert(dy > 0.0); + + libinput_event_destroy(event); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + litest_touch_up(dev, 2); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + 3); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +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; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) || + !libinput_device_has_capability(dev->libinput_device, + LIBINPUT_DEVICE_CAP_GESTURE)) + 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_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); + + libinput_dispatch(li); + litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10); + libinput_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); + ck_assert(dx == 0.0); + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_assert(dy > 0.0); + + libinput_event_destroy(event); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + 3); + ck_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 (libevdev_get_num_slots(dev->evdev) > 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_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); + + libinput_dispatch(li); + litest_touch_move_to(dev, 0, 20, 60, 10, 80, 20); + libinput_dispatch(li); + + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, + 3); + libinput_event_destroy(event); + + while ((event = libinput_get_event(li)) != NULL) { + gevent = 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); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + 3); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(gestures_swipe_4fg) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + + 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); + libinput_dispatch(li); + } + + libinput_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); + ck_assert(dx == 0.0); + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_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); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + 4); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +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; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP) || + !libinput_device_has_capability(dev->libinput_device, + LIBINPUT_DEVICE_CAP_GESTURE)) + 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_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); + + libinput_dispatch(li); + litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10); + libinput_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); + ck_assert(dx == 0.0); + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_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) + ck_assert(dx == 0.0); + else if (dir_x < 0.0) + ck_assert(dx < 0.0); + else if (dir_x > 0.0) + ck_assert(dx > 0.0); + + if (dir_y == 0.0) + ck_assert(dy == 0.0); + else if (dir_y < 0.0) + ck_assert(dy < 0.0); + else if (dir_y > 0.0) + ck_assert(dy > 0.0); + + libinput_event_destroy(event); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_SWIPE_END, + 4); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(gestures_pinch) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + + 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); + libinput_dispatch(li); + } + + 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); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + ck_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); + + ck_assert(scale < oldscale); + + angle = libinput_event_gesture_get_angle_delta(gevent); + ck_assert_double_le(fabs(angle), 1.0); + + libinput_event_destroy(event); + libinput_dispatch(li); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_PINCH_END, + 2); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(gestures_pinch_3fg) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + + 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); + libinput_dispatch(li); + } + + 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); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + ck_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); + + ck_assert(scale < oldscale); + + angle = libinput_event_gesture_get_angle_delta(gevent); + ck_assert_double_le(fabs(angle), 1.0); + + libinput_event_destroy(event); + libinput_dispatch(li); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + litest_touch_up(dev, 2); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_PINCH_END, + 3); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(gestures_pinch_4fg) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + + 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); + libinput_dispatch(li); + } + + 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); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + ck_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); + + ck_assert(scale < oldscale); + + angle = libinput_event_gesture_get_angle_delta(gevent); + ck_assert_double_le(fabs(angle), 1.0); + + libinput_event_destroy(event); + libinput_dispatch(li); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + litest_touch_up(dev, 2); + litest_touch_up(dev, 3); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_PINCH_END, + 4); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(gestures_spread) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_gesture *gevent; + double dx, dy; + int cardinal = _i; /* ranged test */ + 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 (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + + 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); + libinput_dispatch(li); + } + + 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); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + ck_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); + ck_assert(scale > oldscale); + + angle = libinput_event_gesture_get_angle_delta(gevent); + ck_assert_double_le(fabs(angle), 1.0); + + libinput_event_destroy(event); + libinput_dispatch(li); + } + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(li); + event = libinput_get_event(li); + gevent = litest_is_gesture_event(event, + LIBINPUT_EVENT_GESTURE_PINCH_END, + 2); + ck_assert(!libinput_event_gesture_get_cancelled(gevent)); + libinput_event_destroy(event); +} +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 (libevdev_get_num_slots(dev->evdev) < 3) + return; + + 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); + libinput_dispatch(li); + litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, 0, 30, + 30); + + libinput_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); + ck_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) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_num_slots(dev->evdev) < 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); + libinput_dispatch(li); + litest_touch_move_two_touches(dev, 40, 20, 30, 20, 0, 40, 10); + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(li); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); +} +END_TEST + +START_TEST(gestures_3fg_buttonarea_scroll_btntool) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_num_slots(dev->evdev) > 2) + return; + + 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); + libinput_dispatch(li); + litest_touch_move_to(dev, 1, 30, 20, 30, 70, 10); + + litest_touch_up(dev, 1); + libinput_dispatch(li); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 4); +} +END_TEST + +TEST_COLLECTION(gestures) +{ + struct range cardinals = { N, N + NCARDINALS }; + + litest_add("gestures:cap", gestures_cap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("gestures:cap", gestures_nocap, LITEST_ANY, LITEST_TOUCHPAD); + + litest_add_ranged("gestures:swipe", gestures_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:swipe", gestures_swipe_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add("gestures:swipe", gestures_swipe_3fg_btntool_pinch_like, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add_ranged("gestures:swipe", gestures_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:swipe", gestures_swipe_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:pinch", gestures_pinch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:pinch", gestures_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:pinch", gestures_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + litest_add_ranged("gestures:pinch", gestures_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals); + + litest_add("gestures:swipe", gestures_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); + litest_add("gestures:swipe", gestures_3fg_buttonarea_scroll_btntool, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); + + litest_add("gestures:time", gestures_time_usec, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); +} diff --git a/test/test-keyboard.c b/test/test-keyboard.c new file mode 100644 index 0000000..f5b566d --- /dev/null +++ b/test/test-keyboard.c @@ -0,0 +1,494 @@ +/* + * 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 + +#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); + + libinput_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); + ck_assert_int_eq(expected_key_button_count, seat_key_count); + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } + + ck_assert_int_eq(seat_key_count, num_devices); + + for (i = 0; i < num_devices; ++i) + litest_keyboard_key(devices[i], KEY_A, false); + + libinput_dispatch(libinput); + while ((ev = libinput_get_event(libinput))) { + kev = libinput_event_get_keyboard_event(ev); + ck_assert_notnull(kev); + ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A); + ck_assert_int_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); + ck_assert_int_eq(expected_key_button_count, seat_key_count); + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } + + ck_assert_int_eq(seat_key_count, 0); + + for (i = 0; i < num_devices; ++i) + litest_delete_device(devices[i]); + libinput_unref(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 *state; + 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); + + libinput_dispatch(libinput); + + ARRAY_FOR_EACH(expected_states, state) { + event = libinput_get_event(libinput); + ck_assert_notnull(event); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_KEYBOARD_KEY); + kevent = libinput_event_get_keyboard_event(event); + ck_assert_int_eq(libinput_event_keyboard_get_key(kevent), + KEY_A); + ck_assert_int_eq(libinput_event_keyboard_get_key_state(kevent), + *state); + libinput_event_destroy(event); + libinput_dispatch(libinput); + } + + litest_assert_empty_queue(libinput); + litest_delete_device(dev); + libinput_unref(libinput); + libinput_unref(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); + + libinput_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); + ck_assert_notnull(event); + type = libinput_event_get_type(event); + + if (type == LIBINPUT_EVENT_DEVICE_REMOVED) { + libinput_event_destroy(event); + break; + } + + ck_assert_int_eq(type, LIBINPUT_EVENT_KEYBOARD_KEY); + kevent = libinput_event_get_keyboard_event(event); + ck_assert_int_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) { + ck_assert_int_eq(keys[i].released, 0); + keys[i].released = 1; + valid_code = 1; + } + } + ck_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) { + ck_assert_int_eq(keys[i].released, 1); + } + + libinput_unref(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; + + ck_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); + ck_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; + + for (code = 0; code < KEY_CNT; code++) { + has_key = libinput_device_keyboard_has_key(device, code); + ck_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_drain_events(dev->libinput); + + litest_keyboard_key(dev, KEY_A, true); + libinput_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); + ck_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 (!name || !strneq(name, "KEY_", 4)) + continue; + + litest_keyboard_key(dev, code, true); + litest_keyboard_key(dev, code, false); + libinput_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_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); + libinput_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); + libinput_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); + libinput_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); + libinput_dispatch(li); + + litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); + litest_assert_key_event(li, + KEY_LEFTSHIFT, + LIBINPUT_KEY_STATE_RELEASED); + + libinput_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_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, 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); + ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); + method = libinput_device_config_scroll_get_default_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_2FG); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_EDGE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_NO_SCROLL); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); +} +END_TEST + +TEST_COLLECTION(keyboard) +{ + litest_add_no_device("keyboard:seat key count", keyboard_seat_key_count); + litest_add_no_device("keyboard:key counting", keyboard_ignore_no_pressed_release); + litest_add_no_device("keyboard:key counting", keyboard_key_auto_release); + litest_add("keyboard:keys", keyboard_has_key, LITEST_KEYS, LITEST_ANY); + litest_add("keyboard:keys", keyboard_keys_bad_device, LITEST_ANY, LITEST_ANY); + litest_add("keyboard:time", keyboard_time_usec, LITEST_KEYS, LITEST_ANY); + + litest_add("keyboard:events", keyboard_no_buttons, LITEST_KEYS, LITEST_ANY); + litest_add("keyboard:events", keyboard_frame_order, LITEST_KEYS, LITEST_ANY); + + litest_add("keyboard:leds", keyboard_leds, LITEST_ANY, LITEST_ANY); + + litest_add("keyboard:scroll", keyboard_no_scroll, LITEST_KEYS, LITEST_WHEEL); +} diff --git a/test/test-library-version.c b/test/test-library-version.c new file mode 100644 index 0000000..b9f700f --- /dev/null +++ b/test/test-library-version.c @@ -0,0 +1,23 @@ +#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; +} diff --git a/test/test-log.c b/test/test-log.c new file mode 100644 index 0000000..7b035d3 --- /dev/null +++ b/test/test-log.c @@ -0,0 +1,215 @@ +/* + * 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" + +static int log_handler_called; +static struct libinput *log_handler_context; + +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, +}; + +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); +} + +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); + + ck_assert_int_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 = libinput_path_create_context(&simple_interface, NULL); + + 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"); + + ck_assert_int_gt(log_handler_called, 0); + + libinput_unref(li); + + log_handler_context = NULL; + log_handler_called = 0; +} +END_TEST + +START_TEST(log_handler_NULL) +{ + struct libinput *li; + + log_handler_called = 0; + + li = libinput_path_create_context(&simple_interface, NULL); + libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); + libinput_log_set_handler(li, NULL); + + libinput_path_add_device(li, "/tmp"); + + ck_assert_int_eq(log_handler_called, 0); + + libinput_unref(li); + + log_handler_called = 0; +} +END_TEST + +START_TEST(log_priority) +{ + struct libinput *li; + + log_handler_context = NULL; + log_handler_called = 0; + + li = libinput_path_create_context(&simple_interface, NULL); + 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"); + + ck_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"); + ck_assert_int_gt(log_handler_called, 1); + + libinput_unref(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 = _i; /* looped test */ + + 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); + libinput_dispatch(li); + } + + /* Expect only one message per 5 min */ + ck_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) +{ + struct range axes = { ABS_X, ABS_Y + 1}; + + litest_add_deviceless("log:defaults", log_default_priority); + litest_add_deviceless("log:logging", log_handler_invoked); + litest_add_deviceless("log:logging", log_handler_NULL); + litest_add_no_device("log:logging", log_priority); + + /* mtdev clips to axis ranges */ + litest_add_ranged("log:warnings", log_axisrange_warning, LITEST_TOUCH, LITEST_PROTOCOL_A, &axes); + litest_add_ranged("log:warnings", log_axisrange_warning, LITEST_TOUCHPAD, LITEST_ANY, &axes); +} diff --git a/test/test-misc.c b/test/test-misc.c new file mode 100644 index 0000000..9aa3c9e --- /dev/null +++ b/test/test-misc.c @@ -0,0 +1,783 @@ +/* + * 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 "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_int_eq(rc, 0); + 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 = libinput_path_create_context(&simple_interface, NULL); + litest_restore_log_handler(li); /* use the default litest handler */ + libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); + + libinput_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); + ck_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); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + + libinput_event_destroy(event); + } + + libinput_unref(li); + libevdev_uinput_destroy(uinput); + + ck_assert_int_gt(device_added, 0); + ck_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); + + libinput_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); + ck_assert(event == base); + + if (type == LIBINPUT_EVENT_POINTER_MOTION) + motion++; + else if (type == LIBINPUT_EVENT_POINTER_BUTTON) + button++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_assert_int_gt(motion, 0); + ck_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); + + libinput_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); + ck_assert(event == base); + + if (type == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE) + motion++; + else if (type == LIBINPUT_EVENT_POINTER_BUTTON) + button++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_assert_int_gt(motion, 0); + ck_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); + + libinput_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); + ck_assert(event == base); + + key++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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; + + libinput_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); + + libinput_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); + ck_assert(event == base); + + touch++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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; + + libinput_dispatch(li); + + litest_touch_down(dev, 0, 70, 30); + litest_touch_down(dev, 1, 30, 70); + 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); + libinput_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_PINCH_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); + ck_assert(event == base); + + gestures++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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); + + libinput_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); + ck_assert(event == base); + + events++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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); + + libinput_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); + ck_assert(event == base); + + events++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_switch_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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); + libinput_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); + ck_assert(event == base); + + sw++; + + litest_disable_log_handler(li); + ck_assert(libinput_event_get_device_notify_event(event) == NULL); + ck_assert(libinput_event_get_keyboard_event(event) == NULL); + ck_assert(libinput_event_get_pointer_event(event) == NULL); + ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_gesture_event(event) == NULL); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); + ck_assert(libinput_event_get_tablet_pad_event(event) == NULL); + litest_restore_log_handler(li); + } + libinput_event_destroy(event); + } + + ck_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); + ck_assert_notnull(li); + ck_assert_ptr_eq(libinput_unref(li), NULL); + + li = libinput_path_create_context(&simple_interface, NULL); + ck_assert_notnull(li); + ck_assert_ptr_eq(libinput_ref(li), li); + ck_assert_ptr_eq(libinput_unref(li), li); + ck_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++) + ck_assert_str_ne(strs[i], strs[j]); + + invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_INVALID + 1); + ck_assert(invalid == NULL); + invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_SUCCESS - 1); + ck_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 */ +} + +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); + ck_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); + libinput_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); + libinput_dispatch(li); + + libinput_path_add_device(li, path); + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_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) +{ + int *warning_triggered = (int*)libinput_get_user_data(libinput); + + if (priority == LIBINPUT_LOG_PRIORITY_ERROR && + strstr(format, "offset negative")) + (*warning_triggered)++; +} + +START_TEST(timer_offset_bug_warning) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + int warning_triggered = 0; + + 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(); + + libinput_set_user_data(li, &warning_triggered); + libinput_log_set_handler(li, timer_offset_warning); + libinput_dispatch(li); + + /* triggered for touch down and touch up */ + ck_assert_int_eq(warning_triggered, 2); + 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); + libinput_dispatch(li); + keyboard = litest_add_device(li, LITEST_KEYBOARD); + libinput_dispatch(li); + litest_drain_events(li); + + /* make sure tapping works */ + litest_touch_down(touchpad, 0, 50, 50); + litest_touch_up(touchpad, 0); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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); + libinput_dispatch(li); + litest_touch_down(touchpad, 0, 50, 50); + litest_touch_up(touchpad, 0); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + /* Ingore '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 libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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); + libinput_unref(li); +} +END_TEST + +TEST_COLLECTION(misc) +{ + litest_add_no_device("events:conversion", event_conversion_device_notify); + litest_add_for_device("events:conversion", event_conversion_pointer, LITEST_MOUSE); + litest_add_for_device("events:conversion", event_conversion_pointer, LITEST_MOUSE); + litest_add_for_device("events:conversion", event_conversion_pointer_abs, LITEST_XEN_VIRTUAL_POINTER); + litest_add_for_device("events:conversion", event_conversion_key, LITEST_KEYBOARD); + litest_add_for_device("events:conversion", event_conversion_touch, LITEST_WACOM_TOUCH); + litest_add_for_device("events:conversion", event_conversion_gesture, LITEST_BCM5974); + litest_add_for_device("events:conversion", event_conversion_tablet, LITEST_WACOM_CINTIQ); + litest_add_for_device("events:conversion", event_conversion_tablet_pad, LITEST_WACOM_INTUOS5_PAD); + litest_add_for_device("events:conversion", event_conversion_switch, LITEST_LID_SWITCH); + + litest_add_deviceless("context:refcount", context_ref_counting); + litest_add_deviceless("config:status string", config_status_string); + + litest_add_for_device("timer:offset-warning", timer_offset_bug_warning, LITEST_SYNAPTICS_TOUCHPAD); + litest_add_no_device("timer:flush", timer_flush); + + litest_add_no_device("misc:fd", fd_no_event_leak); +} diff --git a/test/test-pad.c b/test/test-pad.c new file mode 100644 index 0000000..6ba8925 --- /dev/null +++ b/test/test-pad.c @@ -0,0 +1,953 @@ +/* + * 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 +#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; + + ck_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; + + ck_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); + libinput_dispatch(li); + + break; + } + + if (!has_buttons) + return; + + ev = libinput_get_event(li); + ck_assert_notnull(ev); + ck_assert_int_eq(libinput_event_get_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); + + ck_assert(time != 0); + ck_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); + libinput_dispatch(li); + + ev = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_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); + + ck_assert(time > oldtime); + ck_assert(time != 0); + ck_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(); + ck_assert_notnull(db); + + wacom = libwacom_new_from_usbid(db, + libevdev_get_id_vendor(dev->evdev), + libevdev_get_id_product(dev->evdev), + NULL); + ck_assert_notnull(wacom); + + nb_lw = libwacom_get_num_buttons(wacom); + nb = libinput_device_tablet_pad_get_num_buttons(device); + + ck_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; + unsigned 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++; + } + + ck_assert_int_eq(libinput_device_tablet_pad_get_num_buttons(device), + nbuttons); +} +END_TEST + +START_TEST(pad_button_intuos) +{ +#if !HAVE_LIBWACOM_GET_BUTTON_EVDEV_CODE + 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; + + /* 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_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)) { + ck_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); + libinput_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); + + ck_assert_int_gt(count, 3); +#endif +} +END_TEST + +START_TEST(pad_button_bamboo) +{ +#if !HAVE_LIBWACOM_GET_BUTTON_EVDEV_CODE + 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; + + if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_LEFT)) + return; + + 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); + libinput_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); + + ck_assert_int_gt(count, 3); +#endif +} +END_TEST + +START_TEST(pad_button_libwacom) +{ +#if HAVE_LIBWACOM_GET_BUTTON_EVDEV_CODE + 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); + libinput_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; + unsigned int code; + unsigned int expected_number = 0; + struct libinput_event *ev; + struct libinput_event_tablet_pad *pev; + + litest_drain_events(li); + + for (code = BTN_0; code < KEY_OK; code++) { + 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); + libinput_dispatch(li); + + switch (code) { + case BTN_STYLUS: + litest_assert_empty_queue(li); + continue; + default: + break; + } + + ev = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_type(ev), + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + pev = libinput_event_get_tablet_pad_event(ev); + + /* litest virtual devices don't have modes */ + mode = libinput_event_tablet_pad_get_mode(pev); + ck_assert_int_eq(mode, 0); + group = libinput_event_tablet_pad_get_mode_group(pev); + index = libinput_tablet_pad_mode_group_get_index(group); + ck_assert_int_eq(index, 0); + + libinput_event_destroy(ev); + + ev = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_type(ev), + LIBINPUT_EVENT_TABLET_PAD_BUTTON); + pev = libinput_event_get_tablet_pad_event(ev); + + mode = libinput_event_tablet_pad_get_mode(pev); + ck_assert_int_eq(mode, 0); + group = libinput_event_tablet_pad_get_mode_group(pev); + index = libinput_tablet_pad_mode_group_get_index(group); + ck_assert_int_eq(index, 0); + libinput_event_destroy(ev); + + expected_number++; + } + + 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); + ck_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); + libinput_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); + ck_assert_double_ge(degrees, 0.0); + ck_assert_double_lt(degrees, 360.0); + + ck_assert_double_eq(degrees, expected); + + libinput_event_destroy(ev); + expected = fmod(degrees + step_size, 360); + } + + ck_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); + libinput_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); + ck_assert_double_eq(degrees, -1.0); + libinput_event_destroy(ev); + + litest_assert_empty_queue(li); +} +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); + ck_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); + libinput_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); + ck_assert_double_ge(pos, 0.0); + ck_assert_double_lt(pos, 1.0); + + /* rounding errors, mostly caused by small physical range */ + ck_assert_double_ge(pos, expected - 0.02); + ck_assert_double_le(pos, expected + 0.02); + + libinput_event_destroy(ev); + + expected = pos + 0.08; + } + + litest_pad_strip_change(dev, 100); + libinput_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); + ck_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); + libinput_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); + ck_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; + + ck_assert(libinput_device_config_left_handed_is_available(device)); + + ck_assert_int_eq(libinput_device_config_left_handed_get_default(device), + 0); + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 0); + + status = libinput_device_config_left_handed_set(dev->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 1); + ck_assert_int_eq(libinput_device_config_left_handed_get_default(device), + 0); + + status = libinput_device_config_left_handed_set(dev->libinput_device, 0); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 0); + ck_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; + enum libinput_config_status status; + + ck_assert(!libinput_device_config_left_handed_is_available(device)); + + ck_assert_int_eq(libinput_device_config_left_handed_get_default(device), + 0); + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 0); + + status = libinput_device_config_left_handed_set(dev->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 0); + ck_assert_int_eq(libinput_device_config_left_handed_get_default(device), + 0); + + status = libinput_device_config_left_handed_set(dev->libinput_device, 0); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + + ck_assert_int_eq(libinput_device_config_left_handed_get(device), + 0); + ck_assert_int_eq(libinput_device_config_left_handed_get_default(device), + 0); +} +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); + libinput_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); + ck_assert_double_ge(degrees, 0.0); + ck_assert_double_lt(degrees, 360.0); + + /* rounding errors, mostly caused by small physical range */ + ck_assert_double_ge(degrees, expected - 2); + ck_assert_double_le(degrees, expected + 2); + + libinput_event_destroy(ev); + + expected = fmod(degrees + 36, 360); + } + + litest_pad_ring_end(dev); +#endif +} +END_TEST + +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; + int i; + + ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); + ck_assert_int_eq(ngroups, 1); + + for (i = 0; i < ngroups; i++) { + group = libinput_device_tablet_pad_get_mode_group(device, i); + ck_assert_notnull(group); + ck_assert_int_eq(libinput_tablet_pad_mode_group_get_index(group), + i); + } + + group = libinput_device_tablet_pad_get_mode_group(device, ngroups); + ck_assert(group == NULL); + group = libinput_device_tablet_pad_get_mode_group(device, ngroups + 1); + ck_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); + ck_assert(libinput_tablet_pad_mode_group_get_user_data(group) == + NULL); + libinput_tablet_pad_mode_group_set_user_data(group, userdata); + ck_assert(libinput_tablet_pad_mode_group_get_user_data(group) == + &rc); + + libinput_tablet_pad_mode_group_set_user_data(group, NULL); + ck_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); + ck_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); + ck_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; + + ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); + ck_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); + ck_assert_int_eq(nmodes, 1); + + mode = libinput_tablet_pad_mode_group_get_mode(group); + ck_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); + ck_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)) { + ck_assert(!found); + found = true; + } + } + ck_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)) { + ck_assert(!found); + found = true; + } + } + ck_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)) { + ck_assert(!found); + found = true; + } + } + ck_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); + ck_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); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_button(group, + nbuttons + 1); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_button(group, + 0x1000000); + ck_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); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_strip(group, + nstrips + 1); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_strip(group, + 0x1000000); + ck_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); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_ring(group, + nrings + 1); + ck_assert_int_eq(rc, 0); + rc = libinput_tablet_pad_mode_group_has_ring(group, + 0x1000000); + ck_assert_int_eq(rc, 0); + } +} +END_TEST + +START_TEST(pad_mode_group_has_no_toggle) +{ + 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; + + ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); + ck_assert_int_ge(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++) { + ck_assert(!libinput_tablet_pad_mode_group_button_is_toggle( + group, + b)); + } + } +} +END_TEST + +TEST_COLLECTION(tablet_pad) +{ + litest_add("pad:cap", pad_cap, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:cap", pad_no_cap, LITEST_ANY, LITEST_TABLET_PAD); + + litest_add("pad:time", pad_time, LITEST_TABLET_PAD, LITEST_ANY); + + litest_add("pad:button", pad_num_buttons, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:button", pad_num_buttons_libwacom, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:button", pad_button_intuos, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:button", pad_button_bamboo, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:button", pad_button_libwacom, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:button", pad_button_mode_groups, LITEST_TABLET_PAD, LITEST_ANY); + + litest_add("pad:ring", pad_has_ring, LITEST_RING, LITEST_ANY); + litest_add("pad:ring", pad_ring, LITEST_RING, LITEST_ANY); + litest_add("pad:ring", pad_ring_finger_up, LITEST_RING, LITEST_ANY); + + litest_add("pad:strip", pad_has_strip, LITEST_STRIP, LITEST_ANY); + litest_add("pad:strip", pad_strip, LITEST_STRIP, LITEST_ANY); + litest_add("pad:strip", pad_strip_finger_up, LITEST_STRIP, LITEST_ANY); + + litest_add_for_device("pad:left_handed", pad_left_handed_default, LITEST_WACOM_INTUOS5_PAD); + litest_add_for_device("pad:left_handed", pad_no_left_handed, LITEST_WACOM_INTUOS3_PAD); + litest_add_for_device("pad:left_handed", pad_left_handed_ring, LITEST_WACOM_INTUOS5_PAD); + /* None of the current strip tablets are left-handed */ + + litest_add("pad:modes", pad_mode_groups, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_groups_userdata, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_groups_ref, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_group_mode, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_group_has, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_group_has_invalid, LITEST_TABLET_PAD, LITEST_ANY); + litest_add("pad:modes", pad_mode_group_has_no_toggle, LITEST_TABLET_PAD, LITEST_ANY); +} diff --git a/test/test-path.c b/test/test-path.c new file mode 100644 index 0000000..7e78dd4 --- /dev/null +++ b/test/test-path.c @@ -0,0 +1,1045 @@ +/* + * 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 "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); + ck_assert(li == NULL); + li = libinput_path_create_context(&counting_interface, &counter); + ck_assert_notnull(li); + libinput_unref(li); + + ck_assert_int_eq(counter.open_func_count, 0); + ck_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); + ck_assert_notnull(li); + + litest_disable_log_handler(li); + + device = libinput_path_add_device(li, path); + ck_assert(device == NULL); + + ck_assert_int_eq(counter.open_func_count, 0); + ck_assert_int_eq(counter.close_func_count, 0); + + litest_restore_log_handler(li); + libinput_unref(li); + ck_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); + ck_assert_notnull(li); + + litest_disable_log_handler(li); + + device = libinput_path_add_device(li, path); + ck_assert(device == NULL); + + ck_assert_int_eq(counter.open_func_count, 1); + ck_assert_int_eq(counter.close_func_count, 1); + + litest_restore_log_handler(li); + libinput_unref(li); + ck_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); + ck_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); + + ck_assert_notnull(li); + device = libinput_path_add_device(li, path); + ck_assert(device == NULL); + + ck_assert_int_eq(counter.open_func_count, 0); + ck_assert_int_eq(counter.close_func_count, 0); + + litest_restore_log_handler(li); + libinput_unref(li); + ck_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); + ck_assert_notnull(li); + device = libinput_path_add_device(li, path); + ck_assert(device == NULL); + + ck_assert_int_eq(counter.open_func_count, 0); + ck_assert_int_eq(counter.close_func_count, 0); + + litest_restore_log_handler(li); + libinput_unref(li); + ck_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); + ck_assert_notnull(li); + + litest_disable_log_handler(li); + + ck_assert(libinput_get_user_data(li) == &counter); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput)); + ck_assert_notnull(device); + + ck_assert_int_eq(counter.open_func_count, 1); + + libevdev_uinput_destroy(uinput); + libinput_unref(li); + ck_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); + ck_assert_notnull(li); + libinput_ref(li); + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(dev->uinput)); + ck_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); + ck_assert_notnull(li); + ck_assert(libinput_get_user_data(li) == &data1); + libinput_set_user_data(li, &data2); + ck_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; + enum libinput_event_type type; + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + + device = libinput_event_get_device(event); + seat = libinput_device_get_seat(device); + ck_assert_notnull(seat); + + seat_name = libinput_seat_get_logical_name(seat); + ck_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; + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_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); + ck_assert_int_eq(rc, 0); + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_DEVICE_REMOVED); + + ck_assert(libinput_event_get_device(event) == device); + libinput_event_destroy(event); + + event = libinput_get_event(li); + ck_assert_notnull(event); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_DEVICE_ADDED); + ck_assert(libinput_event_get_device(event) != device); + libinput_device_unref(device); + + device = libinput_event_get_device(event); + seat2 = libinput_device_get_seat(device); + + ck_assert_str_ne(libinput_seat_get_logical_name(seat2), + seat1_name); + ck_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; + enum libinput_event_type type; + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(event); + ck_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; + enum libinput_event_type type; + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(event); + ck_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)); + ck_assert_notnull(device); + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(event); + ck_assert_notnull(device); + sysname2 = safe_strdup(libinput_device_get_sysname(device)); + libinput_event_destroy(event); + + ck_assert_str_eq(sysname1, sysname2); + + free(sysname1); + free(sysname2); +} +END_TEST + +START_TEST(path_add_invalid_path) +{ + struct libinput *li; + struct libinput_event *event; + 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); + ck_assert(device == NULL); + + libinput_dispatch(li); + + while ((event = libinput_get_event(li))) + ck_abort(); + + libinput_unref(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; + enum libinput_event_type type; + + libinput_dispatch(dev->libinput); + + ev = libinput_get_event(dev->libinput); + ck_assert_notnull(ev); + type = libinput_event_get_type(ev); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(ev); + ck_assert_notnull(device); + sysname = libinput_device_get_sysname(device); + + ck_assert_notnull(sysname); + ck_assert_int_gt(strlen(sysname), 1); + ck_assert(strchr(sysname, '/') == NULL); + ck_assert_int_eq(strncmp(sysname, "event", 5), 0); + + 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)); + ck_assert_notnull(device); + litest_drain_events(li); + + libinput_path_remove_device(device); + libinput_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); + } + + ck_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)); + ck_assert_notnull(device); + litest_drain_events(li); + + libinput_path_remove_device(device); + libinput_path_remove_device(device); + libinput_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); + } + + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput)); + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput)); + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput)); + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput1)); + ck_assert_notnull(device); + libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); + + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 2); + + libinput_suspend(li); + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 2); + + libinput_resume(li); + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + libinput_event_destroy(event); + nevents++; + } + + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput1)); + ck_assert_notnull(device); + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput2)); + ck_assert_notnull(device); + + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 2); + + libinput_suspend(li); + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 2); + + /* now drop one of the devices */ + libevdev_uinput_destroy(uinput1); + rc = libinput_resume(li); + ck_assert_int_eq(rc, -1); + + libinput_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) + ck_abort(); + libinput_event_destroy(event); + nevents++; + } + + ck_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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput1)); + ck_assert_notnull(device); + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput2)); + + libinput_device_ref(device); + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 2); + + libinput_suspend(li); + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED); + libinput_event_destroy(event); + nevents++; + } + + ck_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); + ck_assert_int_eq(rc, 0); + + libinput_dispatch(li); + + nevents = 0; + while ((event = libinput_get_event(li))) { + enum libinput_event_type type; + type = libinput_event_get_type(event); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + libinput_event_destroy(event); + nevents++; + } + + ck_assert_int_eq(nevents, 1); + + libevdev_uinput_destroy(uinput1); + 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; + enum libinput_event_type type; + + 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); + ck_assert_notnull(li); + + device = libinput_path_add_device(li, + libevdev_uinput_get_devnode(uinput)); + ck_assert_notnull(device); + + libinput_dispatch(li); + + ev = libinput_get_event(li); + ck_assert_notnull(ev); + type = libinput_event_get_type(ev); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(ev); + ck_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); + ck_assert_notnull(saved_seat); + + litest_assert_empty_queue(li); + + libinput_suspend(li); + + litest_drain_events(li); + + libinput_resume(li); + + libinput_dispatch(li); + ev = libinput_get_event(li); + ck_assert_notnull(ev); + type = libinput_event_get_type(ev); + ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); + device = libinput_event_get_device(ev); + ck_assert_notnull(device); + + seat = libinput_device_get_seat(device); + user_data = libinput_seat_get_user_data(seat); + if (user_data == &data) { + found = 1; + ck_assert(seat == saved_seat); + } + + libinput_event_destroy(ev); + ck_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"); + ck_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); + ck_assert_notnull(path); + + li = litest_create_context(); + device = libinput_path_add_device(li, path); + ck_assert(device == NULL); + + libinput_unref(li); + litest_delete_device(dev); +} +END_TEST + +TEST_COLLECTION(path) +{ + litest_add_no_device("path:create", path_create_NULL); + litest_add_no_device("path:create", path_create_invalid); + litest_add_no_device("path:create", path_create_invalid_file); + litest_add_no_device("path:create", path_create_invalid_kerneldev); + litest_add_no_device("path:create", path_create_pathmax_file); + litest_add_no_device("path:create", path_create_destroy); + litest_add("path:create", path_force_destroy, LITEST_ANY, LITEST_ANY); + litest_add_no_device("path:create", path_set_user_data); + litest_add_no_device("path:suspend", path_suspend); + litest_add_no_device("path:suspend", path_double_suspend); + litest_add_no_device("path:suspend", path_double_resume); + litest_add_no_device("path:suspend", path_add_device_suspend_resume); + litest_add_no_device("path:suspend", path_add_device_suspend_resume_fail); + litest_add_no_device("path:suspend", path_add_device_suspend_resume_remove_device); + litest_add_for_device("path:seat", path_added_seat, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("path:seat", path_seat_change, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add("path:device events", path_added_device, LITEST_ANY, LITEST_ANY); + litest_add("path:device events", path_device_sysname, LITEST_ANY, LITEST_ANY); + litest_add_for_device("path:device events", path_add_device, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_no_device("path:device events", path_add_invalid_path); + litest_add_for_device("path:device events", path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("path:device events", path_double_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_no_device("path:seat", path_seat_recycle); + litest_add_for_device("path:udev", path_udev_assign_seat, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add_no_device("path:ignore", path_ignore_device); +} diff --git a/test/test-pointer.c b/test/test-pointer.c new file mode 100644 index 0000000..6561489 --- /dev/null +++ b/test/test-pointer.c @@ -0,0 +1,2768 @@ +/* + * 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" + +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); + + libinput_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); + ck_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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; + int cardinal = _i; /* ranged test */ + double len; + + int deltas[8][2] = { + /* N, NE, E, ... */ + { 0, 1 }, + { 1, 1 }, + { 1, 0 }, + { 1, -1 }, + { 0, -1 }, + { -1, -1 }, + { -1, 0 }, + { -1, 1 }, + }; + + litest_drain_events(dev->libinput); + + dx = deltas[cardinal][0]; + dy = deltas[cardinal][1]; + + 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); + + 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); + + ck_assert((evx == 0.0) == (dx == 0)); + ck_assert((evy == 0.0) == (dy == 0)); + + len = hypot(evx, evy); + ck_assert(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); + libinput_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 = _i; /* looped test */ + + 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); + + ck_assert_int_eq(libinput_event_get_type(ev1), + LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); + ck_assert_int_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); + + ck_assert_int_eq(libinput_event_pointer_get_absolute_x(p1), + libinput_event_pointer_get_absolute_x(p2)); + ck_assert_int_eq(libinput_event_pointer_get_absolute_y(p1), + libinput_event_pointer_get_absolute_y(p2)); + + libinput_event_destroy(ev1); + libinput_event_destroy(ev2); + } + + libinput_unref(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); + + libinput_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); + ck_assert_notnull(event); + type = libinput_event_get_type(event); + + if (type == LIBINPUT_EVENT_DEVICE_REMOVED) { + libinput_event_destroy(event); + break; + } + + ck_assert_int_eq(type, LIBINPUT_EVENT_POINTER_BUTTON); + pevent = libinput_event_get_pointer_event(event); + ck_assert_int_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) { + ck_assert_int_eq(buttons[i].released, 0); + buttons[i].released = 1; + valid_code = 1; + } + } + ck_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) { + ck_assert_int_eq(buttons[i].released, 1); + } + + libinput_unref(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; + + ck_assert(!libinput_device_has_capability(device, + LIBINPUT_DEVICE_CAP_POINTER)); + + for (code = BTN_LEFT; code < KEY_OK; code++) + ck_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 enum libinput_pointer_axis_source +wheel_source(struct litest_device *dev, int which) +{ + struct udev_device *d; + bool is_tilt = false; + + d = libinput_device_get_udev_device(dev->libinput_device); + litest_assert_ptr_notnull(d); + + switch(which) { + case REL_WHEEL: + is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_VERTICAL"); + break; + case REL_HWHEEL: + is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_HORIZONTAL"); + break; + default: + litest_abort_msg("Invalid source axis %d\n", which); + break; + } + + udev_device_unref(d); + return is_tilt ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT : + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; +} + +static void +test_wheel_event(struct litest_device *dev, int which, int 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; + + scroll_step = wheel_click_angle(dev, which); + source = wheel_source(dev, which); + expected = amount * scroll_step; + discrete = amount; + + if (libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device)) { + expected *= -1; + discrete *= -1; + } + + /* mouse scroll wheels are 'upside down' */ + if (which == REL_WHEEL) + amount *= -1; + litest_event(dev, EV_REL, which, amount); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + + axis = (which == REL_WHEEL) ? + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL : + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; + + event = libinput_get_event(li); + ptrev = litest_is_axis_event(event, axis, source); + + 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); + libinput_event_destroy(event); +} + +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 */ + ck_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_natural_defaults) +{ + struct litest_device *dev = litest_current_device(); + + ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1); + ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); + ck_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; + + ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + ck_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 */ + ck_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_event(dev, EV_REL, REL_WHEEL, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + pev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + 0); + + ck_assert_int_eq(libinput_event_pointer_has_axis(pev, -1), 0); + ck_assert_int_eq(libinput_event_pointer_has_axis(pev, 2), 0); + ck_assert_int_eq(libinput_event_pointer_has_axis(pev, 3), 0); + ck_assert_int_eq(libinput_event_pointer_has_axis(pev, 0xffff), 0); + libinput_event_destroy(event); +} +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); + + libinput_dispatch(libinput); + while ((ev = libinput_get_event(libinput))) { + if (libinput_event_get_type(ev) != + LIBINPUT_EVENT_POINTER_BUTTON) { + libinput_event_destroy(ev); + libinput_dispatch(libinput); + continue; + } + + tev = libinput_event_get_pointer_event(ev); + ck_assert_notnull(tev); + ck_assert_int_eq(libinput_event_pointer_get_button(tev), + BTN_LEFT); + ck_assert_int_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); + ck_assert_int_eq(expected_seat_button_count, seat_button_count); + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } + + ck_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); + + libinput_dispatch(libinput); + while ((ev = libinput_get_event(libinput))) { + if (libinput_event_get_type(ev) != + LIBINPUT_EVENT_POINTER_BUTTON) { + libinput_event_destroy(ev); + libinput_dispatch(libinput); + continue; + } + + tev = libinput_event_get_pointer_event(ev); + ck_assert_notnull(tev); + ck_assert_int_eq(libinput_event_pointer_get_button(tev), + BTN_LEFT); + ck_assert_int_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); + ck_assert_int_eq(expected_seat_button_count, seat_button_count); + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } + + ck_assert_int_eq(seat_button_count, 0); + + for (i = 0; i < num_devices; ++i) + litest_delete_device(devices[i]); + libinput_unref(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); + ck_assert_int_eq(rc, 0); + rc = libinput_device_config_calibration_get_matrix(d, calibration); + ck_assert_int_eq(rc, 0); + rc = libinput_device_config_calibration_get_default_matrix(d, + calibration); + ck_assert_int_eq(rc, 0); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_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; + + rc = libinput_device_config_left_handed_is_available(d); + ck_assert_int_ne(rc, 0); + + rc = libinput_device_config_left_handed_get(d); + ck_assert_int_eq(rc, 0); + + rc = libinput_device_config_left_handed_get_default(d); + ck_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); + ck_assert_int_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); + libinput_dispatch(li); + + /* Change while button is down, expect correct release event */ + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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_disable_middleemu(dev); + + litest_drain_events(li); + litest_button_click_debounced(dev, li, BTN_LEFT, 1); + libinput_dispatch(li); + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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_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_POINTER_AXIS_SCROLL_VERTICAL, 6); + litest_button_scroll(dev, BTN_LEFT, 1, -7); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7); + litest_button_scroll(dev, BTN_LEFT, 8, 1); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8); + litest_button_scroll(dev, BTN_LEFT, -9, 1); + litest_assert_scroll(li, 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); + ck_assert_int_eq((methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN), 0); + button = libinput_device_config_scroll_get_button(device); + ck_assert_int_eq(button, 0); + button = libinput_device_config_scroll_get_default_button(device); + ck_assert_int_eq(button, 0); + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_scroll_set_button(device, BTN_LEFT); + ck_assert_int_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_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(); + libinput_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; + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_scroll_set_button(device, BTN_MIDDLE); + ck_assert_int_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_RIGHT, 1); + libinput_dispatch(li); + litest_timeout_buttonscroll(); + libinput_dispatch(li); + + for (i = 0; i < 10; i++) { + litest_event(dev, EV_REL, REL_Y, -1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + } + + libinput_dispatch(li); + + litest_button_click_debounced(dev, li, BTN_LEFT, 0); + litest_button_click_debounced(dev, li, BTN_RIGHT, 0); + libinput_dispatch(li); + + litest_assert_scroll(li, 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); + libinput_dispatch(li); + + /* delete the device while the timer is still active */ + litest_delete_device(dev); + libinput_dispatch(li); + + libinput_unref(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)) + expected = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; + else + expected = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; + + method = libinput_device_config_scroll_get_method(device); + ck_assert_int_eq(method, expected); + + method = libinput_device_config_scroll_get_default_method(device); + ck_assert_int_eq(method, expected); + + if (method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) { + button = libinput_device_config_scroll_get_button(device); + ck_assert_int_eq(button, BTN_MIDDLE); + button = libinput_device_config_scroll_get_default_button(device); + ck_assert_int_eq(button, 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); + ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); + method = libinput_device_config_scroll_get_default_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_SCROLL_NO_SCROLL); + + button = libinput_device_config_scroll_get_button(device); + ck_assert_int_eq(button, 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; + + ck_assert(libinput_device_config_accel_is_available(device)); + ck_assert_double_eq(libinput_device_config_accel_get_default_speed(device), + 0.0); + ck_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); + ck_assert_int_eq(status, + LIBINPUT_CONFIG_STATUS_INVALID); + ck_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); + ck_assert_int_eq(status, + LIBINPUT_CONFIG_STATUS_SUCCESS); + ck_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); + ck_assert_int_eq(status, + LIBINPUT_CONFIG_STATUS_INVALID); + ck_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; + + ck_assert(libinput_device_config_accel_is_available(device)); + + status = libinput_device_config_accel_set_speed(device, + NAN); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + status = libinput_device_config_accel_set_speed(device, + INFINITY); + ck_assert_int_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; + + ck_assert(!libinput_device_config_accel_is_available(device)); + ck_assert_double_eq(libinput_device_config_accel_get_default_speed(device), + 0.0); + ck_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) + ck_assert_int_eq(status, + LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + else + ck_assert_int_eq(status, + LIBINPUT_CONFIG_STATUS_INVALID); + ck_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; + + ck_assert(libinput_device_config_accel_is_available(device)); + ck_assert_double_eq(libinput_device_config_accel_get_default_speed(device), + 0.0); + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + do { + pev = libinput_event_get_pointer_event(event); + + delta = libinput_event_pointer_get_dx(pev); + ck_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); + ck_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; + + ck_assert(libinput_device_config_accel_is_available(device)); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + + profiles = libinput_device_config_accel_get_profiles(device); + ck_assert(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + ck_assert(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); +} +END_TEST + +START_TEST(pointer_accel_profile_defaults_noprofile) +{ + 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; + + ck_assert(libinput_device_config_accel_is_available(device)); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profiles = libinput_device_config_accel_get_profiles(device); + ck_assert_int_eq(profiles, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); +} +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; + + ck_assert(libinput_device_config_accel_is_available(device)); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE + 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_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; + + ck_assert(!libinput_device_config_accel_is_available(device)); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE + 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_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_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; + + 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_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; + + 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_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; + + status = libinput_device_config_middle_emulation_set_enabled( + device->libinput_device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + /* 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; + + status = libinput_device_config_middle_emulation_set_enabled( + device->libinput_device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + 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; + + available = libinput_device_config_middle_emulation_is_available(device); + ck_assert(available); + + state = libinput_device_config_middle_emulation_get_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + + state = libinput_device_config_middle_emulation_get_default_enabled( + device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_middle_emulation_set_enabled(device, 3); + ck_assert_int_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); + ck_assert(available); + + state = libinput_device_config_middle_emulation_get_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + state = libinput_device_config_middle_emulation_get_default_enabled( + device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_middle_emulation_set_enabled(device, 3); + ck_assert_int_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; + + available = libinput_device_config_middle_emulation_is_available(device); + ck_assert(!available); + + if (libinput_device_pointer_has_button(device, BTN_MIDDLE)) + return; + + state = libinput_device_config_middle_emulation_get_enabled( + device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + state = libinput_device_config_middle_emulation_get_default_enabled( + device); + ck_assert_int_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); + ck_assert(available); + + state = libinput_device_config_middle_emulation_get_enabled( + device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + state = libinput_device_config_middle_emulation_get_default_enabled( + device); + ck_assert_int_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); + ck_assert(!available); + state = libinput_device_config_middle_emulation_get_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + state = libinput_device_config_middle_emulation_get_default_enabled( + device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + ck_assert_int_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; + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + status = libinput_device_config_scroll_set_button(device, BTN_LEFT); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_LEFT, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + /* middle emulation discards */ + litest_assert_empty_queue(li); + + litest_timeout_middlebutton(); + libinput_dispatch(li); + + /* scroll discards */ + litest_assert_empty_queue(li); + litest_timeout_buttonscroll(); + libinput_dispatch(li); + + for (i = 0; i < 10; i++) { + litest_event(dev, EV_REL, REL_Y, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + } + + ev = libinput_get_event(li); + do { + pev = litest_is_axis_event(ev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); + ck_assert_double_gt(libinput_event_pointer_get_axis_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); + libinput_dispatch(li); + + ev = libinput_get_event(li); + pev = litest_is_axis_event(ev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); + ck_assert_double_eq(libinput_event_pointer_get_axis_value(pev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), + 0.0); + libinput_event_destroy(ev); + + /* 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; + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + status = libinput_device_config_scroll_set_button(device, BTN_LEFT); + if (status == LIBINPUT_CONFIG_STATUS_UNSUPPORTED) + return; + + 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); + libinput_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); + libinput_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_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); + libinput_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_drain_events(li); + + litest_event(dev, EV_KEY, BTN_RIGHT, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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); + ck_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 = _i; /* ranged test */ + + if (!libinput_device_pointer_has_button(dev->libinput_device, + button)) + return; + + 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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + libinput_dispatch(li); + litest_event(dev, EV_KEY, BTN_LEFT, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + litest_timeout_debounce(); + libinput_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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 = _i; /* ranged test */ + + if (!libinput_device_pointer_has_button(dev->libinput_device, + button)) + return; + + 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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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(); + libinput_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + libinput_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. + */ + libinput_dispatch(li); + litest_timeout_middlebutton(); + libinput_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_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_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + + libinput_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_dispatch(li); + + litest_event(dev, EV_KEY, BTN_LEFT, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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_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); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + + libinput_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_drain_events(li); + debounce_trigger_spurious(dev, li); + + litest_event(dev, EV_KEY, BTN_LEFT, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + litest_timeout_debounce(); + libinput_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); + + libinput_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); + libinput_dispatch(li); + + /* delete the device while the timer is still active */ + litest_delete_device(dev); + libinput_dispatch(li); + + litest_timeout_debounce(); + libinput_dispatch(li); + + libinput_unref(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); + libinput_dispatch(li); + + /* delete the device the timer is still active */ + litest_delete_device(dev); + libinput_dispatch(li); + + litest_timeout_debounce(); + libinput_dispatch(li); + + libinput_unref(li); +} +END_TEST + +TEST_COLLECTION(pointer) +{ + struct range axis_range = {ABS_X, ABS_Y + 1}; + struct range compass = {0, 7}; /* cardinal directions */ + struct range buttons = {BTN_LEFT, BTN_TASK + 1}; + + litest_add("pointer:motion", pointer_motion_relative, LITEST_RELATIVE, LITEST_POINTINGSTICK); + litest_add_for_device("pointer:motion", pointer_motion_relative_zero, LITEST_MOUSE); + litest_add_ranged("pointer:motion", pointer_motion_relative_min_decel, LITEST_RELATIVE, LITEST_POINTINGSTICK, &compass); + litest_add("pointer:motion", pointer_motion_absolute, LITEST_ABSOLUTE, LITEST_ANY); + litest_add("pointer:motion", pointer_motion_unaccel, LITEST_RELATIVE, LITEST_ANY); + litest_add("pointer:button", pointer_button, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add_no_device("pointer:button", pointer_button_auto_release); + litest_add_no_device("pointer:button", pointer_seat_button_count); + litest_add_for_device("pointer:button", pointer_button_has_no_button, LITEST_KEYBOARD); + litest_add("pointer:button", pointer_recover_from_lost_button_count, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET); + litest_add("pointer:scroll", pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:scroll", pointer_scroll_button_noscroll, LITEST_ABSOLUTE|LITEST_BUTTON, LITEST_RELATIVE); + litest_add("pointer:scroll", pointer_scroll_button_noscroll, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON); + litest_add("pointer:scroll", pointer_scroll_button_no_event_before_timeout, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:scroll", pointer_scroll_button_middle_emulation, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:scroll", pointer_scroll_button_device_remove_while_down, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON); + litest_add("pointer:scroll", pointer_scroll_nowheel_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_WHEEL); + litest_add_for_device("pointer:scroll", pointer_scroll_defaults_logitech_marble , LITEST_LOGITECH_TRACKBALL); + litest_add("pointer:scroll", pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_TABLET); + litest_add("pointer:scroll", pointer_scroll_natural_defaults_noscroll, LITEST_ANY, LITEST_WHEEL); + litest_add("pointer:scroll", pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_TABLET); + litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_TABLET); + litest_add("pointer:scroll", pointer_scroll_has_axis_invalid, LITEST_WHEEL, LITEST_TABLET); + + litest_add("pointer:calibration", 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", pointer_left_handed_defaults, LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:left-handed", pointer_left_handed, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:left-handed", pointer_left_handed_during_click, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add("pointer:left-handed", pointer_left_handed_during_click_multiple_buttons, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + + litest_add("pointer:accel", pointer_accel_defaults, LITEST_RELATIVE, LITEST_ANY); + litest_add("pointer:accel", pointer_accel_invalid, LITEST_RELATIVE, LITEST_ANY); + litest_add("pointer:accel", pointer_accel_defaults_absolute, LITEST_ABSOLUTE, LITEST_RELATIVE); + litest_add("pointer:accel", pointer_accel_defaults_absolute_relative, LITEST_ABSOLUTE|LITEST_RELATIVE, LITEST_ANY); + litest_add("pointer:accel", pointer_accel_direction_change, LITEST_RELATIVE, LITEST_POINTINGSTICK); + litest_add("pointer:accel", pointer_accel_profile_defaults, LITEST_RELATIVE, LITEST_TOUCHPAD); + litest_add("pointer:accel", pointer_accel_profile_defaults_noprofile, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("pointer:accel", pointer_accel_profile_invalid, LITEST_RELATIVE, LITEST_ANY); + litest_add("pointer:accel", pointer_accel_profile_noaccel, LITEST_ANY, LITEST_TOUCHPAD|LITEST_RELATIVE|LITEST_TABLET); + litest_add("pointer:accel", pointer_accel_profile_flat_motion_relative, LITEST_RELATIVE, LITEST_TOUCHPAD); + + litest_add("pointer:middlebutton", middlebutton, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_nostart_while_down, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_timeout, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_doubleclick, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_middleclick, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_middleclick_during, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_default_enabled, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_POINTINGSTICK); + litest_add("pointer:middlebutton", middlebutton_default_clickpad, LITEST_CLICKPAD, LITEST_ANY); + litest_add("pointer:middlebutton", middlebutton_default_touchpad, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_default_disabled, LITEST_ANY, LITEST_BUTTON); + litest_add_for_device("pointer:middlebutton", middlebutton_default_alps, LITEST_ALPS_SEMI_MT); + litest_add("pointer:middlebutton", middlebutton_button_scrolling, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_button_scrolling_middle, LITEST_RELATIVE|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_device_remove_while_down, LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("pointer:middlebutton", middlebutton_device_remove_while_one_is_down, LITEST_BUTTON, LITEST_CLICKPAD); + + litest_add_ranged("pointer:state", pointer_absolute_initial_state, LITEST_ABSOLUTE, LITEST_ANY, &axis_range); + + litest_add("pointer:time", pointer_time_usec, LITEST_RELATIVE, LITEST_ANY); + + litest_add_ranged("pointer:debounce", debounce_bounce, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE, &buttons); + litest_add("pointer:debounce", debounce_bounce_check_immediate, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); + litest_add_ranged("pointer:debounce", debounce_spurious, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE, &buttons); + litest_add("pointer:debounce", debounce_spurious_multibounce, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); + litest_add("pointer:debounce_otherbutton", debounce_spurious_dont_enable_on_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); + litest_add("pointer:debounce_otherbutton", debounce_spurious_cancel_debounce_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); + litest_add("pointer:debounce_otherbutton", debounce_spurious_switch_to_otherbutton, LITEST_BUTTON, LITEST_TOUCHPAD|LITEST_NO_DEBOUNCE); + litest_add_no_device("pointer:debounce", debounce_remove_device_button_down); + litest_add_no_device("pointer:debounce", debounce_remove_device_button_up); +} diff --git a/test/test-quirks.c b/test/test-quirks.c new file mode 100644 index 0000000..2cb5b85 --- /dev/null +++ b/test/test-quirks.c @@ -0,0 +1,1481 @@ +/* + * 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 "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+"); + rc = fputs(file_content, fp); + fclose(fp); + litest_assert_int_ge(rc, 0); + 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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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); + ck_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", + }; + const char **qf; + + 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); + ck_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=0x0000\n" + "ModelAppleTouchpad=1\n" + "\n" + "[Section name]\n" + "MatchProduct=0x0001\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); + ck_assert_notnull(ctx); + quirks_context_unref(ctx); + 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", + }; + const char **qf; + + 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); + ck_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); + ck_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", + }; + const char **qf; + + 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); + ck_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); + ck_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", + }; + const char **qf; + + 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); + ck_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); + ck_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", + }; + const char **qf; + + 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); + ck_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); + ck_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", + }; + const char **qf; + + 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); + ck_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); + ck_assert_notnull(q); + ck_assert(func(q, which, data)); + ck_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; + int 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, + }; + enum quirk *a; + 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 }, + }; + struct qtest_dim *t; + + 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); + ck_assert_int_eq(rc, t->success); + if (!rc) + continue; + + ck_assert_int_eq(dim.x, t->w); + ck_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, + }; + enum quirk *a; + 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 }, + }; + struct qtest_range *t; + + 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); + ck_assert_int_eq(rc, t->success); + if (!rc) + continue; + + ck_assert_int_eq(r.lower, t->lo); + ck_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, + }; + enum quirk *a; + 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 }, + }; + struct qtest_uint *t; + + 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); + ck_assert_int_eq(rc, t->success); + if (!rc) + continue; + + ck_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, + }; + enum quirk *a; + 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 }, + }; + struct qtest_double *t; + + 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); + ck_assert_int_eq(rc, t->success); + if (!rc) + continue; + + ck_assert_int_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, + }; + enum quirk *a; + 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 }, + }; + struct qtest_str *t; + + 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) + ck_assert_int_eq(rc, true); + else + ck_assert_int_eq(rc, false); + } + } +} +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); + ck_assert(rc); + rc = test_attr_parse(dev, + QUIRK_ATTR_KEYBOARD_INTEGRATION, + "external", + (qparsefunc)quirks_get_string, + &do_not_use); + ck_assert(rc); + rc = test_attr_parse(dev, + QUIRK_ATTR_TRACKPOINT_INTEGRATION, + "internal", + (qparsefunc)quirks_get_string, + &do_not_use); + ck_assert(rc); + rc = test_attr_parse(dev, + QUIRK_ATTR_TRACKPOINT_INTEGRATION, + "external", + (qparsefunc)quirks_get_string, + &do_not_use); + ck_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); + ck_assert_notnull(ctx); + + q = quirks_fetch_for_device(ctx, ud); + ck_assert_notnull(q); + + ck_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset)); + ck_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); + ck_assert_notnull(ctx); + + q = quirks_fetch_for_device(ctx, ud); + ck_assert_notnull(q); + + ck_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset)); + ck_assert(isset == false); + + quirks_unref(q); + quirks_context_unref(ctx); + cleanup_data_dir(dd); + udev_device_unref(ud); +} +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_TOUCHPAD, &value); + + if (strstr(libinput_device_get_name(device), "ALPS")) { + ck_assert(exists); + ck_assert(value); + } else { + ck_assert(!exists); + ck_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) { + ck_assert(exists); + ck_assert(value); + } else { + ck_assert(!exists); + ck_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) { + ck_assert(exists); + ck_assert(value); + } else { + ck_assert(!exists); + ck_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) { + ck_assert(exists); + ck_assert(value); + } else { + ck_assert(!exists); + ck_assert(!value); + } +} +END_TEST + +START_TEST(quirks_call_NULL) +{ + ck_assert(!quirks_fetch_for_device(NULL, NULL)); + + ck_assert(!quirks_get_uint32(NULL, 0, NULL)); + ck_assert(!quirks_get_int32(NULL, 0, NULL)); + ck_assert(!quirks_get_range(NULL, 0, NULL)); + ck_assert(!quirks_get_dimensions(NULL, 0, NULL)); + ck_assert(!quirks_get_double(NULL, 0, NULL)); + ck_assert(!quirks_get_string(NULL, 0, NULL)); + ck_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); + ck_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:datadir", quirks_invalid_dir); + litest_add_deviceless("quirks:datadir", quirks_empty_dir); + + litest_add_deviceless("quirks:structure", quirks_section_empty); + litest_add_deviceless("quirks:structure", quirks_section_double); + litest_add_deviceless("quirks:structure", quirks_section_missing_match); + litest_add_deviceless("quirks:structure", quirks_section_missing_attr); + litest_add_deviceless("quirks:structure", quirks_section_match_after_attr); + litest_add_deviceless("quirks:structure", quirks_section_duplicate_match); + litest_add_deviceless("quirks:structure", quirks_section_duplicate_attr); + + litest_add_deviceless("quirks:parsing", quirks_parse_error_section); + litest_add_deviceless("quirks:parsing", quirks_parse_error_trailing_whitespace); + litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_match); + litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_attr); + litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_model); + litest_add_deviceless("quirks:parsing", quirks_parse_error_unknown_prefix); + litest_add_deviceless("quirks:parsing", quirks_parse_error_model_not_one); + litest_add_deviceless("quirks:parsing", quirks_parse_comment_inline); + litest_add_deviceless("quirks:parsing", quirks_parse_comment_empty); + litest_add_deviceless("quirks:parsing", quirks_parse_string_quotes_single); + litest_add_deviceless("quirks:parsing", quirks_parse_string_quotes_double); + + litest_add_deviceless("quirks:parsing", quirks_parse_bustype); + litest_add_deviceless("quirks:parsing", quirks_parse_bustype_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_vendor); + litest_add_deviceless("quirks:parsing", quirks_parse_vendor_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_product); + litest_add_deviceless("quirks:parsing", quirks_parse_product_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_version); + litest_add_deviceless("quirks:parsing", quirks_parse_version_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_name); + litest_add_deviceless("quirks:parsing", quirks_parse_name_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_udev); + litest_add_deviceless("quirks:parsing", quirks_parse_udev_invalid); + litest_add_deviceless("quirks:parsing", quirks_parse_dmi); + litest_add_deviceless("quirks:parsing", quirks_parse_dmi_invalid); + + litest_add_for_device("quirks:parsing", quirks_parse_dimension_attr, LITEST_MOUSE); + litest_add_for_device("quirks:parsing", quirks_parse_range_attr, LITEST_MOUSE); + litest_add_for_device("quirks:parsing", quirks_parse_uint_attr, LITEST_MOUSE); + litest_add_for_device("quirks:parsing", quirks_parse_double_attr, LITEST_MOUSE); + litest_add_for_device("quirks:parsing", quirks_parse_string_attr, LITEST_MOUSE); + litest_add_for_device("quirks:parsing", quirks_parse_integration_attr, LITEST_MOUSE); + + litest_add_for_device("quirks:model", quirks_model_one, LITEST_MOUSE); + litest_add_for_device("quirks:model", quirks_model_zero, LITEST_MOUSE); + + litest_add("quirks:devices", quirks_model_alps, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("quirks:devices", quirks_model_wacom, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("quirks:devices", quirks_model_apple, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("quirks:devices", quirks_model_synaptics_serial, LITEST_TOUCHPAD, LITEST_ANY); + + litest_add_deviceless("quirks:misc", quirks_call_NULL); + litest_add_deviceless("quirks:misc", quirks_ctx_ref); +} diff --git a/test/test-switch.c b/test/test-switch.c new file mode 100644 index 0000000..29212e8 --- /dev/null +++ b/test/test-switch.c @@ -0,0 +1,1309 @@ +/* + * 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); +} + +static inline bool +switch_has_tablet_mode(struct litest_device *dev) +{ + return libinput_device_switch_has_switch(dev->libinput_device, + LIBINPUT_SWITCH_TABLET_MODE); +} + +START_TEST(switch_has_cap) +{ + struct litest_device *dev = litest_current_device(); + + ck_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; + + ck_assert_int_eq(libinput_device_switch_has_switch(dev->libinput_device, + LIBINPUT_SWITCH_LID), + 1); +} +END_TEST + +START_TEST(switch_has_tablet_mode_switch) +{ + struct litest_device *dev = litest_current_device(); + + if (!libevdev_has_event_code(dev->evdev, EV_SW, SW_TABLET_MODE)) + return; + + ck_assert_int_eq(libinput_device_switch_has_switch(dev->libinput_device, + LIBINPUT_SWITCH_TABLET_MODE), + 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 = _i; /* ranged test */ + + litest_drain_events(li); + + litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); + libinput_dispatch(li); + + if (libinput_device_switch_has_switch(dev->libinput_device, sw)) { + 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); + libinput_dispatch(li); + + if (libinput_device_switch_has_switch(dev->libinput_device, sw)) { + event = libinput_get_event(li); + litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF); + libinput_event_destroy(event); + } + + litest_assert_empty_queue(li); +} +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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(dev->libinput_device, sw)) + return; + + litest_drain_events(li); + + litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); + libinput_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); + libinput_dispatch(li); + + litest_assert_empty_queue(li); +} +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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(dev->libinput_device, sw)) + return; + + if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev)) + return; + + litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); + + /* need separate context to test */ + li = litest_create_context(); + libinput_path_add_device(li, + libevdev_uinput_get_devnode(dev->uinput)); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_SWITCH_TOGGLE, -1); + 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))) { + ck_assert_int_ne(libinput_event_get_type(event), + LIBINPUT_EVENT_SWITCH_TOGGLE); + libinput_event_destroy(event); + } + + litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF); + libinput_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); + + libinput_unref(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)) + return; + + if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev)) + return; + + litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON); + + /* need separate context to test */ + li = litest_create_context(); + libinput_path_add_device(li, + libevdev_uinput_get_devnode(dev->uinput)); + libinput_dispatch(li); + + while ((event = libinput_get_event(li)) != NULL) { + ck_assert_int_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); + libinput_unref(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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + /* 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); +} +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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + litest_disable_tap(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_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + 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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + litest_enable_edge_scroll(touchpad); + + litest_drain_events(li); + + litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + + litest_touch_down(touchpad, 0, 99, 20); + libinput_dispatch(li); + litest_timeout_edgescroll(); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60); + litest_touch_up(touchpad, 0); + libinput_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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + litest_enable_edge_scroll(touchpad); + + litest_drain_events(li); + + litest_touch_down(touchpad, 0, 99, 20); + libinput_dispatch(li); + litest_timeout_edgescroll(); + litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + libinput_event_destroy(event); + + 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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + + litest_disable_tap(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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + litest_disable_tap(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_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 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 = _i; /* ranged test */ + + if (!libinput_device_switch_has_switch(sw->libinput_device, which)) + return; + + touchpad = switch_init_paired_touchpad(li); + mouse = litest_add_device(li, LITEST_MOUSE); + litest_disable_tap(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_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 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; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + + 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); + libinput_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_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; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); + + 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_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); + libinput_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 = _i; /* ranged test */ + + 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(); + } + + libinput_dispatch(li); + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + libinput_dispatch(li); + + 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_delete_device(keyboard); + litest_drain_events(li); + + litest_delete_device(sw); + libinput_dispatch(li); + + libinput_unref(li); +} +END_TEST + +START_TEST(switch_suspend_with_touchpad) +{ + struct libinput *li; + struct litest_device *touchpad, *sw; + enum libinput_switch which = _i; /* ranged test */ + + 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_delete_device(touchpad); + touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); + litest_drain_events(li); + + litest_delete_device(sw); + litest_drain_events(li); + litest_delete_device(touchpad); + litest_drain_events(li); + + libinput_unref(li); +} +END_TEST + +START_TEST(lid_update_hw_on_key) +{ + struct litest_device *sw = litest_current_device(); + struct libinput *li = sw->libinput; + struct libinput *li2; + struct litest_device *keyboard; + struct libinput_event *event; + + if (!switch_has_lid(sw)) + return; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + + /* separate context to listen to the fake hw event */ + li2 = litest_create_context(); + libinput_path_add_device(li2, + libevdev_uinput_get_devnode(sw->uinput)); + litest_drain_events(li2); + + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + libinput_dispatch(li2); + event = libinput_get_event(li2); + litest_is_switch_event(event, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + libinput_event_destroy(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); + + litest_wait_for_event(li2); + event = libinput_get_event(li2); + litest_is_switch_event(event, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); + libinput_event_destroy(event); + litest_assert_empty_queue(li2); + + libinput_unref(li2); + litest_delete_device(keyboard); +} +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 ev; + + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + + /* Make sure kernel state is right */ + libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); + while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0) + ; + ck_assert(libevdev_get_event_value(evdev, EV_SW, SW_LID)); + + 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 */ + while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) { + ck_assert_int_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 */ + libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); + while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0) + ; + ck_assert(!libevdev_get_event_value(evdev, EV_SW, SW_LID)); + + libinput_unref(li); + litest_delete_device(keyboard); +} +END_TEST + +START_TEST(lid_update_hw_on_key_multiple_keyboards) +{ + struct litest_device *sw = litest_current_device(); + struct libinput *li = sw->libinput; + struct libinput *li2; + struct litest_device *keyboard1, *keyboard2; + struct libinput_event *event; + + if (!switch_has_lid(sw)) + return; + + keyboard1 = litest_add_device(li, + LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH); + libinput_dispatch(li); + + keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH); + libinput_dispatch(li); + + /* separate context to listen to the fake hw event */ + li2 = litest_create_context(); + libinput_path_add_device(li2, + libevdev_uinput_get_devnode(sw->uinput)); + litest_drain_events(li2); + + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + + libinput_dispatch(li2); + event = libinput_get_event(li2); + litest_is_switch_event(event, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + libinput_event_destroy(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); + + litest_wait_for_event(li2); + event = libinput_get_event(li2); + litest_is_switch_event(event, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); + libinput_event_destroy(event); + litest_assert_empty_queue(li2); + + libinput_unref(li2); + litest_delete_device(keyboard1); + litest_delete_device(keyboard2); +} +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); + libinput_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_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_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_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; + + touchpad = switch_init_paired_touchpad(li); + litest_disable_tap(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); + libinput_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: + ck_abort(); + } + libinput_event_destroy(event); + } + + ck_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); + libinput_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; + + 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); + libinput_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_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + libinput_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; + + 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_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + 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_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_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; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + 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); + libinput_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: + ck_abort(); + } + libinput_event_destroy(event); + } + + ck_assert(have_switch_toggle); + + 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_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; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); + libinput_suspend(li); + litest_drain_events(li); + + litest_switch_action(sw, + LIBINPUT_SWITCH_TABLET_MODE, + LIBINPUT_SWITCH_STATE_OFF); + + libinput_resume(li); + libinput_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; + + 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_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_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_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_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_drain_events(li); + + litest_event(sw, EV_SW, SW_DOCK, 1); + libinput_dispatch(li); + + litest_event(sw, EV_SW, SW_DOCK, 0); + libinput_dispatch(li); + + litest_assert_empty_queue(li); +} +END_TEST + +TEST_COLLECTION(switch) +{ + struct range switches = { LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_TABLET_MODE + 1}; + + litest_add("switch:has", switch_has_cap, LITEST_SWITCH, LITEST_ANY); + litest_add("switch:has", switch_has_lid_switch, LITEST_SWITCH, LITEST_ANY); + litest_add("switch:has", switch_has_tablet_mode_switch, LITEST_SWITCH, LITEST_ANY); + litest_add_ranged("switch:toggle", switch_toggle, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:toggle", switch_toggle_double, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:toggle", switch_down_on_init, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add("switch:toggle", switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY); + litest_add_ranged("switch:touchpad", switch_disable_touchpad, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_disable_touchpad_edge_scroll_interrupt, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_disable_touchpad_already_open, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_dont_resume_disabled_touchpad, LITEST_SWITCH, LITEST_ANY, &switches); + litest_add_ranged("switch:touchpad", switch_dont_resume_disabled_touchpad_external_mouse, LITEST_SWITCH, LITEST_ANY, &switches); + + litest_add_ranged_no_device("switch:keyboard", switch_suspend_with_keyboard, &switches); + litest_add_ranged_no_device("switch:touchpad", switch_suspend_with_touchpad, &switches); + + litest_add("lid:keyboard", lid_open_on_key, LITEST_SWITCH, LITEST_ANY); + litest_add("lid:keyboard", lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY); + litest_add_for_device("lid:buggy", lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3); + litest_add_for_device("lid:buggy", lid_update_hw_on_key_closed_on_init, LITEST_LID_SWITCH_SURFACE3); + litest_add_for_device("lid:buggy", lid_update_hw_on_key_multiple_keyboards, LITEST_LID_SWITCH_SURFACE3); + litest_add_for_device("lid:keypress", lid_key_press, LITEST_GPIO_KEYS); + + litest_add("tablet-mode:touchpad", tablet_mode_disable_touchpad_on_init, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:touchpad", tablet_mode_disable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:touchpad", tablet_mode_enable_touchpad_on_resume, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_disable_keyboard, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_disable_keyboard_on_init, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_disable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:keyboard", tablet_mode_enable_keyboard_on_resume, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:trackpoint", tablet_mode_disable_trackpoint, LITEST_SWITCH, LITEST_ANY); + litest_add("tablet-mode:trackpoint", tablet_mode_disable_trackpoint_on_init, LITEST_SWITCH, LITEST_ANY); + + litest_add("lid:dock", dock_toggle, LITEST_SWITCH, LITEST_ANY); +} diff --git a/test/test-tablet.c b/test/test-tablet.c new file mode 100644 index 0000000..f4915bc --- /dev/null +++ b/test/test-tablet.c @@ -0,0 +1,5880 @@ +/* + * 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 +#include + +#include "libinput-util.h" +#include "evdev-tablet.h" +#include "litest.h" + +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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), + button); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), + button); + ck_assert_int_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; + 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: + ck_abort(); + } + + 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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), + LIBINPUT_BUTTON_STATE_PRESSED); + ck_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1); + libinput_event_destroy(event); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), + LIBINPUT_BUTTON_STATE_PRESSED); + ck_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 2); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + + litest_button_click(dev2, button, false); + litest_button_click(dev, button, false); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), + LIBINPUT_BUTTON_STATE_RELEASED); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); + ck_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 1); + libinput_event_destroy(event); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), + LIBINPUT_BUTTON_STATE_RELEASED); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); + ck_assert_int_eq(libinput_event_tablet_tool_get_seat_button_count(tev), 0); + 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_INTUOS); + 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); + libinput_dispatch(li); + } + + litest_drain_events(li); + litest_delete_device(dev); + libinput_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); + libinput_unref(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_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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_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_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert_int_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); + ck_assert_int_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_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + 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_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_tablet_proximity_out(dev); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + 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_motion(dev, 10, 20, axes); + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + 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_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_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_motion(dev, 10, 20, axes); + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 10, 20, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + 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_motion(dev, 10, 20, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_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); + libinput_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_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_DOWN); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_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); + ck_assert_double_lt(last_x, x); + ck_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_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + libinput_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_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_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); + ck_assert_double_ne(last_x, x); + ck_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 } + }; + unsigned int axis = _i; /* ranged test */ + double x, y, last_x, last_y; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + /* enough events to get the history going */ + litest_axis_set_value(axes, ABS_PRESSURE, 20); + for (int i = 1; i < 10; i++) { + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10 + i, 10 + i, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + } + litest_drain_events(li); + + litest_tablet_motion(dev, 20, 20, axes); + libinput_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); + litest_push_event_frame(dev); + switch (axis) { + case ABS_X: + litest_tablet_motion(dev, 40, 20, axes); + break; + case ABS_Y: + litest_tablet_motion(dev, 20, 40, axes); + break; + default: + abort(); + } + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_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); + ck_assert_double_ne(last_x, x); + ck_assert_double_ne(last_y, y); + 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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_axis_set_value(axes, ABS_DISTANCE, 10); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + + litest_drain_events(li); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + litest_drain_events(li); + + litest_tablet_motion(dev, 30, 30, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + litest_drain_events(li); + + litest_tablet_motion(dev, 40, 80, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + litest_drain_events(li); + + litest_button_click(dev, button, false); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_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_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + litest_drain_events(li); + + litest_button_click(dev, button, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_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_INTUOS); + 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_motion(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + litest_drain_events(li); + litest_delete_device(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); + libinput_event_destroy(event); + + libinput_unref(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); + libinput_dispatch(li); + + while ((event = libinput_get_event(li))) { + if (libinput_event_get_type(event) == + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { + struct libinput_tablet_tool * tool; + + ck_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); + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), type); + } + libinput_event_destroy(event); + } + ck_assert(have_tool_update); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_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); + } + ck_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); + libinput_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, -1); + 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); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + litest_assert_tablet_button_event(li, + button, + LIBINPUT_BUTTON_STATE_RELEASED); + litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, -1); + 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; + uint32_t button; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + 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 + */ + for (button = BTN_STYLUS; button <= BTN_STYLUS2; 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); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_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))); + + ck_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); + libinput_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); + + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_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)) { + ck_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)) { + ck_assert(libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)); + ck_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, -1); + + 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); + libinput_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); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + litest_drain_events_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, -1); + + 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); + + ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_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)) { + ck_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)) { + ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)); + ck_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_dispatch(li); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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(); + libinput_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(); + libinput_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(); + libinput_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_no_timeout) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); + litest_tablet_motion(dev, 12, 12, axes); + litest_drain_events(li); + + litest_timeout_tablet_proxout(); + litest_assert_empty_queue(li); + + litest_tablet_proximity_out(dev); + /* The forced prox out */ + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + litest_assert_empty_queue(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_INTUOS); + + litest_tablet_proximity_in(dev, 10, 10, NULL); + litest_drain_events(li); + + litest_delete_device(dev); + libinput_dispatch(li); + + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + libinput_unref(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); + libinput_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); + ck_assert(x_changed); + ck_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); + libinput_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); + + ck_assert(x_changed); + ck_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); + + ck_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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(); + + ck_assert(!libinput_device_config_left_handed_is_available(dev->libinput_device)); +} +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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_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); + + ck_assert_double_lt(tx, 0); + ck_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); + ck_assert_notnull(abs); + tilt_center_x = (abs->maximum - abs->minimum + 1) / 2; + + abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y); + ck_assert_notnull(abs); + tilt_center_y = (abs->maximum - abs->minimum + 1) / 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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_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); + ck_assert_int_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; + + status = libinput_device_config_left_handed_set(dev->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_drain_events(li); + + abs = libevdev_get_abs_info(dev->evdev, ABS_Z); + ck_assert_notnull(abs); + scale = (abs->maximum - abs->minimum + 1)/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); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); + val = libinput_event_tablet_tool_get_rotation(tev); + + /* artpen has a 90 deg offset cw */ + ck_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); + + libinput_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); + libinput_dispatch(li); + ck_assert_int_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); + ck_assert_notnull(tablet_event); + + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); + + ck_assert(x > last_x); + ck_assert(y < last_y); + + last_x = x; + last_y = y; + libinput_event_destroy(event); + } + + ck_assert_int_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); + libinput_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); + libinput_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); + ck_assert_double_lt(val, 0.0); + val = libinput_event_tablet_tool_get_y(tablet_event); + ck_assert_double_gt(val, 0.0); + + val = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); + ck_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); + libinput_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); + libinput_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); + ck_assert_double_gt(val, 0.0); + val = libinput_event_tablet_tool_get_y(tablet_event); + ck_assert_double_lt(val, 0.0); + + val = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); + ck_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); + ck_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); + + libinput_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); + ck_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); + libinput_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); + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 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; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, NULL); + libinput_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); + + ck_assert_int_eq(libinput_device_get_id_vendor(dev->libinput_device), + 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: + ck_abort(); + } + + ck_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); + libinput_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); + + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 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); + + libinput_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); + + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 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); + libinput_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); + + ck_assert_notnull(tool); + ck_assert(tool == libinput_tablet_tool_ref(tool)); + ck_assert(tool == libinput_tablet_tool_unref(tool)); + libinput_event_destroy(event); + + ck_assert(libinput_tablet_tool_unref(tool) == NULL); +} +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); + libinput_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); + ck_assert_notnull(tool); + + ck_assert(libinput_tablet_tool_get_user_data(tool) == NULL); + libinput_tablet_tool_set_user_data(tool, userdata); + ck_assert(libinput_tablet_tool_get_user_data(tool) == userdata); + libinput_tablet_tool_set_user_data(tool, NULL); + ck_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); + libinput_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); + libinput_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); + libinput_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_INTUOS); + 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]); + + libinput_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 */ + ck_assert_notnull(tool[0]); + ck_assert_notnull(tool[1]); + ck_assert_ptr_eq(tool[0], tool[1]); + + litest_delete_device(dev[0]); + litest_delete_device(dev[1]); + libinput_unref(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, + 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); + + libinput_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 */ + ck_assert_notnull(tool[0]); + ck_assert_notnull(tool[1]); + ck_assert_ptr_ne(tool[0], tool[1]); + + litest_delete_device(dev[0]); + litest_delete_device(dev[1]); + libinput_unref(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); + libinput_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); + ck_assert_int_eq(serial, 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); + libinput_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); + libinput_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); + ck_assert_int_eq(serial, 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); + libinput_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); + ck_assert_int_eq(serial, 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); + libinput_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); + ck_assert_int_eq(serial, 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; + + ck_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); + intuos = litest_add_device(li, LITEST_WACOM_INTUOS); + litest_drain_events(li); + + litest_event(bamboo, EV_KEY, BTN_TOOL_PEN, 1); + litest_event(bamboo, EV_SYN, SYN_REPORT, 0); + + libinput_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); + + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_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); + libinput_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); + + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_assert(libinput_tablet_tool_has_tilt(tool)); + + libinput_event_destroy(event); + litest_assert_empty_queue(li); + + litest_delete_device(bamboo); + litest_delete_device(intuos); + libinput_unref(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_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; + + litest_drain_events(li); + + for (tt = types; tt->code != -1; tt++) { + 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_push_event_frame(dev); + litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); + litest_tablet_proximity_in(dev, 50, 50, axes); + litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); + litest_event(dev, EV_KEY, tt->code, 1); + litest_pop_event_frame(dev); + libinput_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); + + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), + tt->type); + + libinput_event_destroy(event); + litest_assert_empty_queue(li); + + litest_push_event_frame(dev); + litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN); + litest_tablet_proximity_out(dev); + litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN); + litest_event(dev, EV_KEY, tt->code, 0); + litest_pop_event_frame(dev); + litest_drain_events(li); + } +} +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; + unsigned int 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, -1); + + litest_assert_empty_queue(li); + + litest_tablet_motion(dev, 10, 20, axes); + libinput_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, -1); + + litest_tablet_motion(dev, 30, 40, axes); + libinput_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); + ck_assert_int_eq(serial, + libinput_tablet_tool_get_serial(tool)); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, + -1); + libinput_unref(li); +} +END_TEST + +static void tool_switch_warning(struct libinput *libinput, + enum libinput_log_priority priority, + const char *format, + va_list args) +{ + int *warning_triggered = (int*)libinput_get_user_data(libinput); + + if (priority == LIBINPUT_LOG_PRIORITY_ERROR && + strstr(format, "Multiple tools active simultaneously")) + (*warning_triggered)++; +} + + +START_TEST(tool_direct_switch_warning) +{ + 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 warning_triggered = 0; + + if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) + return; + + libinput_set_user_data(li, &warning_triggered); + libinput_log_set_handler(li, tool_switch_warning); + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + ck_assert_int_eq(warning_triggered, 1); + litest_restore_log_handler(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_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_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); + + /* Direct tool switch after proximity in is ignored */ + litest_disable_log_handler(li); + litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_assert_empty_queue(li); + litest_restore_log_handler(li); + + litest_tablet_motion(dev, 20, 30, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), + tool); + libinput_event_destroy(event); + + /* Direct tool switch during sequence in is ignored */ + litest_disable_log_handler(li); + litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_assert_empty_queue(li); + + 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); + libinput_dispatch(li); + litest_restore_log_handler(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert_ptr_eq(libinput_event_tablet_tool_get_tool(tev), + tool); + libinput_event_destroy(event); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_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(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); + libinput_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); + ck_assert_notnull(tool); + ck_assert_int_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); + libinput_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); + ck_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); + ck_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); + libinput_dispatch(li); + litest_event(dev, EV_KEY, code, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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_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); + libinput_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); + ck_assert_notnull(tool); + libinput_tablet_tool_ref(tool); + + libinput_event_destroy(event); + + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); + + val = libinput_event_tablet_tool_get_wheel_delta(tev); + ck_assert_int_eq(val, 15); + + val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); + ck_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, (abs->maximum - abs->minimum)/i); + abs = libevdev_get_abs_info(dev->evdev, ABS_Y); + litest_event(dev, EV_ABS, ABS_Y, (abs->maximum - abs->minimum)/i); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); + + val = libinput_event_tablet_tool_get_wheel_delta(tev); + ck_assert_int_eq(val, 0); + + val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); + ck_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_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); + libinput_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); + + ck_assert_notnull(tool); + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), + LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); + + ck_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; + double scale; + double expected; + int v; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_AIRBRUSH)) + return; + + litest_drain_events(li); + + abs = libevdev_get_abs_info(dev->evdev, ABS_WHEEL); + ck_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); + + scale = abs->maximum - abs->minimum; + for (v = abs->minimum; v < abs->maximum; v += 8) { + litest_event(dev, EV_ABS, ABS_WHEEL, v); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(libinput_event_tablet_tool_slider_has_changed(tev)); + val = libinput_event_tablet_tool_get_slider_position(tev); + + expected = ((v - abs->minimum)/scale) * 2 - 1; + ck_assert_double_eq(val, expected); + ck_assert_double_ge(val, -1.0); + ck_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_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); + libinput_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); + ck_assert_notnull(tool); + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), + LIBINPUT_TABLET_TOOL_TYPE_PEN); + ck_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_drain_events(li); + + abs = libevdev_get_abs_info(dev->evdev, ABS_Z); + ck_assert_notnull(abs); + scale = (abs->maximum - abs->minimum + 1)/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); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); + val = libinput_event_tablet_tool_get_rotation(tev); + + /* artpen has a 90 deg offset cw */ + ck_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); + libinput_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); + ck_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 pressure but we're still below the tip threshold */ + litest_axis_set_value(axes, ABS_PRESSURE, 1); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + + ck_assert_double_eq(pressure, 0.0); + ck_assert_double_eq(distance, 0.0); + libinput_event_destroy(event); + + /* We have pressure and we're above the threshold now */ + litest_axis_set_value(axes, ABS_PRESSURE, 5.5); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + + ck_assert_double_gt(pressure, 0.0); + ck_assert_double_eq(distance, 0.0); + + libinput_event_destroy(event); +} +END_TEST + +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 = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + + rc = libinput_device_config_calibration_has_matrix(d); + ck_assert_int_eq(rc, has_calibration); + rc = libinput_device_config_calibration_get_matrix(d, calibration); + ck_assert_int_eq(rc, 0); + rc = libinput_device_config_calibration_get_default_matrix(d, + calibration); + ck_assert_int_eq(rc, 0); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + if (has_calibration) + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + else + ck_assert_int_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 } + }; + int has_calibration; + double x, y, dx, dy, mdx, mdy; + + has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + if (!has_calibration) + return; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_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); + libinput_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_drain_events(li); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_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); + libinput_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); + + ck_assert_double_gt(dx, mdx * 2 - 1); + ck_assert_double_lt(dx, mdx * 2 + 1); + ck_assert_double_gt(dy, mdy * 2 - 1); + ck_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 } + }; + int has_calibration; + double x, y; + + has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + if (!has_calibration) + return; + + litest_drain_events(li); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_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); + + ck_assert_double_gt(x, 49.0); + ck_assert_double_lt(x, 51.0); + ck_assert_double_gt(y, 99.0); + ck_assert_double_lt(y, 100.0); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + litest_tablet_proximity_in(dev, 50, 50, axes); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + + calibration[0] = 1; + calibration[4] = 0.5; + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_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); + + ck_assert(x > 99.0); + ck_assert(x < 100.0); + ck_assert(y > 49.0); + ck_assert(y < 51.0); + + litest_tablet_proximity_out(dev); +} +END_TEST + +START_TEST(tablet_pressure_offset) +{ + 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, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* This activates the pressure thresholds */ + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + + /* Put the pen down, with a pressure high enough to meet the + * threshold */ + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 25); + + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_drain_events(li); + + /* 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); + libinput_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); + + /* we can't actually get a real 0.0 because that would trigger a tip + up. but it's close enough to zero. */ + ck_assert_double_lt(pressure, 0.01); + + libinput_event_destroy(event); + litest_drain_events(li); + + litest_axis_set_value(axes, ABS_PRESSURE, 21); + litest_tablet_motion(dev, 70, 70, axes); + + libinput_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); + + ck_assert_double_lt(pressure, 0.015); + libinput_event_destroy(event); + + + /* Make sure we can reach the upper range too */ + litest_axis_set_value(axes, ABS_PRESSURE, 100); + litest_tablet_motion(dev, 70, 70, axes); + + libinput_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); + + ck_assert_double_ge(pressure, 1.0); + 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 libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* offset 20 on prox in */ + 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); + + /* a higher pressure value leaves it as-is */ + litest_tablet_proximity_in(dev, 5, 100, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + pressure = libinput_event_tablet_tool_get_pressure(tev); + ck_assert_double_eq(pressure, 0.0); + + libinput_event_destroy(event); + litest_drain_events(li); + + /* trigger the pressure threshold */ + litest_axis_set_value(axes, ABS_PRESSURE, 15); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_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); + + /* offset is 10, value is 15, so that's a around 5% of the + * remaining range */ + ck_assert_double_eq_tol(pressure, 0.05, 0.01); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_increase) +{ + 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, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* offset 20 on first prox in */ + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + + /* offset 30 on second 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_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_drain_events(li); + + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + /* offset 20, value 30 leaves us with 12% of the remaining 90 range */ + ck_assert_double_eq_tol(pressure, 0.12, 0.01); + libinput_event_destroy(event); + + litest_drain_events(li); + + litest_axis_set_value(axes, ABS_PRESSURE, 20); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + + ck_assert_double_eq(pressure, 0.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) +{ + int *warning_triggered = (int*)libinput_get_user_data(libinput); + + if (priority == LIBINPUT_LOG_PRIORITY_ERROR && + strstr(format, "pressure offset greater")) + (*warning_triggered)++; +} + +START_TEST(tablet_pressure_min_max) +{ + 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 p; + + if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) + return; + + litest_tablet_proximity_in(dev, 5, 50, axes); + litest_drain_events(li); + libinput_dispatch(li); + + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 1); + litest_tablet_motion(dev, 5, 50, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + ck_assert(libinput_event_tablet_tool_pressure_has_changed(tev)); + p = libinput_event_tablet_tool_get_pressure(tev); + ck_assert_double_ge(p, 0.0); + libinput_event_destroy(event); + + /* 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); + libinput_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); + ck_assert_double_ge(p, 1.0); + libinput_event_destroy(event); +} +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); + libinput_dispatch(li); + + for (pressure = 10; pressure <= 100; pressure += 10) { + litest_axis_set_value(axes, ABS_PRESSURE, pressure); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + ck_assert_double_ge(p, 0.0); + ck_assert_double_le(p, 1.0); + libinput_event_destroy(event); + } +} +END_TEST + +START_TEST(tablet_pressure_offset_exceed_threshold) +{ + 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, 70 }, + { ABS_PRESSURE, 30 }, + { -1, -1 }, + }; + double pressure; + int warning_triggered = 0; + + litest_drain_events(li); + + libinput_set_user_data(li, &warning_triggered); + + libinput_log_set_handler(li, pressure_threshold_warning); + litest_tablet_proximity_in(dev, 5, 100, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + pressure = libinput_event_tablet_tool_get_pressure(tev); + ck_assert_double_gt(pressure, 0.0); + libinput_event_destroy(event); + + ck_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 libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + 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_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + pressure = libinput_event_tablet_tool_get_pressure(tev); + ck_assert_double_gt(pressure, 0.0); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_none_for_small_distance) +{ + 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, 20 }, + { -1, -1 }, + }; + double pressure; + + /* 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); + libinput_dispatch(li); + + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 21); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + litest_drain_events(li); + + litest_axis_set_value(axes, ABS_PRESSURE, 20); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + ck_assert_double_gt(pressure, 0.0); + + libinput_event_destroy(event); +} +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); + libinput_dispatch(li); + + for (distance = 0; distance <= 100; distance += 10) { + litest_axis_set_value(axes, ABS_DISTANCE, distance); + litest_tablet_motion(dev, 70, 70, axes); + libinput_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); + ck_assert_double_ge(dist, 0.0); + ck_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); + libinput_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); + ck_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); + libinput_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); + ck_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); + libinput_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); + ck_assert_double_le(tx, -50); + ck_assert_double_ge(tx, -52); + + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_ge(ty, -65); + ck_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); + libinput_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); + ck_assert_double_ge(tx, expected_tx - 2); + ck_assert_double_le(tx, expected_tx + 2); + + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_ge(ty, -65); + ck_assert_double_lt(ty, -63); + + libinput_event_destroy(event); + + expected_tx = tx + 6.04; + } + + /* the last event must reach the max */ + ck_assert_double_ge(tx, 63.0); + ck_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); + libinput_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); + ck_assert_double_le(ty, -50); + ck_assert_double_ge(ty, -52); + + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_ge(tx, -65); + ck_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); + libinput_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); + ck_assert_double_ge(ty, expected_ty - 2); + ck_assert_double_le(ty, expected_ty + 2); + + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_ge(tx, -65); + ck_assert_double_lt(tx, -63); + + libinput_event_destroy(event); + + expected_ty = ty + 6; + } + + /* the last event must reach the max */ + ck_assert_double_ge(ty, 63.0); + ck_assert_double_le(tx, 64.0); +} +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; + + ck_assert(libinput_device_config_accel_is_available(device)); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profiles = libinput_device_config_accel_get_profiles(device); + ck_assert_int_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, 0); + ck_assert_int_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, 0); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_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); + libinput_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); + ck_assert(dx == 0.0); + ck_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); + libinput_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); + ck_assert(dx > 0.0); + ck_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); + libinput_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); + ck_assert(dx < 0.0); + ck_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); + libinput_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); + ck_assert(dx == 0.0); + ck_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); + libinput_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); + ck_assert(dx == 0.0); + ck_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_push_event_frame(dev); + litest_tablet_motion(dev, 30, 20, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert(libinput_event_tablet_tool_x_has_changed(tev)); + ck_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); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + /* normal motion */ + litest_tablet_motion(dev, 40, 30, axes); + libinput_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); + ck_assert(dx > 0.0); + ck_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_push_event_frame(dev); + litest_tablet_motion(dev, 50, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert(libinput_event_tablet_tool_x_has_changed(tev)); + ck_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); + ck_assert(dx == 0.0); + ck_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; + + status = libinput_device_config_calibration_set_matrix( + dev->libinput_device, + calibration); + ck_assert_int_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); + libinput_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); + ck_assert(dx < 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 5, 10, axes); + libinput_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); + ck_assert(dx > 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 20, axes); + libinput_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); + ck_assert(dx == 0.0); + ck_assert(dy < 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 5, axes); + libinput_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); + ck_assert(dx == 0.0); + ck_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_INTUOS: + return LITEST_WACOM_FINGER; + case LITEST_WACOM_FINGER: + return LITEST_WACOM_INTUOS; + 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; + } +} + +START_TEST(touch_arbitration) +{ + 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; + double x, y; + double tx, ty; + + other = paired_device(dev); + if (other == LITEST_NO_DEVICE) + return; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); + + 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); + + tx = 20; + ty = 40; + x = 21; + 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(); + libinput_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(); + libinput_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); + libinput_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); +} +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; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); + if (is_touchpad) + return; + + x = 20; + y = 45; + + 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); + libinput_dispatch(li); + litest_assert_touch_sequence(li); + /* tablet event so we don't time out for proximity */ + litest_tablet_motion(dev, x, y - 0.1, axes); + litest_drain_events(li); + + /* above rect */ + litest_touch_sequence(finger, 0, x + 2, y - 35, x + 20, y - 10, 3); + libinput_dispatch(li); + litest_assert_touch_sequence(li); + /* tablet event so we don't time out for proximity */ + litest_tablet_motion(dev, x, y + 0.1, axes); + litest_drain_events(li); + + /* right of rect */ + litest_touch_sequence(finger, 0, x + 80, y + 2, x + 20, y + 10, 3); + libinput_dispatch(li); + litest_assert_touch_sequence(li); + /* tablet event so we don't time out for proximity */ + litest_tablet_motion(dev, x, y - 0.1, axes); + litest_drain_events(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); + libinput_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; + + 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_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); + libinput_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; + + finger = litest_add_device(li, other); + + is_touchpad = !libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT); + + 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); + libinput_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); + libinput_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; + + tablet = litest_add_device(li, other); + + is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + + /* 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); + ck_assert_int_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(); + libinput_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); + ck_assert_int_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); + libinput_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; + + 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); + libinput_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; + + tablet = litest_add_device(li, other); + + is_touchpad = !libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + + libinput_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(); + libinput_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); + libinput_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; + + 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); + libinput_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; + + 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_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + litest_assert_empty_queue(li); + + litest_delete_device(finger); +} +END_TEST + +static void +verify_left_handed_tablet_motion(struct litest_device *tablet, + struct libinput *li, + int x, int 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); + libinput_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); + libinput_dispatch(li); + litest_drain_events(li); + verify_left_handed_tablet_motion(tablet, li, x, y, left_handed); + litest_tablet_proximity_out(tablet); + libinput_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + p = litest_is_motion_event(event); + x = libinput_event_pointer_get_dx(p); + y = libinput_event_pointer_get_dy(p); + libinput_event_destroy(event); + + event = libinput_get_event(li); + ck_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); + libinput_dispatch(li); +} + +START_TEST(tablet_rotation_left_handed) +{ + struct litest_device *tablet = litest_current_device(); + enum litest_device_type other; + struct litest_device *finger; + struct libinput *li = tablet->libinput; + unsigned int transition = _i; /* ranged test */ + bool tablet_from, touch_from, tablet_to, touch_to; + bool enabled_from, enabled_to; + + other = paired_device(tablet); + if (other == LITEST_NO_DEVICE) + return; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) + goto out; + + 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; + + 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); +} +END_TEST + +START_TEST(tablet_rotation_left_handed_configuration) +{ + struct litest_device *tablet = litest_current_device(); + enum litest_device_type other; + struct litest_device *finger; + struct libinput *li = tablet->libinput; + unsigned int transition = _i; /* ranged test */ + 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; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) + goto out; + + tablet_from = !!(transition & bit(0)); + touch_from = !!(transition & bit(1)); + tablet_to = !!(transition & bit(2)); + touch_to = !!(transition & bit(3)); + + 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); + libinput_dispatch(li); + tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); + touch_enabled = libinput_device_config_left_handed_get(touch_dev); + ck_assert_int_eq(tablet_enabled, tablet_from); + ck_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); + libinput_dispatch(li); + tablet_enabled = libinput_device_config_left_handed_get(tablet_dev); + touch_enabled = libinput_device_config_left_handed_get(touch_dev); + ck_assert_int_eq(tablet_enabled, tablet_to); + ck_assert_int_eq(touch_enabled, touch_to); + +out: + litest_delete_device(finger); +} +END_TEST + +START_TEST(tablet_rotation_left_handed_while_in_prox) +{ + struct litest_device *tablet = litest_current_device(); + enum litest_device_type other; + struct litest_device *finger; + struct libinput *li = tablet->libinput; + unsigned int transition = _i; /* ranged test */ + 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; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) + goto out; + + 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; + + libinput_device_config_left_handed_set(finger->libinput_device, + touch_from); + libinput_device_config_left_handed_set(tablet->libinput_device, + tablet_from); + + + /* Tablet in-prox when setting to left-handed */ + tx = 60; + ty = 60; + litest_tablet_proximity_in(tablet, tx, ty, NULL); + libinput_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_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 intersperce 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); + libinput_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_tablet_proximity_out(tablet); + libinput_dispatch(li); + litest_timeout_tablet_proxout(); + 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); +} +END_TEST + +START_TEST(tablet_rotation_left_handed_while_touch_down) +{ + struct litest_device *tablet = litest_current_device(); + enum litest_device_type other; + struct litest_device *finger; + struct libinput *li = tablet->libinput; + unsigned int transition = _i; /* ranged test */ + 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; + + finger = litest_add_device(li, other); + litest_drain_events(li); + + if (libevdev_has_property(finger->evdev, INPUT_PROP_DIRECT)) + goto out; + + 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; + + 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); + libinput_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); +} +END_TEST + +START_TEST(tablet_rotation_left_handed_add_touchpad) +{ + struct litest_device *tablet = litest_current_device(); + enum litest_device_type other; + struct litest_device *finger; + struct libinput *li = tablet->libinput; + unsigned int transition = _i; /* ranged test */ + bool tablet_from, touch_from, tablet_to, touch_to; + bool enabled_from, enabled_to; + + other = paired_device(tablet); + if (other == LITEST_NO_DEVICE) + return; + + 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 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); + + 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); +} +END_TEST + +START_TEST(tablet_rotation_left_handed_add_tablet) +{ + 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; + + other = paired_device(finger); + if (other == LITEST_NO_DEVICE) + return; + + 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); + + 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); +} +END_TEST +START_TEST(huion_static_btn_tool_pen) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + int i; + + 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); + libinput_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(); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + libinput_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); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); + libinput_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); + libinput_dispatch(li); + } + litest_assert_only_typed_events(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + libinput_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); + libinput_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; + + 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); + + /* 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); + libinput_dispatch(li); + msleep(5); + } + litest_assert_only_typed_events(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + libinput_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; + bool with_timeout = _i; /* ranged test */ + 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 + */ + + 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); + libinput_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(); + libinput_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); + libinput_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_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_tablet_proximity_in(dev, 50, 50, NULL); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); + libinput_dispatch(li); + + for (i = 0; i < 10; i++) { + litest_tablet_motion(dev, 50 + i, 50 + i, NULL); + libinput_dispatch(li); + } + + litest_assert_only_typed_events(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + 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); + libinput_dispatch(li); + + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + litest_assert_empty_queue(li); +} +END_TEST + +TEST_COLLECTION(tablet) +{ + struct range with_timeout = { 0, 2 }; + struct range xyaxes = { ABS_X, ABS_Y + 1 }; + struct range lh_transitions = {0, 16}; /* 2 bits for in, 2 bits for out */ + + litest_add("tablet:tool", tool_ref, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool", tool_user_data, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool", tool_capability, LITEST_TABLET, LITEST_ANY); + litest_add_no_device("tablet:tool", tool_capabilities); + litest_add("tablet:tool", tool_type, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tool", tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); + litest_add("tablet:tool", tool_direct_switch_warning, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tool", tool_direct_switch_skip_tool_update, LITEST_TABLET, LITEST_ANY); + + /* Tablets hold back the proximity until the first event from the + * kernel, the totem sends it immediately */ + litest_add("tablet:tool", tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); + litest_add("tablet:tool_serial", tool_unique, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool_serial", tool_serial, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool_serial", tool_id, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool_serial", serial_changes_tool, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add("tablet:tool_serial", invalid_serials, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY); + litest_add_no_device("tablet:tool_serial", tools_with_serials); + litest_add_no_device("tablet:tool_serial", tools_without_serials); + litest_add_for_device("tablet:tool_serial", tool_delayed_serial, LITEST_WACOM_HID4800_PEN); + litest_add("tablet:proximity", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_in_out, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_in_button_down, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_out_button_up, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_has_axes, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_enter, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_in_out, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_click, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_press, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_release, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:proximity", proximity_out_slow_event, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_out_not_during_contact, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add_for_device("tablet:proximity", proximity_out_no_timeout, LITEST_WACOM_ISDV4_4200_PEN); + + litest_add_no_device("tablet:proximity", proximity_out_on_delete); + litest_add("tablet:button", button_down_up, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:button", button_seat_count, LITEST_TABLET, LITEST_ANY); + litest_add_no_device("tablet:button", button_up_on_delete); + litest_add("tablet:tip", tip_down_up, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_down_prox_in, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_up_prox_out, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_down_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_up_btn_change, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_down_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_up_motion, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add_ranged("tablet:tip", tip_up_motion_one_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY, &xyaxes); + litest_add("tablet:tip", tip_state_proximity, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_state_axis, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:tip", tip_state_button, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add_no_device("tablet:tip", tip_up_on_delete); + litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY); + litest_add_for_device("tablet:motion", motion_outside_bounds, LITEST_WACOM_CINTIQ_24HD); + litest_add("tablet:tilt", tilt_available, LITEST_TABLET|LITEST_TILT, LITEST_ANY); + litest_add("tablet:tilt", tilt_not_available, LITEST_TABLET, LITEST_TILT); + litest_add("tablet:tilt", tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY); + litest_add("tablet:tilt", tilt_y, LITEST_TABLET|LITEST_TILT, LITEST_ANY); + litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:left_handed", left_handed_tilt, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:left_handed", left_handed_mouse_rotation, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:left_handed", left_handed_artpen_rotation, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:left_handed", no_left_handed, LITEST_WACOM_CINTIQ); + litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_TOTEM); + litest_add("tablet:mouse", mouse_tool, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:mouse", mouse_buttons, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:mouse", mouse_rotation, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_ANY); + litest_add("tablet:mouse", mouse_wheel, LITEST_TABLET | LITEST_TOOL_MOUSE, LITEST_WHEEL); + litest_add("tablet:airbrush", airbrush_tool, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:airbrush", airbrush_slider, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:artpen", artpen_tool, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:artpen", artpen_rotation, LITEST_TABLET, LITEST_ANY); + + litest_add("tablet:time", tablet_time_usec, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:pressure", tablet_pressure_distance_exclusive, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + + /* The totem doesn't need calibration */ + litest_add("tablet:calibration", tablet_calibration_has_matrix, LITEST_TABLET, LITEST_TOTEM); + litest_add("tablet:calibration", tablet_calibration_set_matrix, LITEST_TABLET, LITEST_TOTEM); + litest_add("tablet:calibration", tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_TOTEM); + + litest_add("tablet:pressure", tablet_pressure_min_max, LITEST_TABLET, LITEST_ANY); + litest_add_for_device("tablet:pressure", tablet_pressure_range, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_decrease, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_increase, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:distance", tablet_distance_range, LITEST_WACOM_INTUOS); + + litest_add("tablet:relative", relative_no_profile, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_no_delta_prox_in, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_delta, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_no_delta_on_tip, LITEST_TABLET|LITEST_HOVER, LITEST_ANY); + litest_add("tablet:relative", relative_calibration, LITEST_TABLET, LITEST_ANY); + + litest_add("tablet:touch-arbitration", touch_arbitration, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_stop_touch, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_suspend_touch_device, LITEST_TOUCH, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_remove_touch, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_remove_tablet, LITEST_TOUCH, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_keep_ignoring, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_late_touch_lift, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_outside_rect, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); + litest_add("tablet:touch-arbitration", touch_arbitration_remove_after, LITEST_TABLET | LITEST_DIRECT, LITEST_ANY); + + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed, LITEST_TABLET, LITEST_ANY, &lh_transitions); + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed_configuration, LITEST_TABLET, LITEST_ANY, &lh_transitions); + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed_while_in_prox, LITEST_TABLET, LITEST_ANY, &lh_transitions); + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed_while_touch_down, LITEST_TABLET, LITEST_ANY, &lh_transitions); + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed_add_touchpad, LITEST_TABLET, LITEST_ANY, &lh_transitions); + litest_add_ranged("tablet:touch-rotation", tablet_rotation_left_handed_add_tablet, LITEST_TOUCHPAD, LITEST_ANY, &lh_transitions); + + litest_add_for_device("tablet:quirks", huion_static_btn_tool_pen, LITEST_HUION_TABLET); + litest_add_for_device("tablet:quirks", huion_static_btn_tool_pen_no_timeout_during_usage, LITEST_HUION_TABLET); + litest_add_ranged_for_device("tablet:quirks", huion_static_btn_tool_pen_disable_quirk_on_prox_out, LITEST_HUION_TABLET, &with_timeout); +} diff --git a/test/test-totem.c b/test/test-totem.c new file mode 100644 index 0000000..bafa8d2 --- /dev/null +++ b/test/test-totem.c @@ -0,0 +1,605 @@ +/* + * 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 + +#include "libinput-util.h" +#include "evdev-tablet.h" +#include "litest.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); + libinput_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); + + ck_assert_int_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); + libinput_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); + + ck_assert(libinput_tablet_tool_has_rotation(tool)); + ck_assert(libinput_tablet_tool_has_size(tool)); + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert_int_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); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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); + ck_assert_int_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 = (abs->maximum - abs->minimum + 1)/abs->resolution; + abs = libevdev_get_abs_info(dev->evdev, ABS_MT_POSITION_Y); + h = (abs->maximum - abs->minimum + 1)/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); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_DEVICE_ADDED, + -1); + 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); + ck_assert_int_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); + + ck_assert_double_gt(x, w/2 - 1); + ck_assert_double_lt(x, w/2 + 1); + ck_assert_double_gt(y, h/2 - 1); + ck_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); + ck_assert_int_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); + + ck_assert_double_gt(x, w/2 - 1); + ck_assert_double_lt(x, w/2 + 1); + ck_assert_double_gt(y, h/2 - 1); + ck_assert_double_lt(y, h/2 + 1); + + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + + libinput_unref(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); + + libinput_dispatch(li); + event = libinput_get_event(li); + t = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_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); + ck_assert_int_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); + libinput_unref(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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + ck_assert(libinput_event_tablet_tool_x_has_changed(t)); + ck_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) { + ck_assert_double_gt(current_x, old_x); + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + ck_assert(!libinput_event_tablet_tool_x_has_changed(t)); + ck_assert(!libinput_event_tablet_tool_y_has_changed(t)); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(t)); + + r = libinput_event_tablet_tool_get_rotation(t); + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + ck_assert(!libinput_event_tablet_tool_x_has_changed(t)); + ck_assert(!libinput_event_tablet_tool_y_has_changed(t)); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(t)); + + r = libinput_event_tablet_tool_get_rotation(t); + ck_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + ck_assert(libinput_event_tablet_tool_size_major_has_changed(t)); + ck_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); + + ck_assert_double_eq(smaj, 71.8); + ck_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); + libinput_dispatch(li); + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(t), BTN_0); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(t), + LIBINPUT_BUTTON_STATE_PRESSED); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + ck_assert_int_eq(libinput_event_tablet_tool_get_button(t), BTN_0); + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(t), + LIBINPUT_BUTTON_STATE_RELEASED); + ck_assert_int_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); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_DEVICE_ADDED, + -1); + 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); + ck_assert_int_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); + ck_assert_int_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); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + /* but buttons after this should be sent */ + litest_button_click(dev, BTN_0, true); + libinput_dispatch(li); + litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_PRESSED); + litest_button_click(dev, BTN_0, false); + libinput_dispatch(li); + litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED); + + libinput_unref(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); + libinput_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); + libinput_unref(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); + libinput_dispatch(li); + litest_assert_touch_down_frame(li); + litest_touch_move_to(touch, 0, 50, 50, 50, 70, 10); + libinput_dispatch(li); + while (libinput_next_event_type(li)) { + litest_assert_touch_motion_frame(li); + } + + litest_tablet_proximity_in(totem, 50, 70, NULL); + 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); + 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); + libinput_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); + libinput_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); + libinput_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); + libinput_dispatch(li); + + litest_assert_touch_sequence(li); + + litest_delete_device(touch); +} +END_TEST + +TEST_COLLECTION(totem) +{ + litest_add("totem:tool", totem_type, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:tool", totem_axes, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:proximity", totem_proximity_in_out, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:proximity", totem_proximity_in_on_init, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:proximity", totem_proximity_out_on_suspend, LITEST_TOTEM, LITEST_ANY); + + litest_add("totem:axes", totem_motion, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:axes", totem_rotation, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:axes", totem_size, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:button", totem_button, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:button", totem_button_down_on_init, LITEST_TOTEM, LITEST_ANY); + litest_add_no_device("totem:button", totem_button_up_on_delete); + + litest_add("totem:arbitration", totem_arbitration_below, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:arbitration", totem_arbitration_during, LITEST_TOTEM, LITEST_ANY); + litest_add("totem:arbitration", totem_arbitration_outside_rect, LITEST_TOTEM, LITEST_ANY); +} diff --git a/test/test-touch.c b/test/test-touch.c new file mode 100644 index 0000000..81accf9 --- /dev/null +++ b/test/test-touch.c @@ -0,0 +1,1392 @@ +/* + * 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 "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); + libinput_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); + } + ck_assert_int_eq(have_frame_event, 1); + + litest_touch_down(dev, 1, 10, 10); + libinput_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); + } + ck_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); + libinput_dispatch(li); + + litest_assert_touch_down_frame(li); + + litest_touch_up(dev, 0); + libinput_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_TOUCH, + "litest Highres touch device", + NULL, abs, NULL); + + libinput = dev->libinput; + + litest_touch_down(dev, 0, 100, 100); + + libinput_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); + ck_assert_int_eq(fx, 1919.0); + fy = libinput_event_touch_get_y_transformed(tev, 720); + ck_assert_int_eq(fy, 719.0); + + tested = true; + + libinput_event_destroy(ev); + } + + ck_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; + + libinput_dispatch(li); + ev = libinput_get_event(li); + tev = litest_is_touch_event(ev, type); + slot = libinput_event_touch_get_slot(tev); + ck_assert_int_eq(slot, slot); + slot = libinput_event_touch_get_seat_slot(tev); + ck_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_TOUCH); + + 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_TOUCH, + "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); + + libinput_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); + libinput_dispatch(libinput); + } + + ck_assert_notnull(ev); + ck_assert_int_gt(slot_count, 0); + + libinput_dispatch(libinput); + do { + type = libinput_event_get_type(ev); + ck_assert_int_ne(type, LIBINPUT_EVENT_TOUCH_DOWN); + if (type == LIBINPUT_EVENT_TOUCH_UP) + slot_count--; + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } while ((ev = libinput_get_event(libinput))); + + ck_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); + libinput_dispatch(libinput); + litest_restore_log_handler(libinput); + + while ((ev = libinput_get_event(libinput))) { + switch (libinput_event_get_type(ev)) { + case LIBINPUT_EVENT_TOUCH_DOWN: + ck_assert(!got_down); + got_down = true; + break; + case LIBINPUT_EVENT_TOUCH_UP: + ck_assert(got_down); + ck_assert(!got_up); + got_up = true; + break; + default: + break; + } + + libinput_event_destroy(ev); + libinput_dispatch(libinput); + } + + ck_assert(got_down); + ck_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); + libinput_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); + + ck_assert_int_eq(round(x), round(width * matrix[0])); + ck_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); + libinput_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... */ +#define almost_equal(a_, b_) \ + { ck_assert_int_ge((a_) + 0.5, (b_) - 1); \ + ck_assert_int_le((a_) + 0.5, (b_) + 1); } + switch(i) { + case 0: /* 0 deg */ + almost_equal(x, width * 0.8); + almost_equal(y, height * 0.2); + break; + case 1: /* 90 deg cw */ + almost_equal(x, width * 0.8); + almost_equal(y, height * 0.8); + break; + case 2: /* 180 deg cw */ + almost_equal(x, width * 0.2); + almost_equal(y, height * 0.8); + break; + case 3: /* 270 deg cw */ + almost_equal(x, width * 0.2); + almost_equal(y, height * 0.2); + break; + } +#undef almost_equal + + 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); + + libinput_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 */ + ck_assert_int_ge(round(x), width + round(width * matrix[2]) - 1); + ck_assert_int_ge(round(y), height + round(height * matrix[5]) - 1); + ck_assert_int_le(round(x), width + round(width * matrix[2]) + 1); + ck_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); + ck_assert_int_eq(rc, 1); + + rc = libinput_device_config_calibration_get_matrix(dev->libinput_device, + matrix); + ck_assert_int_eq(rc, 1); + + ck_assert_double_eq(matrix[0], 1.2); + ck_assert_double_eq(matrix[1], 3.4); + ck_assert_double_eq(matrix[2], 5.6); + ck_assert_double_eq(matrix[3], 7.8); + ck_assert_double_eq(matrix[4], 9.10); + ck_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); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + libinput_device_config_calibration_get_matrix(dev->libinput_device, matrix); + ck_assert_int_eq(memcmp(matrix, identity, sizeof(matrix)), 0); + + status = libinput_device_config_calibration_set_matrix(dev->libinput_device, nonidentity); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + libinput_device_config_calibration_get_matrix(dev->libinput_device, matrix); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + libinput_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); + + ck_assert_notnull(device); + rc = libinput_device_config_calibration_has_matrix(device); + ck_assert_int_eq(rc, 1); + + rc = libinput_device_config_calibration_get_matrix(device, matrix); + ck_assert_int_eq(rc, 1); + + ck_assert_double_eq(matrix[0], 1.2); + ck_assert_double_eq(matrix[1], 3.4); + ck_assert_double_eq(matrix[2], 5.6); + ck_assert_double_eq(matrix[3], 7.8); + ck_assert_double_eq(matrix[4], 9.10); + ck_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); + ck_assert_int_eq(rc, 0); + + rc = libinput_device_config_left_handed_get(d); + ck_assert_int_eq(rc, 0); + + rc = libinput_device_config_left_handed_get_default(d); + ck_assert_int_eq(rc, 0); + + status = libinput_device_config_left_handed_set(d, 0); + ck_assert_int_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; + + libinput_dispatch(li); + + event = libinput_get_event(li); + device = libinput_event_get_device(event); + + ck_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 */ + ck_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; + + ck_assert_int_ne(libinput_next_event_type(li), + LIBINPUT_EVENT_NONE); + + ck_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); + libinput_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); + libinput_dispatch(li); + + while ((ev = libinput_get_event(li))) { + if (libinput_event_get_type(ev) == + LIBINPUT_EVENT_TOUCH_FRAME) { + libinput_event_destroy(ev); + continue; + } + ck_assert_int_eq(libinput_event_get_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); + + ck_assert_int_gt(x, oldx); + ck_assert_int_lt(y, oldy); + + oldx = x; + oldy = y; + + libinput_event_destroy(ev); + } + + litest_touch_up(dev, 0); + libinput_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); + + libinput_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); + libinput_dispatch(li); + + ev = libinput_get_event(li); + tev = libinput_event_get_touch_event(ev); + ck_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); + ck_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); + libinput_dispatch(li); + litest_assert_touch_up_frame(li); + + litest_touch_up(dev, 1); + libinput_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 = _i; /* looped test */ + + 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); + + libinput_dispatch(libinput1); + libinput_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); + + ck_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; + + ck_assert_int_eq(libinput_event_touch_get_x(t1), + libinput_event_touch_get_x(t2)); + ck_assert_int_eq(libinput_event_touch_get_y(t1), + libinput_event_touch_get_y(t2)); + + libinput_event_destroy(ev1); + libinput_event_destroy(ev2); + } + + libinput_event_destroy(ev1); + libinput_event_destroy(ev2); + + libinput_unref(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); + libinput_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); + ck_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); + libinput_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); + libinput_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; + + ck_assert_int_eq(libevdev_get_abs_fuzz(dev->evdev, ABS_X), 0); + ck_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"); + ck_assert_notnull(prop); + ck_assert(safe_atoi(prop, &fuzz)); + ck_assert_int_eq(fuzz, 10); /* device-specific */ + + prop = udev_device_get_property_value(d, "LIBINPUT_FUZZ_01"); + ck_assert_notnull(prop); + ck_assert(safe_atoi(prop, &fuzz)); + ck_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, espect a release */ + litest_delete_device(dev); + libinput_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); + + libinput_unref(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); + libinput_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); + ck_assert_double_eq(x, 300); /* device has resolution 10 */ + ck_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); + ck_assert_double_eq(round(x), 200); + ck_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); + libinput_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); + ck_assert_double_eq(x, -150); /* device has resolution 10 */ + ck_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); + ck_assert_double_eq(round(x), -100); + ck_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; + + ck_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; + + ck_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; + + ck_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; + + ck_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_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); + libinput_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_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); + libinput_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_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_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); + libinput_dispatch(li); + litest_assert_touch_cancel(li); + + litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); + libinput_dispatch(li); + litest_assert_touch_motion_frame(li); + + litest_touch_up(dev, 1); + libinput_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_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); + libinput_dispatch(li); + litest_assert_touch_cancel(li); + + litest_touch_move_to(dev, 1, 50, 50, 70, 70, 10); + libinput_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); + libinput_dispatch(li); + litest_assert_touch_motion_frame(li); + + litest_touch_up(dev, 1); + libinput_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_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); + libinput_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); + libinput_dispatch(li); + litest_assert_touch_up_frame(li); +} +END_TEST + +TEST_COLLECTION(touch) +{ + struct range axes = { ABS_X, ABS_Y + 1}; + + litest_add("touch:frame", touch_frame_events, LITEST_TOUCH, LITEST_ANY); + litest_add("touch:down", touch_downup_no_motion, LITEST_TOUCH, LITEST_ANY); + litest_add("touch:down", touch_downup_no_motion, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add_no_device("touch:abs-transform", touch_abs_transform); + litest_add("touch:slots", touch_seat_slot, LITEST_TOUCH, LITEST_TOUCHPAD); + litest_add_no_device("touch:slots", touch_many_slots); + litest_add("touch:double-touch-down-up", touch_double_touch_down_up, LITEST_TOUCH, LITEST_PROTOCOL_A); + litest_add("touch:calibration", touch_calibration_scale, LITEST_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:calibration", touch_calibration_scale, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:calibration", touch_calibration_rotation, LITEST_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:calibration", touch_calibration_rotation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:calibration", touch_calibration_translation, LITEST_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:calibration", touch_calibration_translation, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add_for_device("touch:calibration", touch_calibrated_screen_path, LITEST_CALIBRATED_TOUCHSCREEN); + litest_add_for_device("touch:calibration", touch_calibrated_screen_udev, LITEST_CALIBRATED_TOUCHSCREEN); + litest_add("touch:calibration", touch_calibration_config, LITEST_TOUCH, LITEST_ANY); + + litest_add("touch:left-handed", touch_no_left_handed, LITEST_TOUCH, LITEST_ANY); + + litest_add("touch:fake-mt", fake_mt_exists, LITEST_FAKE_MT, LITEST_ANY); + litest_add("touch:fake-mt", fake_mt_no_touch_events, LITEST_FAKE_MT, LITEST_ANY); + + litest_add("touch:protocol a", touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY); + litest_add("touch:protocol a", touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY); + litest_add("touch:protocol a", touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY); + + litest_add_ranged("touch:state", touch_initial_state, LITEST_TOUCH, LITEST_PROTOCOL_A, &axes); + + litest_add("touch:time", touch_time_usec, LITEST_TOUCH, LITEST_TOUCHPAD); + + litest_add_for_device("touch:fuzz", touch_fuzz, LITEST_MULTITOUCH_FUZZ_SCREEN); + litest_add_for_device("touch:fuzz", touch_fuzz_property, LITEST_MULTITOUCH_FUZZ_SCREEN); + + litest_add_no_device("touch:release", touch_release_on_unplug); + + litest_add_for_device("touch:range", touch_invalid_range_over, LITEST_TOUCHSCREEN_INVALID_RANGE); + litest_add_for_device("touch:range", touch_invalid_range_under, LITEST_TOUCHSCREEN_INVALID_RANGE); + + litest_add("touch:count", touch_count_st, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); + litest_add("touch:count", touch_count_mt, LITEST_TOUCH, LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); + litest_add("touch:count", touch_count_unknown, LITEST_PROTOCOL_A, LITEST_ANY); + litest_add("touch:count", touch_count_invalid, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_PROTOCOL_A); + + litest_add("touch:tool", touch_palm_detect_tool_palm, LITEST_TOUCH, LITEST_ANY); + litest_add("touch:tool", touch_palm_detect_tool_palm_on_off, LITEST_TOUCH, LITEST_ANY); + litest_add("touch:tool", touch_palm_detect_tool_palm_keep_type, LITEST_TOUCH, LITEST_ANY); + litest_add("touch:tool", touch_palm_detect_tool_palm_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); + litest_add("touch:tool", touch_palm_detect_tool_palm_on_off_2fg, LITEST_TOUCH, LITEST_SINGLE_TOUCH); + litest_add("touch:tool", touch_palm_detect_tool_palm_keep_type_2fg, LITEST_TOUCH, LITEST_ANY); +} diff --git a/test/test-touchpad-buttons.c b/test/test-touchpad-buttons.c new file mode 100644 index 0000000..907d12b --- /dev/null +++ b/test/test-touchpad-buttons.c @@ -0,0 +1,2168 @@ +/* + * 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 "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_drain_events(li); + + litest_button_click(dev, BTN_LEFT, true); + libinput_dispatch(li); + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_button_click(dev, BTN_LEFT, false); + libinput_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); + ck_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + ck_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + + method = libinput_device_config_click_get_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + method = libinput_device_config_click_get_default_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_NONE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); +} +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); + ck_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + ck_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + + method = libinput_device_config_click_get_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + method = libinput_device_config_click_get_default_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_NONE); + ck_assert_int_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; + + /* call this test for non-clickpads and non-touchpads */ + + methods = libinput_device_config_click_get_methods(device); + ck_assert_int_eq(methods, 0); + + method = libinput_device_config_click_get_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_NONE); + method = libinput_device_config_click_get_default_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_NONE); + + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + ck_assert_int_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); + + libinput_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; + + 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); + + libinput_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_2fg_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_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); + + libinput_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_3fg_clickfinger) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_num_slots(dev->evdev) < 3) + return; + + 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_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); + + libinput_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_clickfinger_btntool) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_num_slots(dev->evdev) >= 3 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + 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_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); + + libinput_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_4fg_clickfinger) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + + if (libevdev_get_num_slots(dev->evdev) < 4) + return; + + 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); + + libinput_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); + + 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; + struct libinput_event *event; + + if (libevdev_get_num_slots(dev->evdev) >= 3 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP)) + return; + + 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_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); + + 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; + struct libinput_event *event; + + if (libevdev_get_num_slots(dev->evdev) >= 4 || + libevdev_get_num_slots(dev->evdev) < 3 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + 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); + + libinput_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); + + 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; + + if (libinput_device_get_size(dev->libinput_device, &w, &h) == 0 && + h < 50.0) + small_touchpad = true; + + litest_enable_clickfinger(dev); + + 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) + expected_button = BTN_RIGHT; + 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; + + if (libevdev_get_num_slots(dev->evdev) < 3) + return; + + litest_enable_clickfinger(dev); + + 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, + BTN_MIDDLE, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_assert_button_event(li, + BTN_MIDDLE, + 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; + + if (libevdev_get_num_slots(dev->evdev) > 2) + return; + + litest_enable_clickfinger(dev); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 90, 15); + litest_touch_down(dev, 1, 10, 15); + libinput_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); + libinput_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, + BTN_MIDDLE, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_assert_button_event(li, + BTN_MIDDLE, + 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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + ck_assert(!(methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)); + ck_assert(methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + + method = libinput_device_config_click_get_method(device); + ck_assert_int_eq(method, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); + + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_click_set_method(device, + LIBINPUT_CONFIG_CLICK_METHOD_NONE); + ck_assert_int_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); + + libinput_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); + + libinput_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); + + libinput_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 = _i; /* ranged test */ + unsigned int button; + int nslots = libevdev_get_num_slots(dev->evdev); + + 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); + + libinput_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); + libinput_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); + } + button = BTN_MIDDLE; + } + + litest_touch_up(dev, 0); + + + libinput_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); + + libinput_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); + + libinput_dispatch(li); + ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE); +} +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); + + libinput_dispatch(li); + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + libinput_dispatch(li); + ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE); + + /* 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); + ck_assert_notnull(abs); + if (abs->resolution == 0) + return; + + if (libinput_device_get_size(dev->libinput_device, &w, &h) != 0) + return; + + 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, 52, 52, 10); + litest_touch_move_to(dev, 0, 52, 52, 48, 48, 10); + litest_touch_move_to(dev, 0, 48, 48, 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); + + libinput_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); + + libinput_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); + + libinput_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); + libinput_dispatch(li); + litest_timeout_softbuttons(); + libinput_dispatch(li); + litest_drain_events(li); + + /* move down left, expect motion */ + litest_touch_move_to(dev, 0, 50, 50, 20, 90, 20); + + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_notnull(event); + while (event) { + struct libinput_event_pointer *p; + + ck_assert_int_eq(libinput_event_get_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); + libinput_dispatch(li); + event = libinput_get_event(li); + } + + ck_assert(x/nevents < 0); + ck_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, 10); + + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_notnull(event); + while (event) { + struct libinput_event_pointer *p; + double x, y; + + ck_assert_int_eq(libinput_event_get_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) { + ck_assert(x > 0); + ck_assert(y == 0); + } + + libinput_event_destroy(event); + libinput_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, 10); + + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_notnull(event); + while (event) { + struct libinput_event_pointer *p; + double x, y; + + ck_assert_int_eq(libinput_event_get_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); + + ck_assert(x == 0); + ck_assert(y > 0); + + libinput_event_destroy(event); + libinput_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, 10); + 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, 10); + 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); + libinput_dispatch(li); + litest_hover_move_to(dev, 0, 50, 50, 90, 90, 10); + libinput_dispatch(li); + + litest_touch_move_to(dev, 0, 90, 90, 91, 91, 1); + + litest_button_click(dev, BTN_LEFT, true); + libinput_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); + libinput_dispatch(li); + litest_timeout_softbuttons(); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_move_to(dev, 0, 80, 5, 80, 90, 20); + libinput_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); + libinput_dispatch(li); + litest_timeout_softbuttons(); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_move_to(dev, 0, 80, 5, 80, 90, 20); + libinput_dispatch(li); + litest_timeout_softbuttons(); + libinput_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); + ck_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); + libinput_dispatch(li); + + /* actual config is delayed, but status is immediate */ + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + enabled = libinput_device_config_middle_emulation_get_enabled(device); + ck_assert(enabled); + + status = libinput_device_config_middle_emulation_set_enabled(device, + LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + enabled = libinput_device_config_middle_emulation_get_enabled(device); + ck_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); + + libinput_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); + + libinput_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); + + libinput_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); + + libinput_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); + + libinput_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); + libinput_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); + + libinput_dispatch(li); +} +END_TEST + +TEST_COLLECTION(touchpad_buttons) +{ + struct range finger_count = {1, 4}; + + litest_add("touchpad:button", touchpad_button, LITEST_TOUCHPAD, LITEST_CLICKPAD); + + litest_add("touchpad:clickfinger", touchpad_1fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_1fg_clickfinger_no_touch, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_2fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_3fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_3fg_clickfinger_btntool, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_4fg_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_4fg_clickfinger_btntool_2slots, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_4fg_clickfinger_btntool_3slots, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_2fg_clickfinger_distance, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_3fg_clickfinger_distance, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_3fg_clickfinger_distance_btntool, LITEST_CLICKPAD, LITEST_ANY); + litest_add_for_device("touchpad:clickfinger", touchpad_2fg_clickfinger_bottom, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add("touchpad:clickfinger", touchpad_clickfinger_to_area_method, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", + touchpad_clickfinger_to_area_method_while_down, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", touchpad_area_to_clickfinger_method, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:clickfinger", + 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", touchpad_clickfinger_3fg_tool_position, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add_for_device("touchpad:clickfinger", touchpad_clickfinger_4fg_tool_position, LITEST_SYNAPTICS_TOPBUTTONPAD); + + litest_add_for_device("touchpad:clickfinger", touchpad_clickfinger_appletouch_config, LITEST_APPLETOUCH); + litest_add_for_device("touchpad:clickfinger", touchpad_clickfinger_appletouch_1fg, LITEST_APPLETOUCH); + litest_add_for_device("touchpad:clickfinger", touchpad_clickfinger_appletouch_2fg, LITEST_APPLETOUCH); + litest_add_for_device("touchpad:clickfinger", touchpad_clickfinger_appletouch_3fg, LITEST_APPLETOUCH); + + litest_add_ranged("touchpad:clickfinger", touchpad_clickfinger_click_drag, LITEST_CLICKPAD, LITEST_ANY, &finger_count); + + litest_add("touchpad:click", touchpad_click_defaults_clickfinger, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:click", touchpad_click_defaults_btnarea, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:click", touchpad_click_defaults_none, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:click", touchpad_click_defaults_none, LITEST_ANY, LITEST_TOUCHPAD); + + litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:click", clickpad_finger_pin, LITEST_CLICKPAD, LITEST_ANY); + + litest_add("touchpad:softbutton", clickpad_softbutton_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_middle, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_left_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_right_tap_n_drag, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_left_1st_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_left_2nd_fg_move, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_left_to_right, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_right_to_left, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:softbutton", clickpad_softbutton_hover_into_buttons, LITEST_CLICKPAD|LITEST_HOVER, LITEST_APPLE_CLICKPAD); + + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_left, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_right, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_middle, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_leftclick, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_move_out_leftclick_before_timeout, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_clickfinger, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("touchpad:topsoftbuttons", clickpad_topsoftbuttons_clickfinger_dev_disabled, LITEST_TOPBUTTONPAD, LITEST_ANY); + + litest_add("touchpad:middleemulation", clickpad_middleemulation_config_delayed, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:middleemulation", clickpad_middleemulation_click, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:middleemulation", clickpad_middleemulation_click_middle_left, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:middleemulation", clickpad_middleemulation_click_middle_right, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:middleemulation", clickpad_middleemulation_click_enable_while_down, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:middleemulation", clickpad_middleemulation_click_disable_while_down, LITEST_CLICKPAD, LITEST_ANY); +} diff --git a/test/test-touchpad-tap.c b/test/test-touchpad-tap.c new file mode 100644 index 0000000..0862908 --- /dev/null +++ b/test/test-touchpad-tap.c @@ -0,0 +1,3665 @@ +/* + * 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 + +#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_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + + libinput_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_1fg_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; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + msleep(10); + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + + libinput_dispatch(li); + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + 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, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_lt(oldtime, curtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_lt(oldtime, curtime); + oldtime = curtime; + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_lt(oldtime, curtime); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_ge(curtime, oldtime); + oldtime = curtime; + } + litest_timeout_tap(); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_ge(curtime, oldtime); + oldtime = curtime; + } + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + litest_assert_only_typed_events(li, + LIBINPUT_EVENT_POINTER_MOTION); + + 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(touchpad_1fg_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 range = _i, + ntaps; + + if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT)) + return; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_down(dev, 1, 70, 50); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_ge(curtime, oldtime); + oldtime = curtime; + } + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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_timeout_tap(); + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_button_click(dev, BTN_LEFT, true); + litest_button_click(dev, BTN_LEFT, false); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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_tap(); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + 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_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + rtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_lt(ptime, rtime); + } + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + oldtime = curtime; + } + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_tap_drag_high_delay) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + int range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + 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. */ + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + msleep(100); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(100); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 50, 70, 10); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + 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_only_typed_events(li, + LIBINPUT_EVENT_POINTER_MOTION); + + 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(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_ge(curtime, oldtime); + oldtime = curtime; + } + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + msleep(10); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps < range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_ge(curtime, oldtime); + oldtime = curtime; + } + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + 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_1fg_tap_n_drag) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + + litest_enable_tap(dev->libinput_device); + litest_disable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); + + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + libinput_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. + */ + libinput_dispatch(li); + event = libinput_get_event(li); + ck_assert_notnull(event); + litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_tap_n_drag_draglock) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); + litest_touch_up(dev, 0); + + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + libinput_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, BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_1fg_tap_n_drag_draglock_tap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); + litest_touch_up(dev, 0); + + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + libinput_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); + litest_touch_down(dev, 0, 50, 50); + 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(touchpad_1fg_tap_n_drag_draglock_tap_click) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + libinput_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); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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_1fg_tap_n_drag_draglock_timeout) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + litest_enable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_timeout_tap(); + + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + litest_assert_empty_queue(li); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tapndrag(); + litest_assert_button_event(li, BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_2fg_tap_n_drag) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + litest_disable_drag_lock(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 30, 70); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 30, 70); + litest_touch_down(dev, 1, 80, 70); + litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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, BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_2fg_tap_n_drag_3fg_btntool) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 30, 70); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 30, 70); + litest_touch_down(dev, 1, 80, 90); + litest_touch_move_to(dev, 0, 30, 70, 30, 30, 5); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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_2fg_tap_n_drag_3fg) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 2) + return; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 30, 70); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 30, 70); + litest_touch_down(dev, 1, 80, 90); + litest_touch_move_to(dev, 0, 30, 70, 30, 30, 10); + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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); + + libinput_dispatch(li); + + litest_assert_button_event(li, BTN_LEFT, + 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_2fg_tap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + struct libinput_event *ev; + struct libinput_event_pointer *ptrev; + uint64_t ptime, rtime; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + + libinput_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); + + ck_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; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + struct libinput_event *ev; + struct libinput_event_pointer *ptrev; + uint64_t ptime, rtime; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + + libinput_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); + + ck_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_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); + + libinput_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_drain_events(dev->libinput); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_down(dev, 1, 70, 70); + litest_touch_up(dev, 1); + + libinput_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_drain_events(dev->libinput); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_down(dev, 1, 70, 70); + litest_touch_up(dev, 0); + + libinput_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_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); + + libinput_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_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); + libinput_dispatch(li); + litest_timeout_tap(); + + libinput_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_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); + + libinput_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_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); + + libinput_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_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); + + libinput_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_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_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); + libinput_dispatch(dev->libinput); + litest_timeout_tap(); + libinput_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_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); + libinput_dispatch(dev->libinput); + litest_touch_move_to(dev, 1, 70, 50, 90, 90, 10); + libinput_dispatch(dev->libinput); + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_dispatch(dev->libinput); + + while ((event = libinput_get_event(li))) { + ck_assert_int_ne(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_BUTTON); + libinput_event_destroy(event); + } +} +END_TEST + +START_TEST(touchpad_1fg_double_tap_click) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(dev->libinput); + + /* one finger down, up, down, button click, finger up + -> two button left event pairs */ + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + 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); + + libinput_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_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_1fg_tap_n_drag_click) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(dev->libinput); + + /* one finger down, up, down, move, button click, finger up + -> two button left event pairs, motion allowed */ + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 80, 50, 10); + + litest_assert_button_event(li, BTN_LEFT, + 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, BTN_LEFT, + 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); + + libinput_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; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + int i; + + if (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 2) + return; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + + libinput_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); + + ck_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 (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) <= 2) + return; + + litest_enable_tap(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); + + libinput_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); + + ck_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 (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 2) + return; + + litest_enable_tap(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); + + libinput_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); + + libinput_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 (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) >= 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + /* 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_enable_tap(dev->libinput_device); + litest_enable_edge_scroll(dev); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_down(dev, 1, 70, 50); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_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); + libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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 (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) >= 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + /* 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; + + if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT) && + libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE)) + return; + + litest_enable_tap(dev->libinput_device); + litest_enable_edge_scroll(dev); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_down(dev, 1, 70, 50); + libinput_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); + libinput_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; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + + libinput_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; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + + libinput_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; + enum libinput_config_tap_button_map map = _i; /* ranged test */ + unsigned int button = 0; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) > 2 || + !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP)) + return; + + litest_enable_tap(dev->libinput_device); + litest_set_tap_map(dev->libinput_device, map); + + 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); + libinput_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); + + libinput_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); + + /* 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); + libinput_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); + libinput_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); + libinput_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); + libinput_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(); + libinput_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_4fg_tap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + int i; + + if (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 3) + return; + + litest_enable_tap(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); + + libinput_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 (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 3) + return; + + litest_enable_tap(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); + + libinput_dispatch(li); + litest_assert_empty_queue(li); + litest_timeout_tap(); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_5fg_tap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + int i; + + if (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 4) + return; + + litest_enable_tap(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); + + libinput_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 (libevdev_get_abs_maximum(dev->evdev, + ABS_MT_SLOT) <= 4) + return; + + litest_enable_tap(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); + + libinput_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_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); + libinput_dispatch(li); + litest_timeout_tap(); + + libinput_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(); + + ck_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(); + + ck_assert_int_eq(libinput_device_config_tap_get_finger_count(dev->libinput_device), 0); + ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), + LIBINPUT_CONFIG_TAP_DISABLED); + ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, + LIBINPUT_CONFIG_TAP_ENABLED), + LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + ck_assert_int_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 */ + + ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), + LIBINPUT_CONFIG_TAP_DISABLED); + ck_assert_int_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 */ + + ck_assert_int_eq(libinput_device_config_tap_get_enabled(dev->libinput_device), + LIBINPUT_CONFIG_TAP_ENABLED); + ck_assert_int_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(); + + ck_assert_int_eq(libinput_device_config_tap_set_enabled(dev->libinput_device, 2), + LIBINPUT_CONFIG_STATUS_INVALID); + ck_assert_int_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); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); + + map = libinput_device_config_tap_get_default_button_map(dev->libinput_device); + ck_assert_int_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); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); + map = libinput_device_config_tap_get_default_button_map(dev->libinput_device); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); + + status = libinput_device_config_tap_set_button_map(dev->libinput_device, + LIBINPUT_CONFIG_TAP_MAP_LMR); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_tap_set_button_map(dev->libinput_device, + LIBINPUT_CONFIG_TAP_MAP_LRM); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + map = libinput_device_config_tap_get_button_map(dev->libinput_device); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); + + map = LIBINPUT_CONFIG_TAP_MAP_LMR; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + map = libinput_device_config_tap_get_button_map(dev->libinput_device); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LMR); + + map = LIBINPUT_CONFIG_TAP_MAP_LRM - 1; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + map = LIBINPUT_CONFIG_TAP_MAP_LMR + 1; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + + map = LIBINPUT_CONFIG_TAP_MAP_LMR; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + + map = LIBINPUT_CONFIG_TAP_MAP_LRM - 1; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + + map = LIBINPUT_CONFIG_TAP_MAP_LMR + 1; + status = libinput_device_config_tap_set_button_map(device, map); + ck_assert_int_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); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LRM); + + map = libinput_device_config_tap_get_default_button_map(device); + ck_assert_int_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_drain_events(dev->libinput); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_down(dev, 1, 70, 70); + libinput_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); + ck_assert_int_eq(map, LIBINPUT_CONFIG_TAP_MAP_LMR); + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + + libinput_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 */ + + ck_assert_int_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), + LIBINPUT_CONFIG_DRAG_DISABLED); + ck_assert_int_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 */ + + ck_assert_int_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), + LIBINPUT_CONFIG_DRAG_ENABLED); + ck_assert_int_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(); + + ck_assert_int_eq(libinput_device_config_tap_set_drag_enabled(dev->libinput_device, 2), + LIBINPUT_CONFIG_STATUS_INVALID); + ck_assert_int_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; + + ck_assert_int_eq(libinput_device_config_tap_get_default_drag_enabled(dev->libinput_device), + LIBINPUT_CONFIG_DRAG_DISABLED); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_tap_set_drag_enabled(dev->libinput_device, + LIBINPUT_CONFIG_DRAG_DISABLED); + ck_assert_int_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_enable_tap(dev->libinput_device); + + litest_disable_tap_drag(dev->libinput_device); + state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DRAG_DISABLED); + + litest_enable_tap_drag(dev->libinput_device); + state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); + ck_assert_int_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); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DRAG_DISABLED); + + litest_enable_tap_drag(dev->libinput_device); + state = libinput_device_config_tap_get_drag_enabled(dev->libinput_device); + ck_assert_int_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; + + litest_enable_tap(dev->libinput_device); + litest_disable_tap_drag(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_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); + libinput_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_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; + + litest_enable_tap(dev->libinput_device); + litest_disable_tap_drag(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + msleep(10); /* to force a time difference */ + libinput_dispatch(li); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + ev = libinput_get_event(li); + ptrev = litest_is_button_event(ev, + BTN_LEFT, + 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, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + release_time = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(ev); + + ck_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 range = _i, /* looped test */ + ntaps; + + litest_enable_tap(dev->libinput_device); + litest_disable_tap_drag(dev->libinput_device); + + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_assert_int_gt(curtime, oldtime); + + event = libinput_get_event(li); + ptrev = litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + curtime = libinput_event_pointer_get_time(ptrev); + libinput_event_destroy(event); + ck_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; + + ck_assert_int_eq(libinput_device_config_tap_get_drag_lock_enabled(device), + LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_tap_set_drag_lock_enabled(device, + LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_tap_set_drag_lock_enabled(device, + LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_tap_set_drag_lock_enabled(device, + 3); + ck_assert_int_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; + + ck_assert_int_eq(libinput_device_config_tap_get_drag_lock_enabled(device), + LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); + ck_assert_int_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + + status = libinput_device_config_tap_set_drag_lock_enabled(device, + LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_tap_set_drag_lock_enabled(device, + 3); + ck_assert_int_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 (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) + return true; + + 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_enable_tap(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); + + libinput_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_enable_tap(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); + + libinput_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_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* Finger down is palm after tap timeout */ + + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + litest_touch_up(dev, 0); + + libinput_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_enable_tap(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); + + libinput_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 } + }; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* tap + palm down */ + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + 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); + + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + 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 } + }; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* tap + palm down */ + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + 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); + + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(touchpad_tap_palm_on_tapped_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_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* tap + palm down + tap with second finger */ + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + + libinput_dispatch(li); + + litest_touch_down(dev, 1, 50, 50); + litest_touch_up(dev, 1); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + 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_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 } + }; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* tap + finger down (->drag), finger turns into palm */ + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + libinput_dispatch(li); + + 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_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 = _i; /* ranged test */ + int this = which % 2, + other = (which + 1) % 2; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + /* tap + finger down, 2nd finger down, finger turns to palm */ + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + + litest_touch_down(dev, this, 50, 50); + litest_touch_down(dev, other, 60, 50); + libinput_dispatch(li); + + litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); + libinput_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, + BTN_LEFT, + 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 = _i; /* ranged test */ + int this = which % 2, + other = (which + 1) % 2; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(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); + + libinput_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 = _i; /* ranged test */ + int this = which % 2, + other = (which + 1) % 2; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(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); + libinput_dispatch(li); + + litest_touch_down(dev, this, 70, 70); + litest_touch_up(dev, this); + litest_touch_up(dev, other); + + libinput_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 = _i; /* ranged test */ + int this = which % 3; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) <= 3) + return; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(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); + libinput_dispatch(li); + + litest_touch_up(dev, (this + 1) % 3); + litest_touch_up(dev, (this + 2) % 3); + + libinput_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 = _i; /* ranged test */ + int this = which % 3; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) <= 3) + return; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(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(); + libinput_dispatch(li); + + litest_touch_move_to_extended(dev, this, 50, 50, 50, 50, axes, 1); + litest_touch_up(dev, this); + libinput_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); + + libinput_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 = _i; /* ranged test */ + int this = which % 4; + + if (libevdev_get_abs_maximum(dev->evdev, ABS_MT_SLOT) <= 4) + return; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(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); + libinput_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 } + }; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + libinput_dispatch(li); + litest_assert_button_event(li, + BTN_LEFT, + 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); + libinput_dispatch(li); + + 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_multitap) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_MT_PRESSURE, 75 }, + { -1, 0 } + }; + int range = _i, /* ranged test */ + ntaps; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + 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_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 range = _i, /* ranged test */ + ntaps; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + 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_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 range = _i, /* ranged test */ + ntaps; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + libinput_dispatch(li); + + /* keep palm finger down */ + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 1, 50, 50); + litest_touch_up(dev, 1); + libinput_dispatch(li); + msleep(10); + } + + for (ntaps = 0; ntaps <= 2 * range; ntaps++) { + 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_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 range = _i, /* ranged test */ + ntaps; + + if (!touchpad_has_palm_pressure(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_drain_events(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + libinput_dispatch(li); + msleep(10); + } + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + libinput_dispatch(li); + /* keep palm finger down */ + + litest_button_click(dev, BTN_LEFT, true); + litest_button_click(dev, BTN_LEFT, false); + libinput_dispatch(li); + + for (ntaps = 0; ntaps <= range; ntaps++) { + litest_assert_button_event(li, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_assert_button_event(li, + BTN_LEFT, + 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_enable_tap(dev->libinput_device); + litest_drain_events(li); + + litest_touch_down_extended(dev, 0, 50, 50, axes); + libinput_dispatch(li); + + litest_button_click(dev, BTN_LEFT, true); + litest_button_click(dev, BTN_LEFT, false); + libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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; + + keyboard = litest_add_device(li, LITEST_KEYBOARD); + + litest_enable_tap(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); + libinput_dispatch(li); + + litest_keyboard_key(keyboard, KEY_B, false); + litest_drain_events(li); + litest_timeout_dwt_long(); + libinput_dispatch(li); + + /* Changes to palm after dwt timeout */ + litest_touch_move_to_extended(dev, 0, 50, 50, 50, 50, axes, 1); + libinput_dispatch(li); + + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_assert_empty_queue(li); + + litest_delete_device(keyboard); +} +END_TEST + +TEST_COLLECTION(touchpad_tap) +{ + struct range any_tap_range = {1, 4}; + struct range multitap_range = {3, 5}; + struct range tap_map_range = { LIBINPUT_CONFIG_TAP_MAP_LRM, + LIBINPUT_CONFIG_TAP_MAP_LMR + 1 }; + struct range range_2fg = {0, 2}; + struct range range_3fg = {0, 3}; + struct range range_4fg = {0, 4}; + + litest_add("tap:1fg", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:1fg", touchpad_1fg_doubletap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_ranged("tap:1fg", touchpad_1fg_tap_drag_high_delay, LITEST_TOUCHPAD, LITEST_ANY, &any_tap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_timeout, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_timeout, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_tap, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_move, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &multitap_range); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY, &multitap_range); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag_draglock, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag_draglock_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag_draglock_timeout, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:2fg", touchpad_2fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:2fg", touchpad_2fg_tap_n_drag_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD); + litest_add("tap:2fg", touchpad_2fg_tap_n_drag_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add_ranged("tap:2fg", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT, &tap_map_range); + litest_add_ranged("tap:2fg", touchpad_2fg_tap_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range); + litest_add("tap:2fg", touchpad_2fg_tap_move_on_release, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_SINGLE_TOUCH); + litest_add("tap:2fg", touchpad_2fg_tap_n_hold_first, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:2fg", touchpad_2fg_tap_n_hold_second, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:2fg", touchpad_2fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:2fg", touchpad_1fg_tap_click, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("tap:2fg", touchpad_2fg_tap_click, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_SINGLE_TOUCH|LITEST_CLICKPAD); + + litest_add("tap:2fg", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("tap:2fg", touchpad_no_2fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:2fg", touchpad_no_2fg_tap_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:2fg", touchpad_no_first_fg_tap_after_move, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add_ranged("tap:3fg", touchpad_3fg_tap_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range); + litest_add_ranged("tap:3fg", touchpad_3fg_tap_btntool_inverted, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range); + litest_add_ranged("tap:3fg", touchpad_3fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &tap_map_range); + litest_add("tap:3fg", touchpad_3fg_tap_tap_again, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:3fg", touchpad_3fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:3fg", touchpad_3fg_tap_hover_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:3fg", touchpad_3fg_tap_pressure_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add_for_device("tap:3fg", touchpad_3fg_tap_btntool_pointerjump, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add_for_device("tap:3fg", touchpad_3fg_tap_slot_release_btntool, LITEST_SYNAPTICS_TOPBUTTONPAD); + + litest_add("tap:4fg", touchpad_4fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:4fg", touchpad_4fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:5fg", touchpad_5fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("tap:5fg", touchpad_5fg_tap_quickrelease, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + + /* Real buttons don't interfere with tapping, so don't run those for + pads with buttons */ + litest_add("tap:1fg", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY); + litest_add_ranged("tap:1fg", touchpad_1fg_multitap_n_drag_tap_click, LITEST_CLICKPAD, LITEST_ANY, &multitap_range); + litest_add("tap:1fg", touchpad_1fg_tap_n_drag_draglock_tap_click, LITEST_CLICKPAD, LITEST_ANY); + + litest_add("tap:config", touchpad_tap_default_disabled, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_ANY); + litest_add("tap:config", touchpad_tap_default_enabled, LITEST_TOUCHPAD, LITEST_BUTTON); + litest_add("tap:config", touchpad_tap_invalid, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:config", touchpad_tap_is_available, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:config", touchpad_tap_is_not_available, LITEST_ANY, LITEST_TOUCHPAD); + + litest_add("tap:config", touchpad_tap_default_map, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:config", touchpad_tap_map_unsupported, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("tap:config", touchpad_tap_set_map, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:config", touchpad_tap_set_map_no_tapping, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("tap:config", touchpad_tap_get_map_no_tapping, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("tap:config", touchpad_tap_map_delayed, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + + litest_add("tap:1fg", clickpad_1fg_tap_click, LITEST_CLICKPAD, LITEST_ANY); + litest_add("tap:2fg", clickpad_2fg_tap_click, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD); + + litest_add("tap:draglock", touchpad_drag_lock_default_disabled, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:draglock", touchpad_drag_lock_default_unavailable, LITEST_ANY, LITEST_TOUCHPAD); + + litest_add("tap:drag", touchpad_drag_default_disabled, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("tap:drag", touchpad_drag_default_enabled, LITEST_TOUCHPAD, LITEST_BUTTON); + litest_add("tap:drag", touchpad_drag_config_invalid, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:drag", touchpad_drag_config_unsupported, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("tap:drag", touchpad_drag_config_enabledisable, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:drag", touchpad_drag_disabled, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:drag", touchpad_drag_disabled_immediate, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_ranged("tap:1fg", touchpad_drag_disabled_multitap_no_drag, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + + litest_add("tap:palm", touchpad_tap_palm_on_idle, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_touch_hold_timeout, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_touch_hold_move, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_tapped, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_tapped_palm_down, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_on_tapped_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("tap:palm", touchpad_tap_palm_on_drag, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_2fg); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_touch_2, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_2fg); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_touch_2_retouch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_2fg); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_touch_3, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_3fg); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_touch_3_retouch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_3fg); + litest_add_ranged("tap:palm", touchpad_tap_palm_on_touch_4, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &range_4fg); + litest_add("tap:palm", touchpad_tap_palm_after_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_ranged("tap:palm", touchpad_tap_palm_multitap, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:palm", touchpad_tap_palm_multitap_timeout, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add_ranged("tap:palm", touchpad_tap_palm_multitap_down_again, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &multitap_range); + litest_add_ranged("tap:palm", touchpad_tap_palm_multitap_click, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range); + litest_add("tap:palm", touchpad_tap_palm_click_then_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("tap:palm", touchpad_tap_palm_dwt_tap, LITEST_TOUCHPAD, LITEST_ANY); +} diff --git a/test/test-touchpad.c b/test/test-touchpad.c new file mode 100644 index 0000000..73dd9f0 --- /dev/null +++ b/test/test-touchpad.c @@ -0,0 +1,7080 @@ +/* + * 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 "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; + struct libinput_event_pointer *ptrev; + + litest_disable_tap(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); + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + while (event) { + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_MOTION); + + ptrev = libinput_event_get_pointer_event(event); + ck_assert_int_ge(libinput_event_pointer_get_dx(ptrev), 0); + ck_assert_int_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); + + libinput_dispatch(li); + + event = libinput_get_event(li); + while (event) { + ck_assert_int_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) { + libinput_dispatch(li); + litest_timeout_tap(); + libinput_dispatch(li); + } + + litest_touch_up(dev, 1); + litest_touch_up(dev, 0); + + libinput_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_enable_2fg_scroll(dev); + litest_drain_events(li); + + test_2fg_scroll(dev, 0.1, 40, false); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 9); + test_2fg_scroll(dev, 0.1, -40, false); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -9); + test_2fg_scroll(dev, 40, 0.1, false); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 9); + test_2fg_scroll(dev, -40, 0.1, false); + litest_assert_scroll(li, 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; + struct libinput_event_pointer *ptrev; + int i; + int expected_nevents; + double w, h; + double ratio; + double ydelta; + + if (!litest_has_2fg_scroll(dev)) + return; + + ck_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); + libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_POINTER_AXIS, + -1); + 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++; + } + + libinput_dispatch(li); + event = libinput_get_event(li); + + do { + ptrev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + ck_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); + + ck_assert_int_eq(expected_nevents, 0); + + litest_touch_up(dev, 1); + litest_touch_up(dev, 0); + libinput_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) { + litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_AXIS); + ptrev = litest_is_axis_event(event, 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 = (libinput_event_pointer_get_axis_value(ptrev, off_axis) == 0.0); + break; + } + + ck_assert(has_on_axis); + ck_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_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); + ck_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); + ck_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_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); + libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_POINTER_AXIS, + -1); + + axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; + ck_assert(is_single_axis_2fg_scroll(dev, axis)); + litest_drain_events(li); + + msleep(200); + libinput_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); + libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_POINTER_AXIS, + -1); + 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); + libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_POINTER_AXIS, + -1); + + axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; + ck_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); + libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_POINTER_AXIS, + -1); + + axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; + ck_assert(!is_single_axis_2fg_scroll(dev, axis)); + + litest_touch_up(dev, 1); + litest_touch_up(dev, 0); + libinput_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; + struct libinput_event_pointer *ptrev; + double width, height; + double y_move = 100; + + if (!litest_has_2fg_scroll(dev)) + return; + + /* We want to move > 5 mm. */ + ck_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_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + /* last event is value 0, tested elsewhere */ + while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) { + double axisval; + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_AXIS); + ptrev = libinput_event_get_pointer_event(event); + + axisval = libinput_event_pointer_get_axis_value(ptrev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + ck_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 */ + ck_assert(axisval < 5.0); + + libinput_event_destroy(event); + event = libinput_get_event(li); + } + + 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; + struct libinput_event_pointer *ptrev; + + if (!litest_has_2fg_scroll(dev)) + return; + + 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, -1); + + while ((event = libinput_get_event(li))) { + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_AXIS); + ptrev = libinput_event_get_pointer_event(event); + ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev), + 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_enable_2fg_scroll(dev); + litest_drain_events(li); + + litest_touch_down(dev, 0, 20, 20); + litest_touch_down(dev, 1, 30, 20); + libinput_dispatch(li); + litest_touch_move_two_touches(dev, + 20, 20, + 30, 20, + 30, 40, + 10); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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_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); + libinput_dispatch(li); + litest_timeout_finger_switch(); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + 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); + libinput_dispatch(li); + litest_timeout_finger_switch(); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + /* 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_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); + libinput_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); + } + libinput_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); + } + libinput_dispatch(li); + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +END_TEST + +START_TEST(touchpad_scroll_natural_defaults) +{ + struct litest_device *dev = litest_current_device(); + + ck_assert_int_ge(libinput_device_config_scroll_has_natural_scroll(dev->libinput_device), 1); + ck_assert_int_eq(libinput_device_config_scroll_get_natural_scroll_enabled(dev->libinput_device), 0); + ck_assert_int_eq(libinput_device_config_scroll_get_default_natural_scroll_enabled(dev->libinput_device), 0); +} +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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + ck_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_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_POINTER_AXIS_SCROLL_VERTICAL, -9); + test_2fg_scroll(dev, 0.1, -40, false); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 9); + test_2fg_scroll(dev, 40, 0.1, false); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9); + test_2fg_scroll(dev, -40, 0.1, false); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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_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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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, 10); + litest_touch_up(dev, 0); + + libinput_dispatch(li); + litest_assert_scroll(li, 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); + + libinput_dispatch(li); + litest_assert_scroll(li, 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_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); + ck_assert(method & LIBINPUT_CONFIG_SCROLL_EDGE); + if (should_have_2fg) + ck_assert(method & LIBINPUT_CONFIG_SCROLL_2FG); + else + ck_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); + ck_assert_int_eq(method, expected); + method = libinput_device_config_scroll_get_default_method(device); + ck_assert_int_eq(method, expected); + + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_EDGE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_scroll_set_method(device, + LIBINPUT_CONFIG_SCROLL_2FG); + + if (should_have_2fg) + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + else + ck_assert_int_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; + struct libinput_event_pointer *ptrev; + double width = 0, height = 0; + int nevents = 0; + double mm; /* one mm in percent of the device */ + + ck_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); + libinput_dispatch(li); + litest_timeout_hysteresis(); + libinput_dispatch(li); + + litest_touch_move_to(dev, 0, 99, 20, 99, 20 + mm/2, 8); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_timeout_edgescroll(); + libinput_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); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1); + + while ((event = libinput_get_event(li))) { + double value; + + ptrev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + 0); + value = libinput_event_pointer_get_axis_value(ptrev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + ck_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. */ + ck_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); + libinput_dispatch(li); + + litest_assert_scroll(li, 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); + libinput_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; + struct libinput_event_pointer *ptrev; + + 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, -1); + + while ((event = libinput_get_event(li))) { + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_AXIS); + ptrev = libinput_event_get_pointer_event(event); + ck_assert_int_eq(libinput_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); + libinput_dispatch(li); + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + /* 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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + /* and out of the zone again */ + litest_touch_move_to(dev, 0, 99, 100, 99, 70, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + /* still out of the zone */ + litest_touch_move_to(dev, 0, 99, 70, 99, 50, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + /* over to right button */ + litest_touch_move_to(dev, 0, 40, 99, 60, 99, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + /* within right button */ + litest_touch_move_to(dev, 0, 60, 99, 80, 99, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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; + struct libinput_event_pointer *ptrev; + double val; + + if (!touchpad_has_horiz_edge_scroll_size(dev)) + return; + + 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, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + litest_button_click(dev, BTN_LEFT, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + ptrev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + val = libinput_event_pointer_get_axis_value(ptrev, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + ck_assert(val == 0.0); + libinput_event_destroy(event); + + 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, 10); + 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; + struct libinput_event_pointer *ptrev; + double val; + + if (!touchpad_has_horiz_edge_scroll_size(dev)) + return; + + 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, 10); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + litest_button_click(dev, BTN_LEFT, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + ptrev = litest_is_axis_event(event, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + val = libinput_event_pointer_get_axis_value(ptrev, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + ck_assert(val == 0.0); + libinput_event_destroy(event); + + 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, 10); + 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_typed_events(li, + LIBINPUT_EVENT_POINTER_AXIS); + 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_typed_events(li, + LIBINPUT_EVENT_POINTER_AXIS); +} +END_TEST + +static bool +touchpad_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 1; + + rc = libinput_device_get_size(dev->libinput_device, &width, &height); + + return rc == 0 && width >= 70; +} + +static bool +touchpad_has_top_palm_detect_size(struct litest_device *dev) +{ + double width, height; + int rc; + + if (!touchpad_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 (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + + litest_disable_tap(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_disable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 20, 1); + litest_touch_move_to(dev, 0, 20, 1, 70, 1, 10); + 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 (!touchpad_has_palm_detect_size(dev)) + return; + + 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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +END_TEST + +START_TEST(touchpad_palm_detect_at_bottom_corners) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + + litest_disable_tap(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 (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + + litest_disable_tap(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 (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + + litest_disable_tap(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_disable_tap(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 (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + + litest_disable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 99, 50); + litest_touch_move_to(dev, 0, 99, 50, 0, 70, 20); + litest_touch_up(dev, 0); + + libinput_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_disable_tap(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); + + libinput_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 (!touchpad_has_palm_detect_size(dev)) + return; + + litest_disable_tap(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, 10); + + litest_drain_events(li); + + litest_touch_move_to(dev, 0, 99, 50, 99, 90, 10); + libinput_dispatch(li); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_touch_up(dev, 0); + libinput_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_disable_tap(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, 10); + + litest_drain_events(li); + + litest_touch_move_to(dev, 0, 0, 2, 50, 50, 10); + libinput_dispatch(li); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); + + litest_touch_up(dev, 0); + libinput_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_enable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 1); + litest_touch_up(dev, 0); + libinput_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 (!touchpad_has_palm_detect_size(dev)) + return; + + litest_enable_tap(dev->libinput_device); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 95, 5); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 5, 5); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 5, 99); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 95, 99); + litest_touch_up(dev, 0); + libinput_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 (!touchpad_has_palm_detect_size(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_enable_buttonareas(dev); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 99, 99); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 1, 99); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 10, 99); + litest_touch_up(dev, 0); + libinput_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); + libinput_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 (!touchpad_has_palm_detect_size(dev)) + return; + + litest_enable_tap(dev->libinput_device); + litest_enable_clickfinger(dev); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 95, 5); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 5, 5); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 5, 99); + litest_touch_up(dev, 0); + libinput_dispatch(li); + + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 95, 99); + litest_touch_up(dev, 0); + libinput_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 (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + 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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +END_TEST + +START_TEST(touchpad_palm_detect_both_edges) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + + if (!touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + 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_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_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_enable_tap(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); + libinput_dispatch(li); + + litest_touch_move_to(dev, 0, 50, 50, 50, 80, 10); + libinput_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); + libinput_dispatch(li); + litest_timeout_tap(); + litest_assert_empty_queue(li); + + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_touch_up(dev, 0); + libinput_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_enable_tap(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); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_up(dev, 0); + libinput_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 (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) + return true; + + 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_disable_tap(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_enable_tap(dev->libinput_device); + litest_enable_clickfinger(dev); + 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); + libinput_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); + libinput_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_enable_tap(dev->libinput_device); + litest_enable_clickfinger(dev); + litest_drain_events(li); + + /* event in state HOLD is thumb */ + litest_touch_down(dev, 0, 50, 99); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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); + libinput_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_enable_tap(dev->libinput_device); + litest_enable_clickfinger(dev); + litest_drain_events(li); + + /* event in state HOLD is thumb */ + litest_touch_down(dev, 0, 50, 99); + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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 */ + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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); + libinput_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_enable_tap(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); + libinput_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); + libinput_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_disable_tap(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); + libinput_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_disable_tap(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) || + !touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + litest_enable_2fg_scroll(dev); + litest_disable_tap(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); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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(); + libinput_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_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_enable_clickfinger(dev); + litest_disable_tap(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; + + if (libevdev_get_num_slots(dev->evdev) < 3) + return; + + litest_enable_clickfinger(dev); + litest_disable_tap(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_enable_clickfinger(dev); + litest_disable_tap(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; + + if (libevdev_get_num_slots(dev->evdev) < 3) + return; + + litest_enable_clickfinger(dev); + litest_disable_tap(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; + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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; + + ck_assert_int_eq(libinput_device_config_left_handed_is_available(d), 0); + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + ck_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; + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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; + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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_enable_tap(dev->libinput_device); + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_up(dev, 0); + + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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_enable_tap(dev->libinput_device); + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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); + + libinput_dispatch(li); + litest_timeout_tap(); + libinput_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_drain_events(li); + litest_button_click(dev, BTN_LEFT, 1); + libinput_dispatch(li); + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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); + libinput_dispatch(li); + litest_timeout_middlebutton(); + libinput_dispatch(li); + litest_button_click(dev, BTN_LEFT, 1); + libinput_dispatch(li); + + status = libinput_device_config_left_handed_set(d, 0); + ck_assert_int_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_drain_events(li); + litest_touch_down(dev, 0, 10, 90); + litest_button_click(dev, BTN_LEFT, 1); + libinput_dispatch(li); + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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); + libinput_dispatch(li); + + status = libinput_device_config_left_handed_set(d, 0); + ck_assert_int_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 + +static inline bool +touchpad_has_rotation(struct libevdev *evdev) +{ + return libevdev_get_id_vendor(evdev) == VENDOR_ID_WACOM; +} + +START_TEST(touchpad_left_handed_rotation) +{ + 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; + struct libinput_event_pointer *p; + bool rotate = touchpad_has_rotation(dev->evdev); + + if (!libinput_device_config_left_handed_is_available(d)) + return; + + status = libinput_device_config_left_handed_set(d, 1); + ck_assert_int_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); + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + do { + 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) { + ck_assert_double_lt(x, 0); + ck_assert_double_gt(y, 0); + ck_assert_double_lt(ux, 0); + ck_assert_double_gt(uy, 0); + } else { + ck_assert_double_gt(x, 0); + ck_assert_double_lt(y, 0); + ck_assert_double_gt(ux, 0); + ck_assert_double_lt(uy, 0); + } + + libinput_event_destroy(event); + } while ((event = libinput_get_event(li))); +} +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); + libinput_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); + } + + libinput_dispatch(li); + + ck_assert_int_ne(libinput_next_event_type(li), + LIBINPUT_EVENT_NONE); + while ((event = libinput_get_event(li)) != NULL) { + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_POINTER_MOTION); + libinput_event_destroy(event); + libinput_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); + libinput_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); + } + + libinput_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); + + libinput_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); + libinput_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); + libinput_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); + + libinput_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); + + libinput_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); + + libinput_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_drain_events(li); + + litest_hover_start(dev, 0, 50, 50); + litest_hover_end(dev, 0); + + libinput_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; + + libinput_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 }, + }; + const struct buttons *b; + + 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 */ + libinput_dispatch(li); + litest_timeout_buttonscroll(); + libinput_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + 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); + ck_assert_int_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; + struct libinput_event_pointer *pev; + double val; + + trackpoint = litest_add_device(li, + LITEST_TRACKPOINT); + + litest_drain_events(li); + + litest_touch_down(touchpad, 0, 49, 70); + litest_touch_down(touchpad, 1, 51, 70); + litest_touch_move_two_touches(touchpad, 49, 70, 51, 70, 0, -40, 10); + + libinput_dispatch(li); + litest_wait_for_event(li); + + /* Make sure we get scroll events but _not_ the scroll release */ + while ((e = libinput_get_event(li))) { + ck_assert_int_eq(libinput_event_get_type(e), + LIBINPUT_EVENT_POINTER_AXIS); + pev = libinput_event_get_pointer_event(e); + val = libinput_event_pointer_get_axis_value(pev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + ck_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + while ((e = libinput_get_event(li))) { + ck_assert_int_eq(libinput_event_get_type(e), + LIBINPUT_EVENT_POINTER_AXIS); + pev = libinput_event_get_pointer_event(e); + val = libinput_event_pointer_get_axis_value(pev, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + ck_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + 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); + + libinput_dispatch(li); + + litest_assert_scroll(li, + 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; + struct libinput_event *ev1, *ev2; + struct libinput_event_pointer *p1, *p2; + int axis = _i; /* looped test */ + int x = 40, y = 60; + + dev = litest_current_device(); + libinput1 = dev->libinput; + + litest_disable_tap(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); + libinput_dispatch(libinput1); + libinput_dispatch(libinput2); + + 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); + + p1 = litest_is_motion_event(ev1); + p2 = litest_is_motion_event(ev2); + + ck_assert_int_eq(libinput_event_get_type(ev1), + libinput_event_get_type(ev2)); + + ck_assert_int_eq(libinput_event_pointer_get_dx(p1), + libinput_event_pointer_get_dx(p2)); + ck_assert_int_eq(libinput_event_pointer_get_dy(p1), + libinput_event_pointer_get_dy(p2)); + libinput_event_destroy(ev1); + libinput_event_destroy(ev2); + } + + libinput_unref(libinput2); +} +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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + libinput_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(); + libinput_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_disable_tap(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); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + litest_timeout_dwt_long(); + libinput_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(); + libinput_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; + + /* 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_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + litest_timeout_dwt_long(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_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); + libinput_dispatch(li); + litest_timeout_dwt_long(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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(); + libinput_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, + }; + unsigned int *key; + + if (!has_disable_while_typing(touchpad)) + return; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(touchpad->libinput_device); + litest_drain_events(li); + + ARRAY_FOR_EACH(modifiers, key) { + litest_keyboard_key(keyboard, *key, true); + litest_keyboard_key(keyboard, *key, false); + libinput_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_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, + }; + unsigned int *key; + + if (!has_disable_while_typing(touchpad)) + return; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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_LEFTSHIFT, + KEY_RIGHTSHIFT, + KEY_FN, + KEY_CAPSLOCK, + KEY_TAB, + KEY_COMPOSE, + KEY_RIGHTMETA, + KEY_LEFTMETA, + }; + unsigned int *key; + + if (!has_disable_while_typing(touchpad)) + return; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_dispatch(li); + + litest_keyboard_key(keyboard, KEY_A, true); + litest_keyboard_key(keyboard, KEY_A, false); + libinput_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(); + libinput_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_LEFTSHIFT, + KEY_RIGHTSHIFT, + KEY_FN, + KEY_CAPSLOCK, + KEY_TAB, + KEY_COMPOSE, + KEY_RIGHTMETA, + KEY_LEFTMETA, + }; + unsigned int *key; + + if (!has_disable_while_typing(touchpad)) + return; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_enable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_enable_tap(touchpad->libinput_device); + litest_drain_events(li); + + litest_keyboard_key(keyboard, KEY_A, true); + libinput_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(); + libinput_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; + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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_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); + libinput_dispatch(li); + litest_timeout_edgescroll(); + libinput_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); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + litest_touch_move_to(touchpad, 0, 99, 20, 99, 80, 60); + libinput_dispatch(li); + litest_assert_empty_queue(li); + + litest_touch_move_to(touchpad, 0, 99, 80, 99, 20, 60); + litest_touch_up(touchpad, 0); + libinput_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; + struct libinput_event_pointer *stop_event; + + if (!has_disable_while_typing(touchpad)) + return; + + litest_enable_edge_scroll(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_drain_events(li); + + litest_touch_down(touchpad, 0, 99, 20); + libinput_dispatch(li); + litest_timeout_edgescroll(); + litest_touch_move_to(touchpad, 0, 99, 20, 99, 30, 10); + libinput_dispatch(li); + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); + + 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 event */ + litest_wait_for_event(li); + stop_event = litest_is_axis_event(libinput_get_event(li), + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + libinput_event_destroy(libinput_event_pointer_get_base_event(stop_event)); + 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) { + ck_assert(!libinput_device_config_dwt_is_available(device)); + return; + } + + ck_assert(libinput_device_config_dwt_is_available(device)); + state = libinput_device_config_dwt_get_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_ENABLED); + state = libinput_device_config_dwt_get_default_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_ENABLED); + + status = libinput_device_config_dwt_set_enabled(device, + LIBINPUT_CONFIG_DWT_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_dwt_set_enabled(device, + LIBINPUT_CONFIG_DWT_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_dwt_set_enabled(device, 3); + ck_assert_int_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; + + ck_assert(!libinput_device_config_dwt_is_available(device)); + state = libinput_device_config_dwt_get_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_DISABLED); + state = libinput_device_config_dwt_get_default_enabled(device); + ck_assert_int_eq(state, LIBINPUT_CONFIG_DWT_DISABLED); + + status = libinput_device_config_dwt_set_enabled(device, + LIBINPUT_CONFIG_DWT_ENABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + status = libinput_device_config_dwt_set_enabled(device, + LIBINPUT_CONFIG_DWT_DISABLED); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + status = libinput_device_config_dwt_set_enabled(device, 3); + ck_assert_int_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; + + disable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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; + + enable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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(); + libinput_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; + + enable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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; + + enable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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); + libinput_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; + + enable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_dispatch(li); + + /* touch down during timeout, wait, should generate events */ + litest_touch_down(touchpad, 0, 50, 50); + libinput_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; + + disable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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; + + disable_dwt(touchpad); + + keyboard = dwt_init_paired_keyboard(li, touchpad); + litest_disable_tap(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); + libinput_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_enable_tap(touchpad->libinput_device); + disable_dwt(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_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + + litest_touch_down(touchpad, 0, 50, 50); + libinput_dispatch(li); + enable_dwt(touchpad); + libinput_dispatch(li); + litest_touch_up(touchpad, 0); + libinput_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_enable_tap(touchpad->libinput_device); + enable_dwt(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); + libinput_dispatch(li); + + litest_touch_down(touchpad, 0, 50, 50); + libinput_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; + + ck_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); + libinput_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; + + ck_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); + libinput_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; + + ck_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_multiple_keyboards_bothkeys) +{ + struct litest_device *touchpad = litest_current_device(); + struct litest_device *k1, *k2; + struct libinput *li = touchpad->libinput; + + ck_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; + + ck_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 = _i; /* ranged test */ + struct litest_device *removed, *remained; + + ck_assert_int_le(which, 1); + + ck_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_disable_tap(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_disable_tap(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); + + if (libevdev_get_num_slots(dev->evdev) < 3) + return; + + litest_drain_events(li); + + /* exceed the speed movement threshold in slot 0 */ + 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); + + /* scroll in slots 1 and 2, despite another finger down this is a + * 2fg gesture */ + litest_touch_down(dev, 1, 50, 50); + litest_touch_down(dev, 2, 55, 50); + libinput_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, 50, y + 1, 1); + } + libinput_dispatch(li); + litest_touch_up(dev, 1); + litest_touch_up(dev, 2); + libinput_dispatch(li); + litest_assert_scroll(li, 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_disable_tap(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 */ + libinput_dispatch(li); + litest_touch_down(dev, 1, 60, 50); + libinput_dispatch(li); + litest_button_click(dev, BTN_LEFT, true); + + libinput_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 */ + libinput_dispatch(li); + litest_touch_down(dev, 0, 50, 50); + libinput_dispatch(li); + litest_button_click(dev, BTN_LEFT, true); + + libinput_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_disable_tap(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 */ + libinput_dispatch(li); + litest_button_click(dev, BTN_LEFT, true); + + /* button areas work as usual with a thumb */ + + libinput_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); + + if (!has_thumb_detect(dev)) + return; + + 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); + libinput_dispatch(li); + litest_touch_down(dev, 1, 70, 99); + libinput_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_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_dispatch(li); + litest_event(dev, EV_KEY, BTN_LEFT, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_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); + libinput_dispatch(li); + litest_event(dev, EV_KEY, BTN_LEFT, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_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; + struct libinput_event_pointer *ptrev; + 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]); + libinput_dispatch(li); + litest_touch_down(dev, 1, start[1][0], start[1][1]); + libinput_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); + libinput_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); + libinput_dispatch(li); + litest_timeout_gesture(); + libinput_dispatch(li); + /* drain a potential scroll stop */ + litest_drain_events(li); + litest_touch_move_to(dev, second, 50, 21, 50, 11, 20); + libinput_dispatch(li); + event = libinput_get_event(li); + do { + ptrev = litest_is_motion_event(event); + ck_assert_double_eq(libinput_event_pointer_get_dx(ptrev), 0.0); + ck_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); + + libinput_unref(li); +} +END_TEST + +START_TEST(touchpad_time_usec) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_pointer *ptrev; + + litest_disable_tap(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); + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + while (event) { + uint64_t utime; + + ptrev = litest_is_motion_event(event); + utime = libinput_event_pointer_get_time_usec(ptrev); + + ck_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; + struct libinput_event_pointer *ptrev; + + 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 */ + libinput_dispatch(li); + event = libinput_get_event(li); + do { + double dx, dy; + + ptrev = litest_is_motion_event(event); + dx = libinput_event_pointer_get_dx(ptrev); + dy = libinput_event_pointer_get_dy(ptrev); + ck_assert_int_lt(abs((int)dx), 20); + ck_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; + struct libinput_event_pointer *ptrev; + + 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 */ + libinput_dispatch(li); + event = libinput_get_event(li); + do { + double dx, dy; + + ptrev = litest_is_motion_event(event); + dx = libinput_event_pointer_get_dx(ptrev); + dy = libinput_event_pointer_get_dy(ptrev); + ck_assert_int_lt(abs((int)dx), 20); + ck_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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); + ck_assert_int_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 (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_PRESSURE)) + return true; + + 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_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_drain_events(li); + + litest_touch_down(dev, 0, 30, 50); + litest_touch_down_extended(dev, 1, 50, 50, axes); + libinput_dispatch(li); + litest_touch_move_to(dev, 0, 50, 50, 80, 80, 10); + libinput_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; + + /* 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); + libinput_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); + libinput_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_enable_tap(dev->libinput_device); + litest_drain_events(li); + + litest_touch_down_extended(dev, 0, 50, 50, axes); + libinput_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_enable_tap(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); + libinput_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_enable_tap(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); + libinput_dispatch(li); + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + libinput_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(); + libinput_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; + + if (!touchpad_has_pressure(dev)) + return; + + litest_enable_tap(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); + libinput_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); + libinput_dispatch(li); + + /* make one finger real */ + litest_touch_move_to(dev, 0, 40, 50, 41, 52, 10); + 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); + libinput_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); + libinput_dispatch(li); + + litest_timeout_tap(); + libinput_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); + libinput_dispatch(li); + + litest_assert_scroll(li, 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); + libinput_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_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_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_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_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); + libinput_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); + libinput_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_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) || + !touchpad_has_palm_detect_size(dev) || + !litest_has_2fg_scroll(dev)) + return; + + 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); + libinput_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; + + 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(); + libinput_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; + + 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); + libinput_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; + + if (!litest_has_2fg_scroll(dev)) + return; + + 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); + libinput_dispatch(li); + + litest_touch_up(dev, 0); + litest_touch_up(dev, 1); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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_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); + libinput_dispatch(li); + + litest_touch_up(dev, 0); + libinput_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_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); + libinput_dispatch(li); + + litest_touch_up(dev, 2); + libinput_dispatch(li); + litest_touch_up(dev, 1); + litest_touch_up(dev, 0); + + litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); +} +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 = _i; /* ranged test */ + enum suspend other; + + if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) + return; + + lid = litest_add_device(li, LITEST_LID_SWITCH); + tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); + extmouse = litest_add_device(li, LITEST_MOUSE); + + litest_disable_tap(tp->libinput_device); + + /* ABBA test for touchpad internal suspend: + * reason A on + * reason B on + * reason B off + * reason A off + */ + for (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: + ck_abort(); + } + + 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: + ck_abort(); + } + + 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: + ck_abort(); + } + + litest_drain_events(li); + assert_touchpad_moves(tp); + } + +out: + 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 = _i; /* ranged test */ + enum suspend other; + + if (first == SUSPEND_EXT_MOUSE && litest_touchpad_is_external(tp)) + return; + + lid = litest_add_device(li, LITEST_LID_SWITCH); + tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS); + extmouse = litest_add_device(li, LITEST_MOUSE); + + litest_disable_tap(tp->libinput_device); + + /* ABAB test for touchpad internal suspend: + * reason A on + * reason B on + * reason A off + * reason B off + */ + for (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: + ck_abort(); + } + + 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: + ck_abort(); + } + + 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: + ck_abort(); + } + + 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: + ck_abort(); + } + + litest_drain_events(li); + assert_touchpad_moves(tp); + } + +out: + 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_drain_events(li); + + litest_touch_down(dev, 0, 50, 50); + litest_touch_move(dev, 0, 50.1, 50.1); + libinput_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); + libinput_dispatch(li); + litest_restore_log_handler(li); + + litest_assert_empty_queue(li); + + litest_timeout_tap(); + libinput_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 */ + ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_X), 0); + ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_Y), 0); + + if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X)) + ck_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)) + ck_assert_int_eq(libevdev_get_abs_fuzz(evdev, ABS_MT_POSITION_Y), 0); +} +END_TEST + +TEST_COLLECTION(touchpad) +{ + struct range suspends = { SUSPEND_EXT_MOUSE, SUSPEND_COUNT }; + struct range axis_range = {ABS_X, ABS_Y + 1}; + struct range twice = {0, 2 }; + + litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + + litest_add("touchpad:scroll", touchpad_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("touchpad:scroll", touchpad_2fg_scroll_initially_diagonal, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("touchpad:scroll", touchpad_2fg_scroll_axis_lock, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("touchpad:scroll", touchpad_2fg_scroll_axis_lock_switch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + + litest_add("touchpad:scroll", touchpad_2fg_scroll_slow_distance, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_2fg_scroll_return_to_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_2fg_scroll_source, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_2fg_scroll_semi_mt, LITEST_SEMI_MT, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_2fg_scroll_from_btnareas, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_scroll_natural_defaults, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_scroll_natural_enable_config, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_scroll_natural_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_scroll_natural_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_scroll_defaults, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_vert, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:scroll", touchpad_edge_scroll_horiz_clickpad, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_no_horiz, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:scroll", touchpad_edge_scroll_no_motion, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_no_edge_after_motion, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_timeout, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_source, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_no_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:scroll", touchpad_edge_scroll_into_buttonareas, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_within_buttonareas, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_buttonareas_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_clickfinger_click_stops_scroll, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:scroll", touchpad_edge_scroll_into_area, LITEST_TOUCHPAD, LITEST_ANY); + + litest_add("touchpad:palm", touchpad_palm_detect_at_edge, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_at_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_at_bottom_corners, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:palm", touchpad_palm_detect_at_top_corners, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_top_palm_becomes_pointer, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_palm_stays_palm, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_top_palm_stays_palm, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_no_palm_moving_into_edges, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_no_palm_moving_into_top, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_no_tap_top_edge, LITEST_TOUCHPAD, LITEST_TOPBUTTONPAD); + litest_add("touchpad:palm", touchpad_palm_detect_tap_hardbuttons, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:palm", touchpad_palm_detect_tap_softbuttons, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_tap_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_no_palm_detect_at_edge_for_edge_scrolling, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:palm", touchpad_no_palm_detect_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_both_edges, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm_on_off, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_tool_palm_tap_after, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + + litest_add("touchpad:palm", touchpad_palm_detect_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_touch_size_late, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_touch_size_keep_palm, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_touch_size_after_edge, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_touch_size_after_dwt, LITEST_APPLE_CLICKPAD, LITEST_ANY); + + litest_add("touchpad:palm", touchpad_palm_detect_pressure, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_late_tap, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_tap_hold, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_tap_hold_2ndfg, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_move_and_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_late, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_keep_palm, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_after_edge, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_detect_pressure_after_dwt, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:palm", touchpad_palm_clickfinger_pressure, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_clickfinger_pressure_2fg, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_clickfinger_size, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:palm", touchpad_palm_clickfinger_size_2fg, LITEST_CLICKPAD, LITEST_ANY); + + litest_add("touchpad:left-handed", touchpad_left_handed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add_for_device("touchpad:left-handed", touchpad_left_handed_appletouch, LITEST_APPLETOUCH); + litest_add("touchpad:left-handed", touchpad_left_handed_clickpad, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:left-handed", touchpad_left_handed_clickfinger, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:left-handed", touchpad_left_handed_tapping, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:left-handed", touchpad_left_handed_tapping_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:left-handed", touchpad_left_handed_delayed, LITEST_TOUCHPAD|LITEST_BUTTON, LITEST_CLICKPAD); + litest_add("touchpad:left-handed", touchpad_left_handed_clickpad_delayed, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); + litest_add("touchpad:left-handed", 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", touchpad_semi_mt_hover_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_down_up, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_down_hover_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_2fg_noevent, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_2fg_1fg_down, LITEST_SYNAPTICS_HOVER_SEMI_MT); + litest_add_for_device("touchpad:semi-mt-hover", touchpad_semi_mt_hover_2fg_up, LITEST_SYNAPTICS_HOVER_SEMI_MT); + + litest_add("touchpad:hover", touchpad_hover_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_down_up, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_down_hover_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_2fg_noevent, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_2fg_1fg_down, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + litest_add("touchpad:hover", touchpad_hover_1fg_tap, LITEST_TOUCHPAD|LITEST_HOVER, LITEST_ANY); + + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_buttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_mb_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_mb_click, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_buttons_softbuttons, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_buttons_2fg_scroll, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + litest_add_for_device("touchpad:trackpoint", touchpad_trackpoint_no_trackpoint, LITEST_SYNAPTICS_TRACKPOINT_BUTTONS); + + litest_add_ranged("touchpad:state", touchpad_initial_state, LITEST_TOUCHPAD, LITEST_ANY, &axis_range); + + litest_add("touchpad:dwt", touchpad_dwt, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_for_device("touchpad:dwt", touchpad_dwt_ext_and_int_keyboard, LITEST_SYNAPTICS_I2C); + litest_add("touchpad:dwt", touchpad_dwt_enable_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_touch_hold, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_key_hold, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_key_hold_timeout, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_key_hold_timeout_existing_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_key_hold_timeout_existing_touch_cornercase, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_type, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_type_short_timeout, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_modifier_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_modifier_combo_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_modifier_combo_dwt_after, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_modifier_combo_dwt_remains, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_fkeys_no_dwt, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_tap_drag, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_click, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_edge_scroll, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:dwt", touchpad_dwt_edge_scroll_interrupt, LITEST_TOUCHPAD, LITEST_CLICKPAD); + litest_add("touchpad:dwt", touchpad_dwt_config_default_on, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_config_default_off, LITEST_ANY, LITEST_TOUCHPAD); + litest_add("touchpad:dwt", touchpad_dwt_disabled, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_disable_during_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_disable_before_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_disable_during_key_release, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_disable_during_key_hold, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_enable_during_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_enable_before_touch, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_enable_during_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:dwt", touchpad_dwt_remove_kbd_while_active, LITEST_TOUCHPAD, LITEST_ANY); + litest_add_for_device("touchpad:dwt", touchpad_dwt_apple, LITEST_BCM5974); + litest_add_for_device("touchpad:dwt", touchpad_dwt_acer_hawaii, LITEST_ACER_HAWAII_TOUCHPAD); + litest_add_for_device("touchpad:dwt", touchpad_dwt_multiple_keyboards, LITEST_SYNAPTICS_I2C); + litest_add_for_device("touchpad:dwt", touchpad_dwt_multiple_keyboards_bothkeys, LITEST_SYNAPTICS_I2C); + litest_add_for_device("touchpad:dwt", touchpad_dwt_multiple_keyboards_bothkeys_modifier, LITEST_SYNAPTICS_I2C); + litest_add_ranged_for_device("touchpad:dwt", touchpad_dwt_multiple_keyboards_remove, LITEST_SYNAPTICS_I2C, &twice); + + litest_add("touchpad:thumb", touchpad_thumb_lower_area_movement, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:thumb", touchpad_thumb_lower_area_movement_rethumb, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:thumb", touchpad_thumb_speed_empty_slots, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:thumb", touchpad_thumb_area_clickfinger, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:thumb", touchpad_thumb_area_btnarea, LITEST_CLICKPAD, LITEST_ANY); + litest_add("touchpad:thumb", touchpad_thumb_no_doublethumb, LITEST_CLICKPAD, LITEST_ANY); + + litest_add_for_device("touchpad:bugs", touchpad_tool_tripletap_touch_count, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add_for_device("touchpad:bugs", touchpad_tool_tripletap_touch_count_late, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add_for_device("touchpad:bugs", touchpad_slot_swap, LITEST_SYNAPTICS_TOPBUTTONPAD); + litest_add_for_device("touchpad:bugs", touchpad_finger_always_down, LITEST_SYNAPTICS_TOPBUTTONPAD); + + litest_add("touchpad:time", touchpad_time_usec, LITEST_TOUCHPAD, LITEST_ANY); + + litest_add_for_device("touchpad:jumps", touchpad_jump_finger_motion, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("touchpad:jumps", touchpad_jump_delta, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add_for_device("touchpad:sendevents", touchpad_disabled_on_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("touchpad:sendevents", touchpad_disabled_on_mouse_suspend_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("touchpad:sendevents", touchpad_disabled_double_mouse, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("touchpad:sendevents", touchpad_disabled_double_mouse_one_suspended, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add("touchpad:pressure", touchpad_pressure, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:pressure", touchpad_pressure_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:pressure", touchpad_pressure_2fg_st, LITEST_TOUCHPAD|LITEST_SINGLE_TOUCH, LITEST_ANY); + litest_add("touchpad:pressure", touchpad_pressure_tap, LITEST_TOUCHPAD, LITEST_ANY); + litest_add("touchpad:pressure", touchpad_pressure_tap_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:pressure", touchpad_pressure_tap_2fg_1fg_light, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:pressure", touchpad_pressure_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH); + litest_add("touchpad:pressure", touchpad_pressure_semi_mt_2fg_goes_light, LITEST_SEMI_MT, LITEST_ANY); + + litest_add("touchpad:touch-size", touchpad_touch_size, LITEST_APPLE_CLICKPAD, LITEST_ANY); + litest_add("touchpad:touch-size", touchpad_touch_size_2fg, LITEST_APPLE_CLICKPAD, LITEST_ANY); + + litest_add("touchpad:speed", touchpad_speed_ignore_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("touchpad:speed", touchpad_speed_allow_nearby_finger, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add("touchpad:speed", touchpad_speed_ignore_finger_edgescroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT); + litest_add_for_device("touchpad:speed", touchpad_speed_ignore_hovering_finger, LITEST_BCM5974); + + litest_add_ranged("touchpad:suspend", touchpad_suspend_abba, LITEST_TOUCHPAD, LITEST_ANY, &suspends); + litest_add_ranged("touchpad:suspend", touchpad_suspend_abab, LITEST_TOUCHPAD, LITEST_ANY, &suspends); + + /* Happens on the "Wacom Intuos Pro M Finger" but our test device + * has the same properties */ + litest_add_for_device("touchpad:bugs", touchpad_end_start_touch, LITEST_WACOM_FINGER); + + litest_add("touchpad:fuzz", touchpad_fuzz, LITEST_TOUCHPAD, LITEST_ANY); +} diff --git a/test/test-trackball.c b/test/test-trackball.c new file mode 100644 index 0000000..5502585 --- /dev/null +++ b/test/test-trackball.c @@ -0,0 +1,272 @@ +/* + * 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 + +#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; + + ck_assert(libinput_device_config_rotation_is_available(device)); + + angle = libinput_device_config_rotation_get_angle(device); + ck_assert_int_eq(angle, 0); + angle = libinput_device_config_rotation_get_default_angle(device); + ck_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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + status = libinput_device_config_rotation_set_angle(device, 361); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + status = libinput_device_config_rotation_set_angle(device, -1); + ck_assert_int_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; + + ck_assert(!libinput_device_config_rotation_is_available(device)); + + angle = libinput_device_config_rotation_get_angle(device); + ck_assert_int_eq(angle, 0); + angle = libinput_device_config_rotation_get_default_angle(device); + ck_assert_int_eq(angle, 0); + + /* 0 always succeeds */ + status = libinput_device_config_rotation_set_angle(device, 0); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + for (angle = 1; angle < 360; angle++) { + if (angle % 90 == 0) + continue; + status = libinput_device_config_rotation_set_angle(device, + angle); + ck_assert_int_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; + + ck_assert(libinput_device_config_rotation_is_available(device)); + + for (angle = 0; angle < 360; angle += 90) { + status = libinput_device_config_rotation_set_angle(device, + angle); + ck_assert_int_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; + + ck_assert(libinput_device_config_rotation_is_available(device)); + + for (angle = 0; angle < 360; angle++) { + if (angle % 90 == 0) + continue; + status = libinput_device_config_rotation_set_angle(device, + angle); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID); + } +} +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); + libinput_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: + ck_assert_double_eq(dx, 1.0); + ck_assert_double_eq(dy, 0.0); + break; + case 90: + ck_assert_double_eq(dx, 0.0); + ck_assert_double_eq(dy, 1.0); + break; + case 180: + ck_assert_double_eq(dx, -1.0); + ck_assert_double_eq(dy, 0.0); + break; + case 270: + ck_assert_double_eq(dx, 0.0); + ck_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); + libinput_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: + ck_assert_double_eq(dx, 0.0); + ck_assert_double_eq(dy, 1.0); + break; + case 90: + ck_assert_double_eq(dx, -1.0); + ck_assert_double_eq(dy, 0.0); + break; + case 180: + ck_assert_double_eq(dx, 0.0); + ck_assert_double_eq(dy, -1.0); + break; + case 270: + ck_assert_double_eq(dx, 1.0); + ck_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); + libinput_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); + + ck_assert_double_lt(dx, 0.0); + ck_assert_double_gt(dy, 0.0); + libinput_event_destroy(event); +} +END_TEST + +TEST_COLLECTION(trackball) +{ + litest_add("trackball:rotation", trackball_rotation_config_defaults, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_config_invalid_range, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_config_no_rotation, LITEST_ANY, LITEST_TRACKBALL); + litest_add("trackball:rotation", trackball_rotation_config_right_angle, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_config_odd_angle, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_x, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_y, LITEST_TRACKBALL, LITEST_ANY); + litest_add("trackball:rotation", trackball_rotation_accel, LITEST_TRACKBALL, LITEST_ANY); +} diff --git a/test/test-trackpoint.c b/test/test-trackpoint.c new file mode 100644 index 0000000..66e5824 --- /dev/null +++ b/test/test-trackpoint.c @@ -0,0 +1,425 @@ +/* + * 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 "libinput-util.h" +#include "litest.h" + +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); + + ck_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_POINTER_AXIS_SCROLL_VERTICAL, 6); + litest_button_scroll(dev, BTN_MIDDLE, 1, -7); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7); + litest_button_scroll(dev, BTN_MIDDLE, 8, 1); + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8); + litest_button_scroll(dev, BTN_MIDDLE, -9, 1); + litest_assert_scroll(li, 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); + ck_assert_notnull(event); + ck_assert_int_eq(libinput_event_get_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, -1); + + while ((event = libinput_get_event(li))) { + ptrev = libinput_event_get_pointer_event(event); + + ck_assert_int_eq(libinput_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; + + 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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_touch_down(touchpad, 0, 5, 5); + libinput_dispatch(li); + litest_button_click_debounced(touchpad, li, BTN_LEFT, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_button_event(event, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_PRESSED); + device = libinput_event_get_device(event); + ck_assert(device == trackpoint->libinput_device); + libinput_event_destroy(event); + + litest_button_click_debounced(touchpad, li, BTN_LEFT, false); + libinput_dispatch(li); + event = libinput_get_event(li); + litest_is_button_event(event, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_RELEASED); + device = libinput_event_get_device(event); + ck_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; + + 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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_touch_down(touchpad, 0, 5, 5); + libinput_dispatch(li); + litest_button_click_debounced(touchpad, li, BTN_LEFT, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); + device = libinput_event_get_device(event); + ck_assert(device == trackpoint->libinput_device); + libinput_event_destroy(event); + + litest_button_click_debounced(touchpad, li, BTN_LEFT, false); + libinput_dispatch(li); + event = libinput_get_event(li); + litest_is_button_event(event, + BTN_LEFT, + LIBINPUT_BUTTON_STATE_RELEASED); + device = libinput_event_get_device(event); + ck_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; + + 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); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + status = libinput_device_config_left_handed_set( + trackpoint->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_touch_down(touchpad, 0, 5, 5); + libinput_dispatch(li); + litest_button_click_debounced(touchpad, li, BTN_LEFT, true); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_button_event(event, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_PRESSED); + device = libinput_event_get_device(event); + ck_assert(device == trackpoint->libinput_device); + libinput_event_destroy(event); + + litest_button_click_debounced(touchpad, li, BTN_LEFT, false); + libinput_dispatch(li); + event = libinput_get_event(li); + litest_is_button_event(event, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_RELEASED); + device = libinput_event_get_device(event); + ck_assert(device == trackpoint->libinput_device); + libinput_event_destroy(event); + + litest_delete_device(trackpoint); +} +END_TEST + +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); + 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); + libinput_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(); + libinput_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_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); + 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); + libinput_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(); + libinput_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); + 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); + libinput_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); + 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); + libinput_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", trackpoint_middlebutton, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:middlebutton", trackpoint_middlebutton_noscroll, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:scroll", trackpoint_scroll, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:scroll", trackpoint_scroll_source, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_trackpoint, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_touchpad, LITEST_TOPBUTTONPAD, LITEST_ANY); + litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_both, LITEST_TOPBUTTONPAD, LITEST_ANY); + + litest_add("trackpoint:palmdetect", trackpoint_palmdetect, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:palmdetect", trackpoint_palmdetect_resume_touch, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:palmdetect", trackpoint_palmdetect_require_min_events, LITEST_POINTINGSTICK, LITEST_ANY); + litest_add("trackpoint:palmdetect", trackpoint_palmdetect_require_min_events_timeout, LITEST_POINTINGSTICK, LITEST_ANY); +} diff --git a/test/test-udev.c b/test/test-udev.c new file mode 100644 index 0000000..592109c --- /dev/null +++ b/test/test-udev.c @@ -0,0 +1,698 @@ +/* + * 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 "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); + ck_assert(li == NULL); + + li = libinput_udev_create_context(&simple_interface, NULL, NULL); + ck_assert(li == NULL); + + li = libinput_udev_create_context(NULL, NULL, udev); + ck_assert(li == NULL); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + fd = libinput_get_fd(li); + ck_assert_int_ge(fd, 0); + + /* expect at least one event */ + libinput_dispatch(li); + event = libinput_get_event(li); + ck_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(); + ck_assert_notnull(udev); + + /* expect a libinput reference, but no events */ + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seatdoesntexist"), 0); + + fd = libinput_get_fd(li); + ck_assert_int_ge(fd, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + litest_set_log_handler_bug(li); + + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, &data1, udev); + ck_assert_notnull(li); + ck_assert(libinput_get_user_data(li) == &data1); + libinput_set_user_data(li, &data2); + ck_assert(libinput_get_user_data(li) == &data2); + + libinput_unref(li); + udev_unref(udev); +} +END_TEST + +/** + * This test only works if there's at least one device in the system that is + * assigned the default seat. Should cover the 99% case. + */ +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; + enum libinput_event_type type; + int default_seat_found = 0; + + udev = udev_new(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + libinput_dispatch(li); + + while (!default_seat_found && (event = libinput_get_event(li))) { + type = libinput_event_get_type(event); + if (type != LIBINPUT_EVENT_DEVICE_ADDED) { + libinput_event_destroy(event); + continue; + } + + device = libinput_event_get_device(event); + seat = libinput_device_get_seat(device); + ck_assert_notnull(seat); + + seat_name = libinput_seat_get_logical_name(seat); + default_seat_found = streq(seat_name, "default"); + libinput_event_destroy(event); + } + + ck_assert(default_seat_found); + + libinput_unref(li); + udev_unref(udev); +} +END_TEST + +/** + * This test only works if there's at least one device in the system that is + * assigned the default seat. Should cover the 99% case. + */ +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; + + udev = udev_new(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_notnull(event); + + ck_assert_int_eq(libinput_event_get_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); + ck_assert_int_eq(rc, 0); + + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_DEVICE_REMOVED); + + ck_assert(libinput_event_get_device(event) == device); + libinput_event_destroy(event); + + event = libinput_get_event(li); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_DEVICE_ADDED); + ck_assert(libinput_event_get_device(event) != device); + libinput_device_unref(device); + + device = libinput_event_get_device(event); + seat2 = libinput_device_get_seat(device); + + ck_assert_str_ne(libinput_seat_get_logical_name(seat2), + seat1_name); + ck_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); +} +END_TEST + +START_TEST(udev_double_suspend) +{ + struct libinput *li; + struct libinput_event *event; + struct udev *udev; + int fd; + + udev = udev_new(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + fd = libinput_get_fd(li); + ck_assert_int_ge(fd, 0); + + /* expect at least one event */ + ck_assert_int_ge(libinput_dispatch(li), 0); + event = libinput_get_event(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + fd = libinput_get_fd(li); + ck_assert_int_ge(fd, 0); + + /* expect at least one event */ + ck_assert_int_ge(libinput_dispatch(li), 0); + event = libinput_get_event(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + fd = libinput_get_fd(li); + ck_assert_int_ge(fd, 0); + + /* Check that at least one device was discovered after creation. */ + ck_assert_int_ge(libinput_dispatch(li), 0); + process_events_count_devices(li, &num_devices); + ck_assert_int_gt(num_devices, 0); + + /* Check that after a suspend, no devices are left. */ + libinput_suspend(li); + ck_assert_int_ge(libinput_dispatch(li), 0); + process_events_count_devices(li, &num_devices); + ck_assert_int_eq(num_devices, 0); + + /* Check that after a resume, at least one device is discovered. */ + libinput_resume(li); + ck_assert_int_ge(libinput_dispatch(li), 0); + process_events_count_devices(li, &num_devices); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + + rc = libinput_resume(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + + libinput_suspend(li); + rc = libinput_resume(li); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + libinput_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); + ck_assert_notnull(sysname); + ck_assert_int_gt(strlen(sysname), 1); + ck_assert(strchr(sysname, '/') == NULL); + ck_assert_int_eq(strncmp(sysname, "event", 5), 0); + 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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + + libinput_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); + ck_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); + } + + ck_assert_notnull(saved_seat); + + libinput_suspend(li); + + litest_drain_events(li); + + libinput_resume(li); + + libinput_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); + ck_assert_notnull(device); + + seat = libinput_device_get_seat(device); + user_data = libinput_seat_get_user_data(seat); + if (user_data == &data) { + found = 1; + ck_assert(seat == saved_seat); + } + break; + default: + break; + } + + libinput_event_destroy(ev); + } + + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_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"); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1); + event = libinput_get_event(li); + device = libinput_event_get_device(event); + ck_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(); + ck_assert_notnull(udev); + + li = libinput_udev_create_context(&simple_interface, NULL, udev); + ck_assert_notnull(li); + litest_restore_log_handler(li); + + ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + ck_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); + ck_assert_str_ne(devname, name); + } + libinput_event_destroy(event); + libinput_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", udev_create_NULL); + litest_add_no_device("udev:create", udev_create_seat0); + litest_add_no_device("udev:create", udev_create_empty_seat); + litest_add_no_device("udev:create", udev_create_seat_too_long); + litest_add_no_device("udev:create", udev_set_user_data); + + litest_add_no_device("udev:seat", udev_added_seat_default); + litest_add_no_device("udev:seat", udev_change_seat); + + litest_add_for_device("udev:suspend", udev_double_suspend, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:suspend", udev_double_resume, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:suspend", udev_suspend_resume, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:suspend", udev_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:suspend", udev_suspend_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:device events", udev_device_sysname, LITEST_SYNAPTICS_CLICKPAD_X220); + litest_add_for_device("udev:seat", udev_seat_recycle, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add_no_device("udev:path", udev_path_add_device); + litest_add_for_device("udev:path", udev_path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220); + + litest_add_no_device("udev:ignore", udev_ignore_device); +} diff --git a/test/test-utils.c b/test/test-utils.c new file mode 100644 index 0000000..0cde5aa --- /dev/null +++ b/test/test-utils.c @@ -0,0 +1,1085 @@ +/* + * 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 "libinput-util.h" +#define TEST_VERSIONSORT +#include "libinput-versionsort.h" + +#include "check-double-macros.h" + +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: + ck_assert(bit_is_set(read_bitfield, i)); + set_bit(write_bitfield, i); + break; + default: + ck_assert(!bit_is_set(read_bitfield, i)); + clear_bit(write_bitfield, i); + break; + } + } + + ck_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++) { + ck_assert_int_eq(m1.val[row][col], + (row == col) ? 1 : 0); + } + } + ck_assert(matrix_is_identity(&m1)); + + matrix_from_farray6(&m2, f); + ck_assert_int_eq(m2.val[0][0], 1); + ck_assert_int_eq(m2.val[0][1], 2); + ck_assert_int_eq(m2.val[0][2], 3); + ck_assert_int_eq(m2.val[1][0], 4); + ck_assert_int_eq(m2.val[1][1], 5); + ck_assert_int_eq(m2.val[1][2], 6); + ck_assert_int_eq(m2.val[2][0], 0); + ck_assert_int_eq(m2.val[2][1], 0); + ck_assert_int_eq(m2.val[2][2], 1); + + x = 100; + y = 5; + matrix_mult_vec(&m1, &x, &y); + ck_assert_int_eq(x, 100); + ck_assert_int_eq(y, 5); + + matrix_mult(&m3, &m1, &m1); + ck_assert(matrix_is_identity(&m3)); + + matrix_init_scale(&m2, 2, 4); + ck_assert_int_eq(m2.val[0][0], 2); + ck_assert_int_eq(m2.val[0][1], 0); + ck_assert_int_eq(m2.val[0][2], 0); + ck_assert_int_eq(m2.val[1][0], 0); + ck_assert_int_eq(m2.val[1][1], 4); + ck_assert_int_eq(m2.val[1][2], 0); + ck_assert_int_eq(m2.val[2][0], 0); + ck_assert_int_eq(m2.val[2][1], 0); + ck_assert_int_eq(m2.val[2][2], 1); + + matrix_mult_vec(&m2, &x, &y); + ck_assert_int_eq(x, 200); + ck_assert_int_eq(y, 20); + + matrix_init_translate(&m2, 10, 100); + ck_assert_int_eq(m2.val[0][0], 1); + ck_assert_int_eq(m2.val[0][1], 0); + ck_assert_int_eq(m2.val[0][2], 10); + ck_assert_int_eq(m2.val[1][0], 0); + ck_assert_int_eq(m2.val[1][1], 1); + ck_assert_int_eq(m2.val[1][2], 100); + ck_assert_int_eq(m2.val[2][0], 0); + ck_assert_int_eq(m2.val[2][1], 0); + ck_assert_int_eq(m2.val[2][2], 1); + + matrix_mult_vec(&m2, &x, &y); + ck_assert_int_eq(x, 210); + ck_assert_int_eq(y, 120); + + matrix_to_farray6(&m2, f); + ck_assert_int_eq(f[0], 1); + ck_assert_int_eq(f[1], 0); + ck_assert_int_eq(f[2], 10); + ck_assert_int_eq(f[3], 0); + ck_assert_int_eq(f[4], 1); + ck_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) { + ck_assert_int_eq(ratelimit_test(&rl), + RATELIMIT_PASS); + } + + /* the 10th attempt reaches the threshold */ + ck_assert_int_eq(ratelimit_test(&rl), RATELIMIT_THRESHOLD); + + /* ..then further attempts must fail.. */ + ck_assert_int_eq(ratelimit_test(&rl), RATELIMIT_EXCEEDED); + + /* ..regardless of how often we try. */ + for (i = 0; i < 100; ++i) { + ck_assert_int_eq(ratelimit_test(&rl), + RATELIMIT_EXCEEDED); + } + + /* ..even after waiting 20ms */ + msleep(100); + for (i = 0; i < 100; ++i) { + ck_assert_int_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); + ck_assert_int_eq(dpi, tests[i].expected_value); + } + + dpi = parse_mouse_dpi_property(NULL); + ck_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); + ck_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); + ck_assert_int_eq(angle, tests[i].expected_value); + } + + angle = parse_mouse_wheel_click_count_property(NULL); + ck_assert_int_eq(angle, 0); +} +END_TEST + +START_TEST(dimension_prop_parser) +{ + struct parser_test_dimension { + char *tag; + bool success; + int 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); + ck_assert(success == tests[i].success); + if (success) { + ck_assert_int_eq(x, tests[i].x); + ck_assert_int_eq(y, tests[i].y); + } else { + ck_assert_int_eq(x, 0xad); + ck_assert_int_eq(y, 0xad); + } + } + + success = parse_dimension_property(NULL, &x, &y); + ck_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", false, 0 }, + { "", 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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(r, tests[i].reliability); + else + ck_assert_int_eq(r, 0xaf); + } + + success = parse_switch_reliability_property(NULL, &r); + ck_assert(success == true); + ck_assert_int_eq(r, RELIABILITY_UNKNOWN); + + success = parse_switch_reliability_property("foo", NULL); + ck_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); + ck_assert_int_eq(success, tests[i].success); + if (success) + rc = memcmp(tests[i].values, + calibration, + sizeof(calibration)); + else + rc = memcmp(untouched, + calibration, + sizeof(calibration)); + ck_assert_int_eq(rc, 0); + } + + memcpy(calibration, untouched, sizeof(calibration)); + + success = parse_calibration_property(NULL, calibration); + ck_assert(success == false); + rc = memcmp(untouched, calibration, sizeof(calibration)); + ck_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); + ck_assert(success == tests[i].success); + if (success) { + ck_assert_int_eq(hi, tests[i].hi); + ck_assert_int_eq(lo, tests[i].lo); + } else { + ck_assert_int_eq(hi, 0xad); + ck_assert_int_eq(lo, 0xad); + } + } + + success = parse_range_property(NULL, NULL, NULL); + ck_assert(success == false); +} +END_TEST + +START_TEST(evcode_prop_parser) +{ + struct parser_test_tuple { + const char *prop; + bool success; + size_t ntuples; + int tuples[20]; + } tests[] = { + { "EV_KEY", true, 1, {EV_KEY, 0xffff} }, + { "EV_ABS;", true, 1, {EV_ABS, 0xffff} }, + { "ABS_X;", true, 1, {EV_ABS, ABS_X} }, + { "SW_TABLET_MODE;", true, 1, {EV_SW, SW_TABLET_MODE} }, + { "EV_SW", true, 1, {EV_SW, 0xffff} }, + { "ABS_Y", true, 1, {EV_ABS, ABS_Y} }, + { "EV_ABS:0x00", true, 1, {EV_ABS, ABS_X} }, + { "EV_ABS:01", true, 1, {EV_ABS, ABS_Y} }, + { "ABS_TILT_X;ABS_TILT_Y;", true, 2, + { EV_ABS, ABS_TILT_X, + EV_ABS, ABS_TILT_Y} }, + { "BTN_TOOL_DOUBLETAP;EV_KEY;KEY_A", true, 3, + { EV_KEY, BTN_TOOL_DOUBLETAP, + EV_KEY, 0xffff, + EV_KEY, KEY_A } }, + { "REL_Y;ABS_Z;BTN_STYLUS", true, 3, + { EV_REL, REL_Y, + EV_ABS, ABS_Z, + EV_KEY, BTN_STYLUS } }, + { "REL_Y;EV_KEY:0x123;BTN_STYLUS", true, 3, + { EV_REL, REL_Y, + EV_KEY, 0x123, + EV_KEY, BTN_STYLUS } }, + { .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); + ck_assert(success == t->success); + if (!success) + continue; + + ck_assert_int_eq(nevents, t->ntuples); + for (size_t j = 0; j < nevents; j++) { + int type, code; + + type = events[j].type; + code = events[j].code; + ck_assert_int_eq(t->tuples[j * 2], type); + ck_assert_int_eq(t->tuples[j * 2 + 1], code); + } + } +} +END_TEST + +START_TEST(time_conversion) +{ + ck_assert_int_eq(us(10), 10); + ck_assert_int_eq(ns2us(10000), 10); + ck_assert_int_eq(ms2us(10), 10000); + ck_assert_int_eq(s2us(1), 1000000); + ck_assert_int_eq(us2ms(10000), 10); +} +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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_assert_int_eq(v, 0xad); + } +} +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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_assert_int_eq(v, 0xad); + } +} +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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_assert_int_eq(v, 0xad); + } +} +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); + ck_assert(success == tests[i].success); + if (success) + ck_assert_int_eq(v, tests[i].val); + else + ck_assert_int_eq(v, 0xad); + } +} +END_TEST + +START_TEST(strsplit_test) +{ + struct strsplit_test { + const char *string; + const char *delim; + const char *results[10]; + } tests[] = { + { "one two three", " ", { "one", "two", "three", NULL } }, + { "one", " ", { "one", NULL } }, + { "one two ", " ", { "one", "two", NULL } }, + { "one two", " ", { "one", "two", NULL } }, + { " one two", " ", { "one", "two", NULL } }, + { "one", "\t \r", { "one", NULL } }, + { "one two three", " t", { "one", "wo", "hree", NULL } }, + { " one two three", "te", { " on", " ", "wo ", "hr", NULL } }, + { "one", "ne", { "o", NULL } }, + { "onene", "ne", { "o", NULL } }, + { NULL, NULL, { NULL }} + }; + struct strsplit_test *t = tests; + + while (t->string) { + char **strv; + int idx = 0; + strv = strv_from_string(t->string, t->delim); + while (t->results[idx]) { + ck_assert_str_eq(t->results[idx], strv[idx]); + idx++; + } + ck_assert_ptr_eq(strv[idx], NULL); + strv_free(strv); + t++; + } + + /* Special cases */ + ck_assert_ptr_eq(strv_from_string("", " "), NULL); + ck_assert_ptr_eq(strv_from_string(" ", " "), NULL); + ck_assert_ptr_eq(strv_from_string(" ", " "), NULL); + ck_assert_ptr_eq(strv_from_string("oneoneone", "one"), NULL); +} +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); + ck_assert_int_eq(npairs, t->nresults); + + for (ssize_t i = 0; i < npairs; i++) { + ck_assert_double_eq(t->results[i].a, result[i].key); + ck_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) + ck_assert(str == NULL); + else + ck_assert_str_eq(str, t->result); + free(str); + t++; + } + + ck_assert(strv_join(nulltest.strv, "x") == NULL); +} +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) { + ck_assert_int_eq(t->val, val); + val--; + } + + ck_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) { + ck_assert_int_eq(t->val, val); + val++; + } + ck_assert_int_eq(val, 5); +} +END_TEST + +START_TEST(strverscmp_test) +{ + ck_assert_int_eq(libinput_strverscmp("", ""), 0); + ck_assert_int_gt(libinput_strverscmp("0.0.1", ""), 0); + ck_assert_int_lt(libinput_strverscmp("", "0.0.1"), 0); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.1"), 0); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.2"), -1); + ck_assert_int_eq(libinput_strverscmp("0.0.2", "0.0.1"), 1); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.1.0"), -1); + ck_assert_int_eq(libinput_strverscmp("0.1.0", "0.0.1"), 1); +} +END_TEST + +static Suite * +litest_utils_suite(void) +{ + TCase *tc; + Suite *s; + + s = suite_create("litest:utils"); + tc = tcase_create("utils"); + + tcase_add_test(tc, bitfield_helpers); + tcase_add_test(tc, matrix_helpers); + tcase_add_test(tc, ratelimit_helpers); + tcase_add_test(tc, dpi_parser); + tcase_add_test(tc, wheel_click_parser); + tcase_add_test(tc, wheel_click_count_parser); + tcase_add_test(tc, dimension_prop_parser); + tcase_add_test(tc, reliability_prop_parser); + tcase_add_test(tc, calibration_prop_parser); + tcase_add_test(tc, range_prop_parser); + tcase_add_test(tc, evcode_prop_parser); + tcase_add_test(tc, safe_atoi_test); + tcase_add_test(tc, safe_atoi_base_16_test); + tcase_add_test(tc, safe_atoi_base_8_test); + tcase_add_test(tc, safe_atou_test); + tcase_add_test(tc, safe_atou_base_16_test); + tcase_add_test(tc, safe_atou_base_8_test); + tcase_add_test(tc, safe_atod_test); + tcase_add_test(tc, strsplit_test); + tcase_add_test(tc, kvsplit_double_test); + tcase_add_test(tc, strjoin_test); + tcase_add_test(tc, time_conversion); + + tcase_add_test(tc, list_test_insert); + tcase_add_test(tc, list_test_append); + tcase_add_test(tc, strverscmp_test); + + return s; +} + +int main(int argc, char **argv) +{ + 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; + + s = litest_utils_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; +} diff --git a/test/valgrind.suppressions b/test/valgrind.suppressions new file mode 100644 index 0000000..7ca3b5b --- /dev/null +++ b/test/valgrind.suppressions @@ -0,0 +1,91 @@ +{ + 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 +} +{ + 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 +} diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c new file mode 100644 index 0000000..23926af --- /dev/null +++ b/tools/libinput-debug-events.c @@ -0,0 +1,1036 @@ +/* + * 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 +#include +#include "linux/input.h" +#include + +#include +#include + +#include "shared.h" + +static uint32_t start_time; +static const uint32_t screen_width = 100; +static const uint32_t screen_height = 100; +static struct tools_options options; +static bool show_keycodes; +static volatile sig_atomic_t stop = 0; +static bool be_quiet = false; + +#define printq(...) ({ if (!be_quiet) printf(__VA_ARGS__); }) + +static void +print_event_header(struct libinput_event *ev) +{ + /* 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 = NULL; + char prefix; + + switch(libinput_event_get_type(ev)) { + 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_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_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_SWITCH_TOGGLE: + type = "SWITCH_TOGGLE"; + break; + } + + prefix = (last_device != dev) ? '-' : ' '; + + printq("%c%-7s %-16s ", + prefix, + libinput_device_get_sysname(dev), + type); + + last_device = dev; +} + +static void +print_event_time(uint32_t time) +{ + printq("%+6.2fs ", (time - start_time) / 1000.0); +} + +static inline void +print_device_options(struct libinput_device *dev) +{ + uint32_t scroll_methods, click_methods; + + if (libinput_device_config_tap_get_finger_count(dev)) { + printq(" tap"); + if (libinput_device_config_tap_get_drag_lock_enabled(dev)) + printq("(dl on)"); + else + printq("(dl off)"); + } + if (libinput_device_config_left_handed_is_available(dev)) + printq(" left"); + if (libinput_device_config_scroll_has_natural_scroll(dev)) + printq(" scroll-nat"); + if (libinput_device_config_calibration_has_matrix(dev)) + printq(" calib"); + + scroll_methods = libinput_device_config_scroll_get_methods(dev); + if (scroll_methods != LIBINPUT_CONFIG_SCROLL_NO_SCROLL) { + printq(" scroll"); + if (scroll_methods & LIBINPUT_CONFIG_SCROLL_2FG) + printq("-2fg"); + if (scroll_methods & LIBINPUT_CONFIG_SCROLL_EDGE) + printq("-edge"); + if (scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) + printq("-button"); + } + + click_methods = libinput_device_config_click_get_methods(dev); + if (click_methods != LIBINPUT_CONFIG_CLICK_METHOD_NONE) { + printq(" click"); + if (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) + printq("-buttonareas"); + if (click_methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) + printq("-clickfinger"); + } + + if (libinput_device_config_dwt_is_available(dev)) { + if (libinput_device_config_dwt_get_enabled(dev) == + LIBINPUT_CONFIG_DWT_ENABLED) + printq(" dwt-on"); + else + printq(" dwt-off)"); + } + + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TABLET_PAD)) { + int nbuttons, nstrips, nrings, ngroups; + + nbuttons = libinput_device_tablet_pad_get_num_buttons(dev); + nstrips = libinput_device_tablet_pad_get_num_strips(dev); + nrings = libinput_device_tablet_pad_get_num_rings(dev); + ngroups = libinput_device_tablet_pad_get_num_mode_groups(dev); + + printq(" buttons:%d strips:%d rings:%d mode groups:%d", + nbuttons, + nstrips, + nrings, + ngroups); + } +} + +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; + double w, h; + static int next_group_id = 0; + intptr_t group_id; + + 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); + } + + printq("%-33s %5s %7s group%-2d", + libinput_device_get_name(dev), + libinput_seat_get_physical_name(seat), + libinput_seat_get_logical_name(seat), + (int)group_id); + + printq(" cap:"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_KEYBOARD)) + printq("k"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_POINTER)) + printq("p"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TOUCH)) + printq("t"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_GESTURE)) + printq("g"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TABLET_TOOL)) + printq("T"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TABLET_PAD)) + printq("P"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_SWITCH)) + printq("S"); + + if (libinput_device_get_size(dev, &w, &h) == 0) + printq(" size %.0fx%.0fmm", w, h); + + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TOUCH)) + printq(" ntouches %d", libinput_device_touch_get_touch_count(dev)); + + if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) + print_device_options(dev); + + printq("\n"); + +} + +static void +print_key_event(struct libinput *li, struct libinput_event *ev) +{ + struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev); + enum libinput_key_state state; + uint32_t key; + const char *keyname; + + print_event_time(libinput_event_keyboard_get_time(k)); + state = libinput_event_keyboard_get_key_state(k); + + key = libinput_event_keyboard_get_key(k); + if (!show_keycodes && (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) { + keyname = "***"; + key = -1; + } else { + keyname = libevdev_event_code_get_name(EV_KEY, key); + keyname = keyname ? keyname : "???"; + } + printq("%s (%d) %s\n", + keyname, + key, + state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released"); +} + +static void +print_motion_event(struct libinput_event *ev) +{ + 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); + + print_event_time(libinput_event_pointer_get_time(p)); + + printq("%6.2f/%6.2f (%+6.2f/%+6.2f)\n", x, y, ux, uy); +} + +static void +print_absmotion_event(struct libinput_event *ev) +{ + struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); + double x = libinput_event_pointer_get_absolute_x_transformed( + p, screen_width); + double y = libinput_event_pointer_get_absolute_y_transformed( + p, screen_height); + + print_event_time(libinput_event_pointer_get_time(p)); + printq("%6.2f/%6.2f\n", x, y); +} + +static void +print_pointer_button_event(struct libinput_event *ev) +{ + struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); + enum libinput_button_state state; + const char *buttonname; + int button; + + print_event_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); + printq("%s (%d) %s, seat count: %u\n", + buttonname ? buttonname : "???", + button, + state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", + libinput_event_pointer_get_seat_button_count(p)); +} + +static void +print_tablet_axes(struct libinput_event_tablet_tool *t) +{ + struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); + double x, y; + double dist, pressure; + double rotation, slider, wheel; + double delta; + double major, minor; + +#define changed_sym(ev, ax) \ + (libinput_event_tablet_tool_##ax##_has_changed(ev) ? "*" : "") + + x = libinput_event_tablet_tool_get_x(t); + y = libinput_event_tablet_tool_get_y(t); + printq("\t%.2f%s/%.2f%s", + x, changed_sym(t, x), + y, changed_sym(t, y)); + + 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); + printq("\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)) { + dist = libinput_event_tablet_tool_get_distance(t); + pressure = libinput_event_tablet_tool_get_pressure(t); + if (dist) + printq("\tdistance: %.2f%s", + dist, changed_sym(t, distance)); + else + printq("\tpressure: %.2f%s", + pressure, changed_sym(t, pressure)); + } + + if (libinput_tablet_tool_has_rotation(tool)) { + rotation = libinput_event_tablet_tool_get_rotation(t); + printq("\trotation: %6.2f%s", + rotation, changed_sym(t, rotation)); + } + + if (libinput_tablet_tool_has_slider(tool)) { + slider = libinput_event_tablet_tool_get_slider_position(t); + printq("\tslider: %.2f%s", + slider, changed_sym(t, slider)); + } + + if (libinput_tablet_tool_has_wheel(tool)) { + wheel = libinput_event_tablet_tool_get_wheel_delta(t); + delta = libinput_event_tablet_tool_get_wheel_delta_discrete(t); + printq("\twheel: %.2f%s (%d)", + wheel, changed_sym(t, wheel), + (int)delta); + } + + if (libinput_tablet_tool_has_size(tool)) { + major = libinput_event_tablet_tool_get_size_major(t); + minor = libinput_event_tablet_tool_get_size_minor(t); + printq("\tsize: %.2f%s/%.2f%s", + major, changed_sym(t, size_major), + minor, changed_sym(t, size_minor)); + } +} + +static void +print_tablet_tip_event(struct libinput_event *ev) +{ + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); + enum libinput_tablet_tool_tip_state state; + + print_event_time(libinput_event_tablet_tool_get_time(t)); + + print_tablet_axes(t); + + state = libinput_event_tablet_tool_get_tip_state(t); + printq(" %s\n", state == LIBINPUT_TABLET_TOOL_TIP_DOWN ? "down" : "up"); +} + +static void +print_tablet_button_event(struct libinput_event *ev) +{ + struct libinput_event_tablet_tool *p = libinput_event_get_tablet_tool_event(ev); + enum libinput_button_state state; + const char *buttonname; + int button; + + print_event_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); + printq("%3d (%s) %s, seat count: %u\n", + button, + buttonname ? buttonname : "???", + state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", + libinput_event_tablet_tool_get_seat_button_count(p)); +} + +static void +print_pointer_axis_event(struct libinput_event *ev) +{ + struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); + double v = 0, h = 0; + int dv = 0, dh = 0; + const char *have_vert = "", + *have_horiz = ""; + const char *source = "invalid"; + + 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 = "tilt"; + break; + } + + 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); + dv = libinput_event_pointer_get_axis_value_discrete(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + have_vert = "*"; + } + 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); + dh = libinput_event_pointer_get_axis_value_discrete(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + have_horiz = "*"; + } + print_event_time(libinput_event_pointer_get_time(p)); + printq("vert %.2f/%d%s horiz %.2f/%d%s (%s)\n", + v, dv, have_vert, h, dh, have_horiz, source); +} + +static void +print_tablet_axis_event(struct libinput_event *ev) +{ + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); + + print_event_time(libinput_event_tablet_tool_get_time(t)); + print_tablet_axes(t); + printq("\n"); +} + +static void +print_touch_event_without_coords(struct libinput_event *ev) +{ + struct libinput_event_touch *t = libinput_event_get_touch_event(ev); + + print_event_time(libinput_event_touch_get_time(t)); + printq("\n"); +} + +static void +print_proximity_event(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); + enum libinput_tablet_tool_proximity_state state; + const char *tool_str, + *state_str; + + 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(libinput_event_tablet_tool_get_time(t)); + + if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { + print_tablet_axes(t); + state_str = "proximity-in"; + } else if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { + print_tablet_axes(t); + state_str = "proximity-out"; + } else { + abort(); + } + + printq("\t%s (%#" PRIx64 ", id %#" PRIx64 ") %s ", + tool_str, + libinput_tablet_tool_get_serial(tool), + libinput_tablet_tool_get_tool_id(tool), + state_str); + + if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { + printq("\taxes:"); + if (libinput_tablet_tool_has_distance(tool)) + printq("d"); + if (libinput_tablet_tool_has_pressure(tool)) + printq("p"); + if (libinput_tablet_tool_has_tilt(tool)) + printq("t"); + if (libinput_tablet_tool_has_rotation(tool)) + printq("r"); + if (libinput_tablet_tool_has_slider(tool)) + printq("s"); + if (libinput_tablet_tool_has_wheel(tool)) + printq("w"); + if (libinput_tablet_tool_has_size(tool)) + printq("S"); + + printq("\tbtn:"); + if (libinput_tablet_tool_has_button(tool, BTN_TOUCH)) + printq("T"); + if (libinput_tablet_tool_has_button(tool, BTN_STYLUS)) + printq("S"); + if (libinput_tablet_tool_has_button(tool, BTN_STYLUS2)) + printq("S2"); + if (libinput_tablet_tool_has_button(tool, BTN_LEFT)) + printq("L"); + if (libinput_tablet_tool_has_button(tool, BTN_MIDDLE)) + printq("M"); + if (libinput_tablet_tool_has_button(tool, BTN_RIGHT)) + printq("R"); + if (libinput_tablet_tool_has_button(tool, BTN_SIDE)) + printq("Sd"); + if (libinput_tablet_tool_has_button(tool, BTN_EXTRA)) + printq("Ex"); + if (libinput_tablet_tool_has_button(tool, BTN_0)) + printq("0"); + } + + printq("\n"); +} + +static void +print_touch_event_with_coords(struct libinput_event *ev) +{ + struct libinput_event_touch *t = libinput_event_get_touch_event(ev); + double x = libinput_event_touch_get_x_transformed(t, screen_width); + double y = libinput_event_touch_get_y_transformed(t, screen_height); + double xmm = libinput_event_touch_get_x(t); + double ymm = libinput_event_touch_get_y(t); + + print_event_time(libinput_event_touch_get_time(t)); + + printq("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n", + libinput_event_touch_get_slot(t), + libinput_event_touch_get_seat_slot(t), + x, y, + xmm, ymm); +} + +static void +print_gesture_event_without_coords(struct libinput_event *ev) +{ + 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; + + type = libinput_event_get_type(ev); + + if (type == LIBINPUT_EVENT_GESTURE_SWIPE_END || + type == LIBINPUT_EVENT_GESTURE_PINCH_END) + cancelled = libinput_event_gesture_get_cancelled(t); + + print_event_time(libinput_event_gesture_get_time(t)); + printq("%d%s\n", finger_count, cancelled ? " cancelled" : ""); +} + +static void +print_gesture_event_with_coords(struct libinput_event *ev) +{ + 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); + + print_event_time(libinput_event_gesture_get_time(t)); + + printq("%d %5.2f/%5.2f (%5.2f/%5.2f unaccelerated)", + libinput_event_gesture_get_finger_count(t), + dx, dy, dx_unaccel, dy_unaccel); + + 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); + + printq(" %5.2f @ %5.2f\n", scale, angle); + } else { + printq("\n"); + } +} + +static void +print_tablet_pad_button_event(struct libinput_event *ev) +{ + 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; + + print_event_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); + printq("%3d %s (mode %d)", + button, + state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", + mode); + + group = libinput_event_tablet_pad_get_mode_group(p); + if (libinput_tablet_pad_mode_group_button_is_toggle(group, button)) + printq(" "); + + printq("\n"); +} + +static void +print_tablet_pad_ring_event(struct libinput_event *ev) +{ + struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); + const char *source = ""; + unsigned int mode; + + print_event_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); + printq("ring %d position %.2f (source %s) (mode %d)\n", + libinput_event_tablet_pad_get_ring_number(p), + libinput_event_tablet_pad_get_ring_position(p), + source, + mode); +} + +static void +print_tablet_pad_strip_event(struct libinput_event *ev) +{ + struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev); + const char *source = ""; + unsigned int mode; + + print_event_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); + printq("strip %d position %.2f (source %s) (mode %d)\n", + libinput_event_tablet_pad_get_strip_number(p), + libinput_event_tablet_pad_get_strip_position(p), + source, + mode); +} + +static void +print_switch_event(struct libinput_event *ev) +{ + struct libinput_event_switch *sw = libinput_event_get_switch_event(ev); + enum libinput_switch_state state; + const char *which; + + print_event_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); + + printq("switch %s state %d\n", which, state); +} + +static int +handle_and_print_events(struct libinput *li) +{ + int rc = -1; + struct libinput_event *ev; + + libinput_dispatch(li); + while ((ev = libinput_get_event(li))) { + print_event_header(ev); + + switch (libinput_event_get_type(ev)) { + case LIBINPUT_EVENT_NONE: + abort(); + case LIBINPUT_EVENT_DEVICE_ADDED: + print_device_notify(ev); + tools_device_apply_config(libinput_event_get_device(ev), + &options); + break; + case LIBINPUT_EVENT_DEVICE_REMOVED: + print_device_notify(ev); + break; + case LIBINPUT_EVENT_KEYBOARD_KEY: + print_key_event(li, ev); + break; + case LIBINPUT_EVENT_POINTER_MOTION: + print_motion_event(ev); + break; + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + print_absmotion_event(ev); + break; + case LIBINPUT_EVENT_POINTER_BUTTON: + print_pointer_button_event(ev); + break; + case LIBINPUT_EVENT_POINTER_AXIS: + print_pointer_axis_event(ev); + break; + case LIBINPUT_EVENT_TOUCH_DOWN: + print_touch_event_with_coords(ev); + break; + case LIBINPUT_EVENT_TOUCH_MOTION: + print_touch_event_with_coords(ev); + break; + case LIBINPUT_EVENT_TOUCH_UP: + print_touch_event_without_coords(ev); + break; + case LIBINPUT_EVENT_TOUCH_CANCEL: + print_touch_event_without_coords(ev); + break; + case LIBINPUT_EVENT_TOUCH_FRAME: + print_touch_event_without_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: + print_gesture_event_without_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: + print_gesture_event_with_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_SWIPE_END: + print_gesture_event_without_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: + print_gesture_event_without_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: + print_gesture_event_with_coords(ev); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_END: + print_gesture_event_without_coords(ev); + break; + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: + print_tablet_axis_event(ev); + break; + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + print_proximity_event(ev); + break; + case LIBINPUT_EVENT_TABLET_TOOL_TIP: + print_tablet_tip_event(ev); + break; + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: + print_tablet_button_event(ev); + break; + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + print_tablet_pad_button_event(ev); + break; + case LIBINPUT_EVENT_TABLET_PAD_RING: + print_tablet_pad_ring_event(ev); + break; + case LIBINPUT_EVENT_TABLET_PAD_STRIP: + print_tablet_pad_strip_event(ev); + break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + print_switch_event(ev); + break; + } + + libinput_event_destroy(ev); + libinput_dispatch(li); + rc = 0; + } + 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; + + /* Handle already-pending device added events */ + if (handle_and_print_events(li)) + fprintf(stderr, "Expected device added events on startup but got none. " + "Maybe you don't have the right permissions?\n"); + + while (!stop && poll(&fds, 1, -1) > -1) + handle_and_print_events(li); + + printf("\n"); +} + +static void +usage(void) { + printf("Usage: libinput debug-events [options] [--udev |--device /dev/input/event0]\n"); +} + +int +main(int argc, char **argv) +{ + struct libinput *li; + struct timespec tp; + enum tools_backend backend = BACKEND_NONE; + const char *seat_or_device = "seat0"; + bool grab = false; + bool verbose = false; + struct sigaction act; + + clock_gettime(CLOCK_MONOTONIC, &tp); + start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; + + tools_init_options(&options); + + while (1) { + int c; + int option_index = 0; + enum { + OPT_DEVICE = 1, + OPT_UDEV, + OPT_GRAB, + OPT_VERBOSE, + OPT_SHOW_KEYCODES, + OPT_QUIET, + }; + 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 }, + { 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_SHOW_KEYCODES: + show_keycodes = true; + break; + case OPT_QUIET: + be_quiet = true; + break; + case OPT_DEVICE: + backend = BACKEND_DEVICE; + seat_or_device = optarg; + break; + case OPT_UDEV: + backend = BACKEND_UDEV; + seat_or_device = optarg; + break; + case OPT_GRAB: + grab = true; + break; + case OPT_VERBOSE: + verbose = true; + 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 = 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, verbose, &grab); + if (!li) + return EXIT_FAILURE; + + mainloop(li); + + libinput_unref(li); + + return EXIT_SUCCESS; +} diff --git a/tools/libinput-debug-events.man b/tools/libinput-debug-events.man new file mode 100644 index 0000000..29a03c5 --- /dev/null +++ b/tools/libinput-debug-events.man @@ -0,0 +1,106 @@ +.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 +.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 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\-tap|\-\-disable\-tap +Enable or disable tap-to-click +.TP 8 +.B \-\-enable-drag|\-\-disable\-drag +Enable or disable tap-and-drag +.TP 8 +.B \-\-enable\-drag-lock|\-\-disable\-drag\-lock +Enable or disable drag-lock +.TP 8 +.B \-\-enable\-natural\-scrolling|\-\-disable\-natural\-scrolling +Enable or disable natural scrolling +.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\-dwt|\-\-disable\-dwt +Enable or disable disable-while-typing +.TP 8 +.B \-\-set\-click\-method=[none|clickfinger|buttonareas] +Set the desired click method +.TP 8 +.B \-\-set\-scroll\-method=[none|twofinger|edge|button] +Set the desired scroll method +.TP 8 +.B \-\-set\-scroll\-button=BTN_MIDDLE +Set the button to the given button code +.TP 8 +.B \-\-set\-profile=[adaptive|flat] +Set pointer acceleration profile +.TP 8 +.B \-\-set\-speed= +Set pointer acceleration speed. The allowed range is [-1, 1]. +.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 diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c new file mode 100644 index 0000000..629a5cf --- /dev/null +++ b/tools/libinput-debug-gui.c @@ -0,0 +1,1585 @@ +/* + * 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 "shared.h" + +#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 device_user_data { + struct point scroll_accumulated; +}; + +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; + + GtkWidget *win; + GtkWidget *area; + int width, height; /* of window */ + + /* sprite position */ + double x, y; + + /* 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 */ + int absx, absy; + + /* 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 { + 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; + + /* 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; + } 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]; +}; + +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); + cairo_set_source_rgb(cr, .2, .2, .8); + + 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; + + 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; + + 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); + } + +draw_outline: + /* The touchpad outline */ + 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 i; + int offset; + + /* swipe */ + cairo_save(cr); + cairo_translate(cr, w->swipe.x, w->swipe.y); + for (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 (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); +} + +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) +{ + struct touch *t; + + 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->absx, w->absy, 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 */ + cairo_set_source_rgb(cr, .7, .7, .0); + cairo_arc(cr, rx, ry, 50, 0, 2 * M_PI); + cairo_fill(cr); + + /* inner ring */ + 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); + + } + + 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; + + /* 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->x, w->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); + + /* 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_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; +} + +static void +map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + struct window *w = data; + GdkDisplay *display; + GdkSeat *seat; + GdkWindow *window; + + gtk_window_get_size(GTK_WINDOW(widget), &w->width, &w->height); + + w->x = w->width/2; + w->y = w->height/2; + + 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; + + 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)); + + seat = gdk_display_get_default_seat(display); + gdk_seat_grab(seat, + window, + GDK_SEAT_CAPABILITY_ALL_POINTING, + FALSE, /* owner-events */ + NULL, /* cursor */ + NULL, /* triggering event */ + NULL, /* prepare_func */ + NULL /* prepare_func_data */ + ); +} + +static void +window_init(struct window *w) +{ + list_init(&w->evdev_devices); + + w->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_events(w->win, 0); + 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); + 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(gtk_main_quit), NULL); + + w->area = gtk_drawing_area_new(); + gtk_widget_set_events(w->area, 0); + gtk_container_add(GTK_CONTAINER(w->win), w->area); + gtk_widget_show_all(w->win); + + w->pad.ring.position = -1; + w->pad.strip.position = -1; +} + +static void +window_cleanup(struct window *w) +{ + struct libinput_device **dev; + ARRAY_FOR_EACH(w->devices, dev) { + if (*dev) + libinput_device_unref(*dev); + } +} + +static void +change_ptraccel(struct window *w, double amount) +{ + struct libinput_device **dev; + + 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; + struct device_user_data *data; + + 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); + + data = zalloc(sizeof *data); + libinput_device_set_user_data(dev, data); + + 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(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; + size_t i; + + 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) { + for (i = 0; i < ARRAY_LENGTH(w->devices); i++) { + if (w->devices[i] == NULL) { + w->devices[i] = libinput_device_ref(dev); + break; + } + } + } else { + for (i = 0; i < ARRAY_LENGTH(w->devices); i++) { + if (w->devices[i] == dev) { + libinput_device_unref(w->devices[i]); + w->devices[i] = 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); + struct point point; + const int mask = ARRAY_LENGTH(w->deltas); + size_t idx; + + w->x += dx; + w->y += dy; + w->x = clip(w->x, 0.0, w->width); + w->y = clip(w->y, 0.0, w->height); + + idx = w->ndeltas % mask; + point = w->deltas[idx]; + idx = (w->ndeltas + 1) % mask; + point.x += libinput_event_pointer_get_dx_unaccelerated(p); + point.y += libinput_event_pointer_get_dy_unaccelerated(p); + 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->absx = x; + w->absy = 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); + struct libinput_device *dev = libinput_event_get_device(ev); + struct device_user_data *data = libinput_device_get_user_data(dev); + double value; + int discrete; + + assert(data); + + if (libinput_event_pointer_has_axis(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { + value = libinput_event_pointer_get_axis_value(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + w->scroll.vy += value; + w->scroll.vy = clip(w->scroll.vy, 0, w->height); + data->scroll_accumulated.y += value; + + discrete = libinput_event_pointer_get_axis_value_discrete(p, + LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + if (discrete) { + w->scroll.vy_discrete += data->scroll_accumulated.y; + w->scroll.vy_discrete = clip(w->scroll.vy_discrete, 0, w->height); + data->scroll_accumulated.y = 0; + } + } + + if (libinput_event_pointer_has_axis(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { + value = libinput_event_pointer_get_axis_value(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + w->scroll.hx += value; + w->scroll.hx = clip(w->scroll.hx, 0, w->width); + data->scroll_accumulated.x += value; + + discrete = libinput_event_pointer_get_axis_value_discrete(p, + LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + if (discrete) { + w->scroll.hx_discrete += data->scroll_accumulated.x; + w->scroll.hx_discrete = clip(w->scroll.hx_discrete, 0, w->width); + data->scroll_accumulated.x = 0; + } + } +} + +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_tablet(struct libinput_event *ev, struct window *w) +{ + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); + 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: + 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; + } else { + w->tool.x_up = x; + w->tool.y_up = y; + } + /* 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; + 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; + 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; + + 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: + 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: + 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); + gtk_main_quit(); + 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_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: + handle_event_tablet_pad(ev, w); + break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + break; + } + + libinput_event_destroy(ev); + libinput_dispatch(li); + } + 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(void) { + printf("Usage: libinput debug-gui [options] [--udev |[--device] /dev/input/event0]\n"); +} + +static gboolean +signal_handler(void *data) +{ + gtk_main_quit(); + + 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 = "seat0"; + bool verbose = false; + + if (!gtk_init_check(&argc, &argv)) + return 77; + + g_unix_signal_add(SIGINT, signal_handler, NULL); + + 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(); + exit(0); + break; + case OPT_DEVICE: + backend = BACKEND_DEVICE; + seat_or_device = optarg; + break; + case OPT_UDEV: + backend = BACKEND_UDEV; + seat_or_device = 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(); + 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 = 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); + + window_init(&w); + w.options = options; + sockets_init(li); + handle_event_libinput(NULL, 0, li); + + gtk_main(); + + window_cleanup(&w); + libinput_unref(li); + + return EXIT_SUCCESS; +} diff --git a/tools/libinput-debug-gui.man b/tools/libinput-debug-gui.man new file mode 100644 index 0000000..3a1b295 --- /dev/null +++ b/tools/libinput-debug-gui.man @@ -0,0 +1,101 @@ +.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. +.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. 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. Ring and strip events are displayed in the +yellow 'IO' symbol, with the position and the number of the ring/strip +filled in when events are 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 diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c new file mode 100644 index 0000000..4b06452 --- /dev/null +++ b/tools/libinput-list-devices.c @@ -0,0 +1,412 @@ +/* + * 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 "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"; + else + return "disabled"; +} + +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"; + else + 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"; + else + 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"; + else + 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"; + else + 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"; + else + 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 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 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", + (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" : ""); + + 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"; + else + 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 void +print_pad_info(struct libinput_device *device) +{ + int nbuttons, nrings, nstrips, 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); + ngroups = libinput_device_tablet_pad_get_num_mode_groups(device); + + group = libinput_device_tablet_pad_get_mode_group(device, 0); + nmodes = libinput_tablet_pad_mode_group_get_num_modes(group); + + printf("Pad:\n"); + printf(" Rings: %d\n", nrings); + printf(" Strips: %d\n", nstrips); + printf(" Buttons: %d\n", nbuttons); + printf(" Mode groups: %d (%d modes)\n", ngroups, nmodes); + +} + +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; + + 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); + + printf("Device: %s\n" + "Kernel: %s\n" + "Group: %d\n" + "Seat: %s, %s\n", + libinput_device_get_name(dev), + devnode, + (int)group_id, + 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) + printf("Size: %.fx%.fmm\n", w, h); + printf("Capabilities: "); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_KEYBOARD)) + printf("keyboard "); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_POINTER)) + printf("pointer "); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TOUCH)) + printf("touch "); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TABLET_TOOL)) + printf("tablet "); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_TABLET_PAD)) + printf("tablet-pad"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_GESTURE)) + printf("gesture"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_SWITCH)) + printf("switch"); + printf("\n"); + + printf("Tap-to-click: %s\n", tap_default(dev)); + printf("Tap-and-drag: %s\n", drag_default(dev)); + printf("Tap drag lock: %s\n", draglock_default(dev)); + printf("Left-handed: %s\n", left_handed_default(dev)); + printf("Nat.scrolling: %s\n", nat_scroll_default(dev)); + printf("Middle emulation: %s\n", middle_emulation_default(dev)); + str = calibration_default(dev); + printf("Calibration: %s\n", str); + free(str); + + str = scroll_defaults(dev); + printf("Scroll methods: %s\n", str); + free(str); + + str = click_defaults(dev); + printf("Click methods: %s\n", str); + free(str); + + printf("Disable-w-typing: %s\n", dwt_default(dev)); + + str = accel_profiles(dev); + printf("Accel profiles: %s\n", str); + free(str); + + str = rotation_default(dev); + printf("Rotation: %s\n", 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; + + /* This is kept for backwards-compatibility with the old + libinput-list-devices */ + if (argc > 1) { + if (streq(argv[1], "--help")) { + usage(); + return 0; + } else if (streq(argv[1], "--version")) { + printf("%s\n", LIBINPUT_VERSION); + return 0; + } else { + usage(); + return EXIT_INVALID_USAGE; + } + } + + li = tools_open_backend(BACKEND_UDEV, "seat0", 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; +} diff --git a/tools/libinput-list-devices.man b/tools/libinput-list-devices.man new file mode 100644 index 0000000..ccb30ff --- /dev/null +++ b/tools/libinput-list-devices.man @@ -0,0 +1,41 @@ +.TH libinput-list-devices "1" "" "libinput @LIBINPUT_VERSION@" "libinput Manual" +.SH NAME +libinput\-list\-devices \- list local devices as recognized by libinput +.SH SYNOPSIS +.B libinput list\-devices [\-\-help] +.SH DESCRIPTION +.PP +The +.B "libinput list\-devices" +tool creates a libinput context on the default seat "seat0" and lists all +devices recognized by libinput. Each device shows available configurations +the respective default configuration setting. +.PP +For configuration options that allow multiple different settings +(e.g. scrolling), all available settings are listed. The default setting is +prefixed by an asterisk (*). +.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 NOTES +.PP +Some specific feature may still be available on a device even when +no configuration is exposed, a lack of a configuration option 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 diff --git a/tools/libinput-measure-fuzz.man b/tools/libinput-measure-fuzz.man new file mode 100644 index 0000000..74b319c --- /dev/null +++ b/tools/libinput-measure-fuzz.man @@ -0,0 +1,30 @@ +.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 diff --git a/tools/libinput-measure-fuzz.py b/tools/libinput-measure-fuzz.py new file mode 100755 index 0000000..41e2825 --- /dev/null +++ b/tools/libinput-measure-fuzz.py @@ -0,0 +1,445 @@ +#!/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' + 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_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 (xfuzz, 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 is 0 and yfuzz is 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, template), 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 udevadm hwdb --update') + subprocess.run(['udevadm', 'hwdb', '--update'], check=True) + syspath = device.path.replace('/dev/input/', '/sys/class/input/') + time.sleep(1) + print('Running udevadm trigger {}'.format(syspath)) + subprocess.run(['udevadm', 'trigger', syspath], check=True) + time.sleep(1) + + +def test_hwdb_entry(device, fuzz): + reload_and_trigger_udev(device) + print_bold('Testing... ', end='') + + d = Device(device.path) + f = d.check_axes() + if fuzz == f[0] and fuzz == f[1]: + 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) diff --git a/tools/libinput-measure-touch-size.man b/tools/libinput-measure-touch-size.man new file mode 100644 index 0000000..7fe042f --- /dev/null +++ b/tools/libinput-measure-touch-size.man @@ -0,0 +1,57 @@ +.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 diff --git a/tools/libinput-measure-touch-size.py b/tools/libinput-measure-touch-size.py new file mode 100755 index 0000000..4b2201e --- /dev/null +++ b/tools/libinput-measure-touch-size.py @@ -0,0 +1,353 @@ +#!/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) + + 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: + 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: + 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) diff --git a/tools/libinput-measure-touchpad-pressure.man b/tools/libinput-measure-touchpad-pressure.man new file mode 100644 index 0000000..f985b87 --- /dev/null +++ b/tools/libinput-measure-touchpad-pressure.man @@ -0,0 +1,63 @@ +.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. +.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 diff --git a/tools/libinput-measure-touchpad-pressure.py b/tools/libinput-measure-touchpad-pressure.py new file mode 100755 index 0000000..bba834c --- /dev/null +++ b/tools/libinput-measure-touchpad-pressure.py @@ -0,0 +1,328 @@ +#!/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, 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 "{:78s}".format("Sequence: no pressure values recorded") + + s = "Sequence {} pressure: "\ + "min: {:3d} max: {:3d} avg: {:3d} median: {:3d} tags:" \ + .format( + self.tracking_id, + self.prange.min, + self.prange.max, + self.avg(), + self.median() + ) + if self.was_down: + s += " down" + if self.was_palm: + s += " palm" + if self.was_thumb: + s += " thumb" + + return s + + def _str_state(self): + s = "Touchpad pressure: {:3d} min: {:3d} max: {:3d} tags: {} {} {}" \ + .format( + self.points[-1].pressure, + self.prange.min, + self.prange.max, + "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_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: + print("\rThis tool cannot handle multiple fingers, " + "output will be invalid", file=sys.stderr) + + +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{}".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{}".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("Ready for recording data.") + print("Pressure range used: {}:{}".format(device.down, device.up)) + print("Palm pressure range used: {}".format(device.palm)) + print("Thumb pressure range used: {}".format(device.thumb)) + print("Place a single finger on the touchpad to measure pressure values.\n" + "Ctrl+C to exit\n") + + 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: + 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' + ) + 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 + + loop(device) + 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 pressure-based touch detection."); + print("Details: {}".format(e)) + + +if __name__ == "__main__": + main(sys.argv) diff --git a/tools/libinput-measure-touchpad-tap.man b/tools/libinput-measure-touchpad-tap.man new file mode 100644 index 0000000..6743e5a --- /dev/null +++ b/tools/libinput-measure-touchpad-tap.man @@ -0,0 +1,80 @@ +.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 occured), 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 diff --git a/tools/libinput-measure-touchpad-tap.py b/tools/libinput-measure-touchpad-tap.py new file mode 100755 index 0000000..8d8a8d8 --- /dev/null +++ b/tools/libinput-measure-touchpad-tap.py @@ -0,0 +1,255 @@ +#!/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 = [] + + 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: + 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) + + l = len(deltas) + + davg = sum(deltas)/l + dmedian = deltas[int(l/2)] + d95pc = deltas[int(l * 0.95)] + d90pc = deltas[int(l * 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 occurence + # 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) diff --git a/tools/libinput-measure.c b/tools/libinput-measure.c new file mode 100644 index 0000000..fb9729c --- /dev/null +++ b/tools/libinput-measure.c @@ -0,0 +1,79 @@ +/* + * 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 +#include +#include +#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); +} diff --git a/tools/libinput-measure.man b/tools/libinput-measure.man new file mode 100644 index 0000000..9dd0f64 --- /dev/null +++ b/tools/libinput-measure.man @@ -0,0 +1,39 @@ +.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 too 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\-tap\-time(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 diff --git a/tools/libinput-quirks.c b/tools/libinput-quirks.c new file mode 100644 index 0000000..0579632 --- /dev/null +++ b/tools/libinput-quirks.c @@ -0,0 +1,222 @@ +/* + * 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 "libinput-util.h" +#include "quirks.h" +#include "shared.h" +#include "builddir.h" + +static bool verbose = false; + +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 = ""; + + 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); + vfprintf(out, buf, args); +} + +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(); + path = argv[optind]; + if (strneq(path, "/sys/", 5)) { + 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; +} diff --git a/tools/libinput-quirks.man b/tools/libinput-quirks.man new file mode 100644 index 0000000..097dabe --- /dev/null +++ b/tools/libinput-quirks.man @@ -0,0 +1,43 @@ +.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 diff --git a/tools/libinput-record-verify-yaml.py b/tools/libinput-record-verify-yaml.py new file mode 100755 index 0000000..2920ef0 --- /dev/null +++ b/tools/libinput-record-verify-yaml.py @@ -0,0 +1,667 @@ +#!/usr/bin/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) diff --git a/tools/libinput-record.c b/tools/libinput-record.c new file mode 100644 index 0000000..75fa284 --- /dev/null +++ b/tools/libinput-record.c @@ -0,0 +1,2476 @@ +/* + * 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 "libinput-versionsort.h" +#include "libinput-util.h" +#include "libinput-version.h" +#include "libinput-git-version.h" +#include "shared.h" +#include "builddir.h" + +static const int FILE_VERSION_NUMBER = 1; + +/* libinput is not designed to keep events past immediate use so we need to + * cache our events. Simplest way to do this is to just cache the printf + * output */ +struct li_event { + char msg[256]; +}; + +enum event_type { + NONE, + EVDEV, + LIBINPUT, + COMMENT, +}; + +struct event { + enum event_type type; + uint64_t time; + union { + struct input_event evdev; + struct li_event libinput; + char comment[200]; + } u; +}; + +struct record_device { + struct list link; + char *devnode; /* device node of the source device */ + struct libevdev *evdev; + struct libinput_device *device; + + struct event *events; + size_t nevents; + size_t events_sz; + + struct { + bool is_touch_device; + uint16_t slot_state; + uint16_t last_slot_state; + } touch; +}; + +struct record_context { + int timeout; + bool show_keycodes; + + uint64_t offset; + + struct list devices; + int ndevices; + + char *outfile; /* file name given on cmdline */ + char *output_file; /* full file name with suffix */ + + int out_fd; + unsigned int indent; + + struct libinput *libinput; +}; + +static inline bool +obfuscate_keycode(struct input_event *ev) +{ + switch (ev->type) { + case EV_KEY: + if (ev->code >= KEY_ESC && ev->code < KEY_ZENKAKUHANKAKU) { + 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; +} + +static inline void +indent_push(struct record_context *ctx) +{ + ctx->indent += 2; +} + +static inline void +indent_pop(struct record_context *ctx) +{ + assert(ctx->indent >= 2); + ctx->indent -= 2; +} + +/** + * Indented dprintf, indentation is given as second parameter. + */ +static inline void +iprintf(const struct record_context *ctx, const char *format, ...) +{ + va_list args; + char fmt[1024]; + static const char space[] = " "; + static const size_t len = sizeof(space); + unsigned int indent = ctx->indent; + 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 -= 2; + + snprintf(fmt, sizeof(fmt), "%s%s", &space[len - indent - 1], format); + va_start(args, format); + rc = vdprintf(ctx->out_fd, fmt, args); + va_end(args); + + assert(rc != -1 && (unsigned int)rc > indent); +} + +/** + * Normal printf, just wrapped for the context + */ +static inline void +noiprintf(const struct record_context *ctx, const char *format, ...) +{ + va_list args; + int rc; + + va_start(args, format); + rc = vdprintf(ctx->out_fd, format, args); + va_end(args); + assert(rc != -1 && (unsigned int)rc > 0); +} + +static inline void +print_evdev_event(struct record_context *ctx, struct input_event *ev) +{ + const char *cname; + bool was_modified = false; + char desc[1024]; + + ev->time = us2tv(tv2us(&ev->time) - ctx->offset); + + /* Don't leak passwords unless the user wants to */ + if (!ctx->show_keycodes) + was_modified = obfuscate_keycode(ev); + + 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(tv2us(&ev->time)); + dt = time - last_ms; + last_ms = time; + + snprintf(desc, + sizeof(desc), + "------------ %s (%d) ---------- %+ldms", + cname, + ev->value, + dt); + } else { + const char *tname = libevdev_event_type_get_name(ev->type); + + snprintf(desc, + sizeof(desc), + "%s / %-20s %6d%s", + tname, + cname, + ev->value, + was_modified ? " (obfuscated)" : ""); + } + + iprintf(ctx, + "- [%3lu, %6u, %3d, %3d, %6d] # %s\n", + ev->time.tv_sec, + (unsigned int)ev->time.tv_usec, + ev->type, + ev->code, + ev->value, + desc); +} + +#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; \ +} + +static inline size_t +handle_evdev_frame(struct record_context *ctx, struct record_device *d) +{ + struct libevdev *evdev = d->evdev; + struct input_event e; + size_t count = 0; + uint32_t last_time = 0; + struct event *event; + + while (libevdev_next_event(evdev, + LIBEVDEV_READ_FLAG_NORMAL, + &e) == LIBEVDEV_READ_STATUS_SUCCESS) { + + if (ctx->offset == 0) + ctx->offset = tv2us(&e.time); + + if (d->nevents == d->events_sz) + resize(d->events, d->events_sz); + + event = &d->events[d->nevents++]; + event->type = EVDEV; + event->time = tv2us(&e.time) - ctx->offset; + event->u.evdev = e; + count++; + + 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 |= 1 << slot; + else + d->touch.slot_state &= ~(1 << slot); + } + + last_time = event->time; + + if (e.type == EV_SYN && e.code == SYN_REPORT) + break; + } + + if (d->touch.slot_state != d->touch.last_slot_state) { + d->touch.last_slot_state = d->touch.slot_state; + if (d->nevents == d->events_sz) + resize(d->events, d->events_sz); + + if (d->touch.slot_state == 0) { + event = &d->events[d->nevents++]; + event->type = COMMENT; + event->time = last_time; + snprintf(event->u.comment, + sizeof(event->u.comment), + " # Touch device in neutral state\n"); + count++; + } + } + + return count; +} + +static void +buffer_device_notify(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + struct libinput_device *dev = libinput_event_get_device(e); + struct libinput_seat *seat = libinput_device_get_seat(dev); + 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(); + } + + event->time = 0; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{type: %s, seat: %5s, logical_seat: %7s}", + type, + libinput_seat_get_physical_name(seat), + libinput_seat_get_logical_name(seat)); +} + +static void +buffer_key_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_keyboard_get_time_usec(k) - ctx->offset : 0; + + state = libinput_event_keyboard_get_key_state(k); + + key = libinput_event_keyboard_get_key(k); + if (!ctx->show_keycodes && + (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) + key = -1; + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, key: %d, state: %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + key, + state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released"); +} + +static void +buffer_motion_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_pointer_get_time_usec(p) - ctx->offset : 0; + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f]}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + x, y, + uax, uay); +} + +static void +buffer_absmotion_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_pointer_get_time_usec(p) - ctx->offset : 0; + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, point: [%6.2f, %6.2f], transformed: [%6.2f, %6.2f]}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + x, y, + tx, ty); +} + +static void +buffer_pointer_button_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_pointer_get_time_usec(p) - ctx->offset : 0; + button = libinput_event_pointer_get_button(p); + state = libinput_event_pointer_get_button_state(p); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, button: %d, state: %s, seat_count: %u}", + (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 +buffer_pointer_axis_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_pointer_get_time_usec(p) - ctx->offset : 0; + 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; + } + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, axes: [%2.2f, %2.2f], discrete: [%d, %d], source: %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + h, v, + hd, vd, + source); +} + +static void +buffer_touch_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_touch_get_time_usec(t) - ctx->offset : 0; + + if (etype != LIBINPUT_EVENT_TOUCH_FRAME) { + slot = libinput_event_touch_get_slot(t); + seat_slot = libinput_event_touch_get_seat_slot(t); + } + event->time = time; + + switch (etype) { + case LIBINPUT_EVENT_TOUCH_FRAME: + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s}", + (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); + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, slot: %d, seat_slot: %d, point: [%6.2f, %6.2f], transformed: [%6.2f, %6.2f]}", + (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: + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, slot: %d, seat_slot: %d}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + slot, + seat_slot); + break; + default: + abort(); + } +} + +static void +buffer_gesture_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_gesture_get_time_usec(g) - ctx->offset : 0; + event->time = time; + + switch (etype) { + case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: + case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: + case LIBINPUT_EVENT_GESTURE_PINCH_END: + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, nfingers: %d, " + "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f], " + "angle_delta: %6.2f, scale: %6.2f}", + (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: + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, nfingers: %d, " + "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f]}", + (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 +buffer_tablet_tool_proximity_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0; + + 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)); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, proximity: %s, tool-type: %s, serial: %" PRIu64 ", axes: %s, %s}", + (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 +buffer_tablet_tool_button_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0; + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, button: %d, state: %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + button, + state ? "pressed" : "released"); +} + +static void +buffer_tablet_tool_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0; + + axes = buffer_tablet_axes(t); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s%s, tip: %s, %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + btn_buffer, /* may be empty string */ + tip ? "down" : "up", + axes); + free(axes); +} + +static void +buffer_tablet_pad_button_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_tablet_pad_get_time_usec(p) - ctx->offset : 0; + + 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); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, button: %d, state: %s, mode: %d, is-toggle: %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + button, + state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", + mode, + libinput_tablet_pad_mode_group_button_is_toggle(group, button) ? "true" : "false" + ); + + +} + +static void +buffer_tablet_pad_ringstrip_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_tablet_pad_get_time_usec(p) - ctx->offset : 0; + + mode = libinput_event_tablet_pad_get_mode(p); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, number: %d, position: %.2f, source: %s, mode: %d}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + number, + pos, + source, + mode); +} + +static void +buffer_switch_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + 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 = ctx->offset ? + libinput_event_switch_get_time_usec(s) - ctx->offset : 0; + + sw = libinput_event_switch_get_switch(s); + state = libinput_event_switch_get_switch_state(s); + + event->time = time; + snprintf(event->u.libinput.msg, + sizeof(event->u.libinput.msg), + "{time: %ld.%06ld, type: %s, switch: %d, state: %s}", + (long)(time / (int)1e6), + (long)(time % (int)1e6), + type, + sw, + state == LIBINPUT_SWITCH_STATE_ON ? "on" : "off"); +} + +static void +buffer_libinput_event(struct record_context *ctx, + struct libinput_event *e, + struct event *event) +{ + switch (libinput_event_get_type(e)) { + case LIBINPUT_EVENT_NONE: + abort(); + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + buffer_device_notify(ctx, e, event); + break; + case LIBINPUT_EVENT_KEYBOARD_KEY: + buffer_key_event(ctx, e, event); + break; + case LIBINPUT_EVENT_POINTER_MOTION: + buffer_motion_event(ctx, e, event); + break; + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + buffer_absmotion_event(ctx, e, event); + break; + case LIBINPUT_EVENT_POINTER_BUTTON: + buffer_pointer_button_event(ctx, e, event); + break; + case LIBINPUT_EVENT_POINTER_AXIS: + buffer_pointer_axis_event(ctx, e, event); + 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: + buffer_touch_event(ctx, e, event); + 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: + buffer_gesture_event(ctx, e, event); + break; + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + buffer_tablet_tool_proximity_event(ctx, e, event); + break; + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: + buffer_tablet_tool_event(ctx, e, event); + break; + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: + buffer_tablet_tool_button_event(ctx, e, event); + break; + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + buffer_tablet_pad_button_event(ctx, e, event); + break; + case LIBINPUT_EVENT_TABLET_PAD_RING: + case LIBINPUT_EVENT_TABLET_PAD_STRIP: + buffer_tablet_pad_ringstrip_event(ctx, e, event); + break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + buffer_switch_event(ctx, e, event); + break; + default: + break; + } +} + +static void +print_cached_events(struct record_context *ctx, + struct record_device *d, + unsigned int offset, + int len) +{ + unsigned int idx; + enum event_type last_type; + uint64_t last_time; + + if (len == -1) + len = d->nevents - offset; + assert(offset + len <= d->nevents); + + if (offset == 0) { + last_type = NONE; + last_time = 0; + } else { + last_type = d->events[offset - 1].type; + last_time = d->events[offset - 1].time; + } + + idx = offset; + indent_push(ctx); + while (idx < offset + len) { + struct event *e; + + e = &d->events[idx++]; + if (e->type != last_type || e->time != last_time) { + bool new_frame = false; + + if (last_time == 0 || e->time != last_time) + new_frame = true; + + indent_pop(ctx); + + switch(e->type) { + case EVDEV: + if (new_frame) + iprintf(ctx, "- evdev:\n"); + else + iprintf(ctx, "evdev:\n"); + break; + case LIBINPUT: + if (new_frame) + iprintf(ctx, "- libinput:\n"); + else + iprintf(ctx, "libinput:\n"); + break; + case COMMENT: + break; + default: + abort(); + } + indent_push(ctx); + + last_type = e->type; + } + + switch (e->type) { + case EVDEV: + print_evdev_event(ctx, &e->u.evdev); + break; + case LIBINPUT: + iprintf(ctx, "- %s\n", e->u.libinput.msg); + break; + case COMMENT: + iprintf(ctx, "%s", e->u.comment); + break; + default: + abort(); + } + + last_time = e->time; + } + indent_pop(ctx); +} + +static inline size_t +handle_libinput_events(struct record_context *ctx, + struct record_device *d) +{ + struct libinput_event *e; + size_t count = 0; + struct record_device *current = d; + + libinput_dispatch(ctx->libinput); + + while ((e = libinput_get_event(ctx->libinput)) != NULL) { + struct libinput_device *device = libinput_event_get_device(e); + struct event *event; + + 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); + } + + if (current->nevents == current->events_sz) + resize(current->events, current->events_sz); + + event = ¤t->events[current->nevents++]; + event->type = LIBINPUT; + buffer_libinput_event(ctx, e, event); + + if (current == d) + count++; + libinput_event_destroy(e); + } + return count; +} + +static inline void +handle_events(struct record_context *ctx, struct record_device *d, bool print) +{ + while(true) { + size_t first_idx = d->nevents; + size_t evcount = 0, + licount = 0; + + evcount = handle_evdev_frame(ctx, d); + + if (ctx->libinput) + licount = handle_libinput_events(ctx, d); + + if (evcount == 0 && licount == 0) + break; + + if (!print) + continue; + + print_cached_events(ctx, d, first_idx, evcount + licount); + } +} + +static inline void +print_libinput_header(struct record_context *ctx) +{ + iprintf(ctx, "libinput:\n"); + indent_push(ctx); + iprintf(ctx, "version: \"%s\"\n", LIBINPUT_VERSION); + iprintf(ctx, "git: \"%s\"\n", LIBINPUT_GIT_VERSION); + if (ctx->timeout > 0) + iprintf(ctx, "autorestart: %d\n", ctx->timeout); + indent_pop(ctx); +} + +static inline void +print_system_header(struct record_context *ctx) +{ + struct utsname u; + const char *kernel = "unknown"; + FILE *dmi; + char modalias[2048] = "unknown"; + + if (uname(&u) != -1) + kernel = u.release; + + dmi = fopen("/sys/class/dmi/id/modalias", "r"); + if (dmi) { + if (fgets(modalias, sizeof(modalias), dmi)) { + modalias[strlen(modalias) - 1] = '\0'; /* linebreak */ + } else { + sprintf(modalias, "unknown"); + } + fclose(dmi); + } + + iprintf(ctx, "system:\n"); + indent_push(ctx); + iprintf(ctx, "kernel: \"%s\"\n", kernel); + iprintf(ctx, "dmi: \"%s\"\n", modalias); + indent_pop(ctx); +} + +static inline void +print_header(struct record_context *ctx) +{ + iprintf(ctx, "version: %d\n", FILE_VERSION_NUMBER); + iprintf(ctx, "ndevices: %d\n", ctx->ndevices); + print_libinput_header(ctx); + print_system_header(ctx); +} + +static inline void +print_description_abs(struct record_context *ctx, + struct libevdev *dev, + unsigned int code) +{ + const struct input_absinfo *abs; + + abs = libevdev_get_abs_info(dev, code); + assert(abs); + + iprintf(ctx, "# Value %6d\n", abs->value); + iprintf(ctx, "# Min %6d\n", abs->minimum); + iprintf(ctx, "# Max %6d\n", abs->maximum); + iprintf(ctx, "# Fuzz %6d\n", abs->fuzz); + iprintf(ctx, "# Flat %6d\n", abs->flat); + iprintf(ctx, "# Resolution %6d\n", abs->resolution); +} + +static inline void +print_description_state(struct record_context *ctx, + struct libevdev *dev, + unsigned int type, + unsigned int code) +{ + int state = libevdev_get_event_value(dev, type, code); + iprintf(ctx, "# State %d\n", state); +} + +static inline void +print_description_codes(struct record_context *ctx, + struct libevdev *dev, + unsigned int type) +{ + int max; + + max = libevdev_event_type_get_max(type); + if (max == -1) + return; + + iprintf(ctx, + "# 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(ctx, + "# Event code %d (%s)\n", + code, + libevdev_event_code_get_name(type, + code)); + + switch (type) { + case EV_ABS: + print_description_abs(ctx, dev, code); + break; + case EV_LED: + case EV_SW: + print_description_state(ctx, dev, type, code); + break; + } + } +} + +static inline void +print_description(struct record_context *ctx, struct libevdev *dev) +{ + const struct input_absinfo *x, *y; + + iprintf(ctx, "# Name: %s\n", libevdev_get_name(dev)); + iprintf(ctx, + "# ID: bus %#02x vendor %#02x product %#02x version %#02x\n", + libevdev_get_id_bustype(dev), + 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(ctx, "# Size in mm: %dx%d\n", w, h); + } else { + iprintf(ctx, + "# Size in mm: unknown, missing resolution\n"); + } + } + + iprintf(ctx, "# Supported Events:\n"); + + for (unsigned int type = 0; type < EV_CNT; type++) { + if (!libevdev_has_event_type(dev, type)) + continue; + + print_description_codes(ctx, dev, type); + } + + iprintf(ctx, "# Properties:\n"); + + for (unsigned int prop = 0; prop < INPUT_PROP_CNT; prop++) { + if (libevdev_has_property(dev, prop)) { + iprintf(ctx, + "# Property %d (%s)\n", + prop, + libevdev_property_get_name(prop)); + } + } +} + +static inline void +print_bits_info(struct record_context *ctx, struct libevdev *dev) +{ + iprintf(ctx, "name: \"%s\"\n", libevdev_get_name(dev)); + iprintf(ctx, + "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 inline void +print_bits_absinfo(struct record_context *ctx, struct libevdev *dev) +{ + const struct input_absinfo *abs; + + if (!libevdev_has_event_type(dev, EV_ABS)) + return; + + iprintf(ctx, "absinfo:\n"); + indent_push(ctx); + + for (unsigned int code = 0; code < ABS_CNT; code++) { + abs = libevdev_get_abs_info(dev, code); + if (!abs) + continue; + + iprintf(ctx, + "%d: [%d, %d, %d, %d, %d]\n", + code, + abs->minimum, + abs->maximum, + abs->fuzz, + abs->flat, + abs->resolution); + } + indent_pop(ctx); +} + +static inline void +print_bits_codes(struct record_context *ctx, + struct libevdev *dev, + unsigned int type) +{ + int max; + bool first = true; + + max = libevdev_event_type_get_max(type); + if (max == -1) + return; + + iprintf(ctx, "%d: [", type); + + for (unsigned int code = 0; code <= (unsigned int)max; code++) { + if (!libevdev_has_event_code(dev, type, code)) + continue; + + noiprintf(ctx, "%s%d", first ? "" : ", ", code); + first = false; + } + + noiprintf(ctx, "] # %s\n", libevdev_event_type_get_name(type)); +} + +static inline void +print_bits_types(struct record_context *ctx, struct libevdev *dev) +{ + iprintf(ctx, "codes:\n"); + indent_push(ctx); + for (unsigned int type = 0; type < EV_CNT; type++) { + if (!libevdev_has_event_type(dev, type)) + continue; + print_bits_codes(ctx, dev, type); + } + indent_pop(ctx); +} + +static inline void +print_bits_props(struct record_context *ctx, struct libevdev *dev) +{ + bool first = true; + + iprintf(ctx, "properties: ["); + for (unsigned int prop = 0; prop < INPUT_PROP_CNT; prop++) { + if (libevdev_has_property(dev, prop)) { + noiprintf(ctx, "%s%d", first ? "" : ", ", prop); + first = false; + } + } + noiprintf(ctx, "]\n"); /* last entry, no comma */ +} + +static inline void +print_evdev_description(struct record_context *ctx, struct record_device *dev) +{ + struct libevdev *evdev = dev->evdev; + + iprintf(ctx, "evdev:\n"); + indent_push(ctx); + + print_description(ctx, evdev); + print_bits_info(ctx, evdev); + print_bits_types(ctx, evdev); + print_bits_absinfo(ctx, evdev); + print_bits_props(ctx, evdev); + + indent_pop(ctx); +} + +static inline void +print_hid_report_descriptor(struct record_context *ctx, + struct record_device *dev) +{ + const char *prefix = "/dev/input/event"; + const char *node; + char syspath[PATH_MAX]; + unsigned char buf[1024]; + int len; + int fd; + bool first = true; + + /* we take the shortcut rather than the proper udev approach, the + report_descriptor is available in sysfs and two devices up from + our device. 2 digits for the event number should be enough. + This approach won't work for /dev/input/by-id devices. */ + if (!strneq(dev->devnode, prefix, strlen(prefix)) || + strlen(dev->devnode) > strlen(prefix) + 2) + return; + + node = &dev->devnode[strlen(prefix)]; + len = snprintf(syspath, + sizeof(syspath), + "/sys/class/input/event%s/device/device/report_descriptor", + node); + if (len < 55 || len > 56) + return; + + fd = open(syspath, O_RDONLY); + if (fd == -1) + return; + + iprintf(ctx, "hid: ["); + + while ((len = read(fd, buf, sizeof(buf))) > 0) { + for (int i = 0; i < len; i++) { + /* YAML requires decimal */ + noiprintf(ctx, "%s%u",first ? "" : ", ", buf[i]); + first = false; + } + } + noiprintf(ctx, " ]\n"); + + close(fd); +} + +static inline void +print_udev_properties(struct record_context *ctx, 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(ctx, "udev:\n"); + indent_push(ctx); + + iprintf(ctx, "properties:\n"); + indent_push(ctx); + + entry = udev_device_get_properties_list_entry(udev_device); + while (entry) { + const char *key, *value; + + key = udev_list_entry_get_name(entry); + + if (strneq(key, "ID_INPUT", 8) || + strneq(key, "LIBINPUT", 8) || + strneq(key, "EV_ABS", 6) || + strneq(key, "MOUSE_DPI", 9) || + strneq(key, "POINTINGSTICK_", 14)) { + value = udev_list_entry_get_value(entry); + iprintf(ctx, "- %s=%s\n", key, value); + } + + entry = udev_list_entry_get_next(entry); + } + + indent_pop(ctx); + indent_pop(ctx); +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) +{ + struct record_context *ctx = userdata; + + iprintf(ctx, "- %s\n", val); +} + +static inline void +print_device_quirks(struct record_context *ctx, 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 initialize the device quirks. " + "Please see the above errors " + "and/or re-run with --verbose for more details\n"); + 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(ctx, "quirks:\n"); + indent_push(ctx); + + tools_list_device_quirks(quirks, udev_device, list_print, ctx); + + indent_pop(ctx); +out: + udev_device_unref(udev_device); + udev_unref(udev); + quirks_context_unref(quirks); +} +static inline void +print_libinput_description(struct record_context *ctx, + 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"}, + }; + struct cap *cap; + bool is_first; + + if (!device) + return; + + iprintf(ctx, "libinput:\n"); + indent_push(ctx); + + if (libinput_device_get_size(device, &w, &h) == 0) + iprintf(ctx, "size: [%.f, %.f]\n", w, h); + + iprintf(ctx, "capabilities: ["); + is_first = true; + ARRAY_FOR_EACH(caps, cap) { + if (!libinput_device_has_capability(device, cap->cap)) + continue; + noiprintf(ctx, "%s%s", is_first ? "" : ", ", cap->name); + is_first = false; + } + noiprintf(ctx, "]\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. + */ + indent_pop(ctx); +} + +static inline void +print_device_description(struct record_context *ctx, struct record_device *dev) +{ + iprintf(ctx, "- node: %s\n", dev->devnode); + + print_evdev_description(ctx, dev); + print_hid_report_descriptor(ctx, dev); + print_udev_properties(ctx, dev); + print_device_quirks(ctx, dev); + print_libinput_description(ctx, dev); +} + +static int is_event_node(const struct dirent *dir) { + return strneq(dir->d_name, "event", 5); +} + +static inline char * +select_device(void) +{ + struct dirent **namelist; + int ndev, selected_device; + int rc; + char *device_path; + bool has_eaccess = false; + int available_devices = 0; + + ndev = scandir("/dev/input", &namelist, is_event_node, versionsort); + if (ndev <= 0) + return NULL; + + fprintf(stderr, "Available devices:\n"); + 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\n", 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. "); + if (has_eaccess) + fprintf(stderr, "Please re-run as root."); + fprintf(stderr, "\n"); + return NULL; + } + + fprintf(stderr, "Select the device event number: "); + 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 inline char ** +all_devices(void) +{ + struct dirent **namelist; + int ndev; + int rc; + 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; + + rc = xasprintf(&device_path, + "/dev/input/%s", + namelist[i]->d_name); + if (rc == -1) + goto error; + + devices[i] = device_path; + } + + return devices; + +error: + 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 strdup(name); +} + +static bool +open_output_file(struct record_context *ctx, bool is_prefix) +{ + int out_fd; + + if (ctx->outfile) { + char *fname = init_output_file(ctx->outfile, is_prefix); + ctx->output_file = fname; + out_fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (out_fd < 0) + return false; + } else { + ctx->output_file = safe_strdup("stdout"); + out_fd = STDOUT_FILENO; + } + + ctx->out_fd = out_fd; + + return true; +} + +static inline 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 int +mainloop(struct record_context *ctx) +{ + bool autorestart = (ctx->timeout > 0); + struct pollfd fds[ctx->ndevices + 2]; + unsigned int nfds = 0; + struct record_device *d = NULL; + struct record_device *first_device = NULL; + struct timespec ts; + sigset_t mask; + + assert(ctx->timeout != 0); + assert(!list_empty(&ctx->devices)); + + sigemptyset(&mask); + sigaddset(&mask, SIGINT); + sigaddset(&mask, SIGQUIT); + sigprocmask(SIG_BLOCK, &mask, NULL); + + fds[0].fd = signalfd(-1, &mask, SFD_NONBLOCK); + fds[0].events = POLLIN; + fds[0].revents = 0; + assert(fds[0].fd != -1); + nfds++; + + if (ctx->libinput) { + fds[1].fd = libinput_get_fd(ctx->libinput); + fds[1].events = POLLIN; + fds[1].revents = 0; + nfds++; + assert(nfds == 2); + } + + list_for_each(d, &ctx->devices, link) { + fds[nfds].fd = libevdev_get_fd(d->evdev); + fds[nfds].events = POLLIN; + fds[nfds].revents = 0; + assert(fds[nfds].fd != -1); + nfds++; + } + + /* 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) { + clock_gettime(CLOCK_MONOTONIC, &ts); + ctx->offset = s2us(ts.tv_sec) + ns2us(ts.tv_nsec); + } + + do { + int rc; + bool had_events = false; /* we delete files without events */ + + if (!open_output_file(ctx, autorestart)) { + fprintf(stderr, + "Failed to open '%s'\n", + ctx->output_file); + break; + } + fprintf(stderr, "Recording to '%s'.\n", ctx->output_file); + + print_header(ctx); + if (autorestart) + iprintf(ctx, + "# Autorestart timeout: %d\n", + ctx->timeout); + + iprintf(ctx, "devices:\n"); + indent_push(ctx); + + /* we only print the first device's description, the + * rest is assembled after CTRL+C */ + first_device = list_first_entry(&ctx->devices, + first_device, + link); + print_device_description(ctx, first_device); + + iprintf(ctx, "events:\n"); + indent_push(ctx); + + if (ctx->libinput) { + size_t count; + libinput_dispatch(ctx->libinput); + count = handle_libinput_events(ctx, first_device); + print_cached_events(ctx, first_device, 0, count); + } + + while (true) { + rc = poll(fds, nfds, ctx->timeout); + if (rc == -1) { /* error */ + fprintf(stderr, "Error: %m\n"); + autorestart = false; + break; + } else if (rc == 0) { + fprintf(stderr, + " ... timeout%s\n", + had_events ? "" : " (file is empty)"); + break; + } else if (fds[0].revents != 0) { /* signal */ + autorestart = false; + break; + } + + /* Pull off the evdev events first since they cause + * libinput events. + * handle_events de-queues libinput events so by the + * time we finish that, we hopefully have all evdev + * events and libinput events roughly in sync. + */ + had_events = true; + list_for_each(d, &ctx->devices, link) + handle_events(ctx, d, d == first_device); + + /* This shouldn't pull any events off unless caused + * by libinput-internal timeouts (e.g. tapping) */ + if (ctx->libinput && fds[1].revents) { + size_t count, offset; + + libinput_dispatch(ctx->libinput); + offset = first_device->nevents; + count = handle_libinput_events(ctx, + first_device); + if (count) { + print_cached_events(ctx, + first_device, + offset, + count); + } + rc--; + } + + if (ctx->out_fd != STDOUT_FILENO) + print_progress_bar(); + + } + indent_pop(ctx); /* events: */ + + if (autorestart) { + noiprintf(ctx, + "# 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) { + if (d == list_first_entry(&ctx->devices, d, link)) + continue; + + print_device_description(ctx, d); + iprintf(ctx, "events:\n"); + indent_push(ctx); + print_cached_events(ctx, d, 0, -1); + indent_pop(ctx); + } + + indent_pop(ctx); /* devices: */ + assert(ctx->indent == 0); + + fsync(ctx->out_fd); + + /* If we didn't have events, delete the file. */ + if (!isatty(ctx->out_fd)) { + if (!had_events && ctx->output_file) { + fprintf(stderr, "No events recorded, deleting '%s'\n", ctx->output_file); + unlink(ctx->output_file); + } + + close(ctx->out_fd); + ctx->out_fd = -1; + } + free(ctx->output_file); + ctx->output_file = NULL; + } while (autorestart); + + close(fds[0].fd); + + sigprocmask(SIG_UNBLOCK, &mask, NULL); + + return 0; +} + +static inline bool +init_device(struct record_context *ctx, char *path) +{ + struct record_device *d; + int fd, rc; + + d = zalloc(sizeof(*d)); + d->devnode = path; + d->nevents = 0; + d->events_sz = 5000; + d->events = zalloc(d->events_sz * sizeof(*d->events)); + + 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) { + fprintf(stderr, + "Failed to create context for %s (%s)\n", + d->devnode, + 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_insert(&ctx->devices, &d->link); + 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); +} + +const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +static inline 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 inline void +usage(void) +{ + printf("Usage: %s [--help] [--multiple|--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 --multiple -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 options { + OPT_AUTORESTART, + OPT_HELP, + OPT_OUTFILE, + OPT_KEYCODES, + OPT_MULTIPLE, + OPT_ALL, + OPT_LIBINPUT, +}; + +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 }, + { 0, 0, 0, 0 }, + }; + struct record_device *d, *tmp; + const char *output_arg = NULL; + bool multiple = false, all = false, with_libinput = false; + int ndevices; + int rc = 1; + + list_init(&ctx.devices); + + 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 = 0; + goto out; + case OPT_AUTORESTART: + if (!safe_atoi(optarg, &ctx.timeout) || + ctx.timeout <= 0) { + 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: + multiple = true; + break; + case OPT_ALL: + all = true; + break; + case OPT_LIBINPUT: + with_libinput = true; + break; + } + } + + if (all && multiple) { + fprintf(stderr, + "Only one of --multiple and --all allowed.\n"); + goto out; + } + + if (ctx.timeout > 0 && output_arg == NULL) { + fprintf(stderr, + "Option --autorestart requires --output-file\n"); + goto out; + } + + ctx.outfile = safe_strdup(output_arg); + + ndevices = argc - optind; + + if (multiple) { + if (output_arg == NULL) { + fprintf(stderr, + "Option --multiple requires --output-file\n"); + goto out; + } + + if (ndevices <= 1) { + fprintf(stderr, + "Option --multiple requires all device nodes on the commandline\n"); + goto out; + } + + for (int i = ndevices; i > 0; i -= 1) { + char *devnode = safe_strdup(argv[optind + i - 1]); + + if (!init_device(&ctx, devnode)) + goto out; + } + } else if (all) { + char **devices; /* NULL-terminated */ + char **d; + + if (output_arg == NULL) { + fprintf(stderr, + "Option --all requires --output-file\n"); + goto out; + } + + devices = all_devices(); + d = devices; + + while (*d) { + if (!init_device(&ctx, safe_strdup(*d))) { + strv_free(devices); + goto out; + } + d++; + } + + strv_free(devices); + } else { + char *path; + + if (ndevices > 1) { + fprintf(stderr, "More than one device, do you want --multiple?\n"); + goto out; + } + + path = ndevices <= 0 ? select_device() : safe_strdup(argv[optind++]); + if (path == NULL) { + goto out; + } + + if (!init_device(&ctx, path)) + goto out; + } + + if (with_libinput && !init_libinput(&ctx)) + goto out; + + rc = mainloop(&ctx); +out: + list_for_each_safe(d, tmp, &ctx.devices, link) { + if (d->device) + libinput_device_unref(d->device); + free(d->events); + free(d->devnode); + libevdev_free(d->evdev); + } + + libinput_unref(ctx.libinput); + + return rc; +} diff --git a/tools/libinput-record.man b/tools/libinput-record.man new file mode 100644 index 0000000..bed3d16 --- /dev/null +++ b/tools/libinput-record.man @@ -0,0 +1,292 @@ +.TH libinput-record "1" +.SH NAME +libinput\-record \- record kernel events +.SH SYNOPSIS +.B libinput record [options] [\fI/dev/input/event0\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 the \fB-o\fR option is given. +.PP +The events recorded are independent of libinput itself, updating or +removing libinput will not change the event stream. +.SH OPTIONS +If a device node is given, this tool opens that device node. 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. Use +\fB\-\-multiple\fR instead. +This option requires that a \fB\-\-output-file\fR is specified and may not +be used together with \fB\-\-multiple\fR. +.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 or +\fB\-\-multiple\fR is given, the filename is used as prefix only. +.TP 8 +.B \-\-multiple +Record multiple devices at once, see section +.B RECORDING MULTIPLE DEVICES +This option requires that a +\fB\-\-output-file\fR is specified and that all devices to be recorded are +given on the commandline. +.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. + +.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. The \fB\-\-multiple\fR option records multiple devices with +an identical time offset, allowing for correct replay of the interaction. +.PP +The \fB\-\-multiple\fR option requires that an output filename is given. +This filename is used as prefix, with the event node number appended. +.PP +All devices to be recorded must be provided on the commandline, an example +invocation is: + +.B libinput record \-\-multiple \-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 switch is provided, \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 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: + 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: + - 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 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: [ {"data": [sec, usec, type, code, value]}, ...] } +Each \fBinput_event\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. + +.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 diff --git a/tools/libinput-replay b/tools/libinput-replay new file mode 100755 index 0000000..91e50aa --- /dev/null +++ b/tools/libinput-replay @@ -0,0 +1,207 @@ +#!/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 multiprocessing +import argparse + +try: + import libevdev + import yaml +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 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() + 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)) + + +def replay(device, verbose): + events = fetch(device, 'events') + if events is None: + return + uinput = device['__uinput'] + + offset = time.time() + handled_first_event = False + + # 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 + + (sec, usec, evtype, evcode, value) = evdev[0] + + # The first event may have a nonzero offset but we want to replay + # immediately regardless. + if not handled_first_event: + offset -= sec + usec/1.e6 + handled_first_event = True + + evtime = sec + usec/1e6 + offset + now = time.time() + + if evtime - now > 150/1e6: # 150 µs error margin + time.sleep(evtime - now - 150/1e6) + + evs = [libevdev.InputEvent(libevdev.evbit(e[2], e[3]), value=e[4], sec=e[0], usec=e[1]) for e in evdev] + uinput.send_events(evs) + if verbose: + print_events(uinput.devnode, device['__index'], evs) + + +def wrap(func, *args): + try: + func(*args) + except KeyboardInterrupt: + pass + + +def loop(args, 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))) + + 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 + + stop = False + while not stop: + input('Hit enter to start replaying') + + processes = [] + for d in devices: + p = multiprocessing.Process(target=wrap, args=(replay, d, args.verbose)) + processes.append(p) + + for p in processes: + p.start() + + for p in processes: + p.join() + + del processes + + +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('--verbose', action='store_true') + args = parser.parse_args() + + try: + with open(args.recording) as f: + y = yaml.safe_load(f) + 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)) + + +if __name__ == '__main__': + main() diff --git a/tools/libinput-replay.man b/tools/libinput-replay.man new file mode 100644 index 0000000..7bca518 --- /dev/null +++ b/tools/libinput-replay.man @@ -0,0 +1,28 @@ +.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 +.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. +.SH LIBINPUT +.PP +Part of the +.B libinput(1) +suite diff --git a/tools/libinput-tool.c b/tools/libinput-tool.c new file mode 100644 index 0000000..7195de0 --- /dev/null +++ b/tools/libinput-tool.c @@ -0,0 +1,114 @@ +/* + * 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 +#include +#include +#include + +#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" + " debug-gui\n" + " Display a simple GUI to visualize libinput's events.\n" + "\n" + " measure \n" + " Measure various device properties. 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); +} diff --git a/tools/libinput.man b/tools/libinput.man new file mode 100644 index 0000000..a2e678e --- /dev/null +++ b/tools/libinput.man @@ -0,0 +1,71 @@ +.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 +.TP 8 +.B libinput\-debug\-gui(1) +Show a GUI to visualize libinput's events +.TP 8 +.B libinput\-list\-devices(1) +List all devices recognized by libinput +.TP 8 +.B libinput\-measure(1) +Measure various properties of devices +.TP 8 +.B libinput\-measure\-touch\-size(1) +Measure touch size and orientation +.TP 8 +.B libinput\-measure\-touchpad\-tap(1) +Measure tap-to-click time +.TP 8 +.B libinput\-measure\-touchpad\-pressure(1) +Measure touch pressure +.TP 8 +.B libinput\-record(1) +Record the events from a device +.TP 8 +.B libinput\-replay(1) +Replay the events from a device +.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/ diff --git a/tools/make-ptraccel-graphs.sh b/tools/make-ptraccel-graphs.sh new file mode 100755 index 0000000..bfb3f91 --- /dev/null +++ b/tools/make-ptraccel-graphs.sh @@ -0,0 +1,87 @@ +#!/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" + "\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; + + enum { + OPT_HELP = 1, + OPT_MODE, + OPT_NEVENTS, + OPT_MAXDX, + OPT_STEP, + OPT_SPEED, + OPT_DPI, + OPT_FILTER, + }; + + 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 }, + {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; + 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 { + 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; + } + + filter_destroy(filter); + + return 0; +} diff --git a/tools/shared.c b/tools/shared.c new file mode 100644 index 0000000..02c09dd --- /dev/null +++ b/tools/shared.c @@ -0,0 +1,672 @@ +/* + * 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 "builddir.h" +#include "shared.h" + +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; + + if (is_tty == -1) + is_tty = isatty(STDOUT_FILENO); + + if (is_tty) { + if (priority >= LIBINPUT_LOG_PRIORITY_ERROR) + printf(ANSI_RED); + else if (priority >= LIBINPUT_LOG_PRIORITY_INFO) + printf(ANSI_HIGHLIGHT); + } + + vprintf(format, args); + + if (is_tty && priority >= LIBINPUT_LOG_PRIORITY_INFO) + printf(ANSI_NORMAL); +} + +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->click_method = -1; + options->scroll_method = -1; + options->scroll_button = -1; + options->speed = 0.0; + options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +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: + options->drag_lock = 1; + break; + case OPT_DRAG_LOCK_DISABLE: + options->drag_lock = 0; + 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_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_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_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 + return 1; + break; + case OPT_DISABLE_SENDEVENTS: + if (!optarg) + return 1; + + snprintf(options->disable_pattern, + sizeof(options->disable_pattern), + "%s", + optarg); + break; + case OPT_APPLY_TO: + if (!optarg) + return 1; + + snprintf(options->match, + sizeof(options->match), + "%s", + optarg); + 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 *path, bool verbose, bool *grab) +{ + struct libinput_device *device; + struct libinput *li; + + li = libinput_path_create_context(&interface, grab); + if (!li) { + fprintf(stderr, "Failed to initialize context from %s\n", path); + return NULL; + } + + if (verbose) { + libinput_log_set_handler(li, log_handler); + libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); + } + + device = libinput_path_add_device(li, path); + if (!device) { + fprintf(stderr, "Failed to initialize device %s\n", path); + libinput_unref(li); + li = NULL; + } + + 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, 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; + + 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->click_method != (enum libinput_config_click_method)-1) + libinput_device_config_click_set_method(device, options->click_method); + + 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 (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); + } +} + +static char* +find_device(const char *udev_tag) +{ + struct udev *udev; + struct udev_enumerate *e; + struct udev_list_entry *entry = NULL; + struct udev_device *device; + const char *path, *sysname; + char *device_node = NULL; + + udev = udev_new(); + 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 (strncmp("event", sysname, 5) != 0) { + 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; + } + 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(); + 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 a libinput command or not installed. " + "See 'libinput --help'\n", + command); + return EXIT_INVALID_USAGE; + } else { + 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) +{ + const struct quirk_tuples *t; + size_t off = 0; + int printed; + const char *name; + + quirks_get_tuples(quirks, QUIRK_ATTR_EVENT_CODE_DISABLE, &t); + name = quirk_get_name(QUIRK_ATTR_EVENT_CODE_DISABLE); + printed = snprintf(buf, sz, "%s=", name); + assert(printed != -1); + off += printed; + + for (size_t i = 0; off < sz && i < t->ntuples; i++) { + const char *name = libevdev_event_code_get_name( + t->tuples[i].first, + t->tuples[i].second); + + printed = snprintf(buf + off, sz - off, "%s;", 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_TOUCHPAD; + do { + if (quirks_has_quirk(quirks, q)) { + const char *name; + + name = quirk_get_name(q); + snprintf(buf, sizeof(buf), "%s=1", name); + 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; + + 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_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: + snprintf(buf, sizeof(buf), "%s=1", name); + callback(userdata, buf); + break; + case QUIRK_ATTR_EVENT_CODE_DISABLE: + sprintf_event_codes(buf, sizeof(buf), quirks); + callback(userdata, buf); + break; + default: + abort(); + break; + } + } + } while(++q < _QUIRK_LAST_ATTR_QUIRK_); + + quirks_unref(quirks); +} diff --git a/tools/shared.h b/tools/shared.h new file mode 100644 index 0000000..e2a6d66 --- /dev/null +++ b/tools/shared.h @@ -0,0 +1,130 @@ +/* + * 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 + +#define EXIT_INVALID_USAGE 2 + +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_CLICK_METHOD, + OPT_SCROLL_METHOD, + OPT_SCROLL_BUTTON, + OPT_SPEED, + OPT_PROFILE, + OPT_DISABLE_SENDEVENTS, + OPT_APPLY_TO, +}; + +#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", no_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 }, \ + { "set-click-method", required_argument, 0, OPT_CLICK_METHOD }, \ + { "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 },\ + { "apply-to", required_argument, 0, OPT_APPLY_TO } + +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_scroll_method scroll_method; + enum libinput_config_tap_button_map tap_map; + int scroll_button; + double speed; + int dwt; + enum libinput_config_accel_profile profile; + char disable_pattern[64]; +}; + +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_device, + bool verbose, + bool *grab); +void tools_device_apply_config(struct libinput_device *device, + 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); + +#endif diff --git a/tools/test-tool-option-parsing.py b/tools/test-tool-option-parsing.py new file mode 100755 index 0000000..d5fbbd5 --- /dev/null +++ b/tools/test-tool-option-parsing.py @@ -0,0 +1,253 @@ +#!/usr/bin/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 unittest +import resource +import sys +import subprocess +import time + + +def _disable_coredump(): + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + + +def run_command(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 TestLibinputTool(unittest.TestCase): + libinput_tool = 'libinput' + subtool = None + + 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) + self.assertIn(rc, [0, 1]) + + def run_command_unrecognized_option(self, args): + rc, stdout, stderr = self.run_command(args) + self.assertEqual(rc, 2) + self.assertTrue(stdout.startswith('Usage') or stdout == '') + self.assertIn('unrecognized option', stderr) + + def run_command_missing_arg(self, args): + rc, stdout, stderr = self.run_command(args) + self.assertEqual(rc, 2) + self.assertTrue(stdout.startswith('Usage') or stdout == '') + self.assertIn('requires an argument', stderr) + + def run_command_unrecognized_tool(self, args): + rc, stdout, stderr = self.run_command(args) + self.assertEqual(rc, 2) + self.assertTrue(stdout.startswith('Usage') or stdout == '') + self.assertIn('is not a libinput command', stderr) + + +class TestLibinputCommand(TestLibinputTool): + subtool = None + + def test_help(self): + rc, stdout, stderr = self.run_command(['--help']) + self.assertEqual(rc, 0) + self.assertTrue(stdout.startswith('Usage:')) + self.assertEqual(stderr, '') + + def test_version(self): + rc, stdout, stderr = self.run_command(['--version']) + self.assertEqual(rc, 0) + self.assertTrue(stdout.startswith('1')) + self.assertEqual(stderr, '') + + def test_invalid_arguments(self): + self.run_command_unrecognized_option(['--banana']) + self.run_command_unrecognized_option(['--foo']) + self.run_command_unrecognized_option(['--quiet']) + self.run_command_unrecognized_option(['--verbose']) + self.run_command_unrecognized_option(['--quiet', 'foo']) + + def test_invalid_tools(self): + self.run_command_unrecognized_tool(['foo']) + self.run_command_unrecognized_tool(['debug']) + self.run_command_unrecognized_tool(['foo', '--quiet']) + + +class TestToolWithOptions(object): + options = { + 'pattern': ['sendevents'], + # enable/disable options + 'enable-disable': [ + 'tap', + 'drag', + 'drag-lock', + 'middlebutton', + 'natural-scrolling', + 'left-handed', + 'dwt' + ], + # 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'], + }, + # options with a range + 'ranges': { + 'set-speed': (float, -1.0, +1.0), + } + } + + def test_udev_seat(self): + self.run_command_missing_arg(['--udev']) + self.run_command_success(['--udev', 'seat0']) + self.run_command_success(['--udev', 'seat1']) + + @unittest.skipIf(os.environ.get('UDEV_NOT_AVAILABLE'), "udev required") + def test_device(self): + self.run_command_missing_arg(['--device']) + self.run_command_success(['--device', '/dev/input/event0']) + self.run_command_success(['--device', '/dev/input/event1']) + self.run_command_success(['/dev/input/event0']) + + def test_options_pattern(self): + for option in self.options['pattern']: + self.run_command_success(['--disable-{}'.format(option), '*']) + self.run_command_success(['--disable-{}'.format(option), 'abc*']) + + def test_options_enable_disable(self): + for option in self.options['enable-disable']: + self.run_command_success(['--enable-{}'.format(option)]) + self.run_command_success(['--disable-{}'.format(option)]) + + def test_options_enums(self): + for option, values in self.options['enums'].items(): + for v in values: + self.run_command_success(['--{}'.format(option), v]) + self.run_command_success(['--{}={}'.format(option, v)]) + + def test_options_ranges(self): + for option, values in self.options['ranges'].items(): + range_type, minimum, maximum = values + self.assertEqual(range_type, float) + step = (maximum - minimum)/10.0 + value = minimum + while value < maximum: + self.run_command_success(['--{}'.format(option), str(value)]) + self.run_command_success(['--{}={}'.format(option, value)]) + value += step + self.run_command_success(['--{}'.format(option), str(maximum)]) + self.run_command_success(['--{}={}'.format(option, maximum)]) + + def test_apply_to(self): + self.run_command_missing_arg(['--apply-to']) + self.run_command_success(['--apply-to', '*foo*']) + self.run_command_success(['--apply-to', 'foobar']) + self.run_command_success(['--apply-to', 'any']) + + +class TestDebugEvents(TestToolWithOptions, TestLibinputTool): + subtool = 'debug-events' + + def test_verbose_quiet(self): + rc, stdout, stderr = self.run_command(['--verbose']) + self.assertEqual(rc, 0) + rc, stdout, stderr = self.run_command(['--quiet']) + self.assertEqual(rc, 0) + rc, stdout, stderr = self.run_command(['--verbose', '--quiet']) + self.assertEqual(rc, 0) + rc, stdout, stderr = self.run_command(['--quiet', '--verbose']) + self.assertEqual(rc, 0) + + def test_invalid_arguments(self): + self.run_command_unrecognized_option(['--banana']) + self.run_command_unrecognized_option(['--foo']) + self.run_command_unrecognized_option(['--version']) + + +class TestDebugGUI(TestToolWithOptions, TestLibinputTool): + subtool = 'debug-gui' + + @classmethod + def setUpClass(cls): + # This is set by meson + debug_gui_enabled = @MESON_ENABLED_DEBUG_GUI@ + if not debug_gui_enabled: + raise unittest.SkipTest() + + if not os.getenv('DISPLAY') and not os.getenv('WAYLAND_DISPLAY'): + raise unittest.SkipTest() + + # 77 means gtk_init() failed, which is probably because you can't + # connect to the display server. + rc, _, _ = run_command([TestLibinputTool.libinput_tool, cls.subtool, '--help']) + if rc == 77: + raise unittest.SkipTest() + + def test_verbose_quiet(self): + rc, stdout, stderr = self.run_command(['--verbose']) + self.assertEqual(rc, 0) + + def test_invalid_arguments(self): + self.run_command_unrecognized_option(['--quiet']) + self.run_command_unrecognized_option(['--banana']) + self.run_command_unrecognized_option(['--foo']) + self.run_command_unrecognized_option(['--version']) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Verify a libinput tool\'s option parsing') + parser.add_argument('--tool-path', metavar='/path/to/builddir/libinput', + type=str, + help='Path to the libinput tool in the builddir') + parser.add_argument('--verbose', action='store_true') + args, remainder = parser.parse_known_args() + if args.tool_path is not None: + TestLibinputTool.libinput_tool = args.tool_path + verbosity = 1 + if args.verbose: + verbosity = 3 + + argv = [sys.argv[0], *remainder] + unittest.main(verbosity=verbosity, argv=argv) diff --git a/udev/80-libinput-device-groups.rules.in b/udev/80-libinput-device-groups.rules.in new file mode 100644 index 0000000..1a26f78 --- /dev/null +++ b/udev/80-libinput-device-groups.rules.in @@ -0,0 +1,9 @@ +ACTION!="add|change", GOTO="libinput_device_group_end" +KERNEL!="event[0-9]*", GOTO="libinput_device_group_end" + +ATTRS{phys}=="?*", \ + ENV{LIBINPUT_DEVICE_GROUP}=="", \ + PROGRAM="@UDEV_TEST_PATH@libinput-device-group %S%p", \ + ENV{LIBINPUT_DEVICE_GROUP}="%c" + +LABEL="libinput_device_group_end" diff --git a/udev/90-libinput-fuzz-override.rules.in b/udev/90-libinput-fuzz-override.rules.in new file mode 100644 index 0000000..e3d8e53 --- /dev/null +++ b/udev/90-libinput-fuzz-override.rules.in @@ -0,0 +1,20 @@ +# 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!="add|change", GOTO="libinput_fuzz_override_end" +KERNEL!="event*", GOTO="libinput_fuzz_override_end" + +# libinput-fuzz-override must only be called once per device, otherwise +# we'll lose the fuzz information +ATTRS{capabilities/abs}!="0", \ + ENV{ID_INPUT_TOUCHPAD}=="1", \ + IMPORT{program}="@UDEV_TEST_PATH@libinput-fuzz-override %S%p", \ + GOTO="libinput_fuzz_override_end" +ATTRS{capabilities/abs}!="0", \ + ENV{ID_INPUT_TOUCHSCREEN}=="1", \ + IMPORT{program}="@UDEV_TEST_PATH@libinput-fuzz-override %S%p", \ + GOTO="libinput_fuzz_override_end" + +LABEL="libinput_fuzz_override_end" diff --git a/udev/libinput-device-group.c b/udev/libinput-device-group.c new file mode 100644 index 0000000..dfcf9e0 --- /dev/null +++ b/udev/libinput-device-group.c @@ -0,0 +1,257 @@ +/* + * 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_GET_PAIRED_DEVICE +#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); +} +#endif + +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, + const 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((char*)*phys_attr); + *phys_attr = strdup(phys); + } + } + + udev_device_unref(d); + } + + udev_enumerate_unref(e); +} + +int main(int argc, char **argv) +{ + int rc = 1; + struct udev *udev = NULL; + struct udev_device *device = NULL; + const char *syspath, + *phys = NULL, + *physmatch = 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 { +#if HAVE_LIBWACOM_GET_PAIRED_DEVICE + 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); + } + + 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("%s\n", group); + + rc = 0; +out: + if (device) + udev_device_unref(device); + if (udev) + udev_unref(udev); + + return rc; +} diff --git a/udev/libinput-fuzz-override.c b/udev/libinput-fuzz-override.c new file mode 100644 index 0000000..bb05886 --- /dev/null +++ b/udev/libinput-fuzz-override.c @@ -0,0 +1,124 @@ +/* + * 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 "libinput-util.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 *code; + 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 == -1 && errno == EACCES) + 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) { + 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); + + printf("LIBINPUT_FUZZ_%02x=%d\n", *code, fuzz); + } + +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; + + handle_absfuzz(device); + + rc = 0; + +out: + if (device) + udev_device_unref(device); + if (udev) + udev_unref(udev); + + return rc; +}