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 26, 2024
1 parent 9d18e01 commit 6d1f914
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 36 deletions.
37 changes: 27 additions & 10 deletions Plugins/FreeRDP/Client/ConnectFreeRDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,19 +1515,29 @@ BOOL CConnectFreeRDP::cb_begin_paint(rdpContext *context)

BOOL CConnectFreeRDP::UpdateBuffer(INT32 x, INT32 y, INT32 w, INT32 h)
{
if(x > m_Image.width() || y > m_Image.height()) {
QRect rect(x, y, w, h);
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;
}

return m_Image.copy(r);
}

QImage CConnectFreeRDP::GetImage(INT32 x, INT32 y, INT32 w, INT32 h)
{
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 GetImage(rect);
}

BOOL CConnectFreeRDP::cb_end_paint(rdpContext *context)
Expand Down Expand Up @@ -2165,5 +2175,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;
}
2 changes: 2 additions & 0 deletions Plugins/FreeRDP/Client/ConnectFreeRDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class CConnectFreeRDP : public CConnectDesktop
UINT32 GetImageFormat();
BOOL CreateImage(rdpContext* context);
BOOL UpdateBuffer(INT32 x, INT32 y, INT32 w, INT32 h);
QImage GetImage(INT32 x, INT32 y, INT32 w, INT32 h);
QImage GetImage(QRect r);

int RedirectionSound();
int RedirectionMicrophone();
Expand Down
39 changes: 29 additions & 10 deletions Plugins/FreeRDP/Client/Rail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,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,7 +507,9 @@ CRail* CRail::GetRail(rdpContext *context)
}

CRailInfo::CRailInfo()
: m_x(0), m_y(0), m_Width(0), m_Height(0), m_ShowStatus(0)
: m_ShowStatus(0)
, m_Style(0)
, m_ExtendedStyle(0)
{}

CRailInfo::CRailInfo(const WINDOW_ORDER_INFO *orderInfo,
Expand All @@ -515,21 +520,35 @@ 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_rectWindow.setX(windowState->windowOffsetX);
m_rectWindow.setY(windowState->windowOffsetY);
m_rectWindow.setWidth(windowState->windowWidth);
m_rectWindow.setHeight(windowState->windowHeight);
m_ShowStatus = windowState->showState;
m_numWindowRects = windowState->numWindowRects;
for(int i = 0; i < m_numWindowRects; i++)
{
RECTANGLE_16* p = &windowState->windowRects[i];
QRect r;
r.setLeft(p->left);
r.setTop(p->top);
r.setRight(p->right);
r.setBottom(p->bottom);
m_windowRects.push_back(r);
}
m_Style = windowState->style;
m_ExtendedStyle = windowState->extendedStyle;
}

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_rectWindow = info.m_rectWindow;
m_ShowStatus = info.m_ShowStatus;
m_numWindowRects = info.m_numWindowRects;
m_windowRects = info.m_windowRects;
m_Style = info.m_Style;
m_ExtendedStyle = info.m_ExtendedStyle;
}

