Skip to content

Commit

Permalink
FreeRDP::Rail: fix QWidge::move invalid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Dec 30, 2024
1 parent fef38fe commit 2c48e51
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ jobs:
cmake --install . --config Release --component Plugin --prefix AppDir/usr
# See: https://github.com/linuxdeploy/linuxdeploy-plugin-qt
export QMAKE=$Qt6_DIR/bin/qmake
export EXTRA_PLATFORM_PLUGINS="libqwayland-generic.so;libqxcb.so;libqwayland-egl.so"
export EXTRA_PLATFORM_PLUGINS="libqxcb.so"
${{env.TOOSL_DIR}}/linuxdeploy-`uname -m`.AppImage --appdir=AppDir -v0 \
--deploy-deps-only=AppDir/usr/plugins/Client \
--deploy-deps-only=AppDir/usr/lib/`uname -m`-linux-gnu \
Expand Down
8 changes: 8 additions & 0 deletions App/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ static Q_LOGGING_CATEGORY(log, "App.Main")
int main(int argc, char *argv[])
{
int nRet = 0;
#if (defined(Q_OS_LINUX) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
/* 现在很多 linux 用 wayland 作为桌面显示,这样会出现一个问题,
由于没有坐标系统,导致无边框窗体无法拖动和定位(即 QWidge::move 失效)。
(一般是 Qt6 开始强制默认优先用 wayland ,之前 Qt5 是默认有 xcb 则优先用 xcb),
你需要在 main 函数最前面加一行 qputenv("QT_QPA_PLATFORM", "xcb");
*/
qputenv("QT_QPA_PLATFORM", "xcb");
#endif
#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Expand Down
7 changes: 4 additions & 3 deletions Plugins/FreeRDP/Client/Rail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ CRailInfo::CRailInfo(const WINDOW_ORDER_INFO *orderInfo,
m_Style = windowState->style;
m_ExtendedStyle = windowState->extendedStyle;
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) {
m_szTitle = GetString(windowState->titleInfo);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) {
m_rectWindow.setX(windowState->windowOffsetX);
m_rectWindow.setY(windowState->windowOffsetY);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) {
m_szTitle = GetString(windowState->titleInfo);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) {
m_rectWindow.setWidth(windowState->windowWidth);
m_rectWindow.setHeight(windowState->windowHeight);
Expand Down Expand Up @@ -358,6 +358,7 @@ CRailInfo::CRailInfo(const CRailInfo &info)
m_OwnerWindowId = info.m_OwnerWindowId;
m_Style = info.m_Style;
m_ExtendedStyle = info.m_ExtendedStyle;
m_szTitle = info.m_szTitle;
m_rectWindow = info.m_rectWindow;
m_ShowStatus = info.m_ShowStatus;
m_UpdateRects = info.m_UpdateRects;
Expand Down
57 changes: 29 additions & 28 deletions Plugins/FreeRDP/Client/RailManageWindows.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
// Author: Kang Lin <[email protected]>

#include <QLoggingCategory>

#include "RailManageWindows.h"
#include "ConnectFreeRDP.h"

#include <QLoggingCategory>
#ifdef Q_OS_LINUX
#include <X11/Xlib.h>

Check failure on line 8 in Plugins/FreeRDP/Client/RailManageWindows.cpp

View workflow job for this annotation

GitHub Actions / android / build_android (Release, android_arm64_v8a, 6.8.1)

'X11/Xlib.h' file not found

Check failure on line 8 in Plugins/FreeRDP/Client/RailManageWindows.cpp

View workflow job for this annotation

GitHub Actions / android / build_android (Release, android_x86_64, 6.8.1)

'X11/Xlib.h' file not found
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QGuiApplication>
#endif
#endif

#define HEX(x) QString("0x%1").arg((x), 8, 16, QLatin1Char('0'))
#define WINDOW_ID(x) QString("WindowId: 0x%1").arg((x), 8, 16, QLatin1Char('0'))

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

CRailManageWindows::CRailManageWindows(QObject *parent)
: QObject{parent}
Expand Down Expand Up @@ -101,44 +109,37 @@ void CRailManageWindows::slotWindow(QSharedPointer<CRailInfo> info)
return;
}

/* Keep track of any position/size update so that we can force a refresh of the window */
if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) ||
(fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) ||
(fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) ||
(fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) ||
(fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) ||
(fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) ||
(fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY))
{

}

/* Update Parameters */

if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
|| (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE))
{
QRect r = pWin->m_Info.m_rectWindow;
if ((fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
&& (info->m_rectWindow.topLeft()
!= pWin->m_Info.m_rectWindow.topLeft())) {
if (fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) {
qDebug(logWin) << WINDOW_ID(info->m_OrderInfo.windowId)
<< "window offset:" << info->m_rectWindow << "old:" << r;
r.setTopLeft(info->m_rectWindow.topLeft());
pWin->move(r.x(), r.y());
}

if ((fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
&& ((info->m_rectWindow.width() != r.width())
|| (info->m_rectWindow.height() != r.height()))) {
qDebug(logWin) << WINDOW_ID(info->m_OrderInfo.windowId)
<< "window size:" << info->m_rectWindow << "old:" << r;
<< "window size:" << info->m_rectWindow
<< "old:" << r
<< "maximumSize:" << pWin->maximumSize()
<< "minimumSize:" << pWin->minimumSize();
r.setWidth(info->m_rectWindow.width());
r.setHeight(info->m_rectWindow.height());
pWin->resize(r.width(), r.height());
pWin->slotSetDesktopSize(r.width(), r.height());
}

if (fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) {
qDebug(logWin) << WINDOW_ID(info->m_OrderInfo.windowId)
<< "window offset:" << info->m_rectWindow << "old:" << r;
r.setTopLeft(info->m_rectWindow.topLeft());

/* 现在很多 linux 用 wayland 作为桌面显示,这样会出现一个问题,
由于没有坐标系统,导致无边框窗体无法拖动和定位(即 QWidge::move 失效)。
(一般是 Qt6 开始强制默认优先用 wayland ,之前 Qt5 是默认有 xcb 则优先用 xcb),
你需要在 main 函数最前面加一行 qputenv("QT_QPA_PLATFORM", "xcb");
*/
pWin->move(r.x(), r.y());
}

pWin->m_Info.m_rectWindow = r;

}
Expand Down
8 changes: 5 additions & 3 deletions Plugins/FreeRDP/Client/RailWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ static Q_LOGGING_CATEGORY(log, "FreeRDP.Rail.Window")
CRailWindow::CRailWindow(QWidget *parent)
: CFrmViewer{parent}
{
qDebug(log) << "CRailWindow origin flags:" << windowFlags();
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
qDebug(log) << "CRailWindow initial flags:" << windowFlags();
//qDebug(log) << "CRailWindow origin flags:" << windowFlags();
setWindowFlags(Qt::FramelessWindowHint);
//qDebug(log) << "CRailWindow initial flags:" << windowFlags();
slotSetAdaptWindows(ADAPT_WINDOWS::Original);
setEnabled(true);
qDebug(log) << "minimumSize:" << minimumSize()
<< "maximumSize:" << maximumSize();
}

void CRailWindow::mousePressEvent(QMouseEvent *event)
Expand Down

0 comments on commit 2c48e51

Please sign in to comment.