| 350 | } |
| 351 | |
| 352 | void raw_mouse_handler::update_devices() |
| 353 | { |
| 354 | u32 max_connect; |
| 355 | { |
| 356 | std::lock_guard lock(mutex); |
| 357 | max_connect = m_info.max_connect; |
| 358 | } |
| 359 | |
| 360 | { |
| 361 | std::map<void*, raw_mouse> enumerated = enumerate_devices(max_connect); |
| 362 | |
| 363 | std::lock_guard lock(m_raw_mutex); |
| 364 | |
| 365 | if (m_is_for_gui) |
| 366 | { |
| 367 | // Use the new devices |
| 368 | m_raw_mice = std::move(enumerated); |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | // Integrate the new devices |
| 373 | std::map<void*, raw_mouse> updated_mice; |
| 374 | |
| 375 | for (u32 i = 0; i < std::min(max_connect, ::size32(g_cfg_raw_mouse.players)); i++) |
| 376 | { |
| 377 | const auto& player = ::at32(g_cfg_raw_mouse.players, i); |
| 378 | const std::string device_name = player->device.to_string(); |
| 379 | |
| 380 | // Check if the configured device for this player is connected |
| 381 | if (const auto it = std::find_if(enumerated.begin(), enumerated.end(), [&device_name](const auto& entry) |
| 382 | { |
| 383 | return entry.second.device_name() == device_name; |
| 384 | }); |
| 385 | it != enumerated.cend()) |
| 386 | { |
| 387 | // Check if the device was already known |
| 388 | const auto it_exists = m_raw_mice.find(it->first); |
| 389 | const bool exists = it_exists != m_raw_mice.cend(); |
| 390 | |
| 391 | // Copy by value to allow for the same device for multiple players |
| 392 | raw_mouse& mouse = updated_mice[it->first]; |
| 393 | mouse = exists ? it_exists->second : it->second; |
| 394 | mouse.set_index(i); |
| 395 | |
| 396 | if (!exists) |
| 397 | { |
| 398 | // Initialize and center mouse |
| 399 | mouse.update_window_handle(); |
| 400 | mouse.center_cursor(); |
| 401 | |
| 402 | input_log.notice("raw_mouse_handler: added new device for player %d: '%s'", i, device_name); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | // Log disconnected devices |
| 408 | for (const auto& [handle, mouse] : m_raw_mice) |
| 409 | { |
nothing calls this directly
no test coverage detected