Skip to content

Commit

Permalink
FreeRDP::Rail: add invalid rect
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Dec 28, 2024
1 parent 52d3b71 commit 5d0a614
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
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
20 changes: 12 additions & 8 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->ConnectRail(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,9 +1513,8 @@ 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)
{
QRect rect(x, y, w, h);
QImage img = GetImage(rect);
emit sigUpdateRect(rect, img);
return TRUE;
Expand Down Expand Up @@ -1593,10 +1592,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 @@ -1622,7 +1626,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
4 changes: 3 additions & 1 deletion Plugins/FreeRDP/Client/ConnectFreeRDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ 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(INT32 x, INT32 y, INT32 w, INT32 h);
QImage GetImage(QRect r);

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

#endif // CCONNECTFREERDP_H
7 changes: 7 additions & 0 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 Down
22 changes: 20 additions & 2 deletions Plugins/FreeRDP/Client/RailManageWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ CRailManageWindows::CRailManageWindows(QObject *parent)
: QObject{parent}
{}

int CRailManageWindows::ConnectRail(CRail *pRail)
int CRailManageWindows::Connect(CRail *pRail)
{
bool check = false;
Q_ASSERT(pRail);
Q_ASSERT(pRail && m_pConnect);
check = connect(
pRail, &CRail::sigWindow,
this, &CRailManageWindows::slotWindow);
Expand All @@ -22,6 +22,9 @@ int CRailManageWindows::ConnectRail(CRail *pRail)
pRail, &CRail::sigWindowDelete,
this, &CRailManageWindows::slotWindowDelete);
Q_ASSERT(check);
check = connect(m_pConnect, &CConnectFreeRDP::sigRailInvalidateRect,
this, &CRailManageWindows::slotInvalidateRect);
Q_ASSERT(check);
return 0;
}

Expand All @@ -47,6 +50,7 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
pWin->m_Info = *info;
int nRet = 0;
if(m_pConnect) {
//qDebug(log) << "m_pConnect->SetRailViewer:" << pWin;
nRet = m_pConnect->SetRailViewer(pWin);
if(nRet) {
qCritical(log) << "Connect SetViewer fail" << nRet;
Expand Down Expand Up @@ -257,3 +261,17 @@ int CRailManageWindows::UpdateWindow(CRailWindow *pWin, CRailInfo *info)

return 0;
}

void CRailManageWindows::slotInvalidateRect(QRect rect)
{
foreach(auto pWin, m_Windows) {
if(!pWin)
continue;
QRect r;
r = pWin->m_Info.m_rectWindow.intersected(rect);
if(r.isValid()) {
QImage img = m_pConnect->GetImage(r);
pWin->slotUpdateRect(r, img);
}
}
}
4 changes: 3 additions & 1 deletion Plugins/FreeRDP/Client/RailManageWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class CRailManageWindows : public QObject
public:
explicit CRailManageWindows(QObject *parent = nullptr);

int ConnectRail(CRail* pRail);
int Connect(CRail* pRail);

CConnectFreeRDP* m_pConnect;
int InvalidateRegion(REGION16* invalidRegion);

public Q_SLOTS:
void slotWindow(QSharedPointer<CRailInfo> info);
void slotWindowDelete(QSharedPointer<CRailInfo> info);
void slotInvalidateRect(QRect rect);

private:
void WindowDelete(UINT32 windowId);
Expand Down
3 changes: 1 addition & 2 deletions Plugins/FreeRDP/Client/RailWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ static Q_LOGGING_CATEGORY(log, "FreeRDP.Rail.Window")
CRailWindow::CRailWindow(QWidget *parent)
: CFrmViewer{parent}
{
#ifndef DEBUG
setWindowFlags(Qt::FramelessWindowHint
| Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
#endif
slotSetAdaptWindows(ADAPT_WINDOWS::Original);
setEnabled(true);
}

0 comments on commit 5d0a614

Please sign in to comment.