1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "libinput_adapter.h"
17
18 #include <regex>
19
20 #include "param_wrapper.h"
21 #include "property_reader.h"
22 #include "input_device_manager.h"
23 #include "input_windows_manager.h"
24 #include "key_event_normalize.h"
25
26 #undef MMI_LOG_DOMAIN
27 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
28 #undef MMI_LOG_TAG
29 #define MMI_LOG_TAG "LibinputAdapter"
30
31 #define VTRACKPAD_ID 100
32
33 namespace OHOS {
34 namespace MMI {
35 namespace {
36 constexpr int32_t WAIT_TIME_FOR_INPUT { 10 };
37 constexpr int32_t MAX_RETRY_COUNT { 5 };
38 constexpr int32_t MIN_RIGHT_BTN_AREA_PERCENT { 0 };
39 constexpr int32_t MAX_RIGHT_BTN_AREA_PERCENT { 100 };
40 constexpr int32_t INVALID_RIGHT_BTN_AREA { -1 };
41 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
42 constexpr int32_t VKEY_TP_SM_MSG_SIZE { 6 };
43 constexpr int32_t VKEY_TP_SM_MSG_TYPE_IDX { 0 };
44 constexpr int32_t VKEY_TP_SM_MSG_POINTER_ID_IDX { 1 };
45 constexpr int32_t VKEY_TP_SM_MSG_POS_X_IDX { 2 };
46 constexpr int32_t VKEY_TP_SM_MSG_POS_Y_IDX { 3 };
47 constexpr int32_t VKEY_TP_SM_MSG_SCALE_IDX { 4 };
48 constexpr int32_t VKEY_TP_SM_MSG_ANGLE_IDX { 5 };
49 constexpr int32_t VKEY_TP_GSE_TWO_FINGERS { 2 };
50 constexpr uint32_t VKEY_TP_LB_ID { 272 };
51 constexpr uint32_t VKEY_TP_RB_ID { 273 };
52 constexpr uint32_t VKEY_TP_SEAT_BTN_COUNT_NONE { 0 };
53 constexpr uint32_t VKEY_TP_SEAT_BTN_COUNT_ONE { 1 };
54 constexpr uint32_t VKEY_TP_AXES_ZERO { 0 };
55 constexpr uint32_t VKEY_TP_AXES_ONE { 1 };
56 constexpr uint32_t VKEY_TP_AXES_TWO { 2 };
57 constexpr double VTP_SCALE_AND_ANGLE_FACTOR { 1000.0 };
58 constexpr uint32_t KEY_CAPSLOCK { 58 };
59 constexpr uint32_t LIBINPUT_KEY_VOLUME_DOWN { 114 };
60 constexpr uint32_t LIBINPUT_KEY_VOLUME_UP { 115 };
61 constexpr uint32_t LIBINPUT_KEY_POWER { 116 };
62 constexpr uint32_t LIBINPUT_KEY_FN { 240 };
63 constexpr float SCREEN_CAPTURE_WINDOW_ZORDER { 8000.0 };
64 enum class VKeyboardTouchEventType : int32_t {
65 TOUCH_DOWN = 0,
66 TOUCH_UP = 1,
67 TOUCH_MOVE = 2,
68 TOUCH_FRAME = 3,
69 };
70 #define SCREEN_RECORD_WINDOW_WIDTH 400
71 #define SCREEN_RECORD_WINDOW_HEIGHT 200
72 #else // OHOS_BUILD_ENABLE_VKEYBOARD
73 constexpr uint32_t KEY_CAPSLOCK { 58 };
74 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
75
HiLogFunc(struct libinput * input,libinput_log_priority priority,const char * fmt,va_list args)76 void HiLogFunc(struct libinput* input, libinput_log_priority priority, const char* fmt, va_list args)
77 {
78 CHKPV(input);
79 CHKPV(fmt);
80 char buffer[256] = {};
81 if (vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, fmt, args) == -1) {
82 MMI_HILOGE("Call vsnprintf_s failed");
83 va_end(args);
84 return;
85 }
86 if (strstr(buffer, "LOG_LEVEL_I") != nullptr) {
87 MMI_HILOGI("PrintLog_Info:%{public}s", buffer);
88 } else if (strstr(buffer, "LOG_LEVEL_D") != nullptr) {
89 MMI_HILOGD("PrintLog_Info:%{public}s", buffer);
90 } else if (strstr(buffer, "LOG_LEVEL_E") != nullptr) {
91 MMI_HILOGE("PrintLog_Info:%{public}s", buffer);
92 } else {
93 MMI_HILOGD("PrintLog_Info:%{public}s", buffer);
94 }
95 va_end(args);
96 }
97 } // namespace
98
DeviceLedUpdate(struct libinput_device * device,int32_t funcKey,bool enable)99 int32_t LibinputAdapter::DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool enable)
100 {
101 CHKPR(device, RET_ERR);
102 return libinput_set_led_state(device, funcKey, enable);
103 }
104
InitRightButtonAreaConfig()105 void LibinputAdapter::InitRightButtonAreaConfig()
106 {
107 CHKPV(input_);
108
109 int32_t height_percent = OHOS::system::GetIntParameter("const.multimodalinput.rightclick_y_percentage",
110 INVALID_RIGHT_BTN_AREA);
111 if ((height_percent <= MIN_RIGHT_BTN_AREA_PERCENT) || (height_percent > MAX_RIGHT_BTN_AREA_PERCENT)) {
112 MMI_HILOGE("Right button area height percent param is invalid");
113 return;
114 }
115
116 int32_t width_percent = OHOS::system::GetIntParameter("const.multimodalinput.rightclick_x_percentage",
117 INVALID_RIGHT_BTN_AREA);
118 if ((width_percent <= MIN_RIGHT_BTN_AREA_PERCENT) || (width_percent > MAX_RIGHT_BTN_AREA_PERCENT)) {
119 MMI_HILOGE("Right button area width percent param is invalid");
120 return;
121 }
122
123 auto status = libinput_config_rightbutton_area(input_, height_percent, width_percent);
124 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
125 MMI_HILOGE("Config the touchpad right button area failed");
126 }
127 }
128
129 constexpr static libinput_interface LIBINPUT_INTERFACE = {
__anonc299d1aa0202()130 .open_restricted = [](const char *path, int32_t flags, void *user_data)->int32_t {
131 if (path == nullptr) {
132 MMI_HILOGWK("Input device path is nullptr");
133 return RET_ERR;
134 }
135 char realPath[PATH_MAX] = {};
136 if (realpath(path, realPath) == nullptr) {
137 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_FOR_INPUT));
138 MMI_HILOGWK("The error path is %{public}s", path);
139 return RET_ERR;
140 }
141 int32_t fd = 0;
142 for (int32_t i = 0; i < MAX_RETRY_COUNT; i++) {
143 fd = open(realPath, flags);
144 if (fd >= 0) {
145 break;
146 }
147 std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_FOR_INPUT));
148 }
149 int32_t errNo = errno;
150 std::regex re("(\\d+)");
151 std::string str_path(path);
152 std::smatch match;
153 int32_t id;
154 bool isPath = std::regex_search(str_path, match, re);
155 if (!isPath) {
156 id = -1;
157 } else {
158 id = std::stoi(match[0]);
159 }
160 MMI_HILOGWK("Libinput .open_restricted id:%{public}d, fd:%{public}d, errno:%{public}d",
161 id, fd, errNo);
162 return fd < 0 ? RET_ERR : fd;
163 },
164 .close_restricted = [](int32_t fd, void *user_data)
__anonc299d1aa0302() 165 {
166 if (fd < 0) {
167 return;
168 }
169 MMI_HILOGI("Libinput .close_restricted fd:%{public}d", fd);
170 close(fd);
171 },
172 };
173
Init(FunInputEvent funInputEvent)174 bool LibinputAdapter::Init(FunInputEvent funInputEvent)
175 {
176 CALL_DEBUG_ENTER;
177 CHKPF(funInputEvent);
178 funInputEvent_ = funInputEvent;
179 input_ = libinput_path_create_context(&LIBINPUT_INTERFACE, nullptr);
180 CHKPF(input_);
181 libinput_log_set_handler(input_, &HiLogFunc);
182 fd_ = libinput_get_fd(input_);
183 if (fd_ < 0) {
184 libinput_unref(input_);
185 fd_ = -1;
186 MMI_HILOGE("The fd_ is less than 0");
187 return false;
188 }
189 InitRightButtonAreaConfig();
190 return hotplugDetector_.Init([this](std::string path) { OnDeviceAdded(std::move(path)); },
191 [this](std::string path) { OnDeviceRemoved(std::move(path)); });
192 }
193
EventDispatch(int32_t fd)194 void LibinputAdapter::EventDispatch(int32_t fd)
195 {
196 CALL_DEBUG_ENTER;
197 if (fd == fd_) {
198 MMI_HILOGD("Start to libinput_dispatch");
199 if (libinput_dispatch(input_) != 0) {
200 MMI_HILOGE("Failed to dispatch libinput");
201 return;
202 }
203 OnEventHandler();
204 MMI_HILOGD("End to OnEventHandler");
205 } else if (fd == hotplugDetector_.GetFd()) {
206 hotplugDetector_.OnEvent();
207 } else {
208 MMI_HILOGE("EventDispatch() called with unknown fd:%{public}d", fd);
209 }
210 }
211
Stop()212 void LibinputAdapter::Stop()
213 {
214 CALL_DEBUG_ENTER;
215 hotplugDetector_.Stop();
216 if (fd_ >= 0) {
217 close(fd_);
218 fd_ = -1;
219 }
220 if (input_ != nullptr) {
221 libinput_unref(input_);
222 input_ = nullptr;
223 }
224 }
225
ProcessPendingEvents()226 void LibinputAdapter::ProcessPendingEvents()
227 {
228 OnEventHandler();
229 }
230
InitVKeyboard(HandleTouchPoint handleTouchPoint,GetMessage getMessage,GetAllTouchMessage getAllTouchMessage,ClearTouchMessage clearTouchMessage,GetAllKeyMessage getAllKeyMessage,ClearKeyMessage clearKeyMessage,HardwareKeyEventDetected hardwareKeyEventDetected,GetKeyboardActivationState getKeyboardActivationState)231 void LibinputAdapter::InitVKeyboard(HandleTouchPoint handleTouchPoint,
232 GetMessage getMessage,
233 GetAllTouchMessage getAllTouchMessage,
234 ClearTouchMessage clearTouchMessage,
235 GetAllKeyMessage getAllKeyMessage,
236 ClearKeyMessage clearKeyMessage,
237 HardwareKeyEventDetected hardwareKeyEventDetected,
238 GetKeyboardActivationState getKeyboardActivationState)
239 {
240 handleTouchPoint_ = handleTouchPoint;
241 getMessage_ = getMessage;
242 getAllTouchMessage_ = getAllTouchMessage;
243 clearTouchMessage_ = clearTouchMessage;
244 getAllKeyMessage_ = getAllKeyMessage;
245 clearKeyMessage_ = clearKeyMessage;
246 hardwareKeyEventDetected_ = hardwareKeyEventDetected;
247 getKeyboardActivationState_ = getKeyboardActivationState;
248
249 deviceId = -1;
250
251 auto vTrackpad = std::make_shared<InputDevice>();
252 vTrackpad->SetName("VirtualTrackpad");
253 vTrackpad->AddCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER);
254 vTrackpad->AddCapability(InputDeviceCapability::INPUT_DEV_CAP_KEYBOARD);
255 int32_t trackpadId = VTRACKPAD_ID;
256 InputDeviceManager::GetInstance()->AddVirtualInputDevice(vTrackpad, trackpadId);
257 }
258
InjectKeyEvent(libinput_event_touch * touch,int32_t keyCode,libinput_key_state state,int64_t frameTime)259 void LibinputAdapter::InjectKeyEvent(libinput_event_touch* touch, int32_t keyCode,
260 libinput_key_state state, int64_t frameTime)
261 {
262 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
263 libinput_event_keyboard* key_event_pressed =
264 libinput_create_keyboard_event(touch, keyCode, state);
265
266 if (keyCode == KEY_CAPSLOCK && state == libinput_key_state::LIBINPUT_KEY_STATE_PRESSED) {
267 struct libinput_device* device = INPUT_DEV_MGR->GetKeyboardDevice();
268 if (device != nullptr) {
269 std::shared_ptr<KeyEvent> keyEvent = KeyEventHdr->GetKeyEvent();
270 if (keyEvent != nullptr) {
271 bool isCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY);
272
273 DeviceLedUpdate(device, KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn);
274 keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !isCapsLockOn);
275 }
276 }
277 }
278
279 funInputEvent_((libinput_event*)key_event_pressed, frameTime);
280 free(key_event_pressed);
281 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
282 }
283
284 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
HandleVFullKeyboardMessages(libinput_event * event,int64_t frameTime,libinput_event_type eventType,libinput_event_touch * touch)285 void LibinputAdapter::HandleVFullKeyboardMessages(
286 libinput_event *event, int64_t frameTime, libinput_event_type eventType, libinput_event_touch *touch)
287 {
288 // handle keyboard and trackpad messages.
289 while (true) {
290 int32_t toggleCodeFirst(-1);
291 int32_t toggleCodeSecond(-1);
292 int32_t keyCode(-1);
293 VKeyboardMessageType type = (VKeyboardMessageType)getMessage_(toggleCodeFirst, toggleCodeSecond, keyCode);
294 MMI_HILOGD("Get message type:%{private}d", static_cast<int32_t>(type));
295 if (type == VNoMessage) {
296 break;
297 }
298
299 switch (type) {
300 case VKeyboardMessageType::VKeyPressed: {
301 MMI_HILOGD("press key:%{private}d", keyCode);
302 InjectKeyEvent(touch, keyCode, libinput_key_state::LIBINPUT_KEY_STATE_PRESSED, frameTime);
303 InjectKeyEvent(touch, keyCode, libinput_key_state::LIBINPUT_KEY_STATE_RELEASED, frameTime);
304 break;
305 }
306 case VKeyboardMessageType::VStartLongPressControl: {
307 MMI_HILOGD("long press start:%{private}d", keyCode);
308 InjectKeyEvent(touch, keyCode, libinput_key_state::LIBINPUT_KEY_STATE_PRESSED, frameTime);
309 break;
310 }
311 case VKeyboardMessageType::VStopLongPressControl: {
312 MMI_HILOGD("long press stop:%{private}d", keyCode);
313 InjectKeyEvent(touch, keyCode, libinput_key_state::LIBINPUT_KEY_STATE_RELEASED, frameTime);
314 break;
315 }
316 case VKeyboardMessageType::VSwitchLayout: {
317 HideMouseCursorTemporary();
318 break;
319 }
320 default:
321 break;
322 }
323 }
324 HandleVKeyTouchpadMessages(touch);
325
326 if (eventType == LIBINPUT_EVENT_TOUCH_FRAME) {
327 // still let frame info go through.
328 funInputEvent_(event, frameTime);
329 }
330 libinput_event_destroy(event);
331 }
332
HandleVKeyTouchpadMessages(libinput_event_touch * touch)333 void LibinputAdapter::HandleVKeyTouchpadMessages(libinput_event_touch* touch)
334 {
335 // Handle all track pad key messages
336 std::vector<std::vector<int32_t>> keyMsgList;
337 if (getAllKeyMessage_ != nullptr) {
338 getAllKeyMessage_(keyMsgList);
339 }
340 if (clearKeyMessage_ != nullptr) {
341 clearKeyMessage_();
342 }
343 if (!keyMsgList.empty()) {
344 ShowMouseCursor();
345 }
346 OnVKeyTrackPadMessage(touch, keyMsgList);
347 // Handle all track pad touch messages
348 std::vector<std::vector<int32_t>> touchMsgList;
349 if (getAllTouchMessage_ != nullptr) {
350 getAllTouchMessage_(touchMsgList);
351 }
352 if (clearTouchMessage_ != nullptr) {
353 clearTouchMessage_();
354 }
355 if (!touchMsgList.empty()) {
356 ShowMouseCursor();
357 }
358 OnVKeyTrackPadMessage(touch, touchMsgList);
359 }
360
OnVKeyTrackPadMessage(libinput_event_touch * touch,const std::vector<std::vector<int32_t>> & msgList)361 void LibinputAdapter::OnVKeyTrackPadMessage(libinput_event_touch* touch,
362 const std::vector<std::vector<int32_t>>& msgList)
363 {
364 for (auto msgItem : msgList) {
365 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
366 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
367 static_cast<int32_t>(msgItem.size()));
368 continue;
369 }
370 auto msgType = static_cast<VTPStateMachineMessageType>(msgItem[VKEY_TP_SM_MSG_TYPE_IDX]);
371 switch (msgType) {
372 case VTPStateMachineMessageType::POINTER_MOVE:
373 if (!HandleVKeyTrackPadPointerMove(touch, msgItem)) {
374 MMI_HILOGE("Virtual TrackPad pointer move event cannot be handled");
375 }
376 break;
377 case VTPStateMachineMessageType::LEFT_CLICK_DOWN:
378 case VTPStateMachineMessageType::LEFT_TOUCH_DOWN:
379 if (!HandleVKeyTrackPadLeftBtnDown(touch, msgItem)) {
380 MMI_HILOGE("Virtual TrackPad left button down event cannot be handled");
381 }
382 break;
383 case VTPStateMachineMessageType::LEFT_CLICK_UP:
384 case VTPStateMachineMessageType::LEFT_TOUCH_UP:
385 if (!HandleVKeyTrackPadLeftBtnUp(touch, msgItem)) {
386 MMI_HILOGE("Virtual TrackPad left button up event cannot be handled");
387 }
388 break;
389 case VTPStateMachineMessageType::RIGHT_CLICK_DOWN:
390 if (!HandleVKeyTrackPadRightBtnDown(touch, msgItem)) {
391 MMI_HILOGE("Virtual TrackPad right button down event cannot be handled");
392 }
393 break;
394 case VTPStateMachineMessageType::RIGHT_CLICK_UP:
395 if (!HandleVKeyTrackPadRightBtnUp(touch, msgItem)) {
396 MMI_HILOGE("Virtual TrackPad right button up event cannot be handled");
397 }
398 break;
399 default:
400 OnVKeyTrackPadGestureMessage(touch, msgType, msgItem);
401 break;
402 }
403 }
404 }
405
OnVKeyTrackPadGestureMessage(libinput_event_touch * touch,VTPStateMachineMessageType msgType,const std::vector<int32_t> & msgItem)406 void LibinputAdapter::OnVKeyTrackPadGestureMessage(libinput_event_touch* touch,
407 VTPStateMachineMessageType msgType, const std::vector<int32_t>& msgItem)
408 {
409 switch (msgType) {
410 case VTPStateMachineMessageType::SCROLL_BEGIN:
411 if (!HandleVKeyTrackPadScrollBegin(touch, msgItem)) {
412 MMI_HILOGE("Virtual TrackPad scroll begin event cannot be handled");
413 }
414 break;
415 case VTPStateMachineMessageType::SCROLL_UPDATE:
416 if (!HandleVKeyTrackPadScrollUpdate(touch, msgItem)) {
417 MMI_HILOGE("Virtual TrackPad scroll update event cannot be handled");
418 }
419 break;
420 case VTPStateMachineMessageType::SCROLL_END:
421 if (!HandleVKeyTrackPadScrollEnd(touch, msgItem)) {
422 MMI_HILOGE("Virtual TrackPad scroll end event cannot be handled");
423 }
424 break;
425 case VTPStateMachineMessageType::PINCH_BEGIN:
426 if (!HandleVKeyTrackPadPinchBegin(touch, msgItem)) {
427 MMI_HILOGE("Virtual TrackPad pinch begin event cannot be handled");
428 }
429 break;
430 case VTPStateMachineMessageType::PINCH_UPDATE:
431 if (!HandleVKeyTrackPadPinchUpdate(touch, msgItem)) {
432 MMI_HILOGE("Virtual TrackPad pinch update event cannot be handled");
433 }
434 break;
435 case VTPStateMachineMessageType::PINCH_END:
436 if (!HandleVKeyTrackPadPinchEnd(touch, msgItem)) {
437 MMI_HILOGE("Virtual TrackPad pinch end event cannot be handled");
438 }
439 break;
440 default:
441 OnVKeyTrackPadGestureTwoMessage(touch, msgType, msgItem);
442 break;
443 }
444 }
445
OnVKeyTrackPadGestureTwoMessage(libinput_event_touch * touch,VTPStateMachineMessageType msgType,const std::vector<int32_t> & msgItem)446 void LibinputAdapter::OnVKeyTrackPadGestureTwoMessage(libinput_event_touch* touch,
447 VTPStateMachineMessageType msgType, const std::vector<int32_t>& msgItem)
448 {
449 switch (msgType) {
450 case VTPStateMachineMessageType::PAN_BEGIN:
451 if (!HandleVKeyTrackPadPanBegin(touch, msgItem)) {
452 MMI_HILOGE("Virtual TrackPad pan begin event cannot be handled");
453 }
454 break;
455 case VTPStateMachineMessageType::PAN_UPDATE:
456 if (!HandleVKeyTrackPadPanUpdate(touch, msgItem)) {
457 MMI_HILOGE("Virtual TrackPad pan update event cannot be handled");
458 }
459 break;
460 case VTPStateMachineMessageType::PAN_END:
461 if (!HandleVKeyTrackPadPanEnd(touch, msgItem)) {
462 MMI_HILOGE("Virtual TrackPad pan end event cannot be handled");
463 }
464 break;
465 case VTPStateMachineMessageType::ROT_BEGIN:
466 if (!HandleVKeyTrackPadRotateBegin(touch, msgItem)) {
467 MMI_HILOGE("Virtual TrackPad rotate begin event cannot be handled");
468 }
469 break;
470 case VTPStateMachineMessageType::ROT_UPDATE:
471 if (!HandleVKeyTrackPadRotateUpdate(touch, msgItem)) {
472 MMI_HILOGE("Virtual TrackPad rotate update event cannot be handled");
473 }
474 break;
475 case VTPStateMachineMessageType::ROT_END:
476 if (!HandleVKeyTrackPadRotateEnd(touch, msgItem)) {
477 MMI_HILOGE("Virtual TrackPad rotate end event cannot be handled");
478 }
479 break;
480 default:
481 break;
482 }
483 }
484
HandleVKeyTrackPadPointerMove(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)485 bool LibinputAdapter::HandleVKeyTrackPadPointerMove(libinput_event_touch* touch,
486 const std::vector<int32_t>& msgItem)
487 {
488 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
489 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
490 static_cast<int32_t>(msgItem.size()));
491 return false;
492 }
493 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
494 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
495 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
496 event_pointer pEvent;
497 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_MOTION_TOUCHPAD;
498 pEvent.delta_raw_x = msgPPosX;
499 pEvent.delta_raw_y = msgPPosY;
500 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
501 PrintVKeyTPPointerLog(pEvent);
502 int64_t frameTime = GetSysClockTime();
503 funInputEvent_((libinput_event*)lpEvent, frameTime);
504 free(lpEvent);
505 return true;
506 }
507
HandleVKeyTrackPadLeftBtnDown(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)508 bool LibinputAdapter::HandleVKeyTrackPadLeftBtnDown(libinput_event_touch* touch,
509 const std::vector<int32_t>& msgItem)
510 {
511 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
512 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
513 static_cast<int32_t>(msgItem.size()));
514 return false;
515 }
516 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
517 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
518 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
519 event_pointer pEvent;
520 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD;
521 pEvent.button = VKEY_TP_LB_ID;
522 pEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_ONE;
523 pEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_PRESSED;
524 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
525 PrintVKeyTPPointerLog(pEvent);
526 int64_t frameTime = GetSysClockTime();
527 funInputEvent_((libinput_event*)lpEvent, frameTime);
528 free(lpEvent);
529 return true;
530 }
531
HandleVKeyTrackPadLeftBtnUp(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)532 bool LibinputAdapter::HandleVKeyTrackPadLeftBtnUp(libinput_event_touch* touch,
533 const std::vector<int32_t>& msgItem)
534 {
535 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
536 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
537 static_cast<int32_t>(msgItem.size()));
538 return false;
539 }
540 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
541 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
542 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
543 event_pointer pEvent;
544 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_BUTTON_TOUCHPAD;
545 pEvent.button = VKEY_TP_LB_ID;
546 pEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_NONE;
547 pEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_RELEASED;
548 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
549 PrintVKeyTPPointerLog(pEvent);
550 int64_t frameTime = GetSysClockTime();
551 funInputEvent_((libinput_event*)lpEvent, frameTime);
552 free(lpEvent);
553 return true;
554 }
555
HandleVKeyTrackPadRightBtnDown(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)556 bool LibinputAdapter::HandleVKeyTrackPadRightBtnDown(libinput_event_touch* touch,
557 const std::vector<int32_t>& msgItem)
558 {
559 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
560 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
561 static_cast<int32_t>(msgItem.size()));
562 return false;
563 }
564 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
565 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
566 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
567 event_pointer pEvent;
568 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_BUTTON;
569 pEvent.button = VKEY_TP_RB_ID;
570 pEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_ONE;
571 pEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_PRESSED;
572 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
573 PrintVKeyTPPointerLog(pEvent);
574 int64_t frameTime = GetSysClockTime();
575 funInputEvent_((libinput_event*)lpEvent, frameTime);
576 free(lpEvent);
577 return true;
578 }
579
HandleVKeyTrackPadRightBtnUp(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)580 bool LibinputAdapter::HandleVKeyTrackPadRightBtnUp(libinput_event_touch* touch,
581 const std::vector<int32_t>& msgItem)
582 {
583 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
584 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
585 static_cast<int32_t>(msgItem.size()));
586 return false;
587 }
588 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
589 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
590 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
591 event_pointer pEvent;
592 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_BUTTON;
593 pEvent.button = VKEY_TP_RB_ID;
594 pEvent.seat_button_count = VKEY_TP_SEAT_BTN_COUNT_NONE;
595 pEvent.state = libinput_button_state::LIBINPUT_BUTTON_STATE_RELEASED;
596 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
597 PrintVKeyTPPointerLog(pEvent);
598 int64_t frameTime = GetSysClockTime();
599 funInputEvent_((libinput_event*)lpEvent, frameTime);
600 free(lpEvent);
601 return true;
602 }
603
HandleVKeyTrackPadScrollBegin(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)604 bool LibinputAdapter::HandleVKeyTrackPadScrollBegin(libinput_event_touch* touch,
605 const std::vector<int32_t>& msgItem)
606 {
607 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
608 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
609 static_cast<int32_t>(msgItem.size()));
610 return false;
611 }
612 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
613 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
614 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
615 MMI_HILOGI("VKey TrackPad Scroll Begin");
616 event_pointer pEvent;
617 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER_BEGIN;
618 pEvent.delta_x = msgPPosX;
619 pEvent.delta_y = msgPPosY;
620 pEvent.delta_raw_x = msgPPosX;
621 pEvent.delta_raw_y = msgPPosY;
622 pEvent.axes = VKEY_TP_AXES_ZERO;
623 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
624 PrintVKeyTPPointerLog(pEvent);
625 int64_t frameTime = GetSysClockTime();
626 funInputEvent_((libinput_event*)lpEvent, frameTime);
627 free(lpEvent);
628 return true;
629 }
630
HandleVKeyTrackPadScrollUpdate(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)631 bool LibinputAdapter::HandleVKeyTrackPadScrollUpdate(libinput_event_touch* touch,
632 const std::vector<int32_t>& msgItem)
633 {
634 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
635 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
636 static_cast<int32_t>(msgItem.size()));
637 return false;
638 }
639 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
640 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
641 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
642 MMI_HILOGI("VKey TrackPad Scroll Update");
643 event_pointer pEvent;
644 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_AXIS;
645 pEvent.delta_x = msgPPosX;
646 pEvent.delta_y = msgPPosY;
647 pEvent.delta_raw_x = msgPPosX;
648 pEvent.delta_raw_y = msgPPosY;
649 pEvent.source = libinput_pointer_axis_source::LIBINPUT_POINTER_AXIS_SOURCE_FINGER;
650 pEvent.axes = VKEY_TP_AXES_ONE;
651 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
652 PrintVKeyTPPointerLog(pEvent);
653 int64_t frameTime = GetSysClockTime();
654 funInputEvent_((libinput_event*)lpEvent, frameTime);
655 free(lpEvent);
656 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
657 lpEvent = libinput_create_pointer_event(touch, pEvent);
658 PrintVKeyTPPointerLog(pEvent);
659 frameTime = GetSysClockTime();
660 funInputEvent_((libinput_event*)lpEvent, frameTime);
661 free(lpEvent);
662 return true;
663 }
664
HandleVKeyTrackPadScrollEnd(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)665 bool LibinputAdapter::HandleVKeyTrackPadScrollEnd(libinput_event_touch* touch,
666 const std::vector<int32_t>& msgItem)
667 {
668 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
669 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
670 static_cast<int32_t>(msgItem.size()));
671 return false;
672 }
673 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
674 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
675 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
676 MMI_HILOGI("VKey TrackPad Scroll End");
677 event_pointer pEvent;
678 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER_END;
679 pEvent.delta_x = msgPPosX;
680 pEvent.delta_y = msgPPosY;
681 pEvent.delta_raw_x = msgPPosX;
682 pEvent.delta_raw_y = msgPPosY;
683 pEvent.axes = VKEY_TP_AXES_ZERO;
684 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
685 PrintVKeyTPPointerLog(pEvent);
686 int64_t frameTime = GetSysClockTime();
687 funInputEvent_((libinput_event*)lpEvent, frameTime);
688 free(lpEvent);
689 return true;
690 }
691
HandleVKeyTrackPadPinchBegin(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)692 bool LibinputAdapter::HandleVKeyTrackPadPinchBegin(libinput_event_touch* touch,
693 const std::vector<int32_t>& msgItem)
694 {
695 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
696 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
697 static_cast<int32_t>(msgItem.size()));
698 return false;
699 }
700 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
701 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
702 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
703 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
704 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
705 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
706 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
707 MMI_HILOGI("VKey TrackPad Pinch Begin");
708 event_gesture gEvent;
709 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_BEGIN;
710 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
711 gEvent.cancelled = 0;
712 gEvent.delta_x = msgPPosX;
713 gEvent.delta_y = msgPPosY;
714 gEvent.delta_unaccel_x = msgPPosX;
715 gEvent.delta_unaccel_y = msgPPosY;
716 sloted_coords_info slotInfo;
717 gEvent.solt_touches = slotInfo;
718 gEvent.scale = scaleToDouble;
719 gEvent.angle = angleToDouble;
720 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
721 PrintVKeyTPGestureLog(gEvent);
722 int64_t frameTime = GetSysClockTime();
723 funInputEvent_((libinput_event*)lgEvent, frameTime);
724 free(lgEvent);
725 return true;
726 }
727
HandleVKeyTrackPadPinchUpdate(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)728 bool LibinputAdapter::HandleVKeyTrackPadPinchUpdate(libinput_event_touch* touch,
729 const std::vector<int32_t>& msgItem)
730 {
731 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
732 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
733 static_cast<int32_t>(msgItem.size()));
734 return false;
735 }
736 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
737 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
738 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
739 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
740 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
741 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
742 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
743 MMI_HILOGI("VKey TrackPad Pinch Update");
744 event_gesture gEvent;
745 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_UPDATE;
746 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
747 gEvent.cancelled = 0;
748 gEvent.delta_x = msgPPosX;
749 gEvent.delta_y = msgPPosY;
750 gEvent.delta_unaccel_x = msgPPosX;
751 gEvent.delta_unaccel_y = msgPPosY;
752 sloted_coords_info slotInfo;
753 gEvent.solt_touches = slotInfo;
754 gEvent.scale = scaleToDouble;
755 gEvent.angle = angleToDouble;
756 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
757 PrintVKeyTPGestureLog(gEvent);
758 int64_t frameTime = GetSysClockTime();
759 funInputEvent_((libinput_event*)lgEvent, frameTime);
760 free(lgEvent);
761 return true;
762 }
763
HandleVKeyTrackPadPinchEnd(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)764 bool LibinputAdapter::HandleVKeyTrackPadPinchEnd(libinput_event_touch* touch,
765 const std::vector<int32_t>& msgItem)
766 {
767 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
768 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
769 static_cast<int32_t>(msgItem.size()));
770 return false;
771 }
772 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
773 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
774 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
775 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
776 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
777 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
778 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
779 MMI_HILOGI("VKey TrackPad Pinch End");
780 event_gesture gEvent;
781 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_END;
782 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
783 gEvent.cancelled = 0;
784 gEvent.delta_x = msgPPosX;
785 gEvent.delta_y = msgPPosY;
786 gEvent.delta_unaccel_x = msgPPosX;
787 gEvent.delta_unaccel_y = msgPPosY;
788 sloted_coords_info slotInfo;
789 gEvent.solt_touches = slotInfo;
790 gEvent.scale = scaleToDouble;
791 gEvent.angle = angleToDouble;
792 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
793 PrintVKeyTPGestureLog(gEvent);
794 int64_t frameTime = GetSysClockTime();
795 funInputEvent_((libinput_event*)lgEvent, frameTime);
796 free(lgEvent);
797 return true;
798 }
799
HandleVKeyTrackPadPanBegin(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)800 bool LibinputAdapter::HandleVKeyTrackPadPanBegin(libinput_event_touch* touch,
801 const std::vector<int32_t>& msgItem)
802 {
803 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
804 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
805 static_cast<int32_t>(msgItem.size()));
806 return false;
807 }
808 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
809 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
810 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
811 MMI_HILOGI("VKey TrackPad Pan Begin");
812 event_pointer pEvent;
813 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER_BEGIN;
814 pEvent.delta_x = msgPPosX;
815 pEvent.delta_y = msgPPosY;
816 pEvent.delta_raw_x = msgPPosX;
817 pEvent.delta_raw_y = msgPPosY;
818 pEvent.axes = VKEY_TP_AXES_ZERO;
819 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
820 PrintVKeyTPPointerLog(pEvent);
821 int64_t frameTime = GetSysClockTime();
822 funInputEvent_((libinput_event*)lpEvent, frameTime);
823 free(lpEvent);
824 return true;
825 }
826
HandleVKeyTrackPadPanUpdate(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)827 bool LibinputAdapter::HandleVKeyTrackPadPanUpdate(libinput_event_touch* touch,
828 const std::vector<int32_t>& msgItem)
829 {
830 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
831 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
832 static_cast<int32_t>(msgItem.size()));
833 return false;
834 }
835 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
836 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
837 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
838 MMI_HILOGI("VKey TrackPad Pan Update");
839 event_pointer pEvent;
840 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_AXIS;
841 pEvent.delta_x = msgPPosX;
842 pEvent.delta_y = msgPPosY;
843 pEvent.delta_raw_x = msgPPosX;
844 pEvent.delta_raw_y = msgPPosY;
845 pEvent.source = libinput_pointer_axis_source::LIBINPUT_POINTER_AXIS_SOURCE_FINGER;
846 pEvent.axes = VKEY_TP_AXES_TWO;
847 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
848 PrintVKeyTPPointerLog(pEvent);
849 int64_t frameTime = GetSysClockTime();
850 funInputEvent_((libinput_event*)lpEvent, frameTime);
851 free(lpEvent);
852 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
853 lpEvent = libinput_create_pointer_event(touch, pEvent);
854 PrintVKeyTPPointerLog(pEvent);
855 frameTime = GetSysClockTime();
856 funInputEvent_((libinput_event*)lpEvent, frameTime);
857 free(lpEvent);
858 return true;
859 }
860
HandleVKeyTrackPadPanEnd(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)861 bool LibinputAdapter::HandleVKeyTrackPadPanEnd(libinput_event_touch* touch,
862 const std::vector<int32_t>& msgItem)
863 {
864 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
865 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
866 static_cast<int32_t>(msgItem.size()));
867 return false;
868 }
869 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
870 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
871 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
872 MMI_HILOGI("VKey TrackPad Pan End");
873 event_pointer pEvent;
874 pEvent.event_type = libinput_event_type::LIBINPUT_EVENT_POINTER_SCROLL_FINGER_END;
875 pEvent.delta_x = msgPPosX;
876 pEvent.delta_y = msgPPosY;
877 pEvent.delta_raw_x = msgPPosX;
878 pEvent.delta_raw_y = msgPPosY;
879 pEvent.axes = VKEY_TP_AXES_ZERO;
880 libinput_event_pointer* lpEvent = libinput_create_pointer_event(touch, pEvent);
881 PrintVKeyTPPointerLog(pEvent);
882 int64_t frameTime = GetSysClockTime();
883 funInputEvent_((libinput_event*)lpEvent, frameTime);
884 free(lpEvent);
885 return true;
886 }
887
HandleVKeyTrackPadRotateBegin(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)888 bool LibinputAdapter::HandleVKeyTrackPadRotateBegin(libinput_event_touch* touch,
889 const std::vector<int32_t>& msgItem)
890 {
891 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
892 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
893 static_cast<int32_t>(msgItem.size()));
894 return false;
895 }
896 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
897 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
898 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
899 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
900 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
901 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
902 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
903 MMI_HILOGI("VKey TrackPad Rotate Begin");
904 event_gesture gEvent;
905 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_BEGIN;
906 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
907 gEvent.cancelled = 0;
908 gEvent.delta_x = msgPPosX;
909 gEvent.delta_y = msgPPosY;
910 gEvent.delta_unaccel_x = msgPPosX;
911 gEvent.delta_unaccel_y = msgPPosY;
912 sloted_coords_info slotInfo;
913 gEvent.solt_touches = slotInfo;
914 gEvent.scale = scaleToDouble;
915 gEvent.angle = angleToDouble;
916 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
917 PrintVKeyTPGestureLog(gEvent);
918 int64_t frameTime = GetSysClockTime();
919 funInputEvent_((libinput_event*)lgEvent, frameTime);
920 free(lgEvent);
921 return true;
922 }
923
HandleVKeyTrackPadRotateUpdate(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)924 bool LibinputAdapter::HandleVKeyTrackPadRotateUpdate(libinput_event_touch* touch,
925 const std::vector<int32_t>& msgItem)
926 {
927 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
928 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
929 static_cast<int32_t>(msgItem.size()));
930 return false;
931 }
932 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
933 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
934 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
935 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
936 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
937 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
938 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
939 MMI_HILOGI("VKey TrackPad Rotate Update");
940 event_gesture gEvent;
941 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_UPDATE;
942 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
943 gEvent.cancelled = 0;
944 gEvent.delta_x = msgPPosX;
945 gEvent.delta_y = msgPPosY;
946 gEvent.delta_unaccel_x = msgPPosX;
947 gEvent.delta_unaccel_y = msgPPosY;
948 sloted_coords_info slotInfo;
949 gEvent.solt_touches = slotInfo;
950 gEvent.scale = scaleToDouble;
951 gEvent.angle = angleToDouble;
952 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
953 PrintVKeyTPGestureLog(gEvent);
954 int64_t frameTime = GetSysClockTime();
955 funInputEvent_((libinput_event*)lgEvent, frameTime);
956 free(lgEvent);
957 return true;
958 }
959
HandleVKeyTrackPadRotateEnd(libinput_event_touch * touch,const std::vector<int32_t> & msgItem)960 bool LibinputAdapter::HandleVKeyTrackPadRotateEnd(libinput_event_touch* touch,
961 const std::vector<int32_t>& msgItem)
962 {
963 if (msgItem.size() < VKEY_TP_SM_MSG_SIZE) {
964 MMI_HILOGE("Virtual TrackPad state machine message size:%{public}d is not correct",
965 static_cast<int32_t>(msgItem.size()));
966 return false;
967 }
968 int32_t msgPId = msgItem[VKEY_TP_SM_MSG_POINTER_ID_IDX];
969 int32_t msgPPosX = msgItem[VKEY_TP_SM_MSG_POS_X_IDX];
970 int32_t msgPPosY = msgItem[VKEY_TP_SM_MSG_POS_Y_IDX];
971 int32_t msgPScale = msgItem[VKEY_TP_SM_MSG_SCALE_IDX];
972 double scaleToDouble = static_cast<double>(msgPScale) / VTP_SCALE_AND_ANGLE_FACTOR;
973 int32_t msgPAngle = msgItem[VKEY_TP_SM_MSG_ANGLE_IDX];
974 double angleToDouble = static_cast<double>(msgPAngle) / VTP_SCALE_AND_ANGLE_FACTOR;
975 MMI_HILOGI("VKey TrackPad Rotate End");
976 event_gesture gEvent;
977 gEvent.event_type = libinput_event_type::LIBINPUT_EVENT_GESTURE_PINCH_END;
978 gEvent.finger_count = VKEY_TP_GSE_TWO_FINGERS;
979 gEvent.cancelled = 0;
980 gEvent.delta_x = msgPPosX;
981 gEvent.delta_y = msgPPosY;
982 gEvent.delta_unaccel_x = msgPPosX;
983 gEvent.delta_unaccel_y = msgPPosY;
984 sloted_coords_info slotInfo;
985 gEvent.solt_touches = slotInfo;
986 gEvent.scale = scaleToDouble;
987 gEvent.angle = angleToDouble;
988 libinput_event_gesture* lgEvent = libinput_create_gesture_event(touch, gEvent);
989 PrintVKeyTPGestureLog(gEvent);
990 int64_t frameTime = GetSysClockTime();
991 funInputEvent_((libinput_event*)lgEvent, frameTime);
992 free(lgEvent);
993 return true;
994 }
995
ConvertToTouchEventType(libinput_event_type eventType)996 int32_t LibinputAdapter::ConvertToTouchEventType(
997 libinput_event_type eventType)
998 {
999 if (eventType == LIBINPUT_EVENT_TOUCH_DOWN) {
1000 return static_cast<int32_t>(VKeyboardTouchEventType::TOUCH_DOWN);
1001 } else if (eventType == LIBINPUT_EVENT_TOUCH_UP) {
1002 return static_cast<int32_t>(VKeyboardTouchEventType::TOUCH_UP);
1003 } else if (eventType == LIBINPUT_EVENT_TOUCH_FRAME) {
1004 return static_cast<int32_t>(VKeyboardTouchEventType::TOUCH_FRAME);
1005 } else {
1006 return static_cast<int32_t>(VKeyboardTouchEventType::TOUCH_MOVE);
1007 }
1008 }
1009
PrintVKeyTPPointerLog(event_pointer & pEvent)1010 void LibinputAdapter::PrintVKeyTPPointerLog(event_pointer &pEvent)
1011 {
1012 MMI_HILOGD("######## pointerEvent");
1013 MMI_HILOGD("######## event type:%{public}d, delta.x:%{public}d, delta.y:%{public}d",
1014 static_cast<int32_t>(pEvent.event_type), static_cast<int32_t>(pEvent.delta_x),
1015 static_cast<int32_t>(pEvent.delta_y));
1016 MMI_HILOGD("######## delta_raw.x:%{public}d, delta_raw.y:%{public}d",
1017 static_cast<int32_t>(pEvent.delta_raw_x), static_cast<int32_t>(pEvent.delta_raw_y));
1018 MMI_HILOGD("######## absolute.x:%{public}d, absolute.y:%{public}d, source:%{public}d",
1019 static_cast<int32_t>(pEvent.absolute_x), static_cast<int32_t>(pEvent.absolute_y),
1020 static_cast<int32_t>(pEvent.source));
1021 MMI_HILOGD("######## axes:%{public}d, button:%{public}d, seat button count:%{public}d",
1022 static_cast<int32_t>(pEvent.axes), static_cast<int32_t>(pEvent.button),
1023 static_cast<int32_t>(pEvent.seat_button_count));
1024 MMI_HILOGD("######## state:%{public}d, discrete.x:%{public}d, discrete.y:%{public}d",
1025 static_cast<int32_t>(pEvent.state), static_cast<int32_t>(pEvent.discrete_x),
1026 static_cast<int32_t>(pEvent.discrete_y));
1027 MMI_HILOGD("######## v120.x:%{public}d, v120.y:%{public}d",
1028 static_cast<int32_t>(pEvent.v120_x), static_cast<int32_t>(pEvent.v120_y));
1029 }
1030
PrintVKeyTPGestureLog(event_gesture & gEvent)1031 void LibinputAdapter::PrintVKeyTPGestureLog(event_gesture &gEvent)
1032 {
1033 MMI_HILOGD("######## gestureEvent");
1034 MMI_HILOGD("######## event_type:%{public}d, finger_count:%{public}d, cancelled:%{public}d",
1035 static_cast<int32_t>(gEvent.event_type), static_cast<int32_t>(gEvent.finger_count),
1036 static_cast<int32_t>(gEvent.cancelled));
1037 MMI_HILOGD("######## delta_x:%{public}f, delta_y:%{public}f",
1038 static_cast<double>(gEvent.delta_x), static_cast<double>(gEvent.delta_y));
1039 MMI_HILOGD("######## delta_unaccel_x:%{public}f, delta_unaccel_y:%{public}f",
1040 static_cast<double>(gEvent.delta_unaccel_x), static_cast<double>(gEvent.delta_unaccel_y));
1041 MMI_HILOGD("######## solt_touches active_count:%{public}d",
1042 static_cast<int32_t>(gEvent.solt_touches.active_count));
1043 MMI_HILOGD("######## scale:%{public}f, angle:%{public}f",
1044 static_cast<double>(gEvent.scale), static_cast<double>(gEvent.angle));
1045 }
1046
HandleHWKeyEventForVKeyboard(libinput_event * event)1047 void LibinputAdapter::HandleHWKeyEventForVKeyboard(libinput_event* event)
1048 {
1049 MMI_HILOGD("Hardware keyboard key event detected");
1050 if (hardwareKeyEventDetected_ == nullptr) {
1051 return;
1052 }
1053 if (event == nullptr) {
1054 MMI_HILOGD("libinput event is nullptr");
1055 return;
1056 }
1057 libinput_event_type eventType = libinput_event_get_type(event);
1058 if (eventType == LIBINPUT_EVENT_KEYBOARD_KEY) {
1059 libinput_event_keyboard* keyboardEvent = libinput_event_get_keyboard_event(event);
1060 if (keyboardEvent == nullptr) {
1061 MMI_HILOGD("keyboardEvent is nullptr");
1062 return;
1063 }
1064 libinput_device* device = libinput_event_get_device(event);
1065 if (device == nullptr) {
1066 MMI_HILOGD("keyboard device is nullptr");
1067 return;
1068 }
1069 uint32_t keyCode = libinput_event_keyboard_get_key(keyboardEvent);
1070 int32_t hasFnKey = libinput_device_has_key(device, LIBINPUT_KEY_FN);
1071 const char* outPutName = libinput_device_get_name(device);
1072 MMI_HILOGD("The current keyCode:%{private}u, hasFnKey %{private}d, outPutName:%{private}s",
1073 keyCode, hasFnKey, outPutName);
1074 if ((keyCode == LIBINPUT_KEY_VOLUME_DOWN || keyCode == LIBINPUT_KEY_VOLUME_UP ||
1075 keyCode == LIBINPUT_KEY_POWER) && !hasFnKey) {
1076 MMI_HILOGD("Skip device local button keyCode:%{private}u", keyCode);
1077 return;
1078 }
1079 hardwareKeyEventDetected_();
1080 }
1081 }
1082
ShowMouseCursor()1083 void LibinputAdapter::ShowMouseCursor()
1084 {
1085 MMI_HILOGD("Check cursor state function valid = %{public}d",
1086 IPointerDrawingManager::GetInstance() != nullptr);
1087 if (IPointerDrawingManager::GetInstance() != nullptr &&
1088 !IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) {
1089 MMI_HILOGI("Found hidden mouse cursor during trackpad operation, show it.");
1090 IPointerDrawingManager::GetInstance()->SetMouseDisplayState(true);
1091 }
1092 }
1093
HideMouseCursorTemporary()1094 void LibinputAdapter::HideMouseCursorTemporary()
1095 {
1096 MMI_HILOGI("VKeyboard hide mouse.");
1097 if (IPointerDrawingManager::GetInstance() != nullptr &&
1098 IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) {
1099 IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false);
1100 }
1101 }
1102
GetAccumulatedPressure(int touchId,int32_t eventType,double touchPressure)1103 double LibinputAdapter::GetAccumulatedPressure(int touchId, int32_t eventType, double touchPressure)
1104 {
1105 auto pos = touchPointPressureCache_.find(touchId);
1106 double accumulatedPressure = 0.0;
1107 if (pos != touchPointPressureCache_.end()) {
1108 accumulatedPressure = pos->second;
1109 }
1110
1111 accumulatedPressure += touchPressure;
1112 touchPointPressureCache_[touchId] = accumulatedPressure;
1113
1114 if (eventType == LIBINPUT_EVENT_TOUCH_UP) {
1115 pos = touchPointPressureCache_.find(touchId);
1116 if (pos != touchPointPressureCache_.end()) {
1117 touchPointPressureCache_.erase(pos);
1118 }
1119 }
1120
1121 return accumulatedPressure;
1122 }
1123
SkipTouchMove(int touchId,int32_t eventType)1124 bool LibinputAdapter::SkipTouchMove(int touchId, int32_t eventType)
1125 {
1126 if (eventType == LIBINPUT_EVENT_TOUCH_DOWN) {
1127 skipTouchMoveCache_[touchId] = true;
1128 } else if (eventType == LIBINPUT_EVENT_TOUCH_UP) {
1129 auto pos = skipTouchMoveCache_.find(touchId);
1130 if (pos != skipTouchMoveCache_.end()) {
1131 skipTouchMoveCache_.erase(pos);
1132 }
1133 } else if (eventType == LIBINPUT_EVENT_TOUCH_MOTION) {
1134 auto pos = skipTouchMoveCache_.find(touchId);
1135 if (pos != skipTouchMoveCache_.end()) {
1136 return pos->second;
1137 }
1138 } else if (eventType == LIBINPUT_EVENT_TOUCH_FRAME) {
1139 auto pos = skipTouchMoveCache_.find(touchId);
1140 if (pos != skipTouchMoveCache_.end()) {
1141 skipTouchMoveCache_[touchId] = !pos->second;
1142 }
1143 }
1144 return false;
1145 }
1146 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
1147
MultiKeyboardSetLedState(bool oldCapsLockState)1148 void LibinputAdapter::MultiKeyboardSetLedState(bool oldCapsLockState)
1149 {
1150 std::vector<struct libinput_device*> input_device;
1151 INPUT_DEV_MGR->GetMultiKeyboardDevice(input_device);
1152 for (auto it = input_device.begin(); it != input_device.end(); ++it) {
1153 auto setDevice = (*it);
1154 CHKPV(setDevice);
1155 DeviceLedUpdate(setDevice, KeyEvent::CAPS_LOCK_FUNCTION_KEY, !oldCapsLockState);
1156 }
1157 }
1158
MultiKeyboardSetFuncState(libinput_event * event)1159 void LibinputAdapter::MultiKeyboardSetFuncState(libinput_event* event)
1160 {
1161 libinput_event_type eventType = libinput_event_get_type(event);
1162 if (eventType == LIBINPUT_EVENT_KEYBOARD_KEY) {
1163 struct libinput_event_keyboard* keyboardEvent = libinput_event_get_keyboard_event(event);
1164 CHKPV(keyboardEvent);
1165 std::shared_ptr<KeyEvent> keyEvent = KeyEventHdr->GetKeyEvent();
1166 if (libinput_event_keyboard_get_key_state(keyboardEvent) == LIBINPUT_KEY_STATE_PRESSED
1167 && libinput_event_keyboard_get_key(keyboardEvent) == KEY_CAPSLOCK
1168 && keyEvent != nullptr) {
1169 bool oldCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY);
1170 MultiKeyboardSetLedState(oldCapsLockOn);
1171 keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !oldCapsLockOn);
1172 libinput_toggle_caps_key();
1173 }
1174 }
1175 }
1176
OnEventHandler()1177 void LibinputAdapter::OnEventHandler()
1178 {
1179 CALL_DEBUG_ENTER;
1180 CHKPV(funInputEvent_);
1181 libinput_event *event = nullptr;
1182 int64_t frameTime = GetSysClockTime();
1183 while ((event = libinput_get_event(input_))) {
1184 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
1185 libinput_event_type eventType = libinput_event_get_type(event);
1186 int32_t touchId = 0;
1187 libinput_event_touch* touch = nullptr;
1188 static int32_t downCount = 0;
1189
1190 // add the logic of screen capture window conuming touch point in high priority
1191 bool isCaptureMode = false;
1192 InputWindowsManager* inputWindowsManager = static_cast<InputWindowsManager *>(WIN_MGR.get());
1193 if (inputWindowsManager != nullptr) {
1194 DisplayGroupInfo displayGroupInfo = inputWindowsManager->GetDisplayGroupInfo();
1195
1196 for (auto &windowInfo : displayGroupInfo.windowsInfo) {
1197 if (windowInfo.zOrder == SCREEN_CAPTURE_WINDOW_ZORDER) {
1198 // screen recorder scenario will be an exception to true
1199 isCaptureMode = ((windowInfo.area.width <= SCREEN_RECORD_WINDOW_WIDTH) \
1200 && (windowInfo.area.height <= SCREEN_RECORD_WINDOW_HEIGHT)) ? false : true;
1201 MMI_HILOGD("#####Currently keyboard will %s consume touch points", (isCaptureMode ? "not" : ""));
1202 break;
1203 }
1204 }
1205 }
1206
1207 if ((eventType == LIBINPUT_EVENT_TOUCH_DOWN && !isCaptureMode)
1208 || eventType == LIBINPUT_EVENT_TOUCH_UP
1209 || eventType == LIBINPUT_EVENT_TOUCH_MOTION
1210 || eventType == LIBINPUT_EVENT_TOUCH_CANCEL
1211 || eventType == LIBINPUT_EVENT_TOUCH_FRAME
1212 ) {
1213 touch = libinput_event_get_touch_event(event);
1214 double touchPressure = 0.0;
1215 double accumulatedPressure = 0.0;
1216 if (eventType != LIBINPUT_EVENT_TOUCH_FRAME) {
1217 touchId = libinput_event_touch_get_slot(touch);
1218 touchPressure = libinput_event_touch_get_pressure(touch);
1219 accumulatedPressure = GetAccumulatedPressure(touchId, eventType, touchPressure);
1220 }
1221
1222 if (deviceId == -1) {
1223 // initialize touch device ID.
1224 libinput_device* device = libinput_event_get_device(event);
1225 deviceId = INPUT_DEV_MGR->FindInputDeviceId(device);
1226 }
1227
1228 EventTouch touchInfo;
1229 int32_t logicalDisplayId = -1;
1230 double x = 0.0;
1231 double y = 0.0;
1232 int32_t touchEventType = ConvertToTouchEventType(eventType);
1233 // touch up event has no coordinates information, skip coordinate calculation.
1234 if (eventType == LIBINPUT_EVENT_TOUCH_DOWN || eventType == LIBINPUT_EVENT_TOUCH_MOTION) {
1235 if (!WIN_MGR->TouchPointToDisplayPoint(deviceId, touch, touchInfo, logicalDisplayId)) {
1236 MMI_HILOGE("Map touch point to display point failed");
1237 } else {
1238 x = touchInfo.point.x;
1239 y = touchInfo.point.y;
1240
1241 touchPoints_[touchId] = std::pair<double, double>(x, y);
1242 }
1243 } else if (eventType == LIBINPUT_EVENT_TOUCH_UP) {
1244 auto pos = touchPoints_.find(touchId);
1245 if (pos != touchPoints_.end()) {
1246 x = (pos->second).first;
1247 y = (pos->second).second;
1248 touchPoints_.erase(pos);
1249 }
1250 }
1251
1252 int32_t longAxis = libinput_event_get_touch_contact_long_axis(touch);
1253 int32_t shortAxis = libinput_event_get_touch_contact_short_axis(touch);
1254 MMI_HILOGD("touch event. deviceId:%{private}d, touchId:%{private}d, x:%{private}d, y:%{private}d, \
1255 type:%{private}d, accPressure:%{private}f, longAxis:%{private}d, shortAxis:%{private}d",
1256 deviceId,
1257 touchId,
1258 static_cast<int32_t>(x),
1259 static_cast<int32_t>(y),
1260 static_cast<int32_t>(eventType),
1261 accumulatedPressure,
1262 longAxis,
1263 shortAxis);
1264
1265 if (handleTouchPoint_ != nullptr &&
1266 handleTouchPoint_(x, y, touchId, touchEventType, accumulatedPressure) == 0) {
1267 MMI_HILOGD("Inside vkeyboard area");
1268 HandleVFullKeyboardMessages(event, frameTime, eventType, touch);
1269 } else {
1270 bool bDropEventFlag = false;
1271
1272 if (getKeyboardActivationState_ != nullptr) {
1273 VKeyboardActivation activateState = (VKeyboardActivation)getKeyboardActivationState_();
1274 switch (activateState) {
1275 case VKeyboardActivation::INACTIVE : {
1276 MMI_HILOGI("activation state: %{public}d", static_cast<int32_t>(activateState));
1277 break;
1278 }
1279 case VKeyboardActivation::ACTIVATED : {
1280 MMI_HILOGI("activation state: %{public}d", static_cast<int32_t>(activateState));
1281 break;
1282 }
1283 case VKeyboardActivation::TOUCH_CANCEL : {
1284 MMI_HILOGI("activation state: %{public}d, sending touch cancel event",
1285 static_cast<int32_t>(activateState));
1286 if (eventType == LIBINPUT_EVENT_TOUCH_MOTION || eventType == LIBINPUT_EVENT_TOUCH_DOWN) {
1287 libinput_set_touch_event_type(touch, LIBINPUT_EVENT_TOUCH_CANCEL);
1288 }
1289 break;
1290 }
1291 case VKeyboardActivation::TOUCH_DROP : {
1292 MMI_HILOGI("activation state: %{public}d, dropping event",
1293 static_cast<int32_t>(activateState));
1294 bDropEventFlag = true;
1295 break;
1296 }
1297 case VKeyboardActivation::EIGHT_FINGERS_UP : {
1298 MMI_HILOGI("activation state: %{public}d", static_cast<int32_t>(activateState));
1299 break;
1300 }
1301 default:
1302 break;
1303 }
1304 }
1305
1306 if (!bDropEventFlag) {
1307 funInputEvent_(event, frameTime);
1308 }
1309 libinput_event_destroy(event);
1310 }
1311 } else if (eventType == LIBINPUT_EVENT_KEYBOARD_KEY) {
1312 struct libinput_event_keyboard* keyboardEvent = libinput_event_get_keyboard_event(event);
1313 std::shared_ptr<KeyEvent> keyEvent = KeyEventHdr->GetKeyEvent();
1314
1315 if (libinput_event_keyboard_get_key_state(keyboardEvent) == LIBINPUT_KEY_STATE_PRESSED
1316 && libinput_event_keyboard_get_key(keyboardEvent) == KEY_CAPSLOCK
1317 && keyEvent != nullptr) {
1318 bool oldCapsLockOn = keyEvent->GetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY);
1319 libinput_device* device = libinput_event_get_device(event);
1320 int libinputCaps = libinput_get_funckey_state(device, MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY);
1321
1322 HandleHWKeyEventForVKeyboard(event);
1323 funInputEvent_(event, frameTime);
1324 libinput_event_destroy(event);
1325
1326 MultiKeyboardSetLedState(oldCapsLockOn);
1327 keyEvent->SetFunctionKey(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, !oldCapsLockOn);
1328 libinput_toggle_caps_key();
1329 } else {
1330 HandleHWKeyEventForVKeyboard(event);
1331 funInputEvent_(event, frameTime);
1332 libinput_event_destroy(event);
1333 }
1334 } else {
1335 funInputEvent_(event, frameTime);
1336 libinput_event_destroy(event);
1337 }
1338 #else // OHOS_BUILD_ENABLE_VKEYBOARD
1339 MultiKeyboardSetFuncState(event);
1340 funInputEvent_(event, frameTime);
1341 libinput_event_destroy(event);
1342 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
1343 }
1344 if (event == nullptr) {
1345 funInputEvent_(nullptr, 0);
1346 }
1347 }
1348
ReloadDevice()1349 void LibinputAdapter::ReloadDevice()
1350 {
1351 CALL_DEBUG_ENTER;
1352 CHKPV(input_);
1353 libinput_suspend(input_);
1354 libinput_resume(input_);
1355 }
1356
OnDeviceAdded(std::string path)1357 void LibinputAdapter::OnDeviceAdded(std::string path)
1358 {
1359 std::regex re("(\\d+)");
1360 std::string str_path(path);
1361 std::smatch match;
1362 int32_t id;
1363 bool isPath = std::regex_search(str_path, match, re);
1364 if (!isPath) {
1365 id = -1;
1366 } else {
1367 id = std::stoi(match[0]);
1368 }
1369 MMI_HILOGI("OnDeviceAdded id:%{public}d", id);
1370 auto pos = devices_.find(path);
1371 if (pos != devices_.end()) {
1372 MMI_HILOGD("Path is found");
1373 return;
1374 }
1375
1376 DTaskCallback cb = [this, path] {
1377 MMI_HILOGI("OnDeviceAdded, path:%{public}s", path.c_str());
1378 udev_device_record_devnode(path.c_str());
1379 libinput_device* device = libinput_path_add_device(input_, path.c_str());
1380 if (device != nullptr) {
1381 devices_[std::move(path)] = libinput_device_ref(device);
1382 // Libinput doesn't signal device adding event in path mode. Process manually.
1383 OnEventHandler();
1384 }
1385 udev_device_property_remove(path.c_str());
1386 return 0;
1387 };
1388 PropReader->ReadPropertys(path, cb);
1389 }
1390
OnDeviceRemoved(std::string path)1391 void LibinputAdapter::OnDeviceRemoved(std::string path)
1392 {
1393 std::regex re("(\\d+)");
1394 std::string str_path(path);
1395 std::smatch match;
1396 int32_t id;
1397 bool isPath = std::regex_search(str_path, match, re);
1398 if (!isPath) {
1399 id = -1;
1400 } else {
1401 id = std::stoi(match[0]);
1402 }
1403 MMI_HILOGI("OnDeviceRemoved id:%{public}d", id);
1404 auto pos = devices_.find(path);
1405 if (pos != devices_.end()) {
1406 libinput_path_remove_device(pos->second);
1407 libinput_device_unref(pos->second);
1408 devices_.erase(pos);
1409 // Libinput doesn't signal device removing event in path mode. Process manually.
1410 OnEventHandler();
1411 }
1412 }
1413 } // namespace MMI
1414 } // namespace OHOS
1415