mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Partially unrevert 05e82c24 for macOS which still needs it
This commit is contained in:
parent
8cc61ca8b8
commit
080421f2fb
@ -19,6 +19,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s
|
|||||||
m_StreamHeight(streamHeight),
|
m_StreamHeight(streamHeight),
|
||||||
m_AbsoluteMouseMode(prefs.absoluteMouseMode),
|
m_AbsoluteMouseMode(prefs.absoluteMouseMode),
|
||||||
m_AbsoluteTouchMode(prefs.absoluteTouchMode),
|
m_AbsoluteTouchMode(prefs.absoluteTouchMode),
|
||||||
|
m_PendingFocusGain(false),
|
||||||
m_LeftButtonReleaseTimer(0),
|
m_LeftButtonReleaseTimer(0),
|
||||||
m_RightButtonReleaseTimer(0),
|
m_RightButtonReleaseTimer(0),
|
||||||
m_DragTimer(0),
|
m_DragTimer(0),
|
||||||
@ -192,6 +193,30 @@ void SdlInputHandler::raiseAllKeys()
|
|||||||
m_KeysDown.clear();
|
m_KeysDown.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SdlInputHandler::notifyFocusGained()
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_DARWIN)
|
||||||
|
int mouseX, mouseY;
|
||||||
|
Uint32 mouseState = SDL_GetGlobalMouseState(&mouseX, &mouseY);
|
||||||
|
if (mouseState & SDL_BUTTON_LMASK) {
|
||||||
|
int x, y, 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) {
|
||||||
|
if (m_AbsoluteMouseMode) {
|
||||||
|
// Send synthetic mouse motion until the button is lifted
|
||||||
|
m_PendingFocusGain = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Recapture the mouse
|
||||||
|
// FIXME: Why is this necessary with SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH?
|
||||||
|
setCaptureActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void SdlInputHandler::notifyFocusLost()
|
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).
|
||||||
|
@ -69,6 +69,8 @@ public:
|
|||||||
|
|
||||||
void raiseAllKeys();
|
void raiseAllKeys();
|
||||||
|
|
||||||
|
void notifyFocusGained();
|
||||||
|
|
||||||
void notifyFocusLost();
|
void notifyFocusLost();
|
||||||
|
|
||||||
bool isCaptureActive();
|
bool isCaptureActive();
|
||||||
@ -125,6 +127,8 @@ private:
|
|||||||
bool m_AbsoluteMouseMode;
|
bool m_AbsoluteMouseMode;
|
||||||
bool m_AbsoluteTouchMode;
|
bool m_AbsoluteTouchMode;
|
||||||
|
|
||||||
|
bool m_PendingFocusGain;
|
||||||
|
|
||||||
SDL_TouchFingerEvent m_TouchDownEvent[MAX_FINGERS];
|
SDL_TouchFingerEvent m_TouchDownEvent[MAX_FINGERS];
|
||||||
SDL_TimerID m_LeftButtonReleaseTimer;
|
SDL_TimerID m_LeftButtonReleaseTimer;
|
||||||
SDL_TimerID m_RightButtonReleaseTimer;
|
SDL_TimerID m_RightButtonReleaseTimer;
|
||||||
|
@ -122,5 +122,29 @@ Uint32 SdlInputHandler::mouseMoveTimerCallback(Uint32 interval, void *param)
|
|||||||
LiSendMouseMoveEvent(deltaX, deltaY);
|
LiSendMouseMoveEvent(deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (me->m_AbsoluteMouseMode && me->m_PendingFocusGain) {
|
||||||
|
int mouseX, mouseY;
|
||||||
|
int windowX, windowY;
|
||||||
|
SDL_Event event;
|
||||||
|
Uint32 buttonState = SDL_GetGlobalMouseState(&mouseX, &mouseY);
|
||||||
|
SDL_GetWindowPosition(me->m_Window, &windowX, &windowY);
|
||||||
|
|
||||||
|
// Send synthetic mouse move events until the button is released
|
||||||
|
event.motion.type = SDL_MOUSEMOTION;
|
||||||
|
event.motion.timestamp = SDL_GetTicks();
|
||||||
|
event.motion.windowID = SDL_GetWindowID(me->m_Window);
|
||||||
|
event.motion.which = 0;
|
||||||
|
event.motion.state = buttonState;
|
||||||
|
event.motion.x = mouseX - windowX;
|
||||||
|
event.motion.y = mouseY - windowY;
|
||||||
|
event.motion.xrel = 0;
|
||||||
|
event.motion.yrel = 0;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
|
||||||
|
if ((buttonState & SDL_BUTTON_LMASK) == 0) {
|
||||||
|
me->m_PendingFocusGain = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
@ -1218,7 +1218,10 @@ void Session::exec(int displayOriginX, int displayOriginY)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
|
||||||
|
m_InputHandler->notifyFocusGained();
|
||||||
|
}
|
||||||
|
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||||
m_InputHandler->notifyFocusLost();
|
m_InputHandler->notifyFocusLost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user