Introduced a ScrcpyWindow to enable integration of the scrcpy tool for device screen mirroring within the application. Platform-specific embedding is supported for macOS and Windows, with structure adjustments made in MainWindow and the build system (CMakeLists.txt).
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include "ScrcpyWindow.h"
|
|
#include <QDebug>
|
|
#include <QTimer>
|
|
|
|
#ifdef Q_OS_WIN
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
ScrcpyWindow::ScrcpyWindow(QWidget *parent) : QWidget(parent), m_process(nullptr) {
|
|
setWindowFlag(Qt::WindowStaysOnTopHint);
|
|
startScrcpy();
|
|
}
|
|
|
|
ScrcpyWindow::~ScrcpyWindow() {
|
|
stopScrcpy();
|
|
}
|
|
|
|
void ScrcpyWindow::startScrcpy() {
|
|
m_process = new QProcess(this);
|
|
m_process->start("scrcpy", {"--window-title", "scrcpy", "--always-on-top"});
|
|
|
|
// Подождём немного, чтобы окно scrcpy запустилось
|
|
QTimer::singleShot(5000, this, &ScrcpyWindow::embedPlatformSpecific);
|
|
}
|
|
|
|
void ScrcpyWindow::stopScrcpy() {
|
|
if (m_process) {
|
|
m_process->terminate();
|
|
m_process->waitForFinished();
|
|
delete m_process;
|
|
m_process = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
void ScrcpyWindow::embedPlatformSpecific() {
|
|
#ifdef Q_OS_WIN
|
|
|
|
HWND hwndScrcpy = FindWindowW(nullptr, L"scrcpy");
|
|
if (!hwndScrcpy) {
|
|
qDebug() << "scrcpy window not found";
|
|
return;
|
|
}
|
|
|
|
HWND hwndTarget = (HWND)this->winId();
|
|
SetParent(hwndScrcpy, hwndTarget);
|
|
|
|
LONG style = GetWindowLong(hwndScrcpy, GWL_STYLE);
|
|
style &= ~(WS_CAPTION | WS_THICKFRAME | WS_BORDER);
|
|
SetWindowLong(hwndScrcpy, GWL_STYLE, style);
|
|
|
|
RECT rect;
|
|
GetClientRect(hwndTarget, &rect);
|
|
SetWindowPos(hwndScrcpy, HWND_TOP, 0, 0,
|
|
rect.right - rect.left, rect.bottom - rect.top,
|
|
SWP_SHOWWINDOW);
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
extern void embedScrcpyMac(QWidget *container);
|
|
embedScrcpyMac(this);
|
|
|
|
#else
|
|
|
|
qDebug() << "Scrcpy embedding not implemented for this OS.";
|
|
|
|
#endif
|
|
} |