mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-09-28 04:09:04 +00:00
Standardize macOS detection and prompt on close
Unify platform checks to use Q_OS_MACOS for Qt6 compatibility and switch the QtScrcpyCore submodule URL to HTTPS for easier cloning. Introduce a confirmation dialog on window close that lets users choose between minimizing to tray or exiting the app. Improve project hygiene by extending .gitignore rules for IDE and cache files, adding missing QDebug includes, and applying minor formatting tweaks for consistency. Standardize macOS detection and add close prompt Unify all platform checks to Q_OS_MACOS for Qt6 compatibility. Switch submodule URL to HTTPS for easier cloning. Introduce a close confirmation dialog letting users minimize to tray or exit. Improve project hygiene: extend .gitignore for IDE/cache files, add missing QDebug includes, and apply formatting tweaks.
This commit is contained in:
parent
02ffb264c9
commit
efa41142b4
7 changed files with 79 additions and 45 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -14,4 +14,8 @@ build-*
|
|||
*.DS_Store
|
||||
userdata.ini
|
||||
Info_Mac.plist
|
||||
/ci/build_temp
|
||||
/ci/build_temp
|
||||
.vscode/
|
||||
.gitignore
|
||||
.gitmodules
|
||||
.cache/
|
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "QtScrcpy/QtScrcpyCore"]
|
||||
path = QtScrcpy/QtScrcpyCore
|
||||
url = git@github.com:barry-ran/QtScrcpyCore.git
|
||||
url = https://github.com/barry-ran/QtScrcpyCore.git
|
||||
|
|
|
@ -28,7 +28,7 @@ int main(int argc, char *argv[])
|
|||
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
qputenv("QTSCRCPY_ADB_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/mac/adb");
|
||||
qputenv("QTSCRCPY_SERVER_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
|
||||
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../../../keymap");
|
||||
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
|||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -92,7 +92,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
installTranslator();
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_OSX)
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
|
||||
MouseTap::getInstance()->initMouseEventTap();
|
||||
#endif
|
||||
|
||||
|
@ -108,11 +108,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
qsc::AdbProcess::setAdbPath(Config::getInstance().getAdbPath());
|
||||
|
||||
g_mainDlg = new Dialog {};
|
||||
g_mainDlg = new Dialog{};
|
||||
g_mainDlg->show();
|
||||
|
||||
qInfo() << QObject::tr("This software is completely open source and free. Use it at your own risk. You can download it at the "
|
||||
"following address:");
|
||||
"following address:");
|
||||
qInfo() << QString("QtScrcpy %1 <https://github.com/barry-ran/QtScrcpy>").arg(QCoreApplication::applicationVersion());
|
||||
|
||||
qInfo() << QObject::tr("If you need more professional batch control mirror software, you can try the following software:");
|
||||
|
@ -126,7 +126,7 @@ int main(int argc, char *argv[])
|
|||
int ret = a.exec();
|
||||
delete g_mainDlg;
|
||||
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_OSX)
|
||||
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
|
||||
MouseTap::getInstance()->quitMouseEventTap();
|
||||
#endif
|
||||
return ret;
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <QRandomGenerator>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
#include <QDialog>
|
||||
#include <QVBoxLayout>
|
||||
#include <QRadioButton>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include "config.h"
|
||||
#include "dialog.h"
|
||||
|
@ -291,13 +295,32 @@ void Dialog::slotActivated(QSystemTrayIcon::ActivationReason reason)
|
|||
|
||||
void Dialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
this->hide();
|
||||
if (!Config::getInstance().getTrayMessageShown()) {
|
||||
Config::getInstance().setTrayMessageShown(true);
|
||||
m_hideIcon->showMessage(tr("Notice"),
|
||||
tr("Hidden here!"),
|
||||
QSystemTrayIcon::Information,
|
||||
3000);
|
||||
// 弹出选择对话框
|
||||
QDialog choiceDialog(this);
|
||||
choiceDialog.setWindowTitle(tr("关闭选项"));
|
||||
QVBoxLayout *layout = new QVBoxLayout(&choiceDialog);
|
||||
QRadioButton *minimizeRadio = new QRadioButton(tr("最小化窗口"), &choiceDialog);
|
||||
QRadioButton *exitRadio = new QRadioButton(tr("退出窗口"), &choiceDialog);
|
||||
minimizeRadio->setChecked(true);
|
||||
layout->addWidget(minimizeRadio);
|
||||
layout->addWidget(exitRadio);
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &choiceDialog);
|
||||
layout->addWidget(buttonBox);
|
||||
// 设置按钮为“确认”和“取消”
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("确认"));
|
||||
buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("取消"));
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, &choiceDialog, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, &choiceDialog, &QDialog::reject);
|
||||
if (choiceDialog.exec() == QDialog::Accepted) {
|
||||
if (minimizeRadio->isChecked()) {
|
||||
this->hide();
|
||||
if (!Config::getInstance().getTrayMessageShown()) {
|
||||
Config::getInstance().setTrayMessageShown(true);
|
||||
m_hideIcon->showMessage(tr("Notice"), tr("Hidden here!"), QSystemTrayIcon::Information, 3000);
|
||||
}
|
||||
} else {
|
||||
qApp->quit();
|
||||
}
|
||||
}
|
||||
event->ignore();
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "iconhelper.h"
|
||||
#include "mousetap/mousetap.h"
|
||||
#include "qyuvopenglwidget.h"
|
||||
#include "toolform.h"
|
||||
#include "mousetap/mousetap.h"
|
||||
#include "ui_videoform.h"
|
||||
#include "videoform.h"
|
||||
|
||||
|
@ -54,7 +54,7 @@ void VideoForm::initUI()
|
|||
m_widthHeightRatio = 1.0f * phone.width() / phone.height();
|
||||
}
|
||||
|
||||
#ifndef Q_OS_OSX
|
||||
#ifndef Q_OS_MACOS
|
||||
// mac下去掉标题栏影响showfullscreen
|
||||
// 去掉标题栏
|
||||
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
|
@ -96,7 +96,7 @@ QRect VideoForm::getGrabCursorRect()
|
|||
rc.setY(rc.y() + 10);
|
||||
rc.setWidth(rc.width() - 20);
|
||||
rc.setHeight(rc.height() - 20);
|
||||
#elif defined(Q_OS_OSX)
|
||||
#elif defined(Q_OS_MACOS)
|
||||
rc = m_videoWidget->geometry();
|
||||
rc.setTopLeft(ui->keepRatioWidget->mapToGlobal(rc.topLeft()));
|
||||
rc.setBottomRight(ui->keepRatioWidget->mapToGlobal(rc.bottomRight()));
|
||||
|
@ -147,7 +147,7 @@ void VideoForm::showFPS(bool show)
|
|||
m_fpsLabel->setVisible(show);
|
||||
}
|
||||
|
||||
void VideoForm::updateRender(int width, int height, uint8_t* dataY, uint8_t* dataU, uint8_t* dataV, int linesizeY, int linesizeU, int linesizeV)
|
||||
void VideoForm::updateRender(int width, int height, uint8_t *dataY, uint8_t *dataU, uint8_t *dataV, int linesizeY, int linesizeU, int linesizeV)
|
||||
{
|
||||
if (m_videoWidget->isHidden()) {
|
||||
if (m_loadingWidget) {
|
||||
|
@ -474,7 +474,7 @@ void VideoForm::switchFullScreen()
|
|||
// fullscreen window will move (0,0). qt bug?
|
||||
move(m_fullScreenBeforePos);
|
||||
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
//setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
||||
//show();
|
||||
#endif
|
||||
|
@ -497,7 +497,7 @@ void VideoForm::switchFullScreen()
|
|||
m_fullScreenBeforePos = pos();
|
||||
// 这种临时增加标题栏再全屏的方案会导致收不到mousemove事件,导致setmousetrack失效
|
||||
// mac fullscreen must show title bar
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
//setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
|
||||
#endif
|
||||
showToolForm(false);
|
||||
|
@ -574,11 +574,11 @@ void VideoForm::mousePressEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QPointF localPos = event->localPos();
|
||||
QPointF globalPos = event->globalPos();
|
||||
QPointF localPos = event->localPos();
|
||||
QPointF globalPos = event->globalPos();
|
||||
#else
|
||||
QPointF localPos = event->position();
|
||||
QPointF globalPos = event->globalPosition();
|
||||
QPointF localPos = event->position();
|
||||
QPointF globalPos = event->globalPosition();
|
||||
#endif
|
||||
|
||||
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||
|
@ -642,11 +642,11 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
|
|||
void VideoForm::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QPointF localPos = event->localPos();
|
||||
QPointF globalPos = event->globalPos();
|
||||
QPointF localPos = event->localPos();
|
||||
QPointF globalPos = event->globalPos();
|
||||
#else
|
||||
QPointF localPos = event->position();
|
||||
QPointF globalPos = event->globalPosition();
|
||||
QPointF localPos = event->position();
|
||||
QPointF globalPos = event->globalPosition();
|
||||
#endif
|
||||
auto device = qsc::IDeviceManage::getInstance().getDevice(m_serial);
|
||||
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||
|
@ -713,8 +713,17 @@ void VideoForm::wheelEvent(QWheelEvent *event)
|
|||
QPointF pos = m_videoWidget->mapFrom(this, event->pos());
|
||||
|
||||
QWheelEvent wheelEvent(
|
||||
pos, event->globalPosF(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(),
|
||||
event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
|
||||
pos,
|
||||
event->globalPosF(),
|
||||
event->pixelDelta(),
|
||||
event->angleDelta(),
|
||||
event->delta(),
|
||||
event->orientation(),
|
||||
event->buttons(),
|
||||
event->modifiers(),
|
||||
event->phase(),
|
||||
event->source(),
|
||||
event->inverted());
|
||||
#endif
|
||||
emit device->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||
}
|
||||
|
@ -759,9 +768,7 @@ void VideoForm::showEvent(QShowEvent *event)
|
|||
{
|
||||
Q_UNUSED(event)
|
||||
if (!isFullScreen() && this->show_toolbar) {
|
||||
QTimer::singleShot(500, this, [this](){
|
||||
showToolForm(this->show_toolbar);
|
||||
});
|
||||
QTimer::singleShot(500, this, [this]() { showToolForm(this->show_toolbar); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
|
||||
#include "config.h"
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
#include "path.h"
|
||||
#endif
|
||||
|
||||
|
@ -127,7 +127,7 @@ Config::Config(QObject *parent) : QObject(parent)
|
|||
m_userData->setIniCodec("UTF-8");
|
||||
#endif
|
||||
|
||||
qDebug()<<m_userData->childGroups();
|
||||
qDebug() << m_userData->childGroups();
|
||||
}
|
||||
|
||||
Config &Config::getInstance()
|
||||
|
@ -145,7 +145,7 @@ const QString &Config::getConfigPath()
|
|||
// default application dir
|
||||
// mac系统当从finder打开app时,默认工作目录不再是可执行程序的目录了,而是"/"
|
||||
// 而Qt的获取工作目录的api都依赖QCoreApplication的初始化,所以使用mac api获取当前目录
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
// get */QtScrcpy.app path
|
||||
s_configPath = Path::GetCurrentPath();
|
||||
s_configPath += "/Contents/MacOS/config";
|
||||
|
@ -199,7 +199,7 @@ UserBootConfig Config::getUserBootConfig()
|
|||
config.keepAlive = m_userData->value(COMMON_KEEP_ALIVE_KEY, COMMON_KEEP_ALIVE_DEF).toBool();
|
||||
config.simpleMode = m_userData->value(COMMON_SIMPLE_MODE_KEY, COMMON_SIMPLE_MODE_DEF).toBool();
|
||||
config.autoUpdateDevice = m_userData->value(COMMON_AUTO_UPDATE_DEVICE_KEY, COMMON_AUTO_UPDATE_DEVICE_DEF).toBool();
|
||||
config.showToolbar =m_userData->value(COMMON_SHOW_TOOLBAR_KEY,COMMON_SHOW_TOOLBAR_DEF).toBool();
|
||||
config.showToolbar = m_userData->value(COMMON_SHOW_TOOLBAR_KEY, COMMON_SHOW_TOOLBAR_DEF).toBool();
|
||||
m_userData->endGroup();
|
||||
return config;
|
||||
}
|
||||
|
@ -393,18 +393,18 @@ QString Config::getTitle()
|
|||
void Config::saveIpHistory(const QString &ip)
|
||||
{
|
||||
QStringList ipList = getIpHistory();
|
||||
|
||||
|
||||
// 移除已存在的相同IP(避免重复)
|
||||
ipList.removeAll(ip);
|
||||
|
||||
|
||||
// 将新IP添加到开头
|
||||
ipList.prepend(ip);
|
||||
|
||||
|
||||
// 限制历史记录数量
|
||||
while (ipList.size() > IP_HISTORY_MAX) {
|
||||
ipList.removeLast();
|
||||
}
|
||||
|
||||
|
||||
m_userData->setValue(IP_HISTORY_KEY, ipList);
|
||||
m_userData->sync();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#ifdef Q_OS_WIN32
|
||||
#include "winmousetap.h"
|
||||
#endif
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
#include "cocoamousetap.h"
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -18,7 +18,7 @@ MouseTap *MouseTap::getInstance()
|
|||
#ifdef Q_OS_WIN32
|
||||
s_instance = new WinMouseTap();
|
||||
#endif
|
||||
#ifdef Q_OS_OSX
|
||||
#ifdef Q_OS_MACOS
|
||||
s_instance = new CocoaMouseTap();
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue