@@ -96,6 +96,9 @@ namespace bp = boost::process;
9696using namespace std ::literals;
9797
9898namespace platf {
99+ void check_and_force_cursor_visibility ();
100+ bool is_streaming = false ;
101+
99102 using adapteraddrs_t = util::c_ptr<IP_ADAPTER_ADDRESSES>;
100103
101104 bool enabled_mouse_keys = false ;
@@ -1133,33 +1136,10 @@ namespace platf {
11331136 }
11341137 }
11351138 }
1136-
1137- // If there is no mouse connected, enable Mouse Keys to force the cursor to appear
1138- if (!GetSystemMetrics (SM_MOUSEPRESENT)) {
1139- BOOST_LOG (info) << " A mouse was not detected. Sunshine will enable Mouse Keys while streaming to force the mouse cursor to appear." ;
1140-
1141- // Get the current state of Mouse Keys so we can restore it when streaming is over
1142- previous_mouse_keys_state.cbSize = sizeof (previous_mouse_keys_state);
1143- if (SystemParametersInfoW (SPI_GETMOUSEKEYS, 0 , &previous_mouse_keys_state, 0 )) {
1144- MOUSEKEYS new_mouse_keys_state = {};
1145-
1146- // Enable Mouse Keys
1147- new_mouse_keys_state.cbSize = sizeof (new_mouse_keys_state);
1148- new_mouse_keys_state.dwFlags = MKF_MOUSEKEYSON | MKF_AVAILABLE;
1149- new_mouse_keys_state.iMaxSpeed = 10 ;
1150- new_mouse_keys_state.iTimeToMaxSpeed = 1000 ;
1151- if (SystemParametersInfoW (SPI_SETMOUSEKEYS, 0 , &new_mouse_keys_state, 0 )) {
1152- // Remember to restore the previous settings when we stop streaming
1153- enabled_mouse_keys = true ;
1154- } else {
1155- auto winerr = GetLastError ();
1156- BOOST_LOG (warning) << " Unable to enable Mouse Keys: " sv << winerr;
1157- }
1158- } else {
1159- auto winerr = GetLastError ();
1160- BOOST_LOG (warning) << " Unable to get current state of Mouse Keys: " sv << winerr;
1161- }
1162- }
1139+ // Ensure the cursor is visible at stream startup
1140+ check_and_force_cursor_visibility ();
1141+ // Started streaming
1142+ is_streaming = true ;
11631143 }
11641144
11651145 void streaming_will_stop () {
@@ -1175,6 +1155,8 @@ namespace platf {
11751155 } else {
11761156 timeEndPeriod (1 );
11771157 }
1158+ // Update is_streaming to not run cursor visibility while not streaming
1159+ is_streaming = false ;
11781160
11791161 // Disable MMCSS scheduling for DWM
11801162 DwmEnableMMCSS (false );
@@ -1798,4 +1780,33 @@ namespace platf {
17981780 std::unique_ptr<high_precision_timer> create_high_precision_timer () {
17991781 return std::make_unique<win32_high_precision_timer>();
18001782 }
1783+
1784+ void check_and_force_cursor_visibility () {
1785+ if (!GetSystemMetrics (SM_MOUSEPRESENT)) {
1786+ BOOST_LOG (info) << " A mouse was not detected. Sunshine will enable Mouse Keys while streaming to force the mouse cursor to appear." ;
1787+
1788+ // Get the current state of Mouse Keys so we can restore it when streaming is over
1789+ previous_mouse_keys_state.cbSize = sizeof (previous_mouse_keys_state);
1790+ if (SystemParametersInfoW (SPI_GETMOUSEKEYS, 0 , &previous_mouse_keys_state, 0 )) {
1791+ MOUSEKEYS new_mouse_keys_state = {};
1792+
1793+ // Enable Mouse Keys
1794+ new_mouse_keys_state.cbSize = sizeof (new_mouse_keys_state);
1795+ new_mouse_keys_state.dwFlags = MKF_MOUSEKEYSON | MKF_AVAILABLE;
1796+ new_mouse_keys_state.iMaxSpeed = 10 ;
1797+ new_mouse_keys_state.iTimeToMaxSpeed = 1000 ;
1798+ if (SystemParametersInfoW (SPI_SETMOUSEKEYS, 0 , &new_mouse_keys_state, 0 )) {
1799+ // Remember to restore the previous settings when we stop streaming
1800+ enabled_mouse_keys = true ;
1801+ } else {
1802+ auto winerr = GetLastError ();
1803+ BOOST_LOG (warning) << " Unable to enable Mouse Keys: " sv << winerr;
1804+ }
1805+ } else {
1806+ auto winerr = GetLastError ();
1807+ BOOST_LOG (warning) << " Unable to get current state of Mouse Keys: " sv << winerr;
1808+ }
1809+ }
1810+ }
1811+
18011812} // namespace platf
0 commit comments