#include "ScrcpyWindow.h" #include #include #ifdef Q_OS_WIN #include #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 }