| 370 | } |
| 371 | |
| 372 | bool UInputController::create_device() |
| 373 | { |
| 374 | LogInfo << "Creating uinput device at" << VAR(device_node_); |
| 375 | |
| 376 | fd_ = ::open(device_node_.c_str(), O_WRONLY | O_NONBLOCK); |
| 377 | if (fd_ < 0) { |
| 378 | LogError << "Failed to open" << VAR(device_node_) << VAR(errno) << VAR(std::strerror(errno)); |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | // Enable event types |
| 383 | if (ioctl(fd_, UI_SET_EVBIT, EV_KEY) < 0) { |
| 384 | LogError << "Failed to set EV_KEY" << VAR(errno) << VAR(std::strerror(errno)); |
| 385 | ::close(fd_); |
| 386 | fd_ = -1; |
| 387 | return false; |
| 388 | } |
| 389 | if (ioctl(fd_, UI_SET_EVBIT, EV_ABS) < 0) { |
| 390 | LogError << "Failed to set EV_ABS" << VAR(errno) << VAR(std::strerror(errno)); |
| 391 | ::close(fd_); |
| 392 | fd_ = -1; |
| 393 | return false; |
| 394 | } |
| 395 | if (ioctl(fd_, UI_SET_EVBIT, EV_REL) < 0) { |
| 396 | LogWarn << "Failed to set EV_REL, relative events may not work" << VAR(errno) << VAR(std::strerror(errno)); |
| 397 | // Non-fatal, continue |
| 398 | } |
| 399 | if (ioctl(fd_, UI_SET_EVBIT, EV_SYN) < 0) { |
| 400 | LogError << "Failed to set EV_SYN" << VAR(errno) << VAR(std::strerror(errno)); |
| 401 | ::close(fd_); |
| 402 | fd_ = -1; |
| 403 | return false; |
| 404 | } |
| 405 | |
| 406 | // Register BTN_LEFT for pointer click support |
| 407 | if (ioctl(fd_, UI_SET_KEYBIT, BTN_LEFT) < 0) { |
| 408 | LogError << "Failed to set BTN_LEFT" << VAR(errno) << VAR(std::strerror(errno)); |
| 409 | ::close(fd_); |
| 410 | fd_ = -1; |
| 411 | return false; |
| 412 | } |
| 413 | |
| 414 | for (int i = 0; i < 105; i++) { |
| 415 | ioctl(fd_, UI_SET_KEYBIT, i); |
| 416 | } |
| 417 | |
| 418 | // Register ONLY ABS_X and ABS_Y — absolute positioning axes. |
| 419 | // No ABS_MT_* axes at all, so udev will NOT classify this as a touchscreen/touchpad. |
| 420 | if (ioctl(fd_, UI_SET_ABSBIT, ABS_X) < 0) { |
| 421 | LogError << "Failed to set ABS_X" << VAR(errno) << VAR(std::strerror(errno)); |
| 422 | ::close(fd_); |
| 423 | fd_ = -1; |
| 424 | return false; |
| 425 | } |
| 426 | if (ioctl(fd_, UI_SET_ABSBIT, ABS_Y) < 0) { |
| 427 | LogError << "Failed to set ABS_Y" << VAR(errno) << VAR(std::strerror(errno)); |
| 428 | ::close(fd_); |
| 429 | fd_ = -1; |
nothing calls this directly
no outgoing calls
no test coverage detected