Skip to content

Commit

Permalink
FreeRDP::Rail: modify window
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Dec 28, 2024
1 parent 9d18e01 commit aa857c1
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 105 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### v0.0.31
- Use [RabbitCommon v2.3.2](https://github.com/KangLin/RabbitCommon/releases/tag/v2.3.2)
- FreeRDP
- Add remote application

### v0.0.30
- Client: fix CFrmParameterClient don't save parameters
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### v0.0.31
- 使用 [RabbitCommon v2.3.2](https://github.com/KangLin/RabbitCommon/releases/tag/v2.3.2)
- FreeRDP
- 增加远程应用

### v0.0.30
- 客户端: 修复 CFrmParameterClient 不保存参数错误
Expand Down
6 changes: 4 additions & 2 deletions Client/FrmViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ CFrmViewer::CFrmViewer(QWidget *parent)
setFocus();

// When the connecter is not connected, don't accept keyboard and mouse event
// When the CConnecter::sigConnected() set true. accept keyboard and mouse event
// \see CConnecter::sigConnected()
// When the CConnect::sigConnected() set true. accept keyboard and mouse event
// \see CConnect::sigConnected()
// CConnectDesktop::SetViewer
// CFrmViewer::slotConnected()
setEnabled(false);
}

Expand Down
2 changes: 1 addition & 1 deletion Client/FrmViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Q_SLOTS:

int ReSize(int width, int height);
void paintDesktop();
int TranslationMousePoint(QPointF inPos, QPointF &outPos);
virtual int TranslationMousePoint(QPointF inPos, QPointF &outPos);
QRectF GetAspectRationRect();

public:
Expand Down
51 changes: 33 additions & 18 deletions Plugins/FreeRDP/Client/ConnectFreeRDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ void CConnectFreeRDP::OnChannelConnectedEventHandler(void *context,
if(!pThis->m_pRail)
{
pThis->m_pRail = new CRail(pThis);
pThis->m_pRailManageWindows->ConnecRail(pThis->m_pRail);
pThis->m_pRailManageWindows->Connect(pThis->m_pRail);
}
if(pThis->m_pRail)
pThis->m_pRail->Init((RailClientContext*)e->pInterface);
Expand Down Expand Up @@ -1513,21 +1513,24 @@ BOOL CConnectFreeRDP::cb_begin_paint(rdpContext *context)
return TRUE;
}

BOOL CConnectFreeRDP::UpdateBuffer(INT32 x, INT32 y, INT32 w, INT32 h)
BOOL CConnectFreeRDP::UpdateBuffer(QRect rect)
{
if(x > m_Image.width() || y > m_Image.height()) {
QImage img = GetImage(rect);
emit sigUpdateRect(rect, img);
return TRUE;
}

QImage CConnectFreeRDP::GetImage(QRect r)
{
QImage img;
if(!m_Image.rect().contains(r)) {
qCritical(log) << "The width and height out of range."
<< "Image width:" << m_Image.width()
<< "Image height:" << m_Image.height()
<< "w:" << w << "h:" << h;
return FALSE;
<< "Image:" << m_Image.rect()
<< r;
return img;
}

QRect rect(x, y, w, h);
QImage img = m_Image.copy(rect);
//qDebug(log) << "Image:" << rect << img.rect() << img;
emit sigUpdateRect(rect, img);
return TRUE;
return m_Image.copy(r);
}

BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
Expand Down Expand Up @@ -1583,10 +1586,15 @@ BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
{
extents = region16_extents(&invalidRegion);
//qDebug(log) << extents->left << extents->top << extents->right << extents->bottom;
pThis->UpdateBuffer(extents->left,
extents->top,
extents->right - extents->left,
extents->bottom - extents->top);
QRect rect(extents->left,
extents->top,
extents->right - extents->left,
extents->bottom - extents->top);
pThis->UpdateBuffer(rect);

if(pThis->m_pRailManageWindows) {
emit pThis->sigRailInvalidateRect(rect);
}
}

region16_uninit(&invalidRegion);
Expand All @@ -1612,7 +1620,7 @@ BOOL CConnectFreeRDP::cb_desktop_resize(rdpContext* context)
return FALSE;

emit pThis->sigSetDesktopSize(desktopWidth, desktopHeight);
pThis->UpdateBuffer(0, 0, desktopWidth, desktopHeight);
pThis->UpdateBuffer(QRect(0, 0, desktopWidth, desktopHeight));
return TRUE;
}

Expand Down Expand Up @@ -2165,5 +2173,12 @@ int CConnectFreeRDP::InitRemoteApp()

int CConnectFreeRDP::SetRailViewer(CFrmViewer *pView)
{
return CConnectDesktop::SetViewer(pView, true);
int nRet = CConnectDesktop::SetViewer(pView, true);
bool check = disconnect(this, SIGNAL(sigUpdateRect(QRect,QImage)),
pView, SLOT(slotUpdateRect(QRect,QImage)));
Q_ASSERT(check);
check = disconnect(this, SIGNAL(sigUpdateRect(QImage)),
pView, SLOT(slotUpdateRect(QImage)));
Q_ASSERT(check);
return nRet;
}
5 changes: 4 additions & 1 deletion Plugins/FreeRDP/Client/ConnectFreeRDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class CConnectFreeRDP : public CConnectDesktop
private:
UINT32 GetImageFormat();
BOOL CreateImage(rdpContext* context);
BOOL UpdateBuffer(INT32 x, INT32 y, INT32 w, INT32 h);
BOOL UpdateBuffer(QRect rect);
QImage GetImage(QRect r);

int RedirectionSound();
int RedirectionMicrophone();
Expand Down Expand Up @@ -180,6 +181,8 @@ private Q_SLOTS:
friend class CRailManageWindows;
int InitRemoteApp();
int SetRailViewer(CFrmViewer* pView);
Q_SIGNALS:
void sigRailInvalidateRect(QRect rect);
};

