diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 5df74a951..e3490e207 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -58,7 +58,7 @@ std::vector InputManager::getInputDevices() const //looks like a joystick. add to devices. currentDevices.push_back(InputDevice(deviceName, 0, 0)); } - dirIt++; + ++dirIt; } //or dump /proc/bus/input/devices anbd search for a Handler=..."js"... entry #elif defined(WIN32) || defined(_WIN32) @@ -122,14 +122,13 @@ Uint32 InputManager::devicePollingCallback(Uint32 interval, void* param) //this thing my be running in a different thread, so we're not allowed to call //any functions or change/allocate/delete stuff, but can send a user event SDL_Event event; - SDL_UserEvent userevent; - userevent.type = SDL_USEREVENT_POLLDEVICES; - userevent.code = 0; - userevent.data1 = nullptr; - userevent.data2 = nullptr; - event.type = SDL_USEREVENT; - event.user = userevent; - SDL_PushEvent(&event); + event.user.type = SDL_USEREVENT; + event.user.code = SDL_USEREVENT_POLLDEVICES; + event.user.data1 = nullptr; + event.user.data2 = nullptr; + if (SDL_PushEvent(&event) != 0) { + LOG(LogError) << "InputManager::devicePollingCallback - SDL event queue is full!"; + } return interval; } @@ -290,15 +289,20 @@ bool InputManager::parseEvent(const SDL_Event& ev) mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false)); return true; - case SDL_USEREVENT_POLLDEVICES: - //poll joystick / HID again - std::vector currentDevices = getInputDevices(); - //compare device lists to see if devices were added/deleted - if (currentDevices != inputDevices) { - LOG(LogInfo) << "Device configuration changed!"; - inputDevices = currentDevices; + case SDL_USEREVENT: + if (ev.user.code == SDL_USEREVENT_POLLDEVICES) { + //poll joystick / HID again + std::vector currentDevices = getInputDevices(); + //compare device lists to see if devices were added/deleted + if (currentDevices != inputDevices) { + LOG(LogInfo) << "Device configuration changed!"; + inputDevices = currentDevices; + //deinit and reinit InputManager + deinit(); + init(); + } + return true; } - return true; } return false; diff --git a/src/main.cpp b/src/main.cpp index 64367bb05..4823308bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) timeSinceLastEvent = 0; } break; - case InputManager::SDL_USEREVENT_POLLDEVICES: + case SDL_USEREVENT: //try to poll input devices, but do not necessarily wake up... window.getInputManager()->parseEvent(event); break; @@ -181,7 +181,7 @@ int main(int argc, char* argv[]) if(sleeping) { lastTime = SDL_GetTicks(); - sleep(1); //this doesn't need to accurate + SDL_Delay(1); //this doesn't need to be accurate continue; } @@ -225,7 +225,6 @@ int main(int argc, char* argv[]) Renderer::swapBuffers(); } - Log::flush(); }