forked from github_mirror/framelesshelper
minor tweaks
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
653fa1d6f1
commit
6e79ba3f33
|
@ -136,7 +136,7 @@ void Dialog::setupUi()
|
|||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
// Qt doesn't support dpr < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
|
|
|
@ -40,6 +40,12 @@ int main(int argc, char *argv[])
|
|||
// of any Q(Core|Gui)Application instances.
|
||||
FramelessHelper::Widgets::initialize();
|
||||
|
||||
#if 0
|
||||
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
|
||||
qputenv("QT_WIDGETS_RHI", FRAMELESSHELPER_BYTEARRAY_LITERAL("1"));
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto application = std::make_unique<QApplication>(argc, argv);
|
||||
|
||||
// Must be called after QGuiApplication has been constructed, we are using
|
||||
|
|
|
@ -40,6 +40,12 @@ int main(int argc, char *argv[])
|
|||
// of any Q(Core|Gui)Application instances.
|
||||
FramelessHelper::Widgets::initialize();
|
||||
|
||||
#if 0
|
||||
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
|
||||
qputenv("QT_WIDGETS_RHI", FRAMELESSHELPER_BYTEARRAY_LITERAL("1"));
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto application = std::make_unique<QApplication>(argc, argv);
|
||||
|
||||
// Must be called after QGuiApplication has been constructed, we are using
|
||||
|
|
|
@ -109,7 +109,7 @@ QMenuBar::item:pressed {
|
|||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
// Qt doesn't support dpr < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
|
|
|
@ -84,7 +84,7 @@ void MainWindow::initialize()
|
|||
const auto savedGeometry = Settings::get<QRect>({}, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>({}, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
// Qt doesn't support dpr < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
|
|
|
@ -63,7 +63,7 @@ bool QuickSettings::restoreGeometry(QWindow *window)
|
|||
return false;
|
||||
}
|
||||
const auto savedDpr = Settings::get<qreal>(objName, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
// Qt doesn't support dpr < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (window->devicePixelRatio() / oldDpr);
|
||||
window->setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
|
|
|
@ -86,9 +86,9 @@ void Log::setup(const QString &app)
|
|||
}
|
||||
once = true;
|
||||
g_app = app;
|
||||
qInstallMessageHandler(myMessageHandler);
|
||||
qSetMessagePattern(FRAMELESSHELPER_STRING_LITERAL(
|
||||
"[%{time yyyy/MM/dd hh:mm:ss.zzz}] <%{if-info}INFO%{endif}%{if-debug}DEBUG"
|
||||
"%{endif}%{if-warning}WARNING%{endif}%{if-critical}CRITICAL%{endif}%{if-fatal}"
|
||||
"FATAL%{endif}> %{if-category}%{category}: %{endif}%{message}"));
|
||||
qInstallMessageHandler(myMessageHandler);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,12 @@ int main(int argc, char *argv[])
|
|||
// of any Q(Core|Gui)Application instances.
|
||||
FramelessHelper::Widgets::initialize();
|
||||
|
||||
#if 0
|
||||
if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) {
|
||||
qputenv("QT_WIDGETS_RHI", FRAMELESSHELPER_BYTEARRAY_LITERAL("1"));
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto application = std::make_unique<QApplication>(argc, argv);
|
||||
|
||||
// Must be called after QGuiApplication has been constructed, we are using
|
||||
|
|
|
@ -136,7 +136,7 @@ void Widget::initialize()
|
|||
const auto savedGeometry = Settings::get<QRect>(objName, kGeometry);
|
||||
if (savedGeometry.isValid() && !parent()) {
|
||||
const auto savedDpr = Settings::get<qreal>(objName, kDevicePixelRatio);
|
||||
// Qt doesn't support dpi < 1.
|
||||
// Qt doesn't support dpr < 1.
|
||||
const qreal oldDpr = std::max(savedDpr, qreal(1));
|
||||
const qreal scale = (devicePixelRatioF() / oldDpr);
|
||||
setGeometry({savedGeometry.topLeft() * scale, savedGeometry.size() * scale});
|
||||
|
|
|
@ -82,7 +82,7 @@ function(setup_compile_params arg_target)
|
|||
target_link_options(${arg_target} PRIVATE /SAFESEH)
|
||||
endif()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
target_link_options(${arg_target} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/HIGHENTROPYVA>)
|
||||
target_link_options(${arg_target} PRIVATE /HIGHENTROPYVA)
|
||||
endif()
|
||||
if(MSVC_VERSION GREATER_EQUAL 1915) # Visual Studio 2017 version 15.8
|
||||
target_compile_options(${arg_target} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:/JMC>)
|
||||
|
|
|
@ -83,7 +83,6 @@ struct ConfigData
|
|||
bool options[OptionCount] = {};
|
||||
bool disableEnvVar = false;
|
||||
bool disableCfgFile = false;
|
||||
QVariantHash internals = {};
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(ConfigData, g_data)
|
||||
|
@ -147,7 +146,7 @@ void FramelessConfig::reload(const bool force)
|
|||
}
|
||||
g_data()->loaded = true;
|
||||
|
||||
QTimer::singleShot(0, qApp, [](){ warnInappropriateOptions(); });
|
||||
QTimer::singleShot(0, this, [](){ warnInappropriateOptions(); });
|
||||
}
|
||||
|
||||
void FramelessConfig::set(const Option option, const bool on)
|
||||
|
|
|
@ -530,11 +530,20 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms)
|
|||
}
|
||||
g_win32Helper()->mutex.unlock();
|
||||
DEBUG.noquote() << "The DPI of window" << hwnd2str(windowId) << "is" << data.dpi;
|
||||
#if 0
|
||||
params.setWindowFlags(params.getWindowFlags() | Qt::FramelessWindowHint);
|
||||
// We need some delay here, otherwise the window styles will be overwritten by
|
||||
// QPA itself. But don't use QThread::sleep(), it doesn't help in our case.
|
||||
QTimer::singleShot(0, qApp, [windowId](){
|
||||
Utils::maybeFixupQtInternals(windowId);
|
||||
});
|
||||
#else
|
||||
// Qt maintains a frame margin internally, we need to update it accordingly
|
||||
// otherwise we'll get lots of warning messages when we change the window
|
||||
// geometry, it will also affect the final window geometry because QPA will
|
||||
// always take it into account when setting window size and position.
|
||||
Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true);
|
||||
#endif
|
||||
// Tell DWM our preferred frame margin.
|
||||
Utils::updateWindowFrameMargins(windowId, false);
|
||||
// Tell DWM we don't use the window icon/caption/sysmenu, don't draw them.
|
||||
|
@ -562,7 +571,7 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms)
|
|||
// The fallback title bar window is only used to activate the Snap Layout feature
|
||||
// introduced in Windows 11, so it's not necessary to create it on systems below Win11.
|
||||
if (!FramelessConfig::instance()->isSet(Option::DisableWindowsSnapLayout)) {
|
||||
if (!createFallbackTitleBarWindow(windowId, data.params.isWindowFixedSize())) {
|
||||
if (!createFallbackTitleBarWindow(windowId, params.isWindowFixedSize())) {
|
||||
WARNING << "Failed to create the fallback title bar window.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1276,7 +1276,9 @@ void Utils::maybeFixupQtInternals(const WId windowId)
|
|||
}
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE));
|
||||
if (windowStyle != 0) {
|
||||
if (windowStyle == 0) {
|
||||
WARNING << getSystemErrorMessage(kGetWindowLongPtrW);
|
||||
} else {
|
||||
// Qt by default adds the "WS_POPUP" flag to all Win32 windows it created and maintained,
|
||||
// which is not a good thing (although it won't cause any obvious issues in most cases
|
||||
// either), because popup windows have some different behavior with normal overlapped
|
||||
|
@ -1285,8 +1287,7 @@ void Utils::maybeFixupQtInternals(const WId windowId)
|
|||
// and this will also break the normal functionalities for our windows, so we do the
|
||||
// correction here unconditionally.
|
||||
static constexpr const DWORD badWindowStyle = WS_POPUP;
|
||||
static constexpr const DWORD goodWindowStyle =
|
||||
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
|
||||
static constexpr const DWORD goodWindowStyle = WS_OVERLAPPEDWINDOW;
|
||||
if ((windowStyle & badWindowStyle) || !(windowStyle & goodWindowStyle)) {
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~badWindowStyle) | goodWindowStyle)) == 0) {
|
||||
|
@ -1295,8 +1296,6 @@ void Utils::maybeFixupQtInternals(const WId windowId)
|
|||
shouldUpdateFrame = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WARNING << getSystemErrorMessage(kGetWindowLongPtrW);
|
||||
}
|
||||
if (shouldUpdateFrame) {
|
||||
triggerFrameChange(windowId);
|
||||
|
|
Loading…
Reference in New Issue