Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80fd47ce authored by Jeff Brown's avatar Jeff Brown
Browse files

Input device protocol enhancements.

Added support for Linux multitouch protocol B (slots).

Added support for using the device's input properties as a hint
to determine the intended usage of a touch device.

Added support for the ABS_MT_DISTANCE axis.

Fixed a bug reporting the presence of the orientation axis.

Change-Id: Icf7b5a5a0f1a9cdf6ad2b35be8ea0c1a35815d48
parent ebed7d6e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -883,8 +883,8 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     * <p>
     * <ul>
     * <li>For a stylus, reports the distance of the stylus from the screen.
     * The value is normalized to a range from 0.0 (direct contact) to 1.0 (furthest measurable
     * distance).
     * The value is nominally measured in millimeters where 0.0 indicates direct contact
     * and larger values indicate increasing distance from the surface.
     * </ul>
     * </p>
     *
+1 −0
Original line number Diff line number Diff line
@@ -385,6 +385,7 @@ public class PointerLocationView extends View {
                .append(" ToolMinor=").append(coords.toolMinor, 3)
                .append(" Orientation=").append((float)(coords.orientation * 180 / Math.PI), 1)
                .append("deg")
                .append(" Distance=").append(coords.getAxisValue(MotionEvent.AXIS_DISTANCE), 1)
                .append(" VScroll=").append(coords.getAxisValue(MotionEvent.AXIS_VSCROLL), 1)
                .append(" HScroll=").append(coords.getAxisValue(MotionEvent.AXIS_HSCROLL), 1)
                .append(" ToolType=").append(MotionEvent.toolTypeToString(toolType))
+26 −13
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ EventHub::Device::Device(int fd, int32_t id, const String8& path,
        const InputDeviceIdentifier& identifier) :
        next(NULL),
        fd(fd), id(id), path(path), identifier(identifier),
        classes(0), keyBitmask(NULL), relBitmask(NULL),
        classes(0), keyBitmask(NULL), relBitmask(NULL), propBitmask(NULL),
        configuration(NULL), virtualKeyMap(NULL) {
}

@@ -109,6 +109,7 @@ EventHub::Device::~Device() {
    close();
    delete[] keyBitmask;
    delete[] relBitmask;
    delete[] propBitmask;
    delete configuration;
    delete virtualKeyMap;
}
@@ -205,6 +206,18 @@ bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const {
    return false;
}

bool EventHub::hasInputProperty(int32_t deviceId, int property) const {
    if (property >= 0 && property <= INPUT_PROP_MAX) {
        AutoMutex _l(mLock);

        Device* device = getDeviceLocked(deviceId);
        if (device && device->propBitmask) {
            return test_bit(property, device->propBitmask);
        }
    }
    return false;
}

int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
    if (scanCode >= 0 && scanCode <= KEY_MAX) {
        AutoMutex _l(mLock);
@@ -834,23 +847,23 @@ int EventHub::openDevice(const char *devicePath) {
    memset(sw_bitmask, 0, sizeof(sw_bitmask));
    ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask);

    uint8_t prop_bitmask[sizeof_bit_array(INPUT_PROP_MAX + 1)];
    memset(prop_bitmask, 0, sizeof(prop_bitmask));
    ioctl(fd, EVIOCGPROP(sizeof(prop_bitmask)), prop_bitmask);

    device->keyBitmask = new uint8_t[sizeof(key_bitmask)];
    if (device->keyBitmask != NULL) {
        memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
    } else {
    device->relBitmask = new uint8_t[sizeof(rel_bitmask)];
    device->propBitmask = new uint8_t[sizeof(prop_bitmask)];

    if (!device->keyBitmask || !device->relBitmask || !device->propBitmask) {
        delete device;
        LOGE("out of memory allocating key bitmask");
        LOGE("out of memory allocating bitmasks");
        return -1;
    }

    device->relBitmask = new uint8_t[sizeof(rel_bitmask)];
    if (device->relBitmask != NULL) {
    memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
    memcpy(device->relBitmask, rel_bitmask, sizeof(rel_bitmask));
    } else {
        delete device;
        LOGE("out of memory allocating rel bitmask");
        return -1;
    }
    memcpy(device->propBitmask, prop_bitmask, sizeof(prop_bitmask));

    // See if this is a keyboard.  Ignore everything in the button range except for
    // joystick and gamepad buttons which are handled like keyboards for the most part.
+35 −17
Original line number Diff line number Diff line
@@ -34,25 +34,38 @@

#include <linux/input.h>

/* These constants are not defined in linux/input.h but they are part of the multitouch
 * input protocol. */

#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 ellipse position */
#define ABS_MT_POSITION_Y 0x36   /* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE 0x37    /* Type of touching device (finger, pen, ...) */
#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 MT_TOOL_FINGER 0 /* Identifies a finger */
#define MT_TOOL_PEN 1    /* Identifies a pen */
/* These constants are not defined in linux/input.h in the version of the kernel
 * headers currently provided with Bionic. */

#define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len)

#define INPUT_PROP_POINTER 0x00
#define INPUT_PROP_DIRECT 0x01
#define INPUT_PROP_BUTTONPAD 0x02
#define INPUT_PROP_SEMI_MT 0x03
#define INPUT_PROP_MAX 0x1f
#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)

#define ABS_MT_SLOT 0x2f
#define ABS_MT_TOUCH_MAJOR 0x30
#define ABS_MT_TOUCH_MINOR 0x31
#define ABS_MT_WIDTH_MAJOR 0x32
#define ABS_MT_WIDTH_MINOR 0x33
#define ABS_MT_ORIENTATION 0x34
#define ABS_MT_POSITION_X 0x35
#define ABS_MT_POSITION_Y 0x36
#define ABS_MT_TOOL_TYPE 0x37
#define ABS_MT_BLOB_ID 0x38
#define ABS_MT_TRACKING_ID 0x39
#define ABS_MT_PRESSURE 0x3a
#define ABS_MT_DISTANCE 0x3b

#define MT_TOOL_FINGER 0
#define MT_TOOL_PEN 1

#define SYN_MT_REPORT 2
#define SYN_DROPPED 3


/* Convenience constants. */

@@ -172,6 +185,8 @@ public:

    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;

    virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;

    virtual status_t mapKey(int32_t deviceId, int scancode,
            int32_t* outKeycode, uint32_t* outFlags) const = 0;

@@ -236,6 +251,8 @@ public:

    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;

    virtual bool hasInputProperty(int32_t deviceId, int property) const;

    virtual status_t mapKey(int32_t deviceId, int scancode,
            int32_t* outKeycode, uint32_t* outFlags) const;

@@ -286,6 +303,7 @@ private:
        uint32_t classes;
        uint8_t* keyBitmask;
        uint8_t* relBitmask;
        uint8_t* propBitmask;
        String8 configurationFile;
        PropertyMap* configuration;
        VirtualKeyMap* virtualKeyMap;
+269 −89

File changed.

Preview size limit exceeded, changes collapsed.

Loading