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

Commit cbb25162 authored by Josep del Río's avatar Josep del Río Committed by Android (Google) Code Review
Browse files

Merge "Allow touchpads to expose associated display" into main

parents 71233d8c d074638d
Loading
Loading
Loading
Loading
+32 −7
Original line number Diff line number Diff line
@@ -350,6 +350,7 @@ void TouchpadInputMapper::dump(std::string& dump) {
    dump += addLinePrefix(mPropertyProvider.dump(), INDENT4);
    dump += INDENT3 "Captured event converter:\n";
    dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4);
    dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str());
}

std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
@@ -361,13 +362,31 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
    }

    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
        std::optional<int32_t> displayId = mPointerController->getDisplayId();
        mDisplayId = ADISPLAY_ID_NONE;
        if (auto viewport = mDeviceContext.getAssociatedViewport(); viewport) {
            // This InputDevice is associated with a viewport.
            // Only generate events for the associated display.
            const bool mismatchedPointerDisplay =
                    (viewport->displayId != mPointerController->getDisplayId());
            if (mismatchedPointerDisplay) {
                ALOGW("Touchpad \"%s\" associated viewport display does not match pointer "
                      "controller",
                      mDeviceContext.getName().c_str());
            }
            mDisplayId = mismatchedPointerDisplay ? std::nullopt
                                                  : std::make_optional(viewport->displayId);
        } else {
            // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
            mDisplayId = mPointerController->getDisplayId();
        }

        ui::Rotation orientation = ui::ROTATION_0;
        if (displayId.has_value()) {
            if (auto viewport = config.getDisplayViewportById(*displayId); viewport) {
        if (mDisplayId.has_value()) {
            if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) {
                orientation = getInverseRotation(viewport->orientation);
            }
        }
        mGestureConverter.setDisplayId(mDisplayId);
        mGestureConverter.setOrientation(orientation);
    }
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::TOUCHPAD_SETTINGS)) {
@@ -497,13 +516,19 @@ void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {

std::list<NotifyArgs> TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t readTime) {
    std::list<NotifyArgs> out = {};
    if (mDisplayId) {
        MetricsAccumulator& metricsAccumulator = MetricsAccumulator::getInstance();
        for (Gesture& gesture : mGesturesToProcess) {
            out += mGestureConverter.handleGesture(when, readTime, gesture);
            metricsAccumulator.processGesture(mMetricsId, gesture);
        }
    }
    mGesturesToProcess.clear();
    return out;
}

std::optional<int32_t> TouchpadInputMapper::getAssociatedDisplayId() {
    return mDisplayId;
}

} // namespace android
+7 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ public:
    using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/,
                                         uint16_t /*productId*/, uint16_t /*version*/>;

    std::optional<int32_t> getAssociatedDisplayId() override;

private:
    void resetGestureInterpreter(nsecs_t when);
    explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
@@ -102,6 +104,11 @@ private:
    std::set<int32_t> mLastFrameTrackingIds;
    // Tracking IDs for touches that have at some point been reported as palms by the touchpad.
    std::set<int32_t> mPalmTrackingIds;

    // The display that events generated by this mapper should target. This can be set to
    // ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e.
    // std::nullopt), all events will be ignored.
    std::optional<int32_t> mDisplayId;
};

} // namespace android
+6 −1
Original line number Diff line number Diff line
@@ -124,6 +124,11 @@ void GestureConverter::populateMotionRanges(InputDeviceInfo& info) const {

std::list<NotifyArgs> GestureConverter::handleGesture(nsecs_t when, nsecs_t readTime,
                                                      const Gesture& gesture) {
    if (!mDisplayId) {
        // Ignore gestures when there is no target display configured.
        return {};
    }

    switch (gesture.type) {
        case kGestureTypeMove:
            return {handleMove(when, readTime, gesture)};
@@ -556,7 +561,7 @@ NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime
            readTime,
            mDeviceId,
            SOURCE,
            mPointerController->getDisplayId(),
            *mDisplayId,
            /* policyFlags= */ POLICY_FLAG_WAKE,
            action,
            /* actionButton= */ actionButton,
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public:
    void setOrientation(ui::Rotation orientation) { mOrientation = orientation; }
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);

    void setDisplayId(std::optional<int32_t> displayId) { mDisplayId = displayId; }

    void populateMotionRanges(InputDeviceInfo& info) const;

    [[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
@@ -84,6 +86,7 @@ private:
    InputReaderContext& mReaderContext;
    std::shared_ptr<PointerControllerInterface> mPointerController;

    std::optional<int32_t> mDisplayId;
    ui::Rotation mOrientation = ui::ROTATION_0;
    RawAbsoluteAxisInfo mXAxisInfo;
    RawAbsoluteAxisInfo mYAxisInfo;
+185 −106

File changed.

Preview size limit exceeded, changes collapsed.