Commit 48fadc2a authored by captainwong's avatar captainwong

update and fix

parent 8a337d1c
...@@ -75,7 +75,7 @@ file_name) ...@@ -75,7 +75,7 @@ file_name)
file_name , 23, 59)); file_name , 23, 59));
auto combined_logger = std::make_shared<spdlog::logger>(g_logger_name, begin(sinks), end(sinks)); auto combined_logger = std::make_shared<spdlog::logger>(g_logger_name, begin(sinks), end(sinks));
combined_logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%L] %v"); combined_logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%t] [%L] %v");
spdlog::register_logger(combined_logger); spdlog::register_logger(combined_logger);
combined_logger->flush_on(spdlog::level::trace); combined_logger->flush_on(spdlog::level::trace);
} catch (const spdlog::spdlog_ex& ex) { } catch (const spdlog::spdlog_ex& ex) {
......
...@@ -13,21 +13,43 @@ ...@@ -13,21 +13,43 @@
#include <QProcess> #include <QProcess>
#include "QtDebug.h" #include "QtDebug.h"
#include "QtPathHelper.h" #include "QtPathHelper.h"
#include <thread>
#include <chrono>
JLIBQT_NAMESPACE_BEGIN JLIBQT_NAMESPACE_BEGIN
/**
* @brief 阻塞等待一段时间
* @param ms 等待的毫秒数
*/
static inline void blocking_wait(int ms, QString log = "") {
if (!log.isEmpty()) {
MYQDEBUG << log << "in";
}
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
if (!log.isEmpty()) {
MYQDEBUG << log << "out";
}
}
/** /**
* @brief 不阻塞UI响应的情况下,等待一段时间 * @brief 不阻塞UI响应的情况下,等待一段时间
* @param ms 等待的毫秒数 * @param ms 等待的毫秒数
*/ */
static inline void non_blocking_wait_in_ui_thread(int ms) { static inline void non_blocking_wait_in_ui_thread(int ms, QString log = "") {
if (!log.isEmpty()) {
MYQDEBUG << log << "in";
}
QEventLoop q; QEventLoop q;
QTimer t; QTimer t;
t.setSingleShot(true); t.setSingleShot(true);
QObject::connect(&t, &QTimer::timeout, &q, &QEventLoop::quit); QObject::connect(&t, &QTimer::timeout, &q, &QEventLoop::quit);
t.start(ms); t.start(ms);
q.exec(); q.exec();
if (!log.isEmpty()) {
MYQDEBUG << log << "out";
}
} }
/** /**
...@@ -43,13 +65,13 @@ static inline void showInGraphicalShell(const QString &pathIn) { ...@@ -43,13 +65,13 @@ static inline void showInGraphicalShell(const QString &pathIn) {
QProcess::startDetached(command); QProcess::startDetached(command);
} }
static inline bool warn_if_load_pixmap_failed(QPixmap& pixmap, QString icon_path, QString file_line) static inline bool warn_if_load_pixmap_failed(QPixmap& pixmap, QString icon_path, QString file_line, bool forceUseQss = true)
{ {
/*if (!QDir().isAbsolutePath(icon_path)) { /*if (!QDir().isAbsolutePath(icon_path)) {
icon_path = PathHelper::program() + "/" + icon_path; icon_path = PathHelper::program() + "/" + icon_path;
}*/ }*/
if (!icon_path.startsWith(":/")) { if (forceUseQss && !icon_path.startsWith(":/")) {
icon_path = ":/" + icon_path; icon_path = ":/" + icon_path;
} }
...@@ -62,6 +84,7 @@ static inline bool warn_if_load_pixmap_failed(QPixmap& pixmap, QString icon_path ...@@ -62,6 +84,7 @@ static inline bool warn_if_load_pixmap_failed(QPixmap& pixmap, QString icon_path
} }
#define LOAD_PIXMAP_EX(icon_path) JLIBQT_NAMESPACE warn_if_load_pixmap_failed(pixmap, icon_path, JLIBQT_QDEBUG_FILE_LINE_VALUE) #define LOAD_PIXMAP_EX(icon_path) JLIBQT_NAMESPACE warn_if_load_pixmap_failed(pixmap, icon_path, JLIBQT_QDEBUG_FILE_LINE_VALUE)
#define LOAD_PIXMAP_EX2(icon_path) JLIBQT_NAMESPACE warn_if_load_pixmap_failed(pixmap, icon_path, JLIBQT_QDEBUG_FILE_LINE_VALUE, false)
static QIcon icon_from_path(QString path, QSize icon_sz) { static QIcon icon_from_path(QString path, QSize icon_sz) {
QPixmap pixmap; QPixmap pixmap;
......
...@@ -243,12 +243,12 @@ static void test_monitor() ...@@ -243,12 +243,12 @@ static void test_monitor()
static void setExtendMode() { static void setExtendMode() {
auto ret = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTEND | SDC_APPLY); auto ret = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTEND | SDC_APPLY);
MYQDEBUG << "SetDisplayConfig SDC_TOPOLOGY_EXTEND returns:" << ret; MYQDEBUG << "SetDisplayConfig SDC_TOPOLOGY_EXTEND returns:" << (ret == ERROR_SUCCESS);
} }
static void setCloneMode() { static void setCloneMode() {
auto ret = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_CLONE | SDC_APPLY); auto ret = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_CLONE | SDC_APPLY);
MYQDEBUG << "SetDisplayConfig SDC_TOPOLOGY_CLONE returns:" << ret; MYQDEBUG << "SetDisplayConfig SDC_TOPOLOGY_CLONE returns:" << (ret == ERROR_SUCCESS);
} }
//void setOnlyDisplayInMainMonitor() { //void setOnlyDisplayInMainMonitor() {
...@@ -263,7 +263,7 @@ static void setCloneMode() { ...@@ -263,7 +263,7 @@ static void setCloneMode() {
static void commitChange() { static void commitChange() {
auto ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL); auto ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
MYQDEBUG << "commitChange ChangeDisplaySettingsExW returns:" << ret; MYQDEBUG << "commitChange ChangeDisplaySettingsExW returns:" << (ret == ERROR_SUCCESS);
}; };
static void disableMonitor(const MonitorInfo& m) { static void disableMonitor(const MonitorInfo& m) {
...@@ -275,7 +275,7 @@ static void disableMonitor(const MonitorInfo& m) { ...@@ -275,7 +275,7 @@ static void disableMonitor(const MonitorInfo& m) {
DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET; DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET;
auto ret = ChangeDisplaySettingsExW(m.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr); auto ret = ChangeDisplaySettingsExW(m.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr);
MYQDEBUG << "disableMonitor ChangeDisplaySettingsExW returns:" << ret; MYQDEBUG << "disableMonitor ChangeDisplaySettingsExW returns:" << (ret == ERROR_SUCCESS);
commitChange(); commitChange();
} }
...@@ -290,7 +290,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai ...@@ -290,7 +290,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai
DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET; DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET;
auto ret = ChangeDisplaySettingsExW(oldMain.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr); auto ret = ChangeDisplaySettingsExW(oldMain.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr);
MYQDEBUG << "moveOld ChangeDisplaySettingsExW returns:" << ret; MYQDEBUG << "moveOld ChangeDisplaySettingsExW returns:" << (ret == ERROR_SUCCESS);
}; };
auto moveNew = [](const MonitorInfo& newMain) { auto moveNew = [](const MonitorInfo& newMain) {
...@@ -302,7 +302,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai ...@@ -302,7 +302,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai
DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET | CDS_SET_PRIMARY; DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_NORESET | CDS_SET_PRIMARY;
auto ret = ChangeDisplaySettingsExW(newMain.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr); auto ret = ChangeDisplaySettingsExW(newMain.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr);
MYQDEBUG << "moveNew ChangeDisplaySettingsExW returns:" << ret; MYQDEBUG << "moveNew ChangeDisplaySettingsExW returns:" << (ret == ERROR_SUCCESS);
}; };
moveOld(newMain, oldMain); moveOld(newMain, oldMain);
...@@ -320,7 +320,7 @@ static void changeResolution(const MonitorInfo& monitor, const MonitorInfo::Reso ...@@ -320,7 +320,7 @@ static void changeResolution(const MonitorInfo& monitor, const MonitorInfo::Reso
DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL; DWORD dwFlags = CDS_UPDATEREGISTRY | CDS_GLOBAL;
auto ret = ChangeDisplaySettingsExW(monitor.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr); auto ret = ChangeDisplaySettingsExW(monitor.deviceName.toStdWString().data(), &dm, nullptr, dwFlags, nullptr);
MYQDEBUG << "changeResolution ChangeDisplaySettingsExW returns:" << ret; MYQDEBUG << "changeResolution ChangeDisplaySettingsExW returns:" << (ret == ERROR_SUCCESS);
commitChange(); commitChange();
} }
......
...@@ -43,8 +43,8 @@ inline std::vector<::RECT> splitRect(::LPCRECT rc, int n, int gap = 50) { ...@@ -43,8 +43,8 @@ inline std::vector<::RECT> splitRect(::LPCRECT rc, int n, int gap = 50) {
double l = sqrt(n); double l = sqrt(n);
int line = int(l); int line = int(l);
int col_step = (int)(Width(rc) / line); int col_step = (int)(width(rc) / line);
int row_step = (int)(Height(rc) / line); int row_step = (int)(height(rc) / line);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
v[i].left = rc->left + (i % line) * col_step; v[i].left = rc->left + (i % line) * col_step;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment