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

Commit 888a6a41 authored by Garfield Tan's avatar Garfield Tan
Browse files

Let InputReader set mouse cursor's display.

InputReader was already responsible to bind device/event and display. It
makes sense to further extend it to control the display where mouse
cursor is shown.

Bug: 146385350
Test: Mouse cursor shows up at expected display.
Test: atest inputflinger_tests
Change-Id: Ie7a9546550b70c8834462b06de929472196fe713
parent c34a8a2e
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -125,6 +125,16 @@ std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByPor
    return std::nullopt;
}

std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportById(
        int32_t displayId) const {
    for (const DisplayViewport& currentViewport : mDisplays) {
        if (currentViewport.displayId == displayId) {
            return std::make_optional(currentViewport);
        }
    }
    return std::nullopt;
}

void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
    mDisplays = viewports;
}
+5 −1
Original line number Diff line number Diff line
@@ -169,6 +169,9 @@ struct InputReaderConfiguration {
    // Used to determine which DisplayViewport should be tied to which InputDevice.
    std::unordered_map<std::string, uint8_t> portAssociations;

    // The suggested display ID to show the cursor.
    int32_t defaultPointerDisplayId;

    // Velocity control parameters for mouse pointer movements.
    VelocityControlParameters pointerVelocityControlParameters;

@@ -273,6 +276,7 @@ struct InputReaderConfiguration {
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
            const;
    std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
    std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
    void setDisplayViewports(const std::vector<DisplayViewport>& viewports);


+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
#define _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H

#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <utils/BitSet.h>
#include <utils/RefBase.h>
@@ -101,6 +102,9 @@ public:

    /* Gets the id of the display where the pointer should be shown. */
    virtual int32_t getDisplayId() const = 0;

    /* Sets the associated display of this pointer. Pointer should show on that display. */
    virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
};

} // namespace android
+21 −1
Original line number Diff line number Diff line
@@ -189,12 +189,32 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*

        // Update the PointerController if viewports changed.
        if (mParameters.mode == Parameters::MODE_POINTER) {
            getPolicy()->obtainPointerController(getDeviceId());
            updatePointerControllerDisplayViewport(*config);
        }
        bumpGeneration();
    }
}

void CursorInputMapper::updatePointerControllerDisplayViewport(
        const InputReaderConfiguration& config) {
    std::optional<DisplayViewport> viewport =
            config.getDisplayViewportById(config.defaultPointerDisplayId);
    if (!viewport) {
        ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
              "mapper. Fall back to default display",
              config.defaultPointerDisplayId);
        viewport = config.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
    }

    if (!viewport) {
        ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
              " PointerController.");
        return;
    }

    mPointerController->setDisplayViewport(*viewport);
}

void CursorInputMapper::configureParameters() {
    mParameters.mode = Parameters::MODE_POINTER;
    String8 cursorModeString;
+2 −1
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ private:
    void dumpParameters(std::string& dump);

    void sync(nsecs_t when);
    void updatePointerControllerDisplayViewport(const InputReaderConfiguration& config);
};

} // namespace android
Loading