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

Commit a62a8dd1 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Move displayid into InputEvent

There are certain use cases where key events should be associated with a
particular display. Refactor KeyEvent and MotionEvent to have an
associated display id.

Remove "hasAssociatedDisplay" variable from KeyboardInputMapper,
it just used to mirror "isOrientationAware".

If the keyboard is orientation aware (= it is physically attached to a
display, and therefore rotates together with that display), then
associate that keyboard with the internal viewport. Otherwise, the key
events are not associated with any particular display.

Remaining to do:
- make mInternalDisplay, mExternalDisplay, mVirtualDisplays into a
single vector with type (internal, external, virtual)
- have getDisplayViewport return std::optional (will require deep
changes)

Bug: 64258305
Test: atest inputflinger_tests libinput_tests

Change-Id: I4fe145e74cb59310efaa55bfc9dc3c2b3bd997e3
parent 62ce5753
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -302,12 +302,18 @@ public:

    inline void setSource(int32_t source) { mSource = source; }

    inline int32_t getDisplayId() const { return mDisplayId; }

    inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }


protected:
    void initialize(int32_t deviceId, int32_t source);
    void initialize(int32_t deviceId, int32_t source, int32_t displayId);
    void initialize(const InputEvent& from);

    int32_t mDeviceId;
    int32_t mSource;
    int32_t mDisplayId;
};

/*
@@ -343,6 +349,7 @@ public:
    void initialize(
            int32_t deviceId,
            int32_t source,
            int32_t displayId,
            int32_t action,
            int32_t flags,
            int32_t keyCode,
@@ -373,10 +380,6 @@ public:

    virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }

    inline int32_t getDisplayId() const { return mDisplayId; }

    inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }

    inline int32_t getAction() const { return mAction; }

    inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
@@ -614,7 +617,6 @@ public:
    static int32_t getAxisFromLabel(const char* label);

protected:
    int32_t mDisplayId;
    int32_t mAction;
    int32_t mActionButton;
    int32_t mFlags;
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ struct InputMessage {
            nsecs_t eventTime __attribute__((aligned(8)));
            int32_t deviceId;
            int32_t source;
            int32_t displayId;
            int32_t action;
            int32_t flags;
            int32_t keyCode;
@@ -211,6 +212,7 @@ public:
            uint32_t seq,
            int32_t deviceId,
            int32_t source,
            int32_t displayId,
            int32_t action,
            int32_t flags,
            int32_t keyCode,
+7 −6
Original line number Diff line number Diff line
@@ -31,14 +31,16 @@ namespace android {

// --- InputEvent ---

void InputEvent::initialize(int32_t deviceId, int32_t source) {
void InputEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId) {
    mDeviceId = deviceId;
    mSource = source;
    mDisplayId = displayId;
}

void InputEvent::initialize(const InputEvent& from) {
    mDeviceId = from.mDeviceId;
    mSource = from.mSource;
    mDisplayId = from.mDisplayId;
}

// --- KeyEvent ---
@@ -54,6 +56,7 @@ int32_t KeyEvent::getKeyCodeFromLabel(const char* label) {
void KeyEvent::initialize(
        int32_t deviceId,
        int32_t source,
        int32_t displayId,
        int32_t action,
        int32_t flags,
        int32_t keyCode,
@@ -62,7 +65,7 @@ void KeyEvent::initialize(
        int32_t repeatCount,
        nsecs_t downTime,
        nsecs_t eventTime) {
    InputEvent::initialize(deviceId, source);
    InputEvent::initialize(deviceId, source, displayId);
    mAction = action;
    mFlags = flags;
    mKeyCode = keyCode;
@@ -231,8 +234,7 @@ void MotionEvent::initialize(
        size_t pointerCount,
        const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords) {
    InputEvent::initialize(deviceId, source);
    mDisplayId = displayId;
    InputEvent::initialize(deviceId, source, displayId);
    mAction = action;
    mActionButton = actionButton;
    mFlags = flags;
@@ -252,8 +254,7 @@ void MotionEvent::initialize(
}

void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
    InputEvent::initialize(other->mDeviceId, other->mSource);
    mDisplayId = other->mDisplayId;
    InputEvent::initialize(other->mDeviceId, other->mSource, other->mDisplayId);
    mAction = other->mAction;
    mActionButton = other->mActionButton;
    mFlags = other->mFlags;
+3 −0
Original line number Diff line number Diff line
@@ -243,6 +243,7 @@ status_t InputPublisher::publishKeyEvent(
        uint32_t seq,
        int32_t deviceId,
        int32_t source,
        int32_t displayId,
        int32_t action,
        int32_t flags,
        int32_t keyCode,
@@ -270,6 +271,7 @@ status_t InputPublisher::publishKeyEvent(
    msg.body.key.seq = seq;
    msg.body.key.deviceId = deviceId;
    msg.body.key.source = source;
    msg.body.key.displayId = displayId;
    msg.body.key.action = action;
    msg.body.key.flags = flags;
    msg.body.key.keyCode = keyCode;
@@ -926,6 +928,7 @@ void InputConsumer::initializeKeyEvent(KeyEvent* event, const InputMessage* msg)
    event->initialize(
            msg->body.key.deviceId,
            msg->body.key.source,
            msg->body.key.displayId,
            msg->body.key.action,
            msg->body.key.flags,
            msg->body.key.keyCode,
+1 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ void KeyCharacterMap::addKey(Vector<KeyEvent>& outEvents,
        int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time) {
    outEvents.push();
    KeyEvent& event = outEvents.editTop();
    event.initialize(deviceId, AINPUT_SOURCE_KEYBOARD,
    event.initialize(deviceId, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE,
            down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
            0, keyCode, 0, metaState, 0, time, time);
}
Loading