mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2025-03-06 22:19:31 +00:00
commit
7656b27db3
@ -24,6 +24,7 @@ config("inputmethod_adapter_native_config") {
|
|||||||
|
|
||||||
ohos_static_library("keboard_event_static") {
|
ohos_static_library("keboard_event_static") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"src/combination_key.cpp",
|
||||||
"src/input_event_callback.cpp",
|
"src/input_event_callback.cpp",
|
||||||
"src/keyboard_event.cpp",
|
"src/keyboard_event.cpp",
|
||||||
]
|
]
|
||||||
|
32
services/adapter/keyboard/include/combination_key.h
Normal file
32
services/adapter/keyboard/include/combination_key.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INPUTMETHOD_IMF_COMBINATION_KEY_H
|
||||||
|
#define INPUTMETHOD_IMF_COMBINATION_KEY_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace MiscServices {
|
||||||
|
enum class CombinationKeyFunction { SWITCH_LANGUAGE = 0, SWITCH_MODE, SWITCH_IME };
|
||||||
|
|
||||||
|
class CombinationKey {
|
||||||
|
public:
|
||||||
|
static bool IsMatch(CombinationKeyFunction combinationKey, uint32_t state);
|
||||||
|
};
|
||||||
|
} // namespace MiscServices
|
||||||
|
} // namespace OHOS
|
||||||
|
|
||||||
|
#endif // INPUTMETHOD_IMF_COMBINATION_KEY_H
|
@ -36,6 +36,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
KeyHandle keyHandler_ = nullptr;
|
KeyHandle keyHandler_ = nullptr;
|
||||||
static uint32_t keyState_;
|
static uint32_t keyState_;
|
||||||
|
static bool isKeyHandled_;
|
||||||
};
|
};
|
||||||
} // namespace MiscServices
|
} // namespace MiscServices
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "key_event.h"
|
#include "key_event.h"
|
||||||
@ -36,10 +35,6 @@ public:
|
|||||||
static constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2;
|
static constexpr uint8_t CTRL_LEFT_MASK = 0X1 << 2;
|
||||||
static constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3;
|
static constexpr uint8_t CTRL_RIGHT_MASK = 0X1 << 3;
|
||||||
static constexpr uint8_t CAPS_MASK = 0X1 << 4;
|
static constexpr uint8_t CAPS_MASK = 0X1 << 4;
|
||||||
static constexpr bool IS_KEYS_DOWN(uint32_t state, uint8_t mask)
|
|
||||||
{
|
|
||||||
return state == mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int32_t PRESS_KEY_DELAY_MS = 200;
|
static constexpr int32_t PRESS_KEY_DELAY_MS = 200;
|
||||||
|
48
services/adapter/keyboard/src/combination_key.cpp
Normal file
48
services/adapter/keyboard/src/combination_key.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "combination_key.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include "keyboard_event.h"
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace MiscServices {
|
||||||
|
const std::map<CombinationKeyFunction, std::set<uint8_t>> COMBINATION_KEY_MAP{
|
||||||
|
{ CombinationKeyFunction::SWITCH_LANGUAGE, { KeyboardEvent::SHIFT_LEFT_MASK, KeyboardEvent::SHIFT_RIGHT_MASK } },
|
||||||
|
{ CombinationKeyFunction::SWITCH_IME,
|
||||||
|
{
|
||||||
|
KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
|
||||||
|
KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
|
||||||
|
KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
|
||||||
|
KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
|
||||||
|
} },
|
||||||
|
{ CombinationKeyFunction::SWITCH_MODE, { KeyboardEvent::CAPS_MASK } },
|
||||||
|
};
|
||||||
|
|
||||||
|
bool CombinationKey::IsMatch(CombinationKeyFunction combinationKey, uint32_t state)
|
||||||
|
{
|
||||||
|
IMSA_HILOGD("combinationKey: %{public}d, state: %{public}d", combinationKey, state);
|
||||||
|
auto expectedKeys = COMBINATION_KEY_MAP.find(combinationKey);
|
||||||
|
if (expectedKeys == COMBINATION_KEY_MAP.end()) {
|
||||||
|
IMSA_HILOGD("known key function");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return expectedKeys->second.find(state) != expectedKeys->second.end();
|
||||||
|
}
|
||||||
|
} // namespace MiscServices
|
||||||
|
} // namespace OHOS
|
@ -20,6 +20,7 @@
|
|||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace MiscServices {
|
namespace MiscServices {
|
||||||
uint32_t InputEventCallback::keyState_ = static_cast<uint32_t>(0);
|
uint32_t InputEventCallback::keyState_ = static_cast<uint32_t>(0);
|
||||||
|
bool InputEventCallback::isKeyHandled_ = false;
|
||||||
const std::map<int32_t, uint8_t> MASK_MAP{
|
const std::map<int32_t, uint8_t> MASK_MAP{
|
||||||
{ MMI::KeyEvent::KEYCODE_SHIFT_LEFT, KeyboardEvent::SHIFT_LEFT_MASK },
|
{ MMI::KeyEvent::KEYCODE_SHIFT_LEFT, KeyboardEvent::SHIFT_LEFT_MASK },
|
||||||
{ MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, KeyboardEvent::SHIFT_RIGHT_MASK },
|
{ MMI::KeyEvent::KEYCODE_SHIFT_RIGHT, KeyboardEvent::SHIFT_RIGHT_MASK },
|
||||||
@ -35,6 +36,7 @@ void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) c
|
|||||||
auto currKey = MASK_MAP.find(keyCode);
|
auto currKey = MASK_MAP.find(keyCode);
|
||||||
if (currKey == MASK_MAP.end()) {
|
if (currKey == MASK_MAP.end()) {
|
||||||
IMSA_HILOGD("key code unknown");
|
IMSA_HILOGD("key code unknown");
|
||||||
|
keyState_ = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction);
|
IMSA_HILOGD("keyCode: %{public}d, keyAction: %{public}d", keyCode, keyAction);
|
||||||
@ -42,14 +44,24 @@ void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) c
|
|||||||
if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) {
|
if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN) {
|
||||||
IMSA_HILOGD("key %{public}d pressed down", keyCode);
|
IMSA_HILOGD("key %{public}d pressed down", keyCode);
|
||||||
keyState_ = static_cast<uint32_t>(keyState_ | currKey->second);
|
keyState_ = static_cast<uint32_t>(keyState_ | currKey->second);
|
||||||
|
if (keyCode == MMI::KeyEvent::KEYCODE_CAPS_LOCK) {
|
||||||
|
if (keyHandler_ != nullptr) {
|
||||||
|
int32_t ret = keyHandler_(keyState_);
|
||||||
|
IMSA_HILOGI("handle key event ret: %{public}d", ret);
|
||||||
|
}
|
||||||
|
isKeyHandled_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isKeyHandled_ = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyAction == MMI::KeyEvent::KEY_ACTION_UP) {
|
if (keyAction == MMI::KeyEvent::KEY_ACTION_UP) {
|
||||||
if (keyHandler_ != nullptr) {
|
if (keyHandler_ != nullptr && !isKeyHandled_) {
|
||||||
int32_t ret = keyHandler_(keyState_);
|
int32_t ret = keyHandler_(keyState_);
|
||||||
IMSA_HILOGI("handle key event ret: %{public}d", ret);
|
IMSA_HILOGI("handle key event ret: %{public}d", ret);
|
||||||
}
|
}
|
||||||
|
isKeyHandled_ = true;
|
||||||
keyState_ = static_cast<uint32_t>(keyState_ & ~currKey->second);
|
keyState_ = static_cast<uint32_t>(keyState_ & ~currKey->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "input_method_system_ability_stub.h"
|
#include "input_method_system_ability_stub.h"
|
||||||
#include "inputmethod_dump.h"
|
#include "inputmethod_dump.h"
|
||||||
#include "inputmethod_trace.h"
|
#include "inputmethod_trace.h"
|
||||||
#include "keyboard_event.h"
|
|
||||||
#include "peruser_session.h"
|
#include "peruser_session.h"
|
||||||
#include "system_ability.h"
|
#include "system_ability.h"
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "ability_manager_interface.h"
|
#include "ability_manager_interface.h"
|
||||||
#include "application_info.h"
|
#include "application_info.h"
|
||||||
#include "bundle_mgr_proxy.h"
|
#include "bundle_mgr_proxy.h"
|
||||||
|
#include "combination_key.h"
|
||||||
#include "common_event_support.h"
|
#include "common_event_support.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
@ -431,7 +432,7 @@ int32_t InputMethodSystemAbility::ListDisabledInputMethod(int32_t userId, std::v
|
|||||||
return ErrorCode::ERROR_NULL_POINTER;
|
return ErrorCode::ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
for (auto iter = props.begin(); iter != props.end();) {
|
for (auto iter = props.begin(); iter != props.end();) {
|
||||||
if (iter->name == filter->name && iter->id == filter->id) {
|
if (iter->name == filter->name) {
|
||||||
iter = props.erase(iter);
|
iter = props.erase(iter);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -996,30 +997,26 @@ int32_t InputMethodSystemAbility::SwitchByCombinationKey(uint32_t state)
|
|||||||
IMSA_HILOGE("GetCurrentInputMethodSubtype failed");
|
IMSA_HILOGE("GetCurrentInputMethodSubtype failed");
|
||||||
return ErrorCode::ERROR_EX_NULL_POINTER;
|
return ErrorCode::ERROR_EX_NULL_POINTER;
|
||||||
}
|
}
|
||||||
if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CAPS_MASK)) {
|
if (CombinationKey::IsMatch(CombinationKeyFunction::SWITCH_MODE, state)) {
|
||||||
IMSA_HILOGI("CAPS press");
|
IMSA_HILOGI("switch mode");
|
||||||
auto target = current->mode == "upper" ?
|
auto target = current->mode == "upper"
|
||||||
FindSubPropertyByCompare(current->id,
|
? FindSubPropertyByCompare(current->id,
|
||||||
[¤t](const SubProperty &property) { return property.mode == "lower"; }) :
|
[¤t](const SubProperty &property) { return property.mode == "lower"; })
|
||||||
FindSubPropertyByCompare(current->id,
|
: FindSubPropertyByCompare(current->id,
|
||||||
[¤t](const SubProperty &property) { return property.mode == "upper"; });
|
[¤t](const SubProperty &property) { return property.mode == "upper"; });
|
||||||
return SwitchInputMethod(target.id, target.label);
|
return SwitchInputMethod(target.id, target.label);
|
||||||
}
|
}
|
||||||
if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::SHIFT_LEFT_MASK) ||
|
if (CombinationKey::IsMatch(CombinationKeyFunction::SWITCH_LANGUAGE, state)) {
|
||||||
KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::SHIFT_RIGHT_MASK)) {
|
IMSA_HILOGI("switch language");
|
||||||
IMSA_HILOGI("SHIFT press");
|
auto target = current->language == "chinese"
|
||||||
auto target = current->language == "chinese" ?
|
? FindSubPropertyByCompare(current->id,
|
||||||
FindSubPropertyByCompare(current->id,
|
[¤t](const SubProperty &property) { return property.language == "english"; })
|
||||||
[¤t](const SubProperty &property) { return property.language == "english"; }) :
|
: FindSubPropertyByCompare(current->id,
|
||||||
FindSubPropertyByCompare(current->id,
|
[¤t](const SubProperty &property) { return property.language == "chinese"; });
|
||||||
[¤t](const SubProperty &property) { return property.language == "chinese"; });
|
|
||||||
return SwitchInputMethod(target.id, target.label);
|
return SwitchInputMethod(target.id, target.label);
|
||||||
}
|
}
|
||||||
if (KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_LEFT_MASK | KeyboardEvent::SHIFT_LEFT_MASK) ||
|
if (CombinationKey::IsMatch(CombinationKeyFunction::SWITCH_IME, state)) {
|
||||||
KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_LEFT_MASK | KeyboardEvent::SHIFT_RIGHT_MASK) ||
|
IMSA_HILOGI("switch ime");
|
||||||
KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_RIGHT_MASK | KeyboardEvent::SHIFT_LEFT_MASK) ||
|
|
||||||
KeyboardEvent::IS_KEYS_DOWN(state, KeyboardEvent::CTRL_RIGHT_MASK | KeyboardEvent::SHIFT_RIGHT_MASK)) {
|
|
||||||
IMSA_HILOGI("CTRL_SHIFT press");
|
|
||||||
std::vector<Property> props = {};
|
std::vector<Property> props = {};
|
||||||
auto ret = ListProperty(MAIN_USER_ID, props);
|
auto ret = ListProperty(MAIN_USER_ID, props);
|
||||||
if (ret != ErrorCode::NO_ERROR) {
|
if (ret != ErrorCode::NO_ERROR) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user