diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index f1ff928d..b5e72628 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -207,6 +207,11 @@ SdlInputHandler::~SdlInputHandler() #endif } +void SdlInputHandler::setWindow(SDL_Window *window) +{ + m_Window = window; +} + void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event) { short keyCode; @@ -659,7 +664,7 @@ void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event) button); } -void SdlInputHandler::handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotionEvent* event) +void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event) { if (!isCaptureActive()) { // Not capturing @@ -678,7 +683,7 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotion src.h = m_StreamHeight; dst.x = dst.y = 0; - SDL_GetWindowSize(window, &dst.w, &dst.h); + SDL_GetWindowSize(m_Window, &dst.w, &dst.h); // Use the stream and window sizes to determine the video region StreamUtils::scaleSourceToDestinationSurface(&src, &dst); @@ -1223,7 +1228,7 @@ void SdlInputHandler::rumble(unsigned short controllerNumber, unsigned short low #endif } -void SdlInputHandler::handleTouchFingerEvent(SDL_Window* window, SDL_TouchFingerEvent* event) +void SdlInputHandler::handleTouchFingerEvent(SDL_TouchFingerEvent* event) { #if SDL_VERSION_ATLEAST(2, 0, 10) if (SDL_GetTouchDeviceType(event->touchId) != SDL_TOUCH_DEVICE_DIRECT) { @@ -1259,7 +1264,7 @@ void SdlInputHandler::handleTouchFingerEvent(SDL_Window* window, SDL_TouchFinger SDL_Rect src, dst; int windowWidth, windowHeight; - SDL_GetWindowSize(window, &windowWidth, &windowHeight); + SDL_GetWindowSize(m_Window, &windowWidth, &windowHeight); src.x = src.y = 0; src.w = m_StreamWidth; @@ -1354,7 +1359,7 @@ void SdlInputHandler::raiseAllKeys() m_KeysDown.clear(); } -void SdlInputHandler::notifyFocusGained(SDL_Window* window) +void SdlInputHandler::notifyFocusGained() { // Capture mouse cursor when user actives the window by clicking on // window's client area (borders and title bar excluded). @@ -1373,24 +1378,22 @@ void SdlInputHandler::notifyFocusGained(SDL_Window* window) Uint32 mouseState = SDL_GetGlobalMouseState(&mouseX, &mouseY); if (mouseState & SDL_BUTTON(SDL_BUTTON_LEFT)) { int x, y, width, height; - SDL_GetWindowPosition(window, &x, &y); - SDL_GetWindowSize(window, &width, &height); + SDL_GetWindowPosition(m_Window, &x, &y); + SDL_GetWindowSize(m_Window, &width, &height); if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height) { setCaptureActive(true); } } -#else - Q_UNUSED(window); #endif } -void SdlInputHandler::notifyFocusLost(SDL_Window* window) +void SdlInputHandler::notifyFocusLost() { // Release mouse cursor when another window is activated (e.g. by using ALT+TAB). // This lets user to interact with our window's title bar and with the buttons in it. // Doing this while the window is full-screen breaks the transition out of FS // (desktop and exclusive), so we must check for that before releasing mouse capture. - if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) && !m_AbsoluteMouseMode) { + if (!(SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN) && !m_AbsoluteMouseMode) { setCaptureActive(false); } diff --git a/app/streaming/input.h b/app/streaming/input.h index 632a21bd..ea791a38 100644 --- a/app/streaming/input.h +++ b/app/streaming/input.h @@ -43,11 +43,13 @@ public: ~SdlInputHandler(); + void setWindow(SDL_Window* window); + void handleKeyEvent(SDL_KeyboardEvent* event); void handleMouseButtonEvent(SDL_MouseButtonEvent* event); - void handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotionEvent* event); + void handleMouseMotionEvent(SDL_MouseMotionEvent* event); void handleMouseWheelEvent(SDL_MouseWheelEvent* event); @@ -61,15 +63,15 @@ public: void rumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor); - void handleTouchFingerEvent(SDL_Window* window, SDL_TouchFingerEvent* event); + void handleTouchFingerEvent(SDL_TouchFingerEvent* event); int getAttachedGamepadMask(); void raiseAllKeys(); - void notifyFocusGained(SDL_Window* window); + void notifyFocusGained(); - void notifyFocusLost(SDL_Window* window); + void notifyFocusLost(); bool isCaptureActive(); @@ -93,6 +95,7 @@ private: static Uint32 mouseEmulationTimerCallback(Uint32 interval, void* param); + SDL_Window* m_Window; bool m_MultiController; bool m_GamepadMouse; SDL_TimerID m_MouseMoveTimer; diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 30e946d6..e7b1b0fd 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -1081,6 +1081,8 @@ void Session::exec(int displayOriginX, int displayOriginY) return; } + m_InputHandler->setWindow(m_Window); + QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg")); QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888); svgImage.fill(0); @@ -1220,10 +1222,10 @@ void Session::exec(int displayOriginX, int displayOriginY) case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { - m_InputHandler->notifyFocusGained(m_Window); + m_InputHandler->notifyFocusGained(); } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { - m_InputHandler->notifyFocusLost(m_Window); + m_InputHandler->notifyFocusLost(); } // Capture the mouse on SDL_WINDOWEVENT_ENTER if needed @@ -1327,7 +1329,7 @@ void Session::exec(int displayOriginX, int displayOriginY) m_InputHandler->handleMouseButtonEvent(&event.button); break; case SDL_MOUSEMOTION: - m_InputHandler->handleMouseMotionEvent(m_Window, &event.motion); + m_InputHandler->handleMouseMotionEvent(&event.motion); break; case SDL_MOUSEWHEEL: m_InputHandler->handleMouseWheelEvent(&event.wheel); @@ -1349,7 +1351,7 @@ void Session::exec(int displayOriginX, int displayOriginY) case SDL_FINGERDOWN: case SDL_FINGERMOTION: case SDL_FINGERUP: - m_InputHandler->handleTouchFingerEvent(m_Window, &event.tfinger); + m_InputHandler->handleTouchFingerEvent(&event.tfinger); break; } }