BOOL CRail::cbWindowCreate(rdpContext *context,
Expand Down
12 changes: 9 additions & 3 deletions Plugins/FreeRDP/Client/Rail.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define RAIL_H

#include <QObject>

#include <QRect>
#include <freerdp/client/rail.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/gdi/dc.h>
Expand All @@ -23,9 +23,15 @@ class CRailInfo{

WINDOW_ORDER_INFO m_OrderInfo;
QString m_szTitle;
qint32 m_x, m_y;
quint32 m_Width, m_Height;
QRect m_rectWindow;

UINT32 m_ShowStatus;

UINT32 m_numWindowRects;
QVector<QRect> m_windowRects;

UINT32 m_Style;
UINT32 m_ExtendedStyle;
};

class CRail : public QObject
Expand Down
67 changes: 59 additions & 8 deletions Plugins/FreeRDP/Client/RailManageWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int CRailManageWindows::ConnecRail(CRail *pRail)

void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
{
qDebug(log) << Q_FUNC_INFO;
qDebug(log) << Q_FUNC_INFO << info->m_OrderInfo.windowId;
UINT32 fieldFlags = info->m_OrderInfo.fieldFlags;
UINT32 windowId = info->m_OrderInfo.windowId;

Expand All @@ -37,25 +37,38 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
pWin = m_Windows.value(windowId);
if (!pWin && (fieldFlags & WINDOW_ORDER_STATE_NEW))
{
pWin = new CRailWindow(info);
pWin = new CRailWindow();
if(!pWin) {
qCritical(log) << "new CRailWindow() fail";
return;
}
m_Windows.insert(windowId, pWin);
pWin->m_Info = *info;
int nRet = 0;
if(m_pConnect) {
nRet = m_pConnect->SetRailViewer(pWin);
if(nRet) {
qCritical(log) << "Connecter SetViewer fail" << nRet;
return;
}
//TODO: 可以不需要,因为远程会删除它。
bool check = connect(pWin, &CRailWindow::destroyed,
this, [&](QObject * obj){
CRailWindow* pW = qobject_cast<CRailWindow*>(obj);
if(pW)
WindowDelete(pW->m_Info.m_OrderInfo.windowId);
});
Q_ASSERT(check);
}
pWin->setGeometry(info->m_x, info->m_y, info->m_Width, info->m_Height);

pWin->setGeometry(pWin->m_Info.m_rectWindow);
pWin->slotSetDesktopSize(info->m_rectWindow.width(),
info->m_rectWindow.height());
if (fieldFlags & WINDOW_ORDER_FIELD_TITLE)
{
pWin->setWindowTitle(info->m_szTitle);
}
UpdateWindow(pWin, info.data());
}

if(!pWin) {
Expand All @@ -80,18 +93,22 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
|| (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE))
{
QRect r = pWin->geometry();
QRect r = pWin->m_Info.m_rectWindow;
if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
{
r.setTopLeft(QPoint(info->m_x, info->m_y));
r.setTopLeft(info->m_rectWindow.topLeft());
}

if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
{
r.setWidth(info->m_Width);
r.setHeight(info->m_Height);
r.setWidth(info->m_rectWindow.width());
r.setHeight(info->m_rectWindow.height());
pWin->slotSetDesktopSize(r.width(), r.height());
}

pWin->setGeometry(r);
pWin->m_Info.m_rectWindow = r;
qDebug(log) << Q_FUNC_INFO << "window size:" << r;
}

if (fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_X)
Expand All @@ -108,6 +125,11 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)

if (fieldFlags & WINDOW_ORDER_FIELD_STYLE)
{
/*if(info->m_Style & WS_POPUP)
pWin->setWindowFlags(pWin->windowFlags() | Qt::Popup);
else
pWin->setWindowFlags(pWin->windowFlags() & ~Qt::Popup);
*/
}

if (fieldFlags & WINDOW_ORDER_FIELD_SHOW)
Expand Down Expand Up @@ -137,7 +159,7 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)

if (fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS)
{

UpdateWindow(pWin, info.data());
}

if (fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
Expand Down Expand Up @@ -181,10 +203,39 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
void CRailManageWindows::slotWindowDelete(QSharedPointer<CRailInfo> info)
{
UINT32 windowId = info->m_OrderInfo.windowId;
WindowDelete(windowId);
}

void CRailManageWindows::WindowDelete(UINT32 windowId)
{
CRailWindow* pWin = m_Windows.value(windowId);
if(pWin) {
pWin->close();
pWin->deleteLater();
}
m_Windows.remove(windowId);
}

int CRailManageWindows::UpdateWindow(CRailWindow *pWin, CRailInfo *info)
{
qDebug(log) << Q_FUNC_INFO << info->m_OrderInfo.windowId;
UINT32 index;
QRect rect;
if (info->m_numWindowRects > 0)
{
rect = info->m_windowRects[0];

for (index = 1; index < info->m_numWindowRects; index++)
{
rect.united(info->m_windowRects[index]);
}

QImage img = m_pConnect->GetImage(rect);
QRect rw = pWin->m_Info.m_rectWindow;

QRect rImg(rect.left() - rw.left(), rect.top() - rw.top(),
rect.width(), rect.height());
pWin->slotUpdateRect(rImg, img);
}
return 0;
}
4 changes: 4 additions & 0 deletions Plugins/FreeRDP/Client/RailManageWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public Q_SLOTS:
void slotWindow(QSharedPointer<CRailInfo> info);
void slotWindowDelete(QSharedPointer<CRailInfo> info);

private:
void WindowDelete(UINT32 windowId);
int UpdateWindow(CRailWindow* pWin, CRailInfo* info);

private:
QMap<UINT32, CRailWindow*> m_Windows;
};
Expand Down
7 changes: 5 additions & 2 deletions Plugins/FreeRDP/Client/RailWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

static Q_LOGGING_CATEGORY(log, "FreeRDP.Rail.Window")

CRailWindow::CRailWindow(QSharedPointer<CRailInfo> info, QWidget *parent)
CRailWindow::CRailWindow(QWidget *parent)
: CFrmViewer{parent}
, m_Info(*info)
{
#ifndef DEBUG
setWindowFlags(Qt::FramelessWindowHint
| Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
#endif
slotSetAdaptWindows(ADAPT_WINDOWS::Original);
}
5 changes: 2 additions & 3 deletions Plugins/FreeRDP/Client/RailWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class CRailWindow : public CFrmViewer
{
Q_OBJECT
public:
explicit CRailWindow(QSharedPointer<CRailInfo> info,
QWidget *parent = nullptr);
private:
explicit CRailWindow(QWidget *parent = nullptr);

CRailInfo m_Info;
};

Expand Down

0 comments on commit 6d1f914

Please sign in to comment.