mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-02-21 18:39:59 +00:00
Enable Mouse Keys while streaming for systems with no mouse plugged in (#721)
This commit is contained in:
parent
e2fce257b5
commit
7770b5f708
@ -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));
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user