libinput/test/litest-device-keyboard-quirked.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

254 lines
6.1 KiB
C
Raw Permalink Normal View History

/*
* 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-int.h"
#include "litest.h"
static struct input_id input_id = {
.bustype = 0x11,
.vendor = 0x1,
.product = 0x1,
};
/* clang-format off */
static int events[] = {
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, KEY_ESC,
EV_KEY, KEY_1,
EV_KEY, KEY_2,
EV_KEY, KEY_3,
EV_KEY, KEY_4,
EV_KEY, KEY_5,
EV_KEY, KEY_6,
EV_KEY, KEY_7,
EV_KEY, KEY_8,
EV_KEY, KEY_9,
EV_KEY, KEY_0,
EV_KEY, KEY_MINUS,
EV_KEY, KEY_EQUAL,
EV_KEY, KEY_BACKSPACE,
EV_KEY, KEY_TAB,
EV_KEY, KEY_Q,
EV_KEY, KEY_W,
EV_KEY, KEY_E,
EV_KEY,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V_KEY, KEY_KP0,
EV_KEY, KEY_KPDOT,
EV_KEY, KEY_ZENKAKUHANKAKU,
EV_KEY, KEY_102ND,
EV_KEY, KEY_F11,
EV_KEY, KEY_F12,
EV_KEY, KEY_RO,
EV_KEY, KEY_KATAKANA,
EV_KEY, KEY_HIRAGANA,
EV_KEY, KEY_HENKAN,
EV_KEY, KEY_KATAKANAHIRAGANA,
EV_KEY, KEY_MUHENKAN,
EV_KEY, KEY_KPJPCOMMA,
EV_KEY, KEY_KPENTER,
EV_KEY, KEY_RIGHTCTRL,
EV_KEY, KEY_KPSLASH,
EV_KEY, KEY_SYSRQ,
EV_KEY, KEY_RIGHTALT,
EV_KEY, KEY_LINEFEED,
EV_KEY, KEY_HOME,
EV_KEY, KEY_UP,
EV_KEY, KEY_PAGEUP,
EV_KEY, KEY_LEFT,
EV_KEY, KEY_RIGHT,
EV_KEY, KEY_END,
EV_KEY, KEY_DOWN,
EV_KEY, KEY_PAGEDOWN,
EV_KEY, KEY_INSERT,
EV_KEY, KEY_DELETE,
EV_KEY, KEY_MACRO,
EV_KEY, KEY_MUTE,
EV_KEY, KEY_VOLUMEDOWN,
EV_KEY, KEY_VOLUMEUP,
EV_KEY, KEY_POWER,
EV_KEY, KEY_KPEQUAL,
EV_KEY, KEY_KPPLUSMINUS,
EV_KEY, KEY_PAUSE,
/* EV_KEY, KEY_SCALE, */
EV_KEY, KEY_KPCOMMA,
EV_KEY, KEY_HANGEUL,
EV_KEY, KEY_HANJA,
EV_KEY, KEY_YEN,
EV_KEY, KEY_LEFTMETA,
EV_KEY, KEY_RIGHTMETA,
EV_KEY, KEY_COMPOSE,
EV_KEY, KEY_STOP,
EV_KEY, KEY_MENU,
EV_KEY, KEY_CALC,
EV_KEY, KEY_SETUP,
EV_KEY, KEY_SLEEP,
EV_KEY, KEY_WAKEUP,
EV_KEY, KEY_SCREENLOCK,
EV_KEY, KEY_DIRECTION,
EV_KEY, KEY_CYCLEWINDOWS,
EV_KEY, KEY_MAIL,
EV_KEY, KEY_BOOKMARKS,
EV_KEY, KEY_COMPUTER,
EV_KEY, KEY_BACK,
EV_KEY, KEY_FORWARD,
EV_KEY, KEY_NEXTSONG,
EV_KEY, KEY_PLAYPAUSE,
EV_KEY, KEY_PREVIOUSSONG,
EV_KEY, KEY_STOPCD,
EV_KEY, KEY_HOMEPAGE,
EV_KEY, KEY_REFRESH,
EV_KEY, KEY_F14,
EV_KEY, KEY_F15,
EV_KEY, KEY_SEARCH,
EV_KEY, KEY_MEDIA,
EV_KEY, KEY_FN,
EV_LED, LED_NUML,
EV_LED, LED_CAPSL,
EV_LED, LED_SCROLLL,
/* gets disabled */
INPUT_PROP_MAX, INPUT_PROP_POINTING_STICK,
-1, -1,
};
/* clang-format on */
static const char quirk_file[] =
quirks: allow overriding of AttrEventCode and AttrInputProp This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
"[litest Quirked Keyboard enable buttons]\n"
"MatchName=litest Quirked Keyboard\n"
quirks: allow overriding of AttrEventCode and AttrInputProp This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
"AttrEventCode=+BTN_RIGHT;+BTN_MIDDLE;+EV_KEY:0x110\n" /* BTN_LEFT */
"\n"
"[litest Quirked Keyboard disable buttons]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrEventCode=-BTN_MIDDLE;-BTN_RIGHT\n"
"\n"
"[litest Quirked Keyboard re-enable buttons]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrEventCode=+BTN_RIGHT\n"
"\n"
"[litest Quirked keyboard disable F1-F3]\n"
"MatchName=litest Quirked Keyboard\n"
quirks: allow overriding of AttrEventCode and AttrInputProp This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
"AttrEventCode=-KEY_F1;-EV_KEY:0x3c;-KEY_F3\n"
"\n"
"[litest Quirked keyboard enable buttonpad]\n"
"MatchName=litest Quirked Keyboard\n"
quirks: allow overriding of AttrEventCode and AttrInputProp This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
"AttrInputProp=+INPUT_PROP_BUTTONPAD\n"
"\n"
"[litest Quirked keyboard disable pointingstick]\n"
"MatchName=litest Quirked Keyboard\n"
quirks: allow overriding of AttrEventCode and AttrInputProp This switches the quirk from AttrEventCodeEnable/Disable to just AttrEventCode with a +/- prefix for each entry. This switches the quirk from AttrInputPropEnable/Disable to just AttrInputProp with a +/- prefix for each entry. Previously, both event codes and input props would only apply the last-matching section entry for a device. Furthermore, an earlier Disable entry would take precedence over a later Enable entry. For example, a set of sections with these lines *should* enable left, right and middle: [first] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE [second] AttrEventCodeDisable=BTN_RIGHT [third] AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT; Alas: the first line was effectively ignored (quirks only returned the last-matching one, i.e. the one from "third"). And due to implementation details in evdev.c, the Disable attribute was processed after Enable, i.e. the device was enabled for left + right and then disabled for right. As a result, the device only had BTN_LEFT enabled. Fix this by changing the attribute to carry both enable/disable information and merging the commands together. Internally, all quirks matching a device are simply ref'd into an array in the struct quirks. The applied value is simply the last entry in the array corresponding to our quirk. For AttrEventCode and AttrInputProp instead do this: - switch them to a tuple with the code as first entry and a boolean enable/disable as second entry - if the struct quirk already has an entry for either, append the more recent one to the existing entry (instead of creating a new entry in the array). This way we have all entries that match and in-order of precedence - i.e. we can process them left-to-right to end up with the right state. Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
"AttrInputProp=-INPUT_PROP_POINTING_STICK\n"
"\n"
"[litest Quirked keyboard enable direct]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrInputProp=+INPUT_PROP_DIRECT\n"
"\n"
"[litest Quirked keyboard disable direct]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrInputProp=-INPUT_PROP_DIRECT\n"
"\n"
"[litest Quirked keyboard disable semi-mt]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrInputProp=-INPUT_PROP_SEMI_MT\n"
"\n"
"[litest Quirked keyboard enable semi-mt]\n"
"MatchName=litest Quirked Keyboard\n"
"AttrInputProp=+INPUT_PROP_SEMI_MT\n";
TEST_DEVICE(LITEST_KEYBOARD_QUIRKED,
.features = LITEST_KEYS |
LITEST_IGNORED, /* Only use this keyboard in specific tests */
.interface = NULL,
.name = "Quirked Keyboard",
.id = &input_id,
.events = events,
.absinfo = NULL,
.quirk_file = quirk_file, )