Improve the Win32Demo project.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
|
@ -146,7 +146,7 @@
|
|||
<string>Minimize</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -187,7 +187,7 @@
|
|||
<string>Maximize</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_maximize_black.svg</normaloff>
|
||||
<normalon>:/images/button_restore_black.svg</normalon>:/images/button_maximize_black.svg</iconset>
|
||||
</property>
|
||||
|
@ -232,7 +232,7 @@
|
|||
<string>Close</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -247,7 +247,7 @@
|
|||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -3,4 +3,5 @@ TEMPLATE = app
|
|||
QT += quick
|
||||
HEADERS += $$PWD/../../framelessquickhelper.h
|
||||
SOURCES += $$PWD/../../framelessquickhelper.cpp main.cpp
|
||||
RESOURCES += qml.qrc
|
||||
include($$PWD/../common.pri)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qml/main.qml</file>
|
||||
<file>qml/MinimizeButton.qml</file>
|
||||
<file>qml/MaximizeButton.qml</file>
|
||||
<file>qml/CloseButton.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -1,7 +1,7 @@
|
|||
TARGET = Win32Demo
|
||||
TEMPLATE = app
|
||||
QT += widgets
|
||||
LIBS += -luser32
|
||||
LIBS += -luser32 -ldwmapi
|
||||
HEADERS += widget.h
|
||||
SOURCES += widget.cpp main.cpp
|
||||
FORMS += widget.ui
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
#include <QStyleOption>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -54,6 +55,12 @@ int main(int argc, char *argv[])
|
|||
QApplication::setFont({QLatin1String("Microsoft YaHei")});
|
||||
|
||||
Widget widget;
|
||||
|
||||
QStyleOption option;
|
||||
option.initFrom(&widget);
|
||||
widget.setWindowIcon(widget.style()->standardIcon(QStyle::SP_ComputerIcon, &option));
|
||||
widget.setWindowTitle(QObject::tr("Hello, World!"));
|
||||
|
||||
widget.show();
|
||||
|
||||
return QApplication::exec();
|
||||
|
|
|
@ -25,9 +25,11 @@
|
|||
#include "widget.h"
|
||||
#include "../../winnativeeventfilter.h"
|
||||
#include "ui_widget.h"
|
||||
#include <dwmapi.h>
|
||||
#include <QColorDialog>
|
||||
#include <QOperatingSystemVersion>
|
||||
#include <QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
#include <qt_windows.h>
|
||||
|
||||
// Copied from windowsx.h
|
||||
|
@ -40,6 +42,33 @@ const char useNativeTitleBar[] = "WNEF_USE_NATIVE_TITLE_BAR";
|
|||
const char preserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
||||
const char forceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
|
||||
|
||||
const QLatin1String systemButtonsStyleSheet(R"(
|
||||
#iconButton, #minimizeButton, #maximizeButton, #closeButton {
|
||||
background-color: transparent;
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
#minimizeButton:hover, #maximizeButton:hover {
|
||||
border-style: none;
|
||||
background-color: #80c7c7c7;
|
||||
}
|
||||
|
||||
#minimizeButton:pressed, #maximizeButton:pressed {
|
||||
border-style: none;
|
||||
background-color: #80808080;
|
||||
}
|
||||
|
||||
#closeButton:hover {
|
||||
border-style: none;
|
||||
background-color: #e81123;
|
||||
}
|
||||
|
||||
#closeButton:pressed {
|
||||
border-style: none;
|
||||
background-color: #8c0a15;
|
||||
}
|
||||
)");
|
||||
|
||||
void *getRawHandle(QWidget *widget)
|
||||
{
|
||||
Q_ASSERT(widget);
|
||||
|
@ -51,25 +80,77 @@ void updateWindow(QWidget *widget)
|
|||
Q_ASSERT(widget);
|
||||
if (widget->isTopLevel()) {
|
||||
void *handle = getRawHandle(widget);
|
||||
WinNativeEventFilter::updateFrameMargins(handle);
|
||||
//WinNativeEventFilter::updateFrameMargins(handle);
|
||||
WinNativeEventFilter::updateWindow(handle, true, true);
|
||||
widget->update();
|
||||
}
|
||||
}
|
||||
|
||||
bool isWin10OrGreater()
|
||||
{
|
||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
||||
}
|
||||
|
||||
bool isGreaterThanWin10_1803()
|
||||
{
|
||||
return QOperatingSystemVersion::current()
|
||||
>= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17134);
|
||||
}
|
||||
|
||||
bool isThemeColorEnabled()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
bool ok = false;
|
||||
const QSettings registry(QLatin1String(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM)"),
|
||||
QSettings::NativeFormat);
|
||||
const bool colorPrevalence = registry.value(QLatin1String("ColorPrevalence"), 0).toULongLong(&ok)
|
||||
!= 0;
|
||||
return (ok && colorPrevalence);
|
||||
}
|
||||
|
||||
bool isDarkModeEnabled()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
}
|
||||
bool ok = false;
|
||||
const QSettings registry(
|
||||
QLatin1String(
|
||||
R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"),
|
||||
QSettings::NativeFormat);
|
||||
const bool appsUseLightTheme
|
||||
= registry.value(QLatin1String("AppsUseLightTheme"), 0).toULongLong(&ok) != 0;
|
||||
return (ok && !appsUseLightTheme);
|
||||
}
|
||||
|
||||
QColor getThemeColor()
|
||||
{
|
||||
DWORD color = 0;
|
||||
BOOL opaqueBlend = FALSE;
|
||||
return SUCCEEDED(DwmGetColorizationColor(&color, &opaqueBlend)) ? QColor::fromRgba(color)
|
||||
: Qt::white;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||
{
|
||||
m_bIsWin10OrGreater = isWin10OrGreater();
|
||||
|
||||
m_cThemeColor = getThemeColor();
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->forceAcrylicCB->setEnabled(isGreaterThanWin10_1803());
|
||||
|
||||
if (shouldDrawBorder()) {
|
||||
layout()->setContentsMargins(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
updateTitleBar();
|
||||
|
||||
connect(ui->iconButton, &QPushButton::clicked, this, [this]() {
|
||||
POINT pos = {};
|
||||
GetCursorPos(&pos);
|
||||
|
@ -96,7 +177,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||
|
||||
connect(ui->customizeTitleBarCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
const bool enable = state == Qt::Checked;
|
||||
ui->windowFrameCB->setEnabled(enable);
|
||||
ui->removeWindowFrameCB->setEnabled(enable);
|
||||
WinNativeEventFilter::updateQtFrame(windowHandle(),
|
||||
enable ? WinNativeEventFilter::getSystemMetric(
|
||||
getRawHandle(this),
|
||||
|
@ -110,12 +191,18 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||
}
|
||||
updateWindow(this);
|
||||
});
|
||||
connect(ui->windowFrameCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
if (state == Qt::Checked) {
|
||||
connect(ui->removeWindowFrameCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
const bool enable = state == Qt::Checked;
|
||||
if (enable) {
|
||||
qunsetenv(preserveWindowFrame);
|
||||
} else {
|
||||
qputenv(preserveWindowFrame, "1");
|
||||
}
|
||||
if (enable && shouldDrawBorder()) {
|
||||
layout()->setContentsMargins(1, 1, 1, 1);
|
||||
} else {
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
updateWindow(this);
|
||||
});
|
||||
connect(ui->blurEffectCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
|
@ -132,6 +219,10 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||
WinNativeEventFilter::setBlurEffectEnabled(getRawHandle(this), enable, color);
|
||||
updateWindow(this);
|
||||
});
|
||||
connect(ui->extendToTitleBarCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
m_bExtendToTitleBar = state == Qt::Checked;
|
||||
updateTitleBar();
|
||||
});
|
||||
connect(ui->forceAcrylicCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
if (state == Qt::Checked) {
|
||||
qputenv(forceUseAcrylicEffect, "1");
|
||||
|
@ -149,11 +240,6 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||
WinNativeEventFilter::setWindowResizable(getRawHandle(this), enable);
|
||||
});
|
||||
|
||||
QStyleOption option;
|
||||
option.initFrom(this);
|
||||
setWindowIcon(style()->standardIcon(QStyle::SP_ComputerIcon, &option));
|
||||
setWindowTitle(tr("Hello, World!"));
|
||||
|
||||
WinNativeEventFilter::WINDOWDATA data = {};
|
||||
data.ignoreObjects << ui->iconButton << ui->minimizeButton << ui->maximizeButton
|
||||
<< ui->closeButton;
|
||||
|
@ -167,22 +253,66 @@ Widget::~Widget()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
bool Widget::isNormaled() const
|
||||
{
|
||||
return !isMinimized() && !isMaximized() && !isFullScreen();
|
||||
}
|
||||
|
||||
bool Widget::shouldDrawBorder(const bool ignoreWindowState) const
|
||||
{
|
||||
return m_bIsWin10OrGreater && (ignoreWindowState ? true : isNormaled())
|
||||
&& ui->removeWindowFrameCB->isChecked() && ui->customizeTitleBarCB->isChecked();
|
||||
}
|
||||
|
||||
bool Widget::shouldDrawThemedBorder(const bool ignoreWindowState) const
|
||||
{
|
||||
return (shouldDrawBorder(ignoreWindowState) && isThemeColorEnabled());
|
||||
}
|
||||
|
||||
QColor Widget::activeBorderColor() const
|
||||
{
|
||||
return isThemeColorEnabled() ? m_cThemeColor
|
||||
: (isDarkModeEnabled() ? m_cDefaultActiveBorderColor : Qt::white);
|
||||
}
|
||||
|
||||
QColor Widget::inactiveBorderColor() const
|
||||
{
|
||||
return m_cDefaultInactiveBorderColor;
|
||||
}
|
||||
|
||||
QColor Widget::borderColor() const
|
||||
{
|
||||
return isActiveWindow() ? activeBorderColor() : inactiveBorderColor();
|
||||
}
|
||||
|
||||
bool Widget::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
Q_ASSERT(event);
|
||||
switch (event->type()) {
|
||||
case QEvent::WindowStateChange: {
|
||||
if (isMaximized()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_restore_black.svg")));
|
||||
} else if (!isFullScreen() && !isMinimized()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg")));
|
||||
if (shouldDrawBorder(true)) {
|
||||
if (isMaximized()) {
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
if (isNormaled()) {
|
||||
layout()->setContentsMargins(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
ui->moveCenterButton->setEnabled(!isMaximized() && !isFullScreen());
|
||||
} break;
|
||||
updateTitleBar();
|
||||
ui->moveCenterButton->setEnabled(isNormaled());
|
||||
break;
|
||||
}
|
||||
case QEvent::WinIdChange:
|
||||
WinNativeEventFilter::addFramelessWindow(this);
|
||||
break;
|
||||
case QEvent::WindowActivate:
|
||||
case QEvent::WindowDeactivate: {
|
||||
if (shouldDrawThemedBorder(true)) {
|
||||
updateTitleBar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -212,9 +342,67 @@ bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *resul
|
|||
}
|
||||
break;
|
||||
}
|
||||
case WM_DWMCOLORIZATIONCOLORCHANGED: {
|
||||
m_cThemeColor = QColor::fromRgba(msg->wParam);
|
||||
if (shouldDrawThemedBorder()) {
|
||||
update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
}
|
||||
|
||||
void Widget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
if (shouldDrawBorder()) {
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setPen(borderColor());
|
||||
painter.drawLine(0, 0, width(), 0);
|
||||
painter.drawLine(0, height(), width(), height());
|
||||
painter.drawLine(0, 0, 0, height());
|
||||
painter.drawLine(width(), 0, width(), height());
|
||||
painter.restore();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::updateTitleBar()
|
||||
{
|
||||
const bool themedTitleBar = shouldDrawThemedBorder(true) && isActiveWindow();
|
||||
if (themedTitleBar && !m_bExtendToTitleBar) {
|
||||
ui->minimizeButton->setIcon(QIcon(QLatin1String(":/images/button_minimize_white.svg")));
|
||||
ui->closeButton->setIcon(QIcon(QLatin1String(":/images/button_close_white.svg")));
|
||||
if (isMaximized()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_restore_white.svg")));
|
||||
}
|
||||
if (isNormaled()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_white.svg")));
|
||||
}
|
||||
} else {
|
||||
ui->minimizeButton->setIcon(QIcon(QLatin1String(":/images/button_minimize_black.svg")));
|
||||
ui->closeButton->setIcon(QIcon(QLatin1String(":/images/button_close_black.svg")));
|
||||
if (isMaximized()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_restore_black.svg")));
|
||||
}
|
||||
if (isNormaled()) {
|
||||
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg")));
|
||||
}
|
||||
}
|
||||
const QColor color = m_bExtendToTitleBar ? Qt::transparent
|
||||
: (themedTitleBar ? m_cThemeColor : Qt::white);
|
||||
ui->titleBarWidget->setStyleSheet(systemButtonsStyleSheet
|
||||
+ QLatin1String(R"(
|
||||
#titleBarWidget {
|
||||
background-color: rgba(%1, %2, %3, %4);
|
||||
}
|
||||
)")
|
||||
.arg(QString::number(color.red()),
|
||||
QString::number(color.green()),
|
||||
QString::number(color.blue()),
|
||||
QString::number(color.alpha())));
|
||||
}
|
||||
|
|
|
@ -39,7 +39,16 @@ class Widget : public QWidget
|
|||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = nullptr);
|
||||
~Widget();
|
||||
~Widget() override;
|
||||
|
||||
bool isNormaled() const;
|
||||
|
||||
bool shouldDrawBorder(const bool ignoreWindowState = false) const;
|
||||
bool shouldDrawThemedBorder(const bool ignoreWindowState = false) const;
|
||||
|
||||
QColor activeBorderColor() const;
|
||||
QColor inactiveBorderColor() const;
|
||||
QColor borderColor() const;
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
@ -48,7 +57,15 @@ protected:
|
|||
#else
|
||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||
#endif
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
void updateTitleBar();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui = nullptr;
|
||||
bool m_bIsWin10OrGreater = false, m_bExtendToTitleBar = false;
|
||||
const QColor m_cDefaultActiveBorderColor = /*{"707070"}*/ Qt::darkGray;
|
||||
const QColor m_cDefaultInactiveBorderColor = /*{"aaaaaa"}*/ Qt::gray;
|
||||
QColor m_cThemeColor = Qt::white;
|
||||
};
|
||||
|
|
|
@ -13,49 +13,7 @@
|
|||
<property name="windowTitle">
|
||||
<string>Widget</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#titleBarWidget {
|
||||
background-color: rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
#iconButton, #minimizeButton, #maximizeButton, #closeButton {
|
||||
background-color: transparent;
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
#minimizeButton:hover, #maximizeButton:hover {
|
||||
border-style: none;
|
||||
background-color: #80c7c7c7;
|
||||
}
|
||||
|
||||
#minimizeButton:pressed, #maximizeButton:pressed {
|
||||
border-style: none;
|
||||
background-color: #80808080;
|
||||
}
|
||||
|
||||
#closeButton:hover {
|
||||
border-style: none;
|
||||
background-color: #e81123;
|
||||
}
|
||||
|
||||
#closeButton:pressed {
|
||||
border-style: none;
|
||||
background-color: #8c0a15;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="titleBarWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
|
@ -161,7 +119,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -196,7 +154,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_maximize_black.svg</normaloff>:/images/button_maximize_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -231,7 +189,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -309,7 +267,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="windowFrameCB">
|
||||
<widget class="QCheckBox" name="removeWindowFrameCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
|
@ -318,7 +276,7 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Get rid of window frame</string>
|
||||
<string>Remove window frame</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
|
@ -339,6 +297,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="extendToTitleBarCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Extend to title bar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="forceAcrylicCB">
|
||||
<property name="font">
|
||||
|
@ -451,7 +423,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -4,7 +4,7 @@ DEFINES += \
|
|||
QT_NO_CAST_FROM_ASCII \
|
||||
QT_NO_CAST_TO_ASCII \
|
||||
FRAMELESSHELPER_STATIC
|
||||
RESOURCES += $$PWD/resources.qrc
|
||||
RESOURCES += $$PWD/images.qrc
|
||||
HEADERS += \
|
||||
$$PWD/../framelesshelper_global.h \
|
||||
$$PWD/../framelesswindowsmanager.h
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/button_minimize_black.svg</file>
|
||||
<file>images/button_minimize_white.svg</file>
|
||||
<file>images/button_maximize_black.svg</file>
|
||||
<file>images/button_maximize_white.svg</file>
|
||||
<file>images/button_restore_black.svg</file>
|
||||
<file>images/button_restore_white.svg</file>
|
||||
<file>images/button_close_black.svg</file>
|
||||
<file>images/button_close_white.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 430 B After Width: | Height: | Size: 430 B |
Before Width: | Height: | Size: 430 B After Width: | Height: | Size: 430 B |
|
@ -1,18 +0,0 @@
|
|||
<RCC>
|
||||
<qresource prefix="/qml">
|
||||
<file alias="main.qml">resources/qml/main.qml</file>
|
||||
<file alias="MinimizeButton.qml">resources/qml/MinimizeButton.qml</file>
|
||||
<file alias="MaximizeButton.qml">resources/qml/MaximizeButton.qml</file>
|
||||
<file alias="CloseButton.qml">resources/qml/CloseButton.qml</file>
|
||||
</qresource>
|
||||
<qresource prefix="/images">
|
||||
<file alias="button_minimize_black.svg">resources/images/button_minimize_black.svg</file>
|
||||
<file alias="button_minimize_white.svg">resources/images/button_minimize_white.svg</file>
|
||||
<file alias="button_maximize_black.svg">resources/images/button_maximize_black.svg</file>
|
||||
<file alias="button_maximize_white.svg">resources/images/button_maximize_white.svg</file>
|
||||
<file alias="button_restore_black.svg">resources/images/button_restore_black.svg</file>
|
||||
<file alias="button_restore_white.svg">resources/images/button_restore_white.svg</file>
|
||||
<file alias="button_close_black.svg">resources/images/button_close_black.svg</file>
|
||||
<file alias="button_close_white.svg">resources/images/button_close_white.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -658,9 +658,14 @@ const UINT m_defaultDotsPerInch = USER_DEFAULT_SCREEN_DPI;
|
|||
|
||||
const qreal m_defaultDevicePixelRatio = 1.0;
|
||||
|
||||
const char envVarUseNativeTitleBar[] = "WNEF_USE_NATIVE_TITLE_BAR";
|
||||
const char envVarPreserveWindowFrame[] = "WNEF_PRESERVE_WINDOW_FRAME";
|
||||
const char envVarForceWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
||||
const char envVarForceAcrylic[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
|
||||
|
||||
bool shouldUseNativeTitleBar()
|
||||
{
|
||||
return qEnvironmentVariableIsSet("WNEF_USE_NATIVE_TITLE_BAR");
|
||||
return qEnvironmentVariableIsSet(envVarUseNativeTitleBar);
|
||||
}
|
||||
|
||||
bool shouldHaveWindowFrame()
|
||||
|
@ -670,8 +675,8 @@ bool shouldHaveWindowFrame()
|
|||
// want to use the native title bar.
|
||||
return true;
|
||||
}
|
||||
const bool should = qEnvironmentVariableIsSet("WNEF_PRESERVE_WINDOW_FRAME");
|
||||
const bool force = qEnvironmentVariableIsSet("WNEF_FORCE_PRESERVE_WINDOW_FRAME");
|
||||
const bool should = qEnvironmentVariableIsSet(envVarPreserveWindowFrame);
|
||||
const bool force = qEnvironmentVariableIsSet(envVarForceWindowFrame);
|
||||
if (should || force) {
|
||||
if (force) {
|
||||
return true;
|
||||
|
@ -689,6 +694,11 @@ bool shouldHaveWindowFrame()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool forceEnableAcrylicOnWin10()
|
||||
{
|
||||
return qEnvironmentVariableIsSet(envVarForceAcrylic);
|
||||
}
|
||||
|
||||
BOOL IsDwmCompositionEnabled()
|
||||
{
|
||||
// Since Win8, DWM composition is always enabled and can't be disabled.
|
||||
|
@ -987,8 +997,8 @@ void UpdateFrameMarginsForWindow(const HWND handle)
|
|||
margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
||||
}
|
||||
} else {
|
||||
//margins.cyTopHeight = 1;
|
||||
margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
||||
margins.cyTopHeight = 1;
|
||||
//margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
|
||||
}
|
||||
if (shouldUseNativeTitleBar()) {
|
||||
// If we are going to use the native title bar,
|
||||
|
@ -1612,7 +1622,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// Fix the flickering problem when resizing.
|
||||
// Don't modify the left, right or bottom edge because
|
||||
// a border line will be seen (at least on Win10).
|
||||
clientRect->top -= 1;
|
||||
//clientRect->top -= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2386,18 +2396,23 @@ bool WinNativeEventFilter::setBlurEffectEnabled(void *handle,
|
|||
wcaData.cbData = sizeof(accentPolicy);
|
||||
if (enabled) {
|
||||
if (isWin10OrGreater(17134)) {
|
||||
// Enabling the Acrylic effect for Win32 windows is
|
||||
// very buggy and it's a bug of Windows 10 itself so
|
||||
// it's not fixable from my side.
|
||||
if (qEnvironmentVariableIsSet("WNEF_FORCE_ACRYLIC_ON_WIN10")) {
|
||||
// Windows 10, version 1803 (10.0.17134)
|
||||
// It's not allowed to enable the Acrylic effect for Win32
|
||||
// applications until Win10 1803.
|
||||
// Windows 10, version 1803 (10.0.17134)
|
||||
// It's not allowed to enable the Acrylic effect for Win32
|
||||
// applications until Win10 1803.
|
||||
if (forceEnableAcrylicOnWin10()) {
|
||||
accentPolicy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
||||
// The gradient color must be set otherwise it'll look
|
||||
// like a classic blur. Use semi-transparent gradient
|
||||
// color to get better appearance.
|
||||
const QColor color = gradientColor.isValid() ? gradientColor
|
||||
: QColor(255, 255, 255, 0);
|
||||
accentPolicy.GradientColor = color.rgba();
|
||||
} else {
|
||||
// Enabling the Acrylic effect for Win32 windows is
|
||||
// very buggy and it's a bug of Windows 10 itself so
|
||||
// it's not fixable from my side.
|
||||
// So here we switch back to use the classic blur as
|
||||
// a workaround.
|
||||
accentPolicy.AccentState = ACCENT_ENABLE_BLURBEHIND;
|
||||
}
|
||||
} else if (isWin10OrGreater(10240)) {
|
||||
|
|