Skip to content
Draft
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
5 changes: 2 additions & 3 deletions src/lib/cooperation/core/gui/phone/screenmirroringwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ void ScreenMirroringWindow::handleSizeChange(const QSize &size)
initShow = true;
}

// only the size is biger current size can be resized.
if (w > this->width() || h > this->height()) {
if (w != this->width() || h != this->height()) {
DLOG << "Resizing window to:" << w << "x" << h;
m_expectSize = QSize(0, 0); // has been resize, reset.
m_expectSize = QSize(0, 0);
this->resize(w, h);
} else {
m_expectSize = size; // record expected size which is not resized
Expand Down
40 changes: 24 additions & 16 deletions src/lib/cooperation/core/gui/phone/vncviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ void VncViewer::frameTimerTimeout()
#ifdef QT_DEBUG
DLOG << " FPS: " << currentFps();
#endif

if (!m_connected || !m_rfbCli)
return;

QMutexLocker locker(&m_mutex);

int curentMode = (m_rfbCli->width < m_rfbCli->height) ? PORTRAIT : LANDSCAPE;
if (curentMode != m_phoneMode) {
DLOG << "Screen rotation detected by timer - old mode: " << m_phoneMode << " new mode: " << curentMode;
m_phoneMode = curentMode;

if (PORTRAIT == m_phoneMode) {
m_phoneScale = static_cast<qreal>(m_rfbCli->height) / static_cast<qreal>(m_realSize.height());
} else {
m_phoneScale = static_cast<qreal>(m_rfbCli->height) / static_cast<qreal>(m_realSize.width());
}

int w = (m_phoneMode == PORTRAIT) ? m_realSize.width() : m_realSize.height();
const QSize size = {static_cast<int>(w * m_phoneScale), m_rfbCli->height};

m_image = QImage();
setSurfaceSize(size);
emit sizeChanged(size);
}
}

void VncViewer::onSizeChange(int width, int height)
Expand Down Expand Up @@ -208,28 +232,12 @@ void VncViewer::setMobileRealSize(const int w, const int h)

void VncViewer::updateImage(const QImage &image)
{
// 使用互斥锁保护图像更新
QMutexLocker locker(&m_mutex);

// 检查图像有效性
if (image.isNull()) {
return;
}

// 检测屏幕是否旋转 (根据图像宽高比判断)
int currentMode = (image.width() < image.height()) ? PORTRAIT : LANDSCAPE;
if (currentMode != m_phoneMode) {
DLOG << "Screen rotation detected from image - old mode: " << m_phoneMode << " new mode: " << currentMode;
m_phoneMode = currentMode;

// 更新显示尺寸
int w = (m_phoneMode == PORTRAIT) ? m_realSize.width() : m_realSize.height();
const QSize size = {static_cast<int>(w * m_phoneScale), image.height()};

setSurfaceSize(size);
emit sizeChanged(size);
}

m_image = image;

update();
Expand Down
Loading