#endif // CCONNECTFREERDP_H
118 changes: 91 additions & 27 deletions Plugins/FreeRDP/Client/Rail.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Author: Kang Lin <[email protected]>

// See:
// - Overview of RemoteApp: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc755055(v=ws.11)?redirectedfrom=MSDN
// - RAIL exec error: execResult=RAIL_EXEC_E_NOT_IN_ALLOWLIST NtError=0x15.
// See: https://github.com/FreeRDP/FreeRDP/issues/998
// this is a configuration problem on your server see #595 on how to add a command to the allow list or
// set "fAllowUnlistedRemotePrograms" to 1 in "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" to allow all commands.

#include <QLoggingCategory>
#include "winpr/string.h"
#include "Rail.h"
Expand All @@ -8,6 +15,9 @@
static Q_LOGGING_CATEGORY(log, "FreeRDP.Rail")
static Q_LOGGING_CATEGORY(logWinInfo, "FreeRDP.Rail.Window.Info")

int g_CRailInfo = qRegisterMetaType<CRailInfo>("CRailInfo");
int g_QSharedPointer_CRailInfo = qRegisterMetaType<QSharedPointer<CRailInfo> >("QSharedPointer<CRailInfo>");

CRail::CRail(CConnectFreeRDP* pConnect, QObject *parent)
: QObject{parent}
, m_pConnect(pConnect)
Expand Down Expand Up @@ -74,7 +84,7 @@ QString GetTitle(const WINDOW_STATE_ORDER *windowState)
} else
qCritical(log) << "failed to convert window title";

qDebug(log) << "Window title:" << szTitle;
//qDebug(log) << "Window title:" << szTitle;
return szTitle;
}

