Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
chenall committed Apr 23, 2023
2 parents afa5a0b + ccd30c8 commit 9c4c5eb
Show file tree
Hide file tree
Showing 170 changed files with 18,547 additions and 4,763 deletions.
6 changes: 3 additions & 3 deletions desktop-ipc/DesktopServerProto.cpp
Expand Up @@ -225,12 +225,12 @@ void DesktopServerProto::readNewClipboard(StringStorage *newClipboard,
gate->readUTF8(newClipboard);
}

void DesktopServerProto::sendNewPointerPos(const Point *newPos, UINT8 keyFlag,
void DesktopServerProto::sendNewPointerPos(const Point newPos, UINT8 keyFlag,
BlockingGate *gate)
{
// Send pointer position
gate->writeUInt16(newPos->x);
gate->writeUInt16(newPos->y);
gate->writeUInt16(newPos.x);
gate->writeUInt16(newPos.y);
// Send key flags
gate->writeUInt8(keyFlag);
}
Expand Down
3 changes: 2 additions & 1 deletion desktop-ipc/DesktopServerProto.h
Expand Up @@ -67,7 +67,7 @@ class DesktopServerProto
BlockingGate *gate);
virtual void readNewClipboard(StringStorage *newClipboard,
BlockingGate *gate);
virtual void sendNewPointerPos(const Point *newPos, UINT8 keyFlag,
virtual void sendNewPointerPos(const Point newPos, UINT8 keyFlag,
BlockingGate *gate);
virtual void readNewPointerPos(Point *newPos, UINT8 *keyFlag,
BlockingGate *gate);
Expand Down Expand Up @@ -107,6 +107,7 @@ class DesktopServerProto
static const UINT8 APPLICATION_REGION_REQ = 39;
static const UINT8 NORMALIZE_RECT_REQ = 40;
static const UINT8 APPLICATION_CHECK_FOCUS = 41;
static const UINT8 DISPLAYS_COORDS_REQ = 42;

static const UINT8 CONFIG_RELOAD_REQ = 50;
static const UINT8 SOFT_INPUT_ENABLING_REQ = 51;
Expand Down
1 change: 0 additions & 1 deletion desktop-ipc/DesktopSrvDispatcher.cpp
Expand Up @@ -38,7 +38,6 @@ DesktopSrvDispatcher::DesktopSrvDispatcher(BlockingGate *gate,
DesktopSrvDispatcher::~DesktopSrvDispatcher()
{
terminate();
resume();
wait();
}

Expand Down
26 changes: 25 additions & 1 deletion desktop-ipc/UserInputClient.cpp
Expand Up @@ -67,7 +67,7 @@ void UserInputClient::sendInit(BlockingGate *gate)
gate->writeUInt8(m_sendMouseFlags);
}

void UserInputClient::setMouseEvent(const Point *newPos, UINT8 keyFlag)
void UserInputClient::setMouseEvent(const Point newPos, UINT8 keyFlag)
{
AutoLock al(m_forwGate);
try {
Expand Down Expand Up @@ -145,6 +145,30 @@ void UserInputClient::getDisplayNumberCoords(Rect *rect,
} while (!success);
}

std::vector<Rect> UserInputClient::getDisplaysCoords()
{
std::vector<Rect> res;
AutoLock al(m_forwGate);
bool success = false;
unsigned char number;
do {
try {
res.resize(0);
// Send request
m_forwGate->writeUInt8(DISPLAYS_COORDS_REQ);
number = m_forwGate->readUInt8();
for (size_t i = 0; i < number; i++) {
Rect rect = readRect(m_forwGate);
res.push_back(rect);
}
success = true;
}
catch (ReconnectException &) {
}
} while (!success);
return res;
}

void UserInputClient::getNormalizedRect(Rect *rect)
{
AutoLock al(m_forwGate);
Expand Down
3 changes: 2 additions & 1 deletion desktop-ipc/UserInputClient.h
Expand Up @@ -42,13 +42,14 @@ class UserInputClient : public UserInput, public DesktopServerProto,

virtual void sendInit(BlockingGate *gate);
virtual void setNewClipboard(const StringStorage *newClipboard);
virtual void setMouseEvent(const Point *newPos, UINT8 keyFlag);
virtual void setMouseEvent(const Point newPos, UINT8 keyFlag);
virtual void setKeyboardEvent(UINT32 keySym, bool down);
virtual void getCurrentUserInfo(StringStorage *desktopName,
StringStorage *userName);
virtual void getPrimaryDisplayCoords(Rect *rect);
virtual void getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber);
virtual std::vector<Rect> getDisplaysCoords();
virtual void getNormalizedRect(Rect *rect);
virtual void getWindowCoords(HWND hwnd, Rect *rect);
virtual HWND getWindowHandleByName(const StringStorage *windowName);
Expand Down
20 changes: 19 additions & 1 deletion desktop-ipc/UserInputServer.cpp
Expand Up @@ -45,6 +45,7 @@ UserInputServer::UserInputServer(BlockingGate *forwGate,
dispatcher->registerNewHandle(WINDOW_COORDS_REQ, this);
dispatcher->registerNewHandle(WINDOW_HANDLE_REQ, this);
dispatcher->registerNewHandle(DISPLAY_NUMBER_COORDS_REQ, this);
dispatcher->registerNewHandle(DISPLAYS_COORDS_REQ, this);
dispatcher->registerNewHandle(APPLICATION_REGION_REQ, this);
dispatcher->registerNewHandle(APPLICATION_CHECK_FOCUS, this);
dispatcher->registerNewHandle(NORMALIZE_RECT_REQ, this);
Expand Down Expand Up @@ -101,6 +102,9 @@ void UserInputServer::onRequest(UINT8 reqCode, BlockingGate *backGate)
case DISPLAY_NUMBER_COORDS_REQ:
ansDisplayNumberCoords(backGate);
break;
case DISPLAYS_COORDS_REQ:
ansDisplaysCoords(backGate);
break;
case APPLICATION_REGION_REQ:
ansApplicationRegion(backGate);
break;
Expand Down Expand Up @@ -133,7 +137,7 @@ void UserInputServer::applyNewPointerPos(BlockingGate *backGate)
Point newPointerPos;
UINT8 keyFlags;
readNewPointerPos(&newPointerPos, &keyFlags, backGate);
m_userInput->setMouseEvent(&newPointerPos, keyFlags);
m_userInput->setMouseEvent(newPointerPos, keyFlags);
}

void UserInputServer::applyNewClipboard(BlockingGate *backGate)
Expand Down Expand Up @@ -197,6 +201,20 @@ void UserInputServer::ansDisplayNumberCoords(BlockingGate *backGate)
sendRect(&rect, backGate);
}

void UserInputServer::ansDisplaysCoords(BlockingGate *backGate)
{
std::vector<Rect> rects = m_userInput->getDisplaysCoords();
size_t number = rects.size();
if (number > 255) {
number = 255;
}
backGate->writeUInt8((UINT8)number);
for (size_t i = 0; i < number; i++) {
Rect rect = rects[i];
sendRect(&rect, backGate);
}
}

void UserInputServer::ansNormalizeRect(BlockingGate *backGate)
{
Rect rect = readRect(backGate);
Expand Down
1 change: 1 addition & 0 deletions desktop-ipc/UserInputServer.h
Expand Up @@ -57,6 +57,7 @@ class UserInputServer: public DesktopServerProto, public ClientListener,
virtual void ansUserInfo(BlockingGate *backGate);
virtual void ansWindowHandle(BlockingGate *backGate);
virtual void ansDisplayNumberCoords(BlockingGate *backGate);
virtual void ansDisplaysCoords(BlockingGate *backGate);
virtual void ansApplicationRegion(BlockingGate *backGate);
virtual void ansApplicationInFocus(BlockingGate *backGate);
virtual void ansNormalizeRect(BlockingGate *backGate);
Expand Down
2 changes: 1 addition & 1 deletion desktop/CursorPositionDetector.cpp
Expand Up @@ -60,7 +60,7 @@ void CursorPositionDetector::execute()
curPoint = m_cursor.getCursorPos();
if (!m_lastCursorPos.isEqualTo(&curPoint)) {
m_lastCursorPos = curPoint;
m_updateKeeper->setCursorPosChanged(&m_lastCursorPos);
m_updateKeeper->setCursorPos(&m_lastCursorPos);
doUpdate();
}
m_sleepTimer.waitForEvent(MOUSE_SLEEP_TIME);
Expand Down
2 changes: 2 additions & 0 deletions desktop/Desktop.h
Expand Up @@ -31,6 +31,7 @@
#include "rfb/PixelFormat.h"
#include "rfb/FrameBuffer.h"
#include "fb-update-sender/UpdateRequestListener.h"
#include <vector>

// This class is a public interface to a desktop.
class Desktop : public UpdateRequestListener
Expand All @@ -51,6 +52,7 @@ class Desktop : public UpdateRequestListener
virtual void getNormalizedRect(Rect *rect) = 0;
virtual void getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber) = 0;
virtual std::vector<Rect> getDisplaysCoords() = 0;
virtual void getWindowCoords(HWND hwnd, Rect *rect) = 0;
virtual HWND getWindowHandleByName(const StringStorage *windowName) = 0;

Expand Down
20 changes: 18 additions & 2 deletions desktop/DesktopBaseImpl.cpp
Expand Up @@ -91,11 +91,27 @@ void DesktopBaseImpl::getDisplayNumberCoords(Rect *rect,
try {
m_userInput->getDisplayNumberCoords(rect, dispNumber);
} catch (Exception &e) {
m_log->error(_T("Exception in DesktopBaseImpl::getDisplayNumberCoords: %s"), e.getMessage());
m_log->error(_T("Exception in DesktopBaseImpl::getDisplayNumberCoords: %s"), e.getMessage());
m_extDeskTermListener->onAbnormalDesktopTerminate();
}
}

std::vector<Rect> DesktopBaseImpl::getDisplaysCoords()
{
_ASSERT(m_userInput != 0);
_ASSERT(m_extDeskTermListener != 0);
m_log->info(_T("get the displays coordinates"));
try {
return m_userInput->getDisplaysCoords();
}
catch (Exception &e) {
m_log->error(_T("Exception in DesktopBaseImpl::getDisplayCoords: %s"), e.getMessage());
m_extDeskTermListener->onAbnormalDesktopTerminate();
}
return std::vector<Rect>();
}


void DesktopBaseImpl::getNormalizedRect(Rect *rect)
{
_ASSERT(m_userInput != 0);
Expand Down Expand Up @@ -199,7 +215,7 @@ void DesktopBaseImpl::setMouseEvent(UINT16 x, UINT16 y, UINT8 buttonMask)
Point point(x, y);
try {
if (isRemoteInputAllowed()) {
m_userInput->setMouseEvent(&point, buttonMask);
m_userInput->setMouseEvent(point, buttonMask);
}
} catch (Exception &e) {
m_log->error(_T("Exception in DesktopBaseImpl::setMouseEvent %s"), e.getMessage());
Expand Down
1 change: 1 addition & 0 deletions desktop/DesktopBaseImpl.h
Expand Up @@ -57,6 +57,7 @@ class DesktopBaseImpl : public Desktop,
virtual void getPrimaryDesktopCoords(Rect *rect);
virtual void getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber);
virtual std::vector<Rect> getDisplaysCoords();
virtual void getNormalizedRect(Rect *rect);
virtual void getWindowCoords(HWND hwnd, Rect *rect);
virtual HWND getWindowHandleByName(const StringStorage *windowName);
Expand Down
9 changes: 8 additions & 1 deletion desktop/HooksUpdateDetector.cpp
Expand Up @@ -37,6 +37,11 @@ HooksUpdateDetector::HooksUpdateDetector(UpdateKeeper *updateKeeper,
m_hookInstaller(0),
m_log(log)
{
#ifndef _WIN64
m_log->debug(_T("Loading the screenhook library for 32bit system"));
#else
m_log->debug(_T("Loading the screenhook library for 64bit system"));
#endif
try {
m_hookInstaller = new HookInstaller();
} catch (Exception &e) {
Expand All @@ -45,7 +50,7 @@ HooksUpdateDetector::HooksUpdateDetector(UpdateKeeper *updateKeeper,
}
HINSTANCE hinst = GetModuleHandle(0);
m_targetWin = new MessageWindow(hinst,
HookDefinitions::HOOK_TARGET_WIN_CLASS_NAME);
HookDefinitions::HOOK_TARGET_WIN_CLASS_NAME);
}

HooksUpdateDetector::~HooksUpdateDetector()
Expand All @@ -72,6 +77,7 @@ void HooksUpdateDetector::onTerminate()
void HooksUpdateDetector::start32Loader()
{
#ifdef _WIN64
m_log->debug(_T("Loading the screenhook library for 32bit system with hookldr.exe"));
if (!isTerminating()) {
StringStorage path, folder;
Environment::getCurrentModuleFolderPath(&folder);
Expand Down Expand Up @@ -160,6 +166,7 @@ void HooksUpdateDetector::execute()
m_updateKeeper->addChangedRect(&rect);
m_updateTimer.sear();
}
// m_log->debug(_T("Screenhook update rectangle: {x=%d, y=%d, w=%d, h=%d}"), rect.left, rect.top, rect.getWidth(), rect.getHeight());
} else {
DispatchMessage(&msg);
}
Expand Down
20 changes: 15 additions & 5 deletions desktop/SasUserInput.cpp
Expand Up @@ -24,6 +24,7 @@

#include "SasUserInput.h"
#include "win-system/Environment.h"
#include "win-system/WTS.h"

#define XK_MISCELLANY
#include "rfb/keysymdef.h"
Expand All @@ -47,7 +48,7 @@ void SasUserInput::sendInit(BlockingGate *gate)
m_client->sendInit(gate);
}

void SasUserInput::setMouseEvent(const Point *newPos, UINT8 keyFlag)
void SasUserInput::setMouseEvent(const Point newPos, UINT8 keyFlag)
{
m_client->setMouseEvent(newPos, keyFlag);
}
Expand Down Expand Up @@ -77,10 +78,14 @@ void SasUserInput::setKeyboardEvent(UINT32 keySym, bool down)
}

if (m_ctrlPressed && m_altPressed && delPressed && m_underVista) {
Environment::simulateCtrlAltDelUnderVista(m_log);
} else {
m_client->setKeyboardEvent(keySym, down);
}
DWORD sessionId = WTS::getActiveConsoleSessionId(m_log);
bool isRdp = WTS::SessionIsRdpSession(sessionId, m_log);
if (!isRdp) {
Environment::simulateCtrlAltDelUnderVista(m_log);
return;
}
}
m_client->setKeyboardEvent(keySym, down);
}

