diff --git a/service/message_handle/src/server_msg_handler.cpp b/service/message_handle/src/server_msg_handler.cpp index 95f9afe5bbbea163060b02c154c83e9d1160fdc4..b6c1dced73633ca475c4a570dba7421a5d4a7f65 100644 --- a/service/message_handle/src/server_msg_handler.cpp +++ b/service/message_handle/src/server_msg_handler.cpp @@ -267,10 +267,13 @@ int32_t ServerMsgHandler::OnInjectPointerEventExt(const std::shared_ptr pointerEvent) { + bool downEvent = (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_DOWN) && + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_UP) && + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_UP); if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) || ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE) && - (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE))) { + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) && downEvent)) { return RET_OK; } PointerEvent::PointerItem pointerItem {}; @@ -289,8 +292,14 @@ int32_t ServerMsgHandler::AccelerateMotion(std::shared_ptr pointer }; auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); CHKPR(displayInfo, ERROR_NULL_POINTER); + if (downEvent) { + if (cursorPos.direction != displayInfo->direction) { + WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, offset.dx, offset.dy); + return RET_OK; + } + } #ifndef OHOS_BUILD_EMULATOR - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (TOUCH_DRAWING_MGR->IsWindowRotation()) { CalculateOffset(displayInfo->direction, offset); } #endif // OHOS_BUILD_EMULATOR diff --git a/service/mouse_event_normalize/include/mouse_transform_processor.h b/service/mouse_event_normalize/include/mouse_transform_processor.h index 8743d4d421bdf3aadb66825d20df6bb27bfad207..93202580bd7efbd2c82215796aa419302022f19e 100644 --- a/service/mouse_event_normalize/include/mouse_transform_processor.h +++ b/service/mouse_event_normalize/include/mouse_transform_processor.h @@ -98,6 +98,7 @@ private: void TransTouchpadRightButton(struct libinput_event_pointer* data, const int32_t type, uint32_t &button); void CalculateOffset(Direction direction, Offset &offset); double HandleAxisAccelateTouchPad(double axisValue); + bool IsWindowRotation(const DisplayInfo* displayInfo); #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING void HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY); void HandlePostMoveMouse(PointerEvent::PointerItem &pointerItem); diff --git a/service/mouse_event_normalize/src/mouse_transform_processor.cpp b/service/mouse_event_normalize/src/mouse_transform_processor.cpp index 2232263a10e740e78753bf742918b0b96d3a9fc6..3e32ee1e102335856663d9c6023776f17ac85cd1 100644 --- a/service/mouse_event_normalize/src/mouse_transform_processor.cpp +++ b/service/mouse_event_normalize/src/mouse_transform_processor.cpp @@ -68,7 +68,10 @@ const std::string DEVICE_TYPE_HARDEN { "HAD" }; const std::string PRODUCT_TYPE = OHOS::system::GetParameter("const.build.product", "HYM"); const std::string MOUSE_FILE_NAME { "mouse_settings.xml" }; const int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotate_policy", 0); +const std::string FOLDABLE_DEVICE_POLICY = system::GetParameter("const.window.foldabledevice.rotate_policy", ""); constexpr int32_t WINDOW_ROTATE { 0 }; +constexpr char ROTATE_WINDOW_ROTATE { '0' }; +constexpr int32_t FOLDABLE_DEVICE { 2 }; constexpr int32_t WAIT_TIME_FOR_BUTTON_UP { 15 }; } // namespace @@ -105,7 +108,7 @@ int32_t MouseTransformProcessor::HandleMotionInner(struct libinput_event_pointer auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); CHKPR(displayInfo, ERROR_NULL_POINTER); #ifndef OHOS_BUILD_EMULATOR - if (ROTATE_POLICY == WINDOW_ROTATE && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (IsWindowRotation(displayInfo) && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { CalculateOffset(displayInfo->direction, offset); } #endif // OHOS_BUILD_EMULATOR @@ -136,6 +139,18 @@ int32_t MouseTransformProcessor::HandleMotionInner(struct libinput_event_pointer return RET_OK; } +bool MouseTransformProcessor::IsWindowRotation() +{ + MMI_HILOGD("ROTATE_POLICY: %{public}d, FOLDABLE_DEVICE_POLICY:%{public}s", + ROTATE_POLICY, FOLDABLE_DEVICE_POLICY.c_str()); + return (ROTATE_POLICY == WINDOW_ROTATE || + (ROTATE_POLICY == FOLDABLE_DEVICE && + ((displayInfo_.displayMode == DisplayMode::MAIN && + FOLDABLE_DEVICE_POLICY[0] == ROTATE_WINDOW_ROTATE) || + (displayInfo_.displayMode == DisplayMode::FULL && + FOLDABLE_DEVICE_POLICY[FOLDABLE_DEVICE] == ROTATE_WINDOW_ROTATE)))); +} + void MouseTransformProcessor::CalculateOffset(Direction direction, Offset &offset) { std::negate neg; @@ -211,6 +226,16 @@ int32_t MouseTransformProcessor::HandleButtonInner(struct libinput_event_pointer buttonMapping_[originButton] = buttonId; isPressed_ = true; buttonId_ = pointerEvent_->GetButtonId(); + CursorPosition cursorPos = WIN_MGR->GetCursorPos(); + if (cursorPos.displayId < 0) { + MMI_HILOGE("No display"); + return RET_ERR; + } + auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); + CHKPR(displayInfo, ERROR_NULL_POINTER); + if (cursorPos.direction != displayInfo->direction) { + WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); + } } else { MMI_HILOGE("Unknown state, state:%{public}u", state); return RET_ERR; diff --git a/service/window_manager/include/i_input_windows_manager.h b/service/window_manager/include/i_input_windows_manager.h index 3cf013bfe4f278e1f620bae20b2e655e865afc06..3e612270a9ac41d0a18973b69b7fb0614274318a 100644 --- a/service/window_manager/include/i_input_windows_manager.h +++ b/service/window_manager/include/i_input_windows_manager.h @@ -46,6 +46,7 @@ struct Coordinate2D { struct CursorPosition { int32_t displayId { -1 }; + Direction direction { Direction::DIRECTION0 }; Coordinate2D cursorPos {}; }; diff --git a/service/window_manager/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index ec35002c683c7680e2a683dc0035b232d63a4a09..931206f624644bcb44b84b0b61f976e97b9bba70 100644 --- a/service/window_manager/include/i_pointer_drawing_manager.h +++ b/service/window_manager/include/i_pointer_drawing_manager.h @@ -73,7 +73,7 @@ public: { return 0; } - virtual void DrawPointerStyle(const PointerStyle& pointerStyle) {} + virtual void DrawPointerStyle(const PointerStyle& pointerStyle, bool simulate = false) {} virtual bool IsPointerVisible() { return false; diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index d78e59fd15604c5341902bcc8ad46913535bf949..b4aa5092036e5eff60c8f32f6403779cc7326fe5 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -213,6 +213,7 @@ private: bool SelectPointerChangeArea(const WindowInfo &windowInfo, PointerStyle &pointerStyle, int32_t logicalX, int32_t logicalY); void UpdatePointerChangeAreas(const DisplayGroupInfo &displayGroupInfo); + void AdjustDisplayRotation(); #endif // OHOS_BUILD_ENABLE_POINTER #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) diff --git a/service/window_manager/include/pointer_drawing_manager.h b/service/window_manager/include/pointer_drawing_manager.h index 98acc1be4aae11cd26c4d6e870fe53d6266aac78..961d986545e0433e87a37488b0d1122d31c081c3 100644 --- a/service/window_manager/include/pointer_drawing_manager.h +++ b/service/window_manager/include/pointer_drawing_manager.h @@ -82,7 +82,7 @@ public: bool isUiExtension = false) override; int32_t SetPointerSize(int32_t size) override; int32_t GetPointerSize() override; - void DrawPointerStyle(const PointerStyle& pointerStyle) override; + void DrawPointerStyle(const PointerStyle& pointerStyle, bool simulate = false) override; bool IsPointerVisible() override; void SetPointerLocation(int32_t x, int32_t y) override; void AdjustMouseFocus(Direction direction, ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY); @@ -186,6 +186,7 @@ private: isMagicCursor hasMagicCursor_; bool hasInitObserver_ { false }; bool isInit_ { false }; + bool simulate_ { false }; #ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR std::shared_ptr hardwareCursorPointerManager_ { nullptr }; #endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR diff --git a/service/window_manager/include/touch_drawing_manager.h b/service/window_manager/include/touch_drawing_manager.h index e868d3026e457d81fffa878831d19225aa76255e..74ae0a79a6d7c987450830075cb8c11e86309d83 100644 --- a/service/window_manager/include/touch_drawing_manager.h +++ b/service/window_manager/include/touch_drawing_manager.h @@ -65,6 +65,7 @@ public: int32_t UpdateBubbleData(); void RotationScreen(); void Dump(int32_t fd, const std::vector &args); + bool IsWindowRotation(); void SetDelegateProxy(std::shared_ptr proxy) { delegateProxy_ = proxy; @@ -99,7 +100,6 @@ private: std::string FormatNumber(T number, int32_t precision); bool IsValidAction(const int32_t action); void Snapshot(); - bool IsWindowRotation(); private: std::shared_ptr surfaceNode_ { nullptr }; std::shared_ptr bubbleCanvasNode_ { nullptr }; diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index fff9cee47ca30bf319250dc35140b7f3aff55c13..40fc39e7669c62dc46803cb0fb167e543ac7f580 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -345,7 +345,7 @@ void InputWindowsManager::FoldScreenRotation(std::shared_ptr point auto displayId = pointerEvent->GetTargetDisplayId(); auto physicDisplayInfo = GetPhysicalDisplay(displayId); CHKPV(physicDisplayInfo); - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (TOUCH_DRAWING_MGR->IsWindowRotation()) { MMI_HILOG_DISPATCHD("Not in the unfolded state of the folding screen"); return; } @@ -800,6 +800,7 @@ void InputWindowsManager::UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo) #endif // OHOS_BUILD_ENABLE_POINTER #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) if (!displayGroupInfo.displaysInfo.empty() && pointerDrawFlag_) { + AdjustDisplayRotation(); PointerDrawingManagerOnDisplayInfo(displayGroupInfo); } #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER @@ -811,6 +812,27 @@ void InputWindowsManager::UpdateDisplayInfo(DisplayGroupInfo &displayGroupInfo) #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING } +void InputWindowsManager::AdjustDisplayRotation() +{ + if (!TOUCH_DRAWING_MGR->IsWindowRotation()) { + PhysicalCoordinate coord { + .x = cursorPos_.cursorpos.x, + .y = cursorPos_.cursorpos.y, + }; + auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); + CHKPR(displayInfo, ERROR_NULL_POINTER); + if (cursorPos.direction != displayInfo->direction) { + RotateScreen(*displayInfo, coord); + cursorPos.direction = displayInfo->direction; + UpdateAndAdjustMouseLocation(cursorPos.displayId, coord.x, coord.y); + IPointerDrawingManager::GetInstance()->UpdateDisplayInfo(*displayInfo); + IPointerDrawingManager::GetInstance()->SetPointerLocation( + static_cast(coord.x), static_cast(coord.y)); + } + } +} + + DisplayMode InputWindowsManager::GetDisplayMode() const { return displayMode_; @@ -843,7 +865,10 @@ void InputWindowsManager::UpdateDisplayMode() void InputWindowsManager::PointerDrawingManagerOnDisplayInfo(const DisplayGroupInfo &displayGroupInfo) { IPointerDrawingManager::GetInstance()->OnDisplayInfo(displayGroupInfo); - if (INPUT_DEV_MGR->HasPointerDevice()) { + CHKPV(lastPointerEvent_); + bool simulate = (lastPointerEvent_->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE && + lastPointerEvent_->HasFlag(InputEvent::EVENT_FLAG_SIMULATE)); + if (INPUT_DEV_MGR->HasPointerDevice() || simulate) { MouseLocation mouseLocation = GetMouseInfo(); int32_t displayId = MouseEventHdr->GetDisplayId(); displayId = displayId < 0 ? displayGroupInfo_.displaysInfo[0].id : displayId; @@ -852,7 +877,6 @@ void InputWindowsManager::PointerDrawingManagerOnDisplayInfo(const DisplayGroupI int32_t logicX = mouseLocation.physicalX + displayInfo->x; int32_t logicY = mouseLocation.physicalY + displayInfo->y; std::optional windowInfo; - CHKPV(lastPointerEvent_); if (lastPointerEvent_->GetPointerAction() != PointerEvent::POINTER_ACTION_DOWN && lastPointerEvent_->GetPressedButtons().empty()) { windowInfo = GetWindowInfo(logicX, logicY); @@ -882,7 +906,7 @@ void InputWindowsManager::PointerDrawingManagerOnDisplayInfo(const DisplayGroupI dragFlag_ = false; isDragBorder_ = false; } - IPointerDrawingManager::GetInstance()->DrawPointerStyle(dragPointerStyle_); + IPointerDrawingManager::GetInstance()->DrawPointerStyle(dragPointerStyle_, simulate); } } @@ -1265,6 +1289,17 @@ void InputWindowsManager::RotateScreen(const DisplayInfo& info, PhysicalCoordina { const Direction direction = info.direction; if (direction == DIRECTION0) { + if (!TOUCH_DRAWING_MGR->IsWindowRotation() && cursorPos.direction != displayInfo->direction) { + if (cursorPos.direction == Direction::DIRECTION90) { + double temp = coord.y; + coord.y = info.height - coord.x; + coord.x = temp; + } else if (cursorPos.direction == Direction::DIRECTION270) { + double temp = coord.x; + coord.x = info.width - coord.y; + coord.y = temp; + } + } MMI_HILOGD("direction is DIRECTION0"); return; } @@ -2214,7 +2249,7 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi isDragBorder_ = false; } Direction direction = DIRECTION0; - if (ROTATE_POLICY == WINDOW_ROTATE && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (TOUCH_DRAWING_MGR->IsWindowRotation() && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { direction = physicalDisplayInfo->direction; TOUCH_DRAWING_MGR->GetOriginalTouchScreenCoordinates(direction, physicalDisplayInfo->width, physicalDisplayInfo->height, physicalX, physicalY); @@ -2227,6 +2262,7 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi IPointerDrawingManager::GetInstance()->DrawPointer(displayId, physicalX, physicalY, dragPointerStyle_, direction); } + cursorPos.direction = physicalDisplayInfo->direction; int64_t endTime = GetSysClockTime(); if ((endTime - beginTime) > RS_PROCESS_TIMEOUT) { MMI_HILOGW("Rs process timeout"); @@ -3218,7 +3254,7 @@ void InputWindowsManager::CoordinateCorrection(int32_t width, int32_t height, in void InputWindowsManager::GetWidthAndHeight(const DisplayInfo* displayInfo, int32_t &width, int32_t &height) { - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (TOUCH_DRAWING_MGR->IsWindowRotation()) { if (displayInfo->direction == DIRECTION0 || displayInfo->direction == DIRECTION180) { width = displayInfo->width; height = displayInfo->height; @@ -3299,7 +3335,7 @@ void InputWindowsManager::UpdateAndAdjustMouseLocation(int32_t& displayId, doubl x = static_cast(integerX) + (x - floor(x)); y = static_cast(integerY) + (y - floor(y)); - if (ROTATE_POLICY == WINDOW_ROTATE && isRealData) { + if (TOUCH_DRAWING_MGR->IsWindowRotation() && isRealData) { PhysicalCoordinate coord { .x = integerX, .y = integerY, @@ -3315,7 +3351,7 @@ void InputWindowsManager::UpdateAndAdjustMouseLocation(int32_t& displayId, doubl MMI_HILOGD("Mouse Data: physicalX:%{public}d,physicalY:%{public}d, displayId:%{public}d", mouseLocation_.physicalX, mouseLocation_.physicalY, displayId); cursorPos_.displayId = displayId; - if (ROTATE_POLICY == WINDOW_ROTATE && !isRealData) { + if (TOUCH_DRAWING_MGR->IsWindowRotation() && !isRealData) { ReverseRotateScreen(*displayInfo, x, y, cursorPos_.cursorPos); return; } diff --git a/service/window_manager/src/pointer_drawing_manager.cpp b/service/window_manager/src/pointer_drawing_manager.cpp index 669adb300837361f0f7a65a46d97e1aacefec4be..f94caac76e49dab3f1283af44c328dfd62718e04 100644 --- a/service/window_manager/src/pointer_drawing_manager.cpp +++ b/service/window_manager/src/pointer_drawing_manager.cpp @@ -61,7 +61,10 @@ const std::string POINTER_SIZE { "pointerSize" }; const std::string MAGIC_POINTER_COLOR { "magicPointerColor" }; const std::string MAGIC_POINTER_SIZE { "magicPointerSize"}; const int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotate_policy", 0); +const std::string FOLDABLE_DEVICE_POLICY = system::GetParameter("const.window.foldabledevice.rotate_policy", ""); constexpr int32_t WINDOW_ROTATE { 0 }; +constexpr char ROTATE_WINDOW_ROTATE { '0' }; +constexpr int32_t FOLDABLE_DEVICE { 2 }; constexpr int32_t BASELINE_DENSITY { 160 }; constexpr int32_t CALCULATE_MIDDLE { 2 }; constexpr int32_t MAGIC_INDEPENDENT_PIXELS { 30 }; @@ -888,7 +891,7 @@ void PointerDrawingManager::FixCursorPosition(int32_t &physicalX, int32_t &physi physicalY = 0; } const int32_t cursorUnit = 16; - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (IsWindowRotation()) { if (displayInfo_.direction == DIRECTION0 || displayInfo_.direction == DIRECTION180) { if (physicalX > (displayInfo_.width - imageWidth_ / cursorUnit)) { physicalX = displayInfo_.width - imageWidth_ / cursorUnit; @@ -1386,7 +1389,7 @@ int32_t PointerDrawingManager::SetPointerSize(int32_t size) MAGIC_CURSOR->SetPointerSize(imageWidth_, imageHeight_); #endif // OHOS_BUILD_ENABLE_MAGICCURSOR Direction direction = DIRECTION0; - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (IsWindowRotation()) { direction = displayInfo_.direction; } AdjustMouseFocus(direction, ICON_TYPE(GetMouseIconPath()[MOUSE_ICON(lastMouseStyle_.id)].alignmentWay), @@ -1488,7 +1491,7 @@ void PointerDrawingManager::DrawManager() WIN_MGR->GetPointerStyle(pid_, windowId_, pointerStyle); MMI_HILOGD("get pid %{publid}d with pointerStyle %{public}d", pid_, pointerStyle.id); Direction direction = DIRECTION0; - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (IsWindowRotation()) { direction = displayInfo_.direction; } if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) { @@ -1859,16 +1862,16 @@ int32_t PointerDrawingManager::ClearWindowPointerStyle(int32_t pid, int32_t wind return WIN_MGR->ClearWindowPointerStyle(pid, windowId); } -void PointerDrawingManager::DrawPointerStyle(const PointerStyle& pointerStyle) +void PointerDrawingManager::DrawPointerStyle(const PointerStyle& pointerStyle, bool simulate) { CALL_DEBUG_ENTER; - if (hasDisplay_ && hasPointerDevice_) { + if (hasDisplay_ && (hasPointerDevice_ || simulate)) { if (surfaceNode_ != nullptr) { AttachToDisplay(); Rosen::RSTransaction::FlushImplicitTransaction(); } Direction direction = DIRECTION0; - if (ROTATE_POLICY == WINDOW_ROTATE) { + if (IsWindowRotation()) { direction = displayInfo_.direction; } if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) { @@ -1986,6 +1989,18 @@ void PointerDrawingManager::RotateDegree(Direction direction) surfaceNode_->SetRotation(degree); } +bool PointerDrawingManager::IsWindowRotation() +{ + MMI_HILOGD("ROTATE_POLICY: %{public}d, FOLDABLE_DEVICE_POLICY:%{public}s", + ROTATE_POLICY, FOLDABLE_DEVICE_POLICY.c_str()); + return (ROTATE_POLICY == WINDOW_ROTATE || + (ROTATE_POLICY == FOLDABLE_DEVICE && + ((displayInfo_.displayMode == DisplayMode::MAIN && + FOLDABLE_DEVICE_POLICY[0] == ROTATE_WINDOW_ROTATE) || + (displayInfo_.displayMode == DisplayMode::FULL && + FOLDABLE_DEVICE_POLICY[FOLDABLE_DEVICE] == ROTATE_WINDOW_ROTATE)))); +} + void PointerDrawingManager::Dump(int32_t fd, const std::vector &args) { CALL_DEBUG_ENTER;