From f9be3c381567b112dfd73a0735853a1fba75467e Mon Sep 17 00:00:00 2001 From: re2zero Date: Thu, 16 Jan 2025 17:37:32 +0800 Subject: [PATCH 1/2] fix: Fix light style issue It did not set correct rgba for light style, that cause show dark on Qt6 env. Log: Fix light style issue. --- src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp b/src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp index 557d43ad..4c34de38 100644 --- a/src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp +++ b/src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp @@ -14,7 +14,7 @@ #include "common/commonutils.h" #include "gui/utils/cooperationguihelper.h" -#ifdef linux +#ifdef __linux__ # include #endif #ifdef DTKWIDGET_CLASS_DSizeMode @@ -90,7 +90,7 @@ void FirstTipWidget::initUI() void FirstTipWidget::initbackgroundFrame() { backgroundFrame = new QFrame(this); - QString backlightStyle = ".QFrame { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(249, 250, 254), stop:1 rgba(232, 242, 255)); " + QString backlightStyle = ".QFrame { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(249, 250, 254, 0.24), stop:1 rgba(232, 242, 255, 0.12)); " "border-radius: 10px;" "color: rgba(0, 0, 0, 0.6);" "border: 1px solid rgba(0, 0, 0, 0.05); } "; From 77290d8d2a5364a364cc4c196a3d1269e67538f1 Mon Sep 17 00:00:00 2001 From: re2zero Date: Fri, 17 Jan 2025 10:54:26 +0800 Subject: [PATCH 2/2] fix: [vnc]Fix display incorrect image issue 1. Skip the first image which may incomplete. 2. Add screen size changed callback in order to handle target phone rotated. Log: Fix display incorrect image issue. --- .../libvncserver/include/rfb/rfbclient.h | 6 ++++++ .../libvncserver/src/libvncclient/rfbclient.c | 1 + .../cooperation/core/gui/phone/vncrecvthread.cpp | 16 ++++++++++++++++ .../cooperation/core/gui/phone/vncrecvthread.h | 4 ++++ src/lib/cooperation/core/gui/phone/vncviewer.cpp | 16 +++++++++++++--- src/lib/cooperation/core/gui/phone/vncviewer.h | 1 + 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/android/library/droidvnc-ng/libvncserver/include/rfb/rfbclient.h b/android/library/droidvnc-ng/libvncserver/include/rfb/rfbclient.h index a974ff5f..f4aa0fb9 100644 --- a/android/library/droidvnc-ng/libvncserver/include/rfb/rfbclient.h +++ b/android/library/droidvnc-ng/libvncserver/include/rfb/rfbclient.h @@ -239,6 +239,9 @@ typedef char* (*GetUserProc)(struct _rfbClient* client); typedef char* (*GetSASLMechanismProc)(struct _rfbClient* client, char* mechlist); #endif /* LIBVNCSERVER_HAVE_SASL */ +/** Callback when the screen size of the client has changed. */ +typedef void (*ScreenSizeChangedProc)(struct _rfbClient* client, int width, int height); + typedef struct _rfbClient { uint8_t* frameBuffer; int width, height; @@ -453,6 +456,9 @@ typedef struct _rfbClient { #endif /* LIBVNCSERVER_HAVE_SASL */ + /** screen size changed nofication */ + ScreenSizeChangedProc ScreenSizeChanged; + #ifdef LIBVNCSERVER_HAVE_LIBZ #ifdef LIBVNCSERVER_HAVE_LIBJPEG /** JPEG decoder state. */ diff --git a/android/library/droidvnc-ng/libvncserver/src/libvncclient/rfbclient.c b/android/library/droidvnc-ng/libvncserver/src/libvncclient/rfbclient.c index 6f0afac2..45b94354 100644 --- a/android/library/droidvnc-ng/libvncserver/src/libvncclient/rfbclient.c +++ b/android/library/droidvnc-ng/libvncserver/src/libvncclient/rfbclient.c @@ -2136,6 +2136,7 @@ HandleRFBServerMessage(rfbClient* client) return FALSE; } rfbClientLog("Updated desktop size: %dx%d\n", rect.r.w, rect.r.h); + client->ScreenSizeChanged(client, rect.r.w, rect.r.h); } client->requestedResize = FALSE; diff --git a/src/lib/cooperation/core/gui/phone/vncrecvthread.cpp b/src/lib/cooperation/core/gui/phone/vncrecvthread.cpp index 0e2f3e5b..b6e5fee0 100644 --- a/src/lib/cooperation/core/gui/phone/vncrecvthread.cpp +++ b/src/lib/cooperation/core/gui/phone/vncrecvthread.cpp @@ -4,6 +4,7 @@ #include "vncrecvthread.h" +bool VNCRecvThread::_skipFirst = false; VNCRecvThread::VNCRecvThread(QObject *parent): QThread(parent) { @@ -17,6 +18,7 @@ void VNCRecvThread::startRun(rfbClient *cl) _cl = cl; _cl->FinishedFrameBufferUpdate = frameBufferUpdated; + _cl->ScreenSizeChanged = screenSizeChanged; rfbClientSetClientData(_cl, nullptr, this); _runFlag = true; @@ -29,9 +31,11 @@ void VNCRecvThread::stopRun() return; _runFlag = false; + _skipFirst = false; if (_cl) { rfbClientSetClientData(_cl, nullptr, nullptr); _cl->FinishedFrameBufferUpdate = nullptr; + _cl->ScreenSizeChanged = nullptr; } } @@ -52,7 +56,19 @@ void VNCRecvThread::run() void VNCRecvThread::frameBufferUpdated(rfbClient *cl) { + if (!_skipFirst) { + // skip the first image buffer which may be incomplete + _skipFirst = true; + return; + } VNCRecvThread *vncRecvThread = static_cast(rfbClientGetClientData(cl, nullptr)); emit vncRecvThread->updateImageSignal(QImage(cl->frameBuffer, cl->width, cl->height, QImage::Format_RGBA8888)); } + +void VNCRecvThread::screenSizeChanged(rfbClient *cl, int width, int height) +{ + VNCRecvThread *vncRecvThread = static_cast(rfbClientGetClientData(cl, nullptr)); + + emit vncRecvThread->sizeChangedSignal(width, height); +} diff --git a/src/lib/cooperation/core/gui/phone/vncrecvthread.h b/src/lib/cooperation/core/gui/phone/vncrecvthread.h index c7829114..7fdb2df7 100644 --- a/src/lib/cooperation/core/gui/phone/vncrecvthread.h +++ b/src/lib/cooperation/core/gui/phone/vncrecvthread.h @@ -21,9 +21,11 @@ class VNCRecvThread : public QThread void stopRun(); static void frameBufferUpdated(rfbClient *cl); + static void screenSizeChanged(rfbClient *cl, int width, int height); signals: void updateImageSignal(QImage); + void sizeChangedSignal(int width, int height); protected: void run() override; @@ -31,6 +33,8 @@ class VNCRecvThread : public QThread private: bool _runFlag = false; rfbClient *_cl; + + static bool _skipFirst; // skip the first image }; #endif // VNCRECVTHREAD_H diff --git a/src/lib/cooperation/core/gui/phone/vncviewer.cpp b/src/lib/cooperation/core/gui/phone/vncviewer.cpp index b9216e6d..1d848603 100644 --- a/src/lib/cooperation/core/gui/phone/vncviewer.cpp +++ b/src/lib/cooperation/core/gui/phone/vncviewer.cpp @@ -29,6 +29,9 @@ VncViewer::VncViewer(QWidget *parent) m_scaled(true), m_buttonMask(0) { + //init the background color + m_backgroundBrush = QBrush(Qt::black); + setFocusPolicy(Qt::StrongFocus); #ifdef TOUCH_MODE setMouseTracking(false); @@ -44,6 +47,7 @@ VncViewer::VncViewer(QWidget *parent) _vncRecvThread = new VNCRecvThread(this); connect(_vncRecvThread, &VNCRecvThread::updateImageSignal, this, &VncViewer::updateImage, Qt::BlockingQueuedConnection); + connect(_vncRecvThread, &VNCRecvThread::sizeChangedSignal, this, &VncViewer::onSizeChange, Qt::QueuedConnection); connect(_vncRecvThread, &VNCRecvThread::finished, this, &VncViewer::stop); m_frameTimer = new QTimer(this); @@ -72,16 +76,19 @@ void VncViewer::frameTimerTimeout() #ifdef QT_DEBUG qWarning() << " FPS: " << currentFps(); #endif +} +void VncViewer::onSizeChange(int width, int height) +{ if (!m_connected) return; // Check the screen has been rotated - int curentMode = (m_rfbCli->width < m_rfbCli->height) ? PORTRAIT : LANDSCAPE; + int curentMode = (width < height) ? PORTRAIT : LANDSCAPE; if (curentMode != m_phoneMode) { m_phoneMode = curentMode; int w = (m_phoneMode == PORTRAIT) ? m_realSize.width() : m_realSize.height(); - const QSize size = {static_cast(w * m_phoneScale), m_rfbCli->height}; + const QSize size = {static_cast(w * m_phoneScale), height}; setSurfaceSize(size); emit sizeChanged(size); @@ -154,6 +161,9 @@ void VncViewer::updateImage(const QImage &image) void VncViewer::paintEvent(QPaintEvent *event) { if (m_connected) { + if (m_image.isNull()) + return; + m_painter.begin(&m_surfacePixmap); // if (m_image.hasAlphaChannel()) { // // 设置合成模式为源模式 @@ -169,7 +179,7 @@ void VncViewer::paintEvent(QPaintEvent *event) m_painter.begin(this); m_painter.setRenderHints(QPainter::SmoothPixmapTransform); - m_painter.fillRect(rect(), m_backgroundBrush); + m_painter.fillRect(rect(), backgroundBrush()); if (scaled()) { m_surfaceRect.moveCenter(rect().center()); m_painter.scale(m_scale, m_scale); diff --git a/src/lib/cooperation/core/gui/phone/vncviewer.h b/src/lib/cooperation/core/gui/phone/vncviewer.h index 33c71d2c..7a5ebb2e 100644 --- a/src/lib/cooperation/core/gui/phone/vncviewer.h +++ b/src/lib/cooperation/core/gui/phone/vncviewer.h @@ -50,6 +50,7 @@ class VncViewer : public QWidget public slots: void frameTimerTimeout(); + void onSizeChange(int width, int height); void onShortcutAction(int action); void updateSurface();