void SasUserInput::getCurrentUserInfo(StringStorage *desktopName,
Expand All @@ -94,6 +99,11 @@ void SasUserInput::getPrimaryDisplayCoords(Rect *rect)
m_client->getPrimaryDisplayCoords(rect);
}

std::vector<Rect> SasUserInput::getDisplaysCoords()
{
return m_client->getDisplaysCoords();
}

void SasUserInput::getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber)
{
Expand Down
3 changes: 2 additions & 1 deletion desktop/SasUserInput.h
Expand Up @@ -38,13 +38,14 @@ class SasUserInput : public UserInput

virtual void sendInit(BlockingGate *gate);
virtual void setNewClipboard(const StringStorage *newClipboard);
virtual void setMouseEvent(const Point *newPos, UINT8 keyFlag);
virtual void setMouseEvent(const Point newPos, UINT8 keyFlag);
virtual void setKeyboardEvent(UINT32 keySym, bool down);
virtual void getCurrentUserInfo(StringStorage *desktopName,
StringStorage *userName);
virtual void getPrimaryDisplayCoords(Rect *rect);
virtual void getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber);
virtual std::vector<Rect> getDisplaysCoords();
virtual void getNormalizedRect(Rect *rect);
virtual void getWindowCoords(HWND hwnd, Rect *rect);
virtual HWND getWindowHandleByName(const StringStorage *windowName);
Expand Down
5 changes: 5 additions & 0 deletions desktop/UpdateHandlerImpl.cpp
Expand Up @@ -98,6 +98,11 @@ void UpdateHandlerImpl::extract(UpdateContainer *updateContainer)
if (m_screenDriver->getScreenSizeChanged() || !currentDimension.isEqualTo(&newDimension)) {
updateContainer->screenSizeChanged = true;
}
m_log->debug(_T("UpdateHandlerImpl::extract: old dims: (%d,%d), new dims: (%d,%d)"),
currentDimension.width,
currentDimension.height,
newDimension.width,
newDimension.height);
m_log->debug(_T("UpdateHandlerImpl::extract : applyNewScreenProperties()"));
applyNewScreenProperties();
{
Expand Down
6 changes: 3 additions & 3 deletions desktop/UpdateKeeper.cpp
Expand Up @@ -142,16 +142,16 @@ void UpdateKeeper::setScreenSizeChanged()
m_updateContainer.screenSizeChanged = true;
}

