Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/platform/windows/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ using namespace std::literals;
namespace platf {
using adapteraddrs_t = util::c_ptr<IP_ADAPTER_ADDRESSES>;

bool enabled_mouse_keys = false;
MOUSEKEYS previous_mouse_keys_state;

std::filesystem::path appdata() {
WCHAR sunshine_path[MAX_PATH];
GetModuleFileNameW(NULL, sunshine_path, _countof(sunshine_path));
Expand Down Expand Up @@ -512,6 +515,35 @@ void streaming_will_start() {

// Promote ourselves to high priority class
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);

// If there is no mouse connected, enable Mouse Keys to force the cursor to appear
if(!GetSystemMetrics(SM_MOUSEPRESENT)) {
BOOST_LOG(info) << "A mouse was not detected. Sunshine will enable Mouse Keys while streaming to force the mouse cursor to appear.";

// Get the current state of Mouse Keys so we can restore it when streaming is over
previous_mouse_keys_state.cbSize = sizeof(previous_mouse_keys_state);
if(SystemParametersInfoW(SPI_GETMOUSEKEYS, 0, &previous_mouse_keys_state, 0)) {
MOUSEKEYS new_mouse_keys_state = {};

// Enable Mouse Keys
new_mouse_keys_state.cbSize = sizeof(new_mouse_keys_state);
new_mouse_keys_state.dwFlags = MKF_MOUSEKEYSON | MKF_AVAILABLE;
new_mouse_keys_state.iMaxSpeed = 10;
new_mouse_keys_state.iTimeToMaxSpeed = 1000;
if(SystemParametersInfoW(SPI_SETMOUSEKEYS, 0, &new_mouse_keys_state, 0)) {
// Remember to restore the previous settings when we stop streaming
enabled_mouse_keys = true;
}
else {
auto winerr = GetLastError();
BOOST_LOG(warning) << "Unable to enable Mouse Keys: "sv << winerr;
}
}
else {
auto winerr = GetLastError();
BOOST_LOG(warning) << "Unable to get current state of Mouse Keys: "sv << winerr;
}
}
}

void streaming_will_stop() {
Expand All @@ -523,6 +555,15 @@ void streaming_will_stop() {

// Disable MMCSS scheduling for DWM
DwmEnableMMCSS(false);

// Restore Mouse Keys back to the previous settings if we turned it on
if(enabled_mouse_keys) {
enabled_mouse_keys = false;
if(!SystemParametersInfoW(SPI_SETMOUSEKEYS, 0, &previous_mouse_keys_state, 0)) {
auto winerr = GetLastError();
BOOST_LOG(warning) << "Unable to restore original state of Mouse Keys: "sv << winerr;
}
}
}

bool restart_supported() {
Expand Down