parent
7694a10e87
commit
d6fe3fd8bd
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
<string>Hello, World!</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Window Title</string>
|
||||
<string>Hello, World!</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
|
|
@ -151,8 +151,6 @@ void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
|
||||
void MainWindow::setupUi()
|
||||
{
|
||||
resize(800, 600);
|
||||
|
||||
appMainWindow = new Ui::MainWindow;
|
||||
appMainWindow->setupUi(this);
|
||||
|
||||
|
@ -183,8 +181,6 @@ void MainWindow::setupUi()
|
|||
titleBarWidget->maximizeButton->setChecked(check);
|
||||
titleBarWidget->maximizeButton->setToolTip(check ? tr("Restore") : tr("Maximize"));
|
||||
});
|
||||
|
||||
setWindowTitle(tr("Hello, World!"));
|
||||
}
|
||||
|
||||
bool MainWindow::isInTitleBarDraggableArea(const QPoint &pos) const
|
||||
|
|
|
@ -75,12 +75,6 @@ static const QString mainStyleSheet = QStringLiteral(R"(#MainWidget {
|
|||
}
|
||||
)");
|
||||
|
||||
[[nodiscard]] static inline bool isTitleBarColorized()
|
||||
{
|
||||
const DwmColorizationArea area = Utilities::getDwmColorizationArea();
|
||||
return ((area == DwmColorizationArea::TitleBar_WindowBorder) || (area == DwmColorizationArea::All));
|
||||
}
|
||||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||
|
@ -290,7 +284,7 @@ void Widget::updateStyleSheet()
|
|||
{
|
||||
const bool active = isActiveWindow();
|
||||
const bool dark = Utilities::shouldAppsUseDarkMode();
|
||||
const bool colorizedTitleBar = isTitleBarColorized();
|
||||
const bool colorizedTitleBar = Utilities::isTitleBarColorized();
|
||||
const QColor titleBarWidgetBackgroundColor = [active, colorizedTitleBar, dark]() -> QColor {
|
||||
if (active) {
|
||||
if (colorizedTitleBar) {
|
||||
|
@ -320,7 +314,7 @@ void Widget::updateStyleSheet()
|
|||
|
||||
void Widget::updateSystemButtonIcons()
|
||||
{
|
||||
const QString prefix = ((Utilities::shouldAppsUseDarkMode() || isTitleBarColorized()) ? QStringLiteral("light") : QStringLiteral("dark"));
|
||||
const QString prefix = ((Utilities::shouldAppsUseDarkMode() || Utilities::isTitleBarColorized()) ? QStringLiteral("light") : QStringLiteral("dark"));
|
||||
m_minimizeButton->setIcon(QIcon(QStringLiteral(":/images/%1/chrome-minimize.svg").arg(prefix)));
|
||||
if (isMaximized() || isFullScreen()) {
|
||||
m_maximizeButton->setIcon(QIcon(QStringLiteral(":/images/%1/chrome-restore.svg").arg(prefix)));
|
||||
|
|
|
@ -71,7 +71,6 @@
|
|||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <uxtheme.h>
|
||||
#include <shellapi.h>
|
||||
#include <dwmapi.h>
|
||||
#include <timeapi.h>
|
||||
|
@ -101,6 +100,10 @@
|
|||
# define SM_CXPADDEDBORDER (92)
|
||||
#endif
|
||||
|
||||
#ifndef SM_CYPADDEDBORDER
|
||||
# define SM_CYPADDEDBORDER SM_CXPADDEDBORDER
|
||||
#endif
|
||||
|
||||
#ifndef ABM_GETAUTOHIDEBAREX
|
||||
# define ABM_GETAUTOHIDEBAREX (0x0000000b)
|
||||
#endif
|
||||
|
|
|
@ -135,11 +135,7 @@ QColor FramelessQuickUtils::systemAccentColor()
|
|||
bool FramelessQuickUtils::titleBarColorVisible()
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
if (!Utilities::isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
const DwmColorizationArea area = Utilities::getDwmColorizationArea();
|
||||
return ((area == DwmColorizationArea::TitleBar_WindowBorder) || (area == DwmColorizationArea::All));
|
||||
return Utilities::isTitleBarColorized();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
|
@ -78,6 +78,8 @@ FRAMELESSHELPER_API void showSystemMenu(const WId winId, const QPointF &pos);
|
|||
FRAMELESSHELPER_API void updateWindowFrameBorderColor(const WId winId, const bool dark);
|
||||
FRAMELESSHELPER_API void fixupQtInternals(const WId winId);
|
||||
[[nodiscard]] FRAMELESSHELPER_API bool isWindowFrameBorderVisible();
|
||||
[[nodiscard]] FRAMELESSHELPER_API bool isTitleBarColorized();
|
||||
[[nodiscard]] FRAMELESSHELPER_API bool isFrameBorderColorized();
|
||||
#endif // Q_OS_WINDOWS
|
||||
|
||||
} // namespace Utilities
|
||||
|
|
|
@ -241,8 +241,8 @@ void Utilities::updateWindowFrameMargins(const WId winId, const bool reset)
|
|||
if (!winId) {
|
||||
return;
|
||||
}
|
||||
// DwmExtendFrameIntoClientArea() will always fail if DWM composition is disabled.
|
||||
// No need to try in this case.
|
||||
// We can't extend the window frame when DWM composition is disabled.
|
||||
// No need to try further in this case.
|
||||
if (!isDwmCompositionEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
@ -252,12 +252,9 @@ void Utilities::updateWindowFrameMargins(const WId winId, const bool reset)
|
|||
if (!pDwmExtendFrameIntoClientArea) {
|
||||
return;
|
||||
}
|
||||
const MARGINS margins = [reset, winId]() -> MARGINS {
|
||||
if (reset) {
|
||||
const MARGINS margins = [reset]() -> MARGINS {
|
||||
if (reset || isWindowFrameBorderVisible()) {
|
||||
return {0, 0, 0, 0};
|
||||
}
|
||||
if (isWindowFrameBorderVisible()) {
|
||||
return {0, static_cast<int>(getTitleBarHeight(winId, true)), 0, 0};
|
||||
} else {
|
||||
return {1, 1, 1, 1};
|
||||
}
|
||||
|
@ -367,7 +364,7 @@ bool Utilities::shouldAppsUseDarkMode()
|
|||
|
||||
DwmColorizationArea Utilities::getDwmColorizationArea()
|
||||
{
|
||||
// It's a Win10 only feature.
|
||||
// It's a Win10 only feature. (TO BE VERIFIED)
|
||||
if (!isWin10OrGreater()) {
|
||||
return DwmColorizationArea::None;
|
||||
}
|
||||
|
@ -686,11 +683,12 @@ quint32 Utilities::getResizeBorderThickness(const WId winId, const bool horizont
|
|||
if (!winId) {
|
||||
return 0;
|
||||
}
|
||||
const int paddedBorderWidth = getSystemMetrics2(winId, SM_CXPADDEDBORDER, true, scaled);
|
||||
if (horizontal) {
|
||||
return (getSystemMetrics2(winId, SM_CXSIZEFRAME, true, scaled) + paddedBorderWidth);
|
||||
return (getSystemMetrics2(winId, SM_CXSIZEFRAME, true, scaled)
|
||||
+ getSystemMetrics2(winId, SM_CXPADDEDBORDER, true, scaled));
|
||||
} else {
|
||||
return (getSystemMetrics2(winId, SM_CYSIZEFRAME, false, scaled) + paddedBorderWidth);
|
||||
return (getSystemMetrics2(winId, SM_CYSIZEFRAME, false, scaled)
|
||||
+ getSystemMetrics2(winId, SM_CYPADDEDBORDER, false, scaled));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -750,11 +748,10 @@ QColor Utilities::getFrameBorderColor(const bool active)
|
|||
}
|
||||
const bool dark = shouldAppsUseDarkMode();
|
||||
if (active) {
|
||||
const DwmColorizationArea area = getDwmColorizationArea();
|
||||
if ((area == DwmColorizationArea::TitleBar_WindowBorder) || (area == DwmColorizationArea::All)) {
|
||||
if (isFrameBorderColorized()) {
|
||||
return getDwmColorizationColor();
|
||||
} else {
|
||||
return (dark ? QColor(QStringLiteral("#4d4d4d")) : QColor(Qt::white));
|
||||
return (dark ? QColor(QStringLiteral("#4d4d4d")) : QColor(Qt::black));
|
||||
}
|
||||
} else {
|
||||
return (dark ? QColor(QStringLiteral("#575959")) : QColor(QStringLiteral("#a6a6a6")));
|
||||
|
@ -771,29 +768,18 @@ void Utilities::updateWindowFrameBorderColor(const WId winId, const bool dark)
|
|||
if (!isWin101809OrGreater()) {
|
||||
return;
|
||||
}
|
||||
static const auto pSetWindowTheme =
|
||||
reinterpret_cast<decltype(&SetWindowTheme)>(
|
||||
QSystemLibrary::resolve(QStringLiteral("uxtheme"), "SetWindowTheme"));
|
||||
static const auto pDwmSetWindowAttribute =
|
||||
reinterpret_cast<decltype(&DwmSetWindowAttribute)>(
|
||||
QSystemLibrary::resolve(QStringLiteral("dwmapi"), "DwmSetWindowAttribute"));
|
||||
if (!pSetWindowTheme || !pDwmSetWindowAttribute) {
|
||||
if (!pDwmSetWindowAttribute) {
|
||||
return;
|
||||
}
|
||||
const auto hwnd = reinterpret_cast<HWND>(winId);
|
||||
const BOOL value = (dark ? TRUE : FALSE);
|
||||
HRESULT hr = pDwmSetWindowAttribute(hwnd, _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &value, sizeof(value));
|
||||
if (FAILED(hr)) {
|
||||
// Just eat this error, because it only works on systems before Win10 20H1.
|
||||
}
|
||||
hr = pDwmSetWindowAttribute(hwnd, _DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||
if (FAILED(hr)) {
|
||||
// Eat this error, it only works on systems greater than or equal to Win10 20H1.
|
||||
}
|
||||
hr = pSetWindowTheme(hwnd, (dark ? L"DarkMode_Explorer" : L" "), nullptr);
|
||||
if (FAILED(hr)) {
|
||||
qWarning() << __getSystemErrorMessage(QStringLiteral("SetWindowTheme"), hr);
|
||||
}
|
||||
// Whether dark window frame is available or not depends on the runtime system version,
|
||||
// it's totally OK if it's not available, so just ignore the errors.
|
||||
pDwmSetWindowAttribute(hwnd, _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, &value, sizeof(value));
|
||||
pDwmSetWindowAttribute(hwnd, _DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||
}
|
||||
|
||||
void Utilities::fixupQtInternals(const WId winId)
|
||||
|
@ -885,4 +871,19 @@ bool Utilities::isWindowFrameBorderVisible()
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Utilities::isTitleBarColorized()
|
||||
{
|
||||
// CHECK: is it supported on win7?
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
const DwmColorizationArea area = getDwmColorizationArea();
|
||||
return ((area == DwmColorizationArea::TitleBar_WindowBorder) || (area == DwmColorizationArea::All));
|
||||
}
|
||||
|
||||
bool Utilities::isFrameBorderColorized()
|
||||
{
|
||||
return isTitleBarColorized();
|
||||
}
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
Loading…
Reference in New Issue