Expand Down Expand Up @@ -196,8 +206,8 @@ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE)
{
qDebug(logWinInfo, "\tStyle: 0x%08X ExtendedStyle: 0x%08X", windowState->style,
windowState->extendedStyle);
qDebug(logWinInfo, "\tStyle: 0x%08X ExtendedStyle: 0x%08X",
windowState->style, windowState->extendedStyle);
PrintWindowStyles(windowState->style);
PrintExtendedWindowStyles(windowState->extendedStyle);
}
Expand All @@ -217,14 +227,14 @@ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
{
qDebug(logWinInfo, "\tClientOffsetX: %d ClientOffsetY: %d", windowState->clientOffsetX,
windowState->clientOffsetY);
qDebug(logWinInfo, "\tClientOffsetX: %d ClientOffsetY: %d",
windowState->clientOffsetX, windowState->clientOffsetY);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
{
qDebug(logWinInfo, "\tClientAreaWidth: %u ClientAreaHeight: %u", windowState->clientAreaWidth,
windowState->clientAreaHeight);
qDebug(logWinInfo, "\tClientAreaWidth: %u ClientAreaHeight: %u",
windowState->clientAreaWidth, windowState->clientAreaHeight);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
Expand All @@ -234,13 +244,14 @@ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
{
qDebug(logWinInfo, "\tRootParentHandle: 0x%08X", windowState->rootParentHandle);
qDebug(logWinInfo, "\tRootParentHandle: 0x%08X",
windowState->rootParentHandle);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
{
qDebug(logWinInfo, "\tWindowOffsetX: %d WindowOffsetY: %d", windowState->windowOffsetX,
windowState->windowOffsetY);
qDebug(logWinInfo, "\tWindowOffsetX: %d WindowOffsetY: %d",
windowState->windowOffsetX, windowState->windowOffsetY);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
Expand All @@ -251,8 +262,8 @@ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
{
qDebug(logWinInfo, "\tWindowWidth: %u WindowHeight: %u", windowState->windowWidth,
windowState->windowHeight);
qDebug(logWinInfo, "\tWindowWidth: %u WindowHeight: %u",
windowState->windowWidth, windowState->windowHeight);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
Expand All @@ -270,14 +281,15 @@ static void PrintRailWindowState(const WINDOW_ORDER_INFO* orderInfo,

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
{
qDebug(logWinInfo, "\tvisibileOffsetX: %d visibleOffsetY: %d", windowState->visibleOffsetX,
windowState->visibleOffsetY);
qDebug(logWinInfo, "\tvisibileOffsetX: %d visibleOffsetY: %d",
windowState->visibleOffsetX, windowState->visibleOffsetY);
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY)
{
RECTANGLE_16* rect;
qDebug(logWinInfo, "\tnumVisibilityRects: %u", windowState->numVisibilityRects);
qDebug(logWinInfo, "\tnumVisibilityRects: %u",
windowState->numVisibilityRects);

for (UINT32 index = 0; index < windowState->numVisibilityRects; index++)
{
Expand Down Expand Up @@ -447,7 +459,10 @@ UINT CRail::cbServerLocalMoveSize(
RailClientContext *context,
const RAIL_LOCALMOVESIZE_ORDER *localMoveSize)
{
qDebug(log) << Q_FUNC_INFO;
qDebug(log) << Q_FUNC_INFO << localMoveSize->windowId
<< localMoveSize->isMoveSizeStart
<< localMoveSize->moveSizeType
<< localMoveSize->posX << localMoveSize->posY;
return CHANNEL_RC_OK;
}

Expand Down Expand Up @@ -504,8 +519,12 @@ CRail* CRail::GetRail(rdpContext *context)
}

CRailInfo::CRailInfo()
: m_x(0), m_y(0), m_Width(0), m_Height(0), m_ShowStatus(0)
{}
: m_Style(0)
, m_ExtendedStyle(0)
, m_ShowStatus(0)
{
memset(&m_OrderInfo, 0, sizeof(WINDOW_ORDER_INFO));
}

CRailInfo::CRailInfo(const WINDOW_ORDER_INFO *orderInfo,
const WINDOW_STATE_ORDER *windowState)
Expand All @@ -515,21 +534,66 @@ CRailInfo::CRailInfo(const WINDOW_ORDER_INFO *orderInfo,
memcpy(&m_OrderInfo, orderInfo, sizeof(WINDOW_ORDER_INFO));
if(!windowState)
return;
m_x = windowState->windowOffsetX;
m_y = windowState->windowOffsetY;
m_Width = windowState->windowWidth;
m_Height = windowState->windowHeight;
m_ShowStatus = windowState->showState;
m_OwnerWindowId = windowState->ownerWindowId;
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) {
m_Style = windowState->style;
m_ExtendedStyle = windowState->extendedStyle;
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) {
m_rectWindow.setX(windowState->windowOffsetX);
m_rectWindow.setY(windowState->windowOffsetY);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) {
m_rectWindow.setWidth(windowState->windowWidth);
m_rectWindow.setHeight(windowState->windowHeight);
}
if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
|| (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)) {
qDebug(log) << "CRailInfo: windowOffsetX:" << windowState->windowOffsetX
<< "windowOffsetY:" << windowState->windowOffsetY
<< "width:" << windowState->windowWidth
<< "height:" << windowState->windowHeight
<< "rect:" << m_rectWindow;
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW)
m_ShowStatus = windowState->showState;
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) {
for(int i = 0; i < windowState->numWindowRects; i++)
{
RECTANGLE_16* p = &windowState->windowRects[i];
QRect r;
r.setLeft(p->left);
r.setTop(p->top);
r.setWidth(p->right - p->left);
r.setHeight(p->bottom - p->top);
m_UpdateRects.push_back(r);
}
qDebug(log) << "CRailInfo: refresh rects:" << m_UpdateRects;
}

if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) {
for(int i = 0; i < windowState->numVisibilityRects; i++) {
RECTANGLE_16* p = &windowState->visibilityRects[i];
QRect r;
r.setLeft(p->left);
r.setTop(p->top);
r.setWidth(p->right - p->left);
r.setHeight(p->bottom - p->top);
m_VisibilityRects.push_back(r);
}
}
}

CRailInfo::CRailInfo(const CRailInfo &info)
{
m_OrderInfo = info.m_OrderInfo;
m_x = info.m_x;
m_y = info.m_y;
m_Width = info.m_Width;
m_Height = info.m_Height;
m_OwnerWindowId = info.m_OwnerWindowId;
m_Style = info.m_Style;
m_ExtendedStyle = info.m_ExtendedStyle;
m_rectWindow = info.m_rectWindow;
m_ShowStatus = info.m_ShowStatus;
m_UpdateRects = info.m_UpdateRects;
m_VisibilityRects = info.m_VisibilityRects;
}

BOOL CRail::cbWindowCreate(rdpContext *context,
Expand Down
Loading

0 comments on commit aa857c1

Please sign in to comment.