File indexing completed on 2024-11-10 04:56:14
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include <config-kwin.h> 0010 0011 #include "mock_libinput.h" 0012 0013 #include <linux/input.h> 0014 0015 int libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code) 0016 { 0017 return device->keys.contains(code); 0018 } 0019 0020 int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability) 0021 { 0022 switch (capability) { 0023 case LIBINPUT_DEVICE_CAP_KEYBOARD: 0024 return device->keyboard; 0025 case LIBINPUT_DEVICE_CAP_POINTER: 0026 return device->pointer; 0027 case LIBINPUT_DEVICE_CAP_TOUCH: 0028 return device->touch; 0029 case LIBINPUT_DEVICE_CAP_GESTURE: 0030 return device->gestureSupported; 0031 case LIBINPUT_DEVICE_CAP_TABLET_TOOL: 0032 return device->tabletTool; 0033 case LIBINPUT_DEVICE_CAP_SWITCH: 0034 return device->switchDevice; 0035 default: 0036 return 0; 0037 } 0038 } 0039 0040 const char *libinput_device_get_name(struct libinput_device *device) 0041 { 0042 return device->name.constData(); 0043 } 0044 0045 const char *libinput_device_get_sysname(struct libinput_device *device) 0046 { 0047 return device->sysName.constData(); 0048 } 0049 0050 const char *libinput_device_get_output_name(struct libinput_device *device) 0051 { 0052 return device->outputName.constData(); 0053 } 0054 0055 unsigned int libinput_device_get_id_product(struct libinput_device *device) 0056 { 0057 return device->product; 0058 } 0059 0060 unsigned int libinput_device_get_id_vendor(struct libinput_device *device) 0061 { 0062 return device->vendor; 0063 } 0064 0065 int libinput_device_config_tap_get_finger_count(struct libinput_device *device) 0066 { 0067 return device->tapFingerCount; 0068 } 0069 0070 enum libinput_config_tap_state libinput_device_config_tap_get_enabled(struct libinput_device *device) 0071 { 0072 if (device->tapToClick) { 0073 return LIBINPUT_CONFIG_TAP_ENABLED; 0074 } else { 0075 return LIBINPUT_CONFIG_TAP_DISABLED; 0076 } 0077 } 0078 0079 enum libinput_config_status libinput_device_config_tap_set_enabled(struct libinput_device *device, enum libinput_config_tap_state enable) 0080 { 0081 if (device->setTapToClickReturnValue == 0) { 0082 device->tapToClick = (enable == LIBINPUT_CONFIG_TAP_ENABLED); 0083 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0084 } 0085 return LIBINPUT_CONFIG_STATUS_INVALID; 0086 } 0087 0088 enum libinput_config_tap_state libinput_device_config_tap_get_default_enabled(struct libinput_device *device) 0089 { 0090 if (device->tapEnabledByDefault) { 0091 return LIBINPUT_CONFIG_TAP_ENABLED; 0092 } else { 0093 return LIBINPUT_CONFIG_TAP_DISABLED; 0094 } 0095 } 0096 0097 enum libinput_config_drag_state libinput_device_config_tap_get_default_drag_enabled(struct libinput_device *device) 0098 { 0099 if (device->tapAndDragEnabledByDefault) { 0100 return LIBINPUT_CONFIG_DRAG_ENABLED; 0101 } else { 0102 return LIBINPUT_CONFIG_DRAG_DISABLED; 0103 } 0104 } 0105 0106 enum libinput_config_drag_state libinput_device_config_tap_get_drag_enabled(struct libinput_device *device) 0107 { 0108 if (device->tapAndDrag) { 0109 return LIBINPUT_CONFIG_DRAG_ENABLED; 0110 } else { 0111 return LIBINPUT_CONFIG_DRAG_DISABLED; 0112 } 0113 } 0114 0115 enum libinput_config_status libinput_device_config_tap_set_drag_enabled(struct libinput_device *device, enum libinput_config_drag_state enable) 0116 { 0117 if (device->setTapAndDragReturnValue == 0) { 0118 device->tapAndDrag = (enable == LIBINPUT_CONFIG_DRAG_ENABLED); 0119 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0120 } 0121 return LIBINPUT_CONFIG_STATUS_INVALID; 0122 } 0123 0124 enum libinput_config_drag_lock_state libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device *device) 0125 { 0126 if (device->tapDragLockEnabledByDefault) { 0127 return LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; 0128 } else { 0129 return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; 0130 } 0131 } 0132 0133 enum libinput_config_drag_lock_state libinput_device_config_tap_get_drag_lock_enabled(struct libinput_device *device) 0134 { 0135 if (device->tapDragLock) { 0136 return LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; 0137 } else { 0138 return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; 0139 } 0140 } 0141 0142 enum libinput_config_status libinput_device_config_tap_set_drag_lock_enabled(struct libinput_device *device, enum libinput_config_drag_lock_state enable) 0143 { 0144 if (device->setTapDragLockReturnValue == 0) { 0145 device->tapDragLock = (enable == LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); 0146 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0147 } 0148 return LIBINPUT_CONFIG_STATUS_INVALID; 0149 } 0150 0151 int libinput_device_config_dwt_is_available(struct libinput_device *device) 0152 { 0153 return device->supportsDisableWhileTyping; 0154 } 0155 0156 enum libinput_config_status libinput_device_config_dwt_set_enabled(struct libinput_device *device, enum libinput_config_dwt_state state) 0157 { 0158 if (device->setDisableWhileTypingReturnValue == 0) { 0159 if (!device->supportsDisableWhileTyping) { 0160 return LIBINPUT_CONFIG_STATUS_INVALID; 0161 } 0162 device->disableWhileTyping = state; 0163 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0164 } 0165 return LIBINPUT_CONFIG_STATUS_INVALID; 0166 } 0167 0168 enum libinput_config_dwt_state libinput_device_config_dwt_get_enabled(struct libinput_device *device) 0169 { 0170 return device->disableWhileTyping; 0171 } 0172 0173 enum libinput_config_dwt_state libinput_device_config_dwt_get_default_enabled(struct libinput_device *device) 0174 { 0175 return device->disableWhileTypingEnabledByDefault; 0176 } 0177 0178 int libinput_device_config_accel_is_available(struct libinput_device *device) 0179 { 0180 return device->supportsPointerAcceleration; 0181 } 0182 0183 int libinput_device_config_calibration_has_matrix(struct libinput_device *device) 0184 { 0185 return device->supportsCalibrationMatrix; 0186 } 0187 0188 enum libinput_config_status libinput_device_config_calibration_set_matrix(struct libinput_device *device, const float matrix[6]) 0189 { 0190 for (std::size_t i = 0; i < 6; i++) { 0191 device->calibrationMatrix[i] = matrix[i]; 0192 } 0193 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0194 } 0195 0196 int libinput_device_config_calibration_get_default_matrix(struct libinput_device *device, float matrix[6]) 0197 { 0198 for (std::size_t i = 0; i < 6; i++) { 0199 matrix[i] = device->defaultCalibrationMatrix[i]; 0200 } 0201 return device->defaultCalibrationMatrixIsIdentity ? 0 : 1; 0202 } 0203 0204 int libinput_device_config_calibration_get_matrix(struct libinput_device *device, float matrix[6]) 0205 { 0206 for (std::size_t i = 0; i < 6; i++) { 0207 matrix[i] = device->calibrationMatrix[i]; 0208 } 0209 return device->calibrationMatrixIsIdentity ? 0 : 1; 0210 } 0211 0212 int libinput_device_config_left_handed_is_available(struct libinput_device *device) 0213 { 0214 return device->supportsLeftHanded; 0215 } 0216 0217 uint32_t libinput_device_config_send_events_get_modes(struct libinput_device *device) 0218 { 0219 uint32_t modes = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; 0220 if (device->supportsDisableEvents) { 0221 modes |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; 0222 } 0223 if (device->supportsDisableEventsOnExternalMouse) { 0224 modes |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; 0225 } 0226 return modes; 0227 } 0228 0229 int libinput_device_config_left_handed_get(struct libinput_device *device) 0230 { 0231 return device->leftHanded; 0232 } 0233 0234 double libinput_device_config_accel_get_default_speed(struct libinput_device *device) 0235 { 0236 return device->defaultPointerAcceleration; 0237 } 0238 0239 int libinput_device_config_left_handed_get_default(struct libinput_device *device) 0240 { 0241 return device->leftHandedEnabledByDefault; 0242 } 0243 0244 double libinput_device_config_accel_get_speed(struct libinput_device *device) 0245 { 0246 return device->pointerAcceleration; 0247 } 0248 0249 uint32_t libinput_device_config_accel_get_profiles(struct libinput_device *device) 0250 { 0251 return device->supportedPointerAccelerationProfiles; 0252 } 0253 0254 enum libinput_config_accel_profile libinput_device_config_accel_get_default_profile(struct libinput_device *device) 0255 { 0256 return device->defaultPointerAccelerationProfile; 0257 } 0258 0259 enum libinput_config_status libinput_device_config_accel_set_profile(struct libinput_device *device, enum libinput_config_accel_profile profile) 0260 { 0261 if (device->setPointerAccelerationProfileReturnValue == 0) { 0262 if (!(device->supportedPointerAccelerationProfiles & profile) && profile != LIBINPUT_CONFIG_ACCEL_PROFILE_NONE) { 0263 return LIBINPUT_CONFIG_STATUS_INVALID; 0264 } 0265 device->pointerAccelerationProfile = profile; 0266 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0267 } 0268 return LIBINPUT_CONFIG_STATUS_INVALID; 0269 } 0270 0271 enum libinput_config_accel_profile libinput_device_config_accel_get_profile(struct libinput_device *device) 0272 { 0273 return device->pointerAccelerationProfile; 0274 } 0275 0276 uint32_t libinput_device_config_click_get_methods(struct libinput_device *device) 0277 { 0278 return device->supportedClickMethods; 0279 } 0280 0281 enum libinput_config_click_method libinput_device_config_click_get_default_method(struct libinput_device *device) 0282 { 0283 return device->defaultClickMethod; 0284 } 0285 0286 enum libinput_config_click_method libinput_device_config_click_get_method(struct libinput_device *device) 0287 { 0288 return device->clickMethod; 0289 } 0290 0291 enum libinput_config_status libinput_device_config_click_set_method(struct libinput_device *device, enum libinput_config_click_method method) 0292 { 0293 if (device->setClickMethodReturnValue == 0) { 0294 if (!(device->supportedClickMethods & method) && method != LIBINPUT_CONFIG_CLICK_METHOD_NONE) { 0295 return LIBINPUT_CONFIG_STATUS_INVALID; 0296 } 0297 device->clickMethod = method; 0298 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0299 } 0300 return LIBINPUT_CONFIG_STATUS_INVALID; 0301 } 0302 0303 uint32_t libinput_device_config_send_events_get_mode(struct libinput_device *device) 0304 { 0305 if (device->enabled) { 0306 return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; 0307 } else { 0308 // TODO: disabled on eternal mouse 0309 return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; 0310 } 0311 } 0312 0313 struct libinput_device *libinput_device_ref(struct libinput_device *device) 0314 { 0315 return device; 0316 } 0317 0318 struct libinput_device *libinput_device_unref(struct libinput_device *device) 0319 { 0320 return device; 0321 } 0322 0323 int libinput_device_get_size(struct libinput_device *device, double *width, double *height) 0324 { 0325 if (device->deviceSizeReturnValue) { 0326 return device->deviceSizeReturnValue; 0327 } 0328 if (width) { 0329 *width = device->deviceSize.width(); 0330 } 0331 if (height) { 0332 *height = device->deviceSize.height(); 0333 } 0334 return device->deviceSizeReturnValue; 0335 } 0336 0337 int libinput_device_pointer_has_button(struct libinput_device *device, uint32_t code) 0338 { 0339 switch (code) { 0340 case BTN_LEFT: 0341 return device->supportedButtons.testFlag(Qt::LeftButton); 0342 case BTN_MIDDLE: 0343 return device->supportedButtons.testFlag(Qt::MiddleButton); 0344 case BTN_RIGHT: 0345 return device->supportedButtons.testFlag(Qt::RightButton); 0346 case BTN_SIDE: 0347 return device->supportedButtons.testFlag(Qt::ExtraButton1); 0348 case BTN_EXTRA: 0349 return device->supportedButtons.testFlag(Qt::ExtraButton2); 0350 case BTN_FORWARD: 0351 return device->supportedButtons.testFlag(Qt::ExtraButton3); 0352 case BTN_BACK: 0353 return device->supportedButtons.testFlag(Qt::ExtraButton4); 0354 case BTN_TASK: 0355 return device->supportedButtons.testFlag(Qt::ExtraButton5); 0356 default: 0357 return 0; 0358 } 0359 } 0360 0361 enum libinput_config_status libinput_device_config_left_handed_set(struct libinput_device *device, int left_handed) 0362 { 0363 if (device->setLeftHandedReturnValue == 0) { 0364 device->leftHanded = left_handed; 0365 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0366 } 0367 return LIBINPUT_CONFIG_STATUS_INVALID; 0368 } 0369 0370 enum libinput_config_status libinput_device_config_accel_set_speed(struct libinput_device *device, double speed) 0371 { 0372 if (device->setPointerAccelerationReturnValue == 0) { 0373 device->pointerAcceleration = speed; 0374 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0375 } 0376 return LIBINPUT_CONFIG_STATUS_INVALID; 0377 } 0378 0379 enum libinput_config_status libinput_device_config_send_events_set_mode(struct libinput_device *device, uint32_t mode) 0380 { 0381 if (device->setEnableModeReturnValue == 0) { 0382 device->enabled = (mode == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); 0383 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0384 } 0385 return LIBINPUT_CONFIG_STATUS_INVALID; 0386 } 0387 0388 enum libinput_event_type libinput_event_get_type(struct libinput_event *event) 0389 { 0390 return event->type; 0391 } 0392 0393 struct libinput_device *libinput_event_get_device(struct libinput_event *event) 0394 { 0395 return event->device; 0396 } 0397 0398 void libinput_event_destroy(struct libinput_event *event) 0399 { 0400 delete event; 0401 } 0402 0403 struct libinput_event_keyboard *libinput_event_get_keyboard_event(struct libinput_event *event) 0404 { 0405 if (event->type == LIBINPUT_EVENT_KEYBOARD_KEY) { 0406 return reinterpret_cast<libinput_event_keyboard *>(event); 0407 } 0408 return nullptr; 0409 } 0410 0411 struct libinput_event_pointer *libinput_event_get_pointer_event(struct libinput_event *event) 0412 { 0413 switch (event->type) { 0414 case LIBINPUT_EVENT_POINTER_MOTION: 0415 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: 0416 case LIBINPUT_EVENT_POINTER_BUTTON: 0417 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: 0418 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: 0419 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: 0420 return reinterpret_cast<libinput_event_pointer *>(event); 0421 default: 0422 return nullptr; 0423 } 0424 } 0425 0426 struct libinput_event_touch *libinput_event_get_touch_event(struct libinput_event *event) 0427 { 0428 switch (event->type) { 0429 case LIBINPUT_EVENT_TOUCH_DOWN: 0430 case LIBINPUT_EVENT_TOUCH_UP: 0431 case LIBINPUT_EVENT_TOUCH_MOTION: 0432 case LIBINPUT_EVENT_TOUCH_CANCEL: 0433 case LIBINPUT_EVENT_TOUCH_FRAME: 0434 return reinterpret_cast<libinput_event_touch *>(event); 0435 default: 0436 return nullptr; 0437 } 0438 } 0439 0440 struct libinput_event_gesture *libinput_event_get_gesture_event(struct libinput_event *event) 0441 { 0442 switch (event->type) { 0443 case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: 0444 case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: 0445 case LIBINPUT_EVENT_GESTURE_PINCH_END: 0446 case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: 0447 case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: 0448 case LIBINPUT_EVENT_GESTURE_SWIPE_END: 0449 return reinterpret_cast<libinput_event_gesture *>(event); 0450 default: 0451 return nullptr; 0452 } 0453 } 0454 0455 int libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event) 0456 { 0457 if (event->type == LIBINPUT_EVENT_GESTURE_PINCH_END || event->type == LIBINPUT_EVENT_GESTURE_SWIPE_END) { 0458 return event->cancelled; 0459 } 0460 return 0; 0461 } 0462 0463 uint64_t libinput_event_gesture_get_time_usec(struct libinput_event_gesture *event) 0464 { 0465 return event->time.count(); 0466 } 0467 0468 int libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event) 0469 { 0470 return event->fingerCount; 0471 } 0472 0473 double libinput_event_gesture_get_dx(struct libinput_event_gesture *event) 0474 { 0475 if (event->type == LIBINPUT_EVENT_GESTURE_PINCH_UPDATE || event->type == LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE) { 0476 return event->delta.x(); 0477 } 0478 return 0.0; 0479 } 0480 0481 double libinput_event_gesture_get_dy(struct libinput_event_gesture *event) 0482 { 0483 if (event->type == LIBINPUT_EVENT_GESTURE_PINCH_UPDATE || event->type == LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE) { 0484 return event->delta.y(); 0485 } 0486 return 0.0; 0487 } 0488 0489 double libinput_event_gesture_get_scale(struct libinput_event_gesture *event) 0490 { 0491 switch (event->type) { 0492 case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: 0493 return 1.0; 0494 case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: 0495 case LIBINPUT_EVENT_GESTURE_PINCH_END: 0496 return event->scale; 0497 default: 0498 return 0.0; 0499 } 0500 } 0501 0502 double libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event) 0503 { 0504 if (event->type == LIBINPUT_EVENT_GESTURE_PINCH_UPDATE) { 0505 return event->angleDelta; 0506 } 0507 return 0.0; 0508 } 0509 0510 uint32_t libinput_event_keyboard_get_key(struct libinput_event_keyboard *event) 0511 { 0512 return event->key; 0513 } 0514 0515 enum libinput_key_state libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event) 0516 { 0517 return event->state; 0518 } 0519 0520 uint64_t libinput_event_keyboard_get_time_usec(struct libinput_event_keyboard *event) 0521 { 0522 return event->time.count(); 0523 } 0524 0525 double libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event) 0526 { 0527 return event->absolutePos.x(); 0528 } 0529 0530 double libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event) 0531 { 0532 return event->absolutePos.y(); 0533 } 0534 0535 double libinput_event_pointer_get_absolute_x_transformed(struct libinput_event_pointer *event, uint32_t width) 0536 { 0537 double deviceWidth = 0.0; 0538 double deviceHeight = 0.0; 0539 libinput_device_get_size(event->device, &deviceWidth, &deviceHeight); 0540 return event->absolutePos.x() / deviceWidth * width; 0541 } 0542 0543 double libinput_event_pointer_get_absolute_y_transformed(struct libinput_event_pointer *event, uint32_t height) 0544 { 0545 double deviceWidth = 0.0; 0546 double deviceHeight = 0.0; 0547 libinput_device_get_size(event->device, &deviceWidth, &deviceHeight); 0548 return event->absolutePos.y() / deviceHeight * height; 0549 } 0550 0551 double libinput_event_pointer_get_dx(struct libinput_event_pointer *event) 0552 { 0553 return event->delta.x(); 0554 } 0555 0556 double libinput_event_pointer_get_dy(struct libinput_event_pointer *event) 0557 { 0558 return event->delta.y(); 0559 } 0560 0561 double libinput_event_pointer_get_dx_unaccelerated(struct libinput_event_pointer *event) 0562 { 0563 return event->delta.x(); 0564 } 0565 0566 double libinput_event_pointer_get_dy_unaccelerated(struct libinput_event_pointer *event) 0567 { 0568 return event->delta.y(); 0569 } 0570 0571 uint64_t libinput_event_pointer_get_time_usec(struct libinput_event_pointer *event) 0572 { 0573 return event->time.count(); 0574 } 0575 0576 uint32_t libinput_event_pointer_get_button(struct libinput_event_pointer *event) 0577 { 0578 return event->button; 0579 } 0580 0581 enum libinput_button_state libinput_event_pointer_get_button_state(struct libinput_event_pointer *event) 0582 { 0583 return event->buttonState; 0584 } 0585 0586 int libinput_event_pointer_has_axis(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) 0587 { 0588 if (axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) { 0589 return event->verticalAxis; 0590 } else { 0591 return event->horizontalAxis; 0592 } 0593 } 0594 0595 double libinput_event_pointer_get_scroll_value(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) 0596 { 0597 if (axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) { 0598 return event->verticalScrollValue; 0599 } else { 0600 return event->horizontalScrollValue; 0601 } 0602 } 0603 0604 double libinput_event_pointer_get_scroll_value_v120(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) 0605 { 0606 if (axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) { 0607 return event->verticalScrollValueV120; 0608 } else { 0609 return event->horizontalScrollValueV120; 0610 } 0611 } 0612 0613 uint64_t libinput_event_touch_get_time_usec(struct libinput_event_touch *event) 0614 { 0615 return event->time.count(); 0616 } 0617 0618 double libinput_event_touch_get_x(struct libinput_event_touch *event) 0619 { 0620 return event->absolutePos.x(); 0621 } 0622 0623 double libinput_event_touch_get_y(struct libinput_event_touch *event) 0624 { 0625 return event->absolutePos.y(); 0626 } 0627 0628 double libinput_event_touch_get_x_transformed(struct libinput_event_touch *event, uint32_t width) 0629 { 0630 double deviceWidth = 0.0; 0631 double deviceHeight = 0.0; 0632 libinput_device_get_size(event->device, &deviceWidth, &deviceHeight); 0633 return event->absolutePos.x() / deviceWidth * width; 0634 } 0635 0636 double libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height) 0637 { 0638 double deviceWidth = 0.0; 0639 double deviceHeight = 0.0; 0640 libinput_device_get_size(event->device, &deviceWidth, &deviceHeight); 0641 return event->absolutePos.y() / deviceHeight * height; 0642 } 0643 0644 int32_t libinput_event_touch_get_seat_slot(struct libinput_event_touch *event) 0645 { 0646 return event->slot; 0647 } 0648 0649 struct libinput *libinput_udev_create_context(const struct libinput_interface *interface, void *user_data, struct udev *udev) 0650 { 0651 if (!udev) { 0652 return nullptr; 0653 } 0654 return new libinput; 0655 } 0656 0657 void libinput_log_set_priority(struct libinput *libinput, enum libinput_log_priority priority) 0658 { 0659 } 0660 0661 void libinput_log_set_handler(struct libinput *libinput, libinput_log_handler log_handler) 0662 { 0663 } 0664 0665 struct libinput *libinput_unref(struct libinput *libinput) 0666 { 0667 libinput->refCount--; 0668 if (libinput->refCount == 0) { 0669 delete libinput; 0670 return nullptr; 0671 } 0672 return libinput; 0673 } 0674 0675 int libinput_udev_assign_seat(struct libinput *libinput, const char *seat_id) 0676 { 0677 if (libinput->assignSeatRetVal == 0) { 0678 libinput->seat = QByteArray(seat_id); 0679 } 0680 return libinput->assignSeatRetVal; 0681 } 0682 0683 int libinput_get_fd(struct libinput *libinput) 0684 { 0685 return -1; 0686 } 0687 0688 int libinput_dispatch(struct libinput *libinput) 0689 { 0690 return 0; 0691 } 0692 0693 struct libinput_event *libinput_get_event(struct libinput *libinput) 0694 { 0695 return nullptr; 0696 } 0697 0698 void libinput_suspend(struct libinput *libinput) 0699 { 0700 } 0701 0702 int libinput_resume(struct libinput *libinput) 0703 { 0704 return 0; 0705 } 0706 0707 int libinput_device_config_middle_emulation_is_available(struct libinput_device *device) 0708 { 0709 return device->supportsMiddleEmulation; 0710 } 0711 0712 enum libinput_config_status libinput_device_config_middle_emulation_set_enabled(struct libinput_device *device, enum libinput_config_middle_emulation_state enable) 0713 { 0714 if (device->setMiddleEmulationReturnValue == 0) { 0715 if (!device->supportsMiddleEmulation) { 0716 return LIBINPUT_CONFIG_STATUS_INVALID; 0717 } 0718 device->middleEmulation = (enable == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); 0719 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0720 } 0721 return LIBINPUT_CONFIG_STATUS_INVALID; 0722 } 0723 0724 enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_enabled(struct libinput_device *device) 0725 { 0726 if (device->middleEmulation) { 0727 return LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; 0728 } else { 0729 return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; 0730 } 0731 } 0732 0733 enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_default_enabled(struct libinput_device *device) 0734 { 0735 if (device->middleEmulationEnabledByDefault) { 0736 return LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; 0737 } else { 0738 return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; 0739 } 0740 } 0741 0742 int libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device) 0743 { 0744 return device->supportsNaturalScroll; 0745 } 0746 0747 enum libinput_config_status libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, int enable) 0748 { 0749 if (device->setNaturalScrollReturnValue == 0) { 0750 if (!device->supportsNaturalScroll) { 0751 return LIBINPUT_CONFIG_STATUS_INVALID; 0752 } 0753 device->naturalScroll = enable; 0754 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0755 } 0756 return LIBINPUT_CONFIG_STATUS_INVALID; 0757 } 0758 0759 int libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device) 0760 { 0761 return device->naturalScroll; 0762 } 0763 0764 int libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device) 0765 { 0766 return device->naturalScrollEnabledByDefault; 0767 } 0768 0769 enum libinput_config_tap_button_map libinput_device_config_tap_get_default_button_map(struct libinput_device *device) 0770 { 0771 return device->defaultTapButtonMap; 0772 } 0773 0774 enum libinput_config_status libinput_device_config_tap_set_button_map(struct libinput_device *device, enum libinput_config_tap_button_map map) 0775 { 0776 if (device->setTapButtonMapReturnValue == 0) { 0777 if (device->tapFingerCount == 0) { 0778 return LIBINPUT_CONFIG_STATUS_INVALID; 0779 } 0780 device->tapButtonMap = map; 0781 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0782 } 0783 return LIBINPUT_CONFIG_STATUS_INVALID; 0784 } 0785 0786 enum libinput_config_tap_button_map libinput_device_config_tap_get_button_map(struct libinput_device *device) 0787 { 0788 return device->tapButtonMap; 0789 } 0790 0791 uint32_t libinput_device_config_scroll_get_methods(struct libinput_device *device) 0792 { 0793 return device->supportedScrollMethods; 0794 } 0795 0796 enum libinput_config_scroll_method libinput_device_config_scroll_get_default_method(struct libinput_device *device) 0797 { 0798 return device->defaultScrollMethod; 0799 } 0800 0801 enum libinput_config_status libinput_device_config_scroll_set_method(struct libinput_device *device, enum libinput_config_scroll_method method) 0802 { 0803 if (device->setScrollMethodReturnValue == 0) { 0804 if (!(device->supportedScrollMethods & method) && method != LIBINPUT_CONFIG_SCROLL_NO_SCROLL) { 0805 return LIBINPUT_CONFIG_STATUS_INVALID; 0806 } 0807 device->scrollMethod = method; 0808 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0809 } 0810 return LIBINPUT_CONFIG_STATUS_INVALID; 0811 } 0812 0813 enum libinput_config_scroll_method libinput_device_config_scroll_get_method(struct libinput_device *device) 0814 { 0815 return device->scrollMethod; 0816 } 0817 0818 enum libinput_config_status libinput_device_config_scroll_set_button(struct libinput_device *device, uint32_t button) 0819 { 0820 if (device->setScrollButtonReturnValue == 0) { 0821 if (!(device->supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { 0822 return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; 0823 } 0824 device->scrollButton = button; 0825 return LIBINPUT_CONFIG_STATUS_SUCCESS; 0826 } 0827 return LIBINPUT_CONFIG_STATUS_INVALID; 0828 } 0829 0830 uint32_t libinput_device_config_scroll_get_button(struct libinput_device *device) 0831 { 0832 return device->scrollButton; 0833 } 0834 0835 uint32_t libinput_device_config_scroll_get_default_button(struct libinput_device *device) 0836 { 0837 return device->defaultScrollButton; 0838 } 0839 0840 int libinput_device_switch_has_switch(struct libinput_device *device, enum libinput_switch sw) 0841 { 0842 switch (sw) { 0843 case LIBINPUT_SWITCH_LID: 0844 return device->lidSwitch; 0845 case LIBINPUT_SWITCH_TABLET_MODE: 0846 return device->tabletModeSwitch; 0847 default: 0848 Q_UNREACHABLE(); 0849 } 0850 return 0; 0851 } 0852 0853 struct libinput_event_switch *libinput_event_get_switch_event(struct libinput_event *event) 0854 { 0855 if (event->type == LIBINPUT_EVENT_SWITCH_TOGGLE) { 0856 return reinterpret_cast<libinput_event_switch *>(event); 0857 } else { 0858 return nullptr; 0859 } 0860 } 0861 0862 enum libinput_switch_state libinput_event_switch_get_switch_state(struct libinput_event_switch *event) 0863 { 0864 switch (event->state) { 0865 case libinput_event_switch::State::On: 0866 return LIBINPUT_SWITCH_STATE_ON; 0867 case libinput_event_switch::State::Off: 0868 return LIBINPUT_SWITCH_STATE_OFF; 0869 default: 0870 Q_UNREACHABLE(); 0871 } 0872 } 0873 0874 uint64_t libinput_event_switch_get_time_usec(struct libinput_event_switch *event) 0875 { 0876 return event->time.count(); 0877 } 0878 0879 struct libinput_event_tablet_pad *libinput_event_get_tablet_pad_event(struct libinput_event *event) 0880 { 0881 if (event->type == LIBINPUT_EVENT_TABLET_PAD_BUTTON) { 0882 return reinterpret_cast<libinput_event_tablet_pad *>(event); 0883 } 0884 return nullptr; 0885 } 0886 0887 struct libinput_event_tablet_tool * 0888 libinput_event_get_tablet_tool_event(struct libinput_event *event) 0889 { 0890 switch (event->type) { 0891 case LIBINPUT_EVENT_TABLET_TOOL_AXIS: 0892 case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: 0893 case LIBINPUT_EVENT_TABLET_TOOL_TIP: 0894 return reinterpret_cast<libinput_event_tablet_tool *>(event); 0895 default: 0896 return nullptr; 0897 } 0898 } 0899 0900 int libinput_device_tablet_pad_get_num_strips(struct libinput_device *device) 0901 { 0902 return device->stripCount; 0903 } 0904 0905 int libinput_device_tablet_pad_get_num_rings(struct libinput_device *device) 0906 { 0907 return device->ringCount; 0908 } 0909 0910 int libinput_device_tablet_pad_get_num_buttons(struct libinput_device *device) 0911 { 0912 return device->buttonCount; 0913 } 0914 0915 struct libinput_device_group * 0916 libinput_device_get_device_group(struct libinput_device *device) 0917 { 0918 return nullptr; 0919 } 0920 0921 void * 0922 libinput_device_group_get_user_data(struct libinput_device_group *group) 0923 { 0924 return nullptr; 0925 } 0926 0927 void libinput_device_led_update(struct libinput_device *device, 0928 enum libinput_led leds) 0929 { 0930 } 0931 0932 void libinput_device_set_user_data(struct libinput_device *device, void *user_data) 0933 { 0934 device->userData = user_data; 0935 } 0936 0937 void * 0938 libinput_device_get_user_data(struct libinput_device *device) 0939 { 0940 return device->userData; 0941 } 0942 0943 double 0944 libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event, 0945 uint32_t width) 0946 { 0947 // it's unused at the moment, it doesn't really matter what we return 0948 return 0; 0949 } 0950 0951 double 0952 libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event, 0953 uint32_t height) 0954 { 0955 return 4; 0956 }