| 343 | } |
| 344 | |
| 345 | std::optional<sf::Event> eventProcess() |
| 346 | { |
| 347 | const std::lock_guard lock(inputMutex); |
| 348 | |
| 349 | // Ensure that we are initialized |
| 350 | initFileDescriptors(); |
| 351 | |
| 352 | // This is for handling the Backspace and DEL text events, which we |
| 353 | // generate based on keystrokes (and not stdin) |
| 354 | static unsigned int doDeferredText = 0; |
| 355 | if (doDeferredText) |
| 356 | { |
| 357 | const auto event = sf::Event::TextEntered{doDeferredText}; |
| 358 | |
| 359 | doDeferredText = 0; |
| 360 | return event; |
| 361 | } |
| 362 | |
| 363 | ssize_t bytesRead = 0; |
| 364 | |
| 365 | // Check all the open file descriptors for the next event |
| 366 | for (auto& fileDescriptor : fileDescriptors) |
| 367 | { |
| 368 | input_event inputEvent{}; |
| 369 | bytesRead = read(fileDescriptor, &inputEvent, sizeof(inputEvent)); |
| 370 | |
| 371 | while (bytesRead > 0) |
| 372 | { |
| 373 | if (inputEvent.type == EV_KEY) |
| 374 | { |
| 375 | if (const std::optional<sf::Mouse::Button> mb = toMouseButton(inputEvent.code)) |
| 376 | { |
| 377 | mouseMap[*mb] = inputEvent.value; |
| 378 | |
| 379 | if (inputEvent.value) |
| 380 | return sf::Event::MouseButtonPressed{*mb, mousePos}; |
| 381 | |
| 382 | return sf::Event::MouseButtonReleased{*mb, mousePos}; |
| 383 | } |
| 384 | |
| 385 | const sf::Keyboard::Key kb = toKey(inputEvent.code); |
| 386 | |
| 387 | unsigned int special = 0; |
| 388 | if ((kb == sf::Keyboard::Key::Delete) || (kb == sf::Keyboard::Key::Backspace)) |
| 389 | special = (kb == sf::Keyboard::Key::Delete) ? 127 : 8; |
| 390 | |
| 391 | if (inputEvent.value == 2) |
| 392 | { |
| 393 | // key repeat events |
| 394 | // |
| 395 | if (special) |
| 396 | { |
| 397 | return sf::Event::TextEntered{special}; |
| 398 | } |
| 399 | } |
| 400 | else if (kb != sf::Keyboard::Key::Unknown) |
| 401 | { |
| 402 | // key down and key up events |
no test coverage detected