Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quirks: add support without udev #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ src_libquirks = [
'src/builddir.h',
]

deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util]
deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util, dep_libevdev]
libquirks = static_library('quirks', src_libquirks,
dependencies : deps_libquirks,
include_directories : includes_include)
Expand Down Expand Up @@ -375,6 +375,8 @@ src_libinput = src_libfilter + [
'src/evdev-tablet-pad.c',
'src/evdev-tablet-pad.h',
'src/evdev-tablet-pad-leds.c',
'src/evdev-type.c',
'src/evdev-type.h',
'src/netlink-seat.c',
'src/netlink-seat.h',
'src/path-seat.c',
Expand Down
4 changes: 4 additions & 0 deletions src/evdev-mt-touchpad-thumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,11 @@ tp_init_thumb(struct tp_dispatch *tp)
tp->thumb.lower_thumb_line = edges.y;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif

if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) {
if (quirks_get_uint32(q,
Expand Down
20 changes: 20 additions & 0 deletions src/evdev-mt-touchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -3219,7 +3219,11 @@ tp_is_tpkb_combo_below(struct evdev_device *device)
int rc = false;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q)
return false;

Expand Down Expand Up @@ -3301,7 +3305,11 @@ tp_read_palm_pressure_prop(struct tp_dispatch *tp,
struct quirks *q;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q)
return threshold;

Expand Down Expand Up @@ -3337,7 +3345,11 @@ tp_init_palmdetect_size(struct tp_dispatch *tp,
uint32_t threshold;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q)
return;

Expand Down Expand Up @@ -3531,7 +3543,11 @@ tp_init_pressure(struct tp_dispatch *tp,
assert(abs);

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) {
hi = r.upper;
lo = r.lower;
Expand Down Expand Up @@ -3587,7 +3603,11 @@ tp_init_touch_size(struct tp_dispatch *tp,
}

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q && quirks_get_range(q, QUIRK_ATTR_TOUCH_SIZE_RANGE, &r)) {
hi = r.upper;
lo = r.lower;
Expand Down
8 changes: 8 additions & 0 deletions src/evdev-tablet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,11 @@ tool_set_pressure_thresholds(struct tablet_dispatch *tablet,
goto out;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif

tool->pressure.offset = pressure->minimum;

Expand Down Expand Up @@ -2400,7 +2404,11 @@ tablet_init_smoothing(struct evdev_device *device,
bool use_smoothing = true;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif

/* By default, always enable smoothing except on AES devices.
* AttrTabletSmoothing can override this, if necessary.
Expand Down
80 changes: 80 additions & 0 deletions src/evdev-type.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <stdint.h>
#include <libevdev/libevdev.h>

#include "evdev-type.h"
#include "linux/input.h"

uint32_t get_input_type(struct libevdev *evdev)
{
uint32_t type = 0;
unsigned long bit;

if (libevdev_has_property(evdev, INPUT_PROP_POINTING_STICK)) {
type |= EVDEV_TYPE_POINTING_STICK;
}

if (libevdev_has_property(evdev, INPUT_PROP_ACCELEROMETER)) {
type |= EVDEV_TYPE_ACCELEROMETER;
}

if (libevdev_has_event_type(evdev, EV_SW)) {
type |= EVDEV_TYPE_SWITCH;
}

if (libevdev_has_event_type(evdev, EV_REL)) {
if (libevdev_has_event_code(evdev, EV_REL, REL_Y) &&
libevdev_has_event_code(evdev, EV_REL, REL_X) &&
libevdev_has_event_code(evdev, EV_KEY, BTN_MOUSE)) {
type |= EVDEV_TYPE_MOUSE;
}
}
else if (libevdev_has_event_type(evdev, EV_ABS)) {
if (libevdev_has_event_code(evdev, EV_KEY, BTN_SELECT) ||
libevdev_has_event_code(evdev, EV_KEY, BTN_TR) ||
libevdev_has_event_code(evdev, EV_KEY, BTN_START) ||
libevdev_has_event_code(evdev, EV_KEY, BTN_TL)) {
if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH)) {
type |= EVDEV_TYPE_TOUCHSCREEN;
}
else {
type |= EVDEV_TYPE_JOYSTICK;
}
}
else if (libevdev_has_event_code(evdev, EV_ABS, ABS_Y) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_X)) {
if (libevdev_has_event_code(evdev, EV_ABS, ABS_Z) &&
!libevdev_has_event_type(evdev, EV_KEY)) {
type |= EVDEV_TYPE_ACCELEROMETER;
}
else if (libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS) ||
libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN)) {
type |= EVDEV_TYPE_TABLET;
}
else if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH)) {
if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER)) {
type |= EVDEV_TYPE_TOUCHPAD;
}
else {
type |= EVDEV_TYPE_TOUCHSCREEN;
}
}
else if (libevdev_has_event_code(evdev, EV_KEY, BTN_MOUSE)) {
type |= EVDEV_TYPE_MOUSE;
}
}
}

for (bit = KEY_ESC; bit < BTN_MISC; bit++) {
if (libevdev_has_event_code(evdev, EV_KEY, bit)) {
type |= EVDEV_TYPE_KEY;

if (libevdev_has_event_code(evdev, EV_KEY, KEY_ENTER)) {
type |= EVDEV_TYPE_KEYBOARD;
}

break;
}
}

return type ? type : EVDEV_TYPE_UNKNOWN;
}
18 changes: 18 additions & 0 deletions src/evdev-type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdint.h>
#include <libevdev/libevdev.h>

enum {
EVDEV_TYPE_UNKNOWN = 1 << 0,
EVDEV_TYPE_MOUSE = 1 << 1,
EVDEV_TYPE_TABLET = 1 << 2,
EVDEV_TYPE_TOUCHPAD = 1 << 3,
EVDEV_TYPE_KEYBOARD = 1 << 4,
EVDEV_TYPE_JOYSTICK = 1 << 5,
EVDEV_TYPE_TOUCHSCREEN = 1 << 6,
EVDEV_TYPE_SWITCH = 1 << 7,
EVDEV_TYPE_ACCELEROMETER = 1 << 8,
EVDEV_TYPE_POINTING_STICK = 1 << 9,
EVDEV_TYPE_KEY = 1 << 10,
};

uint32_t get_input_type(struct libevdev *evdev);
80 changes: 60 additions & 20 deletions src/evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "libinput-private.h"
#include "quirks.h"
#include "util-input-event.h"
#include "evdev-type.h"

#if HAVE_LIBWACOM
#include <libwacom/libwacom.h>
Expand Down Expand Up @@ -98,6 +99,24 @@ static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = {
{"ID_INPUT_TRACKBALL", EVDEV_UDEV_TAG_TRACKBALL},
{"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH},
};
#else
static const struct {
uint32_t name;
enum evdev_device_udev_tags tag;
} evdev_udev_tag_matches[] = {
{EVDEV_TYPE_KEYBOARD, EVDEV_UDEV_TAG_KEYBOARD},
{EVDEV_TYPE_KEY, EVDEV_UDEV_TAG_KEYBOARD},
{EVDEV_TYPE_MOUSE, EVDEV_UDEV_TAG_MOUSE},
{EVDEV_TYPE_TOUCHPAD, EVDEV_UDEV_TAG_TOUCHPAD},
{EVDEV_TYPE_TOUCHSCREEN, EVDEV_UDEV_TAG_TOUCHSCREEN},
{EVDEV_TYPE_TABLET, EVDEV_UDEV_TAG_TABLET},
// {EVDEV_TYPE_TABLET_PAD, EVDEV_UDEV_TAG_TABLET_PAD},
{EVDEV_TYPE_JOYSTICK, EVDEV_UDEV_TAG_JOYSTICK},
{EVDEV_TYPE_ACCELEROMETER, EVDEV_UDEV_TAG_ACCELEROMETER},
{EVDEV_TYPE_POINTING_STICK, EVDEV_UDEV_TAG_POINTINGSTICK},
// {EVDEV_TYPE_TRACKBALL, EVDEV_UDEV_TAG_TRACKBALL},
{EVDEV_TYPE_SWITCH, EVDEV_UDEV_TAG_SWITCH},
};
#endif

static inline bool
Expand Down Expand Up @@ -510,7 +529,11 @@ evdev_tag_trackpoint(struct evdev_device *device,
device->tags |= EVDEV_TAG_TRACKPOINT;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q && quirks_get_string(q, QUIRK_ATTR_TRACKPOINT_INTEGRATION, &prop)) {
if (streq(prop, "internal")) {
/* noop, this is the default anyway */
Expand Down Expand Up @@ -562,7 +585,11 @@ evdev_tag_keyboard(struct evdev_device *device,
}

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q && quirks_get_string(q, QUIRK_ATTR_KEYBOARD_INTEGRATION, &prop)) {
if (streq(prop, "internal")) {
evdev_tag_keyboard_internal(device);
Expand Down Expand Up @@ -994,7 +1021,11 @@ evdev_read_switch_reliability_prop(struct evdev_device *device)
char *prop;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q || !quirks_get_string(q, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) {
r = RELIABILITY_UNKNOWN;
} else if (!parse_switch_reliability_property(prop, &r)) {
Expand Down Expand Up @@ -1408,7 +1439,11 @@ evdev_get_trackpoint_multiplier(struct evdev_device *device)
return 1.0;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q) {
quirks_get_double(q, QUIRK_ATTR_TRACKPOINT_MULTIPLIER, &multiplier);
quirks_unref(q);
Expand Down Expand Up @@ -1437,7 +1472,11 @@ evdev_need_velocity_averaging(struct evdev_device *device)
bool use_velocity_averaging = false; /* default off unless we have quirk */

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (q) {
quirks_get_bool(q,
QUIRK_ATTR_USE_VELOCITY_AVERAGING,
Expand Down Expand Up @@ -1509,7 +1548,11 @@ evdev_read_model_flags(struct evdev_device *device)
struct quirks *q;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif

while (q && m->quirk) {
bool is_set;
Expand Down Expand Up @@ -1576,7 +1619,11 @@ evdev_read_attr_res_prop(struct evdev_device *device,
bool rc = false;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q)
return false;

Expand All @@ -1602,7 +1649,11 @@ evdev_read_attr_size_prop(struct evdev_device *device,
bool rc = false;

quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q)
return false;

Expand Down Expand Up @@ -1688,26 +1739,11 @@ evdev_device_get_udev_tags(struct evdev_device *device,
return 0;
if (major(st.st_rdev) == INPUT_MAJOR)
tags |= EVDEV_UDEV_TAG_INPUT;
if (libevdev_has_event_code(evdev, EV_KEY, KEY_ENTER) ||
libevdev_has_event_code(evdev, EV_KEY, KEY_VOLUMEUP) ||
libevdev_has_event_code(evdev, EV_KEY, KEY_POWER))
tags |= EVDEV_UDEV_TAG_KEYBOARD;
if (libevdev_has_event_code(evdev, EV_REL, REL_X) &&
libevdev_has_event_code(evdev, EV_REL, REL_Y) &&
libevdev_has_event_code(evdev, EV_KEY, BTN_MOUSE))
tags |= EVDEV_UDEV_TAG_MOUSE;
if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_Y)) {
if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER) &&
!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
!libevdev_has_property(evdev, INPUT_PROP_DIRECT)) {
tags |= EVDEV_UDEV_TAG_TOUCHPAD;
} else if (libevdev_has_event_code(evdev, EV_KEY, BTN_MOUSE)) {
tags |= EVDEV_UDEV_TAG_MOUSE;
} else if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH) ||
libevdev_has_property(evdev, INPUT_PROP_DIRECT)) {
tags |= EVDEV_UDEV_TAG_TOUCHSCREEN;
}

uint32_t evdev_type = get_input_type(evdev);
for (size_t i = 0; i < ARRAY_LENGTH(evdev_udev_tag_matches); i++) {
if (evdev_type & evdev_udev_tag_matches[i].name)
tags |= evdev_udev_tag_matches[i].tag;
}
#endif

Expand Down Expand Up @@ -2199,7 +2235,11 @@ evdev_pre_configure_model_quirks(struct evdev_device *device)
* unnecessary wakeups but on some devices we need to watch it for
* pointer jumps */
quirks = evdev_libinput_context(device)->quirks;
#if HAVE_UDEV
q = quirks_fetch_for_device(quirks, device->udev_device);
#else
q = quirks_fetch_for_evdev(quirks, device->evdev);
#endif
if (!q ||
!quirks_get_string(q, QUIRK_ATTR_MSC_TIMESTAMP, &prop) ||
!streq(prop, "watch")) {
Expand Down
Loading