Browse Source

Fixed mouse being super sensitive when viewing the application through Parsec (#808)

Should fix #783
Jorrit Rouwe 1 year ago
parent
commit
021081fc7b
2 changed files with 27 additions and 2 deletions
  1. 25 2
      TestFramework/Input/Mouse.cpp
  2. 2 0
      TestFramework/Input/Mouse.h

+ 25 - 2
TestFramework/Input/Mouse.cpp

@@ -37,6 +37,26 @@ void Mouse::ResetMouse()
 	mDODLength = 0;
 	mTimeLeftButtonLastReleased = 0;
 	mLeftButtonDoubleClicked = false;
+
+}
+
+void Mouse::DetectParsecRunning()
+{
+	mIsParsecRunning = false;
+
+	if (SC_HANDLE manager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT))
+	{
+		if (SC_HANDLE service = OpenServiceA(manager, "Parsec", SERVICE_QUERY_STATUS))
+		{
+			SERVICE_STATUS status;
+			if (QueryServiceStatus(service, &status))
+			{
+				mIsParsecRunning = status.dwCurrentState == SERVICE_RUNNING;
+			}
+			CloseServiceHandle(service);
+		}
+		CloseServiceHandle(manager);
+	}
 }
 
 bool Mouse::Initialize(Renderer *inRenderer)
@@ -92,6 +112,9 @@ bool Mouse::Initialize(Renderer *inRenderer)
 		return false;
 	}
 
+	// Check if the parsec service is running
+	DetectParsecRunning();
+
 	return true;
 }
 
@@ -149,8 +172,8 @@ void Mouse::Poll()
 		}
 	}
 
-	// If we're connected through remote desktop then GetDeviceState returns faulty data for lX and lY so we need to use a fallback
-	if (GetSystemMetrics(SM_REMOTESESSION))
+	// If we're connected through remote desktop or Parsec then GetDeviceState returns faulty data for lX and lY so we need to use a fallback
+	if (GetSystemMetrics(SM_REMOTESESSION) || mIsParsecRunning)
 	{
 		// Just use the delta between the current and last mouse position.
 		// Note that this has the disadvantage that you can no longer rotate any further if you're at the edge of the screen,

+ 2 - 0
TestFramework/Input/Mouse.h

@@ -42,6 +42,7 @@ public:
 	void							SetExclusive(bool inExclusive = true);
 
 private:
+	void							DetectParsecRunning();
 	void							Reset();
 	void							ResetMouse();
 
@@ -54,6 +55,7 @@ private:
 	Renderer *						mRenderer;
 	ComPtr<IDirectInput8>			mDI;
 	ComPtr<IDirectInputDevice8>		mMouse;
+	bool							mIsParsecRunning;					///< If the Parsec remote desktop solution is running, if so we can't trust the mouse movement information from DX and it will make the mouse too sensitive
 	DIMOUSESTATE					mMouseState;
 	bool							mMousePosInitialized = false;
 	POINT							mMousePos;