void UpdateKeeper::setCursorPosChanged(const Point *curPos)
void UpdateKeeper::setCursorPosChanged()
{
AutoLock al(&m_updContLocMut);
m_updateContainer.cursorPosChanged = true;
m_updateContainer.cursorPos = *curPos;
}

void UpdateKeeper::setCursorPos(const Point *curPos)
{
AutoLock al(&m_updContLocMut);
m_updateContainer.cursorPosChanged = true;
m_updateContainer.cursorPos = *curPos;
}

Expand Down Expand Up @@ -188,7 +188,7 @@ void UpdateKeeper::addUpdateContainer(const UpdateContainer *updateContainer)
}
setCursorPos(&updateContainer->cursorPos);
if (updateContainer->cursorPosChanged) {
setCursorPosChanged(&updateContainer->cursorPos);
setCursorPos(&updateContainer->cursorPos);
}
if (updateContainer->cursorShapeChanged) {
setCursorShapeChanged();
Expand Down
2 changes: 1 addition & 1 deletion desktop/UpdateKeeper.h
Expand Up @@ -61,7 +61,7 @@ class UpdateKeeper : public Lockable
void setBorderRect(const Rect *borderRect);

void setScreenSizeChanged();
void setCursorPosChanged(const Point *curPos);
void setCursorPosChanged();
void setCursorPos(const Point *curPos);
void setCursorShapeChanged();

Expand Down
3 changes: 2 additions & 1 deletion desktop/UserInput.h
Expand Up @@ -47,14 +47,15 @@ class UserInput
virtual void setNewClipboard(const StringStorage *newClipboard) = 0;
// By the keyFlag argument will be set the mouse button state as described in
// the rfb protocol.
virtual void setMouseEvent(const Point *newPos, UINT8 keyFlag) = 0;
virtual void setMouseEvent(const Point newPos, UINT8 keyFlag) = 0;
virtual void setKeyboardEvent(UINT32 keySym, bool down) = 0;
virtual void getCurrentUserInfo(StringStorage *desktopName,
StringStorage *userName) = 0;

virtual void getPrimaryDisplayCoords(Rect *rect) = 0;
virtual void getDisplayNumberCoords(Rect *rect,
unsigned char dispNumber) = 0;
virtual std::vector<Rect> getDisplaysCoords() = 0;
virtual void getNormalizedRect(Rect *rect) = 0;

virtual void getWindowCoords(HWND hwnd, Rect *rect) = 0;
Expand Down

0 comments on commit 9c4c5eb

Please sign in to comment.