mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Store a pointer to the window inside the input handler
This commit is contained in:
parent
d7fd578cc3
commit
dbafd05a4e
@ -207,6 +207,11 @@ SdlInputHandler::~SdlInputHandler()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SdlInputHandler::setWindow(SDL_Window *window)
|
||||||
|
{
|
||||||
|
m_Window = window;
|
||||||
|
}
|
||||||
|
|
||||||
void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
|
void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)
|
||||||
{
|
{
|
||||||
short keyCode;
|
short keyCode;
|
||||||
@ -659,7 +664,7 @@ void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event)
|
|||||||
button);
|
button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdlInputHandler::handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotionEvent* event)
|
void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event)
|
||||||
{
|
{
|
||||||
if (!isCaptureActive()) {
|
if (!isCaptureActive()) {
|
||||||
// Not capturing
|
// Not capturing
|
||||||
@ -678,7 +683,7 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotion
|
|||||||
src.h = m_StreamHeight;
|
src.h = m_StreamHeight;
|
||||||
|
|
||||||
dst.x = dst.y = 0;
|
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
|
// Use the stream and window sizes to determine the video region
|
||||||
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
||||||
@ -1223,7 +1228,7 @@ void SdlInputHandler::rumble(unsigned short controllerNumber, unsigned short low
|
|||||||
#endif
|
#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_VERSION_ATLEAST(2, 0, 10)
|
||||||
if (SDL_GetTouchDeviceType(event->touchId) != SDL_TOUCH_DEVICE_DIRECT) {
|
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;
|
SDL_Rect src, dst;
|
||||||
int windowWidth, windowHeight;
|
int windowWidth, windowHeight;
|
||||||
|
|
||||||
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
SDL_GetWindowSize(m_Window, &windowWidth, &windowHeight);
|
||||||
|
|
||||||
src.x = src.y = 0;
|
src.x = src.y = 0;
|
||||||
src.w = m_StreamWidth;
|
src.w = m_StreamWidth;
|
||||||
@ -1354,7 +1359,7 @@ void SdlInputHandler::raiseAllKeys()
|
|||||||
m_KeysDown.clear();
|
m_KeysDown.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdlInputHandler::notifyFocusGained(SDL_Window* window)
|
void SdlInputHandler::notifyFocusGained()
|
||||||
{
|
{
|
||||||
// Capture mouse cursor when user actives the window by clicking on
|
// Capture mouse cursor when user actives the window by clicking on
|
||||||
// window's client area (borders and title bar excluded).
|
// 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);
|
Uint32 mouseState = SDL_GetGlobalMouseState(&mouseX, &mouseY);
|
||||||
if (mouseState & SDL_BUTTON(SDL_BUTTON_LEFT)) {
|
if (mouseState & SDL_BUTTON(SDL_BUTTON_LEFT)) {
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
SDL_GetWindowPosition(window, &x, &y);
|
SDL_GetWindowPosition(m_Window, &x, &y);
|
||||||
SDL_GetWindowSize(window, &width, &height);
|
SDL_GetWindowSize(m_Window, &width, &height);
|
||||||
if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height) {
|
if (mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+height) {
|
||||||
setCaptureActive(true);
|
setCaptureActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
Q_UNUSED(window);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdlInputHandler::notifyFocusLost(SDL_Window* window)
|
void SdlInputHandler::notifyFocusLost()
|
||||||
{
|
{
|
||||||
// Release mouse cursor when another window is activated (e.g. by using ALT+TAB).
|
// 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.
|
// 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
|
// 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.
|
// (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);
|
setCaptureActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,13 @@ public:
|
|||||||
|
|
||||||
~SdlInputHandler();
|
~SdlInputHandler();
|
||||||
|
|
||||||
|
void setWindow(SDL_Window* window);
|
||||||
|
|
||||||
void handleKeyEvent(SDL_KeyboardEvent* event);
|
void handleKeyEvent(SDL_KeyboardEvent* event);
|
||||||
|
|
||||||
void handleMouseButtonEvent(SDL_MouseButtonEvent* event);
|
void handleMouseButtonEvent(SDL_MouseButtonEvent* event);
|
||||||
|
|
||||||
void handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotionEvent* event);
|
void handleMouseMotionEvent(SDL_MouseMotionEvent* event);
|
||||||
|
|
||||||
void handleMouseWheelEvent(SDL_MouseWheelEvent* event);
|
void handleMouseWheelEvent(SDL_MouseWheelEvent* event);
|
||||||
|
|
||||||
@ -61,15 +63,15 @@ public:
|
|||||||
|
|
||||||
void rumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor);
|
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();
|
int getAttachedGamepadMask();
|
||||||
|
|
||||||
void raiseAllKeys();
|
void raiseAllKeys();
|
||||||
|
|
||||||
void notifyFocusGained(SDL_Window* window);
|
void notifyFocusGained();
|
||||||
|
|
||||||
void notifyFocusLost(SDL_Window* window);
|
void notifyFocusLost();
|
||||||
|
|
||||||
bool isCaptureActive();
|
bool isCaptureActive();
|
||||||
|
|
||||||
@ -93,6 +95,7 @@ private:
|
|||||||
static
|
static
|
||||||
Uint32 mouseEmulationTimerCallback(Uint32 interval, void* param);
|
Uint32 mouseEmulationTimerCallback(Uint32 interval, void* param);
|
||||||
|
|
||||||
|
SDL_Window* m_Window;
|
||||||
bool m_MultiController;
|
bool m_MultiController;
|
||||||
bool m_GamepadMouse;
|
bool m_GamepadMouse;
|
||||||
SDL_TimerID m_MouseMoveTimer;
|
SDL_TimerID m_MouseMoveTimer;
|
||||||
|
@ -1081,6 +1081,8 @@ void Session::exec(int displayOriginX, int displayOriginY)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_InputHandler->setWindow(m_Window);
|
||||||
|
|
||||||
QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg"));
|
QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg"));
|
||||||
QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888);
|
QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888);
|
||||||
svgImage.fill(0);
|
svgImage.fill(0);
|
||||||
@ -1220,10 +1222,10 @@ void Session::exec(int displayOriginX, int displayOriginY)
|
|||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
|
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) {
|
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
|
// 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);
|
m_InputHandler->handleMouseButtonEvent(&event.button);
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
m_InputHandler->handleMouseMotionEvent(m_Window, &event.motion);
|
m_InputHandler->handleMouseMotionEvent(&event.motion);
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
m_InputHandler->handleMouseWheelEvent(&event.wheel);
|
m_InputHandler->handleMouseWheelEvent(&event.wheel);
|
||||||
@ -1349,7 +1351,7 @@ void Session::exec(int displayOriginX, int displayOriginY)
|
|||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
m_InputHandler->handleTouchFingerEvent(m_Window, &event.tfinger);
|
m_InputHandler->handleTouchFingerEvent(&event.tfinger);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user