From a159f56a40bc505c90e44ac3ef2c2be41b6ef20c Mon Sep 17 00:00:00 2001 From: guojin31 Date: Mon, 28 Apr 2025 15:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86displaychange=E7=9A=84adjust=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=92=8Cjs=5Fpanel=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=BB=9F=E4=B8=80=E7=94=A8queue=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E8=B0=83=E7=94=A8=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guojin31 --- .../include/js_inputmethod_extension.h | 2 ++ .../src/js_inputmethod_extension.cpp | 24 +++++++++++++------ .../include/tasks/task_imsa.h | 12 ---------- .../src/input_method_ability.cpp | 7 +----- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/frameworks/kits/extension/include/js_inputmethod_extension.h b/frameworks/kits/extension/include/js_inputmethod_extension.h index 9f8b41c13..160969bfc 100644 --- a/frameworks/kits/extension/include/js_inputmethod_extension.h +++ b/frameworks/kits/extension/include/js_inputmethod_extension.h @@ -146,6 +146,8 @@ private: void ListenWindowManager(); + void InitDisplayCache(); + JsRuntime &jsRuntime_; std::unique_ptr jsObj_; std::shared_ptr shellContextRef_ = nullptr; diff --git a/frameworks/kits/extension/src/js_inputmethod_extension.cpp b/frameworks/kits/extension/src/js_inputmethod_extension.cpp index df464dd00..ff270e7a8 100644 --- a/frameworks/kits/extension/src/js_inputmethod_extension.cpp +++ b/frameworks/kits/extension/src/js_inputmethod_extension.cpp @@ -136,6 +136,7 @@ void JsInputMethodExtension::Init(const std::shared_ptr &rec } BindContext(env, obj); handler_ = handler; + InitDisplayCache(); ListenWindowManager(); IMSA_HILOGI("JsInputMethodExtension end."); } @@ -287,10 +288,21 @@ void JsInputMethodExtension::OnStart(const AAFwk::Want &want) TaskManager::GetInstance().PostTask(std::make_shared()); IMSA_HILOGI("ime bind imf"); FinishAsync("OnStart", static_cast(TraceTaskId::ONSTART_EXTENSION)); - TaskManager::GetInstance().Complete(task->GetSeqId()); } +void JsInputMethodExtension::InitDisplayCache() +{ + auto foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus(); + auto displayPtr = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); + if (displayPtr == nullptr) { + IMSA_HILOGE("displayPtr is null"); + return; + } + cacheDisplay_.SetCacheDisplay( + displayPtr->GetWidth(), displayPtr->GetHeight(), displayPtr->GetRotation(), foldStatus); +} + void JsInputMethodExtension::OnStop() { InputMethodExtension::OnStop(); @@ -431,24 +443,22 @@ void JsInputMethodExtension::CheckNeedAdjustKeyboard(Rosen::DisplayId displayId) if (displayId != Rosen::DisplayManager::GetInstance().GetDefaultDisplayId()) { return; } - auto displayPtr = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); + auto foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus(); + auto displayPtr = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); if (displayPtr == nullptr) { return; } - auto foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus(); IMSA_HILOGD("display width: %{public}d, height: %{public}d, rotation: %{public}d, foldStatus: %{public}d", displayPtr->GetWidth(), displayPtr->GetHeight(), displayPtr->GetRotation(), foldStatus); - if (cacheDisplay_.IsEmpty()) { - TaskManager::GetInstance().PostTask(std::make_shared()); - } else { + if (!cacheDisplay_.IsEmpty()) { if ((cacheDisplay_.displayWidth != displayPtr->GetWidth() || cacheDisplay_.displayHeight != displayPtr->GetHeight()) && cacheDisplay_.displayFoldStatus == foldStatus && cacheDisplay_.displayRotation == displayPtr->GetRotation()) { - TaskManager::GetInstance().PostTask(std::make_shared()); + InputMethodAbility::GetInstance()->AdjustKeyboard(); } } cacheDisplay_.SetCacheDisplay( diff --git a/frameworks/native/inputmethod_ability/include/tasks/task_imsa.h b/frameworks/native/inputmethod_ability/include/tasks/task_imsa.h index 89407d87a..9a35612ad 100644 --- a/frameworks/native/inputmethod_ability/include/tasks/task_imsa.h +++ b/frameworks/native/inputmethod_ability/include/tasks/task_imsa.h @@ -184,18 +184,6 @@ public: } ~TaskImsaSetCoreAndAgent() = default; }; -class TaskImsaAdjustKeyboard : public Task { -public: - TaskImsaAdjustKeyboard() : Task(TASK_TYPE_IMSA_ADJUST_KEYBOARD) - { - auto func = []() { - InputMethodAbility::GetInstance()->AdjustKeyboard(); - }; - actions_.emplace_back(std::make_unique(func)); - } - ~TaskImsaAdjustKeyboard() = default; -}; - } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 5223766d1..85fd608d3 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -916,7 +916,7 @@ int32_t InputMethodAbility::OnConnectSystemCmd(const sptr &channe auto panel = GetSoftKeyboardPanel(); if (panel != nullptr) { auto flag = panel->GetPanelFlag(); - if (panel->IsShowing() && flag != FLG_CANDIDATE_COLUMN) { + if (flag != FLG_CANDIDATE_COLUMN) { auto keyboardSize = panel->GetKeyboardSize(); SysPanelStatus sysPanelStatus = { inputType_, flag, keyboardSize.width, keyboardSize.height }; NotifyPanelStatus(panel->GetPanelType(), sysPanelStatus); @@ -1086,11 +1086,6 @@ int32_t InputMethodAbility::NotifyPanelStatus(PanelType panelType, SysPanelStatu if (panelType != PanelType::SOFT_KEYBOARD) { return ErrorCode::NO_ERROR; } - // If it is not binding, do not need to notify the panel - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - return ErrorCode::NO_ERROR; - } sysPanelStatus.inputType = inputType_; auto systemChannel = GetSystemCmdChannelProxy(); if (systemChannel == nullptr) { -- Gitee