Merge pull request #6577 from symless/v1-issue-5294-cursor-locked

Prevented cursor moving off screen when a locking issue may occur
This commit is contained in:
Jnewbon 2019-10-18 15:31:05 +01:00 committed by GitHub
commit e367fa9d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 3 deletions

View File

@ -329,6 +329,13 @@ MSWindowsScreen::enter()
bool bool
MSWindowsScreen::leave() MSWindowsScreen::leave()
{ {
POINT pos;
if (!getThisCursorPos(&pos))
{
LOG((CLOG_DEBUG "Unable to leave screen as Windows security has disabled critical functions required to let synergy work"));
//unable to get position this means synergy will break if the cursor leaves the screen
return false;
}
// get keyboard layout of foreground window. we'll use this // get keyboard layout of foreground window. we'll use this
// keyboard layout for translating keys sent to clients. // keyboard layout for translating keys sent to clients.
HWND window = GetForegroundWindow(); HWND window = GetForegroundWindow();
@ -539,6 +546,60 @@ MSWindowsScreen::getCursorPos(SInt32& x, SInt32& y) const
m_desks->getCursorPos(x, y); m_desks->getCursorPos(x, y);
} }
/*
* getThisCursorPos and setThisCursorPos will attempt to negotiate with the system
* to try get the and set the mouse position, however on the logon screen due to
* hooks this process has it may unable to work around the problem. Although these
* functions did not fix the issue at hand (#5294) its worth keeping them here anyway.
*/
bool MSWindowsScreen::getThisCursorPos(LPPOINT pos)
{
auto result = GetCursorPos(pos);
auto error = GetLastError();
LOG((CLOG_DEBUG3 "%s Attempt: 1 , status %d, code: %d Pos {%d, %d}", __func__, result, error, pos->x, pos->y));
if (!result)
{
result = GetCursorPos(pos);
error = GetLastError();
LOG((CLOG_INFO "%s Attempt: 2, status %d, code: %d Pos {%d, %d}", __func__, result, error, pos->x, pos->y));
updateDesktopThread();
}
return result;
}
bool MSWindowsScreen::setThisCursorPos(int x, int y)
{
auto result = SetCursorPos(x, y);
auto error = GetLastError();
LOG((CLOG_DEBUG3 "%s Attempt: 1, status %d, code: %d", __func__, result, error));
if (!result)
{
result = SetCursorPos(x, y);
error = GetLastError();
LOG((CLOG_INFO "%s Attempt: 2, status %d, code: %d", __func__, result, error));
updateDesktopThread();
}
return result;
}
void MSWindowsScreen::updateDesktopThread()
{
LOG((CLOG_DEBUG3 "Failed to set cursor Attempting to switch desktop"));
SetLastError(0);
HDESK cur_hdesk = OpenInputDesktop(0, true, GENERIC_ALL);
auto error = GetLastError();
LOG((CLOG_DEBUG3 "\tGetting desktop Handle: %p Status code: %d", cur_hdesk, error));
error = GetLastError();
LOG((CLOG_DEBUG3 "\tSetting desktop return: %d Status code: %d", SetThreadDesktop(cur_hdesk), GetLastError()));
CloseDesktop(cur_hdesk);
}
void void
MSWindowsScreen::reconfigure(UInt32 activeSides) MSWindowsScreen::reconfigure(UInt32 activeSides)
{ {
@ -1524,12 +1585,12 @@ MSWindowsScreen::warpCursorNoFlush(SInt32 x, SInt32 y)
// warp mouse. hopefully this inserts a mouse motion event // warp mouse. hopefully this inserts a mouse motion event
// between the previous message and the following message. // between the previous message and the following message.
SetCursorPos(x, y); setThisCursorPos(x, y);
// check to see if the mouse pos was set correctly // check to see if the mouse pos was set correctly
POINT cursorPos; POINT cursorPos;
GetCursorPos(&cursorPos); getThisCursorPos(&cursorPos);
// there is a bug or round error in SetCursorPos and GetCursorPos on // there is a bug or round error in SetCursorPos and GetCursorPos on
// a high DPI setting. The check here is for Vista/7 login screen. // a high DPI setting. The check here is for Vista/7 login screen.
// since this feature is mainly for client, so only check on client. // since this feature is mainly for client, so only check on client.

View File

@ -75,6 +75,25 @@ public:
SInt32& width, SInt32& height) const; SInt32& width, SInt32& height) const;
virtual void getCursorPos(SInt32& x, SInt32& y) const; virtual void getCursorPos(SInt32& x, SInt32& y) const;
/**
* \brief Get the position of the cursor on the current machine
* \param pos the object that the function will use to store the position of the cursor
* \return true if the function was successful
*/
virtual bool getThisCursorPos(LPPOINT pos);
/**
* \brief Sets the cursor position on the current machine
* \param x The x coordinate of the cursor
* \param y The Y coordinate of the cursor
* \return True is successful
*/
virtual bool setThisCursorPos(int x, int y);
/**
* \brief This function will attempt to switch to the current desktop the mouse is located on
*/
virtual void updateDesktopThread();
// IPrimaryScreen overrides // IPrimaryScreen overrides
virtual void reconfigure(UInt32 activeSides); virtual void reconfigure(UInt32 activeSides);
virtual void warpCursor(SInt32 x, SInt32 y); virtual void warpCursor(SInt32 x, SInt32 y);