From 635422be3e0e02b7221633b2eb1b112fc18bb65e Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 2 Dec 2022 00:43:56 +0000 Subject: Convert MotionEvent#getSurfaceRotation to ui::Rotation Because it might have an invalid rotation it needs to return std::optional, but at least we're using the types effectively here. Test: compiles Change-Id: I27076edcc6ce33594552863caa8ee643027a81e7 --- libs/input/Input.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 162b757743..9e8ebf30c5 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -552,21 +553,21 @@ void MotionEvent::addSample( &pointerCoords[getPointerCount()]); } -int32_t MotionEvent::getSurfaceRotation() const { +std::optional MotionEvent::getSurfaceRotation() const { // The surface rotation is the rotation from the window's coordinate space to that of the // display. Since the event's transform takes display space coordinates to window space, the // returned surface rotation is the inverse of the rotation for the surface. switch (mTransform.getOrientation()) { case ui::Transform::ROT_0: - return static_cast(ui::ROTATION_0); + return ui::ROTATION_0; case ui::Transform::ROT_90: - return static_cast(ui::ROTATION_270); + return ui::ROTATION_270; case ui::Transform::ROT_180: - return static_cast(ui::ROTATION_180); + return ui::ROTATION_180; case ui::Transform::ROT_270: - return static_cast(ui::ROTATION_90); + return ui::ROTATION_90; default: - return -1; + return std::nullopt; } } -- cgit v1.2.3-59-g8ed1b