Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix light style issue and display issue #606

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions src/lib/cooperation/core/gui/phone/vncrecvthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "vncrecvthread.h"

bool VNCRecvThread::_skipFirst = false;

VNCRecvThread::VNCRecvThread(QObject *parent): QThread(parent)
{
Expand All @@ -17,6 +18,7 @@ void VNCRecvThread::startRun(rfbClient *cl)

_cl = cl;
_cl->FinishedFrameBufferUpdate = frameBufferUpdated;
_cl->ScreenSizeChanged = screenSizeChanged;
rfbClientSetClientData(_cl, nullptr, this);
_runFlag = true;

Expand All @@ -29,9 +31,11 @@ void VNCRecvThread::stopRun()
return;

_runFlag = false;
_skipFirst = false;
if (_cl) {
rfbClientSetClientData(_cl, nullptr, nullptr);
_cl->FinishedFrameBufferUpdate = nullptr;
_cl->ScreenSizeChanged = nullptr;
}
}

Expand All @@ -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<VNCRecvThread *>(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<VNCRecvThread *>(rfbClientGetClientData(cl, nullptr));

emit vncRecvThread->sizeChangedSignal(width, height);
}
4 changes: 4 additions & 0 deletions src/lib/cooperation/core/gui/phone/vncrecvthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ 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;

private:
bool _runFlag = false;
rfbClient *_cl;

static bool _skipFirst; // skip the first image
};

#endif // VNCRECVTHREAD_H
16 changes: 13 additions & 3 deletions src/lib/cooperation/core/gui/phone/vncviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<int>(w * m_phoneScale), m_rfbCli->height};
const QSize size = {static_cast<int>(w * m_phoneScale), height};

setSurfaceSize(size);
emit sizeChanged(size);
Expand Down Expand Up @@ -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()) {
// // 设置合成模式为源模式
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lib/cooperation/core/gui/phone/vncviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VncViewer : public QWidget

public slots:
void frameTimerTimeout();
void onSizeChange(int width, int height);
void onShortcutAction(int action);

void updateSurface();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/cooperation/core/gui/widgets/firsttipwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "common/commonutils.h"
#include "gui/utils/cooperationguihelper.h"

#ifdef linux
#ifdef __linux__
# include <DPalette>
#endif
#ifdef DTKWIDGET_CLASS_DSizeMode
Expand Down Expand Up @@ -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); } ";
Expand Down
Loading