From 1459c1eaab8661da0bdbbc3d743a9acdb396135e Mon Sep 17 00:00:00 2001 From: XMuli Date: Fri, 21 Oct 2022 17:59:26 +0800 Subject: [PATCH] fix: mac The following screenshot shows only the desktop and no other windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and other tests on mac machines will crash when running(eg: MacOS 11.2) solutions:https://github.com/flameshot-org/flameshot/issues/2957 One of the paths is written dead --- .DS_Store | Bin 10244 -> 10244 bytes src/CMakeLists.txt | 2 +- src/core/xlog.h | 4 +++- src/main.cpp | 28 +++------------------------- src/screen/screenshot.cpp | 35 +++++++++++------------------------ src/tool/parameterbar.cpp | 4 +--- 6 files changed, 19 insertions(+), 54 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4dac54528547b12be9fcc6f44b87fc2651d2aae2..309eaacfd1671788864ce2d983a852d01b3a604e 100644 GIT binary patch delta 20 bcmZn(XbIS`S%BThz(7aA*kJQ60WWa?NIwQb delta 20 bcmZn(XbIS`S%BTx$UsNI$ZYd20WWa?NPY%N diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4076c65..3404278 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) set(PROJECT_NAME PicShot) -project(${PROJECT_NAME} VERSION 0.4 LANGUAGES CXX) +project(${PROJECT_NAME} VERSION 0.4.5 LANGUAGES CXX) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) file(COPY config/config.ini DESTINATION ${CMAKE_BINARY_DIR}/bin) diff --git a/src/core/xlog.h b/src/core/xlog.h index 251c894..19a63c5 100644 --- a/src/core/xlog.h +++ b/src/core/xlog.h @@ -15,9 +15,11 @@ #define SPDLOG_WCHAR_TO_UTF8_SUPPORT // 需要定义在 spdlog 之前,以支持 wchar_t 的输出 #endif +#include #include #include "spdlog/sinks/rotating_file_sink.h" + class XLog { public: @@ -34,7 +36,7 @@ class XLog private: XLog() { - m_logger = spdlog::rotating_logger_mt("fileLogger", "/Users/winks/Desktop/picshot_debug.log", 1024 * 1024 * 20, 10, true); + m_logger = spdlog::rotating_logger_mt("fileLogger", QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first().toStdString() + "/picshot_debug.log", 1024 * 1024 * 20, 10, true); // 默认类型:[2022-03-19 22:15:15.885] [fileLogger] [info] [screenshot.cpp:941] // https://github.com/gabime/spdlog/wiki/3.-Custom-formatting diff --git a/src/main.cpp b/src/main.cpp index 04fff63..27f7773 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,37 +40,15 @@ // test #ifdef Q_OS_WIN - //#include "./platform/wininfo_win.h" + //#include "./platform/wininfo_win.h"Windows10环境下安装Qt Creator5.9.8作为c++的IDE开发工具,学习和使用qt.md #elif defined(Q_OS_MAC) #elif defined(Q_OS_LINUX) #include "./platform/wininfo_x11.h" #endif - - int main(int argc, char *argv[]) { - // TODO 2022-06-18 高分屏适配的许多尝试: - // 【方案一】 Qt 5.14+, 解决 1.5会缩放到2倍,不过显示会有问题,比如按钮之间时不时会有虚线。 - // qputenv("QT_ENABLE_HIGHDPI_SCALING", "1"); - // QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy); - - // 【方案二】 Qt5.12 替代方案 - // qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1.5"); - -// // 【方案三】 Qt5.12 替代方案 -//#if (QT_VERSION >= QT_VERSION_CHECK(5,9,0)) -// qputenv("QT_SCALE_FACTOR", "1.0"); // 全局缩放因子 https://blog.csdn.net/u014410266/article/details/107488789 -// QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -//#endif - - // 【方案四】 使用 windows 自带的 - // exe 统计目录下使用 qt.conf 文件 - - // 三种方案 https://blog.csdn.net/hanjiang08/article/details/124653265 - // https://blog.csdn.net/qq_18260845/article/details/103861201 - // https://blog.csdn.net/feiyangqingyun/article/details/124860909 - + // 高分屏四种方案 https://blog.csdn.net/qq_33154343/article/details/108905279 #if(QT_VERSION > QT_VERSION_CHECK(5,6,0)) // QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 2K、4K 2@ 倍;获取的分辨率 4K 下实际为 /2 后。 此行需在 QApplication a(argc,argv);前面 @@ -127,7 +105,7 @@ int main(int argc, char *argv[]) qDebug()< #include #include +#include +#include +#include #include namespace Util { @@ -460,39 +463,23 @@ void ScreenShot::onSelColor(QColor col) // 获取虚拟屏幕截图 QPixmap* ScreenShot::getVirScrnPixmap() { - if (!m_currPixmap) { - QDesktopWidget* desktop = qApp->desktop(); // 获取桌面的窗体对象 - const QRect geom = currentScreen(QCursor::pos())->geometry(); + if (!m_currPixmap) { + const QScreen* curScrn = currentScreen(QCursor::pos()); + const QRect geom = curScrn->geometry(); #if defined(Q_OS_MAC) -// QPoint mousePos = QCursor:: pos(); - -// int screenNumber = qApp->desktop()->screenNumber(mousePos); -// QScreen* screen = qApp->screenAt(QCursor::pos()); - - -// qDebug() << "Mouse Pos: " << mousePos.x() << ", " << mousePos.y() << ". Screen " << screenNumber << endl; - -// auto t1 = mapToGlobal(mousePos); -// QPixmap m_currPixmap = screen->grabWindow(qApp->desktop()->winId(), t1.x(), t1.y(), 1000, 1000); - - -// auto savePath = QString( "/Users/winks/Desktop/main_%2.png").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmss")); -// // 保存图片 -// qDebug() << "savePath" << savePath; -// m_currPixmap.save(savePath); - m_currPixmap = new QPixmap(m_priScrn->grabWindow(0/*desktop->winId()*/, geom.x(), geom.y(), geom.width(), geom.height())); + m_currPixmap = new QPixmap(m_priScrn->grabWindow(qApp->desktop()->winId(), geom.x(), geom.y(), geom.width(), geom.height())); #else #ifdef _MYDEBUG - m_currPixmap = new QPixmap(m_priScrn->grabWindow(desktop->winId(), geom.x(), geom.y(), geom.width(), geom.height())); + m_currPixmap = new QPixmap(m_priScrn->grabWindow(qApp->desktop()->winId(), geom.x(), geom.y(), geom.width(), geom.height())); #else // 多屏的矩形取并集 - m_currPixmap = new QPixmap(m_priScrn->grabWindow(desktop->winId(), m_virGeom.x(), m_virGeom.y(), m_virGeom.width(), m_virGeom.height())); + m_currPixmap = new QPixmap(m_priScrn->grabWindow(qApp->desktop()->winId(), m_virGeom.x(), m_virGeom.y(), m_virGeom.width(), m_virGeom.height())); #endif #endif } - m_currPixmap->save("/Users/winks/Desktop/123456.png");//m_currPixmap->save("123456.png"); + m_currPixmap->save(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first() + "/m_currPixmap_123456.png"); return m_currPixmap; } @@ -1550,7 +1537,7 @@ void ScreenShot::getScrnInfo() XLOG_INFO("---------------m_screens[] Info BEGIN----------------"); for (const auto& it : m_scrns) { - qDebug() << "序号 it:" << m_scrns.indexOf(it) + qDebug() << "序号 it:" << m_scrns.indexOf(it) << " it:" << it << "\n可用几何 availableGeometry:" << it->availableGeometry() << "\n可用虚拟几何 availableVirtualSize:" << it->availableVirtualSize() << "\n虚拟几何 virtualGeometry:" << it->virtualGeometry() diff --git a/src/tool/parameterbar.cpp b/src/tool/parameterbar.cpp index 27ad516..6eaf8a8 100644 --- a/src/tool/parameterbar.cpp +++ b/src/tool/parameterbar.cpp @@ -114,9 +114,7 @@ void ParameterBar::creatorParaBar(QPointer& manageBar, QString& path, tb->setIcon(XHelper::instance().ChangeSVGColor(it.value(), "rect", XHelper::instance().borderColor(), QSize(ICON_WIDTH, ICON_WIDTH) * XHelper::instance().getScale())); } - if (!tb->setProperty("path", it.value())) - XLOG_INFO("ToolButton Property [path] initialization faile."); - + tb->setProperty("path", it.value()); group->addButton(tb); manageBar->addWidget(tb); it++;