refactor: Improve logging for errors when setting/getting cursor pos on Windows
This commit is contained in:
parent
09c157f9e1
commit
2322f312a9
1 changed files with 37 additions and 18 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
#include "arch/win32/ArchMiscWindows.h"
|
#include "arch/win32/ArchMiscWindows.h"
|
||||||
|
#include "arch/win32/XArchWindows.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "base/TMethodEventJob.h"
|
#include "base/TMethodEventJob.h"
|
||||||
|
|
@ -515,27 +516,38 @@ void MSWindowsScreen::getCursorPos(int32_t &x, int32_t &y) const
|
||||||
bool MSWindowsScreen::getThisCursorPos(LPPOINT pos)
|
bool MSWindowsScreen::getThisCursorPos(LPPOINT pos)
|
||||||
{
|
{
|
||||||
auto result = GetCursorPos(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) {
|
if (!result) {
|
||||||
|
XArchEvalWindows error1;
|
||||||
|
LOG_DEBUG("could not get cursor pos, error: %s", error1.eval().c_str());
|
||||||
|
|
||||||
|
LOG_DEBUG("retrying get cursor pos");
|
||||||
result = GetCursorPos(pos);
|
result = GetCursorPos(pos);
|
||||||
error = GetLastError();
|
if (!result) {
|
||||||
LOG((CLOG_DEBUG3 "%s Attempt: 2, status %d, code: %d Pos {%d, %d}", __func__, result, error, pos->x, pos->y));
|
XArchEvalWindows error2;
|
||||||
updateDesktopThread();
|
LOG((CLOG_DEBUG "could not get cursor pos, error: %s", error2.eval().c_str()));
|
||||||
|
|
||||||
|
updateDesktopThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MSWindowsScreen::setThisCursorPos(int x, int y)
|
bool MSWindowsScreen::setThisCursorPos(int x, int y)
|
||||||
{
|
{
|
||||||
auto result = SetCursorPos(x, y);
|
auto result = SetCursorPos(x, y);
|
||||||
auto error = GetLastError();
|
|
||||||
LOG((CLOG_DEBUG3 "%s Attempt: 1, status %d, code: %d", __func__, result, error));
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
XArchEvalWindows error1;
|
||||||
|
LOG_DEBUG("could not set cursor pos, error: %s", error1.eval().c_str());
|
||||||
|
|
||||||
|
LOG_DEBUG("retrying to set cursor pos");
|
||||||
result = SetCursorPos(x, y);
|
result = SetCursorPos(x, y);
|
||||||
error = GetLastError();
|
if (!result) {
|
||||||
LOG((CLOG_DEBUG3 "%s Attempt: 2, status %d, code: %d", __func__, result, error));
|
XArchEvalWindows error2;
|
||||||
updateDesktopThread();
|
LOG((CLOG_DEBUG "could not set cursor pos, error: %s", error2.eval().c_str()));
|
||||||
|
|
||||||
|
updateDesktopThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -543,17 +555,24 @@ bool MSWindowsScreen::setThisCursorPos(int x, int y)
|
||||||
|
|
||||||
void MSWindowsScreen::updateDesktopThread()
|
void MSWindowsScreen::updateDesktopThread()
|
||||||
{
|
{
|
||||||
LOG((CLOG_WARN "failed to set cursor while attempting to switch desktop"));
|
LOG_DEBUG("updating desktop thread");
|
||||||
SetLastError(0);
|
|
||||||
HDESK cur_hdesk = OpenInputDesktop(0, true, GENERIC_ALL);
|
|
||||||
|
|
||||||
auto error = GetLastError();
|
HDESK hDesk = OpenInputDesktop(0, true, GENERIC_ALL);
|
||||||
LOG((CLOG_DEBUG3 "current desktop, handle=%p code=%d", cur_hdesk, error));
|
if (hDesk == NULL) {
|
||||||
|
XArchEvalWindows error1;
|
||||||
|
LOG_DEBUG("could not open input desktop, error: %s", error1.eval().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error = GetLastError();
|
if (!SetThreadDesktop(hDesk)) {
|
||||||
LOG((CLOG_DEBUG3 "setting desktop, return=%d code=%d", SetThreadDesktop(cur_hdesk), GetLastError()));
|
XArchEvalWindows error1;
|
||||||
|
LOG_DEBUG("could not set thread desktop, error: %s", error1.eval().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
CloseDesktop(cur_hdesk);
|
if (!CloseDesktop(hDesk)) {
|
||||||
|
XArchEvalWindows error1;
|
||||||
|
LOG_DEBUG("could not close desktop, error: %s", error1.eval().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsScreen::reconfigure(uint32_t activeSides)
|
void MSWindowsScreen::reconfigure(uint32_t activeSides)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue