From a8785ea7ebbf8d4071234e5823132d9f2ab429fe Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 20:41:13 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../src/intention_event_manager.cpp | 35 ++++++-- wm/src/window_input_channel.cpp | 34 ++++++-- wm/src/window_session_impl.cpp | 84 +++++++++++-------- 3 files changed, 102 insertions(+), 51 deletions(-) diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 3e001abd70..003f06fc50 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -233,19 +233,38 @@ void IntentionEventManager::InputEventListener::OnInputEvent( WLOGFI("InputTracking id:%{public}d, EventListener OnInputEvent", keyEvent->GetId()); if (focusedSceneSession->GetSessionInfo().isSystem_) { - bool inputMethodHasProcessed = false; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { - WLOGD("dispatch keyEvent to input method"); - inputMethodHasProcessed = - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent); - } -#endif // IMF_ENABLE - if (inputMethodHasProcessed) { - WLOGD("Input method has processed key event"); + WLOGD("Async dispatch keyEvent to input method"); + auto callback = [this, focusedSessionId] (std::shared_ptr keyEvent, bool consumed) { + if (keyEvent == nullptr) { + WLOGFW("keyEvent is null"); + return; + } + + if (consumed) { + WLOGD("Input method has processed key event, id:%{public}" PRId32, keyEvent->GetId()); + return; + } + + auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); + if (focusedSceneSession == nullptr) { + WLOGFE("focusedSceneSession is null"); + return; + } + + if (uiContent_ == nullptr) { + WLOGFE("uiContent_ is null"); + return; + } + + focusedSceneSession->SendKeyEventToUI(keyEvent); + } + MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); return; } +#endif // IMF_ENABLE WLOGFD("Syetem window scene, transfer key event to root scene"); if (uiContent_ == nullptr) { WLOGFE("uiContent_ is null"); diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index e3d768e71d..59d794727b 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -54,18 +54,38 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent } } - bool inputMethodHasProcessed = false; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { - WLOGD("dispatch keyEvent to input method"); - inputMethodHasProcessed = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent); + WLOGD("Async dispatch keyEvent to input method"); + auto callback = [this] (std::shared_ptr keyEvent, bool consumed) { + if (keyEvent == nullptr) { + WLOGFW("keyEvent is null"); + return; + } + + if (consumed) { + WLOGD("Input method has processed key event, id:%{public}d", keyEvent->GetId()); + return; + } + + auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); + if (focusedSceneSession == nullptr) { + WLOGFE("focusedSceneSession is null"); + return; + } + + if (window_ != nullptr) { + WLOGD("dispatch keyEvent to ACE"); + window_->ConsumeKeyEvent(keyEvent); + } + } + MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + return; } #endif // IMF_ENABLE - if (!inputMethodHasProcessed) { - WLOGD("dispatch keyEvent to ACE"); - window_->ConsumeKeyEvent(keyEvent); - } + WLOGD("dispatch keyEvent to ACE"); + window_->ConsumeKeyEvent(keyEvent); } void WindowInputChannel::HandlePointerEvent(std::shared_ptr& pointerEvent) diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 49823c9585..d866649318 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2020,50 +2020,62 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key return; } - bool inputMethodHasProcessed = false; + auto dispatchFunc = [this, &keyEvent] () { + std::shared_ptr inputEventConsumer; + { + std::lock_guard lock(mutex_); + inputEventConsumer = inputEventConsumer_; + } + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { + WLOGFI("input event is consumed by back, return"); + if (inputEventConsumer != nullptr) { + WLOGFD("Transfer key event to inputEventConsumer"); + if (inputEventConsumer->OnInputEvent(keyEvent)) { + return; + } + PerformBack(); + return; + } + HandleBackEvent(); + return; + } + if (inputEventConsumer != nullptr) { + WLOGD("Transfer key event to inputEventConsumer"); + (void)inputEventConsumer->OnInputEvent(keyEvent); + } else if (uiContent_) { + auto isConsumed = uiContent_->ProcessKeyEvent(keyEvent); + if (!isConsumed && keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE && + property_->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && + property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL) { + WLOGI("recover from fullscreen cause KEYCODE_ESCAPE"); + Recover(); + } + } + }; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { - WLOGD("dispatch keyEvent to input method"); - inputMethodHasProcessed = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent); - } -#endif // IMF_ENABLE - if (inputMethodHasProcessed) { - WLOGFD("input method has processed key event"); - return; - } - std::shared_ptr inputEventConsumer; - { - std::lock_guard lock(mutex_); - inputEventConsumer = inputEventConsumer_; - } - int32_t keyCode = keyEvent->GetKeyCode(); - int32_t keyAction = keyEvent->GetKeyAction(); - if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { - WLOGFI("input event is consumed by back, return"); - if (inputEventConsumer != nullptr) { - WLOGFD("Transfer key event to inputEventConsumer"); - if (inputEventConsumer->OnInputEvent(keyEvent)) { + WLOGD("Async dispatch keyEvent to input method"); + auto callback = [this, &dispatchFunc] () { + if (keyEvent == nullptr) { + WLOGFW("keyEvent is null"); return; } - PerformBack(); - return; + + if (consumed) { + WLOGD("Input method has processed key event, id:%{public}" PRId32, keyEvent->GetId()); + return; + } + + dispatchFunc(); } - HandleBackEvent(); + MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); return; } - if (inputEventConsumer != nullptr) { - WLOGD("Transfer key event to inputEventConsumer"); - (void)inputEventConsumer->OnInputEvent(keyEvent); - } else if (uiContent_) { - isConsumed = uiContent_->ProcessKeyEvent(keyEvent); - if (!isConsumed && keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE && - property_->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && - property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL) { - WLOGI("recover from fullscreen cause KEYCODE_ESCAPE"); - Recover(); - } - } +#endif // IMF_ENABLE + dispatchFunc(); } bool WindowSessionImpl::IsKeyboardEvent(const std::shared_ptr& keyEvent) const -- Gitee From c2223e296d61b14c8ef69d0d9bfde3cca2ffa654 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 20:54:32 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- wm/src/window_session_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index d866649318..648457042d 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2058,7 +2058,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this, &dispatchFunc] () { + auto callback = [this, &dispatchFunc] (std::shared_ptr keyEvent, bool consumed) { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); return; -- Gitee From 852cb89999647545282a26a95674c679fe2c4a33 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 21:13:40 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=87=E5=BF=98?= =?UTF-8?q?=E5=BD=95=E5=BA=94=E7=94=A8=E5=9C=A8=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=BC=B9=E5=87=BA=E7=8A=B6=E6=80=81=E4=B8=8B?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=AA=97=E5=8F=A3=E6=9C=8D=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=90=8E=E5=A4=87=E5=BF=98=E5=BD=95=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E7=95=8C=E9=9D=A2=E4=BB=8D=E5=A4=84=E4=BA=8E=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=B3=95=E5=BC=B9=E5=87=BA=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../include/scene_session_manager.h | 1 + .../src/scene_session_manager.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 7f63fdaaf2..79c0e9779b 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -492,6 +492,7 @@ private: sptr windowDeath_ = new AgentDeathRecipient( std::bind(&SceneSessionManager::DestroySpecificSession, this, std::placeholders::_1)); sptr callingSession_ = nullptr; + uint32_t callingWindowId_ = 0; WSError ClearSession(sptr sceneSession); bool IsSessionClearable(sptr scnSession); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 49bc2f3ff0..1865122d18 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -1845,6 +1845,14 @@ void SceneSessionManager::RecoverWindowSessionProperty( auto windowType = property->GetWindowType(); if (windowType == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { RelayoutKeyBoard(sceneSession); + callingWindowId_ = property->GetCallingWindow(); + const auto& callingSession = GetSceneSession(static_cast(callingWindowId_)); + if (callingSession != nullptr) { + WLOGFI("[WMSRecover] NotifyOccupiedAreaChangeInfo after inputMethod session recovered," + "persistentId = %{public}" PRId32, callingSession->GetPersistentId()); + sptr info = new OccupiedAreaChangeInfo(); + callingSession->NotifyOccupiedAreaChangeInfo(info); + } } else { const auto& rect = property->GetWindowRect(); const auto& requestRect = sceneSession->GetSessionProperty()->GetRequestRect(); @@ -1856,6 +1864,14 @@ void SceneSessionManager::RecoverWindowSessionProperty( sceneSession->GetSessionProperty()->SetRequestRect(rect); auto wsRectPos = SessionHelper::TransferToWSRect(rect); sceneSession->UpdateSessionRect(wsRectPos, SizeChangeReason::MOVE); + + auto persistentId = sceneSession->GetPersistentId(); + if (persistentId == callingWindowId_) { + WLOGFI("[WMSRecover] NotifyOccupiedAreaChangeInfo after calling session recovered," + "persistentId = %{public}" PRId32, persistentId); + sptr info = new OccupiedAreaChangeInfo(); + sceneSession->NotifyOccupiedAreaChangeInfo(info); + } } } -- Gitee From 61a86341f95c963ebd7bc0731fb69d7668387110 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 21:48:28 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../include/intention_event_manager.h | 1 + .../src/intention_event_manager.cpp | 88 ++++++++++--------- .../include/scene_session_manager.h | 1 - .../src/scene_session_manager.cpp | 16 ---- wm/include/window_session_impl.h | 1 + wm/src/window_session_impl.cpp | 73 ++++++++------- 6 files changed, 90 insertions(+), 90 deletions(-) diff --git a/window_scene/intention_event/include/intention_event_manager.h b/window_scene/intention_event/include/intention_event_manager.h index 7aa2156834..a49e7e5b64 100644 --- a/window_scene/intention_event/include/intention_event_manager.h +++ b/window_scene/intention_event/include/intention_event_manager.h @@ -47,6 +47,7 @@ public: void RegisterWindowChanged(); private: + void KeyEventConsumedCallback(int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed); void UpdateLastMouseEvent(std::shared_ptr pointerEvent) const; void ProcessEnterLeaveEventAsync(); bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 003f06fc50..75487e642d 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -213,8 +213,34 @@ void IntentionEventManager::InputEventListener::OnInputEvent( UpdateLastMouseEvent(pointerEvent); } -void IntentionEventManager::InputEventListener::OnInputEvent( - std::shared_ptr keyEvent) const +void IntentionEventManager::InputEventListener::KeyEventConsumedCallback( + int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) +{ + if (keyEvent == nullptr) { + WLOGFW("keyEvent is null"); + return; + } + + if (consumed) { + WLOGD("Input method has processed key event, id:%{public}" PRId32, keyEvent->GetId()); + return; + } + + auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); + if (focusedSceneSession == nullptr) { + WLOGFE("focusedSceneSession is null"); + return; + } + + if (uiContent_ == nullptr) { + WLOGFE("uiContent_ is null"); + return; + } + + focusedSceneSession->SendKeyEventToUI(keyEvent); +} + +void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptr keyEvent) const { if (!SceneSessionManager::GetInstance().IsInputEventEnabled()) { WLOGFD("OnInputEvent is disabled temporarily"); @@ -230,50 +256,28 @@ void IntentionEventManager::InputEventListener::OnInputEvent( WLOGFE("focusedSceneSession is null"); return; } - WLOGFI("InputTracking id:%{public}d, EventListener OnInputEvent", - keyEvent->GetId()); - if (focusedSceneSession->GetSessionInfo().isSystem_) { + WLOGFI("InputTracking id:%{public}d, EventListener OnInputEvent", keyEvent->GetId()); + if (!focusedSceneSession->GetSessionInfo().isSystem_) { + focusedSceneSession->TransferKeyEvent(keyEvent); + return; + } #ifdef IMF_ENABLE - bool isKeyboardEvent = IsKeyboardEvent(keyEvent); - if (isKeyboardEvent) { - WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this, focusedSessionId] (std::shared_ptr keyEvent, bool consumed) { - if (keyEvent == nullptr) { - WLOGFW("keyEvent is null"); - return; - } - - if (consumed) { - WLOGD("Input method has processed key event, id:%{public}" PRId32, keyEvent->GetId()); - return; - } - - auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); - if (focusedSceneSession == nullptr) { - WLOGFE("focusedSceneSession is null"); - return; - } - - if (uiContent_ == nullptr) { - WLOGFE("uiContent_ is null"); - return; - } - - focusedSceneSession->SendKeyEventToUI(keyEvent); - } - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); - return; + bool isKeyboardEvent = IsKeyboardEvent(keyEvent); + if (isKeyboardEvent) { + WLOGD("Async dispatch keyEvent to input method"); + auto callback = [this, focusedSessionId] (std::shared_ptr keyEvent, bool consumed) { + this->KeyEventConsumedCallback(focusedSessionId, keyEvent, consumed); } + MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + return; + } #endif // IMF_ENABLE - WLOGFD("Syetem window scene, transfer key event to root scene"); - if (uiContent_ == nullptr) { - WLOGFE("uiContent_ is null"); - return; - } - focusedSceneSession->SendKeyEventToUI(keyEvent); - } else { - focusedSceneSession->TransferKeyEvent(keyEvent); + WLOGFD("Syetem window scene, transfer key event to root scene"); + if (uiContent_ == nullptr) { + WLOGFE("uiContent_ is null"); + return; } + focusedSceneSession->SendKeyEventToUI(keyEvent); } bool IntentionEventManager::InputEventListener::IsKeyboardEvent( diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 79c0e9779b..7f63fdaaf2 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -492,7 +492,6 @@ private: sptr windowDeath_ = new AgentDeathRecipient( std::bind(&SceneSessionManager::DestroySpecificSession, this, std::placeholders::_1)); sptr callingSession_ = nullptr; - uint32_t callingWindowId_ = 0; WSError ClearSession(sptr sceneSession); bool IsSessionClearable(sptr scnSession); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 1865122d18..49bc2f3ff0 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -1845,14 +1845,6 @@ void SceneSessionManager::RecoverWindowSessionProperty( auto windowType = property->GetWindowType(); if (windowType == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { RelayoutKeyBoard(sceneSession); - callingWindowId_ = property->GetCallingWindow(); - const auto& callingSession = GetSceneSession(static_cast(callingWindowId_)); - if (callingSession != nullptr) { - WLOGFI("[WMSRecover] NotifyOccupiedAreaChangeInfo after inputMethod session recovered," - "persistentId = %{public}" PRId32, callingSession->GetPersistentId()); - sptr info = new OccupiedAreaChangeInfo(); - callingSession->NotifyOccupiedAreaChangeInfo(info); - } } else { const auto& rect = property->GetWindowRect(); const auto& requestRect = sceneSession->GetSessionProperty()->GetRequestRect(); @@ -1864,14 +1856,6 @@ void SceneSessionManager::RecoverWindowSessionProperty( sceneSession->GetSessionProperty()->SetRequestRect(rect); auto wsRectPos = SessionHelper::TransferToWSRect(rect); sceneSession->UpdateSessionRect(wsRectPos, SizeChangeReason::MOVE); - - auto persistentId = sceneSession->GetPersistentId(); - if (persistentId == callingWindowId_) { - WLOGFI("[WMSRecover] NotifyOccupiedAreaChangeInfo after calling session recovered," - "persistentId = %{public}" PRId32, persistentId); - sptr info = new OccupiedAreaChangeInfo(); - sceneSession->NotifyOccupiedAreaChangeInfo(info); - } } } diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index efcb866d0c..82c9366649 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -271,6 +271,7 @@ private: RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type); template EnableIfSame>> GetListeners(); + void DispatchKeyEvent(std::shared_ptr& keyEvent); void NotifyAfterFocused(); void NotifyUIContentFocusStatus(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 648457042d..d833cf4dde 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2013,6 +2013,42 @@ void WindowSessionImpl::NotifyPointerEvent(const std::shared_ptr& keyEvent) +{ + std::shared_ptr inputEventConsumer; + { + std::lock_guard lock(mutex_); + inputEventConsumer = inputEventConsumer_; + } + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { + WLOGFI("input event is consumed by back, return"); + if (inputEventConsumer != nullptr) { + WLOGFD("Transfer key event to inputEventConsumer"); + if (inputEventConsumer->OnInputEvent(keyEvent)) { + return; + } + PerformBack(); + return; + } + HandleBackEvent(); + return; + } + if (inputEventConsumer != nullptr) { + WLOGD("Transfer key event to inputEventConsumer"); + (void)inputEventConsumer->OnInputEvent(keyEvent); + } else if (uiContent_) { + auto isConsumed = uiContent_->ProcessKeyEvent(keyEvent); + if (!isConsumed && keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE && + property_->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && + property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL) { + WLOGI("recover from fullscreen cause KEYCODE_ESCAPE"); + Recover(); + } + } +} + void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& keyEvent, bool& isConsumed) { if (keyEvent == nullptr) { @@ -2020,39 +2056,14 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key return; } - auto dispatchFunc = [this, &keyEvent] () { - std::shared_ptr inputEventConsumer; - { - std::lock_guard lock(mutex_); - inputEventConsumer = inputEventConsumer_; - } - int32_t keyCode = keyEvent->GetKeyCode(); - int32_t keyAction = keyEvent->GetKeyAction(); - if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { - WLOGFI("input event is consumed by back, return"); - if (inputEventConsumer != nullptr) { - WLOGFD("Transfer key event to inputEventConsumer"); - if (inputEventConsumer->OnInputEvent(keyEvent)) { - return; - } - PerformBack(); - return; - } - HandleBackEvent(); + wptr weakThis = this; + auto dispatchFunc = [weakThis, &keyEvent] () { + auto promoteThis = weakThis.promote(); + if (promoteThis == nullptr) { + WLOGFW("promoteThis is nullptr"); return; } - if (inputEventConsumer != nullptr) { - WLOGD("Transfer key event to inputEventConsumer"); - (void)inputEventConsumer->OnInputEvent(keyEvent); - } else if (uiContent_) { - auto isConsumed = uiContent_->ProcessKeyEvent(keyEvent); - if (!isConsumed && keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE && - property_->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && - property_->GetMaximizeMode() == MaximizeMode::MODE_FULL_FILL) { - WLOGI("recover from fullscreen cause KEYCODE_ESCAPE"); - Recover(); - } - } + promoteThis->DispatchKeyEvent(keyEvent); }; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); -- Gitee From bdb3d27cff05d6bbf780cd74b4e9d05a60cdd229 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 21:53:04 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- window_scene/intention_event/src/intention_event_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 75487e642d..fe82452388 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -267,7 +267,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptr keyEvent, bool consumed) { this->KeyEventConsumedCallback(focusedSessionId, keyEvent, consumed); - } + }; MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); return; } -- Gitee From 29f94fb7d800df4b6159243d82eed49e2affe91d Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Mon, 8 Jan 2024 22:11:04 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- wm/src/window_input_channel.cpp | 2 +- wm/src/window_session_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 59d794727b..e12b167873 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -79,7 +79,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGD("dispatch keyEvent to ACE"); window_->ConsumeKeyEvent(keyEvent); } - } + }; MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); return; } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index d833cf4dde..2b348c40d2 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2081,7 +2081,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key } dispatchFunc(); - } + }; MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); return; } -- Gitee From 7295c0dcd1c1f380469929119d31632bec46d204 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Tue, 9 Jan 2024 11:28:14 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../intention_event/include/intention_event_manager.h | 3 ++- .../intention_event/src/intention_event_manager.cpp | 4 ++-- wm/src/window_input_channel.cpp | 8 +------- wm/src/window_session_impl.cpp | 7 ++++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/window_scene/intention_event/include/intention_event_manager.h b/window_scene/intention_event/include/intention_event_manager.h index a49e7e5b64..60a52331b8 100644 --- a/window_scene/intention_event/include/intention_event_manager.h +++ b/window_scene/intention_event/include/intention_event_manager.h @@ -47,7 +47,8 @@ public: void RegisterWindowChanged(); private: - void KeyEventConsumedCallback(int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed); + void KeyEventConsumedCallback( + int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const; void UpdateLastMouseEvent(std::shared_ptr pointerEvent) const; void ProcessEnterLeaveEventAsync(); bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index fe82452388..6aecca5082 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -214,7 +214,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent( } void IntentionEventManager::InputEventListener::KeyEventConsumedCallback( - int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) + int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); @@ -265,7 +265,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptr keyEvent, bool consumed) { + auto callback = [this, focusedSessionId] (std::shared_ptr& keyEvent, bool consumed) { this->KeyEventConsumedCallback(focusedSessionId, keyEvent, consumed); }; MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index e12b167873..9eccbef1a7 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -58,7 +58,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this] (std::shared_ptr keyEvent, bool consumed) { + auto callback = [this] (std::shared_ptr& keyEvent, bool consumed) { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); return; @@ -69,12 +69,6 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent return; } - auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); - if (focusedSceneSession == nullptr) { - WLOGFE("focusedSceneSession is null"); - return; - } - if (window_ != nullptr) { WLOGD("dispatch keyEvent to ACE"); window_->ConsumeKeyEvent(keyEvent); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 2b348c40d2..5ae2db3fcc 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2063,13 +2063,13 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key WLOGFW("promoteThis is nullptr"); return; } - promoteThis->DispatchKeyEvent(keyEvent); + promoteThis->DispatchKeyEvent(const_cast&>(keyEvent)); }; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this, &dispatchFunc] (std::shared_ptr keyEvent, bool consumed) { + auto callback = [this, &dispatchFunc] (std::shared_ptr& keyEvent, bool consumed) { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); return; @@ -2082,7 +2082,8 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key dispatchFunc(); }; - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent( + const_cast&>(keyEvent), callback); return; } #endif // IMF_ENABLE -- Gitee From 5ba637f86bf519489dca5dee4e3bcde3c033ede0 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Wed, 10 Jan 2024 22:52:12 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- wm/src/window_input_channel.cpp | 13 ++++++++++--- wm/src/window_session_impl.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 9eccbef1a7..d372c7f30b 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -58,7 +58,14 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this] (std::shared_ptr& keyEvent, bool consumed) { + wptr weakThis = this; + auto callback = [weakThis] (std::shared_ptr& keyEvent, bool consumed) { + auto promoteThis = weakThis.promote(); + if (promoteThis == nullptr) { + WLOGFW("promoteThis is nullptr"); + return; + } + if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); return; @@ -69,9 +76,9 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent return; } - if (window_ != nullptr) { + if (promoteThis->window_ != nullptr) { WLOGD("dispatch keyEvent to ACE"); - window_->ConsumeKeyEvent(keyEvent); + promoteThis->window_->ConsumeKeyEvent(keyEvent); } }; MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 5ae2db3fcc..0dfe7e708e 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2057,7 +2057,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key } wptr weakThis = this; - auto dispatchFunc = [weakThis, &keyEvent] () { + auto dispatchFunc = [weakThis, keyEvent] () { auto promoteThis = weakThis.promote(); if (promoteThis == nullptr) { WLOGFW("promoteThis is nullptr"); @@ -2069,7 +2069,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - auto callback = [this, &dispatchFunc] (std::shared_ptr& keyEvent, bool consumed) { + auto callback = [dispatchFunc] (std::shared_ptr& keyEvent, bool consumed) { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); return; -- Gitee From 1a9570b0c5cf35bad7401146415da55074fb45c6 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Wed, 10 Jan 2024 23:18:43 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- window_scene/intention_event/src/intention_event_manager.cpp | 5 ++++- wm/src/window_input_channel.cpp | 5 ++++- wm/src/window_session_impl.cpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 6aecca5082..b72b3c6903 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -268,7 +268,10 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptr& keyEvent, bool consumed) { this->KeyEventConsumedCallback(focusedSessionId, keyEvent, consumed); }; - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + if (ret != 0) { + WLOGFE("DispatchKeyEvent failed, ret:%{public}d, id:%{public}d", ret, keyEvent->GetId()); + } return; } #endif // IMF_ENABLE diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index d372c7f30b..e7b9310460 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -81,7 +81,10 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent promoteThis->window_->ConsumeKeyEvent(keyEvent); } }; - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); + if (ret != 0) { + WLOGFE("DispatchKeyEvent failed, ret:%{public}d, id:%{public}d", ret, keyEvent->GetId()); + } return; } #endif // IMF_ENABLE diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 0dfe7e708e..2ee5b1051b 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2082,8 +2082,11 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key dispatchFunc(); }; - MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent( + auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent( const_cast&>(keyEvent), callback); + if (ret != 0) { + WLOGFE("DispatchKeyEvent failed, ret:%{public}" PRId32 ", id:%{public}" PRId32, ret, keyEvent->GetId()); + } return; } #endif // IMF_ENABLE -- Gitee From 8884e7f547e46becfc0017b94b4da4a4b37ad01a Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Thu, 11 Jan 2024 09:16:49 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- wm/include/window_input_channel.h | 1 + wm/src/window_input_channel.cpp | 34 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index ed085e9b81..14fe9ef9b1 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -32,6 +32,7 @@ public: void Destroy(); private: bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; + void DispatchKeyEvent(std::shared_ptr& keyEvent, bool consumed); std::mutex mtx_; sptr window_; bool isAvailable_; diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index e7b9310460..04785baa4b 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -34,6 +34,24 @@ WindowInputChannel::~WindowInputChannel() window_->SetNeedRemoveWindowInputChannel(false); } +void WindowInputChannel::DispatchKeyEvent(std::shared_ptr& keyEvent, bool consumed) +{ + if (keyEvent == nullptr) { + WLOGFW("keyEvent is null"); + return; + } + + if (consumed) { + WLOGD("Input method has processed key event, id:%{public}d", keyEvent->GetId()); + return; + } + + if (window_ != nullptr) { + WLOGD("dispatch keyEvent to ACE"); + window_->ConsumeKeyEvent(keyEvent); + } +} + void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) { if (keyEvent == nullptr) { @@ -65,21 +83,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGFW("promoteThis is nullptr"); return; } - - if (keyEvent == nullptr) { - WLOGFW("keyEvent is null"); - return; - } - - if (consumed) { - WLOGD("Input method has processed key event, id:%{public}d", keyEvent->GetId()); - return; - } - - if (promoteThis->window_ != nullptr) { - WLOGD("dispatch keyEvent to ACE"); - promoteThis->window_->ConsumeKeyEvent(keyEvent); - } + promoteThis->DispatchKeyEvent(keyEvent, consumed); }; auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); if (ret != 0) { -- Gitee From 5865d5ae7bf69b93aa03462cbb28aff7c1fdcad7 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Fri, 12 Jan 2024 09:08:10 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../intention_event/include/intention_event_manager.h | 2 +- window_scene/intention_event/src/intention_event_manager.cpp | 4 ++-- wm/include/window_input_channel.h | 2 +- wm/include/window_session_impl.h | 2 +- wm/src/window_input_channel.cpp | 4 ++-- wm/src/window_session_impl.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/window_scene/intention_event/include/intention_event_manager.h b/window_scene/intention_event/include/intention_event_manager.h index 60a52331b8..444ccbe46a 100644 --- a/window_scene/intention_event/include/intention_event_manager.h +++ b/window_scene/intention_event/include/intention_event_manager.h @@ -47,7 +47,7 @@ public: void RegisterWindowChanged(); private: - void KeyEventConsumedCallback( + void DispatchKeyEventCallback( int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const; void UpdateLastMouseEvent(std::shared_ptr pointerEvent) const; void ProcessEnterLeaveEventAsync(); diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index b72b3c6903..9a6de10000 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -213,7 +213,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent( UpdateLastMouseEvent(pointerEvent); } -void IntentionEventManager::InputEventListener::KeyEventConsumedCallback( +void IntentionEventManager::InputEventListener::DispatchKeyEventCallback( int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const { if (keyEvent == nullptr) { @@ -266,7 +266,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptr& keyEvent, bool consumed) { - this->KeyEventConsumedCallback(focusedSessionId, keyEvent, consumed); + this->DispatchKeyEventCallback(focusedSessionId, keyEvent, consumed); }; auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); if (ret != 0) { diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index 14fe9ef9b1..3558f11633 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -32,7 +32,7 @@ public: void Destroy(); private: bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; - void DispatchKeyEvent(std::shared_ptr& keyEvent, bool consumed); + void DispatchKeyEventCallback(std::shared_ptr& keyEvent, bool consumed); std::mutex mtx_; sptr window_; bool isAvailable_; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 82c9366649..e4c7fdcf0c 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -271,7 +271,7 @@ private: RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type); template EnableIfSame>> GetListeners(); - void DispatchKeyEvent(std::shared_ptr& keyEvent); + void DispatchKeyEventCallback(std::shared_ptr& keyEvent); void NotifyAfterFocused(); void NotifyUIContentFocusStatus(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 04785baa4b..e63789305e 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -34,7 +34,7 @@ WindowInputChannel::~WindowInputChannel() window_->SetNeedRemoveWindowInputChannel(false); } -void WindowInputChannel::DispatchKeyEvent(std::shared_ptr& keyEvent, bool consumed) +void WindowInputChannel::DispatchKeyEventCallback(std::shared_ptr& keyEvent, bool consumed) { if (keyEvent == nullptr) { WLOGFW("keyEvent is null"); @@ -83,7 +83,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGFW("promoteThis is nullptr"); return; } - promoteThis->DispatchKeyEvent(keyEvent, consumed); + promoteThis->DispatchKeyEventCallback(keyEvent, consumed); }; auto ret = MiscServices::InputMethodController::GetInstance()->DispatchKeyEvent(keyEvent, callback); if (ret != 0) { diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 2ee5b1051b..bffb01797e 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2013,7 +2013,7 @@ void WindowSessionImpl::NotifyPointerEvent(const std::shared_ptr& keyEvent) +void WindowSessionImpl::DispatchKeyEventCallback(std::shared_ptr& keyEvent) { std::shared_ptr inputEventConsumer; { @@ -2063,7 +2063,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key WLOGFW("promoteThis is nullptr"); return; } - promoteThis->DispatchKeyEvent(const_cast&>(keyEvent)); + promoteThis->DispatchKeyEventCallback(const_cast&>(keyEvent)); }; #ifdef IMF_ENABLE bool isKeyboardEvent = IsKeyboardEvent(keyEvent); -- Gitee From 75b5f9798b9ad89effc04a7c8c4cde74fff5e5dd Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Fri, 12 Jan 2024 10:08:31 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../kits/napi/scene_session_manager/js_scene_session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index 7d6d148649..62fee15188 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -116,7 +116,7 @@ private: void PendingSessionActivation(SessionInfo& info); void PendingSessionActivationInner(std::shared_ptr sessionInfo); void OnSessionStateChange(const SessionState& state); - void OnBufferAvailableChange(const bool isAvailable); + void OnBufferAvailableChange(const bool isBufferAvailable); void OnSessionEvent(uint32_t eventId); void OnCreateSubSession(const sptr& sceneSession); void OnBindDialogTarget(const sptr& sceneSession); -- Gitee From 52962f2b22fcac237ca0baeb37800241bbcc1914 Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Fri, 12 Jan 2024 12:44:18 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=BC=82=E6=AD=A5=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../src/intention_event_manager.cpp | 15 ++++++++++----- wm/src/window_input_channel.cpp | 3 +-- wm/src/window_session_impl.cpp | 5 ++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 9a6de10000..61c0d337f2 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -217,12 +217,14 @@ void IntentionEventManager::InputEventListener::DispatchKeyEventCallback( int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const { if (keyEvent == nullptr) { - WLOGFW("keyEvent is null"); + WLOGFW("keyEvent is null, focusedSessionId:%{public}" PRId32 + ", consumed:%{public}" PRId32, focusedSessionId, consumed); return; } if (consumed) { - WLOGD("Input method has processed key event, id:%{public}" PRId32, keyEvent->GetId()); + WLOGD("Input method has processed key event, id:%{public}" PRId32 ", focusedSessionId:%{public}" PRId32, + keyEvent->GetId(), focusedSessionId); return; } @@ -256,8 +258,10 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptrGetId()); - if (!focusedSceneSession->GetSessionInfo().isSystem_) { + auto isSystem = focusedSceneSession->GetSessionInfo().isSystem_; + WLOGFI("EventListener OnInputEvent InputTracking id:%{public}d, focusedSessionId:%{public}d, isSystem:%{public}d", + keyEvent->GetId(), focusedSessionId, isSystem); + if (!isSystem) { focusedSceneSession->TransferKeyEvent(keyEvent); return; } @@ -270,7 +274,8 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptrDispatchKeyEvent(keyEvent, callback); if (ret != 0) { - WLOGFE("DispatchKeyEvent failed, ret:%{public}d, id:%{public}d", ret, keyEvent->GetId()); + WLOGFE("DispatchKeyEvent failed, ret:%{public}d, id:%{public}d, focusedSessionId:%{public}d", + ret, keyEvent->GetId(), focusedSceneSession); } return; } diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index e63789305e..c2d9255ec4 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -76,8 +76,7 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent bool isKeyboardEvent = IsKeyboardEvent(keyEvent); if (isKeyboardEvent) { WLOGD("Async dispatch keyEvent to input method"); - wptr weakThis = this; - auto callback = [weakThis] (std::shared_ptr& keyEvent, bool consumed) { + auto callback = [weakThis = wptr(this)] (std::shared_ptr& keyEvent, bool consumed) { auto promoteThis = weakThis.promote(); if (promoteThis == nullptr) { WLOGFW("promoteThis is nullptr"); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index bffb01797e..7ea1af06a4 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2056,8 +2056,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key return; } - wptr weakThis = this; - auto dispatchFunc = [weakThis, keyEvent] () { + auto dispatchFunc = [weakThis = wptr(this), keyEvent] () { auto promoteThis = weakThis.promote(); if (promoteThis == nullptr) { WLOGFW("promoteThis is nullptr"); @@ -2071,7 +2070,7 @@ void WindowSessionImpl::NotifyKeyEvent(const std::shared_ptr& key WLOGD("Async dispatch keyEvent to input method"); auto callback = [dispatchFunc] (std::shared_ptr& keyEvent, bool consumed) { if (keyEvent == nullptr) { - WLOGFW("keyEvent is null"); + WLOGFW("keyEvent is null, consumed:%{public}" PRId32, consumed); return; } -- Gitee From e2f322fc53382fd99bf1d71129e526ab50dbfb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=B0=B8=E9=BE=99?= Date: Fri, 12 Jan 2024 08:20:12 +0000 Subject: [PATCH 14/14] update window_scene/intention_event/src/intention_event_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 熊永龙 --- window_scene/intention_event/src/intention_event_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 61c0d337f2..4258f5c428 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -275,7 +275,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptrDispatchKeyEvent(keyEvent, callback); if (ret != 0) { WLOGFE("DispatchKeyEvent failed, ret:%{public}d, id:%{public}d, focusedSessionId:%{public}d", - ret, keyEvent->GetId(), focusedSceneSession); + ret, keyEvent->GetId(), focusedSessionId); } return; } -- Gitee